Completed
Push — develop ( c5c29a...dd2c91 )
by David
02:48
created
src/wordlift.php 2 patches
Indentation   +159 added lines, -159 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.
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function wl_write_log( $log ) {
50 50
 
51
-	Wordlift_Log_Service::get_instance()->info( $log );
51
+    Wordlift_Log_Service::get_instance()->info( $log );
52 52
 
53 53
 }
54 54
 
@@ -64,20 +64,20 @@  discard block
 block discarded – undo
64 64
  */
65 65
 function wl_write_log_handler( $log, $caller = null ) {
66 66
 
67
-	global $wl_logger;
67
+    global $wl_logger;
68 68
 
69
-	if ( true === WP_DEBUG ) {
69
+    if ( true === WP_DEBUG ) {
70 70
 
71
-		$message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
72
-		           ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
71
+        $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
72
+                    ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
73 73
 
74
-		if ( isset( $wl_logger ) ) {
75
-			$wl_logger->info( $message );
76
-		} else {
77
-			error_log( $message );
78
-		}
74
+        if ( isset( $wl_logger ) ) {
75
+            $wl_logger->info( $message );
76
+        } else {
77
+            error_log( $message );
78
+        }
79 79
 
80
-	}
80
+    }
81 81
 
82 82
 }
83 83
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
  */
95 95
 function wl_write_log_hide_key( $text ) {
96 96
 
97
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
97
+    return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
98 98
 }
99 99
 
100 100
 /**
@@ -102,21 +102,21 @@  discard block
 block discarded – undo
102 102
  * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
103 103
  */
104 104
 function wordlift_allowed_post_tags() {
105
-	global $allowedposttags;
106
-
107
-	$tags           = array( 'span' );
108
-	$new_attributes = array(
109
-		'itemscope' => array(),
110
-		'itemtype'  => array(),
111
-		'itemprop'  => array(),
112
-		'itemid'    => array(),
113
-	);
114
-
115
-	foreach ( $tags as $tag ) {
116
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
117
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
118
-		}
119
-	}
105
+    global $allowedposttags;
106
+
107
+    $tags           = array( 'span' );
108
+    $new_attributes = array(
109
+        'itemscope' => array(),
110
+        'itemtype'  => array(),
111
+        'itemprop'  => array(),
112
+        'itemid'    => array(),
113
+    );
114
+
115
+    foreach ( $tags as $tag ) {
116
+        if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
117
+            $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
118
+        }
119
+    }
120 120
 }
121 121
 
122 122
 // add allowed post tags.
@@ -127,28 +127,28 @@  discard block
 block discarded – undo
127 127
  */
128 128
 function wordlift_admin_enqueue_scripts() {
129 129
 
130
-	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
131
-	wp_enqueue_script( 'wpdialogs' );
132
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
130
+    // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
131
+    wp_enqueue_script( 'wpdialogs' );
132
+    wp_enqueue_style( 'wp-jquery-ui-dialog' );
133 133
 
134
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
134
+    wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
135 135
 
136
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
137
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
138
-	wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . 'bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' );
139
-	wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
140
-	wp_enqueue_script( 'angularjs-animate', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-animate.min.js' );
136
+    wp_enqueue_script( 'jquery-ui-autocomplete' );
137
+    wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
138
+    wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . 'bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' );
139
+    wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
140
+    wp_enqueue_script( 'angularjs-animate', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-animate.min.js' );
141 141
 
142
-	// Disable auto-save for custom entity posts only
143
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
144
-		wp_dequeue_script( 'autosave' );
145
-	}
142
+    // Disable auto-save for custom entity posts only
143
+    if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
144
+        wp_dequeue_script( 'autosave' );
145
+    }
146 146
 }
147 147
 
148 148
 add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
149 149
 
150 150
 function wl_enqueue_scripts() {
151
-	wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
151
+    wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
152 152
 }
153 153
 
154 154
 add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' );
@@ -163,18 +163,18 @@  discard block
 block discarded – undo
163 163
  */
164 164
 function wordlift_allowed_html( $allowedtags, $context ) {
165 165
 
166
-	if ( 'post' !== $context ) {
167
-		return $allowedtags;
168
-	}
169
-
170
-	return array_merge_recursive( $allowedtags, array(
171
-		'span' => array(
172
-			'itemscope' => true,
173
-			'itemtype'  => true,
174
-			'itemid'    => true,
175
-			'itemprop'  => true,
176
-		),
177
-	) );
166
+    if ( 'post' !== $context ) {
167
+        return $allowedtags;
168
+    }
169
+
170
+    return array_merge_recursive( $allowedtags, array(
171
+        'span' => array(
172
+            'itemscope' => true,
173
+            'itemtype'  => true,
174
+            'itemid'    => true,
175
+            'itemprop'  => true,
176
+        ),
177
+    ) );
178 178
 }
179 179
 
180 180
 add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
  */
189 189
 function wl_get_coordinates( $post_id ) {
190 190
 
191
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
192
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
191
+    $latitude  = wl_schema_get_value( $post_id, 'latitude' );
192
+    $longitude = wl_schema_get_value( $post_id, 'longitude' );
193 193
 
194
-	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific
195
-	// place on the globe:"The zero/zero point of this system is located in the
196
-	// Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
197
-	return array(
198
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
199
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
200
-	);
194
+    // DO NOT set latitude/longitude to 0/0 as default values. It's a specific
195
+    // place on the globe:"The zero/zero point of this system is located in the
196
+    // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
197
+    return array(
198
+        'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
199
+        'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
200
+    );
201 201
 }
202 202
 
203 203
 /**
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
  */
212 212
 function wl_get_image_urls( $post_id ) {
213 213
 
214
-	return Wordlift_Storage_Factory::get_instance()
215
-	                               ->post_images()
216
-	                               ->get( $post_id );
214
+    return Wordlift_Storage_Factory::get_instance()
215
+                                    ->post_images()
216
+                                    ->get( $post_id );
217 217
 
218 218
 //	// If there is a featured image it has the priority.
219 219
 //	$featured_image_id = get_post_thumbnail_id( $post_id );
@@ -261,24 +261,24 @@  discard block
 block discarded – undo
261 261
  */
262 262
 function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
263 263
 
264
-	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
264
+    // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
265 265
 
266
-	$posts = get_posts( array(
267
-		'post_type'      => 'attachment',
268
-		'posts_per_page' => 1,
269
-		'post_status'    => 'any',
270
-		'post_parent'    => $parent_post_id,
271
-		'meta_key'       => 'wl_source_url',
272
-		'meta_value'     => $source_url,
273
-	) );
266
+    $posts = get_posts( array(
267
+        'post_type'      => 'attachment',
268
+        'posts_per_page' => 1,
269
+        'post_status'    => 'any',
270
+        'post_parent'    => $parent_post_id,
271
+        'meta_key'       => 'wl_source_url',
272
+        'meta_value'     => $source_url,
273
+    ) );
274 274
 
275
-	// Return the found post.
276
-	if ( 1 === count( $posts ) ) {
277
-		return $posts[0];
278
-	}
275
+    // Return the found post.
276
+    if ( 1 === count( $posts ) ) {
277
+        return $posts[0];
278
+    }
279 279
 
280
-	// Return null.
281
-	return null;
280
+    // Return null.
281
+    return null;
282 282
 }
