@@ -26,7 +26,7 @@ discard block |
||
| 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. |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | function wl_write_log( $log ) { |
| 48 | 48 | |
| 49 | - Wordlift_Log_Service::get_instance()->debug( $log ); |
|
| 49 | + Wordlift_Log_Service::get_instance()->debug( $log ); |
|
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | function wl_write_log_hide_key( $text ) { |
| 65 | 65 | |
| 66 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 66 | + return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -71,21 +71,21 @@ discard block |
||
| 71 | 71 | * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/ |
| 72 | 72 | */ |
| 73 | 73 | function wordlift_allowed_post_tags() { |
| 74 | - global $allowedposttags; |
|
| 75 | - |
|
| 76 | - $tags = array( 'span' ); |
|
| 77 | - $new_attributes = array( |
|
| 78 | - 'itemscope' => array(), |
|
| 79 | - 'itemtype' => array(), |
|
| 80 | - 'itemprop' => array(), |
|
| 81 | - 'itemid' => array(), |
|
| 82 | - ); |
|
| 83 | - |
|
| 84 | - foreach ( $tags as $tag ) { |
|
| 85 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 86 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 87 | - } |
|
| 88 | - } |
|
| 74 | + global $allowedposttags; |
|
| 75 | + |
|
| 76 | + $tags = array( 'span' ); |
|
| 77 | + $new_attributes = array( |
|
| 78 | + 'itemscope' => array(), |
|
| 79 | + 'itemtype' => array(), |
|
| 80 | + 'itemprop' => array(), |
|
| 81 | + 'itemid' => array(), |
|
| 82 | + ); |
|
| 83 | + |
|
| 84 | + foreach ( $tags as $tag ) { |
|
| 85 | + if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 86 | + $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // add allowed post tags. |
@@ -96,15 +96,15 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | function wordlift_admin_enqueue_scripts() { |
| 98 | 98 | |
| 99 | - // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
|
| 100 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 101 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 99 | + // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
|
| 100 | + wp_enqueue_script( 'wpdialogs' ); |
|
| 101 | + wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 102 | 102 | |
| 103 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 103 | + wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 104 | 104 | |
| 105 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 105 | + wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 106 | 106 | |
| 107 | - /* |
|
| 107 | + /* |
|
| 108 | 108 | * Angular isn't loaded anymore separately, it is embedded in wordlift-reloaded.js. |
| 109 | 109 | * |
| 110 | 110 | * See https://github.com/insideout10/wordlift-plugin/issues/865. |
@@ -125,10 +125,10 @@ discard block |
||
| 125 | 125 | // |
| 126 | 126 | // $log->debug( 'Registering angular scripts was ' . ( $result ? 'successful.' : 'unsuccessful.' ) ); |
| 127 | 127 | |
| 128 | - // Disable auto-save for custom entity posts only |
|
| 129 | - if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 130 | - wp_dequeue_script( 'autosave' ); |
|
| 131 | - } |
|
| 128 | + // Disable auto-save for custom entity posts only |
|
| 129 | + if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 130 | + wp_dequeue_script( 'autosave' ); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | 133 | } |
| 134 | 134 | |
@@ -153,18 +153,18 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | function wordlift_allowed_html( $allowedtags, $context ) { |
| 155 | 155 | |
| 156 | - if ( 'post' !== $context ) { |
|
| 157 | - return $allowedtags; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return array_merge_recursive( $allowedtags, array( |
|
| 161 | - 'span' => array( |
|
| 162 | - 'itemscope' => true, |
|
| 163 | - 'itemtype' => true, |
|
| 164 | - 'itemid' => true, |
|
| 165 | - 'itemprop' => true, |
|
| 166 | - ), |
|
| 167 | - ) ); |
|
| 156 | + if ( 'post' !== $context ) { |
|
| 157 | + return $allowedtags; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return array_merge_recursive( $allowedtags, array( |
|
| 161 | + 'span' => array( |
|
| 162 | + 'itemscope' => true, |
|
| 163 | + 'itemtype' => true, |
|
| 164 | + 'itemid' => true, |
|
| 165 | + 'itemprop' => true, |
|
| 166 | + ), |
|
| 167 | + ) ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
@@ -178,16 +178,16 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | function wl_get_coordinates( $post_id ) { |
| 180 | 180 | |
| 181 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 182 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 181 | + $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 182 | + $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 183 | 183 | |
| 184 | - // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
|
| 185 | - // place on the globe:"The zero/zero point of this system is located in the |
|
| 186 | - // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 187 | - return array( |
|
| 188 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 189 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 190 | - ); |
|
| 184 | + // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
|
| 185 | + // place on the globe:"The zero/zero point of this system is located in the |
|
| 186 | + // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 187 | + return array( |
|
| 188 | + 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 189 | + 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 190 | + ); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -201,9 +201,9 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | function wl_get_image_urls( $post_id ) { |
| 203 | 203 | |
| 204 | - return Wordlift_Storage_Factory::get_instance() |
|
| 205 | - ->post_images() |
|
| 206 | - ->get( $post_id ); |
|
| 204 | + return Wordlift_Storage_Factory::get_instance() |
|
| 205 | + ->post_images() |
|
| 206 | + ->get( $post_id ); |
|
| 207 | 207 | |
| 208 | 208 | // // If there is a featured image it has the priority. |
| 209 | 209 | // $featured_image_id = get_post_thumbnail_id( $post_id ); |
@@ -251,24 +251,24 @@ discard block |
||
| 251 | 251 | */ |
| 252 | 252 | function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
| 253 | 253 | |
| 254 | - // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
|
| 254 | + // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
|
| 255 | 255 | |
| 256 | - $posts = get_posts( array( |
|
| 257 | - 'post_type' => 'attachment', |
|
| 258 | - 'posts_per_page' => 1, |
|
| 259 | - 'post_status' => 'any', |
|
| 260 | - 'post_parent' => $parent_post_id, |
|
| 261 | - 'meta_key' => 'wl_source_url', |
|
| 262 | - 'meta_value' => $source_url, |
|
| 263 | - ) ); |
|
| 256 | + $posts = get_posts( array( |
|
| 257 | + 'post_type' => 'attachment', |
|
| 258 | + 'posts_per_page' => 1, |
|
| 259 | + 'post_status' => 'any', |
|
| 260 | + 'post_parent' => $parent_post_id, |
|
| 261 | + 'meta_key' => 'wl_source_url', |
|
| 262 | + 'meta_value' => $source_url, |
|
| 263 | + ) ); |
|
| 264 | 264 | |
| 265 | - // Return the found post. |
|
| 266 | - if ( 1 === count( $posts ) ) { |
|
| 267 | - return $posts[0]; |
|
| 268 | - } |
|
| 265 | + // Return the found post. |
|
| 266 | + if ( 1 === count( $posts ) ) { |
|
| 267 | + return $posts[0]; |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - // Return null. |
|
| 271 | - return null; |
|
| 270 | + // Return null. |
|
| 271 | + return null; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | function wl_set_source_url( $post_id, $source_url ) { |
| 281 | 281 | |
| 282 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 283 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 282 | + delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 283 | + add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | function wl_sanitize_uri_path( $path, $char = '_' ) { |
| 298 | 298 | |
| 299 | - return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 299 | + return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | ///** |
@@ -337,47 +337,47 @@ discard block |
||
| 337 | 337 | */ |
| 338 | 338 | function wl_replace_item_id_with_uri( $content ) { |
| 339 | 339 | |
| 340 | - $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' ); |
|
| 341 | - $log->trace( 'Replacing item IDs with URIs...' ); |
|
| 340 | + $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' ); |
|
| 341 | + $log->trace( 'Replacing item IDs with URIs...' ); |
|
| 342 | 342 | |
| 343 | - // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
|
| 344 | - $content = stripslashes( $content ); |
|
| 343 | + // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
|
| 344 | + $content = stripslashes( $content ); |
|
| 345 | 345 | |
| 346 | - // If any match are found. |
|
| 347 | - $matches = array(); |
|
| 348 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 346 | + // If any match are found. |
|
| 347 | + $matches = array(); |
|
| 348 | + if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 349 | 349 | |
| 350 | - foreach ( $matches as $match ) { |
|
| 350 | + foreach ( $matches as $match ) { |
|
| 351 | 351 | |
| 352 | - // Get the item ID. |
|
| 353 | - $item_id = $match[1]; |
|
| 352 | + // Get the item ID. |
|
| 353 | + $item_id = $match[1]; |
|
| 354 | 354 | |
| 355 | - // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
|
| 356 | - $post = Wordlift_Entity_Service::get_instance() |
|
| 357 | - ->get_entity_post_by_uri( $item_id ); |
|
| 355 | + // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
|
| 356 | + $post = Wordlift_Entity_Service::get_instance() |
|
| 357 | + ->get_entity_post_by_uri( $item_id ); |
|
| 358 | 358 | |
| 359 | - // If no entity is found, continue to the next one. |
|
| 360 | - if ( null === $post ) { |
|
| 361 | - continue; |
|
| 362 | - } |
|
| 359 | + // If no entity is found, continue to the next one. |
|
| 360 | + if ( null === $post ) { |
|
| 361 | + continue; |
|
| 362 | + } |
|
| 363 | 363 | |
| 364 | - // Get the URI for that post. |
|
| 365 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 364 | + // Get the URI for that post. |
|
| 365 | + $uri = wl_get_entity_uri( $post->ID ); |
|
| 366 | 366 | |
| 367 | - // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
|
| 367 | + // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
|
| 368 | 368 | |
| 369 | - // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
|
| 370 | - if ( $item_id !== $uri ) { |
|
| 371 | - $uri_e = esc_html( $uri ); |
|
| 372 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - } |
|
| 369 | + // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
|
| 370 | + if ( $item_id !== $uri ) { |
|
| 371 | + $uri_e = esc_html( $uri ); |
|
| 372 | + $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | - // Reapply slashes. |
|
| 378 | - $content = addslashes( $content ); |
|
| 377 | + // Reapply slashes. |
|
| 378 | + $content = addslashes( $content ); |
|
| 379 | 379 | |
| 380 | - return $content; |
|
| 380 | + return $content; |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
@@ -438,24 +438,24 @@ discard block |
||
| 438 | 438 | */ |
| 439 | 439 | function activate_wordlift() { |
| 440 | 440 | |
| 441 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 441 | + $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 442 | 442 | |
| 443 | - $log->info( 'Activating WordLift...' ); |
|
| 443 | + $log->info( 'Activating WordLift...' ); |
|
| 444 | 444 | |
| 445 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 446 | - Wordlift_Activator::activate(); |
|
| 445 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 446 | + Wordlift_Activator::activate(); |
|
| 447 | 447 | |
| 448 | - /** |
|
| 449 | - * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
| 450 | - * |
|
| 451 | - * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
| 452 | - * @since 3.19.2 |
|
| 453 | - */ |
|
| 454 | - Wordlift_Http_Api::activate(); |
|
| 448 | + /** |
|
| 449 | + * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
| 450 | + * |
|
| 451 | + * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
| 452 | + * @since 3.19.2 |
|
| 453 | + */ |
|
| 454 | + Wordlift_Http_Api::activate(); |
|
| 455 | 455 | |
| 456 | - // Ensure the post type is registered before flushing the rewrite rules. |
|
| 457 | - Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 458 | - flush_rewrite_rules(); |
|
| 456 | + // Ensure the post type is registered before flushing the rewrite rules. |
|
| 457 | + Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 458 | + flush_rewrite_rules(); |
|
| 459 | 459 | |
| 460 | 460 | } |
| 461 | 461 | |
@@ -465,10 +465,10 @@ discard block |
||
| 465 | 465 | */ |
| 466 | 466 | function deactivate_wordlift() { |
| 467 | 467 | |
| 468 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 469 | - Wordlift_Deactivator::deactivate(); |
|
| 470 | - Wordlift_Http_Api::deactivate(); |
|
| 471 | - flush_rewrite_rules(); |
|
| 468 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 469 | + Wordlift_Deactivator::deactivate(); |
|
| 470 | + Wordlift_Http_Api::deactivate(); |
|
| 471 | + flush_rewrite_rules(); |
|
| 472 | 472 | |
| 473 | 473 | } |
| 474 | 474 | |
@@ -492,8 +492,8 @@ discard block |
||
| 492 | 492 | */ |
| 493 | 493 | function run_wordlift() { |
| 494 | 494 | |
| 495 | - $plugin = new Wordlift(); |
|
| 496 | - $plugin->run(); |
|
| 495 | + $plugin = new Wordlift(); |
|
| 496 | + $plugin->run(); |
|
| 497 | 497 | |
| 498 | 498 | } |
| 499 | 499 | |
@@ -25,15 +25,15 @@ discard block |
||
| 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. |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @param string|mixed $log The log data. |
| 46 | 46 | */ |
| 47 | -function wl_write_log( $log ) { |
|
| 47 | +function wl_write_log($log) { |
|
| 48 | 48 | |
| 49 | - Wordlift_Log_Service::get_instance()->debug( $log ); |
|
| 49 | + Wordlift_Log_Service::get_instance()->debug($log); |
|
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return string A text with the key hidden. |
| 63 | 63 | */ |
| 64 | -function wl_write_log_hide_key( $text ) { |
|
| 64 | +function wl_write_log_hide_key($text) { |
|
| 65 | 65 | |
| 66 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 66 | + return str_ireplace(wl_configuration_get_key(), '<hidden>', $text); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | function wordlift_allowed_post_tags() { |
| 74 | 74 | global $allowedposttags; |
| 75 | 75 | |
| 76 | - $tags = array( 'span' ); |
|
| 76 | + $tags = array('span'); |
|
| 77 | 77 | $new_attributes = array( |
| 78 | 78 | 'itemscope' => array(), |
| 79 | 79 | 'itemtype' => array(), |
@@ -81,15 +81,15 @@ discard block |
||
| 81 | 81 | 'itemid' => array(), |
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | - foreach ( $tags as $tag ) { |
|
| 85 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 86 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 84 | + foreach ($tags as $tag) { |
|
| 85 | + if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) { |
|
| 86 | + $allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // add allowed post tags. |
| 92 | -add_action( 'init', 'wordlift_allowed_post_tags' ); |
|
| 92 | +add_action('init', 'wordlift_allowed_post_tags'); |
|
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * Register additional scripts for the admin UI. |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | function wordlift_admin_enqueue_scripts() { |
| 98 | 98 | |
| 99 | 99 | // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
| 100 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 101 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 100 | + wp_enqueue_script('wpdialogs'); |
|
| 101 | + wp_enqueue_style('wp-jquery-ui-dialog'); |
|
| 102 | 102 | |
| 103 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 103 | + wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css'); |
|
| 104 | 104 | |
| 105 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 105 | + wp_enqueue_script('jquery-ui-autocomplete'); |
|
| 106 | 106 | |
| 107 | 107 | /* |
| 108 | 108 | * Angular isn't loaded anymore separately, it is embedded in wordlift-reloaded.js. |
@@ -126,13 +126,13 @@ discard block |
||
| 126 | 126 | // $log->debug( 'Registering angular scripts was ' . ( $result ? 'successful.' : 'unsuccessful.' ) ); |
| 127 | 127 | |
| 128 | 128 | // Disable auto-save for custom entity posts only |
| 129 | - if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 130 | - wp_dequeue_script( 'autosave' ); |
|
| 129 | + if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) { |
|
| 130 | + wp_dequeue_script('autosave'); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | -add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' ); |
|
| 135 | +add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts'); |
|
| 136 | 136 | |
| 137 | 137 | // We shouldn't load the wordlift-ui.min.css stylesheet when not needed. |
| 138 | 138 | // |
@@ -151,23 +151,23 @@ discard block |
||
| 151 | 151 | * |
| 152 | 152 | * @return array An array which contains allowed microdata attributes. |
| 153 | 153 | */ |
| 154 | -function wordlift_allowed_html( $allowedtags, $context ) { |
|
| 154 | +function wordlift_allowed_html($allowedtags, $context) { |
|
| 155 | 155 | |
| 156 | - if ( 'post' !== $context ) { |
|
| 156 | + if ('post' !== $context) { |
|
| 157 | 157 | return $allowedtags; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - return array_merge_recursive( $allowedtags, array( |
|
| 160 | + return array_merge_recursive($allowedtags, array( |
|
| 161 | 161 | 'span' => array( |
| 162 | 162 | 'itemscope' => true, |
| 163 | 163 | 'itemtype' => true, |
| 164 | 164 | 'itemid' => true, |
| 165 | 165 | 'itemprop' => true, |
| 166 | 166 | ), |
| 167 | - ) ); |
|
| 167 | + )); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | -add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
|
| 170 | +add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2); |
|
| 171 | 171 | |
| 172 | 172 | /** |
| 173 | 173 | * Get the coordinates for the specified post ID. |
@@ -176,17 +176,17 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @return array|null An array of coordinates or null. |
| 178 | 178 | */ |
| 179 | -function wl_get_coordinates( $post_id ) { |
|
| 179 | +function wl_get_coordinates($post_id) { |
|
| 180 | 180 | |
| 181 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 182 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 181 | + $latitude = wl_schema_get_value($post_id, 'latitude'); |
|
| 182 | + $longitude = wl_schema_get_value($post_id, 'longitude'); |
|
| 183 | 183 | |
| 184 | 184 | // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
| 185 | 185 | // place on the globe:"The zero/zero point of this system is located in the |
| 186 | 186 | // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
| 187 | 187 | return array( |
| 188 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 189 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 188 | + 'latitude' => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '', |
|
| 189 | + 'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '', |
|
| 190 | 190 | ); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @return array An array of image URLs. |
| 201 | 201 | */ |
| 202 | -function wl_get_image_urls( $post_id ) { |
|
| 202 | +function wl_get_image_urls($post_id) { |
|
| 203 | 203 | |
| 204 | 204 | return Wordlift_Storage_Factory::get_instance() |
| 205 | 205 | ->post_images() |
| 206 | - ->get( $post_id ); |
|
| 206 | + ->get($post_id); |
|
| 207 | 207 | |
| 208 | 208 | // // If there is a featured image it has the priority. |
| 209 | 209 | // $featured_image_id = get_post_thumbnail_id( $post_id ); |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * |
| 250 | 250 | * @return WP_Post|null A post instance or null if not found. |
| 251 | 251 | */ |
| 252 | -function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
|
| 252 | +function wl_get_attachment_for_source_url($parent_post_id, $source_url) { |
|
| 253 | 253 | |
| 254 | 254 | // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
| 255 | 255 | |
| 256 | - $posts = get_posts( array( |
|
| 256 | + $posts = get_posts(array( |
|
| 257 | 257 | 'post_type' => 'attachment', |
| 258 | 258 | 'posts_per_page' => 1, |
| 259 | 259 | 'post_status' => 'any', |
| 260 | 260 | 'post_parent' => $parent_post_id, |
| 261 | 261 | 'meta_key' => 'wl_source_url', |
| 262 | 262 | 'meta_value' => $source_url, |
| 263 | - ) ); |
|
| 263 | + )); |
|
| 264 | 264 | |
| 265 | 265 | // Return the found post. |
| 266 | - if ( 1 === count( $posts ) ) { |
|
| 266 | + if (1 === count($posts)) { |
|
| 267 | 267 | return $posts[0]; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -277,10 +277,10 @@ discard block |
||
| 277 | 277 | * @param int $post_id The post ID. |
| 278 | 278 | * @param string $source_url The source URL. |
| 279 | 279 | */ |
| 280 | -function wl_set_source_url( $post_id, $source_url ) { |
|
| 280 | +function wl_set_source_url($post_id, $source_url) { |
|
| 281 | 281 | |
| 282 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 283 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 282 | + delete_post_meta($post_id, 'wl_source_url'); |
|
| 283 | + add_post_meta($post_id, 'wl_source_url', $source_url); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -294,9 +294,9 @@ discard block |
||
| 294 | 294 | * |
| 295 | 295 | * @return string The sanitized path. |
| 296 | 296 | */ |
| 297 | -function wl_sanitize_uri_path( $path, $char = '_' ) { |
|
| 297 | +function wl_sanitize_uri_path($path, $char = '_') { |
|
| 298 | 298 | |
| 299 | - return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 299 | + return Wordlift_Uri_Service::get_instance()->sanitize_path($path, $char); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | ///** |
@@ -335,102 +335,102 @@ discard block |
||
| 335 | 335 | * |
| 336 | 336 | * @return string The updated post content. |
| 337 | 337 | */ |
| 338 | -function wl_replace_item_id_with_uri( $content ) { |
|
| 338 | +function wl_replace_item_id_with_uri($content) { |
|
| 339 | 339 | |
| 340 | - $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' ); |
|
| 341 | - $log->trace( 'Replacing item IDs with URIs...' ); |
|
| 340 | + $log = Wordlift_Log_Service::get_logger('wl_replace_item_id_with_uri'); |
|
| 341 | + $log->trace('Replacing item IDs with URIs...'); |
|
| 342 | 342 | |
| 343 | 343 | // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
| 344 | - $content = stripslashes( $content ); |
|
| 344 | + $content = stripslashes($content); |
|
| 345 | 345 | |
| 346 | 346 | // If any match are found. |
| 347 | 347 | $matches = array(); |
| 348 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 348 | + if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) { |
|
| 349 | 349 | |
| 350 | - foreach ( $matches as $match ) { |
|
| 350 | + foreach ($matches as $match) { |
|
| 351 | 351 | |
| 352 | 352 | // Get the item ID. |
| 353 | 353 | $item_id = $match[1]; |
| 354 | 354 | |
| 355 | 355 | // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
| 356 | 356 | $post = Wordlift_Entity_Service::get_instance() |
| 357 | - ->get_entity_post_by_uri( $item_id ); |
|
| 357 | + ->get_entity_post_by_uri($item_id); |
|
| 358 | 358 | |
| 359 | 359 | // If no entity is found, continue to the next one. |
| 360 | - if ( null === $post ) { |
|
| 360 | + if (null === $post) { |
|
| 361 | 361 | continue; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Get the URI for that post. |
| 365 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 365 | + $uri = wl_get_entity_uri($post->ID); |
|
| 366 | 366 | |
| 367 | 367 | // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
| 368 | 368 | |
| 369 | 369 | // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
| 370 | - if ( $item_id !== $uri ) { |
|
| 371 | - $uri_e = esc_html( $uri ); |
|
| 372 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 370 | + if ($item_id !== $uri) { |
|
| 371 | + $uri_e = esc_html($uri); |
|
| 372 | + $content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content); |
|
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // Reapply slashes. |
| 378 | - $content = addslashes( $content ); |
|
| 378 | + $content = addslashes($content); |
|
| 379 | 379 | |
| 380 | 380 | return $content; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | -add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
|
| 383 | +add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1); |
|
| 384 | 384 | |
| 385 | -require_once( 'wordlift_entity_functions.php' ); |
|
| 385 | +require_once('wordlift_entity_functions.php'); |
|
| 386 | 386 | |
| 387 | 387 | // add editor related methods. |
| 388 | -require_once( 'wordlift_editor.php' ); |
|
| 388 | +require_once('wordlift_editor.php'); |
|
| 389 | 389 | |
| 390 | 390 | // add the WordLift entity custom type. |
| 391 | -require_once( 'wordlift_entity_type.php' ); |
|
| 391 | +require_once('wordlift_entity_type.php'); |
|
| 392 | 392 | |
| 393 | 393 | // add callbacks on post save to notify data changes from wp to redlink triple store |
| 394 | -require_once( 'wordlift_to_redlink_data_push_callbacks.php' ); |
|
| 394 | +require_once('wordlift_to_redlink_data_push_callbacks.php'); |
|
| 395 | 395 | |
| 396 | -require_once( 'modules/configuration/wordlift_configuration_settings.php' ); |
|
| 396 | +require_once('modules/configuration/wordlift_configuration_settings.php'); |
|
| 397 | 397 | |
| 398 | 398 | // Load modules |
| 399 | -require_once( 'modules/analyzer/wordlift_analyzer.php' ); |
|
| 400 | -require_once( 'modules/linked_data/wordlift_linked_data.php' ); |
|
| 401 | -require_once( 'modules/prefixes/wordlift_prefixes.php' ); |
|
| 399 | +require_once('modules/analyzer/wordlift_analyzer.php'); |
|
| 400 | +require_once('modules/linked_data/wordlift_linked_data.php'); |
|
| 401 | +require_once('modules/prefixes/wordlift_prefixes.php'); |
|
| 402 | 402 | |
| 403 | 403 | // Shortcodes |
| 404 | 404 | |
| 405 | -require_once( 'modules/geo_widget/wordlift_geo_widget.php' ); |
|
| 406 | -require_once( 'shortcodes/wordlift_shortcode_chord.php' ); |
|
| 407 | -require_once( 'shortcodes/wordlift_shortcode_geomap.php' ); |
|
| 408 | -require_once( 'shortcodes/wordlift_shortcode_field.php' ); |
|
| 409 | -require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' ); |
|
| 410 | -require_once( 'shortcodes/wordlift_shortcode_navigator.php' ); |
|
| 405 | +require_once('modules/geo_widget/wordlift_geo_widget.php'); |
|
| 406 | +require_once('shortcodes/wordlift_shortcode_chord.php'); |
|
| 407 | +require_once('shortcodes/wordlift_shortcode_geomap.php'); |
|
| 408 | +require_once('shortcodes/wordlift_shortcode_field.php'); |
|
| 409 | +require_once('shortcodes/wordlift_shortcode_faceted_search.php'); |
|
| 410 | +require_once('shortcodes/wordlift_shortcode_navigator.php'); |
|
| 411 | 411 | |
| 412 | -require_once( 'widgets/wordlift_widget_geo.php' ); |
|
| 413 | -require_once( 'widgets/class-wordlift-chord-widget.php' ); |
|
| 414 | -require_once( 'widgets/wordlift_widget_timeline.php' ); |
|
| 412 | +require_once('widgets/wordlift_widget_geo.php'); |
|
| 413 | +require_once('widgets/class-wordlift-chord-widget.php'); |
|
| 414 | +require_once('widgets/wordlift_widget_timeline.php'); |
|
| 415 | 415 | |
| 416 | -require_once( 'wordlift_redlink.php' ); |
|
| 416 | +require_once('wordlift_redlink.php'); |
|
| 417 | 417 | |
| 418 | 418 | // Add admin functions. |
| 419 | 419 | // TODO: find a way to make 'admin' UI tests work. |
| 420 | 420 | //if ( is_admin() ) { |
| 421 | 421 | |
| 422 | -require_once( 'admin/wordlift_admin.php' ); |
|
| 423 | -require_once( 'admin/wordlift_admin_edit_post.php' ); |
|
| 424 | -require_once( 'admin/wordlift_admin_save_post.php' ); |
|
| 422 | +require_once('admin/wordlift_admin.php'); |
|
| 423 | +require_once('admin/wordlift_admin_edit_post.php'); |
|
| 424 | +require_once('admin/wordlift_admin_save_post.php'); |
|
| 425 | 425 | |
| 426 | 426 | // add the entities meta box. |
| 427 | -require_once( 'admin/wordlift_admin_meta_box_entities.php' ); |
|
| 427 | +require_once('admin/wordlift_admin_meta_box_entities.php'); |
|
| 428 | 428 | |
| 429 | 429 | // add the entity creation AJAX. |
| 430 | -require_once( 'admin/wordlift_admin_ajax_related_posts.php' ); |
|
| 430 | +require_once('admin/wordlift_admin_ajax_related_posts.php'); |
|
| 431 | 431 | |
| 432 | 432 | // Load the wl_chord TinyMCE button and configuration dialog. |
| 433 | -require_once( 'admin/wordlift_admin_shortcodes.php' ); |
|
| 433 | +require_once('admin/wordlift_admin_shortcodes.php'); |
|
| 434 | 434 | |
| 435 | 435 | /** |
| 436 | 436 | * The code that runs during plugin activation. |
@@ -438,11 +438,11 @@ discard block |
||
| 438 | 438 | */ |
| 439 | 439 | function activate_wordlift() { |
| 440 | 440 | |
| 441 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 441 | + $log = Wordlift_Log_Service::get_logger('activate_wordlift'); |
|
| 442 | 442 | |
| 443 | - $log->info( 'Activating WordLift...' ); |
|
| 443 | + $log->info('Activating WordLift...'); |
|
| 444 | 444 | |
| 445 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 445 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
| 446 | 446 | Wordlift_Activator::activate(); |
| 447 | 447 | |
| 448 | 448 | /** |
@@ -465,21 +465,21 @@ discard block |
||
| 465 | 465 | */ |
| 466 | 466 | function deactivate_wordlift() { |
| 467 | 467 | |
| 468 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 468 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
| 469 | 469 | Wordlift_Deactivator::deactivate(); |
| 470 | 470 | Wordlift_Http_Api::deactivate(); |
| 471 | 471 | flush_rewrite_rules(); |
| 472 | 472 | |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
| 476 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
| 475 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
| 476 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
| 477 | 477 | |
| 478 | 478 | /** |
| 479 | 479 | * The core plugin class that is used to define internationalization, |
| 480 | 480 | * admin-specific hooks, and public-facing site hooks. |
| 481 | 481 | */ |
| 482 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
| 482 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
| 483 | 483 | |
| 484 | 484 | /** |
| 485 | 485 | * Begins execution of the plugin. |
@@ -18,82 +18,82 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Post_Edit_Page { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The {@link Wordlift} plugin instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.11.0 |
|
| 25 | - * |
|
| 26 | - * @var \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
| 27 | - */ |
|
| 28 | - private $plugin; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * A {@link Wordlift_Log_Service} instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.15.4 |
|
| 34 | - * |
|
| 35 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 36 | - */ |
|
| 37 | - private $log; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Create the {@link Wordlift_Admin_Post_Edit_Page} instance. |
|
| 41 | - * |
|
| 42 | - * @since 3.11.0 |
|
| 43 | - * |
|
| 44 | - * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
| 45 | - */ |
|
| 46 | - function __construct( $plugin ) { |
|
| 47 | - |
|
| 48 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 49 | - |
|
| 50 | - // Bail out if we're in the UX Builder editor. |
|
| 51 | - if ( $this->is_ux_builder_editor() ) { |
|
| 52 | - $this->log->info( 'WordLift will not show, since we are in UX Builder editor.' ); |
|
| 53 | - |
|
| 54 | - return; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - // Define the callback. |
|
| 58 | - $callback = array( $this, 'enqueue_scripts', ); |
|
| 59 | - |
|
| 60 | - // Set a hook to enqueue scripts only when the edit page is displayed. |
|
| 61 | - add_action( 'admin_print_scripts-post.php', $callback ); |
|
| 62 | - add_action( 'admin_print_scripts-post-new.php', $callback ); |
|
| 63 | - |
|
| 64 | - $this->plugin = $plugin; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Check if we're in UX builder. |
|
| 69 | - * |
|
| 70 | - * @see https://github.com/insideout10/wordlift-plugin/issues/691 |
|
| 71 | - * |
|
| 72 | - * @since 3.15.4 |
|
| 73 | - * |
|
| 74 | - * @return bool True if we're in UX builder, otherwise false. |
|
| 75 | - */ |
|
| 76 | - private function is_ux_builder_editor() { |
|
| 77 | - |
|
| 78 | - return function_exists( 'ux_builder_is_editor' ) |
|
| 79 | - && ux_builder_is_editor(); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Enqueue scripts and styles for the edit page. |
|
| 84 | - * |
|
| 85 | - * @since 3.11.0 |
|
| 86 | - */ |
|
| 87 | - public function enqueue_scripts() { |
|
| 88 | - |
|
| 89 | - // Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen. |
|
| 90 | - // |
|
| 91 | - // @see https://github.com/insideout10/wordlift-plugin/issues/832 |
|
| 92 | - wp_dequeue_script( 'ontrapagesAngular' ); |
|
| 93 | - wp_dequeue_script( 'ontrapagesApp' ); |
|
| 94 | - wp_dequeue_script( 'ontrapagesController' ); |
|
| 95 | - |
|
| 96 | - /* |
|
| 21 | + /** |
|
| 22 | + * The {@link Wordlift} plugin instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.11.0 |
|
| 25 | + * |
|
| 26 | + * @var \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
| 27 | + */ |
|
| 28 | + private $plugin; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * A {@link Wordlift_Log_Service} instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.15.4 |
|
| 34 | + * |
|
| 35 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 36 | + */ |
|
| 37 | + private $log; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Create the {@link Wordlift_Admin_Post_Edit_Page} instance. |
|
| 41 | + * |
|
| 42 | + * @since 3.11.0 |
|
| 43 | + * |
|
| 44 | + * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
| 45 | + */ |
|
| 46 | + function __construct( $plugin ) { |
|
| 47 | + |
|
| 48 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 49 | + |
|
| 50 | + // Bail out if we're in the UX Builder editor. |
|
| 51 | + if ( $this->is_ux_builder_editor() ) { |
|
| 52 | + $this->log->info( 'WordLift will not show, since we are in UX Builder editor.' ); |
|
| 53 | + |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + // Define the callback. |
|
| 58 | + $callback = array( $this, 'enqueue_scripts', ); |
|
| 59 | + |
|
| 60 | + // Set a hook to enqueue scripts only when the edit page is displayed. |
|
| 61 | + add_action( 'admin_print_scripts-post.php', $callback ); |
|
| 62 | + add_action( 'admin_print_scripts-post-new.php', $callback ); |
|
| 63 | + |
|
| 64 | + $this->plugin = $plugin; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Check if we're in UX builder. |
|
| 69 | + * |
|
| 70 | + * @see https://github.com/insideout10/wordlift-plugin/issues/691 |
|
| 71 | + * |
|
| 72 | + * @since 3.15.4 |
|
| 73 | + * |
|
| 74 | + * @return bool True if we're in UX builder, otherwise false. |
|
| 75 | + */ |
|
| 76 | + private function is_ux_builder_editor() { |
|
| 77 | + |
|
| 78 | + return function_exists( 'ux_builder_is_editor' ) |
|
| 79 | + && ux_builder_is_editor(); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Enqueue scripts and styles for the edit page. |
|
| 84 | + * |
|
| 85 | + * @since 3.11.0 |
|
| 86 | + */ |
|
| 87 | + public function enqueue_scripts() { |
|
| 88 | + |
|
| 89 | + // Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen. |
|
| 90 | + // |
|
| 91 | + // @see https://github.com/insideout10/wordlift-plugin/issues/832 |
|
| 92 | + wp_dequeue_script( 'ontrapagesAngular' ); |
|
| 93 | + wp_dequeue_script( 'ontrapagesApp' ); |
|
| 94 | + wp_dequeue_script( 'ontrapagesController' ); |
|
| 95 | + |
|
| 96 | + /* |
|
| 97 | 97 | * Enqueue the edit screen JavaScript. The `wordlift-admin.bundle.js` file |
| 98 | 98 | * is scheduled to replace the older `wordlift-admin.min.js` once client-side |
| 99 | 99 | * code is properly refactored. |
@@ -102,33 +102,33 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @since 3.20.0 edit.js has been migrated to the new webpack configuration. |
| 104 | 104 | */ |
| 105 | - // plugin_dir_url( __FILE__ ) . 'js/1/edit.js' |
|
| 106 | - $script_name = plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/edit'; |
|
| 107 | - wp_enqueue_script( |
|
| 108 | - 'wordlift-admin-edit-page', "$script_name.js", |
|
| 109 | - array( |
|
| 110 | - $this->plugin->get_plugin_name(), |
|
| 111 | - 'jquery', |
|
| 112 | - // Require wp.ajax. |
|
| 113 | - 'wp-util', |
|
| 114 | - /* |
|
| 105 | + // plugin_dir_url( __FILE__ ) . 'js/1/edit.js' |
|
| 106 | + $script_name = plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/edit'; |
|
| 107 | + wp_enqueue_script( |
|
| 108 | + 'wordlift-admin-edit-page', "$script_name.js", |
|
| 109 | + array( |
|
| 110 | + $this->plugin->get_plugin_name(), |
|
| 111 | + 'jquery', |
|
| 112 | + // Require wp.ajax. |
|
| 113 | + 'wp-util', |
|
| 114 | + /* |
|
| 115 | 115 | * Angular isn't loaded anymore remotely, but it is loaded within wordlift-reloaded.js. |
| 116 | 116 | * |
| 117 | 117 | * See https://github.com/insideout10/wordlift-plugin/issues/865. |
| 118 | 118 | * |
| 119 | 119 | * @since 3.19.6 |
| 120 | 120 | */ |
| 121 | - // // Require Angular. |
|
| 122 | - // 'wl-angular', |
|
| 123 | - // 'wl-angular-geolocation', |
|
| 124 | - // 'wl-angular-touch', |
|
| 125 | - // 'wl-angular-animate', |
|
| 126 | - ), |
|
| 127 | - $this->plugin->get_version(), |
|
| 128 | - false |
|
| 129 | - ); |
|
| 130 | - wp_enqueue_style( 'wordlift-admin-edit-page', "$script_name.css", array(), $this->plugin->get_version() ); |
|
| 131 | - |
|
| 132 | - } |
|
| 121 | + // // Require Angular. |
|
| 122 | + // 'wl-angular', |
|
| 123 | + // 'wl-angular-geolocation', |
|
| 124 | + // 'wl-angular-touch', |
|
| 125 | + // 'wl-angular-animate', |
|
| 126 | + ), |
|
| 127 | + $this->plugin->get_version(), |
|
| 128 | + false |
|
| 129 | + ); |
|
| 130 | + wp_enqueue_style( 'wordlift-admin-edit-page', "$script_name.css", array(), $this->plugin->get_version() ); |
|
| 131 | + |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | 134 | } |
@@ -16,211 +16,211 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_File_Cache_Service implements Wordlift_Cache_Service { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The cache directory. |
|
| 21 | - * |
|
| 22 | - * @since 3.16.0 |
|
| 23 | - * @access private |
|
| 24 | - * @var string $cache_dir The root cache directory (ending with a trailing slash). |
|
| 25 | - */ |
|
| 26 | - private $cache_dir; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * The file extension for cache files (e.g. `.wlcache`). |
|
| 30 | - * |
|
| 31 | - * @since 3.16.0 |
|
| 32 | - * @access private |
|
| 33 | - * @var string $file_extension The file extension for cache files (e.g. `.wlcache`). |
|
| 34 | - */ |
|
| 35 | - private $file_extension; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * A {@link Wordlift_Log_Service} instance. |
|
| 39 | - * |
|
| 40 | - * @since 3.16.0 |
|
| 41 | - * @access private |
|
| 42 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 43 | - */ |
|
| 44 | - private $log; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * The {@link Wordlift_File_Cache_Service} registered instances. |
|
| 48 | - * |
|
| 49 | - * Each {@link Wordlift_File_Cache_Service} adds itself to the registered |
|
| 50 | - * instances. |
|
| 51 | - * |
|
| 52 | - * @since 3.16.3 |
|
| 53 | - * @access private |
|
| 54 | - * @var array $instances An array of {@link Wordlift_File_Cache_Service} instances. |
|
| 55 | - */ |
|
| 56 | - private static $instances = array(); |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Create a {@link Wordlift_File_Cache_Service} instance. |
|
| 60 | - * |
|
| 61 | - * The File Cache Service requires a base cache directory (to which a unique |
|
| 62 | - * id for the current site will be appended) and a file extension for cache |
|
| 63 | - * files (by default `.wlcache`) is used. |
|
| 64 | - * |
|
| 65 | - * @since 3.16.0 |
|
| 66 | - * |
|
| 67 | - * @param string $cache_dir The base cache directory. |
|
| 68 | - * @param string $file_extension The file extension, by default `.wlcache`. |
|
| 69 | - */ |
|
| 70 | - public function __construct( $cache_dir, $file_extension = '.wlcache' ) { |
|
| 71 | - |
|
| 72 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 73 | - |
|
| 74 | - // Set the cache directory using the base directory provided by the caller |
|
| 75 | - // and appending a hash for the unique site id. |
|
| 76 | - $this->cache_dir = trailingslashit( $cache_dir ) . md5( get_site_url() ) . '/'; |
|
| 77 | - $this->file_extension = $file_extension; |
|
| 78 | - |
|
| 79 | - // Create the cache dir. |
|
| 80 | - if ( ! file_exists( $this->cache_dir ) ) { |
|
| 81 | - @mkdir( $this->cache_dir, 0755, true ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - // Add ourselves to the list of instances. |
|
| 85 | - self::$instances[] = $this; |
|
| 86 | - |
|
| 87 | - $this->log->debug( "File Cache service initialized on $this->cache_dir." ); |
|
| 88 | - |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Get the cached response for the specified `id`. |
|
| 93 | - * |
|
| 94 | - * @since 3.16.0 |
|
| 95 | - * |
|
| 96 | - * @param int $id The cache `id`. |
|
| 97 | - * |
|
| 98 | - * @return mixed|false The cached contents or false if the cache isn't found. |
|
| 99 | - */ |
|
| 100 | - function get_cache( $id ) { |
|
| 101 | - |
|
| 102 | - // Bail out if we don't have the cache. |
|
| 103 | - if ( ! $this->has_cache( $id ) ) { |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // Get the filename. |
|
| 108 | - $filename = $this->get_filename( $id ); |
|
| 109 | - |
|
| 110 | - $this->log->trace( "Trying to get cache contents for $id from $filename..." ); |
|
| 111 | - |
|
| 112 | - // Try to decode the contents. |
|
| 113 | - $contents = json_decode( file_get_contents( $filename ), true ); |
|
| 114 | - |
|
| 115 | - // Return false if decoding failed, otherwise the decoded contents. |
|
| 116 | - return $contents ?: false; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Set the cache contents for the specified `id`. |
|
| 121 | - * |
|
| 122 | - * @since 3.16.0 |
|
| 123 | - * |
|
| 124 | - * @param int $id The cache id. |
|
| 125 | - * |
|
| 126 | - * @return bool True if the `id` has a cache. |
|
| 127 | - */ |
|
| 128 | - function has_cache( $id ) { |
|
| 129 | - |
|
| 130 | - // Get the filename. |
|
| 131 | - $filename = $this->get_filename( $id ); |
|
| 132 | - |
|
| 133 | - // Bail out if the file doesn't exist. |
|
| 134 | - return file_exists( $filename ); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @inheritdoc |
|
| 139 | - */ |
|
| 140 | - function set_cache( $id, $contents ) { |
|
| 141 | - |
|
| 142 | - $filename = $this->get_filename( $id ); |
|
| 143 | - |
|
| 144 | - $this->log->trace( "Writing cache contents for $id to $filename..." ); |
|
| 145 | - |
|
| 146 | - @file_put_contents( $filename, wp_json_encode( $contents ) ); |
|
| 147 | - |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Delete the cache for the specified `id`. |
|
| 152 | - * |
|
| 153 | - * @since 3.16.0 |
|
| 154 | - * |
|
| 155 | - * @param int $id The cache `id`. |
|
| 156 | - */ |
|
| 157 | - function delete_cache( $id ) { |
|
| 158 | - |
|
| 159 | - $filename = $this->get_filename( $id ); |
|
| 160 | - |
|
| 161 | - $this->log->trace( "Deleting cache contents for $id, file $filename..." ); |
|
| 162 | - |
|
| 163 | - @unlink( $filename ); |
|
| 164 | - |
|
| 165 | - } |
|
| 19 | + /** |
|
| 20 | + * The cache directory. |
|
| 21 | + * |
|
| 22 | + * @since 3.16.0 |
|
| 23 | + * @access private |
|
| 24 | + * @var string $cache_dir The root cache directory (ending with a trailing slash). |
|
| 25 | + */ |
|
| 26 | + private $cache_dir; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * The file extension for cache files (e.g. `.wlcache`). |
|
| 30 | + * |
|
| 31 | + * @since 3.16.0 |
|
| 32 | + * @access private |
|
| 33 | + * @var string $file_extension The file extension for cache files (e.g. `.wlcache`). |
|
| 34 | + */ |
|
| 35 | + private $file_extension; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * A {@link Wordlift_Log_Service} instance. |
|
| 39 | + * |
|
| 40 | + * @since 3.16.0 |
|
| 41 | + * @access private |
|
| 42 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 43 | + */ |
|
| 44 | + private $log; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * The {@link Wordlift_File_Cache_Service} registered instances. |
|
| 48 | + * |
|
| 49 | + * Each {@link Wordlift_File_Cache_Service} adds itself to the registered |
|
| 50 | + * instances. |
|
| 51 | + * |
|
| 52 | + * @since 3.16.3 |
|
| 53 | + * @access private |
|
| 54 | + * @var array $instances An array of {@link Wordlift_File_Cache_Service} instances. |
|
| 55 | + */ |
|
| 56 | + private static $instances = array(); |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Create a {@link Wordlift_File_Cache_Service} instance. |
|
| 60 | + * |
|
| 61 | + * The File Cache Service requires a base cache directory (to which a unique |
|
| 62 | + * id for the current site will be appended) and a file extension for cache |
|
| 63 | + * files (by default `.wlcache`) is used. |
|
| 64 | + * |
|
| 65 | + * @since 3.16.0 |
|
| 66 | + * |
|
| 67 | + * @param string $cache_dir The base cache directory. |
|
| 68 | + * @param string $file_extension The file extension, by default `.wlcache`. |
|
| 69 | + */ |
|
| 70 | + public function __construct( $cache_dir, $file_extension = '.wlcache' ) { |
|
| 71 | + |
|
| 72 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 73 | + |
|
| 74 | + // Set the cache directory using the base directory provided by the caller |
|
| 75 | + // and appending a hash for the unique site id. |
|
| 76 | + $this->cache_dir = trailingslashit( $cache_dir ) . md5( get_site_url() ) . '/'; |
|
| 77 | + $this->file_extension = $file_extension; |
|
| 78 | + |
|
| 79 | + // Create the cache dir. |
|
| 80 | + if ( ! file_exists( $this->cache_dir ) ) { |
|
| 81 | + @mkdir( $this->cache_dir, 0755, true ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + // Add ourselves to the list of instances. |
|
| 85 | + self::$instances[] = $this; |
|
| 86 | + |
|
| 87 | + $this->log->debug( "File Cache service initialized on $this->cache_dir." ); |
|
| 88 | + |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Get the cached response for the specified `id`. |
|
| 93 | + * |
|
| 94 | + * @since 3.16.0 |
|
| 95 | + * |
|
| 96 | + * @param int $id The cache `id`. |
|
| 97 | + * |
|
| 98 | + * @return mixed|false The cached contents or false if the cache isn't found. |
|
| 99 | + */ |
|
| 100 | + function get_cache( $id ) { |
|
| 101 | + |
|
| 102 | + // Bail out if we don't have the cache. |
|
| 103 | + if ( ! $this->has_cache( $id ) ) { |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // Get the filename. |
|
| 108 | + $filename = $this->get_filename( $id ); |
|
| 109 | + |
|
| 110 | + $this->log->trace( "Trying to get cache contents for $id from $filename..." ); |
|
| 111 | + |
|
| 112 | + // Try to decode the contents. |
|
| 113 | + $contents = json_decode( file_get_contents( $filename ), true ); |
|
| 114 | + |
|
| 115 | + // Return false if decoding failed, otherwise the decoded contents. |
|
| 116 | + return $contents ?: false; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Set the cache contents for the specified `id`. |
|
| 121 | + * |
|
| 122 | + * @since 3.16.0 |
|
| 123 | + * |
|
| 124 | + * @param int $id The cache id. |
|
| 125 | + * |
|
| 126 | + * @return bool True if the `id` has a cache. |
|
| 127 | + */ |
|
| 128 | + function has_cache( $id ) { |
|
| 129 | + |
|
| 130 | + // Get the filename. |
|
| 131 | + $filename = $this->get_filename( $id ); |
|
| 132 | + |
|
| 133 | + // Bail out if the file doesn't exist. |
|
| 134 | + return file_exists( $filename ); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @inheritdoc |
|
| 139 | + */ |
|
| 140 | + function set_cache( $id, $contents ) { |
|
| 141 | + |
|
| 142 | + $filename = $this->get_filename( $id ); |
|
| 143 | + |
|
| 144 | + $this->log->trace( "Writing cache contents for $id to $filename..." ); |
|
| 145 | + |
|
| 146 | + @file_put_contents( $filename, wp_json_encode( $contents ) ); |
|
| 147 | + |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Delete the cache for the specified `id`. |
|
| 152 | + * |
|
| 153 | + * @since 3.16.0 |
|
| 154 | + * |
|
| 155 | + * @param int $id The cache `id`. |
|
| 156 | + */ |
|
| 157 | + function delete_cache( $id ) { |
|
| 158 | + |
|
| 159 | + $filename = $this->get_filename( $id ); |
|
| 160 | + |
|
| 161 | + $this->log->trace( "Deleting cache contents for $id, file $filename..." ); |
|
| 162 | + |
|
| 163 | + @unlink( $filename ); |
|
| 164 | + |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Flush the whole cache. |
|
| 169 | - * |
|
| 170 | - * @since 3.16.0 |
|
| 171 | - */ |
|
| 172 | - function flush() { |
|
| 167 | + /** |
|
| 168 | + * Flush the whole cache. |
|
| 169 | + * |
|
| 170 | + * @since 3.16.0 |
|
| 171 | + */ |
|
| 172 | + function flush() { |
|
| 173 | 173 | |
| 174 | - // Bail out if the cache dir isn't set. |
|
| 175 | - if ( empty( $this->cache_dir ) || '/' === $this->cache_dir ) { |
|
| 176 | - return; |
|
| 177 | - } |
|
| 174 | + // Bail out if the cache dir isn't set. |
|
| 175 | + if ( empty( $this->cache_dir ) || '/' === $this->cache_dir ) { |
|
| 176 | + return; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - $this->log->trace( "Flushing cache contents from $this->cache_dir..." ); |
|
| 179 | + $this->log->trace( "Flushing cache contents from $this->cache_dir..." ); |
|
| 180 | 180 | |
| 181 | - $handle = @opendir( $this->cache_dir ); |
|
| 181 | + $handle = @opendir( $this->cache_dir ); |
|
| 182 | 182 | |
| 183 | - // Bail out if the directory can't be opened. |
|
| 184 | - if ( false === $handle ) { |
|
| 185 | - return; |
|
| 186 | - } |
|
| 183 | + // Bail out if the directory can't be opened. |
|
| 184 | + if ( false === $handle ) { |
|
| 185 | + return; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - // Calculate the file extension length for matching file names. |
|
| 189 | - $file_extension_length = strlen( $this->file_extension ); |
|
| 188 | + // Calculate the file extension length for matching file names. |
|
| 189 | + $file_extension_length = strlen( $this->file_extension ); |
|
| 190 | 190 | |
| 191 | - // Loop into the directory to delete files. |
|
| 192 | - while ( false !== ( $entry = readdir( $handle ) ) ) { |
|
| 193 | - if ( substr( $entry, - $file_extension_length ) === $this->file_extension ) { |
|
| 194 | - $this->log->trace( "Deleting file {$this->cache_dir}{$entry}..." ); |
|
| 195 | - @unlink( $this->cache_dir . $entry ); |
|
| 196 | - } |
|
| 197 | - } |
|
| 191 | + // Loop into the directory to delete files. |
|
| 192 | + while ( false !== ( $entry = readdir( $handle ) ) ) { |
|
| 193 | + if ( substr( $entry, - $file_extension_length ) === $this->file_extension ) { |
|
| 194 | + $this->log->trace( "Deleting file {$this->cache_dir}{$entry}..." ); |
|
| 195 | + @unlink( $this->cache_dir . $entry ); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - // Finally closed the directory. |
|
| 200 | - closedir( $handle ); |
|
| 199 | + // Finally closed the directory. |
|
| 200 | + closedir( $handle ); |
|
| 201 | 201 | |
| 202 | - } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - public static function flush_all() { |
|
| 204 | + public static function flush_all() { |
|
| 205 | 205 | |
| 206 | - foreach ( self::$instances as $instance ) { |
|
| 207 | - $instance->flush(); |
|
| 208 | - } |
|
| 206 | + foreach ( self::$instances as $instance ) { |
|
| 207 | + $instance->flush(); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - } |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * Get the filename holding the cache contents for the specified `id`. |
|
| 214 | - * |
|
| 215 | - * @since 3.16.0 |
|
| 216 | - * |
|
| 217 | - * @param int $id The cache `id`. |
|
| 218 | - * |
|
| 219 | - * @return string The filename. |
|
| 220 | - */ |
|
| 221 | - private function get_filename( $id ) { |
|
| 212 | + /** |
|
| 213 | + * Get the filename holding the cache contents for the specified `id`. |
|
| 214 | + * |
|
| 215 | + * @since 3.16.0 |
|
| 216 | + * |
|
| 217 | + * @param int $id The cache `id`. |
|
| 218 | + * |
|
| 219 | + * @return string The filename. |
|
| 220 | + */ |
|
| 221 | + private function get_filename( $id ) { |
|
| 222 | 222 | |
| 223 | - return $this->cache_dir . md5( $id ) . $this->file_extension; |
|
| 224 | - } |
|
| 223 | + return $this->cache_dir . md5( $id ) . $this->file_extension; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | 226 | } |
@@ -67,24 +67,24 @@ discard block |
||
| 67 | 67 | * @param string $cache_dir The base cache directory. |
| 68 | 68 | * @param string $file_extension The file extension, by default `.wlcache`. |
| 69 | 69 | */ |
| 70 | - public function __construct( $cache_dir, $file_extension = '.wlcache' ) { |
|
| 70 | + public function __construct($cache_dir, $file_extension = '.wlcache') { |
|
| 71 | 71 | |
| 72 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 72 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 73 | 73 | |
| 74 | 74 | // Set the cache directory using the base directory provided by the caller |
| 75 | 75 | // and appending a hash for the unique site id. |
| 76 | - $this->cache_dir = trailingslashit( $cache_dir ) . md5( get_site_url() ) . '/'; |
|
| 76 | + $this->cache_dir = trailingslashit($cache_dir).md5(get_site_url()).'/'; |
|
| 77 | 77 | $this->file_extension = $file_extension; |
| 78 | 78 | |
| 79 | 79 | // Create the cache dir. |
| 80 | - if ( ! file_exists( $this->cache_dir ) ) { |
|
| 81 | - @mkdir( $this->cache_dir, 0755, true ); |
|
| 80 | + if ( ! file_exists($this->cache_dir)) { |
|
| 81 | + @mkdir($this->cache_dir, 0755, true); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // Add ourselves to the list of instances. |
| 85 | 85 | self::$instances[] = $this; |
| 86 | 86 | |
| 87 | - $this->log->debug( "File Cache service initialized on $this->cache_dir." ); |
|
| 87 | + $this->log->debug("File Cache service initialized on $this->cache_dir."); |
|
| 88 | 88 | |
| 89 | 89 | } |
| 90 | 90 | |
@@ -97,20 +97,20 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return mixed|false The cached contents or false if the cache isn't found. |
| 99 | 99 | */ |
| 100 | - function get_cache( $id ) { |
|
| 100 | + function get_cache($id) { |
|
| 101 | 101 | |
| 102 | 102 | // Bail out if we don't have the cache. |
| 103 | - if ( ! $this->has_cache( $id ) ) { |
|
| 103 | + if ( ! $this->has_cache($id)) { |
|
| 104 | 104 | return false; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // Get the filename. |
| 108 | - $filename = $this->get_filename( $id ); |
|
| 108 | + $filename = $this->get_filename($id); |
|
| 109 | 109 | |
| 110 | - $this->log->trace( "Trying to get cache contents for $id from $filename..." ); |
|
| 110 | + $this->log->trace("Trying to get cache contents for $id from $filename..."); |
|
| 111 | 111 | |
| 112 | 112 | // Try to decode the contents. |
| 113 | - $contents = json_decode( file_get_contents( $filename ), true ); |
|
| 113 | + $contents = json_decode(file_get_contents($filename), true); |
|
| 114 | 114 | |
| 115 | 115 | // Return false if decoding failed, otherwise the decoded contents. |
| 116 | 116 | return $contents ?: false; |
@@ -125,25 +125,25 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | * @return bool True if the `id` has a cache. |
| 127 | 127 | */ |
| 128 | - function has_cache( $id ) { |
|
| 128 | + function has_cache($id) { |
|
| 129 | 129 | |
| 130 | 130 | // Get the filename. |
| 131 | - $filename = $this->get_filename( $id ); |
|
| 131 | + $filename = $this->get_filename($id); |
|
| 132 | 132 | |
| 133 | 133 | // Bail out if the file doesn't exist. |
| 134 | - return file_exists( $filename ); |
|
| 134 | + return file_exists($filename); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * @inheritdoc |
| 139 | 139 | */ |
| 140 | - function set_cache( $id, $contents ) { |
|
| 140 | + function set_cache($id, $contents) { |
|
| 141 | 141 | |
| 142 | - $filename = $this->get_filename( $id ); |
|
| 142 | + $filename = $this->get_filename($id); |
|
| 143 | 143 | |
| 144 | - $this->log->trace( "Writing cache contents for $id to $filename..." ); |
|
| 144 | + $this->log->trace("Writing cache contents for $id to $filename..."); |
|
| 145 | 145 | |
| 146 | - @file_put_contents( $filename, wp_json_encode( $contents ) ); |
|
| 146 | + @file_put_contents($filename, wp_json_encode($contents)); |
|
| 147 | 147 | |
| 148 | 148 | } |
| 149 | 149 | |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | * |
| 155 | 155 | * @param int $id The cache `id`. |
| 156 | 156 | */ |
| 157 | - function delete_cache( $id ) { |
|
| 157 | + function delete_cache($id) { |
|
| 158 | 158 | |
| 159 | - $filename = $this->get_filename( $id ); |
|
| 159 | + $filename = $this->get_filename($id); |
|
| 160 | 160 | |
| 161 | - $this->log->trace( "Deleting cache contents for $id, file $filename..." ); |
|
| 161 | + $this->log->trace("Deleting cache contents for $id, file $filename..."); |
|
| 162 | 162 | |
| 163 | - @unlink( $filename ); |
|
| 163 | + @unlink($filename); |
|
| 164 | 164 | |
| 165 | 165 | } |
| 166 | 166 | |
@@ -172,38 +172,38 @@ discard block |
||
| 172 | 172 | function flush() { |
| 173 | 173 | |
| 174 | 174 | // Bail out if the cache dir isn't set. |
| 175 | - if ( empty( $this->cache_dir ) || '/' === $this->cache_dir ) { |
|
| 175 | + if (empty($this->cache_dir) || '/' === $this->cache_dir) { |
|
| 176 | 176 | return; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - $this->log->trace( "Flushing cache contents from $this->cache_dir..." ); |
|
| 179 | + $this->log->trace("Flushing cache contents from $this->cache_dir..."); |
|
| 180 | 180 | |
| 181 | - $handle = @opendir( $this->cache_dir ); |
|
| 181 | + $handle = @opendir($this->cache_dir); |
|
| 182 | 182 | |
| 183 | 183 | // Bail out if the directory can't be opened. |
| 184 | - if ( false === $handle ) { |
|
| 184 | + if (false === $handle) { |
|
| 185 | 185 | return; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // Calculate the file extension length for matching file names. |
| 189 | - $file_extension_length = strlen( $this->file_extension ); |
|
| 189 | + $file_extension_length = strlen($this->file_extension); |
|
| 190 | 190 | |
| 191 | 191 | // Loop into the directory to delete files. |
| 192 | - while ( false !== ( $entry = readdir( $handle ) ) ) { |
|
| 193 | - if ( substr( $entry, - $file_extension_length ) === $this->file_extension ) { |
|
| 194 | - $this->log->trace( "Deleting file {$this->cache_dir}{$entry}..." ); |
|
| 195 | - @unlink( $this->cache_dir . $entry ); |
|
| 192 | + while (false !== ($entry = readdir($handle))) { |
|
| 193 | + if (substr($entry, - $file_extension_length) === $this->file_extension) { |
|
| 194 | + $this->log->trace("Deleting file {$this->cache_dir}{$entry}..."); |
|
| 195 | + @unlink($this->cache_dir.$entry); |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | // Finally closed the directory. |
| 200 | - closedir( $handle ); |
|
| 200 | + closedir($handle); |
|
| 201 | 201 | |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | public static function flush_all() { |
| 205 | 205 | |
| 206 | - foreach ( self::$instances as $instance ) { |
|
| 206 | + foreach (self::$instances as $instance) { |
|
| 207 | 207 | $instance->flush(); |
| 208 | 208 | } |
| 209 | 209 | |
@@ -218,9 +218,9 @@ discard block |
||
| 218 | 218 | * |
| 219 | 219 | * @return string The filename. |
| 220 | 220 | */ |
| 221 | - private function get_filename( $id ) { |
|
| 221 | + private function get_filename($id) { |
|
| 222 | 222 | |
| 223 | - return $this->cache_dir . md5( $id ) . $this->file_extension; |
|
| 223 | + return $this->cache_dir.md5($id).$this->file_extension; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | } |
@@ -18,312 +18,312 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Sparql_Service { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * A {@link Wordlift_Log_Service} instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.6.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 27 | - */ |
|
| 28 | - private static $log; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * The {@link Wordlift_Sparql_Service} singleton instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.6.0 |
|
| 34 | - * @access private |
|
| 35 | - * @var \Wordlift_Sparql_Service $instance The {@link Wordlift_Sparql_Service} singleton instance. |
|
| 36 | - */ |
|
| 37 | - private static $instance; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Create a {@link Wordlift_Sparql_Service} instance. |
|
| 41 | - * |
|
| 42 | - * @since 3.6.0 |
|
| 43 | - */ |
|
| 44 | - public function __construct() { |
|
| 45 | - |
|
| 46 | - self::$log = Wordlift_Log_Service::get_logger( 'Wordlift_Sparql_Service' ); |
|
| 47 | - |
|
| 48 | - self::$instance = $this; |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Get the singleton instance of the {@link Wordlift_Sparql_Service}. |
|
| 54 | - * |
|
| 55 | - * @since 3.6.0 |
|
| 56 | - * @return \Wordlift_Sparql_Service |
|
| 57 | - */ |
|
| 58 | - public static function get_instance() { |
|
| 59 | - |
|
| 60 | - return self::$instance; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Queue a SPARQL statement for execution. |
|
| 65 | - * |
|
| 66 | - * @since 3.6.0 |
|
| 67 | - * |
|
| 68 | - * @param string $stmt The SPARQL statement. |
|
| 69 | - * @param bool $queue Whether to queue the statement for asynchronous |
|
| 70 | - * execution. |
|
| 71 | - */ |
|
| 72 | - public function execute( $stmt, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) { |
|
| 73 | - |
|
| 74 | - rl_execute_sparql_update_query( $stmt, $queue ); |
|
| 75 | - |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Run the SPARQL queries buffered for the specified request id. |
|
| 80 | - * |
|
| 81 | - * @since 3.13.2 |
|
| 82 | - * |
|
| 83 | - * @param string $request_id A unique request id. |
|
| 84 | - */ |
|
| 85 | - public function run_sparql_query( $request_id ) { |
|
| 86 | - |
|
| 87 | - self::$log->debug( "Running SPARQL queries..." ); |
|
| 88 | - |
|
| 89 | - // Look for a free temporary filename. |
|
| 90 | - for ( $index = 1; $index < PHP_INT_MAX; $index ++ ) { |
|
| 91 | - $filename = WL_TEMP_DIR . $request_id . "-$index.sparql"; |
|
| 92 | - |
|
| 93 | - // Bail out if there are no files left. |
|
| 94 | - if ( ! file_exists( $filename ) ) { |
|
| 95 | - break; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - self::$log->debug( "Running SPARQL from $filename..." ); |
|
| 99 | - |
|
| 100 | - // Get the query saved in the file. |
|
| 101 | - $query = file_get_contents( $filename ); |
|
| 102 | - |
|
| 103 | - // Execute the SPARQL query. |
|
| 104 | - rl_execute_sparql_update_query( $query, false ); |
|
| 105 | - |
|
| 106 | - // Delete the temporary file. |
|
| 107 | - unlink( $filename ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Reindex the triple store. |
|
| 111 | - wordlift_reindex_triple_store(); |
|
| 112 | - |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Queue a SPARQL statement for asynchronous execution. |
|
| 117 | - * |
|
| 118 | - * @since 3.13.2 |
|
| 119 | - * |
|
| 120 | - * @param string $stmt The SPARQL statement. |
|
| 121 | - * |
|
| 122 | - * @throws Exception |
|
| 123 | - */ |
|
| 124 | - public function queue( $stmt ) { |
|
| 125 | - |
|
| 126 | - // Get a temporary filename. |
|
| 127 | - $filename = $this->get_temporary_file_for_sparql(); |
|
| 128 | - |
|
| 129 | - self::$log->debug( "Buffering SPARQL to file $filename..." ); |
|
| 130 | - |
|
| 131 | - // Write the contents to the temporary filename. |
|
| 132 | - @file_put_contents( $filename, $stmt . "\n", FILE_APPEND ); |
|
| 133 | - |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Get a temporary filename where to store SPARQL queries. |
|
| 138 | - * |
|
| 139 | - * @since 3.13.2 |
|
| 140 | - * |
|
| 141 | - * @return string The filename. |
|
| 142 | - * @throws Exception An exception is thrown if there are already 1.000 |
|
| 143 | - * temporary files for this request. |
|
| 144 | - */ |
|
| 145 | - private function get_temporary_file_for_sparql() { |
|
| 146 | - |
|
| 147 | - // Look for a free temporary filename. |
|
| 148 | - for ( $index = 1; $index < PHP_INT_MAX; $index ++ ) { |
|
| 149 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . "-$index.sparql"; |
|
| 150 | - |
|
| 151 | - if ( ! file_exists( $filename ) ) { |
|
| 152 | - |
|
| 153 | - // Only if this it the first buffered SPARQL, then launch the |
|
| 154 | - // action which will be handled by the Async Task. The Async |
|
| 155 | - // Task will take care of all the buffered files _on shutdown_. |
|
| 156 | - if ( 1 === $index ) { |
|
| 157 | - do_action( 'wl_run_sparql_query', WL_REQUEST_ID ); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - // Return the temporary filename. |
|
| 161 | - return $filename; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - throw new Exception( 'Cannot create a temporary file [ ' . WL_TEMP_DIR . WL_REQUEST_ID . ' ].' ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Execute the SELECT query. |
|
| 170 | - * |
|
| 171 | - * @since 3.12.2 |
|
| 172 | - * |
|
| 173 | - * @param string $query The SELECT query to execute. |
|
| 174 | - * |
|
| 175 | - * @return WP_Error|array The response or WP_Error on failure. |
|
| 176 | - */ |
|
| 177 | - public function select( $query ) { |
|
| 178 | - |
|
| 179 | - // Prepare the SPARQL statement by prepending the default namespaces. |
|
| 180 | - $sparql = rl_sparql_prefixes() . "\n" . $query; |
|
| 181 | - |
|
| 182 | - // Get the SPARQL SELECT URL. |
|
| 183 | - $url = wl_configuration_get_query_select_url() . urlencode( $sparql ); |
|
| 184 | - |
|
| 185 | - $http_options = unserialize( WL_REDLINK_API_HTTP_OPTIONS ); |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Filter: 'wl_sparql_select_http_args' - Allow third parties to hook and add additional HTTP args. |
|
| 189 | - * |
|
| 190 | - * @since 3.17.0 |
|
| 191 | - * |
|
| 192 | - * @param array $http_options Current http options. |
|
| 193 | - */ |
|
| 194 | - $args = apply_filters( 'wl_sparql_select_http_args', $http_options ); |
|
| 195 | - |
|
| 196 | - return wp_remote_get( $url, $args ); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Formats the provided value according to the specified type in order to |
|
| 201 | - * insert the value using SPARQL. The value is also escaped. |
|
| 202 | - * |
|
| 203 | - * @since 3.6.0 |
|
| 204 | - * |
|
| 205 | - * @param string $value The value. |
|
| 206 | - * @param string $type The value type. |
|
| 207 | - * @param string|null $language The language tag or null if not set. |
|
| 208 | - * |
|
| 209 | - * @return string The formatted value for SPARQL statements. |
|
| 210 | - */ |
|
| 211 | - public static function format( $value, $type = null, $language = null ) { |
|
| 212 | - |
|
| 213 | - // see https://www.w3.org/TR/sparql11-query/. |
|
| 214 | - |
|
| 215 | - switch ( $type ) { |
|
| 216 | - |
|
| 217 | - case Wordlift_Schema_Service::DATA_TYPE_BOOLEAN: |
|
| 218 | - // SPARQL supports 'true' and 'false', so we evaluate the $value |
|
| 219 | - // and return true/false accordingly. |
|
| 220 | - return $value ? 'true' : 'false'; |
|
| 221 | - |
|
| 222 | - case Wordlift_Schema_Service::DATA_TYPE_DATE: |
|
| 223 | - $date = date_create_from_format( 'Y/m/d', $value ); |
|
| 224 | - $date_value = date_format( $date, 'Y-m-d' ); |
|
| 225 | - |
|
| 226 | - return sprintf( '"%s"^^xsd:date', self::escape( $date_value ) ); |
|
| 227 | - |
|
| 228 | - case Wordlift_Schema_Service::DATA_TYPE_DATE_TIME: |
|
| 229 | - $date = date_create_from_format( 'Y/m/d H:i', $value ); |
|
| 230 | - $date_value = date_format( $date, 'Y-m-d\TH:i:00' ); |
|
| 231 | - |
|
| 232 | - return sprintf( '"%s"^^xsd:dateTime', self::escape( $date_value ) ); |
|
| 233 | - |
|
| 234 | - case Wordlift_Schema_Service::DATA_TYPE_DURATION: |
|
| 235 | - $time = date_create_from_format( 'H:i', $value ); |
|
| 236 | - $time_value = sprintf( 'PT%dH%dM', date_format( $time, 'H' ), intval( date_format( $time, 'i' ) ) ); |
|
| 237 | - |
|
| 238 | - return sprintf( '"%s"^^xsd:duration', self::escape( $time_value ) ); |
|
| 239 | - |
|
| 240 | - case Wordlift_Schema_Service::DATA_TYPE_DOUBLE: |
|
| 241 | - return sprintf( '"%s"^^xsd:double', self::escape( $value ) ); |
|
| 242 | - |
|
| 243 | - case Wordlift_Schema_Service::DATA_TYPE_INTEGER: |
|
| 244 | - return sprintf( '"%s"^^xsd:integer', self::escape( $value ) ); |
|
| 245 | - |
|
| 246 | - case Wordlift_Schema_Service::DATA_TYPE_STRING: |
|
| 247 | - return sprintf( '"%s"^^xsd:string', self::escape( $value ) ); |
|
| 248 | - |
|
| 249 | - case Wordlift_Schema_Service::DATA_TYPE_URI: |
|
| 250 | - /** |
|
| 251 | - * Allow 3rd parties to change the uri. |
|
| 252 | - * |
|
| 253 | - * @since 3.20.0 |
|
| 254 | - * |
|
| 255 | - * @see https://github.com/insideout10/wordlift-plugin/issues/850 |
|
| 256 | - * |
|
| 257 | - * @param string $uri The uri. |
|
| 258 | - */ |
|
| 259 | - return sprintf( '<%s>', self::escape_uri( apply_filters( 'wl_production_uri', $value ) ) ); |
|
| 260 | - |
|
| 261 | - case null: |
|
| 262 | - $language_tag = ( null !== $language ? "@$language" : '' ); |
|
| 263 | - |
|
| 264 | - return sprintf( '"%s"%s', self::escape( $value ), $language_tag ); |
|
| 265 | - |
|
| 266 | - default: |
|
| 267 | - |
|
| 268 | - self::$log->warn( "Unknown data type [ type :: $type ]" ); |
|
| 269 | - |
|
| 270 | - // Try to insert the value anyway. |
|
| 271 | - return sprintf( '"%s"', self::escape( $value ) ); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Escapes an URI for a SPARQL statement. |
|
| 278 | - * |
|
| 279 | - * @since 3.6.0 |
|
| 280 | - * |
|
| 281 | - * @param string $uri The URI to escape. |
|
| 282 | - * |
|
| 283 | - * @return string The escaped URI. |
|
| 284 | - */ |
|
| 285 | - public static function escape_uri( $uri ) { |
|
| 286 | - |
|
| 287 | - // Should we validate the IRI? |
|
| 288 | - // http://www.w3.org/TR/sparql11-query/#QSynIRI |
|
| 289 | - |
|
| 290 | - $uri = str_replace( '<', '\<', $uri ); |
|
| 291 | - $uri = str_replace( '>', '\>', $uri ); |
|
| 292 | - |
|
| 293 | - return $uri; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Escapes a string for a SPARQL statement. |
|
| 298 | - * |
|
| 299 | - * @since 3.6.0 |
|
| 300 | - * |
|
| 301 | - * @param string $string The string to escape. |
|
| 302 | - * |
|
| 303 | - * @return string The escaped string. |
|
| 304 | - */ |
|
| 305 | - public static function escape( $string ) { |
|
| 306 | - |
|
| 307 | - // see http://www.w3.org/TR/rdf-sparql-query/ |
|
| 308 | - // '\t' U+0009 (tab) |
|
| 309 | - // '\n' U+000A (line feed) |
|
| 310 | - // '\r' U+000D (carriage return) |
|
| 311 | - // '\b' U+0008 (backspace) |
|
| 312 | - // '\f' U+000C (form feed) |
|
| 313 | - // '\"' U+0022 (quotation mark, double quote mark) |
|
| 314 | - // "\'" U+0027 (apostrophe-quote, single quote mark) |
|
| 315 | - // '\\' U+005C (backslash) |
|
| 316 | - |
|
| 317 | - $string = str_replace( '\\', '\\\\', $string ); |
|
| 318 | - $string = str_replace( '\'', '\\\'', $string ); |
|
| 319 | - $string = str_replace( '"', '\\"', $string ); |
|
| 320 | - $string = str_replace( "\f", '\\f', $string ); |
|
| 321 | - $string = str_replace( "\b", '\\b', $string ); |
|
| 322 | - $string = str_replace( "\r", '\\r', $string ); |
|
| 323 | - $string = str_replace( "\n", '\\n', $string ); |
|
| 324 | - $string = str_replace( "\t", '\\t', $string ); |
|
| 325 | - |
|
| 326 | - return $string; |
|
| 327 | - } |
|
| 21 | + /** |
|
| 22 | + * A {@link Wordlift_Log_Service} instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.6.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 27 | + */ |
|
| 28 | + private static $log; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * The {@link Wordlift_Sparql_Service} singleton instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.6.0 |
|
| 34 | + * @access private |
|
| 35 | + * @var \Wordlift_Sparql_Service $instance The {@link Wordlift_Sparql_Service} singleton instance. |
|
| 36 | + */ |
|
| 37 | + private static $instance; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Create a {@link Wordlift_Sparql_Service} instance. |
|
| 41 | + * |
|
| 42 | + * @since 3.6.0 |
|
| 43 | + */ |
|
| 44 | + public function __construct() { |
|
| 45 | + |
|
| 46 | + self::$log = Wordlift_Log_Service::get_logger( 'Wordlift_Sparql_Service' ); |
|
| 47 | + |
|
| 48 | + self::$instance = $this; |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Get the singleton instance of the {@link Wordlift_Sparql_Service}. |
|
| 54 | + * |
|
| 55 | + * @since 3.6.0 |
|
| 56 | + * @return \Wordlift_Sparql_Service |
|
| 57 | + */ |
|
| 58 | + public static function get_instance() { |
|
| 59 | + |
|
| 60 | + return self::$instance; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Queue a SPARQL statement for execution. |
|
| 65 | + * |
|
| 66 | + * @since 3.6.0 |
|
| 67 | + * |
|
| 68 | + * @param string $stmt The SPARQL statement. |
|
| 69 | + * @param bool $queue Whether to queue the statement for asynchronous |
|
| 70 | + * execution. |
|
| 71 | + */ |
|
| 72 | + public function execute( $stmt, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) { |
|
| 73 | + |
|
| 74 | + rl_execute_sparql_update_query( $stmt, $queue ); |
|
| 75 | + |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Run the SPARQL queries buffered for the specified request id. |
|
| 80 | + * |
|
| 81 | + * @since 3.13.2 |
|
| 82 | + * |
|
| 83 | + * @param string $request_id A unique request id. |
|
| 84 | + */ |
|
| 85 | + public function run_sparql_query( $request_id ) { |
|
| 86 | + |
|
| 87 | + self::$log->debug( "Running SPARQL queries..." ); |
|
| 88 | + |
|
| 89 | + // Look for a free temporary filename. |
|
| 90 | + for ( $index = 1; $index < PHP_INT_MAX; $index ++ ) { |
|
| 91 | + $filename = WL_TEMP_DIR . $request_id . "-$index.sparql"; |
|
| 92 | + |
|
| 93 | + // Bail out if there are no files left. |
|
| 94 | + if ( ! file_exists( $filename ) ) { |
|
| 95 | + break; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + self::$log->debug( "Running SPARQL from $filename..." ); |
|
| 99 | + |
|
| 100 | + // Get the query saved in the file. |
|
| 101 | + $query = file_get_contents( $filename ); |
|
| 102 | + |
|
| 103 | + // Execute the SPARQL query. |
|
| 104 | + rl_execute_sparql_update_query( $query, false ); |
|
| 105 | + |
|
| 106 | + // Delete the temporary file. |
|
| 107 | + unlink( $filename ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Reindex the triple store. |
|
| 111 | + wordlift_reindex_triple_store(); |
|
| 112 | + |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Queue a SPARQL statement for asynchronous execution. |
|
| 117 | + * |
|
| 118 | + * @since 3.13.2 |
|
| 119 | + * |
|
| 120 | + * @param string $stmt The SPARQL statement. |
|
| 121 | + * |
|
| 122 | + * @throws Exception |
|
| 123 | + */ |
|
| 124 | + public function queue( $stmt ) { |
|
| 125 | + |
|
| 126 | + // Get a temporary filename. |
|
| 127 | + $filename = $this->get_temporary_file_for_sparql(); |
|
| 128 | + |
|
| 129 | + self::$log->debug( "Buffering SPARQL to file $filename..." ); |
|
| 130 | + |
|
| 131 | + // Write the contents to the temporary filename. |
|
| 132 | + @file_put_contents( $filename, $stmt . "\n", FILE_APPEND ); |
|
| 133 | + |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Get a temporary filename where to store SPARQL queries. |
|
| 138 | + * |
|
| 139 | + * @since 3.13.2 |
|
| 140 | + * |
|
| 141 | + * @return string The filename. |
|
| 142 | + * @throws Exception An exception is thrown if there are already 1.000 |
|
| 143 | + * temporary files for this request. |
|
| 144 | + */ |
|
| 145 | + private function get_temporary_file_for_sparql() { |
|
| 146 | + |
|
| 147 | + // Look for a free temporary filename. |
|
| 148 | + for ( $index = 1; $index < PHP_INT_MAX; $index ++ ) { |
|
| 149 | + $filename = WL_TEMP_DIR . WL_REQUEST_ID . "-$index.sparql"; |
|
| 150 | + |
|
| 151 | + if ( ! file_exists( $filename ) ) { |
|
| 152 | + |
|
| 153 | + // Only if this it the first buffered SPARQL, then launch the |
|
| 154 | + // action which will be handled by the Async Task. The Async |
|
| 155 | + // Task will take care of all the buffered files _on shutdown_. |
|
| 156 | + if ( 1 === $index ) { |
|
| 157 | + do_action( 'wl_run_sparql_query', WL_REQUEST_ID ); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + // Return the temporary filename. |
|
| 161 | + return $filename; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + throw new Exception( 'Cannot create a temporary file [ ' . WL_TEMP_DIR . WL_REQUEST_ID . ' ].' ); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Execute the SELECT query. |
|
| 170 | + * |
|
| 171 | + * @since 3.12.2 |
|
| 172 | + * |
|
| 173 | + * @param string $query The SELECT query to execute. |
|
| 174 | + * |
|
| 175 | + * @return WP_Error|array The response or WP_Error on failure. |
|
| 176 | + */ |
|
| 177 | + public function select( $query ) { |
|
| 178 | + |
|
| 179 | + // Prepare the SPARQL statement by prepending the default namespaces. |
|
| 180 | + $sparql = rl_sparql_prefixes() . "\n" . $query; |
|
| 181 | + |
|
| 182 | + // Get the SPARQL SELECT URL. |
|
| 183 | + $url = wl_configuration_get_query_select_url() . urlencode( $sparql ); |
|
| 184 | + |
|
| 185 | + $http_options = unserialize( WL_REDLINK_API_HTTP_OPTIONS ); |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Filter: 'wl_sparql_select_http_args' - Allow third parties to hook and add additional HTTP args. |
|
| 189 | + * |
|
| 190 | + * @since 3.17.0 |
|
| 191 | + * |
|
| 192 | + * @param array $http_options Current http options. |
|
| 193 | + */ |
|
| 194 | + $args = apply_filters( 'wl_sparql_select_http_args', $http_options ); |
|
| 195 | + |
|
| 196 | + return wp_remote_get( $url, $args ); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Formats the provided value according to the specified type in order to |
|
| 201 | + * insert the value using SPARQL. The value is also escaped. |
|
| 202 | + * |
|
| 203 | + * @since 3.6.0 |
|
| 204 | + * |
|
| 205 | + * @param string $value The value. |
|
| 206 | + * @param string $type The value type. |
|
| 207 | + * @param string|null $language The language tag or null if not set. |
|
| 208 | + * |
|
| 209 | + * @return string The formatted value for SPARQL statements. |
|
| 210 | + */ |
|
| 211 | + public static function format( $value, $type = null, $language = null ) { |
|
| 212 | + |
|
| 213 | + // see https://www.w3.org/TR/sparql11-query/. |
|
| 214 | + |
|
| 215 | + switch ( $type ) { |
|
| 216 | + |
|
| 217 | + case Wordlift_Schema_Service::DATA_TYPE_BOOLEAN: |
|
| 218 | + // SPARQL supports 'true' and 'false', so we evaluate the $value |
|
| 219 | + // and return true/false accordingly. |
|
| 220 | + return $value ? 'true' : 'false'; |
|
| 221 | + |
|
| 222 | + case Wordlift_Schema_Service::DATA_TYPE_DATE: |
|
| 223 | + $date = date_create_from_format( 'Y/m/d', $value ); |
|
| 224 | + $date_value = date_format( $date, 'Y-m-d' ); |
|
| 225 | + |
|
| 226 | + return sprintf( '"%s"^^xsd:date', self::escape( $date_value ) ); |
|
| 227 | + |
|
| 228 | + case Wordlift_Schema_Service::DATA_TYPE_DATE_TIME: |
|
| 229 | + $date = date_create_from_format( 'Y/m/d H:i', $value ); |
|
| 230 | + $date_value = date_format( $date, 'Y-m-d\TH:i:00' ); |
|
| 231 | + |
|
| 232 | + return sprintf( '"%s"^^xsd:dateTime', self::escape( $date_value ) ); |
|
| 233 | + |
|
| 234 | + case Wordlift_Schema_Service::DATA_TYPE_DURATION: |
|
| 235 | + $time = date_create_from_format( 'H:i', $value ); |
|
| 236 | + $time_value = sprintf( 'PT%dH%dM', date_format( $time, 'H' ), intval( date_format( $time, 'i' ) ) ); |
|
| 237 | + |
|
| 238 | + return sprintf( '"%s"^^xsd:duration', self::escape( $time_value ) ); |
|
| 239 | + |
|
| 240 | + case Wordlift_Schema_Service::DATA_TYPE_DOUBLE: |
|
| 241 | + return sprintf( '"%s"^^xsd:double', self::escape( $value ) ); |
|
| 242 | + |
|
| 243 | + case Wordlift_Schema_Service::DATA_TYPE_INTEGER: |
|
| 244 | + return sprintf( '"%s"^^xsd:integer', self::escape( $value ) ); |
|
| 245 | + |
|
| 246 | + case Wordlift_Schema_Service::DATA_TYPE_STRING: |
|
| 247 | + return sprintf( '"%s"^^xsd:string', self::escape( $value ) ); |
|
| 248 | + |
|
| 249 | + case Wordlift_Schema_Service::DATA_TYPE_URI: |
|
| 250 | + /** |
|
| 251 | + * Allow 3rd parties to change the uri. |
|
| 252 | + * |
|
| 253 | + * @since 3.20.0 |
|
| 254 | + * |
|
| 255 | + * @see https://github.com/insideout10/wordlift-plugin/issues/850 |
|
| 256 | + * |
|
| 257 | + * @param string $uri The uri. |
|
| 258 | + */ |
|
| 259 | + return sprintf( '<%s>', self::escape_uri( apply_filters( 'wl_production_uri', $value ) ) ); |
|
| 260 | + |
|
| 261 | + case null: |
|
| 262 | + $language_tag = ( null !== $language ? "@$language" : '' ); |
|
| 263 | + |
|
| 264 | + return sprintf( '"%s"%s', self::escape( $value ), $language_tag ); |
|
| 265 | + |
|
| 266 | + default: |
|
| 267 | + |
|
| 268 | + self::$log->warn( "Unknown data type [ type :: $type ]" ); |
|
| 269 | + |
|
| 270 | + // Try to insert the value anyway. |
|
| 271 | + return sprintf( '"%s"', self::escape( $value ) ); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Escapes an URI for a SPARQL statement. |
|
| 278 | + * |
|
| 279 | + * @since 3.6.0 |
|
| 280 | + * |
|
| 281 | + * @param string $uri The URI to escape. |
|
| 282 | + * |
|
| 283 | + * @return string The escaped URI. |
|
| 284 | + */ |
|
| 285 | + public static function escape_uri( $uri ) { |
|
| 286 | + |
|
| 287 | + // Should we validate the IRI? |
|
| 288 | + // http://www.w3.org/TR/sparql11-query/#QSynIRI |
|
| 289 | + |
|
| 290 | + $uri = str_replace( '<', '\<', $uri ); |
|
| 291 | + $uri = str_replace( '>', '\>', $uri ); |
|
| 292 | + |
|
| 293 | + return $uri; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Escapes a string for a SPARQL statement. |
|
| 298 | + * |
|
| 299 | + * @since 3.6.0 |
|
| 300 | + * |
|
| 301 | + * @param string $string The string to escape. |
|
| 302 | + * |
|
| 303 | + * @return string The escaped string. |
|
| 304 | + */ |
|
| 305 | + public static function escape( $string ) { |
|
| 306 | + |
|
| 307 | + // see http://www.w3.org/TR/rdf-sparql-query/ |
|
| 308 | + // '\t' U+0009 (tab) |
|
| 309 | + // '\n' U+000A (line feed) |
|
| 310 | + // '\r' U+000D (carriage return) |
|
| 311 | + // '\b' U+0008 (backspace) |
|
| 312 | + // '\f' U+000C (form feed) |
|
| 313 | + // '\"' U+0022 (quotation mark, double quote mark) |
|
| 314 | + // "\'" U+0027 (apostrophe-quote, single quote mark) |
|
| 315 | + // '\\' U+005C (backslash) |
|
| 316 | + |
|
| 317 | + $string = str_replace( '\\', '\\\\', $string ); |
|
| 318 | + $string = str_replace( '\'', '\\\'', $string ); |
|
| 319 | + $string = str_replace( '"', '\\"', $string ); |
|
| 320 | + $string = str_replace( "\f", '\\f', $string ); |
|
| 321 | + $string = str_replace( "\b", '\\b', $string ); |
|
| 322 | + $string = str_replace( "\r", '\\r', $string ); |
|
| 323 | + $string = str_replace( "\n", '\\n', $string ); |
|
| 324 | + $string = str_replace( "\t", '\\t', $string ); |
|
| 325 | + |
|
| 326 | + return $string; |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | 329 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function __construct() { |
| 45 | 45 | |
| 46 | - self::$log = Wordlift_Log_Service::get_logger( 'Wordlift_Sparql_Service' ); |
|
| 46 | + self::$log = Wordlift_Log_Service::get_logger('Wordlift_Sparql_Service'); |
|
| 47 | 47 | |
| 48 | 48 | self::$instance = $this; |
| 49 | 49 | |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | * @param bool $queue Whether to queue the statement for asynchronous |
| 70 | 70 | * execution. |
| 71 | 71 | */ |
| 72 | - public function execute( $stmt, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) { |
|
| 72 | + public function execute($stmt, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING) { |
|
| 73 | 73 | |
| 74 | - rl_execute_sparql_update_query( $stmt, $queue ); |
|
| 74 | + rl_execute_sparql_update_query($stmt, $queue); |
|
| 75 | 75 | |
| 76 | 76 | } |
| 77 | 77 | |
@@ -82,29 +82,29 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | * @param string $request_id A unique request id. |
| 84 | 84 | */ |
| 85 | - public function run_sparql_query( $request_id ) { |
|
| 85 | + public function run_sparql_query($request_id) { |
|
| 86 | 86 | |
| 87 | - self::$log->debug( "Running SPARQL queries..." ); |
|
| 87 | + self::$log->debug("Running SPARQL queries..."); |
|
| 88 | 88 | |
| 89 | 89 | // Look for a free temporary filename. |
| 90 | - for ( $index = 1; $index < PHP_INT_MAX; $index ++ ) { |
|
| 91 | - $filename = WL_TEMP_DIR . $request_id . "-$index.sparql"; |
|
| 90 | + for ($index = 1; $index < PHP_INT_MAX; $index++) { |
|
| 91 | + $filename = WL_TEMP_DIR.$request_id."-$index.sparql"; |
|
| 92 | 92 | |
| 93 | 93 | // Bail out if there are no files left. |
| 94 | - if ( ! file_exists( $filename ) ) { |
|
| 94 | + if ( ! file_exists($filename)) { |
|
| 95 | 95 | break; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - self::$log->debug( "Running SPARQL from $filename..." ); |
|
| 98 | + self::$log->debug("Running SPARQL from $filename..."); |
|
| 99 | 99 | |
| 100 | 100 | // Get the query saved in the file. |
| 101 | - $query = file_get_contents( $filename ); |
|
| 101 | + $query = file_get_contents($filename); |
|
| 102 | 102 | |
| 103 | 103 | // Execute the SPARQL query. |
| 104 | - rl_execute_sparql_update_query( $query, false ); |
|
| 104 | + rl_execute_sparql_update_query($query, false); |
|
| 105 | 105 | |
| 106 | 106 | // Delete the temporary file. |
| 107 | - unlink( $filename ); |
|
| 107 | + unlink($filename); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Reindex the triple store. |
@@ -121,15 +121,15 @@ discard block |
||
| 121 | 121 | * |
| 122 | 122 | * @throws Exception |
| 123 | 123 | */ |
| 124 | - public function queue( $stmt ) { |
|
| 124 | + public function queue($stmt) { |
|
| 125 | 125 | |
| 126 | 126 | // Get a temporary filename. |
| 127 | 127 | $filename = $this->get_temporary_file_for_sparql(); |
| 128 | 128 | |
| 129 | - self::$log->debug( "Buffering SPARQL to file $filename..." ); |
|
| 129 | + self::$log->debug("Buffering SPARQL to file $filename..."); |
|
| 130 | 130 | |
| 131 | 131 | // Write the contents to the temporary filename. |
| 132 | - @file_put_contents( $filename, $stmt . "\n", FILE_APPEND ); |
|
| 132 | + @file_put_contents($filename, $stmt."\n", FILE_APPEND); |
|
| 133 | 133 | |
| 134 | 134 | } |
| 135 | 135 | |
@@ -145,16 +145,16 @@ discard block |
||
| 145 | 145 | private function get_temporary_file_for_sparql() { |
| 146 | 146 | |
| 147 | 147 | // Look for a free temporary filename. |
| 148 | - for ( $index = 1; $index < PHP_INT_MAX; $index ++ ) { |
|
| 149 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . "-$index.sparql"; |
|
| 148 | + for ($index = 1; $index < PHP_INT_MAX; $index++) { |
|
| 149 | + $filename = WL_TEMP_DIR.WL_REQUEST_ID."-$index.sparql"; |
|
| 150 | 150 | |
| 151 | - if ( ! file_exists( $filename ) ) { |
|
| 151 | + if ( ! file_exists($filename)) { |
|
| 152 | 152 | |
| 153 | 153 | // Only if this it the first buffered SPARQL, then launch the |
| 154 | 154 | // action which will be handled by the Async Task. The Async |
| 155 | 155 | // Task will take care of all the buffered files _on shutdown_. |
| 156 | - if ( 1 === $index ) { |
|
| 157 | - do_action( 'wl_run_sparql_query', WL_REQUEST_ID ); |
|
| 156 | + if (1 === $index) { |
|
| 157 | + do_action('wl_run_sparql_query', WL_REQUEST_ID); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // Return the temporary filename. |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - throw new Exception( 'Cannot create a temporary file [ ' . WL_TEMP_DIR . WL_REQUEST_ID . ' ].' ); |
|
| 165 | + throw new Exception('Cannot create a temporary file [ '.WL_TEMP_DIR.WL_REQUEST_ID.' ].'); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -174,15 +174,15 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return WP_Error|array The response or WP_Error on failure. |
| 176 | 176 | */ |
| 177 | - public function select( $query ) { |
|
| 177 | + public function select($query) { |
|
| 178 | 178 | |
| 179 | 179 | // Prepare the SPARQL statement by prepending the default namespaces. |
| 180 | - $sparql = rl_sparql_prefixes() . "\n" . $query; |
|
| 180 | + $sparql = rl_sparql_prefixes()."\n".$query; |
|
| 181 | 181 | |
| 182 | 182 | // Get the SPARQL SELECT URL. |
| 183 | - $url = wl_configuration_get_query_select_url() . urlencode( $sparql ); |
|
| 183 | + $url = wl_configuration_get_query_select_url().urlencode($sparql); |
|
| 184 | 184 | |
| 185 | - $http_options = unserialize( WL_REDLINK_API_HTTP_OPTIONS ); |
|
| 185 | + $http_options = unserialize(WL_REDLINK_API_HTTP_OPTIONS); |
|
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * Filter: 'wl_sparql_select_http_args' - Allow third parties to hook and add additional HTTP args. |
@@ -191,9 +191,9 @@ discard block |
||
| 191 | 191 | * |
| 192 | 192 | * @param array $http_options Current http options. |
| 193 | 193 | */ |
| 194 | - $args = apply_filters( 'wl_sparql_select_http_args', $http_options ); |
|
| 194 | + $args = apply_filters('wl_sparql_select_http_args', $http_options); |
|
| 195 | 195 | |
| 196 | - return wp_remote_get( $url, $args ); |
|
| 196 | + return wp_remote_get($url, $args); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | * |
| 209 | 209 | * @return string The formatted value for SPARQL statements. |
| 210 | 210 | */ |
| 211 | - public static function format( $value, $type = null, $language = null ) { |
|
| 211 | + public static function format($value, $type = null, $language = null) { |
|
| 212 | 212 | |
| 213 | 213 | // see https://www.w3.org/TR/sparql11-query/. |
| 214 | 214 | |
| 215 | - switch ( $type ) { |
|
| 215 | + switch ($type) { |
|
| 216 | 216 | |
| 217 | 217 | case Wordlift_Schema_Service::DATA_TYPE_BOOLEAN: |
| 218 | 218 | // SPARQL supports 'true' and 'false', so we evaluate the $value |
@@ -220,31 +220,31 @@ discard block |
||
| 220 | 220 | return $value ? 'true' : 'false'; |
| 221 | 221 | |
| 222 | 222 | case Wordlift_Schema_Service::DATA_TYPE_DATE: |
| 223 | - $date = date_create_from_format( 'Y/m/d', $value ); |
|
| 224 | - $date_value = date_format( $date, 'Y-m-d' ); |
|
| 223 | + $date = date_create_from_format('Y/m/d', $value); |
|
| 224 | + $date_value = date_format($date, 'Y-m-d'); |
|
| 225 | 225 | |
| 226 | - return sprintf( '"%s"^^xsd:date', self::escape( $date_value ) ); |
|
| 226 | + return sprintf('"%s"^^xsd:date', self::escape($date_value)); |
|
| 227 | 227 | |
| 228 | 228 | case Wordlift_Schema_Service::DATA_TYPE_DATE_TIME: |
| 229 | - $date = date_create_from_format( 'Y/m/d H:i', $value ); |
|
| 230 | - $date_value = date_format( $date, 'Y-m-d\TH:i:00' ); |
|
| 229 | + $date = date_create_from_format('Y/m/d H:i', $value); |
|
| 230 | + $date_value = date_format($date, 'Y-m-d\TH:i:00'); |
|
| 231 | 231 | |
| 232 | - return sprintf( '"%s"^^xsd:dateTime', self::escape( $date_value ) ); |
|
| 232 | + return sprintf('"%s"^^xsd:dateTime', self::escape($date_value)); |
|
| 233 | 233 | |
| 234 | 234 | case Wordlift_Schema_Service::DATA_TYPE_DURATION: |
| 235 | - $time = date_create_from_format( 'H:i', $value ); |
|
| 236 | - $time_value = sprintf( 'PT%dH%dM', date_format( $time, 'H' ), intval( date_format( $time, 'i' ) ) ); |
|
| 235 | + $time = date_create_from_format('H:i', $value); |
|
| 236 | + $time_value = sprintf('PT%dH%dM', date_format($time, 'H'), intval(date_format($time, 'i'))); |
|
| 237 | 237 | |
| 238 | - return sprintf( '"%s"^^xsd:duration', self::escape( $time_value ) ); |
|
| 238 | + return sprintf('"%s"^^xsd:duration', self::escape($time_value)); |
|
| 239 | 239 | |
| 240 | 240 | case Wordlift_Schema_Service::DATA_TYPE_DOUBLE: |
| 241 | - return sprintf( '"%s"^^xsd:double', self::escape( $value ) ); |
|
| 241 | + return sprintf('"%s"^^xsd:double', self::escape($value)); |
|
| 242 | 242 | |
| 243 | 243 | case Wordlift_Schema_Service::DATA_TYPE_INTEGER: |
| 244 | - return sprintf( '"%s"^^xsd:integer', self::escape( $value ) ); |
|
| 244 | + return sprintf('"%s"^^xsd:integer', self::escape($value)); |
|
| 245 | 245 | |
| 246 | 246 | case Wordlift_Schema_Service::DATA_TYPE_STRING: |
| 247 | - return sprintf( '"%s"^^xsd:string', self::escape( $value ) ); |
|
| 247 | + return sprintf('"%s"^^xsd:string', self::escape($value)); |
|
| 248 | 248 | |
| 249 | 249 | case Wordlift_Schema_Service::DATA_TYPE_URI: |
| 250 | 250 | /** |
@@ -256,19 +256,19 @@ discard block |
||
| 256 | 256 | * |
| 257 | 257 | * @param string $uri The uri. |
| 258 | 258 | */ |
| 259 | - return sprintf( '<%s>', self::escape_uri( apply_filters( 'wl_production_uri', $value ) ) ); |
|
| 259 | + return sprintf('<%s>', self::escape_uri(apply_filters('wl_production_uri', $value))); |
|
| 260 | 260 | |
| 261 | 261 | case null: |
| 262 | - $language_tag = ( null !== $language ? "@$language" : '' ); |
|
| 262 | + $language_tag = (null !== $language ? "@$language" : ''); |
|
| 263 | 263 | |
| 264 | - return sprintf( '"%s"%s', self::escape( $value ), $language_tag ); |
|
| 264 | + return sprintf('"%s"%s', self::escape($value), $language_tag); |
|
| 265 | 265 | |
| 266 | 266 | default: |
| 267 | 267 | |
| 268 | - self::$log->warn( "Unknown data type [ type :: $type ]" ); |
|
| 268 | + self::$log->warn("Unknown data type [ type :: $type ]"); |
|
| 269 | 269 | |
| 270 | 270 | // Try to insert the value anyway. |
| 271 | - return sprintf( '"%s"', self::escape( $value ) ); |
|
| 271 | + return sprintf('"%s"', self::escape($value)); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | } |
@@ -282,13 +282,13 @@ discard block |
||
| 282 | 282 | * |
| 283 | 283 | * @return string The escaped URI. |
| 284 | 284 | */ |
| 285 | - public static function escape_uri( $uri ) { |
|
| 285 | + public static function escape_uri($uri) { |
|
| 286 | 286 | |
| 287 | 287 | // Should we validate the IRI? |
| 288 | 288 | // http://www.w3.org/TR/sparql11-query/#QSynIRI |
| 289 | 289 | |
| 290 | - $uri = str_replace( '<', '\<', $uri ); |
|
| 291 | - $uri = str_replace( '>', '\>', $uri ); |
|
| 290 | + $uri = str_replace('<', '\<', $uri); |
|
| 291 | + $uri = str_replace('>', '\>', $uri); |
|
| 292 | 292 | |
| 293 | 293 | return $uri; |
| 294 | 294 | } |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * |
| 303 | 303 | * @return string The escaped string. |
| 304 | 304 | */ |
| 305 | - public static function escape( $string ) { |
|
| 305 | + public static function escape($string) { |
|
| 306 | 306 | |
| 307 | 307 | // see http://www.w3.org/TR/rdf-sparql-query/ |
| 308 | 308 | // '\t' U+0009 (tab) |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | // "\'" U+0027 (apostrophe-quote, single quote mark) |
| 315 | 315 | // '\\' U+005C (backslash) |
| 316 | 316 | |
| 317 | - $string = str_replace( '\\', '\\\\', $string ); |
|
| 318 | - $string = str_replace( '\'', '\\\'', $string ); |
|
| 319 | - $string = str_replace( '"', '\\"', $string ); |
|
| 320 | - $string = str_replace( "\f", '\\f', $string ); |
|
| 321 | - $string = str_replace( "\b", '\\b', $string ); |
|
| 322 | - $string = str_replace( "\r", '\\r', $string ); |
|
| 323 | - $string = str_replace( "\n", '\\n', $string ); |
|
| 324 | - $string = str_replace( "\t", '\\t', $string ); |
|
| 317 | + $string = str_replace('\\', '\\\\', $string); |
|
| 318 | + $string = str_replace('\'', '\\\'', $string); |
|
| 319 | + $string = str_replace('"', '\\"', $string); |
|
| 320 | + $string = str_replace("\f", '\\f', $string); |
|
| 321 | + $string = str_replace("\b", '\\b', $string); |
|
| 322 | + $string = str_replace("\r", '\\r', $string); |
|
| 323 | + $string = str_replace("\n", '\\n', $string); |
|
| 324 | + $string = str_replace("\t", '\\t', $string); |
|
| 325 | 325 | |
| 326 | 326 | return $string; |
| 327 | 327 | } |
@@ -14,55 +14,55 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Wordlift_Tinymce_Adapter { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The {@link Wordlift} plugin instance. |
|
| 19 | - * |
|
| 20 | - * @since 3.12.0 |
|
| 21 | - * @access private |
|
| 22 | - * @var \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
| 23 | - */ |
|
| 24 | - private $plugin; |
|
| 17 | + /** |
|
| 18 | + * The {@link Wordlift} plugin instance. |
|
| 19 | + * |
|
| 20 | + * @since 3.12.0 |
|
| 21 | + * @access private |
|
| 22 | + * @var \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
| 23 | + */ |
|
| 24 | + private $plugin; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Wordlift_Tinymce_Adapter constructor. |
|
| 28 | - * |
|
| 29 | - * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
| 30 | - */ |
|
| 31 | - public function __construct( $plugin ) { |
|
| 26 | + /** |
|
| 27 | + * Wordlift_Tinymce_Adapter constructor. |
|
| 28 | + * |
|
| 29 | + * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
| 30 | + */ |
|
| 31 | + public function __construct( $plugin ) { |
|
| 32 | 32 | |
| 33 | - $this->plugin = $plugin; |
|
| 33 | + $this->plugin = $plugin; |
|
| 34 | 34 | |
| 35 | - } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Load the TinyMCE plugin. This method is called by the WP mce_external_plugins hook. |
|
| 39 | - * |
|
| 40 | - * @since 3.12.0 |
|
| 41 | - * |
|
| 42 | - * @param array $plugins The existing plugins array. |
|
| 43 | - * |
|
| 44 | - * @return array The modified plugins array. |
|
| 45 | - */ |
|
| 46 | - function mce_external_plugins( $plugins ) { |
|
| 37 | + /** |
|
| 38 | + * Load the TinyMCE plugin. This method is called by the WP mce_external_plugins hook. |
|
| 39 | + * |
|
| 40 | + * @since 3.12.0 |
|
| 41 | + * |
|
| 42 | + * @param array $plugins The existing plugins array. |
|
| 43 | + * |
|
| 44 | + * @return array The modified plugins array. |
|
| 45 | + */ |
|
| 46 | + function mce_external_plugins( $plugins ) { |
|
| 47 | 47 | |
| 48 | - // Get WordLift's version as a cache killer. |
|
| 49 | - $version = $this->plugin->get_version(); |
|
| 48 | + // Get WordLift's version as a cache killer. |
|
| 49 | + $version = $this->plugin->get_version(); |
|
| 50 | 50 | |
| 51 | - // User can edit? |
|
| 52 | - $can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); |
|
| 51 | + // User can edit? |
|
| 52 | + $can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); |
|
| 53 | 53 | |
| 54 | - // If user can't edit or rich editing isn't enabled, bail out. |
|
| 55 | - if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) { |
|
| 56 | - return $plugins; |
|
| 57 | - } |
|
| 54 | + // If user can't edit or rich editing isn't enabled, bail out. |
|
| 55 | + if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) { |
|
| 56 | + return $plugins; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - // Add our own JavaScript file to TinyMCE's extensions. |
|
| 60 | - // DO NOT use the minified version, it'll yield errors with AngularJS. |
|
| 61 | - $plugins['wordlift'] = plugin_dir_url( dirname( __FILE__ ) ) . 'js/wordlift-reloaded.js?ver=' . $version; |
|
| 62 | - $plugins['wl_shortcodes'] = plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version; |
|
| 63 | - $plugins['wl_tinymce'] = plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/tinymce.js?ver=' . $version; |
|
| 59 | + // Add our own JavaScript file to TinyMCE's extensions. |
|
| 60 | + // DO NOT use the minified version, it'll yield errors with AngularJS. |
|
| 61 | + $plugins['wordlift'] = plugin_dir_url( dirname( __FILE__ ) ) . 'js/wordlift-reloaded.js?ver=' . $version; |
|
| 62 | + $plugins['wl_shortcodes'] = plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version; |
|
| 63 | + $plugins['wl_tinymce'] = plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/tinymce.js?ver=' . $version; |
|
| 64 | 64 | |
| 65 | - return $plugins; |
|
| 66 | - } |
|
| 65 | + return $plugins; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
| 30 | 30 | */ |
| 31 | - public function __construct( $plugin ) { |
|
| 31 | + public function __construct($plugin) { |
|
| 32 | 32 | |
| 33 | 33 | $this->plugin = $plugin; |
| 34 | 34 | |
@@ -43,24 +43,24 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return array The modified plugins array. |
| 45 | 45 | */ |
| 46 | - function mce_external_plugins( $plugins ) { |
|
| 46 | + function mce_external_plugins($plugins) { |
|
| 47 | 47 | |
| 48 | 48 | // Get WordLift's version as a cache killer. |
| 49 | 49 | $version = $this->plugin->get_version(); |
| 50 | 50 | |
| 51 | 51 | // User can edit? |
| 52 | - $can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); |
|
| 52 | + $can_edit = current_user_can('edit_posts') || current_user_can('edit_pages'); |
|
| 53 | 53 | |
| 54 | 54 | // If user can't edit or rich editing isn't enabled, bail out. |
| 55 | - if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) { |
|
| 55 | + if ( ! $can_edit || ! get_user_option('rich_editing')) { |
|
| 56 | 56 | return $plugins; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // Add our own JavaScript file to TinyMCE's extensions. |
| 60 | 60 | // DO NOT use the minified version, it'll yield errors with AngularJS. |
| 61 | - $plugins['wordlift'] = plugin_dir_url( dirname( __FILE__ ) ) . 'js/wordlift-reloaded.js?ver=' . $version; |
|
| 62 | - $plugins['wl_shortcodes'] = plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version; |
|
| 63 | - $plugins['wl_tinymce'] = plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/tinymce.js?ver=' . $version; |
|
| 61 | + $plugins['wordlift'] = plugin_dir_url(dirname(__FILE__)).'js/wordlift-reloaded.js?ver='.$version; |
|
| 62 | + $plugins['wl_shortcodes'] = plugin_dir_url(dirname(__FILE__)).'admin/js/wordlift_shortcode_tinymce_plugin.js?ver='.$version; |
|
| 63 | + $plugins['wl_tinymce'] = plugin_dir_url(dirname(__FILE__)).'admin/js/1/tinymce.js?ver='.$version; |
|
| 64 | 64 | |
| 65 | 65 | return $plugins; |
| 66 | 66 | } |