Completed
Push — develop ( 748f92...9b8857 )
by Naveen
03:01
created
src/shortcodes/wordlift_shortcode_navigator.php 2 patches
Indentation   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -19,29 +19,29 @@  discard block
 block discarded – undo
19 19
  */
20 20
 function wl_shortcode_navigator_data() {
21 21
 
22
-	// Create the cache key.
23
-	$cache_key_params = $_REQUEST;
24
-	unset( $cache_key_params['uniqid'] );
25
-	$cache_key = array( 'request_params' => $cache_key_params );
22
+    // Create the cache key.
23
+    $cache_key_params = $_REQUEST;
24
+    unset( $cache_key_params['uniqid'] );
25
+    $cache_key = array( 'request_params' => $cache_key_params );
26 26
 
27
-	// Create the TTL cache and try to get the results.
28
-	$cache         = new Ttl_Cache( "navigator", 8 * 60 * 60 ); // 8 hours.
29
-	$cache_results = $cache->get( $cache_key );
27
+    // Create the TTL cache and try to get the results.
28
+    $cache         = new Ttl_Cache( "navigator", 8 * 60 * 60 ); // 8 hours.
29
+    $cache_results = $cache->get( $cache_key );
30 30
 
31
-	if ( isset( $cache_results ) ) {
32
-		header( 'X-WordLift-Cache: HIT' );
31
+    if ( isset( $cache_results ) ) {
32
+        header( 'X-WordLift-Cache: HIT' );
33 33
 
34
-		return $cache_results;
35
-	}
34
+        return $cache_results;
35
+    }
36 36
 
37
-	header( 'X-WordLift-Cache: MISS' );
37
+    header( 'X-WordLift-Cache: MISS' );
38 38
 
39
-	$results = _wl_navigator_get_data();
39
+    $results = _wl_navigator_get_data();
40 40
 
41
-	// Put the result before sending the json to the client, since sending the json will terminate us.
42
-	$cache->put( $cache_key, $results );
41
+    // Put the result before sending the json to the client, since sending the json will terminate us.
42
+    $cache->put( $cache_key, $results );
43 43
 
44
-	return $results;
44
+    return $results;
45 45
 }
46 46
 
47 47
 /**
@@ -56,234 +56,234 @@  discard block
 block discarded – undo
56 56
  */
57 57
 function wl_network_navigator_wp_json( $request ) {
58 58
 
59
-	// Create the cache key.
60
-	$cache_key_params = $_REQUEST;
61
-	unset( $cache_key_params['uniqid'] );
62
-	$cache_key = array( 'request_params' => $cache_key_params );
59
+    // Create the cache key.
60
+    $cache_key_params = $_REQUEST;
61
+    unset( $cache_key_params['uniqid'] );
62
+    $cache_key = array( 'request_params' => $cache_key_params );
63 63
 
64
-	// Create the TTL cache and try to get the results.
65
-	$cache         = new Ttl_Cache( "network-navigator", 8 * 60 * 60 ); // 8 hours.
66
-	$cache_results = $cache->get( $cache_key );
64
+    // Create the TTL cache and try to get the results.
65
+    $cache         = new Ttl_Cache( "network-navigator", 8 * 60 * 60 ); // 8 hours.
66
+    $cache_results = $cache->get( $cache_key );
67 67
 
68
-	if ( isset( $cache_results ) ) {
69
-		header( 'X-WordLift-Cache: HIT' );
68
+    if ( isset( $cache_results ) ) {
69
+        header( 'X-WordLift-Cache: HIT' );
70 70
 
71
-		return $cache_results;
72
-	}
71
+        return $cache_results;
72
+    }
73 73
 
74
-	header( 'X-WordLift-Cache: MISS' );
74
+    header( 'X-WordLift-Cache: MISS' );
75 75
 
76
-	$results = _wl_network_navigator_get_data( $request );
76
+    $results = _wl_network_navigator_get_data( $request );
77 77
 
78
-	// Put the result before sending the json to the client, since sending the json will terminate us.
79
-	$cache->put( $cache_key, $results );
78
+    // Put the result before sending the json to the client, since sending the json will terminate us.
79
+    $cache->put( $cache_key, $results );
80 80
 
81
-	return $results;
81
+    return $results;
82 82
 
83 83
 }
84 84
 
