Completed
Push — develop ( 2b9d63...78c426 )
by
unknown
03:31
created
src/includes/class-wordlift-schema-service.php 2 patches
Indentation   +715 added lines, -715 removed lines patch added patch discarded remove patch
@@ -7,730 +7,730 @@  discard block
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Schema_Service {
9 9
 
10
-	/**
11
-	 * The 'author' field name.
12
-	 *
13
-	 * @since 3.1.0
14
-	 */
15
-	const FIELD_AUTHOR = 'wl_author';
16
-
17
-	/**
18
-	 * The 'same as' field name.
19
-	 *
20
-	 * @since 3.1.0
21
-	 */
22
-	const FIELD_SAME_AS = 'entity_same_as';
23
-
24
-	/**
25
-	 * The 'date start' field name.
26
-	 *
27
-	 * @since 3.1.0
28
-	 */
29
-	const FIELD_DATE_START = 'wl_cal_date_start';
30
-
31
-	/**
32
-	 * The 'date end' field name.
33
-	 *
34
-	 * @since 3.1.0
35
-	 */
36
-	const FIELD_DATE_END = 'wl_cal_date_end';
37
-
38
-	/**
39
-	 * The 'location' field name.
40
-	 *
41
-	 * @since 3.1.0
42
-	 */
43
-	const FIELD_LOCATION = 'wl_location';
44
-
45
-	/**
46
-	 * The 'founder' field name.
47
-	 *
48
-	 * @since 3.1.0
49
-	 */
50
-	const FIELD_FOUNDER = 'wl_founder';
51
-
52
-	/**
53
-	 * The 'knows' field name.
54
-	 *
55
-	 * @since 3.1.0
56
-	 */
57
-	const FIELD_KNOWS = 'wl_knows';
58
-
59
-	/**
60
-	 * The 'birth date' field name.
61
-	 *
62
-	 * @since 3.1.0
63
-	 */
64
-	const FIELD_BIRTH_DATE = 'wl_birth_date';
65
-
66
-	/**
67
-	 * The 'birth place' field name.
68
-	 *
69
-	 * @since 3.1.0
70
-	 */
71
-	const FIELD_BIRTH_PLACE = 'wl_birth_place';
72
-
73
-	/**
74
-	 * The 'latitude' field name.
75
-	 *
76
-	 * @since 3.1.0
77
-	 */
78
-	const FIELD_GEO_LATITUDE = 'wl_geo_latitude';
79
-
80
-	/**
81
-	 * The 'longitude' field name.
82
-	 *
83
-	 * @since 3.1.0
84
-	 */
85
-	const FIELD_GEO_LONGITUDE = 'wl_geo_longitude';
86
-
87
-	/**
88
-	 * The 'streetAddress' field name.
89
-	 *
90
-	 * @since 3.1.0
91
-	 */
92
-	const FIELD_ADDRESS = 'wl_address';
10
+    /**
11
+     * The 'author' field name.
12
+     *
13
+     * @since 3.1.0
14
+     */
15
+    const FIELD_AUTHOR = 'wl_author';
16
+
17
+    /**
18
+     * The 'same as' field name.
19
+     *
20
+     * @since 3.1.0
21
+     */
22
+    const FIELD_SAME_AS = 'entity_same_as';
23
+
24
+    /**
25
+     * The 'date start' field name.
26
+     *
27
+     * @since 3.1.0
28
+     */
29
+    const FIELD_DATE_START = 'wl_cal_date_start';
30
+
31
+    /**
32
+     * The 'date end' field name.
33
+     *
34
+     * @since 3.1.0
35
+     */
36
+    const FIELD_DATE_END = 'wl_cal_date_end';
37
+
38
+    /**
39
+     * The 'location' field name.
40
+     *
41
+     * @since 3.1.0
42
+     */
43
+    const FIELD_LOCATION = 'wl_location';
44
+
45
+    /**
46
+     * The 'founder' field name.
47
+     *
48
+     * @since 3.1.0
49
+     */
50
+    const FIELD_FOUNDER = 'wl_founder';
51
+
52
+    /**
53
+     * The 'knows' field name.
54
+     *
55
+     * @since 3.1.0
56
+     */
57
+    const FIELD_KNOWS = 'wl_knows';
58
+
59
+    /**
60
+     * The 'birth date' field name.
61
+     *
62
+     * @since 3.1.0
63
+     */
64
+    const FIELD_BIRTH_DATE = 'wl_birth_date';
65
+
66
+    /**
67
+     * The 'birth place' field name.
68
+     *
69
+     * @since 3.1.0
70
+     */
71
+    const FIELD_BIRTH_PLACE = 'wl_birth_place';
72
+
73
+    /**
74
+     * The 'latitude' field name.
75
+     *
76
+     * @since 3.1.0
77
+     */
78
+    const FIELD_GEO_LATITUDE = 'wl_geo_latitude';
79
+
80
+    /**
81
+     * The 'longitude' field name.
82
+     *
83
+     * @since 3.1.0
84
+     */
85
+    const FIELD_GEO_LONGITUDE = 'wl_geo_longitude';
86
+
87
+    /**
88
+     * The 'streetAddress' field name.
89
+     *
90
+     * @since 3.1.0
91
+     */
92
+    const FIELD_ADDRESS = 'wl_address';
93 93
 	
94
-	/**
95
-	 * The 'postOfficeBoxNumber' field name.
96
-	 *
97
-	 * @since 3.3.0
98
-	 */
99
-	const FIELD_ADDRESS_PO_BOX = 'wl_address_post_office_box';
94
+    /**
95
+     * The 'postOfficeBoxNumber' field name.
96
+     *
97
+     * @since 3.3.0
98
+     */
99
+    const FIELD_ADDRESS_PO_BOX = 'wl_address_post_office_box';
100 100
 	
101
-		/**
102
-	 * The 'postalCode' field name.
103
-	 *
104
-	 * @since 3.3.0
105
-	 */
106
-	const FIELD_ADDRESS_POSTAL_CODE = 'wl_address_postal_code';
101
+        /**
102
+         * The 'postalCode' field name.
103
+         *
104
+         * @since 3.3.0
105
+         */
106
+    const FIELD_ADDRESS_POSTAL_CODE = 'wl_address_postal_code';
107 107
 	
108
-		/**
109
-	 * The 'addressLocality' field name.
110
-	 *
111
-	 * @since 3.3.0
112
-	 */
113
-	const FIELD_ADDRESS_LOCALITY = 'wl_address_locality';
114
-	/**
115
-	 * The 'addressRegion' field name.
116
-	 *
117
-	 * @since 3.3.0
118
-	 */
119
-	const FIELD_ADDRESS_REGION = 'wl_address_region';
108
+        /**
109
+         * The 'addressLocality' field name.
110
+         *
111
+         * @since 3.3.0
112
+         */
113
+    const FIELD_ADDRESS_LOCALITY = 'wl_address_locality';
114
+    /**
115
+     * The 'addressRegion' field name.
116
+     *
117
+     * @since 3.3.0
118
+     */
119
+    const FIELD_ADDRESS_REGION = 'wl_address_region';
120 120
 	
121
-	/**
122
-	 * The 'addressCountry' field name.
123
-	 *
124
-	 * @since 3.3.0
125
-	 */
126
-	const FIELD_ADDRESS_COUNTRY = 'wl_address_country';
127
-
128
-	/**
129
-	 * The 'entity type' field name.
130
-	 *
131
-	 * @since 3.1.0
132
-	 */
133
-	const FIELD_ENTITY_TYPE = 'wl_entity_type_uri';
121
+    /**
122
+     * The 'addressCountry' field name.
123
+     *
124
+     * @since 3.3.0
125
+     */
126
+    const FIELD_ADDRESS_COUNTRY = 'wl_address_country';
127
+
128
+    /**
129
+     * The 'entity type' field name.
130
+     *
131
+     * @since 3.1.0
132
+     */
133
+    const FIELD_ENTITY_TYPE = 'wl_entity_type_uri';
134 134
 	
135
-	/**
136
-	 * The 'email' field name.
137
-	 *
138
-	 * @since 3.2.0
139
-	 */
140
-	const FIELD_EMAIL = 'wl_email';
135
+    /**
136
+     * The 'email' field name.
137
+     *
138
+     * @since 3.2.0
139
+     */
140
+    const FIELD_EMAIL = 'wl_email';
141 141
 	
142
-	/**
143
-	 * The 'affiliation' field name.
144
-	 *
145
-	 * @since 3.2.0
146
-	 */
147
-	const FIELD_AFFILIATION = 'wl_affiliation';
148
-
149
-	/**
150
-	 * The 'URI' data type name.
151
-	 *
152
-	 * @since 3.1.0
153
-	 */
154
-	const DATA_TYPE_URI = 'uri';
155
-
156
-	/**
157
-	 * The 'date' data type name.
158
-	 *
159
-	 * @since 3.1.0
160
-	 */
161
-	const DATA_TYPE_DATE = 'date';
162
-
163
-	/**
164
-	 * The 'double' data type name.
165
-	 *
166
-	 * @since 3.1.0
167
-	 */
168
-	const DATA_TYPE_DOUBLE = 'double';
169
-
170
-	/**
171
-	 * The 'string' data type name.
172
-	 *
173
-	 * @since 3.1.0
174
-	 */
175
-	const DATA_TYPE_STRING = 'string';
176
-
177
-	/**
178
-	 * The 'integer' data type name.
179
-	 *
180
-	 * @since 3.1.0
181
-	 */
182
-	const DATA_TYPE_INTEGER = 'int';
183
-
184
-	/**
185
-	 * The 'boolean' data type name.
186
-	 *
187
-	 * @since 3.1.0
188
-	 */
189
-	const DATA_TYPE_BOOLEAN = 'bool';
190
-
191
-	/**
192
-	 * The schema.org Event type URI.
193
-	 *
194
-	 * @since 3.1.0
195
-	 */
196
-	const SCHEMA_EVENT_TYPE = 'http://schema.org/Event';
197
-
198
-	/**
199
-	 * The Schema service singleton instance.
200
-	 *
201
-	 * @since 3.1.0
202
-	 * @access private
203
-	 * @var \Wordlift_Schema_Service $instance The Schema service singleton instance.
204
-	 */
205
-	private static $instance;
206
-
207
-	/**
208
-	 * WordLift's schema.
209
-	 *
210
-	 * @since 3.1.0
211
-	 * @access private
212
-	 * @var array $schema WordLift's schema.
213
-	 */
214
-	private $schema;
215
-
216
-	/**
217
-	 * The Log service.
218
-	 *
219
-	 * @since 3.1.0
220
-	 * @access private
221
-	 * @var \Wordlift_Log_Service $log_service The Log service.
222
-	 */
223
-	private $log_service;
224
-
225
-	/**
226
-	 * Wordlift_Schema_Service constructor.
227
-	 *
228
-	 * @since 3.1.0
229
-	 */
230
-	public function __construct() {
231
-
232
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
233
-
234
-		// Create a singleton instance of the Schema service, useful to provide static functions to global functions.
235
-		self::$instance = $this;
236
-
237
-		// Set the taxonomy data.
238
-		// Note: parent types must be defined before child types.
239
-		$this->schema = array(
240
-			'thing'         => $this->get_thing_schema(),
241
-			'creative-work' => $this->get_creative_work_schema(),
242
-			'event'         => $this->get_event_schema(),
243
-			'organization'  => $this->get_organization_schema(),
244
-			'person'        => $this->get_person_schema(),
245
-			'place'         => $this->get_place_schema(),
246
-			'localbusiness' => $this->get_local_business_schema()
247
-		);
248
-
249
-	}
250
-
251
-	/**
252
-	 * Get a reference to the Schema service.
253
-	 *
254
-	 * @since 3.1.0
255
-	 *
256
-	 * @return Wordlift_Schema_Service A reference to the Schema service.
257
-	 */
258
-	public static function get_instance() {
259
-
260
-		return self::$instance;
261
-	}
262
-
263
-	/**
264
-	 * Get the WordLift's schema.
265
-	 *
266
-	 * @param string $name The schema name.
267
-	 *
268
-	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
269
-	 *
270
-	 * @since 3.1.0
271
-	 */
272
-	public function get_schema( $name ) {
273
-
274
-		// $this->log_service->trace( "Get schema [ name :: $name ]" );
275
-
276
-		// Check if the schema exists and, if not, return NULL.
277
-		if ( ! isset( $this->schema[ $name ] ) ) {
278
-			return null;
279
-		}
280
-
281
-		// Return the requested schema.
282
-		return $this->schema[ $name ];
283
-	}
284
-
285
-	/**
286
-	 * Get the WordLift's schema trough schema type uri.
287
-	 *
288
-	 * @param string $uri The schema uri.
289
-	 *
290
-	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
291
-	 *
292
-	 * @since 3.3.0
293
-	 */
294
-	public function get_schema_by_uri( $uri ) {
295
-
296
-		foreach ( $this->schema as $name => $schema ) {
297
-			if ( $schema[ 'uri' ] === $uri ) {
298
-				return $schema;
299
-			}
300
-		}
301
-		return null;
302
-
303
-		// Return the requested schema.
304
-		return $this->schema[ $name ];
305
-	}
306
-
307
-	/**
308
-	 * Get the 'thing' schema.
309
-	 *
310
-	 * @return array An array with the schema configuration.
311
-	 *
312
-	 * @since 3.1.0
313
-	 */
314
-	private function get_thing_schema() {
315
-
316
-		return array(
317
-			'css_class'          => 'wl-thing',
318
-			'uri'                => 'http://schema.org/Thing',
319
-			'same_as'            => array( '*' ), // set as default.
320
-			'custom_fields'      => array(
321
-				self::FIELD_SAME_AS => array(
322
-					'predicate'   => 'http://schema.org/sameAs',
323
-					'type'        => self::DATA_TYPE_URI,
324
-					'export_type' => 'http://schema.org/Thing',
325
-					'constraints' => array(
326
-						'cardinality' => INF
327
-					),
328
-					'input_field' => 'sameas'   // we need a custom metabox
329
-				)
330
-			),
331
-			// {{sameAs}} not present in the microdata template,
332
-			// because it is treated separately in *wl_content_embed_item_microdata*
333
-			'microdata_template' => '',
334
-			'templates'          => array(
335
-				'subtitle' => '{{id}}'
336
-			)
337
-		);
338
-
339
-	}
340
-
341
-	/**
342
-	 * Get the 'creative work' schema.
343
-	 *
344
-	 * @return array An array with the schema configuration.
345
-	 *
346
-	 * @since 3.1.0
347
-	 */
348
-	private function get_creative_work_schema() {
349
-
350
-		$schema = array(
351
-			'label'              => 'CreativeWork',
352
-			'description'        => 'A creative work (or a Music Album).',
353
-			'parents'            => array( 'thing' ), // give term slug as parent
354
-			'css_class'          => 'wl-creative-work',
355
-			'uri'                => 'http://schema.org/CreativeWork',
356
-			'same_as'            => array(
357
-				'http://schema.org/MusicAlbum',
358
-				'http://schema.org/Product'
359
-			),
360
-			'custom_fields'      => array(
361
-				self::FIELD_AUTHOR => array(
362
-					'predicate'   => 'http://schema.org/author',
363
-					'type'        => self::DATA_TYPE_URI,
364
-					'export_type' => 'http://schema.org/Person',
365
-					'constraints' => array(
366
-						'uri_type'    => array( 'Person', 'Organization' ),
367
-						'cardinality' => INF
368
-					)
369
-				),
370
-			),
371
-			'microdata_template' => '{{author}}',
372
-			'templates'          => array(
373
-				'subtitle' => '{{id}}'
374
-			)
375
-		);
376
-
377
-		// Merge the custom fields with those provided by the thing schema.
378
-		$thing_schema            = $this->get_thing_schema();
379
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
380
-
381
-		return $schema;
382
-	}
383
-
384
-	/**
385
-	 * Get the 'event' schema.
386
-	 *
387
-	 * @return array An array with the schema configuration.
388
-	 *
389
-	 * @since 3.1.0
390
-	 */
391
-	private function get_event_schema() {
392
-
393
-		$schema = array(
394
-			'label'              => 'Event',
395
-			'description'        => 'An event . ',
396
-			'parents'            => array( 'thing' ),
397
-			'css_class'          => 'wl-event',
398
-			'uri'                => self::SCHEMA_EVENT_TYPE,
399
-			'same_as'            => array( 'http://dbpedia.org/ontology/Event' ),
400
-			'custom_fields'      => array(
401
-				self::FIELD_DATE_START => array(
402
-					'predicate'   => 'http://schema.org/startDate',
403
-					'type'        => self::DATA_TYPE_DATE,
404
-					'export_type' => 'xsd:datetime',
405
-					'constraints' => ''
406
-				),
407
-				self::FIELD_DATE_END   => array(
408
-					'predicate'   => 'http://schema.org/endDate',
409
-					'type'        => self::DATA_TYPE_DATE,
410
-					'export_type' => 'xsd:datetime',
411
-					'constraints' => ''
412
-				),
413
-				self::FIELD_LOCATION   => array(
414
-					'predicate'   => 'http://schema.org/location',
415
-					'type'        => self::DATA_TYPE_URI,
416
-					'export_type' => 'http://schema.org/PostalAddress',
417
-					'constraints' => array(
418
-						'uri_type'    => array( 'Place', 'LocalBusiness' ),
419
-						'cardinality' => INF
420
-					)
421
-				)
422
-			),
423
-			'microdata_template' =>
424
-				'{{startDate}}
142
+    /**
143
+     * The 'affiliation' field name.
144
+     *
145
+     * @since 3.2.0
146
+     */
147
+    const FIELD_AFFILIATION = 'wl_affiliation';
148
+
149
+    /**
150
+     * The 'URI' data type name.
151
+     *
152
+     * @since 3.1.0
153
+     */
154
+    const DATA_TYPE_URI = 'uri';
155
+
156
+    /**
157
+     * The 'date' data type name.
158
+     *
159
+     * @since 3.1.0
160
+     */
161
+    const DATA_TYPE_DATE = 'date';
162
+
163
+    /**
164
+     * The 'double' data type name.
165
+     *
166
+     * @since 3.1.0
167
+     */
168
+    const DATA_TYPE_DOUBLE = 'double';
169
+
170
+    /**
171
+     * The 'string' data type name.
172
+     *
173
+     * @since 3.1.0
174
+     */
175
+    const DATA_TYPE_STRING = 'string';
176
+
177
+    /**
178
+     * The 'integer' data type name.
179
+     *
180
+     * @since 3.1.0
181
+     */
182
+    const DATA_TYPE_INTEGER = 'int';
183
+
184
+    /**
185
+     * The 'boolean' data type name.
186
+     *
187
+     * @since 3.1.0
188
+     */
189
+    const DATA_TYPE_BOOLEAN = 'bool';
190
+
191
+    /**
192
+     * The schema.org Event type URI.
193
+     *
194
+     * @since 3.1.0
195
+     */
196
+    const SCHEMA_EVENT_TYPE = 'http://schema.org/Event';
197
+
198
+    /**
199
+     * The Schema service singleton instance.
200
+     *
201
+     * @since 3.1.0
202
+     * @access private
203
+     * @var \Wordlift_Schema_Service $instance The Schema service singleton instance.
204
+     */
205
+    private static $instance;
206
+
207
+    /**
208
+     * WordLift's schema.
209
+     *
210
+     * @since 3.1.0
211
+     * @access private
212
+     * @var array $schema WordLift's schema.
213
+     */
214
+    private $schema;
215
+
216
+    /**
217
+     * The Log service.
218
+     *
219
+     * @since 3.1.0
220
+     * @access private
221
+     * @var \Wordlift_Log_Service $log_service The Log service.
222
+     */
223
+    private $log_service;
224
+
225
+    /**
226
+     * Wordlift_Schema_Service constructor.
227
+     *
228
+     * @since 3.1.0
229
+     */
230
+    public function __construct() {
231
+
232
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
233
+
234
+        // Create a singleton instance of the Schema service, useful to provide static functions to global functions.
235
+        self::$instance = $this;
236
+
237
+        // Set the taxonomy data.
238
+        // Note: parent types must be defined before child types.
239
+        $this->schema = array(
240
+            'thing'         => $this->get_thing_schema(),
241
+            'creative-work' => $this->get_creative_work_schema(),
242
+            'event'         => $this->get_event_schema(),
243
+            'organization'  => $this->get_organization_schema(),
244
+            'person'        => $this->get_person_schema(),
245
+            'place'         => $this->get_place_schema(),
246
+            'localbusiness' => $this->get_local_business_schema()
247
+        );
248
+
249
+    }
250
+
251
+    /**
252
+     * Get a reference to the Schema service.
253
+     *
254
+     * @since 3.1.0
255
+     *
256
+     * @return Wordlift_Schema_Service A reference to the Schema service.
257
+     */
258
+    public static function get_instance() {
259
+
260
+        return self::$instance;
261
+    }
262
+
263
+    /**
264
+     * Get the WordLift's schema.
265
+     *
266
+     * @param string $name The schema name.
267
+     *
268
+     * @return array|null An array with the schema configuration or NULL if the schema is not found.
269
+     *
270
+     * @since 3.1.0
271
+     */
272
+    public function get_schema( $name ) {
273
+
274
+        // $this->log_service->trace( "Get schema [ name :: $name ]" );
275
+
276
+        // Check if the schema exists and, if not, return NULL.
277
+        if ( ! isset( $this->schema[ $name ] ) ) {
278
+            return null;
279
+        }
280
+
281
+        // Return the requested schema.
282
+        return $this->schema[ $name ];
283
+    }
284
+
285
+    /**
286
+     * Get the WordLift's schema trough schema type uri.
287
+     *
288
+     * @param string $uri The schema uri.
289
+     *
290
+     * @return array|null An array with the schema configuration or NULL if the schema is not found.
291
+     *
292
+     * @since 3.3.0
293
+     */
294
+    public function get_schema_by_uri( $uri ) {
295
+
296
+        foreach ( $this->schema as $name => $schema ) {
297
+            if ( $schema[ 'uri' ] === $uri ) {
298
+                return $schema;
299
+            }
300
+        }
301
+        return null;
302
+
303
+        // Return the requested schema.
304
+        return $this->schema[ $name ];
305
+    }
306
+
307
+    /**
308
+     * Get the 'thing' schema.
309
+     *
310
+     * @return array An array with the schema configuration.
311
+     *
312
+     * @since 3.1.0
313
+     */
314
+    private function get_thing_schema() {
315
+
316
+        return array(
317
+            'css_class'          => 'wl-thing',
318
+            'uri'                => 'http://schema.org/Thing',
319
+            'same_as'            => array( '*' ), // set as default.
320
+            'custom_fields'      => array(
321
+                self::FIELD_SAME_AS => array(
322
+                    'predicate'   => 'http://schema.org/sameAs',
323
+                    'type'        => self::DATA_TYPE_URI,
324
+                    'export_type' => 'http://schema.org/Thing',
325
+                    'constraints' => array(
326
+                        'cardinality' => INF
327
+                    ),
328
+                    'input_field' => 'sameas'   // we need a custom metabox
329
+                )
330
+            ),
331
+            // {{sameAs}} not present in the microdata template,
332
+            // because it is treated separately in *wl_content_embed_item_microdata*
333
+            'microdata_template' => '',
334
+            'templates'          => array(
335
+                'subtitle' => '{{id}}'
336
+            )
337
+        );
338
+
339
+    }
340
+
341
+    /**
342
+     * Get the 'creative work' schema.
343
+     *
344
+     * @return array An array with the schema configuration.
345
+     *
346
+     * @since 3.1.0
347
+     */
348
+    private function get_creative_work_schema() {
349
+
350
+        $schema = array(
351
+            'label'              => 'CreativeWork',
352
+            'description'        => 'A creative work (or a Music Album).',
353
+            'parents'            => array( 'thing' ), // give term slug as parent
354
+            'css_class'          => 'wl-creative-work',
355
+            'uri'                => 'http://schema.org/CreativeWork',
356
+            'same_as'            => array(
357
+                'http://schema.org/MusicAlbum',
358
+                'http://schema.org/Product'
359
+            ),
360
+            'custom_fields'      => array(
361
+                self::FIELD_AUTHOR => array(
362
+                    'predicate'   => 'http://schema.org/author',
363
+                    'type'        => self::DATA_TYPE_URI,
364
+                    'export_type' => 'http://schema.org/Person',
365
+                    'constraints' => array(
366
+                        'uri_type'    => array( 'Person', 'Organization' ),
367
+                        'cardinality' => INF
368
+                    )
369
+                ),
370
+            ),
371
+            'microdata_template' => '{{author}}',
372
+            'templates'          => array(
373
+                'subtitle' => '{{id}}'
374
+            )
375
+        );
376
+
377
+        // Merge the custom fields with those provided by the thing schema.
378
+        $thing_schema            = $this->get_thing_schema();
379
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
380
+
381
+        return $schema;
382
+    }
383
+
384
+    /**
385
+     * Get the 'event' schema.
386
+     *
387
+     * @return array An array with the schema configuration.
388
+     *
389
+     * @since 3.1.0
390
+     */
391
+    private function get_event_schema() {
392
+
393
+        $schema = array(
394
+            'label'              => 'Event',
395
+            'description'        => 'An event . ',
396
+            'parents'            => array( 'thing' ),
397
+            'css_class'          => 'wl-event',
398
+            'uri'                => self::SCHEMA_EVENT_TYPE,
399
+            'same_as'            => array( 'http://dbpedia.org/ontology/Event' ),
400
+            'custom_fields'      => array(
401
+                self::FIELD_DATE_START => array(
402
+                    'predicate'   => 'http://schema.org/startDate',
403
+                    'type'        => self::DATA_TYPE_DATE,
404
+                    'export_type' => 'xsd:datetime',
405
+                    'constraints' => ''
406
+                ),
407
+                self::FIELD_DATE_END   => array(
408
+                    'predicate'   => 'http://schema.org/endDate',
409
+                    'type'        => self::DATA_TYPE_DATE,
410
+                    'export_type' => 'xsd:datetime',
411
+                    'constraints' => ''
412
+                ),
413
+                self::FIELD_LOCATION   => array(
414
+                    'predicate'   => 'http://schema.org/location',
415
+                    'type'        => self::DATA_TYPE_URI,
416
+                    'export_type' => 'http://schema.org/PostalAddress',
417
+                    'constraints' => array(
418
+                        'uri_type'    => array( 'Place', 'LocalBusiness' ),
419
+                        'cardinality' => INF
420
+                    )
421
+                )
422
+            ),
423
+            'microdata_template' =>
424
+                '{{startDate}}
425 425
                                 {{endDate}}
426 426
                                 {{location}}',
427
-			'templates'          => array(
428
-				'subtitle' => '{{id}}'
429
-			)
430
-		);
431
-
432
-		// Merge the custom fields with those provided by the thing schema.
433
-		$thing_schema            = $this->get_thing_schema();
434
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
435
-
436
-		return $schema;
437
-	}
438
-
439
-	/**
440
-	 * Get the 'organization' schema.
441
-	 *
442
-	 * @return array An array with the schema configuration.
443
-	 *
444
-	 * @since 3.1.0
445
-	 */
446
-	private function get_organization_schema() {
447
-
448
-		$schema = array(
449
-			'label'              => 'Organization',
450
-			'description'        => 'An organization, including a government or a newspaper.',
451
-			'parents'            => array( 'thing' ),
452
-			'css_class'          => 'wl-organization',
453
-			'uri'                => 'http://schema.org/Organization',
454
-			'same_as'            => array(
455
-				'http://rdf.freebase.com/ns/organization.organization',
456
-				'http://rdf.freebase.com/ns/government.government',
457
-				'http://schema.org/Newspaper'
458
-			),
459
-			'custom_fields'      => array(
460
-				self::FIELD_FOUNDER => array(
461
-					'predicate'   => 'http://schema.org/founder',
462
-					'type'        => self::DATA_TYPE_URI,
463
-					'export_type' => 'http://schema.org/Person',
464
-					'constraints' => array(
465
-						'uri_type'    => 'Person',
466
-						'cardinality' => INF
467
-					)
468
-				),
469
-				self::FIELD_ADDRESS       => array(
470
-					'predicate'   => 'http://schema.org/streetAddress',
471
-					'type'        => self::DATA_TYPE_STRING,
472
-					'export_type' => 'xsd:string',
473
-					'constraints' => '',
474
-					'input_field' => 'address'   // to build custom metabox
475
-				),
476
-				self::FIELD_ADDRESS_PO_BOX => array(
477
-					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
478
-					'type'        => self::DATA_TYPE_STRING,
479
-					'export_type' => 'xsd:string',
480
-					'constraints' => '',
481
-					'input_field' => 'address'   // to build custom metabox
482
-				),
483
-				self::FIELD_ADDRESS_POSTAL_CODE       => array(
484
-					'predicate'   => 'http://schema.org/postalCode',
485
-					'type'        => self::DATA_TYPE_STRING,
486
-					'export_type' => 'xsd:string',
487
-					'constraints' => '',
488
-					'input_field' => 'address'   // to build custom metabox
489
-				),
490
-				self::FIELD_ADDRESS_LOCALITY       => array(
491
-					'predicate'   => 'http://schema.org/addressLocality',
492
-					'type'        => self::DATA_TYPE_STRING,
493
-					'export_type' => 'xsd:string',
494
-					'constraints' => '',
495
-					'input_field' => 'address'   // to build custom metabox
496
-				),
497
-				self::FIELD_ADDRESS_REGION       => array(
498
-					'predicate'   => 'http://schema.org/addressRegion',
499
-					'type'        => self::DATA_TYPE_STRING,
500
-					'export_type' => 'xsd:string',
501
-					'constraints' => '',
502
-					'input_field' => 'address'   // to build custom metabox
503
-				),
504
-				self::FIELD_ADDRESS_COUNTRY       => array(
505
-					'predicate'   => 'http://schema.org/addressCountry',
506
-					'type'        => self::DATA_TYPE_STRING,
507
-					'export_type' => 'xsd:string',
508
-					'constraints' => '',
509
-					'input_field' => 'address'   // to build custom metabox
510
-				),
511
-				self::FIELD_EMAIL => array(
512
-					'predicate'   => 'http://schema.org/email',
513
-					'type'        => self::DATA_TYPE_STRING,
514
-					'export_type' => 'xsd:string',
515
-					'constraints' => ''
516
-				)
517
-			),
518
-			'microdata_template' =>
519
-				'{{founder}}
427
+            'templates'          => array(
428
+                'subtitle' => '{{id}}'
429
+            )
430
+        );
431
+
432
+        // Merge the custom fields with those provided by the thing schema.
433
+        $thing_schema            = $this->get_thing_schema();
434
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
435
+
436
+        return $schema;
437
+    }
438
+
439
+    /**
440
+     * Get the 'organization' schema.
441
+     *
442
+     * @return array An array with the schema configuration.
443
+     *
444
+     * @since 3.1.0
445
+     */
446
+    private function get_organization_schema() {
447
+
448
+        $schema = array(
449
+            'label'              => 'Organization',
450
+            'description'        => 'An organization, including a government or a newspaper.',
451
+            'parents'            => array( 'thing' ),
452
+            'css_class'          => 'wl-organization',
453
+            'uri'                => 'http://schema.org/Organization',
454
+            'same_as'            => array(
455
+                'http://rdf.freebase.com/ns/organization.organization',
456
+                'http://rdf.freebase.com/ns/government.government',
457
+                'http://schema.org/Newspaper'
458
+            ),
459
+            'custom_fields'      => array(
460
+                self::FIELD_FOUNDER => array(
461
+                    'predicate'   => 'http://schema.org/founder',
462
+                    'type'        => self::DATA_TYPE_URI,
463
+                    'export_type' => 'http://schema.org/Person',
464
+                    'constraints' => array(
465
+                        'uri_type'    => 'Person',
466
+                        'cardinality' => INF
467
+                    )
468
+                ),
469
+                self::FIELD_ADDRESS       => array(
470
+                    'predicate'   => 'http://schema.org/streetAddress',
471
+                    'type'        => self::DATA_TYPE_STRING,
472
+                    'export_type' => 'xsd:string',
473
+                    'constraints' => '',
474
+                    'input_field' => 'address'   // to build custom metabox
475
+                ),
476
+                self::FIELD_ADDRESS_PO_BOX => array(
477
+                    'predicate'   => 'http://schema.org/postOfficeBoxNumber',
478
+                    'type'        => self::DATA_TYPE_STRING,
479
+                    'export_type' => 'xsd:string',
480
+                    'constraints' => '',
481
+                    'input_field' => 'address'   // to build custom metabox
482
+                ),
483
+                self::FIELD_ADDRESS_POSTAL_CODE       => array(
484
+                    'predicate'   => 'http://schema.org/postalCode',
485
+                    'type'        => self::DATA_TYPE_STRING,
486
+                    'export_type' => 'xsd:string',
487
+                    'constraints' => '',
488
+                    'input_field' => 'address'   // to build custom metabox
489
+                ),
490
+                self::FIELD_ADDRESS_LOCALITY       => array(
491
+                    'predicate'   => 'http://schema.org/addressLocality',
492
+                    'type'        => self::DATA_TYPE_STRING,
493
+                    'export_type' => 'xsd:string',
494
+                    'constraints' => '',
495
+                    'input_field' => 'address'   // to build custom metabox
496
+                ),
497
+                self::FIELD_ADDRESS_REGION       => array(
498
+                    'predicate'   => 'http://schema.org/addressRegion',
499
+                    'type'        => self::DATA_TYPE_STRING,
500
+                    'export_type' => 'xsd:string',
501
+                    'constraints' => '',
502
+                    'input_field' => 'address'   // to build custom metabox
503
+                ),
504
+                self::FIELD_ADDRESS_COUNTRY       => array(
505
+                    'predicate'   => 'http://schema.org/addressCountry',
506
+                    'type'        => self::DATA_TYPE_STRING,
507
+                    'export_type' => 'xsd:string',
508
+                    'constraints' => '',
509
+                    'input_field' => 'address'   // to build custom metabox
510
+                ),
511
+                self::FIELD_EMAIL => array(
512
+                    'predicate'   => 'http://schema.org/email',
513
+                    'type'        => self::DATA_TYPE_STRING,
514
+                    'export_type' => 'xsd:string',
515
+                    'constraints' => ''
516
+                )
517
+            ),
518
+            'microdata_template' =>
519
+                '{{founder}}
520 520
 				<span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
521 521
 					{{streetAddress}}{{postOfficeBoxNumber}}{{postalCode}}{{addressLocality}}{{addressRegion}}{{addressCountry}}{{email}}
522 522
 				</span>',
523
-			'templates'          => array(
524
-				'subtitle' => '{{id}}'
525
-			)
526
-		);
527
-
528
-		// Merge the custom fields with those provided by the thing schema.
529
-		$thing_schema            = $this->get_thing_schema();
530
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
531
-
532
-		return $schema;
533
-	}
534
-
535
-	/**
536
-	 * Get the 'person' schema.
537
-	 *
538
-	 * @return array An array with the schema configuration.
539
-	 *
540
-	 * @since 3.1.0
541
-	 */
542
-	private function get_person_schema() {
543
-
544
-		$schema = array(
545
-			'label'              => 'Person',
546
-			'description'        => 'A person (or a music artist).',
547
-			'parents'            => array( 'thing' ),
548
-			'css_class'          => 'wl-person',
549
-			'uri'                => 'http://schema.org/Person',
550
-			'same_as'            => array(
551
-				'http://rdf.freebase.com/ns/people.person',
552
-				'http://rdf.freebase.com/ns/music.artist',
553
-				'http://dbpedia.org/class/yago/LivingPeople'
554
-			),
555
-			'custom_fields'      => array(
556
-				self::FIELD_KNOWS       => array(
557
-					'predicate'   => 'http://schema.org/knows',
558
-					'type'        => self::DATA_TYPE_URI,
559
-					'export_type' => 'http://schema.org/Person',
560
-					'constraints' => array(
561
-						'uri_type'    => 'Person',
562
-						'cardinality' => INF
563
-					)
564
-				),
565
-				self::FIELD_BIRTH_DATE  => array(
566
-					'predicate'   => 'http://schema.org/birthDate',
567
-					'type'        => self::DATA_TYPE_DATE,
568
-					'export_type' => 'xsd:date',
569
-					'constraints' => ''
570
-				),
571
-				self::FIELD_BIRTH_PLACE => array(
572
-					'predicate'   => 'http://schema.org/birthPlace',
573
-					'type'        => self::DATA_TYPE_URI,
574
-					'export_type' => 'http://schema.org/Place',
575
-					'constraints' => array(
576
-						'uri_type' => 'Place'
577
-					)
578
-				),
579
-				self::FIELD_AFFILIATION => array(
580
-					'predicate'   => 'http://schema.org/affiliation',
581
-					'type'        => self::DATA_TYPE_URI,
582
-					'export_type' => 'http://schema.org/Organization',
583
-					'constraints' => array(
584
-						'uri_type' => array( 'Organization', 'LocalBusiness' ),
585
-						'cardinality' => INF
586
-					)
587
-				),
588
-				self::FIELD_EMAIL => array(
589
-					'predicate'   => 'http://schema.org/email',
590
-					'type'        => self::DATA_TYPE_STRING,
591
-					'export_type' => 'xsd:string',
592
-					'constraints' => array(
593
-						'cardinality' => INF
594
-					)
595
-				)
596
-			),
597
-			'microdata_template' =>
598
-				'{{birthDate}}
523
+            'templates'          => array(
524
+                'subtitle' => '{{id}}'
525
+            )
526
+        );
527
+
528
+        // Merge the custom fields with those provided by the thing schema.
529
+        $thing_schema            = $this->get_thing_schema();
530
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
531
+
532
+        return $schema;
533
+    }
534
+
535
+    /**
536
+     * Get the 'person' schema.
537
+     *
538
+     * @return array An array with the schema configuration.
539
+     *
540
+     * @since 3.1.0
541
+     */
542
+    private function get_person_schema() {
543
+
544
+        $schema = array(
545
+            'label'              => 'Person',
546
+            'description'        => 'A person (or a music artist).',
547
+            'parents'            => array( 'thing' ),
548
+            'css_class'          => 'wl-person',
549
+            'uri'                => 'http://schema.org/Person',
550
+            'same_as'            => array(
551
+                'http://rdf.freebase.com/ns/people.person',
552
+                'http://rdf.freebase.com/ns/music.artist',
553
+                'http://dbpedia.org/class/yago/LivingPeople'
554
+            ),
555
+            'custom_fields'      => array(
556
+                self::FIELD_KNOWS       => array(
557
+                    'predicate'   => 'http://schema.org/knows',
558
+                    'type'        => self::DATA_TYPE_URI,
559
+                    'export_type' => 'http://schema.org/Person',
560
+                    'constraints' => array(
561
+                        'uri_type'    => 'Person',
562
+                        'cardinality' => INF
563
+                    )
564
+                ),
565
+                self::FIELD_BIRTH_DATE  => array(
566
+                    'predicate'   => 'http://schema.org/birthDate',
567
+                    'type'        => self::DATA_TYPE_DATE,
568
+                    'export_type' => 'xsd:date',
569
+                    'constraints' => ''
570
+                ),
571
+                self::FIELD_BIRTH_PLACE => array(
572
+                    'predicate'   => 'http://schema.org/birthPlace',
573
+                    'type'        => self::DATA_TYPE_URI,
574
+                    'export_type' => 'http://schema.org/Place',
575
+                    'constraints' => array(
576
+                        'uri_type' => 'Place'
577
+                    )
578
+                ),
579
+                self::FIELD_AFFILIATION => array(
580
+                    'predicate'   => 'http://schema.org/affiliation',
581
+                    'type'        => self::DATA_TYPE_URI,
582
+                    'export_type' => 'http://schema.org/Organization',
583
+                    'constraints' => array(
584
+                        'uri_type' => array( 'Organization', 'LocalBusiness' ),
585
+                        'cardinality' => INF
586
+                    )
587
+                ),
588
+                self::FIELD_EMAIL => array(
589
+                    'predicate'   => 'http://schema.org/email',
590
+                    'type'        => self::DATA_TYPE_STRING,
591
+                    'export_type' => 'xsd:string',
592
+                    'constraints' => array(
593
+                        'cardinality' => INF
594
+                    )
595
+                )
596
+            ),
597
+            'microdata_template' =>
598
+                '{{birthDate}}
599 599
                  {{birthPlace}}
600 600
                  {{knows}}
601 601
 				 {{affiliation}}
602 602
 				 {{email}}',
603
-			'templates'          => array(
604
-				'subtitle' => '{{id}}'
605
-			)
606
-		);
607
-
608
-		// Merge the custom fields with those provided by the thing schema.
609
-		$thing_schema            = $this->get_thing_schema();
610
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
611
-
612
-		return $schema;
613
-
614
-	}
615
-
616
-	/**
617
-	 * Get the 'place' schema.
618
-	 *
619
-	 * @return array An array with the schema configuration.
620
-	 *
621
-	 * @since 3.1.0
622
-	 */
623
-	private function get_place_schema() {
624
-
625
-		$schema = array(
626
-			'label'              => 'Place',
627
-			'description'        => 'A place.',
628
-			'parents'            => array( 'thing' ),
629
-			'css_class'          => 'wl-place',
630
-			'uri'                => 'http://schema.org/Place',
631
-			'same_as'            => array(
632
-				'http://rdf.freebase.com/ns/location.location',
633
-				'http://www.opengis.net/gml/_Feature'
634
-			),
635
-			'custom_fields'      => array(
636
-				self::FIELD_GEO_LATITUDE  => array(
637
-					'predicate'   => 'http://schema.org/latitude',
638
-					'type'        => self::DATA_TYPE_DOUBLE,
639
-					'export_type' => 'xsd:double',
640
-					'constraints' => '',
641
-					'input_field' => 'coordinates'   // to build custom metabox
642
-				),
643
-				self::FIELD_GEO_LONGITUDE => array(
644
-					'predicate'   => 'http://schema.org/longitude',
645
-					'type'        => self::DATA_TYPE_DOUBLE,
646
-					'export_type' => 'xsd:double',
647
-					'constraints' => '',
648
-					'input_field' => 'coordinates'   // to build custom metabox
649
-				),
650
-				self::FIELD_ADDRESS       => array(
651
-					'predicate'   => 'http://schema.org/streetAddress',
652
-					'type'        => self::DATA_TYPE_STRING,
653
-					'export_type' => 'xsd:string',
654
-					'constraints' => '',
655
-					'input_field' => 'address'   // to build custom metabox
656
-				),
657
-				self::FIELD_ADDRESS_PO_BOX => array(
658
-					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
659
-					'type'        => self::DATA_TYPE_STRING,
660
-					'export_type' => 'xsd:string',
661
-					'constraints' => '',
662
-					'input_field' => 'address'   // to build custom metabox
663
-				),
664
-				self::FIELD_ADDRESS_POSTAL_CODE       => array(
665
-					'predicate'   => 'http://schema.org/postalCode',
666
-					'type'        => self::DATA_TYPE_STRING,
667
-					'export_type' => 'xsd:string',
668
-					'constraints' => '',
669
-					'input_field' => 'address'   // to build custom metabox
670
-				),
671
-				self::FIELD_ADDRESS_LOCALITY       => array(
672
-					'predicate'   => 'http://schema.org/addressLocality',
673
-					'type'        => self::DATA_TYPE_STRING,
674
-					'export_type' => 'xsd:string',
675
-					'constraints' => '',
676
-					'input_field' => 'address'   // to build custom metabox
677
-				),
678
-				self::FIELD_ADDRESS_REGION       => array(
679
-					'predicate'   => 'http://schema.org/addressRegion',
680
-					'type'        => self::DATA_TYPE_STRING,
681
-					'export_type' => 'xsd:string',
682
-					'constraints' => '',
683
-					'input_field' => 'address'   // to build custom metabox
684
-				),
685
-				self::FIELD_ADDRESS_COUNTRY       => array(
686
-					'predicate'   => 'http://schema.org/addressCountry',
687
-					'type'        => self::DATA_TYPE_STRING,
688
-					'export_type' => 'xsd:string',
689
-					'constraints' => '',
690
-					'input_field' => 'address'   // to build custom metabox
691
-				)				
692
-			),
693
-			'microdata_template' =>
694
-				'<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">
603
+            'templates'          => array(
604
+                'subtitle' => '{{id}}'
605
+            )
606
+        );
607
+
608
+        // Merge the custom fields with those provided by the thing schema.
609
+        $thing_schema            = $this->get_thing_schema();
610
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
611
+
612
+        return $schema;
613
+
614
+    }
615
+
616
+    /**
617
+     * Get the 'place' schema.
618
+     *
619
+     * @return array An array with the schema configuration.
620
+     *
621
+     * @since 3.1.0
622
+     */
623
+    private function get_place_schema() {
624
+
625
+        $schema = array(
626
+            'label'              => 'Place',
627
+            'description'        => 'A place.',
628
+            'parents'            => array( 'thing' ),
629
+            'css_class'          => 'wl-place',
630
+            'uri'                => 'http://schema.org/Place',
631
+            'same_as'            => array(
632
+                'http://rdf.freebase.com/ns/location.location',
633
+                'http://www.opengis.net/gml/_Feature'
634
+            ),
635
+            'custom_fields'      => array(
636
+                self::FIELD_GEO_LATITUDE  => array(
637
+                    'predicate'   => 'http://schema.org/latitude',
638
+                    'type'        => self::DATA_TYPE_DOUBLE,
639
+                    'export_type' => 'xsd:double',
640
+                    'constraints' => '',
641
+                    'input_field' => 'coordinates'   // to build custom metabox
642
+                ),
643
+                self::FIELD_GEO_LONGITUDE => array(
644
+                    'predicate'   => 'http://schema.org/longitude',
645
+                    'type'        => self::DATA_TYPE_DOUBLE,
646
+                    'export_type' => 'xsd:double',
647
+                    'constraints' => '',
648
+                    'input_field' => 'coordinates'   // to build custom metabox
649
+                ),
650
+                self::FIELD_ADDRESS       => array(
651
+                    'predicate'   => 'http://schema.org/streetAddress',
652
+                    'type'        => self::DATA_TYPE_STRING,
653
+                    'export_type' => 'xsd:string',
654
+                    'constraints' => '',
655
+                    'input_field' => 'address'   // to build custom metabox
656
+                ),
657
+                self::FIELD_ADDRESS_PO_BOX => array(
658
+                    'predicate'   => 'http://schema.org/postOfficeBoxNumber',
659
+                    'type'        => self::DATA_TYPE_STRING,
660
+                    'export_type' => 'xsd:string',
661
+                    'constraints' => '',
662
+                    'input_field' => 'address'   // to build custom metabox
663
+                ),
664
+                self::FIELD_ADDRESS_POSTAL_CODE       => array(
665
+                    'predicate'   => 'http://schema.org/postalCode',
666
+                    'type'        => self::DATA_TYPE_STRING,
667
+                    'export_type' => 'xsd:string',
668
+                    'constraints' => '',
669
+                    'input_field' => 'address'   // to build custom metabox
670
+                ),
671
+                self::FIELD_ADDRESS_LOCALITY       => array(
672
+                    'predicate'   => 'http://schema.org/addressLocality',
673
+                    'type'        => self::DATA_TYPE_STRING,
674
+                    'export_type' => 'xsd:string',
675
+                    'constraints' => '',
676
+                    'input_field' => 'address'   // to build custom metabox
677
+                ),
678
+                self::FIELD_ADDRESS_REGION       => array(
679
+                    'predicate'   => 'http://schema.org/addressRegion',
680
+                    'type'        => self::DATA_TYPE_STRING,
681
+                    'export_type' => 'xsd:string',
682
+                    'constraints' => '',
683
+                    'input_field' => 'address'   // to build custom metabox
684
+                ),
685
+                self::FIELD_ADDRESS_COUNTRY       => array(
686
+                    'predicate'   => 'http://schema.org/addressCountry',
687
+                    'type'        => self::DATA_TYPE_STRING,
688
+                    'export_type' => 'xsd:string',
689
+                    'constraints' => '',
690
+                    'input_field' => 'address'   // to build custom metabox
691
+                )				
692
+            ),
693
+            'microdata_template' =>
694
+                '<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">
695 695
 					{{latitude}}
696 696
 					{{longitude}}
697 697
 				</span>
698 698
 				<span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
699 699
 					{{streetAddress}}{{postOfficeBoxNumber}}{{postalCode}}{{addressLocality}}{{addressRegion}}{{addressCountry}}
700 700
 				</span>',
701
-			'templates'          => array(
702
-				'subtitle' => '{{id}}'
703
-			)
704
-		);
705
-
706
-		// Merge the custom fields with those provided by the thing schema.
707
-		$thing_schema            = $this->get_thing_schema();
708
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
709
-
710
-		return $schema;
711
-	}
712
-
713
-	/**
714
-	 * Get the 'local business' schema.
715
-	 *
716
-	 * @return array An array with the schema configuration.
717
-	 *
718
-	 * @since 3.1.0
719
-	 */
720
-	private function get_local_business_schema() {
721
-
722
-		$schema = array(
723
-			'label'              => 'LocalBusiness',
724
-			'description'        => 'A local business.',
725
-			'parents'            => array( 'place', 'organization' ),
726
-			'css_class'          => 'wl-local-business',
727
-			'uri'                => 'http://schema.org/LocalBusiness',
728
-			'same_as'            => array(
729
-				'http://rdf.freebase.com/ns/business/business_location',
730
-				'https://schema.org/Store'
731
-			),
732
-			'custom_fields'      => array(),
733
-			'microdata_template' => '<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">
701
+            'templates'          => array(
702
+                'subtitle' => '{{id}}'
703
+            )
704
+        );
705
+
706
+        // Merge the custom fields with those provided by the thing schema.
707
+        $thing_schema            = $this->get_thing_schema();
708
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
709
+
710
+        return $schema;
711
+    }
712
+
713
+    /**
714
+     * Get the 'local business' schema.
715
+     *
716
+     * @return array An array with the schema configuration.
717
+     *
718
+     * @since 3.1.0
719
+     */
720
+    private function get_local_business_schema() {
721
+
722
+        $schema = array(
723
+            'label'              => 'LocalBusiness',
724
+            'description'        => 'A local business.',
725
+            'parents'            => array( 'place', 'organization' ),
726
+            'css_class'          => 'wl-local-business',
727
+            'uri'                => 'http://schema.org/LocalBusiness',
728
+            'same_as'            => array(
729
+                'http://rdf.freebase.com/ns/business/business_location',
730
+                'https://schema.org/Store'
731
+            ),
732
+            'custom_fields'      => array(),
733
+            'microdata_template' => '<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">
734 734
                                     {{latitude}}
735 735
                                     {{longitude}}
736 736
                                 </span>
@@ -739,17 +739,17 @@  discard block
 block discarded – undo
739 739
 								</span>
740 740
                                 {{founder}}
741 741
 								{{email}}',
742
-			'templates'          => array(
743
-				'subtitle' => '{{id}}'
744
-			)
745
-		);
746
-
747
-		// Merge the custom fields with those provided by the place and organization schema.
748
-		$place_schema            = $this->get_place_schema();
749
-		$organization_schema     = $this->get_organization_schema();
750
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
751
-
752
-		return $schema;
753
-	}
742
+            'templates'          => array(
743
+                'subtitle' => '{{id}}'
744
+            )
745
+        );
746
+
747
+        // Merge the custom fields with those provided by the place and organization schema.
748
+        $place_schema            = $this->get_place_schema();
749
+        $organization_schema     = $this->get_organization_schema();
750
+        $schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
751
+
752
+        return $schema;
753
+    }
754 754
 
755 755
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	 */
230 230
 	public function __construct() {
231 231
 
232
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
232
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Schema_Service');
233 233
 
234 234
 		// Create a singleton instance of the Schema service, useful to provide static functions to global functions.
235 235
 		self::$instance = $this;
@@ -269,17 +269,17 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 * @since 3.1.0
271 271
 	 */
272
-	public function get_schema( $name ) {
272
+	public function get_schema($name) {
273 273
 
274 274
 		// $this->log_service->trace( "Get schema [ name :: $name ]" );
275 275
 
276 276
 		// Check if the schema exists and, if not, return NULL.
277
-		if ( ! isset( $this->schema[ $name ] ) ) {
277
+		if ( ! isset($this->schema[$name])) {
278 278
 			return null;
279 279
 		}
280 280
 
281 281
 		// Return the requested schema.
282
-		return $this->schema[ $name ];
282
+		return $this->schema[$name];
283 283
 	}
284 284
 
285 285
 	/**
@@ -291,17 +291,17 @@  discard block
 block discarded – undo
291 291
 	 *
292 292
 	 * @since 3.3.0
293 293
 	 */
294
-	public function get_schema_by_uri( $uri ) {
294
+	public function get_schema_by_uri($uri) {
295 295
 
296
-		foreach ( $this->schema as $name => $schema ) {
297
-			if ( $schema[ 'uri' ] === $uri ) {
296
+		foreach ($this->schema as $name => $schema) {
297
+			if ($schema['uri'] === $uri) {
298 298
 				return $schema;
299 299
 			}
300 300
 		}
301 301
 		return null;
302 302
 
303 303
 		// Return the requested schema.
304
-		return $this->schema[ $name ];
304
+		return $this->schema[$name];
305 305
 	}
306 306
 
307 307
 	/**
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		return array(
317 317
 			'css_class'          => 'wl-thing',
318 318
 			'uri'                => 'http://schema.org/Thing',
319
-			'same_as'            => array( '*' ), // set as default.
319
+			'same_as'            => array('*'), // set as default.
320 320
 			'custom_fields'      => array(
321 321
 				self::FIELD_SAME_AS => array(
322 322
 					'predicate'   => 'http://schema.org/sameAs',
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 		$schema = array(
351 351
 			'label'              => 'CreativeWork',
352 352
 			'description'        => 'A creative work (or a Music Album).',
353
-			'parents'            => array( 'thing' ), // give term slug as parent
353
+			'parents'            => array('thing'), // give term slug as parent
354 354
 			'css_class'          => 'wl-creative-work',
355 355
 			'uri'                => 'http://schema.org/CreativeWork',
356 356
 			'same_as'            => array(
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 					'type'        => self::DATA_TYPE_URI,
364 364
 					'export_type' => 'http://schema.org/Person',
365 365
 					'constraints' => array(
366
-						'uri_type'    => array( 'Person', 'Organization' ),
366
+						'uri_type'    => array('Person', 'Organization'),
367 367
 						'cardinality' => INF
368 368
 					)
369 369
 				),
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 
377 377
 		// Merge the custom fields with those provided by the thing schema.
378 378
 		$thing_schema            = $this->get_thing_schema();
379
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
379
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $thing_schema['custom_fields']);
380 380
 
381 381
 		return $schema;
382 382
 	}
@@ -393,10 +393,10 @@  discard block
 block discarded – undo
393 393
 		$schema = array(
394 394
 			'label'              => 'Event',
395 395
 			'description'        => 'An event . ',
396
-			'parents'            => array( 'thing' ),
396
+			'parents'            => array('thing'),
397 397
 			'css_class'          => 'wl-event',
398 398
 			'uri'                => self::SCHEMA_EVENT_TYPE,
399
-			'same_as'            => array( 'http://dbpedia.org/ontology/Event' ),
399
+			'same_as'            => array('http://dbpedia.org/ontology/Event'),
400 400
 			'custom_fields'      => array(
401 401
 				self::FIELD_DATE_START => array(
402 402
 					'predicate'   => 'http://schema.org/startDate',
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 					'type'        => self::DATA_TYPE_URI,
416 416
 					'export_type' => 'http://schema.org/PostalAddress',
417 417
 					'constraints' => array(
418
-						'uri_type'    => array( 'Place', 'LocalBusiness' ),
418
+						'uri_type'    => array('Place', 'LocalBusiness'),
419 419
 						'cardinality' => INF
420 420
 					)
421 421
 				)
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 
432 432
 		// Merge the custom fields with those provided by the thing schema.
433 433
 		$thing_schema            = $this->get_thing_schema();
434
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
434
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $thing_schema['custom_fields']);
435 435
 
436 436
 		return $schema;
437 437
 	}
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
 		$schema = array(
449 449
 			'label'              => 'Organization',
450 450
 			'description'        => 'An organization, including a government or a newspaper.',
451
-			'parents'            => array( 'thing' ),
451
+			'parents'            => array('thing'),
452 452
 			'css_class'          => 'wl-organization',
453 453
 			'uri'                => 'http://schema.org/Organization',
454 454
 			'same_as'            => array(
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 
528 528
 		// Merge the custom fields with those provided by the thing schema.
529 529
 		$thing_schema            = $this->get_thing_schema();
530
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
530
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $thing_schema['custom_fields']);
531 531
 
532 532
 		return $schema;
533 533
 	}
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 		$schema = array(
545 545
 			'label'              => 'Person',
546 546
 			'description'        => 'A person (or a music artist).',
547
-			'parents'            => array( 'thing' ),
547
+			'parents'            => array('thing'),
548 548
 			'css_class'          => 'wl-person',
549 549
 			'uri'                => 'http://schema.org/Person',
550 550
 			'same_as'            => array(
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 					'type'        => self::DATA_TYPE_URI,
582 582
 					'export_type' => 'http://schema.org/Organization',
583 583
 					'constraints' => array(
584
-						'uri_type' => array( 'Organization', 'LocalBusiness' ),
584
+						'uri_type' => array('Organization', 'LocalBusiness'),
585 585
 						'cardinality' => INF
586 586
 					)
587 587
 				),
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 
608 608
 		// Merge the custom fields with those provided by the thing schema.
609 609
 		$thing_schema            = $this->get_thing_schema();
610
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
610
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $thing_schema['custom_fields']);
611 611
 
612 612
 		return $schema;
613 613
 
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
 		$schema = array(
626 626
 			'label'              => 'Place',
627 627
 			'description'        => 'A place.',
628
-			'parents'            => array( 'thing' ),
628
+			'parents'            => array('thing'),
629 629
 			'css_class'          => 'wl-place',
630 630
 			'uri'                => 'http://schema.org/Place',
631 631
 			'same_as'            => array(
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
 
706 706
 		// Merge the custom fields with those provided by the thing schema.
707 707
 		$thing_schema            = $this->get_thing_schema();
708
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
708
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $thing_schema['custom_fields']);
709 709
 
710 710
 		return $schema;
711 711
 	}
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
 		$schema = array(
723 723
 			'label'              => 'LocalBusiness',
724 724
 			'description'        => 'A local business.',
725
-			'parents'            => array( 'place', 'organization' ),
725
+			'parents'            => array('place', 'organization'),
726 726
 			'css_class'          => 'wl-local-business',
727 727
 			'uri'                => 'http://schema.org/LocalBusiness',
728 728
 			'same_as'            => array(
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
 		// Merge the custom fields with those provided by the place and organization schema.
748 748
 		$place_schema            = $this->get_place_schema();
749 749
 		$organization_schema     = $this->get_organization_schema();
750
-		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
750
+		$schema['custom_fields'] = array_merge($schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields']);
751 751
 
752 752
 		return $schema;
753 753
 	}
Please login to merge, or discard this patch.
src/admin/WL_Metabox/WL_Metabox.php 2 patches
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -14,255 +14,255 @@
 block discarded – undo
14 14
  */
15 15
 class WL_Metabox {
16 16
 
17
-	public $fields;
18
-
19
-	/**
20
-	 * The Log service.
21
-	 *
22
-	 * @since 3.1.0
23
-	 * @access private
24
-	 * @var Wordlift_Log_Service $log_service The Log service.
25
-	 */
26
-	private $log_service;
27
-
28
-	/**
29
-	 * WL_Metabox constructor.
30
-	 *
31
-	 * @since 3.1.0
32
-	 */
33
-	public function __construct() {
34
-
35
-		// Create a logger instance.
36
-		$this->log_service = Wordlift_Log_Service::get_logger( 'WL_Metabox' );
37
-
38
-		// Add hooks to print metaboxes and save submitted data.
39
-		add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
40
-		add_action( 'wl_linked_data_save_post', array( &$this, 'save_form_data' ) );
41
-
42
-		// Enqueue js and css
43
-		$this->enqueue_scripts_and_styles();
44
-
45
-	}
46
-
47
-	/**
48
-	 * Add a callback to print the metabox in page.
49
-	 * Wordpress will fire the $this->html() callback at the right time.
50
-	 */
51
-	public function add_main_metabox() {
52
-
53
-		// Add main metabox (will print also the inner fields)
54
-		$id		= uniqid( 'wl-metabox-' );
55
-		$title	= get_the_title() . ' ' . __('properties', 'wordlift');
56
-		add_meta_box( $id, $title, array(
57
-			$this,
58
-			'html'
59
-		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
17
+    public $fields;
18
+
19
+    /**
20
+     * The Log service.
21
+     *
22
+     * @since 3.1.0
23
+     * @access private
24
+     * @var Wordlift_Log_Service $log_service The Log service.
25
+     */
26
+    private $log_service;
27
+
28
+    /**
29
+     * WL_Metabox constructor.
30
+     *
31
+     * @since 3.1.0
32
+     */
33
+    public function __construct() {
34
+
35
+        // Create a logger instance.
36
+        $this->log_service = Wordlift_Log_Service::get_logger( 'WL_Metabox' );
37
+
38
+        // Add hooks to print metaboxes and save submitted data.
39
+        add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
40
+        add_action( 'wl_linked_data_save_post', array( &$this, 'save_form_data' ) );
41
+
42
+        // Enqueue js and css
43
+        $this->enqueue_scripts_and_styles();
44
+
45
+    }
46
+
47
+    /**
48
+     * Add a callback to print the metabox in page.
49
+     * Wordpress will fire the $this->html() callback at the right time.
50
+     */
51
+    public function add_main_metabox() {
52
+
53
+        // Add main metabox (will print also the inner fields)
54
+        $id		= uniqid( 'wl-metabox-' );
55
+        $title	= get_the_title() . ' ' . __('properties', 'wordlift');
56
+        add_meta_box( $id, $title, array(
57
+            $this,
58
+            'html'
59
+        ), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
60 60
 		
61
-		// Add filter to change the metabox CSS class
62
-		add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
63
-	}
64
-
65
-	/**
66
-	 * Called from WP to print the metabox content in page.
67
-	 *
68
-	 * @since 3.1.0
69
-	 *
70
-	 * @param WP_Post $post The post.
71
-	 */
72
-	public function html( $post ) {
73
-
74
-		// Build the fields we need to print.
75
-		$this->instantiate_fields( $post->ID );
76
-
77
-		// Loop over the fields
78
-		foreach ( $this->fields as $field ) {
61
+        // Add filter to change the metabox CSS class
62
+        add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
63
+    }
64
+
65
+    /**
66
+     * Called from WP to print the metabox content in page.
67
+     *
68
+     * @since 3.1.0
69
+     *
70
+     * @param WP_Post $post The post.
71
+     */
72
+    public function html( $post ) {
73
+
74
+        // Build the fields we need to print.
75
+        $this->instantiate_fields( $post->ID );
76
+
77
+        // Loop over the fields
78
+        foreach ( $this->fields as $field ) {
79 79
 
80
-			// load data from DB (values will be available in $field->data)
81
-			$field->get_data();
82
-
83
-			// print field HTML (nonce included)
84
-			echo $field->html();
85
-		}
86
-
87
-	}
88
-
89
-	/**
90
-	 * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
91
-	 *
92
-	 * Note: the first function that calls this method will instantiate the fields.
93
-	 * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
94
-	 *
95
-	 * @since 3.1.0
96
-	 *
97
-	 * @param int $post_id The post id.
98
-	 */
99
-	public function instantiate_fields( $post_id ) {
100
-
101
-		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering
102
-		if ( isset( $this->fields ) ) {
103
-			return;
104
-		}
105
-
106
-		$entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
107
-
108
-		if ( isset( $entity_type ) ) {
109
-
110
-			/**
111
-			 * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
112
-			 * We must divide fields in two groups:
113
-			 * - simple: accept values for one property
114
-			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
115
-			 */
116
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
117
-			$simple_metaboxes  = $metaboxes[0];
118
-			$grouped_metaboxes = $metaboxes[1];
119
-
120
-			// Loop over simple entity properties
121
-			foreach ( $simple_metaboxes as $key => $property ) {
122
-
123
-				// Info passed to the metabox
124
-				$info         = array();
125
-				$info[ $key ] = $property;
126
-
127
-				// Build the requested field as WL_Metabox_Field_ object
128
-				$this->add_field( $info );
129
-			}
130
-
131
-			// Loop over grouped properties
132
-			foreach ( $grouped_metaboxes as $key => $property ) {
133
-
134
-				// Info passed to the metabox
135
-				$info         = array();
136
-				$info[ $key ] = $property;
137
-
138
-				// Build the requested field group as WL_Metabox_Field_ object
139
-				$this->add_field( $info, true );
140
-			}
141
-
142
-		}
143
-	}
144
-
145
-	/**
146
-	 * Separes metaboxes in simple and grouped.
147
-	 *
148
-	 * @param array $custom_fields Information on the entity type.
149
-	 */
150
-	public function group_properties_by_input_field( $custom_fields ) {
151
-
152
-		$simple_properties  = array();
153
-		$grouped_properties = array();
154
-
155
-		// Loop over possible entity properties
156
-		foreach ( $custom_fields as $key => $property ) {
157
-
158
-			// Check presence of predicate and type
159
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
160
-
161
-				// Check if input_field is defined
162
-				if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
163
-
164
-					$grouped_key = $property['input_field'];
165
-
166
-					// Update list of grouped properties
167
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
168
-
169
-				} else {
170
-
171
-					// input_field not defined, add simple metabox
172
-					$simple_properties[ $key ] = $property;
173
-				}
174
-			}
175
-		}
80
+            // load data from DB (values will be available in $field->data)
81
+            $field->get_data();
82
+
83
+            // print field HTML (nonce included)
84
+            echo $field->html();
85
+        }
86
+
87
+    }
88
+
89
+    /**
90
+     * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
91
+     *
92
+     * Note: the first function that calls this method will instantiate the fields.
93
+     * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
94
+     *
95
+     * @since 3.1.0
96
+     *
97
+     * @param int $post_id The post id.
98
+     */
99
+    public function instantiate_fields( $post_id ) {
100
+
101
+        // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering
102
+        if ( isset( $this->fields ) ) {
103
+            return;
104
+        }
105
+
106
+        $entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
107
+
108
+        if ( isset( $entity_type ) ) {
109
+
110
+            /**
111
+             * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
112
+             * We must divide fields in two groups:
113
+             * - simple: accept values for one property
114
+             * - grouped: accept values for more properties, or for one property that needs a specific metabox.
115
+             */
116
+            $metaboxes         = $this->group_properties_by_input_field( $entity_type );
117
+            $simple_metaboxes  = $metaboxes[0];
118
+            $grouped_metaboxes = $metaboxes[1];
119
+
120
+            // Loop over simple entity properties
121
+            foreach ( $simple_metaboxes as $key => $property ) {
122
+
123
+                // Info passed to the metabox
124
+                $info         = array();
125
+                $info[ $key ] = $property;
126
+
127
+                // Build the requested field as WL_Metabox_Field_ object
128
+                $this->add_field( $info );
129
+            }
130
+
131
+            // Loop over grouped properties
132
+            foreach ( $grouped_metaboxes as $key => $property ) {
133
+
134
+                // Info passed to the metabox
135
+                $info         = array();
136
+                $info[ $key ] = $property;
137
+
138
+                // Build the requested field group as WL_Metabox_Field_ object
139
+                $this->add_field( $info, true );
140
+            }
141
+
142
+        }
143
+    }
144
+
145
+    /**
146
+     * Separes metaboxes in simple and grouped.
147
+     *
148
+     * @param array $custom_fields Information on the entity type.
149
+     */
150
+    public function group_properties_by_input_field( $custom_fields ) {
151
+
152
+        $simple_properties  = array();
153
+        $grouped_properties = array();
154
+
155
+        // Loop over possible entity properties
156
+        foreach ( $custom_fields as $key => $property ) {
157
+
158
+            // Check presence of predicate and type
159
+            if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
160
+
161
+                // Check if input_field is defined
162
+                if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
163
+
164
+                    $grouped_key = $property['input_field'];
165
+
166
+                    // Update list of grouped properties
167
+                    $grouped_properties[ $grouped_key ][ $key ] = $property;
168
+
169
+                } else {
170
+
171
+                    // input_field not defined, add simple metabox
172
+                    $simple_properties[ $key ] = $property;
173
+                }
174
+            }
175
+        }
176 176
 
177
-		return array( $simple_properties, $grouped_properties );
178
-	}
179
-
180
-	/**
181
-	 * Add a Field to the current Metabox, based on the description of the Field.
182
-	 * This method is a rude factory for Field objects.
183
-	 *
184
-	 * @param type $args
185
-	 * @param type $grouped Flag to distinguish between simple and grouped Fields
186
-	 */
187
-	public function add_field( $args, $grouped = false ) {
188
-
189
-		if ( $grouped ) {
190
-			// Special fields (sameas, coordinates, etc.)
191
-
192
-			// Build Field with a custom class (e.g. WL_Metabox_Field_date)
193
-			$field_class = 'WL_Metabox_Field_' . key( $args );
194
-
195
-		} else {
196
-			// Simple fields (string, uri, boolean, etc.)
177
+        return array( $simple_properties, $grouped_properties );
178
+    }
179
+
180
+    /**
181
+     * Add a Field to the current Metabox, based on the description of the Field.
182
+     * This method is a rude factory for Field objects.
183
+     *
184
+     * @param type $args
185
+     * @param type $grouped Flag to distinguish between simple and grouped Fields
186
+     */
187
+    public function add_field( $args, $grouped = false ) {
188
+
189
+        if ( $grouped ) {
190
+            // Special fields (sameas, coordinates, etc.)
191
+
192
+            // Build Field with a custom class (e.g. WL_Metabox_Field_date)
193
+            $field_class = 'WL_Metabox_Field_' . key( $args );
194
+
195
+        } else {
196
+            // Simple fields (string, uri, boolean, etc.)
197 197
 
198
-			// Which field? We want to use the class that is specific for the field.
199
-			$meta = key( $args );
200
-			if ( ! isset( $args[ $meta ]['type'] ) || ( $args[ $meta ]['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
201
-				// Use default WL_Metabox_Field (manages strings)
202
-				$field_class = 'WL_Metabox_Field';
203
-			} else {
204
-				// Build Field with a custom class (e.g. WL_Metabox_Field_date)
205
-				$field_class = 'WL_Metabox_Field_' . $args[ $meta ]['type'];
206
-			}
207
-		}
198
+            // Which field? We want to use the class that is specific for the field.
199
+            $meta = key( $args );
200
+            if ( ! isset( $args[ $meta ]['type'] ) || ( $args[ $meta ]['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
201
+                // Use default WL_Metabox_Field (manages strings)
202
+                $field_class = 'WL_Metabox_Field';
203
+            } else {
204
+                // Build Field with a custom class (e.g. WL_Metabox_Field_date)
205
+                $field_class = 'WL_Metabox_Field_' . $args[ $meta ]['type'];
206
+            }
207
+        }
208 208
 
209
-		// Call apropriate constructor (e.g. WL_Metabox_Field_... )
210
-		$this->fields[] = new $field_class( $args );
211
-	}
209
+        // Call apropriate constructor (e.g. WL_Metabox_Field_... )
210
+        $this->fields[] = new $field_class( $args );
211
+    }
212 212
 
213
-	public function save_form_data( $entity_id ) {
213
+    public function save_form_data( $entity_id ) {
214 214
 
215
-		// Build Field objects
216
-		$this->instantiate_fields( $entity_id );
215
+        // Build Field objects
216
+        $this->instantiate_fields( $entity_id );
217 217
 
218
-		// Check if WL metabox form was posted
219
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
220
-			return;
221
-		}
218
+        // Check if WL metabox form was posted
219
+        if ( ! isset( $_POST['wl_metaboxes'] ) ) {
220
+            return;
221
+        }
222 222
 
223
-		foreach ( $this->fields as $field ) {
223
+        foreach ( $this->fields as $field ) {
224 224
 
225
-			// Verify nonce
226
-			$valid_nonce = $field->verify_nonce();
227
-			if ( $valid_nonce ) {
225
+            // Verify nonce
226
+            $valid_nonce = $field->verify_nonce();
227
+            if ( $valid_nonce ) {
228 228
 
229
-				$posted_data = $_POST['wl_metaboxes'];
230
-				$field_name  = $field->meta_name;
229
+                $posted_data = $_POST['wl_metaboxes'];
230
+                $field_name  = $field->meta_name;
231 231
 
232
-				// Each Filed only deals with its values.
233
-				if ( isset( $posted_data[ $field_name ] ) ) {
232
+                // Each Filed only deals with its values.
233
+                if ( isset( $posted_data[ $field_name ] ) ) {
234 234
 
235
-					$values = $posted_data[ $field_name ];
236
-					if ( ! is_array( $values ) ) {
237
-						$values = array( $values );
238
-					}
235
+                    $values = $posted_data[ $field_name ];
236
+                    if ( ! is_array( $values ) ) {
237
+                        $values = array( $values );
238
+                    }
239 239
 
240
-					// Save data permanently
241
-					$field->save_data( $values );
242
-				}
243
-			}
244
-		}
240
+                    // Save data permanently
241
+                    $field->save_data( $values );
242
+                }
243
+            }
244
+        }
245 245
 
246
-		wl_linked_data_push_to_redlink( $entity_id );
247
-	}
246
+        wl_linked_data_push_to_redlink( $entity_id );
247
+    }
248 248
 
249
-	// print on page all the js and css the fields will need
250
-	public function enqueue_scripts_and_styles() {
249
+    // print on page all the js and css the fields will need
250
+    public function enqueue_scripts_and_styles() {
251 251
 
252
-		// dateTimePicker
253
-		wp_enqueue_style( 'jquery-ui-timepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/css/jquery.datetimepicker.css' );
254
-		wp_enqueue_script( 'jquery-ui-timepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.full.min.js', array( 'jquery' ) );
252
+        // dateTimePicker
253
+        wp_enqueue_style( 'jquery-ui-timepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/css/jquery.datetimepicker.css' );
254
+        wp_enqueue_script( 'jquery-ui-timepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.full.min.js', array( 'jquery' ) );
255 255
 		
256
-		// Leaflet.
257
-		wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
258
-		wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
259
-
260
-		// Add AJAX autocomplete to facilitate metabox editing
261
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
262
-		wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
263
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
264
-				'action'   => 'entity_by_title'
265
-			)
266
-		);
267
-	}
256
+        // Leaflet.
257
+        wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
258
+        wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
259
+
260
+        // Add AJAX autocomplete to facilitate metabox editing
261
+        wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
262
+        wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
263
+                'ajax_url' => admin_url( 'admin-ajax.php' ),
264
+                'action'   => 'entity_by_title'
265
+            )
266
+        );
267
+    }
268 268
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once( 'WL_Metabox_Field.php' );
4
-require_once( 'WL_Metabox_Field_date.php' );
5
-require_once( 'WL_Metabox_Field_uri.php' );
6
-require_once( 'WL_Metabox_Field_coordinates.php' );
7
-require_once( 'WL_Metabox_Field_sameas.php' );
8
-require_once( 'WL_Metabox_Field_address.php' );
3
+require_once('WL_Metabox_Field.php');
4
+require_once('WL_Metabox_Field_date.php');
5
+require_once('WL_Metabox_Field_uri.php');
6
+require_once('WL_Metabox_Field_coordinates.php');
7
+require_once('WL_Metabox_Field_sameas.php');
8
+require_once('WL_Metabox_Field_address.php');
9 9
 
10 10
 /**
11 11
  * Class WL_Metabox
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	public function __construct() {
34 34
 
35 35
 		// Create a logger instance.
36
-		$this->log_service = Wordlift_Log_Service::get_logger( 'WL_Metabox' );
36
+		$this->log_service = Wordlift_Log_Service::get_logger('WL_Metabox');
37 37
 
38 38
 		// Add hooks to print metaboxes and save submitted data.
39
-		add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
40
-		add_action( 'wl_linked_data_save_post', array( &$this, 'save_form_data' ) );
39
+		add_action('add_meta_boxes', array(&$this, 'add_main_metabox'));
40
+		add_action('wl_linked_data_save_post', array(&$this, 'save_form_data'));
41 41
 
42 42
 		// Enqueue js and css
43 43
 		$this->enqueue_scripts_and_styles();
@@ -51,15 +51,15 @@  discard block
 block discarded – undo
51 51
 	public function add_main_metabox() {
52 52
 
53 53
 		// Add main metabox (will print also the inner fields)
54
-		$id		= uniqid( 'wl-metabox-' );
55
-		$title	= get_the_title() . ' ' . __('properties', 'wordlift');
56
-		add_meta_box( $id, $title, array(
54
+		$id = uniqid('wl-metabox-');
55
+		$title = get_the_title().' '.__('properties', 'wordlift');
56
+		add_meta_box($id, $title, array(
57 57
 			$this,
58 58
 			'html'
59
-		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
59
+		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high');
60 60
 		
61 61
 		// Add filter to change the metabox CSS class
62
-		add_filter( "postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class' );
62
+		add_filter("postbox_classes_entity_$id", 'wl_admin_metaboxes_add_css_class');
63 63
 	}
64 64
 
65 65
 	/**
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @param WP_Post $post The post.
71 71
 	 */
72
-	public function html( $post ) {
72
+	public function html($post) {
73 73
 
74 74
 		// Build the fields we need to print.
75
-		$this->instantiate_fields( $post->ID );
75
+		$this->instantiate_fields($post->ID);
76 76
 
77 77
 		// Loop over the fields
78
-		foreach ( $this->fields as $field ) {
78
+		foreach ($this->fields as $field) {
79 79
 
80 80
 			// load data from DB (values will be available in $field->data)
81 81
 			$field->get_data();
@@ -96,16 +96,16 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 	 * @param int $post_id The post id.
98 98
 	 */
99
-	public function instantiate_fields( $post_id ) {
99
+	public function instantiate_fields($post_id) {
100 100
 
101 101
 		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering
102
-		if ( isset( $this->fields ) ) {
102
+		if (isset($this->fields)) {
103 103
 			return;
104 104
 		}
105 105
 
106
-		$entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
106
+		$entity_type = wl_entity_taxonomy_get_custom_fields($post_id);
107 107
 
108
-		if ( isset( $entity_type ) ) {
108
+		if (isset($entity_type)) {
109 109
 
110 110
 			/**
111 111
 			 * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
@@ -113,30 +113,30 @@  discard block
 block discarded – undo
113 113
 			 * - simple: accept values for one property
114 114
 			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
115 115
 			 */
116
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
116
+			$metaboxes         = $this->group_properties_by_input_field($entity_type);
117 117
 			$simple_metaboxes  = $metaboxes[0];
118 118
 			$grouped_metaboxes = $metaboxes[1];
119 119
 
120 120
 			// Loop over simple entity properties
121
-			foreach ( $simple_metaboxes as $key => $property ) {
121
+			foreach ($simple_metaboxes as $key => $property) {
122 122
 
123 123
 				// Info passed to the metabox
124 124
 				$info         = array();
125
-				$info[ $key ] = $property;
125
+				$info[$key] = $property;
126 126
 
127 127
 				// Build the requested field as WL_Metabox_Field_ object
128
-				$this->add_field( $info );
128
+				$this->add_field($info);
129 129
 			}
130 130
 
131 131
 			// Loop over grouped properties
132
-			foreach ( $grouped_metaboxes as $key => $property ) {
132
+			foreach ($grouped_metaboxes as $key => $property) {
133 133
 
134 134
 				// Info passed to the metabox
135 135
 				$info         = array();
136
-				$info[ $key ] = $property;
136
+				$info[$key] = $property;
137 137
 
138 138
 				// Build the requested field group as WL_Metabox_Field_ object
139
-				$this->add_field( $info, true );
139
+				$this->add_field($info, true);
140 140
 			}
141 141
 
142 142
 		}
@@ -147,34 +147,34 @@  discard block
 block discarded – undo
147 147
 	 *
148 148
 	 * @param array $custom_fields Information on the entity type.
149 149
 	 */
150
-	public function group_properties_by_input_field( $custom_fields ) {
150
+	public function group_properties_by_input_field($custom_fields) {
151 151
 
152 152
 		$simple_properties  = array();
153 153
 		$grouped_properties = array();
154 154
 
155 155
 		// Loop over possible entity properties
156
-		foreach ( $custom_fields as $key => $property ) {
156
+		foreach ($custom_fields as $key => $property) {
157 157
 
158 158
 			// Check presence of predicate and type
159
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
159
+			if (isset($property['predicate']) && isset($property['type'])) {
160 160
 
161 161
 				// Check if input_field is defined
162
-				if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
162
+				if (isset($property['input_field']) && $property['input_field'] !== '') {
163 163
 
164 164
 					$grouped_key = $property['input_field'];
165 165
 
166 166
 					// Update list of grouped properties
167
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
167
+					$grouped_properties[$grouped_key][$key] = $property;
168 168
 
169 169
 				} else {
170 170
 
171 171
 					// input_field not defined, add simple metabox
172
-					$simple_properties[ $key ] = $property;
172
+					$simple_properties[$key] = $property;
173 173
 				}
174 174
 			}
175 175
 		}
176 176
 
177
-		return array( $simple_properties, $grouped_properties );
177
+		return array($simple_properties, $grouped_properties);
178 178
 	}
179 179
 
180 180
 	/**
@@ -184,83 +184,83 @@  discard block
 block discarded – undo
184 184
 	 * @param type $args
185 185
 	 * @param type $grouped Flag to distinguish between simple and grouped Fields
186 186
 	 */
187
-	public function add_field( $args, $grouped = false ) {
187
+	public function add_field($args, $grouped = false) {
188 188
 
189
-		if ( $grouped ) {
189
+		if ($grouped) {
190 190
 			// Special fields (sameas, coordinates, etc.)
191 191
 
192 192
 			// Build Field with a custom class (e.g. WL_Metabox_Field_date)
193
-			$field_class = 'WL_Metabox_Field_' . key( $args );
193
+			$field_class = 'WL_Metabox_Field_'.key($args);
194 194
 
195 195
 		} else {
196 196
 			// Simple fields (string, uri, boolean, etc.)
197 197
 
198 198
 			// Which field? We want to use the class that is specific for the field.
199
-			$meta = key( $args );
200
-			if ( ! isset( $args[ $meta ]['type'] ) || ( $args[ $meta ]['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
199
+			$meta = key($args);
200
+			if ( ! isset($args[$meta]['type']) || ($args[$meta]['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING)) {
201 201
 				// Use default WL_Metabox_Field (manages strings)
202 202
 				$field_class = 'WL_Metabox_Field';
203 203
 			} else {
204 204
 				// Build Field with a custom class (e.g. WL_Metabox_Field_date)
205
-				$field_class = 'WL_Metabox_Field_' . $args[ $meta ]['type'];
205
+				$field_class = 'WL_Metabox_Field_'.$args[$meta]['type'];
206 206
 			}
207 207
 		}
208 208
 
209 209
 		// Call apropriate constructor (e.g. WL_Metabox_Field_... )
210
-		$this->fields[] = new $field_class( $args );
210
+		$this->fields[] = new $field_class($args);
211 211
 	}
212 212
 
213
-	public function save_form_data( $entity_id ) {
213
+	public function save_form_data($entity_id) {
214 214
 
215 215
 		// Build Field objects
216
-		$this->instantiate_fields( $entity_id );
216
+		$this->instantiate_fields($entity_id);
217 217
 
218 218
 		// Check if WL metabox form was posted
219
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
219
+		if ( ! isset($_POST['wl_metaboxes'])) {
220 220
 			return;
221 221
 		}
222 222
 
223
-		foreach ( $this->fields as $field ) {
223
+		foreach ($this->fields as $field) {
224 224
 
225 225
 			// Verify nonce
226 226
 			$valid_nonce = $field->verify_nonce();
227
-			if ( $valid_nonce ) {
227
+			if ($valid_nonce) {
228 228
 
229 229
 				$posted_data = $_POST['wl_metaboxes'];
230 230
 				$field_name  = $field->meta_name;
231 231
 
232 232
 				// Each Filed only deals with its values.
233
-				if ( isset( $posted_data[ $field_name ] ) ) {
233
+				if (isset($posted_data[$field_name])) {
234 234
 
235
-					$values = $posted_data[ $field_name ];
236
-					if ( ! is_array( $values ) ) {
237
-						$values = array( $values );
235
+					$values = $posted_data[$field_name];
236
+					if ( ! is_array($values)) {
237
+						$values = array($values);
238 238
 					}
239 239
 
240 240
 					// Save data permanently
241
-					$field->save_data( $values );
241
+					$field->save_data($values);
242 242
 				}
243 243
 			}
244 244
 		}
245 245
 
246
-		wl_linked_data_push_to_redlink( $entity_id );
246
+		wl_linked_data_push_to_redlink($entity_id);
247 247
 	}
248 248
 
249 249
 	// print on page all the js and css the fields will need
250 250
 	public function enqueue_scripts_and_styles() {
251 251
 
252 252
 		// dateTimePicker
253
-		wp_enqueue_style( 'jquery-ui-timepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/css/jquery.datetimepicker.css' );
254
-		wp_enqueue_script( 'jquery-ui-timepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.full.min.js', array( 'jquery' ) );
253
+		wp_enqueue_style('jquery-ui-timepicker', dirname(plugin_dir_url(__FILE__)).'/css/jquery.datetimepicker.css');
254
+		wp_enqueue_script('jquery-ui-timepicker', dirname(plugin_dir_url(__FILE__)).'/js/jquery.datetimepicker.full.min.js', array('jquery'));
255 255
 		
256 256
 		// Leaflet.
257
-		wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
258
-		wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
257
+		wp_enqueue_style('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.css');
258
+		wp_enqueue_script('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.js', __FILE__);
259 259
 
260 260
 		// Add AJAX autocomplete to facilitate metabox editing
261
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
262
-		wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
263
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
261
+		wp_enqueue_script('wl-entity-metabox-utility', dirname(plugin_dir_url(__FILE__)).'/js/wl_entity_metabox_utilities.js');
262
+		wp_localize_script('wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
263
+				'ajax_url' => admin_url('admin-ajax.php'),
264 264
 				'action'   => 'entity_by_title'
265 265
 			)
266 266
 		);
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-entity-list.php 2 patches
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -13,200 +13,200 @@
 block discarded – undo
13 13
  */
14 14
 class Wordlift_Entity_List_Service {
15 15
 	
16
-	/**
17
-	 * Size of the entity thumbnail in pixels
18
-	 * 
19
-	 * @since  3.3.0
20
-	 */
21
-	const THUMB_SIZE = 50;
22
-
23
-	/**
24
-	 * The Entity service.
25
-	 *
26
-	 * @since 3.3.0
27
-	 * @access private
28
-	 * @var \Wordlift_Entity_Service $entity_service The Entity service.
29
-	 */
30
-	private $entity_service;
31
-
32
-	/**
33
-	 * Create a Wordlift_Entity_List_Service.
34
-	 *
35
-	 * @since 3.3.0
36
-	 *
37
-	 * @param \Wordlift_Entity_Service $entity_service The Entity service.
38
-	 */
39
-	public function __construct( $entity_service ) {
40
-
41
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_List_Service' );
42
-
43
-		$this->entity_service = $entity_service;
44
-
45
-	}
46
-
47
-	/**
48
-	 * Register custom columns for entity listing in backend
49
-	 * @see https://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column
50
-	 *
51
-	 * @since 3.3.0
52
-	 *
53
-	 * @param array $columns the default columns.
54
-	 *
55
-	 * @return array Enhanced columns array.
56
-	 */
57
-	public function register_custom_columns( $columns ) {
16
+    /**
17
+     * Size of the entity thumbnail in pixels
18
+     * 
19
+     * @since  3.3.0
20
+     */
21
+    const THUMB_SIZE = 50;
22
+
23
+    /**
24
+     * The Entity service.
25
+     *
26
+     * @since 3.3.0
27
+     * @access private
28
+     * @var \Wordlift_Entity_Service $entity_service The Entity service.
29
+     */
30
+    private $entity_service;
31
+
32
+    /**
33
+     * Create a Wordlift_Entity_List_Service.
34
+     *
35
+     * @since 3.3.0
36
+     *
37
+     * @param \Wordlift_Entity_Service $entity_service The Entity service.
38
+     */
39
+    public function __construct( $entity_service ) {
40
+
41
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_List_Service' );
42
+
43
+        $this->entity_service = $entity_service;
44
+
45
+    }
46
+
47
+    /**
48
+     * Register custom columns for entity listing in backend
49
+     * @see https://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column
50
+     *
51
+     * @since 3.3.0
52
+     *
53
+     * @param array $columns the default columns.
54
+     *
55
+     * @return array Enhanced columns array.
56
+     */
57
+    public function register_custom_columns( $columns ) {
58 58
 		
59
-		// Take away first column and keep a reference,
60
-		// so we can later insert the thumbnail between the first and the rest of columns.
61
-		$columns_cb = $columns['cb'];
62
-		unset( $columns['cb'] );
59
+        // Take away first column and keep a reference,
60
+        // so we can later insert the thumbnail between the first and the rest of columns.
61
+        $columns_cb = $columns['cb'];
62
+        unset( $columns['cb'] );
63 63
 		
64
-		// Thumbnails column is inserted in second place, while the related posts on the end.
65
-		$columns = array_merge(
66
-			array( 'cb'                      => $columns_cb ),                      // re-add first column
67
-			array( 'wl_column_thumbnail'     => __( 'Image', 'wordlift' ) ),        // thumb
68
-			$columns,                                                               // default columns (without the first)
69
-			array( 'wl_column_related_posts' => __( 'Related Posts', 'wordlift' ) ), // related posts
70
-			array( 'wl_column_rating' 		 => __( 'Rating', 'wordlift' ) ) // related posts
71
-		);
72
-
73
-		return $columns;		
74
-	}
75
-
76
-	/**
77
-	 * Render custom columns
78
-	 * @see https://codex.wordpress.org/Plugin_API/Action_Reference/manage_$post_type_posts_custom_column
79
-	 *
80
-	 * @since 3.3.0
81
-	 *
82
-	 * @param string $column the current column.
83
-	 * @param int $entity_id An entity post id.
84
-	 *
85
-	 * @return true if the post is an entity otherwise false.
86
-	 */
87
-	public function render_custom_columns( $column, $entity_id ) {
64
+        // Thumbnails column is inserted in second place, while the related posts on the end.
65
+        $columns = array_merge(
66
+            array( 'cb'                      => $columns_cb ),                      // re-add first column
67
+            array( 'wl_column_thumbnail'     => __( 'Image', 'wordlift' ) ),        // thumb
68
+            $columns,                                                               // default columns (without the first)
69
+            array( 'wl_column_related_posts' => __( 'Related Posts', 'wordlift' ) ), // related posts
70
+            array( 'wl_column_rating' 		 => __( 'Rating', 'wordlift' ) ) // related posts
71
+        );
72
+
73
+        return $columns;		
74
+    }
75
+
76
+    /**
77
+     * Render custom columns
78
+     * @see https://codex.wordpress.org/Plugin_API/Action_Reference/manage_$post_type_posts_custom_column
79
+     *
80
+     * @since 3.3.0
81
+     *
82
+     * @param string $column the current column.
83
+     * @param int $entity_id An entity post id.
84
+     *
85
+     * @return true if the post is an entity otherwise false.
86
+     */
87
+    public function render_custom_columns( $column, $entity_id ) {
88 88
 		
89
-		switch ( $column ) {
89
+        switch ( $column ) {
90 90
 			
91
-			case 'wl_column_related_posts':
92
-				echo count( wl_core_get_related_post_ids( $entity_id ) );
93
-				break;
91
+            case 'wl_column_related_posts':
92
+                echo count( wl_core_get_related_post_ids( $entity_id ) );
93
+                break;
94 94
 			
95
-			case 'wl_column_thumbnail':
95
+            case 'wl_column_thumbnail':
96 96
 				
97
-				$edit_link = get_edit_post_link( $entity_id );
98
-				$thumb     = get_the_post_thumbnail( $entity_id, array( self::THUMB_SIZE, self::THUMB_SIZE ) );
97
+                $edit_link = get_edit_post_link( $entity_id );
98
+                $thumb     = get_the_post_thumbnail( $entity_id, array( self::THUMB_SIZE, self::THUMB_SIZE ) );
99 99
 				
100
-				if( ! $thumb ) {
101
-					$thumb = "<img src='" . WL_DEFAULT_THUMBNAIL_PATH . "' width='" . self::THUMB_SIZE . "' />";
102
-				}
103
-				echo "<a href='$edit_link'>$thumb</a>";
104
-				break;
105
-
106
-			case 'wl_column_rating':
107
-
108
-				$rating = $this->entity_service->get_rating_for( $entity_id );
109
-				echo '<i class="wl-traffic-light wl-tl-'. $rating[ 'traffic_light_score' ] . '">' . $rating[ 'percentage_score' ] . '%</i>';				
110
-				break;
111
-		}
100
+                if( ! $thumb ) {
101
+                    $thumb = "<img src='" . WL_DEFAULT_THUMBNAIL_PATH . "' width='" . self::THUMB_SIZE . "' />";
102
+                }
103
+                echo "<a href='$edit_link'>$thumb</a>";
104
+                break;
105
+
106
+            case 'wl_column_rating':
107
+
108
+                $rating = $this->entity_service->get_rating_for( $entity_id );
109
+                echo '<i class="wl-traffic-light wl-tl-'. $rating[ 'traffic_light_score' ] . '">' . $rating[ 'percentage_score' ] . '%</i>';				
110
+                break;
111
+        }
112 112
 		
113
-	}
113
+    }
114 114
 	
115
-	/**
116
-	 * Add wl-classification-scope select box before the 'Filter' button.
117
-	 *
118
-	 * @since 3.3.0
119
-	 */
120
-	public function restrict_manage_posts_classification_scope() {
115
+    /**
116
+     * Add wl-classification-scope select box before the 'Filter' button.
117
+     *
118
+     * @since 3.3.0
119
+     */
120
+    public function restrict_manage_posts_classification_scope() {
121 121
 		
122
-		// Return safely if get_current_screen() is not defined (yet)
123
-		if ( FALSE === function_exists( 'get_current_screen' ) ) {
124
-			return;
125
-		}
126
-
127
-		$screen = get_current_screen();
128
-		// If there is any valid screen nothing to do
129
-		if ( NULL === $screen ) {
130
-			return;
131
-		}
132
-
133
-		if( $screen->post_type !== Wordlift_Entity_Service::TYPE_NAME ){
134
-			return;
135
-		}
122
+        // Return safely if get_current_screen() is not defined (yet)
123
+        if ( FALSE === function_exists( 'get_current_screen' ) ) {
124
+            return;
125
+        }
126
+
127
+        $screen = get_current_screen();
128
+        // If there is any valid screen nothing to do
129
+        if ( NULL === $screen ) {
130
+            return;
131
+        }
132
+
133
+        if( $screen->post_type !== Wordlift_Entity_Service::TYPE_NAME ){
134
+            return;
135
+        }
136 136
 		
137
-		// Was a W already selected?
138
-		$selected = isset( $_GET[ 'wl-classification-scope' ] ) ? 
139
-			$_GET['wl-classification-scope'] : '' ;
137
+        // Was a W already selected?
138
+        $selected = isset( $_GET[ 'wl-classification-scope' ] ) ? 
139
+            $_GET['wl-classification-scope'] : '' ;
140 140
 		
141
-		// Print select box with the 4W
142
-		$all_w = array(
143
-			__( "All 'W'" ),
144
-			WL_WHAT_RELATION,
145
-			WL_WHO_RELATION,
146
-			WL_WHERE_RELATION,
147
-			WL_WHEN_RELATION
148
-		);
149
-		echo '<select name="wl-classification-scope" id="wl-dropdown-classification-scope">';
150
-		foreach ( $all_w as $w ) {
151
-			$default  = ( $selected === $w ) ? 'selected' : '';
152
-			echo sprintf( '<option value="%s" %s >%s</option>', $w, $default, __( $w ) );
153
-		}
154
-		echo '</select>';
155
-	}
156
-
157
-	/**
158
-	 * Server side response operations for the classification filter set in *restrict_manage_posts_classification_scope_filter*
159
-	 *
160
-	 * @since 3.3.0
161
-	 * 
162
-	 * @param array $clauses WP main query clauses.
163
-	 * 
164
-	 * @return array Modified clauses.
165
-	 */
166
-	public function posts_clauses_classification_scope( $clauses ) {
141
+        // Print select box with the 4W
142
+        $all_w = array(
143
+            __( "All 'W'" ),
144
+            WL_WHAT_RELATION,
145
+            WL_WHO_RELATION,
146
+            WL_WHERE_RELATION,
147
+            WL_WHEN_RELATION
148
+        );
149
+        echo '<select name="wl-classification-scope" id="wl-dropdown-classification-scope">';
150
+        foreach ( $all_w as $w ) {
151
+            $default  = ( $selected === $w ) ? 'selected' : '';
152
+            echo sprintf( '<option value="%s" %s >%s</option>', $w, $default, __( $w ) );
153
+        }
154
+        echo '</select>';
155
+    }
156
+
157
+    /**
158
+     * Server side response operations for the classification filter set in *restrict_manage_posts_classification_scope_filter*
159
+     *
160
+     * @since 3.3.0
161
+     * 
162
+     * @param array $clauses WP main query clauses.
163
+     * 
164
+     * @return array Modified clauses.
165
+     */
166
+    public function posts_clauses_classification_scope( $clauses ) {
167 167
 		
168
-		// Run only on admin page
169
-		if( ! is_admin() ) {
170
-			return $clauses;
171
-		}
172
-
173
-		// Return safely if get_current_screen() is not defined (yet)
174
-		if ( FALSE === function_exists( 'get_current_screen' ) ) {
175
-			return $clauses;
176
-		}
168
+        // Run only on admin page
169
+        if( ! is_admin() ) {
170
+            return $clauses;
171
+        }
172
+
173
+        // Return safely if get_current_screen() is not defined (yet)
174
+        if ( FALSE === function_exists( 'get_current_screen' ) ) {
175
+            return $clauses;
176
+        }
177 177
 		
178
-		// Only apply on entity list page, only if this is the main query and if the wl-classification-scope query param is set
179
-		$screen = get_current_screen();
178
+        // Only apply on entity list page, only if this is the main query and if the wl-classification-scope query param is set
179
+        $screen = get_current_screen();
180 180
 
181
-		// If there is any valid screen nothing to do
182
-		if ( NULL === $screen ) {
183
-			return $clauses;
184
-		}
181
+        // If there is any valid screen nothing to do
182
+        if ( NULL === $screen ) {
183
+            return $clauses;
184
+        }
185 185
 
186
-		if( ! ( $screen->post_type === Wordlift_Entity_Service::TYPE_NAME && is_main_query() && isset( $_GET['wl-classification-scope'] ) ) ) {
187
-			return $clauses;
188
-		}
186
+        if( ! ( $screen->post_type === Wordlift_Entity_Service::TYPE_NAME && is_main_query() && isset( $_GET['wl-classification-scope'] ) ) ) {
187
+            return $clauses;
188
+        }
189 189
 			
190
-		// Check a valid W was requested
191
-		$requested_w = $_GET['wl-classification-scope'];
192
-		$all_w       = array(
193
-			WL_WHAT_RELATION,
194
-			WL_WHO_RELATION,
195
-			WL_WHERE_RELATION,
196
-			WL_WHEN_RELATION	
197
-		);
198
-		if ( ! in_array( $requested_w, $all_w ) ) {
199
-			return $clauses;
200
-		}
190
+        // Check a valid W was requested
191
+        $requested_w = $_GET['wl-classification-scope'];
192
+        $all_w       = array(
193
+            WL_WHAT_RELATION,
194
+            WL_WHO_RELATION,
195
+            WL_WHERE_RELATION,
196
+            WL_WHEN_RELATION	
197
+        );
198
+        if ( ! in_array( $requested_w, $all_w ) ) {
199
+            return $clauses;
200
+        }
201 201
 		
202
-		global $wpdb;
203
-		$wl_relation_table = wl_core_get_relation_instances_table_name();
202
+        global $wpdb;
203
+        $wl_relation_table = wl_core_get_relation_instances_table_name();
204 204
 		
205
-		// Change WP main query clauses
206
-		$clauses['join']     .= "INNER JOIN {$wl_relation_table} ON {$wpdb->posts}.ID = {$wl_relation_table}.object_id";
207
-		$clauses['where']    .= $wpdb->prepare( "AND {$wl_relation_table}.predicate = %s", $requested_w );
208
-		$clauses['distinct'] .= "DISTINCT";
205
+        // Change WP main query clauses
206
+        $clauses['join']     .= "INNER JOIN {$wl_relation_table} ON {$wpdb->posts}.ID = {$wl_relation_table}.object_id";
207
+        $clauses['where']    .= $wpdb->prepare( "AND {$wl_relation_table}.predicate = %s", $requested_w );
208
+        $clauses['distinct'] .= "DISTINCT";
209 209
 		
210
-		return $clauses;
211
-	}
210
+        return $clauses;
211
+    }
212 212
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 	 *
37 37
 	 * @param \Wordlift_Entity_Service $entity_service The Entity service.
38 38
 	 */
39
-	public function __construct( $entity_service ) {
39
+	public function __construct($entity_service) {
40 40
 
41
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_List_Service' );
41
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Entity_List_Service');
42 42
 
43 43
 		$this->entity_service = $entity_service;
44 44
 
@@ -54,20 +54,20 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 * @return array Enhanced columns array.
56 56
 	 */
57
-	public function register_custom_columns( $columns ) {
57
+	public function register_custom_columns($columns) {
58 58
 		
59 59
 		// Take away first column and keep a reference,
60 60
 		// so we can later insert the thumbnail between the first and the rest of columns.
61 61
 		$columns_cb = $columns['cb'];
62
-		unset( $columns['cb'] );
62
+		unset($columns['cb']);
63 63
 		
64 64
 		// Thumbnails column is inserted in second place, while the related posts on the end.
65 65
 		$columns = array_merge(
66
-			array( 'cb'                      => $columns_cb ),                      // re-add first column
67
-			array( 'wl_column_thumbnail'     => __( 'Image', 'wordlift' ) ),        // thumb
68
-			$columns,                                                               // default columns (without the first)
69
-			array( 'wl_column_related_posts' => __( 'Related Posts', 'wordlift' ) ), // related posts
70
-			array( 'wl_column_rating' 		 => __( 'Rating', 'wordlift' ) ) // related posts
66
+			array('cb'                      => $columns_cb), // re-add first column
67
+			array('wl_column_thumbnail'     => __('Image', 'wordlift')), // thumb
68
+			$columns, // default columns (without the first)
69
+			array('wl_column_related_posts' => __('Related Posts', 'wordlift')), // related posts
70
+			array('wl_column_rating' 		 => __('Rating', 'wordlift')) // related posts
71 71
 		);
72 72
 
73 73
 		return $columns;		
@@ -84,29 +84,29 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @return true if the post is an entity otherwise false.
86 86
 	 */
87
-	public function render_custom_columns( $column, $entity_id ) {
87
+	public function render_custom_columns($column, $entity_id) {
88 88
 		
89
-		switch ( $column ) {
89
+		switch ($column) {
90 90
 			
91 91
 			case 'wl_column_related_posts':
92
-				echo count( wl_core_get_related_post_ids( $entity_id ) );
92
+				echo count(wl_core_get_related_post_ids($entity_id));
93 93
 				break;
94 94
 			
95 95
 			case 'wl_column_thumbnail':
96 96
 				
97
-				$edit_link = get_edit_post_link( $entity_id );
98
-				$thumb     = get_the_post_thumbnail( $entity_id, array( self::THUMB_SIZE, self::THUMB_SIZE ) );
97
+				$edit_link = get_edit_post_link($entity_id);
98
+				$thumb     = get_the_post_thumbnail($entity_id, array(self::THUMB_SIZE, self::THUMB_SIZE));
99 99
 				
100
-				if( ! $thumb ) {
101
-					$thumb = "<img src='" . WL_DEFAULT_THUMBNAIL_PATH . "' width='" . self::THUMB_SIZE . "' />";
100
+				if ( ! $thumb) {
101
+					$thumb = "<img src='".WL_DEFAULT_THUMBNAIL_PATH."' width='".self::THUMB_SIZE."' />";
102 102
 				}
103 103
 				echo "<a href='$edit_link'>$thumb</a>";
104 104
 				break;
105 105
 
106 106
 			case 'wl_column_rating':
107 107
 
108
-				$rating = $this->entity_service->get_rating_for( $entity_id );
109
-				echo '<i class="wl-traffic-light wl-tl-'. $rating[ 'traffic_light_score' ] . '">' . $rating[ 'percentage_score' ] . '%</i>';				
108
+				$rating = $this->entity_service->get_rating_for($entity_id);
109
+				echo '<i class="wl-traffic-light wl-tl-'.$rating['traffic_light_score'].'">'.$rating['percentage_score'].'%</i>';				
110 110
 				break;
111 111
 		}
112 112
 		
@@ -120,36 +120,36 @@  discard block
 block discarded – undo
120 120
 	public function restrict_manage_posts_classification_scope() {
121 121
 		
122 122
 		// Return safely if get_current_screen() is not defined (yet)
123
-		if ( FALSE === function_exists( 'get_current_screen' ) ) {
123
+		if (FALSE === function_exists('get_current_screen')) {
124 124
 			return;
125 125
 		}
126 126
 
127 127
 		$screen = get_current_screen();
128 128
 		// If there is any valid screen nothing to do
129
-		if ( NULL === $screen ) {
129
+		if (NULL === $screen) {
130 130
 			return;
131 131
 		}
132 132
 
133
-		if( $screen->post_type !== Wordlift_Entity_Service::TYPE_NAME ){
133
+		if ($screen->post_type !== Wordlift_Entity_Service::TYPE_NAME) {
134 134
 			return;
135 135
 		}
136 136
 		
137 137
 		// Was a W already selected?
138
-		$selected = isset( $_GET[ 'wl-classification-scope' ] ) ? 
139
-			$_GET['wl-classification-scope'] : '' ;
138
+		$selected = isset($_GET['wl-classification-scope']) ? 
139
+			$_GET['wl-classification-scope'] : '';
140 140
 		
141 141
 		// Print select box with the 4W
142 142
 		$all_w = array(
143
-			__( "All 'W'" ),
143
+			__("All 'W'"),
144 144
 			WL_WHAT_RELATION,
145 145
 			WL_WHO_RELATION,
146 146
 			WL_WHERE_RELATION,
147 147
 			WL_WHEN_RELATION
148 148
 		);
149 149
 		echo '<select name="wl-classification-scope" id="wl-dropdown-classification-scope">';
150
-		foreach ( $all_w as $w ) {
151
-			$default  = ( $selected === $w ) ? 'selected' : '';
152
-			echo sprintf( '<option value="%s" %s >%s</option>', $w, $default, __( $w ) );
150
+		foreach ($all_w as $w) {
151
+			$default = ($selected === $w) ? 'selected' : '';
152
+			echo sprintf('<option value="%s" %s >%s</option>', $w, $default, __($w));
153 153
 		}
154 154
 		echo '</select>';
155 155
 	}
@@ -163,15 +163,15 @@  discard block
 block discarded – undo
163 163
 	 * 
164 164
 	 * @return array Modified clauses.
165 165
 	 */
166
-	public function posts_clauses_classification_scope( $clauses ) {
166
+	public function posts_clauses_classification_scope($clauses) {
167 167
 		
168 168
 		// Run only on admin page
169
-		if( ! is_admin() ) {
169
+		if ( ! is_admin()) {
170 170
 			return $clauses;
171 171
 		}
172 172
 
173 173
 		// Return safely if get_current_screen() is not defined (yet)
174
-		if ( FALSE === function_exists( 'get_current_screen' ) ) {
174
+		if (FALSE === function_exists('get_current_screen')) {
175 175
 			return $clauses;
176 176
 		}
177 177
 		
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 		$screen = get_current_screen();
180 180
 
181 181
 		// If there is any valid screen nothing to do
182
-		if ( NULL === $screen ) {
182
+		if (NULL === $screen) {
183 183
 			return $clauses;
184 184
 		}
185 185
 
186
-		if( ! ( $screen->post_type === Wordlift_Entity_Service::TYPE_NAME && is_main_query() && isset( $_GET['wl-classification-scope'] ) ) ) {
186
+		if ( ! ($screen->post_type === Wordlift_Entity_Service::TYPE_NAME && is_main_query() && isset($_GET['wl-classification-scope']))) {
187 187
 			return $clauses;
188 188
 		}
189 189
 			
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 			WL_WHERE_RELATION,
196 196
 			WL_WHEN_RELATION	
197 197
 		);
198
-		if ( ! in_array( $requested_w, $all_w ) ) {
198
+		if ( ! in_array($requested_w, $all_w)) {
199 199
 			return $clauses;
200 200
 		}
201 201
 		
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 		
205 205
 		// Change WP main query clauses
206 206
 		$clauses['join']     .= "INNER JOIN {$wl_relation_table} ON {$wpdb->posts}.ID = {$wl_relation_table}.object_id";
207
-		$clauses['where']    .= $wpdb->prepare( "AND {$wl_relation_table}.predicate = %s", $requested_w );
207
+		$clauses['where']    .= $wpdb->prepare("AND {$wl_relation_table}.predicate = %s", $requested_w);
208 208
 		$clauses['distinct'] .= "DISTINCT";
209 209
 		
210 210
 		return $clauses;
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-dashboard.php 2 patches
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -14,83 +14,83 @@  discard block
 block discarded – undo
14 14
 class Wordlift_Dashboard_Service {
15 15
 	
16 16
 
17
-	/**
18
-	 * Transient Name
19
-	 * 
20
-	 * @since  3.4.0
21
-	 */
22
-	const TRANSIENT_NAME = 'wl_dashboard_stats';
23
-
24
-	/**
25
-	 * Transient Expiration (in seconds)
26
-	 * 
27
-	 * @since  3.4.0
28
-	 */
29
-	const TRANSIENT_EXPIRATION = 86400;
30
-
31
-	/**
32
-	 * The Entity service.
33
-	 *
34
-	 * @since 3.4.0
35
-	 * @access private
36
-	 * @var \Wordlift_Entity_Service $entity_service The Entity service.
37
-	 */
38
-	private $entity_service;
39
-
40
-	/**
41
-	 * Create a Wordlift_Entity_List_Service.
42
-	 *
43
-	 * @since 3.4.0
44
-	 *
45
-	 * @param \Wordlift_Entity_Service $entity_service The Entity service.
46
-	 */
47
-	public function __construct( $entity_service ) {
48
-
49
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Dashboard_Service' );
50
-
51
-		$this->entity_service = $entity_service;
52
-
53
-	}
54
-
55
-	/**
56
-	 * Return stats layout
57
-	 *
58
-	 * @since 3.4.0
59
-	 *
60
-	 * @return string Dashboard widget html markup
61
-	 */
62
-	public function dashboard_widget_callback( $post ) {
63
-
64
-		$enriched_posts_title = __( 'enriched posts', 'wordlift' ); 
65
-		$enriched_posts_caption = sprintf( wp_kses(
66
-			__( '%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift' ), 
67
-			array(  'a' => array( 'href' => array() ) ) ), 
68
-			$this->render_stat_param( 'annotated_posts_percentage' ),
69
-			esc_url( admin_url( 'edit.php' ) ),
70
-			$this->render_stat_param( 'annotated_posts' ),
71
-			$this->render_stat_param( 'posts' )  
72
-		); 
73
-
74
-		$rating_title = __( 'avarage entity rating', 'wordlift' ); 
75
-		$rating_caption = sprintf( wp_kses(
76
-			__( 'You have %1$s entities in your <a href="%2$s">vocabulary</a> with an avarage rating of %3$s.', 'wordlift' ), 
77
-			array(  'a' => array( 'href' => array() ) ) ), 
78
-			$this->render_stat_param( 'entities' ),
79
-			esc_url( admin_url( 'edit.php?post_type=entity' ) ),
80
-			$this->render_stat_param( 'rating' )
81
-		); 
82
-
83
-		$graph_title = __( 'triples in your graph', 'wordlift' ); 
84
-		$graph_caption = sprintf( wp_kses(
85
-			__( 'Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift' ), 
86
-			array(  'a' => array( 'href' => array() ) ) ), 
87
-			$this->render_stat_param( 'wikidata' ),
88
-			esc_url( 'https://www.wikidata.org/' )
89
-		); 
90
-
91
-		$triples_label = __( 'triples', 'wordlift' ); 
17
+    /**
18
+     * Transient Name
19
+     * 
20
+     * @since  3.4.0
21
+     */
22
+    const TRANSIENT_NAME = 'wl_dashboard_stats';
23
+
24
+    /**
25
+     * Transient Expiration (in seconds)
26
+     * 
27
+     * @since  3.4.0
28
+     */
29
+    const TRANSIENT_EXPIRATION = 86400;
30
+
31
+    /**
32
+     * The Entity service.
33
+     *
34
+     * @since 3.4.0
35
+     * @access private
36
+     * @var \Wordlift_Entity_Service $entity_service The Entity service.
37
+     */
38
+    private $entity_service;
39
+
40
+    /**
41
+     * Create a Wordlift_Entity_List_Service.
42
+     *
43
+     * @since 3.4.0
44
+     *
45
+     * @param \Wordlift_Entity_Service $entity_service The Entity service.
46
+     */
47
+    public function __construct( $entity_service ) {
48
+
49
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Dashboard_Service' );
50
+
51
+        $this->entity_service = $entity_service;
52
+
53
+    }
54
+
55
+    /**
56
+     * Return stats layout
57
+     *
58
+     * @since 3.4.0
59
+     *
60
+     * @return string Dashboard widget html markup
61
+     */
62
+    public function dashboard_widget_callback( $post ) {
63
+
64
+        $enriched_posts_title = __( 'enriched posts', 'wordlift' ); 
65
+        $enriched_posts_caption = sprintf( wp_kses(
66
+            __( '%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift' ), 
67
+            array(  'a' => array( 'href' => array() ) ) ), 
68
+            $this->render_stat_param( 'annotated_posts_percentage' ),
69
+            esc_url( admin_url( 'edit.php' ) ),
70
+            $this->render_stat_param( 'annotated_posts' ),
71
+            $this->render_stat_param( 'posts' )  
72
+        ); 
73
+
74
+        $rating_title = __( 'avarage entity rating', 'wordlift' ); 
75
+        $rating_caption = sprintf( wp_kses(
76
+            __( 'You have %1$s entities in your <a href="%2$s">vocabulary</a> with an avarage rating of %3$s.', 'wordlift' ), 
77
+            array(  'a' => array( 'href' => array() ) ) ), 
78
+            $this->render_stat_param( 'entities' ),
79
+            esc_url( admin_url( 'edit.php?post_type=entity' ) ),
80
+            $this->render_stat_param( 'rating' )
81
+        ); 
82
+
83
+        $graph_title = __( 'triples in your graph', 'wordlift' ); 
84
+        $graph_caption = sprintf( wp_kses(
85
+            __( 'Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift' ), 
86
+            array(  'a' => array( 'href' => array() ) ) ), 
87
+            $this->render_stat_param( 'wikidata' ),
88
+            esc_url( 'https://www.wikidata.org/' )
89
+        ); 
90
+
91
+        $triples_label = __( 'triples', 'wordlift' ); 
92 92
 		
93
-		echo <<<EOF
93
+        echo <<<EOF
94 94
 	<div id="wl-dashboard-widget-inner-wrapper">
95 95
 		<div class="wl-stat-card">
96 96
 			<div class="wl-stat-graph-wrapper">
@@ -119,161 +119,161 @@  discard block
 block discarded – undo
119 119
 	</div>
120 120
 EOF;
121 121
 
122
-	}
123
-
124
-	/**
125
-	 * Return stats
126
-	 *
127
-	 * @since 3.4.0
128
-	 *
129
-	 * @return string markup
130
-	 */
131
-	public function add_dashboard_widgets() {
132
-		wp_add_dashboard_widget('wordlift-dashboard-widget', 'WordLift Dashboard', array( $this, 'dashboard_widget_callback' ) );
133
-	}
134
-
135
-	/**
136
-	 * Return stats
137
-	 * @uses https://codex.wordpress.org/Function_Reference/set_transient
138
-	 *
139
-	 * @since 3.4.0
140
-	 *
141
-	 * @return string JSON obj with all available stats.
142
-	 */
143
-	public function ajax_get_stats() {
122
+    }
123
+
124
+    /**
125
+     * Return stats
126
+     *
127
+     * @since 3.4.0
128
+     *
129
+     * @return string markup
130
+     */
131
+    public function add_dashboard_widgets() {
132
+        wp_add_dashboard_widget('wordlift-dashboard-widget', 'WordLift Dashboard', array( $this, 'dashboard_widget_callback' ) );
133
+    }
134
+
135
+    /**
136
+     * Return stats
137
+     * @uses https://codex.wordpress.org/Function_Reference/set_transient
138
+     *
139
+     * @since 3.4.0
140
+     *
141
+     * @return string JSON obj with all available stats.
142
+     */
143
+    public function ajax_get_stats() {
144 144
 		
145
-		// If needed, the transient is force to reloaed
146
-		if ( isset( $_GET[ 'force_reload'] ) ) {
147
-			delete_transient( self::TRANSIENT_NAME );
148
-		}
149
-
150
-		// Try to retrieve the transient
151
-		$stats = get_transient( self::TRANSIENT_NAME );
152
-
153
-		if ( !$stats ) {
154
-			// Calculate stats
155
-			$stats = array(
156
-				'entities'	=>	$this->count_entities(),
157
-				'posts'	=>	$this->count_posts(),
158
-				'annotated_posts'	=>	$this->count_annotated_posts(),
159
-				'triples'	=> $this->count_triples(),
160
-				'rating' => $this->avarage_entities_rating(),
161
-			);	
162
-			// Cache stats results trough transient
163
-			set_transient( self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION );
164
-		}
165
-		// Return stats as json object
166
-		wl_core_send_json( $stats );
167
-	}
168
-
169
-	/**
170
-	 * Calculate total number of published posts
171
-	 * @uses https://codex.wordpress.org/it:Riferimento_funzioni/wp_count_posts
172
-	 * @since 3.4.0
173
-	 *
174
-	 * @return int Total number of published posts.
175
-	 */
176
-	public function count_posts() {
145
+        // If needed, the transient is force to reloaed
146
+        if ( isset( $_GET[ 'force_reload'] ) ) {
147
+            delete_transient( self::TRANSIENT_NAME );
148
+        }
149
+
150
+        // Try to retrieve the transient
151
+        $stats = get_transient( self::TRANSIENT_NAME );
152
+
153
+        if ( !$stats ) {
154
+            // Calculate stats
155
+            $stats = array(
156
+                'entities'	=>	$this->count_entities(),
157
+                'posts'	=>	$this->count_posts(),
158
+                'annotated_posts'	=>	$this->count_annotated_posts(),
159
+                'triples'	=> $this->count_triples(),
160
+                'rating' => $this->avarage_entities_rating(),
161
+            );	
162
+            // Cache stats results trough transient
163
+            set_transient( self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION );
164
+        }
165
+        // Return stats as json object
166
+        wl_core_send_json( $stats );
167
+    }
168
+
169
+    /**
170
+     * Calculate total number of published posts
171
+     * @uses https://codex.wordpress.org/it:Riferimento_funzioni/wp_count_posts
172
+     * @since 3.4.0
173
+     *
174
+     * @return int Total number of published posts.
175
+     */
176
+    public function count_posts() {
177 177
 		
178
-		return (int) wp_count_posts()->publish;		
179
-	}
180
-
181
-	/**
182
-	 * Calculate total number of annotated published posts
183
-	 * @since 3.4.0
184
-	 *
185
-	 * @return int Total number of annotated published posts.
186
-	 */
187
-	public function count_annotated_posts() {
178
+        return (int) wp_count_posts()->publish;		
179
+    }
180
+
181
+    /**
182
+     * Calculate total number of annotated published posts
183
+     * @since 3.4.0
184
+     *
185
+     * @return int Total number of annotated published posts.
186
+     */
187
+    public function count_annotated_posts() {
188 188
 		
189
-		// Prepare interaction with db
190
-    	global $wpdb;
191
-    	// Retrieve Wordlift relation instances table name
192
-    	$table_name = wl_core_get_relation_instances_table_name();
193
-    	// Calculate sql statement
194
-		$sql_statement = <<<EOF
189
+        // Prepare interaction with db
190
+        global $wpdb;
191
+        // Retrieve Wordlift relation instances table name
192
+        $table_name = wl_core_get_relation_instances_table_name();
193
+        // Calculate sql statement
194
+        $sql_statement = <<<EOF
195 195
     		SELECT COUNT(distinct(p.id)) FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.subject_id AND p.post_type = 'post' AND p.post_status = 'publish';
196 196
 EOF;
197
-		// Perform the query
198
-		return (int) $wpdb->get_var( $sql_statement ); 
197
+        // Perform the query
198
+        return (int) $wpdb->get_var( $sql_statement ); 
199 199
 		
200
-	}
201
-
202
-	/**
203
-	 * Calculate the avarage entities rating
204
-	 * @since 3.4.0
205
-	 *
206
-	 * @return int Avarage entities rating.
207
-	 */
208
-	public function avarage_entities_rating() {
200
+    }
201
+
202
+    /**
203
+     * Calculate the avarage entities rating
204
+     * @since 3.4.0
205
+     *
206
+     * @return int Avarage entities rating.
207
+     */
208
+    public function avarage_entities_rating() {
209 209
 		
210
-		// Prepare interaction with db
211
-    	global $wpdb;
212
-		$query = $wpdb->prepare( 
213
-			"SELECT AVG(meta_value) FROM $wpdb->postmeta where meta_key = %s",
214
-   			Wordlift_Entity_Service::RATING_RAW_SCORE_META_KEY
215
-			);
216
-		// Perform the query
217
-		return $this->entity_service->convert_raw_score_to_percentage( $wpdb->get_var( $query ) ); 	
218
-	}
219
-
220
-	/**
221
-	 * Calculate total number of published entities
222
-	 * @uses https://codex.wordpress.org/it:Riferimento_funzioni/wp_count_posts
223
-	 * @since 3.4.0
224
-	 *
225
-	 * @return int Total number of posts.
226
-	 */
227
-	public function count_entities() {
210
+        // Prepare interaction with db
211
+        global $wpdb;
212
+        $query = $wpdb->prepare( 
213
+            "SELECT AVG(meta_value) FROM $wpdb->postmeta where meta_key = %s",
214
+                Wordlift_Entity_Service::RATING_RAW_SCORE_META_KEY
215
+            );
216
+        // Perform the query
217
+        return $this->entity_service->convert_raw_score_to_percentage( $wpdb->get_var( $query ) ); 	
218
+    }
219
+
220
+    /**
221
+     * Calculate total number of published entities
222
+     * @uses https://codex.wordpress.org/it:Riferimento_funzioni/wp_count_posts
223
+     * @since 3.4.0
224
+     *
225
+     * @return int Total number of posts.
226
+     */
227
+    public function count_entities() {
228 228
 		
229
-		return (int) wp_count_posts( Wordlift_Entity_Service::TYPE_NAME )->publish;		
230
-	}
231
-
232
-	/**
233
-	 * Calculate total number of published rdf triples
234
-	 * @since 3.4.0
235
-	 *
236
-	 * @return int Total number of triples.
237
-	 */
238
-	public function count_triples() {
229
+        return (int) wp_count_posts( Wordlift_Entity_Service::TYPE_NAME )->publish;		
230
+    }
231
+
232
+    /**
233
+     * Calculate total number of published rdf triples
234
+     * @since 3.4.0
235
+     *
236
+     * @return int Total number of triples.
237
+     */
238
+    public function count_triples() {
239 239
 		
240
-		// Set the SPARQL query.
241
-		$sparql = 'SELECT (COUNT(*) AS ?no) { ?s ?p ?o  }';
242
-		// Send the request.
243
-		$response = $this->rl_sparql_select( $sparql );
244
-
245
-		// Return the error in case of failure.
246
-		if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) {
247
-			return (int) FALSE;
248
-		}
249
-
250
-		// Get the body.
251
-		$body = $response['body'];
252
-		// Get the values.
253
-		$matches = array();
254
-		if ( 1 === preg_match( '/(\d+)/im', $body, $matches ) && 2 === count( $matches ) ) {
255
-			// Return the counts.
256
-			return (int) $matches[1];
257
-		}
240
+        // Set the SPARQL query.
241
+        $sparql = 'SELECT (COUNT(*) AS ?no) { ?s ?p ?o  }';
242
+        // Send the request.
243
+        $response = $this->rl_sparql_select( $sparql );
244
+
245
+        // Return the error in case of failure.
246
+        if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) {
247
+            return (int) FALSE;
248
+        }
249
+
250
+        // Get the body.
251
+        $body = $response['body'];
252
+        // Get the values.
253
+        $matches = array();
254
+        if ( 1 === preg_match( '/(\d+)/im', $body, $matches ) && 2 === count( $matches ) ) {
255
+            // Return the counts.
256
+            return (int) $matches[1];
257
+        }
258 258
 		
259
-		return (int) FALSE;
260
-	}
259
+        return (int) FALSE;
260
+    }
261 261
 
262
-	private function rl_sparql_select( $query ) {
262
+    private function rl_sparql_select( $query ) {
263 263
 
264
-		// Prepare the SPARQL statement by prepending the default namespaces.
265
-		$sparql = rl_sparql_prefixes() . "\n" . $query;
266
-		// Get the SPARQL SELECT URL.
267
-		$url = wl_configuration_get_query_select_url( 'csv' ) . urlencode( $sparql );
268
-		// Prepare the request.
269
-		$args = unserialize( WL_REDLINK_API_HTTP_OPTIONS );
264
+        // Prepare the SPARQL statement by prepending the default namespaces.
265
+        $sparql = rl_sparql_prefixes() . "\n" . $query;
266
+        // Get the SPARQL SELECT URL.
267
+        $url = wl_configuration_get_query_select_url( 'csv' ) . urlencode( $sparql );
268
+        // Prepare the request.
269
+        $args = unserialize( WL_REDLINK_API_HTTP_OPTIONS );
270 270
 
271
-		return wp_remote_get( $url, $args );
272
-	}
271
+        return wp_remote_get( $url, $args );
272
+    }
273 273
 
274
-	private function render_stat_param( $param ) {
274
+    private function render_stat_param( $param ) {
275 275
 
276
-		return '<span id="wl-dashboard-widget-' . $param . '" class="wl-stat-value"></span>';
277
-	}
276
+        return '<span id="wl-dashboard-widget-' . $param . '" class="wl-stat-value"></span>';
277
+    }
278 278
 
279 279
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @param \Wordlift_Entity_Service $entity_service The Entity service.
46 46
 	 */
47
-	public function __construct( $entity_service ) {
47
+	public function __construct($entity_service) {
48 48
 
49
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Dashboard_Service' );
49
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Dashboard_Service');
50 50
 
51 51
 		$this->entity_service = $entity_service;
52 52
 
@@ -59,36 +59,36 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @return string Dashboard widget html markup
61 61
 	 */
62
-	public function dashboard_widget_callback( $post ) {
63
-
64
-		$enriched_posts_title = __( 'enriched posts', 'wordlift' ); 
65
-		$enriched_posts_caption = sprintf( wp_kses(
66
-			__( '%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift' ), 
67
-			array(  'a' => array( 'href' => array() ) ) ), 
68
-			$this->render_stat_param( 'annotated_posts_percentage' ),
69
-			esc_url( admin_url( 'edit.php' ) ),
70
-			$this->render_stat_param( 'annotated_posts' ),
71
-			$this->render_stat_param( 'posts' )  
62
+	public function dashboard_widget_callback($post) {
63
+
64
+		$enriched_posts_title = __('enriched posts', 'wordlift'); 
65
+		$enriched_posts_caption = sprintf(wp_kses(
66
+			__('%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift'), 
67
+			array('a' => array('href' => array())) ), 
68
+			$this->render_stat_param('annotated_posts_percentage'),
69
+			esc_url(admin_url('edit.php')),
70
+			$this->render_stat_param('annotated_posts'),
71
+			$this->render_stat_param('posts')  
72 72
 		); 
73 73
 
74
-		$rating_title = __( 'avarage entity rating', 'wordlift' ); 
75
-		$rating_caption = sprintf( wp_kses(
76
-			__( 'You have %1$s entities in your <a href="%2$s">vocabulary</a> with an avarage rating of %3$s.', 'wordlift' ), 
77
-			array(  'a' => array( 'href' => array() ) ) ), 
78
-			$this->render_stat_param( 'entities' ),
79
-			esc_url( admin_url( 'edit.php?post_type=entity' ) ),
80
-			$this->render_stat_param( 'rating' )
74
+		$rating_title = __('avarage entity rating', 'wordlift'); 
75
+		$rating_caption = sprintf(wp_kses(
76
+			__('You have %1$s entities in your <a href="%2$s">vocabulary</a> with an avarage rating of %3$s.', 'wordlift'), 
77
+			array('a' => array('href' => array())) ), 
78
+			$this->render_stat_param('entities'),
79
+			esc_url(admin_url('edit.php?post_type=entity')),
80
+			$this->render_stat_param('rating')
81 81
 		); 
82 82
 
83
-		$graph_title = __( 'triples in your graph', 'wordlift' ); 
84
-		$graph_caption = sprintf( wp_kses(
85
-			__( 'Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift' ), 
86
-			array(  'a' => array( 'href' => array() ) ) ), 
87
-			$this->render_stat_param( 'wikidata' ),
88
-			esc_url( 'https://www.wikidata.org/' )
83
+		$graph_title = __('triples in your graph', 'wordlift'); 
84
+		$graph_caption = sprintf(wp_kses(
85
+			__('Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift'), 
86
+			array('a' => array('href' => array())) ), 
87
+			$this->render_stat_param('wikidata'),
88
+			esc_url('https://www.wikidata.org/')
89 89
 		); 
90 90
 
91
-		$triples_label = __( 'triples', 'wordlift' ); 
91
+		$triples_label = __('triples', 'wordlift'); 
92 92
 		
93 93
 		echo <<<EOF
94 94
 	<div id="wl-dashboard-widget-inner-wrapper">
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 * @return string markup
130 130
 	 */
131 131
 	public function add_dashboard_widgets() {
132
-		wp_add_dashboard_widget('wordlift-dashboard-widget', 'WordLift Dashboard', array( $this, 'dashboard_widget_callback' ) );
132
+		wp_add_dashboard_widget('wordlift-dashboard-widget', 'WordLift Dashboard', array($this, 'dashboard_widget_callback'));
133 133
 	}
134 134
 
135 135
 	/**
@@ -143,14 +143,14 @@  discard block
 block discarded – undo
143 143
 	public function ajax_get_stats() {
144 144
 		
145 145
 		// If needed, the transient is force to reloaed
146
-		if ( isset( $_GET[ 'force_reload'] ) ) {
147
-			delete_transient( self::TRANSIENT_NAME );
146
+		if (isset($_GET['force_reload'])) {
147
+			delete_transient(self::TRANSIENT_NAME);
148 148
 		}
149 149
 
150 150
 		// Try to retrieve the transient
151
-		$stats = get_transient( self::TRANSIENT_NAME );
151
+		$stats = get_transient(self::TRANSIENT_NAME);
152 152
 
153
-		if ( !$stats ) {
153
+		if ( ! $stats) {
154 154
 			// Calculate stats
155 155
 			$stats = array(
156 156
 				'entities'	=>	$this->count_entities(),
@@ -160,10 +160,10 @@  discard block
 block discarded – undo
160 160
 				'rating' => $this->avarage_entities_rating(),
161 161
 			);	
162 162
 			// Cache stats results trough transient
163
-			set_transient( self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION );
163
+			set_transient(self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION);
164 164
 		}
165 165
 		// Return stats as json object
166
-		wl_core_send_json( $stats );
166
+		wl_core_send_json($stats);
167 167
 	}
168 168
 
169 169
 	/**
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
     		SELECT COUNT(distinct(p.id)) FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.subject_id AND p.post_type = 'post' AND p.post_status = 'publish';
196 196
 EOF;
197 197
 		// Perform the query
198
-		return (int) $wpdb->get_var( $sql_statement ); 
198
+		return (int) $wpdb->get_var($sql_statement); 
199 199
 		
200 200
 	}
201 201
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
    			Wordlift_Entity_Service::RATING_RAW_SCORE_META_KEY
215 215
 			);
216 216
 		// Perform the query
217
-		return $this->entity_service->convert_raw_score_to_percentage( $wpdb->get_var( $query ) ); 	
217
+		return $this->entity_service->convert_raw_score_to_percentage($wpdb->get_var($query)); 	
218 218
 	}
219 219
 
220 220
 	/**
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	 */
227 227
 	public function count_entities() {
228 228
 		
229
-		return (int) wp_count_posts( Wordlift_Entity_Service::TYPE_NAME )->publish;		
229
+		return (int) wp_count_posts(Wordlift_Entity_Service::TYPE_NAME)->publish;		
230 230
 	}
231 231
 
232 232
 	/**
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 		// Set the SPARQL query.
241 241
 		$sparql = 'SELECT (COUNT(*) AS ?no) { ?s ?p ?o  }';
242 242
 		// Send the request.
243
-		$response = $this->rl_sparql_select( $sparql );
243
+		$response = $this->rl_sparql_select($sparql);
244 244
 
245 245
 		// Return the error in case of failure.
246
-		if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) {
246
+		if (is_wp_error($response) || 200 !== (int) $response['response']['code']) {
247 247
 			return (int) FALSE;
248 248
 		}
249 249
 
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 		$body = $response['body'];
252 252
 		// Get the values.
253 253
 		$matches = array();
254
-		if ( 1 === preg_match( '/(\d+)/im', $body, $matches ) && 2 === count( $matches ) ) {
254
+		if (1 === preg_match('/(\d+)/im', $body, $matches) && 2 === count($matches)) {
255 255
 			// Return the counts.
256 256
 			return (int) $matches[1];
257 257
 		}
@@ -259,21 +259,21 @@  discard block
 block discarded – undo
259 259
 		return (int) FALSE;
260 260
 	}
261 261
 
262
-	private function rl_sparql_select( $query ) {
262
+	private function rl_sparql_select($query) {
263 263
 
264 264
 		// Prepare the SPARQL statement by prepending the default namespaces.
265
-		$sparql = rl_sparql_prefixes() . "\n" . $query;
265
+		$sparql = rl_sparql_prefixes()."\n".$query;
266 266
 		// Get the SPARQL SELECT URL.
267
-		$url = wl_configuration_get_query_select_url( 'csv' ) . urlencode( $sparql );
267
+		$url = wl_configuration_get_query_select_url('csv').urlencode($sparql);
268 268
 		// Prepare the request.
269
-		$args = unserialize( WL_REDLINK_API_HTTP_OPTIONS );
269
+		$args = unserialize(WL_REDLINK_API_HTTP_OPTIONS);
270 270
 
271
-		return wp_remote_get( $url, $args );
271
+		return wp_remote_get($url, $args);
272 272
 	}
273 273
 
274
-	private function render_stat_param( $param ) {
274
+	private function render_stat_param($param) {
275 275
 
276
-		return '<span id="wl-dashboard-widget-' . $param . '" class="wl-stat-value"></span>';
276
+		return '<span id="wl-dashboard-widget-'.$param.'" class="wl-stat-value"></span>';
277 277
 	}
278 278
 
279 279
 }
Please login to merge, or discard this patch.
src/admin/class-wordlift-entity-types-taxonomy-walker.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * Entity Types taxonomy.
5 5
  */
6 6
 if ( ! class_exists( 'Walker_Category_Checklist' ) ) {
7
-	require_once( ABSPATH . 'wp-admin/includes/template.php' );
7
+    require_once( ABSPATH . 'wp-admin/includes/template.php' );
8 8
 }
9 9
 
10 10
 /**
@@ -14,79 +14,79 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Wordlift_Entity_Types_Taxonomy_Walker extends Walker_Category_Checklist {
16 16
 
17
-	/**
18
-	 * The Log service.
19
-	 *
20
-	 * @since 3.1.0
21
-	 * @access private
22
-	 * @var \Wordlift_Log_Service $log_service The Log service.
23
-	 */
24
-	private $log_service;
17
+    /**
18
+     * The Log service.
19
+     *
20
+     * @since 3.1.0
21
+     * @access private
22
+     * @var \Wordlift_Log_Service $log_service The Log service.
23
+     */
24
+    private $log_service;
25 25
 
26
-	/**
27
-	 * Create an instance of Wordlift_Entity_Types_Taxonomy_Walker.
28
-	 *
29
-	 * @since 3.1.0
30
-	 */
31
-	public function __construct() {
26
+    /**
27
+     * Create an instance of Wordlift_Entity_Types_Taxonomy_Walker.
28
+     *
29
+     * @since 3.1.0
30
+     */
31
+    public function __construct() {
32 32
 
33
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Types_Taxonomy_Walker' );
33
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Types_Taxonomy_Walker' );
34 34
 
35
-	}
35
+    }
36 36
 
37
-	/**
38
-	 * Entity taxonomy metabox must show exclusive options, no checkboxes.
39
-	 *
40
-	 * @since 3.1.0
41
-	 *
42
-	 * @param $args
43
-	 *
44
-	 * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy.
45
-	 */
46
-	function terms_checklist_args( $args ) {
37
+    /**
38
+     * Entity taxonomy metabox must show exclusive options, no checkboxes.
39
+     *
40
+     * @since 3.1.0
41
+     *
42
+     * @param $args
43
+     *
44
+     * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy.
45
+     */
46
+    function terms_checklist_args( $args ) {
47 47
 
48
-		if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
49
-			return $args;
50
-		}
48
+        if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
49
+            return $args;
50
+        }
51 51
 
52
-		// We override the way WP prints the taxonomy metabox HTML
53
-		$args['walker']        = $this;
54
-		$args['checked_ontop'] = false;
52
+        // We override the way WP prints the taxonomy metabox HTML
53
+        $args['walker']        = $this;
54
+        $args['checked_ontop'] = false;
55 55
 
56
-		return $args;
56
+        return $args;
57 57
 
58
-	}
58
+    }
59 59
 
60 60
 
61
-	/**
62
-	 * Change checkboxes to radios.
63
-	 *
64
-	 * $max_depth = -1 means flatly display every element.
65
-	 * $max_depth = 0 means display all levels.
66
-	 * $max_depth > 0 specifies the number of display levels.
67
-	 *
68
-	 * @since 3.1.0
69
-	 *
70
-	 * @param array $elements An array of elements.
71
-	 * @param int $max_depth The maximum hierarchical depth.
72
-	 *
73
-	 * @param array $args Additional arguments.
74
-	 *
75
-	 * @return string The hierarchical item output.
76
-	 */
77
-	public function walk( $elements, $max_depth, $args = array() ) {
61
+    /**
62
+     * Change checkboxes to radios.
63
+     *
64
+     * $max_depth = -1 means flatly display every element.
65
+     * $max_depth = 0 means display all levels.
66
+     * $max_depth > 0 specifies the number of display levels.
67
+     *
68
+     * @since 3.1.0
69
+     *
70
+     * @param array $elements An array of elements.
71
+     * @param int $max_depth The maximum hierarchical depth.
72
+     *
73
+     * @param array $args Additional arguments.
74
+     *
75
+     * @return string The hierarchical item output.
76
+     */
77
+    public function walk( $elements, $max_depth, $args = array() ) {
78 78
 
79
-		$output = parent::walk( $elements, $max_depth, $args );
79
+        $output = parent::walk( $elements, $max_depth, $args );
80 80
 		
81
-		global $post; 
81
+        global $post; 
82 82
 		
83
-		$output = str_replace(
84
-			array( "type=\"checkbox\"", "type='checkbox'" ),
85
-			array( "type=\"radio\"", "type='radio'" ),
86
-			$output
87
-		);
83
+        $output = str_replace(
84
+            array( "type=\"checkbox\"", "type='checkbox'" ),
85
+            array( "type=\"radio\"", "type='radio'" ),
86
+            $output
87
+        );
88 88
 
89
-		return $output;
90
-	}
89
+        return $output;
90
+    }
91 91
 
92 92
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
  * This file contains the Entity Types Taxonomy Walker whose main role is to turn checkboxes to radios for the
4 4
  * Entity Types taxonomy.
5 5
  */
6
-if ( ! class_exists( 'Walker_Category_Checklist' ) ) {
7
-	require_once( ABSPATH . 'wp-admin/includes/template.php' );
6
+if ( ! class_exists('Walker_Category_Checklist')) {
7
+	require_once(ABSPATH.'wp-admin/includes/template.php');
8 8
 }
9 9
 
10 10
 /**
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 */
31 31
 	public function __construct() {
32 32
 
33
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Types_Taxonomy_Walker' );
33
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Entity_Types_Taxonomy_Walker');
34 34
 
35 35
 	}
36 36
 
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy.
45 45
 	 */
46
-	function terms_checklist_args( $args ) {
46
+	function terms_checklist_args($args) {
47 47
 
48
-		if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) {
48
+		if ( ! isset($args['taxonomy']) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy']) {
49 49
 			return $args;
50 50
 		}
51 51
 
@@ -74,15 +74,15 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return string The hierarchical item output.
76 76
 	 */
77
-	public function walk( $elements, $max_depth, $args = array() ) {
77
+	public function walk($elements, $max_depth, $args = array()) {
78 78
 
79
-		$output = parent::walk( $elements, $max_depth, $args );
79
+		$output = parent::walk($elements, $max_depth, $args);
80 80
 		
81 81
 		global $post; 
82 82
 		
83 83
 		$output = str_replace(
84
-			array( "type=\"checkbox\"", "type='checkbox'" ),
85
-			array( "type=\"radio\"", "type='radio'" ),
84
+			array("type=\"checkbox\"", "type='checkbox'"),
85
+			array("type=\"radio\"", "type='radio'"),
86 86
 			$output
87 87
 		);
88 88
 
Please login to merge, or discard this patch.
src/wordlift_entity_type.php 2 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -5,33 +5,33 @@  discard block
 block discarded – undo
5 5
  */
6 6
 function wl_entity_type_register() {
7 7
 
8
-	$labels = array(
9
-		'name'               => _x( 'Vocabulary', 'post type general name', 'wordlift' ),
10
-		'singular_name'      => _x( 'Entity', 'post type singular name', 'wordlift' ),
11
-		'add_new'            => _x( 'Add New Entity', 'entity', 'wordlift' ),
12
-		'add_new_item'       => __( 'Add New Entity', 'wordlift' ),
13
-		'edit_item'          => __( 'Edit Entity', 'wordlift' ),
14
-		'new_item'           => __( 'New Entity', 'wordlift' ),
15
-		'all_items'          => __( 'All Entities', 'wordlift' ),
16
-		'view_item'          => __( 'View Entity', 'wordlift' ),
17
-		'search_items'       => __( 'Search in Vocabulary', 'wordlift' ),
18
-		'not_found'          => __( 'No entities found', 'wordlift' ),
19
-		'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ),
20
-		'parent_item_colon'  => '',
21
-		'menu_name'          => __( 'Vocabulary', 'wordlift' )
22
-	);
23
-
24
-	$args = array(
25
-		'labels'        => $labels,
26
-		'description'   => 'Holds our vocabulary (set of entities) and entity specific data',
27
-		'public'        => true,
28
-		'menu_position' => 20, // after the pages menu.
29
-		'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
30
-		'has_archive'   => true,
31
-		'menu_icon'		=> 'dashicons-tag'
32
-	);
33
-
34
-	register_post_type( Wordlift_Entity_Service::TYPE_NAME, $args );
8
+    $labels = array(
9
+        'name'               => _x( 'Vocabulary', 'post type general name', 'wordlift' ),
10
+        'singular_name'      => _x( 'Entity', 'post type singular name', 'wordlift' ),
11
+        'add_new'            => _x( 'Add New Entity', 'entity', 'wordlift' ),
12
+        'add_new_item'       => __( 'Add New Entity', 'wordlift' ),
13
+        'edit_item'          => __( 'Edit Entity', 'wordlift' ),
14
+        'new_item'           => __( 'New Entity', 'wordlift' ),
15
+        'all_items'          => __( 'All Entities', 'wordlift' ),
16
+        'view_item'          => __( 'View Entity', 'wordlift' ),
17
+        'search_items'       => __( 'Search in Vocabulary', 'wordlift' ),
18
+        'not_found'          => __( 'No entities found', 'wordlift' ),
19
+        'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ),
20
+        'parent_item_colon'  => '',
21
+        'menu_name'          => __( 'Vocabulary', 'wordlift' )
22
+    );
23
+
24
+    $args = array(
25
+        'labels'        => $labels,
26
+        'description'   => 'Holds our vocabulary (set of entities) and entity specific data',
27
+        'public'        => true,
28
+        'menu_position' => 20, // after the pages menu.
29
+        'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
30
+        'has_archive'   => true,
31
+        'menu_icon'		=> 'dashicons-tag'
32
+    );
33
+
34
+    register_post_type( Wordlift_Entity_Service::TYPE_NAME, $args );
35 35
 }
36 36
 
37 37
 add_action( 'init', 'wl_entity_type_register' );
@@ -46,30 +46,30 @@  discard block
 block discarded – undo
46 46
 
47 47
 //	wl_write_log( "wl_set_entity_main_type [ post id :: $post_id ][ type uri :: $type_uri ]" );
48 48
 
49
-	// If the type URI is empty we remove the type.
50
-	if ( empty( $type_uri ) ) {
51
-		wp_set_object_terms( $post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
52
-
53
-		return;
54
-	}
55
-
56
-	// Get all the terms bound to the wl_entity_type taxonomy.
57
-	$terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
58
-		'hide_empty' => false,
59
-		'fields'     => 'id=>slug'
60
-	) );
61
-
62
-	// Check which term matches the specified URI.
63
-	foreach ( $terms as $term_id => $term_slug ) {
64
-		// Load the type data.
65
-		$type = Wordlift_Schema_Service::get_instance()->get_schema( $term_slug );
66
-		// Set the related term ID.
67
-		if ( $type_uri === $type['uri'] || $type_uri === $type['css_class'] ) {
68
-			wp_set_object_terms( $post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
69
-
70
-			return;
71
-		}
72
-	}
49
+    // If the type URI is empty we remove the type.
50
+    if ( empty( $type_uri ) ) {
51
+        wp_set_object_terms( $post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
52
+
53
+        return;
54
+    }
55
+
56
+    // Get all the terms bound to the wl_entity_type taxonomy.
57
+    $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
58
+        'hide_empty' => false,
59
+        'fields'     => 'id=>slug'
60
+    ) );
61
+
62
+    // Check which term matches the specified URI.
63
+    foreach ( $terms as $term_id => $term_slug ) {
64
+        // Load the type data.
65
+        $type = Wordlift_Schema_Service::get_instance()->get_schema( $term_slug );
66
+        // Set the related term ID.
67
+        if ( $type_uri === $type['uri'] || $type_uri === $type['css_class'] ) {
68
+            wp_set_object_terms( $post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
69
+
70
+            return;
71
+        }
72
+    }
73 73
 }
74 74
 
75 75
 /**
@@ -77,46 +77,46 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function wl_print_entity_type_inline_js() {
79 79
 
80
-	$terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
81
-		'hide_empty' => false
82
-	) );
80
+    $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
81
+        'hide_empty' => false
82
+    ) );
83 83
 
84
-	echo <<<EOF
84
+    echo <<<EOF
85 85
     <script type="text/javascript">
86 86
         (function() {
87 87
         var t = [];
88 88
 
89 89
 EOF;
90 90
 
91
-	// Cycle in each WordLift term and get its metadata. The metadata will be printed as a global object in JavaScript
92
-	// to be used by the JavaScript client library.
93
-	foreach ( $terms as $term ) {
91
+    // Cycle in each WordLift term and get its metadata. The metadata will be printed as a global object in JavaScript
92
+    // to be used by the JavaScript client library.
93
+    foreach ( $terms as $term ) {
94 94
 
95
-		$term_name = $term->name;
95
+        $term_name = $term->name;
96 96
 
97
-		// Load the type data.
98
-		$type = Wordlift_Schema_Service::get_instance()->get_schema( $term->slug );
97
+        // Load the type data.
98
+        $type = Wordlift_Schema_Service::get_instance()->get_schema( $term->slug );
99 99
 
100
-		// Skip types that are not defined.
101
-		if ( ! empty( $type['uri'] ) ) {
100
+        // Skip types that are not defined.
101
+        if ( ! empty( $type['uri'] ) ) {
102 102
 
103
-			// Prepare the JSON output then print it to the browser.
104
-			$json = json_encode( array(
105
-				'label'     => $term_name,
106
-				'uri'       => $type['uri'],
107
-				'css'       => $type['css_class'],
108
-				'sameAs'    => $type['same_as'],
109
-				'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ),
110
-			) );
103
+            // Prepare the JSON output then print it to the browser.
104
+            $json = json_encode( array(
105
+                'label'     => $term_name,
106
+                'uri'       => $type['uri'],
107
+                'css'       => $type['css_class'],
108
+                'sameAs'    => $type['same_as'],
109
+                'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ),
110
+            ) );
111 111
 
112
-			// Output the type data.
113
-			echo "t.push($json);\n";
112
+            // Output the type data.
113
+            echo "t.push($json);\n";
114 114
 
115
-		}
115
+        }
116 116
 
117
-	}
117
+    }
118 118
 
119
-	echo <<<EOF
119
+    echo <<<EOF
120 120
             if ('undefined' == typeof window.wordlift) {
121 121
                 window.wordlift = {}
122 122
             }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -6,19 +6,19 @@  discard block
 block discarded – undo
6 6
 function wl_entity_type_register() {
7 7
 
8 8
 	$labels = array(
9
-		'name'               => _x( 'Vocabulary', 'post type general name', 'wordlift' ),
10
-		'singular_name'      => _x( 'Entity', 'post type singular name', 'wordlift' ),
11
-		'add_new'            => _x( 'Add New Entity', 'entity', 'wordlift' ),
12
-		'add_new_item'       => __( 'Add New Entity', 'wordlift' ),
13
-		'edit_item'          => __( 'Edit Entity', 'wordlift' ),
14
-		'new_item'           => __( 'New Entity', 'wordlift' ),
15
-		'all_items'          => __( 'All Entities', 'wordlift' ),
16
-		'view_item'          => __( 'View Entity', 'wordlift' ),
17
-		'search_items'       => __( 'Search in Vocabulary', 'wordlift' ),
18
-		'not_found'          => __( 'No entities found', 'wordlift' ),
19
-		'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ),
9
+		'name'               => _x('Vocabulary', 'post type general name', 'wordlift'),
10
+		'singular_name'      => _x('Entity', 'post type singular name', 'wordlift'),
11
+		'add_new'            => _x('Add New Entity', 'entity', 'wordlift'),
12
+		'add_new_item'       => __('Add New Entity', 'wordlift'),
13
+		'edit_item'          => __('Edit Entity', 'wordlift'),
14
+		'new_item'           => __('New Entity', 'wordlift'),
15
+		'all_items'          => __('All Entities', 'wordlift'),
16
+		'view_item'          => __('View Entity', 'wordlift'),
17
+		'search_items'       => __('Search in Vocabulary', 'wordlift'),
18
+		'not_found'          => __('No entities found', 'wordlift'),
19
+		'not_found_in_trash' => __('No entities found in the Trash', 'wordlift'),
20 20
 		'parent_item_colon'  => '',
21
-		'menu_name'          => __( 'Vocabulary', 'wordlift' )
21
+		'menu_name'          => __('Vocabulary', 'wordlift')
22 22
 	);
23 23
 
24 24
 	$args = array(
@@ -26,15 +26,15 @@  discard block
 block discarded – undo
26 26
 		'description'   => 'Holds our vocabulary (set of entities) and entity specific data',
27 27
 		'public'        => true,
28 28
 		'menu_position' => 20, // after the pages menu.
29
-		'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
29
+		'supports'      => array('title', 'editor', 'thumbnail', 'excerpt', 'comments'),
30 30
 		'has_archive'   => true,
31 31
 		'menu_icon'		=> 'dashicons-tag'
32 32
 	);
33 33
 
34
-	register_post_type( Wordlift_Entity_Service::TYPE_NAME, $args );
34
+	register_post_type(Wordlift_Entity_Service::TYPE_NAME, $args);
35 35
 }
36 36
 
37
-add_action( 'init', 'wl_entity_type_register' );
37
+add_action('init', 'wl_entity_type_register');
38 38
 
39 39
 /**
40 40
  * Set the main type for the entity using the related taxonomy.
@@ -42,30 +42,30 @@  discard block
 block discarded – undo
42 42
  * @param int $post_id The numeric post ID.
43 43
  * @param string $type_uri A type URI.
44 44
  */
45
-function wl_set_entity_main_type( $post_id, $type_uri ) {
45
+function wl_set_entity_main_type($post_id, $type_uri) {
46 46
 
47 47
 //	wl_write_log( "wl_set_entity_main_type [ post id :: $post_id ][ type uri :: $type_uri ]" );
48 48
 
49 49
 	// If the type URI is empty we remove the type.
50
-	if ( empty( $type_uri ) ) {
51
-		wp_set_object_terms( $post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
50
+	if (empty($type_uri)) {
51
+		wp_set_object_terms($post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
52 52
 
53 53
 		return;
54 54
 	}
55 55
 
56 56
 	// Get all the terms bound to the wl_entity_type taxonomy.
57
-	$terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
57
+	$terms = get_terms(Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
58 58
 		'hide_empty' => false,
59 59
 		'fields'     => 'id=>slug'
60
-	) );
60
+	));
61 61
 
62 62
 	// Check which term matches the specified URI.
63
-	foreach ( $terms as $term_id => $term_slug ) {
63
+	foreach ($terms as $term_id => $term_slug) {
64 64
 		// Load the type data.
65
-		$type = Wordlift_Schema_Service::get_instance()->get_schema( $term_slug );
65
+		$type = Wordlift_Schema_Service::get_instance()->get_schema($term_slug);
66 66
 		// Set the related term ID.
67
-		if ( $type_uri === $type['uri'] || $type_uri === $type['css_class'] ) {
68
-			wp_set_object_terms( $post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
67
+		if ($type_uri === $type['uri'] || $type_uri === $type['css_class']) {
68
+			wp_set_object_terms($post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
69 69
 
70 70
 			return;
71 71
 		}
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function wl_print_entity_type_inline_js() {
79 79
 
80
-	$terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
80
+	$terms = get_terms(Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
81 81
 		'hide_empty' => false
82
-	) );
82
+	));
83 83
 
84 84
 	echo <<<EOF
85 85
     <script type="text/javascript">
@@ -90,24 +90,24 @@  discard block
 block discarded – undo
90 90
 
91 91
 	// Cycle in each WordLift term and get its metadata. The metadata will be printed as a global object in JavaScript
92 92
 	// to be used by the JavaScript client library.
93
-	foreach ( $terms as $term ) {
93
+	foreach ($terms as $term) {
94 94
 
95 95
 		$term_name = $term->name;
96 96
 
97 97
 		// Load the type data.
98
-		$type = Wordlift_Schema_Service::get_instance()->get_schema( $term->slug );
98
+		$type = Wordlift_Schema_Service::get_instance()->get_schema($term->slug);
99 99
 
100 100
 		// Skip types that are not defined.
101
-		if ( ! empty( $type['uri'] ) ) {
101
+		if ( ! empty($type['uri'])) {
102 102
 
103 103
 			// Prepare the JSON output then print it to the browser.
104
-			$json = json_encode( array(
104
+			$json = json_encode(array(
105 105
 				'label'     => $term_name,
106 106
 				'uri'       => $type['uri'],
107 107
 				'css'       => $type['css_class'],
108 108
 				'sameAs'    => $type['same_as'],
109
-				'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ),
110
-			) );
109
+				'templates' => (isset($type['templates']) ? $type['templates'] : array()),
110
+			));
111 111
 
112 112
 			// Output the type data.
113 113
 			echo "t.push($json);\n";
@@ -128,6 +128,6 @@  discard block
 block discarded – undo
128 128
 
129 129
 }
130 130
 
131
-add_action( 'admin_print_scripts', 'wl_print_entity_type_inline_js' );
131
+add_action('admin_print_scripts', 'wl_print_entity_type_inline_js');
132 132
 
133
-add_action( 'init', 'wl_entity_type_taxonomy_register', 0 );
133
+add_action('init', 'wl_entity_type_taxonomy_register', 0);
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-service.php 2 patches
Indentation   +705 added lines, -705 removed lines patch added patch discarded remove patch
@@ -7,748 +7,748 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Entity_Service {
9 9
 
10
-	/**
11
-	 * The Log service.
12
-	 *
13
-	 * @since 3.2.0
14
-	 * @access private
15
-	 * @var \Wordlift_Log_Service $log_service The Log service.
16
-	 */
17
-	private $log_service;
18
-
19
-	/**
20
-	 * The UI service.
21
-	 *
22
-	 * @since 3.2.0
23
-	 * @access private
24
-	 * @var \Wordlift_UI_Service $ui_service The UI service.
25
-	 */
26
-	private $ui_service;
27
-
28
-	/**
29
-	 * The Schema service.
30
-	 *
31
-	 * @since 3.3.0
32
-	 * @access private
33
-	 * @var \Wordlift_Schema_Service $schema_service The Schema service.
34
-	 */
35
-	private $schema_service;
36
-
37
-	/**
38
-	 * The Notice service.
39
-	 *
40
-	 * @since 3.3.0
41
-	 * @access private
42
-	 * @var \Wordlift_Notice_Service $notice_service The Notice service.
43
-	 */
44
-	private $notice_service;
45
-
46
-	/**
47
-	 * The entity post type name.
48
-	 *
49
-	 * @since 3.1.0
50
-	 */
51
-	const TYPE_NAME = 'entity';
52
-
53
-	/**
54
-	 * Entity rating max.
55
-	 *
56
-	 * @since 3.3.0
57
-	 */
58
-	const RATING_MAX = 7;
10
+    /**
11
+     * The Log service.
12
+     *
13
+     * @since 3.2.0
14
+     * @access private
15
+     * @var \Wordlift_Log_Service $log_service The Log service.
16
+     */
17
+    private $log_service;
18
+
19
+    /**
20
+     * The UI service.
21
+     *
22
+     * @since 3.2.0
23
+     * @access private
24
+     * @var \Wordlift_UI_Service $ui_service The UI service.
25
+     */
26
+    private $ui_service;
27
+
28
+    /**
29
+     * The Schema service.
30
+     *
31
+     * @since 3.3.0
32
+     * @access private
33
+     * @var \Wordlift_Schema_Service $schema_service The Schema service.
34
+     */
35
+    private $schema_service;
36
+
37
+    /**
38
+     * The Notice service.
39
+     *
40
+     * @since 3.3.0
41
+     * @access private
42
+     * @var \Wordlift_Notice_Service $notice_service The Notice service.
43
+     */
44
+    private $notice_service;
45
+
46
+    /**
47
+     * The entity post type name.
48
+     *
49
+     * @since 3.1.0
50
+     */
51
+    const TYPE_NAME = 'entity';
52
+
53
+    /**
54
+     * Entity rating max.
55
+     *
56
+     * @since 3.3.0
57
+     */
58
+    const RATING_MAX = 7;
59 59
 	
60
-	/**
61
-	 * Entity rating score meta key.
62
-	 *
63
-	 * @since 3.3.0
64
-	 */
65
-	const RATING_RAW_SCORE_META_KEY = '_wl_entity_rating_raw_score';
60
+    /**
61
+     * Entity rating score meta key.
62
+     *
63
+     * @since 3.3.0
64
+     */
65
+    const RATING_RAW_SCORE_META_KEY = '_wl_entity_rating_raw_score';
66 66
 	
67
-	/**
68
-	 * Entity rating warnings meta key.
69
-	 *
70
-	 * @since 3.3.0
71
-	 */
72
-	const RATING_WARNINGS_META_KEY = '_wl_entity_rating_warnings';
73
-
74
-	/**
75
-	 * Entity warning has related post identifier.
76
-	 *
77
-	 * @since 3.3.0
78
-	 */
79
-	const RATING_WARNING_HAS_RELATED_POSTS = 'There are no related posts for the current entity.';
80
-
81
-	/**
82
-	 * Entity warning has content post identifier.
83
-	 *
84
-	 * @since 3.3.0
85
-	 */
86
-	const RATING_WARNING_HAS_CONTENT_POST = 'This entity has not description.';
87
-
88
-	/**
89
-	 * Entity warning has related entities identifier.
90
-	 *
91
-	 * @since 3.3.0
92
-	 */
93
-	const RATING_WARNING_HAS_RELATED_ENTITIES = 'There are no related entities for the current entity.';
94
-
95
-	/**
96
-	 * Entity warning is published identifier.
97
-	 *
98
-	 * @since 3.3.0
99
-	 */
100
-	const RATING_WARNING_IS_PUBLISHED = 'This entity is not published. It will not appear within analysis results.';
101
-
102
-	/**
103
-	 * Entity warning has thumbnail identifier.
104
-	 *
105
-	 * @since 3.3.0
106
-	 */
107
-	const RATING_WARNING_HAS_THUMBNAIL = 'This entity has no featured image yet.';
108
-
109
-	/**
110
-	 * Entity warning has same as identifier.
111
-	 *
112
-	 * @since 3.3.0
113
-	 */
114
-	const RATING_WARNING_HAS_SAME_AS = 'There are no sameAs configured for this entity.';
115
-
116
-	/**
117
-	 * Entity warning has completed metadata identifier.
118
-	 *
119
-	 * @since 3.3.0
120
-	 */
121
-	const RATING_WARNING_HAS_COMPLETED_METADATA = 'Schema.org metadata for this entity are not completed.';
122
-
123
-	/**
124
-	 * The alternative label meta key.
125
-	 *
126
-	 * @since 3.2.0
127
-	 */
128
-	const ALTERNATIVE_LABEL_META_KEY = '_wl_alt_label';
129
-
130
-	/**
131
-	 * The alternative label input template.
132
-	 *
133
-	 * @since 3.2.0
134
-	 */
135
-	// TODO: this should be moved to a class that deals with HTML code.
136
-	const ALTERNATIVE_LABEL_INPUT_TEMPLATE = '<div class="wl-alternative-label">
67
+    /**
68
+     * Entity rating warnings meta key.
69
+     *
70
+     * @since 3.3.0
71
+     */
72
+    const RATING_WARNINGS_META_KEY = '_wl_entity_rating_warnings';
73
+
74
+    /**
75
+     * Entity warning has related post identifier.
76
+     *
77
+     * @since 3.3.0
78
+     */
79
+    const RATING_WARNING_HAS_RELATED_POSTS = 'There are no related posts for the current entity.';
80
+
81
+    /**
82
+     * Entity warning has content post identifier.
83
+     *
84
+     * @since 3.3.0
85
+     */
86
+    const RATING_WARNING_HAS_CONTENT_POST = 'This entity has not description.';
87
+
88
+    /**
89
+     * Entity warning has related entities identifier.
90
+     *
91
+     * @since 3.3.0
92
+     */
93
+    const RATING_WARNING_HAS_RELATED_ENTITIES = 'There are no related entities for the current entity.';
94
+
95
+    /**
96
+     * Entity warning is published identifier.
97
+     *
98
+     * @since 3.3.0
99
+     */
100
+    const RATING_WARNING_IS_PUBLISHED = 'This entity is not published. It will not appear within analysis results.';
101
+
102
+    /**
103
+     * Entity warning has thumbnail identifier.
104
+     *
105
+     * @since 3.3.0
106
+     */
107
+    const RATING_WARNING_HAS_THUMBNAIL = 'This entity has no featured image yet.';
108
+
109
+    /**
110
+     * Entity warning has same as identifier.
111
+     *
112
+     * @since 3.3.0
113
+     */
114
+    const RATING_WARNING_HAS_SAME_AS = 'There are no sameAs configured for this entity.';
115
+
116
+    /**
117
+     * Entity warning has completed metadata identifier.
118
+     *
119
+     * @since 3.3.0
120
+     */
121
+    const RATING_WARNING_HAS_COMPLETED_METADATA = 'Schema.org metadata for this entity are not completed.';
122
+
123
+    /**
124
+     * The alternative label meta key.
125
+     *
126
+     * @since 3.2.0
127
+     */
128
+    const ALTERNATIVE_LABEL_META_KEY = '_wl_alt_label';
129
+
130
+    /**
131
+     * The alternative label input template.
132
+     *
133
+     * @since 3.2.0
134
+     */
135
+    // TODO: this should be moved to a class that deals with HTML code.
136
+    const ALTERNATIVE_LABEL_INPUT_TEMPLATE = '<div class="wl-alternative-label">
137 137
                 <label class="screen-reader-text" id="wl-alternative-label-prompt-text" for="wl-alternative-label">Enter alternative label here</label>
138 138
                 <input name="wl_alternative_label[]" size="30" value="%s" id="wl-alternative-label" type="text">
139 139
                 <button class="button wl-delete-button">%s</button>
140 140
                 </div>';
141 141
 
142
-	/**
143
-	 * A singleton instance of the Entity service.
144
-	 *
145
-	 * @since 3.2.0
146
-	 * @access private
147
-	 * @var \Wordlift_Entity_Service $instance A singleton instance of the Entity service.
148
-	 */
149
-	private static $instance;
150
-
151
-	/**
152
-	 * Create a Wordlift_Entity_Service instance.
153
-	 *
154
-	 * @since 3.2.0
155
-	 *
156
-	 * @param \Wordlift_UI_Service $ui_service The UI service.
157
-	 */
158
-	public function __construct( $ui_service, $schema_service, $notice_service ) {
159
-
160
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
161
-
162
-		// Set the UI service.
163
-		$this->ui_service = $ui_service;
164
-
165
-		// Set the Schema service.
166
-		$this->schema_service = $schema_service;
167
-
168
-		// Set the Schema service.
169
-		$this->notice_service = $notice_service;
170
-
171
-		// Set the singleton instance.
172
-		self::$instance = $this;
173
-
174
-	}
175
-
176
-	/**
177
-	 * Get the singleton instance of the Entity service.
178
-	 *
179
-	 * @since 3.2.0
180
-	 * @return \Wordlift_Entity_Service The singleton instance of the Entity service.
181
-	 */
182
-	public static function get_instance() {
183
-
184
-		return self::$instance;
185
-	}
186
-
187
-	/**
188
-	 * Get rating max 
189
-	 *
190
-	 * @since 3.3.0
191
-	 *
192
-	 * @return int Max rating according to performed checks.
193
-	 */
194
-	public static function get_rating_max() {
195
-		return self::RATING_MAX;
196
-	}
197
-
198
-	/**
199
-	 * Get the entities related to the last 50 posts published on this blog (we're keeping a long function name due to
200
-	 * its specific function).
201
-	 *
202
-	 * @since 3.1.0
203
-	 *
204
-	 * @return array An array of post IDs.
205
-	 */
206
-	public function get_all_related_to_last_50_published_posts() {
207
-
208
-		// Global timeline. Get entities from the latest posts.
209
-		$latest_posts_ids = get_posts( array(
210
-			'numberposts' => 50,
211
-			'fields'      => 'ids', //only get post IDs
212
-			'post_type'   => 'post',
213
-			'post_status' => 'publish'
214
-		) );
215
-
216
-		if ( empty( $latest_posts_ids ) ) {
217
-			// There are no posts.
218
-			return array();
219
-		}
220
-
221
-		// Collect entities related to latest posts
222
-		$entity_ids = array();
223
-		foreach ( $latest_posts_ids as $id ) {
224
-			$entity_ids = array_merge( $entity_ids, wl_core_get_related_entity_ids( $id, array(
225
-				'status' => 'publish'
226
-			) ) );
227
-		}
228
-
229
-		return $entity_ids;
230
-	}
231
-
232
-	/**
233
-	 * Determines whether a post is an entity or not.
234
-	 *
235
-	 * @since 3.1.0
236
-	 *
237
-	 * @param int $post_id A post id.
238
-	 *
239
-	 * @return bool Return true if the post is an entity otherwise false.
240
-	 */
241
-	public function is_entity( $post_id ) {
242
-
243
-		return ( self::TYPE_NAME === get_post_type( $post_id ) );
244
-	}
245
-
246
-	/**
247
-	 * Build an entity uri for a given title
248
-	 * The uri is composed using a given post_type and a title
249
-	 * If already exists an entity e2 with a given uri a numeric suffix is added
250
-	 * If a schema type is given entities with same label and same type are overridden 
251
-	 *
252
-	 * @since 3.5.0
253
-	 *
254
-	 * @param string $title A post title.
255
-	 * @param string $post_type A post type. Default value is 'entity'
256
-	 * @param string $schema_type A schema org type. 
257
-	 * @param integer $increment_digit A digit used to call recursively the same function.
258
-	 *
259
-	 * @return string Returns an uri.
260
-	 */
261
-	public function build_uri( $title, $post_type, $schema_type = NULL, $increment_digit = 0 ) {
142
+    /**
143
+     * A singleton instance of the Entity service.
144
+     *
145
+     * @since 3.2.0
146
+     * @access private
147
+     * @var \Wordlift_Entity_Service $instance A singleton instance of the Entity service.
148
+     */
149
+    private static $instance;
150
+
151
+    /**
152
+     * Create a Wordlift_Entity_Service instance.
153
+     *
154
+     * @since 3.2.0
155
+     *
156
+     * @param \Wordlift_UI_Service $ui_service The UI service.
157
+     */
158
+    public function __construct( $ui_service, $schema_service, $notice_service ) {
159
+
160
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
161
+
162
+        // Set the UI service.
163
+        $this->ui_service = $ui_service;
164
+
165
+        // Set the Schema service.
166
+        $this->schema_service = $schema_service;
167
+
168
+        // Set the Schema service.
169
+        $this->notice_service = $notice_service;
170
+
171
+        // Set the singleton instance.
172
+        self::$instance = $this;
173
+
174
+    }
175
+
176
+    /**
177
+     * Get the singleton instance of the Entity service.
178
+     *
179
+     * @since 3.2.0
180
+     * @return \Wordlift_Entity_Service The singleton instance of the Entity service.
181
+     */
182
+    public static function get_instance() {
183
+
184
+        return self::$instance;
185
+    }
186
+
187
+    /**
188
+     * Get rating max 
189
+     *
190
+     * @since 3.3.0
191
+     *
192
+     * @return int Max rating according to performed checks.
193
+     */
194
+    public static function get_rating_max() {
195
+        return self::RATING_MAX;
196
+    }
197
+
198
+    /**
199
+     * Get the entities related to the last 50 posts published on this blog (we're keeping a long function name due to
200
+     * its specific function).
201
+     *
202
+     * @since 3.1.0
203
+     *
204
+     * @return array An array of post IDs.
205
+     */
206
+    public function get_all_related_to_last_50_published_posts() {
207
+
208
+        // Global timeline. Get entities from the latest posts.
209
+        $latest_posts_ids = get_posts( array(
210
+            'numberposts' => 50,
211
+            'fields'      => 'ids', //only get post IDs
212
+            'post_type'   => 'post',
213
+            'post_status' => 'publish'
214
+        ) );
215
+
216
+        if ( empty( $latest_posts_ids ) ) {
217
+            // There are no posts.
218
+            return array();
219
+        }
220
+
221
+        // Collect entities related to latest posts
222
+        $entity_ids = array();
223
+        foreach ( $latest_posts_ids as $id ) {
224
+            $entity_ids = array_merge( $entity_ids, wl_core_get_related_entity_ids( $id, array(
225
+                'status' => 'publish'
226
+            ) ) );
227
+        }
228
+
229
+        return $entity_ids;
230
+    }
231
+
232
+    /**
233
+     * Determines whether a post is an entity or not.
234
+     *
235
+     * @since 3.1.0
236
+     *
237
+     * @param int $post_id A post id.
238
+     *
239
+     * @return bool Return true if the post is an entity otherwise false.
240
+     */
241
+    public function is_entity( $post_id ) {
242
+
243
+        return ( self::TYPE_NAME === get_post_type( $post_id ) );
244
+    }
245
+
246
+    /**
247
+     * Build an entity uri for a given title
248
+     * The uri is composed using a given post_type and a title
249
+     * If already exists an entity e2 with a given uri a numeric suffix is added
250
+     * If a schema type is given entities with same label and same type are overridden 
251
+     *
252
+     * @since 3.5.0
253
+     *
254
+     * @param string $title A post title.
255
+     * @param string $post_type A post type. Default value is 'entity'
256
+     * @param string $schema_type A schema org type. 
257
+     * @param integer $increment_digit A digit used to call recursively the same function.
258
+     *
259
+     * @return string Returns an uri.
260
+     */
261
+    public function build_uri( $title, $post_type, $schema_type = NULL, $increment_digit = 0 ) {
262 262
 		
263
-		// Get the entity slug suffix digit
264
-		$suffix_digit = $increment_digit + 1;
265
-		// Get a sanitized uri for a given title
266
-		$entity_slug = ( 0 == $increment_digit ) ? 
267
-			wl_sanitize_uri_path( $title ) :
268
-			wl_sanitize_uri_path( $title . '_'. $suffix_digit );
269
-
270
-		// Compose a candidated uri
271
-		$new_entity_uri = sprintf( '%s/%s/%s', 
272
-			wl_configuration_get_redlink_dataset_uri(), 
273
-			$post_type, 
274
-			$entity_slug 
275
-		); 
263
+        // Get the entity slug suffix digit
264
+        $suffix_digit = $increment_digit + 1;
265
+        // Get a sanitized uri for a given title
266
+        $entity_slug = ( 0 == $increment_digit ) ? 
267
+            wl_sanitize_uri_path( $title ) :
268
+            wl_sanitize_uri_path( $title . '_'. $suffix_digit );
269
+
270
+        // Compose a candidated uri
271
+        $new_entity_uri = sprintf( '%s/%s/%s', 
272
+            wl_configuration_get_redlink_dataset_uri(), 
273
+            $post_type, 
274
+            $entity_slug 
275
+        ); 
276 276
 		
277
-		$this->log_service->trace( "Going to check if uri is used [ new_entity_uri :: $new_entity_uri ] [ increment_digit :: $increment_digit ]" );
277
+        $this->log_service->trace( "Going to check if uri is used [ new_entity_uri :: $new_entity_uri ] [ increment_digit :: $increment_digit ]" );
278 278
 		
279
-		global $wpdb;
280
-    	// Check if the candidated uri already is used
281
-    	// TODO Get post ids instead of count()
282
-		$stmt = $wpdb->prepare( 
283
-    		"SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s LIMIT 1", 
284
-    		WL_ENTITY_URL_META_NAME,
285
-    		$new_entity_uri
286
-    	);
287
-
288
-    	// Perform the query
289
-		$post_id = $wpdb->get_var( $stmt ); 		
279
+        global $wpdb;
280
+        // Check if the candidated uri already is used
281
+        // TODO Get post ids instead of count()
282
+        $stmt = $wpdb->prepare( 
283
+            "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s LIMIT 1", 
284
+            WL_ENTITY_URL_META_NAME,
285
+            $new_entity_uri
286
+        );
287
+
288
+        // Perform the query
289
+        $post_id = $wpdb->get_var( $stmt ); 		
290 290
 			
291
-		// If the post does not exist, then the new uri is returned 	
292
-		if ( ! is_numeric( $post_id ) ) {
293
-			$this->log_service->trace( "Going to return uri [ new_entity_uri :: $new_entity_uri ]" );
294
-			return $new_entity_uri;
295
-		}
296
-		// If schema_type is equal to schema org type of post x, then the new uri is returned 
297
-		$schema_post_type = wl_entity_type_taxonomy_get_type( $post_id );
291
+        // If the post does not exist, then the new uri is returned 	
292
+        if ( ! is_numeric( $post_id ) ) {
293
+            $this->log_service->trace( "Going to return uri [ new_entity_uri :: $new_entity_uri ]" );
294
+            return $new_entity_uri;
295
+        }
296
+        // If schema_type is equal to schema org type of post x, then the new uri is returned 
297
+        $schema_post_type = wl_entity_type_taxonomy_get_type( $post_id );
298 298
 			
299
-		if ( $schema_type === $schema_post_type[ 'css_class' ] ) {
300
-			$this->log_service->trace( "An entity with the same title and type already exists! Return uri [ new_entity_uri :: $new_entity_uri ]" );
301
-			return $new_entity_uri;
302
-		}
303
-
304
-		// Otherwise the same function is called recorsively
305
-		return $this->build_uri( $title, $post_type, $schema_type, ++$increment_digit );
306
-	}
307
-
308
-	public function is_used( $post_id ) {
309
-
310
-		if ( FALSE === $this->is_entity( $post_id ) ) {
311
-			return null;
312
-		}
313
-		// Retrieve the post
314
-		$entity = get_post( $post_id ); 
315
-
316
-		global $wpdb;
317
-    	// Retrieve Wordlift relation instances table name
318
-    	$table_name = wl_core_get_relation_instances_table_name();
319
-
320
-		// Check is it's referenced / related to another post / entity
321
-    	$stmt = $wpdb->prepare( 
322
-    		"SELECT COUNT(*) FROM $table_name WHERE  object_id = %d", 
323
-    		$entity->ID
324
-    	);
299
+        if ( $schema_type === $schema_post_type[ 'css_class' ] ) {
300
+            $this->log_service->trace( "An entity with the same title and type already exists! Return uri [ new_entity_uri :: $new_entity_uri ]" );
301
+            return $new_entity_uri;
302
+        }
303
+
304
+        // Otherwise the same function is called recorsively
305
+        return $this->build_uri( $title, $post_type, $schema_type, ++$increment_digit );
306
+    }
307
+
308
+    public function is_used( $post_id ) {
309
+
310
+        if ( FALSE === $this->is_entity( $post_id ) ) {
311
+            return null;
312
+        }
313
+        // Retrieve the post
314
+        $entity = get_post( $post_id ); 
315
+
316
+        global $wpdb;
317
+        // Retrieve Wordlift relation instances table name
318
+        $table_name = wl_core_get_relation_instances_table_name();
319
+
320
+        // Check is it's referenced / related to another post / entity
321
+        $stmt = $wpdb->prepare( 
322
+            "SELECT COUNT(*) FROM $table_name WHERE  object_id = %d", 
323
+            $entity->ID
324
+        );
325 325
 		
326
-		// Perform the query
327
-		$relation_instances = (int) $wpdb->get_var( $stmt ); 
328
-		// If there is at least one relation instance for the current entity, then it's used
329
-		if ( 0 < $relation_instances ) {		
330
-			return TRUE;
331
-		}
332
-
333
-    	// Check if the entity uri is used as meta_value
334
-		$stmt = $wpdb->prepare( 
335
-    		"SELECT COUNT(*) FROM $wpdb->postmeta WHERE post_id != %d AND meta_value = %s", 
336
-    		$entity->ID,
337
-    		wl_get_entity_uri( $entity->ID )
338
-    	);
339
-    	// Perform the query
340
-		$meta_instances = (int) $wpdb->get_var( $stmt ); 
326
+        // Perform the query
327
+        $relation_instances = (int) $wpdb->get_var( $stmt ); 
328
+        // If there is at least one relation instance for the current entity, then it's used
329
+        if ( 0 < $relation_instances ) {		
330
+            return TRUE;
331
+        }
332
+
333
+        // Check if the entity uri is used as meta_value
334
+        $stmt = $wpdb->prepare( 
335
+            "SELECT COUNT(*) FROM $wpdb->postmeta WHERE post_id != %d AND meta_value = %s", 
336
+            $entity->ID,
337
+            wl_get_entity_uri( $entity->ID )
338
+        );
339
+        // Perform the query
340
+        $meta_instances = (int) $wpdb->get_var( $stmt ); 
341 341
 		
342
-		// If there is at least one meta that refers the current entity uri, then current entity is used
343
-		if ( 0 < $meta_instances ) {
344
-			return TRUE;
345
-		}
346
-
347
-		// If we are here, it means the current entity is not used at the moment
348
-		return FALSE;
349
-	}
350
-
351
-	/**
352
-	 * Determines whether a given uri is an internal uri or not.
353
-	 *
354
-	 * @since 3.3.2
355
-	 *
356
-	 * @param int $uri An uri.
357
-	 *
358
-	 * @return true if the uri internal to the current dataset otherwise false.
359
-	 */
360
-	public function is_internal_uri( $uri ) {
361
-
362
-		return ( 0 === strrpos( $uri, wl_configuration_get_redlink_dataset_uri() ) );
363
-	}
364
-
365
-	/**
366
-	 * Find entity posts by the entity URI. Entity as searched by their entity URI or same as.
367
-	 *
368
-	 * @since 3.2.0
369
-	 *
370
-	 * @param string $uri The entity URI.
371
-	 *
372
-	 * @return WP_Post|null A WP_Post instance or null if not found.
373
-	 */
374
-	public function get_entity_post_by_uri( $uri ) {
375
-
376
-		$query_args = array(
377
-			'posts_per_page'	=> 1,
378
-			'post_status'		=> 'any',
379
-			'post_type'			=> self::TYPE_NAME,
380
-			'meta_query'		=> array(
381
-				array(
382
-					'key'     => WL_ENTITY_URL_META_NAME,
383
-					'value'   => $uri,
384
-					'compare' => '='
385
-				)
386
-			)
387
-		);
388
-
389
-		// Only if the current uri is not an internal uri 
390
-		// entity search is performed also looking at sameAs values
391
-		// This solve issues like https://github.com/insideout10/wordlift-plugin/issues/237
392
-		if ( !$this->is_internal_uri( $uri ) ) {
342
+        // If there is at least one meta that refers the current entity uri, then current entity is used
343
+        if ( 0 < $meta_instances ) {
344
+            return TRUE;
345
+        }
346
+
347
+        // If we are here, it means the current entity is not used at the moment
348
+        return FALSE;
349
+    }
350
+
351
+    /**
352
+     * Determines whether a given uri is an internal uri or not.
353
+     *
354
+     * @since 3.3.2
355
+     *
356
+     * @param int $uri An uri.
357
+     *
358
+     * @return true if the uri internal to the current dataset otherwise false.
359
+     */
360
+    public function is_internal_uri( $uri ) {
361
+
362
+        return ( 0 === strrpos( $uri, wl_configuration_get_redlink_dataset_uri() ) );
363
+    }
364
+
365
+    /**
366
+     * Find entity posts by the entity URI. Entity as searched by their entity URI or same as.
367
+     *
368
+     * @since 3.2.0
369
+     *
370
+     * @param string $uri The entity URI.
371
+     *
372
+     * @return WP_Post|null A WP_Post instance or null if not found.
373
+     */
374
+    public function get_entity_post_by_uri( $uri ) {
375
+
376
+        $query_args = array(
377
+            'posts_per_page'	=> 1,
378
+            'post_status'		=> 'any',
379
+            'post_type'			=> self::TYPE_NAME,
380
+            'meta_query'		=> array(
381
+                array(
382
+                    'key'     => WL_ENTITY_URL_META_NAME,
383
+                    'value'   => $uri,
384
+                    'compare' => '='
385
+                )
386
+            )
387
+        );
388
+
389
+        // Only if the current uri is not an internal uri 
390
+        // entity search is performed also looking at sameAs values
391
+        // This solve issues like https://github.com/insideout10/wordlift-plugin/issues/237
392
+        if ( !$this->is_internal_uri( $uri ) ) {
393 393
 		
394
-			$query_args[ 'meta_query' ][ 'relation' ] = 'OR';
395
-			$query_args[ 'meta_query' ][] = array(
396
-				'key'     => Wordlift_Schema_Service::FIELD_SAME_AS,
397
-				'value'   => $uri,
398
-				'compare' => '='
399
-			);
400
-		} 
401
-
402
-		$query = new WP_Query( $query_args );
403
-
404
-		// Get the matching entity posts.
405
-		$posts = $query->get_posts();
406
-
407
-		// Return null if no post is found.
408
-		if ( 0 === count( $posts ) ) {
409
-			return null;
410
-		}
411
-
412
-		// Return the found post.
413
-		return $posts[0];
414
-	}
415
-
416
-	/**
417
-	 * Fires once a post has been saved.
418
-	 *
419
-	 * @since 3.2.0
420
-	 *
421
-	 * @param int $post_id Post ID.
422
-	 * @param WP_Post $post Post object.
423
-	 * @param bool $update Whether this is an existing post being updated or not.
424
-	 */
425
-	public function save_post( $post_id, $post, $update ) {
426
-
427
-		// If it's not an entity, return.
428
-		if ( ! $this->is_entity( $post_id ) ) {
429
-			return;
430
-		}
431
-
432
-		// Get the alt labels from the request (or empty array).
433
-		$alt_labels = isset( $_REQUEST['wl_alternative_label'] ) ? $_REQUEST['wl_alternative_label'] : array();
434
-
435
-		// Set the alternative labels.
436
-		$this->set_alternative_labels( $post_id, $alt_labels );
437
-
438
-	}
439
-
440
-	/**
441
-	 * Set the alternative labels.
442
-	 *
443
-	 * @since 3.2.0
444
-	 *
445
-	 * @param int $post_id The post id.
446
-	 * @param array $alt_labels An array of labels.
447
-	 */
448
-	public function set_alternative_labels( $post_id, $alt_labels ) {
394
+            $query_args[ 'meta_query' ][ 'relation' ] = 'OR';
395
+            $query_args[ 'meta_query' ][] = array(
396
+                'key'     => Wordlift_Schema_Service::FIELD_SAME_AS,
397
+                'value'   => $uri,
398
+                'compare' => '='
399
+            );
400
+        } 
401
+
402
+        $query = new WP_Query( $query_args );
403
+
404
+        // Get the matching entity posts.
405
+        $posts = $query->get_posts();
406
+
407
+        // Return null if no post is found.
408
+        if ( 0 === count( $posts ) ) {
409
+            return null;
410
+        }
411
+
412
+        // Return the found post.
413
+        return $posts[0];
414
+    }
415
+
416
+    /**
417
+     * Fires once a post has been saved.
418
+     *
419
+     * @since 3.2.0
420
+     *
421
+     * @param int $post_id Post ID.
422
+     * @param WP_Post $post Post object.
423
+     * @param bool $update Whether this is an existing post being updated or not.
424
+     */
425
+    public function save_post( $post_id, $post, $update ) {
426
+
427
+        // If it's not an entity, return.
428
+        if ( ! $this->is_entity( $post_id ) ) {
429
+            return;
430
+        }
431
+
432
+        // Get the alt labels from the request (or empty array).
433
+        $alt_labels = isset( $_REQUEST['wl_alternative_label'] ) ? $_REQUEST['wl_alternative_label'] : array();
434
+
435
+        // Set the alternative labels.
436
+        $this->set_alternative_labels( $post_id, $alt_labels );
437
+
438
+    }
439
+
440
+    /**
441
+     * Set the alternative labels.
442
+     *
443
+     * @since 3.2.0
444
+     *
445
+     * @param int $post_id The post id.
446
+     * @param array $alt_labels An array of labels.
447
+     */
448
+    public function set_alternative_labels( $post_id, $alt_labels ) {
449 449
 		
450
-		// Force $alt_labels to be an array
451
-		if( !is_array( $alt_labels ) ) {
452
-			$alt_labels = array( $alt_labels );
453
-		}
450
+        // Force $alt_labels to be an array
451
+        if( !is_array( $alt_labels ) ) {
452
+            $alt_labels = array( $alt_labels );
453
+        }
454 454
 
455
-		$this->log_service->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . " ]" );
455
+        $this->log_service->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . " ]" );
456 456
 
457
-		// Delete all the existing alternate labels.
458
-		delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
457
+        // Delete all the existing alternate labels.
458
+        delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
459 459
 		
460
-		// Set the alternative labels.
461
-		foreach ( $alt_labels as $alt_label ) {
462
-			if ( ! empty( $alt_label ) ) {
463
-				add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, $alt_label );
464
-			}
465
-		}
466
-
467
-	}
468
-
469
-	/**
470
-	 * Retrieve the alternate labels.
471
-	 *
472
-	 * @since 3.2.0
473
-	 *
474
-	 * @param int $post_id Post id.
475
-	 *
476
-	 * @return mixed An array  of alternative labels.
477
-	 */
478
-	public function get_alternative_labels( $post_id ) {
479
-
480
-		return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
481
-	}
482
-
483
-	/**
484
-	 * Fires before the permalink field in the edit form (this event is available in WP from 4.1.0).
485
-	 *
486
-	 * @since 3.2.0
487
-	 *
488
-	 * @param WP_Post $post Post object.
489
-	 */
490
-	public function edit_form_before_permalink( $post ) {
491
-
492
-		// If it's not an entity, return.
493
-		if ( ! $this->is_entity( $post->ID ) ) {
494
-			return;
495
-		}
496
-
497
-		// Print the input template.
498
-		$this->ui_service->print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
499
-
500
-		// Print all the currently set alternative labels.
501
-		foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
502
-
503
-			echo $this->get_alternative_label_input( $alt_label );
504
-
505
-		};
506
-
507
-		// Print the button.
508
-		$this->ui_service->print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
509
-
510
-	}
511
-
512
-	/**
513
-	 * Add admin notices for the current entity depending on the current rating.
514
-	 *
515
-	 * @since 3.3.0
516
-	 *
517
-	 * @param WP_Post $post Post object.
518
-	 */
519
-	public function in_admin_header() {
520
-
521
-		// Return safely if get_current_screen() is not defined (yet)
522
-		if ( FALSE === function_exists( 'get_current_screen' ) ) {
523
-			return;
524
-		}
460
+        // Set the alternative labels.
461
+        foreach ( $alt_labels as $alt_label ) {
462
+            if ( ! empty( $alt_label ) ) {
463
+                add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, $alt_label );
464
+            }
465
+        }
466
+
467
+    }
468
+
469
+    /**
470
+     * Retrieve the alternate labels.
471
+     *
472
+     * @since 3.2.0
473
+     *
474
+     * @param int $post_id Post id.
475
+     *
476
+     * @return mixed An array  of alternative labels.
477
+     */
478
+    public function get_alternative_labels( $post_id ) {
479
+
480
+        return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
481
+    }
482
+
483
+    /**
484
+     * Fires before the permalink field in the edit form (this event is available in WP from 4.1.0).
485
+     *
486
+     * @since 3.2.0
487
+     *
488
+     * @param WP_Post $post Post object.
489
+     */
490
+    public function edit_form_before_permalink( $post ) {
491
+
492
+        // If it's not an entity, return.
493
+        if ( ! $this->is_entity( $post->ID ) ) {
494
+            return;
495
+        }
496
+
497
+        // Print the input template.
498
+        $this->ui_service->print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
499
+
500
+        // Print all the currently set alternative labels.
501
+        foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
502
+
503
+            echo $this->get_alternative_label_input( $alt_label );
504
+
505
+        };
506
+
507
+        // Print the button.
508
+        $this->ui_service->print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
509
+
510
+    }
511
+
512
+    /**
513
+     * Add admin notices for the current entity depending on the current rating.
514
+     *
515
+     * @since 3.3.0
516
+     *
517
+     * @param WP_Post $post Post object.
518
+     */
519
+    public function in_admin_header() {
520
+
521
+        // Return safely if get_current_screen() is not defined (yet)
522
+        if ( FALSE === function_exists( 'get_current_screen' ) ) {
523
+            return;
524
+        }
525 525
 		
526
-		$screen = get_current_screen();
527
-		// If there is any valid screen nothing to do
528
-		if ( NULL === $screen ) {
529
-			return $clauses;
530
-		}
531
-
532
-		// If you're not in the entity post edit page, return.
533
-		if ( self::TYPE_NAME !== $screen->id ) {
534
-			return;
535
-		}
536
-		// Retrieve the current global post
537
-		global $post;
538
-		// If it's not an entity, return.
539
-		if ( ! $this->is_entity( $post->ID ) ) {
540
-			return;
541
-		}
542
-		// Retrieve an updated rating for the current entity
543
-		$rating = $this->get_rating_for( $post->ID, true );
544
-		// If there is at least 1 warning
545
-		if ( isset( $rating[ 'warnings' ] ) && 0 < count( $rating[ 'warnings' ] ) ) {
546
-			// TODO - Pass Wordlift_Notice_Service trough the service constructor 
547
-			$this->notice_service->add_suggestion( $rating[ 'warnings' ] );
548
-		}
526
+        $screen = get_current_screen();
527
+        // If there is any valid screen nothing to do
528
+        if ( NULL === $screen ) {
529
+            return $clauses;
530
+        }
531
+
532
+        // If you're not in the entity post edit page, return.
533
+        if ( self::TYPE_NAME !== $screen->id ) {
534
+            return;
535
+        }
536
+        // Retrieve the current global post
537
+        global $post;
538
+        // If it's not an entity, return.
539
+        if ( ! $this->is_entity( $post->ID ) ) {
540
+            return;
541
+        }
542
+        // Retrieve an updated rating for the current entity
543
+        $rating = $this->get_rating_for( $post->ID, true );
544
+        // If there is at least 1 warning
545
+        if ( isset( $rating[ 'warnings' ] ) && 0 < count( $rating[ 'warnings' ] ) ) {
546
+            // TODO - Pass Wordlift_Notice_Service trough the service constructor 
547
+            $this->notice_service->add_suggestion( $rating[ 'warnings' ] );
548
+        }
549 549
 		
550
-	}
550
+    }
551 551
 	
552
-	/**
553
-	 * Set rating for a given entity
554
-	 *
555
-	 * @since 3.3.0
556
-	 *
557
-	 * @param int $post_id The entity post id.
558
-	 *
559
-	 * @return int An array representing the rating obj.
560
-	 */
561
-	public function set_rating_for( $post_id ) {
562
-
563
-		// Calculate rating for the given post
564
-		$rating = $this->calculate_rating_for( $post_id );
565
-		// Store the rating on db as post meta
566
-		// Please notice that RATING_RAW_SCORE_META_KEY 
567
-		// is saved on a different meta to allow score sorting
568
-		// Both meta are managed as unique
569
-		// https://codex.wordpress.org/Function_Reference/update_post_meta
570
-		update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating[ 'raw_score' ] );
571
-		update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating[ 'warnings' ] );
552
+    /**
553
+     * Set rating for a given entity
554
+     *
555
+     * @since 3.3.0
556
+     *
557
+     * @param int $post_id The entity post id.
558
+     *
559
+     * @return int An array representing the rating obj.
560
+     */
561
+    public function set_rating_for( $post_id ) {
562
+
563
+        // Calculate rating for the given post
564
+        $rating = $this->calculate_rating_for( $post_id );
565
+        // Store the rating on db as post meta
566
+        // Please notice that RATING_RAW_SCORE_META_KEY 
567
+        // is saved on a different meta to allow score sorting
568
+        // Both meta are managed as unique
569
+        // https://codex.wordpress.org/Function_Reference/update_post_meta
570
+        update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating[ 'raw_score' ] );
571
+        update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating[ 'warnings' ] );
572 572
 		
573
-		$this->log_service->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating[ 'raw_score' ]  ) );
573
+        $this->log_service->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating[ 'raw_score' ]  ) );
574 574
 		
575
-		// Finally returns the rating 
576
-		return $rating;
577
-	}
578
-	/**
579
-	 * Get or calculate rating for a given entity
580
-	 *
581
-	 * @since 3.3.0
582
-	 *
583
-	 * @param int $post_id The entity post id.
584
-	 * @param $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj.
585
-	 *
586
-	 * @return int An array representing the rating obj.
587
-	 */
588
-	public function get_rating_for( $post_id, $force_reload = false ) {
575
+        // Finally returns the rating 
576
+        return $rating;
577
+    }
578
+    /**
579
+     * Get or calculate rating for a given entity
580
+     *
581
+     * @since 3.3.0
582
+     *
583
+     * @param int $post_id The entity post id.
584
+     * @param $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj.
585
+     *
586
+     * @return int An array representing the rating obj.
587
+     */
588
+    public function get_rating_for( $post_id, $force_reload = false ) {
589 589
 		
590
-		// If forced reload is required or rating is missing ..
591
-		if ( $force_reload ) {
592
-			$this->log_service->trace( "Force rating reload [ post_id :: $post_id ]" );
593
-			return $this->set_rating_for( $post_id );
594
-		}
590
+        // If forced reload is required or rating is missing ..
591
+        if ( $force_reload ) {
592
+            $this->log_service->trace( "Force rating reload [ post_id :: $post_id ]" );
593
+            return $this->set_rating_for( $post_id );
594
+        }
595 595
 		
596
-		$current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true );  
596
+        $current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true );  
597 597
 			
598
-		if ( ! is_numeric( $current_raw_score ) ) {
599
-			$this->log_service->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" );
600
-			return $this->set_rating_for( $post_id );
601
-		}
602
-		$current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true );  
598
+        if ( ! is_numeric( $current_raw_score ) ) {
599
+            $this->log_service->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" );
600
+            return $this->set_rating_for( $post_id );
601
+        }
602
+        $current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true );  
603 603
 		
604
-		// Finally return score and warnings
605
-		return array( 
606
-			'raw_score'				=> $current_raw_score,
607
-			'traffic_light_score'	=> $this->convert_raw_score_to_traffic_light( $current_raw_score ),
608
-			'percentage_score'		=> $this->convert_raw_score_to_percentage( $current_raw_score ),
609
-			'warnings'				=> $current_warnings, 
610
-		);
611
-
612
-	}
613
-	/**
614
-	 * Calculate rating for a given entity
615
-	 * Rating depends from following criteria
616
-	 *
617
-	 * 1. Is the current entity related to at least 1 post?
618
-	 * 2. Is the current entity content post not empty?
619
-	 * 3. Is the current entity related to at least 1 entity?
620
-	 * 4. Is the entity published? 
621
-	 * 5. There is a a thumbnail associated to the entity?
622
-	 * 6. Has the entity a sameas defined?
623
-	 * 7. Are all schema.org required metadata compiled?
624
-	 *
625
-	 * Each positive check means +1 in terms of rating score
626
-	 *
627
-	 * @since 3.3.0
628
-	 *
629
-	 * @param int $post_id The entity post id.
630
-	 *
631
-	 * @return int An array representing the rating obj.
632
-	 */
633
-	public function calculate_rating_for( $post_id ) {
604
+        // Finally return score and warnings
605
+        return array( 
606
+            'raw_score'				=> $current_raw_score,
607
+            'traffic_light_score'	=> $this->convert_raw_score_to_traffic_light( $current_raw_score ),
608
+            'percentage_score'		=> $this->convert_raw_score_to_percentage( $current_raw_score ),
609
+            'warnings'				=> $current_warnings, 
610
+        );
611
+
612
+    }
613
+    /**
614
+     * Calculate rating for a given entity
615
+     * Rating depends from following criteria
616
+     *
617
+     * 1. Is the current entity related to at least 1 post?
618
+     * 2. Is the current entity content post not empty?
619
+     * 3. Is the current entity related to at least 1 entity?
620
+     * 4. Is the entity published? 
621
+     * 5. There is a a thumbnail associated to the entity?
622
+     * 6. Has the entity a sameas defined?
623
+     * 7. Are all schema.org required metadata compiled?
624
+     *
625
+     * Each positive check means +1 in terms of rating score
626
+     *
627
+     * @since 3.3.0
628
+     *
629
+     * @param int $post_id The entity post id.
630
+     *
631
+     * @return int An array representing the rating obj.
632
+     */
633
+    public function calculate_rating_for( $post_id ) {
634 634
 		
635
-		// If it's not an entity, return.
636
-		if ( ! $this->is_entity( $post_id ) ) {
637
-			return;
638
-		}
639
-		// Retrieve the post object
640
-		$post = get_post( $post_id );
641
-		// Rating value
642
-		$score = 0;
643
-		// Store warning messages
644
-		$warnings = array();
645
-
646
-		// Is the current entity related to at least 1 post?
647
-		( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ?
648
-			$score++ : 
649
-			array_push( $warnings, __( self::RATING_WARNING_HAS_RELATED_POSTS, 'wordlift' ) );
635
+        // If it's not an entity, return.
636
+        if ( ! $this->is_entity( $post_id ) ) {
637
+            return;
638
+        }
639
+        // Retrieve the post object
640
+        $post = get_post( $post_id );
641
+        // Rating value
642
+        $score = 0;
643
+        // Store warning messages
644
+        $warnings = array();
645
+
646
+        // Is the current entity related to at least 1 post?
647
+        ( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ?
648
+            $score++ : 
649
+            array_push( $warnings, __( self::RATING_WARNING_HAS_RELATED_POSTS, 'wordlift' ) );
650 650
 		
651
-		// Is the post content not empty?
652
-		( ! empty( $post->post_content ) ) ?
653
-			$score++ :
654
-			array_push( $warnings, __( self::RATING_WARNING_HAS_CONTENT_POST, 'wordlift' ) );
651
+        // Is the post content not empty?
652
+        ( ! empty( $post->post_content ) ) ?
653
+            $score++ :
654
+            array_push( $warnings, __( self::RATING_WARNING_HAS_CONTENT_POST, 'wordlift' ) );
655 655
 		
656
-		// Is the current entity related to at least 1 entity?
657
-		// Was the current entity already disambiguated?
658
-		( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ?
659
-			$score++ :
660
-			array_push( $warnings, __( self::RATING_WARNING_HAS_RELATED_ENTITIES, 'wordlift' ) );
656
+        // Is the current entity related to at least 1 entity?
657
+        // Was the current entity already disambiguated?
658
+        ( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ?
659
+            $score++ :
660
+            array_push( $warnings, __( self::RATING_WARNING_HAS_RELATED_ENTITIES, 'wordlift' ) );
661 661
 		
662
-		// Is the entity published?
663
-		( 'publish' === get_post_status( $post->ID ) ) ?
664
-			$score++ :
665
-			array_push( $warnings, __( self::RATING_WARNING_IS_PUBLISHED, 'wordlift' ) );
662
+        // Is the entity published?
663
+        ( 'publish' === get_post_status( $post->ID ) ) ?
664
+            $score++ :
665
+            array_push( $warnings, __( self::RATING_WARNING_IS_PUBLISHED, 'wordlift' ) );
666 666
 		
667
-		// Has a thumbnail?
668
-		( has_post_thumbnail( $post->ID ) ) ?
669
-			$score++ :
670
-			array_push( $warnings, __( self::RATING_WARNING_HAS_THUMBNAIL, 'wordlift' ) );
667
+        // Has a thumbnail?
668
+        ( has_post_thumbnail( $post->ID ) ) ?
669
+            $score++ :
670
+            array_push( $warnings, __( self::RATING_WARNING_HAS_THUMBNAIL, 'wordlift' ) );
671 671
 		
672
-		// Get all post meta keys for the current post		
673
-		global $wpdb;
674
-		$query = $wpdb->prepare( 
675
-			"SELECT DISTINCT(meta_key) FROM $wpdb->postmeta  WHERE post_id = %d", $post->ID 
676
-		);
672
+        // Get all post meta keys for the current post		
673
+        global $wpdb;
674
+        $query = $wpdb->prepare( 
675
+            "SELECT DISTINCT(meta_key) FROM $wpdb->postmeta  WHERE post_id = %d", $post->ID 
676
+        );
677 677
 		
678
-		// Check intersection between available meta keys 
679
-		// and expected ones arrays to detect missing values
680
-		$available_meta_keys = $wpdb->get_col( $query );
681
-
682
-		// If each expected key is contained in available keys array ...
683
-		( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ?
684
-			$score++ :
685
-			array_push( $warnings, __( self::RATING_WARNING_HAS_SAME_AS, 'wordlift' ) );
678
+        // Check intersection between available meta keys 
679
+        // and expected ones arrays to detect missing values
680
+        $available_meta_keys = $wpdb->get_col( $query );
681
+
682
+        // If each expected key is contained in available keys array ...
683
+        ( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ?
684
+            $score++ :
685
+            array_push( $warnings, __( self::RATING_WARNING_HAS_SAME_AS, 'wordlift' ) );
686 686
 		
687
-		$schema = wl_entity_type_taxonomy_get_type( $post_id );
687
+        $schema = wl_entity_type_taxonomy_get_type( $post_id );
688 688
 
689
-		$expected_meta_keys = ( null === $schema[ 'custom_fields' ] ) ? 
690
-			array() : 
691
-			array_keys( $schema[ 'custom_fields' ] );
689
+        $expected_meta_keys = ( null === $schema[ 'custom_fields' ] ) ? 
690
+            array() : 
691
+            array_keys( $schema[ 'custom_fields' ] );
692 692
 
693
-		$intersection = array_intersect( $expected_meta_keys, $available_meta_keys );
694
-		// If each expected key is contained in available keys array ...
695
-		( count( $intersection ) === count( $expected_meta_keys ) ) ?
696
-			$score++ :
697
-			array_push( $warnings, __( self::RATING_WARNING_HAS_COMPLETED_METADATA, 'wordlift' ) );
693
+        $intersection = array_intersect( $expected_meta_keys, $available_meta_keys );
694
+        // If each expected key is contained in available keys array ...
695
+        ( count( $intersection ) === count( $expected_meta_keys ) ) ?
696
+            $score++ :
697
+            array_push( $warnings, __( self::RATING_WARNING_HAS_COMPLETED_METADATA, 'wordlift' ) );
698 698
 		
699
-		// Finally return score and warnings
700
-		return array( 
701
-			'raw_score'				=> $score,
702
-			'traffic_light_score'	=> $this->convert_raw_score_to_traffic_light( $score ),
703
-			'percentage_score'		=> $this->convert_raw_score_to_percentage( $score ),
704
-			'warnings'				=> $warnings, 
705
-		);
706
-
707
-	}
708
-
709
-	/**
710
-	 * Get as rating as input and convert in a traffic-light rating
711
-	 *
712
-	 * @since 3.3.0
713
-	 *
714
-	 * @param int $score The rating score for a given entity.
715
-	 *
716
-	 * @return string The input HTML code.
717
-	 */
718
-	private function convert_raw_score_to_traffic_light( $score ) {
719
-		// RATING_MAX : $score = 3 : x 
720
-		// See http://php.net/manual/en/function.round.php
721
-		$rating = round( ( $score * 3 ) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP );
722
-		// If rating is 0, return 1, otherwise return rating
723
-		return ( 0 == $rating ) ? 1 : $rating; 
724
-
725
-	}
726
-
727
-	/**
728
-	 * Get as rating as input and convert in a traffic-light rating
729
-	 *
730
-	 * @since 3.3.0
731
-	 *
732
-	 * @param int $score The rating score for a given entity.
733
-	 *
734
-	 * @return string The input HTML code.
735
-	 */
736
-	public function convert_raw_score_to_percentage( $score ) {
737
-		// RATING_MAX : $score = 100 : x 
738
-		return round( ( $score * 100) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP );
739
-	}
740
-
741
-	/**
742
-	 * Get the alternative label input HTML code.
743
-	 *
744
-	 * @since 3.2.0
745
-	 *
746
-	 * @param string $value The input value.
747
-	 *
748
-	 * @return string The input HTML code.
749
-	 */
750
-	private function get_alternative_label_input( $value = '' ) {
751
-
752
-		return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), __( 'Delete', 'wordlift' ) );
753
-	}
699
+        // Finally return score and warnings
700
+        return array( 
701
+            'raw_score'				=> $score,
702
+            'traffic_light_score'	=> $this->convert_raw_score_to_traffic_light( $score ),
703
+            'percentage_score'		=> $this->convert_raw_score_to_percentage( $score ),
704
+            'warnings'				=> $warnings, 
705
+        );
706
+
707
+    }
708
+
709
+    /**
710
+     * Get as rating as input and convert in a traffic-light rating
711
+     *
712
+     * @since 3.3.0
713
+     *
714
+     * @param int $score The rating score for a given entity.
715
+     *
716
+     * @return string The input HTML code.
717
+     */
718
+    private function convert_raw_score_to_traffic_light( $score ) {
719
+        // RATING_MAX : $score = 3 : x 
720
+        // See http://php.net/manual/en/function.round.php
721
+        $rating = round( ( $score * 3 ) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP );
722
+        // If rating is 0, return 1, otherwise return rating
723
+        return ( 0 == $rating ) ? 1 : $rating; 
724
+
725
+    }
726
+
727
+    /**
728
+     * Get as rating as input and convert in a traffic-light rating
729
+     *
730
+     * @since 3.3.0
731
+     *
732
+     * @param int $score The rating score for a given entity.
733
+     *
734
+     * @return string The input HTML code.
735
+     */
736
+    public function convert_raw_score_to_percentage( $score ) {
737
+        // RATING_MAX : $score = 100 : x 
738
+        return round( ( $score * 100) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP );
739
+    }
740
+
741
+    /**
742
+     * Get the alternative label input HTML code.
743
+     *
744
+     * @since 3.2.0
745
+     *
746
+     * @param string $value The input value.
747
+     *
748
+     * @return string The input HTML code.
749
+     */
750
+    private function get_alternative_label_input( $value = '' ) {
751
+
752
+        return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), __( 'Delete', 'wordlift' ) );
753
+    }
754 754
 }
Please login to merge, or discard this patch.
Spacing   +112 added lines, -121 removed lines patch added patch discarded remove patch
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 	 *
156 156
 	 * @param \Wordlift_UI_Service $ui_service The UI service.
157 157
 	 */
158
-	public function __construct( $ui_service, $schema_service, $notice_service ) {
158
+	public function __construct($ui_service, $schema_service, $notice_service) {
159 159
 
160
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
160
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Entity_Service');
161 161
 
162 162
 		// Set the UI service.
163 163
 		$this->ui_service = $ui_service;
@@ -206,24 +206,24 @@  discard block
 block discarded – undo
206 206
 	public function get_all_related_to_last_50_published_posts() {
207 207
 
208 208
 		// Global timeline. Get entities from the latest posts.
209
-		$latest_posts_ids = get_posts( array(
209
+		$latest_posts_ids = get_posts(array(
210 210
 			'numberposts' => 50,
211 211
 			'fields'      => 'ids', //only get post IDs
212 212
 			'post_type'   => 'post',
213 213
 			'post_status' => 'publish'
214
-		) );
214
+		));
215 215
 
216
-		if ( empty( $latest_posts_ids ) ) {
216
+		if (empty($latest_posts_ids)) {
217 217
 			// There are no posts.
218 218
 			return array();
219 219
 		}
220 220
 
221 221
 		// Collect entities related to latest posts
222 222
 		$entity_ids = array();
223
-		foreach ( $latest_posts_ids as $id ) {
224
-			$entity_ids = array_merge( $entity_ids, wl_core_get_related_entity_ids( $id, array(
223
+		foreach ($latest_posts_ids as $id) {
224
+			$entity_ids = array_merge($entity_ids, wl_core_get_related_entity_ids($id, array(
225 225
 				'status' => 'publish'
226
-			) ) );
226
+			)));
227 227
 		}
228 228
 
229 229
 		return $entity_ids;
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
 	 *
239 239
 	 * @return bool Return true if the post is an entity otherwise false.
240 240
 	 */
241
-	public function is_entity( $post_id ) {
241
+	public function is_entity($post_id) {
242 242
 
243
-		return ( self::TYPE_NAME === get_post_type( $post_id ) );
243
+		return (self::TYPE_NAME === get_post_type($post_id));
244 244
 	}
245 245
 
246 246
 	/**
@@ -258,23 +258,22 @@  discard block
 block discarded – undo
258 258
 	 *
259 259
 	 * @return string Returns an uri.
260 260
 	 */
261
-	public function build_uri( $title, $post_type, $schema_type = NULL, $increment_digit = 0 ) {
261
+	public function build_uri($title, $post_type, $schema_type = NULL, $increment_digit = 0) {
262 262
 		
263 263
 		// Get the entity slug suffix digit
264 264
 		$suffix_digit = $increment_digit + 1;
265 265
 		// Get a sanitized uri for a given title
266
-		$entity_slug = ( 0 == $increment_digit ) ? 
267
-			wl_sanitize_uri_path( $title ) :
268
-			wl_sanitize_uri_path( $title . '_'. $suffix_digit );
266
+		$entity_slug = (0 == $increment_digit) ? 
267
+			wl_sanitize_uri_path($title) : wl_sanitize_uri_path($title.'_'.$suffix_digit);
269 268
 
270 269
 		// Compose a candidated uri
271
-		$new_entity_uri = sprintf( '%s/%s/%s', 
270
+		$new_entity_uri = sprintf('%s/%s/%s', 
272 271
 			wl_configuration_get_redlink_dataset_uri(), 
273 272
 			$post_type, 
274 273
 			$entity_slug 
275 274
 		); 
276 275
 		
277
-		$this->log_service->trace( "Going to check if uri is used [ new_entity_uri :: $new_entity_uri ] [ increment_digit :: $increment_digit ]" );
276
+		$this->log_service->trace("Going to check if uri is used [ new_entity_uri :: $new_entity_uri ] [ increment_digit :: $increment_digit ]");
278 277
 		
279 278
 		global $wpdb;
280 279
     	// Check if the candidated uri already is used
@@ -286,32 +285,32 @@  discard block
 block discarded – undo
286 285
     	);
287 286
 
288 287
     	// Perform the query
289
-		$post_id = $wpdb->get_var( $stmt ); 		
288
+		$post_id = $wpdb->get_var($stmt); 		
290 289
 			
291 290
 		// If the post does not exist, then the new uri is returned 	
292
-		if ( ! is_numeric( $post_id ) ) {
293
-			$this->log_service->trace( "Going to return uri [ new_entity_uri :: $new_entity_uri ]" );
291
+		if ( ! is_numeric($post_id)) {
292
+			$this->log_service->trace("Going to return uri [ new_entity_uri :: $new_entity_uri ]");
294 293
 			return $new_entity_uri;
295 294
 		}
296 295
 		// If schema_type is equal to schema org type of post x, then the new uri is returned 
297
-		$schema_post_type = wl_entity_type_taxonomy_get_type( $post_id );
296
+		$schema_post_type = wl_entity_type_taxonomy_get_type($post_id);
298 297
 			
299
-		if ( $schema_type === $schema_post_type[ 'css_class' ] ) {
300
-			$this->log_service->trace( "An entity with the same title and type already exists! Return uri [ new_entity_uri :: $new_entity_uri ]" );
298
+		if ($schema_type === $schema_post_type['css_class']) {
299
+			$this->log_service->trace("An entity with the same title and type already exists! Return uri [ new_entity_uri :: $new_entity_uri ]");
301 300
 			return $new_entity_uri;
302 301
 		}
303 302
 
304 303
 		// Otherwise the same function is called recorsively
305
-		return $this->build_uri( $title, $post_type, $schema_type, ++$increment_digit );
304
+		return $this->build_uri($title, $post_type, $schema_type, ++$increment_digit);
306 305
 	}
307 306
 
308
-	public function is_used( $post_id ) {
307
+	public function is_used($post_id) {
309 308
 
310
-		if ( FALSE === $this->is_entity( $post_id ) ) {
309
+		if (FALSE === $this->is_entity($post_id)) {
311 310
 			return null;
312 311
 		}
313 312
 		// Retrieve the post
314
-		$entity = get_post( $post_id ); 
313
+		$entity = get_post($post_id); 
315 314
 
316 315
 		global $wpdb;
317 316
     	// Retrieve Wordlift relation instances table name
@@ -324,9 +323,9 @@  discard block
 block discarded – undo
324 323
     	);
325 324
 		
326 325
 		// Perform the query
327
-		$relation_instances = (int) $wpdb->get_var( $stmt ); 
326
+		$relation_instances = (int) $wpdb->get_var($stmt); 
328 327
 		// If there is at least one relation instance for the current entity, then it's used
329
-		if ( 0 < $relation_instances ) {		
328
+		if (0 < $relation_instances) {		
330 329
 			return TRUE;
331 330
 		}
332 331
 
@@ -334,13 +333,13 @@  discard block
 block discarded – undo
334 333
 		$stmt = $wpdb->prepare( 
335 334
     		"SELECT COUNT(*) FROM $wpdb->postmeta WHERE post_id != %d AND meta_value = %s", 
336 335
     		$entity->ID,
337
-    		wl_get_entity_uri( $entity->ID )
336
+    		wl_get_entity_uri($entity->ID)
338 337
     	);
339 338
     	// Perform the query
340
-		$meta_instances = (int) $wpdb->get_var( $stmt ); 
339
+		$meta_instances = (int) $wpdb->get_var($stmt); 
341 340
 		
342 341
 		// If there is at least one meta that refers the current entity uri, then current entity is used
343
-		if ( 0 < $meta_instances ) {
342
+		if (0 < $meta_instances) {
344 343
 			return TRUE;
345 344
 		}
346 345
 
@@ -357,9 +356,9 @@  discard block
 block discarded – undo
357 356
 	 *
358 357
 	 * @return true if the uri internal to the current dataset otherwise false.
359 358
 	 */
360
-	public function is_internal_uri( $uri ) {
359
+	public function is_internal_uri($uri) {
361 360
 
362
-		return ( 0 === strrpos( $uri, wl_configuration_get_redlink_dataset_uri() ) );
361
+		return (0 === strrpos($uri, wl_configuration_get_redlink_dataset_uri()));
363 362
 	}
364 363
 
365 364
 	/**
@@ -371,7 +370,7 @@  discard block
 block discarded – undo
371 370
 	 *
372 371
 	 * @return WP_Post|null A WP_Post instance or null if not found.
373 372
 	 */
374
-	public function get_entity_post_by_uri( $uri ) {
373
+	public function get_entity_post_by_uri($uri) {
375 374
 
376 375
 		$query_args = array(
377 376
 			'posts_per_page'	=> 1,
@@ -389,23 +388,23 @@  discard block
 block discarded – undo
389 388
 		// Only if the current uri is not an internal uri 
390 389
 		// entity search is performed also looking at sameAs values
391 390
 		// This solve issues like https://github.com/insideout10/wordlift-plugin/issues/237
392
-		if ( !$this->is_internal_uri( $uri ) ) {
391
+		if ( ! $this->is_internal_uri($uri)) {
393 392
 		
394
-			$query_args[ 'meta_query' ][ 'relation' ] = 'OR';
395
-			$query_args[ 'meta_query' ][] = array(
393
+			$query_args['meta_query']['relation'] = 'OR';
394
+			$query_args['meta_query'][] = array(
396 395
 				'key'     => Wordlift_Schema_Service::FIELD_SAME_AS,
397 396
 				'value'   => $uri,
398 397
 				'compare' => '='
399 398
 			);
400 399
 		} 
401 400
 
402
-		$query = new WP_Query( $query_args );
401
+		$query = new WP_Query($query_args);
403 402
 
404 403
 		// Get the matching entity posts.
405 404
 		$posts = $query->get_posts();
406 405
 
407 406
 		// Return null if no post is found.
408
-		if ( 0 === count( $posts ) ) {
407
+		if (0 === count($posts)) {
409 408
 			return null;
410 409
 		}
411 410
 
@@ -422,18 +421,18 @@  discard block
 block discarded – undo
422 421
 	 * @param WP_Post $post Post object.
423 422
 	 * @param bool $update Whether this is an existing post being updated or not.
424 423
 	 */
425
-	public function save_post( $post_id, $post, $update ) {
424
+	public function save_post($post_id, $post, $update) {
426 425
 
427 426
 		// If it's not an entity, return.
428
-		if ( ! $this->is_entity( $post_id ) ) {
427
+		if ( ! $this->is_entity($post_id)) {
429 428
 			return;
430 429
 		}
431 430
 
432 431
 		// Get the alt labels from the request (or empty array).
433
-		$alt_labels = isset( $_REQUEST['wl_alternative_label'] ) ? $_REQUEST['wl_alternative_label'] : array();
432
+		$alt_labels = isset($_REQUEST['wl_alternative_label']) ? $_REQUEST['wl_alternative_label'] : array();
434 433
 
435 434
 		// Set the alternative labels.
436
-		$this->set_alternative_labels( $post_id, $alt_labels );
435
+		$this->set_alternative_labels($post_id, $alt_labels);
437 436
 
438 437
 	}
439 438
 
@@ -445,22 +444,22 @@  discard block
 block discarded – undo
445 444
 	 * @param int $post_id The post id.
446 445
 	 * @param array $alt_labels An array of labels.
447 446
 	 */
448
-	public function set_alternative_labels( $post_id, $alt_labels ) {
447
+	public function set_alternative_labels($post_id, $alt_labels) {
449 448
 		
450 449
 		// Force $alt_labels to be an array
451
-		if( !is_array( $alt_labels ) ) {
452
-			$alt_labels = array( $alt_labels );
450
+		if ( ! is_array($alt_labels)) {
451
+			$alt_labels = array($alt_labels);
453 452
 		}
454 453
 
455
-		$this->log_service->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . " ]" );
454
+		$this->log_service->debug("Setting alternative labels [ post id :: $post_id ][ alt labels :: ".implode(',', $alt_labels)." ]");
456 455
 
457 456
 		// Delete all the existing alternate labels.
458
-		delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
457
+		delete_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY);
459 458
 		
460 459
 		// Set the alternative labels.
461
-		foreach ( $alt_labels as $alt_label ) {
462
-			if ( ! empty( $alt_label ) ) {
463
-				add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, $alt_label );
460
+		foreach ($alt_labels as $alt_label) {
461
+			if ( ! empty($alt_label)) {
462
+				add_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY, $alt_label);
464 463
 			}
465 464
 		}
466 465
 
@@ -475,9 +474,9 @@  discard block
 block discarded – undo
475 474
 	 *
476 475
 	 * @return mixed An array  of alternative labels.
477 476
 	 */
478
-	public function get_alternative_labels( $post_id ) {
477
+	public function get_alternative_labels($post_id) {
479 478
 
480
-		return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
479
+		return get_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY);
481 480
 	}
482 481
 
483 482
 	/**
@@ -487,25 +486,25 @@  discard block
 block discarded – undo
487 486
 	 *
488 487
 	 * @param WP_Post $post Post object.
489 488
 	 */
490
-	public function edit_form_before_permalink( $post ) {
489
+	public function edit_form_before_permalink($post) {
491 490
 
492 491
 		// If it's not an entity, return.
493
-		if ( ! $this->is_entity( $post->ID ) ) {
492
+		if ( ! $this->is_entity($post->ID)) {
494 493
 			return;
495 494
 		}
496 495
 
497 496
 		// Print the input template.
498
-		$this->ui_service->print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
497
+		$this->ui_service->print_template('wl-tmpl-alternative-label-input', $this->get_alternative_label_input());
499 498
 
500 499
 		// Print all the currently set alternative labels.
501
-		foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
500
+		foreach ($this->get_alternative_labels($post->ID) as $alt_label) {
502 501
 
503
-			echo $this->get_alternative_label_input( $alt_label );
502
+			echo $this->get_alternative_label_input($alt_label);
504 503
 
505 504
 		};
506 505
 
507 506
 		// Print the button.
508
-		$this->ui_service->print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
507
+		$this->ui_service->print_button('wl-add-alternative-labels-button', __('Add more titles', 'wordlift'));
509 508
 
510 509
 	}
511 510
 
@@ -519,32 +518,32 @@  discard block
 block discarded – undo
519 518
 	public function in_admin_header() {
520 519
 
521 520
 		// Return safely if get_current_screen() is not defined (yet)
522
-		if ( FALSE === function_exists( 'get_current_screen' ) ) {
521
+		if (FALSE === function_exists('get_current_screen')) {
523 522
 			return;
524 523
 		}
525 524
 		
526 525
 		$screen = get_current_screen();
527 526
 		// If there is any valid screen nothing to do
528
-		if ( NULL === $screen ) {
527
+		if (NULL === $screen) {
529 528
 			return $clauses;
530 529
 		}
531 530
 
532 531
 		// If you're not in the entity post edit page, return.
533
-		if ( self::TYPE_NAME !== $screen->id ) {
532
+		if (self::TYPE_NAME !== $screen->id) {
534 533
 			return;
535 534
 		}
536 535
 		// Retrieve the current global post
537 536
 		global $post;
538 537
 		// If it's not an entity, return.
539
-		if ( ! $this->is_entity( $post->ID ) ) {
538
+		if ( ! $this->is_entity($post->ID)) {
540 539
 			return;
541 540
 		}
542 541
 		// Retrieve an updated rating for the current entity
543
-		$rating = $this->get_rating_for( $post->ID, true );
542
+		$rating = $this->get_rating_for($post->ID, true);
544 543
 		// If there is at least 1 warning
545
-		if ( isset( $rating[ 'warnings' ] ) && 0 < count( $rating[ 'warnings' ] ) ) {
544
+		if (isset($rating['warnings']) && 0 < count($rating['warnings'])) {
546 545
 			// TODO - Pass Wordlift_Notice_Service trough the service constructor 
547
-			$this->notice_service->add_suggestion( $rating[ 'warnings' ] );
546
+			$this->notice_service->add_suggestion($rating['warnings']);
548 547
 		}
549 548
 		
550 549
 	}
@@ -558,19 +557,19 @@  discard block
 block discarded – undo
558 557
 	 *
559 558
 	 * @return int An array representing the rating obj.
560 559
 	 */
561
-	public function set_rating_for( $post_id ) {
560
+	public function set_rating_for($post_id) {
562 561
 
563 562
 		// Calculate rating for the given post
564
-		$rating = $this->calculate_rating_for( $post_id );
563
+		$rating = $this->calculate_rating_for($post_id);
565 564
 		// Store the rating on db as post meta
566 565
 		// Please notice that RATING_RAW_SCORE_META_KEY 
567 566
 		// is saved on a different meta to allow score sorting
568 567
 		// Both meta are managed as unique
569 568
 		// https://codex.wordpress.org/Function_Reference/update_post_meta
570
-		update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating[ 'raw_score' ] );
571
-		update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating[ 'warnings' ] );
569
+		update_post_meta($post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score']);
570
+		update_post_meta($post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings']);
572 571
 		
573
-		$this->log_service->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating[ 'raw_score' ]  ) );
572
+		$this->log_service->trace(sprintf("Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score']));
574 573
 		
575 574
 		// Finally returns the rating 
576 575
 		return $rating;
@@ -585,27 +584,27 @@  discard block
 block discarded – undo
585 584
 	 *
586 585
 	 * @return int An array representing the rating obj.
587 586
 	 */
588
-	public function get_rating_for( $post_id, $force_reload = false ) {
587
+	public function get_rating_for($post_id, $force_reload = false) {
589 588
 		
590 589
 		// If forced reload is required or rating is missing ..
591
-		if ( $force_reload ) {
592
-			$this->log_service->trace( "Force rating reload [ post_id :: $post_id ]" );
593
-			return $this->set_rating_for( $post_id );
590
+		if ($force_reload) {
591
+			$this->log_service->trace("Force rating reload [ post_id :: $post_id ]");
592
+			return $this->set_rating_for($post_id);
594 593
 		}
595 594
 		
596
-		$current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true );  
595
+		$current_raw_score = get_post_meta($post_id, self::RATING_RAW_SCORE_META_KEY, true);  
597 596
 			
598
-		if ( ! is_numeric( $current_raw_score ) ) {
599
-			$this->log_service->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" );
600
-			return $this->set_rating_for( $post_id );
597
+		if ( ! is_numeric($current_raw_score)) {
598
+			$this->log_service->trace("Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]");
599
+			return $this->set_rating_for($post_id);
601 600
 		}
602
-		$current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true );  
601
+		$current_warnings = get_post_meta($post_id, self::RATING_WARNINGS_META_KEY, true);  
603 602
 		
604 603
 		// Finally return score and warnings
605 604
 		return array( 
606 605
 			'raw_score'				=> $current_raw_score,
607
-			'traffic_light_score'	=> $this->convert_raw_score_to_traffic_light( $current_raw_score ),
608
-			'percentage_score'		=> $this->convert_raw_score_to_percentage( $current_raw_score ),
606
+			'traffic_light_score'	=> $this->convert_raw_score_to_traffic_light($current_raw_score),
607
+			'percentage_score'		=> $this->convert_raw_score_to_percentage($current_raw_score),
609 608
 			'warnings'				=> $current_warnings, 
610 609
 		);
611 610
 
@@ -630,44 +629,39 @@  discard block
 block discarded – undo
630 629
 	 *
631 630
 	 * @return int An array representing the rating obj.
632 631
 	 */
633
-	public function calculate_rating_for( $post_id ) {
632
+	public function calculate_rating_for($post_id) {
634 633
 		
635 634
 		// If it's not an entity, return.
636
-		if ( ! $this->is_entity( $post_id ) ) {
635
+		if ( ! $this->is_entity($post_id)) {
637 636
 			return;
638 637
 		}
639 638
 		// Retrieve the post object
640
-		$post = get_post( $post_id );
639
+		$post = get_post($post_id);
641 640
 		// Rating value
642 641
 		$score = 0;
643 642
 		// Store warning messages
644 643
 		$warnings = array();
645 644
 
646 645
 		// Is the current entity related to at least 1 post?
647
-		( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ?
648
-			$score++ : 
649
-			array_push( $warnings, __( self::RATING_WARNING_HAS_RELATED_POSTS, 'wordlift' ) );
646
+		(0 < count(wl_core_get_related_post_ids($post->ID))) ?
647
+			$score++ : array_push($warnings, __(self::RATING_WARNING_HAS_RELATED_POSTS, 'wordlift'));
650 648
 		
651 649
 		// Is the post content not empty?
652
-		( ! empty( $post->post_content ) ) ?
653
-			$score++ :
654
-			array_push( $warnings, __( self::RATING_WARNING_HAS_CONTENT_POST, 'wordlift' ) );
650
+		( ! empty($post->post_content)) ?
651
+			$score++ : array_push($warnings, __(self::RATING_WARNING_HAS_CONTENT_POST, 'wordlift'));
655 652
 		
656 653
 		// Is the current entity related to at least 1 entity?
657 654
 		// Was the current entity already disambiguated?
658
-		( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ?
659
-			$score++ :
660
-			array_push( $warnings, __( self::RATING_WARNING_HAS_RELATED_ENTITIES, 'wordlift' ) );
655
+		(0 < count(wl_core_get_related_entity_ids($post->ID))) ?
656
+			$score++ : array_push($warnings, __(self::RATING_WARNING_HAS_RELATED_ENTITIES, 'wordlift'));
661 657
 		
662 658
 		// Is the entity published?
663
-		( 'publish' === get_post_status( $post->ID ) ) ?
664
-			$score++ :
665
-			array_push( $warnings, __( self::RATING_WARNING_IS_PUBLISHED, 'wordlift' ) );
659
+		('publish' === get_post_status($post->ID)) ?
660
+			$score++ : array_push($warnings, __(self::RATING_WARNING_IS_PUBLISHED, 'wordlift'));
666 661
 		
667 662
 		// Has a thumbnail?
668
-		( has_post_thumbnail( $post->ID ) ) ?
669
-			$score++ :
670
-			array_push( $warnings, __( self::RATING_WARNING_HAS_THUMBNAIL, 'wordlift' ) );
663
+		(has_post_thumbnail($post->ID)) ?
664
+			$score++ : array_push($warnings, __(self::RATING_WARNING_HAS_THUMBNAIL, 'wordlift'));
671 665
 		
672 666
 		// Get all post meta keys for the current post		
673 667
 		global $wpdb;
@@ -677,30 +671,27 @@  discard block
 block discarded – undo
677 671
 		
678 672
 		// Check intersection between available meta keys 
679 673
 		// and expected ones arrays to detect missing values
680
-		$available_meta_keys = $wpdb->get_col( $query );
674
+		$available_meta_keys = $wpdb->get_col($query);
681 675
 
682 676
 		// If each expected key is contained in available keys array ...
683
-		( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ?
684
-			$score++ :
685
-			array_push( $warnings, __( self::RATING_WARNING_HAS_SAME_AS, 'wordlift' ) );
677
+		(in_array(Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys)) ?
678
+			$score++ : array_push($warnings, __(self::RATING_WARNING_HAS_SAME_AS, 'wordlift'));
686 679
 		
687
-		$schema = wl_entity_type_taxonomy_get_type( $post_id );
680
+		$schema = wl_entity_type_taxonomy_get_type($post_id);
688 681
 
689
-		$expected_meta_keys = ( null === $schema[ 'custom_fields' ] ) ? 
690
-			array() : 
691
-			array_keys( $schema[ 'custom_fields' ] );
682
+		$expected_meta_keys = (null === $schema['custom_fields']) ? 
683
+			array() : array_keys($schema['custom_fields']);
692 684
 
693
-		$intersection = array_intersect( $expected_meta_keys, $available_meta_keys );
685
+		$intersection = array_intersect($expected_meta_keys, $available_meta_keys);
694 686
 		// If each expected key is contained in available keys array ...
695
-		( count( $intersection ) === count( $expected_meta_keys ) ) ?
696
-			$score++ :
697
-			array_push( $warnings, __( self::RATING_WARNING_HAS_COMPLETED_METADATA, 'wordlift' ) );
687
+		(count($intersection) === count($expected_meta_keys)) ?
688
+			$score++ : array_push($warnings, __(self::RATING_WARNING_HAS_COMPLETED_METADATA, 'wordlift'));
698 689
 		
699 690
 		// Finally return score and warnings
700 691
 		return array( 
701 692
 			'raw_score'				=> $score,
702
-			'traffic_light_score'	=> $this->convert_raw_score_to_traffic_light( $score ),
703
-			'percentage_score'		=> $this->convert_raw_score_to_percentage( $score ),
693
+			'traffic_light_score'	=> $this->convert_raw_score_to_traffic_light($score),
694
+			'percentage_score'		=> $this->convert_raw_score_to_percentage($score),
704 695
 			'warnings'				=> $warnings, 
705 696
 		);
706 697
 
@@ -715,12 +706,12 @@  discard block
 block discarded – undo
715 706
 	 *
716 707
 	 * @return string The input HTML code.
717 708
 	 */
718
-	private function convert_raw_score_to_traffic_light( $score ) {
709
+	private function convert_raw_score_to_traffic_light($score) {
719 710
 		// RATING_MAX : $score = 3 : x 
720 711
 		// See http://php.net/manual/en/function.round.php
721
-		$rating = round( ( $score * 3 ) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP );
712
+		$rating = round(($score * 3) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP);
722 713
 		// If rating is 0, return 1, otherwise return rating
723
-		return ( 0 == $rating ) ? 1 : $rating; 
714
+		return (0 == $rating) ? 1 : $rating; 
724 715
 
725 716
 	}
726 717
 
@@ -733,9 +724,9 @@  discard block
 block discarded – undo
733 724
 	 *
734 725
 	 * @return string The input HTML code.
735 726
 	 */
736
-	public function convert_raw_score_to_percentage( $score ) {
727
+	public function convert_raw_score_to_percentage($score) {
737 728
 		// RATING_MAX : $score = 100 : x 
738
-		return round( ( $score * 100) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP );
729
+		return round(($score * 100) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP);
739 730
 	}
740 731
 
741 732
 	/**
@@ -747,8 +738,8 @@  discard block
 block discarded – undo
747 738
 	 *
748 739
 	 * @return string The input HTML code.
749 740
 	 */
750
-	private function get_alternative_label_input( $value = '' ) {
741
+	private function get_alternative_label_input($value = '') {
751 742
 
752
-		return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), __( 'Delete', 'wordlift' ) );
743
+		return sprintf(self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr($value), __('Delete', 'wordlift'));
753 744
 	}
754 745
 }
Please login to merge, or discard this patch.
src/shortcodes/wordlift_shortcode_faceted_search.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  */
6 6
 function wl_shortcode_faceted_search( $atts ) {
7 7
 
8
-	// Extract attributes and set default values.
8
+    // Extract attributes and set default values.
9 9
     $shortcode_atts = shortcode_atts( array(
10 10
         'title'			=>	__( 'Related articles', 'wordlift' ),
11 11
         'show_facets'	=> true
@@ -13,42 +13,42 @@  discard block
 block discarded – undo
13 13
 
14 14
     // See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode
15 15
     $shortcode_atts[ 'show_facets' ] = filter_var( 
16
-    	$shortcode_atts[ 'show_facets' ], FILTER_VALIDATE_BOOLEAN 
16
+        $shortcode_atts[ 'show_facets' ], FILTER_VALIDATE_BOOLEAN 
17 17
     );
18 18
 
19
-	// If the current post is not an entity and has no related entities
20
-	// than the shortcode cannot be rendered
21
-	// TODO Add an alert visibile only for connected admin users
22
-	$current_post = get_post();
23
-
24
-	$entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ?
25
-		$current_post->ID : 
26
-		wl_core_get_related_entity_ids( $current_post->ID );
27
-
28
-	if ( 0 === count( $entity_ids ) ) {
29
-		return '';
30
-	}
31
-
32
-	$div_id = 'wordlift-faceted-entity-search-widget';
33
-
34
-	wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css' );
35
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
36
-	wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' );
37
-
38
-	wp_localize_script( 
39
-		'wordlift-faceted-search', 
40
-		'wl_faceted_search_params', array(
41
-			'ajax_url'				=> admin_url( 'admin-ajax.php' ),
42
-			'action'				=> 'wl_faceted_search',
43
-			'post_id'				=> $current_post->ID,
44
-			'entity_ids'			=> $entity_ids,
45
-			'div_id'				=> $div_id,
46
-			'defaultThumbnailPath'	=> WL_DEFAULT_THUMBNAIL_PATH,
47
-			'attrs'					=> $shortcode_atts
48
-		)
49
-	);
50
-
51
-	return '<div id="' . $div_id . '" style="width:100%"></div>';
19
+    // If the current post is not an entity and has no related entities
20
+    // than the shortcode cannot be rendered
21
+    // TODO Add an alert visibile only for connected admin users
22
+    $current_post = get_post();
23
+
24
+    $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ?
25
+        $current_post->ID : 
26
+        wl_core_get_related_entity_ids( $current_post->ID );
27
+
28
+    if ( 0 === count( $entity_ids ) ) {
29
+        return '';
30
+    }
31
+
32
+    $div_id = 'wordlift-faceted-entity-search-widget';
33
+
34
+    wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css' );
35
+    wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
36
+    wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' );
37
+
38
+    wp_localize_script( 
39
+        'wordlift-faceted-search', 
40
+        'wl_faceted_search_params', array(
41
+            'ajax_url'				=> admin_url( 'admin-ajax.php' ),
42
+            'action'				=> 'wl_faceted_search',
43
+            'post_id'				=> $current_post->ID,
44
+            'entity_ids'			=> $entity_ids,
45
+            'div_id'				=> $div_id,
46
+            'defaultThumbnailPath'	=> WL_DEFAULT_THUMBNAIL_PATH,
47
+            'attrs'					=> $shortcode_atts
48
+        )
49
+    );
50
+
51
+    return '<div id="' . $div_id . '" style="width:100%"></div>';
52 52
 }
53 53
 
54 54
 add_shortcode( 'wl_faceted_search', 'wl_shortcode_faceted_search' );
@@ -59,122 +59,122 @@  discard block
 block discarded – undo
59 59
  */
60 60
 function wl_shortcode_faceted_search_ajax( $http_raw_data = null ) {
61 61
 	
62
-	// Post ID must be defined
63
-	if ( ! isset( $_GET[ 'post_id' ] ) ) {
64
-		wp_die( 'No post_id given' );
65
-		return;
66
-	}
67
-
68
-	// Extract filtering conditions
69
-	$filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data;
70
-	$filtering_entity_uris = json_decode( $filtering_entity_uris );
71
-
72
-	$current_post_id = $_GET[ 'post_id' ];
73
-	$current_post = get_post( $current_post_id );	
62
+    // Post ID must be defined
63
+    if ( ! isset( $_GET[ 'post_id' ] ) ) {
64
+        wp_die( 'No post_id given' );
65
+        return;
66
+    }
67
+
68
+    // Extract filtering conditions
69
+    $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data;
70
+    $filtering_entity_uris = json_decode( $filtering_entity_uris );
71
+
72
+    $current_post_id = $_GET[ 'post_id' ];
73
+    $current_post = get_post( $current_post_id );	
74 74
 	
75
-	// Post ID has to match an existing item
76
-	if ( null === $current_post ) {
77
-		wp_die( 'No valid post_id given' );
78
-		return;
79
-	}
80
-
81
-	// If the current post is an entity, 
82
-	// the current post is used as main entity.
83
-	// Otherwise, current post related entities are used. 
84
-	$entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ?
85
-		array( $current_post->ID ) :
86
-		wl_core_get_related_entity_ids( $current_post->ID );
87
-
88
-	// If there are no entities we cannot render the widget
89
-	if ( 0 === count( $entity_ids ) ) {
90
-		wp_die( 'No entities available' );
91
-		return;
92
-	}
93
-
94
-	// Retrieve requested type
95
-	$required_type = ( isset( $_GET[ 'type' ] ) ) ? $_GET[ 'type' ] : null;  
96
-
97
-	// Set up data structures            
98
-	$referencing_posts = wl_core_get_posts( array(
99
-		'get'				=> 'posts',
100
-		'post__not_in'      =>  array( $current_post_id ), 
101
-		'related_to__in'	=> $entity_ids,
102
-		'post_type'			=> 'post',
103
-		'as'				=> 'subject',
104
-		'post_status'		=> 'publish',
105
-	) );
106
-
107
-	$referencing_post_ids = array_map( function( $p ) { return $p->ID; }, $referencing_posts );
108
-
109
-	$results              = array();
110
-
111
-	if ( 'posts' === $required_type ) {
75
+    // Post ID has to match an existing item
76
+    if ( null === $current_post ) {
77
+        wp_die( 'No valid post_id given' );
78
+        return;
79
+    }
80
+
81
+    // If the current post is an entity, 
82
+    // the current post is used as main entity.
83
+    // Otherwise, current post related entities are used. 
84
+    $entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ?
85
+        array( $current_post->ID ) :
86
+        wl_core_get_related_entity_ids( $current_post->ID );
87
+
88
+    // If there are no entities we cannot render the widget
89
+    if ( 0 === count( $entity_ids ) ) {
90
+        wp_die( 'No entities available' );
91
+        return;
92
+    }
93
+
94
+    // Retrieve requested type
95
+    $required_type = ( isset( $_GET[ 'type' ] ) ) ? $_GET[ 'type' ] : null;  
96
+
97
+    // Set up data structures            
98
+    $referencing_posts = wl_core_get_posts( array(
99
+        'get'				=> 'posts',
100
+        'post__not_in'      =>  array( $current_post_id ), 
101
+        'related_to__in'	=> $entity_ids,
102
+        'post_type'			=> 'post',
103
+        'as'				=> 'subject',
104
+        'post_status'		=> 'publish',
105
+    ) );
106
+
107
+    $referencing_post_ids = array_map( function( $p ) { return $p->ID; }, $referencing_posts );
108
+
109
+    $results              = array();
110
+
111
+    if ( 'posts' === $required_type ) {
112 112
 		
113
-		// Required filtered posts.
114
-		wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" );
113
+        // Required filtered posts.
114
+        wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" );
115 115
 
116
-		$filtered_posts = ( empty( $filtering_entity_uris ) ) ?
117
-			$referencing_posts : 
118
-			wl_core_get_posts( array(
119
-				'get'            => 'posts',
120
-				'post__in'       => $referencing_post_ids,
121
-				'related_to__in' => wl_get_entity_post_ids_by_uris( $filtering_entity_uris ),
122
-				'post_type'      => 'post',
123
-				'as'             => 'subject',
124
-			) );
116
+        $filtered_posts = ( empty( $filtering_entity_uris ) ) ?
117
+            $referencing_posts : 
118
+            wl_core_get_posts( array(
119
+                'get'            => 'posts',
120
+                'post__in'       => $referencing_post_ids,
121
+                'related_to__in' => wl_get_entity_post_ids_by_uris( $filtering_entity_uris ),
122
+                'post_type'      => 'post',
123
+                'as'             => 'subject',
124
+            ) );
125 125
 
126
-		foreach ( $filtered_posts as $post_obj ) {
126
+        foreach ( $filtered_posts as $post_obj ) {
127 127
 
128
-			$thumbnail           = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) );
129
-			$post_obj->thumbnail = ( $thumbnail ) ?
130
-			$thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
131
-			$post_obj->permalink = get_post_permalink( $post_obj->ID );
128
+            $thumbnail           = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) );
129
+            $post_obj->thumbnail = ( $thumbnail ) ?
130
+            $thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
131
+            $post_obj->permalink = get_post_permalink( $post_obj->ID );
132 132
 
133
-			$results[] = $post_obj;
133
+            $results[] = $post_obj;
134 134
 
135
-		}
135
+        }
136 136
 
137
-	} else {
137
+    } else {
138 138
 
139
-		global $wpdb;
139
+        global $wpdb;
140 140
 
141
-		wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" );
141
+        wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" );
142 142
 
143
-		// Retrieve Wordlift relation instances table name
144
-		$table_name = wl_core_get_relation_instances_table_name();
143
+        // Retrieve Wordlift relation instances table name
144
+        $table_name = wl_core_get_relation_instances_table_name();
145 145
 
146
-		$subject_ids = implode( ',', $referencing_post_ids );
146
+        $subject_ids = implode( ',', $referencing_post_ids );
147 147
 		
148
-		// TODO - if an entity is related with different predicates each predicate impacts on counter
149
-		$query = <<<EOF
148
+        // TODO - if an entity is related with different predicates each predicate impacts on counter
149
+        $query = <<<EOF
150 150
             SELECT object_id as ID, count( object_id ) as counter 
151 151
             FROM $table_name 
152 152
             WHERE subject_id IN ($subject_ids) and object_id != ($current_post_id)
153 153
             GROUP BY object_id;
154 154
 EOF;
155
-		wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" );
155
+        wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" );
156 156
 
157
-		$entities = $wpdb->get_results( $query, OBJECT );
157
+        $entities = $wpdb->get_results( $query, OBJECT );
158 158
 
159
-		wl_write_log( "Entities found " . count( $entities ) );
159
+        wl_write_log( "Entities found " . count( $entities ) );
160 160
 
161
-		foreach ( $entities as $obj ) {
161
+        foreach ( $entities as $obj ) {
162 162
 
163
-			$entity 		   = get_post( $obj->ID );
164
-			$created_at 	   = $entity->post_date;
163
+            $entity 		   = get_post( $obj->ID );
164
+            $created_at 	   = $entity->post_date;
165 165
 			
166
-			$entity            = wl_serialize_entity( $entity );
166
+            $entity            = wl_serialize_entity( $entity );
167 167
 
168
-			$entity[ 'counter' ] = $obj->counter;
169
-			$entity[ 'createdAt' ] = $created_at;
168
+            $entity[ 'counter' ] = $obj->counter;
169
+            $entity[ 'createdAt' ] = $created_at;
170 170
 			
171
-			$results[]         = $entity;
171
+            $results[]         = $entity;
172 172
 
173
-		}
173
+        }
174 174
 
175
-	}
175
+    }
176 176
 
177
-	wl_core_send_json( $results );
177
+    wl_core_send_json( $results );
178 178
 
179 179
 }
180 180
 
Please login to merge, or discard this patch.
Spacing   +58 added lines, -61 removed lines patch added patch discarded remove patch
@@ -3,17 +3,17 @@  discard block
 block discarded – undo
3 3
 /*
4 4
  * Function in charge of diplaying the [wl-faceted-search]
5 5
  */
6
-function wl_shortcode_faceted_search( $atts ) {
6
+function wl_shortcode_faceted_search($atts) {
7 7
 
8 8
 	// Extract attributes and set default values.
9
-    $shortcode_atts = shortcode_atts( array(
10
-        'title'			=>	__( 'Related articles', 'wordlift' ),
9
+    $shortcode_atts = shortcode_atts(array(
10
+        'title'			=>	__('Related articles', 'wordlift'),
11 11
         'show_facets'	=> true
12
-    ), $atts );
12
+    ), $atts);
13 13
 
14 14
     // See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode
15
-    $shortcode_atts[ 'show_facets' ] = filter_var( 
16
-    	$shortcode_atts[ 'show_facets' ], FILTER_VALIDATE_BOOLEAN 
15
+    $shortcode_atts['show_facets'] = filter_var( 
16
+    	$shortcode_atts['show_facets'], FILTER_VALIDATE_BOOLEAN 
17 17
     );
18 18
 
19 19
 	// If the current post is not an entity and has no related entities
@@ -21,24 +21,23 @@  discard block
 block discarded – undo
21 21
 	// TODO Add an alert visibile only for connected admin users
22 22
 	$current_post = get_post();
23 23
 
24
-	$entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ?
25
-		$current_post->ID : 
26
-		wl_core_get_related_entity_ids( $current_post->ID );
24
+	$entity_ids = (Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type) ?
25
+		$current_post->ID : wl_core_get_related_entity_ids($current_post->ID);
27 26
 
28
-	if ( 0 === count( $entity_ids ) ) {
27
+	if (0 === count($entity_ids)) {
29 28
 		return '';
30 29
 	}
31 30
 
32 31
 	$div_id = 'wordlift-faceted-entity-search-widget';
33 32
 
34
-	wp_enqueue_style( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-faceted-entity-search-widget.min.css' );
35
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
36
-	wp_enqueue_script( 'wordlift-faceted-search', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-faceted-entity-search-widget.min.js' );
33
+	wp_enqueue_style('wordlift-faceted-search', dirname(plugin_dir_url(__FILE__)).'/css/wordlift-faceted-entity-search-widget.min.css');
34
+	wp_enqueue_script('angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js');
35
+	wp_enqueue_script('wordlift-faceted-search', dirname(plugin_dir_url(__FILE__)).'/js/wordlift-faceted-entity-search-widget.min.js');
37 36
 
38 37
 	wp_localize_script( 
39 38
 		'wordlift-faceted-search', 
40 39
 		'wl_faceted_search_params', array(
41
-			'ajax_url'				=> admin_url( 'admin-ajax.php' ),
40
+			'ajax_url'				=> admin_url('admin-ajax.php'),
42 41
 			'action'				=> 'wl_faceted_search',
43 42
 			'post_id'				=> $current_post->ID,
44 43
 			'entity_ids'			=> $entity_ids,
@@ -48,87 +47,85 @@  discard block
 block discarded – undo
48 47
 		)
49 48
 	);
50 49
 
51
-	return '<div id="' . $div_id . '" style="width:100%"></div>';
50
+	return '<div id="'.$div_id.'" style="width:100%"></div>';
52 51
 }
53 52
 
54
-add_shortcode( 'wl_faceted_search', 'wl_shortcode_faceted_search' );
53
+add_shortcode('wl_faceted_search', 'wl_shortcode_faceted_search');
55 54
 
56 55
 
57 56
 /*
58 57
  * Ajax call for the faceted search widget
59 58
  */
60
-function wl_shortcode_faceted_search_ajax( $http_raw_data = null ) {
59
+function wl_shortcode_faceted_search_ajax($http_raw_data = null) {
61 60
 	
62 61
 	// Post ID must be defined
63
-	if ( ! isset( $_GET[ 'post_id' ] ) ) {
64
-		wp_die( 'No post_id given' );
62
+	if ( ! isset($_GET['post_id'])) {
63
+		wp_die('No post_id given');
65 64
 		return;
66 65
 	}
67 66
 
68 67
 	// Extract filtering conditions
69
-	$filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents( "php://input" ) : $http_raw_data;
70
-	$filtering_entity_uris = json_decode( $filtering_entity_uris );
68
+	$filtering_entity_uris = (null == $http_raw_data) ? file_get_contents("php://input") : $http_raw_data;
69
+	$filtering_entity_uris = json_decode($filtering_entity_uris);
71 70
 
72
-	$current_post_id = $_GET[ 'post_id' ];
73
-	$current_post = get_post( $current_post_id );	
71
+	$current_post_id = $_GET['post_id'];
72
+	$current_post = get_post($current_post_id);	
74 73
 	
75 74
 	// Post ID has to match an existing item
76
-	if ( null === $current_post ) {
77
-		wp_die( 'No valid post_id given' );
75
+	if (null === $current_post) {
76
+		wp_die('No valid post_id given');
78 77
 		return;
79 78
 	}
80 79
 
81 80
 	// If the current post is an entity, 
82 81
 	// the current post is used as main entity.
83 82
 	// Otherwise, current post related entities are used. 
84
-	$entity_ids = ( Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type ) ?
85
-		array( $current_post->ID ) :
86
-		wl_core_get_related_entity_ids( $current_post->ID );
83
+	$entity_ids = (Wordlift_Entity_Service::TYPE_NAME === $current_post->post_type) ?
84
+		array($current_post->ID) : wl_core_get_related_entity_ids($current_post->ID);
87 85
 
88 86
 	// If there are no entities we cannot render the widget
89
-	if ( 0 === count( $entity_ids ) ) {
90
-		wp_die( 'No entities available' );
87
+	if (0 === count($entity_ids)) {
88
+		wp_die('No entities available');
91 89
 		return;
92 90
 	}
93 91
 
94 92
 	// Retrieve requested type
95
-	$required_type = ( isset( $_GET[ 'type' ] ) ) ? $_GET[ 'type' ] : null;  
93
+	$required_type = (isset($_GET['type'])) ? $_GET['type'] : null;  
96 94
 
97 95
 	// Set up data structures            
98
-	$referencing_posts = wl_core_get_posts( array(
96
+	$referencing_posts = wl_core_get_posts(array(
99 97
 		'get'				=> 'posts',
100
-		'post__not_in'      =>  array( $current_post_id ), 
98
+		'post__not_in'      =>  array($current_post_id), 
101 99
 		'related_to__in'	=> $entity_ids,
102 100
 		'post_type'			=> 'post',
103 101
 		'as'				=> 'subject',
104 102
 		'post_status'		=> 'publish',
105
-	) );
103
+	));
106 104
 
107
-	$referencing_post_ids = array_map( function( $p ) { return $p->ID; }, $referencing_posts );
105
+	$referencing_post_ids = array_map(function($p) { return $p->ID; }, $referencing_posts);
108 106
 
109 107
 	$results              = array();
110 108
 
111
-	if ( 'posts' === $required_type ) {
109
+	if ('posts' === $required_type) {
112 110
 		
113 111
 		// Required filtered posts.
114
-		wl_write_log( "Going to find related posts for the current post [ post ID :: $current_post_id ]" );
112
+		wl_write_log("Going to find related posts for the current post [ post ID :: $current_post_id ]");
115 113
 
116
-		$filtered_posts = ( empty( $filtering_entity_uris ) ) ?
117
-			$referencing_posts : 
118
-			wl_core_get_posts( array(
114
+		$filtered_posts = (empty($filtering_entity_uris)) ?
115
+			$referencing_posts : wl_core_get_posts(array(
119 116
 				'get'            => 'posts',
120 117
 				'post__in'       => $referencing_post_ids,
121
-				'related_to__in' => wl_get_entity_post_ids_by_uris( $filtering_entity_uris ),
118
+				'related_to__in' => wl_get_entity_post_ids_by_uris($filtering_entity_uris),
122 119
 				'post_type'      => 'post',
123 120
 				'as'             => 'subject',
124
-			) );
121
+			));
125 122
 
126
-		foreach ( $filtered_posts as $post_obj ) {
123
+		foreach ($filtered_posts as $post_obj) {
127 124
 
128
-			$thumbnail           = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) );
129
-			$post_obj->thumbnail = ( $thumbnail ) ?
125
+			$thumbnail           = wp_get_attachment_url(get_post_thumbnail_id($post_obj->ID, 'thumbnail'));
126
+			$post_obj->thumbnail = ($thumbnail) ?
130 127
 			$thumbnail : WL_DEFAULT_THUMBNAIL_PATH;
131
-			$post_obj->permalink = get_post_permalink( $post_obj->ID );
128
+			$post_obj->permalink = get_post_permalink($post_obj->ID);
132 129
 
133 130
 			$results[] = $post_obj;
134 131
 
@@ -138,12 +135,12 @@  discard block
 block discarded – undo
138 135
 
139 136
 		global $wpdb;
140 137
 
141
-		wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ]" );
138
+		wl_write_log("Going to find related entities for the current post [ post ID :: $current_post_id ]");
142 139
 
143 140
 		// Retrieve Wordlift relation instances table name
144 141
 		$table_name = wl_core_get_relation_instances_table_name();
145 142
 
146
-		$subject_ids = implode( ',', $referencing_post_ids );
143
+		$subject_ids = implode(',', $referencing_post_ids);
147 144
 		
148 145
 		// TODO - if an entity is related with different predicates each predicate impacts on counter
149 146
 		$query = <<<EOF
@@ -152,32 +149,32 @@  discard block
 block discarded – undo
152 149
             WHERE subject_id IN ($subject_ids) and object_id != ($current_post_id)
153 150
             GROUP BY object_id;
154 151
 EOF;
155
-		wl_write_log( "Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]" );
152
+		wl_write_log("Going to find related entities for the current post [ post ID :: $current_post_id ] [ query :: $query ]");
156 153
 
157
-		$entities = $wpdb->get_results( $query, OBJECT );
154
+		$entities = $wpdb->get_results($query, OBJECT);
158 155
 
159
-		wl_write_log( "Entities found " . count( $entities ) );
156
+		wl_write_log("Entities found ".count($entities));
160 157
 
161
-		foreach ( $entities as $obj ) {
158
+		foreach ($entities as $obj) {
162 159
 
163
-			$entity 		   = get_post( $obj->ID );
164
-			$created_at 	   = $entity->post_date;
160
+			$entity = get_post($obj->ID);
161
+			$created_at = $entity->post_date;
165 162
 			
166
-			$entity            = wl_serialize_entity( $entity );
163
+			$entity = wl_serialize_entity($entity);
167 164
 
168
-			$entity[ 'counter' ] = $obj->counter;
169
-			$entity[ 'createdAt' ] = $created_at;
165
+			$entity['counter'] = $obj->counter;
166
+			$entity['createdAt'] = $created_at;
170 167
 			
171
-			$results[]         = $entity;
168
+			$results[] = $entity;
172 169
 
173 170
 		}
174 171
 
175 172
 	}
176 173
 
177
-	wl_core_send_json( $results );
174
+	wl_core_send_json($results);
178 175
 
179 176
 }
180 177
 
181
-add_action( 'wp_ajax_wl_faceted_search', 'wl_shortcode_faceted_search_ajax' );
182
-add_action( 'wp_ajax_nopriv_wl_faceted_search', 'wl_shortcode_faceted_search_ajax' );
178
+add_action('wp_ajax_wl_faceted_search', 'wl_shortcode_faceted_search_ajax');
179
+add_action('wp_ajax_nopriv_wl_faceted_search', 'wl_shortcode_faceted_search_ajax');
183 180
 
Please login to merge, or discard this patch.
src/wordlift.php 2 patches
Indentation   +232 added lines, -232 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.
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
  */
48 48
 function wl_write_log( $log ) {
49 49
 
50
-	$handler = apply_filters( 'wl_write_log_handler', null );
50
+    $handler = apply_filters( 'wl_write_log_handler', null );
51 51
 
52
-	$callers         = debug_backtrace();
53
-	$caller_function = $callers[1]['function'];
52
+    $callers         = debug_backtrace();
53
+    $caller_function = $callers[1]['function'];
54 54
 
55
-	if ( is_null( $handler ) ) {
56
-		wl_write_log_handler( $log, $caller_function );
55
+    if ( is_null( $handler ) ) {
56
+        wl_write_log_handler( $log, $caller_function );
57 57
 
58
-		return;
59
-	}
58
+        return;
59
+    }
60 60
 
61
-	call_user_func( $handler, $log, $caller_function );
61
+    call_user_func( $handler, $log, $caller_function );
62 62
 }
63 63
 
64 64
 /**
@@ -71,20 +71,20 @@  discard block
 block discarded – undo
71 71
  */
72 72
 function wl_write_log_handler( $log, $caller = null ) {
73 73
 
74
-	global $wl_logger;
74
+    global $wl_logger;
75 75
 
76
-	if ( true === WP_DEBUG ) {
76
+    if ( true === WP_DEBUG ) {
77 77
 
78
-		$message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
79
-		           ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
78
+        $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
79
+                    ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
80 80
 
81
-		if ( isset( $wl_logger ) ) {
82
-			$wl_logger->info( $message );
83
-		} else {
84
-			error_log( $message );
85
-		}
81
+        if ( isset( $wl_logger ) ) {
82
+            $wl_logger->info( $message );
83
+        } else {
84
+            error_log( $message );
85
+        }
86 86
 
87
-	}
87
+    }
88 88
 
89 89
 }
90 90
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
  */
100 100
 function wl_write_log_hide_key( $text ) {
101 101
 
102
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
102
+    return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
103 103
 }
104 104
 
105 105
 /**
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
  */
112 112
 function wl_queue_sparql_update_query( $query ) {
113 113
 
114
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
115
-	file_put_contents( $filename, $query . "\n", FILE_APPEND );
114
+    $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
115
+    file_put_contents( $filename, $query . "\n", FILE_APPEND );
116 116
 
117
-	wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" );
117
+    wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" );
118 118
 }
119 119
 
120 120
 /**
@@ -124,28 +124,28 @@  discard block
 block discarded – undo
124 124
  */
125 125
 function wl_execute_saved_sparql_update_query( $request_id ) {
126 126
 
127
-	$filename = WL_TEMP_DIR . $request_id . '.sparql';
127
+    $filename = WL_TEMP_DIR . $request_id . '.sparql';
128 128
 
129
-	// If the file doesn't exist, exit.
130
-	if ( ! file_exists( $filename ) ) {
131
-		wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" );
129
+    // If the file doesn't exist, exit.
130
+    if ( ! file_exists( $filename ) ) {
131
+        wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" );
132 132
 
133
-		return;
134
-	}
133
+        return;
134
+    }
135 135
 
136
-	wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" );
136
+    wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" );
137 137
 
138
-	// Get the query saved in the file.
139
-	$query = file_get_contents( $filename );
138
+    // Get the query saved in the file.
139
+    $query = file_get_contents( $filename );
140 140
 
141
-	// Execute the SPARQL query.
142
-	rl_execute_sparql_update_query( $query, false );
141
+    // Execute the SPARQL query.
142
+    rl_execute_sparql_update_query( $query, false );
143 143
 
144
-	// Reindex the triple store.
145
-	wordlift_reindex_triple_store();
144
+    // Reindex the triple store.
145
+    wordlift_reindex_triple_store();
146 146
 
147
-	// Delete the temporary file.
148
-	unlink( $filename );
147
+    // Delete the temporary file.
148
+    unlink( $filename );
149 149
 }
150 150
 
151 151
 add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 );
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
  */
156 156
 function wordlift_buttonhooks() {
157 157
 
158
-	// Only add hooks when the current user has permissions AND is in Rich Text editor mode
159
-	if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
160
-		add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' );
161
-	}
158
+    // Only add hooks when the current user has permissions AND is in Rich Text editor mode
159
+    if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
160
+        add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' );
161
+    }
162 162
 }
163 163
 
164 164
 /**
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
  */
171 171
 function wordlift_register_tinymce_javascript( $plugin_array ) {
172 172
 
173
-	// add the wordlift plugin.
174
-	$plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
173
+    // add the wordlift plugin.
174
+    $plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
175 175
 
176
-	return $plugin_array;
176
+    return $plugin_array;
177 177
 }
178 178
 
179 179
 /**
@@ -181,21 +181,21 @@  discard block
 block discarded – undo
181 181
  * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
182 182
  */
183 183
 function wordlift_allowed_post_tags() {
184
-	global $allowedposttags;
185
-
186
-	$tags           = array( 'span' );
187
-	$new_attributes = array(
188
-		'itemscope' => array(),
189
-		'itemtype'  => array(),
190
-		'itemprop'  => array(),
191
-		'itemid'    => array()
192
-	);
193
-
194
-	foreach ( $tags as $tag ) {
195
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
196
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
197
-		}
198
-	}
184
+    global $allowedposttags;
185
+
186
+    $tags           = array( 'span' );
187
+    $new_attributes = array(
188
+        'itemscope' => array(),
189
+        'itemtype'  => array(),
190
+        'itemprop'  => array(),
191
+        'itemid'    => array()
192
+    );
193
+
194
+    foreach ( $tags as $tag ) {
195
+        if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
196
+            $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
197
+        }
198
+    }
199 199
 }
200 200
 
201 201
 // init process for button control
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
  */
210 210
 function wordlift_admin_enqueue_scripts() {
211 211
 
212
-	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
213
-	wp_enqueue_script( 'wpdialogs' );
214
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
212
+    // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
213
+    wp_enqueue_script( 'wpdialogs' );
214
+    wp_enqueue_style( 'wp-jquery-ui-dialog' );
215 215
 
216
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
216
+    wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
217 217
 
218
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
219
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
218
+    wp_enqueue_script( 'jquery-ui-autocomplete' );
219
+    wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
220 220
 
221
-	// Disable auto-save for custom entity posts only
222
-	if( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ){
223
-		wp_dequeue_script('autosave');
224
-	}
221
+    // Disable auto-save for custom entity posts only
222
+    if( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ){
223
+        wp_dequeue_script('autosave');
224
+    }
225 225
 }
226 226
 
227 227
 add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
228 228
 
229 229
 function wl_enqueue_scripts() {
230
-	wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
230
+    wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
231 231
 }
232 232
 
233 233
 add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' );
@@ -242,18 +242,18 @@  discard block
 block discarded – undo
242 242
  */
243 243
 function wordlift_allowed_html( $allowedtags, $context ) {
244 244
 
245
-	if ( 'post' !== $context ) {
246
-		return $allowedtags;
247
-	}
248
-
249
-	return array_merge_recursive( $allowedtags, array(
250
-		'span' => array(
251
-			'itemscope' => true,
252
-			'itemtype'  => true,
253
-			'itemid'    => true,
254
-			'itemprop'  => true
255
-		)
256
-	) );
245
+    if ( 'post' !== $context ) {
246
+        return $allowedtags;
247
+    }
248
+
249
+    return array_merge_recursive( $allowedtags, array(
250
+        'span' => array(
251
+            'itemscope' => true,
252
+            'itemtype'  => true,
253
+            'itemid'    => true,
254
+            'itemprop'  => true
255
+        )
256
+    ) );
257 257
 }
258 258
 
259 259
 add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
@@ -267,15 +267,15 @@  discard block
 block discarded – undo
267 267
  */
268 268
 function wl_get_coordinates( $post_id ) {
269 269
 
270
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
271
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
270
+    $latitude  = wl_schema_get_value( $post_id, 'latitude' );
271
+    $longitude = wl_schema_get_value( $post_id, 'longitude' );
272 272
 
273
-	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
274
-	// "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
275
-	return array(
276
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
277
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : ''
278
-	);
273
+    // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
274
+    // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
275
+    return array(
276
+        'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
277
+        'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : ''
278
+    );
279 279
 }
280 280
 
281 281
 /**
@@ -287,13 +287,13 @@  discard block
 block discarded – undo
287 287
  */
288 288
 function wl_get_post_modified_time( $post ) {
289 289
 
290
-	$date_modified = get_post_modified_time( 'c', true, $post );
290
+    $date_modified = get_post_modified_time( 'c', true, $post );
291 291
 
292
-	if ( '-' === substr( $date_modified, 0, 1 ) ) {
293
-		return get_the_time( 'c', $post );
294
-	}
292
+    if ( '-' === substr( $date_modified, 0, 1 ) ) {
293
+        return get_the_time( 'c', $post );
294
+    }
295 295
 
296
-	return $date_modified;
296
+    return $date_modified;
297 297
 }
298 298
 
299 299
 /**
@@ -305,34 +305,34 @@  discard block
 block discarded – undo
305 305
  */
306 306
 function wl_get_image_urls( $post_id ) {
307 307
 
308
-	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
308
+    // wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
309 309
 
310
-	$images = get_children( array(
311
-		'post_parent'    => $post_id,
312
-		'post_type'      => 'attachment',
313
-		'post_mime_type' => 'image'
314
-	) );
310
+    $images = get_children( array(
311
+        'post_parent'    => $post_id,
312
+        'post_type'      => 'attachment',
313
+        'post_mime_type' => 'image'
314
+    ) );
315 315
 
316
-	// Return an empty array if no image is found.
317
-	if ( empty( $images ) ) {
318
-		return array();
319
-	}
316
+    // Return an empty array if no image is found.
317
+    if ( empty( $images ) ) {
318
+        return array();
319
+    }
320 320
 
321
-	// Prepare the return array.
322
-	$image_urls = array();
321
+    // Prepare the return array.
322
+    $image_urls = array();
323 323
 
324
-	// Collect the URLs.
325
-	foreach ( $images as $attachment_id => $attachment ) {
326
-		$image_url = wp_get_attachment_url( $attachment_id );
327
-		// Ensure the URL isn't collected already.
328
-		if ( ! in_array( $image_url, $image_urls ) ) {
329
-			array_push( $image_urls, $image_url );
330
-		}
331
-	}
324
+    // Collect the URLs.
325
+    foreach ( $images as $attachment_id => $attachment ) {
326
+        $image_url = wp_get_attachment_url( $attachment_id );
327
+        // Ensure the URL isn't collected already.
328
+        if ( ! in_array( $image_url, $image_urls ) ) {
329
+            array_push( $image_urls, $image_url );
330
+        }
331
+    }
332 332
 
333
-	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" );
333
+    // wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" );
334 334
 
335
-	return $image_urls;
335
+    return $image_urls;
336 336
 }
337 337
 
338 338
 /**
@@ -345,19 +345,19 @@  discard block
 block discarded – undo
345 345
  */
346 346
 function wl_get_sparql_images( $uri, $post_id ) {
347 347
 
348
-	$sparql = '';
348
+    $sparql = '';
349 349
 
350
-	// Get the escaped URI.
351
-	$uri_e = esc_html( $uri );
350
+    // Get the escaped URI.
351
+    $uri_e = esc_html( $uri );
352 352
 
353
-	// Add SPARQL stmts to write the schema:image.
354
-	$image_urls = wl_get_image_urls( $post_id );
355
-	foreach ( $image_urls as $image_url ) {
356
-		$image_url_esc = wl_sparql_escape_uri( $image_url );
357
-		$sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
358
-	}
353
+    // Add SPARQL stmts to write the schema:image.
354
+    $image_urls = wl_get_image_urls( $post_id );
355
+    foreach ( $image_urls as $image_url ) {
356
+        $image_url_esc = wl_sparql_escape_uri( $image_url );
357
+        $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
358
+    }
359 359
 
360
-	return $sparql;
360
+    return $sparql;
361 361
 }
362 362
 
363 363
 /**
@@ -370,24 +370,24 @@  discard block
 block discarded – undo
370 370
  */
371 371
 function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
372 372
 
373
-	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
373
+    // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
374 374
 
375
-	$posts = get_posts( array(
376
-		'post_type'      => 'attachment',
377
-		'posts_per_page' => 1,
378
-		'post_status'    => 'any',
379
-		'post_parent'    => $parent_post_id,
380
-		'meta_key'       => 'wl_source_url',
381
-		'meta_value'     => $source_url
382
-	) );
375
+    $posts = get_posts( array(
376
+        'post_type'      => 'attachment',
377
+        'posts_per_page' => 1,
378
+        'post_status'    => 'any',
379
+        'post_parent'    => $parent_post_id,
380
+        'meta_key'       => 'wl_source_url',
381
+        'meta_value'     => $source_url
382
+    ) );
383 383
 
384
-	// Return the found post.
385
-	if ( 1 === count( $posts ) ) {
386
-		return $posts[0];
387
-	}
384
+    // Return the found post.
385
+    if ( 1 === count( $posts ) ) {
386
+        return $posts[0];
387
+    }
388 388
 
389
-	// Return null.
390
-	return null;
389
+    // Return null.
390
+    return null;
391 391
 }
392 392
 
393 393
 /**
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
  */
399 399
 function wl_set_source_url( $post_id, $source_url ) {
400 400
 
401
-	delete_post_meta( $post_id, 'wl_source_url' );
402
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
401
+    delete_post_meta( $post_id, 'wl_source_url' );
402
+    add_post_meta( $post_id, 'wl_source_url', $source_url );
403 403
 }
404 404
 
405 405
 
@@ -417,43 +417,43 @@  discard block
 block discarded – undo
417 417
  */
418 418
 function wl_flush_rewrite_rules_hard( $hard ) {
419 419
 
420
-	// Get all published posts.
421
-	$posts = get_posts( array(
422
-		'posts_per_page' => - 1,
423
-		'post_type'      => 'any',
424
-		'post_status'    => 'publish'
425
-	) );
420
+    // Get all published posts.
421
+    $posts = get_posts( array(
422
+        'posts_per_page' => - 1,
423
+        'post_type'      => 'any',
424
+        'post_status'    => 'publish'
425
+    ) );
426 426
 
427
-	// Holds the delete part of the query.
428
-	$delete_query = rl_sparql_prefixes();
429
-	// Holds the insert part of the query.
430
-	$insert_query = 'INSERT DATA { ';
427
+    // Holds the delete part of the query.
428
+    $delete_query = rl_sparql_prefixes();
429
+    // Holds the insert part of the query.
430
+    $insert_query = 'INSERT DATA { ';
431 431
 
432
-	// Cycle in each post to build the query.
433
-	foreach ( $posts as $post ) {
432
+    // Cycle in each post to build the query.
433
+    foreach ( $posts as $post ) {
434 434
 
435
-		// Ignore revisions.
436
-		if ( wp_is_post_revision( $post->ID ) ) {
437
-			continue;
438
-		}
435
+        // Ignore revisions.
436
+        if ( wp_is_post_revision( $post->ID ) ) {
437
+            continue;
438
+        }
439 439
 
440
-		// Get the entity URI.
441
-		$uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
440
+        // Get the entity URI.
441
+        $uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
442 442
 
443
-		// Get the post URL.
444
-		$url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
443
+        // Get the post URL.
444
+        $url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
445 445
 
446
-		// Prepare the DELETE and INSERT commands.
447
-		$delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE  { <$uri> schema:url ?u . };\n";
448
-		$insert_query .= " <$uri> schema:url <$url> . \n";
446
+        // Prepare the DELETE and INSERT commands.
447
+        $delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE  { <$uri> schema:url ?u . };\n";
448
+        $insert_query .= " <$uri> schema:url <$url> . \n";
449 449
 
450
-		// wl_write_log( "[ uri :: $uri ][ url :: $url ]" );
451
-	}
450
+        // wl_write_log( "[ uri :: $uri ][ url :: $url ]" );
451
+    }
452 452
 
453
-	$insert_query .= ' };';
453
+    $insert_query .= ' };';
454 454
 
455
-	// Execute the query.
456
-	rl_execute_sparql_update_query( $delete_query . $insert_query );
455
+    // Execute the query.
456
+    rl_execute_sparql_update_query( $delete_query . $insert_query );
457 457
 }
458 458
 
459 459
 add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 );
@@ -470,15 +470,15 @@  discard block
 block discarded – undo
470 470
  */
471 471
 function wl_sanitize_uri_path( $path, $char = '_' ) {
472 472
 
473
-	// wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" );
473
+    // wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" );
474 474
 
475
-	// According to RFC2396 (http://www.ietf.org/rfc/rfc2396.txt) these characters are reserved:
476
-	// ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
477
-	// "$" | ","
478
-	// Plus the ' ' (space).
479
-	// TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex)
475
+    // According to RFC2396 (http://www.ietf.org/rfc/rfc2396.txt) these characters are reserved:
476
+    // ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
477
+    // "$" | ","
478
+    // Plus the ' ' (space).
479
+    // TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex)
480 480
 
481
-	return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) );
481
+    return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) );
482 482
 }
483 483
 
484 484
 /**
@@ -490,11 +490,11 @@  discard block
 block discarded – undo
490 490
  */
491 491
 function wl_force_to_array( $value ) {
492 492
 	
493
-	if ( ! is_array( $value ) ) {
494
-		return array( $value );
495
-	}
493
+    if ( ! is_array( $value ) ) {
494
+        return array( $value );
495
+    }
496 496
 	
497
-	return $value;
497
+    return $value;
498 498
 }
499 499
 
500 500
 /**
@@ -502,26 +502,26 @@  discard block
 block discarded – undo
502 502
  */
503 503
 function wl_shutdown() {
504 504
 
505
-	// Get the filename to the temporary SPARQL file.
506
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
505
+    // Get the filename to the temporary SPARQL file.
506
+    $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
507 507
 
508
-	// If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
509
-	if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
508
+    // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
509
+    if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
510 510
 
511
-		// The request ID.
512
-		$args = array( WL_REQUEST_ID );
511
+        // The request ID.
512
+        $args = array( WL_REQUEST_ID );
513 513
 
514
-		// Schedule the execution of the SPARQL query with the request ID.
515
-		wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
514
+        // Schedule the execution of the SPARQL query with the request ID.
515
+        wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
516 516
 
517
-		// Check that the request is scheduled.
518
-		$timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
517
+        // Check that the request is scheduled.
518
+        $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
519 519
 
520
-		// Spawn the cron.
521
-		spawn_cron();
520
+        // Spawn the cron.
521
+        spawn_cron();
522 522
 
523
-		wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
524
-	}
523
+        wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
524
+    }
525 525
 }
526 526
 
527 527
 add_action( 'shutdown', 'wl_shutdown' );
@@ -535,45 +535,45 @@  discard block
 block discarded – undo
535 535
  */
536 536
 function wl_replace_item_id_with_uri( $content ) {
537 537
 
538
-	// wl_write_log( "wl_replace_item_id_with_uri" );
538
+    // wl_write_log( "wl_replace_item_id_with_uri" );
539 539
 
540
-	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
541
-	$content = stripslashes( $content );
540
+    // Strip slashes, see https://core.trac.wordpress.org/ticket/21767
541
+    $content = stripslashes( $content );
542 542
 
543
-	// If any match are found.
544
-	$matches = array();
545
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
543
+    // If any match are found.
544
+    $matches = array();
545
+    if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
546 546
 
547
-		foreach ( $matches as $match ) {
547
+        foreach ( $matches as $match ) {
548 548
 
549
-			// Get the item ID.
550
-			$item_id = $match[1];
549
+            // Get the item ID.
550
+            $item_id = $match[1];
551 551
 
552
-			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
553
-			$post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $item_id );
552
+            // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
553
+            $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $item_id );
554 554
 
555
-			// If no entity is found, continue to the next one.
556
-			if ( null === $post ) {
557
-				continue;
558
-			}
555
+            // If no entity is found, continue to the next one.
556
+            if ( null === $post ) {
557
+                continue;
558
+            }
559 559
 
560
-			// Get the URI for that post.
561
-			$uri = wl_get_entity_uri( $post->ID );
560
+            // Get the URI for that post.
561
+            $uri = wl_get_entity_uri( $post->ID );
562 562
 
563
-			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
563
+            // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
564 564
 
565
-			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
566
-			if ( $item_id !== $uri ) {
567
-				$uri_e   = esc_html( $uri );
568
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
569
-			}
570
-		}
571
-	}
565
+            // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
566
+            if ( $item_id !== $uri ) {
567
+                $uri_e   = esc_html( $uri );
568
+                $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
569
+            }
570
+        }
571
+    }
572 572
 
573
-	// Reapply slashes.
574
-	$content = addslashes( $content );
573
+    // Reapply slashes.
574
+    $content = addslashes( $content );
575 575
 
576
-	return $content;
576
+    return $content;
577 577
 }
578 578
 
579 579
 add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
@@ -651,8 +651,8 @@  discard block
 block discarded – undo
651 651
  * This action is documented in includes/class-wordlift-activator.php
652 652
  */
653 653
 function activate_wordlift() {
654
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
655
-	Wordlift_Activator::activate();
654
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
655
+    Wordlift_Activator::activate();
656 656
 }
657 657
 
658 658
 /**
@@ -660,8 +660,8 @@  discard block
 block discarded – undo
660 660
  * This action is documented in includes/class-wordlift-deactivator.php
661 661
  */
662 662
 function deactivate_wordlift() {
663
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
664
-	Wordlift_Deactivator::deactivate();
663
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
664
+    Wordlift_Deactivator::deactivate();
665 665
 }
666 666
 
667 667
 register_activation_hook( __FILE__, 'activate_wordlift' );
@@ -684,8 +684,8 @@  discard block
 block discarded – undo
684 684
  */
685 685
 function run_wordlift() {
686 686
 
687
-	$plugin = new Wordlift();
688
-	$plugin->run();
687
+    $plugin = new Wordlift();
688
+    $plugin->run();
689 689
 
690 690
 }
691 691
 
Please login to merge, or discard this patch.
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -25,16 +25,16 @@  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' );
37
-require_once( 'modules/configuration/wordlift_configuration.php' );
36
+require_once('modules/core/wordlift_core.php');
37
+require_once('modules/configuration/wordlift_configuration.php');
38 38
 
39 39
 /**
40 40
  * Log to the debug.log file.
@@ -45,20 +45,20 @@  discard block
 block discarded – undo
45 45
  *
46 46
  * @param string|mixed $log The log data.
47 47
  */
48
-function wl_write_log( $log ) {
48
+function wl_write_log($log) {
49 49
 
50
-	$handler = apply_filters( 'wl_write_log_handler', null );
50
+	$handler = apply_filters('wl_write_log_handler', null);
51 51
 
52 52
 	$callers         = debug_backtrace();
53 53
 	$caller_function = $callers[1]['function'];
54 54
 
55
-	if ( is_null( $handler ) ) {
56
-		wl_write_log_handler( $log, $caller_function );
55
+	if (is_null($handler)) {
56
+		wl_write_log_handler($log, $caller_function);
57 57
 
58 58
 		return;
59 59
 	}
60 60
 
61
-	call_user_func( $handler, $log, $caller_function );
61
+	call_user_func($handler, $log, $caller_function);
62 62
 }
63 63
 
64 64
 /**
@@ -69,19 +69,19 @@  discard block
 block discarded – undo
69 69
  * @param string|array $log The log data.
70 70
  * @param string $caller The calling function.
71 71
  */
72
-function wl_write_log_handler( $log, $caller = null ) {
72
+function wl_write_log_handler($log, $caller = null) {
73 73
 
74 74
 	global $wl_logger;
75 75
 
76
-	if ( true === WP_DEBUG ) {
76
+	if (true === WP_DEBUG) {
77 77
 
78
-		$message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
79
-		           ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
78
+		$message = (isset($caller) ? sprintf('[%-40.40s] ', $caller) : '').
79
+		           (is_array($log) || is_object($log) ? print_r($log, true) : wl_write_log_hide_key($log));
80 80
 
81
-		if ( isset( $wl_logger ) ) {
82
-			$wl_logger->info( $message );
81
+		if (isset($wl_logger)) {
82
+			$wl_logger->info($message);
83 83
 		} else {
84
-			error_log( $message );
84
+			error_log($message);
85 85
 		}
86 86
 
87 87
 	}
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
  *
98 98
  * @return string A text with the key hidden.
99 99
  */
100
-function wl_write_log_hide_key( $text ) {
100
+function wl_write_log_hide_key($text) {
101 101
 
102
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
102
+	return str_ireplace(wl_configuration_get_key(), '<hidden>', $text);
103 103
 }
104 104
 
105 105
 /**
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
  *
110 110
  * @param string $query A SPARQL query.
111 111
  */
112
-function wl_queue_sparql_update_query( $query ) {
112
+function wl_queue_sparql_update_query($query) {
113 113
 
114
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
115
-	file_put_contents( $filename, $query . "\n", FILE_APPEND );
114
+	$filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql';
115
+	file_put_contents($filename, $query."\n", FILE_APPEND);
116 116
 
117
-	wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" );
117
+	wl_write_log("wl_queue_sparql_update_query [ filename :: $filename ]");
118 118
 }
119 119
 
120 120
 /**
@@ -122,33 +122,33 @@  discard block
 block discarded – undo
122 122
  *
123 123
  * @param int $request_id The request ID.
124 124
  */
125
-function wl_execute_saved_sparql_update_query( $request_id ) {
125
+function wl_execute_saved_sparql_update_query($request_id) {
126 126
 
127
-	$filename = WL_TEMP_DIR . $request_id . '.sparql';
127
+	$filename = WL_TEMP_DIR.$request_id.'.sparql';
128 128
 
129 129
 	// If the file doesn't exist, exit.
130
-	if ( ! file_exists( $filename ) ) {
131
-		wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" );
130
+	if ( ! file_exists($filename)) {
131
+		wl_write_log("wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]");
132 132
 
133 133
 		return;
134 134
 	}
135 135
 
136
-	wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" );
136
+	wl_write_log("wl_execute_saved_sparql_update_query [ filename :: $filename ]");
137 137
 
138 138
 	// Get the query saved in the file.
139
-	$query = file_get_contents( $filename );
139
+	$query = file_get_contents($filename);
140 140
 
141 141
 	// Execute the SPARQL query.
142
-	rl_execute_sparql_update_query( $query, false );
142
+	rl_execute_sparql_update_query($query, false);
143 143
 
144 144
 	// Reindex the triple store.
145 145
 	wordlift_reindex_triple_store();
146 146
 
147 147
 	// Delete the temporary file.
148
-	unlink( $filename );
148
+	unlink($filename);
149 149
 }
150 150
 
151
-add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 );
151
+add_action('wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1);
152 152
 
153 153
 /**
154 154
  * Add buttons hook for the TinyMCE editor. This method is called by the WP init hook.
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 function wordlift_buttonhooks() {
157 157
 
158 158
 	// Only add hooks when the current user has permissions AND is in Rich Text editor mode
159
-	if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
160
-		add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' );
159
+	if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) {
160
+		add_filter('mce_external_plugins', 'wordlift_register_tinymce_javascript');
161 161
 	}
162 162
 }
163 163
 
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
  *
169 169
  * @return array The modified plugins array.
170 170
  */
171
-function wordlift_register_tinymce_javascript( $plugin_array ) {
171
+function wordlift_register_tinymce_javascript($plugin_array) {
172 172
 
173 173
 	// add the wordlift plugin.
174
-	$plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
174
+	$plugin_array['wordlift'] = plugin_dir_url(__FILE__).'js/wordlift-reloaded.js';
175 175
 
176 176
 	return $plugin_array;
177 177
 }
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 function wordlift_allowed_post_tags() {
184 184
 	global $allowedposttags;
185 185
 
186
-	$tags           = array( 'span' );
186
+	$tags           = array('span');
187 187
 	$new_attributes = array(
188 188
 		'itemscope' => array(),
189 189
 		'itemtype'  => array(),
@@ -191,17 +191,17 @@  discard block
 block discarded – undo
191 191
 		'itemid'    => array()
192 192
 	);
193 193
 
194
-	foreach ( $tags as $tag ) {
195
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
196
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
194
+	foreach ($tags as $tag) {
195
+		if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) {
196
+			$allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes);
197 197
 		}
198 198
 	}
199 199
 }
200 200
 
201 201
 // init process for button control
202
-add_action( 'init', 'wordlift_buttonhooks' );
202
+add_action('init', 'wordlift_buttonhooks');
203 203
 // add allowed post tags.
204
-add_action( 'init', 'wordlift_allowed_post_tags' );
204
+add_action('init', 'wordlift_allowed_post_tags');
205 205
 
206 206
 
207 207
 /**
@@ -210,27 +210,27 @@  discard block
 block discarded – undo
210 210
 function wordlift_admin_enqueue_scripts() {
211 211
 
212 212
 	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
213
-	wp_enqueue_script( 'wpdialogs' );
214
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
213
+	wp_enqueue_script('wpdialogs');
214
+	wp_enqueue_style('wp-jquery-ui-dialog');
215 215
 
216
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
216
+	wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css');
217 217
 
218
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
219
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
218
+	wp_enqueue_script('jquery-ui-autocomplete');
219
+	wp_enqueue_script('angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js');
220 220
 
221 221
 	// Disable auto-save for custom entity posts only
222
-	if( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ){
222
+	if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) {
223 223
 		wp_dequeue_script('autosave');
224 224
 	}
225 225
 }
226 226
 
227
-add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
227
+add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts');
228 228
 
229 229
 function wl_enqueue_scripts() {
230
-	wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
230
+	wp_enqueue_style('wordlift-ui', plugin_dir_url(__FILE__).'css/wordlift-ui.min.css');
231 231
 }
232 232
 
233
-add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' );
233
+add_action('wp_enqueue_scripts', 'wl_enqueue_scripts');
234 234
 
235 235
 /**
236 236
  * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes.
@@ -240,23 +240,23 @@  discard block
 block discarded – undo
240 240
  *
241 241
  * @return array An array which contains allowed microdata attributes.
242 242
  */
243
-function wordlift_allowed_html( $allowedtags, $context ) {
243
+function wordlift_allowed_html($allowedtags, $context) {
244 244
 
245
-	if ( 'post' !== $context ) {
245
+	if ('post' !== $context) {
246 246
 		return $allowedtags;
247 247
 	}
248 248
 
249
-	return array_merge_recursive( $allowedtags, array(
249
+	return array_merge_recursive($allowedtags, array(
250 250
 		'span' => array(
251 251
 			'itemscope' => true,
252 252
 			'itemtype'  => true,
253 253
 			'itemid'    => true,
254 254
 			'itemprop'  => true
255 255
 		)
256
-	) );
256
+	));
257 257
 }
258 258
 
259
-add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
259
+add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2);
260 260
 
261 261
 /**
262 262
  * Get the coordinates for the specified post ID.
@@ -265,16 +265,16 @@  discard block
 block discarded – undo
265 265
  *
266 266
  * @return array|null An array of coordinates or null.
267 267
  */
268
-function wl_get_coordinates( $post_id ) {
268
+function wl_get_coordinates($post_id) {
269 269
 
270
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
271
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
270
+	$latitude  = wl_schema_get_value($post_id, 'latitude');
271
+	$longitude = wl_schema_get_value($post_id, 'longitude');
272 272
 
273 273
 	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
274 274
 	// "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
275 275
 	return array(
276
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
277
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : ''
276
+		'latitude'  => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '',
277
+		'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : ''
278 278
 	);
279 279
 }
280 280
 
@@ -285,12 +285,12 @@  discard block
 block discarded – undo
285 285
  *
286 286
  * @return string A datetime.
287 287
  */
288
-function wl_get_post_modified_time( $post ) {
288
+function wl_get_post_modified_time($post) {
289 289
 
290
-	$date_modified = get_post_modified_time( 'c', true, $post );
290
+	$date_modified = get_post_modified_time('c', true, $post);
291 291
 
292
-	if ( '-' === substr( $date_modified, 0, 1 ) ) {
293
-		return get_the_time( 'c', $post );
292
+	if ('-' === substr($date_modified, 0, 1)) {
293
+		return get_the_time('c', $post);
294 294
 	}
295 295
 
296 296
 	return $date_modified;
@@ -303,18 +303,18 @@  discard block
 block discarded – undo
303 303
  *
304 304
  * @return array An array of image URLs.
305 305
  */
306
-function wl_get_image_urls( $post_id ) {
306
+function wl_get_image_urls($post_id) {
307 307
 
308 308
 	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
309 309
 
310
-	$images = get_children( array(
310
+	$images = get_children(array(
311 311
 		'post_parent'    => $post_id,
312 312
 		'post_type'      => 'attachment',
313 313
 		'post_mime_type' => 'image'
314
-	) );
314
+	));
315 315
 
316 316
 	// Return an empty array if no image is found.
317
-	if ( empty( $images ) ) {
317
+	if (empty($images)) {
318 318
 		return array();
319 319
 	}
320 320
 
@@ -322,11 +322,11 @@  discard block
 block discarded – undo
322 322
 	$image_urls = array();
323 323
 
324 324
 	// Collect the URLs.
325
-	foreach ( $images as $attachment_id => $attachment ) {
326
-		$image_url = wp_get_attachment_url( $attachment_id );
325
+	foreach ($images as $attachment_id => $attachment) {
326
+		$image_url = wp_get_attachment_url($attachment_id);
327 327
 		// Ensure the URL isn't collected already.
328
-		if ( ! in_array( $image_url, $image_urls ) ) {
329
-			array_push( $image_urls, $image_url );
328
+		if ( ! in_array($image_url, $image_urls)) {
329
+			array_push($image_urls, $image_url);
330 330
 		}
331 331
 	}
332 332
 
@@ -343,17 +343,17 @@  discard block
 block discarded – undo
343 343
  *
344 344
  * @return string The SPARQL fragment.
345 345
  */
346
-function wl_get_sparql_images( $uri, $post_id ) {
346
+function wl_get_sparql_images($uri, $post_id) {
347 347
 
348 348
 	$sparql = '';
349 349
 
350 350
 	// Get the escaped URI.
351
-	$uri_e = esc_html( $uri );
351
+	$uri_e = esc_html($uri);
352 352
 
353 353
 	// Add SPARQL stmts to write the schema:image.
354
-	$image_urls = wl_get_image_urls( $post_id );
355
-	foreach ( $image_urls as $image_url ) {
356
-		$image_url_esc = wl_sparql_escape_uri( $image_url );
354
+	$image_urls = wl_get_image_urls($post_id);
355
+	foreach ($image_urls as $image_url) {
356
+		$image_url_esc = wl_sparql_escape_uri($image_url);
357 357
 		$sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
358 358
 	}
359 359
 
@@ -368,21 +368,21 @@  discard block
 block discarded – undo
368 368
  *
369 369
  * @return WP_Post|null A post instance or null if not found.
370 370
  */
371
-function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
371
+function wl_get_attachment_for_source_url($parent_post_id, $source_url) {
372 372
 
373 373
 	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
374 374
 
375
-	$posts = get_posts( array(
375
+	$posts = get_posts(array(
376 376
 		'post_type'      => 'attachment',
377 377
 		'posts_per_page' => 1,
378 378
 		'post_status'    => 'any',
379 379
 		'post_parent'    => $parent_post_id,
380 380
 		'meta_key'       => 'wl_source_url',
381 381
 		'meta_value'     => $source_url
382
-	) );
382
+	));
383 383
 
384 384
 	// Return the found post.
385
-	if ( 1 === count( $posts ) ) {
385
+	if (1 === count($posts)) {
386 386
 		return $posts[0];
387 387
 	}
388 388
 
@@ -396,10 +396,10 @@  discard block
 block discarded – undo
396 396
  * @param int $post_id The post ID.
397 397
  * @param string $source_url The source URL.
398 398
  */
399
-function wl_set_source_url( $post_id, $source_url ) {
399
+function wl_set_source_url($post_id, $source_url) {
400 400
 
401
-	delete_post_meta( $post_id, 'wl_source_url' );
402
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
401
+	delete_post_meta($post_id, 'wl_source_url');
402
+	add_post_meta($post_id, 'wl_source_url', $source_url);
403 403
 }
404 404
 
405 405
 
@@ -415,14 +415,14 @@  discard block
 block discarded – undo
415 415
  *
416 416
  * @param bool $hard True if the rewrite involves configuration updates in Apache/IIS.
417 417
  */
418
-function wl_flush_rewrite_rules_hard( $hard ) {
418
+function wl_flush_rewrite_rules_hard($hard) {
419 419
 
420 420
 	// Get all published posts.
421
-	$posts = get_posts( array(
422
-		'posts_per_page' => - 1,
421
+	$posts = get_posts(array(
422
+		'posts_per_page' => -1,
423 423
 		'post_type'      => 'any',
424 424
 		'post_status'    => 'publish'
425
-	) );
425
+	));
426 426
 
427 427
 	// Holds the delete part of the query.
428 428
 	$delete_query = rl_sparql_prefixes();
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
 	$insert_query = 'INSERT DATA { ';
431 431
 
432 432
 	// Cycle in each post to build the query.
433
-	foreach ( $posts as $post ) {
433
+	foreach ($posts as $post) {
434 434
 
435 435
 		// Ignore revisions.
436
-		if ( wp_is_post_revision( $post->ID ) ) {
436
+		if (wp_is_post_revision($post->ID)) {
437 437
 			continue;
438 438
 		}
439 439
 
440 440
 		// Get the entity URI.
441
-		$uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
441
+		$uri = wl_sparql_escape_uri(wl_get_entity_uri($post->ID));
442 442
 
443 443
 		// Get the post URL.
444
-		$url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
444
+		$url = wl_sparql_escape_uri(get_permalink($post->ID));
445 445
 
446 446
 		// Prepare the DELETE and INSERT commands.
447 447
 		$delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE  { <$uri> schema:url ?u . };\n";
@@ -453,10 +453,10 @@  discard block
 block discarded – undo
453 453
 	$insert_query .= ' };';
454 454
 
455 455
 	// Execute the query.
456
-	rl_execute_sparql_update_query( $delete_query . $insert_query );
456
+	rl_execute_sparql_update_query($delete_query.$insert_query);
457 457
 }
458 458
 
459
-add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 );
459
+add_filter('flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1);
460 460
 
461 461
 /**
462 462
  * Sanitizes an URI path by replacing the non allowed characters with an underscore.
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
  *
469 469
  * @return The sanitized path.
470 470
  */
471
-function wl_sanitize_uri_path( $path, $char = '_' ) {
471
+function wl_sanitize_uri_path($path, $char = '_') {
472 472
 
473 473
 	// wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" );
474 474
 
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 	// Plus the ' ' (space).
479 479
 	// TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex)
480 480
 
481
-	return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) );
481
+	return sanitize_title(preg_replace('/[;\/?:@&=+$,\s]/', $char, stripslashes($path)));
482 482
 }
483 483
 
484 484
 /**
@@ -488,10 +488,10 @@  discard block
 block discarded – undo
488 488
  * 
489 489
  * @return array Array containing $value (if $value was not an array) 
490 490
  */
491
-function wl_force_to_array( $value ) {
491
+function wl_force_to_array($value) {
492 492
 	
493
-	if ( ! is_array( $value ) ) {
494
-		return array( $value );
493
+	if ( ! is_array($value)) {
494
+		return array($value);
495 495
 	}
496 496
 	
497 497
 	return $value;
@@ -503,28 +503,28 @@  discard block
 block discarded – undo
503 503
 function wl_shutdown() {
504 504
 
505 505
 	// Get the filename to the temporary SPARQL file.
506
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
506
+	$filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql';
507 507
 
508 508
 	// If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
509
-	if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
509
+	if (WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists($filename)) {
510 510
 
511 511
 		// The request ID.
512
-		$args = array( WL_REQUEST_ID );
512
+		$args = array(WL_REQUEST_ID);
513 513
 
514 514
 		// Schedule the execution of the SPARQL query with the request ID.
515
-		wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
515
+		wp_schedule_single_event(time(), 'wl_execute_saved_sparql_update_query', $args);
516 516
 
517 517
 		// Check that the request is scheduled.
518
-		$timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
518
+		$timestamp = wp_next_scheduled('wl_execute_saved_sparql_update_query', $args);
519 519
 
520 520
 		// Spawn the cron.
521 521
 		spawn_cron();
522 522
 
523
-		wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
523
+		wl_write_log("wl_shutdown [ request id :: ".WL_REQUEST_ID." ][ timestamp :: $timestamp ]");
524 524
 	}
525 525
 }
526 526
 
527
-add_action( 'shutdown', 'wl_shutdown' );
527
+add_action('shutdown', 'wl_shutdown');
528 528
 
529 529
 /**
530 530
  * Replaces the *itemid* attributes URIs with the WordLift URIs.
@@ -533,117 +533,117 @@  discard block
 block discarded – undo
533 533
  *
534 534
  * @return string The updated post content.
535 535
  */
536
-function wl_replace_item_id_with_uri( $content ) {
536
+function wl_replace_item_id_with_uri($content) {
537 537
 
538 538
 	// wl_write_log( "wl_replace_item_id_with_uri" );
539 539
 
540 540
 	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
541
-	$content = stripslashes( $content );
541
+	$content = stripslashes($content);
542 542
 
543 543
 	// If any match are found.
544 544
 	$matches = array();
545
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
545
+	if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) {
546 546
 
547
-		foreach ( $matches as $match ) {
547
+		foreach ($matches as $match) {
548 548
 
549 549
 			// Get the item ID.
550 550
 			$item_id = $match[1];
551 551
 
552 552
 			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
553
-			$post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $item_id );
553
+			$post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri($item_id);
554 554
 
555 555
 			// If no entity is found, continue to the next one.
556
-			if ( null === $post ) {
556
+			if (null === $post) {
557 557
 				continue;
558 558
 			}
559 559
 
560 560
 			// Get the URI for that post.
561
-			$uri = wl_get_entity_uri( $post->ID );
561
+			$uri = wl_get_entity_uri($post->ID);
562 562
 
563 563
 			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
564 564
 
565 565
 			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
566
-			if ( $item_id !== $uri ) {
567
-				$uri_e   = esc_html( $uri );
568
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
566
+			if ($item_id !== $uri) {
567
+				$uri_e   = esc_html($uri);
568
+				$content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content);
569 569
 			}
570 570
 		}
571 571
 	}
572 572
 
573 573
 	// Reapply slashes.
574
-	$content = addslashes( $content );
574
+	$content = addslashes($content);
575 575
 
576 576
 	return $content;
577 577
 }
578 578
 
579
-add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
579
+add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1);
580 580
 
581
-require_once( 'wordlift_entity_functions.php' );
581
+require_once('wordlift_entity_functions.php');
582 582
 
583 583
 // add editor related methods.
584
-require_once( 'wordlift_editor.php' );
584
+require_once('wordlift_editor.php');
585 585
 
586 586
 // add the WordLift entity custom type.
587
-require_once( 'wordlift_entity_type.php' );
588
-require_once( 'wordlift_entity_type_taxonomy.php' );
587
+require_once('wordlift_entity_type.php');
588
+require_once('wordlift_entity_type_taxonomy.php');
589 589
 
590 590
 // filters the post content when saving posts.
591
-require_once( 'wordlift_content_filter.php' );
591
+require_once('wordlift_content_filter.php');
592 592
 // add callbacks on post save to notify data changes from wp to redlink triple store
593
-require_once( 'wordlift_to_redlink_data_push_callbacks.php' );
593
+require_once('wordlift_to_redlink_data_push_callbacks.php');
594 594
 
595 595
 // Load modules
596
-require_once( 'modules/analyzer/wordlift_analyzer.php' );
597
-require_once( 'modules/linked_data/wordlift_linked_data.php' );
598
-require_once( 'modules/prefixes/wordlift_prefixes.php' );
599
-require_once( 'modules/caching/wordlift_caching.php' );
600
-require_once( 'modules/redirector/wordlift_redirector.php' );
601
-require_once( 'modules/freebase_image_proxy/wordlift_freebase_image_proxy.php' );
596
+require_once('modules/analyzer/wordlift_analyzer.php');
597
+require_once('modules/linked_data/wordlift_linked_data.php');
598
+require_once('modules/prefixes/wordlift_prefixes.php');
599
+require_once('modules/caching/wordlift_caching.php');
600
+require_once('modules/redirector/wordlift_redirector.php');
601
+require_once('modules/freebase_image_proxy/wordlift_freebase_image_proxy.php');
602 602
 
603 603
 // Shortcodes
604 604
 
605
-require_once( 'modules/geo_widget/wordlift_geo_widget.php' );
606
-require_once( 'shortcodes/wordlift_shortcode_chord.php' );
607
-require_once( 'shortcodes/wordlift_shortcode_geomap.php' );
608
-require_once( 'shortcodes/wordlift_shortcode_field.php' );
609
-require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' );
610
-require_once( 'shortcodes/wordlift_shortcode_navigator.php' );
605
+require_once('modules/geo_widget/wordlift_geo_widget.php');
606
+require_once('shortcodes/wordlift_shortcode_chord.php');
607
+require_once('shortcodes/wordlift_shortcode_geomap.php');
608
+require_once('shortcodes/wordlift_shortcode_field.php');
609
+require_once('shortcodes/wordlift_shortcode_faceted_search.php');
610
+require_once('shortcodes/wordlift_shortcode_navigator.php');
611 611
 
612 612
 // disable In-Depth Articles
613 613
 //require_once('wordlift_indepth_articles.php');
614 614
 
615
-require_once( 'widgets/wordlift_widget_geo.php' );
616
-require_once( 'widgets/wordlift_widget_chord.php' );
617
-require_once( 'widgets/wordlift_widget_timeline.php' );
615
+require_once('widgets/wordlift_widget_geo.php');
616
+require_once('widgets/wordlift_widget_chord.php');
617
+require_once('widgets/wordlift_widget_timeline.php');
618 618
 
619
-require_once( 'wordlift_sparql.php' );
620
-require_once( 'wordlift_redlink.php' );
619
+require_once('wordlift_sparql.php');
620
+require_once('wordlift_redlink.php');
621 621
 
622 622
 // Add admin functions.
623 623
 // TODO: find a way to make 'admin' UI tests work.
624 624
 //if ( is_admin() ) {
625 625
 
626
-require_once( 'admin/wordlift_admin.php' );
627
-require_once( 'admin/wordlift_admin_edit_post.php' );
628
-require_once( 'admin/wordlift_admin_save_post.php' );
626
+require_once('admin/wordlift_admin.php');
627
+require_once('admin/wordlift_admin_edit_post.php');
628
+require_once('admin/wordlift_admin_save_post.php');
629 629
 
630 630
 // add the entities meta box.
631
-require_once( 'admin/wordlift_admin_meta_box_entities.php' );
631
+require_once('admin/wordlift_admin_meta_box_entities.php');
632 632
 
633 633
 // add the entity creation AJAX.
634
-require_once( 'admin/wordlift_admin_ajax_related_posts.php' );
634
+require_once('admin/wordlift_admin_ajax_related_posts.php');
635 635
 
636 636
 // Load the wl_chord TinyMCE button and configuration dialog.
637
-require_once( 'admin/wordlift_admin_shortcodes.php' );
637
+require_once('admin/wordlift_admin_shortcodes.php');
638 638
 
639 639
 // Provide syncing features.
640
-require_once( 'admin/wordlift_admin_sync.php' );
640
+require_once('admin/wordlift_admin_sync.php');
641 641
 //}
642 642
 
643 643
 // load languages.
644 644
 // TODO: the following call gives for granted that the plugin is in the wordlift directory,
645 645
 //       we're currently doing this because wordlift is symbolic linked.
646
-load_plugin_textdomain( 'wordlift', false, '/wordlift/languages' );
646
+load_plugin_textdomain('wordlift', false, '/wordlift/languages');
647 647
 
648 648
 
649 649
 /**
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
  * This action is documented in includes/class-wordlift-activator.php
652 652
  */
653 653
 function activate_wordlift() {
654
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
654
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
655 655
 	Wordlift_Activator::activate();
656 656
 }
657 657
 
@@ -660,18 +660,18 @@  discard block
 block discarded – undo
660 660
  * This action is documented in includes/class-wordlift-deactivator.php
661 661
  */
662 662
 function deactivate_wordlift() {
663
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
663
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
664 664
 	Wordlift_Deactivator::deactivate();
665 665
 }
666 666
 
667
-register_activation_hook( __FILE__, 'activate_wordlift' );
668
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
667
+register_activation_hook(__FILE__, 'activate_wordlift');
668
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
669 669
 
670 670
 /**
671 671
  * The core plugin class that is used to define internationalization,
672 672
  * admin-specific hooks, and public-facing site hooks.
673 673
  */
674
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
674
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
675 675
 
676 676
 /**
677 677
  * Begins execution of the plugin.
Please login to merge, or discard this patch.