Completed
Push — master ( d6dd65...5463c4 )
by David
02:47
created

wordlift.php ➔ wl_shutdown()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 23
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 2
nop 0
dl 0
loc 23
rs 8.7972
c 0
b 0
f 0
1
<?php
2
/**
3
 * The plugin bootstrap file
4
 *
5
 * This file is read by WordPress to generate the plugin information in the plugin
6
 * admin area. This file also includes all of the dependencies used by the plugin,
7
 * registers the activation and deactivation functions, and defines a function
8
 * that starts the plugin.
9
 *
10
 * @link              https://wordlift.io
11
 * @since             1.0.0
12
 * @package           Wordlift
13
 *
14
 * @wordpress-plugin
15
 * Plugin Name:       WordLift
16
 * Plugin URI:        https://wordlift.io
17
 * Description:       WordLift brings the power of AI to organize content, attract new readers and get their attention. To activate the plugin ​<a href="https://wordlift.io/">visit our website</a>.
18
 * Version:           3.13.2
19
 * Author:            WordLift, Insideout10
20
 * Author URI:        https://wordlift.io
21
 * License:           GPL-2.0+
22
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
23
 * Text Domain:       wordlift
24
 * Domain Path:       /languages
25
 */
26
27
// If this file is called directly, abort.
28
if ( ! defined( 'WPINC' ) ) {
29
	die;
30
}
31
32
// Include WordLift constants.
33
require_once( 'wordlift_constants.php' );
34
35
// Load modules.
36
require_once( 'modules/core/wordlift_core.php' );
37
38
/**
39
 * Log to the debug.log file.
40
 *
41
 * @deprecated use Wordlift_Log_Service::get_instance()->info( $log );
42
 *
43
 * @since      3.0.0
44
 *
45
 * @uses       wl_write_log_handler() to write the log output.
46
 *
47
 * @param string|mixed $log The log data.
48
 */
49
function wl_write_log( $log ) {
50
51
	Wordlift_Log_Service::get_instance()->info( $log );
52
53
}
54
55
/**
56
 * The default log handler prints out the log.
57
 *
58
 * @deprecated
59
 *
60
 * @since 3.0.0
61
 *
62
 * @param string|array $log    The log data.
63
 * @param string       $caller The calling function.
64
 */
65
function wl_write_log_handler( $log, $caller = null ) {
66
67
	global $wl_logger;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
68
69
	if ( true === WP_DEBUG ) {
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 ) );
0 ignored issues
show
Deprecated Code introduced by
The function wl_write_log_hide_key() has been deprecated.

This function has been deprecated.

Loading history...
73
74
		if ( isset( $wl_logger ) ) {
75
			$wl_logger->info( $message );
76
		} else {
77
			error_log( $message );
78
		}
79
80
	}
81
82
}
83
84
/**
85
 * Hide the WordLift Key from the provided text.
86
 *
87
 * @deprecated
88
 *
89
 * @since 3.0.0
90
 *
91
 * @param string $text A text that may potentially contain a WL key.
92
 *
93
 * @return string A text with the key hidden.
94
 */
95
function wl_write_log_hide_key( $text ) {
96
97
	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
0 ignored issues
show
Deprecated Code introduced by
The function wl_configuration_get_key() has been deprecated with message: use Wordlift_Configuration_Service::get_instance()->get_key()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
98
}
99
100
///**
101
// * Execute the SPARQL query from the buffer saved for the specified request id.
102
// *
103
// * @deprecated
104
// *
105
// * @param int $request_id The request ID.
106
// */
107
//function wl_execute_saved_sparql_update_query( $request_id ) {
108
//
109
//	$filename = WL_TEMP_DIR . $request_id . '.sparql';
110
//
111
//	// If the file doesn't exist, exit.
112
//	if ( ! file_exists( $filename ) ) {
113
//		wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" );
114
//
115
//		return;
116
//	}
117
//
118
//	wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" );
119
//
120
//	// Get the query saved in the file.
121
//	$query = file_get_contents( $filename );
122
//
123
//	// Execute the SPARQL query.
124
//	rl_execute_sparql_update_query( $query, false );
125
//
126
//	// Reindex the triple store.
127
//	wordlift_reindex_triple_store();
128
//
129
//	// Delete the temporary file.
130
//	unlink( $filename );
131
//}
132
//
133
//add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 );
134
135
/**
136
 * Enable microdata schema.org tagging.
137
 * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
138
 */
