Completed
Push — master ( 1519b2...10cfb1 )
by David
02:25
created
src/admin/class-wordlift-admin.php 2 patches
Indentation   +299 added lines, -299 removed lines patch added patch discarded remove patch
@@ -22,342 +22,342 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class Wordlift_Admin {
24 24
 
25
-	/**
26
-	 * The ID of this plugin.
27
-	 *
28
-	 * @since    1.0.0
29
-	 * @access   private
30
-	 * @var      string $plugin_name The ID of this plugin.
31
-	 */
32
-	private $plugin_name;
33
-
34
-	/**
35
-	 * The version of this plugin.
36
-	 *
37
-	 * @since    1.0.0
38
-	 * @access   private
39
-	 * @var      string $version The current version of this plugin.
40
-	 */
41
-	private $version;
42
-
43
-	/**
44
-	 * The {@link Wordlift_Configuration_Service} instance.
45
-	 *
46
-	 * @since  3.14.0
47
-	 * @access private
48
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
49
-	 */
50
-	private $configuration_service;
51
-
52
-	/**
53
-	 * The {@link Wordlift_User_Service} instance.
54
-	 *
55
-	 * @since  3.14.0
56
-	 * @access private
57
-	 * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
58
-	 */
59
-	private $user_service;
60
-
61
-	/**
62
-	 * The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance.
63
-	 *
64
-	 * @since 3.20.0
65
-	 * @access private
66
-	 * @var \Wordlift_Batch_Operation_Ajax_Adapter $sync_batch_operation_ajax_adapter The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance.
67
-	 */
68
-	private $sync_batch_operation_ajax_adapter;
69
-
70
-	/**
71
-	 * The singleton instance.
72
-	 *
73
-	 * @since 3.19.4
74
-	 * @access private
75
-	 * @var Wordlift_Admin $instance The singleton instance.
76
-	 */
77
-	private static $instance;
78
-
79
-	/**
80
-	 * Initialize the class and set its properties.
81
-	 *
82
-	 * @param string $plugin_name The name of this plugin.
83
-	 * @param string $version The version of this plugin.
84
-	 * @param \Wordlift_Configuration_Service $configuration_service The configuration service.
85
-	 * @param \Wordlift_Notice_Service $notice_service The notice service.
86
-	 * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
87
-	 *
88
-	 * @since  1.0.0
89
-	 *
90
-	 */
91
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
92
-
93
-		$this->plugin_name = $plugin_name;
94
-		$this->version     = $version;
95
-
96
-		$this->configuration_service = $configuration_service;
97
-		$this->user_service          = $user_service;
98
-
99
-		$dataset_uri = $configuration_service->get_dataset_uri();
100
-		$key         = $configuration_service->get_key();
101
-
102
-		if ( empty( $dataset_uri ) ) {
103
-			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
104
-			if ( empty( $key ) ) {
105
-				$error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
106
-			} else {
107
-				$error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
108
-			}
109
-			$notice_service->add_error( $error );
110
-		}
111
-
112
-		// Load additional code if we're in the admin UI.
113
-		if ( is_admin() ) {
114
-
115
-			// Require the PHP files for the next code fragment.
116
-			self::require_files();
117
-
118
-			/*
25
+    /**
26
+     * The ID of this plugin.
27
+     *
28
+     * @since    1.0.0
29
+     * @access   private
30
+     * @var      string $plugin_name The ID of this plugin.
31
+     */
32
+    private $plugin_name;
33
+
34
+    /**
35
+     * The version of this plugin.
36
+     *
37
+     * @since    1.0.0
38
+     * @access   private
39
+     * @var      string $version The current version of this plugin.
40
+     */
41
+    private $version;
42
+
43
+    /**
44
+     * The {@link Wordlift_Configuration_Service} instance.
45
+     *
46
+     * @since  3.14.0
47
+     * @access private
48
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
49
+     */
50
+    private $configuration_service;
51
+
52
+    /**
53
+     * The {@link Wordlift_User_Service} instance.
54
+     *
55
+     * @since  3.14.0
56
+     * @access private
57
+     * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
58
+     */
59
+    private $user_service;
60
+
61
+    /**
62
+     * The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance.
63
+     *
64
+     * @since 3.20.0
65
+     * @access private
66
+     * @var \Wordlift_Batch_Operation_Ajax_Adapter $sync_batch_operation_ajax_adapter The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance.
67
+     */
68
+    private $sync_batch_operation_ajax_adapter;
69
+
70
+    /**
71
+     * The singleton instance.
72
+     *
73
+     * @since 3.19.4
74
+     * @access private
75
+     * @var Wordlift_Admin $instance The singleton instance.
76
+     */
77
+    private static $instance;
78
+
79
+    /**
80
+     * Initialize the class and set its properties.
81
+     *
82
+     * @param string $plugin_name The name of this plugin.
83
+     * @param string $version The version of this plugin.
84
+     * @param \Wordlift_Configuration_Service $configuration_service The configuration service.
85
+     * @param \Wordlift_Notice_Service $notice_service The notice service.
86
+     * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
87
+     *
88
+     * @since  1.0.0
89
+     *
90
+     */
91
+    public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
92
+
93
+        $this->plugin_name = $plugin_name;
94
+        $this->version     = $version;
95
+
96
+        $this->configuration_service = $configuration_service;
97
+        $this->user_service          = $user_service;
98
+
99
+        $dataset_uri = $configuration_service->get_dataset_uri();
100
+        $key         = $configuration_service->get_key();
101
+
102
+        if ( empty( $dataset_uri ) ) {
103
+            $settings_page = Wordlift_Admin_Settings_Page::get_instance();
104
+            if ( empty( $key ) ) {
105
+                $error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
106
+            } else {
107
+                $error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
108
+            }
109
+            $notice_service->add_error( $error );
110
+        }
111
+
112
+        // Load additional code if we're in the admin UI.
113
+        if ( is_admin() ) {
114
+
115
+            // Require the PHP files for the next code fragment.
116
+            self::require_files();
117
+
118
+            /*
119 119
 			 * @since 3.24.2 This function isn't called anymore because it was causing the Block Category to
120 120
 			 * multiply in Block Editor.
121 121
 			 *
122 122
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/1004
123 123
 			 */
124
-			// Add Wordlift custom block category.
125
-			// self::add_block_category();
124
+            // Add Wordlift custom block category.
125
+            // self::add_block_category();
126 126
 
127
-			new Wordlift_Dashboard_Latest_News();
127
+            new Wordlift_Dashboard_Latest_News();
128 128
 
129
-			// Search Rankings.
130
-			$search_rankings_service = new Wordlift_Admin_Search_Rankings_Service( Wordlift_Api_Service::get_instance() );
131
-			new Wordlift_Admin_Search_Rankings_Ajax_Adapter( $search_rankings_service );
129
+            // Search Rankings.
130
+            $search_rankings_service = new Wordlift_Admin_Search_Rankings_Service( Wordlift_Api_Service::get_instance() );
131
+            new Wordlift_Admin_Search_Rankings_Ajax_Adapter( $search_rankings_service );
132 132
 
133
-			/*
133
+            /*
134 134
 			 * Add support for `All Entity Types`.
135 135
 			 *
136 136
 			 * @since 3.20.0
137 137
 			 *
138 138
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/835
139 139
 			 */
140
-			if ( WL_ALL_ENTITY_TYPES ) {
141
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php';
142
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-property-metabox.php';
140
+            if ( WL_ALL_ENTITY_TYPES ) {
141
+                require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php';
142
+                require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-property-metabox.php';
143 143
 
144
-				// new Wordlift_Admin_Schemaorg_Property_Metabox( Wordlift_Schemaorg_Property_Service::get_instance() );
145
-				/*
144
+                // new Wordlift_Admin_Schemaorg_Property_Metabox( Wordlift_Schemaorg_Property_Service::get_instance() );
145
+                /*
146 146
 				 * The `Mappings` admin page.
147 147
 				 */
148
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-mappings-page.php';
149
-				new Wordlift_Admin_Mappings_Page();
148
+                require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-mappings-page.php';
149
+                new Wordlift_Admin_Mappings_Page();
150 150
 
151
-				/*
151
+                /*
152 152
 				 * Allow sync'ing the schema.org taxonomy with the schema.org json file.
153 153
 				 *
154 154
 				 * @since 3.20.0
155 155
 				 */
156
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php';
156
+                require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php';
157 157
 
158
-				$this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' );
158
+                $this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' );
159 159
 
160
-			}
160
+            }
161 161
 
162
-			/*
162
+            /*
163 163
 			 * Add the {@link Wordlift_Admin_Term_Adapter}.
164 164
 			 *
165 165
 			 * @since 3.20.0
166 166
 			 */
167
-			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-term-adapter.php';
168
-			new Wordlift_Admin_Term_Adapter();
167
+            require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-term-adapter.php';
168
+            new Wordlift_Admin_Term_Adapter();
169 169
 
170
-			/*
170
+            /*
171 171
 			 * The new dashboard.
172 172
 			 *
173 173
 			 * @since 3.20.0
174 174
 			 *
175 175
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/879
176 176
 			 */
177
-			new Wordlift_Admin_Dashboard_V2(
178
-				$search_rankings_service,
179
-				Wordlift::get_instance()->get_dashboard_service(),
180
-				Wordlift_Entity_Service::get_instance()
181
-			);
182
-			new Wordlift_Admin_Not_Enriched_Filter();
183
-
184
-		}
185
-
186
-		// Set the singleton instance.
187
-		self::$instance = $this;
188
-
189
-	}
190
-
191
-	/**
192
-	 * Get the singleton instance.
193
-	 *
194
-	 * @return \Wordlift_Admin The singleton instance.
195
-	 * @since 3.19.4
196
-	 *
197
-	 */
198
-	public static function get_instance() {
199
-
200
-		return self::$instance;
201
-	}
202
-
203
-	/**
204
-	 * Register the stylesheets for the admin area.
205
-	 *
206
-	 * @since    1.0.0
207
-	 */
208
-	public function enqueue_styles() {
209
-
210
-		/**
211
-		 * This function is provided for demonstration purposes only.
212
-		 *
213
-		 * An instance of this class should be passed to the run() function
214
-		 * defined in Wordlift_Loader as all of the hooks are defined
215
-		 * in that particular class.
216
-		 *
217
-		 * The Wordlift_Loader will then create the relationship
218
-		 * between the defined hooks and the functions defined in this
219
-		 * class.
220
-		 */
221
-
222
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
223
-
224
-	}
225
-
226
-	/**
227
-	 * Register the JavaScript for the admin area.
228
-	 *
229
-	 * @since    1.0.0
230
-	 */
231
-	public function enqueue_scripts() {
232
-
233
-		/*
177
+            new Wordlift_Admin_Dashboard_V2(
178
+                $search_rankings_service,
179
+                Wordlift::get_instance()->get_dashboard_service(),
180
+                Wordlift_Entity_Service::get_instance()
181
+            );
182
+            new Wordlift_Admin_Not_Enriched_Filter();
183
+
184
+        }
185
+
186
+        // Set the singleton instance.
187
+        self::$instance = $this;
188
+
189
+    }
190
+
191
+    /**
192
+     * Get the singleton instance.
193
+     *
194
+     * @return \Wordlift_Admin The singleton instance.
195
+     * @since 3.19.4
196
+     *
197
+     */
198
+    public static function get_instance() {
199
+
200
+        return self::$instance;
201
+    }
202
+
203
+    /**
204
+     * Register the stylesheets for the admin area.
205
+     *
206
+     * @since    1.0.0
207
+     */
208
+    public function enqueue_styles() {
209
+
210
+        /**
211
+         * This function is provided for demonstration purposes only.
212
+         *
213
+         * An instance of this class should be passed to the run() function
214
+         * defined in Wordlift_Loader as all of the hooks are defined
215
+         * in that particular class.
216
+         *
217
+         * The Wordlift_Loader will then create the relationship
218
+         * between the defined hooks and the functions defined in this
219
+         * class.
220
+         */
221
+
222
+        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
223
+
224
+    }
225
+
226
+    /**
227
+     * Register the JavaScript for the admin area.
228
+     *
229
+     * @since    1.0.0
230
+     */
231
+    public function enqueue_scripts() {
232
+
233
+        /*
234 234
 		 * Do not load our scripts on the Filter Urls plugin admin pages.
235 235
 		 *
236 236
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/901
237 237
 		 * @since 3.20.0
238 238
 		 */
239
-		$screen = get_current_screen();
240
-		if ( is_a( $screen, 'WP_Screen' ) && 'filter-urls_page_filter_urls_form' === $screen->id ) {
241
-			return;
242
-		}
239
+        $screen = get_current_screen();
240
+        if ( is_a( $screen, 'WP_Screen' ) && 'filter-urls_page_filter_urls_form' === $screen->id ) {
241
+            return;
242
+        }
243 243
 
244
-		// Enqueue the admin scripts.
245
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
246
-			'jquery',
247
-			'underscore',
248
-			'backbone',
249
-		), $this->version, false );
244
+        // Enqueue the admin scripts.
245
+        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
246
+            'jquery',
247
+            'underscore',
248
+            'backbone',
249
+        ), $this->version, false );
250 250
 
251 251
 
252
-		$can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' );
252
+        $can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' );
253 253
 
254
-		/*
254
+        /*
255 255
 		 * People that can create entities will see the scope set in the wp-config.php file (by default `cloud`). People
256 256
 		 * that cannot edit create entities will always see the local entities.
257 257
 		 *
258 258
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/839
259 259
 		 */