85 85
 function _wl_navigator_get_data() {
86 86
 
87
-	// Post ID must be defined
88
-	if ( ! isset( $_GET['post_id'] ) ) {
89
-		wp_send_json_error( 'No post_id given' );
90
-
91
-		return array();
92
-	}
93
-
94
-	// Post ID must be defined
95
-	if ( ! isset( $_GET['uniqid'] ) ) {
96
-		wp_send_json_error( 'No uniqid given' );
97
-
98
-		return array();
99
-	}
100
-
101
-	// Limit the results (defaults to 4)
102
-	$navigator_length    = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4;
103
-	$navigator_offset    = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0;
104
-	$order_by            = isset( $_GET['sort'] ) ? sanitize_sql_orderby( $_GET['sort'] ) : 'ID DESC';
105
-	$post_types          = isset( $_GET['post_types'] ) ? (string) $_GET['post_types'] : '';
106
-	$post_types          = explode( ',', $post_types );
107
-	$existing_post_types = get_post_types();
108
-	$post_types          = array_values( array_intersect( $existing_post_types, $post_types ) );
109
-	$current_post_id     = $_GET['post_id'];
110
-	$current_post        = get_post( $current_post_id );
111
-
112
-	$navigator_id = $_GET['uniqid'];
113
-
114
-	// Post ID has to match an existing item
115
-	if ( null === $current_post ) {
116
-		wp_send_json_error( 'No valid post_id given' );
117
-
118
-		return array();
119
-	}
120
-
121
-	// Determine navigator type and call respective _get_results
122
-	if ( get_post_type( $current_post_id ) === Wordlift_Entity_Service::TYPE_NAME ) {
123
-
124
-		$referencing_posts = Navigator_Data::entity_navigator_get_results( $current_post_id, array(
125
-			'ID',
126
-			'post_title',
127
-		), $order_by, $navigator_length, $navigator_offset, $post_types );
128
-	} else {
129
-		$referencing_posts = Navigator_Data::post_navigator_get_results( $current_post_id, array(
130
-			'ID',
131
-			'post_title',
132
-		), $order_by, $navigator_length, $navigator_offset, $post_types );
133
-	}
134
-
135
-	// loop over them and take the first one which is not already in the $related_posts
136
-	$results = array();
137
-	foreach ( $referencing_posts as $referencing_post ) {
138
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
139
-
140
-		/**
141
-		 * Use the thumbnail.
142
-		 *
143
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
144
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/837
145
-		 *
146
-		 * @since 3.19.3 We're using the medium size image.
147
-		 */
148
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
149
-
150
-		$result = array(
151
-			'post'   => array(
152
-				'id'        => $referencing_post->ID,
153
-				'permalink' => get_permalink( $referencing_post->ID ),
154
-				'title'     => $referencing_post->post_title,
155
-				'thumbnail' => $thumbnail,
156
-			),
157
-			'entity' => array(
158
-				'id'        => $referencing_post->entity_id,
159
-				'label'     => $serialized_entity['label'],
160
-				'mainType'  => $serialized_entity['mainType'],
161
-				'permalink' => get_permalink( $referencing_post->entity_id ),
162
-			),
163
-		);
164
-
165
-		$results[] = $result;
166
-	}
167
-
168
-
169
-	if ( count( $results ) < $navigator_length ) {
170
-		$results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
171
-	}
172
-
173
-	// Add filler posts if needed
174
-	$filler_count = $navigator_length - count( $results );
175
-	if ( $filler_count > 0 ) {
176
-		$referencing_post_ids = array_map( function ( $p ) {
177
-			return $p->ID;
178
-		}, $referencing_posts );
179
-		/**
180
-		 * @since 3.27.8
181
-		 * Filler posts are fetched using this util.
182
-		 */
183
-		$filler_posts_util    = new Filler_Posts_Util( $current_post_id );
184
-		$post_ids_to_be_excluded = array_merge( array( $current_post_id ), $referencing_post_ids );
185
-		$filler_posts            = $filler_posts_util->get_filler_response( $filler_count, $post_ids_to_be_excluded );
186
-		$results                 = array_merge( $results, $filler_posts );
187
-	}
188
-
189
-	// Apply filters after fillers are added
190
-	foreach ( $results as $result_index => $result ) {
191
-		$results[ $result_index ]['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $result['post']['id'] ), $navigator_id );
192
-		$results[ $result_index ]['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
193
-	}
194
-
195
-	return $results;
87
+    // Post ID must be defined
88
+    if ( ! isset( $_GET['post_id'] ) ) {
89
+        wp_send_json_error( 'No post_id given' );
90
+
91
+        return array();
92
+    }
93
+
94
+    // Post ID must be defined
95
+    if ( ! isset( $_GET['uniqid'] ) ) {
96
+        wp_send_json_error( 'No uniqid given' );
97
+
98
+        return array();
99
+    }
100
+
101
+    // Limit the results (defaults to 4)
102
+    $navigator_length    = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4;
103
+    $navigator_offset    = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0;
104
+    $order_by            = isset( $_GET['sort'] ) ? sanitize_sql_orderby( $_GET['sort'] ) : 'ID DESC';
105
+    $post_types          = isset( $_GET['post_types'] ) ? (string) $_GET['post_types'] : '';
106
+    $post_types          = explode( ',', $post_types );
107
+    $existing_post_types = get_post_types();
108
+    $post_types          = array_values( array_intersect( $existing_post_types, $post_types ) );
109
+    $current_post_id     = $_GET['post_id'];
110
+    $current_post        = get_post( $current_post_id );
111
+
112
+    $navigator_id = $_GET['uniqid'];
113
+
114
+    // Post ID has to match an existing item
115
+    if ( null === $current_post ) {
116
+        wp_send_json_error( 'No valid post_id given' );
117
+
118
+        return array();
119
+    }
120
+
121
+    // Determine navigator type and call respective _get_results
122
+    if ( get_post_type( $current_post_id ) === Wordlift_Entity_Service::TYPE_NAME ) {
123
+
124
+        $referencing_posts = Navigator_Data::entity_navigator_get_results( $current_post_id, array(
125
+            'ID',
126
+            'post_title',
127
+        ), $order_by, $navigator_length, $navigator_offset, $post_types );
128
+    } else {
129
+        $referencing_posts = Navigator_Data::post_navigator_get_results( $current_post_id, array(
130
+            'ID',
131
+            'post_title',
132
+        ), $order_by, $navigator_length, $navigator_offset, $post_types );
133
+    }
134
+
135
+    // loop over them and take the first one which is not already in the $related_posts
136
+    $results = array();
137
+    foreach ( $referencing_posts as $referencing_post ) {
138
+        $serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
139
+
140
+        /**
141
+         * Use the thumbnail.
142
+         *
143
+         * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
144
+         * @see https://github.com/insideout10/wordlift-plugin/issues/837
145
+         *
146
+         * @since 3.19.3 We're using the medium size image.
147
+         */
148
+        $thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
149
+
150
+        $result = array(
151
+            'post'   => array(
152
+                'id'        => $referencing_post->ID,
153
+                'permalink' => get_permalink( $referencing_post->ID ),
154
+                'title'     => $referencing_post->post_title,
155
+                'thumbnail' => $thumbnail,
156
+            ),
157
+            'entity' => array(
158
+                'id'        => $referencing_post->entity_id,
159
+                'label'     => $serialized_entity['label'],
160
+                'mainType'  => $serialized_entity['mainType'],
161
+                'permalink' => get_permalink( $referencing_post->entity_id ),
162
+            ),
163
+        );
164
+
165
+        $results[] = $result;
166
+    }
167
+
168
+
169
+    if ( count( $results ) < $navigator_length ) {
170
+        $results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
171
+    }
172
+
173
+    // Add filler posts if needed
174
+    $filler_count = $navigator_length - count( $results );
175
+    if ( $filler_count > 0 ) {
176
+        $referencing_post_ids = array_map( function ( $p ) {
177
+            return $p->ID;
178
+        }, $referencing_posts );
179
+        /**
180
+         * @since 3.27.8
181
+         * Filler posts are fetched using this util.
182
+         */
183
+        $filler_posts_util    = new Filler_Posts_Util( $current_post_id );
184
+        $post_ids_to_be_excluded = array_merge( array( $current_post_id ), $referencing_post_ids );
185
+        $filler_posts            = $filler_posts_util->get_filler_response( $filler_count, $post_ids_to_be_excluded );
186
+        $results                 = array_merge( $results, $filler_posts );
187
+    }
188
+
189
+    // Apply filters after fillers are added
190
+    foreach ( $results as $result_index => $result ) {
191
+        $results[ $result_index ]['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $result['post']['id'] ), $navigator_id );
192
+        $results[ $result_index ]['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
193
+    }
194
+
195
+    return $results;
196 196
 }
197 197
 
198 198
 function _wl_network_navigator_get_data( $request ) {
199 199
 
200
-	// Limit the results (defaults to 4)
201
-	$navigator_length = isset( $request['limit'] ) ? intval( $request['limit'] ) : 4;
202
-	$navigator_offset = isset( $request['offset'] ) ? intval( $request['offset'] ) : 0;
203
-	$navigator_id     = $request['uniqid'];
204
-	$order_by         = isset( $_GET['sort'] ) ? sanitize_sql_orderby( $_GET['sort'] ) : 'ID DESC';
205
-
206
-	$entities = $request['entities'];
207
-
208
-	// Post ID has to match an existing item
209
-	if ( ! isset( $entities ) || empty( $entities ) ) {
210
-		wp_send_json_error( 'No valid entities provided' );
211
-	}
212
-
213
-	$referencing_posts = _wl_network_navigator_get_results( $entities, array(
214
-		'ID',
215
-		'post_title',
216
-	), $order_by, $navigator_length, $navigator_offset );
217
-
218
-	// loop over them and take the first one which is not already in the $related_posts
219
-	$results = array();
220
-	foreach ( $referencing_posts as $referencing_post ) {
221
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
222
-
223
-		/**
224
-		 * Use the thumbnail.
225
-		 *
226
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
227
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/837
228
-		 *
229
-		 * @since 3.19.3 We're using the medium size image.
230
-		 */
231
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
232
-
233
-		$result = array(
234
-			'post'   => array(
235
-				'permalink' => get_permalink( $referencing_post->ID ),
236
-				'title'     => $referencing_post->post_title,
237
-				'thumbnail' => $thumbnail,
238
-			),
239
-			'entity' => array(
240
-				'label'     => $serialized_entity['label'],
241
-				'mainType'  => $serialized_entity['mainType'],
242
-				'permalink' => get_permalink( $referencing_post->entity_id ),
243
-			),
244
-		);
245
-
246
-		$result['post']   = apply_filters( 'wl_network_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
247
-		$result['entity'] = apply_filters( 'wl_network_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
248
-
249
-		$results[] = $result;
250
-
251
-	}
252
-
253
-	if ( count( $results ) < $navigator_length ) {
254
-		$results = apply_filters( 'wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
255
-	}
256
-
257
-	return $results;
200
+    // Limit the results (defaults to 4)
201
+    $navigator_length = isset( $request['limit'] ) ? intval( $request['limit'] ) : 4;
202
+    $navigator_offset = isset( $request['offset'] ) ? intval( $request['offset'] ) : 0;
203
+    $navigator_id     = $request['uniqid'];
204
+    $order_by         = isset( $_GET['sort'] ) ? sanitize_sql_orderby( $_GET['sort'] ) : 'ID DESC';
205
+
206
+    $entities = $request['entities'];
207
+
208
+    // Post ID has to match an existing item
209
+    if ( ! isset( $entities ) || empty( $entities ) ) {
210
+        wp_send_json_error( 'No valid entities provided' );
211
+    }
212
+
213
+    $referencing_posts = _wl_network_navigator_get_results( $entities, array(
214
+        'ID',
215
+        'post_title',
216
+    ), $order_by, $navigator_length, $navigator_offset );
217
+
218
+    // loop over them and take the first one which is not already in the $related_posts
219
+    $results = array();
220
+    foreach ( $referencing_posts as $referencing_post ) {
221
+        $serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
222
+
223
+        /**
224
+         * Use the thumbnail.
225
+         *
226
+         * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
227
+         * @see https://github.com/insideout10/wordlift-plugin/issues/837
228
+         *
229
+         * @since 3.19.3 We're using the medium size image.
230
+         */
231
+        $thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
232
+
233
+        $result = array(
234
+            'post'   => array(
235
+                'permalink' => get_permalink( $referencing_post->ID ),
236
+                'title'     => $referencing_post->post_title,
237
+                'thumbnail' => $thumbnail,
238
+            ),
239
+            'entity' => array(
240
+                'label'     => $serialized_entity['label'],
241
+                'mainType'  => $serialized_entity['mainType'],
242
+                'permalink' => get_permalink( $referencing_post->entity_id ),
243
+            ),
244
+        );
245
+
246
+        $result['post']   = apply_filters( 'wl_network_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
247
+        $result['entity'] = apply_filters( 'wl_network_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
248
+
249
+        $results[] = $result;
250
+
251
+    }
252
+
253
+    if ( count( $results ) < $navigator_length ) {
254
+        $results = apply_filters( 'wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
255
+    }
256
+
257
+    return $results;
258 258
 
259 259
 }
260 260
 
261 261
 function _wl_network_navigator_get_results(
262
-	$entities, $fields = array(
263
-	'ID',
264
-	'post_title',
262
+    $entities, $fields = array(
263
+    'ID',
264
+    'post_title',
265 265
 ), $order_by = 'ID DESC', $limit = 10, $offset = 0
266 266
 ) {
267
-	global $wpdb;
268
-
269
-	$select = implode( ', ', array_map( function ( $item ) {
270
-		return "p.$item AS $item";
271
-	}, (array) $fields ) );
272
-
273
-	$order_by = implode( ', ', array_map( function ( $item ) {
274
-		return "p.$item";
275
-	}, (array) $order_by ) );
276
-
277
-	$entities_in = implode( ',', array_map( function ( $item ) {
278
-		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( urldecode( $item ) );
279
-		if ( isset( $entity ) ) {
280
-			return $entity->ID;
281
-		}
282
-	}, $entities ) );
283
-
284
-	/** @noinspection SqlNoDataSourceInspection */
285
-	return $wpdb->get_results(
286
-		$wpdb->prepare( <<<EOF
267
+    global $wpdb;
268
+
269
+    $select = implode( ', ', array_map( function ( $item ) {
270
+        return "p.$item AS $item";
271
+    }, (array) $fields ) );
272
+
273
+    $order_by = implode( ', ', array_map( function ( $item ) {
274
+        return "p.$item";
275
+    }, (array) $order_by ) );
276
+
277
+    $entities_in = implode( ',', array_map( function ( $item ) {
278
+        $entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( urldecode( $item ) );
279
+        if ( isset( $entity ) ) {
280
+            return $entity->ID;
281
+        }
282
+    }, $entities ) );
283
+
284
+    /** @noinspection SqlNoDataSourceInspection */
285
+    return $wpdb->get_results(
286
+        $wpdb->prepare( <<<EOF
287 287
 SELECT %3\$s, p2.ID as entity_id
288 288
  FROM {$wpdb->prefix}wl_relation_instances r1
289 289
 	-- get the ID of the post entity in common between the object and the subject 2. 
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
  LIMIT %1\$d
310 310
  OFFSET %2\$d
311 311
 EOF
312
-			, $limit, $offset, $select, $order_by )
313
-	);
312
+            , $limit, $offset, $select, $order_by )
313
+    );
314 314
 
315 315
 }
316 316
 
@@ -322,9 +322,9 @@  discard block
 block discarded – undo
322 322
  */
323 323
 function wl_shortcode_navigator_ajax() {
324 324
 
325
-	// Temporary blocking the Navigator.
326
-	$results = wl_shortcode_navigator_data();
327
-	wl_core_send_json( $results );
325
+    // Temporary blocking the Navigator.
326
+    $results = wl_shortcode_navigator_data();
327
+    wl_core_send_json( $results );
328 328
 
329 329
 }
330 330
 
@@ -336,16 +336,16 @@  discard block
 block discarded – undo
336 336
  */
337 337
 function wl_shortcode_navigator_wp_json() {
338 338
 
339
-	$results = wl_shortcode_navigator_data();
340
-	if ( ob_get_contents() ) {
341
-		ob_clean();
342
-	}
339
+    $results = wl_shortcode_navigator_data();
340
+    if ( ob_get_contents() ) {
341
+        ob_clean();
342
+    }
343 343
 
344
-	return array(
345
-		'items' => array(
346
-			array( 'values' => $results ),
347
-		),
348
-	);
344
+    return array(
345
+        'items' => array(
346
+            array( 'values' => $results ),
347
+        ),
348
+    );
349 349
 
350 350
 }
351 351
 
@@ -353,22 +353,22 @@  discard block
 block discarded – undo
353 353
  * Adding `rest_api_init` action for amp backend of navigator
354 354
  */
355 355
 add_action( 'rest_api_init', function () {
356
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
357
-		'methods'             => 'GET',
358
-		'permission_callback' => '__return_true',
359
-		'callback'            => 'wl_shortcode_navigator_wp_json'
360
-	) );
356
+    register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
357
+        'methods'             => 'GET',
358
+        'permission_callback' => '__return_true',
359
+        'callback'            => 'wl_shortcode_navigator_wp_json'
360
+    ) );
361 361
 } );
362 362
 
363 363
 /**
364 364
  * Adding `rest_api_init` action for backend of network navigator
365 365
  */
366 366
 add_action( 'rest_api_init', function () {
367
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
368
-		'methods'             => 'GET',
369
-		'callback'            => 'wl_network_navigator_wp_json',
370
-		'permission_callback' => '__return_true',
371
-	) );
367
+    register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
368
+        'methods'             => 'GET',
369
+        'callback'            => 'wl_network_navigator_wp_json',
370
+        'permission_callback' => '__return_true',
371
+    ) );
372 372
 } );
373 373
 
374 374
 /**
@@ -378,22 +378,22 @@  discard block
 block discarded – undo
378 378
  */
379 379
 add_action( 'plugins_loaded', function () {
380 380
 
381
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
382
-		return;
383
-	}
381
+    if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
382
+        return;
383
+    }
384 384
 
385
-	remove_action( 'plugins_loaded', 'rocket_init' );
386
-	remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
387
-	remove_action( 'plugins_loaded', 'wpseo_init', 14 );
385
+    remove_action( 'plugins_loaded', 'rocket_init' );
386
+    remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
387
+    remove_action( 'plugins_loaded', 'wpseo_init', 14 );
388 388
 }, 0 );
389 389
 
390 390
 add_action( 'init', function () {
391 391
 
392
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
393
-		return;
394
-	}
392
+    if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
393
+        return;
394
+    }
395 395
 
396
-	remove_action( 'init', 'wp_widgets_init', 1 );
397
-	remove_action( 'init', 'gglcptch_init' );
396
+    remove_action( 'init', 'wp_widgets_init', 1 );
397
+    remove_action( 'init', 'gglcptch_init' );
398 398
 }, 0 );