139
function wordlift_allowed_post_tags() {
140
	global $allowedposttags;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
141
142
	$tags           = array( 'span' );
143
	$new_attributes = array(
144
		'itemscope' => array(),
145
		'itemtype'  => array(),
146
		'itemprop'  => array(),
147
		'itemid'    => array(),
148
	);
149
150
	foreach ( $tags as $tag ) {
151
		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
152
			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
153
		}
154
	}
155
}
156
157
// init process for button control
158
//add_action( 'init', 'wordlift_buttonhooks' );
159
160
// add allowed post tags.
161
add_action( 'init', 'wordlift_allowed_post_tags' );
162
163
164
/**
165
 * Register additional scripts for the admin UI.
166
 */
167
function wordlift_admin_enqueue_scripts() {
168
169
	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
170
	wp_enqueue_script( 'wpdialogs' );
171
	wp_enqueue_style( 'wp-jquery-ui-dialog' );
172
173
	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
174
175
	wp_enqueue_script( 'jquery-ui-autocomplete' );
176
	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
177
	wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . '/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' );
178
	wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
179
	wp_enqueue_script( 'angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js' );
180
181
	// Disable auto-save for custom entity posts only
182
	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
183
		wp_dequeue_script( 'autosave' );
184
	}
185
}
186
187
add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
188
189
function wl_enqueue_scripts() {
190
	wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
191
}
192
193
add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' );
194
195
/**
196
 * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes.
197
 *
198
 * @param array  $allowedtags The array with the currently configured elements and attributes.
199
 * @param string $context     The context.
200
 *
201
 * @return array An array which contains allowed microdata attributes.
202
 */
203
function wordlift_allowed_html( $allowedtags, $context ) {
204
205
	if ( 'post' !== $context ) {
206
		return $allowedtags;
207
	}
208
209
	return array_merge_recursive( $allowedtags, array(
210
		'span' => array(
211
			'itemscope' => true,
212
			'itemtype'  => true,
213
			'itemid'    => true,
214
			'itemprop'  => true,
215
		),
216
	) );
217
}
218
219
add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
220
221
/**
222
 * Get the coordinates for the specified post ID.
223
 *
224
 * @param int $post_id The post ID.
225
 *
226
 * @return array|null An array of coordinates or null.
227
 */
228
function wl_get_coordinates( $post_id ) {
229
230
	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
231
	$longitude = wl_schema_get_value( $post_id, 'longitude' );
232
233
	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific
234
	// place on the globe:"The zero/zero point of this system is located in the
235
	// Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
236
	return array(
237
		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
238
		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
239
	);
240
}
241
242
/**
243
 * Get the modified time of the provided post. If the time is negative, return the published date.
244
 *
245
 * @param object $post A post instance.
246
 *
247
 * @return string A datetime.
248
 */
249
function wl_get_post_modified_time( $post ) {
250
251
	$date_modified = get_post_modified_time( 'c', true, $post );
252
253
	if ( '-' === substr( $date_modified, 0, 1 ) ) {
254
		return get_the_time( 'c', $post );
255
	}
256
257
	return $date_modified;
258
}
259
260
/**
261
 * Get all the images bound to a post.
262
 *
263
 * @param int $post_id The post ID.
264
 *
265
 * @return array An array of image URLs.
266
 */
267
function wl_get_image_urls( $post_id ) {
268
269
	// If there is a featured image it has the priority.
270
	$featured_image_id = get_post_thumbnail_id( $post_id );
271
	if ( is_numeric( $featured_image_id ) ) {
272
		$image_url = wp_get_attachment_url( $featured_image_id );
273
274
		return array( $image_url );
275
	}
276
277
	$images = get_children( array(
278
		'post_parent'    => $post_id,
279
		'post_type'      => 'attachment',
280
		'post_mime_type' => 'image',
281
	) );
282
283
	// Return an empty array if no image is found.
284
	if ( empty( $images ) ) {
285
		return array();
286
	}
287
288
	// Prepare the return array.
289
	$image_urls = array();
290
291
	// Collect the URLs.
292
	foreach ( $images as $attachment_id => $attachment ) {
293
		$image_url = wp_get_attachment_url( $attachment_id );
294
		// Ensure the URL isn't collected already.
295
		if ( ! in_array( $image_url, $image_urls ) ) {
296
			array_push( $image_urls, $image_url );
297
		}
298
	}
299
300
	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" );
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
301
302
	return $image_urls;
303
}
304
305
/**
306
 * Get a SPARQL fragment with schema:image predicates.
307
 *
308
 * @param string $uri     The URI subject of the statements.
309
 * @param int    $post_id The post ID.
310
 *
311
 * @return string The SPARQL fragment.
312
 */
