Completed
Push — develop ( 9df7e0...060b1d )
by David
03:17 queued 22s
created
src/wordlift.php 2 patches
Indentation   +253 added lines, -253 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
 // If this file is called directly, abort.
28 28
 if ( ! defined( 'WPINC' ) ) {
29
-	die;
29
+    die;
30 30
 }
31 31
 
32 32
 // Include WordLift constants.
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
  */
48 48
 function wl_write_log( $log ) {
49 49
 
50
-	$handler = apply_filters( 'wl_write_log_handler', NULL );
50
+    $handler = apply_filters( 'wl_write_log_handler', NULL );
51 51
 
52
-	$callers         = debug_backtrace();
53
-	$caller_function = $callers[1]['function'];
52
+    $callers         = debug_backtrace();
53
+    $caller_function = $callers[1]['function'];
54 54
 
55
-	if ( is_null( $handler ) ) {
56
-		wl_write_log_handler( $log, $caller_function );
55
+    if ( is_null( $handler ) ) {
56
+        wl_write_log_handler( $log, $caller_function );
57 57
 
58
-		return;
59
-	}
58
+        return;
59
+    }
60 60
 
61
-	call_user_func( $handler, $log, $caller_function );
61
+    call_user_func( $handler, $log, $caller_function );
62 62
 }
63 63
 
64 64
 /**
@@ -71,20 +71,20 @@  discard block
 block discarded – undo
71 71
  */
72 72
 function wl_write_log_handler( $log, $caller = NULL ) {
73 73
 
74
-	global $wl_logger;
74
+    global $wl_logger;
75 75
 
76
-	if ( TRUE === WP_DEBUG ) {
76
+    if ( TRUE === WP_DEBUG ) {
77 77
 
78
-		$message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
79
-		           ( is_array( $log ) || is_object( $log ) ? print_r( $log, TRUE ) : wl_write_log_hide_key( $log ) );
78
+        $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
79
+                    ( is_array( $log ) || is_object( $log ) ? print_r( $log, TRUE ) : wl_write_log_hide_key( $log ) );
80 80
 
81
-		if ( isset( $wl_logger ) ) {
82
-			$wl_logger->info( $message );
83
-		} else {
84
-			error_log( $message );
85
-		}
81
+        if ( isset( $wl_logger ) ) {
82
+            $wl_logger->info( $message );
83
+        } else {
84
+            error_log( $message );
85
+        }
86 86
 
87
-	}
87
+    }
88 88
 
89 89
 }
90 90
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
  */
100 100
 function wl_write_log_hide_key( $text ) {
101 101
 
102
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
102
+    return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
103 103
 }
104 104
 
105 105
 /**
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
  */
112 112
 function wl_queue_sparql_update_query( $query ) {
113 113
 
114
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
115
-	file_put_contents( $filename, $query . "\n", FILE_APPEND );
114
+    $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
115
+    file_put_contents( $filename, $query . "\n", FILE_APPEND );
116 116
 
117
-	wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" );
117
+    wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" );
118 118
 }
119 119
 
120 120
 /**
@@ -124,28 +124,28 @@  discard block
 block discarded – undo
124 124
  */
125 125
 function wl_execute_saved_sparql_update_query( $request_id ) {
126 126
 
127
-	$filename = WL_TEMP_DIR . $request_id . '.sparql';
127
+    $filename = WL_TEMP_DIR . $request_id . '.sparql';
128 128
 
129
-	// If the file doesn't exist, exit.
130
-	if ( ! file_exists( $filename ) ) {
131
-		wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" );
129
+    // If the file doesn't exist, exit.
130
+    if ( ! file_exists( $filename ) ) {
131
+        wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" );
132 132
 
133
-		return;
134
-	}
133
+        return;
134
+    }
135 135
 
136
-	wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" );
136
+    wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" );
137 137
 
138
-	// Get the query saved in the file.
139
-	$query = file_get_contents( $filename );
138
+    // Get the query saved in the file.
139
+    $query = file_get_contents( $filename );
140 140
 
141
-	// Execute the SPARQL query.
142
-	rl_execute_sparql_update_query( $query, FALSE );
141
+    // Execute the SPARQL query.
142
+    rl_execute_sparql_update_query( $query, FALSE );
143 143
 
144
-	// Reindex the triple store.
145
-	wordlift_reindex_triple_store();
144
+    // Reindex the triple store.
145
+    wordlift_reindex_triple_store();
146 146
 
147
-	// Delete the temporary file.
148
-	unlink( $filename );
147
+    // Delete the temporary file.
148
+    unlink( $filename );
149 149
 }
150 150
 
151 151
 add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 );
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
  */
156 156
 function wordlift_buttonhooks() {
157 157
 
158
-	// Only add hooks when the current user has permissions AND is in Rich Text editor mode
159
-	if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
160
-		add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' );
161
-	}
158
+    // Only add hooks when the current user has permissions AND is in Rich Text editor mode
159
+    if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
160
+        add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' );
161
+    }
162 162
 }
163 163
 
164 164
 /**
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
  */
171 171
 function wordlift_register_tinymce_javascript( $plugin_array ) {
172 172
 
173
-	// add the wordlift plugin.
174
-	$plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
173
+    // add the wordlift plugin.
174
+    $plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
175 175
 
176
-	return $plugin_array;
176
+    return $plugin_array;
177 177
 }
178 178
 
179 179
 /**
@@ -181,21 +181,21 @@  discard block
 block discarded – undo
181 181
  * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
182 182
  */
183 183
 function wordlift_allowed_post_tags() {
184
-	global $allowedposttags;
185
-
186
-	$tags           = array( 'span' );
187
-	$new_attributes = array(
188
-		'itemscope' => array(),
189
-		'itemtype'  => array(),
190
-		'itemprop'  => array(),
191
-		'itemid'    => array()
192
-	);
193
-
194
-	foreach ( $tags as $tag ) {
195
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
196
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
197
-		}
198
-	}
184
+    global $allowedposttags;
185
+
186
+    $tags           = array( 'span' );
187
+    $new_attributes = array(
188
+        'itemscope' => array(),
189
+        'itemtype'  => array(),
190
+        'itemprop'  => array(),
191
+        'itemid'    => array()
192
+    );
193
+
194
+    foreach ( $tags as $tag ) {
195
+        if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
196
+            $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
197
+        }
198
+    }
199 199
 }
200 200
 
201 201
 // init process for button control
@@ -209,28 +209,28 @@  discard block
 block discarded – undo
209 209
  */
210 210
 function wordlift_admin_enqueue_scripts() {
211 211
 
212
-	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
213
-	wp_enqueue_script( 'wpdialogs' );
214
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
212
+    // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
213
+    wp_enqueue_script( 'wpdialogs' );
214
+    wp_enqueue_style( 'wp-jquery-ui-dialog' );
215 215
 
216
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
216
+    wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
217 217
 
218
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
219
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
220
-	wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . '/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' );
221
-	wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
222
-	wp_enqueue_script( 'angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js' );
218
+    wp_enqueue_script( 'jquery-ui-autocomplete' );
219
+    wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
220
+    wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . '/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' );
221
+    wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
222
+    wp_enqueue_script( 'angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js' );
223 223
 
