Completed
Push — develop ( 5c7568...6a9ba1 )
by David
14:52
created
src/shortcodes/wordlift_shortcode_faceted_search.php 2 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -14,77 +14,77 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wl_shortcode_faceted_search( $atts ) {
16 16
 
17
-	// Extract attributes and set default values.
18
-	$shortcode_atts = shortcode_atts( array(
19
-		'title'          => __( 'Related articles', 'wordlift' ),
20
-		'show_facets'    => true,
21
-		'with_carousel'  => true,
22
-		'squared_thumbs' => false,
23
-		'limit'          => 20,
24
-
25
-	), $atts );
26
-
27
-	foreach (
28
-		array(
29
-			'show_facets',
30
-			'with_carousel',
31
-			'squared_thumbs',
32
-		) as $att
33
-	) {
34
-
35
-		// See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode.
36
-		$shortcode_atts[ $att ] = filter_var(
37
-			$shortcode_atts[ $att ], FILTER_VALIDATE_BOOLEAN
38
-		);
39
-	}
40
-
41
-	// If the current post is not an entity and has no related entities
42
-	// than the shortcode cannot be rendered
43
-	// TODO Add an alert visibile only for connected admin users.
44
-	$current_post = get_post();
45
-
46
-	$entity_service = Wordlift_Entity_Service::get_instance();
47
-	$entity_ids     = $entity_service->is_entity( $current_post->ID ) ?
48
-		array( $current_post->ID ) :
49
-		wl_core_get_related_entity_ids( $current_post->ID );
50
-
51
-	// Bail if there are no entity ids.
52
-	if ( 0 === count( $entity_ids ) ) {
53
-		return '';
54
-	}
55
-
56
-	$div_id = 'wordlift-faceted-entity-search-widget';
57
-
58
-	$deps = apply_filters( 'wl_include_font_awesome', true )
59
-		? array( 'wordlift-font-awesome' )
60
-		: array();
61
-	wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css', $deps, Wordlift::get_instance()->get_version() );
62
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
63
-	wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
64
-
65
-	wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' );
66
-
67
-	wp_localize_script(
68
-		'wordlift-faceted-search',
69
-		'wl_faceted_search_params', array(
70
-			'ajax_url'             => admin_url( 'admin-ajax.php' ),
71
-			'action'               => 'wl_faceted_search',
72
-			'post_id'              => $current_post->ID,
73
-			'entity_ids'           => $entity_ids,
74
-			'limit'                => apply_filters( 'wl_faceted_search_limit', $shortcode_atts['limit'] ),
75
-			'div_id'               => $div_id,
76
-			'defaultThumbnailPath' => WL_DEFAULT_THUMBNAIL_PATH,
77
-			'attrs'                => $shortcode_atts,
78
-			'l10n'                 => array(
79
-				'what'  => _x( 'What', 'Faceted Search Widget', 'wordlift' ),
80
-				'who'   => _x( 'Who', 'Faceted Search Widget', 'wordlift' ),
81
-				'where' => _x( 'Where', 'Faceted Search Widget', 'wordlift' ),
82
-				'when'  => _x( 'When', 'Faceted Search Widget', 'wordlift' ),
83
-			),
84
-		)
85
-	);
86
-
87
-	return '<div id="' . $div_id . '" style="width:100%"></div>';
17
+    // Extract attributes and set default values.
18
+    $shortcode_atts = shortcode_atts( array(
19
+        'title'          => __( 'Related articles', 'wordlift' ),
20
+        'show_facets'    => true,
21
+        'with_carousel'  => true,
22
+        'squared_thumbs' => false,
23
+        'limit'          => 20,
24
+
25
+    ), $atts );
26
+
27
+    foreach (
28
+        array(
29
+            'show_facets',
30
+            'with_carousel',
31
+            'squared_thumbs',
32
+        ) as $att
33
+    ) {
34
+
35
+        // See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode.
36
+        $shortcode_atts[ $att ] = filter_var(
37
+            $shortcode_atts[ $att ], FILTER_VALIDATE_BOOLEAN
38
+        );
39
+    }
40
+
41
+    // If the current post is not an entity and has no related entities
42
+    // than the shortcode cannot be rendered
43
+    // TODO Add an alert visibile only for connected admin users.
44
+    $current_post = get_post();
45
+
46
+    $entity_service = Wordlift_Entity_Service::get_instance();
47
+    $entity_ids     = $entity_service->is_entity( $current_post->ID ) ?
48
+        array( $current_post->ID ) :
49
+        wl_core_get_related_entity_ids( $current_post->ID );
50
+
51
+    // Bail if there are no entity ids.
52
+    if ( 0 === count( $entity_ids ) ) {
53
+        return '';
54
+    }
55
+
56
+    $div_id = 'wordlift-faceted-entity-search-widget';
57
+
58
+    $deps = apply_filters( 'wl_include_font_awesome', true )
59
+        ? array( 'wordlift-font-awesome' )
60
+        : array();
61
+    wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css', $deps, Wordlift::get_instance()->get_version() );
62
+    wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
63
+    wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
64
+
65
+    wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' );
66
+
67
+    wp_localize_script(
68
+        'wordlift-faceted-search',
69
+        'wl_faceted_search_params', array(
70
+            'ajax_url'             => admin_url( 'admin-ajax.php' ),
71
+            'action'               => 'wl_faceted_search',
72
+            'post_id'              => $current_post->ID,
73
+            'entity_ids'           => $entity_ids,
74
+            'limit'                => apply_filters( 'wl_faceted_search_limit', $shortcode_atts['limit'] ),
75
+            'div_id'               => $div_id,
76
+            'defaultThumbnailPath' => WL_DEFAULT_THUMBNAIL_PATH,
77
+            'attrs'                => $shortcode_atts,
78
+            'l10n'                 => array(
79
+                'what'  => _x( 'What', 'Faceted Search Widget', 'wordlift' ),
80
+                'who'   => _x( 'Who', 'Faceted Search Widget', 'wordlift' ),
81
+                'where' => _x( 'Where', 'Faceted Search Widget', 'wordlift' ),
82
+                'when'  => _x( 'When', 'Faceted Search Widget', 'wordlift' ),
83
+            ),
84
+        )
85
+    );
86
+
87
+    return '<div id="' . $div_id . '" style="width:100%"></div>';
88 88
 }
89 89
 
90 90
 add_shortcode( 'wl_faceted_search', 'wl_shortcode_faceted_search' );
@@ -95,114 +95,114 @@  discard block
 block discarded – undo
95 95
  */
96 96
 function wl_shortcode_faceted_search_ajax( $http_raw_data = null ) {
97 97
 
98
-	// Post ID must be defined.
99
-	if ( ! isset( $_GET['post_id'] ) ) { // WPCS: input var ok; CSRF ok.
100
-		wp_die( 'No post_id given' );
101
-
102
-		return;
103
-	}
104
-
105
-	// Extract filtering conditions.
106
-	$filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( 'php://input' ) : $http_raw_data;
107
-	$filtering_entity_uris = json_decode( $filtering_entity_uris );
108
-
109
-	$current_post_id = $_GET['post_id']; // WPCS: input var ok; CSRF ok.
110
-	$current_post    = get_post( $current_post_id );
111
-
112
-	// Post ID has to match an existing item.
113
-	if ( null === $current_post ) {
114
-		wp_die( 'No valid post_id given' );
115
-
116
-		return;
117
-	}
118
-
119
-	// If the current post is an entity,
120
-	// the current post is used as main entity.
121
-	// Otherwise, current post related entities are used.
122
-	$entity_service = Wordlift_Entity_Service::get_instance();
123
-	$entity_ids     = $entity_service->is_entity( $current_post->ID ) ?
124
-		array( $current_post->ID ) :
125
-		wl_core_get_related_entity_ids( $current_post->ID );
126
-
127
-	// If there are no entities we cannot render the widget.
128
-	if ( 0 === count( $entity_ids ) ) {
129
-		wp_die( 'No entities available' );
130
-
131
-		return;
132
-	}
133
-
134
-	// Retrieve requested type
135
-	$required_type = ( isset( $_GET['type'] ) ) ? $_GET['type'] : null; // WPCS: input var ok; CSRF ok.
136
-
137
-	$limit = ( isset( $_GET['limit'] ) ) ? (int) $_GET['limit'] : 20;  // WPCS: input var ok; CSRF ok.
138
-
139
-	$referencing_posts = Wordlift_Relation_Service::get_instance()->get_article_subjects(
140
-		$entity_ids,
141
-		'*',
142
-		null,
143
-		'publish',
144
-		array( $current_post_id ),
145
-		$limit
146
-	);
147
-
148
-	$referencing_post_ids = array_map( function ( $p ) {
149
-		return $p->ID;
150
-	}, $referencing_posts );
151
-	$results              = array();
152
-
153
-	if ( 'posts' === $required_type ) {
154
-
155
-		// Required filtered posts.
156
-		wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" );
157
-
158
-		$filtered_posts = ( empty( $filtering_entity_uris ) ) ?
159
-			$referencing_posts :
160
-			Wordlift_Relation_Service::get_instance()->get_article_subjects(
161
-				wl_get_entity_post_ids_by_uris( $filtering_entity_uris ),
162
-				'*',
163
-				null,
164
-				null,
165
-				array(),
166
-				null,
167
-				$referencing_post_ids
168
-			);
169
-
170
-		if ( $filtered_posts ) {
171
-			foreach ( $filtered_posts as $post_obj ) {
172
-
173
-				/**
174
-				 * Use the thumbnail.
175
-				 *
176
-				 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
177
-				 * @see https://github.com/insideout10/wordlift-plugin/issues/837
178
-				 *
179
-				 * @since 3.19.3 We're using the medium size image.
180
-				 */
181
-				$thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
182
-				$post_obj->thumbnail = ( $thumbnail ) ?
183
-					$thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
184
-				$post_obj->permalink = get_post_permalink( $post_obj->ID );
185
-
186
-				$results[] = $post_obj;
187
-			}
188
-		}
189
-	} else {
190
-
191
-		global $wpdb;
192
-
193
-		wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" );
194
-
195
-		// Retrieve Wordlift relation instances table name.
196
-		$table_name = wl_core_get_relation_instances_table_name();
197
-
198
-		/*
98
+    // Post ID must be defined.
99
+    if ( ! isset( $_GET['post_id'] ) ) { // WPCS: input var ok; CSRF ok.
100
+        wp_die( 'No post_id given' );
101
+
102
+        return;
103
+    }
104
+
105
+    // Extract filtering conditions.
106
+    $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( 'php://input' ) : $http_raw_data;
107
+    $filtering_entity_uris = json_decode( $filtering_entity_uris );
108
+
109
+    $current_post_id = $_GET['post_id']; // WPCS: input var ok; CSRF ok.
110
+    $current_post    = get_post( $current_post_id );
111
+
112
+    // Post ID has to match an existing item.
113
+    if ( null === $current_post ) {
114
+        wp_die( 'No valid post_id given' );
115
+
116
+        return;
117
+    }
118
+
119
+    // If the current post is an entity,
120
+    // the current post is used as main entity.
121
+    // Otherwise, current post related entities are used.
122
+    $entity_service = Wordlift_Entity_Service::get_instance();
123
+    $entity_ids     = $entity_service->is_entity( $current_post->ID ) ?
124
+        array( $current_post->ID ) :
125
+        wl_core_get_related_entity_ids( $current_post->ID );
126
+
127
+    // If there are no entities we cannot render the widget.
128
+    if ( 0 === count( $entity_ids ) ) {
129
+        wp_die( 'No entities available' );
130
+
131
+        return;
132
+    }
133
+
134
+    // Retrieve requested type
135
+    $required_type = ( isset( $_GET['type'] ) ) ? $_GET['type'] : null; // WPCS: input var ok; CSRF ok.
136
+
137
+    $limit = ( isset( $_GET['limit'] ) ) ? (int) $_GET['limit'] : 20;  // WPCS: input var ok; CSRF ok.
138
+
139
+    $referencing_posts = Wordlift_Relation_Service::get_instance()->get_article_subjects(
140
+        $entity_ids,
141
+        '*',
142
+        null,
143
+        'publish',
144
+        array( $current_post_id ),
145
+        $limit
146
+    );
147
+
148
+    $referencing_post_ids = array_map( function ( $p ) {
149
+        return $p->ID;
150
+    }, $referencing_posts );
151
+    $results              = array();
152
+
153
+    if ( 'posts' === $required_type ) {
154
+
155
+        // Required filtered posts.
156
+        wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" );
157
+
158
+        $filtered_posts = ( empty( $filtering_entity_uris ) ) ?
159
+            $referencing_posts :
160
+            Wordlift_Relation_Service::get_instance()->get_article_subjects(
161
+                wl_get_entity_post_ids_by_uris( $filtering_entity_uris ),
162
+                '*',
163
+                null,
164
+                null,
165
+                array(),
166
+                null,
167
+                $referencing_post_ids
168
+            );
169
+
170
+        if ( $filtered_posts ) {
171
+            foreach ( $filtered_posts as $post_obj ) {
172
+
173
+                /**
174
+                 * Use the thumbnail.
175
+                 *
176
+                 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
177
+                 * @see https://github.com/insideout10/wordlift-plugin/issues/837
178
+                 *
179
+                 * @since 3.19.3 We're using the medium size image.
180
+                 */
181
+                $thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
182
+                $post_obj->thumbnail = ( $thumbnail ) ?
183
+                    $thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
184
+                $post_obj->permalink = get_post_permalink( $post_obj->ID );
185
+
186
+                $results[] = $post_obj;
187
+            }
188
+        }
189
+    } else {
190
+
191
+        global $wpdb;
192
+
193
+        wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" );
194
+
195
+        // Retrieve Wordlift relation instances table name.
196
+        $table_name = wl_core_get_relation_instances_table_name();
197
+
198
+        /*
199 199
 		 * Make sure we have some referenced post, otherwise the IN parts of
200 200
 		 * the SQL will produce an SQL error.
201 201
 		 */
202
-		if ( ! empty( $referencing_post_ids ) ) {
203
-			$subject_ids = implode( ',', $referencing_post_ids );
202
+        if ( ! empty( $referencing_post_ids ) ) {
203
+            $subject_ids = implode( ',', $referencing_post_ids );
204 204
 
205
-			$query = "
205
+            $query = "
206 206
 				SELECT
207 207
 					object_id AS ID,
208 208
 					count( object_id ) AS counter
@@ -214,30 +214,30 @@  discard block
 block discarded – undo
214 214
 				LIMIT $limit;
215 215
 			";
216 216
 
217
-			wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" );
217
+            wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" );
218 218
 
219
-			$entities = $wpdb->get_results( $query, OBJECT ); // No cache ok.
219
+            $entities = $wpdb->get_results( $query, OBJECT ); // No cache ok.
220 220
 
221
-			wl_write_log( 'Entities found ' . count( $entities ) );
221
+            wl_write_log( 'Entities found ' . count( $entities ) );
222 222
 
223
-			foreach ( $entities as $obj ) {
223
+            foreach ( $entities as $obj ) {
224 224
 
225
-				$entity = get_post( $obj->ID );
225
+                $entity = get_post( $obj->ID );
226 226
 
227
-				// Ensure only valid and published entities are returned.
228
-				if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) {
227
+                // Ensure only valid and published entities are returned.
228
+                if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) {
229 229
 
230
-					$serialized_entity              = wl_serialize_entity( $entity );
231
-					$serialized_entity['counter']   = $obj->counter;
232
-					$serialized_entity['createdAt'] = $entity->post_date;
230
+                    $serialized_entity              = wl_serialize_entity( $entity );
231
+                    $serialized_entity['counter']   = $obj->counter;
232
+                    $serialized_entity['createdAt'] = $entity->post_date;
233 233
 
234
-					$results[] = $serialized_entity;
235
-				}
236
-			}
237
-		}
238
-	}
234
+                    $results[] = $serialized_entity;
235
+                }
236
+            }
237
+        }
238
+    }
239 239
 
240
-	wl_core_send_json( $results );
240
+    wl_core_send_json( $results );
241 241
 
242 242
 }
243 243
 
Please login to merge, or discard this patch.
Spacing   +63 added lines, -66 removed lines patch added patch discarded remove patch
@@ -12,17 +12,17 @@  discard block
 block discarded – undo
12 12
  *
13 13
  * @param array $atts Shortcode attributes.
14 14
  */
