Completed
Push — develop ( 836f45...748f92 )
by Naveen
02:53
created
src/shortcodes/wordlift_shortcode_navigator.php 2 patches
Indentation   +258 added lines, -258 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,235 +56,235 @@  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
-		var_dump($referencing_posts);
134
-	}
135
-
136
-	// loop over them and take the first one which is not already in the $related_posts
137
-	$results = array();
138
-	foreach ( $referencing_posts as $referencing_post ) {
139
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
140
-
141
-		/**
142
-		 * Use the thumbnail.
143
-		 *
144
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
145
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/837
146
-		 *
147
-		 * @since 3.19.3 We're using the medium size image.
148
-		 */
149
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
150
-
151
-		$result = array(
152
-			'post'   => array(
153
-				'id'        => $referencing_post->ID,
154
-				'permalink' => get_permalink( $referencing_post->ID ),
155
-				'title'     => $referencing_post->post_title,
156
-				'thumbnail' => $thumbnail,
157
-			),
158
-			'entity' => array(
159
-				'id'        => $referencing_post->entity_id,
160
-				'label'     => $serialized_entity['label'],
161
-				'mainType'  => $serialized_entity['mainType'],
162
-				'permalink' => get_permalink( $referencing_post->entity_id ),
163
-			),
164
-		);
165
-
166
-		$results[] = $result;
167
-	}
168
-
169
-
170
-	if ( count( $results ) < $navigator_length ) {
171
-		$results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
172
-	}
173
-
174
-	// Add filler posts if needed
175
-	$filler_count = $navigator_length - count( $results );
176
-	if ( $filler_count > 0 ) {
177
-		$referencing_post_ids = array_map( function ( $p ) {
178
-			return $p->ID;
179
-		}, $referencing_posts );
180
-		/**
181
-		 * @since 3.27.8
182
-		 * Filler posts are fetched using this util.
183
-		 */
184
-		$filler_posts_util    = new Filler_Posts_Util( $current_post_id );
185
-		$post_ids_to_be_excluded = array_merge( array( $current_post_id ), $referencing_post_ids );
186
-		$filler_posts            = $filler_posts_util->get_filler_response( $filler_count, $post_ids_to_be_excluded );
187
-		$results                 = array_merge( $results, $filler_posts );
188
-	}
189
-
190
-	// Apply filters after fillers are added
191
-	foreach ( $results as $result_index => $result ) {
192
-		$results[ $result_index ]['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $result['post']['id'] ), $navigator_id );
193
-		$results[ $result_index ]['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
194
-	}
195
-
196
-	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
+        var_dump($referencing_posts);
134
+    }
135
+
136
+    // loop over them and take the first one which is not already in the $related_posts
137
+    $results = array();
138
+    foreach ( $referencing_posts as $referencing_post ) {
139
+        $serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
140
+
141
+        /**
142
+         * Use the thumbnail.
143
+         *
144
+         * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
145
+         * @see https://github.com/insideout10/wordlift-plugin/issues/837
146
+         *
147
+         * @since 3.19.3 We're using the medium size image.
148
+         */
149
+        $thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
150
+
151
+        $result = array(
152
+            'post'   => array(
153
+                'id'        => $referencing_post->ID,
154
+                'permalink' => get_permalink( $referencing_post->ID ),
155
+                'title'     => $referencing_post->post_title,
156
+                'thumbnail' => $thumbnail,
157
+            ),
158
+            'entity' => array(
159
+                'id'        => $referencing_post->entity_id,
160
+                'label'     => $serialized_entity['label'],
161
+                'mainType'  => $serialized_entity['mainType'],
162
+                'permalink' => get_permalink( $referencing_post->entity_id ),
163
+            ),
164
+        );
165
+
166
+        $results[] = $result;
167
+    }
168
+
169
+
170
+    if ( count( $results ) < $navigator_length ) {
171
+        $results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
172
+    }
173
+
174
+    // Add filler posts if needed
175
+    $filler_count = $navigator_length - count( $results );
176
+    if ( $filler_count > 0 ) {
177
+        $referencing_post_ids = array_map( function ( $p ) {
178
+            return $p->ID;
179
+        }, $referencing_posts );
180
+        /**
181
+         * @since 3.27.8
182
+         * Filler posts are fetched using this util.
183
+         */
184
+        $filler_posts_util    = new Filler_Posts_Util( $current_post_id );
185
+        $post_ids_to_be_excluded = array_merge( array( $current_post_id ), $referencing_post_ids );
186
+        $filler_posts            = $filler_posts_util->get_filler_response( $filler_count, $post_ids_to_be_excluded );
187
+        $results                 = array_merge( $results, $filler_posts );
188
+    }
189
+
190
+    // Apply filters after fillers are added
191
+    foreach ( $results as $result_index => $result ) {
192
+        $results[ $result_index ]['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $result['post']['id'] ), $navigator_id );
193
+        $results[ $result_index ]['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
194
+    }
195
+
196
+    return $results;
197 197
 }
198 198
 
199 199
 function _wl_network_navigator_get_data( $request ) {
200 200
 
201
-	// Limit the results (defaults to 4)
202
-	$navigator_length = isset( $request['limit'] ) ? intval( $request['limit'] ) : 4;
203
-	$navigator_offset = isset( $request['offset'] ) ? intval( $request['offset'] ) : 0;
204
-	$navigator_id     = $request['uniqid'];
205
-	$order_by         = isset( $_GET['sort'] ) ? sanitize_sql_orderby( $_GET['sort'] ) : 'ID DESC';
206
-
207
-	$entities = $request['entities'];
208
-
209
-	// Post ID has to match an existing item
210
-	if ( ! isset( $entities ) || empty( $entities ) ) {
211
-		wp_send_json_error( 'No valid entities provided' );
212
-	}
213
-
214
-	$referencing_posts = _wl_network_navigator_get_results( $entities, array(
215
-		'ID',
216
-		'post_title',
217
-	), $order_by, $navigator_length, $navigator_offset );
218
-
219
-	// loop over them and take the first one which is not already in the $related_posts
220
-	$results = array();
221
-	foreach ( $referencing_posts as $referencing_post ) {
222
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
223
-
224
-		/**
225
-		 * Use the thumbnail.
226
-		 *
227
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
228
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/837
229
-		 *
230
-		 * @since 3.19.3 We're using the medium size image.
231
-		 */
232
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
233
-
234
-		$result = array(
235
-			'post'   => array(
236
-				'permalink' => get_permalink( $referencing_post->ID ),
237
-				'title'     => $referencing_post->post_title,
238
-				'thumbnail' => $thumbnail,
239
-			),
240
-			'entity' => array(
241
-				'label'     => $serialized_entity['label'],
242
-				'mainType'  => $serialized_entity['mainType'],
243
-				'permalink' => get_permalink( $referencing_post->entity_id ),
244
-			),
245
-		);
246
-
247
-		$result['post']   = apply_filters( 'wl_network_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
248
-		$result['entity'] = apply_filters( 'wl_network_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
249
-
250
-		$results[] = $result;
251
-
252
-	}
253
-
254
-	if ( count( $results ) < $navigator_length ) {
255
-		$results = apply_filters( 'wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
256
-	}
257
-
258
-	return $results;
201
+    // Limit the results (defaults to 4)
202
+    $navigator_length = isset( $request['limit'] ) ? intval( $request['limit'] ) : 4;
203
+    $navigator_offset = isset( $request['offset'] ) ? intval( $request['offset'] ) : 0;
204
+    $navigator_id     = $request['uniqid'];
205
+    $order_by         = isset( $_GET['sort'] ) ? sanitize_sql_orderby( $_GET['sort'] ) : 'ID DESC';
206
+
207
+    $entities = $request['entities'];
208
+
209
+    // Post ID has to match an existing item
210
+    if ( ! isset( $entities ) || empty( $entities ) ) {
211
+        wp_send_json_error( 'No valid entities provided' );
212
+    }
213
+
214
+    $referencing_posts = _wl_network_navigator_get_results( $entities, array(
215
+        'ID',
216
+        'post_title',
217
+    ), $order_by, $navigator_length, $navigator_offset );
218
+
219
+    // loop over them and take the first one which is not already in the $related_posts
220
+    $results = array();
221
+    foreach ( $referencing_posts as $referencing_post ) {
222
+        $serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
223
+
224
+        /**
225
+         * Use the thumbnail.
226
+         *
227
+         * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
228
+         * @see https://github.com/insideout10/wordlift-plugin/issues/837
229
+         *
230
+         * @since 3.19.3 We're using the medium size image.
231
+         */
232
+        $thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
233
+
234
+        $result = array(
235
+            'post'   => array(
236
+                'permalink' => get_permalink( $referencing_post->ID ),
237
+                'title'     => $referencing_post->post_title,
238
+                'thumbnail' => $thumbnail,
239
+            ),
240
+            'entity' => array(
241
+                'label'     => $serialized_entity['label'],
242
+                'mainType'  => $serialized_entity['mainType'],
243
+                'permalink' => get_permalink( $referencing_post->entity_id ),
244
+            ),
245
+        );
246
+
247
+        $result['post']   = apply_filters( 'wl_network_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
248
+        $result['entity'] = apply_filters( 'wl_network_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
249
+
250
+        $results[] = $result;
251
+
252
+    }
253
+
254
+    if ( count( $results ) < $navigator_length ) {
255
+        $results = apply_filters( 'wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
256
+    }
257
+
258
+    return $results;
259 259
 
260 260
 }
261 261
 
262 262
 function _wl_network_navigator_get_results(
263
-	$entities, $fields = array(
264
-	'ID',
265
-	'post_title',
263
+    $entities, $fields = array(
264
+    'ID',
265
+    'post_title',
266 266
 ), $order_by = 'ID DESC', $limit = 10, $offset = 0
267 267
 ) {
268
-	global $wpdb;
269
-
270
-	$select = implode( ', ', array_map( function ( $item ) {
271
-		return "p.$item AS $item";
272
-	}, (array) $fields ) );
273
-
274
-	$order_by = implode( ', ', array_map( function ( $item ) {
275
-		return "p.$item";
276
-	}, (array) $order_by ) );
277
-
278
-	$entities_in = implode( ',', array_map( function ( $item ) {
279
-		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( urldecode( $item ) );
280
-		if ( isset( $entity ) ) {
281
-			return $entity->ID;
282
-		}
283
-	}, $entities ) );
284
-
285
-	/** @noinspection SqlNoDataSourceInspection */
286
-	return $wpdb->get_results(
287
-		$wpdb->prepare( <<<EOF
268
+    global $wpdb;
269
+
270
+    $select = implode( ', ', array_map( function ( $item ) {
271
+        return "p.$item AS $item";
272
+    }, (array) $fields ) );
273
+
274
+    $order_by = implode( ', ', array_map( function ( $item ) {
275
+        return "p.$item";
276
+    }, (array) $order_by ) );
277
+
278
+    $entities_in = implode( ',', array_map( function ( $item ) {
279
+        $entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( urldecode( $item ) );
280
+        if ( isset( $entity ) ) {
281
+            return $entity->ID;
282
+        }
283
+    }, $entities ) );
284
+
285
+    /** @noinspection SqlNoDataSourceInspection */
286
+    return $wpdb->get_results(
287
+        $wpdb->prepare( <<<EOF
288 288
 SELECT %3\$s, p2.ID as entity_id
289 289
  FROM {$wpdb->prefix}wl_relation_instances r1
290 290
 	-- get the ID of the post entity in common between the object and the subject 2. 
@@ -310,8 +310,8 @@  discard block
 block discarded – undo
310 310
  LIMIT %1\$d
311 311
  OFFSET %2\$d
312 312
 EOF
313
-			, $limit, $offset, $select, $order_by )
314
-	);
313
+            , $limit, $offset, $select, $order_by )
314
+    );
315 315
 
316 316
 }
317 317
 
@@ -323,9 +323,9 @@  discard block
 block discarded – undo
323 323
  */
324 324
 function wl_shortcode_navigator_ajax() {
325 325
 
326
-	// Temporary blocking the Navigator.
327
-	$results = wl_shortcode_navigator_data();
328
-	wl_core_send_json( $results );
326
+    // Temporary blocking the Navigator.
327
+    $results = wl_shortcode_navigator_data();
328
+    wl_core_send_json( $results );
329 329
 
330 330
 }
331 331
 
@@ -337,16 +337,16 @@  discard block
 block discarded – undo
337 337
  */
338 338
 function wl_shortcode_navigator_wp_json() {
339 339
 
340
-	$results = wl_shortcode_navigator_data();
341
-	if ( ob_get_contents() ) {
342
-		ob_clean();
343
-	}
340
+    $results = wl_shortcode_navigator_data();
341
+    if ( ob_get_contents() ) {
342
+        ob_clean();
343
+    }
344 344
 
345
-	return array(
346
-		'items' => array(
347
-			array( 'values' => $results ),
348
-		),
349
-	);
345
+    return array(
346
+        'items' => array(
347
+            array( 'values' => $results ),
348
+        ),
349
+    );
350 350
 
351 351
 }
352 352
 
@@ -354,22 +354,22 @@  discard block
 block discarded – undo
354 354
  * Adding `rest_api_init` action for amp backend of navigator
355 355
  */
356 356
 add_action( 'rest_api_init', function () {
357
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
358
-		'methods'             => 'GET',
359
-		'permission_callback' => '__return_true',
360
-		'callback'            => 'wl_shortcode_navigator_wp_json'
361
-	) );
357
+    register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
358
+        'methods'             => 'GET',
359
+        'permission_callback' => '__return_true',
360
+        'callback'            => 'wl_shortcode_navigator_wp_json'
361
+    ) );
362 362
 } );
363 363
 
364 364
 /**
365 365
  * Adding `rest_api_init` action for backend of network navigator
366 366
  */
367 367
 add_action( 'rest_api_init', function () {
368
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
369
-		'methods'             => 'GET',
370
-		'callback'            => 'wl_network_navigator_wp_json',
371
-		'permission_callback' => '__return_true',
372
-	) );
368
+    register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
369
+        'methods'             => 'GET',
370
+        'callback'            => 'wl_network_navigator_wp_json',
371
+        'permission_callback' => '__return_true',
372
+    ) );
373 373
 } );
374 374
 
375 375
 /**
@@ -379,22 +379,22 @@  discard block
 block discarded – undo
379 379
  */
380 380
 add_action( 'plugins_loaded', function () {
381 381
 
382
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
383
-		return;
384
-	}
382
+    if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
383
+        return;
384
+    }
385 385
 
386
-	remove_action( 'plugins_loaded', 'rocket_init' );
387
-	remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
388
-	remove_action( 'plugins_loaded', 'wpseo_init', 14 );
386
+    remove_action( 'plugins_loaded', 'rocket_init' );
387
+    remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
388
+    remove_action( 'plugins_loaded', 'wpseo_init', 14 );
389 389
 }, 0 );