224
-	// Disable auto-save for custom entity posts only
225
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
226
-		wp_dequeue_script( 'autosave' );
227
-	}
224
+    // Disable auto-save for custom entity posts only
225
+    if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
226
+        wp_dequeue_script( 'autosave' );
227
+    }
228 228
 }
229 229
 
230 230
 add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
231 231
 
232 232
 function wl_enqueue_scripts() {
233
-	wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
233
+    wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
234 234
 }
235 235
 
236 236
 add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' );
@@ -245,18 +245,18 @@  discard block
 block discarded – undo
245 245
  */
246 246
 function wordlift_allowed_html( $allowedtags, $context ) {
247 247
 
248
-	if ( 'post' !== $context ) {
249
-		return $allowedtags;
250
-	}
251
-
252
-	return array_merge_recursive( $allowedtags, array(
253
-		'span' => array(
254
-			'itemscope' => TRUE,
255
-			'itemtype'  => TRUE,
256
-			'itemid'    => TRUE,
257
-			'itemprop'  => TRUE
258
-		)
259
-	) );
248
+    if ( 'post' !== $context ) {
249
+        return $allowedtags;
250
+    }
251
+
252
+    return array_merge_recursive( $allowedtags, array(
253
+        'span' => array(
254
+            'itemscope' => TRUE,
255
+            'itemtype'  => TRUE,
256
+            'itemid'    => TRUE,
257
+            'itemprop'  => TRUE
258
+        )
259
+    ) );
260 260
 }
261 261
 
262 262
 add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
@@ -270,15 +270,15 @@  discard block
 block discarded – undo
270 270
  */
271 271
 function wl_get_coordinates( $post_id ) {
272 272
 
273
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
274
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
273
+    $latitude  = wl_schema_get_value( $post_id, 'latitude' );
274
+    $longitude = wl_schema_get_value( $post_id, 'longitude' );
275 275
 
276
-	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
277
-	// "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
278
-	return array(
279
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
280
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : ''
281
-	);
276
+    // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
277
+    // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
278
+    return array(
279
+        'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
280
+        'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : ''
281
+    );
282 282
 }
283 283
 
284 284
 /**
@@ -290,13 +290,13 @@  discard block
 block discarded – undo
290 290
  */
291 291
 function wl_get_post_modified_time( $post ) {
292 292
 
293
-	$date_modified = get_post_modified_time( 'c', TRUE, $post );
293
+    $date_modified = get_post_modified_time( 'c', TRUE, $post );
294 294
 
295
-	if ( '-' === substr( $date_modified, 0, 1 ) ) {
296
-		return get_the_time( 'c', $post );
297
-	}
295
+    if ( '-' === substr( $date_modified, 0, 1 ) ) {
296
+        return get_the_time( 'c', $post );
297
+    }
298 298
 
299
-	return $date_modified;
299
+    return $date_modified;
300 300
 }
301 301
 
302 302
 /**
@@ -309,42 +309,42 @@  discard block
 block discarded – undo
309 309
 function wl_get_image_urls( $post_id ) {
310 310
 
311 311
 
312
-	// If there is a featured image it has the priority
313
-	$featured_image_id = get_post_thumbnail_id( $post_id );
314
-	if ( is_numeric( $featured_image_id ) ) {
315
-		$image_url = wp_get_attachment_url( $featured_image_id );
312
+    // If there is a featured image it has the priority
313
+    $featured_image_id = get_post_thumbnail_id( $post_id );
314
+    if ( is_numeric( $featured_image_id ) ) {
315
+        $image_url = wp_get_attachment_url( $featured_image_id );
316 316
 
317
-		return array( $image_url );
318
-	}
317
+        return array( $image_url );
318
+    }
319 319
 
320
-	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
320
+    // wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
321 321
 
322
-	$images = get_children( array(
323
-		'post_parent'    => $post_id,
324
-		'post_type'      => 'attachment',
325
-		'post_mime_type' => 'image'
326
-	) );
322
+    $images = get_children( array(
323
+        'post_parent'    => $post_id,
324
+        'post_type'      => 'attachment',
325
+        'post_mime_type' => 'image'
326
+    ) );
327 327
 
328
-	// Return an empty array if no image is found.
329
-	if ( empty( $images ) ) {
330
-		return array();
331
-	}
328
+    // Return an empty array if no image is found.
329
+    if ( empty( $images ) ) {
330
+        return array();
331
+    }
332 332
 
333
-	// Prepare the return array.
334
-	$image_urls = array();
333
+    // Prepare the return array.
334
+    $image_urls = array();
335 335
 
336
-	// Collect the URLs.
337
-	foreach ( $images as $attachment_id => $attachment ) {
338
-		$image_url = wp_get_attachment_url( $attachment_id );
339
-		// Ensure the URL isn't collected already.
340
-		if ( ! in_array( $image_url, $image_urls ) ) {
341
-			array_push( $image_urls, $image_url );
342
-		}
343
-	}
336
+    // Collect the URLs.
337
+    foreach ( $images as $attachment_id => $attachment ) {
338
+        $image_url = wp_get_attachment_url( $attachment_id );
339
+        // Ensure the URL isn't collected already.
340
+        if ( ! in_array( $image_url, $image_urls ) ) {
341
+            array_push( $image_urls, $image_url );
342
+        }
343
+    }
344 344
 
345
-	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" );
345
+    // wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" );
346 346
 
347
-	return $image_urls;
347
+    return $image_urls;
348 348
 }
349 349
 
350 350
 /**
@@ -357,19 +357,19 @@  discard block
 block discarded – undo
357 357
  */
358 358
 function wl_get_sparql_images( $uri, $post_id ) {
359 359
 
360
-	$sparql = '';
360
+    $sparql = '';
361 361
 
362
-	// Get the escaped URI.
363
-	$uri_e = esc_html( $uri );
362
+    // Get the escaped URI.
363
+    $uri_e = esc_html( $uri );
364 364
 
365
-	// Add SPARQL stmts to write the schema:image.
366
-	$image_urls = wl_get_image_urls( $post_id );
367
-	foreach ( $image_urls as $image_url ) {
368
-		$image_url_esc = wl_sparql_escape_uri( $image_url );
369
-		$sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
370
-	}
365
+    // Add SPARQL stmts to write the schema:image.
366
+    $image_urls = wl_get_image_urls( $post_id );
367
+    foreach ( $image_urls as $image_url ) {
368
+        $image_url_esc = wl_sparql_escape_uri( $image_url );
369
+        $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
370
+    }
371 371
 
372
-	return $sparql;
372
+    return $sparql;
373 373
 }
374 374
 
