Completed
Pull Request — develop (#1701)
by David
01:16
created
src/modules/events/vendor/composer/autoload_classmap.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,8 +6,8 @@
 block discarded – undo
6 6
 $baseDir = dirname($vendorDir);
7 7
 
8 8
 return array(
9
-    'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
10
-    'Wordlift\\Modules\\Events\\Options_Entity\\Events_Options_Entity_Include_Exclude' => $baseDir . '/includes/Options_Entity/Events_Options_Entity_Include_Exclude.php',
11
-    'Wordlift\\Modules\\Events\\Post_Entity\\Events_Post_Entity_Jsonld' => $baseDir . '/includes/Post_Entity/Events_Post_Entity_Jsonld.php',
12
-    'Wordlift\\Modules\\Events\\Term_Entity\\Events_Term_Entity_Jsonld' => $baseDir . '/includes/Term_Entity/Events_Term_Entity_Jsonld.php',
9
+    'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php',
10
+    'Wordlift\\Modules\\Events\\Options_Entity\\Events_Options_Entity_Include_Exclude' => $baseDir.'/includes/Options_Entity/Events_Options_Entity_Include_Exclude.php',
11
+    'Wordlift\\Modules\\Events\\Post_Entity\\Events_Post_Entity_Jsonld' => $baseDir.'/includes/Post_Entity/Events_Post_Entity_Jsonld.php',
12
+    'Wordlift\\Modules\\Events\\Term_Entity\\Events_Term_Entity_Jsonld' => $baseDir.'/includes/Term_Entity/Events_Term_Entity_Jsonld.php',
13 13
 );
Please login to merge, or discard this patch.
src/modules/include-exclude-push-config/includes/Include_Exclude_API.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -6,29 +6,29 @@
 block discarded – undo
6 6
 
7 7
 class Include_Exclude_API {
8 8
 
9
-	/**
10
-	 * @var Api_Service
11
-	 */
12
-	private $api_service;
9
+    /**
10
+     * @var Api_Service
11
+     */
12
+    private $api_service;
13 13
 
14
-	/**
15
-	 * @param Api_Service $api_service
16
-	 */
17
-	public function __construct( Api_Service $api_service ) {
18
-		$this->api_service = $api_service;
19
-	}
14
+    /**
15
+     * @param Api_Service $api_service
16
+     */
17
+    public function __construct( Api_Service $api_service ) {
18
+        $this->api_service = $api_service;
19
+    }
20 20
 
21
-	/**
22
-	 * Update.
23
-	 *
24
-	 * @param $payload
25
-	 */
26
-	public function update( $payload ) {
27
-		$this->api_service->request(
28
-			'PUT',
29
-			'/accounts/me/include-excludes',
30
-			array( 'content-type' => 'application/json' ),
31
-			wp_json_encode( $payload )
32
-		);
33
-	}
21
+    /**
22
+     * Update.
23
+     *
24
+     * @param $payload
25
+     */
26
+    public function update( $payload ) {
27
+        $this->api_service->request(
28
+            'PUT',
29
+            '/accounts/me/include-excludes',
30
+            array( 'content-type' => 'application/json' ),
31
+            wp_json_encode( $payload )
32
+        );
33
+    }
34 34
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 	/**
15 15
 	 * @param Api_Service $api_service
16 16
 	 */
17
-	public function __construct( Api_Service $api_service ) {
17
+	public function __construct(Api_Service $api_service) {
18 18
 		$this->api_service = $api_service;
19 19
 	}
20 20
 
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param $payload
25 25
 	 */
26
-	public function update( $payload ) {
26
+	public function update($payload) {
27 27
 		$this->api_service->request(
28 28
 			'PUT',
29 29
 			'/accounts/me/include-excludes',
30
-			array( 'content-type' => 'application/json' ),
31
-			wp_json_encode( $payload )
30
+			array('content-type' => 'application/json'),
31
+			wp_json_encode($payload)
32 32
 		);
33 33
 	}
34 34
 }
Please login to merge, or discard this patch.
src/modules/include-exclude-push-config/load.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -6,60 +6,60 @@
 block discarded – undo
6 6
 use Wordlift\Modules\Include_Exclude_Push_Config\Include_Exclude_API;
7 7
 
8 8
 if ( ! defined( 'ABSPATH' ) ) {
9
-	exit;
9
+    exit;
10 10
 }
11 11
 
12 12
 // Bail out if the feature isn't enabled.
13 13
 if ( ! apply_filters( 'wl_feature__enable__include-exclude', false ) ) { // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 // Autoloader for dependencies.
18 18
 if ( file_exists( __DIR__ . '/third-party/vendor/scoper-autoload.php' ) ) {
19
-	require __DIR__ . '/third-party/vendor/scoper-autoload.php';
19
+    require __DIR__ . '/third-party/vendor/scoper-autoload.php';
20 20
 }
21 21
 
22 22
 // Autoloader for plugin itself.
23 23
 if ( file_exists( __DIR__ . '/includes/vendor/autoload.php' ) ) {
24
-	require __DIR__ . '/includes/vendor/autoload.php';
24
+    require __DIR__ . '/includes/vendor/autoload.php';
25 25
 }
26 26
 
27 27
 function __wl_include_exclude_push_config() {
28
-	// Get the configuration.
29
-	$config = get_option( 'wl_exclude_include_urls_settings', array() );
28
+    // Get the configuration.
29
+    $config = get_option( 'wl_exclude_include_urls_settings', array() );
30 30
 
31
-	// Set the default data.
32
-	if ( ! is_array( $config ) || empty( $config ) || ! isset( $config['include_exclude'] ) || ! isset( $config['urls'] ) ) {
33
-		$config = get_option(
34
-			'wl_exclude_include_urls_settings',
35
-			array(
36
-				'include_exclude' => 'exclude',
37
-				'urls'            => '',
38
-			)
39
-		);
40
-	}
31
+    // Set the default data.
32
+    if ( ! is_array( $config ) || empty( $config ) || ! isset( $config['include_exclude'] ) || ! isset( $config['urls'] ) ) {
33
+        $config = get_option(
34
+            'wl_exclude_include_urls_settings',
35
+            array(
36
+                'include_exclude' => 'exclude',
37
+                'urls'            => '',
38
+            )
39
+        );
40
+    }
41 41
 
42
-	// Map the configuration to the payload.
43
-	$payload = array_map(
44
-		function ( $item ) use ( $config ) {
45
-			return array(
46
-				'url'  =>
47
-					( 1 === preg_match( '@^https?://.*$@', $item ) ? $item : get_home_url( null, $item ) ),
48
-				'flag' => strtoupper( $config['include_exclude'] ),
49
-			);
50
-		},
51
-		array_filter( preg_split( '/[\r\n]+/', $config['urls'] ) )
52
-	);
42
+    // Map the configuration to the payload.
43
+    $payload = array_map(
44
+        function ( $item ) use ( $config ) {
45
+            return array(
46
+                'url'  =>
47
+                    ( 1 === preg_match( '@^https?://.*$@', $item ) ? $item : get_home_url( null, $item ) ),
48
+                'flag' => strtoupper( $config['include_exclude'] ),
49
+            );
50
+        },
51
+        array_filter( preg_split( '/[\r\n]+/', $config['urls'] ) )
52
+    );
53 53
 
54
-	// Load the service.
55
-	$container_builder = new ContainerBuilder();
56
-	$loader            = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) );
57
-	$loader->load( 'services.yml' );
58
-	$container_builder->compile();
54
+    // Load the service.
55
+    $container_builder = new ContainerBuilder();
56
+    $loader            = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) );
57
+    $loader->load( 'services.yml' );
58
+    $container_builder->compile();
59 59
 
60
-	/** @var Include_Exclude_API $api */
61
-	$api = $container_builder->get( 'Wordlift\Modules\Include_Exclude_Push_Config\Include_Exclude_API' );
62
-	$api->update( $payload );
60
+    /** @var Include_Exclude_API $api */
61
+    $api = $container_builder->get( 'Wordlift\Modules\Include_Exclude_Push_Config\Include_Exclude_API' );
62
+    $api->update( $payload );
63 63
 }
64 64
 
65 65
 /**
Please login to merge, or discard this patch.
src/wordlift.php 2 patches
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
  * @since 3.33.6
48 48
  */
49 49
 if ( ! apply_filters( 'wl_is_enabled', true ) ) {
50
-	return;
50
+    return;
51 51
 }
52 52
 
53 53
 require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
@@ -76,33 +76,33 @@  discard block
 block discarded – undo
76 76
  */
77 77
 function activate_wordlift() {
78 78
 
79
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
79
+    $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
80 80
 
81
-	$log->info( 'Activating WordLift...' );
81
+    $log->info( 'Activating WordLift...' );
82 82
 
83
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
84
-	Wordlift_Activator::activate();
83
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
84
+    Wordlift_Activator::activate();
85 85
 
86
-	/**
87
-	 * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
88
-	 *
89
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
90
-	 * @since 3.19.2
91
-	 */
92
-	Wordlift_Http_Api::activate();
86
+    /**
87
+     * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
88
+     *
89
+     * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
90
+     * @since 3.19.2
91
+     */
92
+    Wordlift_Http_Api::activate();
93 93
 
94
-	// Ensure the post type is registered before flushing the rewrite rules.
95
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
96
-	flush_rewrite_rules();
97
-	/**
98
-	 * @since 3.27.7
99
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
100
-	 */
101
-	Top_Entities::activate();
94
+    // Ensure the post type is registered before flushing the rewrite rules.
95
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
96
+    flush_rewrite_rules();
97
+    /**
98
+     * @since 3.27.7
99
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1214
100
+     */
101
+    Top_Entities::activate();
102 102
 
103
-	if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
104
-		wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
105
-	}
103
+    if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
104
+        wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
105
+    }
106 106
 
107 107
 }
108 108
 
@@ -112,23 +112,23 @@  discard block
 block discarded – undo
112 112
  */
113 113
 function deactivate_wordlift() {
114 114
 
115
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
116
-	Wordlift_Deactivator::deactivate();
117
-	Wordlift_Http_Api::deactivate();
118
-	Ttl_Cache_Cleaner::deactivate();
119
-	/**
120
-	 * @since 3.27.7
121
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
122
-	 */
123
-	Top_Entities::deactivate();
124
-	/**
125
-	 * @since 3.27.8
126
-	 * Remove notification flag on deactivation.
127
-	 */
128
-	Key_Validation_Notice::remove_notification_flag();
129
-	flush_rewrite_rules();
130
-
131
-	wp_clear_scheduled_hook( 'wl_daily_cron' );
115
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
116
+    Wordlift_Deactivator::deactivate();
117
+    Wordlift_Http_Api::deactivate();
118
+    Ttl_Cache_Cleaner::deactivate();
119
+    /**
120
+     * @since 3.27.7
121
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1214
122
+     */
123
+    Top_Entities::deactivate();
124
+    /**
125
+     * @since 3.27.8
126
+     * Remove notification flag on deactivation.
127
+     */
128
+    Key_Validation_Notice::remove_notification_flag();
129
+    flush_rewrite_rules();
130
+
131
+    wp_clear_scheduled_hook( 'wl_daily_cron' );
132 132
 
133 133
 }
134 134
 
@@ -151,84 +151,84 @@  discard block
 block discarded – undo
151 151
  * @since    1.0.0
152 152
  */