283 283
 
284 284
 /**
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
  */
290 290
 function wl_set_source_url( $post_id, $source_url ) {
291 291
 
292
-	delete_post_meta( $post_id, 'wl_source_url' );
293
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
292
+    delete_post_meta( $post_id, 'wl_source_url' );
293
+    add_post_meta( $post_id, 'wl_source_url', $source_url );
294 294
 }
295 295
 
296 296
 
@@ -307,61 +307,61 @@  discard block
 block discarded – undo
307 307
  */
308 308
 function wl_flush_rewrite_rules_hard( $hard ) {
309 309
 
310
-	// If WL is not yet configured, we cannot perform any update, so we exit.
311
-	if ( '' === wl_configuration_get_key() ) {
312
-		return;
313
-	}
310
+    // If WL is not yet configured, we cannot perform any update, so we exit.
311
+    if ( '' === wl_configuration_get_key() ) {
312
+        return;
313
+    }
314 314
 
315
-	// Set the initial offset and limit each call to 100 posts to avoid memory errors.
316
-	$offset = 0;
317
-	$limit  = 100;
315
+    // Set the initial offset and limit each call to 100 posts to avoid memory errors.
316
+    $offset = 0;
317
+    $limit  = 100;
318 318
 
319
-	// Get more posts if the number of returned posts matches the limit.
320
-	while ( $limit === ( $posts = get_posts( array(
321
-			'offset'      => $offset,
322
-			'numberposts' => $limit,
323
-			'orderby'     => 'ID',
324
-			'post_type'   => 'any',
325
-			'post_status' => 'publish',
326
-		) ) ) ) {
319
+    // Get more posts if the number of returned posts matches the limit.
320
+    while ( $limit === ( $posts = get_posts( array(
321
+            'offset'      => $offset,
322
+            'numberposts' => $limit,
323
+            'orderby'     => 'ID',
324
+            'post_type'   => 'any',
325
+            'post_status' => 'publish',
326
+        ) ) ) ) {
327 327
 
328
-		// Holds the delete part of the query.
329
-		$delete_query = rl_sparql_prefixes();
328
+        // Holds the delete part of the query.
329
+        $delete_query = rl_sparql_prefixes();
330 330
 
331
-		// Holds the insert part of the query.
332
-		$insert_query = '';
331
+        // Holds the insert part of the query.
332
+        $insert_query = '';
333 333
 
334
-		// Cycle in each post to build the query.
335
-		foreach ( $posts as $post ) {
334
+        // Cycle in each post to build the query.
335
+        foreach ( $posts as $post ) {
336 336
 
337
-			// Ignore revisions.
338
-			if ( wp_is_post_revision( $post->ID ) ) {
339
-				continue;
340
-			}
337
+            // Ignore revisions.
338
+            if ( wp_is_post_revision( $post->ID ) ) {
339
+                continue;
340
+            }
341 341
 
342
-			// Get the entity URI.
343
-			$s = Wordlift_Sparql_Service::escape_uri( Wordlift_Entity_Service::get_instance()
344
-			                                                                 ->get_uri( $post->ID ) );
342
+            // Get the entity URI.
343
+            $s = Wordlift_Sparql_Service::escape_uri( Wordlift_Entity_Service::get_instance()
344
+                                                                                ->get_uri( $post->ID ) );
345 345
 
346
-			// Get the post URL.
347
-			// $url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
346
+            // Get the post URL.
347
+            // $url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
348 348
 
349
-			// Prepare the DELETE and INSERT commands.
350
-			$delete_query .= "DELETE { <$s> schema:url ?u . } WHERE  { <$s> schema:url ?u . };\n";
349
+            // Prepare the DELETE and INSERT commands.
350
+            $delete_query .= "DELETE { <$s> schema:url ?u . } WHERE  { <$s> schema:url ?u . };\n";
351 351
 
352
-			$insert_query .= Wordlift_Schema_Url_Property_Service::get_instance()
353
-			                                                     ->get_insert_query( $s, $post->ID );
352
+            $insert_query .= Wordlift_Schema_Url_Property_Service::get_instance()
353
+                                                                    ->get_insert_query( $s, $post->ID );
354 354
 
355
-		}
355
+        }
356 356
 
357 357
 
358
-		// Execute the query.
359
-		rl_execute_sparql_update_query( $delete_query . $insert_query );
358
+        // Execute the query.
359
+        rl_execute_sparql_update_query( $delete_query . $insert_query );
360 360
 
361
-		// Advance to the next posts.
362
-		$offset += $limit;
361
+        // Advance to the next posts.
362
+        $offset += $limit;
363 363
 
364
-	}
364
+    }
365 365
 
366 366
 }
367 367
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
  */
381 381
 function wl_sanitize_uri_path( $path, $char = '_' ) {
382 382
 
383
-	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
383
+    return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
384 384
 }
385 385
 
386 386
 ///**
@@ -421,46 +421,46 @@  discard block
 block discarded – undo
421 421
  */
422 422
 function wl_replace_item_id_with_uri( $content ) {
423 423
 
424
-	// wl_write_log( "wl_replace_item_id_with_uri" );
424
+    // wl_write_log( "wl_replace_item_id_with_uri" );
425 425
 
426
-	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
427
-	$content = stripslashes( $content );
426
+    // Strip slashes, see https://core.trac.wordpress.org/ticket/21767
427
+    $content = stripslashes( $content );
428 428
 
429
-	// If any match are found.
430
-	$matches = array();
431
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
429
+    // If any match are found.
430
+    $matches = array();
431
+    if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
432 432
 
433
-		foreach ( $matches as $match ) {
433
+        foreach ( $matches as $match ) {
434 434
 
435
-			// Get the item ID.
436
-			$item_id = $match[1];
435
+            // Get the item ID.
436
+            $item_id = $match[1];
437 437
 
438
-			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
439
-			$post = Wordlift_Entity_Service::get_instance()
440
-			                               ->get_entity_post_by_uri( $item_id );
438
+            // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
439
+            $post = Wordlift_Entity_Service::get_instance()
440
+                                            ->get_entity_post_by_uri( $item_id );
441 441
 
442
-			// If no entity is found, continue to the next one.
443
-			if ( null === $post ) {
444
-				continue;
445
-			}
442
+            // If no entity is found, continue to the next one.
443
+            if ( null === $post ) {
444
+                continue;
445
+            }
446 446
 
447
-			// Get the URI for that post.
448
-			$uri = wl_get_entity_uri( $post->ID );
447
+            // Get the URI for that post.
448
+            $uri = wl_get_entity_uri( $post->ID );
449 449
 
450
-			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
450
+            // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
451 451
 
452
-			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
453
-			if ( $item_id !== $uri ) {
454
-				$uri_e   = esc_html( $uri );
455
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
456
-			}
457
-		}
458
-	}
452
+            // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
453
+            if ( $item_id !== $uri ) {
454
+                $uri_e   = esc_html( $uri );
455
+                $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
456
+            }
457
+        }
458
+    }
459 459
 