375 375
 /**
@@ -382,24 +382,24 @@  discard block
 block discarded – undo
382 382
  */
383 383
 function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
384 384
 
385
-	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
385
+    // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
386 386
 
387
-	$posts = get_posts( array(
388
-		'post_type'      => 'attachment',
389
-		'posts_per_page' => 1,
390
-		'post_status'    => 'any',
391
-		'post_parent'    => $parent_post_id,
392
-		'meta_key'       => 'wl_source_url',
393
-		'meta_value'     => $source_url
394
-	) );
387
+    $posts = get_posts( array(
388
+        'post_type'      => 'attachment',
389
+        'posts_per_page' => 1,
390
+        'post_status'    => 'any',
391
+        'post_parent'    => $parent_post_id,
392
+        'meta_key'       => 'wl_source_url',
393
+        'meta_value'     => $source_url
394
+    ) );
395 395
 
396
-	// Return the found post.
397
-	if ( 1 === count( $posts ) ) {
398
-		return $posts[0];
399
-	}
396
+    // Return the found post.
397
+    if ( 1 === count( $posts ) ) {
398
+        return $posts[0];
399
+    }
400 400
 
401
-	// Return null.
402
-	return NULL;
401
+    // Return null.
402
+    return NULL;
403 403
 }
404 404
 
405 405
 /**
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
  */
411 411
 function wl_set_source_url( $post_id, $source_url ) {
412 412
 
413
-	delete_post_meta( $post_id, 'wl_source_url' );
414
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
413
+    delete_post_meta( $post_id, 'wl_source_url' );
414
+    add_post_meta( $post_id, 'wl_source_url', $source_url );
415 415
 }
416 416
 
417 417
 
@@ -429,59 +429,59 @@  discard block
 block discarded – undo
429 429
  */
430 430
 function wl_flush_rewrite_rules_hard( $hard ) {
431 431
 
432
-	// If WL is not yet configured, we cannot perform any update, so we exit.
433
-	if ( '' === wl_configuration_get_key() ) {
434
-		return;
435
-	}
432
+    // If WL is not yet configured, we cannot perform any update, so we exit.
433
+    if ( '' === wl_configuration_get_key() ) {
434
+        return;
435
+    }
436 436
 
437
-	// Set the initial offset and limit each call to 100 posts to avoid memory errors.
438
-	$offset = 0;
439
-	$limit  = 100;
437
+    // Set the initial offset and limit each call to 100 posts to avoid memory errors.
438
+    $offset = 0;
439
+    $limit  = 100;
440 440
 
441
-	// Get more posts if the number of returned posts matches the limit.
442
-	while ( $limit === ( $posts = get_posts( array(
443
-			'offset'      => $offset,
444
-			'numberposts' => $limit,
445
-			'orderby'     => 'ID',
446
-			'post_type'   => 'any',
447
-			'post_status' => 'publish'
448
-		) ) ) ) {
441
+    // Get more posts if the number of returned posts matches the limit.
442
+    while ( $limit === ( $posts = get_posts( array(
443
+            'offset'      => $offset,
444
+            'numberposts' => $limit,
445
+            'orderby'     => 'ID',
446
+            'post_type'   => 'any',
447
+            'post_status' => 'publish'
448
+        ) ) ) ) {
449 449
 
450
-		// Holds the delete part of the query.
451
-		$delete_query = rl_sparql_prefixes();
450
+        // Holds the delete part of the query.
451
+        $delete_query = rl_sparql_prefixes();
452 452
 
453
-		// Holds the insert part of the query.
454
-		$insert_query = 'INSERT DATA { ';
453
+        // Holds the insert part of the query.
454
+        $insert_query = 'INSERT DATA { ';
455 455
 
456
-		// Cycle in each post to build the query.
457
-		foreach ( $posts as $post ) {
456
+        // Cycle in each post to build the query.
457
+        foreach ( $posts as $post ) {
458 458
 
459
-			// Ignore revisions.
460
-			if ( wp_is_post_revision( $post->ID ) ) {
461
-				continue;
462
-			}
459
+            // Ignore revisions.
460
+            if ( wp_is_post_revision( $post->ID ) ) {
461
+                continue;
462
+            }
463 463
 
464
-			// Get the entity URI.
465
-			$uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
464
+            // Get the entity URI.
465
+            $uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
466 466
 
467
-			// Get the post URL.
468
-			$url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
467
+            // Get the post URL.
468
+            $url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
469 469
 
470
-			// Prepare the DELETE and INSERT commands.
471
-			$delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE  { <$uri> schema:url ?u . };\n";
472
-			$insert_query .= " <$uri> schema:url <$url> . \n";
470
+            // Prepare the DELETE and INSERT commands.
471
+            $delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE  { <$uri> schema:url ?u . };\n";
472
+            $insert_query .= " <$uri> schema:url <$url> . \n";
473 473
 
474
-		}
474
+        }
475 475
 
476
-		$insert_query .= ' };';
476
+        $insert_query .= ' };';
477 477
 
478
-		// Execute the query.
479
-		rl_execute_sparql_update_query( $delete_query . $insert_query );
478
+        // Execute the query.
479
+        rl_execute_sparql_update_query( $delete_query . $insert_query );
480 480
 
481
-		// Advance to the next posts.
482
-		$offset += $limit;
481
+        // Advance to the next posts.
482
+        $offset += $limit;
483 483
 
484
-	}
484
+    }
485 485
 
486 486
 //	// Get all published posts.
487 487
 //	$posts = get_posts( array(
@@ -506,15 +506,15 @@  discard block
 block discarded – undo
506 506
  */
507 507
 function wl_sanitize_uri_path( $path, $char = '_' ) {
508 508
 
509
-	// wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" );
509
+    // wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" );
510 510
 
511
-	// According to RFC2396 (http://www.ietf.org/rfc/rfc2396.txt) these characters are reserved:
512
-	// ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
513
-	// "$" | ","
514
-	// Plus the ' ' (space).
515
-	// TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex)
511
+    // According to RFC2396 (http://www.ietf.org/rfc/rfc2396.txt) these characters are reserved:
512
+    // ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
513
+    // "$" | ","
514
+    // Plus the ' ' (space).
515
+    // TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex)
516 516
 
517
-	return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) );
517
+    return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) );
518 518
 }
519 519
 
520 520
 /**
@@ -526,11 +526,11 @@  discard block
 block discarded – undo
526 526
  */
527 527
 function wl_force_to_array( $value ) {
528 528
 
529
-	if ( ! is_array( $value ) ) {
530
-		return array( $value );
531
-	}
529
+    if ( ! is_array( $value ) ) {
530
+        return array( $value );
531
+    }
532 532
 
533
-	return $value;
533
+    return $value;
534 534
 }
535 535
 
536 536
 /**
@@ -538,26 +538,26 @@  discard block
 block discarded – undo
538 538
  */