260
-		$autocomplete_scope = $can_edit_wordlift_entities ? WL_AUTOCOMPLETE_SCOPE : "local";
261
-
262
-		// Set the basic params.
263
-		$params = array(
264
-			// @todo scripts in admin should use wp.post.
265
-			'ajax_url'                   => admin_url( 'admin-ajax.php' ),
266
-			// @todo remove specific actions from settings.
267
-			'action'                     => 'entity_by_title',
268
-			'datasetUri'                 => $this->configuration_service->get_dataset_uri(),
269
-			'language'                   => $this->configuration_service->get_language_code(),
270
-			'link_by_default'            => $this->configuration_service->is_link_by_default(),
271
-			// Whether the current user is allowed to create new entities.
272
-			//
273
-			// @see https://github.com/insideout10/wordlift-plugin/issues/561
274
-			'can_create_entities'        => $can_edit_wordlift_entities ? 'yes' : 'no',
275
-			'l10n'                       => array(
276
-				'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
277
-				'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
278
-				'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
279
-				'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
280
-				'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
281
-				'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ),
282
-				'Add keywords to track'                                              => __( 'Add Keywords to track', 'wordlift' ),
283
-			),
284
-			'wl_autocomplete_nonce'      => wp_create_nonce( 'wl_autocomplete' ),
285
-			'autocomplete_scope'         => $autocomplete_scope,
286
-			/**
287
-			 * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load
288
-			 * or change the TinyMCE id.
289
-			 *
290
-			 * The editor id is currently referenced by `src/coffee/editpost-widget/app.services.EditorAdapter.coffee`.
291
-			 *
292
-			 * @param string $editor The default editor id, by default `content`.
293
-			 *
294
-			 * @see https://github.com/insideout10/wordlift-plugin/issues/848
295
-			 *
296
-			 * @since 3.19.4
297
-			 *
298
-			 */
299
-			'default_editor_id'          => apply_filters( 'wl_default_editor_id', 'content' ),
300
-			/**
301
-			 * Add the link to the Search Keywords admin page.
302
-			 *
303
-			 * @since 3.20.0
304
-			 */
305
-			'search_keywords_admin_page' => admin_url( 'admin.php?page=wl_configuration_admin_menu&tab=search-keywords' ),
306
-
307
-			'analysis' => array( '_wpnonce' => wp_create_nonce( 'wl_analyze' ), )
308
-		);
309
-
310
-		// Set post-related values if there's a current post.
311
-		if ( null !== $post = $entity_being_edited = get_post() ) {
312
-
313
-			$params['post_id']           = $entity_being_edited->ID;
314
-			$entity_service              = Wordlift_Entity_Service::get_instance();
315
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
316
-			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
317
-			// from the results, since we don't want the current entity to be discovered by the analysis.
318
-			//
319
-			// See https://github.com/insideout10/wordlift-plugin/issues/345
320
-			$params['itemId']                      = $entity_service->get_uri( $entity_being_edited->ID );
321
-			$params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' );
322
-
323
-			/*
260
+        $autocomplete_scope = $can_edit_wordlift_entities ? WL_AUTOCOMPLETE_SCOPE : "local";
261
+
262
+        // Set the basic params.
263
+        $params = array(
264
+            // @todo scripts in admin should use wp.post.
265
+            'ajax_url'                   => admin_url( 'admin-ajax.php' ),
266
+            // @todo remove specific actions from settings.
267
+            'action'                     => 'entity_by_title',
268
+            'datasetUri'                 => $this->configuration_service->get_dataset_uri(),
269
+            'language'                   => $this->configuration_service->get_language_code(),
270
+            'link_by_default'            => $this->configuration_service->is_link_by_default(),
271
+            // Whether the current user is allowed to create new entities.
272
+            //
273
+            // @see https://github.com/insideout10/wordlift-plugin/issues/561
274
+            'can_create_entities'        => $can_edit_wordlift_entities ? 'yes' : 'no',
275
+            'l10n'                       => array(
276
+                'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
277
+                'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
278
+                'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
279
+                'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
280
+                'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
281
+                'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ),
282
+                'Add keywords to track'                                              => __( 'Add Keywords to track', 'wordlift' ),
283
+            ),
284
+            'wl_autocomplete_nonce'      => wp_create_nonce( 'wl_autocomplete' ),
285
+            'autocomplete_scope'         => $autocomplete_scope,
286
+            /**
287
+             * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load
288
+             * or change the TinyMCE id.
289
+             *
290
+             * The editor id is currently referenced by `src/coffee/editpost-widget/app.services.EditorAdapter.coffee`.
291
+             *
292
+             * @param string $editor The default editor id, by default `content`.
293
+             *
294
+             * @see https://github.com/insideout10/wordlift-plugin/issues/848
295
+             *
296
+             * @since 3.19.4
297
+             *
298
+             */
299
+            'default_editor_id'          => apply_filters( 'wl_default_editor_id', 'content' ),
300
+            /**
301
+             * Add the link to the Search Keywords admin page.
302
+             *
303
+             * @since 3.20.0
304
+             */
305
+            'search_keywords_admin_page' => admin_url( 'admin.php?page=wl_configuration_admin_menu&tab=search-keywords' ),
306
+
307
+            'analysis' => array( '_wpnonce' => wp_create_nonce( 'wl_analyze' ), )
308
+        );
309
+
310
+        // Set post-related values if there's a current post.
311
+        if ( null !== $post = $entity_being_edited = get_post() ) {
312
+
313
+            $params['post_id']           = $entity_being_edited->ID;
314
+            $entity_service              = Wordlift_Entity_Service::get_instance();
315
+            $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
316
+            // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
317
+            // from the results, since we don't want the current entity to be discovered by the analysis.
318
+            //
319
+            // See https://github.com/insideout10/wordlift-plugin/issues/345
320
+            $params['itemId']                      = $entity_service->get_uri( $entity_being_edited->ID );
321
+            $params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' );
322
+
323
+            /*
324 324
 			 * Add the `properties` if `WL_ALL_ENTITY_TYPES` is enabled.
325 325
 			 *
326 326
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/835
327 327
 			 */
328
-			if ( WL_ALL_ENTITY_TYPES ) {
329
-				$params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID );
330
-			}
331
-
332
-		}
333
-
334
-		// Finally output the params as `wlSettings` for JavaScript code.
335
-		wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) );
336
-
337
-	}
338
-
339
-	/**
340
-	 * Require files needed for the Admin UI.
341
-	 *
342
-	 * @since 3.20.0
343
-	 */
344
-	private static function require_files() {
345
-
346
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
347
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-service.php';
348
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-ajax-adapter.php';
349
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-v2.php';
350
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-not-enriched-filter.php';
351
-
352
-	}
353
-
354
-	/**
355
-	 * Add Wordlift custom block category.
356
-	 *
357
-	 * @since 3.21.0
358
-	 * @since 3.24.2 this function isn't called anymore as it was causing the WordLift block category to multiply
359
-	 *   in Block Editor, https://github.com/insideout10/wordlift-plugin/issues/1004
360
-	 */
328
+            if ( WL_ALL_ENTITY_TYPES ) {
329
+                $params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID );
330
+            }
331
+
332
+        }
333
+
334
+        // Finally output the params as `wlSettings` for JavaScript code.
335
+        wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) );
336
+
337
+    }
338
+
339
+    /**
340
+     * Require files needed for the Admin UI.
341
+     *
342
+     * @since 3.20.0
343
+     */
344
+    private static function require_files() {
345
+
346
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
347
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-service.php';
348
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-ajax-adapter.php';
349
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-v2.php';
350
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-not-enriched-filter.php';
351
+
352
+    }
353
+
354
+    /**
355
+     * Add Wordlift custom block category.
356
+     *
357
+     * @since 3.21.0
358
+     * @since 3.24.2 this function isn't called anymore as it was causing the WordLift block category to multiply
359
+     *   in Block Editor, https://github.com/insideout10/wordlift-plugin/issues/1004
360
+     */
361 361
 //	private static function add_block_category() {
362 362
 //		add_filter( 'block_categories', function ( $categories, $post ) {
363 363
 //			return array_merge(
@@ -373,22 +373,22 @@  discard block
 block discarded – undo
373 373
 //		}, 10, 2 );
374 374
 //	}
375 375
 
376
-	public static function is_gutenberg() {
377
-		if ( function_exists( 'is_gutenberg_page' ) &&
378
-		     is_gutenberg_page()
379
-		) {
380
-			// The Gutenberg plugin is on.
381
-			return true;
382
-		}
383
-		$current_screen = get_current_screen();
384
-		if ( method_exists( $current_screen, 'is_block_editor' ) &&
385
-		     $current_screen->is_block_editor()
386
-		) {
387
-			// Gutenberg page on 5+.
388
-			return true;
389
-		}
390
-
391
-		return false;
392
-	}
376
+    public static function is_gutenberg() {
377
+        if ( function_exists( 'is_gutenberg_page' ) &&
378
+             is_gutenberg_page()
379
+        ) {
380
+            // The Gutenberg plugin is on.
381
+            return true;
382
+        }
383
+        $current_screen = get_current_screen();
384
+        if ( method_exists( $current_screen, 'is_block_editor' ) &&
385
+             $current_screen->is_block_editor()
386
+        ) {
387
+            // Gutenberg page on 5+.
388
+            return true;
389
+        }
390
+
391
+        return false;
392
+    }
393 393
 
394 394
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 * @since  1.0.0
89 89
 	 *
90 90
 	 */