399 399
 
Please login to merge, or discard this patch.
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -21,25 +21,25 @@  discard block
 block discarded – undo
21 21
 
22 22
 	// Create the cache key.
23 23
 	$cache_key_params = $_REQUEST;
24
-	unset( $cache_key_params['uniqid'] );
25
-	$cache_key = array( 'request_params' => $cache_key_params );
24
+	unset($cache_key_params['uniqid']);
25
+	$cache_key = array('request_params' => $cache_key_params);
26 26
 
27 27
 	// Create the TTL cache and try to get the results.
28
-	$cache         = new Ttl_Cache( "navigator", 8 * 60 * 60 ); // 8 hours.
29
-	$cache_results = $cache->get( $cache_key );
28
+	$cache         = new Ttl_Cache("navigator", 8 * 60 * 60); // 8 hours.
29
+	$cache_results = $cache->get($cache_key);
30 30
 
31
-	if ( isset( $cache_results ) ) {
32
-		header( 'X-WordLift-Cache: HIT' );
31
+	if (isset($cache_results)) {
32
+		header('X-WordLift-Cache: HIT');
33 33
 
34 34
 		return $cache_results;
35 35
 	}
36 36
 
37
-	header( 'X-WordLift-Cache: MISS' );
37
+	header('X-WordLift-Cache: MISS');
38 38
 
39 39
 	$results = _wl_navigator_get_data();
40 40
 
41 41
 	// Put the result before sending the json to the client, since sending the json will terminate us.
42
-	$cache->put( $cache_key, $results );
42
+	$cache->put($cache_key, $results);
43 43
 
44 44
 	return $results;
45 45
 }
