@@ -14,119 +14,119 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | abstract class Wordlift_Property_Service { |
| 16 | 16 | |
| 17 | - // TODO: check that this is relative to the extending class. |
|
| 18 | - protected static $instance; |
|
| 19 | - |
|
| 20 | - public function __construct() { |
|
| 21 | - |
|
| 22 | - static::$instance = $this; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Get the field singleton. |
|
| 27 | - * |
|
| 28 | - * @since 3.6.0 |
|
| 29 | - * @return \Wordlift_Schema_Url_Property_Service The singleton instance. |
|
| 30 | - */ |
|
| 31 | - public static function get_instance() { |
|
| 32 | - |
|
| 33 | - return static::$instance; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Get the value for the specified post/entity. |
|
| 38 | - * |
|
| 39 | - * @since 3.6.0 |
|
| 40 | - * |
|
| 41 | - * @param int $post_id The post id. |
|
| 42 | - * |
|
| 43 | - * @return mixed |
|
| 44 | - */ |
|
| 45 | - public abstract function get( $post_id ); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Sanitize the provided value. |
|
| 49 | - * |
|
| 50 | - * @since 3.6.0 |
|
| 51 | - * |
|
| 52 | - * @param mixed $value The value to sanitize. |
|
| 53 | - * |
|
| 54 | - * @return mixed|NULL The sanitized value or NULL avoid saving this value (see {@link WL_Metabox_Field}). |
|
| 55 | - */ |
|
| 56 | - public abstract function sanitize( $value ); |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * The RDF predicate for the property. |
|
| 60 | - * |
|
| 61 | - * @since 3.6.0 |
|
| 62 | - * @return string The RDF predicate. |
|
| 63 | - */ |
|
| 64 | - public abstract function get_rdf_predicate(); |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * The RDF data type. |
|
| 68 | - * |
|
| 69 | - * @since 3.6.0 |
|
| 70 | - * @return string The RDF data type. |
|
| 71 | - */ |
|
| 72 | - public abstract function get_rdf_data_type(); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * The internal data type. |
|
| 76 | - * |
|
| 77 | - * @since 3.6.0 |
|
| 78 | - * @return string The internal data type. |
|
| 79 | - */ |
|
| 80 | - public abstract function get_data_type(); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * The cardinality. |
|
| 84 | - * |
|
| 85 | - * @since 3.6.0 |
|
| 86 | - * @return mixed The cardinality. |
|
| 87 | - */ |
|
| 88 | - public abstract function get_cardinality(); |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * The metabox field class name. |
|
| 92 | - * |
|
| 93 | - * @since 3.6.0 |
|
| 94 | - * @return string The metabox field class name. |
|
| 95 | - */ |
|
| 96 | - public abstract function get_metabox_class(); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * The untranslated metabox field label. |
|
| 100 | - * |
|
| 101 | - * @since 3.6.0 |
|
| 102 | - * @return string The untranslated metabox field label. |
|
| 103 | - */ |
|
| 104 | - public abstract function get_metabox_label(); |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * The definition of the property returned as a compatible array. |
|
| 108 | - * |
|
| 109 | - * @deprecated |
|
| 110 | - * |
|
| 111 | - * @since 3.6.0 |
|
| 112 | - * @return array An array of property definitions. |
|
| 113 | - */ |
|
| 114 | - public function get_compat_definition() { |
|
| 115 | - |
|
| 116 | - return array( |
|
| 117 | - 'type' => $this->get_data_type(), |
|
| 118 | - 'predicate' => $this->get_rdf_predicate(), |
|
| 119 | - 'export_type' => $this->get_rdf_data_type(), |
|
| 120 | - 'constraints' => array( |
|
| 121 | - 'cardinality' => $this->get_cardinality(), |
|
| 122 | - ), |
|
| 123 | - // Use the standard metabox for these URI (the URI metabox creates local entities). |
|
| 124 | - 'metabox' => array( |
|
| 125 | - 'class' => $this->get_metabox_class(), |
|
| 126 | - 'label' => $this->get_metabox_label(), |
|
| 127 | - ), |
|
| 128 | - 'sanitize' => array( $this, 'sanitize' ), |
|
| 129 | - ); |
|
| 130 | - } |
|
| 17 | + // TODO: check that this is relative to the extending class. |
|
| 18 | + protected static $instance; |
|
| 19 | + |
|
| 20 | + public function __construct() { |
|
| 21 | + |
|
| 22 | + static::$instance = $this; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Get the field singleton. |
|
| 27 | + * |
|
| 28 | + * @since 3.6.0 |
|
| 29 | + * @return \Wordlift_Schema_Url_Property_Service The singleton instance. |
|
| 30 | + */ |
|
| 31 | + public static function get_instance() { |
|
| 32 | + |
|
| 33 | + return static::$instance; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Get the value for the specified post/entity. |
|
| 38 | + * |
|
| 39 | + * @since 3.6.0 |
|
| 40 | + * |
|
| 41 | + * @param int $post_id The post id. |
|
| 42 | + * |
|
| 43 | + * @return mixed |
|
| 44 | + */ |
|
| 45 | + public abstract function get( $post_id ); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Sanitize the provided value. |
|
| 49 | + * |
|
| 50 | + * @since 3.6.0 |
|
| 51 | + * |
|
| 52 | + * @param mixed $value The value to sanitize. |
|
| 53 | + * |
|
| 54 | + * @return mixed|NULL The sanitized value or NULL avoid saving this value (see {@link WL_Metabox_Field}). |
|
| 55 | + */ |
|
| 56 | + public abstract function sanitize( $value ); |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * The RDF predicate for the property. |
|
| 60 | + * |
|
| 61 | + * @since 3.6.0 |
|
| 62 | + * @return string The RDF predicate. |
|
| 63 | + */ |
|
| 64 | + public abstract function get_rdf_predicate(); |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * The RDF data type. |
|
| 68 | + * |
|
| 69 | + * @since 3.6.0 |
|
| 70 | + * @return string The RDF data type. |
|
| 71 | + */ |
|
| 72 | + public abstract function get_rdf_data_type(); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * The internal data type. |
|
| 76 | + * |
|
| 77 | + * @since 3.6.0 |
|
| 78 | + * @return string The internal data type. |
|
| 79 | + */ |
|
| 80 | + public abstract function get_data_type(); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * The cardinality. |
|
| 84 | + * |
|
| 85 | + * @since 3.6.0 |
|
| 86 | + * @return mixed The cardinality. |
|
| 87 | + */ |
|
| 88 | + public abstract function get_cardinality(); |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * The metabox field class name. |
|
| 92 | + * |
|
| 93 | + * @since 3.6.0 |
|
| 94 | + * @return string The metabox field class name. |
|
| 95 | + */ |
|
| 96 | + public abstract function get_metabox_class(); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * The untranslated metabox field label. |
|
| 100 | + * |
|
| 101 | + * @since 3.6.0 |
|
| 102 | + * @return string The untranslated metabox field label. |
|
| 103 | + */ |
|
| 104 | + public abstract function get_metabox_label(); |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * The definition of the property returned as a compatible array. |
|
| 108 | + * |
|
| 109 | + * @deprecated |
|
| 110 | + * |
|
| 111 | + * @since 3.6.0 |
|
| 112 | + * @return array An array of property definitions. |
|
| 113 | + */ |
|
| 114 | + public function get_compat_definition() { |
|
| 115 | + |
|
| 116 | + return array( |
|
| 117 | + 'type' => $this->get_data_type(), |
|
| 118 | + 'predicate' => $this->get_rdf_predicate(), |
|
| 119 | + 'export_type' => $this->get_rdf_data_type(), |
|
| 120 | + 'constraints' => array( |
|
| 121 | + 'cardinality' => $this->get_cardinality(), |
|
| 122 | + ), |
|
| 123 | + // Use the standard metabox for these URI (the URI metabox creates local entities). |
|
| 124 | + 'metabox' => array( |
|
| 125 | + 'class' => $this->get_metabox_class(), |
|
| 126 | + 'label' => $this->get_metabox_label(), |
|
| 127 | + ), |
|
| 128 | + 'sanitize' => array( $this, 'sanitize' ), |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | 132 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return mixed |
| 44 | 44 | */ |
| 45 | - public abstract function get( $post_id ); |
|
| 45 | + public abstract function get($post_id); |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Sanitize the provided value. |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return mixed|NULL The sanitized value or NULL avoid saving this value (see {@link WL_Metabox_Field}). |
| 55 | 55 | */ |
| 56 | - public abstract function sanitize( $value ); |
|
| 56 | + public abstract function sanitize($value); |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * The RDF predicate for the property. |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | 'class' => $this->get_metabox_class(), |
| 126 | 126 | 'label' => $this->get_metabox_label(), |
| 127 | 127 | ), |
| 128 | - 'sanitize' => array( $this, 'sanitize' ), |
|
| 128 | + 'sanitize' => array($this, 'sanitize'), |
|
| 129 | 129 | ); |
| 130 | 130 | } |
| 131 | 131 | |
@@ -18,74 +18,74 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Batch_Analysis_Page extends Wordlift_Admin_Page { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The {@link Wordlift_Batch_analysis_Service} instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.14.0 |
|
| 25 | - * |
|
| 26 | - * @var \Wordlift_Batch_Analysis_Service $batch_analysis_service The {@link Wordlift_Batch_analysis_Service} instance. |
|
| 27 | - */ |
|
| 28 | - public $batch_analysis_service; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * The {@link Wordlift_Batch_Analysis_page} instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.14.0 |
|
| 34 | - * |
|
| 35 | - * @param \Wordlift_Batch_Analysis_Service $batch_analysis_service The {@link Wordlift_Batch_analysis_Service} instance. |
|
| 36 | - */ |
|
| 37 | - public function __construct( $batch_analysis_service ) { |
|
| 38 | - |
|
| 39 | - $this->batch_analysis_service = $batch_analysis_service; |
|
| 40 | - |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @inheritdoc |
|
| 45 | - */ |
|
| 46 | - function get_parent_slug() { |
|
| 47 | - |
|
| 48 | - return 'wl_admin_menu'; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @inheritdoc |
|
| 53 | - */ |
|
| 54 | - function get_capability() { |
|
| 55 | - |
|
| 56 | - return 'manage_options'; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @inheritdoc |
|
| 61 | - */ |
|
| 62 | - function get_page_title() { |
|
| 63 | - |
|
| 64 | - return __( 'Batch Analysis', 'wordlift' ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @inheritdoc |
|
| 69 | - */ |
|
| 70 | - function get_menu_title() { |
|
| 71 | - |
|
| 72 | - return __( 'Batch Analysis', 'wordlift' ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @inheritdoc |
|
| 77 | - */ |
|
| 78 | - function get_menu_slug() { |
|
| 79 | - |
|
| 80 | - return 'wl_batch_analysis_menu'; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @inheritdoc |
|
| 85 | - */ |
|
| 86 | - function get_partial_name() { |
|
| 87 | - |
|
| 88 | - return 'wordlift-admin-batch-analysis-page.php'; |
|
| 89 | - } |
|
| 21 | + /** |
|
| 22 | + * The {@link Wordlift_Batch_analysis_Service} instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.14.0 |
|
| 25 | + * |
|
| 26 | + * @var \Wordlift_Batch_Analysis_Service $batch_analysis_service The {@link Wordlift_Batch_analysis_Service} instance. |
|
| 27 | + */ |
|
| 28 | + public $batch_analysis_service; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * The {@link Wordlift_Batch_Analysis_page} instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.14.0 |
|
| 34 | + * |
|
| 35 | + * @param \Wordlift_Batch_Analysis_Service $batch_analysis_service The {@link Wordlift_Batch_analysis_Service} instance. |
|
| 36 | + */ |
|
| 37 | + public function __construct( $batch_analysis_service ) { |
|
| 38 | + |
|
| 39 | + $this->batch_analysis_service = $batch_analysis_service; |
|
| 40 | + |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @inheritdoc |
|
| 45 | + */ |
|
| 46 | + function get_parent_slug() { |
|
| 47 | + |
|
| 48 | + return 'wl_admin_menu'; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @inheritdoc |
|
| 53 | + */ |
|
| 54 | + function get_capability() { |
|
| 55 | + |
|
| 56 | + return 'manage_options'; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @inheritdoc |
|
| 61 | + */ |
|
| 62 | + function get_page_title() { |
|
| 63 | + |
|
| 64 | + return __( 'Batch Analysis', 'wordlift' ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @inheritdoc |
|
| 69 | + */ |
|
| 70 | + function get_menu_title() { |
|
| 71 | + |
|
| 72 | + return __( 'Batch Analysis', 'wordlift' ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @inheritdoc |
|
| 77 | + */ |
|
| 78 | + function get_menu_slug() { |
|
| 79 | + |
|
| 80 | + return 'wl_batch_analysis_menu'; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @inheritdoc |
|
| 85 | + */ |
|
| 86 | + function get_partial_name() { |
|
| 87 | + |
|
| 88 | + return 'wordlift-admin-batch-analysis-page.php'; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @param \Wordlift_Batch_Analysis_Service $batch_analysis_service The {@link Wordlift_Batch_analysis_Service} instance. |
| 36 | 36 | */ |
| 37 | - public function __construct( $batch_analysis_service ) { |
|
| 37 | + public function __construct($batch_analysis_service) { |
|
| 38 | 38 | |
| 39 | 39 | $this->batch_analysis_service = $batch_analysis_service; |
| 40 | 40 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | function get_page_title() { |
| 63 | 63 | |
| 64 | - return __( 'Batch Analysis', 'wordlift' ); |
|
| 64 | + return __('Batch Analysis', 'wordlift'); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | function get_menu_title() { |
| 71 | 71 | |
| 72 | - return __( 'Batch Analysis', 'wordlift' ); |
|
| 72 | + return __('Batch Analysis', 'wordlift'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | function wl_configuration_get_key() { |
| 13 | 13 | |
| 14 | - return Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 14 | + return Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function wl_configuration_get_redlink_dataset_uri() { |
| 28 | 28 | |
| 29 | - return Wordlift_Configuration_Service::get_instance()->get_dataset_uri(); |
|
| 29 | + return Wordlift_Configuration_Service::get_instance()->get_dataset_uri(); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -41,16 +41,16 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | function wl_configuration_get_analyzer_url() { |
| 43 | 43 | |
| 44 | - // If the WordLift Key is set, we use WordLift. |
|
| 45 | - $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 44 | + // If the WordLift Key is set, we use WordLift. |
|
| 45 | + $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 46 | 46 | |
| 47 | - // Return a NULL URL if the key isn't set. |
|
| 48 | - if ( empty( $key ) ) { |
|
| 49 | - return null; |
|
| 50 | - } |
|
| 47 | + // Return a NULL URL if the key isn't set. |
|
| 48 | + if ( empty( $key ) ) { |
|
| 49 | + return null; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "analyses?key=$key" |
|
| 53 | - . ( defined( 'WL_EXCLUDE_IMAGES_REGEX' ) ? '&exclimage=' . urlencode( WL_EXCLUDE_IMAGES_REGEX ) : '' ); |
|
| 52 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "analyses?key=$key" |
|
| 53 | + . ( defined( 'WL_EXCLUDE_IMAGES_REGEX' ) ? '&exclimage=' . urlencode( WL_EXCLUDE_IMAGES_REGEX ) : '' ); |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | function wl_configuration_get_query_select_url() { |
| 65 | 65 | |
| 66 | - // If the WordLift Key is set, we use WordLift. |
|
| 67 | - $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 66 | + // If the WordLift Key is set, we use WordLift. |
|
| 67 | + $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 68 | 68 | |
| 69 | - if ( empty( $key ) ) { |
|
| 70 | - return null; |
|
| 71 | - } |
|
| 69 | + if ( empty( $key ) ) { |
|
| 70 | + return null; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries?q="; |
|
| 73 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries?q="; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -82,13 +82,13 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | function wl_configuration_get_query_update_url() { |
| 84 | 84 | |
| 85 | - // If the WordLift Key is set, we use WordLift. |
|
| 86 | - $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 87 | - if ( empty( $key ) ) { |
|
| 88 | - return null; |
|
| 89 | - } |
|
| 85 | + // If the WordLift Key is set, we use WordLift. |
|
| 86 | + $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 87 | + if ( empty( $key ) ) { |
|
| 88 | + return null; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries"; |
|
| 91 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries"; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | function wl_configuration_get_dataset_index_url() { |
| 103 | 103 | |
| 104 | - // If the WordLift Key is set, we use WordLift. |
|
| 105 | - $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 106 | - if ( empty( $key ) ) { |
|
| 107 | - return null; |
|
| 108 | - } |
|
| 104 | + // If the WordLift Key is set, we use WordLift. |
|
| 105 | + $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
|
| 106 | + if ( empty( $key ) ) { |
|
| 107 | + return null; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/index"; |
|
| 110 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/index"; |
|
| 111 | 111 | } |
@@ -45,12 +45,12 @@ discard block |
||
| 45 | 45 | $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
| 46 | 46 | |
| 47 | 47 | // Return a NULL URL if the key isn't set. |
| 48 | - if ( empty( $key ) ) { |
|
| 48 | + if (empty($key)) { |
|
| 49 | 49 | return null; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "analyses?key=$key" |
|
| 53 | - . ( defined( 'WL_EXCLUDE_IMAGES_REGEX' ) ? '&exclimage=' . urlencode( WL_EXCLUDE_IMAGES_REGEX ) : '' ); |
|
| 52 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."analyses?key=$key" |
|
| 53 | + . (defined('WL_EXCLUDE_IMAGES_REGEX') ? '&exclimage='.urlencode(WL_EXCLUDE_IMAGES_REGEX) : ''); |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | // If the WordLift Key is set, we use WordLift. |
| 67 | 67 | $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
| 68 | 68 | |
| 69 | - if ( empty( $key ) ) { |
|
| 69 | + if (empty($key)) { |
|
| 70 | 70 | return null; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries?q="; |
|
| 73 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."datasets/key=$key/queries?q="; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | // If the WordLift Key is set, we use WordLift. |
| 86 | 86 | $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
| 87 | - if ( empty( $key ) ) { |
|
| 87 | + if (empty($key)) { |
|
| 88 | 88 | return null; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries"; |
|
| 91 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."datasets/key=$key/queries"; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | // If the WordLift Key is set, we use WordLift. |
| 105 | 105 | $key = Wordlift_Configuration_Service::get_instance()->get_key(); |
| 106 | - if ( empty( $key ) ) { |
|
| 106 | + if (empty($key)) { |
|
| 107 | 107 | return null; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/index"; |
|
| 110 | + return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."datasets/key=$key/index"; |
|
| 111 | 111 | } |
@@ -18,41 +18,41 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Metabox_Field_Duration extends WL_Metabox_Field_date { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * {@inheritdoc} |
|
| 23 | - */ |
|
| 24 | - public function __construct( $args ) { |
|
| 25 | - parent::__construct( $args ); |
|
| 26 | - |
|
| 27 | - $this->date_format = 'H:i'; |
|
| 28 | - $this->timepicker = true; |
|
| 29 | - $this->no_calendar = true; |
|
| 30 | - |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Sanitize a single value. Called from $this->sanitize_data. Default sanitization excludes empty values. |
|
| 35 | - * make sure the value is either empty, an integer representing valid number of minutes |
|
| 36 | - * or an HH:MM time format. |
|
| 37 | - * |
|
| 38 | - * @param mixed $value The value being sanitized. |
|
| 39 | - * |
|
| 40 | - * @return mixed Returns sanitized value, or null. |
|
| 41 | - */ |
|
| 42 | - public function sanitize_data_filter( $value ) { |
|
| 43 | - |
|
| 44 | - if ( ! is_null( $value ) && '' !== $value ) { // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ . |
|
| 45 | - preg_match( '#((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}#', |
|
| 46 | - trim( $value ), |
|
| 47 | - $matches |
|
| 48 | - ); |
|
| 49 | - |
|
| 50 | - if ( count( $matches ) > 0 ) { |
|
| 51 | - return $matches[0]; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return null; |
|
| 56 | - } |
|
| 21 | + /** |
|
| 22 | + * {@inheritdoc} |
|
| 23 | + */ |
|
| 24 | + public function __construct( $args ) { |
|
| 25 | + parent::__construct( $args ); |
|
| 26 | + |
|
| 27 | + $this->date_format = 'H:i'; |
|
| 28 | + $this->timepicker = true; |
|
| 29 | + $this->no_calendar = true; |
|
| 30 | + |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Sanitize a single value. Called from $this->sanitize_data. Default sanitization excludes empty values. |
|
| 35 | + * make sure the value is either empty, an integer representing valid number of minutes |
|
| 36 | + * or an HH:MM time format. |
|
| 37 | + * |
|
| 38 | + * @param mixed $value The value being sanitized. |
|
| 39 | + * |
|
| 40 | + * @return mixed Returns sanitized value, or null. |
|
| 41 | + */ |
|
| 42 | + public function sanitize_data_filter( $value ) { |
|
| 43 | + |
|
| 44 | + if ( ! is_null( $value ) && '' !== $value ) { // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ . |
|
| 45 | + preg_match( '#((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}#', |
|
| 46 | + trim( $value ), |
|
| 47 | + $matches |
|
| 48 | + ); |
|
| 49 | + |
|
| 50 | + if ( count( $matches ) > 0 ) { |
|
| 51 | + return $matches[0]; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return null; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | } |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * {@inheritdoc} |
| 23 | 23 | */ |
| 24 | - public function __construct( $args ) { |
|
| 25 | - parent::__construct( $args ); |
|
| 24 | + public function __construct($args) { |
|
| 25 | + parent::__construct($args); |
|
| 26 | 26 | |
| 27 | 27 | $this->date_format = 'H:i'; |
| 28 | 28 | $this->timepicker = true; |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @return mixed Returns sanitized value, or null. |
| 41 | 41 | */ |
| 42 | - public function sanitize_data_filter( $value ) { |
|
| 42 | + public function sanitize_data_filter($value) { |
|
| 43 | 43 | |
| 44 | - if ( ! is_null( $value ) && '' !== $value ) { // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ . |
|
| 45 | - preg_match( '#((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}#', |
|
| 46 | - trim( $value ), |
|
| 44 | + if ( ! is_null($value) && '' !== $value) { // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/ . |
|
| 45 | + preg_match('#((([01]?[0-9]{1}|2[0-3]{1}):)?[0-5]{1})?[0-9]{1}#', |
|
| 46 | + trim($value), |
|
| 47 | 47 | $matches |
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | - if ( count( $matches ) > 0 ) { |
|
| 50 | + if (count($matches) > 0) { |
|
| 51 | 51 | return $matches[0]; |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -17,77 +17,77 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Wordlift_Key_Validation_Service { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * A {@link Wordlift_Log_Service} instance. |
|
| 22 | - * |
|
| 23 | - * @since 3.14.0 |
|
| 24 | - * @access private |
|
| 25 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 26 | - */ |
|
| 27 | - private $log; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * The {@link Wordlift_Configuration_Service} instance. |
|
| 31 | - * |
|
| 32 | - * @since 3.14.0 |
|
| 33 | - * @access private |
|
| 34 | - * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 35 | - */ |
|
| 36 | - private $configuration_service; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Create a {@link Wordlift_Key_Validation_Service} instance. |
|
| 40 | - * |
|
| 41 | - * @since 3.14.0 |
|
| 42 | - * |
|
| 43 | - * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 44 | - */ |
|
| 45 | - public function __construct( $configuration_service ) { |
|
| 46 | - |
|
| 47 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' ); |
|
| 48 | - |
|
| 49 | - $this->configuration_service = $configuration_service; |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Validate the provided key. |
|
| 55 | - * |
|
| 56 | - * @since 3.9.0 |
|
| 57 | - * |
|
| 58 | - * @param string $key WordLift's key to validate. |
|
| 59 | - * |
|
| 60 | - * @return bool True if the key is valid, otherwise false. |
|
| 61 | - */ |
|
| 62 | - public function is_valid( $key ) { |
|
| 63 | - |
|
| 64 | - $this->log->debug( 'Validating key...' ); |
|
| 65 | - |
|
| 66 | - // Request the dataset URI as a way to validate the key |
|
| 67 | - $response = wp_remote_get( $this->configuration_service->get_accounts_by_key_dataset_uri( $key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) ); |
|
| 68 | - |
|
| 69 | - // If the response is valid, the key is valid. |
|
| 70 | - return ! is_wp_error( $response ) && 200 === (int) $response['response']['code']; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * This function is hooked to the `wl_validate_key` AJAX call. |
|
| 75 | - * |
|
| 76 | - * @since 3.9.0 |
|
| 77 | - */ |
|
| 78 | - public function validate_key() { |
|
| 79 | - |
|
| 80 | - // Ensure we don't have garbage before us. |
|
| 81 | - ob_clean(); |
|
| 82 | - |
|
| 83 | - // Check if we have a key. |
|
| 84 | - if ( ! isset( $_POST['key'] ) ) { |
|
| 85 | - wp_send_json_error( 'The key parameter is required.' ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - // Set a response with valid set to true or false according to the key validity. |
|
| 89 | - wp_send_json_success( array( 'valid' => $this->is_valid( $_POST['key'] ) ) ); |
|
| 90 | - |
|
| 91 | - } |
|
| 20 | + /** |
|
| 21 | + * A {@link Wordlift_Log_Service} instance. |
|
| 22 | + * |
|
| 23 | + * @since 3.14.0 |
|
| 24 | + * @access private |
|
| 25 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 26 | + */ |
|
| 27 | + private $log; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * The {@link Wordlift_Configuration_Service} instance. |
|
| 31 | + * |
|
| 32 | + * @since 3.14.0 |
|
| 33 | + * @access private |
|
| 34 | + * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 35 | + */ |
|
| 36 | + private $configuration_service; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Create a {@link Wordlift_Key_Validation_Service} instance. |
|
| 40 | + * |
|
| 41 | + * @since 3.14.0 |
|
| 42 | + * |
|
| 43 | + * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 44 | + */ |
|
| 45 | + public function __construct( $configuration_service ) { |
|
| 46 | + |
|
| 47 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' ); |
|
| 48 | + |
|
| 49 | + $this->configuration_service = $configuration_service; |
|
| 50 | + |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Validate the provided key. |
|
| 55 | + * |
|
| 56 | + * @since 3.9.0 |
|
| 57 | + * |
|
| 58 | + * @param string $key WordLift's key to validate. |
|
| 59 | + * |
|
| 60 | + * @return bool True if the key is valid, otherwise false. |
|
| 61 | + */ |
|
| 62 | + public function is_valid( $key ) { |
|
| 63 | + |
|
| 64 | + $this->log->debug( 'Validating key...' ); |
|
| 65 | + |
|
| 66 | + // Request the dataset URI as a way to validate the key |
|
| 67 | + $response = wp_remote_get( $this->configuration_service->get_accounts_by_key_dataset_uri( $key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) ); |
|
| 68 | + |
|
| 69 | + // If the response is valid, the key is valid. |
|
| 70 | + return ! is_wp_error( $response ) && 200 === (int) $response['response']['code']; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * This function is hooked to the `wl_validate_key` AJAX call. |
|
| 75 | + * |
|
| 76 | + * @since 3.9.0 |
|
| 77 | + */ |
|
| 78 | + public function validate_key() { |
|
| 79 | + |
|
| 80 | + // Ensure we don't have garbage before us. |
|
| 81 | + ob_clean(); |
|
| 82 | + |
|
| 83 | + // Check if we have a key. |
|
| 84 | + if ( ! isset( $_POST['key'] ) ) { |
|
| 85 | + wp_send_json_error( 'The key parameter is required.' ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + // Set a response with valid set to true or false according to the key validity. |
|
| 89 | + wp_send_json_success( array( 'valid' => $this->is_valid( $_POST['key'] ) ) ); |
|
| 90 | + |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | } |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
| 44 | 44 | */ |
| 45 | - public function __construct( $configuration_service ) { |
|
| 45 | + public function __construct($configuration_service) { |
|
| 46 | 46 | |
| 47 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' ); |
|
| 47 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Key_Validation_Service'); |
|
| 48 | 48 | |
| 49 | 49 | $this->configuration_service = $configuration_service; |
| 50 | 50 | |
@@ -59,15 +59,15 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @return bool True if the key is valid, otherwise false. |
| 61 | 61 | */ |
| 62 | - public function is_valid( $key ) { |
|
| 62 | + public function is_valid($key) { |
|
| 63 | 63 | |
| 64 | - $this->log->debug( 'Validating key...' ); |
|
| 64 | + $this->log->debug('Validating key...'); |
|
| 65 | 65 | |
| 66 | 66 | // Request the dataset URI as a way to validate the key |
| 67 | - $response = wp_remote_get( $this->configuration_service->get_accounts_by_key_dataset_uri( $key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) ); |
|
| 67 | + $response = wp_remote_get($this->configuration_service->get_accounts_by_key_dataset_uri($key), unserialize(WL_REDLINK_API_HTTP_OPTIONS)); |
|
| 68 | 68 | |
| 69 | 69 | // If the response is valid, the key is valid. |
| 70 | - return ! is_wp_error( $response ) && 200 === (int) $response['response']['code']; |
|
| 70 | + return ! is_wp_error($response) && 200 === (int) $response['response']['code']; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -81,12 +81,12 @@ discard block |
||
| 81 | 81 | ob_clean(); |
| 82 | 82 | |
| 83 | 83 | // Check if we have a key. |
| 84 | - if ( ! isset( $_POST['key'] ) ) { |
|
| 85 | - wp_send_json_error( 'The key parameter is required.' ); |
|
| 84 | + if ( ! isset($_POST['key'])) { |
|
| 85 | + wp_send_json_error('The key parameter is required.'); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // Set a response with valid set to true or false according to the key validity. |
| 89 | - wp_send_json_success( array( 'valid' => $this->is_valid( $_POST['key'] ) ) ); |
|
| 89 | + wp_send_json_success(array('valid' => $this->is_valid($_POST['key']))); |
|
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | |
@@ -19,25 +19,25 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Wordlift_Duration_Property_Service extends Wordlift_Simple_Property_Service { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * {@inheritdoc} |
|
| 24 | - */ |
|
| 25 | - function get( $post_id, $meta_key ) { |
|
| 22 | + /** |
|
| 23 | + * {@inheritdoc} |
|
| 24 | + */ |
|
| 25 | + function get( $post_id, $meta_key ) { |
|
| 26 | 26 | |
| 27 | - // Get the values and filter out the empty ones (or the ones with 00:00). |
|
| 28 | - $values = array_filter( parent::get( $post_id, $meta_key ), function ( $item ) { |
|
| 29 | - return ! empty( $item ) && '00:00' !== $item; |
|
| 30 | - } ); |
|
| 27 | + // Get the values and filter out the empty ones (or the ones with 00:00). |
|
| 28 | + $values = array_filter( parent::get( $post_id, $meta_key ), function ( $item ) { |
|
| 29 | + return ! empty( $item ) && '00:00' !== $item; |
|
| 30 | + } ); |
|
| 31 | 31 | |
| 32 | - /* |
|
| 32 | + /* |
|
| 33 | 33 | * Map the value in the meta |
| 34 | 34 | * The UI for the meta date enable two forms, a number of minutes |
| 35 | 35 | * or an h:mm format. |
| 36 | 36 | * Both needs to be adjusted to the iso format. |
| 37 | 37 | */ |
| 38 | - return array_map( function ( $value ) { |
|
| 39 | - return 'PT' . str_replace( ':', 'H', $value ) . 'M'; |
|
| 40 | - }, $values ); |
|
| 41 | - } |
|
| 38 | + return array_map( function ( $value ) { |
|
| 39 | + return 'PT' . str_replace( ':', 'H', $value ) . 'M'; |
|
| 40 | + }, $values ); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | } |
@@ -22,11 +22,11 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * {@inheritdoc} |
| 24 | 24 | */ |
| 25 | - function get( $post_id, $meta_key ) { |
|
| 25 | + function get($post_id, $meta_key) { |
|
| 26 | 26 | |
| 27 | 27 | // Get the values and filter out the empty ones (or the ones with 00:00). |
| 28 | - $values = array_filter( parent::get( $post_id, $meta_key ), function ( $item ) { |
|
| 29 | - return ! empty( $item ) && '00:00' !== $item; |
|
| 28 | + $values = array_filter(parent::get($post_id, $meta_key), function($item) { |
|
| 29 | + return ! empty($item) && '00:00' !== $item; |
|
| 30 | 30 | } ); |
| 31 | 31 | |
| 32 | 32 | /* |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * or an h:mm format. |
| 36 | 36 | * Both needs to be adjusted to the iso format. |
| 37 | 37 | */ |
| 38 | - return array_map( function ( $value ) { |
|
| 39 | - return 'PT' . str_replace( ':', 'H', $value ) . 'M'; |
|
| 40 | - }, $values ); |
|
| 38 | + return array_map(function($value) { |
|
| 39 | + return 'PT'.str_replace(':', 'H', $value).'M'; |
|
| 40 | + }, $values); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | } |
@@ -17,58 +17,58 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Wordlift_Sample_Data_Ajax_Adapter { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * The {@link Wordlift_Sample_Data_Service} instance. |
|
| 22 | - * |
|
| 23 | - * @since 3.12.0 |
|
| 24 | - * @access private |
|
| 25 | - * @var \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance. |
|
| 26 | - */ |
|
| 27 | - private $sample_data_service; |
|
| 20 | + /** |
|
| 21 | + * The {@link Wordlift_Sample_Data_Service} instance. |
|
| 22 | + * |
|
| 23 | + * @since 3.12.0 |
|
| 24 | + * @access private |
|
| 25 | + * @var \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance. |
|
| 26 | + */ |
|
| 27 | + private $sample_data_service; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Create a {@link Wordlift_Sample_Data_Ajax_Adapter} instance. |
|
| 31 | - * |
|
| 32 | - * @since 3.12.0 |
|
| 33 | - * |
|
| 34 | - * @param \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance. |
|
| 35 | - */ |
|
| 36 | - function __construct( $sample_data_service ) { |
|
| 29 | + /** |
|
| 30 | + * Create a {@link Wordlift_Sample_Data_Ajax_Adapter} instance. |
|
| 31 | + * |
|
| 32 | + * @since 3.12.0 |
|
| 33 | + * |
|
| 34 | + * @param \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance. |
|
| 35 | + */ |
|
| 36 | + function __construct( $sample_data_service ) { |
|
| 37 | 37 | |
| 38 | - $this->sample_data_service = $sample_data_service; |
|
| 38 | + $this->sample_data_service = $sample_data_service; |
|
| 39 | 39 | |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Handle the `wl_sample_data_create` ajax action. |
|
| 44 | - * |
|
| 45 | - * @since 3.12.0 |
|
| 46 | - */ |
|
| 47 | - function create() { |
|
| 42 | + /** |
|
| 43 | + * Handle the `wl_sample_data_create` ajax action. |
|
| 44 | + * |
|
| 45 | + * @since 3.12.0 |
|
| 46 | + */ |
|
| 47 | + function create() { |
|
| 48 | 48 | |
| 49 | - // Clean any potential garbage before us. |
|
| 50 | - ob_clean(); |
|
| 49 | + // Clean any potential garbage before us. |
|
| 50 | + ob_clean(); |
|
| 51 | 51 | |
| 52 | - // Create the sample data. |
|
| 53 | - $this->sample_data_service->create(); |
|
| 52 | + // Create the sample data. |
|
| 53 | + $this->sample_data_service->create(); |
|
| 54 | 54 | |
| 55 | - // Send success. |
|
| 56 | - wp_send_json_success(); |
|
| 55 | + // Send success. |
|
| 56 | + wp_send_json_success(); |
|
| 57 | 57 | |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - function delete() { |
|
| 60 | + function delete() { |
|
| 61 | 61 | |
| 62 | - // Clean any potential garbage before us. |
|
| 63 | - ob_clean(); |
|
| 62 | + // Clean any potential garbage before us. |
|
| 63 | + ob_clean(); |
|
| 64 | 64 | |
| 65 | - // Create the sample data. |
|
| 66 | - $this->sample_data_service->delete(); |
|
| 65 | + // Create the sample data. |
|
| 66 | + $this->sample_data_service->delete(); |
|
| 67 | 67 | |
| 68 | - // Send success. |
|
| 69 | - @header( 'Content-Disposition: inline' ); |
|
| 70 | - wp_send_json_success(); |
|
| 68 | + // Send success. |
|
| 69 | + @header( 'Content-Disposition: inline' ); |
|
| 70 | + wp_send_json_success(); |
|
| 71 | 71 | |
| 72 | - } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | } |
| 75 | 75 | \ No newline at end of file |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @param \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance. |
| 35 | 35 | */ |
| 36 | - function __construct( $sample_data_service ) { |
|
| 36 | + function __construct($sample_data_service) { |
|
| 37 | 37 | |
| 38 | 38 | $this->sample_data_service = $sample_data_service; |
| 39 | 39 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $this->sample_data_service->delete(); |
| 67 | 67 | |
| 68 | 68 | // Send success. |
| 69 | - @header( 'Content-Disposition: inline' ); |
|
| 69 | + @header('Content-Disposition: inline'); |
|
| 70 | 70 | wp_send_json_success(); |
| 71 | 71 | |
| 72 | 72 | } |
@@ -11,68 +11,68 @@ |
||
| 11 | 11 | <h2><?php esc_html_e( 'WordLift Batch Analyze Monitor', 'wordlift' ) ?></h2> |
| 12 | 12 | |
| 13 | 13 | <?php |
| 14 | - $queue = $this->batch_analysis_service->waiting_for_analysis(); |
|
| 15 | - $submit_count = count( $queue ); |
|
| 16 | - ?> |
|
| 14 | + $queue = $this->batch_analysis_service->waiting_for_analysis(); |
|
| 15 | + $submit_count = count( $queue ); |
|
| 16 | + ?> |
|
| 17 | 17 | <h3><?php esc_html_e( 'Posts in queue', 'wordlift' ) ?><?php echo " ($submit_count)"; ?></h3> |
| 18 | 18 | <?php |
| 19 | - if ( empty( $queue ) ) { |
|
| 20 | - esc_html_e( 'Nothing is currently in queue', 'wordlift' ); |
|
| 21 | - } else { |
|
| 22 | - echo '<ul>'; |
|
| 23 | - foreach ( $queue as $pid ) { |
|
| 24 | - $cancel_link = admin_url( "admin-ajax.php?action=wl_batch_analysis_cancel&post=$pid" ); |
|
| 25 | - ?> |
|
| 19 | + if ( empty( $queue ) ) { |
|
| 20 | + esc_html_e( 'Nothing is currently in queue', 'wordlift' ); |
|
| 21 | + } else { |
|
| 22 | + echo '<ul>'; |
|
| 23 | + foreach ( $queue as $pid ) { |
|
| 24 | + $cancel_link = admin_url( "admin-ajax.php?action=wl_batch_analysis_cancel&post=$pid" ); |
|
| 25 | + ?> |
|
| 26 | 26 | <li><a href="<?php echo get_edit_post_link( $pid ) ?>"><?php |
| 27 | - echo get_the_title( $pid ) ?></a> [<a |
|
| 27 | + echo get_the_title( $pid ) ?></a> [<a |
|
| 28 | 28 | href="<?php echo esc_attr( $cancel_link ); ?> "><?php esc_html_e( 'Cancel', 'wordlift' ); ?></a>] |
| 29 | 29 | </li> |
| 30 | 30 | <?php |
| 31 | - } |
|
| 32 | - echo '</ul>'; |
|
| 33 | - } |
|
| 31 | + } |
|
| 32 | + echo '</ul>'; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - $queue = $this->batch_analysis_service->waiting_for_response(); |
|
| 36 | - $request_count = count( $queue ); |
|
| 37 | - ?> |
|
| 35 | + $queue = $this->batch_analysis_service->waiting_for_response(); |
|
| 36 | + $request_count = count( $queue ); |
|
| 37 | + ?> |
|
| 38 | 38 | <h3><?php esc_html_e( 'Posts being processed', 'wordlift' ) ?><?php echo " ($request_count)"; ?></h3> |
| 39 | 39 | <?php |
| 40 | - if ( empty( $queue ) ) { |
|
| 41 | - esc_html_e( 'Nothing is currently being processed', 'wordlift' ); |
|
| 42 | - } else { |
|
| 43 | - echo '<ul>'; |
|
| 44 | - foreach ( $queue as $pid ) { |
|
| 45 | - $cancel_link = admin_url( "admin-ajax.php?action=wl_batch_analysis_cancel&post=$pid" ); |
|
| 46 | - ?> |
|
| 40 | + if ( empty( $queue ) ) { |
|
| 41 | + esc_html_e( 'Nothing is currently being processed', 'wordlift' ); |
|
| 42 | + } else { |
|
| 43 | + echo '<ul>'; |
|
| 44 | + foreach ( $queue as $pid ) { |
|
| 45 | + $cancel_link = admin_url( "admin-ajax.php?action=wl_batch_analysis_cancel&post=$pid" ); |
|
| 46 | + ?> |
|
| 47 | 47 | <li><a href="<?php echo get_edit_post_link( $pid ) ?>"><?php |
| 48 | - echo get_the_title( $pid ) ?></a> [<a |
|
| 48 | + echo get_the_title( $pid ) ?></a> [<a |
|
| 49 | 49 | href="<?php echo esc_attr( $cancel_link ); ?> "><?php esc_html_e( 'Cancel', 'wordlift' ); ?></a>] |
| 50 | 50 | </li> |
| 51 | 51 | <?php |
| 52 | - } |
|
| 53 | - echo '</ul>'; |
|
| 54 | - } |
|
| 52 | + } |
|
| 53 | + echo '</ul>'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $queue = $this->batch_analysis_service->get_warnings(); |
|
| 57 | - $warning_count = count( $queue ); |
|
| 58 | - ?> |
|
| 56 | + $queue = $this->batch_analysis_service->get_warnings(); |
|
| 57 | + $warning_count = count( $queue ); |
|
| 58 | + ?> |
|
| 59 | 59 | |
| 60 | 60 | <h3><?php esc_html_e( 'Posts with warnings', 'wordlift' ) ?><?php echo " ($warning_count)"; ?></h3> |
| 61 | 61 | <?php |
| 62 | - if ( empty( $queue ) ) { |
|
| 63 | - esc_html_e( 'No warnings :-)', 'wordlift' ); |
|
| 64 | - } else { |
|
| 65 | - echo '<ul>'; |
|
| 66 | - foreach ( $queue as $pid ) { |
|
| 67 | - $cancel_link = admin_url( "admin-ajax.php?action=wl_batch_analysis_clear_warning&post=$pid" ); |
|
| 68 | - ?> |
|
| 62 | + if ( empty( $queue ) ) { |
|
| 63 | + esc_html_e( 'No warnings :-)', 'wordlift' ); |
|
| 64 | + } else { |
|
| 65 | + echo '<ul>'; |
|
| 66 | + foreach ( $queue as $pid ) { |
|
| 67 | + $cancel_link = admin_url( "admin-ajax.php?action=wl_batch_analysis_clear_warning&post=$pid" ); |
|
| 68 | + ?> |
|
| 69 | 69 | <li><a href="<?php echo get_edit_post_link( $pid ) ?>"><?php |
| 70 | - echo get_the_title( $pid ) ?></a> [<a |
|
| 70 | + echo get_the_title( $pid ) ?></a> [<a |
|
| 71 | 71 | href="<?php echo esc_attr( $cancel_link ); ?> "><?php esc_html_e( 'Clear warning', 'wordlift' ); ?></a>] |
| 72 | 72 | </li> |
| 73 | 73 | <?php |
| 74 | - } |
|
| 75 | - echo '</ul>'; |
|
| 76 | - } |
|
| 77 | - ?> |
|
| 74 | + } |
|
| 75 | + echo '</ul>'; |
|
| 76 | + } |
|
| 77 | + ?> |
|
| 78 | 78 | </div> |
@@ -8,24 +8,24 @@ discard block |
||
| 8 | 8 | ?> |
| 9 | 9 | |
| 10 | 10 | <div class="wrap"> |
| 11 | - <h2><?php esc_html_e( 'WordLift Batch Analyze Monitor', 'wordlift' ) ?></h2> |
|
| 11 | + <h2><?php esc_html_e('WordLift Batch Analyze Monitor', 'wordlift') ?></h2> |
|
| 12 | 12 | |
| 13 | 13 | <?php |
| 14 | 14 | $queue = $this->batch_analysis_service->waiting_for_analysis(); |
| 15 | - $submit_count = count( $queue ); |
|
| 15 | + $submit_count = count($queue); |
|
| 16 | 16 | ?> |
| 17 | - <h3><?php esc_html_e( 'Posts in queue', 'wordlift' ) ?><?php echo " ($submit_count)"; ?></h3> |
|
| 17 | + <h3><?php esc_html_e('Posts in queue', 'wordlift') ?><?php echo " ($submit_count)"; ?></h3> |
|
| 18 | 18 | <?php |
| 19 | - if ( empty( $queue ) ) { |
|
| 20 | - esc_html_e( 'Nothing is currently in queue', 'wordlift' ); |
|
| 19 | + if (empty($queue)) { |
|
| 20 | + esc_html_e('Nothing is currently in queue', 'wordlift'); |
|
| 21 | 21 | } else { |
| 22 | 22 | echo '<ul>'; |
| 23 | - foreach ( $queue as $pid ) { |
|
| 24 | - $cancel_link = admin_url( "admin-ajax.php?action=wl_batch_analysis_cancel&post=$pid" ); |
|
| 23 | + foreach ($queue as $pid) { |
|
| 24 | + $cancel_link = admin_url("admin-ajax.php?action=wl_batch_analysis_cancel&post=$pid"); |
|
| 25 | 25 | ?> |
| 26 | - <li><a href="<?php echo get_edit_post_link( $pid ) ?>"><?php |
|
| 27 | - echo get_the_title( $pid ) ?></a> [<a |
|
| 28 | - href="<?php echo esc_attr( $cancel_link ); ?> "><?php esc_html_e( 'Cancel', 'wordlift' ); ?></a>] |
|
| 26 | + <li><a href="<?php echo get_edit_post_link($pid) ?>"><?php |
|
| 27 | + echo get_the_title($pid) ?></a> [<a |
|
| 28 | + href="<?php echo esc_attr($cancel_link); ?> "><?php esc_html_e('Cancel', 'wordlift'); ?></a>] |
|
| 29 | 29 | </li> |
| 30 | 30 | <?php |
| 31 | 31 | } |
@@ -33,20 +33,20 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $queue = $this->batch_analysis_service->waiting_for_response(); |
| 36 | - $request_count = count( $queue ); |
|
| 36 | + $request_count = count($queue); |
|
| 37 | 37 | ?> |
| 38 | - <h3><?php esc_html_e( 'Posts being processed', 'wordlift' ) ?><?php echo " ($request_count)"; ?></h3> |
|
| 38 | + <h3><?php esc_html_e('Posts being processed', 'wordlift') ?><?php echo " ($request_count)"; ?></h3> |
|
| 39 | 39 | <?php |
| 40 | - if ( empty( $queue ) ) { |
|
| 41 | - esc_html_e( 'Nothing is currently being processed', 'wordlift' ); |
|
| 40 | + if (empty($queue)) { |
|
| 41 | + esc_html_e('Nothing is currently being processed', 'wordlift'); |
|
| 42 | 42 | } else { |
| 43 | 43 | echo '<ul>'; |
| 44 | - foreach ( $queue as $pid ) { |
|
| 45 | - $cancel_link = admin_url( "admin-ajax.php?action=wl_batch_analysis_cancel&post=$pid" ); |
|
| 44 | + foreach ($queue as $pid) { |
|
| 45 | + $cancel_link = admin_url("admin-ajax.php?action=wl_batch_analysis_cancel&post=$pid"); |
|
| 46 | 46 | ?> |
| 47 | - <li><a href="<?php echo get_edit_post_link( $pid ) ?>"><?php |
|
| 48 | - echo get_the_title( $pid ) ?></a> [<a |
|
| 49 | - href="<?php echo esc_attr( $cancel_link ); ?> "><?php esc_html_e( 'Cancel', 'wordlift' ); ?></a>] |
|
| 47 | + <li><a href="<?php echo get_edit_post_link($pid) ?>"><?php |
|
| 48 | + echo get_the_title($pid) ?></a> [<a |
|
| 49 | + href="<?php echo esc_attr($cancel_link); ?> "><?php esc_html_e('Cancel', 'wordlift'); ?></a>] |
|
| 50 | 50 | </li> |
| 51 | 51 | <?php |
| 52 | 52 | } |
@@ -54,21 +54,21 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $queue = $this->batch_analysis_service->get_warnings(); |
| 57 | - $warning_count = count( $queue ); |
|
| 57 | + $warning_count = count($queue); |
|
| 58 | 58 | ?> |
| 59 | 59 | |
| 60 | - <h3><?php esc_html_e( 'Posts with warnings', 'wordlift' ) ?><?php echo " ($warning_count)"; ?></h3> |
|
| 60 | + <h3><?php esc_html_e('Posts with warnings', 'wordlift') ?><?php echo " ($warning_count)"; ?></h3> |
|
| 61 | 61 | <?php |
| 62 | - if ( empty( $queue ) ) { |
|
| 63 | - esc_html_e( 'No warnings :-)', 'wordlift' ); |
|
| 62 | + if (empty($queue)) { |
|
| 63 | + esc_html_e('No warnings :-)', 'wordlift'); |
|
| 64 | 64 | } else { |
| 65 | 65 | echo '<ul>'; |
| 66 | - foreach ( $queue as $pid ) { |
|
| 67 | - $cancel_link = admin_url( "admin-ajax.php?action=wl_batch_analysis_clear_warning&post=$pid" ); |
|
| 66 | + foreach ($queue as $pid) { |
|
| 67 | + $cancel_link = admin_url("admin-ajax.php?action=wl_batch_analysis_clear_warning&post=$pid"); |
|
| 68 | 68 | ?> |
| 69 | - <li><a href="<?php echo get_edit_post_link( $pid ) ?>"><?php |
|
| 70 | - echo get_the_title( $pid ) ?></a> [<a |
|
| 71 | - href="<?php echo esc_attr( $cancel_link ); ?> "><?php esc_html_e( 'Clear warning', 'wordlift' ); ?></a>] |
|
| 69 | + <li><a href="<?php echo get_edit_post_link($pid) ?>"><?php |
|
| 70 | + echo get_the_title($pid) ?></a> [<a |
|
| 71 | + href="<?php echo esc_attr($cancel_link); ?> "><?php esc_html_e('Clear warning', 'wordlift'); ?></a>] |
|
| 72 | 72 | </li> |
| 73 | 73 | <?php |
| 74 | 74 | } |
@@ -7,127 +7,127 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_Thumbnail_Service { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * The Thumbnail id meta key. |
|
| 12 | - * |
|
| 13 | - * @since 3.1.5 |
|
| 14 | - */ |
|
| 15 | - const THUMBNAIL_ID_META_KEY = '_thumbnail_id'; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * The predicate used in RDF to describe the thumbnail. |
|
| 19 | - * |
|
| 20 | - * @since 3.1.5 |
|
| 21 | - */ |
|
| 22 | - const THUMBNAIL_RDF_PREDICATE = 'http://schema.org/image'; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * The Log service. |
|
| 26 | - * |
|
| 27 | - * @since 3.1.5 |
|
| 28 | - * @access private |
|
| 29 | - * @var \Wordlift_Log_Service The Log service. |
|
| 30 | - */ |
|
| 31 | - private $log_service; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Create an instance of the Thumbnail service. |
|
| 35 | - * |
|
| 36 | - * @since 3.1.5 |
|
| 37 | - */ |
|
| 38 | - public function __construct() { |
|
| 39 | - |
|
| 40 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Thumbnail_Service' ); |
|
| 41 | - |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Receive post meta events immediately after a post metadata has been deleted. |
|
| 46 | - * |
|
| 47 | - * @since 3.1.5 |
|
| 48 | - * |
|
| 49 | - * @param array $meta_ids An array of deleted metadata entry IDs. |
|
| 50 | - * @param int $object_id Object ID. |
|
| 51 | - * @param string $meta_key Meta key. |
|
| 52 | - * @param mixed $_meta_value Meta value. |
|
| 53 | - */ |
|
| 54 | - public function deleted_post_meta( $meta_ids, $object_id, $meta_key, $_meta_value ) { |
|
| 55 | - |
|
| 56 | - // Return if it's not the Thumbnail id meta key. |
|
| 57 | - if ( self::THUMBNAIL_ID_META_KEY !== $meta_key ) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // Do not perform any action is the post is not published. |
|
| 62 | - if ( 'publish' !== get_post_status( $object_id ) ) { |
|
| 63 | - return; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // Get the post uri and return if it's null. |
|
| 67 | - if ( null === ( $uri = wl_get_entity_uri( $object_id ) ) ) { |
|
| 68 | - return; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // Prepare the query and execute it. We don't buffer the query since we're not going to reindex. |
|
| 72 | - $query = sprintf( 'DELETE { <%s> <%s> ?o . } WHERE { <%1$s> <%2$s> ?o . };', $uri, self::THUMBNAIL_RDF_PREDICATE ); |
|
| 73 | - if ( false === rl_execute_sparql_update_query( $query, false ) ) { |
|
| 74 | - |
|
| 75 | - $this->log_service->error( "An error occurred removing the post thumbnail [ meta ids :: " . ( is_array( $meta_ids ) ? implode( ',', $meta_ids ) : $meta_ids ) . " ][ object id :: $object_id ][ meta key :: $meta_key ][ meta value :: " . ( is_array( $_meta_value ) ? implode( ',', $_meta_value ) : $_meta_value ) . " ][ query :: $query ]" ); |
|
| 76 | - |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Receive post meta events immediately after a post metadata has been added. |
|
| 83 | - * |
|
| 84 | - * @since 3.1.5 |
|
| 85 | - * |
|
| 86 | - * @param int $mid The meta ID after successful update. |
|
| 87 | - * @param int $object_id Object ID. |
|
| 88 | - * @param string $meta_key Meta key. |
|
| 89 | - * @param mixed $_meta_value Meta value. |
|
| 90 | - */ |
|
| 91 | - public function added_or_updated_post_meta( $mid, $object_id, $meta_key, $_meta_value ) { |
|
| 92 | - |
|
| 93 | - // $this->log_service->trace( "A post meta has been updated [ meta id :: $mid ][ object id :: $object_id ][ meta key :: $meta_key ][ meta value :: " . var_export( $_meta_value, true ) . " ]" ); |
|
| 94 | - |
|
| 95 | - // Return if it's not the Thumbnail id meta key. |
|
| 96 | - if ( self::THUMBNAIL_ID_META_KEY !== $meta_key ) { |
|
| 97 | - return; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // The meta value must be the numeric id of the attachment. If it isn't, return. |
|
| 101 | - if ( ! is_numeric( $_meta_value ) ) { |
|
| 102 | - return; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Do not perform any action is the post is not published. |
|
| 106 | - if ( 'publish' !== get_post_status( $object_id ) ) { |
|
| 107 | - return; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Get the post uri and return if it's null. |
|
| 111 | - if ( null === ( $uri = wl_get_entity_uri( $object_id ) ) ) { |
|
| 112 | - return; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Don't pollute the cache. |
|
| 116 | - wp_cache_delete( $object_id, 'post_meta' ); |
|
| 117 | - |
|
| 118 | - // Get the attachment url and return if not found. |
|
| 119 | - if ( false === ( $attachment_url = wp_get_attachment_url( $_meta_value ) ) ) { |
|
| 120 | - return; |
|
| 121 | - }; |
|
| 122 | - |
|
| 123 | - // Prepare the query and execute it. We don't buffer the query since we're not going to reindex. |
|
| 124 | - $query = sprintf( 'DELETE { <%1$s> <%2$s> ?o . } WHERE { <%1$s> <%2$s> ?o . }; INSERT DATA { <%1$s> <%2$s> <%3$s> . };', $uri, self::THUMBNAIL_RDF_PREDICATE, $attachment_url ); |
|
| 125 | - if ( false === rl_execute_sparql_update_query( $query, false ) ) { |
|
| 126 | - |
|
| 127 | - $this->log_service->error( "An error occurred removing the post thumbnail [ meta ids :: $mid ][ object id :: $object_id ][ meta key :: $meta_key ][ meta value :: " . var_export( $_meta_value, true ) . " ][ query :: $query ]" ); |
|
| 128 | - |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - } |
|
| 10 | + /** |
|
| 11 | + * The Thumbnail id meta key. |
|
| 12 | + * |
|
| 13 | + * @since 3.1.5 |
|
| 14 | + */ |
|
| 15 | + const THUMBNAIL_ID_META_KEY = '_thumbnail_id'; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * The predicate used in RDF to describe the thumbnail. |
|
| 19 | + * |
|
| 20 | + * @since 3.1.5 |
|
| 21 | + */ |
|
| 22 | + const THUMBNAIL_RDF_PREDICATE = 'http://schema.org/image'; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * The Log service. |
|
| 26 | + * |
|
| 27 | + * @since 3.1.5 |
|
| 28 | + * @access private |
|
| 29 | + * @var \Wordlift_Log_Service The Log service. |
|
| 30 | + */ |
|
| 31 | + private $log_service; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Create an instance of the Thumbnail service. |
|
| 35 | + * |
|
| 36 | + * @since 3.1.5 |
|
| 37 | + */ |
|
| 38 | + public function __construct() { |
|
| 39 | + |
|
| 40 | + $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Thumbnail_Service' ); |
|
| 41 | + |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Receive post meta events immediately after a post metadata has been deleted. |
|
| 46 | + * |
|
| 47 | + * @since 3.1.5 |
|
| 48 | + * |
|
| 49 | + * @param array $meta_ids An array of deleted metadata entry IDs. |
|
| 50 | + * @param int $object_id Object ID. |
|
| 51 | + * @param string $meta_key Meta key. |
|
| 52 | + * @param mixed $_meta_value Meta value. |
|
| 53 | + */ |
|
| 54 | + public function deleted_post_meta( $meta_ids, $object_id, $meta_key, $_meta_value ) { |
|
| 55 | + |
|
| 56 | + // Return if it's not the Thumbnail id meta key. |
|
| 57 | + if ( self::THUMBNAIL_ID_META_KEY !== $meta_key ) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // Do not perform any action is the post is not published. |
|
| 62 | + if ( 'publish' !== get_post_status( $object_id ) ) { |
|
| 63 | + return; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // Get the post uri and return if it's null. |
|
| 67 | + if ( null === ( $uri = wl_get_entity_uri( $object_id ) ) ) { |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // Prepare the query and execute it. We don't buffer the query since we're not going to reindex. |
|
| 72 | + $query = sprintf( 'DELETE { <%s> <%s> ?o . } WHERE { <%1$s> <%2$s> ?o . };', $uri, self::THUMBNAIL_RDF_PREDICATE ); |
|
| 73 | + if ( false === rl_execute_sparql_update_query( $query, false ) ) { |
|
| 74 | + |
|
| 75 | + $this->log_service->error( "An error occurred removing the post thumbnail [ meta ids :: " . ( is_array( $meta_ids ) ? implode( ',', $meta_ids ) : $meta_ids ) . " ][ object id :: $object_id ][ meta key :: $meta_key ][ meta value :: " . ( is_array( $_meta_value ) ? implode( ',', $_meta_value ) : $_meta_value ) . " ][ query :: $query ]" ); |
|
| 76 | + |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Receive post meta events immediately after a post metadata has been added. |
|
| 83 | + * |
|
| 84 | + * @since 3.1.5 |
|
| 85 | + * |
|
| 86 | + * @param int $mid The meta ID after successful update. |
|
| 87 | + * @param int $object_id Object ID. |
|
| 88 | + * @param string $meta_key Meta key. |
|
| 89 | + * @param mixed $_meta_value Meta value. |
|
| 90 | + */ |
|
| 91 | + public function added_or_updated_post_meta( $mid, $object_id, $meta_key, $_meta_value ) { |
|
| 92 | + |
|
| 93 | + // $this->log_service->trace( "A post meta has been updated [ meta id :: $mid ][ object id :: $object_id ][ meta key :: $meta_key ][ meta value :: " . var_export( $_meta_value, true ) . " ]" ); |
|
| 94 | + |
|
| 95 | + // Return if it's not the Thumbnail id meta key. |
|
| 96 | + if ( self::THUMBNAIL_ID_META_KEY !== $meta_key ) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // The meta value must be the numeric id of the attachment. If it isn't, return. |
|
| 101 | + if ( ! is_numeric( $_meta_value ) ) { |
|
| 102 | + return; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Do not perform any action is the post is not published. |
|
| 106 | + if ( 'publish' !== get_post_status( $object_id ) ) { |
|
| 107 | + return; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Get the post uri and return if it's null. |
|
| 111 | + if ( null === ( $uri = wl_get_entity_uri( $object_id ) ) ) { |
|
| 112 | + return; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Don't pollute the cache. |
|
| 116 | + wp_cache_delete( $object_id, 'post_meta' ); |
|
| 117 | + |
|
| 118 | + // Get the attachment url and return if not found. |
|
| 119 | + if ( false === ( $attachment_url = wp_get_attachment_url( $_meta_value ) ) ) { |
|
| 120 | + return; |
|
| 121 | + }; |
|
| 122 | + |
|
| 123 | + // Prepare the query and execute it. We don't buffer the query since we're not going to reindex. |
|
| 124 | + $query = sprintf( 'DELETE { <%1$s> <%2$s> ?o . } WHERE { <%1$s> <%2$s> ?o . }; INSERT DATA { <%1$s> <%2$s> <%3$s> . };', $uri, self::THUMBNAIL_RDF_PREDICATE, $attachment_url ); |
|
| 125 | + if ( false === rl_execute_sparql_update_query( $query, false ) ) { |
|
| 126 | + |
|
| 127 | + $this->log_service->error( "An error occurred removing the post thumbnail [ meta ids :: $mid ][ object id :: $object_id ][ meta key :: $meta_key ][ meta value :: " . var_export( $_meta_value, true ) . " ][ query :: $query ]" ); |
|
| 128 | + |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | 133 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function __construct() { |
| 39 | 39 | |
| 40 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Thumbnail_Service' ); |
|
| 40 | + $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Thumbnail_Service'); |
|
| 41 | 41 | |
| 42 | 42 | } |
| 43 | 43 | |
@@ -51,28 +51,28 @@ discard block |
||
| 51 | 51 | * @param string $meta_key Meta key. |
| 52 | 52 | * @param mixed $_meta_value Meta value. |
| 53 | 53 | */ |
| 54 | - public function deleted_post_meta( $meta_ids, $object_id, $meta_key, $_meta_value ) { |
|
| 54 | + public function deleted_post_meta($meta_ids, $object_id, $meta_key, $_meta_value) { |
|
| 55 | 55 | |
| 56 | 56 | // Return if it's not the Thumbnail id meta key. |
| 57 | - if ( self::THUMBNAIL_ID_META_KEY !== $meta_key ) { |
|
| 57 | + if (self::THUMBNAIL_ID_META_KEY !== $meta_key) { |
|
| 58 | 58 | return; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // Do not perform any action is the post is not published. |
| 62 | - if ( 'publish' !== get_post_status( $object_id ) ) { |
|
| 62 | + if ('publish' !== get_post_status($object_id)) { |
|
| 63 | 63 | return; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // Get the post uri and return if it's null. |
| 67 | - if ( null === ( $uri = wl_get_entity_uri( $object_id ) ) ) { |
|
| 67 | + if (null === ($uri = wl_get_entity_uri($object_id))) { |
|
| 68 | 68 | return; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // Prepare the query and execute it. We don't buffer the query since we're not going to reindex. |
| 72 | - $query = sprintf( 'DELETE { <%s> <%s> ?o . } WHERE { <%1$s> <%2$s> ?o . };', $uri, self::THUMBNAIL_RDF_PREDICATE ); |
|
| 73 | - if ( false === rl_execute_sparql_update_query( $query, false ) ) { |
|
| 72 | + $query = sprintf('DELETE { <%s> <%s> ?o . } WHERE { <%1$s> <%2$s> ?o . };', $uri, self::THUMBNAIL_RDF_PREDICATE); |
|
| 73 | + if (false === rl_execute_sparql_update_query($query, false)) { |
|
| 74 | 74 | |
| 75 | - $this->log_service->error( "An error occurred removing the post thumbnail [ meta ids :: " . ( is_array( $meta_ids ) ? implode( ',', $meta_ids ) : $meta_ids ) . " ][ object id :: $object_id ][ meta key :: $meta_key ][ meta value :: " . ( is_array( $_meta_value ) ? implode( ',', $_meta_value ) : $_meta_value ) . " ][ query :: $query ]" ); |
|
| 75 | + $this->log_service->error("An error occurred removing the post thumbnail [ meta ids :: ".(is_array($meta_ids) ? implode(',', $meta_ids) : $meta_ids)." ][ object id :: $object_id ][ meta key :: $meta_key ][ meta value :: ".(is_array($_meta_value) ? implode(',', $_meta_value) : $_meta_value)." ][ query :: $query ]"); |
|
| 76 | 76 | |
| 77 | 77 | } |
| 78 | 78 | |
@@ -88,43 +88,43 @@ discard block |
||
| 88 | 88 | * @param string $meta_key Meta key. |
| 89 | 89 | * @param mixed $_meta_value Meta value. |
| 90 | 90 | */ |
| 91 | - public function added_or_updated_post_meta( $mid, $object_id, $meta_key, $_meta_value ) { |
|
| 91 | + public function added_or_updated_post_meta($mid, $object_id, $meta_key, $_meta_value) { |
|
| 92 | 92 | |
| 93 | 93 | // $this->log_service->trace( "A post meta has been updated [ meta id :: $mid ][ object id :: $object_id ][ meta key :: $meta_key ][ meta value :: " . var_export( $_meta_value, true ) . " ]" ); |
| 94 | 94 | |
| 95 | 95 | // Return if it's not the Thumbnail id meta key. |
| 96 | - if ( self::THUMBNAIL_ID_META_KEY !== $meta_key ) { |
|
| 96 | + if (self::THUMBNAIL_ID_META_KEY !== $meta_key) { |
|
| 97 | 97 | return; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // The meta value must be the numeric id of the attachment. If it isn't, return. |
| 101 | - if ( ! is_numeric( $_meta_value ) ) { |
|
| 101 | + if ( ! is_numeric($_meta_value)) { |
|
| 102 | 102 | return; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Do not perform any action is the post is not published. |
| 106 | - if ( 'publish' !== get_post_status( $object_id ) ) { |
|
| 106 | + if ('publish' !== get_post_status($object_id)) { |
|
| 107 | 107 | return; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Get the post uri and return if it's null. |
| 111 | - if ( null === ( $uri = wl_get_entity_uri( $object_id ) ) ) { |
|
| 111 | + if (null === ($uri = wl_get_entity_uri($object_id))) { |
|
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // Don't pollute the cache. |
| 116 | - wp_cache_delete( $object_id, 'post_meta' ); |
|
| 116 | + wp_cache_delete($object_id, 'post_meta'); |
|
| 117 | 117 | |
| 118 | 118 | // Get the attachment url and return if not found. |
| 119 | - if ( false === ( $attachment_url = wp_get_attachment_url( $_meta_value ) ) ) { |
|
| 119 | + if (false === ($attachment_url = wp_get_attachment_url($_meta_value))) { |
|
| 120 | 120 | return; |
| 121 | 121 | }; |
| 122 | 122 | |
| 123 | 123 | // Prepare the query and execute it. We don't buffer the query since we're not going to reindex. |
| 124 | - $query = sprintf( 'DELETE { <%1$s> <%2$s> ?o . } WHERE { <%1$s> <%2$s> ?o . }; INSERT DATA { <%1$s> <%2$s> <%3$s> . };', $uri, self::THUMBNAIL_RDF_PREDICATE, $attachment_url ); |
|
| 125 | - if ( false === rl_execute_sparql_update_query( $query, false ) ) { |
|
| 124 | + $query = sprintf('DELETE { <%1$s> <%2$s> ?o . } WHERE { <%1$s> <%2$s> ?o . }; INSERT DATA { <%1$s> <%2$s> <%3$s> . };', $uri, self::THUMBNAIL_RDF_PREDICATE, $attachment_url); |
|
| 125 | + if (false === rl_execute_sparql_update_query($query, false)) { |
|
| 126 | 126 | |
| 127 | - $this->log_service->error( "An error occurred removing the post thumbnail [ meta ids :: $mid ][ object id :: $object_id ][ meta key :: $meta_key ][ meta value :: " . var_export( $_meta_value, true ) . " ][ query :: $query ]" ); |
|
| 127 | + $this->log_service->error("An error occurred removing the post thumbnail [ meta ids :: $mid ][ object id :: $object_id ][ meta key :: $meta_key ][ meta value :: ".var_export($_meta_value, true)." ][ query :: $query ]"); |
|
| 128 | 128 | |
| 129 | 129 | } |
| 130 | 130 | |