153 153
 function run_wordlift() {
154
-	/**
155
-	 * Filter: wl_feature__enable__widgets.
156
-	 *
157
-	 * @param bool whether the widgets needed to be registered, defaults to true.
158
-	 *
159
-	 * @return bool
160
-	 * @since 3.27.6
161
-	 */
162
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
163
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
164
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
165
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
166
-	}
167
-	add_filter( 'widget_text', 'do_shortcode' );
168
-
169
-	/**
170
-	 * Filter: wl_feature__enable__analysis
171
-	 *
172
-	 * @param bool Whether to send api request to analysis or not
173
-	 *
174
-	 * @return bool
175
-	 * @since 3.27.6
176
-	 */
177
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
178
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
179
-	} else {
180
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
181
-	}
182
-
183
-	$plugin = new Wordlift();
184
-	$plugin->run();
185
-
186
-	// Initialize the TTL Cache Cleaner.
187
-	new Ttl_Cache_Cleaner();
188
-
189
-	// Load the new Post Adapter.
190
-	new Post_Adapter();
191
-
192
-	// Load the API Data Hooks.
193
-	new Api_Data_Hooks();
194
-
195
-	add_action(
196
-		'plugins_loaded',
197
-		function () {
198
-			// All features from registry should be initialized here.
199
-			$features_registry = Features_Registry::get_instance();
200
-			$features_registry->initialize_all_features();
201
-		},
202
-		5
203
-	);
204
-
205
-	add_action(
206
-		'plugins_loaded',
207
-		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
208
-		function () use ( $plugin ) {
209
-
210
-			new Wordlift_Products_Navigator_Shortcode_REST();
211
-
212
-			// Register the Dataset module, requires `$api_service`.
213
-			require_once plugin_dir_path( __FILE__ ) . 'classes/dataset/index.php';
214
-			require_once plugin_dir_path( __FILE__ ) . 'classes/shipping-data/index.php';
215
-
216
-			/*
154
+    /**
155
+     * Filter: wl_feature__enable__widgets.
156
+     *
157
+     * @param bool whether the widgets needed to be registered, defaults to true.
158
+     *
159
+     * @return bool
160
+     * @since 3.27.6
161
+     */
162
+    if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
163
+        add_action( 'widgets_init', 'wl_register_chord_widget' );
164
+        add_action( 'widgets_init', 'wl_register_geo_widget' );
165
+        add_action( 'widgets_init', 'wl_register_timeline_widget' );
166
+    }
167
+    add_filter( 'widget_text', 'do_shortcode' );
168
+
169
+    /**
170
+     * Filter: wl_feature__enable__analysis
171
+     *
172
+     * @param bool Whether to send api request to analysis or not
173
+     *
174
+     * @return bool
175
+     * @since 3.27.6
176
+     */
177
+    if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
178
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
179
+    } else {
180
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
181
+    }
182
+
183
+    $plugin = new Wordlift();
184
+    $plugin->run();
185
+
186
+    // Initialize the TTL Cache Cleaner.
187
+    new Ttl_Cache_Cleaner();
188
+
189
+    // Load the new Post Adapter.
190
+    new Post_Adapter();
191
+
192
+    // Load the API Data Hooks.
193
+    new Api_Data_Hooks();
194
+
195
+    add_action(
196
+        'plugins_loaded',
197
+        function () {
198
+            // All features from registry should be initialized here.
199
+            $features_registry = Features_Registry::get_instance();
200
+            $features_registry->initialize_all_features();
201
+        },
202
+        5
203
+    );
204
+
205
+    add_action(
206
+        'plugins_loaded',
207
+        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
208
+        function () use ( $plugin ) {
209
+
210
+            new Wordlift_Products_Navigator_Shortcode_REST();
211
+
212
+            // Register the Dataset module, requires `$api_service`.
213
+            require_once plugin_dir_path( __FILE__ ) . 'classes/dataset/index.php';
214
+            require_once plugin_dir_path( __FILE__ ) . 'classes/shipping-data/index.php';
215
+
216
+            /*
217 217
 			* Require the Entity annotation cleanup module.
218 218
 			*
219 219
 			* @since 3.34.6
220 220
 			*/
221
-			require_once plugin_dir_path( __FILE__ ) . 'classes/cleanup/index.php';
221
+            require_once plugin_dir_path( __FILE__ ) . 'classes/cleanup/index.php';
222 222
 
223
-			/*
223
+            /*
224 224
 			* Import LOD entities.
225 225
 			*
226 226
 			* @since 3.35.0
227 227
 			*/
228
-			require_once plugin_dir_path( __FILE__ ) . 'classes/lod-import/index.php';
228
+            require_once plugin_dir_path( __FILE__ ) . 'classes/lod-import/index.php';
229 229
 
230
-		}
231
-	);
230
+        }
231
+    );
232 232
 
233 233
 }
234 234
 
@@ -242,50 +242,50 @@  discard block
 block discarded – undo
242 242
  */
243 243
 function wordlift_plugin_autoload_register() {
244 244
 
245
-	spl_autoload_register(
246
-		function ( $class_name ) {
245
+    spl_autoload_register(
246
+        function ( $class_name ) {
247 247
 
248
-			// Bail out if these are not our classes.
249
-			if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
250
-				return false;
251
-			}
248
+            // Bail out if these are not our classes.
249
+            if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
250
+                return false;
251
+            }
252 252
 
253
-			$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
253
+            $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
254 254
 
255
-			preg_match( '|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
255
+            preg_match( '|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
256 256
 
257
-			$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
258
-			$file = 'class-' . $matches[2] . '.php';
257
+            $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
258
+            $file = 'class-' . $matches[2] . '.php';
259 259
 
260
-			$full_path = plugin_dir_path( __FILE__ ) . 'classes' . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $file;
260
+            $full_path = plugin_dir_path( __FILE__ ) . 'classes' . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $file;
261 261
 
262
-			if ( ! file_exists( $full_path ) ) {
263
-				return false;
264
-			}
262
+            if ( ! file_exists( $full_path ) ) {
263
+                return false;
264
+            }
265 265
 
266
-			try {
267
-				require_once $full_path;
268
-			} catch ( Exception $e ) {
269
-				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
270
-				error_log( "[WordLift] $full_path not found, cannot include." );
271
-			}
266
+            try {
267
+                require_once $full_path;
268
+            } catch ( Exception $e ) {
269
+                // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
270
+                error_log( "[WordLift] $full_path not found, cannot include." );
271
+            }
272 272
 
273
-			return true;
274
-		}
275
-	);
273
+            return true;
274
+        }
275
+    );
276 276
 
277 277
 }
278 278
 
279 279
 function wl_block_categories( $categories ) {
280
-	return array_merge(
281
-		$categories,
282
-		array(
283
-			array(
284
-				'slug'  => 'wordlift',
285
-				'title' => __( 'WordLift', 'wordlift' ),
286
-			),
287
-		)
288
-	);
280
+    return array_merge(
281
+        $categories,
282
+        array(
283
+            array(
284
+                'slug'  => 'wordlift',
285
+                'title' => __( 'WordLift', 'wordlift' ),
286
+            ),
287
+        )
288
+    );
289 289
 }
290 290
 
291 291
 /**
@@ -293,19 +293,19 @@  discard block
 block discarded – undo
293 293
  * this has to be removed when removing the legacy fields from the ui.
294 294
  */
295 295
 function wl_enqueue_leaflet( $in_footer = false ) {
296
-	// Leaflet.
297
-	wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
298
-	wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
296
+    // Leaflet.
297
+    wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
298
+    wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
299 299
 }
300 300
 
301 301
 add_filter( 'block_categories', 'wl_block_categories', 10 );
302 302
 
303 303
 // Temporary fix for a typo in WooCommerce Extension.
304 304
 add_filter(
305
-	'wl_feature__enable__dataset',
306
-	function ( $value ) {
307
-		return apply_filters( 'wl_features__enable__dataset', $value );
308
-	}
305
+    'wl_feature__enable__dataset',
306
+    function ( $value ) {
307
+        return apply_filters( 'wl_features__enable__dataset', $value );
308
+    }
309 309
 );
310 310
 
311 311
 require_once __DIR__ . '/modules/food-kg/load.php';
@@ -320,35 +320,35 @@  discard block
 block discarded – undo
320 320
 require_once __DIR__ . '/modules/events/load.php';
321 321
 
322 322
 function _wl_update_plugins_raptive_domain( $update, $plugin_data, $plugin_file ) {
323
-	// Bail out if it's not our plugin.
324
-	$update_uri = $plugin_data['UpdateURI'];
325
-	if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) {
326
-		return $update;
327
-	}
328
-
329
-	$response = wp_remote_get( "$update_uri?nocache=" . time() );
330
-
331
-	if ( is_wp_error( $response ) ) {
332
-		return $update;
333
-	}
334
-
335
-	try {
336
-		return json_decode( wp_remote_retrieve_body( $response ) );
337
-	} catch ( Exception $e ) {
338
-		return $update;
339
-	}
323
+    // Bail out if it's not our plugin.
324
+    $update_uri = $plugin_data['UpdateURI'];
325
+    if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) {
326
+        return $update;
327
+    }
328
+
329
+    $response = wp_remote_get( "$update_uri?nocache=" . time() );
330
+
331
+    if ( is_wp_error( $response ) ) {
332
+        return $update;
333
+    }
334
+
335
+    try {
336
+        return json_decode( wp_remote_retrieve_body( $response ) );
337
+    } catch ( Exception $e ) {
338
+        return $update;
339
+    }
340 340
 }
341 341
 
342 342
 add_action(
343
-	'update_plugins_adthrive.wordlift.io',
344
-	'_wl_update_plugins_raptive_domain',
345
-	10,
346
-	3
343
+    'update_plugins_adthrive.wordlift.io',
344
+    '_wl_update_plugins_raptive_domain',
345
+    10,
346
+    3
347 347
 );
348 348
 
349 349
 add_action(
350
-	'update_plugins_raptive.wordlift.io',
351
-	'_wl_update_plugins_raptive_domain',
352
-	10,
353
-	3
350
+    'update_plugins_raptive.wordlift.io',
351
+    '_wl_update_plugins_raptive_domain',
352
+    10,
353
+    3
354 354
 );
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -31,26 +31,26 @@  discard block
 block discarded – undo
31 31
 use Wordlift\Features\Features_Registry;
32 32
 use Wordlift\Post\Post_Adapter;
33 33
 
34
-define( 'WORDLIFT_PLUGIN_FILE', __FILE__ );
35
-define( 'WORDLIFT_VERSION', '3.48.0-6' );
34
+define('WORDLIFT_PLUGIN_FILE', __FILE__);
35
+define('WORDLIFT_VERSION', '3.48.0-6');
36 36
 
37 37
 // ## DO NOT REMOVE THIS LINE: WHITELABEL PLACEHOLDER ##
38 38
 
39
-require_once plugin_dir_path( __FILE__ ) . '/libraries/action-scheduler/action-scheduler.php';
40
-require_once __DIR__ . '/modules/common/load.php';
41
-require_once __DIR__ . '/modules/app/load.php';
42
-require_once __DIR__ . '/modules/include-exclude/load.php';
39
+require_once plugin_dir_path(__FILE__).'/libraries/action-scheduler/action-scheduler.php';
40
+require_once __DIR__.'/modules/common/load.php';
41
+require_once __DIR__.'/modules/app/load.php';
42
+require_once __DIR__.'/modules/include-exclude/load.php';
43 43
 
44 44
 /**
45 45
  * Filter to disable WLP on any request, defaults to true.
46 46
  *
47 47
  * @since 3.33.6
48 48
  */