313
function wl_get_sparql_images( $uri, $post_id ) {
314
315
	$sparql = '';
316
317
	// Get the escaped URI.
318
	$uri_e = esc_html( $uri );
319
320
	// Add SPARQL stmts to write the schema:image.
321
	$image_urls = wl_get_image_urls( $post_id );
322
	foreach ( $image_urls as $image_url ) {
323
		$image_url_esc = wl_sparql_escape_uri( $image_url );
0 ignored issues
show
Deprecated Code introduced by
The function wl_sparql_escape_uri() has been deprecated with message: use return Wordlift_Sparql_Service::get_instance()->escape_uri($string)

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
324
		$sparql        .= " <$uri_e> schema:image <$image_url_esc> . \n";
325
	}
326
327
	return $sparql;
328
}
329
330
/**
331
 * Get an attachment with the specified parent post ID and source URL.
332
 *
333
 * @param int    $parent_post_id The parent post ID.
334
 * @param string $source_url     The source URL.
335
 *
336
 * @return WP_Post|null A post instance or null if not found.
337
 */
338
function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
339
340
	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
341
342
	$posts = get_posts( array(
343
		'post_type'      => 'attachment',
344
		'posts_per_page' => 1,
345
		'post_status'    => 'any',
346
		'post_parent'    => $parent_post_id,
347
		'meta_key'       => 'wl_source_url',
348
		'meta_value'     => $source_url,
349
	) );
350
351
	// Return the found post.
352
	if ( 1 === count( $posts ) ) {
353
		return $posts[0];
354
	}
355
356
	// Return null.
357
	return null;
358
}
359
360
/**
361
 * Set the source URL.
362
 *
363
 * @param int    $post_id    The post ID.
364
 * @param string $source_url The source URL.
365
 */
366
function wl_set_source_url( $post_id, $source_url ) {
367
368
	delete_post_meta( $post_id, 'wl_source_url' );
369
	add_post_meta( $post_id, 'wl_source_url', $source_url );
370
}
371
372
373
/**
374
 * This function is called by the *flush_rewrite_rules_hard* hook. It recalculates the URI for all the posts.
375
 *
376
 * @since 3.0.0
377
 *
378
 * @uses  rl_sparql_prefixes() to get the SPARQL prefixes.
379
 * @uses  wordlift_esc_sparql() to escape the SPARQL query.
380
 * @uses  wl_get_entity_uri() to get an entity URI.
381
 * @uses  rl_execute_sparql_update_query() to post the DELETE and INSERT queries.
382
 *
383
 * @param bool $hard True if the rewrite involves configuration updates in Apache/IIS.
384
 */