460
-	// Reapply slashes.
461
-	$content = addslashes( $content );
460
+    // Reapply slashes.
461
+    $content = addslashes( $content );
462 462
 
463
-	return $content;
463
+    return $content;
464 464
 }
465 465
 
466 466
 add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
@@ -527,8 +527,8 @@  discard block
 block discarded – undo
527 527
  * This action is documented in includes/class-wordlift-activator.php
528 528
  */
529 529
 function activate_wordlift() {
530
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
531
-	Wordlift_Activator::activate();
530
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
531
+    Wordlift_Activator::activate();
532 532
 }
533 533
 
534 534
 /**
@@ -536,8 +536,8 @@  discard block
 block discarded – undo
536 536
  * This action is documented in includes/class-wordlift-deactivator.php
537 537
  */
538 538
 function deactivate_wordlift() {
539
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
540
-	Wordlift_Deactivator::deactivate();
539
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
540
+    Wordlift_Deactivator::deactivate();
541 541
 }
542 542
 
543 543
 register_activation_hook( __FILE__, 'activate_wordlift' );
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
  */
561 561
 function run_wordlift() {
562 562
 
563
-	$plugin = new Wordlift();
564
-	$plugin->run();
563
+    $plugin = new Wordlift();
564
+    $plugin->run();
565 565
 
566 566
 }
567 567
 
Please login to merge, or discard this patch.
Spacing   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -25,15 +25,15 @@  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' );
36
+require_once('modules/core/wordlift_core.php');
37 37
 
38 38
 /**
39 39
  * Log to the debug.log file.
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
  *
47 47
  * @param string|mixed $log The log data.
48 48
  */