539 539
 function wl_shutdown() {
540 540
 
541
-	// Get the filename to the temporary SPARQL file.
542
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
541
+    // Get the filename to the temporary SPARQL file.
542
+    $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
543 543
 
544
-	// If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
545
-	if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
544
+    // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
545
+    if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
546 546
 
547
-		// The request ID.
548
-		$args = array( WL_REQUEST_ID );
547
+        // The request ID.
548
+        $args = array( WL_REQUEST_ID );
549 549
 
550
-		// Schedule the execution of the SPARQL query with the request ID.
551
-		wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
550
+        // Schedule the execution of the SPARQL query with the request ID.
551
+        wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
552 552
 
553
-		// Check that the request is scheduled.
554
-		$timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
553
+        // Check that the request is scheduled.
554
+        $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
555 555
 
556
-		// Spawn the cron.
557
-		spawn_cron();
556
+        // Spawn the cron.
557
+        spawn_cron();
558 558
 
559
-		wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
560
-	}
559
+        wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
560
+    }
561 561
 }
562 562
 
563 563
 add_action( 'shutdown', 'wl_shutdown' );
@@ -571,46 +571,46 @@  discard block
 block discarded – undo
571 571
  */
572 572
 function wl_replace_item_id_with_uri( $content ) {
573 573
 
574
-	// wl_write_log( "wl_replace_item_id_with_uri" );
574
+    // wl_write_log( "wl_replace_item_id_with_uri" );
575 575
 
576
-	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
577
-	$content = stripslashes( $content );
576
+    // Strip slashes, see https://core.trac.wordpress.org/ticket/21767
577
+    $content = stripslashes( $content );
578 578
 
579
-	// If any match are found.
580
-	$matches = array();
581
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
579
+    // If any match are found.
580
+    $matches = array();
581
+    if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
582 582
 
583
-		foreach ( $matches as $match ) {
583
+        foreach ( $matches as $match ) {
584 584
 
585
-			// Get the item ID.
586
-			$item_id = $match[1];
585
+            // Get the item ID.
586
+            $item_id = $match[1];
587 587
 
588
-			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
589
-			$post = Wordlift_Entity_Service::get_instance()
590
-			                               ->get_entity_post_by_uri( $item_id );
588
+            // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
589
+            $post = Wordlift_Entity_Service::get_instance()
590
+                                            ->get_entity_post_by_uri( $item_id );
591 591
 
592
-			// If no entity is found, continue to the next one.
593
-			if ( NULL === $post ) {
594
-				continue;
595
-			}
592
+            // If no entity is found, continue to the next one.
593
+            if ( NULL === $post ) {
594
+                continue;
595
+            }
596 596
 
597
-			// Get the URI for that post.
598
-			$uri = wl_get_entity_uri( $post->ID );
597
+            // Get the URI for that post.
598
+            $uri = wl_get_entity_uri( $post->ID );
599 599
 
600
-			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
600
+            // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
601 601
 
602
-			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
603
-			if ( $item_id !== $uri ) {
604
-				$uri_e   = esc_html( $uri );
605
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
606
-			}
607
-		}
608
-	}
602
+            // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
603
+            if ( $item_id !== $uri ) {
604
+                $uri_e   = esc_html( $uri );
605
+                $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
606
+            }
607
+        }
608
+    }
609 609
 
610
-	// Reapply slashes.
611
-	$content = addslashes( $content );
610
+    // Reapply slashes.
611
+    $content = addslashes( $content );
612 612
 
613
-	return $content;
613
+    return $content;
614 614
 }
615 615
 
616 616
 add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
@@ -688,8 +688,8 @@  discard block
 block discarded – undo
688 688
  * This action is documented in includes/class-wordlift-activator.php
689 689
  */
690 690
 function activate_wordlift() {
691
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
692
-	Wordlift_Activator::activate();
691
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
692
+    Wordlift_Activator::activate();
693 693
 }
694 694
 
695 695
 /**
@@ -697,8 +697,8 @@  discard block
 block discarded – undo
697 697
  * This action is documented in includes/class-wordlift-deactivator.php
698 698
  */
699 699
 function deactivate_wordlift() {
700
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
701
-	Wordlift_Deactivator::deactivate();
700
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
701
+    Wordlift_Deactivator::deactivate();
702 702
 }
703 703
 
704 704
 register_activation_hook( __FILE__, 'activate_wordlift' );
@@ -721,8 +721,8 @@  discard block
 block discarded – undo
721 721
  */
722 722
 function run_wordlift() {
723 723
 
724
-	$plugin = new Wordlift();
725
-	$plugin->run();
724
+    $plugin = new Wordlift();
725
+    $plugin->run();
726 726
 
727 727
 }
728 728
 
Please login to merge, or discard this patch.
Spacing   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -25,16 +25,16 @@  discard block
 block discarded – undo
25 25
  */
26 26
 
27 27
 // If this file is called directly, abort.