385
function wl_flush_rewrite_rules_hard( $hard ) {
0 ignored issues
show
Unused Code introduced by
The parameter $hard is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
386
387
	// If WL is not yet configured, we cannot perform any update, so we exit.
388
	if ( '' === wl_configuration_get_key() ) {
0 ignored issues
show
Deprecated Code introduced by
The function wl_configuration_get_key() has been deprecated with message: use Wordlift_Configuration_Service::get_instance()->get_key()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
389
		return;
390
	}
391
392
	// Set the initial offset and limit each call to 100 posts to avoid memory errors.
393
	$offset = 0;
394
	$limit  = 100;
395
396
	// Get more posts if the number of returned posts matches the limit.
397
	while ( $limit === ( $posts = get_posts( array(
398
			'offset'      => $offset,
399
			'numberposts' => $limit,
400
			'orderby'     => 'ID',
401
			'post_type'   => 'any',
402
			'post_status' => 'publish',
403
		) ) ) ) {
404
405
		// Holds the delete part of the query.
406
		$delete_query = rl_sparql_prefixes();
407
408
		// Holds the insert part of the query.
409
		$insert_query = '';
410
411
		// Cycle in each post to build the query.
412
		foreach ( $posts as $post ) {
413
414
			// Ignore revisions.
415
			if ( wp_is_post_revision( $post->ID ) ) {
416
				continue;
417
			}
418
419
			// Get the entity URI.
420
			$s = Wordlift_Sparql_Service::escape_uri( Wordlift_Entity_Service::get_instance()
421
			                                                                 ->get_uri( $post->ID ) );
422
423
			// Get the post URL.
424
			// $url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
425
426
			// Prepare the DELETE and INSERT commands.
427
			$delete_query .= "DELETE { <$s> schema:url ?u . } WHERE  { <$s> schema:url ?u . };\n";
428
429
			$insert_query .= Wordlift_Schema_Url_Property_Service::get_instance()
430
			                                                     ->get_insert_query( $s, $post->ID );
431
432
		}
433
434
435
		// Execute the query.
436
		rl_execute_sparql_update_query( $delete_query . $insert_query );
437
438
		// Advance to the next posts.
439
		$offset += $limit;
440
441
	}
442
443
//	// Get all published posts.
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
444
//	$posts = get_posts( array(
445
//		'posts_per_page' => - 1,
446
//		'post_type'      => 'any',
447
//		'post_status'    => 'publish'
448
//	) );
449
450
}
451
452
add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 );
453
454
/**
455
 * Sanitizes an URI path by replacing the non allowed characters with an underscore.
456
 * @uses       sanitize_title() to manage not ASCII chars
457
 * @deprecated use Wordlift_Uri_Service::get_instance()->sanitize_path();
458
 * @see        https://codex.wordpress.org/Function_Reference/sanitize_title
459
 *
460
 * @param string $path The path to sanitize.
461
 * @param string $char The replacement character (by default an underscore).
462
 *
463
 * @return string The sanitized path.
464
 */
465
function wl_sanitize_uri_path( $path, $char = '_' ) {
466
467
	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
468
}
469
470
/**
471
 * Utility function to check if a variable is set and force it to be an array
472
 *
473
 * @package mixed $value Any value
474
 *
475
 * @return array Array containing $value (if $value was not an array)
476
 */
477
function wl_force_to_array( $value ) {
478
479
	if ( ! is_array( $value ) ) {
480
		return array( $value );
481
	}
482
483
	return $value;
484
}
485
486
///**
487
// * Schedule the execution of SPARQL Update queries before the WordPress look ends.
488
// */
489
//function wl_shutdown() {
490
//
491
//	// Get the filename to the temporary SPARQL file.
492
//	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
493
//
494
//	// If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
495
//	if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
496
//
497
//		// The request ID.
498
//		$args = array( WL_REQUEST_ID );
499
//
500
//		// Schedule the execution of the SPARQL query with the request ID.
501
//		wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
502
//
503
//		// Check that the request is scheduled.
504
//		$timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
505
//
506
//		// Spawn the cron.
507
//		spawn_cron();
508
//
509
//		wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
510
//	}
511
//}
512
//
513
//add_action( 'shutdown', 'wl_shutdown' );
514
515
/**
516
 * Replaces the *itemid* attributes URIs with the WordLift URIs.
517
 *
518
 * @param string $content The post content.
519
 *
520
 * @return string The updated post content.
521
 */
522
function wl_replace_item_id_with_uri( $content ) {
523
524
	// wl_write_log( "wl_replace_item_id_with_uri" );
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
525
526
	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
527
	$content = stripslashes( $content );
528
529
	// If any match are found.
530
	$matches = array();
531
	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
532
533
		foreach ( $matches as $match ) {
0 ignored issues
show
Bug introduced by
The expression $matches of type null|array<integer,array<integer,string>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
534
535
			// Get the item ID.
536
			$item_id = $match[1];
537
538
			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
539
			$post = Wordlift_Entity_Service::get_instance()
540
			                               ->get_entity_post_by_uri( $item_id );
541
542
			// If no entity is found, continue to the next one.
543
			if ( null === $post ) {
544
				continue;
545
			}
546
547
			// Get the URI for that post.
548
			$uri = wl_get_entity_uri( $post->ID );
0 ignored issues
show
Deprecated Code introduced by
The function wl_get_entity_uri() has been deprecated with message: use Wordlift_Entity_Service::get_instance()->get_uri( $post_id )

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
549
550
			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
551
552
			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
553
			if ( $item_id !== $uri ) {
554
				$uri_e   = esc_html( $uri );
555
				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
556
			}
557
		}
558
	}