390 390
 
391 391
 add_action( 'init', function () {
392 392
 
393
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
394
-		return;
395
-	}
393
+    if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
394
+        return;
395
+    }
396 396
 
397
-	remove_action( 'init', 'wp_widgets_init', 1 );
398
-	remove_action( 'init', 'gglcptch_init' );
397
+    remove_action( 'init', 'wp_widgets_init', 1 );
398
+    remove_action( 'init', 'gglcptch_init' );
399 399
 }, 0 );
400 400
 
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,58 +85,58 @@  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
 		var_dump($referencing_posts);
134 134
 	}
135 135
 
136 136
 	// loop over them and take the first one which is not already in the $related_posts
137 137
 	$results = array();
138
-	foreach ( $referencing_posts as $referencing_post ) {
139
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
138
+	foreach ($referencing_posts as $referencing_post) {
139
+		$serialized_entity = wl_serialize_entity($referencing_post->entity_id);
140 140
 
141 141
 		/**
142 142
 		 * Use the thumbnail.
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
 		 *
147 147
 		 * @since 3.19.3 We're using the medium size image.
148 148
 		 */
149
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
149
+		$thumbnail = get_the_post_thumbnail_url($referencing_post, 'medium');
150 150
 
151 151
 		$result = array(
152 152
 			'post'   => array(
153 153
 				'id'        => $referencing_post->ID,
154
-				'permalink' => get_permalink( $referencing_post->ID ),
154
+				'permalink' => get_permalink($referencing_post->ID),
155 155
 				'title'     => $referencing_post->post_title,
156 156
 				'thumbnail' => $thumbnail,
157 157
 			),
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 				'id'        => $referencing_post->entity_id,
160 160
 				'label'     => $serialized_entity['label'],
161 161
 				'mainType'  => $serialized_entity['mainType'],
162
-				'permalink' => get_permalink( $referencing_post->entity_id ),
162
+				'permalink' => get_permalink($referencing_post->entity_id),
163 163
 			),
164 164
 		);
165 165
 
@@ -167,59 +167,59 @@  discard block
 block discarded – undo
167 167
 	}