49
-if ( ! apply_filters( 'wl_is_enabled', true ) ) {
49
+if ( ! apply_filters('wl_is_enabled', true)) {
50 50
 	return;
51 51
 }
52 52
 
53
-require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
53
+require_once plugin_dir_path(__FILE__).'vendor/autoload.php';
54 54
 
55 55
 /*
56 56
  * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http.
@@ -60,15 +60,15 @@  discard block
 block discarded – undo
60 60
 wordlift_plugin_autoload_register();
61 61
 
62 62
 // Include WordLift constants.
63
-require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php';
63
+require_once plugin_dir_path(__FILE__).'wordlift-constants.php';
64 64
 
65 65
 // Load modules.
66
-require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php';
66
+require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php';
67 67
 
68
-require_once plugin_dir_path( __FILE__ ) . 'deprecations.php';
68
+require_once plugin_dir_path(__FILE__).'deprecations.php';
69 69
 
70 70
 // Load early to enable/disable features.
71
-require_once plugin_dir_path( __FILE__ ) . 'classes/features/index.php';
71
+require_once plugin_dir_path(__FILE__).'classes/features/index.php';
72 72
 
73 73
 /**
74 74
  * The code that runs during plugin activation.
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
  */
77 77
 function activate_wordlift() {
78 78
 
79
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
79
+	$log = Wordlift_Log_Service::get_logger('activate_wordlift');
80 80
 
81
-	$log->info( 'Activating WordLift...' );
81
+	$log->info('Activating WordLift...');
82 82
 
83
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
83
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
84 84
 	Wordlift_Activator::activate();
85 85
 
86 86
 	/**
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
 	 */
101 101
 	Top_Entities::activate();
102 102
 
103
-	if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
104
-		wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
103
+	if ( ! wp_next_scheduled('wl_daily_cron')) {
104
+		wp_schedule_event(time(), 'daily', 'wl_daily_cron');
105 105
 	}
106 106
 
107 107
 }
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
  */
113 113
 function deactivate_wordlift() {
114 114
 
115
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
115
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
116 116
 	Wordlift_Deactivator::deactivate();
117 117
 	Wordlift_Http_Api::deactivate();
118 118
 	Ttl_Cache_Cleaner::deactivate();
@@ -128,18 +128,18 @@  discard block
 block discarded – undo
128 128
 	Key_Validation_Notice::remove_notification_flag();
129 129
 	flush_rewrite_rules();
130 130
 
131
-	wp_clear_scheduled_hook( 'wl_daily_cron' );
131
+	wp_clear_scheduled_hook('wl_daily_cron');
132 132
 
133 133
 }
134 134
 
135
-register_activation_hook( __FILE__, 'activate_wordlift' );
136
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
135
+register_activation_hook(__FILE__, 'activate_wordlift');
136
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
137 137
 
138 138
 /**
139 139
  * The core plugin class that is used to define internationalization,
140 140
  * admin-specific hooks, and public-facing site hooks.
141 141
  */
142
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
142
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
143 143
 
144 144
 /**
145 145
  * Begins execution of the plugin.
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
 	 * @return bool
160 160
 	 * @since 3.27.6
161 161
 	 */
162
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
163
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
164
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
165
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
162
+	if (apply_filters('wl_feature__enable__widgets', true)) {
163
+		add_action('widgets_init', 'wl_register_chord_widget');
164
+		add_action('widgets_init', 'wl_register_geo_widget');
165
+		add_action('widgets_init', 'wl_register_timeline_widget');
166 166
 	}
167
-	add_filter( 'widget_text', 'do_shortcode' );
167
+	add_filter('widget_text', 'do_shortcode');
168 168
 
169 169
 	/**
170 170
 	 * Filter: wl_feature__enable__analysis
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 	 * @return bool
175 175
 	 * @since 3.27.6
176 176
 	 */
177
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
178
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
177
+	if (apply_filters('wl_feature__enable__analysis', true)) {
178
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action');
179 179
 	} else {
180
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
180
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action');
181 181
 	}
182 182
 
183 183
 	$plugin = new Wordlift();
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 
195 195
 	add_action(
196 196
 		'plugins_loaded',
197
-		function () {
197
+		function() {
198 198
 			// All features from registry should be initialized here.
199 199
 			$features_registry = Features_Registry::get_instance();
200 200
 			$features_registry->initialize_all_features();
@@ -205,27 +205,27 @@  discard block
 block discarded – undo
205 205
 	add_action(
206 206
 		'plugins_loaded',
207 207
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
208
-		function () use ( $plugin ) {
208
+		function() use ($plugin) {
209 209
 
210 210
 			new Wordlift_Products_Navigator_Shortcode_REST();
211 211
 
212 212
 			// Register the Dataset module, requires `$api_service`.
213
-			require_once plugin_dir_path( __FILE__ ) . 'classes/dataset/index.php';
214
-			require_once plugin_dir_path( __FILE__ ) . 'classes/shipping-data/index.php';
213
+			require_once plugin_dir_path(__FILE__).'classes/dataset/index.php';
214
+			require_once plugin_dir_path(__FILE__).'classes/shipping-data/index.php';
215 215
 
216 216
 			/*
217 217
 			* Require the Entity annotation cleanup module.
218 218
 			*
219 219
 			* @since 3.34.6
220 220
 			*/
221
-			require_once plugin_dir_path( __FILE__ ) . 'classes/cleanup/index.php';
221
+			require_once plugin_dir_path(__FILE__).'classes/cleanup/index.php';
222 222
 
223 223
 			/*
224 224
 			* Import LOD entities.
225 225
 			*
226 226
 			* @since 3.35.0
227 227
 			*/
228
-			require_once plugin_dir_path( __FILE__ ) . 'classes/lod-import/index.php';
228
+			require_once plugin_dir_path(__FILE__).'classes/lod-import/index.php';
229 229
 
230 230
 		}
231 231
 	);
@@ -243,31 +243,31 @@  discard block
 block discarded – undo
243 243
 function wordlift_plugin_autoload_register() {
244 244
 
245 245
 	spl_autoload_register(
246
-		function ( $class_name ) {
246
+		function($class_name) {
247 247
 
248 248
 			// Bail out if these are not our classes.
249
-			if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
249
+			if (0 !== strpos($class_name, 'Wordlift\\')) {
250 250
 				return false;
251 251
 			}
252 252
 
253
-			$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
253
+			$class_name_lc = strtolower(str_replace('_', '-', $class_name));
254 254
 
255
-			preg_match( '|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
255
+			preg_match('|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches);
256 256
 
257
-			$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
258
-			$file = 'class-' . $matches[2] . '.php';
257
+			$path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]);
258
+			$file = 'class-'.$matches[2].'.php';
259 259
 
260
-			$full_path = plugin_dir_path( __FILE__ ) . 'classes' . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $file;
260
+			$full_path = plugin_dir_path(__FILE__).'classes'.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$file;
261 261
 
262
-			if ( ! file_exists( $full_path ) ) {
262
+			if ( ! file_exists($full_path)) {
263 263
 				return false;
264 264
 			}
265 265
 
266 266
 			try {
267 267
 				require_once $full_path;
268
-			} catch ( Exception $e ) {
268
+			} catch (Exception $e) {
269 269
 				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
270
-				error_log( "[WordLift] $full_path not found, cannot include." );
270
+				error_log("[WordLift] $full_path not found, cannot include.");
271 271
 			}
272 272
 
273 273
 			return true;
@@ -276,13 +276,13 @@  discard block
 block discarded – undo
276 276
 
277 277
 }
278 278
 
279
-function wl_block_categories( $categories ) {
279
+function wl_block_categories($categories) {
280 280
 	return array_merge(
281 281
 		$categories,
282 282
 		array(
283 283
 			array(
284 284
 				'slug'  => 'wordlift',
285
-				'title' => __( 'WordLift', 'wordlift' ),
285
+				'title' => __('WordLift', 'wordlift'),
286 286
 			),
287 287
 		)
288 288
 	);
@@ -292,49 +292,49 @@  discard block
 block discarded – undo
292 292
  * This function is created temporarily to handle the legacy library,
293 293
  * this has to be removed when removing the legacy fields from the ui.
294 294
  */
295
-function wl_enqueue_leaflet( $in_footer = false ) {
295
+function wl_enqueue_leaflet($in_footer = false) {
296 296
 	// Leaflet.
297
-	wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
298
-	wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
297
+	wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0');
298
+	wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer);
299 299
 }
300 300
 
301
-add_filter( 'block_categories', 'wl_block_categories', 10 );
301
+add_filter('block_categories', 'wl_block_categories', 10);
302 302
 
303 303
 // Temporary fix for a typo in WooCommerce Extension.
304 304
 add_filter(
305 305
 	'wl_feature__enable__dataset',
306
-	function ( $value ) {
307
-		return apply_filters( 'wl_features__enable__dataset', $value );
306
+	function($value) {
307
+		return apply_filters('wl_features__enable__dataset', $value);
308 308
 	}
309 309
 );
310 310
 
311
-require_once __DIR__ . '/modules/food-kg/load.php';
312
-require_once __DIR__ . '/modules/gardening-kg/load.php';
313
-require_once __DIR__ . '/modules/acf4so/load.php';
314
-require_once __DIR__ . '/modules/dashboard/load.php';
315
-require_once __DIR__ . '/modules/pods/load.php';
316
-require_once __DIR__ . '/modules/include-exclude-push-config/load.php';
317
-require_once __DIR__ . '/modules/super-resolution/load.php';
318
-require_once __DIR__ . '/modules/redeem-code/load.php';
319
-require_once __DIR__ . '/modules/raptive-setup/load.php';
320
-require_once __DIR__ . '/modules/events/load.php';
321
-
322
-function _wl_update_plugins_raptive_domain( $update, $plugin_data, $plugin_file ) {
311
+require_once __DIR__.'/modules/food-kg/load.php';
312
+require_once __DIR__.'/modules/gardening-kg/load.php';
313
+require_once __DIR__.'/modules/acf4so/load.php';
314
+require_once __DIR__.'/modules/dashboard/load.php';
315
+require_once __DIR__.'/modules/pods/load.php';
316
+require_once __DIR__.'/modules/include-exclude-push-config/load.php';
317
+require_once __DIR__.'/modules/super-resolution/load.php';
318
+require_once __DIR__.'/modules/redeem-code/load.php';
319
+require_once __DIR__.'/modules/raptive-setup/load.php';
320
+require_once __DIR__.'/modules/events/load.php';
321
+
322
+function _wl_update_plugins_raptive_domain($update, $plugin_data, $plugin_file) {
323 323
 	// Bail out if it's not our plugin.
324 324
 	$update_uri = $plugin_data['UpdateURI'];
325
-	if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) {
325
+	if ('wordlift/wordlift.php' !== $plugin_file || ! isset($update_uri)) {
326 326
 		return $update;
327 327
 	}
328 328
 
329
-	$response = wp_remote_get( "$update_uri?nocache=" . time() );
329
+	$response = wp_remote_get("$update_uri?nocache=".time());
330 330
 
331
-	if ( is_wp_error( $response ) ) {
331
+	if (is_wp_error($response)) {
332 332
 		return $update;
333 333
 	}
334 334
 
335 335
 	try {
336
-		return json_decode( wp_remote_retrieve_body( $response ) );
337
-	} catch ( Exception $e ) {
336
+		return json_decode(wp_remote_retrieve_body($response));
337
+	} catch (Exception $e) {
338 338
 		return $update;
339 339
 	}
340 340
 }
Please login to merge, or discard this patch.
src/modules/events/vendor/composer/installed.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
         'version' => 'dev-develop',
6 6
         'reference' => '8ecf5a41e6c7973462fa86644e2e9ef88737d2b7',
7 7
         'type' => 'wordpress-plugin',
8
-        'install_path' => __DIR__ . '/../../',
8
+        'install_path' => __DIR__.'/../../',
9 9
         'aliases' => array(),
10 10
         'dev' => true,
11 11
     ),
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
             'version' => 'dev-develop',
16 16
             'reference' => '8ecf5a41e6c7973462fa86644e2e9ef88737d2b7',
17 17
             'type' => 'wordpress-plugin',
18
-            'install_path' => __DIR__ . '/../../',
18
+            'install_path' => __DIR__.'/../../',
19 19
             'aliases' => array(),
20 20
             'dev_requirement' => false,
21 21
         ),
Please login to merge, or discard this patch.
events/includes/Options_Entity/Events_Options_Entity_Include_Exclude.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -11,148 +11,148 @@
 block discarded – undo
11 11
  * @package Wordlift\Modules\Events\Options_Entity
12 12
  */
13 13
 class Events_Options_Entity_Include_Exclude {
14
-	/**
15
-	 * The {@link Api_Service} used to communicate with the remote APIs.
16
-	 *
17
-	 * @access private
18
-	 * @var Api_Service
19
-	 */
20
-	private $api_service;
21
-
22
-	/**
23
-	 * @param Api_Service $api_service
24
-	 */
25
-	public function __construct( $api_service ) {
26
-		$this->api_service = $api_service;
27
-	}
28
-
29
-	/**
30
-	 * Register hooks.
31
-	 */
32
-	public function register_hooks() {
33
-		add_action( 'update_option_wl_exclude_include_urls_settings', array( $this, 'event_update' ), 15, 2 );
34
-	}
35
-
36
-	/**
37
-	 * Include exclude event update.
38
-	 *
39
-	 * @param mixed $old_value
40
-	 * @param mixed $new_value
41
-	 *
42
-	 * @throws Exception If the application fails to load the services configuration file or if the URL cannot be processed.
43
-	 */
44
-	public function event_update( $old_value, $new_value ) {
45
-		// Get the configurations.
46
-		$urls = $this->get_urls( $new_value, $old_value );
47
-
48
-		// Call API method for each URL.
49
-		foreach ( $urls['included'] as $url ) {
50
-			$this->send_event( $url, 'include' );
51
-		}
52
-		foreach ( $urls['excluded'] as $url ) {
53
-			$this->send_event( $url, 'exclude' );
54
-		}
55
-	}
56
-
57
-	/**
58
-	 * Get included and excluded urls.
59
-	 *
60
-	 * @param $config
61
-	 * @param $old_config
62
-	 *
63
-	 * @return array
64
-	 */
65
-	private function get_urls( $config, $old_config ) {
66
-		// Get the payload for both new and old values:
67
-		$payload_new = $this->get_payload( $config );
68
-		$payload_old = $this->get_payload( $old_config );
69
-
70
-		// Extract URLs from payloads.
71
-		$urls_new = array_column( $payload_new, 'url' );
72
-		$urls_old = array_column( $payload_old, 'url' );
73
-
74
-		// If both $urls_new and $urls_old are empty, there is no URL to process.
75
-		if ( empty( $urls_new ) && empty( $urls_old ) ) {
76
-			return array(
77
-				'included' => array(),
78
-				'excluded' => array(),
79
-			);
80
-		}
81
-
82
-		// Find added and removed URLs.
83
-		$urls_added   = array_diff( $urls_new, $urls_old );
84
-		$urls_removed = array_diff( $urls_old, $urls_new );
85
-
86
-		// Determine included and excluded URLs.
87
-		$included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_added : $urls_removed;
88
-		$excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_added;
89
-
90
-		// Check if filter type has changed.
91
-		$filter_changed = strtolower( $config['include_exclude'] ) !== strtolower( $old_config['include_exclude'] );
92
-
93
-		if ( $filter_changed ) {
94
-			// Filter type changed, so we reverse the logic of adding URLs to included and excluded arrays.
95
-			$included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_new : $urls_removed;
96
-			$excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_new;
97
-		}
98
-
99
-		return array(
100
-			'included' => $included,
101
-			'excluded' => $excluded,
102
-		);
103
-	}
104
-
105
-	/**
106
-	 * Get payload.
107
-	 *
108
-	 * @param $config
109
-	 *
110
-	 * @return array|array[]
111
-	 */
112
-	private function get_payload( $config ) {
113
-		// Set the default data.
114
-		if ( ! is_array( $config ) || empty( $config ) || ! isset( $config['include_exclude'] ) || ! isset( $config['urls'] ) ) {
115
-			$config = array(
116
-				'include_exclude' => 'exclude',
117
-				'urls'            => '',
118
-			);
119
-		}
120
-
121
-		// Map the configuration to the payload.
122
-		return array_map(
123
-			function ( $item ) use ( $config ) {
124
-				return array(
125
-					'url'  => ( 1 === preg_match( '@^https?://.*$@', $item ) ? $item : get_home_url( null, $item ) ),
126
-					'flag' => strtoupper( $config['include_exclude'] ),
127
-				);
128
-			},
129
-			array_filter( preg_split( '/[\r\n]+/', $config['urls'] ) )
130
-		);
131
-	}
132
-
133
-	/**
134
-	 * Send event.
135
-	 *
136
-	 * @param $url
137
-	 * @param $value
138
-	 */
139
-	private function send_event( $url, $value ) {
140
-		$this->api_service->request(
141
-			'POST',
142
-			'/plugin/events',
143
-			array( 'content-type' => 'application/json' ),
144
-			wp_json_encode(
145
-				array(
146
-					'source' => 'include-exclude',
147
-					'args'   => array(
148
-						array( 'value' => $value ),
149
-					),
150
-					'url'    => $url,
151
-				)
152
-			),
153
-			0.001,
154
-			null,
155
-			array( 'blocking' => false )
156
-		);
157
-	}
14
+    /**
15
+     * The {@link Api_Service} used to communicate with the remote APIs.
16
+     *
17
+     * @access private
18
+     * @var Api_Service
19
+     */
20
+    private $api_service;
21
+
22
+    /**
23
+     * @param Api_Service $api_service
24
+     */
25
+    public function __construct( $api_service ) {
26
+        $this->api_service = $api_service;
27
+    }
28
+
29
+    /**
30
+     * Register hooks.
31
+     */
32
+    public function register_hooks() {
33
+        add_action( 'update_option_wl_exclude_include_urls_settings', array( $this, 'event_update' ), 15, 2 );
34
+    }
35
+
36
+    /**
37
+     * Include exclude event update.
38
+     *
39
+     * @param mixed $old_value
40
+     * @param mixed $new_value
41
+     *
42
+     * @throws Exception If the application fails to load the services configuration file or if the URL cannot be processed.
43
+     */
44
+    public function event_update( $old_value, $new_value ) {
45
+        // Get the configurations.
46
+        $urls = $this->get_urls( $new_value, $old_value );
47
+
48
+        // Call API method for each URL.
49
+        foreach ( $urls['included'] as $url ) {
50
+            $this->send_event( $url, 'include' );
51
+        }
52
+        foreach ( $urls['excluded'] as $url ) {
53
+            $this->send_event( $url, 'exclude' );
54
+        }
55
+    }
56
+
57
+    /**
58
+     * Get included and excluded urls.
59
+     *
60
+     * @param $config
61
+     * @param $old_config
62
+     *
63
+     * @return array
64
+     */
65
+    private function get_urls( $config, $old_config ) {
66
+        // Get the payload for both new and old values:
67
+        $payload_new = $this->get_payload( $config );
68
+        $payload_old = $this->get_payload( $old_config );
69
+
70
+        // Extract URLs from payloads.
71
+        $urls_new = array_column( $payload_new, 'url' );
72
+        $urls_old = array_column( $payload_old, 'url' );
73
+
74
+        // If both $urls_new and $urls_old are empty, there is no URL to process.
75
+        if ( empty( $urls_new ) && empty( $urls_old ) ) {
76
+            return array(
77
+                'included' => array(),
78
+                'excluded' => array(),
79
+            );
80
+        }
81
+
82
+        // Find added and removed URLs.
83
+        $urls_added   = array_diff( $urls_new, $urls_old );
84
+        $urls_removed = array_diff( $urls_old, $urls_new );
85
+
86
+        // Determine included and excluded URLs.
87
+        $included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_added : $urls_removed;
88
+        $excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_added;
89
+
90
+        // Check if filter type has changed.
91
+        $filter_changed = strtolower( $config['include_exclude'] ) !== strtolower( $old_config['include_exclude'] );
92
+
93
+        if ( $filter_changed ) {
94
+            // Filter type changed, so we reverse the logic of adding URLs to included and excluded arrays.
95
+            $included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_new : $urls_removed;
96
+            $excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_new;
97
+        }
98
+
99
+        return array(
100
+            'included' => $included,
101
+            'excluded' => $excluded,
102
+        );
103
+    }
104
+
105
+    /**
106
+     * Get payload.
107
+     *
108
+     * @param $config
109
+     *
110
+     * @return array|array[]
111
+     */
112
+    private function get_payload( $config ) {
113
+        // Set the default data.
114
+        if ( ! is_array( $config ) || empty( $config ) || ! isset( $config['include_exclude'] ) || ! isset( $config['urls'] ) ) {
115
+            $config = array(
116
+                'include_exclude' => 'exclude',
117
+                'urls'            => '',
118
+            );
119
+        }
120
+
121
+        // Map the configuration to the payload.
122
+        return array_map(
123
+            function ( $item ) use ( $config ) {
124
+                return array(
125
+                    'url'  => ( 1 === preg_match( '@^https?://.*$@', $item ) ? $item : get_home_url( null, $item ) ),
126
+                    'flag' => strtoupper( $config['include_exclude'] ),
127
+                );
128
+            },
129
+            array_filter( preg_split( '/[\r\n]+/', $config['urls'] ) )
130
+        );
131
+    }
132
+
133
+    /**
134
+     * Send event.
135
+     *
136
+     * @param $url
137
+     * @param $value
138
+     */
139
+    private function send_event( $url, $value ) {
140
+        $this->api_service->request(
141
+            'POST',
142
+            '/plugin/events',
143
+            array( 'content-type' => 'application/json' ),
144
+            wp_json_encode(
145
+                array(
146
+                    'source' => 'include-exclude',
147
+                    'args'   => array(
148
+                        array( 'value' => $value ),
149
+                    ),
150
+                    'url'    => $url,
151
+                )
152
+            ),
153
+            0.001,
154
+            null,
155
+            array( 'blocking' => false )
156
+        );
157
+    }
158 158
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * @param Api_Service $api_service
24 24
 	 */
25
-	public function __construct( $api_service ) {
25
+	public function __construct($api_service) {
26 26
 		$this->api_service = $api_service;
27 27
 	}
28 28
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 * Register hooks.
31 31
 	 */
32 32
 	public function register_hooks() {
33
-		add_action( 'update_option_wl_exclude_include_urls_settings', array( $this, 'event_update' ), 15, 2 );
33
+		add_action('update_option_wl_exclude_include_urls_settings', array($this, 'event_update'), 15, 2);
34 34
 	}
35 35
 
36 36
 	/**
@@ -41,16 +41,16 @@  discard block
 block discarded – undo
41 41
 	 *
42 42
 	 * @throws Exception If the application fails to load the services configuration file or if the URL cannot be processed.
43 43
 	 */
44
-	public function event_update( $old_value, $new_value ) {
44
+	public function event_update($old_value, $new_value) {
45 45
 		// Get the configurations.
46
-		$urls = $this->get_urls( $new_value, $old_value );
46
+		$urls = $this->get_urls($new_value, $old_value);
47 47
 
48 48
 		// Call API method for each URL.
49
-		foreach ( $urls['included'] as $url ) {
50
-			$this->send_event( $url, 'include' );
49
+		foreach ($urls['included'] as $url) {
50
+			$this->send_event($url, 'include');
51 51
 		}
52
-		foreach ( $urls['excluded'] as $url ) {
53
-			$this->send_event( $url, 'exclude' );
52
+		foreach ($urls['excluded'] as $url) {
53
+			$this->send_event($url, 'exclude');
54 54
 		}
55 55
 	}
56 56
 
@@ -62,17 +62,17 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * @return array
64 64
 	 */
65
-	private function get_urls( $config, $old_config ) {
65
+	private function get_urls($config, $old_config) {
66 66
 		// Get the payload for both new and old values:
67
-		$payload_new = $this->get_payload( $config );
68
-		$payload_old = $this->get_payload( $old_config );
67
+		$payload_new = $this->get_payload($config);
68
+		$payload_old = $this->get_payload($old_config);
69 69
 
70 70
 		// Extract URLs from payloads.
71
-		$urls_new = array_column( $payload_new, 'url' );
72
-		$urls_old = array_column( $payload_old, 'url' );
71
+		$urls_new = array_column($payload_new, 'url');
72
+		$urls_old = array_column($payload_old, 'url');
73 73
 
74 74
 		// If both $urls_new and $urls_old are empty, there is no URL to process.
75
-		if ( empty( $urls_new ) && empty( $urls_old ) ) {
75
+		if (empty($urls_new) && empty($urls_old)) {
76 76
 			return array(
77 77
 				'included' => array(),
78 78
 				'excluded' => array(),
@@ -80,20 +80,20 @@  discard block
 block discarded – undo
80 80
 		}
81 81
 
82 82
 		// Find added and removed URLs.
83
-		$urls_added   = array_diff( $urls_new, $urls_old );
84
-		$urls_removed = array_diff( $urls_old, $urls_new );
83
+		$urls_added   = array_diff($urls_new, $urls_old);
84
+		$urls_removed = array_diff($urls_old, $urls_new);
85 85
 
86 86
 		// Determine included and excluded URLs.
87
-		$included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_added : $urls_removed;
88
-		$excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_added;
87
+		$included = ('include' === strtolower($config['include_exclude'])) ? $urls_added : $urls_removed;
88
+		$excluded = ('include' === strtolower($config['include_exclude'])) ? $urls_removed : $urls_added;
89 89
 
90 90
 		// Check if filter type has changed.
91
-		$filter_changed = strtolower( $config['include_exclude'] ) !== strtolower( $old_config['include_exclude'] );
91
+		$filter_changed = strtolower($config['include_exclude']) !== strtolower($old_config['include_exclude']);
92 92
 
93
-		if ( $filter_changed ) {
93
+		if ($filter_changed) {
94 94
 			// Filter type changed, so we reverse the logic of adding URLs to included and excluded arrays.
95
-			$included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_new : $urls_removed;
96
-			$excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_new;
95
+			$included = ('include' === strtolower($config['include_exclude'])) ? $urls_new : $urls_removed;
96
+			$excluded = ('include' === strtolower($config['include_exclude'])) ? $urls_removed : $urls_new;
97 97
 		}
98 98
 
99 99
 		return array(
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
 	 *
110 110
 	 * @return array|array[]
111 111
 	 */
112
-	private function get_payload( $config ) {
112
+	private function get_payload($config) {
113 113
 		// Set the default data.
114
-		if ( ! is_array( $config ) || empty( $config ) || ! isset( $config['include_exclude'] ) || ! isset( $config['urls'] ) ) {
114
+		if ( ! is_array($config) || empty($config) || ! isset($config['include_exclude']) || ! isset($config['urls'])) {
115 115
 			$config = array(
116 116
 				'include_exclude' => 'exclude',
117 117
 				'urls'            => '',
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
 
121 121
 		// Map the configuration to the payload.
122 122
 		return array_map(
123
-			function ( $item ) use ( $config ) {
123
+			function($item) use ($config) {
124 124
 				return array(
125
-					'url'  => ( 1 === preg_match( '@^https?://.*$@', $item ) ? $item : get_home_url( null, $item ) ),
126
-					'flag' => strtoupper( $config['include_exclude'] ),
125
+					'url'  => (1 === preg_match('@^https?://.*$@', $item) ? $item : get_home_url(null, $item)),
126
+					'flag' => strtoupper($config['include_exclude']),
127 127
 				);
128 128
 			},
129
-			array_filter( preg_split( '/[\r\n]+/', $config['urls'] ) )
129
+			array_filter(preg_split('/[\r\n]+/', $config['urls']))
130 130
 		);
131 131
 	}
132 132
 
@@ -136,23 +136,23 @@  discard block
 block discarded – undo
136 136
 	 * @param $url
137 137
 	 * @param $value
138 138
 	 */
139
-	private function send_event( $url, $value ) {
139
+	private function send_event($url, $value) {
140 140
 		$this->api_service->request(
141 141
 			'POST',
142 142
 			'/plugin/events',
143
-			array( 'content-type' => 'application/json' ),
143
+			array('content-type' => 'application/json'),
144 144
 			wp_json_encode(
145 145
 				array(
146 146
 					'source' => 'include-exclude',
147 147
 					'args'   => array(
148
-						array( 'value' => $value ),
148
+						array('value' => $value),
149 149
 					),
150 150
 					'url'    => $url,
151 151
 				)
152 152
 			),
153 153
 			0.001,
154 154
 			null,
155
-			array( 'blocking' => false )
155
+			array('blocking' => false)
156 156
 		);
157 157
 	}
158 158
 }
Please login to merge, or discard this patch.
src/modules/events/includes/Term_Entity/Events_Term_Entity_Jsonld.php 2 patches
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -13,199 +13,199 @@
 block discarded – undo
13 13
  */
14 14
 class Events_Term_Entity_Jsonld {
15 15
 
16
-	/**
17
-	 * The {@link Api_Service} used to communicate with the remote APIs.
18
-	 *
19
-	 * @access private
20
-	 * @var Api_Service
21
-	 */
22
-	private $api_service;
23
-
24
-	/**
25
-	 * @param Api_Service $api_service
26
-	 */
27
-	public function __construct( Api_Service $api_service ) {
28
-		$this->api_service = $api_service;
29
-	}
30
-
31
-	/**
32
-	 * Register hooks.
33
-	 */
34
-	public function register_hooks() {
35
-		add_filter( 'wl_term_jsonld_array', array( $this, 'set_events_request' ), 90, 3 );
36
-	}
37
-
38
-	/**
39
-	 * Set term jsonld array event.
40
-	 *
41
-	 * @param $data array An array containing jsonld for term and entities.
42
-	 * @param $term_id int The term id for which the jsonld is generated.
43
-	 * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum
44
-	 *
45
-	 * @return array
46
-	 */
47
-	public function set_events_request( $data, $term_id, $context ) {
48
-		$jsonld_arr = $data['jsonld'];
49
-
50
-		if ( $this->should_return_early( $context ) ) {
51
-			return $data;
52
-		}
53
-
54
-		$counts = $this->get_initial_counts( $term_id );
55
-
56
-		$change_status = $this->update_counts_if_necessary( $jsonld_arr, $counts, $term_id );
57
-
58
-		if ( $change_status ) {
59
-			$this->send_api_request( $counts, $term_id );
60
-		}
61
-
62
-		return $data;
63
-	}
64
-
65
-	/**
66
-	 * If context is not PAGE, return early.
67
-	 *
68
-	 * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum
69
-	 *
70
-	 * @return bool
71
-	 */
72
-	private function should_return_early( $context ) {
73
-		return Jsonld_Context_Enum::PAGE !== $context;
74
-	}
75
-
76
-	/**
77
-	 * Fetch the initial 'about' and 'mentions' counts from term meta.
78
-	 *
79
-	 * @param $term_id int The term id for which the jsonld is generated.
80
-	 *
81
-	 * @return int[]
82
-	 */
83
-	private function get_initial_counts( $term_id ) {
84
-		return array(
85
-			'about'    => get_term_meta( $term_id, 'wl_about_count', true ) ? (int) get_term_meta( $term_id, 'wl_about_count', true ) : 0,
86
-			'mentions' => get_term_meta( $term_id, 'wl_mentions_count', true )
87
-				? (int) get_term_meta( $term_id, 'wl_mentions_count', true )
88
-				: 0,
89
-		);
90
-	}
91
-
92
-	/**
93
-	 * Update counts if necessary.
94
-	 *
95
-	 * @param $jsonld_arr
96
-	 * @param $counts
97
-	 * @param $term_id
98
-	 *
99
-	 * @return bool
100
-	 */
101
-	private function update_counts_if_necessary( $jsonld_arr, &$counts, $term_id ) {
102
-		// Flag to indicate if we should make an API request.
103
-		$change_status = false;
104
-
105
-		// If the $jsonld_arr is empty but the counts were previously more than 0.
106
-		if ( empty( $jsonld_arr[0] ) ) {
107
-			return $this->reset_counts_if_non_zero( $counts, $term_id );
108
-		}
109
-
110
-		// Get data from the array.
111
-		$data_arr = $jsonld_arr[0];
112
-
113
-		// Iterate over the counts array.
114
-		foreach ( $counts as $type => $type_count ) {
115
-			// Check if data has 'about' or 'mentions' and the count is different from the existing meta value.
116
-			if ( isset( $data_arr[ $type ] ) ) {
117
-				$new_count = count( $data_arr[ $type ] );
118
-				if ( $type_count !== $new_count ) {
119
-					// Set flag to true if counts have changed.
120
-					$change_status = true;
121
-
122
-					// Update the counts array with new count.
123
-					$counts[ $type ] = $new_count;
124
-
125
-					// Update term meta with new count.
126
-					update_term_meta( $term_id, 'wl_' . $type . '_count', $new_count );
127
-					continue;
128
-				}
129
-			}
130
-
131
-			if ( $type_count > 0 ) {
132
-				// If the 'about' or 'mentions' has become empty, set it to 0.
133
-				$change_status   = true;
134
-				$counts[ $type ] = 0;
135
-				update_term_meta( $term_id, 'wl_' . $type . '_count', 0 );
136
-			}
137
-		}
138
-
139
-		return $change_status;
140
-	}
141
-
142
-	/**
143
-	 * Reset counts if non zero.
144
-	 *
145
-	 * @param $counts
146
-	 * @param $term_id
147
-	 *
148
-	 * @return bool
149
-	 */
150
-	private function reset_counts_if_non_zero( &$counts, $term_id ) {
151
-		$change_status = false;
152
-
153
-		foreach ( $counts as $type => $type_count ) {
154
-			if ( $type_count > 0 ) {
155
-				$change_status   = true;
156
-				$counts[ $type ] = 0;
157
-				update_term_meta( $term_id, 'wl_' . $type . '_count', 0 );
158
-			}
159
-		}
160
-
161
-		return $change_status;
162
-	}
163
-
164
-	/**
165
-	 * Send api request.
166
-	 *
167
-	 * @param $counts
168
-	 * @param $term_id
169
-	 */
170
-	private function send_api_request( $counts, $term_id ) {
171
-		// If the count has changed, make the API request.
172
-		$this->api_service->request(
173
-			'POST',
174
-			'/plugin/events',
175
-			array( 'Content-Type' => 'application/json' ),
176
-			wp_json_encode(
177
-				array(
178
-					'source' => 'jsonld',
179
-					'args'   => array(
180
-						array( 'about_count' => $counts['about'] ),
181
-						array( 'mentions_count' => $counts['mentions'] ),
182
-					),
183
-					'url'    => $this->get_term_url( $term_id ),
184
-				)
185
-			),
186
-			0.001,
187
-			null,
188
-			array( 'blocking' => false )
189
-		);
190
-	}
191
-
192
-	/**
193
-	 * Get term url.
194
-	 *
195
-	 * @param $id
196
-	 *
197
-	 * @return array|false|int|mixed|string|\WP_Error|\WP_Term|null
198
-	 */
199
-	private function get_term_url( $id ) {
200
-		if ( null === $id ) {
201
-			return isset( $_SERVER['REQUEST_URI'] ) ? filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ) : '';
202
-		}
203
-
204
-		$maybe_url = get_term_meta( $id, Wordlift_Url_Property_Service::META_KEY, true );
205
-		if ( ! empty( $maybe_url ) ) {
206
-			return $maybe_url;
207
-		}
208
-
209
-		return get_term_link( $id );
210
-	}
16
+    /**
17
+     * The {@link Api_Service} used to communicate with the remote APIs.
18
+     *
19
+     * @access private
20
+     * @var Api_Service
21
+     */
22
+    private $api_service;
23
+
24
+    /**
25
+     * @param Api_Service $api_service
26
+     */
27
+    public function __construct( Api_Service $api_service ) {
28
+        $this->api_service = $api_service;
29
+    }
30
+
31
+    /**
32
+     * Register hooks.
33
+     */
34
+    public function register_hooks() {
35
+        add_filter( 'wl_term_jsonld_array', array( $this, 'set_events_request' ), 90, 3 );
36
+    }
37
+
38
+    /**
39
+     * Set term jsonld array event.
40
+     *
41
+     * @param $data array An array containing jsonld for term and entities.
42
+     * @param $term_id int The term id for which the jsonld is generated.
43
+     * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum
44
+     *
45
+     * @return array
46
+     */
47
+    public function set_events_request( $data, $term_id, $context ) {
48
+        $jsonld_arr = $data['jsonld'];
49
+
50
+        if ( $this->should_return_early( $context ) ) {
51
+            return $data;
52
+        }
53
+
54
+        $counts = $this->get_initial_counts( $term_id );
55
+
56
+        $change_status = $this->update_counts_if_necessary( $jsonld_arr, $counts, $term_id );
57
+
58
+        if ( $change_status ) {
59
+            $this->send_api_request( $counts, $term_id );
60
+        }
61
+
62
+        return $data;
63
+    }
64
+
65
+    /**
66
+     * If context is not PAGE, return early.
67
+     *
68
+     * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum
69
+     *
70
+     * @return bool
71
+     */
72
+    private function should_return_early( $context ) {
73
+        return Jsonld_Context_Enum::PAGE !== $context;
74
+    }
75
+
76
+    /**
77
+     * Fetch the initial 'about' and 'mentions' counts from term meta.
78
+     *
79
+     * @param $term_id int The term id for which the jsonld is generated.
80
+     *
81
+     * @return int[]
82
+     */
83
+    private function get_initial_counts( $term_id ) {
84
+        return array(
85
+            'about'    => get_term_meta( $term_id, 'wl_about_count', true ) ? (int) get_term_meta( $term_id, 'wl_about_count', true ) : 0,
86
+            'mentions' => get_term_meta( $term_id, 'wl_mentions_count', true )
87
+                ? (int) get_term_meta( $term_id, 'wl_mentions_count', true )
88
+                : 0,
89
+        );
90
+    }
91
+
92
+    /**
93
+     * Update counts if necessary.
94
+     *
95
+     * @param $jsonld_arr
96
+     * @param $counts
97
+     * @param $term_id
98
+     *
99
+     * @return bool
100
+     */
101
+    private function update_counts_if_necessary( $jsonld_arr, &$counts, $term_id ) {
102
+        // Flag to indicate if we should make an API request.
103
+        $change_status = false;
104
+
105
+        // If the $jsonld_arr is empty but the counts were previously more than 0.
106
+        if ( empty( $jsonld_arr[0] ) ) {
107
+            return $this->reset_counts_if_non_zero( $counts, $term_id );
108
+        }
109
+
110
+        // Get data from the array.
111
+        $data_arr = $jsonld_arr[0];
112
+
113
+        // Iterate over the counts array.
114
+        foreach ( $counts as $type => $type_count ) {
115
+            // Check if data has 'about' or 'mentions' and the count is different from the existing meta value.
116
+            if ( isset( $data_arr[ $type ] ) ) {
117
+                $new_count = count( $data_arr[ $type ] );
118
+                if ( $type_count !== $new_count ) {
119
+                    // Set flag to true if counts have changed.
120
+                    $change_status = true;
121
+
122
+                    // Update the counts array with new count.
123
+                    $counts[ $type ] = $new_count;
124
+
125
+                    // Update term meta with new count.
126
+                    update_term_meta( $term_id, 'wl_' . $type . '_count', $new_count );
127
+                    continue;
128
+                }
129
+            }
130
+
131
+            if ( $type_count > 0 ) {
132
+                // If the 'about' or 'mentions' has become empty, set it to 0.
133
+                $change_status   = true;
134
+                $counts[ $type ] = 0;
135
+                update_term_meta( $term_id, 'wl_' . $type . '_count', 0 );
136
+            }
137
+        }
138
+
139
+        return $change_status;
140
+    }
141
+
142
+    /**
143
+     * Reset counts if non zero.
144
+     *
145
+     * @param $counts
146
+     * @param $term_id
147
+     *
148
+     * @return bool
149
+     */
150
+    private function reset_counts_if_non_zero( &$counts, $term_id ) {
151
+        $change_status = false;
152
+
153
+        foreach ( $counts as $type => $type_count ) {
154
+            if ( $type_count > 0 ) {
155
+                $change_status   = true;
156
+                $counts[ $type ] = 0;
157
+                update_term_meta( $term_id, 'wl_' . $type . '_count', 0 );
158
+            }
159
+        }
160
+
161
+        return $change_status;
162
+    }
163
+
164
+    /**
165
+     * Send api request.
166
+     *
167
+     * @param $counts
168
+     * @param $term_id
169
+     */
170
+    private function send_api_request( $counts, $term_id ) {
171
+        // If the count has changed, make the API request.
172
+        $this->api_service->request(
173
+            'POST',
174
+            '/plugin/events',
175
+            array( 'Content-Type' => 'application/json' ),
176
+            wp_json_encode(
177
+                array(
178
+                    'source' => 'jsonld',
179
+                    'args'   => array(
180
+                        array( 'about_count' => $counts['about'] ),
181
+                        array( 'mentions_count' => $counts['mentions'] ),
182
+                    ),
183
+                    'url'    => $this->get_term_url( $term_id ),
184
+                )
185
+            ),
186
+            0.001,
187
+            null,
188
+            array( 'blocking' => false )
189
+        );
190
+    }
191
+
192
+    /**
193
+     * Get term url.
194
+     *
195
+     * @param $id
196
+     *
197
+     * @return array|false|int|mixed|string|\WP_Error|\WP_Term|null
198
+     */
199
+    private function get_term_url( $id ) {
200
+        if ( null === $id ) {
201
+            return isset( $_SERVER['REQUEST_URI'] ) ? filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ) : '';
202
+        }
203
+
204
+        $maybe_url = get_term_meta( $id, Wordlift_Url_Property_Service::META_KEY, true );
205
+        if ( ! empty( $maybe_url ) ) {
206
+            return $maybe_url;
207
+        }
208
+
209
+        return get_term_link( $id );
210
+    }
211 211
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	/**
25 25
 	 * @param Api_Service $api_service
26 26
 	 */
27
-	public function __construct( Api_Service $api_service ) {
27
+	public function __construct(Api_Service $api_service) {
28 28
 		$this->api_service = $api_service;
29 29
 	}
30 30
 
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 * Register hooks.
33 33
 	 */
34 34
 	public function register_hooks() {
35
-		add_filter( 'wl_term_jsonld_array', array( $this, 'set_events_request' ), 90, 3 );
35
+		add_filter('wl_term_jsonld_array', array($this, 'set_events_request'), 90, 3);
36 36
 	}
37 37
 
38 38
 	/**
@@ -44,19 +44,19 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @return array
46 46
 	 */
47
-	public function set_events_request( $data, $term_id, $context ) {
47
+	public function set_events_request($data, $term_id, $context) {
48 48
 		$jsonld_arr = $data['jsonld'];
49 49
 
50
-		if ( $this->should_return_early( $context ) ) {
50
+		if ($this->should_return_early($context)) {
51 51
 			return $data;
52 52
 		}
53 53
 
54
-		$counts = $this->get_initial_counts( $term_id );
54
+		$counts = $this->get_initial_counts($term_id);
55 55
 
56
-		$change_status = $this->update_counts_if_necessary( $jsonld_arr, $counts, $term_id );
56
+		$change_status = $this->update_counts_if_necessary($jsonld_arr, $counts, $term_id);
57 57
 
58
-		if ( $change_status ) {
59
-			$this->send_api_request( $counts, $term_id );
58
+		if ($change_status) {
59
+			$this->send_api_request($counts, $term_id);
60 60
 		}
61 61
 
62 62
 		return $data;
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return bool
71 71
 	 */
72
-	private function should_return_early( $context ) {
72
+	private function should_return_early($context) {
73 73
 		return Jsonld_Context_Enum::PAGE !== $context;
74 74
 	}
75 75
 
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @return int[]
82 82
 	 */
83
-	private function get_initial_counts( $term_id ) {
83
+	private function get_initial_counts($term_id) {
84 84
 		return array(
85
-			'about'    => get_term_meta( $term_id, 'wl_about_count', true ) ? (int) get_term_meta( $term_id, 'wl_about_count', true ) : 0,
86
-			'mentions' => get_term_meta( $term_id, 'wl_mentions_count', true )
87
-				? (int) get_term_meta( $term_id, 'wl_mentions_count', true )
85
+			'about'    => get_term_meta($term_id, 'wl_about_count', true) ? (int) get_term_meta($term_id, 'wl_about_count', true) : 0,
86
+			'mentions' => get_term_meta($term_id, 'wl_mentions_count', true)
87
+				? (int) get_term_meta($term_id, 'wl_mentions_count', true)
88 88
 				: 0,
89 89
 		);
90 90
 	}
@@ -98,41 +98,41 @@  discard block
 block discarded – undo
98 98
 	 *
99 99
 	 * @return bool
100 100
 	 */
101
-	private function update_counts_if_necessary( $jsonld_arr, &$counts, $term_id ) {
101
+	private function update_counts_if_necessary($jsonld_arr, &$counts, $term_id) {
102 102
 		// Flag to indicate if we should make an API request.
103 103
 		$change_status = false;
104 104
 
105 105
 		// If the $jsonld_arr is empty but the counts were previously more than 0.
106
-		if ( empty( $jsonld_arr[0] ) ) {
107
-			return $this->reset_counts_if_non_zero( $counts, $term_id );
106
+		if (empty($jsonld_arr[0])) {
107
+			return $this->reset_counts_if_non_zero($counts, $term_id);
108 108
 		}
109 109
 
110 110
 		// Get data from the array.
111 111
 		$data_arr = $jsonld_arr[0];
112 112
 
113 113
 		// Iterate over the counts array.
114
-		foreach ( $counts as $type => $type_count ) {
114
+		foreach ($counts as $type => $type_count) {
115 115
 			// Check if data has 'about' or 'mentions' and the count is different from the existing meta value.
116
-			if ( isset( $data_arr[ $type ] ) ) {
117
-				$new_count = count( $data_arr[ $type ] );
118
-				if ( $type_count !== $new_count ) {
116
+			if (isset($data_arr[$type])) {
117
+				$new_count = count($data_arr[$type]);
118
+				if ($type_count !== $new_count) {
119 119
 					// Set flag to true if counts have changed.
120 120
 					$change_status = true;
121 121
 
122 122
 					// Update the counts array with new count.
123
-					$counts[ $type ] = $new_count;
123
+					$counts[$type] = $new_count;
124 124
 
125 125
 					// Update term meta with new count.
126
-					update_term_meta( $term_id, 'wl_' . $type . '_count', $new_count );
126
+					update_term_meta($term_id, 'wl_'.$type.'_count', $new_count);
127 127
 					continue;
128 128
 				}
129 129
 			}
130 130
 
131
-			if ( $type_count > 0 ) {
131
+			if ($type_count > 0) {
132 132
 				// If the 'about' or 'mentions' has become empty, set it to 0.
133 133
 				$change_status   = true;
134
-				$counts[ $type ] = 0;
135
-				update_term_meta( $term_id, 'wl_' . $type . '_count', 0 );
134
+				$counts[$type] = 0;
135
+				update_term_meta($term_id, 'wl_'.$type.'_count', 0);
136 136
 			}
137 137
 		}
138 138
 
@@ -147,14 +147,14 @@  discard block
 block discarded – undo
147 147
 	 *
148 148
 	 * @return bool
149 149
 	 */
150
-	private function reset_counts_if_non_zero( &$counts, $term_id ) {
150
+	private function reset_counts_if_non_zero(&$counts, $term_id) {
151 151
 		$change_status = false;
152 152
 
153
-		foreach ( $counts as $type => $type_count ) {
154
-			if ( $type_count > 0 ) {
153
+		foreach ($counts as $type => $type_count) {
154
+			if ($type_count > 0) {
155 155
 				$change_status   = true;
156
-				$counts[ $type ] = 0;
157
-				update_term_meta( $term_id, 'wl_' . $type . '_count', 0 );
156
+				$counts[$type] = 0;
157
+				update_term_meta($term_id, 'wl_'.$type.'_count', 0);
158 158
 			}
159 159
 		}
160 160
 
@@ -167,25 +167,25 @@  discard block
 block discarded – undo
167 167
 	 * @param $counts
168 168
 	 * @param $term_id
169 169
 	 */
170
-	private function send_api_request( $counts, $term_id ) {
170
+	private function send_api_request($counts, $term_id) {
171 171
 		// If the count has changed, make the API request.
172 172
 		$this->api_service->request(
173 173
 			'POST',
174 174
 			'/plugin/events',
175
-			array( 'Content-Type' => 'application/json' ),
175
+			array('Content-Type' => 'application/json'),
176 176
 			wp_json_encode(
177 177
 				array(
178 178
 					'source' => 'jsonld',
179 179
 					'args'   => array(
180
-						array( 'about_count' => $counts['about'] ),
181
-						array( 'mentions_count' => $counts['mentions'] ),
180
+						array('about_count' => $counts['about']),
181
+						array('mentions_count' => $counts['mentions']),
182 182
 					),
183
-					'url'    => $this->get_term_url( $term_id ),
183
+					'url'    => $this->get_term_url($term_id),
184 184
 				)
185 185
 			),
186 186
 			0.001,
187 187
 			null,
188
-			array( 'blocking' => false )
188
+			array('blocking' => false)
189 189
 		);
190 190
 	}
191 191
 
@@ -196,16 +196,16 @@  discard block
 block discarded – undo
196 196
 	 *
197 197
 	 * @return array|false|int|mixed|string|\WP_Error|\WP_Term|null
198 198
 	 */
199
-	private function get_term_url( $id ) {
200
-		if ( null === $id ) {
201
-			return isset( $_SERVER['REQUEST_URI'] ) ? filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ) : '';
199
+	private function get_term_url($id) {
200
+		if (null === $id) {
201
+			return isset($_SERVER['REQUEST_URI']) ? filter_var(wp_unslash($_SERVER['REQUEST_URI']), FILTER_SANITIZE_URL) : '';
202 202
 		}
203 203
 
204
-		$maybe_url = get_term_meta( $id, Wordlift_Url_Property_Service::META_KEY, true );
205
-		if ( ! empty( $maybe_url ) ) {
204
+		$maybe_url = get_term_meta($id, Wordlift_Url_Property_Service::META_KEY, true);
205
+		if ( ! empty($maybe_url)) {
206 206
 			return $maybe_url;
207 207
 		}
208 208
 
209
-		return get_term_link( $id );
209
+		return get_term_link($id);
210 210
 	}
211 211
 }
Please login to merge, or discard this patch.
src/modules/events/load.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 use Wordlift\Modules\Events\Term_Entity\Events_Term_Entity_Jsonld;
17 17
 
18 18
 if ( ! defined( 'ABSPATH' ) ) {
19
-	exit;
19
+    exit;
20 20
 }
21 21
 
22 22
 /**
@@ -30,39 +30,39 @@  discard block
 block discarded – undo
30 30
  */
31 31
 function __wl_events__load() {
32 32
 
33
-	// Dashboard is available only for Food Kg and Gardening Kg atm
34
-	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
35
-	if ( ! apply_filters( 'wl_feature__enable__kpi-events', false ) ) {
36
-		return;
37
-	}
33
+    // Dashboard is available only for Food Kg and Gardening Kg atm
34
+    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
35
+    if ( ! apply_filters( 'wl_feature__enable__kpi-events', false ) ) {
36
+        return;
37
+    }
38 38
 
39
-	// Autoloader for plugin itself.
40
-	if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
41
-		require __DIR__ . '/vendor/autoload.php';
42
-	}
39
+    // Autoloader for plugin itself.
40
+    if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
41
+        require __DIR__ . '/vendor/autoload.php';
42
+    }
43 43
 
44
-	$container_builder = new ContainerBuilder();
45
-	$loader            = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) );
46
-	$loader->load( 'services.yml' );
47
-	$container_builder->compile();
44
+    $container_builder = new ContainerBuilder();
45
+    $loader            = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) );
46
+    $loader->load( 'services.yml' );
47
+    $container_builder->compile();
48 48
 
49
-	/**
50
-	 * @var $post_entity Events_Post_Entity_Jsonld
51
-	 */
52
-	$post_entity = $container_builder->get( Events_Post_Entity_Jsonld::class );
53
-	$post_entity->register_hooks();
49
+    /**
50
+     * @var $post_entity Events_Post_Entity_Jsonld
51
+     */
52
+    $post_entity = $container_builder->get( Events_Post_Entity_Jsonld::class );
53
+    $post_entity->register_hooks();
54 54
 
55
-	/**
56
-	 * @var $term_entity Events_Term_Entity_Jsonld
57
-	 */
58
-	$term_entity = $container_builder->get( Events_Term_Entity_Jsonld::class );
59
-	$term_entity->register_hooks();
55
+    /**
56
+     * @var $term_entity Events_Term_Entity_Jsonld
57
+     */
58
+    $term_entity = $container_builder->get( Events_Term_Entity_Jsonld::class );
59
+    $term_entity->register_hooks();
60 60
 
61
-	/**
62
-	 * @var $include_exclude Events_Options_Entity_Include_Exclude
63
-	 */
64
-	$include_exclude = $container_builder->get( Events_Options_Entity_Include_Exclude::class );
65
-	$include_exclude->register_hooks();
61
+    /**
62
+     * @var $include_exclude Events_Options_Entity_Include_Exclude
63
+     */
64
+    $include_exclude = $container_builder->get( Events_Options_Entity_Include_Exclude::class );
65
+    $include_exclude->register_hooks();
66 66
 }
67 67
 
68 68
 add_action( 'plugins_loaded', '__wl_events__load' );
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 use Wordlift\Modules\Events\Post_Entity\Events_Post_Entity_Jsonld;
16 16
 use Wordlift\Modules\Events\Term_Entity\Events_Term_Entity_Jsonld;
17 17
 
18
-if ( ! defined( 'ABSPATH' ) ) {
18
+if ( ! defined('ABSPATH')) {
19 19
 	exit;
20 20
 }
21 21
 
@@ -32,37 +32,37 @@  discard block
 block discarded – undo
32 32
 
33 33
 	// Dashboard is available only for Food Kg and Gardening Kg atm
34 34
 	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
35
-	if ( ! apply_filters( 'wl_feature__enable__kpi-events', false ) ) {
35
+	if ( ! apply_filters('wl_feature__enable__kpi-events', false)) {
36 36
 		return;
37 37
 	}
38 38
 
39 39
 	// Autoloader for plugin itself.
40
-	if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
41
-		require __DIR__ . '/vendor/autoload.php';
40
+	if (file_exists(__DIR__.'/vendor/autoload.php')) {
41
+		require __DIR__.'/vendor/autoload.php';
42 42
 	}
43 43
 
44 44
 	$container_builder = new ContainerBuilder();
45
-	$loader            = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) );
46
-	$loader->load( 'services.yml' );
45
+	$loader            = new YamlFileLoader($container_builder, new FileLocator(__DIR__));
46
+	$loader->load('services.yml');
47 47
 	$container_builder->compile();
48 48
 
49 49
 	/**
50 50
 	 * @var $post_entity Events_Post_Entity_Jsonld
51 51
 	 */
52
-	$post_entity = $container_builder->get( Events_Post_Entity_Jsonld::class );
52
+	$post_entity = $container_builder->get(Events_Post_Entity_Jsonld::class);
53 53
 	$post_entity->register_hooks();
54 54
 
55 55
 	/**
56 56
 	 * @var $term_entity Events_Term_Entity_Jsonld
57 57
 	 */
58
-	$term_entity = $container_builder->get( Events_Term_Entity_Jsonld::class );
58
+	$term_entity = $container_builder->get(Events_Term_Entity_Jsonld::class);
59 59
 	$term_entity->register_hooks();
60 60
 
61 61
 	/**
62 62
 	 * @var $include_exclude Events_Options_Entity_Include_Exclude
63 63
 	 */
64
-	$include_exclude = $container_builder->get( Events_Options_Entity_Include_Exclude::class );
64
+	$include_exclude = $container_builder->get(Events_Options_Entity_Include_Exclude::class);
65 65
 	$include_exclude->register_hooks();
66 66
 }
67 67
 
68
-add_action( 'plugins_loaded', '__wl_events__load' );
68
+add_action('plugins_loaded', '__wl_events__load');
Please login to merge, or discard this patch.
src/modules/events/includes/Post_Entity/Events_Post_Entity_Jsonld.php 2 patches
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -12,198 +12,198 @@
 block discarded – undo
12 12
  */
13 13
 class Events_Post_Entity_Jsonld {
14 14
 
15
-	/**
16
-	 * The {@link Api_Service} used to communicate with the remote APIs.
17
-	 *
18
-	 * @access private
19
-	 * @var Api_Service
20
-	 */
21
-	private $api_service;
22
-
23
-	/**
24
-	 * @param Api_Service $api_service
25
-	 */
26
-	public function __construct( Api_Service $api_service ) {
27
-		$this->api_service = $api_service;
28
-	}
29
-
30
-	/**
31
-	 * Register hooks.
32
-	 */
33
-	public function register_hooks() {
34
-		add_filter( 'wl_after_get_jsonld', array( $this, 'set_events_request' ), 90, 3 );
35
-		add_filter( 'wprm_recipe_metadata', array( $this, '__recipe_metadata' ), PHP_INT_MAX - 100, 2 );
36
-	}
37
-
38
-	/**
39
-	 * Set events request.
40
-	 *
41
-	 * @param $jsonld_arr array The final jsonld before outputting to page.
42
-	 * @param $post_id int The post id for which the jsonld is generated.
43
-	 * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum
44
-	 *
45
-	 * @return array
46
-	 */
47
-	public function set_events_request( $jsonld_arr, $post_id, $context ) {
48
-		if ( $this->should_return_early( $context ) ) {
49
-			return $jsonld_arr;
50
-		}
51
-
52
-		$counts = $this->get_initial_counts_post( $post_id );
53
-
54
-		$change_status = $this->update_counts_if_necessary_post( $jsonld_arr, $counts, $post_id );
55
-
56
-		if ( $change_status ) {
57
-			$this->send_api_request_post( $counts, $post_id );
58
-		}
59
-
60
-		return $jsonld_arr;
61
-	}
62
-
63
-	/**
64
-	 * @param $value
65
-	 * @param \WPRM_Recipe $recipe
66
-	 *
67
-	 * @return mixed
68
-	 */
69
-	public function __recipe_metadata( $value, $recipe ) {
70
-		// We only handle the parent post.
71
-		$parent_post_id = $recipe->parent_post_id();
72
-		if ( is_numeric( $parent_post_id ) && 0 < $parent_post_id ) {
73
-			$this->set_events_request( array( $value ), $parent_post_id, Jsonld_Context_Enum::PAGE );
74
-		}
75
-
76
-		return $value;
77
-	}
78
-
79
-	/**
80
-	 * If context is not PAGE, return early.
81
-	 *
82
-	 * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum
83
-	 *
84
-	 * @return bool
85
-	 */
86
-	private function should_return_early( $context ) {
87
-		return Jsonld_Context_Enum::PAGE !== $context;
88
-	}
89
-
90
-	/**
91
-	 * Fetch the initial 'about' and 'mentions' counts from post meta.
92
-	 *
93
-	 * @param $post_id int The post id for which the jsonld is generated.
94
-	 *
95
-	 * @return int[]
96
-	 */
97
-	private function get_initial_counts_post( $post_id ) {
98
-		return array(
99
-			'about'    => get_post_meta( $post_id, 'wl_about_count', true ) ? (int) get_post_meta( $post_id, 'wl_about_count', true ) : 0,
100
-			'mentions' => get_post_meta( $post_id, 'wl_mentions_count', true )
101
-				? (int) get_post_meta( $post_id, 'wl_mentions_count', true )
102
-				: 0,
103
-		);
104
-	}
105
-
106
-	/**
107
-	 * Update counts if necessary post.
108
-	 *
109
-	 * @param $jsonld_arr
110
-	 * @param $counts
111
-	 * @param $post_id
112
-	 *
113
-	 * @return bool
114
-	 */
115
-	private function update_counts_if_necessary_post( $jsonld_arr, &$counts, $post_id ) {
116
-		// Flag to indicate if we should make an API request.
117
-		$change_status = false;
118
-
119
-		// If the $jsonld_arr is empty but the counts were previously more than 0.
120
-		if ( empty( $jsonld_arr[0] ) ) {
121
-			return $this->reset_counts_if_non_zero_post( $counts, $post_id );
122
-		}
123
-
124
-		// Get data from the array.
125
-		$data = $jsonld_arr[0];
126
-
127
-		// Iterate over the counts array.
128
-		foreach ( $counts as $type => $type_count ) {
129
-			// Check if data has 'about' or 'mentions' and the count is different from the existing meta value.
130
-			if ( isset( $data[ $type ] ) ) {
131
-				$new_count = count( $data[ $type ] );
132
-				if ( $type_count !== $new_count ) {
133
-					// Set flag to true if counts have changed.
134
-					$change_status = true;
135
-
136
-					// Update the counts array with new count.
137
-					$counts[ $type ] = $new_count;
138
-
139
-					// Update post meta with new count.
140
-					update_post_meta( $post_id, 'wl_' . $type . '_count', $new_count );
141
-					continue;
142
-				}
143
-			}
144
-
145
-			if ( $type_count > 0 ) {
146
-				// If the 'about' or 'mentions' has become empty, set it to 0.
147
-				$change_status   = true;
148
-				$counts[ $type ] = 0;
149
-				update_post_meta( $post_id, 'wl_' . $type . '_count', 0 );
150
-			}
151
-		}
152
-
153
-		return $change_status;
154
-	}
155
-
156
-	/**
157
-	 * Reset counts if non zero post.
158
-	 *
159
-	 * @param $counts
160
-	 * @param $post_id
161
-	 *
162
-	 * @return bool
163
-	 */
164
-	private function reset_counts_if_non_zero_post( &$counts, $post_id ) {
165
-		$change_status = false;
166
-
167
-		foreach ( $counts as $type => $type_count ) {
168
-			if ( $type_count > 0 ) {
169
-				$change_status   = true;
170
-				$counts[ $type ] = 0;
171
-				update_post_meta( $post_id, 'wl_' . $type . '_count', 0 );
172
-			}
173
-		}
174
-
175
-		return $change_status;
176
-	}
177
-
178
-	/**
179
-	 * Send api request post.
180
-	 *
181
-	 * @param $counts
182
-	 * @param $post_id
183
-	 */
184
-	private function send_api_request_post( $counts, $post_id ) {
185
-		// If the count has changed, make the API request.
186
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
187
-		$blocking = apply_filters( 'wl_feature__enable__sync-blocking', false );
188
-
189
-		// Apply the filter to the request args
190
-		$this->api_service->request(
191
-			'POST',
192
-			'/plugin/events',
193
-			array( 'Content-Type' => 'application/json' ),
194
-			wp_json_encode(
195
-				array(
196
-					'source' => 'jsonld',
197
-					'args'   => array(
198
-						array( 'about_count' => $counts['about'] ),
199
-						array( 'mentions_count' => $counts['mentions'] ),
200
-					),
201
-					'url'    => get_permalink( $post_id ),
202
-				)
203
-			),
204
-			$blocking ? 60 : 0.001,
205
-			null,
206
-			array( 'blocking' => $blocking )
207
-		);
208
-	}
15
+    /**
16
+     * The {@link Api_Service} used to communicate with the remote APIs.
17
+     *
18
+     * @access private
19
+     * @var Api_Service
20
+     */
21
+    private $api_service;
22
+
23
+    /**
24
+     * @param Api_Service $api_service
25
+     */
26
+    public function __construct( Api_Service $api_service ) {
27
+        $this->api_service = $api_service;
28
+    }
29
+
30
+    /**
31
+     * Register hooks.
32
+     */
33
+    public function register_hooks() {
34
+        add_filter( 'wl_after_get_jsonld', array( $this, 'set_events_request' ), 90, 3 );
35
+        add_filter( 'wprm_recipe_metadata', array( $this, '__recipe_metadata' ), PHP_INT_MAX - 100, 2 );
36
+    }
37
+
38
+    /**
39
+     * Set events request.
40
+     *
41
+     * @param $jsonld_arr array The final jsonld before outputting to page.
42
+     * @param $post_id int The post id for which the jsonld is generated.
43
+     * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum
44
+     *
45
+     * @return array
46
+     */
47
+    public function set_events_request( $jsonld_arr, $post_id, $context ) {
48
+        if ( $this->should_return_early( $context ) ) {
49
+            return $jsonld_arr;
50
+        }
51
+
52
+        $counts = $this->get_initial_counts_post( $post_id );
53
+
54
+        $change_status = $this->update_counts_if_necessary_post( $jsonld_arr, $counts, $post_id );
55
+
56
+        if ( $change_status ) {
57
+            $this->send_api_request_post( $counts, $post_id );
58
+        }
59
+
60
+        return $jsonld_arr;
61
+    }
62
+
63
+    /**
64
+     * @param $value
65
+     * @param \WPRM_Recipe $recipe
66
+     *
67
+     * @return mixed
68
+     */
69
+    public function __recipe_metadata( $value, $recipe ) {
70
+        // We only handle the parent post.
71
+        $parent_post_id = $recipe->parent_post_id();
72
+        if ( is_numeric( $parent_post_id ) && 0 < $parent_post_id ) {
73
+            $this->set_events_request( array( $value ), $parent_post_id, Jsonld_Context_Enum::PAGE );
74
+        }
75
+
76
+        return $value;
77
+    }
78
+
79
+    /**
80
+     * If context is not PAGE, return early.
81
+     *
82
+     * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum
83
+     *
84
+     * @return bool
85
+     */
86
+    private function should_return_early( $context ) {
87
+        return Jsonld_Context_Enum::PAGE !== $context;
88
+    }
89
+
90
+    /**
91
+     * Fetch the initial 'about' and 'mentions' counts from post meta.
92
+     *
93
+     * @param $post_id int The post id for which the jsonld is generated.
94
+     *
95
+     * @return int[]
96
+     */
97
+    private function get_initial_counts_post( $post_id ) {
98
+        return array(
99
+            'about'    => get_post_meta( $post_id, 'wl_about_count', true ) ? (int) get_post_meta( $post_id, 'wl_about_count', true ) : 0,
100
+            'mentions' => get_post_meta( $post_id, 'wl_mentions_count', true )
101
+                ? (int) get_post_meta( $post_id, 'wl_mentions_count', true )
102
+                : 0,
103
+        );
104
+    }
105
+
106
+    /**
107
+     * Update counts if necessary post.
108
+     *
109
+     * @param $jsonld_arr
110
+     * @param $counts
111
+     * @param $post_id
112
+     *
113
+     * @return bool
114
+     */
115
+    private function update_counts_if_necessary_post( $jsonld_arr, &$counts, $post_id ) {
116
+        // Flag to indicate if we should make an API request.
117
+        $change_status = false;
118
+
119
+        // If the $jsonld_arr is empty but the counts were previously more than 0.
120
+        if ( empty( $jsonld_arr[0] ) ) {
121
+            return $this->reset_counts_if_non_zero_post( $counts, $post_id );
122
+        }
123
+
124
+        // Get data from the array.
125
+        $data = $jsonld_arr[0];
126
+
127
+        // Iterate over the counts array.
128
+        foreach ( $counts as $type => $type_count ) {
129
+            // Check if data has 'about' or 'mentions' and the count is different from the existing meta value.
130
+            if ( isset( $data[ $type ] ) ) {
131
+                $new_count = count( $data[ $type ] );
132
+                if ( $type_count !== $new_count ) {
133
+                    // Set flag to true if counts have changed.
134
+                    $change_status = true;
135
+
136
+                    // Update the counts array with new count.
137
+                    $counts[ $type ] = $new_count;
138
+
139
+                    // Update post meta with new count.
140
+                    update_post_meta( $post_id, 'wl_' . $type . '_count', $new_count );
141
+                    continue;
142
+                }
143
+            }
144
+
145
+            if ( $type_count > 0 ) {
146
+                // If the 'about' or 'mentions' has become empty, set it to 0.
147
+                $change_status   = true;
148
+                $counts[ $type ] = 0;
149
+                update_post_meta( $post_id, 'wl_' . $type . '_count', 0 );
150
+            }
151
+        }
152
+
153
+        return $change_status;
154
+    }
155
+
156
+    /**
157
+     * Reset counts if non zero post.
158
+     *
159
+     * @param $counts
160
+     * @param $post_id
161
+     *
162
+     * @return bool
163
+     */
164
+    private function reset_counts_if_non_zero_post( &$counts, $post_id ) {
165
+        $change_status = false;
166
+
167
+        foreach ( $counts as $type => $type_count ) {
168
+            if ( $type_count > 0 ) {
169
+                $change_status   = true;
170
+                $counts[ $type ] = 0;
171
+                update_post_meta( $post_id, 'wl_' . $type . '_count', 0 );
172
+            }
173
+        }
174
+
175
+        return $change_status;
176
+    }
177
+
178
+    /**
179
+     * Send api request post.
180
+     *
181
+     * @param $counts
182
+     * @param $post_id
183
+     */
184
+    private function send_api_request_post( $counts, $post_id ) {
185
+        // If the count has changed, make the API request.
186
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
187
+        $blocking = apply_filters( 'wl_feature__enable__sync-blocking', false );
188
+
189
+        // Apply the filter to the request args
190
+        $this->api_service->request(
191
+            'POST',
192
+            '/plugin/events',
193
+            array( 'Content-Type' => 'application/json' ),
194
+            wp_json_encode(
195
+                array(
196
+                    'source' => 'jsonld',
197
+                    'args'   => array(
198
+                        array( 'about_count' => $counts['about'] ),
199
+                        array( 'mentions_count' => $counts['mentions'] ),
200
+                    ),
201
+                    'url'    => get_permalink( $post_id ),
202
+                )
203
+            ),
204
+            $blocking ? 60 : 0.001,
205
+            null,
206
+            array( 'blocking' => $blocking )
207
+        );
208
+    }
209 209
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	/**
24 24
 	 * @param Api_Service $api_service
25 25
 	 */
26
-	public function __construct( Api_Service $api_service ) {
26
+	public function __construct(Api_Service $api_service) {
27 27
 		$this->api_service = $api_service;
28 28
 	}
29 29
 
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 	 * Register hooks.
32 32
 	 */
33 33
 	public function register_hooks() {
34
-		add_filter( 'wl_after_get_jsonld', array( $this, 'set_events_request' ), 90, 3 );
35
-		add_filter( 'wprm_recipe_metadata', array( $this, '__recipe_metadata' ), PHP_INT_MAX - 100, 2 );
34
+		add_filter('wl_after_get_jsonld', array($this, 'set_events_request'), 90, 3);
35
+		add_filter('wprm_recipe_metadata', array($this, '__recipe_metadata'), PHP_INT_MAX - 100, 2);
36 36
 	}
37 37
 
38 38
 	/**
@@ -44,17 +44,17 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @return array
46 46
 	 */
47
-	public function set_events_request( $jsonld_arr, $post_id, $context ) {
48
-		if ( $this->should_return_early( $context ) ) {
47
+	public function set_events_request($jsonld_arr, $post_id, $context) {
48
+		if ($this->should_return_early($context)) {
49 49
 			return $jsonld_arr;
50 50
 		}
51 51
 
52
-		$counts = $this->get_initial_counts_post( $post_id );
52
+		$counts = $this->get_initial_counts_post($post_id);
53 53
 
54
-		$change_status = $this->update_counts_if_necessary_post( $jsonld_arr, $counts, $post_id );
54
+		$change_status = $this->update_counts_if_necessary_post($jsonld_arr, $counts, $post_id);
55 55
 
56
-		if ( $change_status ) {
57
-			$this->send_api_request_post( $counts, $post_id );
56
+		if ($change_status) {
57
+			$this->send_api_request_post($counts, $post_id);
58 58
 		}
59 59
 
60 60
 		return $jsonld_arr;
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 * @return mixed
68 68
 	 */
69
-	public function __recipe_metadata( $value, $recipe ) {
69
+	public function __recipe_metadata($value, $recipe) {
70 70
 		// We only handle the parent post.
71 71
 		$parent_post_id = $recipe->parent_post_id();
72
-		if ( is_numeric( $parent_post_id ) && 0 < $parent_post_id ) {
73
-			$this->set_events_request( array( $value ), $parent_post_id, Jsonld_Context_Enum::PAGE );
72
+		if (is_numeric($parent_post_id) && 0 < $parent_post_id) {
73
+			$this->set_events_request(array($value), $parent_post_id, Jsonld_Context_Enum::PAGE);
74 74
 		}
75 75
 
76 76
 		return $value;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @return bool
85 85
 	 */
86
-	private function should_return_early( $context ) {
86
+	private function should_return_early($context) {
87 87
 		return Jsonld_Context_Enum::PAGE !== $context;
88 88
 	}
89 89
 
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
 	 *
95 95
 	 * @return int[]
96 96
 	 */
97
-	private function get_initial_counts_post( $post_id ) {
97
+	private function get_initial_counts_post($post_id) {
98 98
 		return array(
99
-			'about'    => get_post_meta( $post_id, 'wl_about_count', true ) ? (int) get_post_meta( $post_id, 'wl_about_count', true ) : 0,
100
-			'mentions' => get_post_meta( $post_id, 'wl_mentions_count', true )
101
-				? (int) get_post_meta( $post_id, 'wl_mentions_count', true )
99
+			'about'    => get_post_meta($post_id, 'wl_about_count', true) ? (int) get_post_meta($post_id, 'wl_about_count', true) : 0,
100
+			'mentions' => get_post_meta($post_id, 'wl_mentions_count', true)
101
+				? (int) get_post_meta($post_id, 'wl_mentions_count', true)
102 102
 				: 0,
103 103
 		);
104 104
 	}
@@ -112,41 +112,41 @@  discard block
 block discarded – undo
112 112
 	 *
113 113
 	 * @return bool
114 114
 	 */
115
-	private function update_counts_if_necessary_post( $jsonld_arr, &$counts, $post_id ) {
115
+	private function update_counts_if_necessary_post($jsonld_arr, &$counts, $post_id) {
116 116
 		// Flag to indicate if we should make an API request.
117 117
 		$change_status = false;
118 118
 
119 119
 		// If the $jsonld_arr is empty but the counts were previously more than 0.
120
-		if ( empty( $jsonld_arr[0] ) ) {
121
-			return $this->reset_counts_if_non_zero_post( $counts, $post_id );
120
+		if (empty($jsonld_arr[0])) {
121
+			return $this->reset_counts_if_non_zero_post($counts, $post_id);
122 122
 		}
123 123
 
124 124
 		// Get data from the array.
125 125
 		$data = $jsonld_arr[0];
126 126
 
127 127
 		// Iterate over the counts array.
128
-		foreach ( $counts as $type => $type_count ) {
128
+		foreach ($counts as $type => $type_count) {
129 129
 			// Check if data has 'about' or 'mentions' and the count is different from the existing meta value.
130
-			if ( isset( $data[ $type ] ) ) {
131
-				$new_count = count( $data[ $type ] );
132
-				if ( $type_count !== $new_count ) {
130
+			if (isset($data[$type])) {
131
+				$new_count = count($data[$type]);
132
+				if ($type_count !== $new_count) {
133 133
 					// Set flag to true if counts have changed.
134 134
 					$change_status = true;
135 135
 
136 136
 					// Update the counts array with new count.
137
-					$counts[ $type ] = $new_count;
137
+					$counts[$type] = $new_count;
138 138
 
139 139
 					// Update post meta with new count.
140
-					update_post_meta( $post_id, 'wl_' . $type . '_count', $new_count );
140
+					update_post_meta($post_id, 'wl_'.$type.'_count', $new_count);
141 141
 					continue;
142 142
 				}
143 143
 			}
144 144
 
145
-			if ( $type_count > 0 ) {
145
+			if ($type_count > 0) {
146 146
 				// If the 'about' or 'mentions' has become empty, set it to 0.
147 147
 				$change_status   = true;
148
-				$counts[ $type ] = 0;
149
-				update_post_meta( $post_id, 'wl_' . $type . '_count', 0 );
148
+				$counts[$type] = 0;
149
+				update_post_meta($post_id, 'wl_'.$type.'_count', 0);
150 150
 			}
151 151
 		}
152 152
 
@@ -161,14 +161,14 @@  discard block
 block discarded – undo
161 161
 	 *
162 162
 	 * @return bool
163 163
 	 */
164
-	private function reset_counts_if_non_zero_post( &$counts, $post_id ) {
164
+	private function reset_counts_if_non_zero_post(&$counts, $post_id) {
165 165
 		$change_status = false;
166 166
 
167
-		foreach ( $counts as $type => $type_count ) {
168
-			if ( $type_count > 0 ) {
167
+		foreach ($counts as $type => $type_count) {
168
+			if ($type_count > 0) {
169 169
 				$change_status   = true;
170
-				$counts[ $type ] = 0;
171
-				update_post_meta( $post_id, 'wl_' . $type . '_count', 0 );
170
+				$counts[$type] = 0;
171
+				update_post_meta($post_id, 'wl_'.$type.'_count', 0);
172 172
 			}
173 173
 		}
174 174
 
@@ -181,29 +181,29 @@  discard block
 block discarded – undo
181 181
 	 * @param $counts
182 182
 	 * @param $post_id
183 183
 	 */
184
-	private function send_api_request_post( $counts, $post_id ) {
184
+	private function send_api_request_post($counts, $post_id) {
185 185
 		// If the count has changed, make the API request.
186 186
 		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
187
-		$blocking = apply_filters( 'wl_feature__enable__sync-blocking', false );
187
+		$blocking = apply_filters('wl_feature__enable__sync-blocking', false);
188 188
 
189 189
 		// Apply the filter to the request args
190 190
 		$this->api_service->request(
191 191
 			'POST',
192 192
 			'/plugin/events',
193
-			array( 'Content-Type' => 'application/json' ),
193
+			array('Content-Type' => 'application/json'),
194 194
 			wp_json_encode(
195 195
 				array(
196 196
 					'source' => 'jsonld',
197 197
 					'args'   => array(
198
-						array( 'about_count' => $counts['about'] ),
199
-						array( 'mentions_count' => $counts['mentions'] ),
198
+						array('about_count' => $counts['about']),
199
+						array('mentions_count' => $counts['mentions']),
200 200
 					),
201
-					'url'    => get_permalink( $post_id ),
201
+					'url'    => get_permalink($post_id),
202 202
 				)
203 203
 			),
204 204
 			$blocking ? 60 : 0.001,
205 205
 			null,
206
-			array( 'blocking' => $blocking )
206
+			array('blocking' => $blocking)
207 207
 		);
208 208
 	}
209 209
 }
Please login to merge, or discard this patch.