28
-if ( ! defined( 'WPINC' ) ) {
28
+if ( ! defined('WPINC')) {
29 29
 	die;
30 30
 }
31 31
 
32 32
 // Include WordLift constants.
33
-require_once( 'wordlift_constants.php' );
33
+require_once('wordlift_constants.php');
34 34
 
35 35
 // Load modules
36
-require_once( 'modules/core/wordlift_core.php' );
37
-require_once( 'modules/configuration/wordlift_configuration.php' );
36
+require_once('modules/core/wordlift_core.php');
37
+require_once('modules/configuration/wordlift_configuration.php');
38 38
 
39 39
 /**
40 40
  * Log to the debug.log file.
@@ -45,20 +45,20 @@  discard block
 block discarded – undo
45 45
  *
46 46
  * @param string|mixed $log The log data.
47 47
  */
48
-function wl_write_log( $log ) {
48
+function wl_write_log($log) {
49 49
 
50
-	$handler = apply_filters( 'wl_write_log_handler', NULL );
50
+	$handler = apply_filters('wl_write_log_handler', NULL);
51 51
 
52 52
 	$callers         = debug_backtrace();
53 53
 	$caller_function = $callers[1]['function'];
54 54
 
55
-	if ( is_null( $handler ) ) {
56
-		wl_write_log_handler( $log, $caller_function );
55
+	if (is_null($handler)) {
56
+		wl_write_log_handler($log, $caller_function);
57 57
 
58 58
 		return;
59 59
 	}
60 60
 
61
-	call_user_func( $handler, $log, $caller_function );
61
+	call_user_func($handler, $log, $caller_function);
62 62
 }
63 63
 
64 64
 /**
@@ -69,19 +69,19 @@  discard block
 block discarded – undo
69 69
  * @param string|array $log The log data.
70 70
  * @param string $caller The calling function.
71 71
  */
72
-function wl_write_log_handler( $log, $caller = NULL ) {
72
+function wl_write_log_handler($log, $caller = NULL) {
73 73
 
74 74
 	global $wl_logger;
75 75
 
76
-	if ( TRUE === WP_DEBUG ) {
76
+	if (TRUE === WP_DEBUG) {
77 77
 
78
-		$message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
79
-		           ( is_array( $log ) || is_object( $log ) ? print_r( $log, TRUE ) : wl_write_log_hide_key( $log ) );
78
+		$message = (isset($caller) ? sprintf('[%-40.40s] ', $caller) : '').
79
+		           (is_array($log) || is_object($log) ? print_r($log, TRUE) : wl_write_log_hide_key($log));
80 80
 
81
-		if ( isset( $wl_logger ) ) {
82
-			$wl_logger->info( $message );
81
+		if (isset($wl_logger)) {
82
+			$wl_logger->info($message);
83 83
 		} else {
84
-			error_log( $message );
84
+			error_log($message);
85 85
 		}
86 86
 
87 87
 	}
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
  *
98 98
  * @return string A text with the key hidden.
99 99
  */
100
-function wl_write_log_hide_key( $text ) {
100
+function wl_write_log_hide_key($text) {
101 101
 
102
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
102
+	return str_ireplace(wl_configuration_get_key(), '<hidden>', $text);
103 103
 }
104 104
 
105 105
 /**
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
  *
110 110
  * @param string $query A SPARQL query.
111 111
  */
112
-function wl_queue_sparql_update_query( $query ) {
112
+function wl_queue_sparql_update_query($query) {
113 113
 
114
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
115
-	file_put_contents( $filename, $query . "\n", FILE_APPEND );
114
+	$filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql';
115
+	file_put_contents($filename, $query."\n", FILE_APPEND);
116 116
 
117
-	wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" );
117
+	wl_write_log("wl_queue_sparql_update_query [ filename :: $filename ]");
118 118
 }
119 119
 
120 120
 /**
@@ -122,33 +122,33 @@  discard block
 block discarded – undo
122 122
  *
123 123
  * @param int $request_id The request ID.
124 124
  */
125
-function wl_execute_saved_sparql_update_query( $request_id ) {
125
+function wl_execute_saved_sparql_update_query($request_id) {
126 126
 
127
-	$filename = WL_TEMP_DIR . $request_id . '.sparql';
127
+	$filename = WL_TEMP_DIR.$request_id.'.sparql';
128 128
 
129 129
 	// If the file doesn't exist, exit.
130
-	if ( ! file_exists( $filename ) ) {
131
-		wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" );
130
+	if ( ! file_exists($filename)) {
131
+		wl_write_log("wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]");
132 132
 
133 133
 		return;
134 134
 	}
135 135
 
136
-	wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" );
136
+	wl_write_log("wl_execute_saved_sparql_update_query [ filename :: $filename ]");
137 137
 
138 138
 	// Get the query saved in the file.
139
-	$query = file_get_contents( $filename );
139
+	$query = file_get_contents($filename);
140 140
 
141 141
 	// Execute the SPARQL query.
142
-	rl_execute_sparql_update_query( $query, FALSE );
142
+	rl_execute_sparql_update_query($query, FALSE);
143 143
 
144 144
 	// Reindex the triple store.
145 145
 	wordlift_reindex_triple_store();
146 146
 
147 147
 	// Delete the temporary file.
148
-	unlink( $filename );
148
+	unlink($filename);
149 149
 }
150 150
 
151
-add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 );
151
+add_action('wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1);
152 152
 
153 153
 /**
154 154
  * Add buttons hook for the TinyMCE editor. This method is called by the WP init hook.
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 function wordlift_buttonhooks() {
157 157
 
158 158
 	// Only add hooks when the current user has permissions AND is in Rich Text editor mode
159
-	if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
160
-		add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' );
159
+	if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) {
160
+		add_filter('mce_external_plugins', 'wordlift_register_tinymce_javascript');
161 161
 	}
162 162
 }
163 163
 
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
  *
169 169
  * @return array The modified plugins array.
170 170
  */
171
-function wordlift_register_tinymce_javascript( $plugin_array ) {
171
+function wordlift_register_tinymce_javascript($plugin_array) {
172 172
 
173 173
 	// add the wordlift plugin.
174
-	$plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
174
+	$plugin_array['wordlift'] = plugin_dir_url(__FILE__).'js/wordlift-reloaded.js';
175 175
 
176 176
 	return $plugin_array;
177 177
 }
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 function wordlift_allowed_post_tags() {
184 184
 	global $allowedposttags;
185 185
 
186
-	$tags           = array( 'span' );
186
+	$tags           = array('span');
187 187
 	$new_attributes = array(
188 188
 		'itemscope' => array(),
189 189
 		'itemtype'  => array(),
@@ -191,17 +191,17 @@  discard block
 block discarded – undo
191 191
 		'itemid'    => array()
192 192
 	);
193 193
 
194
-	foreach ( $tags as $tag ) {
195
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
196
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
194
+	foreach ($tags as $tag) {
195
+		if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) {
196
+			$allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes);
197 197
 		}
198 198
 	}
199 199
 }
200 200
 
201 201
 // init process for button control
202
-add_action( 'init', 'wordlift_buttonhooks' );
202
+add_action('init', 'wordlift_buttonhooks');
203 203
 // add allowed post tags.
204
-add_action( 'init', 'wordlift_allowed_post_tags' );
204
+add_action('init', 'wordlift_allowed_post_tags');
205 205
 
206 206
 
207 207
 /**
@@ -210,30 +210,30 @@  discard block
 block discarded – undo
210 210
 function wordlift_admin_enqueue_scripts() {
211 211
 
212 212
 	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
213
-	wp_enqueue_script( 'wpdialogs' );
214
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
213
+	wp_enqueue_script('wpdialogs');
214
+	wp_enqueue_style('wp-jquery-ui-dialog');
215 215
 
216
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
216
+	wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css');
217 217
 
218
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
219
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
220
-	wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . '/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' );
221
-	wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
222
-	wp_enqueue_script( 'angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js' );
218
+	wp_enqueue_script('jquery-ui-autocomplete');
219
+	wp_enqueue_script('angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js');
220
+	wp_enqueue_script('angularjs-geolocation', plugin_dir_url(__FILE__).'/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js');
221
+	wp_enqueue_script('angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js');
222
+	wp_enqueue_script('angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js');
223 223
 
224 224
 	// Disable auto-save for custom entity posts only
225
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
226
-		wp_dequeue_script( 'autosave' );
225
+	if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) {
226
+		wp_dequeue_script('autosave');
227 227
 	}
228 228
 }
229 229
 
230
-add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
230
+add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts');
231 231
 
232 232
 function wl_enqueue_scripts() {
233
-	wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
233
+	wp_enqueue_style('wordlift-ui', plugin_dir_url(__FILE__).'css/wordlift-ui.min.css');
234 234
 }
235 235
 
236
-add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' );
236
+add_action('wp_enqueue_scripts', 'wl_enqueue_scripts');
237 237
 
238 238
 /**
239 239
  * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes.
@@ -243,23 +243,23 @@  discard block
 block discarded – undo
243 243
  *
244 244
  * @return array An array which contains allowed microdata attributes.
245 245
  */
246
-function wordlift_allowed_html( $allowedtags, $context ) {
246
+function wordlift_allowed_html($allowedtags, $context) {
247 247
 
248
-	if ( 'post' !== $context ) {
248
+	if ('post' !== $context) {
249 249
 		return $allowedtags;
250 250
 	}
251 251
 
252
-	return array_merge_recursive( $allowedtags, array(
252
+	return array_merge_recursive($allowedtags, array(
253 253
 		'span' => array(
254 254
 			'itemscope' => TRUE,
255 255
 			'itemtype'  => TRUE,
256 256
 			'itemid'    => TRUE,
257 257
 			'itemprop'  => TRUE
258 258
 		)
259
-	) );
259
+	));
260 260
 }
261 261
 
262
-add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
262
+add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2);
263 263
 
264 264
 /**
265 265
  * Get the coordinates for the specified post ID.
@@ -268,16 +268,16 @@  discard block
 block discarded – undo
268 268
  *
269 269
  * @return array|null An array of coordinates or null.
270 270
  */
271
-function wl_get_coordinates( $post_id ) {
271
+function wl_get_coordinates($post_id) {
272 272
 
273
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
274
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
273
+	$latitude  = wl_schema_get_value($post_id, 'latitude');
274
+	$longitude = wl_schema_get_value($post_id, 'longitude');
275 275
 
276 276
 	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
277 277
 	// "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
278 278
 	return array(
279
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
280
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : ''
279
+		'latitude'  => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '',
280
+		'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : ''
281 281
 	);
282 282
 }
283 283
 
@@ -288,12 +288,12 @@  discard block
 block discarded – undo
288 288
  *
289 289
  * @return string A datetime.
290 290
  */
291
-function wl_get_post_modified_time( $post ) {
291
+function wl_get_post_modified_time($post) {
292 292
 
293
-	$date_modified = get_post_modified_time( 'c', TRUE, $post );
293
+	$date_modified = get_post_modified_time('c', TRUE, $post);
294 294
 
295
-	if ( '-' === substr( $date_modified, 0, 1 ) ) {
296
-		return get_the_time( 'c', $post );
295
+	if ('-' === substr($date_modified, 0, 1)) {
296
+		return get_the_time('c', $post);
297 297
 	}
298 298
 
299 299
 	return $date_modified;
@@ -306,27 +306,27 @@  discard block
 block discarded – undo
306 306
  *
307 307
  * @return array An array of image URLs.
308 308
  */
309
-function wl_get_image_urls( $post_id ) {
309
+function wl_get_image_urls($post_id) {
310 310
 
311 311
 
312 312
 	// If there is a featured image it has the priority
313
-	$featured_image_id = get_post_thumbnail_id( $post_id );
314
-	if ( is_numeric( $featured_image_id ) ) {
315
-		$image_url = wp_get_attachment_url( $featured_image_id );
313
+	$featured_image_id = get_post_thumbnail_id($post_id);
314
+	if (is_numeric($featured_image_id)) {
315
+		$image_url = wp_get_attachment_url($featured_image_id);
316 316
 
317
-		return array( $image_url );
317
+		return array($image_url);
318 318
 	}
319 319
 
320 320
 	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
321 321
 
322
-	$images = get_children( array(
322
+	$images = get_children(array(
323 323
 		'post_parent'    => $post_id,
324 324
 		'post_type'      => 'attachment',
325 325
 		'post_mime_type' => 'image'
326
-	) );
326
+	));
327 327
 
328 328
 	// Return an empty array if no image is found.
329
-	if ( empty( $images ) ) {
329
+	if (empty($images)) {
330 330
 		return array();
331 331
 	}
332 332
 
@@ -334,11 +334,11 @@  discard block
 block discarded – undo
334 334
 	$image_urls = array();
335 335
 
336 336
 	// Collect the URLs.
337
-	foreach ( $images as $attachment_id => $attachment ) {
338
-		$image_url = wp_get_attachment_url( $attachment_id );
337
+	foreach ($images as $attachment_id => $attachment) {
338
+		$image_url = wp_get_attachment_url($attachment_id);
339 339
 		// Ensure the URL isn't collected already.
340
-		if ( ! in_array( $image_url, $image_urls ) ) {
341
-			array_push( $image_urls, $image_url );
340
+		if ( ! in_array($image_url, $image_urls)) {
341
+			array_push($image_urls, $image_url);
342 342
 		}
343 343
 	}
344 344
 
@@ -355,17 +355,17 @@  discard block
 block discarded – undo
355 355
  *
356 356
  * @return string The SPARQL fragment.
357 357
  */
358
-function wl_get_sparql_images( $uri, $post_id ) {
358
+function wl_get_sparql_images($uri, $post_id) {
359 359
 
360 360
 	$sparql = '';
361 361
 
362 362
 	// Get the escaped URI.
363
-	$uri_e = esc_html( $uri );
363
+	$uri_e = esc_html($uri);
364 364
 
365 365
 	// Add SPARQL stmts to write the schema:image.
366
-	$image_urls = wl_get_image_urls( $post_id );
367
-	foreach ( $image_urls as $image_url ) {
368
-		$image_url_esc = wl_sparql_escape_uri( $image_url );
366
+	$image_urls = wl_get_image_urls($post_id);
367
+	foreach ($image_urls as $image_url) {
368
+		$image_url_esc = wl_sparql_escape_uri($image_url);
369 369
 		$sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
370 370
 	}
371 371
 
@@ -380,21 +380,21 @@  discard block
 block discarded – undo
380 380
  *
381 381
  * @return WP_Post|null A post instance or null if not found.
382 382
  */
383
-function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
383
+function wl_get_attachment_for_source_url($parent_post_id, $source_url) {
384 384
 
385 385
 	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
386 386
 
387
-	$posts = get_posts( array(
387
+	$posts = get_posts(array(
388 388
 		'post_type'      => 'attachment',
389 389
 		'posts_per_page' => 1,
390 390
 		'post_status'    => 'any',
391 391
 		'post_parent'    => $parent_post_id,
392 392
 		'meta_key'       => 'wl_source_url',
393 393
 		'meta_value'     => $source_url
394
-	) );
394
+	));
395 395
 
396 396
 	// Return the found post.
397
-	if ( 1 === count( $posts ) ) {
397
+	if (1 === count($posts)) {
398 398
 		return $posts[0];
399 399
 	}
400 400
 
@@ -408,10 +408,10 @@  discard block
 block discarded – undo
408 408
  * @param int $post_id The post ID.
409 409
  * @param string $source_url The source URL.
410 410
  */
411
-function wl_set_source_url( $post_id, $source_url ) {
411
+function wl_set_source_url($post_id, $source_url) {
412 412
 
413
-	delete_post_meta( $post_id, 'wl_source_url' );
414
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
413
+	delete_post_meta($post_id, 'wl_source_url');
414
+	add_post_meta($post_id, 'wl_source_url', $source_url);
415 415
 }
416 416
 
417 417
 
@@ -427,10 +427,10 @@  discard block
 block discarded – undo
427 427
  *
428 428
  * @param bool $hard True if the rewrite involves configuration updates in Apache/IIS.
429 429
  */
430
-function wl_flush_rewrite_rules_hard( $hard ) {
430
+function wl_flush_rewrite_rules_hard($hard) {
431 431
 
432 432
 	// If WL is not yet configured, we cannot perform any update, so we exit.
433
-	if ( '' === wl_configuration_get_key() ) {
433
+	if ('' === wl_configuration_get_key()) {
434 434
 		return;
435 435
 	}
436 436
 
@@ -439,13 +439,13 @@  discard block
 block discarded – undo
439 439
 	$limit  = 100;
440 440
 
441 441
 	// Get more posts if the number of returned posts matches the limit.
442
-	while ( $limit === ( $posts = get_posts( array(
442
+	while ($limit === ($posts = get_posts(array(
443 443
 			'offset'      => $offset,
444 444
 			'numberposts' => $limit,
445 445
 			'orderby'     => 'ID',
446 446
 			'post_type'   => 'any',
447 447
 			'post_status' => 'publish'
448
-		) ) ) ) {
448
+		)))) {
449 449
 
450 450
 		// Holds the delete part of the query.
451 451
 		$delete_query = rl_sparql_prefixes();
@@ -454,18 +454,18 @@  discard block
 block discarded – undo
454 454
 		$insert_query = 'INSERT DATA { ';
455 455
 
456 456
 		// Cycle in each post to build the query.
457
-		foreach ( $posts as $post ) {
457
+		foreach ($posts as $post) {
458 458
 
459 459
 			// Ignore revisions.
460
-			if ( wp_is_post_revision( $post->ID ) ) {
460
+			if (wp_is_post_revision($post->ID)) {
461 461
 				continue;
462 462
 			}
463 463
 
464 464
 			// Get the entity URI.
465
-			$uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
465
+			$uri = wl_sparql_escape_uri(wl_get_entity_uri($post->ID));
466 466
 
467 467
 			// Get the post URL.
468
-			$url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
468
+			$url = wl_sparql_escape_uri(get_permalink($post->ID));
469 469
 
470 470
 			// Prepare the DELETE and INSERT commands.
471 471
 			$delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE  { <$uri> schema:url ?u . };\n";
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 		$insert_query .= ' };';
477 477
 
478 478
 		// Execute the query.
479
-		rl_execute_sparql_update_query( $delete_query . $insert_query );
479
+		rl_execute_sparql_update_query($delete_query.$insert_query);
480 480
 
481 481
 		// Advance to the next posts.
482 482
 		$offset += $limit;
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 
493 493
 }
494 494
 
495
-add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 );
495
+add_filter('flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1);
496 496
 
497 497
 /**
498 498
  * Sanitizes an URI path by replacing the non allowed characters with an underscore.
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
  *
505 505
  * @return The sanitized path.
506 506
  */
507
-function wl_sanitize_uri_path( $path, $char = '_' ) {
507
+function wl_sanitize_uri_path($path, $char = '_') {
508 508
 
509 509
 	// wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" );
510 510
 
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 	// Plus the ' ' (space).
515 515
 	// TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex)
516 516
 
517
-	return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) );
517
+	return sanitize_title(preg_replace('/[;\/?:@&=+$,\s]/', $char, stripslashes($path)));
518 518
 }
519 519
 
520 520
 /**
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
  *
525 525
  * @return array Array containing $value (if $value was not an array)
526 526
  */
527
-function wl_force_to_array( $value ) {
527
+function wl_force_to_array($value) {
528 528
 
529
-	if ( ! is_array( $value ) ) {
530
-		return array( $value );
529
+	if ( ! is_array($value)) {
530
+		return array($value);
531 531
 	}
532 532
 
533 533
 	return $value;
@@ -539,28 +539,28 @@  discard block
 block discarded – undo
539 539
 function wl_shutdown() {
540 540
 
541 541
 	// Get the filename to the temporary SPARQL file.
542
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
542
+	$filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql';
543 543
 
544 544
 	// If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
545
-	if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
545
+	if (WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists($filename)) {
546 546
 
547 547
 		// The request ID.
548
-		$args = array( WL_REQUEST_ID );
548
+		$args = array(WL_REQUEST_ID);
549 549
 
550 550
 		// Schedule the execution of the SPARQL query with the request ID.
551
-		wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
551
+		wp_schedule_single_event(time(), 'wl_execute_saved_sparql_update_query', $args);
552 552
 
553 553
 		// Check that the request is scheduled.
554
-		$timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
554
+		$timestamp = wp_next_scheduled('wl_execute_saved_sparql_update_query', $args);
555 555
 
556 556
 		// Spawn the cron.
557 557
 		spawn_cron();
558 558
 
559
-		wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
559
+		wl_write_log("wl_shutdown [ request id :: ".WL_REQUEST_ID." ][ timestamp :: $timestamp ]");
560 560
 	}
561 561
 }
562 562
 
563
-add_action( 'shutdown', 'wl_shutdown' );
563
+add_action('shutdown', 'wl_shutdown');
564 564
 
565 565
 /**
566 566
  * Replaces the *itemid* attributes URIs with the WordLift URIs.
@@ -569,118 +569,118 @@  discard block
 block discarded – undo
569 569
  *
570 570
  * @return string The updated post content.
571 571
  */
572
-function wl_replace_item_id_with_uri( $content ) {
572
+function wl_replace_item_id_with_uri($content) {
573 573
 
574 574
 	// wl_write_log( "wl_replace_item_id_with_uri" );
575 575
 
576 576
 	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
577
-	$content = stripslashes( $content );
577
+	$content = stripslashes($content);
578 578
 
579 579
 	// If any match are found.
580 580
 	$matches = array();
581
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
581
+	if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) {
582 582
 
583
-		foreach ( $matches as $match ) {
583
+		foreach ($matches as $match) {
584 584
 
585 585
 			// Get the item ID.
586 586
 			$item_id = $match[1];
587 587
 
588 588
 			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
589 589
 			$post = Wordlift_Entity_Service::get_instance()
590
-			                               ->get_entity_post_by_uri( $item_id );
590
+			                               ->get_entity_post_by_uri($item_id);
591 591
 
592 592
 			// If no entity is found, continue to the next one.
593
-			if ( NULL === $post ) {
593
+			if (NULL === $post) {
594 594
 				continue;
595 595
 			}
596 596
 
597 597
 			// Get the URI for that post.
598
-			$uri = wl_get_entity_uri( $post->ID );
598
+			$uri = wl_get_entity_uri($post->ID);
599 599
 
600 600
 			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
601 601
 
602 602
 			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
603
-			if ( $item_id !== $uri ) {
604
-				$uri_e   = esc_html( $uri );
605
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
603
+			if ($item_id !== $uri) {
604
+				$uri_e   = esc_html($uri);
605
+				$content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content);
606 606
 			}
607 607
 		}
608 608
 	}
609 609
 
610 610
 	// Reapply slashes.
611
-	$content = addslashes( $content );
611
+	$content = addslashes($content);
612 612
 
613 613
 	return $content;
614 614
 }
615 615
 
616
-add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
616
+add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1);
617 617
 
618
-require_once( 'wordlift_entity_functions.php' );
618
+require_once('wordlift_entity_functions.php');
619 619
 
620 620
 // add editor related methods.
621
-require_once( 'wordlift_editor.php' );
621
+require_once('wordlift_editor.php');
622 622
 
623 623
 // add the WordLift entity custom type.
624
-require_once( 'wordlift_entity_type.php' );
625
-require_once( 'wordlift_entity_type_taxonomy.php' );
624
+require_once('wordlift_entity_type.php');
625
+require_once('wordlift_entity_type_taxonomy.php');
626 626
 
627 627
 // filters the post content when saving posts.
628
-require_once( 'wordlift_content_filter.php' );
628
+require_once('wordlift_content_filter.php');
629 629
 // add callbacks on post save to notify data changes from wp to redlink triple store
630
-require_once( 'wordlift_to_redlink_data_push_callbacks.php' );
630
+require_once('wordlift_to_redlink_data_push_callbacks.php');
631 631
 
632 632
 // Load modules
633
-require_once( 'modules/analyzer/wordlift_analyzer.php' );
634
-require_once( 'modules/linked_data/wordlift_linked_data.php' );
635
-require_once( 'modules/prefixes/wordlift_prefixes.php' );
636
-require_once( 'modules/caching/wordlift_caching.php' );
637
-require_once( 'modules/redirector/wordlift_redirector.php' );
638
-require_once( 'modules/freebase_image_proxy/wordlift_freebase_image_proxy.php' );
633
+require_once('modules/analyzer/wordlift_analyzer.php');
634
+require_once('modules/linked_data/wordlift_linked_data.php');
635
+require_once('modules/prefixes/wordlift_prefixes.php');
636
+require_once('modules/caching/wordlift_caching.php');
637
+require_once('modules/redirector/wordlift_redirector.php');
638
+require_once('modules/freebase_image_proxy/wordlift_freebase_image_proxy.php');
639 639
 
640 640
 // Shortcodes
641 641
 
642
-require_once( 'modules/geo_widget/wordlift_geo_widget.php' );
643
-require_once( 'shortcodes/wordlift_shortcode_chord.php' );
644
-require_once( 'shortcodes/wordlift_shortcode_geomap.php' );
645
-require_once( 'shortcodes/wordlift_shortcode_field.php' );
646
-require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' );
647
-require_once( 'shortcodes/wordlift_shortcode_navigator.php' );
642
+require_once('modules/geo_widget/wordlift_geo_widget.php');
643
+require_once('shortcodes/wordlift_shortcode_chord.php');
644
+require_once('shortcodes/wordlift_shortcode_geomap.php');
645
+require_once('shortcodes/wordlift_shortcode_field.php');
646
+require_once('shortcodes/wordlift_shortcode_faceted_search.php');
647
+require_once('shortcodes/wordlift_shortcode_navigator.php');
648 648
 
649 649
 // disable In-Depth Articles
650 650
 //require_once('wordlift_indepth_articles.php');
651 651
 
652
-require_once( 'widgets/wordlift_widget_geo.php' );
653
-require_once( 'widgets/wordlift_widget_chord.php' );
654
-require_once( 'widgets/wordlift_widget_timeline.php' );
652
+require_once('widgets/wordlift_widget_geo.php');
653
+require_once('widgets/wordlift_widget_chord.php');
654
+require_once('widgets/wordlift_widget_timeline.php');
655 655
 
656
-require_once( 'wordlift_sparql.php' );
657
-require_once( 'wordlift_redlink.php' );
656
+require_once('wordlift_sparql.php');
657
+require_once('wordlift_redlink.php');
658 658
 
659 659
 // Add admin functions.
660 660
 // TODO: find a way to make 'admin' UI tests work.
661 661
 //if ( is_admin() ) {
662 662
 
663
-require_once( 'admin/wordlift_admin.php' );
664
-require_once( 'admin/wordlift_admin_edit_post.php' );
665
-require_once( 'admin/wordlift_admin_save_post.php' );
663
+require_once('admin/wordlift_admin.php');
664
+require_once('admin/wordlift_admin_edit_post.php');
665
+require_once('admin/wordlift_admin_save_post.php');
666 666
 
667 667
 // add the entities meta box.
668
-require_once( 'admin/wordlift_admin_meta_box_entities.php' );
668
+require_once('admin/wordlift_admin_meta_box_entities.php');
669 669
 
670 670
 // add the entity creation AJAX.
671
-require_once( 'admin/wordlift_admin_ajax_related_posts.php' );
671
+require_once('admin/wordlift_admin_ajax_related_posts.php');
672 672
 
673 673
 // Load the wl_chord TinyMCE button and configuration dialog.
674
-require_once( 'admin/wordlift_admin_shortcodes.php' );
674
+require_once('admin/wordlift_admin_shortcodes.php');
675 675
 
676 676
 // Provide syncing features.
677
-require_once( 'admin/wordlift_admin_sync.php' );
677
+require_once('admin/wordlift_admin_sync.php');
678 678
 //}
679 679
 
680 680
 // load languages.
681 681
 // TODO: the following call gives for granted that the plugin is in the wordlift directory,
682 682
 //       we're currently doing this because wordlift is symbolic linked.
683
-load_plugin_textdomain( 'wordlift', FALSE, '/wordlift/languages' );
683
+load_plugin_textdomain('wordlift', FALSE, '/wordlift/languages');
684 684
 
685 685
 
686 686
 /**
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
  * This action is documented in includes/class-wordlift-activator.php
689 689
  */
690 690
 function activate_wordlift() {
691
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
691
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
692 692
 	Wordlift_Activator::activate();
693 693
 }
694 694
 
@@ -697,18 +697,18 @@  discard block
 block discarded – undo
697 697
  * This action is documented in includes/class-wordlift-deactivator.php
698 698
  */
699 699
 function deactivate_wordlift() {
700
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
700
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
701 701
 	Wordlift_Deactivator::deactivate();
702 702
 }
703 703
 
704
-register_activation_hook( __FILE__, 'activate_wordlift' );
705
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
704
+register_activation_hook(__FILE__, 'activate_wordlift');
705
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
706 706
 
707 707
 /**
708 708
  * The core plugin class that is used to define internationalization,
709 709
  * admin-specific hooks, and public-facing site hooks.
710 710
  */
711
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
711
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
712 712
 
713 713
 /**
714 714
  * Begins execution of the plugin.
Please login to merge, or discard this patch.