168 168
 
169 169
 
170
-	if ( count( $results ) < $navigator_length ) {
171
-		$results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
170
+	if (count($results) < $navigator_length) {
171
+		$results = apply_filters('wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length);
172 172
 	}
173 173
 
174 174
 	// Add filler posts if needed
175
-	$filler_count = $navigator_length - count( $results );
176
-	if ( $filler_count > 0 ) {
177
-		$referencing_post_ids = array_map( function ( $p ) {
175
+	$filler_count = $navigator_length - count($results);
176
+	if ($filler_count > 0) {
177
+		$referencing_post_ids = array_map(function($p) {
178 178
 			return $p->ID;
179
-		}, $referencing_posts );
179
+		}, $referencing_posts);
180 180
 		/**
181 181
 		 * @since 3.27.8
182 182
 		 * Filler posts are fetched using this util.
183 183
 		 */
184
-		$filler_posts_util    = new Filler_Posts_Util( $current_post_id );
185
-		$post_ids_to_be_excluded = array_merge( array( $current_post_id ), $referencing_post_ids );
186
-		$filler_posts            = $filler_posts_util->get_filler_response( $filler_count, $post_ids_to_be_excluded );
187
-		$results                 = array_merge( $results, $filler_posts );
184
+		$filler_posts_util = new Filler_Posts_Util($current_post_id);
185
+		$post_ids_to_be_excluded = array_merge(array($current_post_id), $referencing_post_ids);
186
+		$filler_posts            = $filler_posts_util->get_filler_response($filler_count, $post_ids_to_be_excluded);
187
+		$results                 = array_merge($results, $filler_posts);
188 188
 	}
189 189
 
190 190
 	// Apply filters after fillers are added
191
-	foreach ( $results as $result_index => $result ) {
192
-		$results[ $result_index ]['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $result['post']['id'] ), $navigator_id );
193
-		$results[ $result_index ]['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $result['entity']['id'] ), $navigator_id );
191
+	foreach ($results as $result_index => $result) {
192
+		$results[$result_index]['post']   = apply_filters('wl_navigator_data_post', $result['post'], intval($result['post']['id']), $navigator_id);
193
+		$results[$result_index]['entity'] = apply_filters('wl_navigator_data_entity', $result['entity'], intval($result['entity']['id']), $navigator_id);
194 194
 	}
195 195
 
196 196
 	return $results;
197 197
 }
198 198
 
199
-function _wl_network_navigator_get_data( $request ) {
199
+function _wl_network_navigator_get_data($request) {
200 200
 
201 201
 	// Limit the results (defaults to 4)
202
-	$navigator_length = isset( $request['limit'] ) ? intval( $request['limit'] ) : 4;
203
-	$navigator_offset = isset( $request['offset'] ) ? intval( $request['offset'] ) : 0;
202
+	$navigator_length = isset($request['limit']) ? intval($request['limit']) : 4;
203
+	$navigator_offset = isset($request['offset']) ? intval($request['offset']) : 0;
204 204
 	$navigator_id     = $request['uniqid'];
205
-	$order_by         = isset( $_GET['sort'] ) ? sanitize_sql_orderby( $_GET['sort'] ) : 'ID DESC';
205
+	$order_by         = isset($_GET['sort']) ? sanitize_sql_orderby($_GET['sort']) : 'ID DESC';
206 206
 
207 207
 	$entities = $request['entities'];
208 208
 
209 209
 	// Post ID has to match an existing item
210
-	if ( ! isset( $entities ) || empty( $entities ) ) {
211
-		wp_send_json_error( 'No valid entities provided' );
210
+	if ( ! isset($entities) || empty($entities)) {
211
+		wp_send_json_error('No valid entities provided');
212 212
 	}
213 213
 
214
-	$referencing_posts = _wl_network_navigator_get_results( $entities, array(
214
+	$referencing_posts = _wl_network_navigator_get_results($entities, array(
215 215
 		'ID',
216 216
 		'post_title',
217
-	), $order_by, $navigator_length, $navigator_offset );
217
+	), $order_by, $navigator_length, $navigator_offset);
218 218
 
219 219
 	// loop over them and take the first one which is not already in the $related_posts
220 220
 	$results = array();
221
-	foreach ( $referencing_posts as $referencing_post ) {
222
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
221
+	foreach ($referencing_posts as $referencing_post) {
222
+		$serialized_entity = wl_serialize_entity($referencing_post->entity_id);
223 223
 
224 224
 		/**
225 225
 		 * Use the thumbnail.
@@ -229,30 +229,30 @@  discard block
 block discarded – undo
229 229
 		 *
230 230
 		 * @since 3.19.3 We're using the medium size image.
231 231
 		 */
232
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
232
+		$thumbnail = get_the_post_thumbnail_url($referencing_post, 'medium');
233 233
 
234 234
 		$result = array(
235 235
 			'post'   => array(
236
-				'permalink' => get_permalink( $referencing_post->ID ),
236
+				'permalink' => get_permalink($referencing_post->ID),
237 237
 				'title'     => $referencing_post->post_title,
238 238
 				'thumbnail' => $thumbnail,
239 239
 			),
240 240
 			'entity' => array(
241 241
 				'label'     => $serialized_entity['label'],
242 242
 				'mainType'  => $serialized_entity['mainType'],
243
-				'permalink' => get_permalink( $referencing_post->entity_id ),
243
+				'permalink' => get_permalink($referencing_post->entity_id),
244 244
 			),
245 245
 		);
246 246
 
247
-		$result['post']   = apply_filters( 'wl_network_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
248
-		$result['entity'] = apply_filters( 'wl_network_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
247
+		$result['post']   = apply_filters('wl_network_navigator_data_post', $result['post'], intval($referencing_post->ID), $navigator_id);
248
+		$result['entity'] = apply_filters('wl_network_navigator_data_entity', $result['entity'], intval($referencing_post->entity_id), $navigator_id);
249 249
 
250 250
 		$results[] = $result;
251 251
 
252 252
 	}
253 253
 
254
-	if ( count( $results ) < $navigator_length ) {
255
-		$results = apply_filters( 'wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
254
+	if (count($results) < $navigator_length) {
255
+		$results = apply_filters('wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length);
256 256
 	}
257 257
 
258 258
 	return $results;
@@ -267,24 +267,24 @@  discard block
 block discarded – undo
267 267
 ) {
268 268
 	global $wpdb;
269 269
 
270
-	$select = implode( ', ', array_map( function ( $item ) {
270
+	$select = implode(', ', array_map(function($item) {
271 271
 		return "p.$item AS $item";
272
-	}, (array) $fields ) );
272
+	}, (array) $fields));
273 273
 
274
-	$order_by = implode( ', ', array_map( function ( $item ) {
274
+	$order_by = implode(', ', array_map(function($item) {
275 275
 		return "p.$item";
276
-	}, (array) $order_by ) );
276
+	}, (array) $order_by));
277 277
 
278
-	$entities_in = implode( ',', array_map( function ( $item ) {
279
-		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( urldecode( $item ) );
280
-		if ( isset( $entity ) ) {
278
+	$entities_in = implode(',', array_map(function($item) {
279
+		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri(urldecode($item));
280
+		if (isset($entity)) {
281 281
 			return $entity->ID;
282 282
 		}
283
-	}, $entities ) );
283
+	}, $entities));
284 284
 
285 285
 	/** @noinspection SqlNoDataSourceInspection */
286 286
 	return $wpdb->get_results(
287
-		$wpdb->prepare( <<<EOF
287
+		$wpdb->prepare(<<<EOF
288 288
 SELECT %3\$s, p2.ID as entity_id
289 289
  FROM {$wpdb->prefix}wl_relation_instances r1
290 290
 	-- get the ID of the post entity in common between the object and the subject 2. 
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
  LIMIT %1\$d
311 311
  OFFSET %2\$d
312 312
 EOF
313
-			, $limit, $offset, $select, $order_by )
313
+			, $limit, $offset, $select, $order_by)
314 314
 	);
315 315
 
316 316
 }
@@ -325,12 +325,12 @@  discard block
 block discarded – undo
325 325
 
326 326
 	// Temporary blocking the Navigator.
327 327
 	$results = wl_shortcode_navigator_data();
328
-	wl_core_send_json( $results );
328
+	wl_core_send_json($results);
329 329
 
330 330
 }
331 331
 
332
-add_action( 'wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax' );
333
-add_action( 'wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax' );
332
+add_action('wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax');
333
+add_action('wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax');
334 334
 
335 335
 /**
336 336
  * wp-json call for the navigator widget
@@ -338,13 +338,13 @@  discard block
 block discarded – undo
338 338
 function wl_shortcode_navigator_wp_json() {
339 339
 
340 340
 	$results = wl_shortcode_navigator_data();
341
-	if ( ob_get_contents() ) {
341
+	if (ob_get_contents()) {
342 342
 		ob_clean();
343 343
 	}
344 344
 
345 345
 	return array(
346 346
 		'items' => array(
347
-			array( 'values' => $results ),
347
+			array('values' => $results),
348 348
 		),
349 349
 	);
350 350
 
@@ -353,23 +353,23 @@  discard block
 block discarded – undo
353 353
 /**
354 354
  * Adding `rest_api_init` action for amp backend of navigator
355 355
  */
356
-add_action( 'rest_api_init', function () {
357
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
356
+add_action('rest_api_init', function() {
357
+	register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
358 358
 		'methods'             => 'GET',
359 359
 		'permission_callback' => '__return_true',
360 360
 		'callback'            => 'wl_shortcode_navigator_wp_json'
361
-	) );
361
+	));
362 362
 } );
363 363
 
364 364
 /**
365 365
  * Adding `rest_api_init` action for backend of network navigator
366 366
  */
367
-add_action( 'rest_api_init', function () {
368
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
367
+add_action('rest_api_init', function() {
368
+	register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
369 369
 		'methods'             => 'GET',
370 370
 		'callback'            => 'wl_network_navigator_wp_json',
371 371
 		'permission_callback' => '__return_true',
372
-	) );
372
+	));
373 373
 } );
374 374
 
375 375
 /**
@@ -377,24 +377,24 @@  discard block
 block discarded – undo
377 377
  *
378 378
  * @since 2.2.0
379 379
  */
380
-add_action( 'plugins_loaded', function () {
380
+add_action('plugins_loaded', function() {
381 381
 
382
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
382
+	if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action']) {
383 383
 		return;
384 384
 	}
385 385
 
386
-	remove_action( 'plugins_loaded', 'rocket_init' );
387
-	remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
388
-	remove_action( 'plugins_loaded', 'wpseo_init', 14 );
389
-}, 0 );
386
+	remove_action('plugins_loaded', 'rocket_init');
387
+	remove_action('plugins_loaded', 'wpseo_premium_init', 14);
388
+	remove_action('plugins_loaded', 'wpseo_init', 14);
389
+}, 0);
390 390
 
391
-add_action( 'init', function () {
391
+add_action('init', function() {
392 392
 
393
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
393
+	if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action']) {
394 394
 		return;
395 395
 	}
396 396
 
397
-	remove_action( 'init', 'wp_widgets_init', 1 );
398
-	remove_action( 'init', 'gglcptch_init' );
399
-}, 0 );
397
+	remove_action('init', 'wp_widgets_init', 1);
398
+	remove_action('init', 'gglcptch_init');
399
+}, 0);
400 400
 
Please login to merge, or discard this patch.