@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | // If this file is called directly, abort. |
| 50 | 50 | if ( ! defined( 'WPINC' ) ) { |
| 51 | - die; |
|
| 51 | + die; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | function wl_write_log( $log ) { |
| 73 | 73 | |
| 74 | - Wordlift_Log_Service::get_instance()->debug( $log ); |
|
| 74 | + Wordlift_Log_Service::get_instance()->debug( $log ); |
|
| 75 | 75 | |
| 76 | 76 | } |
| 77 | 77 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | function wl_write_log_hide_key( $text ) { |
| 90 | 90 | |
| 91 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 91 | + return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -96,21 +96,21 @@ discard block |
||
| 96 | 96 | * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/ |
| 97 | 97 | */ |
| 98 | 98 | function wordlift_allowed_post_tags() { |
| 99 | - global $allowedposttags; |
|
| 100 | - |
|
| 101 | - $tags = array( 'span' ); |
|
| 102 | - $new_attributes = array( |
|
| 103 | - 'itemscope' => array(), |
|
| 104 | - 'itemtype' => array(), |
|
| 105 | - 'itemprop' => array(), |
|
| 106 | - 'itemid' => array(), |
|
| 107 | - ); |
|
| 108 | - |
|
| 109 | - foreach ( $tags as $tag ) { |
|
| 110 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 111 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 112 | - } |
|
| 113 | - } |
|
| 99 | + global $allowedposttags; |
|
| 100 | + |
|
| 101 | + $tags = array( 'span' ); |
|
| 102 | + $new_attributes = array( |
|
| 103 | + 'itemscope' => array(), |
|
| 104 | + 'itemtype' => array(), |
|
| 105 | + 'itemprop' => array(), |
|
| 106 | + 'itemid' => array(), |
|
| 107 | + ); |
|
| 108 | + |
|
| 109 | + foreach ( $tags as $tag ) { |
|
| 110 | + if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 111 | + $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // add allowed post tags. |
@@ -121,18 +121,18 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | function wordlift_admin_enqueue_scripts() { |
| 123 | 123 | |
| 124 | - // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
|
| 125 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 126 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 124 | + // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
|
| 125 | + wp_enqueue_script( 'wpdialogs' ); |
|
| 126 | + wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 127 | 127 | |
| 128 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 128 | + wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 129 | 129 | |
| 130 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 130 | + wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 131 | 131 | |
| 132 | - // Disable auto-save for custom entity posts only |
|
| 133 | - if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 134 | - wp_dequeue_script( 'autosave' ); |
|
| 135 | - } |
|
| 132 | + // Disable auto-save for custom entity posts only |
|
| 133 | + if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 134 | + wp_dequeue_script( 'autosave' ); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | 137 | } |
| 138 | 138 | |
@@ -148,18 +148,18 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | function wordlift_allowed_html( $allowedtags, $context ) { |
| 150 | 150 | |
| 151 | - if ( 'post' !== $context ) { |
|
| 152 | - return $allowedtags; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return array_merge_recursive( $allowedtags, array( |
|
| 156 | - 'span' => array( |
|
| 157 | - 'itemscope' => true, |
|
| 158 | - 'itemtype' => true, |
|
| 159 | - 'itemid' => true, |
|
| 160 | - 'itemprop' => true, |
|
| 161 | - ), |
|
| 162 | - ) ); |
|
| 151 | + if ( 'post' !== $context ) { |
|
| 152 | + return $allowedtags; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return array_merge_recursive( $allowedtags, array( |
|
| 156 | + 'span' => array( |
|
| 157 | + 'itemscope' => true, |
|
| 158 | + 'itemtype' => true, |
|
| 159 | + 'itemid' => true, |
|
| 160 | + 'itemprop' => true, |
|
| 161 | + ), |
|
| 162 | + ) ); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
@@ -173,16 +173,16 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | function wl_get_coordinates( $post_id ) { |
| 175 | 175 | |
| 176 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 177 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 176 | + $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 177 | + $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 178 | 178 | |
| 179 | - // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
|
| 180 | - // place on the globe:"The zero/zero point of this system is located in the |
|
| 181 | - // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 182 | - return array( |
|
| 183 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 184 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 185 | - ); |
|
| 179 | + // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
|
| 180 | + // place on the globe:"The zero/zero point of this system is located in the |
|
| 181 | + // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 182 | + return array( |
|
| 183 | + 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 184 | + 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 185 | + ); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -196,9 +196,9 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | function wl_get_image_urls( $post_id ) { |
| 198 | 198 | |
| 199 | - return Wordlift_Storage_Factory::get_instance() |
|
| 200 | - ->post_images() |
|
| 201 | - ->get( $post_id ); |
|
| 199 | + return Wordlift_Storage_Factory::get_instance() |
|
| 200 | + ->post_images() |
|
| 201 | + ->get( $post_id ); |
|
| 202 | 202 | |
| 203 | 203 | } |
| 204 | 204 | |
@@ -212,24 +212,24 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
| 214 | 214 | |
| 215 | - // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
|
| 215 | + // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
|
| 216 | 216 | |
| 217 | - $posts = get_posts( array( |
|
| 218 | - 'post_type' => 'attachment', |
|
| 219 | - 'posts_per_page' => 1, |
|
| 220 | - 'post_status' => 'any', |
|
| 221 | - 'post_parent' => $parent_post_id, |
|
| 222 | - 'meta_key' => 'wl_source_url', |
|
| 223 | - 'meta_value' => $source_url, |
|
| 224 | - ) ); |
|
| 217 | + $posts = get_posts( array( |
|
| 218 | + 'post_type' => 'attachment', |
|
| 219 | + 'posts_per_page' => 1, |
|
| 220 | + 'post_status' => 'any', |
|
| 221 | + 'post_parent' => $parent_post_id, |
|
| 222 | + 'meta_key' => 'wl_source_url', |
|
| 223 | + 'meta_value' => $source_url, |
|
| 224 | + ) ); |
|
| 225 | 225 | |
| 226 | - // Return the found post. |
|
| 227 | - if ( 1 === count( $posts ) ) { |
|
| 228 | - return $posts[0]; |
|
| 229 | - } |
|
| 226 | + // Return the found post. |
|
| 227 | + if ( 1 === count( $posts ) ) { |
|
| 228 | + return $posts[0]; |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - // Return null. |
|
| 232 | - return null; |
|
| 231 | + // Return null. |
|
| 232 | + return null; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -240,8 +240,8 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | function wl_set_source_url( $post_id, $source_url ) { |
| 242 | 242 | |
| 243 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 244 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 243 | + delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 244 | + add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | function wl_sanitize_uri_path( $path, $char = '_' ) { |
| 260 | 260 | |
| 261 | - return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 261 | + return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -270,47 +270,47 @@ discard block |
||
| 270 | 270 | */ |
| 271 | 271 | function wl_replace_item_id_with_uri( $content ) { |
| 272 | 272 | |
| 273 | - $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' ); |
|
| 274 | - $log->trace( 'Replacing item IDs with URIs...' ); |
|
| 273 | + $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' ); |
|
| 274 | + $log->trace( 'Replacing item IDs with URIs...' ); |
|
| 275 | 275 | |
| 276 | - // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
|
| 277 | - $content = stripslashes( $content ); |
|
| 276 | + // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
|
| 277 | + $content = stripslashes( $content ); |
|
| 278 | 278 | |
| 279 | - // If any match are found. |
|
| 280 | - $matches = array(); |
|
| 281 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 279 | + // If any match are found. |
|
| 280 | + $matches = array(); |
|
| 281 | + if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 282 | 282 | |
| 283 | - foreach ( $matches as $match ) { |
|
| 283 | + foreach ( $matches as $match ) { |
|
| 284 | 284 | |
| 285 | - // Get the item ID. |
|
| 286 | - $item_id = $match[1]; |
|
| 285 | + // Get the item ID. |
|
| 286 | + $item_id = $match[1]; |
|
| 287 | 287 | |
| 288 | - // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
|
| 289 | - $post = Wordlift_Entity_Service::get_instance() |
|
| 290 | - ->get_entity_post_by_uri( $item_id ); |
|
| 288 | + // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
|
| 289 | + $post = Wordlift_Entity_Service::get_instance() |
|
| 290 | + ->get_entity_post_by_uri( $item_id ); |
|
| 291 | 291 | |
| 292 | - // If no entity is found, continue to the next one. |
|
| 293 | - if ( null === $post ) { |
|
| 294 | - continue; |
|
| 295 | - } |
|
| 292 | + // If no entity is found, continue to the next one. |
|
| 293 | + if ( null === $post ) { |
|
| 294 | + continue; |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - // Get the URI for that post. |
|
| 298 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 297 | + // Get the URI for that post. |
|
| 298 | + $uri = wl_get_entity_uri( $post->ID ); |
|
| 299 | 299 | |
| 300 | - // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
|
| 300 | + // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
|
| 301 | 301 | |
| 302 | - // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
|
| 303 | - if ( $item_id !== $uri ) { |
|
| 304 | - $uri_e = esc_html( $uri ); |
|
| 305 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - } |
|
| 302 | + // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
|
| 303 | + if ( $item_id !== $uri ) { |
|
| 304 | + $uri_e = esc_html( $uri ); |
|
| 305 | + $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - // Reapply slashes. |
|
| 311 | - $content = addslashes( $content ); |
|
| 310 | + // Reapply slashes. |
|
| 311 | + $content = addslashes( $content ); |
|
| 312 | 312 | |
| 313 | - return $content; |
|
| 313 | + return $content; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
@@ -373,24 +373,24 @@ discard block |
||
| 373 | 373 | */ |
| 374 | 374 | function activate_wordlift() { |
| 375 | 375 | |
| 376 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 376 | + $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 377 | 377 | |
| 378 | - $log->info( 'Activating WordLift...' ); |
|
| 378 | + $log->info( 'Activating WordLift...' ); |
|
| 379 | 379 | |
| 380 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 381 | - Wordlift_Activator::activate(); |
|
| 380 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 381 | + Wordlift_Activator::activate(); |
|
| 382 | 382 | |
| 383 | - /** |
|
| 384 | - * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
| 385 | - * |
|
| 386 | - * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
| 387 | - * @since 3.19.2 |
|
| 388 | - */ |
|
| 389 | - Wordlift_Http_Api::activate(); |
|
| 383 | + /** |
|
| 384 | + * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
| 385 | + * |
|
| 386 | + * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
| 387 | + * @since 3.19.2 |
|
| 388 | + */ |
|
| 389 | + Wordlift_Http_Api::activate(); |
|
| 390 | 390 | |
| 391 | - // Ensure the post type is registered before flushing the rewrite rules. |
|
| 392 | - Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 393 | - flush_rewrite_rules(); |
|
| 391 | + // Ensure the post type is registered before flushing the rewrite rules. |
|
| 392 | + Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
| 393 | + flush_rewrite_rules(); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -399,11 +399,11 @@ discard block |
||
| 399 | 399 | */ |
| 400 | 400 | function deactivate_wordlift() { |
| 401 | 401 | |
| 402 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 403 | - Wordlift_Deactivator::deactivate(); |
|
| 404 | - Wordlift_Http_Api::deactivate(); |
|
| 405 | - Ttl_Cache_Cleaner::deactivate(); |
|
| 406 | - flush_rewrite_rules(); |
|
| 402 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 403 | + Wordlift_Deactivator::deactivate(); |
|
| 404 | + Wordlift_Http_Api::deactivate(); |
|
| 405 | + Ttl_Cache_Cleaner::deactivate(); |
|
| 406 | + flush_rewrite_rules(); |
|
| 407 | 407 | |
| 408 | 408 | } |
| 409 | 409 | |
@@ -426,98 +426,98 @@ discard block |
||
| 426 | 426 | * @since 1.0.0 |
| 427 | 427 | */ |
| 428 | 428 | function run_wordlift() { |
| 429 | - /** |
|
| 430 | - * Filter: wl_feature__enable__widgets. |
|
| 431 | - * |
|
| 432 | - * @param bool whether the widgets needed to be registered, defaults to true. |
|
| 433 | - * |
|
| 434 | - * @return bool |
|
| 435 | - * @since 3.27.6 |
|
| 436 | - */ |
|
| 437 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
| 438 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 439 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
| 440 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
| 441 | - } |
|
| 442 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Filter: wl_feature__enable__analysis |
|
| 447 | - * |
|
| 448 | - * @param bool Whether to send api request to analysis or not |
|
| 449 | - * |
|
| 450 | - * @return bool |
|
| 451 | - * @since 3.27.6 |
|
| 452 | - */ |
|
| 453 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
| 454 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
| 455 | - } else { |
|
| 456 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - /* |
|
| 429 | + /** |
|
| 430 | + * Filter: wl_feature__enable__widgets. |
|
| 431 | + * |
|
| 432 | + * @param bool whether the widgets needed to be registered, defaults to true. |
|
| 433 | + * |
|
| 434 | + * @return bool |
|
| 435 | + * @since 3.27.6 |
|
| 436 | + */ |
|
| 437 | + if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
| 438 | + add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 439 | + add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
| 440 | + add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
| 441 | + } |
|
| 442 | + add_filter( 'widget_text', 'do_shortcode' ); |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Filter: wl_feature__enable__analysis |
|
| 447 | + * |
|
| 448 | + * @param bool Whether to send api request to analysis or not |
|
| 449 | + * |
|
| 450 | + * @return bool |
|
| 451 | + * @since 3.27.6 |
|
| 452 | + */ |
|
| 453 | + if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
| 454 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
| 455 | + } else { |
|
| 456 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + /* |
|
| 460 | 460 | * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http. |
| 461 | 461 | * |
| 462 | 462 | * @since 3.21.2 |
| 463 | 463 | */ |
| 464 | - wordlift_plugin_autoload_register(); |
|
| 464 | + wordlift_plugin_autoload_register(); |
|
| 465 | 465 | |
| 466 | - $plugin = new Wordlift(); |
|
| 467 | - $plugin->run(); |
|
| 466 | + $plugin = new Wordlift(); |
|
| 467 | + $plugin->run(); |
|
| 468 | 468 | |
| 469 | - // Initialize the TTL Cache Cleaner. |
|
| 470 | - new Ttl_Cache_Cleaner(); |
|
| 469 | + // Initialize the TTL Cache Cleaner. |
|
| 470 | + new Ttl_Cache_Cleaner(); |
|
| 471 | 471 | |
| 472 | - // Load the new Post Adapter. |
|
| 473 | - new Post_Adapter(); |
|
| 472 | + // Load the new Post Adapter. |
|
| 473 | + new Post_Adapter(); |
|
| 474 | 474 | |
| 475 | - // Load the API Data Hooks. |
|
| 476 | - new Api_Data_Hooks(); |
|
| 475 | + // Load the API Data Hooks. |
|
| 476 | + new Api_Data_Hooks(); |
|
| 477 | 477 | |
| 478 | - add_action( 'plugins_loaded', function () use ( $plugin ) { |
|
| 479 | - // Load early. **PLEASE NOTE** that features are applied only to calls that happen **AFTER** the `plugins_loaded` |
|
| 480 | - // action. |
|
| 481 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php'; |
|
| 478 | + add_action( 'plugins_loaded', function () use ( $plugin ) { |
|
| 479 | + // Load early. **PLEASE NOTE** that features are applied only to calls that happen **AFTER** the `plugins_loaded` |
|
| 480 | + // action. |
|
| 481 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php'; |
|
| 482 | 482 | |
| 483 | - // Licenses Images. |
|
| 484 | - $user_agent = User_Agent::get_user_agent(); |
|
| 485 | - $wordlift_key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 486 | - $api_service = new Default_Api_Service( apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ), 60, $user_agent, $wordlift_key ); |
|
| 487 | - $image_license_factory = new Image_License_Factory(); |
|
| 488 | - $image_license_service = new Image_License_Service( $api_service, $image_license_factory ); |
|
| 489 | - $image_license_cache = new Ttl_Cache( 'image-license', 86400 * 30 ); // 30 days. |
|
| 490 | - $cached_image_license_service = new Cached_Image_License_Service( $image_license_service, $image_license_cache ); |
|
| 483 | + // Licenses Images. |
|
| 484 | + $user_agent = User_Agent::get_user_agent(); |
|
| 485 | + $wordlift_key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 486 | + $api_service = new Default_Api_Service( apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ), 60, $user_agent, $wordlift_key ); |
|
| 487 | + $image_license_factory = new Image_License_Factory(); |
|
| 488 | + $image_license_service = new Image_License_Service( $api_service, $image_license_factory ); |
|
| 489 | + $image_license_cache = new Ttl_Cache( 'image-license', 86400 * 30 ); // 30 days. |
|
| 490 | + $cached_image_license_service = new Cached_Image_License_Service( $image_license_service, $image_license_cache ); |
|
| 491 | 491 | |
| 492 | - $image_license_scheduler = new Image_License_Scheduler( $image_license_service, $image_license_cache ); |
|
| 493 | - $image_license_cleanup_service = new Image_License_Cleanup_Service(); |
|
| 492 | + $image_license_scheduler = new Image_License_Scheduler( $image_license_service, $image_license_cache ); |
|
| 493 | + $image_license_cleanup_service = new Image_License_Cleanup_Service(); |
|
| 494 | 494 | |
| 495 | - // Get the cached data. If we have cached data, we load the notifier. |
|
| 496 | - $image_license_data = $image_license_cache->get( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES ); |
|
| 497 | - if ( null !== $image_license_data ) { |
|
| 498 | - $image_license_page = new Image_License_Page( $image_license_data, Wordlift::get_instance()->get_version() ); |
|
| 499 | - new Image_License_Notifier( $image_license_data, $image_license_page ); |
|
| 500 | - } |
|
| 495 | + // Get the cached data. If we have cached data, we load the notifier. |
|
| 496 | + $image_license_data = $image_license_cache->get( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES ); |
|
| 497 | + if ( null !== $image_license_data ) { |
|
| 498 | + $image_license_page = new Image_License_Page( $image_license_data, Wordlift::get_instance()->get_version() ); |
|
| 499 | + new Image_License_Notifier( $image_license_data, $image_license_page ); |
|
| 500 | + } |
|
| 501 | 501 | |
| 502 | - $remove_all_images_task = new Remove_All_Images_Task( $cached_image_license_service ); |
|
| 503 | - $remove_all_images_task_adapter = new Task_Ajax_Adapter( $remove_all_images_task ); |
|
| 502 | + $remove_all_images_task = new Remove_All_Images_Task( $cached_image_license_service ); |
|
| 503 | + $remove_all_images_task_adapter = new Task_Ajax_Adapter( $remove_all_images_task ); |
|
| 504 | 504 | |
| 505 | - $reload_data_task = new Reload_Data_Task(); |
|
| 506 | - $reload_data_task_adapter = new Task_Ajax_Adapter( $reload_data_task ); |
|
| 505 | + $reload_data_task = new Reload_Data_Task(); |
|
| 506 | + $reload_data_task_adapter = new Task_Ajax_Adapter( $reload_data_task ); |
|
| 507 | 507 | |
| 508 | - $add_license_caption_or_remove_task = new Add_License_Caption_Or_Remove_Task( $cached_image_license_service ); |
|
| 509 | - $add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter( $add_license_caption_or_remove_task ); |
|
| 508 | + $add_license_caption_or_remove_task = new Add_License_Caption_Or_Remove_Task( $cached_image_license_service ); |
|
| 509 | + $add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter( $add_license_caption_or_remove_task ); |
|
| 510 | 510 | |
| 511 | - $remove_all_images_task_page = new Remove_All_Images_Page( new Task_Ajax_Adapters_Registry( $remove_all_images_task_adapter ), $plugin->get_version() ); |
|
| 512 | - $reload_data_task_page = new Reload_Data_Page( new Task_Ajax_Adapters_Registry( $reload_data_task_adapter ), $plugin->get_version() ); |
|
| 513 | - $add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page( new Task_Ajax_Adapters_Registry( $add_license_caption_or_remove_task_adapter ), $plugin->get_version() ); |
|
| 511 | + $remove_all_images_task_page = new Remove_All_Images_Page( new Task_Ajax_Adapters_Registry( $remove_all_images_task_adapter ), $plugin->get_version() ); |
|
| 512 | + $reload_data_task_page = new Reload_Data_Page( new Task_Ajax_Adapters_Registry( $reload_data_task_adapter ), $plugin->get_version() ); |
|
| 513 | + $add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page( new Task_Ajax_Adapters_Registry( $add_license_caption_or_remove_task_adapter ), $plugin->get_version() ); |
|
| 514 | 514 | |
| 515 | - new Wordlift_Products_Navigator_Shortcode_REST(); |
|
| 515 | + new Wordlift_Products_Navigator_Shortcode_REST(); |
|
| 516 | 516 | |
| 517 | - // Register the Dataset module, requires `$api_service`. |
|
| 518 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
| 517 | + // Register the Dataset module, requires `$api_service`. |
|
| 518 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
| 519 | 519 | |
| 520 | - } ); |
|
| 520 | + } ); |
|
| 521 | 521 | |
| 522 | 522 | } |
| 523 | 523 | |
@@ -531,45 +531,45 @@ discard block |
||
| 531 | 531 | */ |
| 532 | 532 | function wordlift_plugin_autoload_register() { |
| 533 | 533 | |
| 534 | - spl_autoload_register( function ( $class_name ) { |
|
| 534 | + spl_autoload_register( function ( $class_name ) { |
|
| 535 | 535 | |
| 536 | - // Bail out if these are not our classes. |
|
| 537 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
| 538 | - return false; |
|
| 539 | - } |
|
| 536 | + // Bail out if these are not our classes. |
|
| 537 | + if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
| 538 | + return false; |
|
| 539 | + } |
|
| 540 | 540 | |
| 541 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
| 541 | + $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
| 542 | 542 | |
| 543 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
| 543 | + preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
| 544 | 544 | |
| 545 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
| 546 | - $file = 'class-' . $matches[2] . '.php'; |
|
| 545 | + $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
| 546 | + $file = 'class-' . $matches[2] . '.php'; |
|
| 547 | 547 | |
| 548 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
| 548 | + $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
| 549 | 549 | |
| 550 | - if ( ! file_exists( $full_path ) ) { |
|
| 551 | - echo( "Class $class_name not found at $full_path." ); |
|
| 550 | + if ( ! file_exists( $full_path ) ) { |
|
| 551 | + echo( "Class $class_name not found at $full_path." ); |
|
| 552 | 552 | |
| 553 | - return false; |
|
| 554 | - } |
|
| 553 | + return false; |
|
| 554 | + } |
|
| 555 | 555 | |
| 556 | - require_once $full_path; |
|
| 556 | + require_once $full_path; |
|
| 557 | 557 | |
| 558 | - return true; |
|
| 559 | - } ); |
|
| 558 | + return true; |
|
| 559 | + } ); |
|
| 560 | 560 | |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | function wl_block_categories( $categories, $post ) { |
| 564 | - return array_merge( |
|
| 565 | - $categories, |
|
| 566 | - array( |
|
| 567 | - array( |
|
| 568 | - 'slug' => 'wordlift', |
|
| 569 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
| 570 | - ), |
|
| 571 | - ) |
|
| 572 | - ); |
|
| 564 | + return array_merge( |
|
| 565 | + $categories, |
|
| 566 | + array( |
|
| 567 | + array( |
|
| 568 | + 'slug' => 'wordlift', |
|
| 569 | + 'title' => __( 'WordLift', 'wordlift' ), |
|
| 570 | + ), |
|
| 571 | + ) |
|
| 572 | + ); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | add_filter( 'block_categories', 'wl_block_categories', 10, 2 ); |
@@ -47,17 +47,17 @@ discard block |
||
| 47 | 47 | use Wordlift\Tasks\Task_Ajax_Adapters_Registry; |
| 48 | 48 | |
| 49 | 49 | // If this file is called directly, abort. |
| 50 | -if ( ! defined( 'WPINC' ) ) { |
|
| 50 | +if ( ! defined('WPINC')) { |
|
| 51 | 51 | die; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | -require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
|
| 54 | +require_once plugin_dir_path(__FILE__).'vendor/autoload.php'; |
|
| 55 | 55 | |
| 56 | 56 | // Include WordLift constants. |
| 57 | -require_once( 'wordlift_constants.php' ); |
|
| 57 | +require_once('wordlift_constants.php'); |
|
| 58 | 58 | |
| 59 | 59 | // Load modules. |
| 60 | -require_once( 'modules/core/wordlift_core.php' ); |
|
| 60 | +require_once('modules/core/wordlift_core.php'); |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * Log to the debug.log file. |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | * @deprecated use Wordlift_Log_Service::get_instance()->info( $log ); |
| 70 | 70 | * |
| 71 | 71 | */ |
| 72 | -function wl_write_log( $log ) { |
|
| 72 | +function wl_write_log($log) { |
|
| 73 | 73 | |
| 74 | - Wordlift_Log_Service::get_instance()->debug( $log ); |
|
| 74 | + Wordlift_Log_Service::get_instance()->debug($log); |
|
| 75 | 75 | |
| 76 | 76 | } |
| 77 | 77 | |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | * @since 3.0.0 |
| 87 | 87 | * |
| 88 | 88 | */ |
| 89 | -function wl_write_log_hide_key( $text ) { |
|
| 89 | +function wl_write_log_hide_key($text) { |
|
| 90 | 90 | |
| 91 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 91 | + return str_ireplace(wl_configuration_get_key(), '<hidden>', $text); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | function wordlift_allowed_post_tags() { |
| 99 | 99 | global $allowedposttags; |
| 100 | 100 | |
| 101 | - $tags = array( 'span' ); |
|
| 101 | + $tags = array('span'); |
|
| 102 | 102 | $new_attributes = array( |
| 103 | 103 | 'itemscope' => array(), |
| 104 | 104 | 'itemtype' => array(), |
@@ -106,15 +106,15 @@ discard block |
||
| 106 | 106 | 'itemid' => array(), |
| 107 | 107 | ); |
| 108 | 108 | |
| 109 | - foreach ( $tags as $tag ) { |
|
| 110 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 111 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 109 | + foreach ($tags as $tag) { |
|
| 110 | + if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) { |
|
| 111 | + $allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // add allowed post tags. |
| 117 | -add_action( 'init', 'wordlift_allowed_post_tags' ); |
|
| 117 | +add_action('init', 'wordlift_allowed_post_tags'); |
|
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * Register additional scripts for the admin UI. |
@@ -122,21 +122,21 @@ discard block |
||
| 122 | 122 | function wordlift_admin_enqueue_scripts() { |
| 123 | 123 | |
| 124 | 124 | // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
| 125 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 126 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 125 | + wp_enqueue_script('wpdialogs'); |
|
| 126 | + wp_enqueue_style('wp-jquery-ui-dialog'); |
|
| 127 | 127 | |
| 128 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 128 | + wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css'); |
|
| 129 | 129 | |
| 130 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 130 | + wp_enqueue_script('jquery-ui-autocomplete'); |
|
| 131 | 131 | |
| 132 | 132 | // Disable auto-save for custom entity posts only |
| 133 | - if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) { |
|
| 134 | - wp_dequeue_script( 'autosave' ); |
|
| 133 | + if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) { |
|
| 134 | + wp_dequeue_script('autosave'); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | -add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' ); |
|
| 139 | +add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts'); |
|
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes. |
@@ -146,23 +146,23 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @return array An array which contains allowed microdata attributes. |
| 148 | 148 | */ |
| 149 | -function wordlift_allowed_html( $allowedtags, $context ) { |
|
| 149 | +function wordlift_allowed_html($allowedtags, $context) { |
|
| 150 | 150 | |
| 151 | - if ( 'post' !== $context ) { |
|
| 151 | + if ('post' !== $context) { |
|
| 152 | 152 | return $allowedtags; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - return array_merge_recursive( $allowedtags, array( |
|
| 155 | + return array_merge_recursive($allowedtags, array( |
|
| 156 | 156 | 'span' => array( |
| 157 | 157 | 'itemscope' => true, |
| 158 | 158 | 'itemtype' => true, |
| 159 | 159 | 'itemid' => true, |
| 160 | 160 | 'itemprop' => true, |
| 161 | 161 | ), |
| 162 | - ) ); |
|
| 162 | + )); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | -add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
|
| 165 | +add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2); |
|
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | 168 | * Get the coordinates for the specified post ID. |
@@ -171,17 +171,17 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return array|null An array of coordinates or null. |
| 173 | 173 | */ |
| 174 | -function wl_get_coordinates( $post_id ) { |
|
| 174 | +function wl_get_coordinates($post_id) { |
|
| 175 | 175 | |
| 176 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 177 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 176 | + $latitude = wl_schema_get_value($post_id, 'latitude'); |
|
| 177 | + $longitude = wl_schema_get_value($post_id, 'longitude'); |
|
| 178 | 178 | |
| 179 | 179 | // DO NOT set latitude/longitude to 0/0 as default values. It's a specific |
| 180 | 180 | // place on the globe:"The zero/zero point of this system is located in the |
| 181 | 181 | // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
| 182 | 182 | return array( |
| 183 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 184 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 183 | + 'latitude' => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '', |
|
| 184 | + 'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '', |
|
| 185 | 185 | ); |
| 186 | 186 | } |
| 187 | 187 | |
@@ -194,11 +194,11 @@ discard block |
||
| 194 | 194 | * @deprecated use Wordlift_Storage_Factory::get_instance()->post_images()->get( $post_id ) |
| 195 | 195 | * |
| 196 | 196 | */ |
| 197 | -function wl_get_image_urls( $post_id ) { |
|
| 197 | +function wl_get_image_urls($post_id) { |
|
| 198 | 198 | |
| 199 | 199 | return Wordlift_Storage_Factory::get_instance() |
| 200 | 200 | ->post_images() |
| 201 | - ->get( $post_id ); |
|
| 201 | + ->get($post_id); |
|
| 202 | 202 | |
| 203 | 203 | } |
| 204 | 204 | |
@@ -210,21 +210,21 @@ discard block |
||
| 210 | 210 | * |
| 211 | 211 | * @return WP_Post|null A post instance or null if not found. |
| 212 | 212 | */ |
| 213 | -function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
|
| 213 | +function wl_get_attachment_for_source_url($parent_post_id, $source_url) { |
|
| 214 | 214 | |
| 215 | 215 | // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
| 216 | 216 | |
| 217 | - $posts = get_posts( array( |
|
| 217 | + $posts = get_posts(array( |
|
| 218 | 218 | 'post_type' => 'attachment', |
| 219 | 219 | 'posts_per_page' => 1, |
| 220 | 220 | 'post_status' => 'any', |
| 221 | 221 | 'post_parent' => $parent_post_id, |
| 222 | 222 | 'meta_key' => 'wl_source_url', |
| 223 | 223 | 'meta_value' => $source_url, |
| 224 | - ) ); |
|
| 224 | + )); |
|
| 225 | 225 | |
| 226 | 226 | // Return the found post. |
| 227 | - if ( 1 === count( $posts ) ) { |
|
| 227 | + if (1 === count($posts)) { |
|
| 228 | 228 | return $posts[0]; |
| 229 | 229 | } |
| 230 | 230 | |
@@ -238,10 +238,10 @@ discard block |
||
| 238 | 238 | * @param int $post_id The post ID. |
| 239 | 239 | * @param string $source_url The source URL. |
| 240 | 240 | */ |
| 241 | -function wl_set_source_url( $post_id, $source_url ) { |
|
| 241 | +function wl_set_source_url($post_id, $source_url) { |
|
| 242 | 242 | |
| 243 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 244 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 243 | + delete_post_meta($post_id, 'wl_source_url'); |
|
| 244 | + add_post_meta($post_id, 'wl_source_url', $source_url); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | * @see https://codex.wordpress.org/Function_Reference/sanitize_title |
| 257 | 257 | * |
| 258 | 258 | */ |
| 259 | -function wl_sanitize_uri_path( $path, $char = '_' ) { |
|
| 259 | +function wl_sanitize_uri_path($path, $char = '_') { |
|
| 260 | 260 | |
| 261 | - return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char ); |
|
| 261 | + return Wordlift_Uri_Service::get_instance()->sanitize_path($path, $char); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -268,104 +268,104 @@ discard block |
||
| 268 | 268 | * |
| 269 | 269 | * @return string The updated post content. |
| 270 | 270 | */ |
| 271 | -function wl_replace_item_id_with_uri( $content ) { |
|
| 271 | +function wl_replace_item_id_with_uri($content) { |
|
| 272 | 272 | |
| 273 | - $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' ); |
|
| 274 | - $log->trace( 'Replacing item IDs with URIs...' ); |
|
| 273 | + $log = Wordlift_Log_Service::get_logger('wl_replace_item_id_with_uri'); |
|
| 274 | + $log->trace('Replacing item IDs with URIs...'); |
|
| 275 | 275 | |
| 276 | 276 | // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
| 277 | - $content = stripslashes( $content ); |
|
| 277 | + $content = stripslashes($content); |
|
| 278 | 278 | |
| 279 | 279 | // If any match are found. |
| 280 | 280 | $matches = array(); |
| 281 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 281 | + if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) { |
|
| 282 | 282 | |
| 283 | - foreach ( $matches as $match ) { |
|
| 283 | + foreach ($matches as $match) { |
|
| 284 | 284 | |
| 285 | 285 | // Get the item ID. |
| 286 | 286 | $item_id = $match[1]; |
| 287 | 287 | |
| 288 | 288 | // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
| 289 | 289 | $post = Wordlift_Entity_Service::get_instance() |
| 290 | - ->get_entity_post_by_uri( $item_id ); |
|
| 290 | + ->get_entity_post_by_uri($item_id); |
|
| 291 | 291 | |
| 292 | 292 | // If no entity is found, continue to the next one. |
| 293 | - if ( null === $post ) { |
|
| 293 | + if (null === $post) { |
|
| 294 | 294 | continue; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | // Get the URI for that post. |
| 298 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 298 | + $uri = wl_get_entity_uri($post->ID); |
|
| 299 | 299 | |
| 300 | 300 | // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
| 301 | 301 | |
| 302 | 302 | // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
| 303 | - if ( $item_id !== $uri ) { |
|
| 304 | - $uri_e = esc_html( $uri ); |
|
| 305 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 303 | + if ($item_id !== $uri) { |
|
| 304 | + $uri_e = esc_html($uri); |
|
| 305 | + $content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content); |
|
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | // Reapply slashes. |
| 311 | - $content = addslashes( $content ); |
|
| 311 | + $content = addslashes($content); |
|
| 312 | 312 | |
| 313 | 313 | return $content; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | -add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
|
| 316 | +add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1); |
|
| 317 | 317 | |
| 318 | -require_once( 'wordlift_entity_functions.php' ); |
|
| 318 | +require_once('wordlift_entity_functions.php'); |
|
| 319 | 319 | |
| 320 | 320 | // add editor related methods. |
| 321 | -require_once( 'wordlift_editor.php' ); |
|
| 321 | +require_once('wordlift_editor.php'); |
|
| 322 | 322 | |
| 323 | 323 | // add the WordLift entity custom type. |
| 324 | -require_once( 'wordlift_entity_type.php' ); |
|
| 324 | +require_once('wordlift_entity_type.php'); |
|
| 325 | 325 | |
| 326 | 326 | // add callbacks on post save to notify data changes from wp to redlink triple store |
| 327 | -require_once( 'wordlift_to_redlink_data_push_callbacks.php' ); |
|
| 327 | +require_once('wordlift_to_redlink_data_push_callbacks.php'); |
|
| 328 | 328 | |
| 329 | -require_once( 'modules/configuration/wordlift_configuration_settings.php' ); |
|
| 329 | +require_once('modules/configuration/wordlift_configuration_settings.php'); |
|
| 330 | 330 | |
| 331 | 331 | // Load modules |
| 332 | -require_once( 'modules/analyzer/wordlift_analyzer.php' ); |
|
| 333 | -require_once( 'modules/linked_data/wordlift_linked_data.php' ); |
|
| 334 | -require_once( 'modules/prefixes/wordlift_prefixes.php' ); |
|
| 332 | +require_once('modules/analyzer/wordlift_analyzer.php'); |
|
| 333 | +require_once('modules/linked_data/wordlift_linked_data.php'); |
|
| 334 | +require_once('modules/prefixes/wordlift_prefixes.php'); |
|
| 335 | 335 | |
| 336 | 336 | // Shortcodes |
| 337 | 337 | |
| 338 | -require_once( 'modules/geo_widget/wordlift_geo_widget.php' ); |
|
| 339 | -require_once( 'shortcodes/class-wordlift-shortcode-rest.php' ); |
|
| 340 | -require_once( 'shortcodes/wordlift_shortcode_chord.php' ); |
|
| 341 | -require_once( 'shortcodes/wordlift_shortcode_geomap.php' ); |
|
| 342 | -require_once( 'shortcodes/wordlift_shortcode_field.php' ); |
|
| 343 | -require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' ); |
|
| 344 | -require_once( 'shortcodes/wordlift_shortcode_navigator.php' ); |
|
| 345 | -require_once( 'shortcodes/class-wordlift-products-navigator-shortcode-rest.php' ); |
|
| 338 | +require_once('modules/geo_widget/wordlift_geo_widget.php'); |
|
| 339 | +require_once('shortcodes/class-wordlift-shortcode-rest.php'); |
|
| 340 | +require_once('shortcodes/wordlift_shortcode_chord.php'); |
|
| 341 | +require_once('shortcodes/wordlift_shortcode_geomap.php'); |
|
| 342 | +require_once('shortcodes/wordlift_shortcode_field.php'); |
|
| 343 | +require_once('shortcodes/wordlift_shortcode_faceted_search.php'); |
|
| 344 | +require_once('shortcodes/wordlift_shortcode_navigator.php'); |
|
| 345 | +require_once('shortcodes/class-wordlift-products-navigator-shortcode-rest.php'); |
|
| 346 | 346 | |
| 347 | -require_once( 'widgets/wordlift_widget_geo.php' ); |
|
| 348 | -require_once( 'widgets/class-wordlift-chord-widget.php' ); |
|
| 349 | -require_once( 'widgets/wordlift_widget_timeline.php' ); |
|
| 347 | +require_once('widgets/wordlift_widget_geo.php'); |
|
| 348 | +require_once('widgets/class-wordlift-chord-widget.php'); |
|
| 349 | +require_once('widgets/wordlift_widget_timeline.php'); |
|
| 350 | 350 | |
| 351 | -require_once( 'wordlift_redlink.php' ); |
|
| 351 | +require_once('wordlift_redlink.php'); |
|
| 352 | 352 | |
| 353 | 353 | // Add admin functions. |
| 354 | 354 | // TODO: find a way to make 'admin' UI tests work. |
| 355 | 355 | //if ( is_admin() ) { |
| 356 | 356 | |
| 357 | -require_once( 'admin/wordlift_admin.php' ); |
|
| 358 | -require_once( 'admin/wordlift_admin_edit_post.php' ); |
|
| 359 | -require_once( 'admin/wordlift_admin_save_post.php' ); |
|
| 357 | +require_once('admin/wordlift_admin.php'); |
|
| 358 | +require_once('admin/wordlift_admin_edit_post.php'); |
|
| 359 | +require_once('admin/wordlift_admin_save_post.php'); |
|
| 360 | 360 | |
| 361 | 361 | // add the entities meta box. |
| 362 | -require_once( 'admin/wordlift_admin_meta_box_entities.php' ); |
|
| 362 | +require_once('admin/wordlift_admin_meta_box_entities.php'); |
|
| 363 | 363 | |
| 364 | 364 | // add the entity creation AJAX. |
| 365 | -require_once( 'admin/wordlift_admin_ajax_related_posts.php' ); |
|
| 365 | +require_once('admin/wordlift_admin_ajax_related_posts.php'); |
|
| 366 | 366 | |
| 367 | 367 | // Load the wl_chord TinyMCE button and configuration dialog. |
| 368 | -require_once( 'admin/wordlift_admin_shortcodes.php' ); |
|
| 368 | +require_once('admin/wordlift_admin_shortcodes.php'); |
|
| 369 | 369 | |
| 370 | 370 | /** |
| 371 | 371 | * The code that runs during plugin activation. |
@@ -373,11 +373,11 @@ discard block |
||
| 373 | 373 | */ |
| 374 | 374 | function activate_wordlift() { |
| 375 | 375 | |
| 376 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
| 376 | + $log = Wordlift_Log_Service::get_logger('activate_wordlift'); |
|
| 377 | 377 | |
| 378 | - $log->info( 'Activating WordLift...' ); |
|
| 378 | + $log->info('Activating WordLift...'); |
|
| 379 | 379 | |
| 380 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 380 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
| 381 | 381 | Wordlift_Activator::activate(); |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | */ |
| 400 | 400 | function deactivate_wordlift() { |
| 401 | 401 | |
| 402 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 402 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
| 403 | 403 | Wordlift_Deactivator::deactivate(); |
| 404 | 404 | Wordlift_Http_Api::deactivate(); |
| 405 | 405 | Ttl_Cache_Cleaner::deactivate(); |
@@ -407,14 +407,14 @@ discard block |
||
| 407 | 407 | |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
| 411 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
| 410 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
| 411 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
| 412 | 412 | |
| 413 | 413 | /** |
| 414 | 414 | * The core plugin class that is used to define internationalization, |
| 415 | 415 | * admin-specific hooks, and public-facing site hooks. |
| 416 | 416 | */ |
| 417 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
| 417 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
| 418 | 418 | |
| 419 | 419 | /** |
| 420 | 420 | * Begins execution of the plugin. |
@@ -434,12 +434,12 @@ discard block |
||
| 434 | 434 | * @return bool |
| 435 | 435 | * @since 3.27.6 |
| 436 | 436 | */ |
| 437 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
| 438 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 439 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
| 440 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
| 437 | + if (apply_filters('wl_feature__enable__widgets', true)) { |
|
| 438 | + add_action('widgets_init', 'wl_register_chord_widget'); |
|
| 439 | + add_action('widgets_init', 'wl_register_geo_widget'); |
|
| 440 | + add_action('widgets_init', 'wl_register_timeline_widget'); |
|
| 441 | 441 | } |
| 442 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
| 442 | + add_filter('widget_text', 'do_shortcode'); |
|
| 443 | 443 | |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -450,10 +450,10 @@ discard block |
||
| 450 | 450 | * @return bool |
| 451 | 451 | * @since 3.27.6 |
| 452 | 452 | */ |
| 453 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
| 454 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
| 453 | + if (apply_filters('wl_feature__enable__analysis', true)) { |
|
| 454 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action'); |
|
| 455 | 455 | } else { |
| 456 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
| 456 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action'); |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | /* |
@@ -475,47 +475,47 @@ discard block |
||
| 475 | 475 | // Load the API Data Hooks. |
| 476 | 476 | new Api_Data_Hooks(); |
| 477 | 477 | |
| 478 | - add_action( 'plugins_loaded', function () use ( $plugin ) { |
|
| 478 | + add_action('plugins_loaded', function() use ($plugin) { |
|
| 479 | 479 | // Load early. **PLEASE NOTE** that features are applied only to calls that happen **AFTER** the `plugins_loaded` |
| 480 | 480 | // action. |
| 481 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php'; |
|
| 481 | + require_once plugin_dir_path(__FILE__).'wordlift/features/index.php'; |
|
| 482 | 482 | |
| 483 | 483 | // Licenses Images. |
| 484 | 484 | $user_agent = User_Agent::get_user_agent(); |
| 485 | 485 | $wordlift_key = Wordlift_Configuration_Service::get_instance()->get_key(); |
| 486 | - $api_service = new Default_Api_Service( apply_filters( 'wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE ), 60, $user_agent, $wordlift_key ); |
|
| 486 | + $api_service = new Default_Api_Service(apply_filters('wl_api_base_url', WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE), 60, $user_agent, $wordlift_key); |
|
| 487 | 487 | $image_license_factory = new Image_License_Factory(); |
| 488 | - $image_license_service = new Image_License_Service( $api_service, $image_license_factory ); |
|
| 489 | - $image_license_cache = new Ttl_Cache( 'image-license', 86400 * 30 ); // 30 days. |
|
| 490 | - $cached_image_license_service = new Cached_Image_License_Service( $image_license_service, $image_license_cache ); |
|
| 488 | + $image_license_service = new Image_License_Service($api_service, $image_license_factory); |
|
| 489 | + $image_license_cache = new Ttl_Cache('image-license', 86400 * 30); // 30 days. |
|
| 490 | + $cached_image_license_service = new Cached_Image_License_Service($image_license_service, $image_license_cache); |
|
| 491 | 491 | |
| 492 | - $image_license_scheduler = new Image_License_Scheduler( $image_license_service, $image_license_cache ); |
|
| 492 | + $image_license_scheduler = new Image_License_Scheduler($image_license_service, $image_license_cache); |
|
| 493 | 493 | $image_license_cleanup_service = new Image_License_Cleanup_Service(); |
| 494 | 494 | |
| 495 | 495 | // Get the cached data. If we have cached data, we load the notifier. |
| 496 | - $image_license_data = $image_license_cache->get( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES ); |
|
| 497 | - if ( null !== $image_license_data ) { |
|
| 498 | - $image_license_page = new Image_License_Page( $image_license_data, Wordlift::get_instance()->get_version() ); |
|
| 499 | - new Image_License_Notifier( $image_license_data, $image_license_page ); |
|
| 496 | + $image_license_data = $image_license_cache->get(Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES); |
|
| 497 | + if (null !== $image_license_data) { |
|
| 498 | + $image_license_page = new Image_License_Page($image_license_data, Wordlift::get_instance()->get_version()); |
|
| 499 | + new Image_License_Notifier($image_license_data, $image_license_page); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | - $remove_all_images_task = new Remove_All_Images_Task( $cached_image_license_service ); |
|
| 503 | - $remove_all_images_task_adapter = new Task_Ajax_Adapter( $remove_all_images_task ); |
|
| 502 | + $remove_all_images_task = new Remove_All_Images_Task($cached_image_license_service); |
|
| 503 | + $remove_all_images_task_adapter = new Task_Ajax_Adapter($remove_all_images_task); |
|
| 504 | 504 | |
| 505 | 505 | $reload_data_task = new Reload_Data_Task(); |
| 506 | - $reload_data_task_adapter = new Task_Ajax_Adapter( $reload_data_task ); |
|
| 506 | + $reload_data_task_adapter = new Task_Ajax_Adapter($reload_data_task); |
|
| 507 | 507 | |
| 508 | - $add_license_caption_or_remove_task = new Add_License_Caption_Or_Remove_Task( $cached_image_license_service ); |
|
| 509 | - $add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter( $add_license_caption_or_remove_task ); |
|
| 508 | + $add_license_caption_or_remove_task = new Add_License_Caption_Or_Remove_Task($cached_image_license_service); |
|
| 509 | + $add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter($add_license_caption_or_remove_task); |
|
| 510 | 510 | |
| 511 | - $remove_all_images_task_page = new Remove_All_Images_Page( new Task_Ajax_Adapters_Registry( $remove_all_images_task_adapter ), $plugin->get_version() ); |
|
| 512 | - $reload_data_task_page = new Reload_Data_Page( new Task_Ajax_Adapters_Registry( $reload_data_task_adapter ), $plugin->get_version() ); |
|
| 513 | - $add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page( new Task_Ajax_Adapters_Registry( $add_license_caption_or_remove_task_adapter ), $plugin->get_version() ); |
|
| 511 | + $remove_all_images_task_page = new Remove_All_Images_Page(new Task_Ajax_Adapters_Registry($remove_all_images_task_adapter), $plugin->get_version()); |
|
| 512 | + $reload_data_task_page = new Reload_Data_Page(new Task_Ajax_Adapters_Registry($reload_data_task_adapter), $plugin->get_version()); |
|
| 513 | + $add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page(new Task_Ajax_Adapters_Registry($add_license_caption_or_remove_task_adapter), $plugin->get_version()); |
|
| 514 | 514 | |
| 515 | 515 | new Wordlift_Products_Navigator_Shortcode_REST(); |
| 516 | 516 | |
| 517 | 517 | // Register the Dataset module, requires `$api_service`. |
| 518 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
| 518 | + require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php'; |
|
| 519 | 519 | |
| 520 | 520 | } ); |
| 521 | 521 | |
@@ -531,24 +531,24 @@ discard block |
||
| 531 | 531 | */ |
| 532 | 532 | function wordlift_plugin_autoload_register() { |
| 533 | 533 | |
| 534 | - spl_autoload_register( function ( $class_name ) { |
|
| 534 | + spl_autoload_register(function($class_name) { |
|
| 535 | 535 | |
| 536 | 536 | // Bail out if these are not our classes. |
| 537 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
| 537 | + if (0 !== strpos($class_name, 'Wordlift\\')) { |
|
| 538 | 538 | return false; |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
| 541 | + $class_name_lc = strtolower(str_replace('_', '-', $class_name)); |
|
| 542 | 542 | |
| 543 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
| 543 | + preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches); |
|
| 544 | 544 | |
| 545 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
| 546 | - $file = 'class-' . $matches[2] . '.php'; |
|
| 545 | + $path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]); |
|
| 546 | + $file = 'class-'.$matches[2].'.php'; |
|
| 547 | 547 | |
| 548 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
| 548 | + $full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file; |
|
| 549 | 549 | |
| 550 | - if ( ! file_exists( $full_path ) ) { |
|
| 551 | - echo( "Class $class_name not found at $full_path." ); |
|
| 550 | + if ( ! file_exists($full_path)) { |
|
| 551 | + echo("Class $class_name not found at $full_path."); |
|
| 552 | 552 | |
| 553 | 553 | return false; |
| 554 | 554 | } |
@@ -560,16 +560,16 @@ discard block |
||
| 560 | 560 | |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | -function wl_block_categories( $categories, $post ) { |
|
| 563 | +function wl_block_categories($categories, $post) { |
|
| 564 | 564 | return array_merge( |
| 565 | 565 | $categories, |
| 566 | 566 | array( |
| 567 | 567 | array( |
| 568 | 568 | 'slug' => 'wordlift', |
| 569 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
| 569 | + 'title' => __('WordLift', 'wordlift'), |
|
| 570 | 570 | ), |
| 571 | 571 | ) |
| 572 | 572 | ); |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | -add_filter( 'block_categories', 'wl_block_categories', 10, 2 ); |
|
| 575 | +add_filter('block_categories', 'wl_block_categories', 10, 2); |
|
@@ -7,122 +7,122 @@ |
||
| 7 | 7 | namespace Wordlift\Api; |
| 8 | 8 | |
| 9 | 9 | class Default_Api_Service implements Api_Service { |
| 10 | - /** |
|
| 11 | - * @var Default_Api_Service |
|
| 12 | - */ |
|
| 13 | - private static $instance; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - private $wordlift_key; |
|
| 19 | - /** |
|
| 20 | - * @var int |
|
| 21 | - */ |
|
| 22 | - private $timeout; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - private $user_agent; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - private $headers; |
|
| 33 | - /** |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - private $base_url; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var \Wordlift_Log_Service |
|
| 40 | - */ |
|
| 41 | - private $log; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Default_Api_Service constructor. |
|
| 45 | - * |
|
| 46 | - * @param string $base_url |
|
| 47 | - * @param int $timeout |
|
| 48 | - * @param string $user_agent |
|
| 49 | - * @param string $wordlift_key |
|
| 50 | - */ |
|
| 51 | - public function __construct( $base_url, $timeout, $user_agent, $wordlift_key ) { |
|
| 52 | - |
|
| 53 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 54 | - |
|
| 55 | - $this->base_url = untrailingslashit( $base_url ); |
|
| 56 | - $this->timeout = $timeout; |
|
| 57 | - $this->user_agent = $user_agent; |
|
| 58 | - $this->wordlift_key = $wordlift_key; |
|
| 59 | - |
|
| 60 | - $this->headers = array( |
|
| 61 | - 'Content-Type' => 'application/json', |
|
| 62 | - 'Authorization' => "Key $wordlift_key", |
|
| 63 | - 'Expect' => '', |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - self::$instance = $this; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public static function get_instance() { |
|
| 70 | - return self::$instance; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function request( $method, $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) { |
|
| 74 | - |
|
| 75 | - // Get the timeout for this request. |
|
| 76 | - $request_timeout = isset( $timeout ) ? $timeout : $this->timeout; |
|
| 77 | - |
|
| 78 | - // Set the time limit if lesser than our request timeout. |
|
| 79 | - $max_execution_time = ini_get( 'max_execution_time' ); |
|
| 80 | - if ( $max_execution_time < $request_timeout ) { |
|
| 81 | - @set_time_limit( $request_timeout ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $request_url = $this->base_url . $path; |
|
| 85 | - |
|
| 86 | - // Create the request args in the following order: |
|
| 87 | - // 1. use `$args` as base if provided. |
|
| 88 | - // 2. set the custom timeout if provided. |
|
| 89 | - // 3. set the custom user-agent if provided. |
|
| 90 | - // 4. merge the API headers to the provided headers. |
|
| 91 | - // 5. add the body. |
|
| 92 | - // |
|
| 93 | - // In this way the user can fully control the request if wanted (using `$args`) and we can add our defaults. |
|
| 94 | - $request_args = $args + array( |
|
| 95 | - 'method' => $method, |
|
| 96 | - 'timeout' => $request_timeout, |
|
| 97 | - 'user-agent' => isset( $user_agent ) ? $user_agent : $this->user_agent, |
|
| 98 | - 'headers' => $headers + $this->headers, |
|
| 99 | - 'body' => $body, |
|
| 100 | - ); |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Allow 3rd parties to process the response. |
|
| 104 | - */ |
|
| 105 | - $response = apply_filters( 'wl_api_service__response', |
|
| 106 | - wp_remote_request( $request_url, $request_args ), $request_url, $request_args ); |
|
| 107 | - |
|
| 108 | - if ( defined( 'WL_DEBUG' ) && WL_DEBUG ) { |
|
| 109 | - $this->log->trace( |
|
| 110 | - "=== REQUEST ===========================\n" |
|
| 111 | - . var_export( $request_args, true ) |
|
| 112 | - . "=== RESPONSE ===========================\n" |
|
| 113 | - . var_export( $response, true ) ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return new Response( $response ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function get( $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) { |
|
| 120 | - |
|
| 121 | - return $this->request( 'GET', $path, $headers, $body, $timeout, $user_agent, $args ); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function get_base_url() { |
|
| 125 | - return $this->base_url; |
|
| 126 | - } |
|
| 10 | + /** |
|
| 11 | + * @var Default_Api_Service |
|
| 12 | + */ |
|
| 13 | + private static $instance; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + private $wordlift_key; |
|
| 19 | + /** |
|
| 20 | + * @var int |
|
| 21 | + */ |
|
| 22 | + private $timeout; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + private $user_agent; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + private $headers; |
|
| 33 | + /** |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + private $base_url; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var \Wordlift_Log_Service |
|
| 40 | + */ |
|
| 41 | + private $log; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Default_Api_Service constructor. |
|
| 45 | + * |
|
| 46 | + * @param string $base_url |
|
| 47 | + * @param int $timeout |
|
| 48 | + * @param string $user_agent |
|
| 49 | + * @param string $wordlift_key |
|
| 50 | + */ |
|
| 51 | + public function __construct( $base_url, $timeout, $user_agent, $wordlift_key ) { |
|
| 52 | + |
|
| 53 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 54 | + |
|
| 55 | + $this->base_url = untrailingslashit( $base_url ); |
|
| 56 | + $this->timeout = $timeout; |
|
| 57 | + $this->user_agent = $user_agent; |
|
| 58 | + $this->wordlift_key = $wordlift_key; |
|
| 59 | + |
|
| 60 | + $this->headers = array( |
|
| 61 | + 'Content-Type' => 'application/json', |
|
| 62 | + 'Authorization' => "Key $wordlift_key", |
|
| 63 | + 'Expect' => '', |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + self::$instance = $this; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public static function get_instance() { |
|
| 70 | + return self::$instance; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function request( $method, $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) { |
|
| 74 | + |
|
| 75 | + // Get the timeout for this request. |
|
| 76 | + $request_timeout = isset( $timeout ) ? $timeout : $this->timeout; |
|
| 77 | + |
|
| 78 | + // Set the time limit if lesser than our request timeout. |
|
| 79 | + $max_execution_time = ini_get( 'max_execution_time' ); |
|
| 80 | + if ( $max_execution_time < $request_timeout ) { |
|
| 81 | + @set_time_limit( $request_timeout ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $request_url = $this->base_url . $path; |
|
| 85 | + |
|
| 86 | + // Create the request args in the following order: |
|
| 87 | + // 1. use `$args` as base if provided. |
|
| 88 | + // 2. set the custom timeout if provided. |
|
| 89 | + // 3. set the custom user-agent if provided. |
|
| 90 | + // 4. merge the API headers to the provided headers. |
|
| 91 | + // 5. add the body. |
|
| 92 | + // |
|
| 93 | + // In this way the user can fully control the request if wanted (using `$args`) and we can add our defaults. |
|
| 94 | + $request_args = $args + array( |
|
| 95 | + 'method' => $method, |
|
| 96 | + 'timeout' => $request_timeout, |
|
| 97 | + 'user-agent' => isset( $user_agent ) ? $user_agent : $this->user_agent, |
|
| 98 | + 'headers' => $headers + $this->headers, |
|
| 99 | + 'body' => $body, |
|
| 100 | + ); |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Allow 3rd parties to process the response. |
|
| 104 | + */ |
|
| 105 | + $response = apply_filters( 'wl_api_service__response', |
|
| 106 | + wp_remote_request( $request_url, $request_args ), $request_url, $request_args ); |
|
| 107 | + |
|
| 108 | + if ( defined( 'WL_DEBUG' ) && WL_DEBUG ) { |
|
| 109 | + $this->log->trace( |
|
| 110 | + "=== REQUEST ===========================\n" |
|
| 111 | + . var_export( $request_args, true ) |
|
| 112 | + . "=== RESPONSE ===========================\n" |
|
| 113 | + . var_export( $response, true ) ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return new Response( $response ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function get( $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) { |
|
| 120 | + |
|
| 121 | + return $this->request( 'GET', $path, $headers, $body, $timeout, $user_agent, $args ); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function get_base_url() { |
|
| 125 | + return $this->base_url; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | 128 | } |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | * @param string $user_agent |
| 49 | 49 | * @param string $wordlift_key |
| 50 | 50 | */ |
| 51 | - public function __construct( $base_url, $timeout, $user_agent, $wordlift_key ) { |
|
| 51 | + public function __construct($base_url, $timeout, $user_agent, $wordlift_key) { |
|
| 52 | 52 | |
| 53 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
| 53 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
| 54 | 54 | |
| 55 | - $this->base_url = untrailingslashit( $base_url ); |
|
| 55 | + $this->base_url = untrailingslashit($base_url); |
|
| 56 | 56 | $this->timeout = $timeout; |
| 57 | 57 | $this->user_agent = $user_agent; |
| 58 | 58 | $this->wordlift_key = $wordlift_key; |
@@ -70,18 +70,18 @@ discard block |
||
| 70 | 70 | return self::$instance; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function request( $method, $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) { |
|
| 73 | + public function request($method, $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array()) { |
|
| 74 | 74 | |
| 75 | 75 | // Get the timeout for this request. |
| 76 | - $request_timeout = isset( $timeout ) ? $timeout : $this->timeout; |
|
| 76 | + $request_timeout = isset($timeout) ? $timeout : $this->timeout; |
|
| 77 | 77 | |
| 78 | 78 | // Set the time limit if lesser than our request timeout. |
| 79 | - $max_execution_time = ini_get( 'max_execution_time' ); |
|
| 80 | - if ( $max_execution_time < $request_timeout ) { |
|
| 81 | - @set_time_limit( $request_timeout ); |
|
| 79 | + $max_execution_time = ini_get('max_execution_time'); |
|
| 80 | + if ($max_execution_time < $request_timeout) { |
|
| 81 | + @set_time_limit($request_timeout); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - $request_url = $this->base_url . $path; |
|
| 84 | + $request_url = $this->base_url.$path; |
|
| 85 | 85 | |
| 86 | 86 | // Create the request args in the following order: |
| 87 | 87 | // 1. use `$args` as base if provided. |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $request_args = $args + array( |
| 95 | 95 | 'method' => $method, |
| 96 | 96 | 'timeout' => $request_timeout, |
| 97 | - 'user-agent' => isset( $user_agent ) ? $user_agent : $this->user_agent, |
|
| 97 | + 'user-agent' => isset($user_agent) ? $user_agent : $this->user_agent, |
|
| 98 | 98 | 'headers' => $headers + $this->headers, |
| 99 | 99 | 'body' => $body, |
| 100 | 100 | ); |
@@ -102,23 +102,23 @@ discard block |
||
| 102 | 102 | /** |
| 103 | 103 | * Allow 3rd parties to process the response. |
| 104 | 104 | */ |
| 105 | - $response = apply_filters( 'wl_api_service__response', |
|
| 106 | - wp_remote_request( $request_url, $request_args ), $request_url, $request_args ); |
|
| 105 | + $response = apply_filters('wl_api_service__response', |
|
| 106 | + wp_remote_request($request_url, $request_args), $request_url, $request_args); |
|
| 107 | 107 | |
| 108 | - if ( defined( 'WL_DEBUG' ) && WL_DEBUG ) { |
|
| 108 | + if (defined('WL_DEBUG') && WL_DEBUG) { |
|
| 109 | 109 | $this->log->trace( |
| 110 | 110 | "=== REQUEST ===========================\n" |
| 111 | - . var_export( $request_args, true ) |
|
| 111 | + . var_export($request_args, true) |
|
| 112 | 112 | . "=== RESPONSE ===========================\n" |
| 113 | - . var_export( $response, true ) ); |
|
| 113 | + . var_export($response, true) ); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - return new Response( $response ); |
|
| 116 | + return new Response($response); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - public function get( $path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array() ) { |
|
| 119 | + public function get($path, $headers = array(), $body = null, $timeout = null, $user_agent = null, $args = array()) { |
|
| 120 | 120 | |
| 121 | - return $this->request( 'GET', $path, $headers, $body, $timeout, $user_agent, $args ); |
|
| 121 | + return $this->request('GET', $path, $headers, $body, $timeout, $user_agent, $args); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | public function get_base_url() { |
@@ -6,28 +6,28 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | // Define the basic options for HTTP calls to REDLINK. |
| 9 | -define( 'WL_REDLINK_API_HTTP_OPTIONS', serialize( array( |
|
| 9 | +define('WL_REDLINK_API_HTTP_OPTIONS', serialize(array( |
|
| 10 | 10 | 'timeout' => 300, |
| 11 | 11 | 'redirection' => 5, |
| 12 | 12 | 'httpversion' => '1.1', |
| 13 | 13 | 'blocking' => true, |
| 14 | 14 | 'cookies' => array(), |
| 15 | - 'sslverify' => ( 'false' === getenv( 'WL_SSL_VERIFY_ENABLED' ) ) ? false : true, |
|
| 15 | + 'sslverify' => ('false' === getenv('WL_SSL_VERIFY_ENABLED')) ? false : true, |
|
| 16 | 16 | //'sslcertificates' => dirname( __FILE__ ) . '/ssl/ca-bundle.crt', |
| 17 | 17 | 'decompress' => false, |
| 18 | -) ) ); |
|
| 18 | +))); |
|
| 19 | 19 | |
| 20 | 20 | // Create a unique ID for this request, useful to hook async HTTP requests. |
| 21 | -define( 'WL_REQUEST_ID', uniqid( true ) ); |
|
| 21 | +define('WL_REQUEST_ID', uniqid(true)); |
|
| 22 | 22 | |
| 23 | 23 | // Set the temporary files folder. |
| 24 | -defined( 'WL_TEMP_DIR' ) || define( 'WL_TEMP_DIR', wl_temp_dir() ); |
|
| 24 | +defined('WL_TEMP_DIR') || define('WL_TEMP_DIR', wl_temp_dir()); |
|
| 25 | 25 | |
| 26 | -define( 'WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING', wl_is_sparql_update_queries_buffering_enabled() ); |
|
| 26 | +define('WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING', wl_is_sparql_update_queries_buffering_enabled()); |
|
| 27 | 27 | |
| 28 | 28 | function wl_is_sparql_update_queries_buffering_enabled() { |
| 29 | 29 | |
| 30 | - if ( isset( $_REQUEST['wl-async'] ) && 'false' === $_REQUEST['wl-async'] ) { |
|
| 30 | + if (isset($_REQUEST['wl-async']) && 'false' === $_REQUEST['wl-async']) { |
|
| 31 | 31 | return false; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -35,43 +35,43 @@ discard block |
||
| 35 | 35 | * Switching to disabled by default. |
| 36 | 36 | */ |
| 37 | 37 | // return 'true' !== getenv( 'WL_DISABLE_SPARQL_UPDATE_QUERIES_BUFFERING' ); |
| 38 | - return 'yes' === getenv( 'WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING' ); |
|
| 38 | + return 'yes' === getenv('WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING'); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // Define the meta name used to store the entity URL. |
| 42 | -define( 'WL_ENTITY_URL_META_NAME', 'entity_url' ); |
|
| 42 | +define('WL_ENTITY_URL_META_NAME', 'entity_url'); |
|
| 43 | 43 | |
| 44 | 44 | // Max number of recursions when printing microdata. |
| 45 | -define( 'WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING', 3 ); |
|
| 45 | +define('WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING', 3); |
|
| 46 | 46 | |
| 47 | 47 | // Use the WordLift API URL set on the command line. |
| 48 | -if ( ! defined( 'WORDLIFT_API_URL' ) && false !== getenv( 'WORDLIFT_API_URL' ) ) { |
|
| 49 | - define( 'WORDLIFT_API_URL', getenv( 'WORDLIFT_API_URL' ) ); |
|
| 48 | +if ( ! defined('WORDLIFT_API_URL') && false !== getenv('WORDLIFT_API_URL')) { |
|
| 49 | + define('WORDLIFT_API_URL', getenv('WORDLIFT_API_URL')); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // 3.13.0, we use by default WLS 1.11 which provides us with the new, faster |
| 53 | 53 | // chunked analysis. |
| 54 | -define( 'WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined( 'WORDLIFT_API_URL' ) ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.io/' ); |
|
| 54 | +define('WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined('WORDLIFT_API_URL') ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.io/'); |
|
| 55 | 55 | |
| 56 | -define( 'WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url=' ); |
|
| 56 | +define('WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url='); |
|
| 57 | 57 | |
| 58 | 58 | // If is set to true, there will be additional button in 'Download Your Data' page |
| 59 | 59 | // that will allow users to download their data in JSON-LD format. |
| 60 | -defined( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA' ) || define( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA', false ); |
|
| 60 | +defined('WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA') || define('WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA', false); |
|
| 61 | 61 | |
| 62 | 62 | /* |
| 63 | 63 | * Define the default scope for autocomplete requests. |
| 64 | 64 | * |
| 65 | 65 | * @see https://github.com/insideout10/wordlift-plugin/issues/839 |
| 66 | 66 | */ |
| 67 | -defined( 'WL_AUTOCOMPLETE_SCOPE' ) || define( 'WL_AUTOCOMPLETE_SCOPE', 'cloud' ); |
|
| 67 | +defined('WL_AUTOCOMPLETE_SCOPE') || define('WL_AUTOCOMPLETE_SCOPE', 'cloud'); |
|
| 68 | 68 | |
| 69 | 69 | /* |
| 70 | 70 | * Enable/disable the `all entity types` feature. Initially we keep the feature disabled to enture proper Q/A. |
| 71 | 71 | * |
| 72 | 72 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 73 | 73 | */ |
| 74 | -defined( 'WL_ALL_ENTITY_TYPES' ) || define( 'WL_ALL_ENTITY_TYPES', false ); |
|
| 74 | +defined('WL_ALL_ENTITY_TYPES') || define('WL_ALL_ENTITY_TYPES', false); |
|
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * Get an array with commonly supported prefixes. |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | $items = wl_prefixes_list(); |
| 84 | 84 | $prefixes = array(); |
| 85 | 85 | |
| 86 | - foreach ( $items as $item ) { |
|
| 87 | - $prefixes[ $item['prefix'] ] = $item['namespace']; |
|
| 86 | + foreach ($items as $item) { |
|
| 87 | + $prefixes[$item['prefix']] = $item['namespace']; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | return $prefixes; |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | function wl_temp_dir() { |
| 106 | 106 | $tempdir = get_temp_dir(); |
| 107 | - $unique = md5( site_url() . get_current_blog_id() ); |
|
| 108 | - $unique_temp_dir = $tempdir . 'wl_' . $unique; // $tempdir should have a trailing slash. |
|
| 107 | + $unique = md5(site_url().get_current_blog_id()); |
|
| 108 | + $unique_temp_dir = $tempdir.'wl_'.$unique; // $tempdir should have a trailing slash. |
|
| 109 | 109 | |
| 110 | 110 | // If directory do not exist, create it. |
| 111 | - if ( ! file_exists( $unique_temp_dir ) ) { |
|
| 112 | - @mkdir( $unique_temp_dir ); |
|
| 111 | + if ( ! file_exists($unique_temp_dir)) { |
|
| 112 | + @mkdir($unique_temp_dir); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - return $unique_temp_dir . '/'; |
|
| 115 | + return $unique_temp_dir.'/'; |
|
| 116 | 116 | } |