49
-function wl_write_log( $log ) {
49
+function wl_write_log($log) {
50 50
 
51
-	Wordlift_Log_Service::get_instance()->info( $log );
51
+	Wordlift_Log_Service::get_instance()->info($log);
52 52
 
53 53
 }
54 54
 
@@ -62,19 +62,19 @@  discard block
 block discarded – undo
62 62
  * @param string|array $log    The log data.
63 63
  * @param string       $caller The calling function.
64 64
  */
65
-function wl_write_log_handler( $log, $caller = null ) {
65
+function wl_write_log_handler($log, $caller = null) {
66 66
 
67 67
 	global $wl_logger;
68 68
 
69
-	if ( true === WP_DEBUG ) {
69
+	if (true === WP_DEBUG) {
70 70
 
71
-		$message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
72
-		           ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
71
+		$message = (isset($caller) ? sprintf('[%-40.40s] ', $caller) : '').
72
+		           (is_array($log) || is_object($log) ? print_r($log, true) : wl_write_log_hide_key($log));
73 73
 
74
-		if ( isset( $wl_logger ) ) {
75
-			$wl_logger->info( $message );
74
+		if (isset($wl_logger)) {
75
+			$wl_logger->info($message);
76 76
 		} else {
77
-			error_log( $message );
77
+			error_log($message);
78 78
 		}
79 79
 
80 80
 	}
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
  *
93 93
  * @return string A text with the key hidden.
94 94
  */
95
-function wl_write_log_hide_key( $text ) {
95
+function wl_write_log_hide_key($text) {
96 96
 
97
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
97
+	return str_ireplace(wl_configuration_get_key(), '<hidden>', $text);
98 98
 }
99 99
 
100 100
 /**
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 function wordlift_allowed_post_tags() {
105 105
 	global $allowedposttags;
106 106
 
107
-	$tags           = array( 'span' );
107
+	$tags           = array('span');
108 108
 	$new_attributes = array(
109 109
 		'itemscope' => array(),
110 110
 		'itemtype'  => array(),
@@ -112,15 +112,15 @@  discard block
 block discarded – undo
112 112
 		'itemid'    => array(),
113 113
 	);
114 114
 
115
-	foreach ( $tags as $tag ) {
116
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
117
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
115
+	foreach ($tags as $tag) {
116
+		if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) {
117
+			$allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes);
118 118
 		}
119 119
 	}
120 120
 }
121 121
 
122 122
 // add allowed post tags.
123
-add_action( 'init', 'wordlift_allowed_post_tags' );
123
+add_action('init', 'wordlift_allowed_post_tags');
124 124
 
125 125
 /**
126 126
  * Register additional scripts for the admin UI.
@@ -128,30 +128,30 @@  discard block
 block discarded – undo
128 128
 function wordlift_admin_enqueue_scripts() {
129 129
 
130 130
 	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
131
-	wp_enqueue_script( 'wpdialogs' );
132
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
131
+	wp_enqueue_script('wpdialogs');
132
+	wp_enqueue_style('wp-jquery-ui-dialog');
133 133
 
134
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
134
+	wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css');
135 135
 
136
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
137
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
138
-	wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . 'bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' );
139
-	wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
140
-	wp_enqueue_script( 'angularjs-animate', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-animate.min.js' );
136
+	wp_enqueue_script('jquery-ui-autocomplete');
137
+	wp_enqueue_script('angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js');
138
+	wp_enqueue_script('angularjs-geolocation', plugin_dir_url(__FILE__).'bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js');
139
+	wp_enqueue_script('angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js');
140
+	wp_enqueue_script('angularjs-animate', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-animate.min.js');
141 141
 
142 142
 	// Disable auto-save for custom entity posts only
143
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
144
-		wp_dequeue_script( 'autosave' );
143
+	if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) {
144
+		wp_dequeue_script('autosave');
145 145
 	}
146 146
 }
147 147
 
148
-add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
148
+add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts');
149 149
 
150 150
 function wl_enqueue_scripts() {
151
-	wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
151
+	wp_enqueue_style('wordlift-ui', plugin_dir_url(__FILE__).'css/wordlift-ui.min.css');
152 152
 }
153 153
 
154
-add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' );
154
+add_action('wp_enqueue_scripts', 'wl_enqueue_scripts');
155 155
 
156 156
 /**
157 157
  * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes.
@@ -161,23 +161,23 @@  discard block
 block discarded – undo
161 161
  *
162 162
  * @return array An array which contains allowed microdata attributes.
163 163
  */
164
-function wordlift_allowed_html( $allowedtags, $context ) {
164
+function wordlift_allowed_html($allowedtags, $context) {
165 165
 
166
-	if ( 'post' !== $context ) {
166
+	if ('post' !== $context) {
167 167
 		return $allowedtags;
168 168
 	}
169 169
 
170
-	return array_merge_recursive( $allowedtags, array(
170
+	return array_merge_recursive($allowedtags, array(
171 171
 		'span' => array(
172 172
 			'itemscope' => true,
173 173
 			'itemtype'  => true,
174 174
 			'itemid'    => true,
175 175
 			'itemprop'  => true,
176 176
 		),
177
-	) );
177
+	));
178 178
 }
179 179
 
180
-add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
180
+add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2);
181 181
 
182 182
 /**
183 183
  * Get the coordinates for the specified post ID.
@@ -186,17 +186,17 @@  discard block
 block discarded – undo
186 186
  *
187 187
  * @return array|null An array of coordinates or null.
188 188
  */
189
-function wl_get_coordinates( $post_id ) {
189
+function wl_get_coordinates($post_id) {
190 190
 
191
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
192
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
191
+	$latitude  = wl_schema_get_value($post_id, 'latitude');
192
+	$longitude = wl_schema_get_value($post_id, 'longitude');
193 193
 
194 194
 	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific
195 195
 	// place on the globe:"The zero/zero point of this system is located in the
196 196
 	// Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
197 197
 	return array(
198
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
199
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
198
+		'latitude'  => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '',
199
+		'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '',
200 200
 	);
201 201
 }
202 202
 
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
  *
210 210
  * @return array An array of image URLs.
211 211
  */
212
-function wl_get_image_urls( $post_id ) {
212
+function wl_get_image_urls($post_id) {
213 213
 
214 214
 	return Wordlift_Storage_Factory::get_instance()
215 215
 	                               ->post_images()
216
-	                               ->get( $post_id );
216
+	                               ->get($post_id);
217 217
 
218 218
 //	// If there is a featured image it has the priority.
219 219
 //	$featured_image_id = get_post_thumbnail_id( $post_id );
@@ -259,21 +259,21 @@  discard block
 block discarded – undo
259 259
  *
260 260
  * @return WP_Post|null A post instance or null if not found.
261 261
  */
262
-function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
262
+function wl_get_attachment_for_source_url($parent_post_id, $source_url) {
263 263
 
264 264
 	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
265 265
 
266
-	$posts = get_posts( array(
266
+	$posts = get_posts(array(
267 267
 		'post_type'      => 'attachment',
268 268
 		'posts_per_page' => 1,
269 269
 		'post_status'    => 'any',
270 270
 		'post_parent'    => $parent_post_id,
271 271
 		'meta_key'       => 'wl_source_url',
272 272
 		'meta_value'     => $source_url,
273
-	) );
273
+	));
274 274
 
275 275
 	// Return the found post.
276
-	if ( 1 === count( $posts ) ) {
276
+	if (1 === count($posts)) {
277 277
 		return $posts[0];
278 278
 	}
279 279
 
@@ -287,10 +287,10 @@  discard block
 block discarded – undo
287 287
  * @param int    $post_id    The post ID.
288 288
  * @param string $source_url The source URL.
289 289
  */
290
-function wl_set_source_url( $post_id, $source_url ) {
290
+function wl_set_source_url($post_id, $source_url) {
291 291
 
292
-	delete_post_meta( $post_id, 'wl_source_url' );
293
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
292
+	delete_post_meta($post_id, 'wl_source_url');
293
+	add_post_meta($post_id, 'wl_source_url', $source_url);
294 294
 }
295 295
 
296 296
 
@@ -305,10 +305,10 @@  discard block
 block discarded – undo
305 305
  *
306 306
  * @param bool $hard True if the rewrite involves configuration updates in Apache/IIS.
307 307
  */
308
-function wl_flush_rewrite_rules_hard( $hard ) {
308
+function wl_flush_rewrite_rules_hard($hard) {
309 309
 
310 310
 	// If WL is not yet configured, we cannot perform any update, so we exit.
311
-	if ( '' === wl_configuration_get_key() ) {
311
+	if ('' === wl_configuration_get_key()) {
312 312
 		return;
313 313
 	}
314 314
 
@@ -317,13 +317,13 @@  discard block
 block discarded – undo
317 317
 	$limit  = 100;
318 318
 
319 319
 	// Get more posts if the number of returned posts matches the limit.
320
-	while ( $limit === ( $posts = get_posts( array(
320
+	while ($limit === ($posts = get_posts(array(
321 321
 			'offset'      => $offset,
322 322
 			'numberposts' => $limit,
323 323
 			'orderby'     => 'ID',
324 324
 			'post_type'   => 'any',
325 325
 			'post_status' => 'publish',
326
-		) ) ) ) {
326
+		)))) {
327 327
 
328 328
 		// Holds the delete part of the query.
329 329
 		$delete_query = rl_sparql_prefixes();
@@ -332,16 +332,16 @@  discard block
 block discarded – undo
332 332
 		$insert_query = '';
333 333
 
334 334
 		// Cycle in each post to build the query.
335
-		foreach ( $posts as $post ) {
335
+		foreach ($posts as $post) {
336 336
 
337 337
 			// Ignore revisions.
338
-			if ( wp_is_post_revision( $post->ID ) ) {
338
+			if (wp_is_post_revision($post->ID)) {
339 339
 				continue;
340 340
 			}
341 341
 
342 342
 			// Get the entity URI.
343
-			$s = Wordlift_Sparql_Service::escape_uri( Wordlift_Entity_Service::get_instance()
344
-			                                                                 ->get_uri( $post->ID ) );
343
+			$s = Wordlift_Sparql_Service::escape_uri(Wordlift_Entity_Service::get_instance()
344
+			                                                                 ->get_uri($post->ID));
345 345
 
346 346
 			// Get the post URL.
347 347
 			// $url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
@@ -350,13 +350,13 @@  discard block
 block discarded – undo
350 350
 			$delete_query .= "DELETE { <$s> schema:url ?u . } WHERE  { <$s> schema:url ?u . };\n";
351 351
 
352 352
 			$insert_query .= Wordlift_Schema_Url_Property_Service::get_instance()
353
-			                                                     ->get_insert_query( $s, $post->ID );
353
+			                                                     ->get_insert_query($s, $post->ID);
354 354
 
355 355
 		}
356 356
 
357 357
 
358 358
 		// Execute the query.
359
-		rl_execute_sparql_update_query( $delete_query . $insert_query );
359
+		rl_execute_sparql_update_query($delete_query.$insert_query);
360 360
 
361 361
 		// Advance to the next posts.
362 362
 		$offset += $limit;
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 
366 366
 }
367 367
 
368
-add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 );
368
+add_filter('flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1);
369 369
 
370 370
 /**
371 371
  * Sanitizes an URI path by replacing the non allowed characters with an underscore.
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
  *
379 379
  * @return string The sanitized path.
380 380
  */
381
-function wl_sanitize_uri_path( $path, $char = '_' ) {
381
+function wl_sanitize_uri_path($path, $char = '_') {
382 382
 
383
-	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
383
+	return Wordlift_Uri_Service::get_instance()->sanitize_path($path, $char);
384 384
 }
385 385
 
386 386
 ///**
@@ -419,107 +419,107 @@  discard block
 block discarded – undo
419 419
  *
420 420
  * @return string The updated post content.
421 421
  */
422
-function wl_replace_item_id_with_uri( $content ) {
422
+function wl_replace_item_id_with_uri($content) {
423 423
 
424 424
 	// wl_write_log( "wl_replace_item_id_with_uri" );
425 425
 
426 426
 	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
427
-	$content = stripslashes( $content );
427
+	$content = stripslashes($content);
428 428
 
429 429
 	// If any match are found.
430 430
 	$matches = array();
431
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
431
+	if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) {
432 432
 
433
-		foreach ( $matches as $match ) {
433
+		foreach ($matches as $match) {
434 434
 
435 435
 			// Get the item ID.
436 436
 			$item_id = $match[1];
437 437
 
438 438
 			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
439 439
 			$post = Wordlift_Entity_Service::get_instance()
440
-			                               ->get_entity_post_by_uri( $item_id );
440
+			                               ->get_entity_post_by_uri($item_id);
441 441
 
442 442
 			// If no entity is found, continue to the next one.
443
-			if ( null === $post ) {
443
+			if (null === $post) {
444 444
 				continue;
445 445
 			}
446 446
 
447 447
 			// Get the URI for that post.
448
-			$uri = wl_get_entity_uri( $post->ID );
448
+			$uri = wl_get_entity_uri($post->ID);
449 449
 
450 450
 			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
451 451
 
452 452
 			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
453
-			if ( $item_id !== $uri ) {
454
-				$uri_e   = esc_html( $uri );
455
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
453
+			if ($item_id !== $uri) {
454
+				$uri_e   = esc_html($uri);
455
+				$content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content);
456 456
 			}
457 457
 		}
458 458
 	}
459 459
 
460 460
 	// Reapply slashes.
461
-	$content = addslashes( $content );
461
+	$content = addslashes($content);
462 462
 
463 463
 	return $content;
464 464
 }
465 465
 
466
-add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
466
+add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1);
467 467
 
468
-require_once( 'wordlift_entity_functions.php' );
468
+require_once('wordlift_entity_functions.php');
469 469
 
470 470
 // add editor related methods.
471
-require_once( 'wordlift_editor.php' );
471
+require_once('wordlift_editor.php');
472 472
 
473 473
 // add the WordLift entity custom type.
474
-require_once( 'wordlift_entity_type.php' );
475
-require_once( 'wordlift_entity_type_taxonomy.php' );
474
+require_once('wordlift_entity_type.php');
475
+require_once('wordlift_entity_type_taxonomy.php');
476 476
 
477 477
 // add callbacks on post save to notify data changes from wp to redlink triple store
478
-require_once( 'wordlift_to_redlink_data_push_callbacks.php' );
478
+require_once('wordlift_to_redlink_data_push_callbacks.php');
479 479
 
480
-require_once( 'modules/configuration/wordlift_configuration_settings.php' );
480
+require_once('modules/configuration/wordlift_configuration_settings.php');
481 481
 
482 482
 // Load modules
483
-require_once( 'modules/analyzer/wordlift_analyzer.php' );
484
-require_once( 'modules/linked_data/wordlift_linked_data.php' );
485
-require_once( 'modules/prefixes/wordlift_prefixes.php' );
483
+require_once('modules/analyzer/wordlift_analyzer.php');
484
+require_once('modules/linked_data/wordlift_linked_data.php');
485
+require_once('modules/prefixes/wordlift_prefixes.php');
486 486
 
487 487
 // Shortcodes
488 488
 
489
-require_once( 'modules/geo_widget/wordlift_geo_widget.php' );
490
-require_once( 'shortcodes/wordlift_shortcode_chord.php' );
491
-require_once( 'shortcodes/wordlift_shortcode_geomap.php' );
492
-require_once( 'shortcodes/wordlift_shortcode_field.php' );
493
-require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' );
494
-require_once( 'shortcodes/wordlift_shortcode_navigator.php' );
489
+require_once('modules/geo_widget/wordlift_geo_widget.php');
490
+require_once('shortcodes/wordlift_shortcode_chord.php');
491
+require_once('shortcodes/wordlift_shortcode_geomap.php');
492
+require_once('shortcodes/wordlift_shortcode_field.php');
493
+require_once('shortcodes/wordlift_shortcode_faceted_search.php');
494
+require_once('shortcodes/wordlift_shortcode_navigator.php');
495 495
 
496
-require_once( 'widgets/wordlift_widget_geo.php' );
497
-require_once( 'widgets/wordlift_widget_chord.php' );
498
-require_once( 'widgets/wordlift_widget_timeline.php' );
496
+require_once('widgets/wordlift_widget_geo.php');
497
+require_once('widgets/wordlift_widget_chord.php');
498
+require_once('widgets/wordlift_widget_timeline.php');
499 499
 
500
-require_once( 'wordlift_redlink.php' );
500
+require_once('wordlift_redlink.php');
501 501
 
502 502
 // Add admin functions.
503 503
 // TODO: find a way to make 'admin' UI tests work.
504 504
 //if ( is_admin() ) {
505 505
 
506
-require_once( 'admin/wordlift_admin.php' );
507
-require_once( 'admin/wordlift_admin_edit_post.php' );
508
-require_once( 'admin/wordlift_admin_save_post.php' );
506
+require_once('admin/wordlift_admin.php');
507
+require_once('admin/wordlift_admin_edit_post.php');
508
+require_once('admin/wordlift_admin_save_post.php');
509 509
 
510 510
 // add the entities meta box.
511
-require_once( 'admin/wordlift_admin_meta_box_entities.php' );
511
+require_once('admin/wordlift_admin_meta_box_entities.php');
512 512
 
513 513
 // add the entity creation AJAX.
514
-require_once( 'admin/wordlift_admin_ajax_related_posts.php' );
514
+require_once('admin/wordlift_admin_ajax_related_posts.php');
515 515
 
516 516
 // Load the wl_chord TinyMCE button and configuration dialog.
517
-require_once( 'admin/wordlift_admin_shortcodes.php' );
517
+require_once('admin/wordlift_admin_shortcodes.php');
518 518
 
519 519
 // load languages.
520 520
 // TODO: the following call gives for granted that the plugin is in the wordlift directory,
521 521
 //       we're currently doing this because wordlift is symbolic linked.
522
-load_plugin_textdomain( 'wordlift', false, '/wordlift/languages' );
522
+load_plugin_textdomain('wordlift', false, '/wordlift/languages');
523 523
 
524 524
 
525 525
 /**
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
  * This action is documented in includes/class-wordlift-activator.php
528 528
  */
529 529
 function activate_wordlift() {
530
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
530
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
531 531
 	Wordlift_Activator::activate();
532 532
 }
533 533
 
@@ -536,18 +536,18 @@  discard block
 block discarded – undo
536 536
  * This action is documented in includes/class-wordlift-deactivator.php
537 537
  */
538 538
 function deactivate_wordlift() {
539
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
539
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
540 540
 	Wordlift_Deactivator::deactivate();
541 541
 }
542 542
 
543
-register_activation_hook( __FILE__, 'activate_wordlift' );
544
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
543
+register_activation_hook(__FILE__, 'activate_wordlift');
544
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
545 545
 
546 546
 /**
547 547
  * The core plugin class that is used to define internationalization,
548 548
  * admin-specific hooks, and public-facing site hooks.
549 549
  */
550
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
550
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
551 551
 
552 552
 /**
553 553
  * Begins execution of the plugin.
Please login to merge, or discard this patch.
src/includes/class-wordlift-content-filter-service.php 2 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -18,231 +18,231 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Content_Filter_Service {
20 20
 
21
-	/**
22
-	 * The pattern to find entities in text.
23
-	 *
24
-	 * @since 3.8.0
25
-	 */
26
-	const PATTERN = '/<(\\w+)[^<]*class="([^"]*)"\\sitemid=\"([^"]+)\"[^>]*>([^<]*)<\\/\\1>/i';
27
-
28
-	/**
29
-	 * A {@link Wordlift_Entity_Service} instance.
30
-	 *
31
-	 * @since  3.8.0
32
-	 * @access private
33
-	 * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
34
-	 */
35
-	private $entity_service;
36
-
37
-	/**
38
-	 * The {@link Wordlift_Configuration_Service} instance.
39
-	 *
40
-	 * @since  3.13.0
41
-	 * @access private
42
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
43
-	 */
44
-	private $configuration_service;
45
-
46
-	/**
47
-	 * The `link by default` setting.
48
-	 *
49
-	 * @since  3.13.0
50
-	 * @access private
51
-	 * @var bool True if link by default is enabled otherwise false.
52
-	 */
53
-	private $is_link_by_default;
54
-
55
-	/**
56
-	 * The {@link Wordlift_Content_Filter_Service} singleton instance.
57
-	 *
58
-	 * @since  3.14.2
59
-	 * @access private
60
-	 * @var \Wordlift_Content_Filter_Service $instance The {@link Wordlift_Content_Filter_Service} singleton instance.
61
-	 */
62
-	private static $instance;
63
-
64
-	/**
65
-	 * Create a {@link Wordlift_Content_Filter_Service} instance.
66
-	 *
67
-	 * @since 3.8.0
68
-	 *
69
-	 * @param \Wordlift_Entity_Service        $entity_service        The {@link Wordlift_Entity_Service} instance.
70
-	 * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
71
-	 */
72
-	public function __construct( $entity_service, $configuration_service ) {
73
-
74
-		$this->entity_service        = $entity_service;
75
-		$this->configuration_service = $configuration_service;
76
-
77
-		self::$instance = $this;
78
-
79
-	}
80
-
81
-	/**
82
-	 * Get the {@link Wordlift_Content_Filter_Service} singleton instance.
83
-	 *
84
-	 * @since 3.14.2
85
-	 * @return \Wordlift_Content_Filter_Service The {@link Wordlift_Content_Filter_Service} singleton instance.
86
-	 */
87
-	public static function get_instance() {
88
-
89
-		return self::$instance;
90
-	}
91
-
92
-	/**
93
-	 * Mangle the content by adding links to the entity pages. This function is
94
-	 * hooked to the 'the_content' WP's filter.
95
-	 *
96
-	 * @since 3.8.0
97
-	 *
98
-	 * @param string $content The content being filtered.
99
-	 *
100
-	 * @return string The filtered content.
101
-	 */
102
-	public function the_content( $content ) {
103
-
104
-		// Links should be added only on the front end and not for RSS.
105
-		if ( is_feed() ) {
106
-			return $content;
107
-		}
108
-
109
-		// Preload the `link by default` setting.
110
-		$this->is_link_by_default = $this->configuration_service->is_link_by_default();
111
-
112
-		// Replace each match of the entity tag with the entity link. If an error
113
-		// occurs fail silently returning the original content.
114
-		return preg_replace_callback( self::PATTERN, array(
115
-			$this,
116
-			'link',
117
-		), $content ) ?: $content;
118
-	}
119
-
120
-	/**
121
-	 * Get the entity match and replace it with a page link.
122
-	 *
123
-	 * @since 3.8.0
124
-	 *
125
-	 * @param array $matches An array of matches.
126
-	 *
127
-	 * @return string The replaced text with the link to the entity page.
128
-	 */
129
-	private function link( $matches ) {
130
-
131
-		// Get the entity itemid URI and label.
132
-		$css_class = $matches[2];
133
-		$uri       = $matches[3];
134
-		$label     = $matches[4];
135
-
136
-		// Get the entity post by URI.
137
-		$post = $this->entity_service->get_entity_post_by_uri( $uri );
138
-		if ( null === $post ) {
139
-
140
-			// If the entity post is not found return the label w/o the markup
141
-			// around it.
142
-			//
143
-			// See https://github.com/insideout10/wordlift-plugin/issues/461.
144
-			return $label;
145
-		}
146
-
147
-		$no_link = - 1 < strpos( $css_class, 'wl-no-link' );
148
-		$link    = - 1 < strpos( $css_class, 'wl-link' );
149
-
150
-		// Don't link if links are disabled and the entity is not link or the
151
-		// entity is do not link.
152
-		$dont_link = ( ! $this->is_link_by_default && ! $link ) || $no_link;
153
-
154
-		// Return the label if it's don't link.
155
-		if ( $dont_link ) {
156
-			return $label;
157
-		}
158
-
159
-		// Get the link.
160
-		$href = get_permalink( $post );
161
-
162
-		// Get an alternative title attribute.
163
-		$title_attribute = $this->get_title_attribute( $post->ID, $label );
164
-
165
-		// Return the link.
166
-		return "<a class='wl-entity-page-link' $title_attribute href='$href'>$label</a>";
167
-	}
168
-
169
-	/**
170
-	 * Get a `title` attribute with an alternative label for the link.
171
-	 *
172
-	 * If an alternative title isn't available an empty string is returned.
173
-	 *
174
-	 * @since 3.15.0
175
-	 *
176
-	 * @param int    $post_id The {@link WP_Post}'s id.
177
-	 * @param string $label   The main link label.
178
-	 *
179
-	 * @return string A `title` attribute with an alternative label or an empty
180
-	 *                string if none available.
181
-	 */
182
-	private function get_title_attribute( $post_id, $label ) {
183
-
184
-		// Get an alternative title.
185
-		$title = $this->get_link_title( $post_id, $label );
186
-		if ( ! empty( $title ) ) {
187
-			return 'title="' . esc_attr( $title ) . '"';
188
-		}
189
-
190
-		return '';
191
-	}
192
-
193
-	/**
194
-	 * Get a string to be used as a title attribute in links to a post
195
-	 *
196
-	 * @since 3.15.0
197
-	 *
198
-	 * @param int    $post_id      The post id of the post being linked.
199
-	 * @param string $ignore_label A label to ignore.
200
-	 *
201
-	 * @return string    The title to be used in the link. An empty string when
202
-	 *                    there is no alternative that is not the $ignore_label.
203
-	 */
204
-	function get_link_title( $post_id, $ignore_label ) {
205
-
206
-		// Get possible alternative labels we can select from.
207
-		$labels = $this->entity_service->get_alternative_labels( $post_id );
208
-
209
-		/*
21
+    /**
22
+     * The pattern to find entities in text.
23
+     *
24
+     * @since 3.8.0
25
+     */
26
+    const PATTERN = '/<(\\w+)[^<]*class="([^"]*)"\\sitemid=\"([^"]+)\"[^>]*>([^<]*)<\\/\\1>/i';
27
+
28
+    /**
29
+     * A {@link Wordlift_Entity_Service} instance.
30
+     *
31
+     * @since  3.8.0
32
+     * @access private
33
+     * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
34
+     */
35
+    private $entity_service;
36
+
37
+    /**
38
+     * The {@link Wordlift_Configuration_Service} instance.
39
+     *
40
+     * @since  3.13.0
41
+     * @access private
42
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
43
+     */
44
+    private $configuration_service;
45
+
46
+    /**
47
+     * The `link by default` setting.
48
+     *
49
+     * @since  3.13.0
50
+     * @access private
51
+     * @var bool True if link by default is enabled otherwise false.
52
+     */
53
+    private $is_link_by_default;
54
+
55
+    /**
56
+     * The {@link Wordlift_Content_Filter_Service} singleton instance.
57
+     *
58
+     * @since  3.14.2
59
+     * @access private
60
+     * @var \Wordlift_Content_Filter_Service $instance The {@link Wordlift_Content_Filter_Service} singleton instance.
61
+     */
62
+    private static $instance;
63
+
64
+    /**
65
+     * Create a {@link Wordlift_Content_Filter_Service} instance.
66
+     *
67
+     * @since 3.8.0
68
+     *
69
+     * @param \Wordlift_Entity_Service        $entity_service        The {@link Wordlift_Entity_Service} instance.
70
+     * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
71
+     */
72
+    public function __construct( $entity_service, $configuration_service ) {
73
+
74
+        $this->entity_service        = $entity_service;
75
+        $this->configuration_service = $configuration_service;
76
+
77
+        self::$instance = $this;
78
+
79
+    }
80
+
81
+    /**
82
+     * Get the {@link Wordlift_Content_Filter_Service} singleton instance.
83
+     *
84
+     * @since 3.14.2
85
+     * @return \Wordlift_Content_Filter_Service The {@link Wordlift_Content_Filter_Service} singleton instance.
86
+     */
87
+    public static function get_instance() {
88
+
89
+        return self::$instance;
90
+    }
91
+
92
+    /**
93
+     * Mangle the content by adding links to the entity pages. This function is
94
+     * hooked to the 'the_content' WP's filter.
95
+     *
96
+     * @since 3.8.0
97
+     *
98
+     * @param string $content The content being filtered.
99
+     *
100
+     * @return string The filtered content.
101
+     */
102
+    public function the_content( $content ) {
103
+
104
+        // Links should be added only on the front end and not for RSS.
105
+        if ( is_feed() ) {
106
+            return $content;
107
+        }
108
+
109
+        // Preload the `link by default` setting.
110
+        $this->is_link_by_default = $this->configuration_service->is_link_by_default();
111
+
112
+        // Replace each match of the entity tag with the entity link. If an error
113
+        // occurs fail silently returning the original content.
114
+        return preg_replace_callback( self::PATTERN, array(
115
+            $this,
116
+            'link',
117
+        ), $content ) ?: $content;
118
+    }
119
+
120
+    /**
121
+     * Get the entity match and replace it with a page link.
122
+     *
123
+     * @since 3.8.0
124
+     *
125
+     * @param array $matches An array of matches.
126
+     *
127
+     * @return string The replaced text with the link to the entity page.
128
+     */
129
+    private function link( $matches ) {
130
+
131
+        // Get the entity itemid URI and label.
132
+        $css_class = $matches[2];
133
+        $uri       = $matches[3];
134
+        $label     = $matches[4];
135
+
136
+        // Get the entity post by URI.
137
+        $post = $this->entity_service->get_entity_post_by_uri( $uri );
138
+        if ( null === $post ) {
139
+
140
+            // If the entity post is not found return the label w/o the markup
141
+            // around it.
142
+            //
143
+            // See https://github.com/insideout10/wordlift-plugin/issues/461.
144
+            return $label;
145
+        }
146
+
147
+        $no_link = - 1 < strpos( $css_class, 'wl-no-link' );
148
+        $link    = - 1 < strpos( $css_class, 'wl-link' );
149
+
150
+        // Don't link if links are disabled and the entity is not link or the
151
+        // entity is do not link.
152
+        $dont_link = ( ! $this->is_link_by_default && ! $link ) || $no_link;
153
+
154
+        // Return the label if it's don't link.
155
+        if ( $dont_link ) {
156
+            return $label;
157
+        }
158
+
159
+        // Get the link.
160
+        $href = get_permalink( $post );
161
+
162
+        // Get an alternative title attribute.
163
+        $title_attribute = $this->get_title_attribute( $post->ID, $label );
164
+
165
+        // Return the link.
166
+        return "<a class='wl-entity-page-link' $title_attribute href='$href'>$label</a>";
167
+    }
168
+
169
+    /**
170
+     * Get a `title` attribute with an alternative label for the link.
171
+     *
172
+     * If an alternative title isn't available an empty string is returned.
173
+     *
174
+     * @since 3.15.0
175
+     *
176
+     * @param int    $post_id The {@link WP_Post}'s id.
177
+     * @param string $label   The main link label.
178
+     *
179
+     * @return string A `title` attribute with an alternative label or an empty
180
+     *                string if none available.
181
+     */
182
+    private function get_title_attribute( $post_id, $label ) {
183
+
184
+        // Get an alternative title.
185
+        $title = $this->get_link_title( $post_id, $label );
186
+        if ( ! empty( $title ) ) {
187
+            return 'title="' . esc_attr( $title ) . '"';
188
+        }
189
+
190
+        return '';
191
+    }
192
+
193
+    /**
194
+     * Get a string to be used as a title attribute in links to a post
195
+     *
196
+     * @since 3.15.0
197
+     *
198
+     * @param int    $post_id      The post id of the post being linked.
199
+     * @param string $ignore_label A label to ignore.
200
+     *
201
+     * @return string    The title to be used in the link. An empty string when
202
+     *                    there is no alternative that is not the $ignore_label.
203
+     */
204
+    function get_link_title( $post_id, $ignore_label ) {
205
+
206
+        // Get possible alternative labels we can select from.
207
+        $labels = $this->entity_service->get_alternative_labels( $post_id );
208
+
209
+        /*
210 210
 		 * Since the original text might use an alternative label than the
211 211
 		 * Entity title, add the title itself which is not returned by the api.
212 212
 		 */
213
-		$labels[] = get_the_title( $post_id );
214
-
215
-		// Add some randomness to the label selection.
216
-		shuffle( $labels );
217
-
218
-		// Select the first label which is not to be ignored.
219
-		$title = '';
220
-		foreach ( $labels as $label ) {
221
-			if ( 0 !== strcasecmp( $label, $ignore_label ) ) {
222
-				$title = $label;
223
-				break;
224
-			}
225
-		}
226
-
227
-		return $title;
228
-	}
229
-
230
-	/**
231
-	 * Get the entity URIs (configured in the `itemid` attribute) contained in
232
-	 * the provided content.
233
-	 *
234
-	 * @since 3.14.2
235
-	 *
236
-	 * @param string $content The content.
237
-	 *
238
-	 * @return array An array of URIs.
239
-	 */
240
-	public function get_entity_uris( $content ) {
241
-
242
-		$matches = array();
243
-		preg_match_all( Wordlift_Content_Filter_Service::PATTERN, $content, $matches );
244
-
245
-		return array_unique( $matches[3] );
246
-	}
213
+        $labels[] = get_the_title( $post_id );
214
+
215
+        // Add some randomness to the label selection.
216
+        shuffle( $labels );
217
+
218
+        // Select the first label which is not to be ignored.
219
+        $title = '';
220
+        foreach ( $labels as $label ) {
221
+            if ( 0 !== strcasecmp( $label, $ignore_label ) ) {
222
+                $title = $label;
223
+                break;
224
+            }
225
+        }
226
+
227
+        return $title;
228
+    }
229
+
230
+    /**
231
+     * Get the entity URIs (configured in the `itemid` attribute) contained in
232
+     * the provided content.
233
+     *
234
+     * @since 3.14.2
235
+     *
236
+     * @param string $content The content.
237
+     *
238
+     * @return array An array of URIs.
239
+     */
240
+    public function get_entity_uris( $content ) {
241
+
242
+        $matches = array();
243
+        preg_match_all( Wordlift_Content_Filter_Service::PATTERN, $content, $matches );
244
+
245
+        return array_unique( $matches[3] );
246
+    }
247 247
 
248 248
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * @param \Wordlift_Entity_Service        $entity_service        The {@link Wordlift_Entity_Service} instance.
70 70
 	 * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
71 71
 	 */
72
-	public function __construct( $entity_service, $configuration_service ) {
72
+	public function __construct($entity_service, $configuration_service) {
73 73
 
74 74
 		$this->entity_service        = $entity_service;
75 75
 		$this->configuration_service = $configuration_service;
@@ -99,10 +99,10 @@  discard block
 block discarded – undo
99 99
 	 *
100 100
 	 * @return string The filtered content.
101 101
 	 */
102
-	public function the_content( $content ) {
102
+	public function the_content($content) {
103 103
 
104 104
 		// Links should be added only on the front end and not for RSS.
105
-		if ( is_feed() ) {
105
+		if (is_feed()) {
106 106
 			return $content;
107 107
 		}
108 108
 
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
 
112 112
 		// Replace each match of the entity tag with the entity link. If an error
113 113
 		// occurs fail silently returning the original content.
114
-		return preg_replace_callback( self::PATTERN, array(
114
+		return preg_replace_callback(self::PATTERN, array(
115 115
 			$this,
116 116
 			'link',
117
-		), $content ) ?: $content;
117
+		), $content) ?: $content;
118 118
 	}
119 119
 
120 120
 	/**
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 *
127 127
 	 * @return string The replaced text with the link to the entity page.
128 128
 	 */
129
-	private function link( $matches ) {
129
+	private function link($matches) {
130 130
 
131 131
 		// Get the entity itemid URI and label.
132 132
 		$css_class = $matches[2];
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 		$label     = $matches[4];
135 135
 
136 136
 		// Get the entity post by URI.
137
-		$post = $this->entity_service->get_entity_post_by_uri( $uri );
138
-		if ( null === $post ) {
137
+		$post = $this->entity_service->get_entity_post_by_uri($uri);
138
+		if (null === $post) {
139 139
 
140 140
 			// If the entity post is not found return the label w/o the markup
141 141
 			// around it.
@@ -144,23 +144,23 @@  discard block
 block discarded – undo
144 144
 			return $label;
145 145
 		}
146 146
 
147
-		$no_link = - 1 < strpos( $css_class, 'wl-no-link' );
148
-		$link    = - 1 < strpos( $css_class, 'wl-link' );
147
+		$no_link = - 1 < strpos($css_class, 'wl-no-link');
148
+		$link    = - 1 < strpos($css_class, 'wl-link');
149 149
 
150 150
 		// Don't link if links are disabled and the entity is not link or the
151 151
 		// entity is do not link.
152
-		$dont_link = ( ! $this->is_link_by_default && ! $link ) || $no_link;
152
+		$dont_link = ( ! $this->is_link_by_default && ! $link) || $no_link;
153 153
 
154 154
 		// Return the label if it's don't link.
155
-		if ( $dont_link ) {
155
+		if ($dont_link) {
156 156
 			return $label;
157 157
 		}
158 158
 
159 159
 		// Get the link.
160
-		$href = get_permalink( $post );
160
+		$href = get_permalink($post);
161 161
 
162 162
 		// Get an alternative title attribute.
163
-		$title_attribute = $this->get_title_attribute( $post->ID, $label );
163
+		$title_attribute = $this->get_title_attribute($post->ID, $label);
164 164
 
165 165
 		// Return the link.
166 166
 		return "<a class='wl-entity-page-link' $title_attribute href='$href'>$label</a>";
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
 	 * @return string A `title` attribute with an alternative label or an empty
180 180
 	 *                string if none available.
181 181
 	 */
182
-	private function get_title_attribute( $post_id, $label ) {
182
+	private function get_title_attribute($post_id, $label) {
183 183
 
184 184
 		// Get an alternative title.
185
-		$title = $this->get_link_title( $post_id, $label );
186
-		if ( ! empty( $title ) ) {
187
-			return 'title="' . esc_attr( $title ) . '"';
185
+		$title = $this->get_link_title($post_id, $label);
186
+		if ( ! empty($title)) {
187
+			return 'title="'.esc_attr($title).'"';
188 188
 		}
189 189
 
190 190
 		return '';
@@ -201,24 +201,24 @@  discard block
 block discarded – undo
201 201
 	 * @return string    The title to be used in the link. An empty string when
202 202
 	 *                    there is no alternative that is not the $ignore_label.
203 203
 	 */
204
-	function get_link_title( $post_id, $ignore_label ) {
204
+	function get_link_title($post_id, $ignore_label) {
205 205
 
206 206
 		// Get possible alternative labels we can select from.
207
-		$labels = $this->entity_service->get_alternative_labels( $post_id );
207
+		$labels = $this->entity_service->get_alternative_labels($post_id);
208 208
 
209 209
 		/*
210 210
 		 * Since the original text might use an alternative label than the
211 211
 		 * Entity title, add the title itself which is not returned by the api.
212 212
 		 */
213
-		$labels[] = get_the_title( $post_id );
213
+		$labels[] = get_the_title($post_id);
214 214
 
215 215
 		// Add some randomness to the label selection.
216
-		shuffle( $labels );
216
+		shuffle($labels);
217 217
 
218 218
 		// Select the first label which is not to be ignored.
219 219
 		$title = '';
220
-		foreach ( $labels as $label ) {
221
-			if ( 0 !== strcasecmp( $label, $ignore_label ) ) {
220
+		foreach ($labels as $label) {
221
+			if (0 !== strcasecmp($label, $ignore_label)) {
222 222
 				$title = $label;
223 223
 				break;
224 224
 			}
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
 	 *
238 238
 	 * @return array An array of URIs.
239 239
 	 */
240
-	public function get_entity_uris( $content ) {
240
+	public function get_entity_uris($content) {
241 241
 
242 242
 		$matches = array();
243
-		preg_match_all( Wordlift_Content_Filter_Service::PATTERN, $content, $matches );
243
+		preg_match_all(Wordlift_Content_Filter_Service::PATTERN, $content, $matches);
244 244
 
245
-		return array_unique( $matches[3] );
245
+		return array_unique($matches[3]);
246 246
 	}
247 247
 
248 248
 }
Please login to merge, or discard this patch.