559
560
	// Reapply slashes.
561
	$content = addslashes( $content );
562
563
	return $content;
564
}
565
566
add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
567
568
require_once( 'wordlift_entity_functions.php' );
569
570
// add editor related methods.
571
require_once( 'wordlift_editor.php' );
572
573
// add the WordLift entity custom type.
574
require_once( 'wordlift_entity_type.php' );
575
require_once( 'wordlift_entity_type_taxonomy.php' );
576
577
// add callbacks on post save to notify data changes from wp to redlink triple store
578
require_once( 'wordlift_to_redlink_data_push_callbacks.php' );
579
580
require_once( 'modules/configuration/wordlift_configuration_settings.php' );
581
582
// Load modules
583
require_once( 'modules/analyzer/wordlift_analyzer.php' );
584
require_once( 'modules/linked_data/wordlift_linked_data.php' );
585
require_once( 'modules/prefixes/wordlift_prefixes.php' );
586
require_once( 'modules/redirector/wordlift_redirector.php' );
587
588
// Shortcodes
589
590
require_once( 'modules/geo_widget/wordlift_geo_widget.php' );
591
require_once( 'shortcodes/wordlift_shortcode_chord.php' );
592
require_once( 'shortcodes/wordlift_shortcode_geomap.php' );
593
require_once( 'shortcodes/wordlift_shortcode_field.php' );
594
require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' );
595
require_once( 'shortcodes/wordlift_shortcode_navigator.php' );
596
597
require_once( 'widgets/wordlift_widget_geo.php' );
598
require_once( 'widgets/wordlift_widget_chord.php' );
599
require_once( 'widgets/wordlift_widget_timeline.php' );
600
601
require_once( 'wordlift_sparql.php' );
602
require_once( 'wordlift_redlink.php' );
603
604
// Add admin functions.
605
// TODO: find a way to make 'admin' UI tests work.
606
//if ( is_admin() ) {
607
608
require_once( 'admin/wordlift_admin.php' );
609
require_once( 'admin/wordlift_admin_edit_post.php' );
610
require_once( 'admin/wordlift_admin_save_post.php' );
611
612
// add the entities meta box.
613
require_once( 'admin/wordlift_admin_meta_box_entities.php' );
614
615
// add the entity creation AJAX.
616
require_once( 'admin/wordlift_admin_ajax_related_posts.php' );
617
618
// Load the wl_chord TinyMCE button and configuration dialog.
619
require_once( 'admin/wordlift_admin_shortcodes.php' );
620
621
// load languages.
622
// TODO: the following call gives for granted that the plugin is in the wordlift directory,
623
//       we're currently doing this because wordlift is symbolic linked.
624
load_plugin_textdomain( 'wordlift', false, '/wordlift/languages' );
625
626
627
/**
628
 * The code that runs during plugin activation.
629
 * This action is documented in includes/class-wordlift-activator.php
630
 */
631
function activate_wordlift() {
632
	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
633
	Wordlift_Activator::activate();
634
}
635
636
/**
637
 * The code that runs during plugin deactivation.
638
 * This action is documented in includes/class-wordlift-deactivator.php
639
 */
640
function deactivate_wordlift() {
641
	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
642
	Wordlift_Deactivator::deactivate();
643
}
644
645
register_activation_hook( __FILE__, 'activate_wordlift' );
646
register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
647
648
/**
649
 * The core plugin class that is used to define internationalization,
650
 * admin-specific hooks, and public-facing site hooks.
651
 */
652
require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
653
654
/**
655
 * Begins execution of the plugin.
656
 *
657
 * Since everything within the plugin is registered via hooks,
658
 * then kicking off the plugin from this point in the file does
659
 * not affect the page life cycle.
660
 *
661
 * @since    1.0.0
662
 */
663
function run_wordlift() {
664
665
	$plugin = new Wordlift();
666
	$plugin->run();
667
668
}
669
670
run_wordlift();
671