15
-function wl_shortcode_faceted_search( $atts ) {
15
+function wl_shortcode_faceted_search($atts) {
16 16
 
17 17
 	// Extract attributes and set default values.
18
-	$shortcode_atts = shortcode_atts( array(
19
-		'title'          => __( 'Related articles', 'wordlift' ),
18
+	$shortcode_atts = shortcode_atts(array(
19
+		'title'          => __('Related articles', 'wordlift'),
20 20
 		'show_facets'    => true,
21 21
 		'with_carousel'  => true,
22 22
 		'squared_thumbs' => false,
23 23
 		'limit'          => 20,
24 24
 
25
-	), $atts );
25
+	), $atts);
26 26
 
27 27
 	foreach (
28 28
 		array(
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 	) {
34 34
 
35 35
 		// See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode.
36
-		$shortcode_atts[ $att ] = filter_var(
37
-			$shortcode_atts[ $att ], FILTER_VALIDATE_BOOLEAN
36
+		$shortcode_atts[$att] = filter_var(
37
+			$shortcode_atts[$att], FILTER_VALIDATE_BOOLEAN
38 38
 		);
39 39
 	}
40 40
 
@@ -44,74 +44,73 @@  discard block
 block discarded – undo
44 44
 	$current_post = get_post();
45 45
 
46 46
 	$entity_service = Wordlift_Entity_Service::get_instance();
47
-	$entity_ids     = $entity_service->is_entity( $current_post->ID ) ?
48
-		array( $current_post->ID ) :
49
-		wl_core_get_related_entity_ids( $current_post->ID );
47
+	$entity_ids     = $entity_service->is_entity($current_post->ID) ?
48
+		array($current_post->ID) : wl_core_get_related_entity_ids($current_post->ID);
50 49
 
51 50
 	// Bail if there are no entity ids.
52
-	if ( 0 === count( $entity_ids ) ) {
51
+	if (0 === count($entity_ids)) {
53 52
 		return '';
54 53
 	}
55 54
 
56 55
 	$div_id = 'wordlift-faceted-entity-search-widget';
57 56
 
58
-	$deps = apply_filters( 'wl_include_font_awesome', true )
59
-		? array( 'wordlift-font-awesome' )
57
+	$deps = apply_filters('wl_include_font_awesome', true)
58
+		? array('wordlift-font-awesome')
60 59
 		: array();
61
-	wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css', $deps, Wordlift::get_instance()->get_version() );
62
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
63
-	wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
60
+	wp_enqueue_style('wordlift-faceted-search', dirname(plugin_dir_url(__FILE__)).'/css/wordlift-faceted-entity-search-widget.min.css', $deps, Wordlift::get_instance()->get_version());
61
+	wp_enqueue_script('angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js');
62
+	wp_enqueue_script('angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js');
64 63
 
65
-	wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' );
64
+	wp_enqueue_script('wordlift-faceted-search', dirname(plugin_dir_url(__FILE__)).'/js/wordlift-faceted-entity-search-widget.min.js');
66 65
 
67 66
 	wp_localize_script(
68 67
 		'wordlift-faceted-search',
69 68
 		'wl_faceted_search_params', array(
70
-			'ajax_url'             => admin_url( 'admin-ajax.php' ),
69
+			'ajax_url'             => admin_url('admin-ajax.php'),
71 70
 			'action'               => 'wl_faceted_search',
72 71
 			'post_id'              => $current_post->ID,
73 72
 			'entity_ids'           => $entity_ids,
74
-			'limit'                => apply_filters( 'wl_faceted_search_limit', $shortcode_atts['limit'] ),
73
+			'limit'                => apply_filters('wl_faceted_search_limit', $shortcode_atts['limit']),
75 74
 			'div_id'               => $div_id,
76 75
 			'defaultThumbnailPath' => WL_DEFAULT_THUMBNAIL_PATH,
77 76
 			'attrs'                => $shortcode_atts,
78 77
 			'l10n'                 => array(
79
-				'what'  => _x( 'What', 'Faceted Search Widget', 'wordlift' ),
80
-				'who'   => _x( 'Who', 'Faceted Search Widget', 'wordlift' ),
81
-				'where' => _x( 'Where', 'Faceted Search Widget', 'wordlift' ),
82
-				'when'  => _x( 'When', 'Faceted Search Widget', 'wordlift' ),
78
+				'what'  => _x('What', 'Faceted Search Widget', 'wordlift'),
79
+				'who'   => _x('Who', 'Faceted Search Widget', 'wordlift'),
80
+				'where' => _x('Where', 'Faceted Search Widget', 'wordlift'),
81
+				'when'  => _x('When', 'Faceted Search Widget', 'wordlift'),
83 82
 			),
84 83
 		)
85 84
 	);
86 85
 
87
-	return '<div id="' . $div_id . '" style="width:100%"></div>';
86
+	return '<div id="'.$div_id.'" style="width:100%"></div>';
88 87
 }
89 88
 
90
-add_shortcode( 'wl_faceted_search', 'wl_shortcode_faceted_search' );
89
+add_shortcode('wl_faceted_search', 'wl_shortcode_faceted_search');
91 90
 
92 91
 
93 92
 /**
94 93
  * Ajax call for the faceted search widget
95 94
  */
96
-function wl_shortcode_faceted_search_ajax( $http_raw_data = null ) {
95
+function wl_shortcode_faceted_search_ajax($http_raw_data = null) {
97 96
 
98 97
 	// Post ID must be defined.
99
-	if ( ! isset( $_GET['post_id'] ) ) { // WPCS: input var ok; CSRF ok.
100
-		wp_die( 'No post_id given' );
98
+	if ( ! isset($_GET['post_id'])) { // WPCS: input var ok; CSRF ok.
99
+		wp_die('No post_id given');
101 100
 
102 101
 		return;
103 102
 	}
104 103
 
105 104
 	// Extract filtering conditions.
106
-	$filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( 'php://input' ) : $http_raw_data;
107
-	$filtering_entity_uris = json_decode( $filtering_entity_uris );
105
+	$filtering_entity_uris = (null == $http_raw_data) ? file_get_contents('php://input') : $http_raw_data;
106
+	$filtering_entity_uris = json_decode($filtering_entity_uris);
108 107
 
109 108
 	$current_post_id = $_GET['post_id']; // WPCS: input var ok; CSRF ok.
110
-	$current_post    = get_post( $current_post_id );
109
+	$current_post    = get_post($current_post_id);
111 110
 
112 111
 	// Post ID has to match an existing item.
113
-	if ( null === $current_post ) {
114
-		wp_die( 'No valid post_id given' );
112
+	if (null === $current_post) {
113
+		wp_die('No valid post_id given');
115 114
 
116 115
 		return;
117 116
 	}
@@ -120,45 +119,43 @@  discard block
 block discarded – undo
120 119
 	// the current post is used as main entity.
121 120
 	// Otherwise, current post related entities are used.
122 121
 	$entity_service = Wordlift_Entity_Service::get_instance();
123
-	$entity_ids     = $entity_service->is_entity( $current_post->ID ) ?
124
-		array( $current_post->ID ) :
125
-		wl_core_get_related_entity_ids( $current_post->ID );
122
+	$entity_ids     = $entity_service->is_entity($current_post->ID) ?
123
+		array($current_post->ID) : wl_core_get_related_entity_ids($current_post->ID);
126 124
 
127 125
 	// If there are no entities we cannot render the widget.
128
-	if ( 0 === count( $entity_ids ) ) {
129
-		wp_die( 'No entities available' );
126
+	if (0 === count($entity_ids)) {
127
+		wp_die('No entities available');
130 128
 
131 129
 		return;
132 130
 	}
133 131
 
134 132
 	// Retrieve requested type
135
-	$required_type = ( isset( $_GET['type'] ) ) ? $_GET['type'] : null; // WPCS: input var ok; CSRF ok.
133
+	$required_type = (isset($_GET['type'])) ? $_GET['type'] : null; // WPCS: input var ok; CSRF ok.
136 134
 
137
-	$limit = ( isset( $_GET['limit'] ) ) ? (int) $_GET['limit'] : 20;  // WPCS: input var ok; CSRF ok.
135
+	$limit = (isset($_GET['limit'])) ? (int) $_GET['limit'] : 20; // WPCS: input var ok; CSRF ok.
138 136
 
139 137
 	$referencing_posts = Wordlift_Relation_Service::get_instance()->get_article_subjects(
140 138
 		$entity_ids,
141 139
 		'*',
142 140
 		null,
143 141
 		'publish',
144
-		array( $current_post_id ),
142
+		array($current_post_id),
145 143
 		$limit
146 144
 	);
147 145
 
148
-	$referencing_post_ids = array_map( function ( $p ) {
146
+	$referencing_post_ids = array_map(function($p) {
149 147
 		return $p->ID;
150
-	}, $referencing_posts );
148
+	}, $referencing_posts);
151 149
 	$results              = array();
152 150
 
153
-	if ( 'posts' === $required_type ) {
151
+	if ('posts' === $required_type) {
154 152
 
155 153
 		// Required filtered posts.
156
-		wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" );
154
+		wl_write_log("Going to find related posts for the current post [ post ID :: $current_post_id ]");
157 155
 
158
-		$filtered_posts = ( empty( $filtering_entity_uris ) ) ?
159
-			$referencing_posts :
160
-			Wordlift_Relation_Service::get_instance()->get_article_subjects(
161
-				wl_get_entity_post_ids_by_uris( $filtering_entity_uris ),
156
+		$filtered_posts = (empty($filtering_entity_uris)) ?
157
+			$referencing_posts : Wordlift_Relation_Service::get_instance()->get_article_subjects(
158
+				wl_get_entity_post_ids_by_uris($filtering_entity_uris),
162 159
 				'*',
163 160
 				null,
164 161
 				null,
@@ -167,8 +164,8 @@  discard block
 block discarded – undo
167 164
 				$referencing_post_ids
168 165
 			);
169 166
 
170
-		if ( $filtered_posts ) {
171
-			foreach ( $filtered_posts as $post_obj ) {
167
+		if ($filtered_posts) {
168
+			foreach ($filtered_posts as $post_obj) {
172 169
 
173 170
 				/**
174 171
 				 * Use the thumbnail.
@@ -178,10 +175,10 @@  discard block
 block discarded – undo
178 175
 				 *
179 176
 				 * @since 3.19.3 We're using the medium size image.
180 177
 				 */
181
-				$thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
182
-				$post_obj->thumbnail = ( $thumbnail ) ?
178
+				$thumbnail           = get_the_post_thumbnail_url($post_obj, 'medium');
179
+				$post_obj->thumbnail = ($thumbnail) ?
183 180
 					$thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
184
-				$post_obj->permalink = get_post_permalink( $post_obj->ID );
181
+				$post_obj->permalink = get_post_permalink($post_obj->ID);
185 182
 
186 183
 				$results[] = $post_obj;
187 184
 			}
@@ -190,7 +187,7 @@  discard block
 block discarded – undo
190 187
 
191 188
 		global $wpdb;
192 189
 
193
-		wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" );
190
+		wl_write_log("Going to find related entities for the current post [ post ID :: $current_post_id ]");
194 191
 
195 192
 		// Retrieve Wordlift relation instances table name.
196 193
 		$table_name = wl_core_get_relation_instances_table_name();
@@ -199,8 +196,8 @@  discard block
 block discarded – undo
199 196
 		 * Make sure we have some referenced post, otherwise the IN parts of
200 197
 		 * the SQL will produce an SQL error.
201 198
 		 */
202
-		if ( ! empty( $referencing_post_ids ) ) {
203
-			$subject_ids = implode( ',', $referencing_post_ids );
199
+		if ( ! empty($referencing_post_ids)) {
200
+			$subject_ids = implode(',', $referencing_post_ids);
204 201
 
205 202
 			$query = "
206 203
 				SELECT
@@ -214,20 +211,20 @@  discard block
 block discarded – undo
214 211
 				LIMIT $limit;
215 212
 			";
216 213
 
217
-			wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" );
214
+			wl_write_log("Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]");
218 215
 
219
-			$entities = $wpdb->get_results( $query, OBJECT ); // No cache ok.
216
+			$entities = $wpdb->get_results($query, OBJECT); // No cache ok.
220 217
 
221
-			wl_write_log( 'Entities found ' . count( $entities ) );
218
+			wl_write_log('Entities found '.count($entities));
222 219
 
223
-			foreach ( $entities as $obj ) {
220
+			foreach ($entities as $obj) {
224 221
 
225
-				$entity = get_post( $obj->ID );
222
+				$entity = get_post($obj->ID);
226 223
 
227 224
 				// Ensure only valid and published entities are returned.
228
-				if ( ( null !== $entity ) && ( 'publish' === $entity->post_status ) ) {
225
+				if ((null !== $entity) && ('publish' === $entity->post_status)) {
229 226
 
230
-					$serialized_entity              = wl_serialize_entity( $entity );
227
+					$serialized_entity              = wl_serialize_entity($entity);
231 228
 					$serialized_entity['counter']   = $obj->counter;
232 229
 					$serialized_entity['createdAt'] = $entity->post_date;
233 230
 
@@ -237,9 +234,9 @@  discard block
 block discarded – undo
237 234
 		}
238 235
 	}
239 236
 
240
-	wl_core_send_json( $results );
237
+	wl_core_send_json($results);
241 238
 
242 239
 }
243 240
 
244
-add_action( 'wp_ajax_wl_faceted_search', 'wl_shortcode_faceted_search_ajax' );
245
-add_action( 'wp_ajax_nopriv_wl_faceted_search', 'wl_shortcode_faceted_search_ajax' );
241
+add_action('wp_ajax_wl_faceted_search', 'wl_shortcode_faceted_search_ajax');
242
+add_action('wp_ajax_nopriv_wl_faceted_search', 'wl_shortcode_faceted_search_ajax');
Please login to merge, or discard this patch.
src/shortcodes/wordlift_shortcode_navigator.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -14,102 +14,102 @@
 block discarded – undo
14 14
  */
15 15
 function wl_shortcode_navigator_ajax() {
16 16
 
17
-	// Post ID must be defined
18
-	if ( ! isset( $_GET['post_id'] ) ) {
19
-		wp_die( 'No post_id given' );
17
+    // Post ID must be defined
18
+    if ( ! isset( $_GET['post_id'] ) ) {
19
+        wp_die( 'No post_id given' );
20 20
 
21
-		return;
22
-	}
21
+        return;
22
+    }
23 23
 
24
-	$current_post_id = $_GET['post_id'];
25
-	$current_post    = get_post( $current_post_id );
24
+    $current_post_id = $_GET['post_id'];
25
+    $current_post    = get_post( $current_post_id );
26 26
 
27
-	// Post ID has to match an existing item
28
-	if ( null === $current_post ) {
29
-		wp_die( 'No valid post_id given' );
27
+    // Post ID has to match an existing item
28
+    if ( null === $current_post ) {
29
+        wp_die( 'No valid post_id given' );
30 30
 
31
-		return;
32
-	}
31
+        return;
32
+    }
33 33
 
34
-	// prepare structures to memorize other related posts
35
-	$results          = array();
36
-	$blacklist_ids    = array( $current_post_id );
37
-	$related_entities = array();
34
+    // prepare structures to memorize other related posts
35
+    $results          = array();
36
+    $blacklist_ids    = array( $current_post_id );
37
+    $related_entities = array();
38 38
 
39 39
 
40
-	$relation_service = Wordlift_Relation_Service::get_instance();
40
+    $relation_service = Wordlift_Relation_Service::get_instance();
41 41
 
42
-	// Get the related entities, ordering them by WHO, WHAT, WHERE, WHEN 
43
-	// TODO Replace with a single query if it is possible
44
-	// We select in inverse order to give priority to less used entities 
45
-	foreach (
46
-		array(
47
-			WL_WHEN_RELATION,
48
-			WL_WHERE_RELATION,
49
-			WL_WHAT_RELATION,
50
-			WL_WHO_RELATION,
51
-		) as $predicate
52
-	) {
42
+    // Get the related entities, ordering them by WHO, WHAT, WHERE, WHEN 
43
+    // TODO Replace with a single query if it is possible
44
+    // We select in inverse order to give priority to less used entities 
45
+    foreach (
46
+        array(
47
+            WL_WHEN_RELATION,
48
+            WL_WHERE_RELATION,
49
+            WL_WHAT_RELATION,
50
+            WL_WHO_RELATION,
51
+        ) as $predicate
52
+    ) {
53 53
 
54
-		$related_entities = array_merge( $related_entities,
55
-			$relation_service->get_objects( $current_post_id, '*', $predicate, 'publish' )
54
+        $related_entities = array_merge( $related_entities,
55
+            $relation_service->get_objects( $current_post_id, '*', $predicate, 'publish' )
56 56
 //			wl_core_get_related_entities( $current_post_id, array(
57 57
 //					'predicate' => $predicate,
58 58
 //					'status'    => 'publish',
59 59
 //				)
60
-		);
61
-
62
-	}
63
-
64
-	foreach ( $related_entities as $related_entity ) {
65
-
66
-		// take the id of posts referencing the entity
67
-		$referencing_posts = Wordlift_Relation_Service::get_instance()->get_article_subjects( $related_entity->ID, '*', null, 'publish' );
68
-
69
-		// loop over them and take the first one which is not already in the $related_posts
70
-		foreach ( $referencing_posts as $referencing_post ) {
71
-
72
-			if ( ! in_array( $referencing_post->ID, $blacklist_ids ) ) {
73
-
74
-				$blacklist_ids[]   = $referencing_post->ID;
75
-				$serialized_entity = wl_serialize_entity( $related_entity );
76
-
77
-				/**
78
-				 * Use the thumbnail.
79
-				 *
80
-				 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
81
-				 * @see https://github.com/insideout10/wordlift-plugin/issues/837
82
-				 *
83
-				 * @since 3.19.3 We're using the medium size image.
84
-				 */
85
-				$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
86
-
87
-				if ( $thumbnail ) {
88
-
89
-					$results[] = array(
90
-						'post'   => array(
91
-							'permalink' => get_post_permalink( $referencing_post->ID ),
92
-							'title'     => $referencing_post->post_title,
93
-							'thumbnail' => $thumbnail,
94
-						),
95
-						'entity' => array(
96
-							'label'     => $serialized_entity['label'],
97
-							'mainType'  => $serialized_entity['mainType'],
98
-							'permalink' => get_post_permalink( $related_entity->ID ),
99
-						),
100
-					);
101
-
102
-					// Be sure no more than 1 post for entity is returned
103
-					break;
104
-				}
105
-			}
106
-		}
107
-	}
108
-
109
-	// Return first 4 results in json accordingly to 4 columns layout
110
-	wl_core_send_json(
111
-		array_slice( array_reverse( $results ), 0, 4 )
112
-	);
60
+        );
61
+
62
+    }
63
+
64
+    foreach ( $related_entities as $related_entity ) {
65
+
66
+        // take the id of posts referencing the entity
67
+        $referencing_posts = Wordlift_Relation_Service::get_instance()->get_article_subjects( $related_entity->ID, '*', null, 'publish' );
68
+
69
+        // loop over them and take the first one which is not already in the $related_posts
70
+        foreach ( $referencing_posts as $referencing_post ) {
71
+
72
+            if ( ! in_array( $referencing_post->ID, $blacklist_ids ) ) {
73
+
74
+                $blacklist_ids[]   = $referencing_post->ID;
75
+                $serialized_entity = wl_serialize_entity( $related_entity );
76
+
77
+                /**
78
+                 * Use the thumbnail.
79
+                 *
80
+                 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
81
+                 * @see https://github.com/insideout10/wordlift-plugin/issues/837
82
+                 *
83
+                 * @since 3.19.3 We're using the medium size image.
84
+                 */
85
+                $thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
86
+
87
+                if ( $thumbnail ) {
88
+
89
+                    $results[] = array(
90
+                        'post'   => array(
91
+                            'permalink' => get_post_permalink( $referencing_post->ID ),
92
+                            'title'     => $referencing_post->post_title,
93
+                            'thumbnail' => $thumbnail,
94
+                        ),
95
+                        'entity' => array(
96
+                            'label'     => $serialized_entity['label'],
97
+                            'mainType'  => $serialized_entity['mainType'],
98
+                            'permalink' => get_post_permalink( $related_entity->ID ),
99
+                        ),
100
+                    );
101
+
102
+                    // Be sure no more than 1 post for entity is returned
103
+                    break;
104
+                }
105
+            }
106
+        }
107
+    }
108
+
109
+    // Return first 4 results in json accordingly to 4 columns layout
110
+    wl_core_send_json(
111
+        array_slice( array_reverse( $results ), 0, 4 )
112
+    );
113 113
 }
114 114
 
115 115
 ///**
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -15,25 +15,25 @@  discard block
 block discarded – undo
15 15
 function wl_shortcode_navigator_ajax() {
16 16
 
17 17
 	// Post ID must be defined
18
-	if ( ! isset( $_GET['post_id'] ) ) {
19
-		wp_die( 'No post_id given' );
18
+	if ( ! isset($_GET['post_id'])) {
19
+		wp_die('No post_id given');
20 20
 
21 21
 		return;
22 22
 	}
23 23
 
24 24
 	$current_post_id = $_GET['post_id'];
25
-	$current_post    = get_post( $current_post_id );
25
+	$current_post    = get_post($current_post_id);
26 26
 
27 27
 	// Post ID has to match an existing item
28
-	if ( null === $current_post ) {
29
-		wp_die( 'No valid post_id given' );
28
+	if (null === $current_post) {
29
+		wp_die('No valid post_id given');
30 30
 
31 31
 		return;
32 32
 	}
33 33
 
34 34
 	// prepare structures to memorize other related posts
35 35
 	$results          = array();
36
-	$blacklist_ids    = array( $current_post_id );
36
+	$blacklist_ids    = array($current_post_id);
37 37
 	$related_entities = array();
38 38
 
39 39
 
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 		) as $predicate
52 52
 	) {
53 53
 
54
-		$related_entities = array_merge( $related_entities,
55
-			$relation_service->get_objects( $current_post_id, '*', $predicate, 'publish' )
54
+		$related_entities = array_merge($related_entities,
55
+			$relation_service->get_objects($current_post_id, '*', $predicate, 'publish')
56 56
 //			wl_core_get_related_entities( $current_post_id, array(
57 57
 //					'predicate' => $predicate,
58 58
 //					'status'    => 'publish',
@@ -61,18 +61,18 @@  discard block
 block discarded – undo
61 61
 
62 62
 	}
63 63
 
64
-	foreach ( $related_entities as $related_entity ) {
64
+	foreach ($related_entities as $related_entity) {
65 65
 
66 66
 		// take the id of posts referencing the entity
67
-		$referencing_posts = Wordlift_Relation_Service::get_instance()->get_article_subjects( $related_entity->ID, '*', null, 'publish' );
67
+		$referencing_posts = Wordlift_Relation_Service::get_instance()->get_article_subjects($related_entity->ID, '*', null, 'publish');
68 68
 
69 69
 		// loop over them and take the first one which is not already in the $related_posts
70
-		foreach ( $referencing_posts as $referencing_post ) {
70
+		foreach ($referencing_posts as $referencing_post) {
71 71
 
72
-			if ( ! in_array( $referencing_post->ID, $blacklist_ids ) ) {
72
+			if ( ! in_array($referencing_post->ID, $blacklist_ids)) {
73 73
 
74 74
 				$blacklist_ids[]   = $referencing_post->ID;
75
-				$serialized_entity = wl_serialize_entity( $related_entity );
75
+				$serialized_entity = wl_serialize_entity($related_entity);
76 76
 
77 77
 				/**
78 78
 				 * Use the thumbnail.
@@ -82,20 +82,20 @@  discard block
 block discarded – undo
82 82
 				 *
83 83
 				 * @since 3.19.3 We're using the medium size image.
84 84
 				 */
85
-				$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
85
+				$thumbnail = get_the_post_thumbnail_url($referencing_post, 'medium');
86 86
 
87
-				if ( $thumbnail ) {
87
+				if ($thumbnail) {
88 88
 
89 89
 					$results[] = array(
90 90
 						'post'   => array(
91
-							'permalink' => get_post_permalink( $referencing_post->ID ),
91
+							'permalink' => get_post_permalink($referencing_post->ID),
92 92
 							'title'     => $referencing_post->post_title,
93 93
 							'thumbnail' => $thumbnail,
94 94
 						),
95 95
 						'entity' => array(
96 96
 							'label'     => $serialized_entity['label'],
97 97
 							'mainType'  => $serialized_entity['mainType'],
98
-							'permalink' => get_post_permalink( $related_entity->ID ),
98
+							'permalink' => get_post_permalink($related_entity->ID),
99 99
 						),
100 100
 					);
101 101
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 
109 109
 	// Return first 4 results in json accordingly to 4 columns layout
110 110
 	wl_core_send_json(
111
-		array_slice( array_reverse( $results ), 0, 4 )
111
+		array_slice(array_reverse($results), 0, 4)
112 112
 	);
113 113
 }
114 114
 
@@ -164,6 +164,6 @@  discard block
 block discarded – undo
164 164
 //}
165 165
 
166 166
 //add_action( 'init', 'wordlift_register_shortcode_navigator' );
167
-add_action( 'wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax' );
168
-add_action( 'wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax' );
167
+add_action('wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax');
168
+add_action('wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax');
169 169
 
Please login to merge, or discard this patch.
src/wordlift_constants.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -6,61 +6,61 @@  discard block
 block discarded – undo
6 6
  */
7 7
 
8 8
 // Define the basic options for HTTP calls to REDLINK.
9
-define( 'WL_REDLINK_API_HTTP_OPTIONS', serialize( array(
9
+define('WL_REDLINK_API_HTTP_OPTIONS', serialize(array(
10 10
 	'timeout'         => 300,
11 11
 	'redirection'     => 5,
12 12
 	'httpversion'     => '1.1',
13 13
 	'blocking'        => true,
14 14
 	'cookies'         => array(),
15
-	'sslverify'       => ( 'false' === getenv( 'WL_SSL_VERIFY_ENABLED' ) ) ? false : true,
16
-	'sslcertificates' => dirname( __FILE__ ) . '/ssl/ca-bundle.crt',
15
+	'sslverify'       => ('false' === getenv('WL_SSL_VERIFY_ENABLED')) ? false : true,
16
+	'sslcertificates' => dirname(__FILE__).'/ssl/ca-bundle.crt',
17 17
 	'decompress'      => false,
18
-) ) );
18
+)));
19 19
 
20 20
 // Create a unique ID for this request, useful to hook async HTTP requests.
21
-define( 'WL_REQUEST_ID', uniqid( true ) );
21
+define('WL_REQUEST_ID', uniqid(true));
22 22
 
23 23
 // Set the temporary files folder.
24
-defined( 'WL_TEMP_DIR' ) || define( 'WL_TEMP_DIR', wl_temp_dir() );
24
+defined('WL_TEMP_DIR') || define('WL_TEMP_DIR', wl_temp_dir());
25 25
 
26
-define( 'WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING', wl_is_sparql_update_queries_buffering_enabled() );
26
+define('WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING', wl_is_sparql_update_queries_buffering_enabled());
27 27
 
28 28
 function wl_is_sparql_update_queries_buffering_enabled() {
29 29
 
30
-	if ( isset( $_REQUEST['wl-async'] ) && 'false' === $_REQUEST['wl-async'] ) {
30
+	if (isset($_REQUEST['wl-async']) && 'false' === $_REQUEST['wl-async']) {
31 31
 		return false;
32 32
 	}
33 33
 
34
-	return 'true' !== getenv( 'WL_DISABLE_SPARQL_UPDATE_QUERIES_BUFFERING' );
34
+	return 'true' !== getenv('WL_DISABLE_SPARQL_UPDATE_QUERIES_BUFFERING');
35 35
 }
36 36
 
37 37
 // Define the meta name used to store the entity URL.
38
-define( 'WL_ENTITY_URL_META_NAME', 'entity_url' );
38
+define('WL_ENTITY_URL_META_NAME', 'entity_url');
39 39
 
40 40
 // Max number of recursions when printing microdata.
41
-define( 'WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING', 3 );
41
+define('WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING', 3);
42 42
 
43 43
 // Use the WordLift API URL set on the command line.
44
-if ( ! defined( 'WORDLIFT_API_URL' ) && false !== getenv( 'WORDLIFT_API_URL' ) ) {
45
-	define( 'WORDLIFT_API_URL', getenv( 'WORDLIFT_API_URL' ) );
44
+if ( ! defined('WORDLIFT_API_URL') && false !== getenv('WORDLIFT_API_URL')) {
45
+	define('WORDLIFT_API_URL', getenv('WORDLIFT_API_URL'));
46 46
 }
47 47
 
48 48
 // 3.13.0, we use by default WLS 1.11 which provides us with the new, faster
49 49
 // chunked analysis.
50
-define( 'WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined( 'WORDLIFT_API_URL' ) ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.it/' );
50
+define('WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined('WORDLIFT_API_URL') ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.it/');
51 51
 
52
-define( 'WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url=' );
52
+define('WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url=');
53 53
 
54 54
 // If is set to true, there will be additional button in 'Download Your Data' page
55 55
 // that will allow users to download their data in JSON-LD format.
56
-defined( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA' ) || define( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA', false );
56
+defined('WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA') || define('WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA', false);
57 57
 
58 58
 /*
59 59
  * Define the default scope for autocomplete requests.
60 60
  *
61 61
  * @see https://github.com/insideout10/wordlift-plugin/issues/839
62 62
  */
63
-defined( 'WL_AUTOCOMPLETE_SCOPE' ) || define( 'WL_AUTOCOMPLETE_SCOPE', 'cloud' );
63
+defined('WL_AUTOCOMPLETE_SCOPE') || define('WL_AUTOCOMPLETE_SCOPE', 'cloud');
64 64
 
65 65
 /**
66 66
  * Get an array with commonly supported prefixes.
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 	$items    = wl_prefixes_list();
73 73
 	$prefixes = array();
74 74
 
75
-	foreach ( $items as $item ) {
76
-		$prefixes[ $item['prefix'] ] = $item['namespace'];
75
+	foreach ($items as $item) {
76
+		$prefixes[$item['prefix']] = $item['namespace'];
77 77
 	}
78 78
 
79 79
 	return $prefixes;
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
  */
94 94
 function wl_temp_dir() {
95 95
 	$tempdir         = get_temp_dir();
96
-	$unique          = md5( site_url() . get_current_blog_id() );
97
-	$unique_temp_dir = $tempdir . 'wl_' . $unique; // $tempdir should have a trailing slash.
96
+	$unique          = md5(site_url().get_current_blog_id());
97
+	$unique_temp_dir = $tempdir.'wl_'.$unique; // $tempdir should have a trailing slash.
98 98
 
99 99
 	// If directory do not exist, create it.
100
-	if ( ! file_exists( $unique_temp_dir ) ) {
101
-		mkdir( $unique_temp_dir );
100
+	if ( ! file_exists($unique_temp_dir)) {
101
+		mkdir($unique_temp_dir);
102 102
 	}
103 103
 
104
-	return $unique_temp_dir . '/';
104
+	return $unique_temp_dir.'/';
105 105
 }
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-post-edit-page.php 2 patches
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -18,100 +18,100 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Admin_Post_Edit_Page {
20 20
 
21
-	/**
22
-	 * The {@link Wordlift} plugin instance.
23
-	 *
24
-	 * @since 3.11.0
25
-	 *
26
-	 * @var \Wordlift $plugin The {@link Wordlift} plugin instance.
27
-	 */
28
-	private $plugin;
29
-
30
-	/**
31
-	 * A {@link Wordlift_Log_Service} instance.
32
-	 *
33
-	 * @since 3.15.4
34
-	 *
35
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
36
-	 */
37
-	private $log;
38
-
39
-	/**
40
-	 * Create the {@link Wordlift_Admin_Post_Edit_Page} instance.
41
-	 *
42
-	 * @since 3.11.0
43
-	 *
44
-	 * @param \Wordlift $plugin The {@link Wordlift} plugin instance.
45
-	 */
46
-	function __construct( $plugin ) {
47
-
48
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
49
-
50
-		// Bail out if we're in the UX Builder editor.
51
-		if ( $this->is_ux_builder_editor() ) {
52
-			$this->log->info( 'WordLift will not show, since we are in UX Builder editor.' );
53
-
54
-			return;
55
-		}
56
-
57
-		// Define the callback.
58
-		$callback = array( $this, 'enqueue_scripts', );
59
-
60
-		// Set a hook to enqueue scripts only when the edit page is displayed.
61
-		add_action( 'admin_print_scripts-post.php', $callback );
62
-		add_action( 'admin_print_scripts-post-new.php', $callback );
63
-
64
-		$this->plugin = $plugin;
65
-	}
66
-
67
-	/**
68
-	 * Check if we're in UX builder.
69
-	 *
70
-	 * @see   https://github.com/insideout10/wordlift-plugin/issues/691
71
-	 *
72
-	 * @since 3.15.4
73
-	 *
74
-	 * @return bool True if we're in UX builder, otherwise false.
75
-	 */
76
-	private function is_ux_builder_editor() {
77
-
78
-		return function_exists( 'ux_builder_is_editor' )
79
-		       && ux_builder_is_editor();
80
-	}
81
-
82
-	/**
83
-	 * Enqueue scripts and styles for the edit page.
84
-	 *
85
-	 * @since 3.11.0
86
-	 */
87
-	public function enqueue_scripts() {
88
-
89
-		// Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen.
90
-		//
91
-		// @see https://github.com/insideout10/wordlift-plugin/issues/832
92
-		wp_dequeue_script( 'ontrapagesAngular' );
93
-		wp_dequeue_script( 'ontrapagesApp' );
94
-		wp_dequeue_script( 'ontrapagesController' );
95
-
96
-		// Enqueue the edit screen JavaScript. The `wordlift-admin.bundle.js` file
97
-		// is scheduled to replace the older `wordlift-admin.min.js` once client-side
98
-		// code is properly refactored.
99
-		wp_enqueue_script(
100
-			'wordlift-admin-edit-page', plugin_dir_url( __FILE__ ) . 'js/1/edit.js',
101
-			array(
102
-				$this->plugin->get_plugin_name(),
103
-				'jquery',
104
-				// Require Angular.
105
-				'wl-angular',
106
-				'wl-angular-geolocation',
107
-				'wl-angular-touch',
108
-				'wl-angular-animate',
109
-			),
110
-			$this->plugin->get_version(),
111
-			false
112
-		);
113
-		wp_enqueue_style( 'wordlift-admin-edit-page', plugin_dir_url( __FILE__ ) . 'js/1/edit.css', array(), $this->plugin->get_version() );
114
-
115
-	}
21
+    /**
22
+     * The {@link Wordlift} plugin instance.
23
+     *
24
+     * @since 3.11.0
25
+     *
26
+     * @var \Wordlift $plugin The {@link Wordlift} plugin instance.
27
+     */
28
+    private $plugin;
29
+
30
+    /**
31
+     * A {@link Wordlift_Log_Service} instance.
32
+     *
33
+     * @since 3.15.4
34
+     *
35
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
36
+     */
37
+    private $log;
38
+
39
+    /**
40
+     * Create the {@link Wordlift_Admin_Post_Edit_Page} instance.
41
+     *
42
+     * @since 3.11.0
43
+     *
44
+     * @param \Wordlift $plugin The {@link Wordlift} plugin instance.
45
+     */
46
+    function __construct( $plugin ) {
47
+
48
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
49
+
50
+        // Bail out if we're in the UX Builder editor.
51
+        if ( $this->is_ux_builder_editor() ) {
52
+            $this->log->info( 'WordLift will not show, since we are in UX Builder editor.' );
53
+
54
+            return;
55
+        }
56
+
57
+        // Define the callback.
58
+        $callback = array( $this, 'enqueue_scripts', );
59
+
60
+        // Set a hook to enqueue scripts only when the edit page is displayed.
61
+        add_action( 'admin_print_scripts-post.php', $callback );
62
+        add_action( 'admin_print_scripts-post-new.php', $callback );
63
+
64
+        $this->plugin = $plugin;
65
+    }
66
+
67
+    /**
68
+     * Check if we're in UX builder.
69
+     *
70
+     * @see   https://github.com/insideout10/wordlift-plugin/issues/691
71
+     *
72
+     * @since 3.15.4
73
+     *
74
+     * @return bool True if we're in UX builder, otherwise false.
75
+     */
76
+    private function is_ux_builder_editor() {
77
+
78
+        return function_exists( 'ux_builder_is_editor' )
79
+               && ux_builder_is_editor();
80
+    }
81
+
82
+    /**
83
+     * Enqueue scripts and styles for the edit page.
84
+     *
85
+     * @since 3.11.0
86
+     */
87
+    public function enqueue_scripts() {
88
+
89
+        // Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen.
90
+        //
91
+        // @see https://github.com/insideout10/wordlift-plugin/issues/832
92
+        wp_dequeue_script( 'ontrapagesAngular' );
93
+        wp_dequeue_script( 'ontrapagesApp' );
94
+        wp_dequeue_script( 'ontrapagesController' );
95
+
96
+        // Enqueue the edit screen JavaScript. The `wordlift-admin.bundle.js` file
97
+        // is scheduled to replace the older `wordlift-admin.min.js` once client-side
98
+        // code is properly refactored.
99
+        wp_enqueue_script(
100
+            'wordlift-admin-edit-page', plugin_dir_url( __FILE__ ) . 'js/1/edit.js',
101
+            array(
102
+                $this->plugin->get_plugin_name(),
103
+                'jquery',
104
+                // Require Angular.
105
+                'wl-angular',
106
+                'wl-angular-geolocation',
107
+                'wl-angular-touch',
108
+                'wl-angular-animate',
109
+            ),
110
+            $this->plugin->get_version(),
111
+            false
112
+        );
113
+        wp_enqueue_style( 'wordlift-admin-edit-page', plugin_dir_url( __FILE__ ) . 'js/1/edit.css', array(), $this->plugin->get_version() );
114
+
115
+    }
116 116
 
117 117
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -43,23 +43,23 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @param \Wordlift $plugin The {@link Wordlift} plugin instance.
45 45
 	 */
46
-	function __construct( $plugin ) {
46
+	function __construct($plugin) {
47 47
 
48
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
48
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
49 49
 
50 50
 		// Bail out if we're in the UX Builder editor.
51
-		if ( $this->is_ux_builder_editor() ) {
52
-			$this->log->info( 'WordLift will not show, since we are in UX Builder editor.' );
51
+		if ($this->is_ux_builder_editor()) {
52
+			$this->log->info('WordLift will not show, since we are in UX Builder editor.');
53 53
 
54 54
 			return;
55 55
 		}
56 56
 
57 57
 		// Define the callback.
58
-		$callback = array( $this, 'enqueue_scripts', );
58
+		$callback = array($this, 'enqueue_scripts',);
59 59
 
60 60
 		// Set a hook to enqueue scripts only when the edit page is displayed.
61
-		add_action( 'admin_print_scripts-post.php', $callback );
62
-		add_action( 'admin_print_scripts-post-new.php', $callback );
61
+		add_action('admin_print_scripts-post.php', $callback);
62
+		add_action('admin_print_scripts-post-new.php', $callback);
63 63
 
64 64
 		$this->plugin = $plugin;
65 65
 	}
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	private function is_ux_builder_editor() {
77 77
 
78
-		return function_exists( 'ux_builder_is_editor' )
78
+		return function_exists('ux_builder_is_editor')
79 79
 		       && ux_builder_is_editor();
80 80
 	}
81 81
 
@@ -89,15 +89,15 @@  discard block
 block discarded – undo
89 89
 		// Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen.
90 90
 		//
91 91
 		// @see https://github.com/insideout10/wordlift-plugin/issues/832
92
-		wp_dequeue_script( 'ontrapagesAngular' );
93
-		wp_dequeue_script( 'ontrapagesApp' );
94
-		wp_dequeue_script( 'ontrapagesController' );
92
+		wp_dequeue_script('ontrapagesAngular');
93
+		wp_dequeue_script('ontrapagesApp');
94
+		wp_dequeue_script('ontrapagesController');
95 95
 
96 96
 		// Enqueue the edit screen JavaScript. The `wordlift-admin.bundle.js` file
97 97
 		// is scheduled to replace the older `wordlift-admin.min.js` once client-side
98 98
 		// code is properly refactored.
99 99
 		wp_enqueue_script(
100
-			'wordlift-admin-edit-page', plugin_dir_url( __FILE__ ) . 'js/1/edit.js',
100
+			'wordlift-admin-edit-page', plugin_dir_url(__FILE__).'js/1/edit.js',
101 101
 			array(
102 102
 				$this->plugin->get_plugin_name(),
103 103
 				'jquery',
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 			$this->plugin->get_version(),
111 111
 			false
112 112
 		);
113
-		wp_enqueue_style( 'wordlift-admin-edit-page', plugin_dir_url( __FILE__ ) . 'js/1/edit.css', array(), $this->plugin->get_version() );
113
+		wp_enqueue_style('wordlift-admin-edit-page', plugin_dir_url(__FILE__).'js/1/edit.css', array(), $this->plugin->get_version());
114 114
 
115 115
 	}
116 116
 
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -22,185 +22,185 @@
 block discarded – undo
22 22
  */
23 23
 class Wordlift_Admin {
24 24
 
25
-	/**
26
-	 * The ID of this plugin.
27
-	 *
28
-	 * @since    1.0.0
29
-	 * @access   private
30
-	 * @var      string $plugin_name The ID of this plugin.
31
-	 */
32
-	private $plugin_name;
33
-
34
-	/**
35
-	 * The version of this plugin.
36
-	 *
37
-	 * @since    1.0.0
38
-	 * @access   private
39
-	 * @var      string $version The current version of this plugin.
40
-	 */
41
-	private $version;
42
-
43
-	/**
44
-	 * The {@link Wordlift_Configuration_Service} instance.
45
-	 *
46
-	 * @since  3.14.0
47
-	 * @access private
48
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
49
-	 */
50
-	private $configuration_service;
51
-
52
-	/**
53
-	 * The {@link Wordlift_User_Service} instance.
54
-	 *
55
-	 * @since  3.14.0
56
-	 * @access private
57
-	 * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
58
-	 */
59
-	private $user_service;
60
-
61
-	/**
62
-	 * Initialize the class and set its properties.
63
-	 *
64
-	 * @since  1.0.0
65
-	 *
66
-	 * @param string                          $plugin_name The name of this plugin.
67
-	 * @param string                          $version The version of this plugin.
68
-	 * @param \Wordlift_Configuration_Service $configuration_service The configuration service.
69
-	 * @param \Wordlift_Notice_Service        $notice_service The notice service.
70
-	 * @param \Wordlift_User_Service          $user_service The {@link Wordlift_User_Service} instance.
71
-	 */
72
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
73
-
74
-		$this->plugin_name = $plugin_name;
75
-		$this->version     = $version;
76
-
77
-		$this->configuration_service = $configuration_service;
78
-		$this->user_service          = $user_service;
79
-
80
-		$dataset_uri = $configuration_service->get_dataset_uri();
81
-		$key         = $configuration_service->get_key();
82
-
83
-		if ( empty( $dataset_uri ) ) {
84
-			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
85
-			if ( empty( $key ) ) {
86
-				$error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
87
-			} else {
88
-				$error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
89
-			}
90
-			$notice_service->add_error( $error );
91
-		}
92
-
93
-		// Load additional code if we're in the admin UI.
94
-		if ( is_admin() ) {
95
-			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
96
-
97
-			new Wordlift_Dashboard_Latest_News();
98
-		}
99
-
100
-	}
101
-
102
-	/**
103
-	 * Register the stylesheets for the admin area.
104
-	 *
105
-	 * @since    1.0.0
106
-	 */
107
-	public function enqueue_styles() {
108
-
109
-		/**
110
-		 * This function is provided for demonstration purposes only.
111
-		 *
112
-		 * An instance of this class should be passed to the run() function
113
-		 * defined in Wordlift_Loader as all of the hooks are defined
114
-		 * in that particular class.
115
-		 *
116
-		 * The Wordlift_Loader will then create the relationship
117
-		 * between the defined hooks and the functions defined in this
118
-		 * class.
119
-		 */
120
-
121
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
122
-
123
-	}
124
-
125
-	/**
126
-	 * Register the JavaScript for the admin area.
127
-	 *
128
-	 * @since    1.0.0
129
-	 */
130
-	public function enqueue_scripts() {
131
-
132
-		/**
133
-		 * This function is provided for demonstration purposes only.
134
-		 *
135
-		 * An instance of this class should be passed to the run() function
136
-		 * defined in Wordlift_Loader as all of the hooks are defined
137
-		 * in that particular class.
138
-		 *
139
-		 * The Wordlift_Loader will then create the relationship
140
-		 * between the defined hooks and the functions defined in this
141
-		 * class.
142
-		 */
143
-
144
-		// Enqueue the admin scripts.
145
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
146
-			'jquery',
147
-			'underscore',
148
-			'backbone',
149
-		), $this->version, false );
150
-
151
-
152
-		$can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' );
153
-
154
-		/*
25
+    /**
26
+     * The ID of this plugin.
27
+     *
28
+     * @since    1.0.0
29
+     * @access   private
30
+     * @var      string $plugin_name The ID of this plugin.
31
+     */
32
+    private $plugin_name;
33
+
34
+    /**
35
+     * The version of this plugin.
36
+     *
37
+     * @since    1.0.0
38
+     * @access   private
39
+     * @var      string $version The current version of this plugin.
40
+     */
41
+    private $version;
42
+
43
+    /**
44
+     * The {@link Wordlift_Configuration_Service} instance.
45
+     *
46
+     * @since  3.14.0
47
+     * @access private
48
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
49
+     */
50
+    private $configuration_service;
51
+
52
+    /**
53
+     * The {@link Wordlift_User_Service} instance.
54
+     *
55
+     * @since  3.14.0
56
+     * @access private
57
+     * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance.
58
+     */
59
+    private $user_service;
60
+
61
+    /**
62
+     * Initialize the class and set its properties.
63
+     *
64
+     * @since  1.0.0
65
+     *
66
+     * @param string                          $plugin_name The name of this plugin.
67
+     * @param string                          $version The version of this plugin.
68
+     * @param \Wordlift_Configuration_Service $configuration_service The configuration service.
69
+     * @param \Wordlift_Notice_Service        $notice_service The notice service.
70
+     * @param \Wordlift_User_Service          $user_service The {@link Wordlift_User_Service} instance.
71
+     */
72
+    public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
73
+
74
+        $this->plugin_name = $plugin_name;
75
+        $this->version     = $version;
76
+
77
+        $this->configuration_service = $configuration_service;
78
+        $this->user_service          = $user_service;
79
+
80
+        $dataset_uri = $configuration_service->get_dataset_uri();
81
+        $key         = $configuration_service->get_key();
82
+
83
+        if ( empty( $dataset_uri ) ) {
84
+            $settings_page = Wordlift_Admin_Settings_Page::get_instance();
85
+            if ( empty( $key ) ) {
86
+                $error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
87
+            } else {
88
+                $error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
89
+            }
90
+            $notice_service->add_error( $error );
91
+        }
92
+
93
+        // Load additional code if we're in the admin UI.
94
+        if ( is_admin() ) {
95
+            require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
96
+
97
+            new Wordlift_Dashboard_Latest_News();
98
+        }
99
+
100
+    }
101
+
102
+    /**
103
+     * Register the stylesheets for the admin area.
104
+     *
105
+     * @since    1.0.0
106
+     */
107
+    public function enqueue_styles() {
108
+
109
+        /**
110
+         * This function is provided for demonstration purposes only.
111
+         *
112
+         * An instance of this class should be passed to the run() function
113
+         * defined in Wordlift_Loader as all of the hooks are defined
114
+         * in that particular class.
115
+         *
116
+         * The Wordlift_Loader will then create the relationship
117
+         * between the defined hooks and the functions defined in this
118
+         * class.
119
+         */
120
+
121
+        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
122
+
123
+    }
124
+
125
+    /**
126
+     * Register the JavaScript for the admin area.
127
+     *
128
+     * @since    1.0.0
129
+     */
130
+    public function enqueue_scripts() {
131
+
132
+        /**
133
+         * This function is provided for demonstration purposes only.
134
+         *
135
+         * An instance of this class should be passed to the run() function
136
+         * defined in Wordlift_Loader as all of the hooks are defined
137
+         * in that particular class.
138
+         *
139
+         * The Wordlift_Loader will then create the relationship
140
+         * between the defined hooks and the functions defined in this
141
+         * class.
142
+         */
143
+
144
+        // Enqueue the admin scripts.
145
+        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
146
+            'jquery',
147
+            'underscore',
148
+            'backbone',
149
+        ), $this->version, false );
150
+
151
+
152
+        $can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' );
153
+
154
+        /*
155 155
 		 * People that can create entities will see the scope set in the wp-config.php file (by default `cloud`). People
156 156
 		 * that cannot edit create entities will always see the local entities.
157 157
 		 *
158 158
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/839
159 159
 		 */
160
-		$autocomplete_scope = $can_edit_wordlift_entities ? WL_AUTOCOMPLETE_SCOPE : "local";
161
-
162
-		// Set the basic params.
163
-		$params = array(
164
-			// @todo scripts in admin should use wp.post.
165
-			'ajax_url'              => admin_url( 'admin-ajax.php' ),
166
-			// @todo remove specific actions from settings.
167
-			'action'                => 'entity_by_title',
168
-			'datasetUri'            => $this->configuration_service->get_dataset_uri(),
169
-			'language'              => $this->configuration_service->get_language_code(),
170
-			'link_by_default'       => $this->configuration_service->is_link_by_default(),
171
-			// Whether the current user is allowed to create new entities.
172
-			//
173
-			// @see https://github.com/insideout10/wordlift-plugin/issues/561
174
-			'can_create_entities'   => $can_edit_wordlift_entities ? 'yes' : 'no',
175
-			'l10n'                  => array(
176
-				'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
177
-				'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
178
-				'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
179
-				'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
180
-				'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
181
-				'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ),
182
-			),
183
-			'wl_autocomplete_nonce' => wp_create_nonce( 'wordlift_autocomplete' ),
184
-			'autocomplete_scope'    => $autocomplete_scope,
185
-		);
186
-
187
-		// Set post-related values if there's a current post.
188
-		if ( null !== $post = $entity_being_edited = get_post() ) {
189
-
190
-			$params['post_id']           = $entity_being_edited->ID;
191
-			$entity_service              = Wordlift_Entity_Service::get_instance();
192
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
193
-			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
194
-			// from the results, since we don't want the current entity to be discovered by the analysis.
195
-			//
196
-			// See https://github.com/insideout10/wordlift-plugin/issues/345
197
-			$params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID );
198
-
199
-		}
200
-
201
-		// Finally output the params as `wlSettings` for JavaScript code.
202
-		wp_localize_script( $this->plugin_name, 'wlSettings', $params );
203
-
204
-	}
160
+        $autocomplete_scope = $can_edit_wordlift_entities ? WL_AUTOCOMPLETE_SCOPE : "local";
161
+
162
+        // Set the basic params.
163
+        $params = array(
164
+            // @todo scripts in admin should use wp.post.
165
+            'ajax_url'              => admin_url( 'admin-ajax.php' ),
166
+            // @todo remove specific actions from settings.
167
+            'action'                => 'entity_by_title',
168
+            'datasetUri'            => $this->configuration_service->get_dataset_uri(),
169
+            'language'              => $this->configuration_service->get_language_code(),
170
+            'link_by_default'       => $this->configuration_service->is_link_by_default(),
171
+            // Whether the current user is allowed to create new entities.
172
+            //
173
+            // @see https://github.com/insideout10/wordlift-plugin/issues/561
174
+            'can_create_entities'   => $can_edit_wordlift_entities ? 'yes' : 'no',
175
+            'l10n'                  => array(
176
+                'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
177
+                'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
178
+                'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
179
+                'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
180
+                'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
181
+                'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ),
182
+            ),
183
+            'wl_autocomplete_nonce' => wp_create_nonce( 'wordlift_autocomplete' ),
184
+            'autocomplete_scope'    => $autocomplete_scope,
185
+        );
186
+
187
+        // Set post-related values if there's a current post.
188
+        if ( null !== $post = $entity_being_edited = get_post() ) {
189
+
190
+            $params['post_id']           = $entity_being_edited->ID;
191
+            $entity_service              = Wordlift_Entity_Service::get_instance();
192
+            $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
193
+            // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
194
+            // from the results, since we don't want the current entity to be discovered by the analysis.
195
+            //
196
+            // See https://github.com/insideout10/wordlift-plugin/issues/345
197
+            $params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID );
198
+
199
+        }
200
+
201
+        // Finally output the params as `wlSettings` for JavaScript code.
202
+        wp_localize_script( $this->plugin_name, 'wlSettings', $params );
203
+
204
+    }
205 205
 
206 206
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * @param \Wordlift_Notice_Service        $notice_service The notice service.
70 70
 	 * @param \Wordlift_User_Service          $user_service The {@link Wordlift_User_Service} instance.
71 71
 	 */
72
-	public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) {
72
+	public function __construct($plugin_name, $version, $configuration_service, $notice_service, $user_service) {
73 73
 
74 74
 		$this->plugin_name = $plugin_name;
75 75
 		$this->version     = $version;
@@ -80,19 +80,19 @@  discard block
 block discarded – undo
80 80
 		$dataset_uri = $configuration_service->get_dataset_uri();
81 81
 		$key         = $configuration_service->get_key();
82 82
 
83
-		if ( empty( $dataset_uri ) ) {
83
+		if (empty($dataset_uri)) {
84 84
 			$settings_page = Wordlift_Admin_Settings_Page::get_instance();
85
-			if ( empty( $key ) ) {
86
-				$error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
85
+			if (empty($key)) {
86
+				$error = sprintf(esc_html__("WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>');
87 87
 			} else {
88
-				$error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' );
88
+				$error = sprintf(esc_html__("WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>');
89 89
 			}
90
-			$notice_service->add_error( $error );
90
+			$notice_service->add_error($error);
91 91
 		}
92 92
 
93 93
 		// Load additional code if we're in the admin UI.
94
-		if ( is_admin() ) {
95
-			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php';
94
+		if (is_admin()) {
95
+			require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-dashboard-latest-news.php';
96 96
 
97 97
 			new Wordlift_Dashboard_Latest_News();
98 98
 		}
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		 * class.
119 119
 		 */
120 120
 
121
-		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' );
121
+		wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wordlift-admin.css', array(), $this->version, 'all');
122 122
 
123 123
 	}
124 124
 
@@ -142,14 +142,14 @@  discard block
 block discarded – undo
142 142
 		 */
143 143
 
144 144
 		// Enqueue the admin scripts.
145
-		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array(
145
+		wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/1/admin.js', array(
146 146
 			'jquery',
147 147
 			'underscore',
148 148
 			'backbone',
149
-		), $this->version, false );
149
+		), $this->version, false);
150 150
 
151 151
 
152
-		$can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' );
152
+		$can_edit_wordlift_entities = current_user_can('edit_wordlift_entities');
153 153
 
154 154
 		/*
155 155
 		 * People that can create entities will see the scope set in the wp-config.php file (by default `cloud`). People
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 		// Set the basic params.
163 163
 		$params = array(
164 164
 			// @todo scripts in admin should use wp.post.
165
-			'ajax_url'              => admin_url( 'admin-ajax.php' ),
165
+			'ajax_url'              => admin_url('admin-ajax.php'),
166 166
 			// @todo remove specific actions from settings.
167 167
 			'action'                => 'entity_by_title',
168 168
 			'datasetUri'            => $this->configuration_service->get_dataset_uri(),
@@ -173,33 +173,33 @@  discard block
 block discarded – undo
173 173
 			// @see https://github.com/insideout10/wordlift-plugin/issues/561
174 174
 			'can_create_entities'   => $can_edit_wordlift_entities ? 'yes' : 'no',
175 175
 			'l10n'                  => array(
176
-				'You already published an entity with the same name'                 => __( 'You already published an entity with the same name: ', 'wordlift' ),
177
-				'logo_selection_title'                                               => __( 'WordLift Choose Logo', 'wordlift' ),
178
-				'logo_selection_button'                                              => array( 'text' => __( 'Choose Logo', 'wordlift' ) ),
179
-				'Type at least 3 characters to search...'                            => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ),
180
-				'No results found for your search.'                                  => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ),
181
-				'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ),
176
+				'You already published an entity with the same name'                 => __('You already published an entity with the same name: ', 'wordlift'),
177
+				'logo_selection_title'                                               => __('WordLift Choose Logo', 'wordlift'),
178
+				'logo_selection_button'                                              => array('text' => __('Choose Logo', 'wordlift')),
179
+				'Type at least 3 characters to search...'                            => _x('Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift'),
180
+				'No results found for your search.'                                  => _x('No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift'),
181
+				'Please wait while we look for entities in the linked data cloud...' => _x('Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift'),
182 182
 			),
183
-			'wl_autocomplete_nonce' => wp_create_nonce( 'wordlift_autocomplete' ),
183
+			'wl_autocomplete_nonce' => wp_create_nonce('wordlift_autocomplete'),
184 184
 			'autocomplete_scope'    => $autocomplete_scope,
185 185
 		);
186 186
 
187 187
 		// Set post-related values if there's a current post.
188
-		if ( null !== $post = $entity_being_edited = get_post() ) {
188
+		if (null !== $post = $entity_being_edited = get_post()) {
189 189
 
190 190
 			$params['post_id']           = $entity_being_edited->ID;
191 191
 			$entity_service              = Wordlift_Entity_Service::get_instance();
192
-			$params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() );
192
+			$params['entityBeingEdited'] = isset($entity_being_edited->post_type) && $entity_service->is_entity($post->ID) && is_numeric(get_the_ID());
193 193
 			// We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it
194 194
 			// from the results, since we don't want the current entity to be discovered by the analysis.
195 195
 			//
196 196
 			// See https://github.com/insideout10/wordlift-plugin/issues/345
197
-			$params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID );
197
+			$params['itemId'] = $entity_service->get_uri($entity_being_edited->ID);
198 198
 
199 199
 		}
200 200
 
201 201
 		// Finally output the params as `wlSettings` for JavaScript code.
202
-		wp_localize_script( $this->plugin_name, 'wlSettings', $params );
202
+		wp_localize_script($this->plugin_name, 'wlSettings', $params);
203 203
 
204 204
 	}
205 205
 
Please login to merge, or discard this patch.
src/admin/wordlift_admin_ajax_related_posts.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -16,57 +16,57 @@
 block discarded – undo
16 16
  */
17 17
 function wordlift_ajax_related_posts( $http_raw_data = null ) {
18 18
 
19
-	// Extract filtering conditions
20
-	if ( ! isset( $_GET["post_id"] ) || ! is_numeric( $_GET["post_id"] ) ) {
21
-		wp_die( 'Post id missing or invalid!' );
19
+    // Extract filtering conditions
20
+    if ( ! isset( $_GET["post_id"] ) || ! is_numeric( $_GET["post_id"] ) ) {
21
+        wp_die( 'Post id missing or invalid!' );
22 22
 
23
-		return;
24
-	}
23
+        return;
24
+    }
25 25
 
26
-	// Get the current post
27
-	$post_id = $_GET["post_id"];
28
-	$post    = get_post( $post_id );
26
+    // Get the current post
27
+    $post_id = $_GET["post_id"];
28
+    $post    = get_post( $post_id );
29 29
 
30
-	Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." );
30
+    Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." );
31 31
 
32
-	// Extract filtering conditions
33
-	$filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data;
34
-	$filtering_entity_uris = json_decode( $filtering_entity_uris );
32
+    // Extract filtering conditions
33
+    $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data;
34
+    $filtering_entity_uris = json_decode( $filtering_entity_uris );
35 35
 
36
-	$filtering_entity_ids = wl_get_entity_post_ids_by_uris( $filtering_entity_uris );
37
-	$related_posts        = array();
36
+    $filtering_entity_ids = wl_get_entity_post_ids_by_uris( $filtering_entity_uris );
37
+    $related_posts        = array();
38 38
 
39
-	// If the current post is an entity, related posts to the current entity are
40
-	// returned.
41
-	$entity_service = Wordlift_Entity_Service::get_instance();
39
+    // If the current post is an entity, related posts to the current entity are
40
+    // returned.
41
+    $entity_service = Wordlift_Entity_Service::get_instance();
42 42
 
43
-	if ( $entity_service->is_entity( $post->ID ) ) {
44
-		$filtering_entity_ids = array( $post_id );
45
-	}
43
+    if ( $entity_service->is_entity( $post->ID ) ) {
44
+        $filtering_entity_ids = array( $post_id );
45
+    }
46 46
 
47
-	if ( ! empty( $filtering_entity_ids ) ) {
47
+    if ( ! empty( $filtering_entity_ids ) ) {
48 48
 
49
-		$related_posts = Wordlift_Relation_Service::get_instance()
50
-		                                          ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 );
49
+        $related_posts = Wordlift_Relation_Service::get_instance()
50
+                                                    ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 );
51 51
 
52
-		foreach ( $related_posts as $post_obj ) {
52
+        foreach ( $related_posts as $post_obj ) {
53 53
 
54
-			/**
55
-			 * Use the thumbnail.
56
-			 *
57
-			 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
58
-			 * @see https://github.com/insideout10/wordlift-plugin/issues/837
59
-			 *
60
-			 * @since 3.19.3 We're using the medium size image.
61
-			 */
62
-			$thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
63
-			$post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
64
-			$post_obj->link      = get_edit_post_link( $post_obj->ID, 'none' );
65
-			$post_obj->permalink = get_post_permalink( $post_obj->ID );
66
-		}
67
-	}
54
+            /**
55
+             * Use the thumbnail.
56
+             *
57
+             * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
58
+             * @see https://github.com/insideout10/wordlift-plugin/issues/837
59
+             *
60
+             * @since 3.19.3 We're using the medium size image.
61
+             */
62
+            $thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
63
+            $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
64
+            $post_obj->link      = get_edit_post_link( $post_obj->ID, 'none' );
65
+            $post_obj->permalink = get_post_permalink( $post_obj->ID );
66
+        }
67
+    }
68 68
 
69
-	wl_core_send_json( $related_posts );
69
+    wl_core_send_json( $related_posts );
70 70
 
71 71
 }
72 72
 
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -14,42 +14,42 @@  discard block
 block discarded – undo
14 14
  *
15 15
  * @param null $http_raw_data
16 16
  */
17
-function wordlift_ajax_related_posts( $http_raw_data = null ) {
17
+function wordlift_ajax_related_posts($http_raw_data = null) {
18 18
 
19 19
 	// Extract filtering conditions
20
-	if ( ! isset( $_GET["post_id"] ) || ! is_numeric( $_GET["post_id"] ) ) {
21
-		wp_die( 'Post id missing or invalid!' );
20
+	if ( ! isset($_GET["post_id"]) || ! is_numeric($_GET["post_id"])) {
21
+		wp_die('Post id missing or invalid!');
22 22
 
23 23
 		return;
24 24
 	}
25 25
 
26 26
 	// Get the current post
27 27
 	$post_id = $_GET["post_id"];
28
-	$post    = get_post( $post_id );
28
+	$post    = get_post($post_id);
29 29
 
30
-	Wordlift_Log_Service::get_logger( 'wordlift_ajax_related_posts' )->trace( "Going to find posts related to current with post id: $post_id ..." );
30
+	Wordlift_Log_Service::get_logger('wordlift_ajax_related_posts')->trace("Going to find posts related to current with post id: $post_id ...");
31 31
 
32 32
 	// Extract filtering conditions
33
-	$filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data;
34
-	$filtering_entity_uris = json_decode( $filtering_entity_uris );
33
+	$filtering_entity_uris = (null == $http_raw_data) ? file_get_contents("php://input") : $http_raw_data;
34
+	$filtering_entity_uris = json_decode($filtering_entity_uris);
35 35
 
36
-	$filtering_entity_ids = wl_get_entity_post_ids_by_uris( $filtering_entity_uris );
36
+	$filtering_entity_ids = wl_get_entity_post_ids_by_uris($filtering_entity_uris);
37 37
 	$related_posts        = array();
38 38
 
39 39
 	// If the current post is an entity, related posts to the current entity are
40 40
 	// returned.
41 41
 	$entity_service = Wordlift_Entity_Service::get_instance();
42 42
 
43
-	if ( $entity_service->is_entity( $post->ID ) ) {
44
-		$filtering_entity_ids = array( $post_id );
43
+	if ($entity_service->is_entity($post->ID)) {
44
+		$filtering_entity_ids = array($post_id);
45 45
 	}
46 46
 
47
-	if ( ! empty( $filtering_entity_ids ) ) {
47
+	if ( ! empty($filtering_entity_ids)) {
48 48
 
49 49
 		$related_posts = Wordlift_Relation_Service::get_instance()
50
-		                                          ->get_article_subjects( $filtering_entity_ids, '*', null, 'publish', array( $post_id ), 5 );
50
+		                                          ->get_article_subjects($filtering_entity_ids, '*', null, 'publish', array($post_id), 5);
51 51
 
52
-		foreach ( $related_posts as $post_obj ) {
52
+		foreach ($related_posts as $post_obj) {
53 53
 
54 54
 			/**
55 55
 			 * Use the thumbnail.
@@ -59,15 +59,15 @@  discard block
 block discarded – undo
59 59
 			 *
60 60
 			 * @since 3.19.3 We're using the medium size image.
61 61
 			 */
62
-			$thumbnail           = get_the_post_thumbnail_url( $post_obj, 'medium' );
63
-			$post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
64
-			$post_obj->link      = get_edit_post_link( $post_obj->ID, 'none' );
65
-			$post_obj->permalink = get_post_permalink( $post_obj->ID );
62
+			$thumbnail           = get_the_post_thumbnail_url($post_obj, 'medium');
63
+			$post_obj->thumbnail = ($thumbnail) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
64
+			$post_obj->link      = get_edit_post_link($post_obj->ID, 'none');
65
+			$post_obj->permalink = get_post_permalink($post_obj->ID);
66 66
 		}
67 67
 	}
68 68
 
69
-	wl_core_send_json( $related_posts );
69
+	wl_core_send_json($related_posts);
70 70
 
71 71
 }
72 72
 
73
-add_action( 'wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts' );
73
+add_action('wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts');
Please login to merge, or discard this patch.
src/wordlift.php 2 patches
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
 // If this file is called directly, abort.
28 28
 if ( ! defined( 'WPINC' ) ) {
29
-	die;
29
+    die;
30 30
 }
31 31
 
32 32
 // Include WordLift constants.
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function wl_write_log( $log ) {
50 50
 
51
-	Wordlift_Log_Service::get_instance()->debug( $log );
51
+    Wordlift_Log_Service::get_instance()->debug( $log );
52 52
 
53 53
 }
54 54
 
@@ -64,20 +64,20 @@  discard block
 block discarded – undo
64 64
  */
65 65
 function wl_write_log_handler( $log, $caller = null ) {
66 66
 
67
-	global $wl_logger;
67
+    global $wl_logger;
68 68
 
69
-	if ( true === WP_DEBUG ) {
69
+    if ( true === WP_DEBUG ) {
70 70
 
71
-		$message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
72
-		           ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
71
+        $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
72
+                    ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
73 73
 
74
-		if ( isset( $wl_logger ) ) {
75
-			$wl_logger->info( $message );
76
-		} else {
77
-			error_log( $message );
78
-		}
74
+        if ( isset( $wl_logger ) ) {
75
+            $wl_logger->info( $message );
76
+        } else {
77
+            error_log( $message );
78
+        }
79 79
 
80
-	}
80
+    }
81 81
 
82 82
 }
83 83
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
  */
95 95
 function wl_write_log_hide_key( $text ) {
96 96
 
97
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
97
+    return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
98 98
 }
99 99
 
100 100
 /**
@@ -102,21 +102,21 @@  discard block
 block discarded – undo
102 102
  * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
103 103
  */
104 104
 function wordlift_allowed_post_tags() {
105
-	global $allowedposttags;
106
-
107
-	$tags           = array( 'span' );
108
-	$new_attributes = array(
109
-		'itemscope' => array(),
110
-		'itemtype'  => array(),
111
-		'itemprop'  => array(),
112
-		'itemid'    => array(),
113
-	);
114
-
115
-	foreach ( $tags as $tag ) {
116
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
117
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
118
-		}
119
-	}
105
+    global $allowedposttags;
106
+
107
+    $tags           = array( 'span' );
108
+    $new_attributes = array(
109
+        'itemscope' => array(),
110
+        'itemtype'  => array(),
111
+        'itemprop'  => array(),
112
+        'itemid'    => array(),
113
+    );
114
+
115
+    foreach ( $tags as $tag ) {
116
+        if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
117
+            $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
118
+        }
119
+    }
120 120
 }
121 121
 
122 122
 // add allowed post tags.
@@ -127,32 +127,32 @@  discard block
 block discarded – undo
127 127
  */
128 128
 function wordlift_admin_enqueue_scripts() {
129 129
 
130
-	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
131
-	wp_enqueue_script( 'wpdialogs' );
132
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
130
+    // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
131
+    wp_enqueue_script( 'wpdialogs' );
132
+    wp_enqueue_style( 'wp-jquery-ui-dialog' );
133 133
 
134
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
134
+    wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
135 135
 
136
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
136
+    wp_enqueue_script( 'jquery-ui-autocomplete' );
137 137
 
138
-	$log = Wordlift_Log_Service::get_logger( 'wordlift_admin_enqueue_scripts' );
139
-	$log->trace( 'Registering admin scripts...' );
138
+    $log = Wordlift_Log_Service::get_logger( 'wordlift_admin_enqueue_scripts' );
139
+    $log->trace( 'Registering admin scripts...' );
140 140
 
141
-	// We now register angular scripts and have dependent scripts (currently
142
-	// only the edit post page) depend on them, to avoid potential conflicts.
143
-	//
144
-	// See https://github.com/insideout10/wordlift-plugin/issues/691.
145
-	$result = wp_register_script( 'wl-angular', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' )
146
-	          && wp_register_script( 'wl-angular-geolocation', plugin_dir_url( __FILE__ ) . 'bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' )
147
-	          && wp_register_script( 'wl-angular-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' )
148
-	          && wp_register_script( 'wl-angular-animate', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-animate.min.js' );
141
+    // We now register angular scripts and have dependent scripts (currently
142
+    // only the edit post page) depend on them, to avoid potential conflicts.
143
+    //
144
+    // See https://github.com/insideout10/wordlift-plugin/issues/691.
145
+    $result = wp_register_script( 'wl-angular', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' )
146
+              && wp_register_script( 'wl-angular-geolocation', plugin_dir_url( __FILE__ ) . 'bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' )
147
+              && wp_register_script( 'wl-angular-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' )
148
+              && wp_register_script( 'wl-angular-animate', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-animate.min.js' );
149 149
 
150
-	$log->debug( 'Registering angular scripts was ' . ( $result ? 'successful.' : 'unsuccessful.' ) );
150
+    $log->debug( 'Registering angular scripts was ' . ( $result ? 'successful.' : 'unsuccessful.' ) );
151 151
 
152
-	// Disable auto-save for custom entity posts only
153
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
154
-		wp_dequeue_script( 'autosave' );
155
-	}
152
+    // Disable auto-save for custom entity posts only
153
+    if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
154
+        wp_dequeue_script( 'autosave' );
155
+    }
156 156
 
157 157
 }
158 158
 
@@ -177,18 +177,18 @@  discard block
 block discarded – undo
177 177
  */
178 178
 function wordlift_allowed_html( $allowedtags, $context ) {
179 179
 
180
-	if ( 'post' !== $context ) {
181
-		return $allowedtags;
182
-	}
183
-
184
-	return array_merge_recursive( $allowedtags, array(
185
-		'span' => array(
186
-			'itemscope' => true,
187
-			'itemtype'  => true,
188
-			'itemid'    => true,
189
-			'itemprop'  => true,
190
-		),
191
-	) );
180
+    if ( 'post' !== $context ) {
181
+        return $allowedtags;
182
+    }
183
+
184
+    return array_merge_recursive( $allowedtags, array(
185
+        'span' => array(
186
+            'itemscope' => true,
187
+            'itemtype'  => true,
188
+            'itemid'    => true,
189
+            'itemprop'  => true,
190
+        ),
191
+    ) );
192 192
 }
193 193
 
194 194
 add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
@@ -202,16 +202,16 @@  discard block
 block discarded – undo
202 202
  */
203 203
 function wl_get_coordinates( $post_id ) {
204 204
 
205
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
206
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
205
+    $latitude  = wl_schema_get_value( $post_id, 'latitude' );
206
+    $longitude = wl_schema_get_value( $post_id, 'longitude' );
207 207
 
208
-	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific
209
-	// place on the globe:"The zero/zero point of this system is located in the
210
-	// Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
211
-	return array(
212
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
213
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
214
-	);
208
+    // DO NOT set latitude/longitude to 0/0 as default values. It's a specific
209
+    // place on the globe:"The zero/zero point of this system is located in the
210
+    // Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
211
+    return array(
212
+        'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
213
+        'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
214
+    );
215 215
 }
216 216
 
217 217
 /**
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
  */
226 226
 function wl_get_image_urls( $post_id ) {
227 227
 
228
-	return Wordlift_Storage_Factory::get_instance()
229
-	                               ->post_images()
230
-	                               ->get( $post_id );
228
+    return Wordlift_Storage_Factory::get_instance()
229
+                                    ->post_images()
230
+                                    ->get( $post_id );
231 231
 
232 232
 //	// If there is a featured image it has the priority.
233 233
 //	$featured_image_id = get_post_thumbnail_id( $post_id );
@@ -275,24 +275,24 @@  discard block
 block discarded – undo
275 275
  */
276 276
 function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
277 277
 
278
-	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
278
+    // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
279 279
 
280
-	$posts = get_posts( array(
281
-		'post_type'      => 'attachment',
282
-		'posts_per_page' => 1,
283
-		'post_status'    => 'any',
284
-		'post_parent'    => $parent_post_id,
285
-		'meta_key'       => 'wl_source_url',
286
-		'meta_value'     => $source_url,
287
-	) );
280
+    $posts = get_posts( array(
281
+        'post_type'      => 'attachment',
282
+        'posts_per_page' => 1,
283
+        'post_status'    => 'any',
284
+        'post_parent'    => $parent_post_id,
285
+        'meta_key'       => 'wl_source_url',
286
+        'meta_value'     => $source_url,
287
+    ) );
288 288
 
289
-	// Return the found post.
290
-	if ( 1 === count( $posts ) ) {
291
-		return $posts[0];
292
-	}
289
+    // Return the found post.
290
+    if ( 1 === count( $posts ) ) {
291
+        return $posts[0];
292
+    }
293 293
 
294
-	// Return null.
295
-	return null;
294
+    // Return null.
295
+    return null;
296 296
 }
297 297
 
298 298
 /**
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
  */
304 304
 function wl_set_source_url( $post_id, $source_url ) {
305 305
 
306
-	delete_post_meta( $post_id, 'wl_source_url' );
307
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
306
+    delete_post_meta( $post_id, 'wl_source_url' );
307
+    add_post_meta( $post_id, 'wl_source_url', $source_url );
308 308
 }
309 309
 
310 310
 /**
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
  */
321 321
 function wl_sanitize_uri_path( $path, $char = '_' ) {
322 322
 
323
-	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
323
+    return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
324 324
 }
325 325
 
326 326
 ///**
@@ -361,47 +361,47 @@  discard block
 block discarded – undo
361 361
  */
362 362
 function wl_replace_item_id_with_uri( $content ) {
363 363
 
364
-	$log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' );
365
-	$log->trace( 'Replacing item IDs with URIs...' );
364
+    $log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' );
365
+    $log->trace( 'Replacing item IDs with URIs...' );
366 366
 
367
-	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
368
-	$content = stripslashes( $content );
367
+    // Strip slashes, see https://core.trac.wordpress.org/ticket/21767
368
+    $content = stripslashes( $content );
369 369
 
370
-	// If any match are found.
371
-	$matches = array();
372
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
370
+    // If any match are found.
371
+    $matches = array();
372
+    if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
373 373
 
374
-		foreach ( $matches as $match ) {
374
+        foreach ( $matches as $match ) {
375 375
 
376
-			// Get the item ID.
377
-			$item_id = $match[1];
376
+            // Get the item ID.
377
+            $item_id = $match[1];
378 378
 
379
-			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
380
-			$post = Wordlift_Entity_Service::get_instance()
381
-			                               ->get_entity_post_by_uri( $item_id );
379
+            // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
380
+            $post = Wordlift_Entity_Service::get_instance()
381
+                                            ->get_entity_post_by_uri( $item_id );
382 382
 
383
-			// If no entity is found, continue to the next one.
384
-			if ( null === $post ) {
385
-				continue;
386
-			}
383
+            // If no entity is found, continue to the next one.
384
+            if ( null === $post ) {
385
+                continue;
386
+            }
387 387
 
388
-			// Get the URI for that post.
389
-			$uri = wl_get_entity_uri( $post->ID );
388
+            // Get the URI for that post.
389
+            $uri = wl_get_entity_uri( $post->ID );
390 390
 
391
-			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
391
+            // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
392 392
 
393
-			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
394
-			if ( $item_id !== $uri ) {
395
-				$uri_e   = esc_html( $uri );
396
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
397
-			}
398
-		}
399
-	}
393
+            // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
394
+            if ( $item_id !== $uri ) {
395
+                $uri_e   = esc_html( $uri );
396
+                $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
397
+            }
398
+        }
399
+    }
400 400
 
401
-	// Reapply slashes.
402
-	$content = addslashes( $content );
401
+    // Reapply slashes.
402
+    $content = addslashes( $content );
403 403
 
404
-	return $content;
404
+    return $content;
405 405
 }
406 406
 
407 407
 add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
@@ -462,24 +462,24 @@  discard block
 block discarded – undo
462 462
  */
463 463
 function activate_wordlift() {
464 464
 
465
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
465
+    $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
466 466
 
467
-	$log->info( 'Activating WordLift...' );
467
+    $log->info( 'Activating WordLift...' );
468 468
 
469
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
470
-	Wordlift_Activator::activate();
469
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
470
+    Wordlift_Activator::activate();
471 471
 
472
-	/**
473
-	 * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
474
-	 *
475
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
476
-	 * @since 3.19.2
477
-	 */
478
-	Wordlift_Http_Api::activate();
472
+    /**
473
+     * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
474
+     *
475
+     * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
476
+     * @since 3.19.2
477
+     */
478
+    Wordlift_Http_Api::activate();
479 479
 
480
-	// Ensure the post type is registered before flushing the rewrite rules.
481
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
482
-	flush_rewrite_rules();
480
+    // Ensure the post type is registered before flushing the rewrite rules.
481
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
482
+    flush_rewrite_rules();
483 483
 
484 484
 }
485 485
 
@@ -489,9 +489,9 @@  discard block
 block discarded – undo
489 489
  */
490 490
 function deactivate_wordlift() {
491 491
 
492
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
493
-	Wordlift_Deactivator::deactivate();
494
-	flush_rewrite_rules();
492
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
493
+    Wordlift_Deactivator::deactivate();
494
+    flush_rewrite_rules();
495 495
 
496 496
 }
497 497
 
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
  */
516 516
 function run_wordlift() {
517 517
 
518
-	$plugin = new Wordlift();
519
-	$plugin->run();
518
+    $plugin = new Wordlift();
519
+    $plugin->run();
520 520
 
521 521
 }
522 522
 
Please login to merge, or discard this patch.
Spacing   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -25,15 +25,15 @@  discard block
 block discarded – undo
25 25
  */
26 26
 
27 27
 // If this file is called directly, abort.
28
-if ( ! defined( 'WPINC' ) ) {
28
+if ( ! defined('WPINC')) {
29 29
 	die;
30 30
 }
31 31
 
32 32
 // Include WordLift constants.
33
-require_once( 'wordlift_constants.php' );
33
+require_once('wordlift_constants.php');
34 34
 
35 35
 // Load modules.
36
-require_once( 'modules/core/wordlift_core.php' );
36
+require_once('modules/core/wordlift_core.php');
37 37
 
38 38
 /**
39 39
  * Log to the debug.log file.
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
  *
47 47
  * @param string|mixed $log The log data.
48 48
  */
49
-function wl_write_log( $log ) {
49
+function wl_write_log($log) {
50 50
 
51
-	Wordlift_Log_Service::get_instance()->debug( $log );
51
+	Wordlift_Log_Service::get_instance()->debug($log);
52 52
 
53 53
 }
54 54
 
@@ -62,19 +62,19 @@  discard block
 block discarded – undo
62 62
  * @param string|array $log The log data.
63 63
  * @param string       $caller The calling function.
64 64
  */
65
-function wl_write_log_handler( $log, $caller = null ) {
65
+function wl_write_log_handler($log, $caller = null) {
66 66
 
67 67
 	global $wl_logger;
68 68
 
69
-	if ( true === WP_DEBUG ) {
69
+	if (true === WP_DEBUG) {
70 70
 
71
-		$message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
72
-		           ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
71
+		$message = (isset($caller) ? sprintf('[%-40.40s] ', $caller) : '').
72
+		           (is_array($log) || is_object($log) ? print_r($log, true) : wl_write_log_hide_key($log));
73 73
 
74
-		if ( isset( $wl_logger ) ) {
75
-			$wl_logger->info( $message );
74
+		if (isset($wl_logger)) {
75
+			$wl_logger->info($message);
76 76
 		} else {
77
-			error_log( $message );
77
+			error_log($message);
78 78
 		}
79 79
 
80 80
 	}
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
  *
93 93
  * @return string A text with the key hidden.
94 94
  */
95
-function wl_write_log_hide_key( $text ) {
95
+function wl_write_log_hide_key($text) {
96 96
 
97
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
97
+	return str_ireplace(wl_configuration_get_key(), '<hidden>', $text);
98 98
 }
99 99
 
100 100
 /**
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 function wordlift_allowed_post_tags() {
105 105
 	global $allowedposttags;
106 106
 
107
-	$tags           = array( 'span' );
107
+	$tags           = array('span');
108 108
 	$new_attributes = array(
109 109
 		'itemscope' => array(),
110 110
 		'itemtype'  => array(),
@@ -112,15 +112,15 @@  discard block
 block discarded – undo
112 112
 		'itemid'    => array(),
113 113
 	);
114 114
 
115
-	foreach ( $tags as $tag ) {
116
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
117
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
115
+	foreach ($tags as $tag) {
116
+		if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) {
117
+			$allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes);
118 118
 		}
119 119
 	}
120 120
 }
121 121
 
122 122
 // add allowed post tags.
123
-add_action( 'init', 'wordlift_allowed_post_tags' );
123
+add_action('init', 'wordlift_allowed_post_tags');
124 124
 
125 125
 /**
126 126
  * Register additional scripts for the admin UI.
@@ -128,35 +128,35 @@  discard block
 block discarded – undo
128 128
 function wordlift_admin_enqueue_scripts() {
129 129
 
130 130
 	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
131
-	wp_enqueue_script( 'wpdialogs' );
132
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
131
+	wp_enqueue_script('wpdialogs');
132
+	wp_enqueue_style('wp-jquery-ui-dialog');
133 133
 
134
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
134
+	wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css');
135 135
 
136
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
136
+	wp_enqueue_script('jquery-ui-autocomplete');
137 137
 
138
-	$log = Wordlift_Log_Service::get_logger( 'wordlift_admin_enqueue_scripts' );
139
-	$log->trace( 'Registering admin scripts...' );
138
+	$log = Wordlift_Log_Service::get_logger('wordlift_admin_enqueue_scripts');
139
+	$log->trace('Registering admin scripts...');
140 140
 
141 141
 	// We now register angular scripts and have dependent scripts (currently
142 142
 	// only the edit post page) depend on them, to avoid potential conflicts.
143 143
 	//
144 144
 	// See https://github.com/insideout10/wordlift-plugin/issues/691.
145
-	$result = wp_register_script( 'wl-angular', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' )
146
-	          && wp_register_script( 'wl-angular-geolocation', plugin_dir_url( __FILE__ ) . 'bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' )
147
-	          && wp_register_script( 'wl-angular-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' )
148
-	          && wp_register_script( 'wl-angular-animate', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-animate.min.js' );
145
+	$result = wp_register_script('wl-angular', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js')
146
+	          && wp_register_script('wl-angular-geolocation', plugin_dir_url(__FILE__).'bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js')
147
+	          && wp_register_script('wl-angular-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js')
148
+	          && wp_register_script('wl-angular-animate', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-animate.min.js');
149 149
 
150
-	$log->debug( 'Registering angular scripts was ' . ( $result ? 'successful.' : 'unsuccessful.' ) );
150
+	$log->debug('Registering angular scripts was '.($result ? 'successful.' : 'unsuccessful.'));
151 151
 
152 152
 	// Disable auto-save for custom entity posts only
153
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
154
-		wp_dequeue_script( 'autosave' );
153
+	if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) {
154
+		wp_dequeue_script('autosave');
155 155
 	}
156 156
 
157 157
 }
158 158
 
159
-add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
159
+add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts');
160 160
 
161 161
 // We shouldn't load the wordlift-ui.min.css stylesheet when not needed.
162 162
 //
@@ -175,23 +175,23 @@  discard block
 block discarded – undo
175 175
  *
176 176
  * @return array An array which contains allowed microdata attributes.
177 177
  */
178
-function wordlift_allowed_html( $allowedtags, $context ) {
178
+function wordlift_allowed_html($allowedtags, $context) {
179 179
 
180
-	if ( 'post' !== $context ) {
180
+	if ('post' !== $context) {
181 181
 		return $allowedtags;
182 182
 	}
183 183
 
184
-	return array_merge_recursive( $allowedtags, array(
184
+	return array_merge_recursive($allowedtags, array(
185 185
 		'span' => array(
186 186
 			'itemscope' => true,
187 187
 			'itemtype'  => true,
188 188
 			'itemid'    => true,
189 189
 			'itemprop'  => true,
190 190
 		),
191
-	) );
191
+	));
192 192
 }
193 193
 
194
-add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
194
+add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2);
195 195
 
196 196
 /**
197 197
  * Get the coordinates for the specified post ID.
@@ -200,17 +200,17 @@  discard block
 block discarded – undo
200 200
  *
201 201
  * @return array|null An array of coordinates or null.
202 202
  */
203
-function wl_get_coordinates( $post_id ) {
203
+function wl_get_coordinates($post_id) {
204 204
 
205
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
206
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
205
+	$latitude  = wl_schema_get_value($post_id, 'latitude');
206
+	$longitude = wl_schema_get_value($post_id, 'longitude');
207 207
 
208 208
 	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific
209 209
 	// place on the globe:"The zero/zero point of this system is located in the
210 210
 	// Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
211 211
 	return array(
212
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
213
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
212
+		'latitude'  => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '',
213
+		'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '',
214 214
 	);
215 215
 }
216 216
 
@@ -223,11 +223,11 @@  discard block
 block discarded – undo
223 223
  *
224 224
  * @return array An array of image URLs.
225 225
  */
226
-function wl_get_image_urls( $post_id ) {
226
+function wl_get_image_urls($post_id) {
227 227
 
228 228
 	return Wordlift_Storage_Factory::get_instance()
229 229
 	                               ->post_images()
230
-	                               ->get( $post_id );
230
+	                               ->get($post_id);
231 231
 
232 232
 //	// If there is a featured image it has the priority.
233 233
 //	$featured_image_id = get_post_thumbnail_id( $post_id );
@@ -273,21 +273,21 @@  discard block
 block discarded – undo
273 273
  *
274 274
  * @return WP_Post|null A post instance or null if not found.
275 275
  */
276
-function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
276
+function wl_get_attachment_for_source_url($parent_post_id, $source_url) {
277 277
 
278 278
 	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
279 279
 
280
-	$posts = get_posts( array(
280
+	$posts = get_posts(array(
281 281
 		'post_type'      => 'attachment',
282 282
 		'posts_per_page' => 1,
283 283
 		'post_status'    => 'any',
284 284
 		'post_parent'    => $parent_post_id,
285 285
 		'meta_key'       => 'wl_source_url',
286 286
 		'meta_value'     => $source_url,
287
-	) );
287
+	));
288 288
 
289 289
 	// Return the found post.
290
-	if ( 1 === count( $posts ) ) {
290
+	if (1 === count($posts)) {
291 291
 		return $posts[0];
292 292
 	}
293 293
 
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
  * @param int    $post_id The post ID.
302 302
  * @param string $source_url The source URL.
303 303
  */
304
-function wl_set_source_url( $post_id, $source_url ) {
304
+function wl_set_source_url($post_id, $source_url) {
305 305
 
306
-	delete_post_meta( $post_id, 'wl_source_url' );
307
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
306
+	delete_post_meta($post_id, 'wl_source_url');
307
+	add_post_meta($post_id, 'wl_source_url', $source_url);
308 308
 }
309 309
 
310 310
 /**
@@ -318,9 +318,9 @@  discard block
 block discarded – undo
318 318
  *
319 319
  * @return string The sanitized path.
320 320
  */
321
-function wl_sanitize_uri_path( $path, $char = '_' ) {
321
+function wl_sanitize_uri_path($path, $char = '_') {
322 322
 
323
-	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
323
+	return Wordlift_Uri_Service::get_instance()->sanitize_path($path, $char);
324 324
 }
325 325
 
326 326
 ///**
@@ -359,102 +359,102 @@  discard block
 block discarded – undo
359 359
  *
360 360
  * @return string The updated post content.
361 361
  */
362
-function wl_replace_item_id_with_uri( $content ) {
362
+function wl_replace_item_id_with_uri($content) {
363 363
 
364
-	$log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' );
365
-	$log->trace( 'Replacing item IDs with URIs...' );
364
+	$log = Wordlift_Log_Service::get_logger('wl_replace_item_id_with_uri');
365
+	$log->trace('Replacing item IDs with URIs...');
366 366
 
367 367
 	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
368
-	$content = stripslashes( $content );
368
+	$content = stripslashes($content);
369 369
 
370 370
 	// If any match are found.
371 371
 	$matches = array();
372
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
372
+	if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) {
373 373
 
374
-		foreach ( $matches as $match ) {
374
+		foreach ($matches as $match) {
375 375
 
376 376
 			// Get the item ID.
377 377
 			$item_id = $match[1];
378 378
 
379 379
 			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
380 380
 			$post = Wordlift_Entity_Service::get_instance()
381
-			                               ->get_entity_post_by_uri( $item_id );
381
+			                               ->get_entity_post_by_uri($item_id);
382 382
 
383 383
 			// If no entity is found, continue to the next one.
384
-			if ( null === $post ) {
384
+			if (null === $post) {
385 385
 				continue;
386 386
 			}
387 387
 
388 388
 			// Get the URI for that post.
389
-			$uri = wl_get_entity_uri( $post->ID );
389
+			$uri = wl_get_entity_uri($post->ID);
390 390
 
391 391
 			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
392 392
 
393 393
 			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
394
-			if ( $item_id !== $uri ) {
395
-				$uri_e   = esc_html( $uri );
396
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
394
+			if ($item_id !== $uri) {
395
+				$uri_e   = esc_html($uri);
396
+				$content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content);
397 397
 			}
398 398
 		}
399 399
 	}
400 400
 
401 401
 	// Reapply slashes.
402
-	$content = addslashes( $content );
402
+	$content = addslashes($content);
403 403
 
404 404
 	return $content;
405 405
 }
406 406
 
407
-add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
407
+add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1);
408 408
 
409
-require_once( 'wordlift_entity_functions.php' );
409
+require_once('wordlift_entity_functions.php');
410 410
 
411 411
 // add editor related methods.
412
-require_once( 'wordlift_editor.php' );
412
+require_once('wordlift_editor.php');
413 413
 
414 414
 // add the WordLift entity custom type.
415
-require_once( 'wordlift_entity_type.php' );
415
+require_once('wordlift_entity_type.php');
416 416
 
417 417
 // add callbacks on post save to notify data changes from wp to redlink triple store
418
-require_once( 'wordlift_to_redlink_data_push_callbacks.php' );
418
+require_once('wordlift_to_redlink_data_push_callbacks.php');
419 419
 
420
-require_once( 'modules/configuration/wordlift_configuration_settings.php' );
420
+require_once('modules/configuration/wordlift_configuration_settings.php');
421 421
 
422 422
 // Load modules
423
-require_once( 'modules/analyzer/wordlift_analyzer.php' );
424
-require_once( 'modules/linked_data/wordlift_linked_data.php' );
425
-require_once( 'modules/prefixes/wordlift_prefixes.php' );
423
+require_once('modules/analyzer/wordlift_analyzer.php');
424
+require_once('modules/linked_data/wordlift_linked_data.php');
425
+require_once('modules/prefixes/wordlift_prefixes.php');
426 426
 
427 427
 // Shortcodes
428 428
 
429
-require_once( 'modules/geo_widget/wordlift_geo_widget.php' );
430
-require_once( 'shortcodes/wordlift_shortcode_chord.php' );
431
-require_once( 'shortcodes/wordlift_shortcode_geomap.php' );
432
-require_once( 'shortcodes/wordlift_shortcode_field.php' );
433
-require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' );
434
-require_once( 'shortcodes/wordlift_shortcode_navigator.php' );
429
+require_once('modules/geo_widget/wordlift_geo_widget.php');
430
+require_once('shortcodes/wordlift_shortcode_chord.php');
431
+require_once('shortcodes/wordlift_shortcode_geomap.php');
432
+require_once('shortcodes/wordlift_shortcode_field.php');
433
+require_once('shortcodes/wordlift_shortcode_faceted_search.php');
434
+require_once('shortcodes/wordlift_shortcode_navigator.php');
435 435
 
436
-require_once( 'widgets/wordlift_widget_geo.php' );
437
-require_once( 'widgets/class-wordlift-chord-widget.php' );
438
-require_once( 'widgets/wordlift_widget_timeline.php' );
436
+require_once('widgets/wordlift_widget_geo.php');
437
+require_once('widgets/class-wordlift-chord-widget.php');
438
+require_once('widgets/wordlift_widget_timeline.php');
439 439
 
440
-require_once( 'wordlift_redlink.php' );
440
+require_once('wordlift_redlink.php');
441 441
 
442 442
 // Add admin functions.
443 443
 // TODO: find a way to make 'admin' UI tests work.
444 444
 //if ( is_admin() ) {
445 445
 
446
-require_once( 'admin/wordlift_admin.php' );
447
-require_once( 'admin/wordlift_admin_edit_post.php' );
448
-require_once( 'admin/wordlift_admin_save_post.php' );
446
+require_once('admin/wordlift_admin.php');
447
+require_once('admin/wordlift_admin_edit_post.php');
448
+require_once('admin/wordlift_admin_save_post.php');
449 449
 
450 450
 // add the entities meta box.
451
-require_once( 'admin/wordlift_admin_meta_box_entities.php' );
451
+require_once('admin/wordlift_admin_meta_box_entities.php');
452 452
 
453 453
 // add the entity creation AJAX.
454
-require_once( 'admin/wordlift_admin_ajax_related_posts.php' );
454
+require_once('admin/wordlift_admin_ajax_related_posts.php');
455 455
 
456 456
 // Load the wl_chord TinyMCE button and configuration dialog.
457
-require_once( 'admin/wordlift_admin_shortcodes.php' );
457
+require_once('admin/wordlift_admin_shortcodes.php');
458 458
 
459 459
 /**
460 460
  * The code that runs during plugin activation.
@@ -462,11 +462,11 @@  discard block
 block discarded – undo
462 462
  */
463 463
 function activate_wordlift() {
464 464
 
465
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
465
+	$log = Wordlift_Log_Service::get_logger('activate_wordlift');
466 466
 
467
-	$log->info( 'Activating WordLift...' );
467
+	$log->info('Activating WordLift...');
468 468
 
469
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
469
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
470 470
 	Wordlift_Activator::activate();
471 471
 
472 472
 	/**
@@ -489,20 +489,20 @@  discard block
 block discarded – undo
489 489
  */
490 490
 function deactivate_wordlift() {
491 491
 
492
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
492
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
493 493
 	Wordlift_Deactivator::deactivate();
494 494
 	flush_rewrite_rules();
495 495
 
496 496
 }
497 497
 
498
-register_activation_hook( __FILE__, 'activate_wordlift' );
499
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
498
+register_activation_hook(__FILE__, 'activate_wordlift');
499
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
500 500
 
501 501
 /**
502 502
  * The core plugin class that is used to define internationalization,
503 503
  * admin-specific hooks, and public-facing site hooks.
504 504
  */
505
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
505
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
506 506
 
507 507
 /**
508 508
  * Begins execution of the plugin.
Please login to merge, or discard this patch.
src/includes/class-wordlift-autocomplete-adapter.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 if ( ! defined( 'ABSPATH' ) ) {
14
-	exit;
14
+    exit;
15 15
 }
16 16
 
17 17
 /**
@@ -21,82 +21,82 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Wordlift_Autocomplete_Adapter {
23 23
 
24
-	/**
25
-	 * The {@link Wordlift_Autocomplete_Service} instance.
26
-	 *
27
-	 * @since  3.15.0
28
-	 * @access private
29
-	 * @var \Wordlift_Autocomplete_Service $configuration_service The {@link Wordlift_Autocomplete_Service} instance.
30
-	 */
31
-	private $autocomplete_service;
24
+    /**
25
+     * The {@link Wordlift_Autocomplete_Service} instance.
26
+     *
27
+     * @since  3.15.0
28
+     * @access private
29
+     * @var \Wordlift_Autocomplete_Service $configuration_service The {@link Wordlift_Autocomplete_Service} instance.
30
+     */
31
+    private $autocomplete_service;
32 32
 
33 33
 
34
-	/**
35
-	 * Wordlift_Autocomplete_Adapter constructor.
36
-	 *
37
-	 * @since 3.14.2
38
-	 *
39
-	 * @param \Wordlift_Autocomplete_Service $autocomplete_service The {@link Wordlift_Autocomplete_Service} instance.
40
-	 */
41
-	public function __construct( $autocomplete_service ) {
42
-		$this->autocomplete_service = $autocomplete_service;
43
-	}
34
+    /**
35
+     * Wordlift_Autocomplete_Adapter constructor.
36
+     *
37
+     * @since 3.14.2
38
+     *
39
+     * @param \Wordlift_Autocomplete_Service $autocomplete_service The {@link Wordlift_Autocomplete_Service} instance.
40
+     */
41
+    public function __construct( $autocomplete_service ) {
42
+        $this->autocomplete_service = $autocomplete_service;
43
+    }
44 44
 
45
-	/**
46
-	 * Handle the autocomplete ajax request.
47
-	 *
48
-	 * @since 3.15.0
49
-	 */
50
-	public function wl_autocomplete() {
51
-		if (
52
-			! isset( $_REQUEST['_wpnonce'] ) || // Input var okay.
53
-			! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'wordlift_autocomplete' ) // Input var okay.
54
-		) {
55
-			wp_send_json_error( array(
56
-				'message' => __( 'Nonce field doesn\'t match.', 'wordlift' ),
57
-			) );
58
-		}
45
+    /**
46
+     * Handle the autocomplete ajax request.
47
+     *
48
+     * @since 3.15.0
49
+     */
50
+    public function wl_autocomplete() {
51
+        if (
52
+            ! isset( $_REQUEST['_wpnonce'] ) || // Input var okay.
53
+            ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'wordlift_autocomplete' ) // Input var okay.
54
+        ) {
55
+            wp_send_json_error( array(
56
+                'message' => __( 'Nonce field doesn\'t match.', 'wordlift' ),
57
+            ) );
58
+        }
59 59
 
60
-		// Return error if the query param is empty.
61
-		if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay.
62
-			$query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay.
63
-		} else {
64
-			wp_send_json_error( array(
65
-				'message' => __( 'The query param is empty.', 'wordlift' ),
66
-			) );
67
-		}
60
+        // Return error if the query param is empty.
61
+        if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay.
62
+            $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay.
63
+        } else {
64
+            wp_send_json_error( array(
65
+                'message' => __( 'The query param is empty.', 'wordlift' ),
66
+            ) );
67
+        }
68 68
 
69
-		// Get the exclude parameter.
70
-		$exclude = ! empty( $_REQUEST['exclude'] )
71
-			? sanitize_text_field( wp_unslash( $_REQUEST['exclude'] ) ) : '';
69
+        // Get the exclude parameter.
70
+        $exclude = ! empty( $_REQUEST['exclude'] )
71
+            ? sanitize_text_field( wp_unslash( $_REQUEST['exclude'] ) ) : '';
72 72
 
73
-		$scope = ! empty( $_REQUEST['scope'] )
74
-			? sanitize_text_field( wp_unslash( $_REQUEST['scope'] ) ) : WL_AUTOCOMPLETE_SCOPE;
73
+        $scope = ! empty( $_REQUEST['scope'] )
74
+            ? sanitize_text_field( wp_unslash( $_REQUEST['scope'] ) ) : WL_AUTOCOMPLETE_SCOPE;
75 75
 
76
-		// Make request.
77
-		$response = $this->autocomplete_service->make_request( $query, $exclude, $scope );
76
+        // Make request.
77
+        $response = $this->autocomplete_service->make_request( $query, $exclude, $scope );
78 78
 
79
-		// Clear any buffer.
80
-		ob_clean();
79
+        // Clear any buffer.
80
+        ob_clean();
81 81
 
82
-		// If the response is valid, then send the suggestions.
83
-		if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
84
-			// Echo the response.
85
-			wp_send_json_success( json_decode( wp_remote_retrieve_body( $response ), true ) );
86
-		} else {
87
-			// Default error message.
88
-			$error_message = 'Something went wrong.';
82
+        // If the response is valid, then send the suggestions.
83
+        if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
84
+            // Echo the response.
85
+            wp_send_json_success( json_decode( wp_remote_retrieve_body( $response ), true ) );
86
+        } else {
87
+            // Default error message.
88
+            $error_message = 'Something went wrong.';
89 89
 
90
-			// Get the real error message if there is WP_Error.
91
-			if ( is_wp_error( $response ) ) {
92
-				$error_message = $response->get_error_message();
93
-			}
90
+            // Get the real error message if there is WP_Error.
91
+            if ( is_wp_error( $response ) ) {
92
+                $error_message = $response->get_error_message();
93
+            }
94 94
 
95
-			// There is an error, so send error message.
96
-			wp_send_json_error( array(
97
-				/* translators: Placeholders: %s - the error message that will be returned. */
98
-				'message' => sprintf( esc_html__( 'Error: %s', 'wordlift' ), $error_message ),
99
-			) );
100
-		}
101
-	}
95
+            // There is an error, so send error message.
96
+            wp_send_json_error( array(
97
+                /* translators: Placeholders: %s - the error message that will be returned. */
98
+                'message' => sprintf( esc_html__( 'Error: %s', 'wordlift' ), $error_message ),
99
+            ) );
100
+        }
101
+    }
102 102
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since      3.15.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @param \Wordlift_Autocomplete_Service $autocomplete_service The {@link Wordlift_Autocomplete_Service} instance.
40 40
 	 */
41
-	public function __construct( $autocomplete_service ) {
41
+	public function __construct($autocomplete_service) {
42 42
 		$this->autocomplete_service = $autocomplete_service;
43 43
 	}
44 44
 
@@ -49,54 +49,54 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	public function wl_autocomplete() {
51 51
 		if (
52
-			! isset( $_REQUEST['_wpnonce'] ) || // Input var okay.
53
-			! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'wordlift_autocomplete' ) // Input var okay.
52
+			! isset($_REQUEST['_wpnonce']) || // Input var okay.
53
+			! wp_verify_nonce(sanitize_key($_REQUEST['_wpnonce']), 'wordlift_autocomplete') // Input var okay.
54 54
 		) {
55
-			wp_send_json_error( array(
56
-				'message' => __( 'Nonce field doesn\'t match.', 'wordlift' ),
57
-			) );
55
+			wp_send_json_error(array(
56
+				'message' => __('Nonce field doesn\'t match.', 'wordlift'),
57
+			));
58 58
 		}
59 59
 
60 60
 		// Return error if the query param is empty.
61
-		if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay.
62
-			$query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay.
61
+		if ( ! empty($_REQUEST['query'])) { // Input var okay.
62
+			$query = sanitize_text_field(wp_unslash($_REQUEST['query'])); // Input var okay.
63 63
 		} else {
64
-			wp_send_json_error( array(
65
-				'message' => __( 'The query param is empty.', 'wordlift' ),
66
-			) );
64
+			wp_send_json_error(array(
65
+				'message' => __('The query param is empty.', 'wordlift'),
66
+			));
67 67
 		}
68 68
 
69 69
 		// Get the exclude parameter.
70
-		$exclude = ! empty( $_REQUEST['exclude'] )
71
-			? sanitize_text_field( wp_unslash( $_REQUEST['exclude'] ) ) : '';
70
+		$exclude = ! empty($_REQUEST['exclude'])
71
+			? sanitize_text_field(wp_unslash($_REQUEST['exclude'])) : '';
72 72
 
73
-		$scope = ! empty( $_REQUEST['scope'] )
74
-			? sanitize_text_field( wp_unslash( $_REQUEST['scope'] ) ) : WL_AUTOCOMPLETE_SCOPE;
73
+		$scope = ! empty($_REQUEST['scope'])
74
+			? sanitize_text_field(wp_unslash($_REQUEST['scope'])) : WL_AUTOCOMPLETE_SCOPE;
75 75
 
76 76
 		// Make request.
77
-		$response = $this->autocomplete_service->make_request( $query, $exclude, $scope );
77
+		$response = $this->autocomplete_service->make_request($query, $exclude, $scope);
78 78
 
79 79
 		// Clear any buffer.
80 80
 		ob_clean();
81 81
 
82 82
 		// If the response is valid, then send the suggestions.
83
-		if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
83
+		if ( ! is_wp_error($response) && 200 === (int) $response['response']['code']) {
84 84
 			// Echo the response.
85
-			wp_send_json_success( json_decode( wp_remote_retrieve_body( $response ), true ) );
85
+			wp_send_json_success(json_decode(wp_remote_retrieve_body($response), true));
86 86
 		} else {
87 87
 			// Default error message.
88 88
 			$error_message = 'Something went wrong.';
89 89
 
90 90
 			// Get the real error message if there is WP_Error.
91
-			if ( is_wp_error( $response ) ) {
91
+			if (is_wp_error($response)) {
92 92
 				$error_message = $response->get_error_message();
93 93
 			}
94 94
 
95 95
 			// There is an error, so send error message.
96
-			wp_send_json_error( array(
96
+			wp_send_json_error(array(
97 97
 				/* translators: Placeholders: %s - the error message that will be returned. */
98
-				'message' => sprintf( esc_html__( 'Error: %s', 'wordlift' ), $error_message ),
99
-			) );
98
+				'message' => sprintf(esc_html__('Error: %s', 'wordlift'), $error_message),
99
+			));
100 100
 		}
101 101
 	}
102 102
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-autocomplete-service.php 2 patches
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 if ( ! defined( 'ABSPATH' ) ) {
14
-	exit;
14
+    exit;
15 15
 }
16 16
 
17 17
 /**
@@ -20,93 +20,93 @@  discard block
 block discarded – undo
20 20
  * @since 3.15.0
21 21
  */
22 22
 class Wordlift_Autocomplete_Service {
23
-	/**
24
-	 * The {@link Wordlift_Configuration_Service} instance.
25
-	 *
26
-	 * @since  3.15.0
27
-	 * @access private
28
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
29
-	 */
30
-	private $configuration_service;
23
+    /**
24
+     * The {@link Wordlift_Configuration_Service} instance.
25
+     *
26
+     * @since  3.15.0
27
+     * @access private
28
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
29
+     */
30
+    private $configuration_service;
31 31
 
32
-	/**
33
-	 * A {@link Wordlift_Log_Service} instance.
34
-	 *
35
-	 * @since  3.15.0
36
-	 * @access private
37
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
38
-	 */
39
-	private $log;
32
+    /**
33
+     * A {@link Wordlift_Log_Service} instance.
34
+     *
35
+     * @since  3.15.0
36
+     * @access private
37
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
38
+     */
39
+    private $log;
40 40
 
41
-	/**
42
-	 * The {@link Class_Wordlift_Autocomplete_Service} instance.
43
-	 *
44
-	 * @since 3.15.0
45
-	 *
46
-	 * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
47
-	 */
48
-	public function __construct( $configuration_service ) {
49
-		$this->configuration_service = $configuration_service;
50
-		$this->log                   = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' );
51
-	}
41
+    /**
42
+     * The {@link Class_Wordlift_Autocomplete_Service} instance.
43
+     *
44
+     * @since 3.15.0
45
+     *
46
+     * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
47
+     */
48
+    public function __construct( $configuration_service ) {
49
+        $this->configuration_service = $configuration_service;
50
+        $this->log                   = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' );
51
+    }
52 52
 
53
-	/**
54
-	 * Make request to external API and return the response.
55
-	 *
56
-	 * @since 3.15.0
57
-	 *
58
-	 * @param string       $query The search string.
59
-	 * @param array|string $exclude The exclude parameter string.
60
-	 * @param string       $scope The search scope: "local" will search only in the local dataset; "cloud" will search also
61
-	 *                      in Wikipedia. By default is "cloud".
62
-	 *
63
-	 * @return array $response The API response.
64
-	 */
65
-	public function make_request( $query, $exclude = '', $scope = 'cloud' ) {
66
-		$url = $this->build_request_url( $query, $exclude, $scope );
53
+    /**
54
+     * Make request to external API and return the response.
55
+     *
56
+     * @since 3.15.0
57
+     *
58
+     * @param string       $query The search string.
59
+     * @param array|string $exclude The exclude parameter string.
60
+     * @param string       $scope The search scope: "local" will search only in the local dataset; "cloud" will search also
61
+     *                      in Wikipedia. By default is "cloud".
62
+     *
63
+     * @return array $response The API response.
64
+     */
65
+    public function make_request( $query, $exclude = '', $scope = 'cloud' ) {
66
+        $url = $this->build_request_url( $query, $exclude, $scope );
67 67
 
68
-		// Make request.
69
-		$response = wp_remote_get( $url );
68
+        // Make request.
69
+        $response = wp_remote_get( $url );
70 70
 
71
-		// Return the response.
72
-		return $response;
73
-	}
71
+        // Return the response.
72
+        return $response;
73
+    }
74 74
 
75
-	/**
76
-	 * Build the autocomplete url.
77
-	 *
78
-	 * @since 3.15.0
79
-	 *
80
-	 * @param string       $query The search string.
81
-	 * @param array|string $exclude The exclude parameter.
82
-	 * @param string       $scope The search scope: "local" will search only in the local dataset; "cloud" will search also
83
-	 *                      in Wikipedia. By default is "cloud".
84
-	 *
85
-	 * @return string Built url.
86
-	 */
87
-	private function build_request_url( $query, $exclude, $scope ) {
88
-		$args = array(
89
-			'key'      => $this->configuration_service->get_key(),
90
-			'language' => $this->configuration_service->get_language_code(),
91
-			'query'    => $query,
92
-			'scope'    => $scope,
93
-			'limit'    => 100,
94
-		);
75
+    /**
76
+     * Build the autocomplete url.
77
+     *
78
+     * @since 3.15.0
79
+     *
80
+     * @param string       $query The search string.
81
+     * @param array|string $exclude The exclude parameter.
82
+     * @param string       $scope The search scope: "local" will search only in the local dataset; "cloud" will search also
83
+     *                      in Wikipedia. By default is "cloud".
84
+     *
85
+     * @return string Built url.
86
+     */
87
+    private function build_request_url( $query, $exclude, $scope ) {
88
+        $args = array(
89
+            'key'      => $this->configuration_service->get_key(),
90
+            'language' => $this->configuration_service->get_language_code(),
91
+            'query'    => $query,
92
+            'scope'    => $scope,
93
+            'limit'    => 100,
94
+        );
95 95
 
96
-		// Add args to URL.
97
-		$request_url = add_query_arg(
98
-			urlencode_deep( $args ),
99
-			$this->configuration_service->get_autocomplete_url()
100
-		);
96
+        // Add args to URL.
97
+        $request_url = add_query_arg(
98
+            urlencode_deep( $args ),
99
+            $this->configuration_service->get_autocomplete_url()
100
+        );
101 101
 
102
-		// Add the exclude parameter.
103
-		if ( ! empty( $exclude ) ) {
104
-			foreach ( (array) $exclude as $item ) {
105
-				$request_url .= "&exclude=" . urlencode( $item );
106
-			}
107
-		}
102
+        // Add the exclude parameter.
103
+        if ( ! empty( $exclude ) ) {
104
+            foreach ( (array) $exclude as $item ) {
105
+                $request_url .= "&exclude=" . urlencode( $item );
106
+            }
107
+        }
108 108
 
109
-		// return the built url.
110
-		return $request_url;
111
-	}
109
+        // return the built url.
110
+        return $request_url;
111
+    }
112 112
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since      3.15.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
47 47
 	 */
48
-	public function __construct( $configuration_service ) {
48
+	public function __construct($configuration_service) {
49 49
 		$this->configuration_service = $configuration_service;
50
-		$this->log                   = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' );
50
+		$this->log                   = Wordlift_Log_Service::get_logger('Wordlift_Autocomplete_Service');
51 51
 	}
52 52
 
53 53
 	/**
@@ -62,11 +62,11 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * @return array $response The API response.
64 64
 	 */
65
-	public function make_request( $query, $exclude = '', $scope = 'cloud' ) {
66
-		$url = $this->build_request_url( $query, $exclude, $scope );
65
+	public function make_request($query, $exclude = '', $scope = 'cloud') {
66
+		$url = $this->build_request_url($query, $exclude, $scope);
67 67
 
68 68
 		// Make request.
69
-		$response = wp_remote_get( $url );
69
+		$response = wp_remote_get($url);
70 70
 
71 71
 		// Return the response.
72 72
 		return $response;
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @return string Built url.
86 86
 	 */
87
-	private function build_request_url( $query, $exclude, $scope ) {
87
+	private function build_request_url($query, $exclude, $scope) {
88 88
 		$args = array(
89 89
 			'key'      => $this->configuration_service->get_key(),
90 90
 			'language' => $this->configuration_service->get_language_code(),
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
 
96 96
 		// Add args to URL.
97 97
 		$request_url = add_query_arg(
98
-			urlencode_deep( $args ),
98
+			urlencode_deep($args),
99 99
 			$this->configuration_service->get_autocomplete_url()
100 100
 		);
101 101
 
102 102
 		// Add the exclude parameter.
103
-		if ( ! empty( $exclude ) ) {
104
-			foreach ( (array) $exclude as $item ) {
105
-				$request_url .= "&exclude=" . urlencode( $item );
103
+		if ( ! empty($exclude)) {
104
+			foreach ((array) $exclude as $item) {
105
+				$request_url .= "&exclude=".urlencode($item);
106 106
 			}
107 107
 		}
108 108
 
Please login to merge, or discard this patch.