91
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
91
+	public function __construct($plugin_name, $version, $configuration_service, $notice_service, $user_service) {
92 92
 
93 93
 		$this->plugin_name = $plugin_name;
94 94
 		$this->version     = $version;
@@ -99,18 +99,18 @@  discard block
 block discarded – undo
99 99
 		$dataset_uri = $configuration_service->get_dataset_uri();
100 100
 		$key         = $configuration_service->get_key();
101 101
 
102
-		if ( empty( $dataset_uri ) ) {
102
+		if (empty($dataset_uri)) {
103 103
 			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
104
-			if ( empty( $key ) ) {
105
-				$error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
104
+			if (empty($key)) {
105
+				$error = sprintf(esc_html__("WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>');
106 106
 			} else {
107
-				$error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
107
+				$error = sprintf(esc_html__("WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>');
108 108
 			}
109
-			$notice_service->add_error( $error );
109
+			$notice_service->add_error($error);
110 110
 		}
111 111
 
112 112
 		// Load additional code if we're in the admin UI.
113
-		if ( is_admin() ) {
113
+		if (is_admin()) {
114 114
 
115 115
 			// Require the PHP files for the next code fragment.
116 116
 			self::require_files();
@@ -127,8 +127,8 @@  discard block
 block discarded – undo
127 127
 			new Wordlift_Dashboard_Latest_News();
128 128
 
129 129
 			// Search Rankings.
130
-			$search_rankings_service = new Wordlift_Admin_Search_Rankings_Service( Wordlift_Api_Service::get_instance() );
131
-			new Wordlift_Admin_Search_Rankings_Ajax_Adapter( $search_rankings_service );
130
+			$search_rankings_service = new Wordlift_Admin_Search_Rankings_Service(Wordlift_Api_Service::get_instance());
131
+			new Wordlift_Admin_Search_Rankings_Ajax_Adapter($search_rankings_service);
132 132
 
133 133
 			/*
134 134
 			 * Add support for `All Entity Types`.
@@ -137,15 +137,15 @@  discard block
 block discarded – undo
137 137
 			 *
138 138
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/835
139 139
 			 */
140
-			if ( WL_ALL_ENTITY_TYPES ) {
141
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php';
142
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-property-metabox.php';
140
+			if (WL_ALL_ENTITY_TYPES) {
141
+				require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php';
142
+				require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-schemaorg-property-metabox.php';
143 143
 
144 144
 				// new Wordlift_Admin_Schemaorg_Property_Metabox( Wordlift_Schemaorg_Property_Service::get_instance() );
145 145
 				/*
146 146
 				 * The `Mappings` admin page.
147 147
 				 */
148
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-mappings-page.php';
148
+				require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-mappings-page.php';
149 149
 				new Wordlift_Admin_Mappings_Page();
150 150
 
151 151
 				/*
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
 				 *
154 154
 				 * @since 3.20.0
155 155
 				 */
156
-				require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php';
156
+				require_once plugin_dir_path(dirname(__FILE__)).'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php';
157 157
 
158
-				$this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' );
158
+				$this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter(new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync');
159 159
 
160 160
 			}
161 161
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 			 *
165 165
 			 * @since 3.20.0
166 166
 			 */
167
-			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-term-adapter.php';
167
+			require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-term-adapter.php';
168 168
 			new Wordlift_Admin_Term_Adapter();
169 169
 
170 170
 			/*
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 		 * class.
220 220
 		 */
221 221
 
222
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
222
+		wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wordlift-admin.css', array(), $this->version, 'all');
223 223
 
224 224
 	}
225 225
 
@@ -237,19 +237,19 @@  discard block
 block discarded – undo
237 237
 		 * @since 3.20.0
238 238
 		 */
239 239
 		$screen = get_current_screen();
240
-		if ( is_a( $screen, 'WP_Screen' ) && 'filter-urls_page_filter_urls_form' === $screen->id ) {
240
+		if (is_a($screen, 'WP_Screen') && 'filter-urls_page_filter_urls_form' === $screen->id) {
241 241
 			return;
242 242
 		}
243 243
 
244 244
 		// Enqueue the admin scripts.
245
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
245
+		wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/1/admin.js', array(
246 246
 			'jquery',
247 247
 			'underscore',
248 248
 			'backbone',
249
-		), $this->version, false );
249
+		), $this->version, false);
250 250
 
251 251
 
252
-		$can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' );
252
+		$can_edit_wordlift_entities = current_user_can('edit_wordlift_entities');
253 253
 
254 254
 		/*
255 255
 		 * People that can create entities will see the scope set in the wp-config.php file (by default `cloud`). People
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 		// Set the basic params.
263 263
 		$params = array(
264 264
 			// @todo scripts in admin should use wp.post.
265
-			'ajax_url'                   => admin_url( 'admin-ajax.php' ),
265
+			'ajax_url'                   => admin_url('admin-ajax.php'),
266 266
 			// @todo remove specific actions from settings.
267 267
 			'action'                     => 'entity_by_title',
268 268
 			'datasetUri'                 => $this->configuration_service->get_dataset_uri(),
@@ -273,15 +273,15 @@  discard block
 block discarded – undo
273 273
 			// @see https://github.com/insideout10/wordlift-plugin/issues/561
274 274
 			'can_create_entities'        => $can_edit_wordlift_entities ? 'yes' : 'no',
275 275
 			'l10n'                       => array(
276
-				'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
277
-				'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
278
-				'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
279
-				'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
280
-				'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
281
-				'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ),
282
-				'Add keywords to track'                                              => __( 'Add Keywords to track', 'wordlift' ),
276
+				'You already published an entity with the same name'                 => __('You already published an entity with the same name: ', 'wordlift'),
277
+				'logo_selection_title'                                               => __('WordLift Choose Logo', 'wordlift'),
278
+				'logo_selection_button'                                              => array('text' => __('Choose Logo', 'wordlift')),
279
+				'Type at least 3 characters to search...'                            => _x('Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift'),
280
+				'No results found for your search.'                                  => _x('No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift'),
281
+				'Please wait while we look for entities in the linked data cloud...' => _x('Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift'),
282
+				'Add keywords to track'                                              => __('Add Keywords to track', 'wordlift'),
283 283
 			),
284
-			'wl_autocomplete_nonce'      => wp_create_nonce( 'wl_autocomplete' ),
284
+			'wl_autocomplete_nonce'      => wp_create_nonce('wl_autocomplete'),
285 285
 			'autocomplete_scope'         => $autocomplete_scope,
286 286
 			/**
287 287
 			 * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load
@@ -296,43 +296,43 @@  discard block
 block discarded – undo
296 296
 			 * @since 3.19.4
297 297
 			 *
298 298
 			 */
299
-			'default_editor_id'          => apply_filters( 'wl_default_editor_id', 'content' ),
299
+			'default_editor_id'          => apply_filters('wl_default_editor_id', 'content'),
300 300
 			/**
301 301
 			 * Add the link to the Search Keywords admin page.
302 302
 			 *
303 303
 			 * @since 3.20.0
304 304
 			 */
305
-			'search_keywords_admin_page' => admin_url( 'admin.php?page=wl_configuration_admin_menu&tab=search-keywords' ),
305
+			'search_keywords_admin_page' => admin_url('admin.php?page=wl_configuration_admin_menu&tab=search-keywords'),
306 306
 
307
-			'analysis' => array( '_wpnonce' => wp_create_nonce( 'wl_analyze' ), )
307
+			'analysis' => array('_wpnonce' => wp_create_nonce('wl_analyze'),)
308 308
 		);
309 309
 
310 310
 		// Set post-related values if there's a current post.
311
-		if ( null !== $post = $entity_being_edited = get_post() ) {
311
+		if (null !== $post = $entity_being_edited = get_post()) {
312 312
 
313 313
 			$params['post_id']           = $entity_being_edited->ID;
314 314
 			$entity_service              = Wordlift_Entity_Service::get_instance();
315
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
315
+			$params['entityBeingEdited'] = isset($entity_being_edited->post_type) && $entity_service->is_entity($post->ID) && is_numeric(get_the_ID());
316 316
 			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
317 317
 			// from the results, since we don't want the current entity to be discovered by the analysis.
318 318
 			//
319 319
 			// See https://github.com/insideout10/wordlift-plugin/issues/345
320
-			$params['itemId']                      = $entity_service->get_uri( $entity_being_edited->ID );
321
-			$params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' );
320
+			$params['itemId']                      = $entity_service->get_uri($entity_being_edited->ID);
321
+			$params['wl_schemaorg_property_nonce'] = wp_create_nonce('wl_schemaorg_property');
322 322
 
323 323
 			/*
324 324
 			 * Add the `properties` if `WL_ALL_ENTITY_TYPES` is enabled.
325 325
 			 *
326 326
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/835
327 327
 			 */
328
-			if ( WL_ALL_ENTITY_TYPES ) {
329
-				$params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID );
328
+			if (WL_ALL_ENTITY_TYPES) {
329
+				$params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all($post->ID);
330 330
 			}
331 331
 
332 332
 		}
333 333
 
334 334
 		// Finally output the params as `wlSettings` for JavaScript code.
335
-		wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) );
335
+		wp_localize_script($this->plugin_name, 'wlSettings', apply_filters('wl_admin_settings', $params));
336 336
 
337 337
 	}
338 338
 
@@ -343,11 +343,11 @@  discard block
 block discarded – undo
343 343
 	 */
344 344
 	private static function require_files() {
345 345
 
346
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
347
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-service.php';
348
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-ajax-adapter.php';
349
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-v2.php';
350
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-not-enriched-filter.php';
346
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-dashboard-latest-news.php';
347
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-search-rankings-service.php';
348
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-search-rankings-ajax-adapter.php';
349
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-dashboard-v2.php';
350
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-not-enriched-filter.php';
351 351
 
352 352
 	}
353 353
 
@@ -374,14 +374,14 @@  discard block
 block discarded – undo
374 374
 //	}
375 375
 
376 376
 	public static function is_gutenberg() {
377
-		if ( function_exists( 'is_gutenberg_page' ) &&
377
+		if (function_exists('is_gutenberg_page') &&
378 378
 		     is_gutenberg_page()
379 379
 		) {
380 380
 			// The Gutenberg plugin is on.
381 381
 			return true;
382 382
 		}
383 383
 		$current_screen = get_current_screen();
384
-		if ( method_exists( $current_screen, 'is_block_editor' ) &&
384
+		if (method_exists($current_screen, 'is_block_editor') &&
385 385
 		     $current_screen->is_block_editor()
386 386
 		) {
387 387
 			// Gutenberg page on 5+.
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-post-edit-page.php 2 patches
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -18,116 +18,116 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Admin_Post_Edit_Page {
20 20
 
21
-	/**
22
-	 * The {@link Wordlift} plugin instance.
23
-	 *
24
-	 * @since 3.11.0
25
-	 *
26
-	 * @var \Wordlift $plugin The {@link Wordlift} plugin instance.
27
-	 */
28
-	private $plugin;
29
-
30
-	/**
31
-	 * A {@link Wordlift_Log_Service} instance.
32
-	 *
33
-	 * @since 3.15.4
34
-	 *
35
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
36
-	 */
37
-	private $log;
38
-
39
-	/**
40
-	 * Create the {@link Wordlift_Admin_Post_Edit_Page} instance.
41
-	 *
42
-	 * @param \Wordlift $plugin The {@link Wordlift} plugin instance.
43
-	 *
44
-	 * @since 3.11.0
45
-	 *
46
-	 */
47
-	function __construct( $plugin ) {
48
-
49
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
50
-
51
-		// Bail out if we're in the UX Builder editor.
52
-		if ( $this->is_ux_builder_editor() ) {
53
-			$this->log->info( 'WordLift will not show, since we are in UX Builder editor.' );
54
-
55
-			return;
56
-		}
57
-
58
-		// Define the callbacks.
59
-		$callback                  = array( $this, 'enqueue_scripts', );
60
-
61
-		// Set a hook to enqueue scripts only when the edit page is displayed.
62
-		add_action( 'admin_print_scripts-post.php', $callback );
63
-		add_action( 'admin_print_scripts-post-new.php', $callback );
64
-
65
-		add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts_gutenberg', ) );
66
-
67
-		$this->plugin = $plugin;
68
-	}
69
-
70
-	/**
71
-	 * Check whether the current post opens with G'berg or not.
72
-	 *
73
-	 * @return bool True if G'berg is used otherwise false.
74
-	 * @since 3.22.3
75
-	 */
76
-	function is_gutenberg_page() {
77
-		if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) {
78
-			// The Gutenberg plugin is on.
79
-			return true;
80
-		}
81
-
82
-		$current_screen = get_current_screen();
83
-		if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
84
-			// Gutenberg page on 5+.
85
-			return true;
86
-		}
87
-
88
-		return false;
89
-	}
90
-
91
-	/**
92
-	 * Check if we're in UX builder.
93
-	 *
94
-	 * @see   https://github.com/insideout10/wordlift-plugin/issues/691
95
-	 *
96
-	 * @since 3.15.4
97
-	 *
98
-	 * @return bool True if we're in UX builder, otherwise false.
99
-	 */
100
-	private function is_ux_builder_editor() {
101
-
102
-		return function_exists( 'ux_builder_is_editor' )
103
-		       && ux_builder_is_editor();
104
-	}
105
-
106
-	/**
107
-	 * Enqueue scripts and styles for the edit page.
108
-	 *
109
-	 * @since 3.11.0
110
-	 */
111
-	public function enqueue_scripts() {
112
-
113
-		// Bail out if this is G'berg.
114
-		if ( $this->is_gutenberg_page() ) {
115
-			return;
116
-		}
117
-
118
-		// Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen.
119
-		//
120
-		// @see https://github.com/insideout10/wordlift-plugin/issues/832
121
-		wp_dequeue_script( 'ontrapagesAngular' );
122
-		wp_dequeue_script( 'ontrapagesApp' );
123
-		wp_dequeue_script( 'ontrapagesController' );
124
-
125
-		// If Gutenberg is enabled for the post, do not load the legacy edit.js.
126
-		if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) {
127
-			return;
128
-		}
129
-
130
-		/*
21
+    /**
22
+     * The {@link Wordlift} plugin instance.
23
+     *
24
+     * @since 3.11.0
25
+     *
26
+     * @var \Wordlift $plugin The {@link Wordlift} plugin instance.
27
+     */
28
+    private $plugin;
29
+
30
+    /**
31
+     * A {@link Wordlift_Log_Service} instance.
32
+     *
33
+     * @since 3.15.4
34
+     *
35
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
36
+     */
37
+    private $log;
38
+
39
+    /**
40
+     * Create the {@link Wordlift_Admin_Post_Edit_Page} instance.
41
+     *
42
+     * @param \Wordlift $plugin The {@link Wordlift} plugin instance.
43
+     *
44
+     * @since 3.11.0
45
+     *
46
+     */
47
+    function __construct( $plugin ) {
48
+
49
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
50
+
51
+        // Bail out if we're in the UX Builder editor.
52
+        if ( $this->is_ux_builder_editor() ) {
53
+            $this->log->info( 'WordLift will not show, since we are in UX Builder editor.' );
54
+
55
+            return;
56
+        }
57
+
58
+        // Define the callbacks.
59
+        $callback                  = array( $this, 'enqueue_scripts', );
60
+
61
+        // Set a hook to enqueue scripts only when the edit page is displayed.
62
+        add_action( 'admin_print_scripts-post.php', $callback );
63
+        add_action( 'admin_print_scripts-post-new.php', $callback );
64
+
65
+        add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts_gutenberg', ) );
66
+
67
+        $this->plugin = $plugin;
68
+    }
69
+
70
+    /**
71
+     * Check whether the current post opens with G'berg or not.
72
+     *
73
+     * @return bool True if G'berg is used otherwise false.
74
+     * @since 3.22.3
75
+     */
76
+    function is_gutenberg_page() {
77
+        if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) {
78
+            // The Gutenberg plugin is on.
79
+            return true;
80
+        }
81
+
82
+        $current_screen = get_current_screen();
83
+        if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
84
+            // Gutenberg page on 5+.
85
+            return true;
86
+        }
87
+
88
+        return false;
89
+    }
90
+
91
+    /**
92
+     * Check if we're in UX builder.
93
+     *
94
+     * @see   https://github.com/insideout10/wordlift-plugin/issues/691
95
+     *
96
+     * @since 3.15.4
97
+     *
98
+     * @return bool True if we're in UX builder, otherwise false.
99
+     */
100
+    private function is_ux_builder_editor() {
101
+
102
+        return function_exists( 'ux_builder_is_editor' )
103
+               && ux_builder_is_editor();
104
+    }
105
+
106
+    /**
107
+     * Enqueue scripts and styles for the edit page.
108
+     *
109
+     * @since 3.11.0
110
+     */
111
+    public function enqueue_scripts() {
112
+
113
+        // Bail out if this is G'berg.
114
+        if ( $this->is_gutenberg_page() ) {
115
+            return;
116
+        }
117
+
118
+        // Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen.
119
+        //
120
+        // @see https://github.com/insideout10/wordlift-plugin/issues/832
121
+        wp_dequeue_script( 'ontrapagesAngular' );
122
+        wp_dequeue_script( 'ontrapagesApp' );
123
+        wp_dequeue_script( 'ontrapagesController' );
124
+
125
+        // If Gutenberg is enabled for the post, do not load the legacy edit.js.
126
+        if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) {
127
+            return;
128
+        }
129
+
130
+        /*
131 131
 		 * Enqueue the edit screen JavaScript. The `wordlift-admin.bundle.js` file
132 132
 		 * is scheduled to replace the older `wordlift-admin.min.js` once client-side
133 133
 		 * code is properly refactored.
@@ -136,118 +136,118 @@  discard block
 block discarded – undo
136 136
 		 *
137 137
 		 * @since 3.20.0 edit.js has been migrated to the new webpack configuration.
138 138
 		 */
139
-		// plugin_dir_url( __FILE__ ) . 'js/1/edit.js'
140
-		$script_name = plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/edit';
141
-
142
-		$this->enqueue_based_on_wordpress_version( 'wordlift-admin-edit-page', $script_name, array(
143
-			$this->plugin->get_plugin_name(),
144
-			'jquery',
145
-			// Require wp.ajax.
146
-			'wp-util',
147
-			// @@todo: provide the following dependencies when we're in WP < 5.0 (i.e. when these dependencies aren't already defined).
148
-			'react',
149
-			'react-dom',
150
-			'wp-element',
151
-			'wp-polyfill',
152
-			/*
139
+        // plugin_dir_url( __FILE__ ) . 'js/1/edit.js'
140
+        $script_name = plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/edit';
141
+
142
+        $this->enqueue_based_on_wordpress_version( 'wordlift-admin-edit-page', $script_name, array(
143
+            $this->plugin->get_plugin_name(),
144
+            'jquery',
145
+            // Require wp.ajax.
146
+            'wp-util',
147
+            // @@todo: provide the following dependencies when we're in WP < 5.0 (i.e. when these dependencies aren't already defined).
148
+            'react',
149
+            'react-dom',
150
+            'wp-element',
151
+            'wp-polyfill',
152
+            /*
153 153
 			 * Angular isn't loaded anymore remotely, but it is loaded within wordlift-reloaded.js.
154 154
 			 *
155 155
 			 * See https://github.com/insideout10/wordlift-plugin/issues/865.
156 156
 			 *
157 157
 			 * @since 3.19.6
158 158
 			 */
159
-			//				// Require Angular.
160
-			//				'wl-angular',
161
-			//				'wl-angular-geolocation',
162
-			//				'wl-angular-touch',
163
-			//				'wl-angular-animate',
164
-			/**
165
-			 * We need the `wp.hooks` global to allow the edit.js script to send actions.
166
-			 *
167
-			 * @since 3.23.0
168
-			 */
169
-			'wp-hooks',
170
-		) );
171
-
172
-		wp_enqueue_style( 'wordlift-admin-edit-page', "$script_name.css", array(), $this->plugin->get_version() );
173
-
174
-	}
175
-
176
-	/**
177
-	 * This function loads the javascript file according to the WordPress version.
178
-	 *
179
-	 * For WordPress < 5.0 it'll load the javascript file using the `.full` suffix i.e. the file that embeds all the
180
-	 * dependencies.
181
-	 *
182
-	 * For WordPress >= 5.0 it'll load the stripped down js.
183
-	 *
184
-	 * @param string $handle The handle name.
185
-	 * @param string $script_name The full script URL without the `.js` extension.
186
-	 * @param array $dependencies An array of dependencies to be added only in WordPress > 5.0.
187
-	 */
188
-	private function enqueue_based_on_wordpress_version( $handle, $script_name, $dependencies ) {
189
-		global $wp_version;
190
-
191
-		if ( version_compare( $wp_version, '5.0', '<' ) ) {
192
-			$actual_script_name  = "$script_name.full.js";
193
-			$actual_dependencies = array();
194
-		} else {
195
-			$actual_script_name  = "$script_name.js";
196
-			$actual_dependencies = $dependencies;
197
-		}
198
-
199
-		wp_enqueue_script( $handle, $actual_script_name, $actual_dependencies, $this->plugin->get_version(), false );
200
-
201
-	}
202
-
203
-	/**
204
-	 * Enqueue scripts and styles for the gutenberg edit page.
205
-	 *
206
-	 * @since 3.21.0
207
-	 */
208
-	public function enqueue_scripts_gutenberg() {
209
-
210
-		wp_register_script(
211
-			'wl-block-editor',
212
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor.js',
213
-			array(
214
-				'react',
215
-				'wordlift',
216
-				'wp-hooks',
217
-				'wp-data',
218
-				'wp-rich-text',
219
-				'wp-blocks',
220
-				'wp-plugins',
221
-				'wp-edit-post',
222
-			),
223
-			$this->plugin->get_version()
224
-		);
225
-		wp_localize_script( 'wl-block-editor', '_wlBlockEditorSettings', array(
226
-			'root'  => esc_url_raw( rest_url() ),
227
-			'nonce' => wp_create_nonce( 'wp_rest' )
228
-		) );
229
-
230
-		wp_enqueue_style(
231
-			'wl-block-editor',
232
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor.css',
233
-			array(),
234
-			$this->plugin->get_version()
235
-		);
236
-
237
-		wp_enqueue_script(
238
-			'wl-autocomplete-select',
239
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/autocomplete-select.js',
240
-			array(),
241
-			$this->plugin->get_version(),
242
-			true
243
-		);
244
-
245
-		wp_enqueue_style(
246
-			'wl-autocomplete-select',
247
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/autocomplete-select.css',
248
-			array(),
249
-			$this->plugin->get_version()
250
-		);
251
-	}
159
+            //				// Require Angular.
160
+            //				'wl-angular',
161
+            //				'wl-angular-geolocation',
162
+            //				'wl-angular-touch',
163
+            //				'wl-angular-animate',
164
+            /**
165
+             * We need the `wp.hooks` global to allow the edit.js script to send actions.
166
+             *
167
+             * @since 3.23.0
168
+             */
169
+            'wp-hooks',
170
+        ) );
171
+
172
+        wp_enqueue_style( 'wordlift-admin-edit-page', "$script_name.css", array(), $this->plugin->get_version() );
173
+
174
+    }
175
+
176
+    /**
177
+     * This function loads the javascript file according to the WordPress version.
178
+     *
179
+     * For WordPress < 5.0 it'll load the javascript file using the `.full` suffix i.e. the file that embeds all the
180
+     * dependencies.
181
+     *
182
+     * For WordPress >= 5.0 it'll load the stripped down js.
183
+     *
184
+     * @param string $handle The handle name.
185
+     * @param string $script_name The full script URL without the `.js` extension.
186
+     * @param array $dependencies An array of dependencies to be added only in WordPress > 5.0.
187
+     */
188
+    private function enqueue_based_on_wordpress_version( $handle, $script_name, $dependencies ) {
189
+        global $wp_version;
190
+
191
+        if ( version_compare( $wp_version, '5.0', '<' ) ) {
192
+            $actual_script_name  = "$script_name.full.js";
193
+            $actual_dependencies = array();
194
+        } else {
195
+            $actual_script_name  = "$script_name.js";
196
+            $actual_dependencies = $dependencies;
197
+        }
198
+
199
+        wp_enqueue_script( $handle, $actual_script_name, $actual_dependencies, $this->plugin->get_version(), false );
200
+
201
+    }
202
+
203
+    /**
204
+     * Enqueue scripts and styles for the gutenberg edit page.
205
+     *
206
+     * @since 3.21.0
207
+     */
208
+    public function enqueue_scripts_gutenberg() {
209
+
210
+        wp_register_script(
211
+            'wl-block-editor',
212
+            plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor.js',
213
+            array(
214
+                'react',
215
+                'wordlift',
216
+                'wp-hooks',
217
+                'wp-data',
218
+                'wp-rich-text',
219
+                'wp-blocks',
220
+                'wp-plugins',
221
+                'wp-edit-post',
222
+            ),
223
+            $this->plugin->get_version()
224
+        );
225
+        wp_localize_script( 'wl-block-editor', '_wlBlockEditorSettings', array(
226
+            'root'  => esc_url_raw( rest_url() ),
227
+            'nonce' => wp_create_nonce( 'wp_rest' )
228
+        ) );
229
+
230
+        wp_enqueue_style(
231
+            'wl-block-editor',
232
+            plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor.css',
233
+            array(),
234
+            $this->plugin->get_version()
235
+        );
236
+
237
+        wp_enqueue_script(
238
+            'wl-autocomplete-select',
239
+            plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/autocomplete-select.js',
240
+            array(),
241
+            $this->plugin->get_version(),
242
+            true
243
+        );
244
+
245
+        wp_enqueue_style(
246
+            'wl-autocomplete-select',
247
+            plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/autocomplete-select.css',
248
+            array(),
249
+            $this->plugin->get_version()
250
+        );
251
+    }
252 252
 
253 253
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -44,25 +44,25 @@  discard block
 block discarded – undo
44 44
 	 * @since 3.11.0
45 45
 	 *
46 46
 	 */
47
-	function __construct( $plugin ) {
47
+	function __construct($plugin) {
48 48
 
49
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
49
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
50 50
 
51 51
 		// Bail out if we're in the UX Builder editor.
52
-		if ( $this->is_ux_builder_editor() ) {
53
-			$this->log->info( 'WordLift will not show, since we are in UX Builder editor.' );
52
+		if ($this->is_ux_builder_editor()) {
53
+			$this->log->info('WordLift will not show, since we are in UX Builder editor.');
54 54
 
55 55
 			return;
56 56
 		}
57 57
 
58 58
 		// Define the callbacks.
59
-		$callback                  = array( $this, 'enqueue_scripts', );
59
+		$callback = array($this, 'enqueue_scripts',);
60 60
 
61 61
 		// Set a hook to enqueue scripts only when the edit page is displayed.
62
-		add_action( 'admin_print_scripts-post.php', $callback );
63
-		add_action( 'admin_print_scripts-post-new.php', $callback );
62
+		add_action('admin_print_scripts-post.php', $callback);
63
+		add_action('admin_print_scripts-post-new.php', $callback);
64 64
 
65
-		add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts_gutenberg', ) );
65
+		add_action('enqueue_block_editor_assets', array($this, 'enqueue_scripts_gutenberg',));
66 66
 
67 67
 		$this->plugin = $plugin;
68 68
 	}
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
 	 * @since 3.22.3
75 75
 	 */
76 76
 	function is_gutenberg_page() {
77
-		if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) {
77
+		if (function_exists('is_gutenberg_page') && is_gutenberg_page()) {
78 78
 			// The Gutenberg plugin is on.
79 79
 			return true;
80 80
 		}
81 81
 
82 82
 		$current_screen = get_current_screen();
83
-		if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
83
+		if (method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()) {
84 84
 			// Gutenberg page on 5+.
85 85
 			return true;
86 86
 		}
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	private function is_ux_builder_editor() {
101 101
 
102
-		return function_exists( 'ux_builder_is_editor' )
102
+		return function_exists('ux_builder_is_editor')
103 103
 		       && ux_builder_is_editor();
104 104
 	}
105 105
 
@@ -111,19 +111,19 @@  discard block
 block discarded – undo
111 111
 	public function enqueue_scripts() {
112 112
 
113 113
 		// Bail out if this is G'berg.
114
-		if ( $this->is_gutenberg_page() ) {
114
+		if ($this->is_gutenberg_page()) {
115 115
 			return;
116 116
 		}
117 117
 
118 118
 		// Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen.
119 119
 		//
120 120
 		// @see https://github.com/insideout10/wordlift-plugin/issues/832
121
-		wp_dequeue_script( 'ontrapagesAngular' );
122
-		wp_dequeue_script( 'ontrapagesApp' );
123
-		wp_dequeue_script( 'ontrapagesController' );
121
+		wp_dequeue_script('ontrapagesAngular');
122
+		wp_dequeue_script('ontrapagesApp');
123
+		wp_dequeue_script('ontrapagesController');
124 124
 
125 125
 		// If Gutenberg is enabled for the post, do not load the legacy edit.js.
126
-		if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) {
126
+		if (function_exists('use_block_editor_for_post') && use_block_editor_for_post(get_post())) {
127 127
 			return;
128 128
 		}
129 129
 
@@ -137,9 +137,9 @@  discard block
 block discarded – undo
137 137
 		 * @since 3.20.0 edit.js has been migrated to the new webpack configuration.
138 138
 		 */
139 139
 		// plugin_dir_url( __FILE__ ) . 'js/1/edit.js'
140
-		$script_name = plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/edit';
140
+		$script_name = plugin_dir_url(dirname(__FILE__)).'js/dist/edit';
141 141
 
142
-		$this->enqueue_based_on_wordpress_version( 'wordlift-admin-edit-page', $script_name, array(
142
+		$this->enqueue_based_on_wordpress_version('wordlift-admin-edit-page', $script_name, array(
143 143
 			$this->plugin->get_plugin_name(),
144 144
 			'jquery',
145 145
 			// Require wp.ajax.
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
 			 * @since 3.23.0
168 168
 			 */
169 169
 			'wp-hooks',
170
-		) );
170
+		));
171 171
 
172
-		wp_enqueue_style( 'wordlift-admin-edit-page', "$script_name.css", array(), $this->plugin->get_version() );
172
+		wp_enqueue_style('wordlift-admin-edit-page', "$script_name.css", array(), $this->plugin->get_version());
173 173
 
174 174
 	}
175 175
 
@@ -185,10 +185,10 @@  discard block
 block discarded – undo
185 185
 	 * @param string $script_name The full script URL without the `.js` extension.
186 186
 	 * @param array $dependencies An array of dependencies to be added only in WordPress > 5.0.
187 187
 	 */
188
-	private function enqueue_based_on_wordpress_version( $handle, $script_name, $dependencies ) {
188
+	private function enqueue_based_on_wordpress_version($handle, $script_name, $dependencies) {
189 189
 		global $wp_version;
190 190
 
191
-		if ( version_compare( $wp_version, '5.0', '<' ) ) {
191
+		if (version_compare($wp_version, '5.0', '<')) {
192 192
 			$actual_script_name  = "$script_name.full.js";
193 193
 			$actual_dependencies = array();
194 194
 		} else {
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 			$actual_dependencies = $dependencies;
197 197
 		}
198 198
 
199
-		wp_enqueue_script( $handle, $actual_script_name, $actual_dependencies, $this->plugin->get_version(), false );
199
+		wp_enqueue_script($handle, $actual_script_name, $actual_dependencies, $this->plugin->get_version(), false);
200 200
 
201 201
 	}
202 202
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 
210 210
 		wp_register_script(
211 211
 			'wl-block-editor',
212
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor.js',
212
+			plugin_dir_url(dirname(__FILE__)).'js/dist/block-editor.js',
213 213
 			array(
214 214
 				'react',
215 215
 				'wordlift',
@@ -222,21 +222,21 @@  discard block
 block discarded – undo
222 222
 			),
223 223
 			$this->plugin->get_version()
224 224
 		);
225
-		wp_localize_script( 'wl-block-editor', '_wlBlockEditorSettings', array(
226
-			'root'  => esc_url_raw( rest_url() ),
227
-			'nonce' => wp_create_nonce( 'wp_rest' )
228
-		) );
225
+		wp_localize_script('wl-block-editor', '_wlBlockEditorSettings', array(
226
+			'root'  => esc_url_raw(rest_url()),
227
+			'nonce' => wp_create_nonce('wp_rest')
228
+		));
229 229
 
230 230
 		wp_enqueue_style(
231 231
 			'wl-block-editor',
232
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor.css',
232
+			plugin_dir_url(dirname(__FILE__)).'js/dist/block-editor.css',
233 233
 			array(),
234 234
 			$this->plugin->get_version()
235 235
 		);
236 236
 
237 237
 		wp_enqueue_script(
238 238
 			'wl-autocomplete-select',
239
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/autocomplete-select.js',
239
+			plugin_dir_url(dirname(__FILE__)).'js/dist/autocomplete-select.js',
240 240
 			array(),
241 241
 			$this->plugin->get_version(),
242 242
 			true
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 
245 245
 		wp_enqueue_style(
246 246
 			'wl-autocomplete-select',
247
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/autocomplete-select.css',
247
+			plugin_dir_url(dirname(__FILE__)).'js/dist/autocomplete-select.css',
248 248
 			array(),
249 249
 			$this->plugin->get_version()
250 250
 		);
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -17,41 +17,41 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Admin_Schemaorg_Taxonomy_Metabox {
19 19
 
20
-	/**
21
-	 * Render the metabox.
22
-	 *
23
-	 * @since 3.20.0
24
-	 */
25
-	public static function render() {
20
+    /**
21
+     * Render the metabox.
22
+     *
23
+     * @since 3.20.0
24
+     */
25
+    public static function render() {
26 26
 
27
-		Wordlift_Admin_Schemaorg_Taxonomy_Metabox::post_categories_meta_box( get_post(), array(
28
-			'args' =>
29
-				array( 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ),
30
-		) );
27
+        Wordlift_Admin_Schemaorg_Taxonomy_Metabox::post_categories_meta_box( get_post(), array(
28
+            'args' =>
29
+                array( 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ),
30
+        ) );
31 31
 
32
-	}
32
+    }
33 33
 
34
-	/**
35
-	 * A function which resembles WordPress' own to display a metabox, but which customizes the output
36
-	 * to display the Schema.org classes tree.
37
-	 *
38
-	 * @param WP_Post $post The {@link WP_Post} being edited.
39
-	 * @param array $box An array of arguments.
40
-	 *
41
-	 * @since 3.20.0
42
-	 *
43
-	 */
44
-	private static function post_categories_meta_box( $post, $box ) {
45
-		$defaults = array( 'taxonomy' => 'category' );
46
-		if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {
47
-			$args = array();
48
-		} else {
49
-			$args = $box['args'];
50
-		}
51
-		$r        = wp_parse_args( $args, $defaults );
52
-		$tax_name = esc_attr( $r['taxonomy'] );
53
-		$taxonomy = get_taxonomy( $r['taxonomy'] );
54
-		?>
34
+    /**
35
+     * A function which resembles WordPress' own to display a metabox, but which customizes the output
36
+     * to display the Schema.org classes tree.
37
+     *
38
+     * @param WP_Post $post The {@link WP_Post} being edited.
39
+     * @param array $box An array of arguments.
40
+     *
41
+     * @since 3.20.0
42
+     *
43
+     */
44
+    private static function post_categories_meta_box( $post, $box ) {
45
+        $defaults = array( 'taxonomy' => 'category' );
46
+        if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {
47
+            $args = array();
48
+        } else {
49
+            $args = $box['args'];
50
+        }
51
+        $r        = wp_parse_args( $args, $defaults );
52
+        $tax_name = esc_attr( $r['taxonomy'] );
53
+        $taxonomy = get_taxonomy( $r['taxonomy'] );
54
+        ?>
55 55
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
56 56
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
57 57
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a>
@@ -74,15 +74,15 @@  discard block
 block discarded – undo
74 74
 
75 75
             <div id="<?php echo $tax_name; ?>-legacy" class="tabs-panel" style="display: none;">
76 76
 				<?php
77
-				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
78
-				echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
79
-				?>
77
+                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
78
+                echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
79
+                ?>
80 80
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>"
81 81
                     class="categorychecklist form-no-clear">
82 82
 					<?php wp_terms_checklist( $post->ID, array(
83
-						'taxonomy'     => $tax_name,
84
-						'popular_cats' => $popular_ids,
85
-					) ); ?>
83
+                        'taxonomy'     => $tax_name,
84
+                        'popular_cats' => $popular_ids,
85
+                    ) ); ?>
86 86
                 </ul>
87 87
             </div>
88 88
 			<?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
                     <a id="<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add"
91 91
                        class="taxonomy-add-new">
92 92
 						<?php
93
-						/* translators: %s: add new taxonomy label */
94
-						printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
95
-						?>
93
+                        /* translators: %s: add new taxonomy label */
94
+                        printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
95
+                        ?>
96 96
                     </a>
97 97
                     <p id="<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
98 98
                         <label class="screen-reader-text"
@@ -105,43 +105,43 @@  discard block
 block discarded – undo
105 105
 							<?php echo $taxonomy->labels->parent_item_colon; ?>
106 106
                         </label>
107 107
 						<?php
108
-						$parent_dropdown_args = array(
109
-							'taxonomy'         => $tax_name,
110
-							'hide_empty'       => 0,
111
-							'name'             => 'new' . $tax_name . '_parent',
112
-							'orderby'          => 'name',
113
-							'hierarchical'     => 1,
114
-							'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
115
-						);
108
+                        $parent_dropdown_args = array(
109
+                            'taxonomy'         => $tax_name,
110
+                            'hide_empty'       => 0,
111
+                            'name'             => 'new' . $tax_name . '_parent',
112
+                            'orderby'          => 'name',
113
+                            'hierarchical'     => 1,
114
+                            'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
115
+                        );
116 116
 
117
-						/**
118
-						 * Filters the arguments for the taxonomy parent dropdown on the Post Edit page.
119
-						 *
120
-						 * @param array $parent_dropdown_args {
121
-						 *     Optional. Array of arguments to generate parent dropdown.
122
-						 *
123
-						 * @type string $taxonomy Name of the taxonomy to retrieve.
124
-						 * @type bool $hide_if_empty True to skip generating markup if no
125
-						 *                                      categories are found. Default 0.
126
-						 * @type string $name Value for the 'name' attribute
127
-						 *                                      of the select element.
128
-						 *                                      Default "new{$tax_name}_parent".
129
-						 * @type string $orderby Which column to use for ordering
130
-						 *                                      terms. Default 'name'.
131
-						 * @type bool|int $hierarchical Whether to traverse the taxonomy
132
-						 *                                      hierarchy. Default 1.
133
-						 * @type string $show_option_none Text to display for the "none" option.
134
-						 *                                      Default "&mdash; {$parent} &mdash;",
135
-						 *                                      where `$parent` is 'parent_item'
136
-						 *                                      taxonomy label.
137
-						 * }
138
-						 * @since 4.4.0
139
-						 *
140
-						 */
141
-						$parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args );
117
+                        /**
118
+                         * Filters the arguments for the taxonomy parent dropdown on the Post Edit page.
119
+                         *
120
+                         * @param array $parent_dropdown_args {
121
+                         *     Optional. Array of arguments to generate parent dropdown.
122
+                         *
123
+                         * @type string $taxonomy Name of the taxonomy to retrieve.
124
+                         * @type bool $hide_if_empty True to skip generating markup if no
125
+                         *                                      categories are found. Default 0.
126
+                         * @type string $name Value for the 'name' attribute
127
+                         *                                      of the select element.
128
+                         *                                      Default "new{$tax_name}_parent".
129
+                         * @type string $orderby Which column to use for ordering
130
+                         *                                      terms. Default 'name'.
131
+                         * @type bool|int $hierarchical Whether to traverse the taxonomy
132
+                         *                                      hierarchy. Default 1.
133
+                         * @type string $show_option_none Text to display for the "none" option.
134
+                         *                                      Default "&mdash; {$parent} &mdash;",
135
+                         *                                      where `$parent` is 'parent_item'
136
+                         *                                      taxonomy label.
137
+                         * }
138
+                         * @since 4.4.0
139
+                         *
140
+                         */
141
+                        $parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args );
142 142
 
143
-						wp_dropdown_categories( $parent_dropdown_args );
144
-						?>
143
+                        wp_dropdown_categories( $parent_dropdown_args );
144
+                        ?>
145 145
                         <input type="button" id="<?php echo $tax_name; ?>-add-submit"
146 146
                                data-wp-lists="add:<?php echo $tax_name; ?>checklist:<?php echo $tax_name; ?>-add"
147 147
                                class="button category-add-submit"
@@ -153,6 +153,6 @@  discard block
 block discarded – undo
153 153
 			<?php endif; ?>
154 154
         </div>
155 155
 		<?php
156
-	}
156
+    }
157 157
 
158 158
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
 	 */
25 25
 	public static function render() {
26 26
 
27
-		Wordlift_Admin_Schemaorg_Taxonomy_Metabox::post_categories_meta_box( get_post(), array(
27
+		Wordlift_Admin_Schemaorg_Taxonomy_Metabox::post_categories_meta_box(get_post(), array(
28 28
 			'args' =>
29
-				array( 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ),
30
-		) );
29
+				array('taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME),
30
+		));
31 31
 
32 32
 	}
33 33
 
@@ -41,24 +41,24 @@  discard block
 block discarded – undo
41 41
 	 * @since 3.20.0
42 42
 	 *
43 43
 	 */
44
-	private static function post_categories_meta_box( $post, $box ) {
45
-		$defaults = array( 'taxonomy' => 'category' );
46
-		if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {
44
+	private static function post_categories_meta_box($post, $box) {
45
+		$defaults = array('taxonomy' => 'category');
46
+		if ( ! isset($box['args']) || ! is_array($box['args'])) {
47 47
 			$args = array();
48 48
 		} else {
49 49
 			$args = $box['args'];
50 50
 		}
51
-		$r        = wp_parse_args( $args, $defaults );
52
-		$tax_name = esc_attr( $r['taxonomy'] );
53
-		$taxonomy = get_taxonomy( $r['taxonomy'] );
51
+		$r        = wp_parse_args($args, $defaults);
52
+		$tax_name = esc_attr($r['taxonomy']);
53
+		$taxonomy = get_taxonomy($r['taxonomy']);
54 54
 		?>
55 55
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
56 56
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
57 57
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a>
58 58
                 </li>
59
-                <li><a href="#<?php echo $tax_name; ?>-pop"><?php echo esc_html__( 'Most Used' ); ?></a></li>
59
+                <li><a href="#<?php echo $tax_name; ?>-pop"><?php echo esc_html__('Most Used'); ?></a></li>
60 60
                 <li><a href="#<?php echo $tax_name; ?>-legacy">
61
-						<?php echo esc_html_x( 'A-Z', 'Entity Types metabox', 'wordlift' ); ?></a>
61
+						<?php echo esc_html_x('A-Z', 'Entity Types metabox', 'wordlift'); ?></a>
62 62
                 </li>
63 63
             </ul>
64 64
 
@@ -68,30 +68,30 @@  discard block
 block discarded – undo
68 68
 
69 69
             <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;">
70 70
                 <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear">
71
-					<?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
71
+					<?php $popular_ids = wp_popular_terms_checklist($tax_name); ?>
72 72
                 </ul>
73 73
             </div>
74 74
 
75 75
             <div id="<?php echo $tax_name; ?>-legacy" class="tabs-panel" style="display: none;">
76 76
 				<?php
77
-				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
77
+				$name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']';
78 78
 				echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
79 79
 				?>
80 80
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>"
81 81
                     class="categorychecklist form-no-clear">
82
-					<?php wp_terms_checklist( $post->ID, array(
82
+					<?php wp_terms_checklist($post->ID, array(
83 83
 						'taxonomy'     => $tax_name,
84 84
 						'popular_cats' => $popular_ids,
85
-					) ); ?>
85
+					)); ?>
86 86
                 </ul>
87 87
             </div>
88
-			<?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
88
+			<?php if (current_user_can($taxonomy->cap->edit_terms)) : ?>
89 89
                 <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">
90 90
                     <a id="<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add"
91 91
                        class="taxonomy-add-new">
92 92
 						<?php
93 93
 						/* translators: %s: add new taxonomy label */
94
-						printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
94
+						printf(__('+ %s'), $taxonomy->labels->add_new_item);
95 95
 						?>
96 96
                     </a>
97 97
                     <p id="<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
                                for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
100 100
                         <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>"
101 101
                                class="form-required form-input-tip"
102
-                               value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>"
102
+                               value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>"
103 103
                                aria-required="true"/>
104 104
                         <label class="screen-reader-text" for="new<?php echo $tax_name; ?>_parent">
105 105
 							<?php echo $taxonomy->labels->parent_item_colon; ?>
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
 						$parent_dropdown_args = array(
109 109
 							'taxonomy'         => $tax_name,
110 110
 							'hide_empty'       => 0,
111
-							'name'             => 'new' . $tax_name . '_parent',
111
+							'name'             => 'new'.$tax_name.'_parent',
112 112
 							'orderby'          => 'name',
113 113
 							'hierarchical'     => 1,
114
-							'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
114
+							'show_option_none' => '&mdash; '.$taxonomy->labels->parent_item.' &mdash;',
115 115
 						);
116 116
 
117 117
 						/**
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 						 * @since 4.4.0
139 139
 						 *
140 140
 						 */
141
-						$parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args );
141
+						$parent_dropdown_args = apply_filters('post_edit_category_parent_dropdown_args', $parent_dropdown_args);
142 142
 
143
-						wp_dropdown_categories( $parent_dropdown_args );
143
+						wp_dropdown_categories($parent_dropdown_args);
144 144
 						?>
145 145
                         <input type="button" id="<?php echo $tax_name; ?>-add-submit"
146 146
                                data-wp-lists="add:<?php echo $tax_name; ?>checklist:<?php echo $tax_name; ?>-add"
147 147
                                class="button category-add-submit"
148
-                               value="<?php echo esc_attr( $taxonomy->labels->add_new_item ); ?>"/>
149
-						<?php wp_nonce_field( 'add-' . $tax_name, '_ajax_nonce-add-' . $tax_name, false ); ?>
148
+                               value="<?php echo esc_attr($taxonomy->labels->add_new_item); ?>"/>
149
+						<?php wp_nonce_field('add-'.$tax_name, '_ajax_nonce-add-'.$tax_name, false); ?>
150 150
                         <span id="<?php echo $tax_name; ?>-ajax-response"></span>
151 151
                     </p>
152 152
                 </div>
Please login to merge, or discard this patch.
src/wordlift/analysis/response/class-analysis-response-ops.php 2 patches
Indentation   +314 added lines, -314 removed lines patch added patch discarded remove patch
@@ -7,319 +7,319 @@
 block discarded – undo
7 7
 
8 8
 class Analysis_Response_Ops {
9 9
 
10
-	/**
11
-	 * The analysis response json.
12
-	 *
13
-	 * @since 3.21.5
14
-	 * @access private
15
-	 * @var mixed $json Holds the analysis response json.
16
-	 */
17
-	private $json;
18
-
19
-	/**
20
-	 * Holds the {@link Wordlift_Entity_Uri_Service}.
21
-	 *
22
-	 * @since 3.21.5
23
-	 * @access private
24
-	 * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance.
25
-	 */
26
-	private $entity_uri_service;
27
-
28
-	private $entity_service;
29
-
30
-	/**
31
-	 * @var \Wordlift_Entity_Type_Service
32
-	 */
33
-	private $entity_type_service;
34
-	/**
35
-	 * @var \Wordlift_Post_Image_Storage
36
-	 */
37
-	private $post_image_storage;
38
-
39
-	/**
40
-	 * Analysis_Response_Ops constructor.
41
-	 *
42
-	 * @param \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service}.
43
-	 * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service}.
44
-	 * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service}.
45
-	 * @param \Wordlift_Post_Image_Storage $post_image_storage A {@link Wordlift_Post_Image_Storage} instance.
46
-	 * @param mixed $json The analysis response json.
47
-	 *
48
-	 * @since 3.21.5
49
-	 */
50
-	public function __construct( $entity_uri_service, $entity_service, $entity_type_service, $post_image_storage, $json ) {
51
-
52
-		$this->json                = $json;
53
-		$this->entity_uri_service  = $entity_uri_service;
54
-		$this->entity_service      = $entity_service;
55
-		$this->entity_type_service = $entity_type_service;
56
-		$this->post_image_storage  = $post_image_storage;
57
-
58
-	}
59
-
60
-	/**
61
-	 * Switches remote entities, i.e. entities with id outside the local dataset, to local entities.
62
-	 *
63
-	 * The function takes all the entities that have an id which is not local. For each remote entity, a list of URIs
64
-	 * is built comprising the entity id and the sameAs. Then a query is issued in the local database to find potential
65
-	 * matches from the local vocabulary.
66
-	 *
67
-	 * If found, the entity id is swapped with the local id and the remote id is added to the sameAs.
68
-	 *
69
-	 * @return Analysis_Response_Ops The current Analysis_Response_Ops instance.
70
-	 */
71
-	public function make_entities_local() {
72
-
73
-		if ( ! isset( $this->json->entities ) ) {
74
-			return $this;
75
-		}
76
-
77
-		// Get the URIs.
78
-		$uris = array_keys( get_object_vars( $this->json->entities ) );
79
-
80
-		// Filter only the external URIs.
81
-		$entity_uri_service = $this->entity_uri_service;
82
-		$external_uris      = array_filter( $uris, function ( $item ) use ( $entity_uri_service ) {
83
-			return ! $entity_uri_service->is_internal( $item );
84
-		} );
85
-
86
-		// Preload the URIs.
87
-		$entity_uri_service->preload_uris( $external_uris );
88
-
89
-		$mappings = array();
90
-		foreach ( $external_uris as $external_uri ) {
91
-			$entity = $entity_uri_service->get_entity( $external_uri );
92
-			if ( null !== $entity ) {
93
-
94
-				// Get the internal URI.
95
-				$internal_uri              = $this->entity_service->get_uri( $entity->ID );
96
-				$mappings[ $external_uri ] = $internal_uri;
97
-			}
98
-		}
99
-
100
-		foreach ( $mappings as $external_uri => $internal_uri ) {
101
-
102
-			// Move the data from the external URI to the internal URI.
103
-			if ( ! isset( $this->json->entities->{$internal_uri} ) ) {
104
-				$this->json->entities->{$internal_uri} = $this->json->entities->{$external_uri};
105
-			}
106
-
107
-			// Ensure sameAs is an array.
108
-			if ( ! isset( $this->json->entities->{$internal_uri}->sameAs )
109
-			     || ! is_array( $this->json->entities->{$internal_uri}->sameAs ) ) {
110
-				$this->json->entities->{$internal_uri}->sameAs = array();
111
-			}
112
-
113
-			// Add the external URI as sameAs.
114
-			$this->json->entities->{$internal_uri}->sameAs[] = $external_uri;
115
-
116
-			// Finally remove the external URI.
117
-			unset( $this->json->entities->{$external_uri} );
118
-		}
119
-
120
-		if ( isset( $this->json->annotations ) ) {
121
-			foreach ( $this->json->annotations as $key => $annotation ) {
122
-				if ( isset( $annotation->entityMatches ) ) {
123
-					foreach ( $annotation->entityMatches as $match ) {
124
-						if ( isset( $match->entityId ) && isset( $mappings[ $match->entityId ] ) ) {
125
-							$match->entityId = $mappings[ $match->entityId ];
126
-						}
127
-					}
128
-				}
129
-			}
130
-		}
131
-
132
-		return $this;
133
-	}
134
-
135
-	/**
136
-	 * Add occurrences by parsing the provided html content.
137
-	 *
138
-	 * @param string $content The html content with annotations.
139
-	 *
140
-	 * @return Analysis_Response_Ops The {@link Analysis_Response_Ops} instance.
141
-	 *
142
-	 * @since 3.23.7 refactor the regex pattern to take into account that there might be css classes between textannotation
143
-	 *  and disambiguated.
144
-	 *
145
-	 * @link https://github.com/insideout10/wordlift-plugin/issues/1001
146
-	 */
147
-	public function add_occurrences( $content ) {
148
-
149
-		// Try to get all the disambiguated annotations and bail out if an error occurs.
150
-		if ( false === preg_match_all(
151
-				'|<span\s+id="([^"]+)"\s+class="textannotation\s+(?:\S+\s+)?disambiguated(?=[\s"])[^"]*"\s+itemid="([^"]*)">(.*?)</span>|',
152
-				$content,
153
-				$matches,
154
-				PREG_OFFSET_CAPTURE
155
-			) ) {
156
-			return $this;
157
-		}
158
-
159
-		if ( empty( $matches ) ) {
160
-			return $this;
161
-		}
162
-
163
-		$parse_data = array_reduce( range( 0, count( $matches[1] ) - 1 ), function ( $carry, $i ) use ( $matches ) {
164
-			if ( empty( $matches[0] ) ) {
165
-				return $carry;
166
-			}
167
-
168
-			$start         = $matches[0][ $i ][1];
169
-			$end           = $start + strlen( $matches[0][ $i ][0] );
170
-			$annotation_id = $matches[1][ $i ][0];
171
-			$item_id       = $matches[2][ $i ][0];
172
-			$text          = $matches[3][ $i ][0];
173
-
174
-			$annotation               = new StdClass;
175
-			$annotation->annotationId = $annotation_id;
176
-			$annotation->start        = $start;
177
-			$annotation->end          = $end;
178
-			$annotation->text         = $text;
179
-
180
-			$entity_match                = new StdClass;
181
-			$entity_match->confidence    = 100;
182
-			$entity_match->entityId      = $item_id;
183
-			$annotation->entityMatches[] = $entity_match;
184
-
185
-			$carry['annotations'][ $annotation_id ] = $annotation;
186
-			$carry['occurrences'][ $item_id ][]     = $annotation_id;
187
-
188
-			return $carry;
189
-		}, array( 'annotations' => array(), 'occurrences' => array(), ) );
190
-
191
-		$annotations = $parse_data['annotations'];
192
-		$occurrences = $parse_data['occurrences'];
193
-
194
-		foreach ( array_keys( $occurrences ) as $item_id ) {
195
-
196
-			// If the entity isn't there, add it.
197
-			if ( ! isset( $this->json->entities->{$item_id} ) ) {
198
-				$entity = $this->get_local_entity( $item_id );
199
-
200
-				// Entity not found in the local vocabulary, continue to the next one.
201
-				if ( false === $entity ) {
202
-					continue;
203
-				}
204
-
205
-				$this->json->entities->{$item_id} = $entity;
206
-			}
207
-		}
208
-
209
-		// Here we're adding back some data structures required by the client-side code.
210
-		//
211
-		// We're adding:
212
-		//  1. the .entities[entity_id].occurrences array with the annotations' ids.
213
-		//  2. the .entities[entity_id].annotations[annotation_id] = { id: annotation_id } map.
214
-		//
215
-		// Before 3.23.0 this was done by the client-side code located in src/coffee/editpost-widget/app.services.AnalysisService.coffee
216
-		// function `preselect`, which was called by src/coffee/editpost-widget/app.services.EditorService.coffee in
217
-		// `embedAnalysis`.
218
-		foreach ( $this->json->entities as $id => $entity ) {
219
-			$this->json->entities->{$id}->occurrences = isset( $occurrences[ $id ] ) ? $occurrences[ $id ] : array();;
220
-
221
-			foreach ( $this->json->entities->{$id}->occurrences as $annotation_id ) {
222
-				$this->json->entities->{$id}->annotations[ $annotation_id ] = array(
223
-					'id' => $annotation_id,
224
-				);
225
-			}
226
-		}
227
-
228
-		// Add the missing annotations. This allows the analysis response to work also if we didn't receive results
229
-		// from the analysis API.
230
-		foreach ( $annotations as $annotation_id => $annotation ) {
231
-
232
-			if ( ! isset( $this->json->annotations->{$annotation_id} ) ) {
233
-				$this->json->annotations->{$annotation_id} = $annotation;
234
-			}
235
-
236
-		}
237
-
238
-		return $this;
239
-	}
240
-
241
-	private function get_local_entity( $uri ) {
242
-
243
-		$entity = $this->entity_uri_service->get_entity( $uri );
244
-
245
-		if ( null === $entity ) {
246
-			return false;
247
-		}
248
-
249
-		$type   = $this->entity_type_service->get( $entity->ID );
250
-		$images = $this->post_image_storage->get( $entity->ID );
251
-
252
-		return (object) array(
253
-			'id'          => $uri,
254
-			'label'       => $entity->post_title,
255
-			'description' => $entity->post_content,
256
-			'sameAs'      => wl_schema_get_value( $entity->ID, 'sameAs' ),
257
-			'mainType'    => str_replace( 'wl-', '', $type['css_class'] ),
258
-			'types'       => wl_get_entity_rdf_types( $entity->ID ),
259
-			'images'      => $images,
260
-		);
261
-	}
262
-
263
-	/**
264
-	 * Return the JSON response.
265
-	 *
266
-	 * @return mixed The JSON response.
267
-	 * @since 3.24.2
268
-	 */
269
-	public function get_json() {
270
-
271
-		return $this->json;
272
-	}
273
-
274
-	/**
275
-	 * Get the string representation of the JSON.
276
-	 *
277
-	 * @return false|string The string representation or false in case of error.
278
-	 */
279
-	public function to_string() {
280
-
281
-		// Add the `JSON_UNESCAPED_UNICODE` only for PHP 5.4+.
282
-		$options = ( version_compare( PHP_VERSION, '5.4', '>=' )
283
-			? 256 : 0 );
284
-
285
-		return wp_json_encode( $this->json, $options );
286
-	}
287
-
288
-	/**
289
-	 * Create an Analysis_Response_Ops instance given the provided JSON structure.
290
-	 *
291
-	 * @param mixed $json The JSON structure.
292
-	 *
293
-	 * @return Analysis_Response_Ops A new Analysis_Response_Ops instance.
294
-	 */
295
-	public static function create( $json ) {
296
-
297
-		return new static(
298
-			\Wordlift_Entity_Uri_Service::get_instance(),
299
-			\Wordlift_Entity_Service::get_instance(),
300
-			\Wordlift_Entity_Type_Service::get_instance(),
301
-			\Wordlift_Storage_Factory::get_instance()->post_images(),
302
-			$json );
303
-	}
304
-
305
-	/**
306
-	 * Create an Analysis_Response_Ops instance given the provided http response.
307
-	 *
308
-	 * @param array $response {
309
-	 *
310
-	 * @type string $body The response body.
311
-	 * }
312
-	 *
313
-	 * @return Analysis_Response_Ops A new Analysis_Response_Ops instance.
314
-	 * @throws \Exception if the provided response doesn't contain a `body` element.
315
-	 */
316
-	public static function create_with_response( $response ) {
317
-
318
-		if ( ! isset( $response['body'] ) ) {
319
-			throw new \Exception( "`body` is required in response." );
320
-		}
321
-
322
-		return static::create( json_decode( $response['body'] ) );
323
-	}
10
+    /**
11
+     * The analysis response json.
12
+     *
13
+     * @since 3.21.5
14
+     * @access private
15
+     * @var mixed $json Holds the analysis response json.
16
+     */
17
+    private $json;
18
+
19
+    /**
20
+     * Holds the {@link Wordlift_Entity_Uri_Service}.
21
+     *
22
+     * @since 3.21.5
23
+     * @access private
24
+     * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance.
25
+     */
26
+    private $entity_uri_service;
27
+
28
+    private $entity_service;
29
+
30
+    /**
31
+     * @var \Wordlift_Entity_Type_Service
32
+     */
33
+    private $entity_type_service;
34
+    /**
35
+     * @var \Wordlift_Post_Image_Storage
36
+     */
37
+    private $post_image_storage;
38
+
39
+    /**
40
+     * Analysis_Response_Ops constructor.
41
+     *
42
+     * @param \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service}.
43
+     * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service}.
44
+     * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service}.
45
+     * @param \Wordlift_Post_Image_Storage $post_image_storage A {@link Wordlift_Post_Image_Storage} instance.
46
+     * @param mixed $json The analysis response json.
47
+     *
48
+     * @since 3.21.5
49
+     */
50
+    public function __construct( $entity_uri_service, $entity_service, $entity_type_service, $post_image_storage, $json ) {
51
+
52
+        $this->json                = $json;
53
+        $this->entity_uri_service  = $entity_uri_service;
54
+        $this->entity_service      = $entity_service;
55
+        $this->entity_type_service = $entity_type_service;
56
+        $this->post_image_storage  = $post_image_storage;
57
+
58
+    }
59
+
60
+    /**
61
+     * Switches remote entities, i.e. entities with id outside the local dataset, to local entities.
62
+     *
63
+     * The function takes all the entities that have an id which is not local. For each remote entity, a list of URIs
64
+     * is built comprising the entity id and the sameAs. Then a query is issued in the local database to find potential
65
+     * matches from the local vocabulary.
66
+     *
67
+     * If found, the entity id is swapped with the local id and the remote id is added to the sameAs.
68
+     *
69
+     * @return Analysis_Response_Ops The current Analysis_Response_Ops instance.
70
+     */
71
+    public function make_entities_local() {
72
+
73
+        if ( ! isset( $this->json->entities ) ) {
74
+            return $this;
75
+        }
76
+
77
+        // Get the URIs.
78
+        $uris = array_keys( get_object_vars( $this->json->entities ) );
79
+
80
+        // Filter only the external URIs.
81
+        $entity_uri_service = $this->entity_uri_service;
82
+        $external_uris      = array_filter( $uris, function ( $item ) use ( $entity_uri_service ) {
83
+            return ! $entity_uri_service->is_internal( $item );
84
+        } );
85
+
86
+        // Preload the URIs.
87
+        $entity_uri_service->preload_uris( $external_uris );
88
+
89
+        $mappings = array();
90
+        foreach ( $external_uris as $external_uri ) {
91
+            $entity = $entity_uri_service->get_entity( $external_uri );
92
+            if ( null !== $entity ) {
93
+
94
+                // Get the internal URI.
95
+                $internal_uri              = $this->entity_service->get_uri( $entity->ID );
96
+                $mappings[ $external_uri ] = $internal_uri;
97
+            }
98
+        }
99
+
100
+        foreach ( $mappings as $external_uri => $internal_uri ) {
101
+
102
+            // Move the data from the external URI to the internal URI.
103
+            if ( ! isset( $this->json->entities->{$internal_uri} ) ) {
104
+                $this->json->entities->{$internal_uri} = $this->json->entities->{$external_uri};
105
+            }
106
+
107
+            // Ensure sameAs is an array.
108
+            if ( ! isset( $this->json->entities->{$internal_uri}->sameAs )
109
+                 || ! is_array( $this->json->entities->{$internal_uri}->sameAs ) ) {
110
+                $this->json->entities->{$internal_uri}->sameAs = array();
111
+            }
112
+
113
+            // Add the external URI as sameAs.
114
+            $this->json->entities->{$internal_uri}->sameAs[] = $external_uri;
115
+
116
+            // Finally remove the external URI.
117
+            unset( $this->json->entities->{$external_uri} );
118
+        }
119
+
120
+        if ( isset( $this->json->annotations ) ) {
121
+            foreach ( $this->json->annotations as $key => $annotation ) {
122
+                if ( isset( $annotation->entityMatches ) ) {
123
+                    foreach ( $annotation->entityMatches as $match ) {
124
+                        if ( isset( $match->entityId ) && isset( $mappings[ $match->entityId ] ) ) {
125
+                            $match->entityId = $mappings[ $match->entityId ];
126
+                        }
127
+                    }
128
+                }
129
+            }
130
+        }
131
+
132
+        return $this;
133
+    }
134
+
135
+    /**
136
+     * Add occurrences by parsing the provided html content.
137
+     *
138
+     * @param string $content The html content with annotations.
139
+     *
140
+     * @return Analysis_Response_Ops The {@link Analysis_Response_Ops} instance.
141
+     *
142
+     * @since 3.23.7 refactor the regex pattern to take into account that there might be css classes between textannotation
143
+     *  and disambiguated.
144
+     *
145
+     * @link https://github.com/insideout10/wordlift-plugin/issues/1001
146
+     */
147
+    public function add_occurrences( $content ) {
148
+
149
+        // Try to get all the disambiguated annotations and bail out if an error occurs.
150
+        if ( false === preg_match_all(
151
+                '|<span\s+id="([^"]+)"\s+class="textannotation\s+(?:\S+\s+)?disambiguated(?=[\s"])[^"]*"\s+itemid="([^"]*)">(.*?)</span>|',
152
+                $content,
153
+                $matches,
154
+                PREG_OFFSET_CAPTURE
155
+            ) ) {
156
+            return $this;
157
+        }
158
+
159
+        if ( empty( $matches ) ) {
160
+            return $this;
161
+        }
162
+
163
+        $parse_data = array_reduce( range( 0, count( $matches[1] ) - 1 ), function ( $carry, $i ) use ( $matches ) {
164
+            if ( empty( $matches[0] ) ) {
165
+                return $carry;
166
+            }
167
+
168
+            $start         = $matches[0][ $i ][1];
169
+            $end           = $start + strlen( $matches[0][ $i ][0] );
170
+            $annotation_id = $matches[1][ $i ][0];
171
+            $item_id       = $matches[2][ $i ][0];
172
+            $text          = $matches[3][ $i ][0];
173
+
174
+            $annotation               = new StdClass;
175
+            $annotation->annotationId = $annotation_id;
176
+            $annotation->start        = $start;
177
+            $annotation->end          = $end;
178
+            $annotation->text         = $text;
179
+
180
+            $entity_match                = new StdClass;
181
+            $entity_match->confidence    = 100;
182
+            $entity_match->entityId      = $item_id;
183
+            $annotation->entityMatches[] = $entity_match;
184
+
185
+            $carry['annotations'][ $annotation_id ] = $annotation;
186
+            $carry['occurrences'][ $item_id ][]     = $annotation_id;
187
+
188
+            return $carry;
189
+        }, array( 'annotations' => array(), 'occurrences' => array(), ) );
190
+
191
+        $annotations = $parse_data['annotations'];
192
+        $occurrences = $parse_data['occurrences'];
193
+
194
+        foreach ( array_keys( $occurrences ) as $item_id ) {
195
+
196
+            // If the entity isn't there, add it.
197
+            if ( ! isset( $this->json->entities->{$item_id} ) ) {
198
+                $entity = $this->get_local_entity( $item_id );
199
+
200
+                // Entity not found in the local vocabulary, continue to the next one.
201
+                if ( false === $entity ) {
202
+                    continue;
203
+                }
204
+
205
+                $this->json->entities->{$item_id} = $entity;
206
+            }
207
+        }
208
+
209
+        // Here we're adding back some data structures required by the client-side code.
210
+        //
211
+        // We're adding:
212
+        //  1. the .entities[entity_id].occurrences array with the annotations' ids.
213
+        //  2. the .entities[entity_id].annotations[annotation_id] = { id: annotation_id } map.
214
+        //
215
+        // Before 3.23.0 this was done by the client-side code located in src/coffee/editpost-widget/app.services.AnalysisService.coffee
216
+        // function `preselect`, which was called by src/coffee/editpost-widget/app.services.EditorService.coffee in
217
+        // `embedAnalysis`.
218
+        foreach ( $this->json->entities as $id => $entity ) {
219
+            $this->json->entities->{$id}->occurrences = isset( $occurrences[ $id ] ) ? $occurrences[ $id ] : array();;
220
+
221
+            foreach ( $this->json->entities->{$id}->occurrences as $annotation_id ) {
222
+                $this->json->entities->{$id}->annotations[ $annotation_id ] = array(
223
+                    'id' => $annotation_id,
224
+                );
225
+            }
226
+        }
227
+
228
+        // Add the missing annotations. This allows the analysis response to work also if we didn't receive results
229
+        // from the analysis API.
230
+        foreach ( $annotations as $annotation_id => $annotation ) {
231
+
232
+            if ( ! isset( $this->json->annotations->{$annotation_id} ) ) {
233
+                $this->json->annotations->{$annotation_id} = $annotation;
234
+            }
235
+
236
+        }
237
+
238
+        return $this;
239
+    }
240
+
241
+    private function get_local_entity( $uri ) {
242
+
243
+        $entity = $this->entity_uri_service->get_entity( $uri );
244
+
245
+        if ( null === $entity ) {
246
+            return false;
247
+        }
248
+
249
+        $type   = $this->entity_type_service->get( $entity->ID );
250
+        $images = $this->post_image_storage->get( $entity->ID );
251
+
252
+        return (object) array(
253
+            'id'          => $uri,
254
+            'label'       => $entity->post_title,
255
+            'description' => $entity->post_content,
256
+            'sameAs'      => wl_schema_get_value( $entity->ID, 'sameAs' ),
257
+            'mainType'    => str_replace( 'wl-', '', $type['css_class'] ),
258
+            'types'       => wl_get_entity_rdf_types( $entity->ID ),
259
+            'images'      => $images,
260
+        );
261
+    }
262
+
263
+    /**
264
+     * Return the JSON response.
265
+     *
266
+     * @return mixed The JSON response.
267
+     * @since 3.24.2
268
+     */
269
+    public function get_json() {
270
+
271
+        return $this->json;
272
+    }
273
+
274
+    /**
275
+     * Get the string representation of the JSON.
276
+     *
277
+     * @return false|string The string representation or false in case of error.
278
+     */
279
+    public function to_string() {
280
+
281
+        // Add the `JSON_UNESCAPED_UNICODE` only for PHP 5.4+.
282
+        $options = ( version_compare( PHP_VERSION, '5.4', '>=' )
283
+            ? 256 : 0 );
284
+
285
+        return wp_json_encode( $this->json, $options );
286
+    }
287
+
288
+    /**
289
+     * Create an Analysis_Response_Ops instance given the provided JSON structure.
290
+     *
291
+     * @param mixed $json The JSON structure.
292
+     *
293
+     * @return Analysis_Response_Ops A new Analysis_Response_Ops instance.
294
+     */
295
+    public static function create( $json ) {
296
+
297
+        return new static(
298
+            \Wordlift_Entity_Uri_Service::get_instance(),
299
+            \Wordlift_Entity_Service::get_instance(),
300
+            \Wordlift_Entity_Type_Service::get_instance(),
301
+            \Wordlift_Storage_Factory::get_instance()->post_images(),
302
+            $json );
303
+    }
304
+
305
+    /**
306
+     * Create an Analysis_Response_Ops instance given the provided http response.
307
+     *
308
+     * @param array $response {
309
+     *
310
+     * @type string $body The response body.
311
+     * }
312
+     *
313
+     * @return Analysis_Response_Ops A new Analysis_Response_Ops instance.
314
+     * @throws \Exception if the provided response doesn't contain a `body` element.
315
+     */
316
+    public static function create_with_response( $response ) {
317
+
318
+        if ( ! isset( $response['body'] ) ) {
319
+            throw new \Exception( "`body` is required in response." );
320
+        }
321
+
322
+        return static::create( json_decode( $response['body'] ) );
323
+    }
324 324
 
325 325
 }
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 *
48 48
 	 * @since 3.21.5
49 49
 	 */
50
-	public function __construct( $entity_uri_service, $entity_service, $entity_type_service, $post_image_storage, $json ) {
50
+	public function __construct($entity_uri_service, $entity_service, $entity_type_service, $post_image_storage, $json) {
51 51
 
52 52
 		$this->json                = $json;
53 53
 		$this->entity_uri_service  = $entity_uri_service;
@@ -70,43 +70,43 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	public function make_entities_local() {
72 72
 
73
-		if ( ! isset( $this->json->entities ) ) {
73
+		if ( ! isset($this->json->entities)) {
74 74
 			return $this;
75 75
 		}
76 76
 
77 77
 		// Get the URIs.
78
-		$uris = array_keys( get_object_vars( $this->json->entities ) );
78
+		$uris = array_keys(get_object_vars($this->json->entities));
79 79
 
80 80
 		// Filter only the external URIs.
81 81
 		$entity_uri_service = $this->entity_uri_service;
82
-		$external_uris      = array_filter( $uris, function ( $item ) use ( $entity_uri_service ) {
83
-			return ! $entity_uri_service->is_internal( $item );
82
+		$external_uris      = array_filter($uris, function($item) use ($entity_uri_service) {
83
+			return ! $entity_uri_service->is_internal($item);
84 84
 		} );
85 85
 
86 86
 		// Preload the URIs.
87
-		$entity_uri_service->preload_uris( $external_uris );
87
+		$entity_uri_service->preload_uris($external_uris);
88 88
 
89 89
 		$mappings = array();
90
-		foreach ( $external_uris as $external_uri ) {
91
-			$entity = $entity_uri_service->get_entity( $external_uri );
92
-			if ( null !== $entity ) {
90
+		foreach ($external_uris as $external_uri) {
91
+			$entity = $entity_uri_service->get_entity($external_uri);
92
+			if (null !== $entity) {
93 93
 
94 94
 				// Get the internal URI.
95
-				$internal_uri              = $this->entity_service->get_uri( $entity->ID );
96
-				$mappings[ $external_uri ] = $internal_uri;
95
+				$internal_uri              = $this->entity_service->get_uri($entity->ID);
96
+				$mappings[$external_uri] = $internal_uri;
97 97
 			}
98 98
 		}
99 99
 
100
-		foreach ( $mappings as $external_uri => $internal_uri ) {
100
+		foreach ($mappings as $external_uri => $internal_uri) {
101 101
 
102 102
 			// Move the data from the external URI to the internal URI.
103
-			if ( ! isset( $this->json->entities->{$internal_uri} ) ) {
103
+			if ( ! isset($this->json->entities->{$internal_uri} )) {
104 104
 				$this->json->entities->{$internal_uri} = $this->json->entities->{$external_uri};
105 105
 			}
106 106
 
107 107
 			// Ensure sameAs is an array.
108
-			if ( ! isset( $this->json->entities->{$internal_uri}->sameAs )
109
-			     || ! is_array( $this->json->entities->{$internal_uri}->sameAs ) ) {
108
+			if ( ! isset($this->json->entities->{$internal_uri}->sameAs)
109
+			     || ! is_array($this->json->entities->{$internal_uri}->sameAs)) {
110 110
 				$this->json->entities->{$internal_uri}->sameAs = array();
111 111
 			}
112 112
 
@@ -114,15 +114,15 @@  discard block
 block discarded – undo
114 114
 			$this->json->entities->{$internal_uri}->sameAs[] = $external_uri;
115 115
 
116 116
 			// Finally remove the external URI.
117
-			unset( $this->json->entities->{$external_uri} );
117
+			unset($this->json->entities->{$external_uri} );
118 118
 		}
119 119
 
120
-		if ( isset( $this->json->annotations ) ) {
121
-			foreach ( $this->json->annotations as $key => $annotation ) {
122
-				if ( isset( $annotation->entityMatches ) ) {
123
-					foreach ( $annotation->entityMatches as $match ) {
124
-						if ( isset( $match->entityId ) && isset( $mappings[ $match->entityId ] ) ) {
125
-							$match->entityId = $mappings[ $match->entityId ];
120
+		if (isset($this->json->annotations)) {
121
+			foreach ($this->json->annotations as $key => $annotation) {
122
+				if (isset($annotation->entityMatches)) {
123
+					foreach ($annotation->entityMatches as $match) {
124
+						if (isset($match->entityId) && isset($mappings[$match->entityId])) {
125
+							$match->entityId = $mappings[$match->entityId];
126 126
 						}
127 127
 					}
128 128
 				}
@@ -144,32 +144,32 @@  discard block
 block discarded – undo
144 144
 	 *
145 145
 	 * @link https://github.com/insideout10/wordlift-plugin/issues/1001
146 146
 	 */
147
-	public function add_occurrences( $content ) {
147
+	public function add_occurrences($content) {
148 148
 
149 149
 		// Try to get all the disambiguated annotations and bail out if an error occurs.
150
-		if ( false === preg_match_all(
150
+		if (false === preg_match_all(
151 151
 				'|<span\s+id="([^"]+)"\s+class="textannotation\s+(?:\S+\s+)?disambiguated(?=[\s"])[^"]*"\s+itemid="([^"]*)">(.*?)</span>|',
152 152
 				$content,
153 153
 				$matches,
154 154
 				PREG_OFFSET_CAPTURE
155
-			) ) {
155
+			)) {
156 156
 			return $this;
157 157
 		}
158 158
 
159
-		if ( empty( $matches ) ) {
159
+		if (empty($matches)) {
160 160
 			return $this;
161 161
 		}
162 162
 
163
-		$parse_data = array_reduce( range( 0, count( $matches[1] ) - 1 ), function ( $carry, $i ) use ( $matches ) {
164
-			if ( empty( $matches[0] ) ) {
163
+		$parse_data = array_reduce(range(0, count($matches[1]) - 1), function($carry, $i) use ($matches) {
164
+			if (empty($matches[0])) {
165 165
 				return $carry;
166 166
 			}
167 167
 
168
-			$start         = $matches[0][ $i ][1];
169
-			$end           = $start + strlen( $matches[0][ $i ][0] );
170
-			$annotation_id = $matches[1][ $i ][0];
171
-			$item_id       = $matches[2][ $i ][0];
172
-			$text          = $matches[3][ $i ][0];
168
+			$start         = $matches[0][$i][1];
169
+			$end           = $start + strlen($matches[0][$i][0]);
170
+			$annotation_id = $matches[1][$i][0];
171
+			$item_id       = $matches[2][$i][0];
172
+			$text          = $matches[3][$i][0];
173 173
 
174 174
 			$annotation               = new StdClass;
175 175
 			$annotation->annotationId = $annotation_id;
@@ -182,23 +182,23 @@  discard block
 block discarded – undo
182 182
 			$entity_match->entityId      = $item_id;
183 183
 			$annotation->entityMatches[] = $entity_match;
184 184
 
185
-			$carry['annotations'][ $annotation_id ] = $annotation;
186
-			$carry['occurrences'][ $item_id ][]     = $annotation_id;
185
+			$carry['annotations'][$annotation_id] = $annotation;
186
+			$carry['occurrences'][$item_id][]     = $annotation_id;
187 187
 
188 188
 			return $carry;
189
-		}, array( 'annotations' => array(), 'occurrences' => array(), ) );
189
+		}, array('annotations' => array(), 'occurrences' => array(),));
190 190
 
191 191
 		$annotations = $parse_data['annotations'];
192 192
 		$occurrences = $parse_data['occurrences'];
193 193
 
194
-		foreach ( array_keys( $occurrences ) as $item_id ) {
194
+		foreach (array_keys($occurrences) as $item_id) {
195 195
 
196 196
 			// If the entity isn't there, add it.
197
-			if ( ! isset( $this->json->entities->{$item_id} ) ) {
198
-				$entity = $this->get_local_entity( $item_id );
197
+			if ( ! isset($this->json->entities->{$item_id} )) {
198
+				$entity = $this->get_local_entity($item_id);
199 199
 
200 200
 				// Entity not found in the local vocabulary, continue to the next one.
201
-				if ( false === $entity ) {
201
+				if (false === $entity) {
202 202
 					continue;
203 203
 				}
204 204
 
@@ -215,11 +215,11 @@  discard block
 block discarded – undo
215 215
 		// Before 3.23.0 this was done by the client-side code located in src/coffee/editpost-widget/app.services.AnalysisService.coffee
216 216
 		// function `preselect`, which was called by src/coffee/editpost-widget/app.services.EditorService.coffee in
217 217
 		// `embedAnalysis`.
218
-		foreach ( $this->json->entities as $id => $entity ) {
219
-			$this->json->entities->{$id}->occurrences = isset( $occurrences[ $id ] ) ? $occurrences[ $id ] : array();;
218
+		foreach ($this->json->entities as $id => $entity) {
219
+			$this->json->entities->{$id}->occurrences = isset($occurrences[$id]) ? $occurrences[$id] : array(); ;
220 220
 
221
-			foreach ( $this->json->entities->{$id}->occurrences as $annotation_id ) {
222
-				$this->json->entities->{$id}->annotations[ $annotation_id ] = array(
221
+			foreach ($this->json->entities->{$id}->occurrences as $annotation_id) {
222
+				$this->json->entities->{$id}->annotations[$annotation_id] = array(
223 223
 					'id' => $annotation_id,
224 224
 				);
225 225
 			}
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
 
228 228
 		// Add the missing annotations. This allows the analysis response to work also if we didn't receive results
229 229
 		// from the analysis API.
230
-		foreach ( $annotations as $annotation_id => $annotation ) {
230
+		foreach ($annotations as $annotation_id => $annotation) {
231 231
 
232
-			if ( ! isset( $this->json->annotations->{$annotation_id} ) ) {
232
+			if ( ! isset($this->json->annotations->{$annotation_id} )) {
233 233
 				$this->json->annotations->{$annotation_id} = $annotation;
234 234
 			}
235 235
 
@@ -238,24 +238,24 @@  discard block
 block discarded – undo
238 238
 		return $this;
239 239
 	}
240 240
 
241
-	private function get_local_entity( $uri ) {
241
+	private function get_local_entity($uri) {
242 242
 
243
-		$entity = $this->entity_uri_service->get_entity( $uri );
243
+		$entity = $this->entity_uri_service->get_entity($uri);
244 244
 
245
-		if ( null === $entity ) {
245
+		if (null === $entity) {
246 246
 			return false;
247 247
 		}
248 248
 
249
-		$type   = $this->entity_type_service->get( $entity->ID );
250
-		$images = $this->post_image_storage->get( $entity->ID );
249
+		$type   = $this->entity_type_service->get($entity->ID);
250
+		$images = $this->post_image_storage->get($entity->ID);
251 251
 
252 252
 		return (object) array(
253 253
 			'id'          => $uri,
254 254
 			'label'       => $entity->post_title,
255 255
 			'description' => $entity->post_content,
256
-			'sameAs'      => wl_schema_get_value( $entity->ID, 'sameAs' ),
257
-			'mainType'    => str_replace( 'wl-', '', $type['css_class'] ),
258
-			'types'       => wl_get_entity_rdf_types( $entity->ID ),
256
+			'sameAs'      => wl_schema_get_value($entity->ID, 'sameAs'),
257
+			'mainType'    => str_replace('wl-', '', $type['css_class']),
258
+			'types'       => wl_get_entity_rdf_types($entity->ID),
259 259
 			'images'      => $images,
260 260
 		);
261 261
 	}
@@ -279,10 +279,10 @@  discard block
 block discarded – undo
279 279
 	public function to_string() {
280 280
 
281 281
 		// Add the `JSON_UNESCAPED_UNICODE` only for PHP 5.4+.
282
-		$options = ( version_compare( PHP_VERSION, '5.4', '>=' )
283
-			? 256 : 0 );
282
+		$options = (version_compare(PHP_VERSION, '5.4', '>=')
283
+			? 256 : 0);
284 284
 
285
-		return wp_json_encode( $this->json, $options );
285
+		return wp_json_encode($this->json, $options);
286 286
 	}
287 287
 
288 288
 	/**
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 *
293 293
 	 * @return Analysis_Response_Ops A new Analysis_Response_Ops instance.
294 294
 	 */
295
-	public static function create( $json ) {
295
+	public static function create($json) {
296 296
 
297 297
 		return new static(
298 298
 			\Wordlift_Entity_Uri_Service::get_instance(),
@@ -313,13 +313,13 @@  discard block
 block discarded – undo
313 313
 	 * @return Analysis_Response_Ops A new Analysis_Response_Ops instance.
314 314
 	 * @throws \Exception if the provided response doesn't contain a `body` element.
315 315
 	 */
316
-	public static function create_with_response( $response ) {
316
+	public static function create_with_response($response) {
317 317
 
318
-		if ( ! isset( $response['body'] ) ) {
319
-			throw new \Exception( "`body` is required in response." );
318
+		if ( ! isset($response['body'])) {
319
+			throw new \Exception("`body` is required in response.");
320 320
 		}
321 321
 
322
-		return static::create( json_decode( $response['body'] ) );
322
+		return static::create(json_decode($response['body']));
323 323
 	}
324 324
 
325 325
 }
Please login to merge, or discard this patch.
src/wordlift/autocomplete/class-abstract-autocomplete-service.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -4,17 +4,17 @@
 block discarded – undo
4 4
 
5 5
 abstract class Abstract_Autocomplete_Service implements Autocomplete_Service {
6 6
 
7
-	protected function filter( $results, $excludes ) {
7
+    protected function filter( $results, $excludes ) {
8 8
 
9
-		$excludes_array = (array) $excludes;
9
+        $excludes_array = (array) $excludes;
10 10
 
11
-		return array_filter( $results, function ( $item ) use ( $excludes_array ) {
11
+        return array_filter( $results, function ( $item ) use ( $excludes_array ) {
12 12
 
13
-			return 0 === count( array_intersect(
14
-					array_merge( (array) $item['id'], $item['sameAss'] ),
15
-					$excludes_array
16
-				) );
17
-		} );
18
-	}
13
+            return 0 === count( array_intersect(
14
+                    array_merge( (array) $item['id'], $item['sameAss'] ),
15
+                    $excludes_array
16
+                ) );
17
+        } );
18
+    }
19 19
 
20 20
 }
21 21
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -4,16 +4,16 @@
 block discarded – undo
4 4
 
5 5
 abstract class Abstract_Autocomplete_Service implements Autocomplete_Service {
6 6
 
7
-	protected function filter( $results, $excludes ) {
7
+	protected function filter($results, $excludes) {
8 8
 
9 9
 		$excludes_array = (array) $excludes;
10 10
 
11
-		return array_filter( $results, function ( $item ) use ( $excludes_array ) {
11
+		return array_filter($results, function($item) use ($excludes_array) {
12 12
 
13
-			return 0 === count( array_intersect(
14
-					array_merge( (array) $item['id'], $item['sameAss'] ),
13
+			return 0 === count(array_intersect(
14
+					array_merge((array) $item['id'], $item['sameAss']),
15 15
 					$excludes_array
16
-				) );
16
+				));
17 17
 		} );
18 18
 	}
19 19
 
Please login to merge, or discard this patch.
src/wordlift/autocomplete/class-autocomplete-service.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,15 +11,15 @@
 block discarded – undo
11 11
 
12 12
 interface Autocomplete_Service {
13 13
 
14
-	/**
15
-	 * Query the service for the specified data.
16
-	 *
17
-	 * @param string $query The query.
18
-	 * @param string $scope The scope.
19
-	 * @param string|string[] $excludes URLs to exclude.
20
-	 *
21
-	 * @return array An array of results.
22
-	 */
23
-	public function query( $query, $scope, $excludes );
14
+    /**
15
+     * Query the service for the specified data.
16
+     *
17
+     * @param string $query The query.
18
+     * @param string $scope The scope.
19
+     * @param string|string[] $excludes URLs to exclude.
20
+     *
21
+     * @return array An array of results.
22
+     */
23
+    public function query( $query, $scope, $excludes );
24 24
 
25 25
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,6 +20,6 @@
 block discarded – undo
20 20
 	 *
21 21
 	 * @return array An array of results.
22 22
 	 */
23
-	public function query( $query, $scope, $excludes );
23
+	public function query($query, $scope, $excludes);
24 24
 
25 25
 }
Please login to merge, or discard this patch.
src/wordlift/autocomplete/class-local-autocomplete-service.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -14,42 +14,42 @@
 block discarded – undo
14 14
 
15 15
 class Local_Autocomplete_Service extends Abstract_Autocomplete_Service {
16 16
 
17
-	/**
18
-	 * @inheritDoc
19
-	 */
20
-	public function query( $query, $scope, $excludes ) {
21
-
22
-		$args = Wordlift_Entity_Service::add_criterias( array(
23
-			'numberposts'         => 50,
24
-			'post_status'         => 'any',
25
-			's'                   => $query,
26
-			'ignore_sticky_posts' => true,
27
-			'suppress_filters'    => true,
28
-		) );
29
-
30
-		$posts = get_posts( $args );
31
-
32
-		$results = array_map( function ( $item ) {
33
-
34
-			$entity_service = Wordlift_Entity_Service::get_instance();
35
-			$uri            = $entity_service->get_uri( $item->ID );
36
-
37
-			return array(
38
-				'id'           => $uri,
39
-				'label'        => array( $item->post_title ),
40
-				'labels'       => $entity_service->get_alternative_labels( $item->ID ),
41
-				'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ),
42
-				'scope'        => 'local',
43
-				'sameAss'      => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ),
44
-				// The following properties are less relevant because we're linking entities that exist already in the
45
-				// vocabulary. That's why we don't make an effort to load the real data.
46
-				'types'        => array( 'http://schema.org/Thing' ),
47
-				'urls'         => array(),
48
-				'images'       => array(),
49
-			);
50
-		}, $posts );
51
-
52
-		return $this->filter( $results, $excludes );
53
-	}
17
+    /**
18
+     * @inheritDoc
19
+     */
20
+    public function query( $query, $scope, $excludes ) {
21
+
22
+        $args = Wordlift_Entity_Service::add_criterias( array(
23
+            'numberposts'         => 50,
24
+            'post_status'         => 'any',
25
+            's'                   => $query,
26
+            'ignore_sticky_posts' => true,
27
+            'suppress_filters'    => true,
28
+        ) );
29
+
30
+        $posts = get_posts( $args );
31
+
32
+        $results = array_map( function ( $item ) {
33
+
34
+            $entity_service = Wordlift_Entity_Service::get_instance();
35
+            $uri            = $entity_service->get_uri( $item->ID );
36
+
37
+            return array(
38
+                'id'           => $uri,
39
+                'label'        => array( $item->post_title ),
40
+                'labels'       => $entity_service->get_alternative_labels( $item->ID ),
41
+                'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ),
42
+                'scope'        => 'local',
43
+                'sameAss'      => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ),
44
+                // The following properties are less relevant because we're linking entities that exist already in the
45
+                // vocabulary. That's why we don't make an effort to load the real data.
46
+                'types'        => array( 'http://schema.org/Thing' ),
47
+                'urls'         => array(),
48
+                'images'       => array(),
49
+            );
50
+        }, $posts );
51
+
52
+        return $this->filter( $results, $excludes );
53
+    }
54 54
 
55 55
 }
56 56
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -17,39 +17,39 @@
 block discarded – undo
17 17
 	/**
18 18
 	 * @inheritDoc
19 19
 	 */
20
-	public function query( $query, $scope, $excludes ) {
20
+	public function query($query, $scope, $excludes) {
21 21
 
22
-		$args = Wordlift_Entity_Service::add_criterias( array(
22
+		$args = Wordlift_Entity_Service::add_criterias(array(
23 23
 			'numberposts'         => 50,
24 24
 			'post_status'         => 'any',
25 25
 			's'                   => $query,
26 26
 			'ignore_sticky_posts' => true,
27 27
 			'suppress_filters'    => true,
28
-		) );
28
+		));
29 29
 
30
-		$posts = get_posts( $args );
30
+		$posts = get_posts($args);
31 31
 
32
-		$results = array_map( function ( $item ) {
32
+		$results = array_map(function($item) {
33 33
 
34 34
 			$entity_service = Wordlift_Entity_Service::get_instance();
35
-			$uri            = $entity_service->get_uri( $item->ID );
35
+			$uri            = $entity_service->get_uri($item->ID);
36 36
 
37 37
 			return array(
38 38
 				'id'           => $uri,
39
-				'label'        => array( $item->post_title ),
40
-				'labels'       => $entity_service->get_alternative_labels( $item->ID ),
41
-				'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ),
39
+				'label'        => array($item->post_title),
40
+				'labels'       => $entity_service->get_alternative_labels($item->ID),
41
+				'descriptions' => array(Wordlift_Post_Excerpt_Helper::get_text_excerpt($item)),
42 42
 				'scope'        => 'local',
43
-				'sameAss'      => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ),
43
+				'sameAss'      => get_post_meta($item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS),
44 44
 				// The following properties are less relevant because we're linking entities that exist already in the
45 45
 				// vocabulary. That's why we don't make an effort to load the real data.
46
-				'types'        => array( 'http://schema.org/Thing' ),
46
+				'types'        => array('http://schema.org/Thing'),
47 47
 				'urls'         => array(),
48 48
 				'images'       => array(),
49 49
 			);
50
-		}, $posts );
50
+		}, $posts);
51 51
 
52
-		return $this->filter( $results, $excludes );
52
+		return $this->filter($results, $excludes);
53 53
 	}
54 54
 
55 55
 }
56 56
\ No newline at end of file
Please login to merge, or discard this patch.
src/wordlift/autocomplete/class-linked-data-autocomplete-service.php 2 patches
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -13,112 +13,112 @@
 block discarded – undo
13 13
 
14 14
 class Linked_Data_Autocomplete_Service implements Autocomplete_Service {
15 15
 
16
-	/**
17
-	 * The {@link Wordlift_Configuration_Service} instance.
18
-	 *
19
-	 * @since  3.15.0
20
-	 * @access private
21
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
22
-	 */
23
-	private $configuration_service;
24
-
25
-	/**
26
-	 * A {@link Wordlift_Log_Service} instance.
27
-	 *
28
-	 * @since  3.15.0
29
-	 * @access private
30
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
31
-	 */
32
-	private $log;
33
-
34
-	/**
35
-	 * The {@link Class_Wordlift_Autocomplete_Service} instance.
36
-	 *
37
-	 * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
38
-	 *
39
-	 * @since 3.15.0
40
-	 *
41
-	 */
42
-	public function __construct( $configuration_service ) {
43
-		$this->configuration_service = $configuration_service;
44
-		$this->log                   = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' );
45
-	}
46
-
47
-	/**
48
-	 * Make request to external API and return the response.
49
-	 *
50
-	 * @param string $query The search string.
51
-	 * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also
52
-	 *                      in Wikipedia. By default is "cloud".
53
-	 * @param array|string $exclude The exclude parameter string.
54
-	 *
55
-	 * @return array $response The API response.
56
-	 * @since 3.15.0
57
-	 *
58
-	 */
59
-	public function query( $query, $scope = 'cloud', $exclude = '' ) {
60
-		$url = $this->build_request_url( $query, $exclude, $scope );
61
-
62
-		// Return the response.
63
-		$response = wp_remote_get( $url, array(
64
-			'timeout' => 30
65
-		) );
66
-
67
-		// If the response is valid, then send the suggestions.
68
-		if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
69
-			// Echo the response.
70
-			return json_decode( wp_remote_retrieve_body( $response ), true );
71
-		} else {
72
-			// Default error message.
73
-			$error_message = 'Something went wrong.';
74
-
75
-			// Get the real error message if there is WP_Error.
76
-			if ( is_wp_error( $response ) ) {
77
-				$error_message = $response->get_error_message();
78
-			}
79
-
80
-			$this->log->error( $error_message );
81
-
82
-			return array();
83
-		}
84
-	}
85
-
86
-	/**
87
-	 * Build the autocomplete url.
88
-	 *
89
-	 * @param string $query The search string.
90
-	 * @param array|string $exclude The exclude parameter.
91
-	 * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also
92
-	 *                      in Wikipedia. By default is "cloud".
93
-	 *
94
-	 * @return string Built url.
95
-	 * @since 3.15.0
96
-	 *
97
-	 */
98
-	private function build_request_url( $query, $exclude, $scope ) {
99
-		$args = array(
100
-			'key'      => $this->configuration_service->get_key(),
101
-			'language' => $this->configuration_service->get_language_code(),
102
-			'query'    => $query,
103
-			'scope'    => $scope,
104
-			'limit'    => 10,
105
-		);
106
-
107
-		// Add args to URL.
108
-		$request_url = add_query_arg(
109
-			urlencode_deep( $args ),
110
-			$this->configuration_service->get_autocomplete_url()
111
-		);
112
-
113
-		// Add the exclude parameter.
114
-		if ( ! empty( $exclude ) ) {
115
-			foreach ( (array) $exclude as $item ) {
116
-				$request_url .= "&exclude=" . urlencode( $item );
117
-			}
118
-		}
119
-
120
-		// return the built url.
121
-		return $request_url;
122
-	}
16
+    /**
17
+     * The {@link Wordlift_Configuration_Service} instance.
18
+     *
19
+     * @since  3.15.0
20
+     * @access private
21
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
22
+     */
23
+    private $configuration_service;
24
+
25
+    /**
26
+     * A {@link Wordlift_Log_Service} instance.
27
+     *
28
+     * @since  3.15.0
29
+     * @access private
30
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
31
+     */
32
+    private $log;
33
+
34
+    /**
35
+     * The {@link Class_Wordlift_Autocomplete_Service} instance.
36
+     *
37
+     * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
38
+     *
39
+     * @since 3.15.0
40
+     *
41
+     */
42
+    public function __construct( $configuration_service ) {
43
+        $this->configuration_service = $configuration_service;
44
+        $this->log                   = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' );
45
+    }
46
+
47
+    /**
48
+     * Make request to external API and return the response.
49
+     *
50
+     * @param string $query The search string.
51
+     * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also
52
+     *                      in Wikipedia. By default is "cloud".
53
+     * @param array|string $exclude The exclude parameter string.
54
+     *
55
+     * @return array $response The API response.
56
+     * @since 3.15.0
57
+     *
58
+     */
59
+    public function query( $query, $scope = 'cloud', $exclude = '' ) {
60
+        $url = $this->build_request_url( $query, $exclude, $scope );
61
+
62
+        // Return the response.
63
+        $response = wp_remote_get( $url, array(
64
+            'timeout' => 30
65
+        ) );
66
+
67
+        // If the response is valid, then send the suggestions.
68
+        if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
69
+            // Echo the response.
70
+            return json_decode( wp_remote_retrieve_body( $response ), true );
71
+        } else {
72
+            // Default error message.
73
+            $error_message = 'Something went wrong.';
74
+
75
+            // Get the real error message if there is WP_Error.
76
+            if ( is_wp_error( $response ) ) {
77
+                $error_message = $response->get_error_message();
78
+            }
79
+
80
+            $this->log->error( $error_message );
81
+
82
+            return array();
83
+        }
84
+    }
85
+
86
+    /**
87
+     * Build the autocomplete url.
88
+     *
89
+     * @param string $query The search string.
90
+     * @param array|string $exclude The exclude parameter.
91
+     * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also
92
+     *                      in Wikipedia. By default is "cloud".
93
+     *
94
+     * @return string Built url.
95
+     * @since 3.15.0
96
+     *
97
+     */
98
+    private function build_request_url( $query, $exclude, $scope ) {
99
+        $args = array(
100
+            'key'      => $this->configuration_service->get_key(),
101
+            'language' => $this->configuration_service->get_language_code(),
102
+            'query'    => $query,
103
+            'scope'    => $scope,
104
+            'limit'    => 10,
105
+        );
106
+
107
+        // Add args to URL.
108
+        $request_url = add_query_arg(
109
+            urlencode_deep( $args ),
110
+            $this->configuration_service->get_autocomplete_url()
111
+        );
112
+
113
+        // Add the exclude parameter.
114
+        if ( ! empty( $exclude ) ) {
115
+            foreach ( (array) $exclude as $item ) {
116
+                $request_url .= "&exclude=" . urlencode( $item );
117
+            }
118
+        }
119
+
120
+        // return the built url.
121
+        return $request_url;
122
+    }
123 123
 
124 124
 }
125 125
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
 	 * @since 3.15.0
40 40
 	 *
41 41
 	 */
42
-	public function __construct( $configuration_service ) {
42
+	public function __construct($configuration_service) {
43 43
 		$this->configuration_service = $configuration_service;
44
-		$this->log                   = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' );
44
+		$this->log                   = Wordlift_Log_Service::get_logger('Wordlift_Autocomplete_Service');
45 45
 	}
46 46
 
47 47
 	/**
@@ -56,28 +56,28 @@  discard block
 block discarded – undo
56 56
 	 * @since 3.15.0
57 57
 	 *
58 58
 	 */
59
-	public function query( $query, $scope = 'cloud', $exclude = '' ) {
60
-		$url = $this->build_request_url( $query, $exclude, $scope );
59
+	public function query($query, $scope = 'cloud', $exclude = '') {
60
+		$url = $this->build_request_url($query, $exclude, $scope);
61 61
 
62 62
 		// Return the response.
63
-		$response = wp_remote_get( $url, array(
63
+		$response = wp_remote_get($url, array(
64 64
 			'timeout' => 30
65
-		) );
65
+		));
66 66
 
67 67
 		// If the response is valid, then send the suggestions.
68
-		if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
68
+		if ( ! is_wp_error($response) && 200 === (int) $response['response']['code']) {
69 69
 			// Echo the response.
70
-			return json_decode( wp_remote_retrieve_body( $response ), true );
70
+			return json_decode(wp_remote_retrieve_body($response), true);
71 71
 		} else {
72 72
 			// Default error message.
73 73
 			$error_message = 'Something went wrong.';
74 74
 
75 75
 			// Get the real error message if there is WP_Error.
76
-			if ( is_wp_error( $response ) ) {
76
+			if (is_wp_error($response)) {
77 77
 				$error_message = $response->get_error_message();
78 78
 			}
79 79
 
80
-			$this->log->error( $error_message );
80
+			$this->log->error($error_message);
81 81
 
82 82
 			return array();
83 83
 		}
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 * @since 3.15.0
96 96
 	 *
97 97
 	 */
98
-	private function build_request_url( $query, $exclude, $scope ) {
98
+	private function build_request_url($query, $exclude, $scope) {
99 99
 		$args = array(
100 100
 			'key'      => $this->configuration_service->get_key(),
101 101
 			'language' => $this->configuration_service->get_language_code(),
@@ -106,14 +106,14 @@  discard block
 block discarded – undo
106 106
 
107 107
 		// Add args to URL.
108 108
 		$request_url = add_query_arg(
109
-			urlencode_deep( $args ),
109
+			urlencode_deep($args),
110 110
 			$this->configuration_service->get_autocomplete_url()
111 111
 		);
112 112
 
113 113
 		// Add the exclude parameter.
114
-		if ( ! empty( $exclude ) ) {
115
-			foreach ( (array) $exclude as $item ) {
116
-				$request_url .= "&exclude=" . urlencode( $item );
114
+		if ( ! empty($exclude)) {
115
+			foreach ((array) $exclude as $item) {
116
+				$request_url .= "&exclude=".urlencode($item);
117 117
 			}
118 118
 		}
119 119
 
Please login to merge, or discard this patch.
src/wordlift/autocomplete/class-all-autocomplete-service.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -5,34 +5,34 @@
 block discarded – undo
5 5
 class All_Autocomplete_Service implements Autocomplete_Service {
6 6
 
7 7
 
8
-	/**
9
-	 * @var Autocomplete_Service|Autocomplete_Service[] $autocomplete_services
10
-	 */
11
-	private $autocomplete_services;
8
+    /**
9
+     * @var Autocomplete_Service|Autocomplete_Service[] $autocomplete_services
10
+     */
11
+    private $autocomplete_services;
12 12
 
13
-	/**
14
-	 * All_Autocomplete_Service constructor.
15
-	 *
16
-	 * @param Autocomplete_Service|Autocomplete_Service[] $autocomplete_services
17
-	 */
18
-	public function __construct( $autocomplete_services ) {
13
+    /**
14
+     * All_Autocomplete_Service constructor.
15
+     *
16
+     * @param Autocomplete_Service|Autocomplete_Service[] $autocomplete_services
17
+     */
18
+    public function __construct( $autocomplete_services ) {
19 19
 
20
-		$this->autocomplete_services = (array) $autocomplete_services;
21
-	}
20
+        $this->autocomplete_services = (array) $autocomplete_services;
21
+    }
22 22
 
23
-	/**
24
-	 * {@inheritDoc}
25
-	 */
26
-	public function query( $query, $scope, $excludes ) {
23
+    /**
24
+     * {@inheritDoc}
25
+     */
26
+    public function query( $query, $scope, $excludes ) {
27 27
 
28
-		// Query each Autocomplete service and merge the results.
29
-		return array_reduce( $this->autocomplete_services, function ( $carry, $item ) use ( $query, $scope, $excludes ) {
28
+        // Query each Autocomplete service and merge the results.
29
+        return array_reduce( $this->autocomplete_services, function ( $carry, $item ) use ( $query, $scope, $excludes ) {
30 30
 
31
-			$results = $item->query( $query, $scope, $excludes );
31
+            $results = $item->query( $query, $scope, $excludes );
32 32
 
33
-			return array_merge( $carry, $results );
34
-		}, array() );
33
+            return array_merge( $carry, $results );
34
+        }, array() );
35 35
 
36
-	}
36
+    }
37 37
 
38 38
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 *
16 16
 	 * @param Autocomplete_Service|Autocomplete_Service[] $autocomplete_services
17 17
 	 */
18
-	public function __construct( $autocomplete_services ) {
18
+	public function __construct($autocomplete_services) {
19 19
 
20 20
 		$this->autocomplete_services = (array) $autocomplete_services;
21 21
 	}
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 	/**
24 24
 	 * {@inheritDoc}
25 25
 	 */
26
-	public function query( $query, $scope, $excludes ) {
26
+	public function query($query, $scope, $excludes) {
27 27
 
28 28
 		// Query each Autocomplete service and merge the results.
29
-		return array_reduce( $this->autocomplete_services, function ( $carry, $item ) use ( $query, $scope, $excludes ) {
29
+		return array_reduce($this->autocomplete_services, function($carry, $item) use ($query, $scope, $excludes) {
30 30
 
31
-			$results = $item->query( $query, $scope, $excludes );
31
+			$results = $item->query($query, $scope, $excludes);
32 32
 
33
-			return array_merge( $carry, $results );
34
-		}, array() );
33
+			return array_merge($carry, $results);
34
+		}, array());
35 35
 
36 36
 	}
37 37
 
Please login to merge, or discard this patch.