@@ -54,29 +54,29 @@  discard block
 block discarded – undo
54 54
  * @since 3.22.6
55 55
  *
56 56
  */
57
-function wl_network_navigator_wp_json( $request ) {
57
+function wl_network_navigator_wp_json($request) {
58 58
 
59 59
 	// Create the cache key.
60 60
 	$cache_key_params = $_REQUEST;
61
-	unset( $cache_key_params['uniqid'] );
62
-	$cache_key = array( 'request_params' => $cache_key_params );
61
+	unset($cache_key_params['uniqid']);
62
+	$cache_key = array('request_params' => $cache_key_params);
63 63
 
64 64
 	// Create the TTL cache and try to get the results.
65
-	$cache         = new Ttl_Cache( "network-navigator", 8 * 60 * 60 ); // 8 hours.
66
-	$cache_results = $cache->get( $cache_key );
65
+	$cache         = new Ttl_Cache("network-navigator", 8 * 60 * 60); // 8 hours.
66
+	$cache_results = $cache->get($cache_key);
67 67
 
68
-	if ( isset( $cache_results ) ) {
69
-		header( 'X-WordLift-Cache: HIT' );
68
+	if (isset($cache_results)) {
69
+		header('X-WordLift-Cache: HIT');
70 70
 
71 71
 		return $cache_results;
72 72
 	}
73 73
 
74
-	header( 'X-WordLift-Cache: MISS' );
74
+	header('X-WordLift-Cache: MISS');
75 75
 
76
-	$results = _wl_network_navigator_get_data( $request );
76
+	$results = _wl_network_navigator_get_data($request);
77 77
 
78 78
 	// Put the result before sending the json to the client, since sending the json will terminate us.
79
-	$cache->put( $cache_key, $results );
79
+	$cache->put($cache_key, $results);
80 80
 
81 81
 	return $results;
82 82
 
@@ -85,57 +85,57 @@  discard block
 block discarded – undo
85 85
 function _wl_navigator_get_data() {
86 86
 
87 87
 	// Post ID must be defined
88
-	if ( ! isset( $_GET['post_id'] ) ) {
89
-		wp_send_json_error( 'No post_id given' );
88
+	if ( ! isset($_GET['post_id'])) {
89
+		wp_send_json_error('No post_id given');
90 90
 
91 91
 		return array();
92 92
 	}
93 93
 
94 94
 	// Post ID must be defined
95
-	if ( ! isset( $_GET['uniqid'] ) ) {
96
-		wp_send_json_error( 'No uniqid given' );
95
+	if ( ! isset($_GET['uniqid'])) {
96
+		wp_send_json_error('No uniqid given');
97 97
 
98 98
 		return array();
99 99
 	}
100 100
 
101 101
 	// Limit the results (defaults to 4)
102
-	$navigator_length    = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4;
103
-	$navigator_offset    = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0;
104
-	$order_by            = isset( $_GET['sort'] ) ? sanitize_sql_orderby( $_GET['sort'] ) : 'ID DESC';
105
-	$post_types          = isset( $_GET['post_types'] ) ? (string) $_GET['post_types'] : '';
106
-	$post_types          = explode( ',', $post_types );
102
+	$navigator_length    = isset($_GET['limit']) ? intval($_GET['limit']) : 4;
103
+	$navigator_offset    = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
104
+	$order_by            = isset($_GET['sort']) ? sanitize_sql_orderby($_GET['sort']) : 'ID DESC';
105
+	$post_types          = isset($_GET['post_types']) ? (string) $_GET['post_types'] : '';
106
+	$post_types          = explode(',', $post_types);
107 107
 	$existing_post_types = get_post_types();
108
-	$post_types          = array_values( array_intersect( $existing_post_types, $post_types ) );
108
+	$post_types          = array_values(array_intersect($existing_post_types, $post_types));
109 109
 	$current_post_id     = $_GET['post_id'];
110
-	$current_post        = get_post( $current_post_id );
110
+	$current_post        = get_post($current_post_id);
111 111
 
112 112
 	$navigator_id = $_GET['uniqid'];
113 113
 
114 114
 	// Post ID has to match an existing item
115
-	if ( null === $current_post ) {
116
-		wp_send_json_error( 'No valid post_id given' );
115
+	if (null === $current_post) {
116
+		wp_send_json_error('No valid post_id given');
117 117
 
118 118
 		return array();
119 119
 	}
120 120
 
121 121
 	// Determine navigator type and call respective _get_results
122
-	if ( get_post_type( $current_post_id ) === Wordlift_Entity_Service::TYPE_NAME ) {
122
+	if (get_post_type($current_post_id) === Wordlift_Entity_Service::TYPE_NAME) {
123 123
 
124
-		$referencing_posts = Navigator_Data::entity_navigator_get_results( $current_post_id, array(
124
+		$referencing_posts = Navigator_Data::entity_navigator_get_results($current_post_id, array(
125 125
 			'ID',
126 126
 			'post_title',
127
-		), $order_by, $navigator_length, $navigator_offset, $post_types );
127
+		), $order_by, $navigator_length, $navigator_offset, $post_types);
128 128
 	} else {
129
-		$referencing_posts = Navigator_Data::post_navigator_get_results( $current_post_id, array(
129
+		$referencing_posts = Navigator_Data::post_navigator_get_results($current_post_id, array(
130 130
 			'ID',
131 131
 			'post_title',
132
-		), $order_by, $navigator_length, $navigator_offset, $post_types );
132
+		), $order_by, $navigator_length, $navigator_offset, $post_types);
133 133
 	}
134 134
 
135 135
 	// loop over them and take the first one which is not already in the $related_posts
136 136
 	$results = array();
137
-	foreach ( $referencing_posts as $referencing_post ) {
138
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
137
+	foreach ($referencing_posts as $referencing_post) {
138
+		$serialized_entity = wl_serialize_entity($referencing_post->entity_id);
139 139
 
140 140
 		/**
141 141
 		 * Use the thumbnail.
@@ -145,12 +145,12 @@  discard block
 block discarded – undo
145 145
 		 *
146 146
 		 * @since 3.19.3 We're using the medium size image.
147 147
 		 */
148
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
148
+		$thumbnail = get_the_post_thumbnail_url($referencing_post, 'medium');
149 149
 
150 150
 		$result = array(
151 151
 			'post'   => array(
152 152
 				'id'        => $referencing_post->ID,
153
-				'permalink' => get_permalink( $referencing_post->ID ),
153
+				'permalink' => get_permalink($referencing_post->ID),
154 154
 				'title'     => $referencing_post->post_title,
155 155
 				'thumbnail' => $thumbnail,
156 156
 			),
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 				'id'        => $referencing_post->entity_id,
159 159
 				'label'     => $serialized_entity['label'],
160 160
 				'mainType'  => $serialized_entity['mainType'],
161
-				'permalink' => get_permalink( $referencing_post->entity_id ),
161
+				'permalink' => get_permalink($referencing_post->entity_id),
162 162
 			),
163 163
 		);
164 164
 
@@ -166,59 +166,59 @@  discard block
 block discarded – undo
166 166
 	}
167 167
 
168 168
 
169
-	if ( count( $results ) < $navigator_length ) {
170
-		$results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
169
+	if (count($results) < $navigator_length) {
170
+		$results = apply_filters('wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length);
171 171
 	}
172 172
 
173 173
 	// Add filler posts if needed
174
-	$filler_count = $navigator_length - count( $results );
175
-	if ( $filler_count > 0 ) {
176
-		$referencing_post_ids = array_map( function ( $p ) {
174
+	$filler_count = $navigator_length - count($results);
175
+	if ($filler_count > 0) {
176
+		$referencing_post_ids = array_map(function($p) {
177 177
 			return $p->ID;
178
-		}, $referencing_posts );
178
+		}, $referencing_posts);
179 179
 		/**
180 180
 		 * @since 3.27.8
181 181
 		 * Filler posts are fetched using this util.
182 182
 		 */
183
-		$filler_posts_util    = new Filler_Posts_Util( $current_post_id );
184
-		$post_ids_to_be_excluded = array_merge( array( $current_post_id ), $referencing_post_ids );
185
-		$filler_posts            = $filler_posts_util->get_filler_response( $filler_count, $post_ids_to_be_excluded );
186
-		$results                 = array_merge( $results, $filler_posts );
183
+		$filler_posts_util = new Filler_Posts_Util($current_post_id);
184
+		$post_ids_to_be_excluded = array_merge(array($current_post_id), $referencing_post_ids);
185
+		$filler_posts            = $filler_posts_util->get_filler_response($filler_count, $post_ids_to_be_excluded);
186
+		$results                 = array_merge($results, $filler_posts);
187 187
 	}
188 188
 
189 189
 	// Apply filters after fillers are added
190
-	foreach ( $results as $result_index => $result ) {
191
-		$results[ $result_index ]['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $result['post']['id'] ), $navigator_id );
192
-		$results[ $result_index ]['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
190
+	foreach ($results as $result_index => $result) {
191
+		$results[$result_index]['post']   = apply_filters('wl_navigator_data_post', $result['post'], intval($result['post']['id']), $navigator_id);
192
+		$results[$result_index]['entity'] = apply_filters('wl_navigator_data_entity', $result['entity'], intval($result['entity']['id']), $navigator_id);
193 193
 	}
194 194
 
195 195
 	return $results;
196 196
 }
197 197
 
198
-function _wl_network_navigator_get_data( $request ) {
198
+function _wl_network_navigator_get_data($request) {
199 199
 
200 200
 	// Limit the results (defaults to 4)
201
-	$navigator_length = isset( $request['limit'] ) ? intval( $request['limit'] ) : 4;
202
-	$navigator_offset = isset( $request['offset'] ) ? intval( $request['offset'] ) : 0;
201
+	$navigator_length = isset($request['limit']) ? intval($request['limit']) : 4;
202
+	$navigator_offset = isset($request['offset']) ? intval($request['offset']) : 0;
203 203
 	$navigator_id     = $request['uniqid'];
204
-	$order_by         = isset( $_GET['sort'] ) ? sanitize_sql_orderby( $_GET['sort'] ) : 'ID DESC';
204
+	$order_by         = isset($_GET['sort']) ? sanitize_sql_orderby($_GET['sort']) : 'ID DESC';
205 205
 
206 206
 	$entities = $request['entities'];
207 207
 
208 208
 	// Post ID has to match an existing item
209
-	if ( ! isset( $entities ) || empty( $entities ) ) {
210
-		wp_send_json_error( 'No valid entities provided' );
209
+	if ( ! isset($entities) || empty($entities)) {
210
+		wp_send_json_error('No valid entities provided');
211 211
 	}
212 212
 
213
-	$referencing_posts = _wl_network_navigator_get_results( $entities, array(
213
+	$referencing_posts = _wl_network_navigator_get_results($entities, array(
214 214
 		'ID',
215 215
 		'post_title',
216
-	), $order_by, $navigator_length, $navigator_offset );
216
+	), $order_by, $navigator_length, $navigator_offset);
217 217
 
218 218
 	// loop over them and take the first one which is not already in the $related_posts
219 219
 	$results = array();
220
-	foreach ( $referencing_posts as $referencing_post ) {
221
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
220
+	foreach ($referencing_posts as $referencing_post) {
221
+		$serialized_entity = wl_serialize_entity($referencing_post->entity_id);
222 222
 
223 223
 		/**
224 224
 		 * Use the thumbnail.
@@ -228,30 +228,30 @@  discard block
 block discarded – undo
228 228
 		 *
229 229
 		 * @since 3.19.3 We're using the medium size image.
230 230
 		 */
231
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
231
+		$thumbnail = get_the_post_thumbnail_url($referencing_post, 'medium');
232 232
 
233 233
 		$result = array(
234 234
 			'post'   => array(
235
-				'permalink' => get_permalink( $referencing_post->ID ),
235
+				'permalink' => get_permalink($referencing_post->ID),
236 236
 				'title'     => $referencing_post->post_title,
237 237
 				'thumbnail' => $thumbnail,
238 238
 			),
239 239
 			'entity' => array(
240 240
 				'label'     => $serialized_entity['label'],
241 241
 				'mainType'  => $serialized_entity['mainType'],
242
-				'permalink' => get_permalink( $referencing_post->entity_id ),
242
+				'permalink' => get_permalink($referencing_post->entity_id),
243 243
 			),
244 244
 		);
245 245
 
246
-		$result['post']   = apply_filters( 'wl_network_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
247
-		$result['entity'] = apply_filters( 'wl_network_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
246
+		$result['post']   = apply_filters('wl_network_navigator_data_post', $result['post'], intval($referencing_post->ID), $navigator_id);
247
+		$result['entity'] = apply_filters('wl_network_navigator_data_entity', $result['entity'], intval($referencing_post->entity_id), $navigator_id);
248 248
 
249 249
 		$results[] = $result;
250 250
 
251 251
 	}
252 252
 
253
-	if ( count( $results ) < $navigator_length ) {
254
-		$results = apply_filters( 'wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
253
+	if (count($results) < $navigator_length) {
254
+		$results = apply_filters('wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length);
255 255
 	}
256 256
 
257 257
 	return $results;
@@ -266,24 +266,24 @@  discard block
 block discarded – undo
266 266
 ) {
267 267
 	global $wpdb;
268 268
 
269
-	$select = implode( ', ', array_map( function ( $item ) {
269
+	$select = implode(', ', array_map(function($item) {
270 270
 		return "p.$item AS $item";
271
-	}, (array) $fields ) );
271
+	}, (array) $fields));
272 272
 
273
-	$order_by = implode( ', ', array_map( function ( $item ) {
273
+	$order_by = implode(', ', array_map(function($item) {
274 274
 		return "p.$item";
275
-	}, (array) $order_by ) );
275
+	}, (array) $order_by));
276 276
 
277
-	$entities_in = implode( ',', array_map( function ( $item ) {
278
-		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( urldecode( $item ) );
279
-		if ( isset( $entity ) ) {
277
+	$entities_in = implode(',', array_map(function($item) {
278
+		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri(urldecode($item));
279
+		if (isset($entity)) {
280 280
 			return $entity->ID;
281 281
 		}
282
-	}, $entities ) );
282
+	}, $entities));
283 283
 
284 284
 	/** @noinspection SqlNoDataSourceInspection */
285 285
 	return $wpdb->get_results(
286
-		$wpdb->prepare( <<<EOF
286
+		$wpdb->prepare(<<<EOF
287 287
 SELECT %3\$s, p2.ID as entity_id
288 288
  FROM {$wpdb->prefix}wl_relation_instances r1
289 289
 	-- get the ID of the post entity in common between the object and the subject 2. 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
  LIMIT %1\$d
310 310
  OFFSET %2\$d
311 311
 EOF
312
-			, $limit, $offset, $select, $order_by )
312
+			, $limit, $offset, $select, $order_by)
313 313
 	);
314 314
 
315 315
 }
@@ -324,12 +324,12 @@  discard block
 block discarded – undo
324 324
 
325 325
 	// Temporary blocking the Navigator.
326 326
 	$results = wl_shortcode_navigator_data();
327
-	wl_core_send_json( $results );
327
+	wl_core_send_json($results);
328 328
 
329 329
 }
330 330
 
331
-add_action( 'wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax' );
332
-add_action( 'wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax' );
331
+add_action('wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax');
332
+add_action('wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax');
333 333
 
334 334
 /**
335 335
  * wp-json call for the navigator widget
@@ -337,13 +337,13 @@  discard block
 block discarded – undo
337 337
 function wl_shortcode_navigator_wp_json() {
338 338
 
339 339
 	$results = wl_shortcode_navigator_data();
340
-	if ( ob_get_contents() ) {
340
+	if (ob_get_contents()) {
341 341
 		ob_clean();
342 342
 	}
343 343
 
344 344
 	return array(
345 345
 		'items' => array(
346
-			array( 'values' => $results ),
346
+			array('values' => $results),
347 347
 		),
348 348
 	);
349 349
 
@@ -352,23 +352,23 @@  discard block
 block discarded – undo
352 352
 /**
353 353
  * Adding `rest_api_init` action for amp backend of navigator
354 354
  */
355
-add_action( 'rest_api_init', function () {
356
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
355
+add_action('rest_api_init', function() {
356
+	register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
357 357
 		'methods'             => 'GET',
358 358
 		'permission_callback' => '__return_true',
359 359
 		'callback'            => 'wl_shortcode_navigator_wp_json'
360
-	) );
360
+	));
361 361
 } );
362 362
 
363 363
 /**
364 364
  * Adding `rest_api_init` action for backend of network navigator
365 365
  */
366
-add_action( 'rest_api_init', function () {
367
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
366
+add_action('rest_api_init', function() {
367
+	register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
368 368
 		'methods'             => 'GET',
369 369
 		'callback'            => 'wl_network_navigator_wp_json',
370 370
 		'permission_callback' => '__return_true',
371
-	) );
371
+	));
372 372
 } );
373 373
 
374 374
 /**
@@ -376,24 +376,24 @@  discard block
 block discarded – undo
376 376
  *
377 377
  * @since 2.2.0
378 378
  */
379
-add_action( 'plugins_loaded', function () {
379
+add_action('plugins_loaded', function() {
380 380
 
381
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
381
+	if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action']) {
382 382
 		return;
383 383
 	}
384 384
 
385
-	remove_action( 'plugins_loaded', 'rocket_init' );
386
-	remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
387
-	remove_action( 'plugins_loaded', 'wpseo_init', 14 );
388
-}, 0 );
385
+	remove_action('plugins_loaded', 'rocket_init');
386
+	remove_action('plugins_loaded', 'wpseo_premium_init', 14);
387
+	remove_action('plugins_loaded', 'wpseo_init', 14);
388
+}, 0);
389 389
 
390
-add_action( 'init', function () {
390
+add_action('init', function() {
391 391
 
392
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
392
+	if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action']) {
393 393
 		return;
394 394
 	}
395 395
 
396
-	remove_action( 'init', 'wp_widgets_init', 1 );
397
-	remove_action( 'init', 'gglcptch_init' );
398
-}, 0 );
396
+	remove_action('init', 'wp_widgets_init', 1);
397
+	remove_action('init', 'gglcptch_init');
398
+}, 0);
399 399
 
Please login to merge, or discard this patch.
src/wordlift/widgets/navigator/class-navigator-data.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -7,37 +7,37 @@  discard block
 block discarded – undo
7 7
  */
8 8
 class Navigator_Data {
9 9
 
10
-	public static function get_post_types_as_string( $post_types ) {
11
-		if ( $post_types === array() ) {
12
-			$post_types = get_post_types();
13
-		}
14
-		$post_types = array_map( function ( $post_type ) {
15
-			return "'" . esc_sql( $post_type ) . "'";
16
-		}, $post_types );
10
+    public static function get_post_types_as_string( $post_types ) {
11
+        if ( $post_types === array() ) {
12
+            $post_types = get_post_types();
13
+        }
14
+        $post_types = array_map( function ( $post_type ) {
15
+            return "'" . esc_sql( $post_type ) . "'";
16
+        }, $post_types );
17 17
 
18
-		return implode( ',', $post_types );
19
-	}
18
+        return implode( ',', $post_types );
19
+    }
20 20
 
21
-	public static function post_navigator_get_results(
22
-		$post_id, $fields = array(
23
-		'ID',
24
-		'post_title',
25
-	), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array()
26
-	) {
21
+    public static function post_navigator_get_results(
22
+        $post_id, $fields = array(
23
+        'ID',
24
+        'post_title',
25
+    ), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array()
26
+    ) {
27 27
 
28
-		$post_types = self::get_post_types_as_string( $post_types );
29
-		global $wpdb;
28
+        $post_types = self::get_post_types_as_string( $post_types );
29
+        global $wpdb;
30 30
 
31
-		$select = implode( ', ', array_map( function ( $item ) {
32
-			return "p.$item AS $item";
33
-		}, (array) $fields ) );
31
+        $select = implode( ', ', array_map( function ( $item ) {
32
+            return "p.$item AS $item";
33
+        }, (array) $fields ) );
34 34
 
35
-		$order_by = implode( ', ', array_map( function ( $item ) {
36
-			return "p.$item";
37
-		}, (array) $order_by ) );
35
+        $order_by = implode( ', ', array_map( function ( $item ) {
36
+            return "p.$item";
37
+        }, (array) $order_by ) );
38 38
 
39 39
 
40
-		$sql = 			$wpdb->prepare( <<<EOF
40
+        $sql = 			$wpdb->prepare( <<<EOF
41 41
 SELECT %4\$s, p2.ID as entity_id
42 42
  FROM {$wpdb->prefix}wl_relation_instances r1
43 43
     INNER JOIN {$wpdb->prefix}wl_relation_instances r2
@@ -71,37 +71,37 @@  discard block
 block discarded – undo
71 71
  LIMIT %2\$d
72 72
  OFFSET %3\$d
73 73
 EOF
74
-			, $post_id, $limit, $offset, $select, $order_by );
75
-		var_dump($sql);
76
-		/** @noinspection SqlNoDataSourceInspection */
77
-		return $wpdb->get_results(
78
-			$sql
79
-		);
74
+            , $post_id, $limit, $offset, $select, $order_by );
75
+        var_dump($sql);
76
+        /** @noinspection SqlNoDataSourceInspection */
77
+        return $wpdb->get_results(
78
+            $sql
79
+        );
80 80
 
81
-	}
81
+    }
82 82
 
83 83
 
84
-	public static function entity_navigator_get_results(
85
-		$post_id, $fields = array(
86
-		'ID',
87
-		'post_title',
88
-	), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array()
89
-	) {
90
-		global $wpdb;
84
+    public static function entity_navigator_get_results(
85
+        $post_id, $fields = array(
86
+        'ID',
87
+        'post_title',
88
+    ), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array()
89
+    ) {
90
+        global $wpdb;
91 91
 
92
-		$select = implode( ', ', array_map( function ( $item ) {
93
-			return "p.$item AS $item";
94
-		}, (array) $fields ) );
92
+        $select = implode( ', ', array_map( function ( $item ) {
93
+            return "p.$item AS $item";
94
+        }, (array) $fields ) );
95 95
 
96
-		$order_by = implode( ', ', array_map( function ( $item ) {
97
-			return "p.$item";
98
-		}, (array) $order_by ) );
96
+        $order_by = implode( ', ', array_map( function ( $item ) {
97
+            return "p.$item";
98
+        }, (array) $order_by ) );
99 99
 
100
-		$post_types = self::get_post_types_as_string( $post_types );
100
+        $post_types = self::get_post_types_as_string( $post_types );
101 101
 
102
-		/** @noinspection SqlNoDataSourceInspection */
103
-		return $wpdb->get_results(
104
-			$wpdb->prepare( <<<EOF
102
+        /** @noinspection SqlNoDataSourceInspection */
103
+        return $wpdb->get_results(
104
+            $wpdb->prepare( <<<EOF
105 105
 SELECT %4\$s, p2.ID as entity_id
106 106
  FROM {$wpdb->prefix}wl_relation_instances r1
107 107
 	-- get the ID of the post entity in common between the object and the subject 2. 
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
  LIMIT %2\$d
133 133
  OFFSET %3\$d
134 134
 EOF
135
-				, $post_id, $limit, $offset, $select, $order_by )
136
-		);
137
-	}
135
+                , $post_id, $limit, $offset, $select, $order_by )
136
+        );
137
+    }
138 138
 
139 139
 
140 140
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
 class Navigator_Data {
9 9
 
10
-	public static function get_post_types_as_string( $post_types ) {
11
-		if ( $post_types === array() ) {
10
+	public static function get_post_types_as_string($post_types) {
11
+		if ($post_types === array()) {
12 12
 			$post_types = get_post_types();
13 13
 		}
14
-		$post_types = array_map( function ( $post_type ) {
15
-			return "'" . esc_sql( $post_type ) . "'";
16
-		}, $post_types );
14
+		$post_types = array_map(function($post_type) {
15
+			return "'".esc_sql($post_type)."'";
16
+		}, $post_types);
17 17
 
18
-		return implode( ',', $post_types );
18
+		return implode(',', $post_types);
19 19
 	}
20 20
 
21 21
 	public static function post_navigator_get_results(
@@ -25,19 +25,19 @@  discard block
 block discarded – undo
25 25
 	), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array()
26 26
 	) {
27 27
 
28
-		$post_types = self::get_post_types_as_string( $post_types );
28
+		$post_types = self::get_post_types_as_string($post_types);
29 29
 		global $wpdb;
30 30
 
31
-		$select = implode( ', ', array_map( function ( $item ) {
31
+		$select = implode(', ', array_map(function($item) {
32 32
 			return "p.$item AS $item";
33
-		}, (array) $fields ) );
33
+		}, (array) $fields));
34 34
 
35
-		$order_by = implode( ', ', array_map( function ( $item ) {
35
+		$order_by = implode(', ', array_map(function($item) {
36 36
 			return "p.$item";
37
-		}, (array) $order_by ) );
37
+		}, (array) $order_by));
38 38
 
39 39
 
40
-		$sql = 			$wpdb->prepare( <<<EOF
40
+		$sql = $wpdb->prepare(<<<EOF
41 41
 SELECT %4\$s, p2.ID as entity_id
42 42
  FROM {$wpdb->prefix}wl_relation_instances r1
43 43
     INNER JOIN {$wpdb->prefix}wl_relation_instances r2
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
  LIMIT %2\$d
72 72
  OFFSET %3\$d
73 73
 EOF
74
-			, $post_id, $limit, $offset, $select, $order_by );
74
+			, $post_id, $limit, $offset, $select, $order_by);
75 75
 		var_dump($sql);
76 76
 		/** @noinspection SqlNoDataSourceInspection */
77 77
 		return $wpdb->get_results(
@@ -89,19 +89,19 @@  discard block
 block discarded – undo
89 89
 	) {
90 90
 		global $wpdb;
91 91
 
92
-		$select = implode( ', ', array_map( function ( $item ) {
92
+		$select = implode(', ', array_map(function($item) {
93 93
 			return "p.$item AS $item";
94
-		}, (array) $fields ) );
94
+		}, (array) $fields));
95 95
 
96
-		$order_by = implode( ', ', array_map( function ( $item ) {
96
+		$order_by = implode(', ', array_map(function($item) {
97 97
 			return "p.$item";
98
-		}, (array) $order_by ) );
98
+		}, (array) $order_by));
99 99
 
100
-		$post_types = self::get_post_types_as_string( $post_types );
100
+		$post_types = self::get_post_types_as_string($post_types);
101 101
 
102 102
 		/** @noinspection SqlNoDataSourceInspection */
103 103
 		return $wpdb->get_results(
104
-			$wpdb->prepare( <<<EOF
104
+			$wpdb->prepare(<<<EOF
105 105
 SELECT %4\$s, p2.ID as entity_id
106 106
  FROM {$wpdb->prefix}wl_relation_instances r1
107 107
 	-- get the ID of the post entity in common between the object and the subject 2. 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
  LIMIT %2\$d
133 133
  OFFSET %3\$d
134 134
 EOF
135
-				, $post_id, $limit, $offset, $select, $order_by )
135
+				, $post_id, $limit, $offset, $select, $order_by)
136 136
 		);
137 137
 	}
138 138
 
Please login to merge, or discard this patch.