Completed
Branch feature/397-review-wordlifts-s... (3d685b)
by David
02:44
created
src/admin/wordlift_admin_edit_post.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
  * @param string $new_title Optional. New title.
13 13
  * @param string $new_slug Optional. New slug.
14 14
  *
15
- * @return The enhanced html.
15
+ * @return string enhanced html.
16 16
  */
17 17
 function wl_admin_permalink_html( $html, $post_id, $new_title, $new_slug ) {
18 18
 
Please login to merge, or discard this patch.
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -16,23 +16,23 @@
 block discarded – undo
16 16
  */
17 17
 function wl_admin_permalink_html( $html, $post_id, $new_title, $new_slug ) {
18 18
 
19
-	// If the post is published, add the button to view Redlink's linked data.
20
-	if ( 'publish' == get_post_status( $post_id ) ) {
21
-		if ( $uri = wl_get_entity_uri( $post_id ) ) {
22
-			$uri_esc       = esc_attr( wl_get_entity_uri( $post_id ) );
23
-			$lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc;
24
-			$html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>" .
25
-			         __( 'View Linked Data', 'wordlift' ) .
26
-			         "</a></span>\n";
27
-		}
28
-		$html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL .
29
-		         urlencode( get_permalink( $post_id ) ) .
30
-		         "' class='button button-small wl-button' target='_blank'>" .
31
-		         __( 'Test Google Rich Snippets', 'wordlift' ) .
32
-		         "</a></span>\n";
33
-	}
19
+    // If the post is published, add the button to view Redlink's linked data.
20
+    if ( 'publish' == get_post_status( $post_id ) ) {
21
+        if ( $uri = wl_get_entity_uri( $post_id ) ) {
22
+            $uri_esc       = esc_attr( wl_get_entity_uri( $post_id ) );
23
+            $lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc;
24
+            $html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>" .
25
+                        __( 'View Linked Data', 'wordlift' ) .
26
+                        "</a></span>\n";
27
+        }
28
+        $html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL .
29
+                    urlencode( get_permalink( $post_id ) ) .
30
+                    "' class='button button-small wl-button' target='_blank'>" .
31
+                    __( 'Test Google Rich Snippets', 'wordlift' ) .
32
+                    "</a></span>\n";
33
+    }
34 34
 
35
-	return $html;
35
+    return $html;
36 36
 }
37 37
 
38 38
 add_filter( 'get_sample_permalink_html', 'wl_admin_permalink_html', 10, 4 );
39 39
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,25 +14,25 @@
 block discarded – undo
14 14
  *
15 15
  * @return The enhanced html.
16 16
  */
17
-function wl_admin_permalink_html( $html, $post_id, $new_title, $new_slug ) {
17
+function wl_admin_permalink_html($html, $post_id, $new_title, $new_slug) {
18 18
 
19 19
 	// If the post is published, add the button to view Redlink's linked data.
20
-	if ( 'publish' == get_post_status( $post_id ) ) {
21
-		if ( $uri = wl_get_entity_uri( $post_id ) ) {
22
-			$uri_esc       = esc_attr( wl_get_entity_uri( $post_id ) );
23
-			$lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc;
24
-			$html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>" .
25
-			         __( 'View Linked Data', 'wordlift' ) .
20
+	if ('publish' == get_post_status($post_id)) {
21
+		if ($uri = wl_get_entity_uri($post_id)) {
22
+			$uri_esc       = esc_attr(wl_get_entity_uri($post_id));
23
+			$lod_view_href = 'http://lodview.it/lodview/?IRI='.$uri_esc;
24
+			$html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>".
25
+			         __('View Linked Data', 'wordlift').
26 26
 			         "</a></span>\n";
27 27
 		}
28
-		$html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL .
29
-		         urlencode( get_permalink( $post_id ) ) .
30
-		         "' class='button button-small wl-button' target='_blank'>" .
31
-		         __( 'Test Google Rich Snippets', 'wordlift' ) .
28
+		$html .= "<span id='view-post-btn'><a href='".WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL.
29
+		         urlencode(get_permalink($post_id)).
30
+		         "' class='button button-small wl-button' target='_blank'>".
31
+		         __('Test Google Rich Snippets', 'wordlift').
32 32
 		         "</a></span>\n";
33 33
 	}
34 34
 
35 35
 	return $html;
36 36
 }
37 37
 
38
-add_filter( 'get_sample_permalink_html', 'wl_admin_permalink_html', 10, 4 );
39 38
\ No newline at end of file
39
+add_filter('get_sample_permalink_html', 'wl_admin_permalink_html', 10, 4);
40 40
\ No newline at end of file
Please login to merge, or discard this patch.
src/modules/core/wordlift_core_post_entity_relations.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -266,6 +266,8 @@  discard block
 block discarded – undo
266 266
 * @param int $subject_id The post ID | The entity post ID.
267 267
 * @param string $predicate Name of the relation: null | 'what' | 'where' | 'when' | 'who'
268 268
 * @param string $post_status Filter by post status null | 'publish' | 'draft' | 'pending' | 'trash'. null means *any* post status
269
+* @param string $get
270
+* @param integer $item_id
269 271
 *
270 272
 * @return (array) Array of ids.
271 273
 */
@@ -337,6 +339,8 @@  discard block
 block discarded – undo
337 339
 * @param int $object_id The entity ID or the post ID.
338 340
 * @param string $predicate Name of the relation: null | 'what' | 'where' | 'when' | 'who'
339 341
 * @param string $post_status Filter by post status null | 'publish' | 'draft' | 'pending' | 'trash'. null means *any* post status
342
+* @param string $get
343
+* @param integer $item_id
340 344
 *
341 345
 * @return (array) Array of objects.
342 346
 */
Please login to merge, or discard this patch.
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -7,11 +7,11 @@  discard block
 block discarded – undo
7 7
  * 
8 8
  * @return boolean Return true if supported, false otherwise
9 9
  */
10
-function wl_core_check_relation_predicate_is_supported( $predicate ) {
10
+function wl_core_check_relation_predicate_is_supported($predicate) {
11 11
     
12
-    return in_array( $predicate, array(
12
+    return in_array($predicate, array(
13 13
         WL_WHAT_RELATION, WL_WHEN_RELATION, WL_WHERE_RELATION, WL_WHO_RELATION
14
-    ) );
14
+    ));
15 15
 }
16 16
 /**
17 17
  * Return an array of validation rules used by wl_core_get_posts
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  */
21 21
 function wl_core_get_validation_rules() { 
22 22
 
23
-    return unserialize( WL_CORE_GET_POSTS_VALIDATION_RULES );
23
+    return unserialize(WL_CORE_GET_POSTS_VALIDATION_RULES);
24 24
 }
25 25
 /**
26 26
  * Return the wordlift relation instances table name
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 function wl_core_get_relation_instances_table_name() { 
31 31
 
32 32
     global $wpdb;
33
-    $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
33
+    $table_name = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME;
34 34
     return $table_name;
35 35
 }
36 36
 
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
 * @uses $wpdb->replace() to perform the query
45 45
 * @return (integer|boolean) Return then relation instance ID or false
46 46
 */
47
-function wl_core_add_relation_instance( $subject_id, $predicate, $object_id ) {
47
+function wl_core_add_relation_instance($subject_id, $predicate, $object_id) {
48 48
     
49 49
     // Checks on subject and object
50
-    if( !is_numeric( $subject_id ) || !is_numeric( $object_id ) ) {
50
+    if ( ! is_numeric($subject_id) || ! is_numeric($object_id)) {
51 51
         return false;
52 52
     }
53 53
     
54 54
     // Checks on the given relation
55
-    if( !wl_core_check_relation_predicate_is_supported( $predicate ) ) {
55
+    if ( ! wl_core_check_relation_predicate_is_supported($predicate)) {
56 56
         return false;
57 57
     }
58 58
     
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		'predicate' => $predicate, 
69 69
 		'object_id' => $object_id 
70 70
 	   ), 
71
-	   array( '%d', '%s', '%d'	) 
71
+	   array('%d', '%s', '%d') 
72 72
     );
73 73
     
74 74
     // Return record id
@@ -85,22 +85,22 @@  discard block
 block discarded – undo
85 85
 *
86 86
 * @return (boolean) False for failure. True for success.
87 87
 */
88
-function wl_core_delete_relation_instance( $subject_id, $predicate, $object_id ) {
88
+function wl_core_delete_relation_instance($subject_id, $predicate, $object_id) {
89 89
 
90 90
     // Checks on subject and object
91
-    if( !is_numeric( $subject_id ) || !is_numeric( $object_id ) ) {
91
+    if ( ! is_numeric($subject_id) || ! is_numeric($object_id)) {
92 92
         return false;
93 93
     }
94 94
     
95 95
     // Checks on the given relation
96
-    if( !wl_core_check_relation_predicate_is_supported( $predicate ) ) {
96
+    if ( ! wl_core_check_relation_predicate_is_supported($predicate)) {
97 97
         return false;
98 98
     }
99 99
     
100 100
     // Prepare interaction with db
101 101
     global $wpdb;
102 102
 
103
-    wl_write_log( "Going to delete relation instace [ subject_id :: $subject_id ] [ object_id :: $object_id ] [ predicate :: $predicate ]"); 
103
+    wl_write_log("Going to delete relation instace [ subject_id :: $subject_id ] [ object_id :: $object_id ] [ predicate :: $predicate ]"); 
104 104
     
105 105
     // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe
106 106
     $wpdb->delete(
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
         'predicate' => $predicate, 
111 111
         'object_id' => $object_id 
112 112
        ), 
113
-       array( '%d', '%s', '%d'  ) 
113
+       array('%d', '%s', '%d') 
114 114
     );
115 115
 
116 116
     return true;    
@@ -126,27 +126,27 @@  discard block
 block discarded – undo
126 126
 *
127 127
 * @return (integer|boolean) Return the relation instances IDs or false
128 128
 */
129
-function wl_core_add_relation_instances( $subject_id, $predicate, $object_ids ) {
129
+function wl_core_add_relation_instances($subject_id, $predicate, $object_ids) {
130 130
     
131 131
     // Checks on subject and object
132
-    if( !is_numeric( $subject_id ) ) {
132
+    if ( ! is_numeric($subject_id)) {
133 133
         return false;
134 134
     }
135 135
     
136 136
     // Checks on the given relation
137
-    if( !wl_core_check_relation_predicate_is_supported( $predicate ) ) {
137
+    if ( ! wl_core_check_relation_predicate_is_supported($predicate)) {
138 138
         return false;
139 139
     }
140 140
     
141 141
     // Check $object_ids is an array
142
-    if( !is_array( $object_ids ) || empty( $object_ids ) ) {
142
+    if ( ! is_array($object_ids) || empty($object_ids)) {
143 143
         return false;
144 144
     }
145 145
     
146 146
     // Call method to check and add each single relation
147 147
     $inserted_records_ids = array();
148
-    foreach ( $object_ids as $object_id ) {
149
-        $new_record_id = wl_core_add_relation_instance( $subject_id, $predicate, $object_id );
148
+    foreach ($object_ids as $object_id) {
149
+        $new_record_id = wl_core_add_relation_instance($subject_id, $predicate, $object_id);
150 150
         $inserted_records_ids[] = $new_record_id;
151 151
     }
152 152
     
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 *
162 162
 * @return (boolean) False for failure. True for success.
163 163
 */
164
-function wl_core_delete_relation_instances( $subject_id ) {
164
+function wl_core_delete_relation_instances($subject_id) {
165 165
 
166 166
     // Checks on subject and object
167
-    if( !is_numeric( $subject_id ) ) {
167
+    if ( ! is_numeric($subject_id)) {
168 168
         return false;
169 169
     }
170 170
     
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
        array( 
180 180
         'subject_id' => $subject_id,
181 181
        ), 
182
-       array( '%d' ) 
182
+       array('%d') 
183 183
     );
184 184
 
185 185
     return true;
@@ -196,16 +196,16 @@  discard block
 block discarded – undo
196 196
  *      'status'    => null
197 197
  *  );
198 198
  */
199
-function wl_core_validate_filters_for_related( $filters ) {
199
+function wl_core_validate_filters_for_related($filters) {
200 200
     
201
-    if( !is_array( $filters ) ) {
201
+    if ( ! is_array($filters)) {
202 202
         $filters = array();
203 203
     }
204 204
     
205
-    if( !isset( $filters['predicate'] )) {
205
+    if ( ! isset($filters['predicate'])) {
206 206
         $filters['predicate'] = null;
207 207
     }
208
-    if( !isset( $filters['status'] )) {
208
+    if ( ! isset($filters['status'])) {
209 209
         $filters['status'] = null;
210 210
     }
211 211
     
@@ -228,11 +228,11 @@  discard block
 block discarded – undo
228 228
 *
229 229
 * @return (array) Array of post entity objects.
230 230
 */
231
-function wl_core_get_related_entities( $subject_id, $filters = array() ) {
231
+function wl_core_get_related_entities($subject_id, $filters = array()) {
232 232
     
233
-    $filters = wl_core_validate_filters_for_related( $filters );
233
+    $filters = wl_core_validate_filters_for_related($filters);
234 234
     
235
-    return wl_core_inner_get_related_entities( "posts", $subject_id, $filters['predicate'], $filters['status'] );
235
+    return wl_core_inner_get_related_entities("posts", $subject_id, $filters['predicate'], $filters['status']);
236 236
 }
237 237
 
238 238
 /**
@@ -251,11 +251,11 @@  discard block
 block discarded – undo
251 251
 *
252 252
 * @return (array) Array of post entity objects.
253 253
 */
254
-function wl_core_get_related_entity_ids( $subject_id, $filters = array() ) {
254
+function wl_core_get_related_entity_ids($subject_id, $filters = array()) {
255 255
     
256
-    $filters = wl_core_validate_filters_for_related( $filters );
256
+    $filters = wl_core_validate_filters_for_related($filters);
257 257
     
258
-    return wl_core_inner_get_related_entities( "post_ids", $subject_id, $filters['predicate'], $filters['status'] );
258
+    return wl_core_inner_get_related_entities("post_ids", $subject_id, $filters['predicate'], $filters['status']);
259 259
 }
260 260
 
261 261
 /**
@@ -269,16 +269,16 @@  discard block
 block discarded – undo
269 269
 *
270 270
 * @return (array) Array of ids.
271 271
 */
272
-function wl_core_inner_get_related_entities( $get, $item_id, $predicate = null, $post_status = null ) {
272
+function wl_core_inner_get_related_entities($get, $item_id, $predicate = null, $post_status = null) {
273 273
     
274
-    if ( $results = wl_core_get_posts( array(
274
+    if ($results = wl_core_get_posts(array(
275 275
         'get'               =>  $get,
276 276
         'post_type'         =>  'entity',
277 277
         'post_status'       =>  $post_status,
278 278
         'related_to'        =>  $item_id, 
279 279
         'as'                =>  'object',
280 280
         'with_predicate'    =>  $predicate,
281
-        ) ) ) {
281
+        ))) {
282 282
             return $results;
283 283
     }
284 284
     // If wl_core_get_posts return false then an empty array is returned
@@ -301,11 +301,11 @@  discard block
 block discarded – undo
301 301
 *
302 302
 * @return (array) Array of objects.
303 303
 */
304
-function wl_core_get_related_posts( $object_id, $filters = array() ) {
304
+function wl_core_get_related_posts($object_id, $filters = array()) {
305 305
     
306
-    $filters = wl_core_validate_filters_for_related( $filters );
306
+    $filters = wl_core_validate_filters_for_related($filters);
307 307
     
308
-    return wl_core_inner_get_related_posts( "posts", $object_id, $filters[ 'predicate' ], $filters[ 'status' ] );
308
+    return wl_core_inner_get_related_posts("posts", $object_id, $filters['predicate'], $filters['status']);
309 309
 }
310 310
 /**
311 311
 * Find all post ids related to a given $object_id
@@ -322,11 +322,11 @@  discard block
 block discarded – undo
322 322
 * </code>
323 323
 * @return (array) Array of objects.
324 324
 */
325
-function wl_core_get_related_post_ids( $object_id, $filters = array() ) {
325
+function wl_core_get_related_post_ids($object_id, $filters = array()) {
326 326
     
327
-    $filters = wl_core_validate_filters_for_related( $filters );
327
+    $filters = wl_core_validate_filters_for_related($filters);
328 328
     
329
-    return wl_core_inner_get_related_posts( "post_ids", $object_id, $filters[ 'predicate' ], $filters[ 'status' ] );
329
+    return wl_core_inner_get_related_posts("post_ids", $object_id, $filters['predicate'], $filters['status']);
330 330
 }
331 331
 
332 332
 /**
@@ -340,35 +340,35 @@  discard block
 block discarded – undo
340 340
 *
341 341
 * @return (array) Array of objects.
342 342
 */
343
-function wl_core_inner_get_related_posts( $get, $item_id, $predicate = null, $post_status = null ) {
343
+function wl_core_inner_get_related_posts($get, $item_id, $predicate = null, $post_status = null) {
344 344
 
345 345
     // Retrieve the post object
346
-    $post = get_post( $item_id );
347
-    if ( null === $post ) {
346
+    $post = get_post($item_id);
347
+    if (null === $post) {
348 348
         return array();
349 349
     }
350 350
 
351
-    if ( "entity" === $post->post_type ) {
352
-        if ( $results = wl_core_get_posts( array(
351
+    if ("entity" === $post->post_type) {
352
+        if ($results = wl_core_get_posts(array(
353 353
             'get'               =>  $get,
354 354
             'post_type'         =>  'post',
355 355
             'post_status'       =>  $post_status,
356 356
             'related_to'        =>  $item_id, 
357 357
             'as'                =>  'subject',
358 358
             'with_predicate'    =>  $predicate,
359
-        ) ) ) {
359
+        ))) {
360 360
             return $results;
361 361
         }
362 362
     } else {
363
-        if ( $results = wl_core_get_posts( array(
363
+        if ($results = wl_core_get_posts(array(
364 364
             'get'               =>  $get,
365 365
             'post_type'         =>  'post',
366 366
             'post_status'       =>  $post_status,
367
-            'post__not_in'      =>  array( $item_id ), 
368
-            'related_to__in'    =>  wl_core_get_related_entity_ids( $post->ID ), 
367
+            'post__not_in'      =>  array($item_id), 
368
+            'related_to__in'    =>  wl_core_get_related_entity_ids($post->ID), 
369 369
             'as'                =>  'subject',
370 370
             'with_predicate'    =>  $predicate,
371
-        ) ) ) {
371
+        ))) {
372 372
             return $results;
373 373
         }
374 374
     }
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 *
402 402
 * @return string | false String representing a sql statement, or false in case of error 
403 403
 */
404
-function wl_core_sql_query_builder( $args ) {
404
+function wl_core_sql_query_builder($args) {
405 405
 
406 406
     // Prepare interaction with db
407 407
     global $wpdb;
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
     // Sql Action
412 412
     $sql = "SELECT ";
413 413
     // Determine what has to be returned depending on 'get' argument value
414
-    switch ( $args[ 'get' ] ) {
414
+    switch ($args['get']) {
415 415
         case 'posts':
416 416
             $sql .= "p.*";
417 417
             break;
@@ -421,16 +421,16 @@  discard block
 block discarded – undo
421 421
     }
422 422
 
423 423
     // If we look for posts related as objects the JOIN has to be done with the object_id column and viceversa
424
-    $join_column = $args[ 'as' ] . "_id"; 
424
+    $join_column = $args['as']."_id"; 
425 425
         
426 426
     $sql .= " FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.$join_column";
427 427
     
428 428
     // Sql add post type filter
429
-    $sql .= $wpdb->prepare( " AND p.post_type = %s AND", $args[ 'post_type' ] );
429
+    $sql .= $wpdb->prepare(" AND p.post_type = %s AND", $args['post_type']);
430 430
     
431 431
     // Sql add post status filter
432
-    if( isset( $args['post_status'] ) && !is_null( $args['post_status'] ) ) {
433
-        $sql .= $wpdb->prepare( " p.post_status = %s AND", $args[ 'post_status' ] );
432
+    if (isset($args['post_status']) && ! is_null($args['post_status'])) {
433
+        $sql .= $wpdb->prepare(" p.post_status = %s AND", $args['post_status']);
434 434
     }
435 435
     
436 436
     // Add filtering conditions
@@ -439,34 +439,34 @@  discard block
 block discarded – undo
439 439
     // If we look for posts related as subject this means that 
440 440
     // related_to is reference for an object: object_id is the filtering column
441 441
         
442
-    $filtering_column = ( 'object' == $args[ 'as' ] ) ? "subject_id" : "object_id";
442
+    $filtering_column = ('object' == $args['as']) ? "subject_id" : "object_id";
443 443
         
444
-    if( isset( $args[ 'related_to' ] ) ) {
445
-        $sql .= $wpdb->prepare( " r.$filtering_column = %d", $args[ 'related_to' ] );
444
+    if (isset($args['related_to'])) {
445
+        $sql .= $wpdb->prepare(" r.$filtering_column = %d", $args['related_to']);
446 446
     }
447
-    if( isset( $args[ 'related_to' ] ) && isset($args[ 'related_to__in' ] ) ) {
447
+    if (isset($args['related_to']) && isset($args['related_to__in'])) {
448 448
         $sql .= " AND";
449 449
     }
450
-    if( isset($args[ 'related_to__in' ] ) ) {
451
-        $sql .= " r.$filtering_column IN (" . implode(",", $args[ 'related_to__in' ] ) . ")";
450
+    if (isset($args['related_to__in'])) {
451
+        $sql .= " r.$filtering_column IN (".implode(",", $args['related_to__in']).")";
452 452
     }
453
-    if( isset( $args[ 'post__not_in' ] ) ) {
454
-        $sql .= " AND r." . $args[ 'as' ] . "_id NOT IN (" . implode(",", $args[ 'post__not_in' ] ) . ")";
453
+    if (isset($args['post__not_in'])) {
454
+        $sql .= " AND r.".$args['as']."_id NOT IN (".implode(",", $args['post__not_in']).")";
455 455
     }
456
-    if( isset( $args[ 'post__in' ] ) ) {
457
-        $sql .= " AND r." . $args[ 'as' ] . "_id IN (" . implode(",", $args[ 'post__in' ] ) . ")";
456
+    if (isset($args['post__in'])) {
457
+        $sql .= " AND r.".$args['as']."_id IN (".implode(",", $args['post__in']).")";
458 458
     }
459 459
     // Add predicate filter if required
460
-    if ( isset( $args[ 'with_predicate' ] ) ) {
460
+    if (isset($args['with_predicate'])) {
461 461
         // Sql Inner Join clausole 
462
-        $sql .= $wpdb->prepare( " AND r.predicate = %s", $args[ 'with_predicate' ] );
462
+        $sql .= $wpdb->prepare(" AND r.predicate = %s", $args['with_predicate']);
463 463
     }
464 464
     // Add a group by clousole to avoid duplicated rows
465 465
     $sql .= " GROUP BY p.id";
466 466
     
467
-    if ( isset( $args[ 'first' ] ) && is_numeric( $args[ 'first' ] ) ) {
467
+    if (isset($args['first']) && is_numeric($args['first'])) {
468 468
         // Sql Inner Join clausole 
469
-        $sql .= $wpdb->prepare( " LIMIT %d", $args[ 'first'] );
469
+        $sql .= $wpdb->prepare(" LIMIT %d", $args['first']);
470 470
     }
471 471
     // Close sql statement
472 472
     $sql .= ";";
@@ -485,10 +485,10 @@  discard block
 block discarded – undo
485 485
 *
486 486
 * @return (array) List of WP_Post objects or list of WP_Post ids. False in case of error or invalid params
487 487
 */
488
-function wl_core_get_posts( $args, $returned_type = OBJECT ) {
488
+function wl_core_get_posts($args, $returned_type = OBJECT) {
489 489
 
490 490
     // Merge given args with defaults args value
491
-    $args = array_merge( array(
491
+    $args = array_merge(array(
492 492
         'with_predicate' => null,
493 493
         'as' => 'subject',
494 494
         'post_type' => 'post',
@@ -498,29 +498,29 @@  discard block
 block discarded – undo
498 498
 
499 499
     // Arguments validation rules
500 500
     // At least one between related_to and related_to__in has to be set
501
-    if ( !isset( $args[ 'related_to' ] ) && !isset( $args[ 'related_to__in' ] ) ) {
501
+    if ( ! isset($args['related_to']) && ! isset($args['related_to__in'])) {
502 502
         return false;
503 503
     }
504
-    if ( isset( $args[ 'related_to' ] ) && !is_numeric( $args[ 'related_to' ] ) ) {
504
+    if (isset($args['related_to']) && ! is_numeric($args['related_to'])) {
505 505
         return false;
506 506
     }
507 507
 
508 508
     // The same check is applied to post_in, post__not_in and related_to__in options
509 509
     // Only arrays with at least one numeric value are considerad valid
510 510
     // The argument value is further sanitized in order to clean up not numeric values
511
-    foreach ( array( 'post__in', 'post__not_in', 'related_to__in' ) as $option_name ) {
512
-        if ( isset( $args[ $option_name ] ) ) {
513
-            if ( !is_array( $args[ $option_name ] ) || 0 == count( array_filter( $args[ $option_name ], "is_numeric" ) ) ) {
511
+    foreach (array('post__in', 'post__not_in', 'related_to__in') as $option_name) {
512
+        if (isset($args[$option_name])) {
513
+            if ( ! is_array($args[$option_name]) || 0 == count(array_filter($args[$option_name], "is_numeric"))) {
514 514
                 return false;
515 515
             }
516 516
             // Sanitize value removing non numeric values from the array
517
-            $args[ $option_name ] = array_filter( $args[ $option_name ], "is_numeric" );
517
+            $args[$option_name] = array_filter($args[$option_name], "is_numeric");
518 518
         }
519 519
     }
520 520
     // Performing validation rules
521
-    foreach ( wl_core_get_validation_rules() as $option_name => $accepeted_values ) {
522
-        if ( isset( $args[ $option_name ] ) && !is_null( $args[ $option_name ] ) ) {
523
-            if ( !in_array( $args[ $option_name ], $accepeted_values ) )  {
521
+    foreach (wl_core_get_validation_rules() as $option_name => $accepeted_values) {
522
+        if (isset($args[$option_name]) && ! is_null($args[$option_name])) {
523
+            if ( ! in_array($args[$option_name], $accepeted_values)) {
524 524
                 return false;
525 525
             }
526 526
         }
@@ -529,21 +529,21 @@  discard block
 block discarded – undo
529 529
     // Prepare interaction with db
530 530
     global $wpdb;
531 531
     // Build sql statement with given arguments
532
-    $sql_statement = wl_core_sql_query_builder( $args ); 
532
+    $sql_statement = wl_core_sql_query_builder($args); 
533 533
 
534 534
     // wl_write_log( "Going to execute sql statement: $sql_statement " );
535 535
     // $results = array();
536 536
 
537 537
     // If ids are required, returns a one-dimensional array containing ids.
538 538
     // Otherwise an array of associative arrays representing the post | relation object
539
-    if ( 'post_ids' == $args[ 'get' ] ) {
539
+    if ('post_ids' == $args['get']) {
540 540
         # See https://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Column
541
-        $results = $wpdb->get_col( $sql_statement );
541
+        $results = $wpdb->get_col($sql_statement);
542 542
     } else {
543
-        $results = $wpdb->get_results( $sql_statement, $returned_type );
543
+        $results = $wpdb->get_results($sql_statement, $returned_type);
544 544
     }
545 545
     // If there were an error performing the query then false is returned
546
-    if ( !empty( $wpdb->last_error ) ) {
546
+    if ( ! empty($wpdb->last_error)) {
547 547
         return false;
548 548
     }
549 549
     // Finally
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
     // Checks passed. Add relation if not exists
63 63
     // See https://codex.wordpress.org/Class_Reference/wpdb#REPLACE_row
64 64
     $wpdb->replace( 
65
-	   wl_core_get_relation_instances_table_name(), 
66
-	   array( 
65
+        wl_core_get_relation_instances_table_name(), 
66
+        array( 
67 67
         'subject_id' => $subject_id,
68
-		'predicate' => $predicate, 
69
-		'object_id' => $object_id 
70
-	   ), 
71
-	   array( '%d', '%s', '%d'	) 
68
+        'predicate' => $predicate, 
69
+        'object_id' => $object_id 
70
+        ), 
71
+        array( '%d', '%s', '%d'	) 
72 72
     );
73 73
     
74 74
     // Return record id
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
     
105 105
     // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe
106 106
     $wpdb->delete(
107
-       wl_core_get_relation_instances_table_name(), 
108
-       array( 
107
+        wl_core_get_relation_instances_table_name(), 
108
+        array( 
109 109
         'subject_id' => $subject_id,
110 110
         'predicate' => $predicate, 
111 111
         'object_id' => $object_id 
112
-       ), 
113
-       array( '%d', '%s', '%d'  ) 
112
+        ), 
113
+        array( '%d', '%s', '%d'  ) 
114 114
     );
115 115
 
116 116
     return true;    
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
     
176 176
     // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe
177 177
     $wpdb->delete(
178
-       wl_core_get_relation_instances_table_name(), 
179
-       array( 
178
+        wl_core_get_relation_instances_table_name(), 
179
+        array( 
180 180
         'subject_id' => $subject_id,
181
-       ), 
182
-       array( '%d' ) 
181
+        ), 
182
+        array( '%d' ) 
183 183
     );
184 184
 
185 185
     return true;
Please login to merge, or discard this patch.
src/modules/core/wordlift_core_schema_api.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -170,9 +170,9 @@
 block discarded – undo
170 170
  * Sets the entity type(s) for the specified post ID. Support is now for only one type per entity.
171 171
  *
172 172
  * @param $post_id numeric The numeric post ID
173
- * @param $type_names array An array of strings, each defining a type (e.g. Type, for the http://schema.org/Type)
173
+ * @param string $type_names array An array of strings, each defining a type (e.g. Type, for the http://schema.org/Type)
174 174
  *
175
- * @return boolean True if everything went ok, an error string otherwise.
175
+ * @return boolean|null True if everything went ok, an error string otherwise.
176 176
  */
177 177
 function wl_schema_set_types( $post_id, $type_names ) {
178 178
 
Please login to merge, or discard this patch.
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -10,28 +10,28 @@  discard block
 block discarded – undo
10 10
  */
11 11
 function wl_schema_reset_value( $post_id, $property_name ) {
12 12
 
13
-	// Some checks on the parameters
14
-	if ( ! is_numeric( $post_id ) || is_null( $property_name ) ) {
15
-		return FALSE;
16
-	}
13
+    // Some checks on the parameters
14
+    if ( ! is_numeric( $post_id ) || is_null( $property_name ) ) {
15
+        return FALSE;
16
+    }
17 17
 
18
-	// Build full schema uri if necessary
19
-	$property_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
18
+    // Build full schema uri if necessary
19
+    $property_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
20 20
 
21
-	// Get accepted properties
22
-	$accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id );
21
+    // Get accepted properties
22
+    $accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id );
23 23
 
24
-	// Find the name of the custom-field managing the schema property
25
-	foreach ( $accepted_fields as $wl_constant => $field ) {
26
-		if ( $field['predicate'] == $property_name ) {
24
+    // Find the name of the custom-field managing the schema property
25
+    foreach ( $accepted_fields as $wl_constant => $field ) {
26
+        if ( $field['predicate'] == $property_name ) {
27 27
 
28
-			delete_post_meta( $post_id, $wl_constant );
28
+            delete_post_meta( $post_id, $wl_constant );
29 29
 
30
-			return TRUE;
31
-		}
32
-	}
30
+            return TRUE;
31
+        }
32
+    }
33 33
 
34
-	return FALSE;
34
+    return FALSE;
35 35
 }
36 36
 
37 37
 /**
@@ -44,34 +44,34 @@  discard block
 block discarded – undo
44 44
  */
45 45
 function wl_schema_get_value( $post_id, $property_name ) {
46 46
 
47
-	// Property name must be defined.
48
-	if ( ! isset( $property_name ) || is_null( $property_name ) ) {
49
-		return NULL;
50
-	}
51
-
52
-	// store eventual schema name in  different variable
53
-	$property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
54
-
55
-	// Establish entity id.
56
-	if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
57
-		$post_id = get_the_ID();
58
-		if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
59
-			return NULL;
60
-		}
61
-	}
62
-
63
-	// Get custom fields.
64
-	$term_mapping = wl_entity_taxonomy_get_custom_fields( $post_id );
65
-	// Search for the required meta value (by constant name or schema name)
66
-	foreach ( $term_mapping as $wl_constant => $property_info ) {
67
-		$found_constant  = ( $wl_constant == $property_name );
68
-		$found_predicate = ( isset( $property_info['predicate'] ) && $property_info['predicate'] == $property_schema_name );
69
-		if ( $found_constant || $found_predicate ) {
70
-			return get_post_meta( $post_id, $wl_constant );
71
-		}
72
-	}
73
-
74
-	return NULL;
47
+    // Property name must be defined.
48
+    if ( ! isset( $property_name ) || is_null( $property_name ) ) {
49
+        return NULL;
50
+    }
51
+
52
+    // store eventual schema name in  different variable
53
+    $property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
54
+
55
+    // Establish entity id.
56
+    if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
57
+        $post_id = get_the_ID();
58
+        if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
59
+            return NULL;
60
+        }
61
+    }
62
+
63
+    // Get custom fields.
64
+    $term_mapping = wl_entity_taxonomy_get_custom_fields( $post_id );
65
+    // Search for the required meta value (by constant name or schema name)
66
+    foreach ( $term_mapping as $wl_constant => $property_info ) {
67
+        $found_constant  = ( $wl_constant == $property_name );
68
+        $found_predicate = ( isset( $property_info['predicate'] ) && $property_info['predicate'] == $property_schema_name );
69
+        if ( $found_constant || $found_predicate ) {
70
+            return get_post_meta( $post_id, $wl_constant );
71
+        }
72
+    }
73
+
74
+    return NULL;
75 75
 }
76 76
 
77 77
 /**
@@ -85,15 +85,15 @@  discard block
 block discarded – undo
85 85
  */
86 86
 function wl_schema_add_value( $post_id, $property_name, $property_value ) {
87 87
 
88
-	if ( ! is_array( $property_value ) ) {
89
-		$property_value = array( $property_value );
90
-	}
88
+    if ( ! is_array( $property_value ) ) {
89
+        $property_value = array( $property_value );
90
+    }
91 91
 
92
-	$old_values = wl_schema_get_value( $post_id, $property_name );
92
+    $old_values = wl_schema_get_value( $post_id, $property_name );
93 93
 
94
-	$merged_property_value = array_unique( array_merge( $property_value, $old_values ) );
94
+    $merged_property_value = array_unique( array_merge( $property_value, $old_values ) );
95 95
 
96
-	wl_schema_set_value( $post_id, $property_name, $merged_property_value );
96
+    wl_schema_set_value( $post_id, $property_name, $merged_property_value );
97 97
 }
98 98
 
99 99
 /**
@@ -107,38 +107,38 @@  discard block
 block discarded – undo
107 107
  */
108 108
 function wl_schema_set_value( $post_id, $property_name, $property_value ) {
109 109
 
110
-	// Some checks on the parameters
111
-	if ( ! is_numeric( $post_id ) || is_null( $property_name ) || empty( $property_value ) || is_null( $property_value ) ) {
112
-		return FALSE;
113
-	}
110
+    // Some checks on the parameters
111
+    if ( ! is_numeric( $post_id ) || is_null( $property_name ) || empty( $property_value ) || is_null( $property_value ) ) {
112
+        return FALSE;
113
+    }
114 114
 
115
-	// Build full schema uri if necessary
116
-	$property_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
115
+    // Build full schema uri if necessary
116
+    $property_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
117 117
 
118
-	// Get accepted properties
119
-	$accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id );
118
+    // Get accepted properties
119
+    $accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id );
120 120
 
121
-	// Find the name of the custom-field managing the schema property
122
-	foreach ( $accepted_fields as $wl_constant => $field ) {
123
-		if ( $field['predicate'] == $property_name ) {
121
+    // Find the name of the custom-field managing the schema property
122
+    foreach ( $accepted_fields as $wl_constant => $field ) {
123
+        if ( $field['predicate'] == $property_name ) {
124 124
 
125
-			// Deal with single values
126
-			if ( ! is_array( $property_value ) ) {
127
-				$property_value = array( $property_value );
128
-			}
125
+            // Deal with single values
126
+            if ( ! is_array( $property_value ) ) {
127
+                $property_value = array( $property_value );
128
+            }
129 129
 
130
-			// Delete present meta
131
-			delete_post_meta( $post_id, $wl_constant );
130
+            // Delete present meta
131
+            delete_post_meta( $post_id, $wl_constant );
132 132
 
133
-			foreach ( $property_value as $value ) {
134
-				add_post_meta( $post_id, $wl_constant, $value );
135
-			}
133
+            foreach ( $property_value as $value ) {
134
+                add_post_meta( $post_id, $wl_constant, $value );
135
+            }
136 136
 
137
-			return TRUE;
138
-		}
139
-	}
137
+            return TRUE;
138
+        }
139
+    }
140 140
 
141
-	return FALSE;
141
+    return FALSE;
142 142
 }
143 143
 
144 144
 
@@ -152,18 +152,18 @@  discard block
 block discarded – undo
152 152
  */
153 153
 function wl_schema_get_types( $post_id ) {
154 154
 
155
-	// Some checks on the parameters
156
-	if ( ! is_numeric( $post_id ) ) {
157
-		return NULL;
158
-	}
155
+    // Some checks on the parameters
156
+    if ( ! is_numeric( $post_id ) ) {
157
+        return NULL;
158
+    }
159 159
 
160
-	$type = wl_entity_type_taxonomy_get_type( $post_id );
160
+    $type = wl_entity_type_taxonomy_get_type( $post_id );
161 161
 
162
-	if ( isset( $type['uri'] ) ) {
163
-		return array( $type['uri'] );
164
-	}
162
+    if ( isset( $type['uri'] ) ) {
163
+        return array( $type['uri'] );
164
+    }
165 165
 
166
-	return NULL;
166
+    return NULL;
167 167
 }
168 168
 
169 169
 /**
@@ -176,24 +176,24 @@  discard block
 block discarded – undo
176 176
  */
177 177
 function wl_schema_set_types( $post_id, $type_names ) {
178 178
 
179
-	// Some checks on the parameters
180
-	if ( ! is_numeric( $post_id ) || empty( $type_names ) || is_null( $type_names ) ) {
181
-		return NULL;
182
-	}
179
+    // Some checks on the parameters
180
+    if ( ! is_numeric( $post_id ) || empty( $type_names ) || is_null( $type_names ) ) {
181
+        return NULL;
182
+    }
183 183
 
184
-	// TODO: support more than one type
185
-	if ( is_array( $type_names ) ) {
186
-		$type_names = $type_names[0];
187
-	}
184
+    // TODO: support more than one type
185
+    if ( is_array( $type_names ) ) {
186
+        $type_names = $type_names[0];
187
+    }
188 188
 
189
-	// Get the schema URI (e.g. http://schema.org/Thing)
190
-	$type_names = wl_build_full_schema_uri_from_schema_slug( $type_names );
189
+    // Get the schema URI (e.g. http://schema.org/Thing)
190
+    $type_names = wl_build_full_schema_uri_from_schema_slug( $type_names );
191 191
 
192
-	Wordlift_Log_Service::get_logger( 'wl_schema_set_types' )
193
-	                    ->debug( "[ type names :: $type_names ]" );
192
+    Wordlift_Log_Service::get_logger( 'wl_schema_set_types' )
193
+                        ->debug( "[ type names :: $type_names ]" );
194 194
 
195
-	// Actually sets the taxonomy type
196
-	wl_set_entity_main_type( $post_id, $type_names );
195
+    // Actually sets the taxonomy type
196
+    wl_set_entity_main_type( $post_id, $type_names );
197 197
 
198 198
 }
199 199
 
@@ -209,24 +209,24 @@  discard block
 block discarded – undo
209 209
  */
210 210
 function wl_schema_get_type_properties( $type_name ) {
211 211
 
212
-	// Build full schema uri if necessary
213
-	$type_name = wl_build_full_schema_uri_from_schema_slug( $type_name );
212
+    // Build full schema uri if necessary
213
+    $type_name = wl_build_full_schema_uri_from_schema_slug( $type_name );
214 214
 
215
-	// Get all custom fields
216
-	$all_types_and_fields = wl_entity_taxonomy_get_custom_fields();
215
+    // Get all custom fields
216
+    $all_types_and_fields = wl_entity_taxonomy_get_custom_fields();
217 217
 
218
-	$schema_root_address = 'http://schema.org/';
219
-	$type_properties     = array();
218
+    $schema_root_address = 'http://schema.org/';
219
+    $type_properties     = array();
220 220
 
221
-	// Search for the entity type which has the requested name as uri
222
-	if ( isset( $all_types_and_fields[ $type_name ] ) ) {
223
-		foreach ( $all_types_and_fields[ $type_name ] as $field ) {
224
-			// Convert to schema slug and store in array
225
-			$type_properties[] = str_replace( $schema_root_address, '', $field['predicate'] );
226
-		}
227
-	}
221
+    // Search for the entity type which has the requested name as uri
222
+    if ( isset( $all_types_and_fields[ $type_name ] ) ) {
223
+        foreach ( $all_types_and_fields[ $type_name ] as $field ) {
224
+            // Convert to schema slug and store in array
225
+            $type_properties[] = str_replace( $schema_root_address, '', $field['predicate'] );
226
+        }
227
+    }
228 228
 
229
-	return $type_properties;
229
+    return $type_properties;
230 230
 }
231 231
 
232 232
 /**
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
  */
239 239
 function wl_build_full_schema_uri_from_schema_slug( $schema_name ) {
240 240
 
241
-	$schema_root_address = 'http://schema.org/';
241
+    $schema_root_address = 'http://schema.org/';
242 242
 
243
-	if ( strpos( $schema_name, $schema_root_address ) === FALSE ) {   // === necessary
244
-		$schema_name = $schema_root_address . $schema_name;
245
-	}
243
+    if ( strpos( $schema_name, $schema_root_address ) === FALSE ) {   // === necessary
244
+        $schema_name = $schema_root_address . $schema_name;
245
+    }
246 246
 
247
-	return $schema_name;
247
+    return $schema_name;
248 248
 }
249 249
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -8,24 +8,24 @@  discard block
 block discarded – undo
8 8
  *
9 9
  * @return boolean The method returns true if everything went ok, false otherwise.
10 10
  */
11
-function wl_schema_reset_value( $post_id, $property_name ) {
11
+function wl_schema_reset_value($post_id, $property_name) {
12 12
 
13 13
 	// Some checks on the parameters
14
-	if ( ! is_numeric( $post_id ) || is_null( $property_name ) ) {
14
+	if ( ! is_numeric($post_id) || is_null($property_name)) {
15 15
 		return FALSE;
16 16
 	}
17 17
 
18 18
 	// Build full schema uri if necessary
19
-	$property_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
19
+	$property_name = wl_build_full_schema_uri_from_schema_slug($property_name);
20 20
 
21 21
 	// Get accepted properties
22
-	$accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id );
22
+	$accepted_fields = wl_entity_taxonomy_get_custom_fields($post_id);
23 23
 
24 24
 	// Find the name of the custom-field managing the schema property
25
-	foreach ( $accepted_fields as $wl_constant => $field ) {
26
-		if ( $field['predicate'] == $property_name ) {
25
+	foreach ($accepted_fields as $wl_constant => $field) {
26
+		if ($field['predicate'] == $property_name) {
27 27
 
28
-			delete_post_meta( $post_id, $wl_constant );
28
+			delete_post_meta($post_id, $wl_constant);
29 29
 
30 30
 			return TRUE;
31 31
 		}
@@ -42,32 +42,32 @@  discard block
 block discarded – undo
42 42
  *
43 43
  * @return array An array of values or NULL in case of no values (or error).
44 44
  */
45
-function wl_schema_get_value( $post_id, $property_name ) {
45
+function wl_schema_get_value($post_id, $property_name) {
46 46
 
47 47
 	// Property name must be defined.
48
-	if ( ! isset( $property_name ) || is_null( $property_name ) ) {
48
+	if ( ! isset($property_name) || is_null($property_name)) {
49 49
 		return NULL;
50 50
 	}
51 51
 
52 52
 	// store eventual schema name in  different variable
53
-	$property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
53
+	$property_schema_name = wl_build_full_schema_uri_from_schema_slug($property_name);
54 54
 
55 55
 	// Establish entity id.
56
-	if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
56
+	if (is_null($post_id) || ! is_numeric($post_id)) {
57 57
 		$post_id = get_the_ID();
58
-		if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
58
+		if (is_null($post_id) || ! is_numeric($post_id)) {
59 59
 			return NULL;
60 60
 		}
61 61
 	}
62 62
 
63 63
 	// Get custom fields.
64
-	$term_mapping = wl_entity_taxonomy_get_custom_fields( $post_id );
64
+	$term_mapping = wl_entity_taxonomy_get_custom_fields($post_id);
65 65
 	// Search for the required meta value (by constant name or schema name)
66
-	foreach ( $term_mapping as $wl_constant => $property_info ) {
67
-		$found_constant  = ( $wl_constant == $property_name );
68
-		$found_predicate = ( isset( $property_info['predicate'] ) && $property_info['predicate'] == $property_schema_name );
69
-		if ( $found_constant || $found_predicate ) {
70
-			return get_post_meta( $post_id, $wl_constant );
66
+	foreach ($term_mapping as $wl_constant => $property_info) {
67
+		$found_constant  = ($wl_constant == $property_name);
68
+		$found_predicate = (isset($property_info['predicate']) && $property_info['predicate'] == $property_schema_name);
69
+		if ($found_constant || $found_predicate) {
70
+			return get_post_meta($post_id, $wl_constant);
71 71
 		}
72 72
 	}
73 73
 
@@ -83,17 +83,17 @@  discard block
 block discarded – undo
83 83
  *
84 84
  * @return array An array of values or NULL in case of no values (or error).
85 85
  */
86
-function wl_schema_add_value( $post_id, $property_name, $property_value ) {
86
+function wl_schema_add_value($post_id, $property_name, $property_value) {
87 87
 
88
-	if ( ! is_array( $property_value ) ) {
89
-		$property_value = array( $property_value );
88
+	if ( ! is_array($property_value)) {
89
+		$property_value = array($property_value);
90 90
 	}
91 91
 
92
-	$old_values = wl_schema_get_value( $post_id, $property_name );
92
+	$old_values = wl_schema_get_value($post_id, $property_name);
93 93
 
94
-	$merged_property_value = array_unique( array_merge( $property_value, $old_values ) );
94
+	$merged_property_value = array_unique(array_merge($property_value, $old_values));
95 95
 
96
-	wl_schema_set_value( $post_id, $property_name, $merged_property_value );
96
+	wl_schema_set_value($post_id, $property_name, $merged_property_value);
97 97
 }
98 98
 
99 99
 /**
@@ -105,33 +105,33 @@  discard block
 block discarded – undo
105 105
  *
106 106
  * @return boolean The method returns true if everything went ok, an error string otherwise.
107 107
  */
108
-function wl_schema_set_value( $post_id, $property_name, $property_value ) {
108
+function wl_schema_set_value($post_id, $property_name, $property_value) {
109 109
 
110 110
 	// Some checks on the parameters
111
-	if ( ! is_numeric( $post_id ) || is_null( $property_name ) || empty( $property_value ) || is_null( $property_value ) ) {
111
+	if ( ! is_numeric($post_id) || is_null($property_name) || empty($property_value) || is_null($property_value)) {
112 112
 		return FALSE;
113 113
 	}
114 114
 
115 115
 	// Build full schema uri if necessary
116
-	$property_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
116
+	$property_name = wl_build_full_schema_uri_from_schema_slug($property_name);
117 117
 
118 118
 	// Get accepted properties
119
-	$accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id );
119
+	$accepted_fields = wl_entity_taxonomy_get_custom_fields($post_id);
120 120
 
121 121
 	// Find the name of the custom-field managing the schema property
122
-	foreach ( $accepted_fields as $wl_constant => $field ) {
123
-		if ( $field['predicate'] == $property_name ) {
122
+	foreach ($accepted_fields as $wl_constant => $field) {
123
+		if ($field['predicate'] == $property_name) {
124 124
 
125 125
 			// Deal with single values
126
-			if ( ! is_array( $property_value ) ) {
127
-				$property_value = array( $property_value );
126
+			if ( ! is_array($property_value)) {
127
+				$property_value = array($property_value);
128 128
 			}
129 129
 
130 130
 			// Delete present meta
131
-			delete_post_meta( $post_id, $wl_constant );
131
+			delete_post_meta($post_id, $wl_constant);
132 132
 
133
-			foreach ( $property_value as $value ) {
134
-				add_post_meta( $post_id, $wl_constant, $value );
133
+			foreach ($property_value as $value) {
134
+				add_post_meta($post_id, $wl_constant, $value);
135 135
 			}
136 136
 
137 137
 			return TRUE;
@@ -150,17 +150,17 @@  discard block
 block discarded – undo
150 150
  * @return array Array of type(s) (e.g. Type, for the http://schema.org/Type)
151 151
  * or NULL in case of no values (or error).
152 152
  */
153
-function wl_schema_get_types( $post_id ) {
153
+function wl_schema_get_types($post_id) {
154 154
 
155 155
 	// Some checks on the parameters
156
-	if ( ! is_numeric( $post_id ) ) {
156
+	if ( ! is_numeric($post_id)) {
157 157
 		return NULL;
158 158
 	}
159 159
 
160
-	$type = wl_entity_type_taxonomy_get_type( $post_id );
160
+	$type = wl_entity_type_taxonomy_get_type($post_id);
161 161
 
162
-	if ( isset( $type['uri'] ) ) {
163
-		return array( $type['uri'] );
162
+	if (isset($type['uri'])) {
163
+		return array($type['uri']);
164 164
 	}
165 165
 
166 166
 	return NULL;
@@ -174,26 +174,26 @@  discard block
 block discarded – undo
174 174
  *
175 175
  * @return boolean True if everything went ok, an error string otherwise.
176 176
  */
177
-function wl_schema_set_types( $post_id, $type_names ) {
177
+function wl_schema_set_types($post_id, $type_names) {
178 178
 
179 179
 	// Some checks on the parameters
180
-	if ( ! is_numeric( $post_id ) || empty( $type_names ) || is_null( $type_names ) ) {
180
+	if ( ! is_numeric($post_id) || empty($type_names) || is_null($type_names)) {
181 181
 		return NULL;
182 182
 	}
183 183
 
184 184
 	// TODO: support more than one type
185
-	if ( is_array( $type_names ) ) {
185
+	if (is_array($type_names)) {
186 186
 		$type_names = $type_names[0];
187 187
 	}
188 188
 
189 189
 	// Get the schema URI (e.g. http://schema.org/Thing)
190
-	$type_names = wl_build_full_schema_uri_from_schema_slug( $type_names );
190
+	$type_names = wl_build_full_schema_uri_from_schema_slug($type_names);
191 191
 
192
-	Wordlift_Log_Service::get_logger( 'wl_schema_set_types' )
193
-	                    ->debug( "[ type names :: $type_names ]" );
192
+	Wordlift_Log_Service::get_logger('wl_schema_set_types')
193
+	                    ->debug("[ type names :: $type_names ]");
194 194
 
195 195
 	// Actually sets the taxonomy type
196
-	wl_set_entity_main_type( $post_id, $type_names );
196
+	wl_set_entity_main_type($post_id, $type_names);
197 197
 
198 198
 }
199 199
 
@@ -207,10 +207,10 @@  discard block
 block discarded – undo
207 207
  * @return array The method returns an array of supported properties for the type, e.g. (‘startDate’, ‘endDate’) for an Event.
208 208
  * You can call wl_schema_get_property_expected_type on each to know which data type they expect.
209 209
  */
210
-function wl_schema_get_type_properties( $type_name ) {
210
+function wl_schema_get_type_properties($type_name) {
211 211
 
212 212
 	// Build full schema uri if necessary
213
-	$type_name = wl_build_full_schema_uri_from_schema_slug( $type_name );
213
+	$type_name = wl_build_full_schema_uri_from_schema_slug($type_name);
214 214
 
215 215
 	// Get all custom fields
216 216
 	$all_types_and_fields = wl_entity_taxonomy_get_custom_fields();
@@ -219,10 +219,10 @@  discard block
 block discarded – undo
219 219
 	$type_properties     = array();
220 220
 
221 221
 	// Search for the entity type which has the requested name as uri
222
-	if ( isset( $all_types_and_fields[ $type_name ] ) ) {
223
-		foreach ( $all_types_and_fields[ $type_name ] as $field ) {
222
+	if (isset($all_types_and_fields[$type_name])) {
223
+		foreach ($all_types_and_fields[$type_name] as $field) {
224 224
 			// Convert to schema slug and store in array
225
-			$type_properties[] = str_replace( $schema_root_address, '', $field['predicate'] );
225
+			$type_properties[] = str_replace($schema_root_address, '', $field['predicate']);
226 226
 		}
227 227
 	}
228 228
 
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
  *
237 237
  * @return string The full schema uri (es. 'latitude' returns 'http://schema.org/latitude')
238 238
  */
239
-function wl_build_full_schema_uri_from_schema_slug( $schema_name ) {
239
+function wl_build_full_schema_uri_from_schema_slug($schema_name) {
240 240
 
241 241
 	$schema_root_address = 'http://schema.org/';
242 242
 
243
-	if ( strpos( $schema_name, $schema_root_address ) === FALSE ) {   // === necessary
244
-		$schema_name = $schema_root_address . $schema_name;
243
+	if (strpos($schema_name, $schema_root_address) === FALSE) {   // === necessary
244
+		$schema_name = $schema_root_address.$schema_name;
245 245
 	}
246 246
 
247 247
 	return $schema_name;
Please login to merge, or discard this patch.
src/shortcodes/wordlift_shortcode_geomap.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -160,7 +160,6 @@
 block discarded – undo
160 160
  * @uses wl_shortcode_geomap_get_places() in order to retrieve places
161 161
  * @uses wl_shortcode_geomap_prepare_map() in order to encode retireved places in a Leaflet friendly format
162 162
  *
163
- * @param array $places An array of place posts.
164 163
  *
165 164
  * @return array An array of place posts.
166 165
  */
Please login to merge, or discard this patch.
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -14,56 +14,56 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wl_shortcode_geomap_get_places( $post_id = null ) {
16 16
 
17
-	// If $post_id is null or is not numeric it means this is a global geomap
18
-	$is_global = is_null( $post_id ) || ! is_numeric( $post_id );
17
+    // If $post_id is null or is not numeric it means this is a global geomap
18
+    $is_global = is_null( $post_id ) || ! is_numeric( $post_id );
19 19
 
20
-	// If the current one is not a global geomap, retrieve related entities ids
21
-	if ( $is_global ) {
22
-		$related_ids = array();
23
-	} else {
24
-		$related_ids = wl_core_get_related_entity_ids( $post_id, array(
25
-			'status' => 'publish'
26
-		) );
20
+    // If the current one is not a global geomap, retrieve related entities ids
21
+    if ( $is_global ) {
22
+        $related_ids = array();
23
+    } else {
24
+        $related_ids = wl_core_get_related_entity_ids( $post_id, array(
25
+            'status' => 'publish'
26
+        ) );
27 27
 		
28
-		// Also include current entity
29
-		if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) {
30
-			$related_ids[] = $post_id;
31
-		}
32
-	}
28
+        // Also include current entity
29
+        if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) {
30
+            $related_ids[] = $post_id;
31
+        }
32
+    }
33 33
 
34
-	// If is not a global geomap, an empty $related_ids means that no entities are related to the post
35
-	// An empty array can be returned in this case
36
-	if ( ! $is_global && empty( $related_ids ) ) {
37
-		return array();
38
-	}
34
+    // If is not a global geomap, an empty $related_ids means that no entities are related to the post
35
+    // An empty array can be returned in this case
36
+    if ( ! $is_global && empty( $related_ids ) ) {
37
+        return array();
38
+    }
39 39
 
40
-	// Retrieve all 'published' places with geo coordinates defined
41
-	// If $related_ids is not empty, it's used to limit query results to the current post related places
42
-	// Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query
43
-	return get_posts( array(
44
-		'post__in'    => $related_ids,
45
-		'post_type'   => Wordlift_Entity_Service::TYPE_NAME,
46
-		'nopaging'    => true,
47
-		'post_status' => 'publish',
48
-		'meta_query'  => array(
49
-			'relation' => 'AND',
50
-			array(
51
-				'key'     => Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
52
-				'value'   => null,
53
-				'compare' => '!=',
54
-			),
55
-			array(
56
-				'key'     => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
57
-				'value'   => null,
58
-				'compare' => '!=',
59
-			)
60
-		),
61
-		'tax_query'      => array(
62
-			'taxonomy' => Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
63
-			'field'    => 'slug',
64
-			'terms'    => 'place'
65
-		)
66
-	) );
40
+    // Retrieve all 'published' places with geo coordinates defined
41
+    // If $related_ids is not empty, it's used to limit query results to the current post related places
42
+    // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query
43
+    return get_posts( array(
44
+        'post__in'    => $related_ids,
45
+        'post_type'   => Wordlift_Entity_Service::TYPE_NAME,
46
+        'nopaging'    => true,
47
+        'post_status' => 'publish',
48
+        'meta_query'  => array(
49
+            'relation' => 'AND',
50
+            array(
51
+                'key'     => Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
52
+                'value'   => null,
53
+                'compare' => '!=',
54
+            ),
55
+            array(
56
+                'key'     => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
57
+                'value'   => null,
58
+                'compare' => '!=',
59
+            )
60
+        ),
61
+        'tax_query'      => array(
62
+            'taxonomy' => Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
63
+            'field'    => 'slug',
64
+            'terms'    => 'place'
65
+        )
66
+    ) );
67 67
 }
68 68
 
69 69
 /**
@@ -78,88 +78,88 @@  discard block
 block discarded – undo
78 78
  */
79 79
 function wl_shortcode_geomap_prepare_map( $places ) {
80 80
 
81
-	// Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript.
82
-	$min_latitude  = PHP_INT_MAX;
83
-	$min_longitude = PHP_INT_MAX;
84
-	$max_latitude  = ~PHP_INT_MAX;
85
-	$max_longitude = ~PHP_INT_MAX;
81
+    // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript.
82
+    $min_latitude  = PHP_INT_MAX;
83
+    $min_longitude = PHP_INT_MAX;
84
+    $max_latitude  = ~PHP_INT_MAX;
85
+    $max_longitude = ~PHP_INT_MAX;
86 86
 
87
-	// Prepare an empty array of POIs in geoJSON format.
88
-	$pois = array();
89
-	// And store list of points to allow Leaflet compute the optimal bounding box.
90
-	// The main reason for this is that geoJSON has swapped coordinates (lon. lat)
91
-	$boundaries = array();
87
+    // Prepare an empty array of POIs in geoJSON format.
88
+    $pois = array();
89
+    // And store list of points to allow Leaflet compute the optimal bounding box.
90
+    // The main reason for this is that geoJSON has swapped coordinates (lon. lat)
91
+    $boundaries = array();
92 92
 
93
-	// Add a POI for each entity that has coordinates.
94
-	foreach ( $places as $entity ) {
93
+    // Add a POI for each entity that has coordinates.
94
+    foreach ( $places as $entity ) {
95 95
 
96
-		// Get the coordinates.
97
-		$coordinates = wl_get_coordinates( $entity->ID );
96
+        // Get the coordinates.
97
+        $coordinates = wl_get_coordinates( $entity->ID );
98 98
 
99
-		// Don't show the widget if the coordinates aren't set.
100
-		if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) {
101
-			continue;
102
-		}
99
+        // Don't show the widget if the coordinates aren't set.
100
+        if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) {
101
+            continue;
102
+        }
103 103
 
104
-		// TODO Map html rendering should be delegated to the wordlift js ui layer
105
-		// This function should be focused on returning pure data instead
104
+        // TODO Map html rendering should be delegated to the wordlift js ui layer
105
+        // This function should be focused on returning pure data instead
106 106
 
107
-		// Get the title, URL and thumb of the entity.
108
-		$title = esc_attr( $entity->post_title );
109
-		$link  = esc_attr( get_permalink( $entity->ID ) );
110
-		if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) &&
111
-		     false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) )
112
-		) {
113
-			$img_src = esc_attr( $attachment[0] );
114
-		}
107
+        // Get the title, URL and thumb of the entity.
108
+        $title = esc_attr( $entity->post_title );
109
+        $link  = esc_attr( get_permalink( $entity->ID ) );
110
+        if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) &&
111
+             false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) )
112
+        ) {
113
+            $img_src = esc_attr( $attachment[0] );
114
+        }
115 115
 
116
-		// Build HTML popup. TODO: move thumb width in css
117
-		$content = "<a href=$link><h6>$title</h6>";
118
-		if ( isset( $img_src ) ) {
119
-			$content = $content . "<img src=$img_src style='width:100%'/>";
120
-		}
121
-		$content = $content . "</a><ul>";
122
-		// Get the related posts (published) and print them in the popup.
123
-		$related_posts = wl_core_get_related_post_ids( $entity->ID, array(
124
-			'status' => 'publish'
125
-		) );
126
-		foreach ( $related_posts as $rp_id ) {
116
+        // Build HTML popup. TODO: move thumb width in css
117
+        $content = "<a href=$link><h6>$title</h6>";
118
+        if ( isset( $img_src ) ) {
119
+            $content = $content . "<img src=$img_src style='width:100%'/>";
120
+        }
121
+        $content = $content . "</a><ul>";
122
+        // Get the related posts (published) and print them in the popup.
123
+        $related_posts = wl_core_get_related_post_ids( $entity->ID, array(
124
+            'status' => 'publish'
125
+        ) );
126
+        foreach ( $related_posts as $rp_id ) {
127 127
 
128
-			$rp      = get_post( $rp_id );
129
-			$title   = esc_attr( $rp->post_title );
130
-			$link    = esc_attr( get_permalink( $rp->ID ) );
131
-			$content = $content . "<li><a href=$link>$title</a></li>";
132
-		}
133
-		$content = $content . "</ul>";
128
+            $rp      = get_post( $rp_id );
129
+            $title   = esc_attr( $rp->post_title );
130
+            $link    = esc_attr( get_permalink( $rp->ID ) );
131
+            $content = $content . "<li><a href=$link>$title</a></li>";
132
+        }
133
+        $content = $content . "</ul>";
134 134
 
135
-		// Formatting POI in geoJSON.
136
-		// http://leafletjs.com/examples/geojson.html
137
-		$poi = array(
138
-			'type'       => 'Feature',
139
-			'properties' => array( 'popupContent' => $content ),
140
-			'geometry'   => array(
141
-				'type'        => 'Point',
142
-				'coordinates' => array(
143
-					// Leaflet geoJSON wants them swapped
144
-					$coordinates['longitude'],
145
-					$coordinates['latitude']
146
-				)
147
-			)
148
-		);
135
+        // Formatting POI in geoJSON.
136
+        // http://leafletjs.com/examples/geojson.html
137
+        $poi = array(
138
+            'type'       => 'Feature',
139
+            'properties' => array( 'popupContent' => $content ),
140
+            'geometry'   => array(
141
+                'type'        => 'Point',
142
+                'coordinates' => array(
143
+                    // Leaflet geoJSON wants them swapped
144
+                    $coordinates['longitude'],
145
+                    $coordinates['latitude']
146
+                )
147
+            )
148
+        );
149 149
 
150
-		$pois[] = $poi;
150
+        $pois[] = $poi;
151 151
 
152
-		// Formatting boundaries in a Leaflet-like format (see LatLngBounds).
153
-		// http://leafletjs.com/reference.html#latlngbounds
154
-		$boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] );
152
+        // Formatting boundaries in a Leaflet-like format (see LatLngBounds).
153
+        // http://leafletjs.com/reference.html#latlngbounds
154
+        $boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] );
155 155
 
156
-	}
156
+    }
157 157
 
158
-	$map_data               = array();
159
-	$map_data['features']   = $pois;
160
-	$map_data['boundaries'] = $boundaries;
158
+    $map_data               = array();
159
+    $map_data['features']   = $pois;
160
+    $map_data['boundaries'] = $boundaries;
161 161
 
162
-	return $map_data;
162
+    return $map_data;
163 163
 }
164 164
 
165 165
 /**
@@ -173,13 +173,13 @@  discard block
 block discarded – undo
173 173
  * @return array An array of place posts.
174 174
  */
175 175
 function wl_shortcode_geomap_ajax() {
176
-	// Get the post Id.
177
-	$post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null );
176
+    // Get the post Id.
177
+    $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null );
178 178
 
179
-	$places   = wl_shortcode_geomap_get_places( $post_id );
180
-	$map_data = wl_shortcode_geomap_prepare_map( $places );
179
+    $places   = wl_shortcode_geomap_get_places( $post_id );
180
+    $map_data = wl_shortcode_geomap_prepare_map( $places );
181 181
 
182
-	wl_core_send_json( $map_data );
182
+    wl_core_send_json( $map_data );
183 183
 }
184 184
 
185 185
 add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' );
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -12,35 +12,35 @@  discard block
 block discarded – undo
12 12
  *
13 13
  * @return array An array of place posts.
14 14
  */
15
-function wl_shortcode_geomap_get_places( $post_id = null ) {
15
+function wl_shortcode_geomap_get_places($post_id = null) {
16 16
 
17 17
 	// If $post_id is null or is not numeric it means this is a global geomap
18
-	$is_global = is_null( $post_id ) || ! is_numeric( $post_id );
18
+	$is_global = is_null($post_id) || ! is_numeric($post_id);
19 19
 
20 20
 	// If the current one is not a global geomap, retrieve related entities ids
21
-	if ( $is_global ) {
21
+	if ($is_global) {
22 22
 		$related_ids = array();
23 23
 	} else {
24
-		$related_ids = wl_core_get_related_entity_ids( $post_id, array(
24
+		$related_ids = wl_core_get_related_entity_ids($post_id, array(
25 25
 			'status' => 'publish'
26
-		) );
26
+		));
27 27
 		
28 28
 		// Also include current entity
29
-		if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) {
29
+		if (Wordlift_Entity_Service::get_instance()->is_entity($post_id)) {
30 30
 			$related_ids[] = $post_id;
31 31
 		}
32 32
 	}
33 33
 
34 34
 	// If is not a global geomap, an empty $related_ids means that no entities are related to the post
35 35
 	// An empty array can be returned in this case
36
-	if ( ! $is_global && empty( $related_ids ) ) {
36
+	if ( ! $is_global && empty($related_ids)) {
37 37
 		return array();
38 38
 	}
39 39
 
40 40
 	// Retrieve all 'published' places with geo coordinates defined
41 41
 	// If $related_ids is not empty, it's used to limit query results to the current post related places
42 42
 	// Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query
43
-	return get_posts( array(
43
+	return get_posts(array(
44 44
 		'post__in'    => $related_ids,
45 45
 		'post_type'   => Wordlift_Entity_Service::TYPE_NAME,
46 46
 		'nopaging'    => true,
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 			'field'    => 'slug',
64 64
 			'terms'    => 'place'
65 65
 		)
66
-	) );
66
+	));
67 67
 }
68 68
 
69 69
 /**
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
  *
77 77
  * @return array An array of markers and boundaries for Leaflet.
78 78
  */
79
-function wl_shortcode_geomap_prepare_map( $places ) {
79
+function wl_shortcode_geomap_prepare_map($places) {
80 80
 
81 81
 	// Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript.
82 82
 	$min_latitude  = PHP_INT_MAX;
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
 	$boundaries = array();
92 92
 
93 93
 	// Add a POI for each entity that has coordinates.
94
-	foreach ( $places as $entity ) {
94
+	foreach ($places as $entity) {
95 95
 
96 96
 		// Get the coordinates.
97
-		$coordinates = wl_get_coordinates( $entity->ID );
97
+		$coordinates = wl_get_coordinates($entity->ID);
98 98
 
99 99
 		// Don't show the widget if the coordinates aren't set.
100
-		if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) {
100
+		if ($coordinates['latitude'] == 0 || $coordinates['longitude'] == 0) {
101 101
 			continue;
102 102
 		}
103 103
 
@@ -105,38 +105,38 @@  discard block
 block discarded – undo
105 105
 		// This function should be focused on returning pure data instead
106 106
 
107 107
 		// Get the title, URL and thumb of the entity.
108
-		$title = esc_attr( $entity->post_title );
109
-		$link  = esc_attr( get_permalink( $entity->ID ) );
110
-		if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) &&
111
-		     false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) )
108
+		$title = esc_attr($entity->post_title);
109
+		$link  = esc_attr(get_permalink($entity->ID));
110
+		if ('' !== ($thumbnail_id = get_post_thumbnail_id($entity->ID)) &&
111
+		     false !== ($attachment = wp_get_attachment_image_src($thumbnail_id))
112 112
 		) {
113
-			$img_src = esc_attr( $attachment[0] );
113
+			$img_src = esc_attr($attachment[0]);
114 114
 		}
115 115
 
116 116
 		// Build HTML popup. TODO: move thumb width in css
117 117
 		$content = "<a href=$link><h6>$title</h6>";
118
-		if ( isset( $img_src ) ) {
119
-			$content = $content . "<img src=$img_src style='width:100%'/>";
118
+		if (isset($img_src)) {
119
+			$content = $content."<img src=$img_src style='width:100%'/>";
120 120
 		}
121
-		$content = $content . "</a><ul>";
121
+		$content = $content."</a><ul>";
122 122
 		// Get the related posts (published) and print them in the popup.
123
-		$related_posts = wl_core_get_related_post_ids( $entity->ID, array(
123
+		$related_posts = wl_core_get_related_post_ids($entity->ID, array(
124 124
 			'status' => 'publish'
125
-		) );
126
-		foreach ( $related_posts as $rp_id ) {
125
+		));
126
+		foreach ($related_posts as $rp_id) {
127 127
 
128
-			$rp      = get_post( $rp_id );
129
-			$title   = esc_attr( $rp->post_title );
130
-			$link    = esc_attr( get_permalink( $rp->ID ) );
131
-			$content = $content . "<li><a href=$link>$title</a></li>";
128
+			$rp      = get_post($rp_id);
129
+			$title   = esc_attr($rp->post_title);
130
+			$link    = esc_attr(get_permalink($rp->ID));
131
+			$content = $content."<li><a href=$link>$title</a></li>";
132 132
 		}
133
-		$content = $content . "</ul>";
133
+		$content = $content."</ul>";
134 134
 
135 135
 		// Formatting POI in geoJSON.
136 136
 		// http://leafletjs.com/examples/geojson.html
137 137
 		$poi = array(
138 138
 			'type'       => 'Feature',
139
-			'properties' => array( 'popupContent' => $content ),
139
+			'properties' => array('popupContent' => $content),
140 140
 			'geometry'   => array(
141 141
 				'type'        => 'Point',
142 142
 				'coordinates' => array(
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 
152 152
 		// Formatting boundaries in a Leaflet-like format (see LatLngBounds).
153 153
 		// http://leafletjs.com/reference.html#latlngbounds
154
-		$boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] );
154
+		$boundaries[] = array($coordinates['latitude'], $coordinates['longitude']);
155 155
 
156 156
 	}
157 157
 
@@ -174,16 +174,16 @@  discard block
 block discarded – undo
174 174
  */
175 175
 function wl_shortcode_geomap_ajax() {
176 176
 	// Get the post Id.
177
-	$post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null );
177
+	$post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : null);
178 178
 
179
-	$places   = wl_shortcode_geomap_get_places( $post_id );
180
-	$map_data = wl_shortcode_geomap_prepare_map( $places );
179
+	$places   = wl_shortcode_geomap_get_places($post_id);
180
+	$map_data = wl_shortcode_geomap_prepare_map($places);
181 181
 
182
-	wl_core_send_json( $map_data );
182
+	wl_core_send_json($map_data);
183 183
 }
184 184
 
185
-add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' );
186
-add_action( 'wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax' );
185
+add_action('wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax');
186
+add_action('wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax');
187 187
 
188 188
 ///**
189 189
 // * Print geomap shortcode
Please login to merge, or discard this patch.
src/wordlift.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@
 block discarded – undo
93 93
  *
94 94
  * @since 3.0.0
95 95
  *
96
- * @param $text string A text that may potentially contain a WL key.
96
+ * @param string $text string A text that may potentially contain a WL key.
97 97
  *
98 98
  * @return string A text with the key hidden.
99 99
  */
Please login to merge, or discard this patch.
Indentation   +249 added lines, -249 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,11 +170,11 @@  discard block
 block discarded – undo
170 170
  */
171 171
 function wordlift_register_tinymce_javascript( $plugin_array ) {
172 172
 
173
-	// add the wordlift plugin.
174
-	// We can't use the minified version here.
175
-	$plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
173
+    // add the wordlift plugin.
174
+    // We can't use the minified version here.
175
+    $plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
176 176
 
177
-	return $plugin_array;
177
+    return $plugin_array;
178 178
 }
179 179
 
180 180
 /**
@@ -182,21 +182,21 @@  discard block
 block discarded – undo
182 182
  * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
183 183
  */
184 184
 function wordlift_allowed_post_tags() {
185
-	global $allowedposttags;
186
-
187
-	$tags           = array( 'span' );
188
-	$new_attributes = array(
189
-		'itemscope' => array(),
190
-		'itemtype'  => array(),
191
-		'itemprop'  => array(),
192
-		'itemid'    => array(),
193
-	);
194
-
195
-	foreach ( $tags as $tag ) {
196
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
197
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
198
-		}
199
-	}
185
+    global $allowedposttags;
186
+
187
+    $tags           = array( 'span' );
188
+    $new_attributes = array(
189
+        'itemscope' => array(),
190
+        'itemtype'  => array(),
191
+        'itemprop'  => array(),
192
+        'itemid'    => array(),
193
+    );
194
+
195
+    foreach ( $tags as $tag ) {
196
+        if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
197
+            $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
198
+        }
199
+    }
200 200
 }
201 201
 
202 202
 // init process for button control
@@ -210,28 +210,28 @@  discard block
 block discarded – undo
210 210
  */
211 211
 function wordlift_admin_enqueue_scripts() {
212 212
 
213
-	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
214
-	wp_enqueue_script( 'wpdialogs' );
215
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
213
+    // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
214
+    wp_enqueue_script( 'wpdialogs' );
215
+    wp_enqueue_style( 'wp-jquery-ui-dialog' );
216 216
 
217
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
217
+    wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
218 218
 
219
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
220
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
221
-	wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . '/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' );
222
-	wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
223
-	wp_enqueue_script( 'angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js' );
219
+    wp_enqueue_script( 'jquery-ui-autocomplete' );
220
+    wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
221
+    wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . '/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' );
222
+    wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
223
+    wp_enqueue_script( 'angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js' );
224 224
 
225
-	// Disable auto-save for custom entity posts only
226
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
227
-		wp_dequeue_script( 'autosave' );
228
-	}
225
+    // Disable auto-save for custom entity posts only
226
+    if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
227
+        wp_dequeue_script( 'autosave' );
228
+    }
229 229
 }
230 230
 
231 231
 add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
232 232
 
233 233
 function wl_enqueue_scripts() {
234
-	wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
234
+    wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
235 235
 }
236 236
 
237 237
 add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' );
@@ -246,18 +246,18 @@  discard block
 block discarded – undo
246 246
  */
247 247
 function wordlift_allowed_html( $allowedtags, $context ) {
248 248
 
249
-	if ( 'post' !== $context ) {
250
-		return $allowedtags;
251
-	}
252
-
253
-	return array_merge_recursive( $allowedtags, array(
254
-		'span' => array(
255
-			'itemscope' => TRUE,
256
-			'itemtype'  => TRUE,
257
-			'itemid'    => TRUE,
258
-			'itemprop'  => TRUE,
259
-		),
260
-	) );
249
+    if ( 'post' !== $context ) {
250
+        return $allowedtags;
251
+    }
252
+
253
+    return array_merge_recursive( $allowedtags, array(
254
+        'span' => array(
255
+            'itemscope' => TRUE,
256
+            'itemtype'  => TRUE,
257
+            'itemid'    => TRUE,
258
+            'itemprop'  => TRUE,
259
+        ),
260
+    ) );
261 261
 }
262 262
 
263 263
 add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
@@ -271,15 +271,15 @@  discard block
 block discarded – undo
271 271
  */
272 272
 function wl_get_coordinates( $post_id ) {
273 273
 
274
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
275
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
274
+    $latitude  = wl_schema_get_value( $post_id, 'latitude' );
275
+    $longitude = wl_schema_get_value( $post_id, 'longitude' );
276 276
 
277
-	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
278
-	// "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
279
-	return array(
280
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
281
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
282
-	);
277
+    // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
278
+    // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
279
+    return array(
280
+        'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
281
+        'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
282
+    );
283 283
 }
284 284
 
285 285
 /**
@@ -291,13 +291,13 @@  discard block
 block discarded – undo
291 291
  */
292 292
 function wl_get_post_modified_time( $post ) {
293 293
 
294
-	$date_modified = get_post_modified_time( 'c', TRUE, $post );
294
+    $date_modified = get_post_modified_time( 'c', TRUE, $post );
295 295
 
296
-	if ( '-' === substr( $date_modified, 0, 1 ) ) {
297
-		return get_the_time( 'c', $post );
298
-	}
296
+    if ( '-' === substr( $date_modified, 0, 1 ) ) {
297
+        return get_the_time( 'c', $post );
298
+    }
299 299
 
300
-	return $date_modified;
300
+    return $date_modified;
301 301
 }
302 302
 
303 303
 /**
@@ -310,42 +310,42 @@  discard block
 block discarded – undo
310 310
 function wl_get_image_urls( $post_id ) {
311 311
 
312 312
 
313
-	// If there is a featured image it has the priority
314
-	$featured_image_id = get_post_thumbnail_id( $post_id );
315
-	if ( is_numeric( $featured_image_id ) ) {
316
-		$image_url = wp_get_attachment_url( $featured_image_id );
313
+    // If there is a featured image it has the priority
314
+    $featured_image_id = get_post_thumbnail_id( $post_id );
315
+    if ( is_numeric( $featured_image_id ) ) {
316
+        $image_url = wp_get_attachment_url( $featured_image_id );
317 317
 
318
-		return array( $image_url );
319
-	}
318
+        return array( $image_url );
319
+    }
320 320
 
321
-	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
321
+    // wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
322 322
 
323
-	$images = get_children( array(
324
-		'post_parent'    => $post_id,
325
-		'post_type'      => 'attachment',
326
-		'post_mime_type' => 'image',
327
-	) );
323
+    $images = get_children( array(
324
+        'post_parent'    => $post_id,
325
+        'post_type'      => 'attachment',
326
+        'post_mime_type' => 'image',
327
+    ) );
328 328
 
329
-	// Return an empty array if no image is found.
330
-	if ( empty( $images ) ) {
331
-		return array();
332
-	}
329
+    // Return an empty array if no image is found.
330
+    if ( empty( $images ) ) {
331
+        return array();
332
+    }
333 333
 
334
-	// Prepare the return array.
335
-	$image_urls = array();
334
+    // Prepare the return array.
335
+    $image_urls = array();
336 336
 
337
-	// Collect the URLs.
338
-	foreach ( $images as $attachment_id => $attachment ) {
339
-		$image_url = wp_get_attachment_url( $attachment_id );
340
-		// Ensure the URL isn't collected already.
341
-		if ( ! in_array( $image_url, $image_urls ) ) {
342
-			array_push( $image_urls, $image_url );
343
-		}
344
-	}
337
+    // Collect the URLs.
338
+    foreach ( $images as $attachment_id => $attachment ) {
339
+        $image_url = wp_get_attachment_url( $attachment_id );
340
+        // Ensure the URL isn't collected already.
341
+        if ( ! in_array( $image_url, $image_urls ) ) {
342
+            array_push( $image_urls, $image_url );
343
+        }
344
+    }
345 345
 
346
-	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" );
346
+    // wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" );
347 347
 
348
-	return $image_urls;
348
+    return $image_urls;
349 349
 }
350 350
 
351 351
 /**
@@ -358,19 +358,19 @@  discard block
 block discarded – undo
358 358
  */
359 359
 function wl_get_sparql_images( $uri, $post_id ) {
360 360
 
361
-	$sparql = '';
361
+    $sparql = '';
362 362
 
363
-	// Get the escaped URI.
364
-	$uri_e = esc_html( $uri );
363
+    // Get the escaped URI.
364
+    $uri_e = esc_html( $uri );
365 365
 
366
-	// Add SPARQL stmts to write the schema:image.
367
-	$image_urls = wl_get_image_urls( $post_id );
368
-	foreach ( $image_urls as $image_url ) {
369
-		$image_url_esc = wl_sparql_escape_uri( $image_url );
370
-		$sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
371
-	}
366
+    // Add SPARQL stmts to write the schema:image.
367
+    $image_urls = wl_get_image_urls( $post_id );
368
+    foreach ( $image_urls as $image_url ) {
369
+        $image_url_esc = wl_sparql_escape_uri( $image_url );
370
+        $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
371
+    }
372 372
 
373
-	return $sparql;
373
+    return $sparql;
374 374
 }
375 375
 
376 376
 /**
@@ -383,24 +383,24 @@  discard block
 block discarded – undo
383 383
  */
384 384
 function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
385 385
 
386
-	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
386
+    // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
387 387
 
388
-	$posts = get_posts( array(
389
-		'post_type'      => 'attachment',
390
-		'posts_per_page' => 1,
391
-		'post_status'    => 'any',
392
-		'post_parent'    => $parent_post_id,
393
-		'meta_key'       => 'wl_source_url',
394
-		'meta_value'     => $source_url,
395
-	) );
388
+    $posts = get_posts( array(
389
+        'post_type'      => 'attachment',
390
+        'posts_per_page' => 1,
391
+        'post_status'    => 'any',
392
+        'post_parent'    => $parent_post_id,
393
+        'meta_key'       => 'wl_source_url',
394
+        'meta_value'     => $source_url,
395
+    ) );
396 396
 
397
-	// Return the found post.
398
-	if ( 1 === count( $posts ) ) {
399
-		return $posts[0];
400
-	}
397
+    // Return the found post.
398
+    if ( 1 === count( $posts ) ) {
399
+        return $posts[0];
400
+    }
401 401
 
402
-	// Return null.
403
-	return NULL;
402
+    // Return null.
403
+    return NULL;
404 404
 }
405 405
 
406 406
 /**
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
  */
412 412
 function wl_set_source_url( $post_id, $source_url ) {
413 413
 
414
-	delete_post_meta( $post_id, 'wl_source_url' );
415
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
414
+    delete_post_meta( $post_id, 'wl_source_url' );
415
+    add_post_meta( $post_id, 'wl_source_url', $source_url );
416 416
 }
417 417
 
418 418
 
@@ -430,61 +430,61 @@  discard block
 block discarded – undo
430 430
  */
431 431
 function wl_flush_rewrite_rules_hard( $hard ) {
432 432
 
433
-	// If WL is not yet configured, we cannot perform any update, so we exit.
434
-	if ( '' === wl_configuration_get_key() ) {
435
-		return;
436
-	}
433
+    // If WL is not yet configured, we cannot perform any update, so we exit.
434
+    if ( '' === wl_configuration_get_key() ) {
435
+        return;
436
+    }
437 437
 
438
-	// Set the initial offset and limit each call to 100 posts to avoid memory errors.
439
-	$offset = 0;
440
-	$limit  = 100;
438
+    // Set the initial offset and limit each call to 100 posts to avoid memory errors.
439
+    $offset = 0;
440
+    $limit  = 100;
441 441
 
442
-	// Get more posts if the number of returned posts matches the limit.
443
-	while ( $limit === ( $posts = get_posts( array(
444
-			'offset'      => $offset,
445
-			'numberposts' => $limit,
446
-			'orderby'     => 'ID',
447
-			'post_type'   => 'any',
448
-			'post_status' => 'publish',
449
-		) ) ) ) {
442
+    // Get more posts if the number of returned posts matches the limit.
443
+    while ( $limit === ( $posts = get_posts( array(
444
+            'offset'      => $offset,
445
+            'numberposts' => $limit,
446
+            'orderby'     => 'ID',
447
+            'post_type'   => 'any',
448
+            'post_status' => 'publish',
449
+        ) ) ) ) {
450 450
 
451
-		// Holds the delete part of the query.
452
-		$delete_query = rl_sparql_prefixes();
451
+        // Holds the delete part of the query.
452
+        $delete_query = rl_sparql_prefixes();
453 453
 
454
-		// Holds the insert part of the query.
455
-		$insert_query = '';
454
+        // Holds the insert part of the query.
455
+        $insert_query = '';
456 456
 
457
-		// Cycle in each post to build the query.
458
-		foreach ( $posts as $post ) {
457
+        // Cycle in each post to build the query.
458
+        foreach ( $posts as $post ) {
459 459
 
460
-			// Ignore revisions.
461
-			if ( wp_is_post_revision( $post->ID ) ) {
462
-				continue;
463
-			}
460
+            // Ignore revisions.
461
+            if ( wp_is_post_revision( $post->ID ) ) {
462
+                continue;
463
+            }
464 464
 
465
-			// Get the entity URI.
466
-			$s = Wordlift_Sparql_Service::escape_uri( Wordlift_Entity_Service::get_instance()
467
-			                                                                 ->get_uri( $post->ID ) );
465
+            // Get the entity URI.
466
+            $s = Wordlift_Sparql_Service::escape_uri( Wordlift_Entity_Service::get_instance()
467
+                                                                                ->get_uri( $post->ID ) );
468 468
 
469
-			// Get the post URL.
470
-			// $url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
469
+            // Get the post URL.
470
+            // $url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
471 471
 
472
-			// Prepare the DELETE and INSERT commands.
473
-			$delete_query .= "DELETE { <$s> schema:url ?u . } WHERE  { <$s> schema:url ?u . };\n";
472
+            // Prepare the DELETE and INSERT commands.
473
+            $delete_query .= "DELETE { <$s> schema:url ?u . } WHERE  { <$s> schema:url ?u . };\n";
474 474
 
475
-			$insert_query .= Wordlift_Schema_Url_Property_Service::get_instance()
476
-			                                                     ->get_insert_query( $s, $post->ID );
475
+            $insert_query .= Wordlift_Schema_Url_Property_Service::get_instance()
476
+                                                                    ->get_insert_query( $s, $post->ID );
477 477
 
478
-		}
478
+        }
479 479
 
480 480
 
481
-		// Execute the query.
482
-		rl_execute_sparql_update_query( $delete_query . $insert_query );
481
+        // Execute the query.
482
+        rl_execute_sparql_update_query( $delete_query . $insert_query );
483 483
 
484
-		// Advance to the next posts.
485
-		$offset += $limit;
484
+        // Advance to the next posts.
485
+        $offset += $limit;
486 486
 
487
-	}
487
+    }
488 488
 
489 489
 //	// Get all published posts.
490 490
 //	$posts = get_posts( array(
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
  */
511 511
 function wl_sanitize_uri_path( $path, $char = '_' ) {
512 512
 
513
-	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
513
+    return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
514 514
 }
515 515
 
516 516
 /**
@@ -522,11 +522,11 @@  discard block
 block discarded – undo
522 522
  */
523 523
 function wl_force_to_array( $value ) {
524 524
 
525
-	if ( ! is_array( $value ) ) {
526
-		return array( $value );
527
-	}
525
+    if ( ! is_array( $value ) ) {
526
+        return array( $value );
527
+    }
528 528
 
529
-	return $value;
529
+    return $value;
530 530
 }
531 531
 
532 532
 /**
@@ -534,26 +534,26 @@  discard block
 block discarded – undo
534 534
  */
535 535
 function wl_shutdown() {
536 536
 
537
-	// Get the filename to the temporary SPARQL file.
538
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
537
+    // Get the filename to the temporary SPARQL file.
538
+    $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
539 539
 
540
-	// If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
541
-	if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
540
+    // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
541
+    if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
542 542
 
543
-		// The request ID.
544
-		$args = array( WL_REQUEST_ID );
543
+        // The request ID.
544
+        $args = array( WL_REQUEST_ID );
545 545
 
546
-		// Schedule the execution of the SPARQL query with the request ID.
547
-		wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
546
+        // Schedule the execution of the SPARQL query with the request ID.
547
+        wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
548 548
 
549
-		// Check that the request is scheduled.
550
-		$timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
549
+        // Check that the request is scheduled.
550
+        $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
551 551
 
552
-		// Spawn the cron.
553
-		spawn_cron();
552
+        // Spawn the cron.
553
+        spawn_cron();
554 554
 
555
-		wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
556
-	}
555
+        wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
556
+    }
557 557
 }
558 558
 
559 559
 add_action( 'shutdown', 'wl_shutdown' );
@@ -567,46 +567,46 @@  discard block
 block discarded – undo
567 567
  */
568 568
 function wl_replace_item_id_with_uri( $content ) {
569 569
 
570
-	// wl_write_log( "wl_replace_item_id_with_uri" );
570
+    // wl_write_log( "wl_replace_item_id_with_uri" );
571 571
 
572
-	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
573
-	$content = stripslashes( $content );
572
+    // Strip slashes, see https://core.trac.wordpress.org/ticket/21767
573
+    $content = stripslashes( $content );
574 574
 
575
-	// If any match are found.
576
-	$matches = array();
577
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
575
+    // If any match are found.
576
+    $matches = array();
577
+    if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
578 578
 
579
-		foreach ( $matches as $match ) {
579
+        foreach ( $matches as $match ) {
580 580
 
581
-			// Get the item ID.
582
-			$item_id = $match[1];
581
+            // Get the item ID.
582
+            $item_id = $match[1];
583 583
 
584
-			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
585
-			$post = Wordlift_Entity_Service::get_instance()
586
-			                               ->get_entity_post_by_uri( $item_id );
584
+            // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
585
+            $post = Wordlift_Entity_Service::get_instance()
586
+                                            ->get_entity_post_by_uri( $item_id );
587 587
 
588
-			// If no entity is found, continue to the next one.
589
-			if ( NULL === $post ) {
590
-				continue;
591
-			}
588
+            // If no entity is found, continue to the next one.
589
+            if ( NULL === $post ) {
590
+                continue;
591
+            }
592 592
 
593
-			// Get the URI for that post.
594
-			$uri = wl_get_entity_uri( $post->ID );
593
+            // Get the URI for that post.
594
+            $uri = wl_get_entity_uri( $post->ID );
595 595
 
596
-			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
596
+            // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
597 597
 
598
-			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
599
-			if ( $item_id !== $uri ) {
600
-				$uri_e   = esc_html( $uri );
601
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
602
-			}
603
-		}
604
-	}
598
+            // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
599
+            if ( $item_id !== $uri ) {
600
+                $uri_e   = esc_html( $uri );
601
+                $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
602
+            }
603
+        }
604
+    }
605 605
 
606
-	// Reapply slashes.
607
-	$content = addslashes( $content );
606
+    // Reapply slashes.
607
+    $content = addslashes( $content );
608 608
 
609
-	return $content;
609
+    return $content;
610 610
 }
611 611
 
612 612
 add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
@@ -679,8 +679,8 @@  discard block
 block discarded – undo
679 679
  * This action is documented in includes/class-wordlift-activator.php
680 680
  */
681 681
 function activate_wordlift() {
682
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
683
-	Wordlift_Activator::activate();
682
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
683
+    Wordlift_Activator::activate();
684 684
 }
685 685
 
686 686
 /**
@@ -688,8 +688,8 @@  discard block
 block discarded – undo
688 688
  * This action is documented in includes/class-wordlift-deactivator.php
689 689
  */
690 690
 function deactivate_wordlift() {
691
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
692
-	Wordlift_Deactivator::deactivate();
691
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
692
+    Wordlift_Deactivator::deactivate();
693 693
 }
694 694
 
695 695
 register_activation_hook( __FILE__, 'activate_wordlift' );
@@ -712,8 +712,8 @@  discard block
 block discarded – undo
712 712
  */
713 713
 function run_wordlift() {
714 714
 
715
-	$plugin = new Wordlift();
716
-	$plugin->run();
715
+    $plugin = new Wordlift();
716
+    $plugin->run();
717 717
 
718 718
 }
719 719
 
Please login to merge, or discard this patch.
Spacing   +162 added lines, -162 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,11 +168,11 @@  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 174
 	// We can't use the minified version here.
175
-	$plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
175
+	$plugin_array['wordlift'] = plugin_dir_url(__FILE__).'js/wordlift-reloaded.js';
176 176
 
177 177
 	return $plugin_array;
178 178
 }
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 function wordlift_allowed_post_tags() {
185 185
 	global $allowedposttags;
186 186
 
187
-	$tags           = array( 'span' );
187
+	$tags           = array('span');
188 188
 	$new_attributes = array(
189 189
 		'itemscope' => array(),
190 190
 		'itemtype'  => array(),
@@ -192,17 +192,17 @@  discard block
 block discarded – undo
192 192
 		'itemid'    => array(),
193 193
 	);
194 194
 
195
-	foreach ( $tags as $tag ) {
196
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
197
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
195
+	foreach ($tags as $tag) {
196
+		if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) {
197
+			$allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes);
198 198
 		}
199 199
 	}
200 200
 }
201 201
 
202 202
 // init process for button control
203
-add_action( 'init', 'wordlift_buttonhooks' );
203
+add_action('init', 'wordlift_buttonhooks');
204 204
 // add allowed post tags.
205
-add_action( 'init', 'wordlift_allowed_post_tags' );
205
+add_action('init', 'wordlift_allowed_post_tags');
206 206
 
207 207
 
208 208
 /**
@@ -211,30 +211,30 @@  discard block
 block discarded – undo
211 211
 function wordlift_admin_enqueue_scripts() {
212 212
 
213 213
 	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
214
-	wp_enqueue_script( 'wpdialogs' );
215
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
214
+	wp_enqueue_script('wpdialogs');
215
+	wp_enqueue_style('wp-jquery-ui-dialog');
216 216
 
217
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
217
+	wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css');
218 218
 
219
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
220
-	wp_enqueue_script( 'angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js' );
221
-	wp_enqueue_script( 'angularjs-geolocation', plugin_dir_url( __FILE__ ) . '/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js' );
222
-	wp_enqueue_script( 'angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js' );
223
-	wp_enqueue_script( 'angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js' );
219
+	wp_enqueue_script('jquery-ui-autocomplete');
220
+	wp_enqueue_script('angularjs', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.min.js');
221
+	wp_enqueue_script('angularjs-geolocation', plugin_dir_url(__FILE__).'/bower_components/angularjs-geolocation/dist/angularjs-geolocation.min.js');
222
+	wp_enqueue_script('angularjs-touch', 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular-touch.min.js');
223
+	wp_enqueue_script('angularjs-animate', 'https://code.angularjs.org/1.3.11/angular-animate.min.js');
224 224
 
225 225
 	// Disable auto-save for custom entity posts only
226
-	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
227
-		wp_dequeue_script( 'autosave' );
226
+	if (Wordlift_Entity_Service::TYPE_NAME === get_post_type()) {
227
+		wp_dequeue_script('autosave');
228 228
 	}
229 229
 }
230 230
 
231
-add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
231
+add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts');
232 232
 
233 233
 function wl_enqueue_scripts() {
234
-	wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
234
+	wp_enqueue_style('wordlift-ui', plugin_dir_url(__FILE__).'css/wordlift-ui.min.css');
235 235
 }
236 236
 
237
-add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' );
237
+add_action('wp_enqueue_scripts', 'wl_enqueue_scripts');
238 238
 
239 239
 /**
240 240
  * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes.
@@ -244,23 +244,23 @@  discard block
 block discarded – undo
244 244
  *
245 245
  * @return array An array which contains allowed microdata attributes.
246 246
  */
247
-function wordlift_allowed_html( $allowedtags, $context ) {
247
+function wordlift_allowed_html($allowedtags, $context) {
248 248
 
249
-	if ( 'post' !== $context ) {
249
+	if ('post' !== $context) {
250 250
 		return $allowedtags;
251 251
 	}
252 252
 
253
-	return array_merge_recursive( $allowedtags, array(
253
+	return array_merge_recursive($allowedtags, array(
254 254
 		'span' => array(
255 255
 			'itemscope' => TRUE,
256 256
 			'itemtype'  => TRUE,
257 257
 			'itemid'    => TRUE,
258 258
 			'itemprop'  => TRUE,
259 259
 		),
260
-	) );
260
+	));
261 261
 }
262 262
 
263
-add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
263
+add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2);
264 264
 
265 265
 /**
266 266
  * Get the coordinates for the specified post ID.
@@ -269,16 +269,16 @@  discard block
 block discarded – undo
269 269
  *
270 270
  * @return array|null An array of coordinates or null.
271 271
  */
272
-function wl_get_coordinates( $post_id ) {
272
+function wl_get_coordinates($post_id) {
273 273
 
274
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
275
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
274
+	$latitude  = wl_schema_get_value($post_id, 'latitude');
275
+	$longitude = wl_schema_get_value($post_id, 'longitude');
276 276
 
277 277
 	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
278 278
 	// "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
279 279
 	return array(
280
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
281
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
280
+		'latitude'  => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '',
281
+		'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '',
282 282
 	);
283 283
 }
284 284
 
@@ -289,12 +289,12 @@  discard block
 block discarded – undo
289 289
  *
290 290
  * @return string A datetime.
291 291
  */
292
-function wl_get_post_modified_time( $post ) {
292
+function wl_get_post_modified_time($post) {
293 293
 
294
-	$date_modified = get_post_modified_time( 'c', TRUE, $post );
294
+	$date_modified = get_post_modified_time('c', TRUE, $post);
295 295
 
296
-	if ( '-' === substr( $date_modified, 0, 1 ) ) {
297
-		return get_the_time( 'c', $post );
296
+	if ('-' === substr($date_modified, 0, 1)) {
297
+		return get_the_time('c', $post);
298 298
 	}
299 299
 
300 300
 	return $date_modified;
@@ -307,27 +307,27 @@  discard block
 block discarded – undo
307 307
  *
308 308
  * @return array An array of image URLs.
309 309
  */
310
-function wl_get_image_urls( $post_id ) {
310
+function wl_get_image_urls($post_id) {
311 311
 
312 312
 
313 313
 	// If there is a featured image it has the priority
314
-	$featured_image_id = get_post_thumbnail_id( $post_id );
315
-	if ( is_numeric( $featured_image_id ) ) {
316
-		$image_url = wp_get_attachment_url( $featured_image_id );
314
+	$featured_image_id = get_post_thumbnail_id($post_id);
315
+	if (is_numeric($featured_image_id)) {
316
+		$image_url = wp_get_attachment_url($featured_image_id);
317 317
 
318
-		return array( $image_url );
318
+		return array($image_url);
319 319
 	}
320 320
 
321 321
 	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
322 322
 
323
-	$images = get_children( array(
323
+	$images = get_children(array(
324 324
 		'post_parent'    => $post_id,
325 325
 		'post_type'      => 'attachment',
326 326
 		'post_mime_type' => 'image',
327
-	) );
327
+	));
328 328
 
329 329
 	// Return an empty array if no image is found.
330
-	if ( empty( $images ) ) {
330
+	if (empty($images)) {
331 331
 		return array();
332 332
 	}
333 333
 
@@ -335,11 +335,11 @@  discard block
 block discarded – undo
335 335
 	$image_urls = array();
336 336
 
337 337
 	// Collect the URLs.
338
-	foreach ( $images as $attachment_id => $attachment ) {
339
-		$image_url = wp_get_attachment_url( $attachment_id );
338
+	foreach ($images as $attachment_id => $attachment) {
339
+		$image_url = wp_get_attachment_url($attachment_id);
340 340
 		// Ensure the URL isn't collected already.
341
-		if ( ! in_array( $image_url, $image_urls ) ) {
342
-			array_push( $image_urls, $image_url );
341
+		if ( ! in_array($image_url, $image_urls)) {
342
+			array_push($image_urls, $image_url);
343 343
 		}
344 344
 	}
345 345
 
@@ -356,17 +356,17 @@  discard block
 block discarded – undo
356 356
  *
357 357
  * @return string The SPARQL fragment.
358 358
  */
359
-function wl_get_sparql_images( $uri, $post_id ) {
359
+function wl_get_sparql_images($uri, $post_id) {
360 360
 
361 361
 	$sparql = '';
362 362
 
363 363
 	// Get the escaped URI.
364
-	$uri_e = esc_html( $uri );
364
+	$uri_e = esc_html($uri);
365 365
 
366 366
 	// Add SPARQL stmts to write the schema:image.
367
-	$image_urls = wl_get_image_urls( $post_id );
368
-	foreach ( $image_urls as $image_url ) {
369
-		$image_url_esc = wl_sparql_escape_uri( $image_url );
367
+	$image_urls = wl_get_image_urls($post_id);
368
+	foreach ($image_urls as $image_url) {
369
+		$image_url_esc = wl_sparql_escape_uri($image_url);
370 370
 		$sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
371 371
 	}
372 372
 
@@ -381,21 +381,21 @@  discard block
 block discarded – undo
381 381
  *
382 382
  * @return WP_Post|null A post instance or null if not found.
383 383
  */
384
-function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
384
+function wl_get_attachment_for_source_url($parent_post_id, $source_url) {
385 385
 
386 386
 	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
387 387
 
388
-	$posts = get_posts( array(
388
+	$posts = get_posts(array(
389 389
 		'post_type'      => 'attachment',
390 390
 		'posts_per_page' => 1,
391 391
 		'post_status'    => 'any',
392 392
 		'post_parent'    => $parent_post_id,
393 393
 		'meta_key'       => 'wl_source_url',
394 394
 		'meta_value'     => $source_url,
395
-	) );
395
+	));
396 396
 
397 397
 	// Return the found post.
398
-	if ( 1 === count( $posts ) ) {
398
+	if (1 === count($posts)) {
399 399
 		return $posts[0];
400 400
 	}
401 401
 
@@ -409,10 +409,10 @@  discard block
 block discarded – undo
409 409
  * @param int    $post_id    The post ID.
410 410
  * @param string $source_url The source URL.
411 411
  */
412
-function wl_set_source_url( $post_id, $source_url ) {
412
+function wl_set_source_url($post_id, $source_url) {
413 413
 
414
-	delete_post_meta( $post_id, 'wl_source_url' );
415
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
414
+	delete_post_meta($post_id, 'wl_source_url');
415
+	add_post_meta($post_id, 'wl_source_url', $source_url);
416 416
 }
417 417
 
418 418
 
@@ -428,10 +428,10 @@  discard block
 block discarded – undo
428 428
  *
429 429
  * @param bool $hard True if the rewrite involves configuration updates in Apache/IIS.
430 430
  */
431
-function wl_flush_rewrite_rules_hard( $hard ) {
431
+function wl_flush_rewrite_rules_hard($hard) {
432 432
 
433 433
 	// If WL is not yet configured, we cannot perform any update, so we exit.
434
-	if ( '' === wl_configuration_get_key() ) {
434
+	if ('' === wl_configuration_get_key()) {
435 435
 		return;
436 436
 	}
437 437
 
@@ -440,13 +440,13 @@  discard block
 block discarded – undo
440 440
 	$limit  = 100;
441 441
 
442 442
 	// Get more posts if the number of returned posts matches the limit.
443
-	while ( $limit === ( $posts = get_posts( array(
443
+	while ($limit === ($posts = get_posts(array(
444 444
 			'offset'      => $offset,
445 445
 			'numberposts' => $limit,
446 446
 			'orderby'     => 'ID',
447 447
 			'post_type'   => 'any',
448 448
 			'post_status' => 'publish',
449
-		) ) ) ) {
449
+		)))) {
450 450
 
451 451
 		// Holds the delete part of the query.
452 452
 		$delete_query = rl_sparql_prefixes();
@@ -455,16 +455,16 @@  discard block
 block discarded – undo
455 455
 		$insert_query = '';
456 456
 
457 457
 		// Cycle in each post to build the query.
458
-		foreach ( $posts as $post ) {
458
+		foreach ($posts as $post) {
459 459
 
460 460
 			// Ignore revisions.
461
-			if ( wp_is_post_revision( $post->ID ) ) {
461
+			if (wp_is_post_revision($post->ID)) {
462 462
 				continue;
463 463
 			}
464 464
 
465 465
 			// Get the entity URI.
466
-			$s = Wordlift_Sparql_Service::escape_uri( Wordlift_Entity_Service::get_instance()
467
-			                                                                 ->get_uri( $post->ID ) );
466
+			$s = Wordlift_Sparql_Service::escape_uri(Wordlift_Entity_Service::get_instance()
467
+			                                                                 ->get_uri($post->ID));
468 468
 
469 469
 			// Get the post URL.
470 470
 			// $url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
@@ -473,13 +473,13 @@  discard block
 block discarded – undo
473 473
 			$delete_query .= "DELETE { <$s> schema:url ?u . } WHERE  { <$s> schema:url ?u . };\n";
474 474
 
475 475
 			$insert_query .= Wordlift_Schema_Url_Property_Service::get_instance()
476
-			                                                     ->get_insert_query( $s, $post->ID );
476
+			                                                     ->get_insert_query($s, $post->ID);
477 477
 
478 478
 		}
479 479
 
480 480
 
481 481
 		// Execute the query.
482
-		rl_execute_sparql_update_query( $delete_query . $insert_query );
482
+		rl_execute_sparql_update_query($delete_query.$insert_query);
483 483
 
484 484
 		// Advance to the next posts.
485 485
 		$offset += $limit;
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 
496 496
 }
497 497
 
498
-add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 );
498
+add_filter('flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1);
499 499
 
500 500
 /**
501 501
  * Sanitizes an URI path by replacing the non allowed characters with an underscore.
@@ -508,9 +508,9 @@  discard block
 block discarded – undo
508 508
  *
509 509
  * @return string The sanitized path.
510 510
  */
511
-function wl_sanitize_uri_path( $path, $char = '_' ) {
511
+function wl_sanitize_uri_path($path, $char = '_') {
512 512
 
513
-	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
513
+	return Wordlift_Uri_Service::get_instance()->sanitize_path($path, $char);
514 514
 }
515 515
 
516 516
 /**
@@ -520,10 +520,10 @@  discard block
 block discarded – undo
520 520
  *
521 521
  * @return array Array containing $value (if $value was not an array)
522 522
  */
523
-function wl_force_to_array( $value ) {
523
+function wl_force_to_array($value) {
524 524
 
525
-	if ( ! is_array( $value ) ) {
526
-		return array( $value );
525
+	if ( ! is_array($value)) {
526
+		return array($value);
527 527
 	}
528 528
 
529 529
 	return $value;
@@ -535,28 +535,28 @@  discard block
 block discarded – undo
535 535
 function wl_shutdown() {
536 536
 
537 537
 	// Get the filename to the temporary SPARQL file.
538
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
538
+	$filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql';
539 539
 
540 540
 	// If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
541
-	if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
541
+	if (WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists($filename)) {
542 542
 
543 543
 		// The request ID.
544
-		$args = array( WL_REQUEST_ID );
544
+		$args = array(WL_REQUEST_ID);
545 545
 
546 546
 		// Schedule the execution of the SPARQL query with the request ID.
547
-		wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
547
+		wp_schedule_single_event(time(), 'wl_execute_saved_sparql_update_query', $args);
548 548
 
549 549
 		// Check that the request is scheduled.
550
-		$timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
550
+		$timestamp = wp_next_scheduled('wl_execute_saved_sparql_update_query', $args);
551 551
 
552 552
 		// Spawn the cron.
553 553
 		spawn_cron();
554 554
 
555
-		wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
555
+		wl_write_log("wl_shutdown [ request id :: ".WL_REQUEST_ID." ][ timestamp :: $timestamp ]");
556 556
 	}
557 557
 }
558 558
 
559
-add_action( 'shutdown', 'wl_shutdown' );
559
+add_action('shutdown', 'wl_shutdown');
560 560
 
561 561
 /**
562 562
  * Replaces the *itemid* attributes URIs with the WordLift URIs.
@@ -565,113 +565,113 @@  discard block
 block discarded – undo
565 565
  *
566 566
  * @return string The updated post content.
567 567
  */
568
-function wl_replace_item_id_with_uri( $content ) {
568
+function wl_replace_item_id_with_uri($content) {
569 569
 
570 570
 	// wl_write_log( "wl_replace_item_id_with_uri" );
571 571
 
572 572
 	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
573
-	$content = stripslashes( $content );
573
+	$content = stripslashes($content);
574 574
 
575 575
 	// If any match are found.
576 576
 	$matches = array();
577
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
577
+	if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) {
578 578
 
579
-		foreach ( $matches as $match ) {
579
+		foreach ($matches as $match) {
580 580
 
581 581
 			// Get the item ID.
582 582
 			$item_id = $match[1];
583 583
 
584 584
 			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
585 585
 			$post = Wordlift_Entity_Service::get_instance()
586
-			                               ->get_entity_post_by_uri( $item_id );
586
+			                               ->get_entity_post_by_uri($item_id);
587 587
 
588 588
 			// If no entity is found, continue to the next one.
589
-			if ( NULL === $post ) {
589
+			if (NULL === $post) {
590 590
 				continue;
591 591
 			}
592 592
 
593 593
 			// Get the URI for that post.
594
-			$uri = wl_get_entity_uri( $post->ID );
594
+			$uri = wl_get_entity_uri($post->ID);
595 595
 
596 596
 			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
597 597
 
598 598
 			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
599
-			if ( $item_id !== $uri ) {
600
-				$uri_e   = esc_html( $uri );
601
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
599
+			if ($item_id !== $uri) {
600
+				$uri_e   = esc_html($uri);
601
+				$content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content);
602 602
 			}
603 603
 		}
604 604
 	}
605 605
 
606 606
 	// Reapply slashes.
607
-	$content = addslashes( $content );
607
+	$content = addslashes($content);
608 608
 
609 609
 	return $content;
610 610
 }
611 611
 
612
-add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
612
+add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1);
613 613
 
614
-require_once( 'wordlift_entity_functions.php' );
614
+require_once('wordlift_entity_functions.php');
615 615
 
616 616
 // add editor related methods.
617
-require_once( 'wordlift_editor.php' );
617
+require_once('wordlift_editor.php');
618 618
 
619 619
 // add the WordLift entity custom type.
620
-require_once( 'wordlift_entity_type.php' );
621
-require_once( 'wordlift_entity_type_taxonomy.php' );
620
+require_once('wordlift_entity_type.php');
621
+require_once('wordlift_entity_type_taxonomy.php');
622 622
 
623 623
 // add callbacks on post save to notify data changes from wp to redlink triple store
624
-require_once( 'wordlift_to_redlink_data_push_callbacks.php' );
624
+require_once('wordlift_to_redlink_data_push_callbacks.php');
625 625
 
626 626
 // Load modules
627
-require_once( 'modules/analyzer/wordlift_analyzer.php' );
628
-require_once( 'modules/linked_data/wordlift_linked_data.php' );
629
-require_once( 'modules/prefixes/wordlift_prefixes.php' );
630
-require_once( 'modules/caching/wordlift_caching.php' );
631
-require_once( 'modules/redirector/wordlift_redirector.php' );
632
-require_once( 'modules/freebase_image_proxy/wordlift_freebase_image_proxy.php' );
627
+require_once('modules/analyzer/wordlift_analyzer.php');
628
+require_once('modules/linked_data/wordlift_linked_data.php');
629
+require_once('modules/prefixes/wordlift_prefixes.php');
630
+require_once('modules/caching/wordlift_caching.php');
631
+require_once('modules/redirector/wordlift_redirector.php');
632
+require_once('modules/freebase_image_proxy/wordlift_freebase_image_proxy.php');
633 633
 
634 634
 // Shortcodes
635 635
 
636
-require_once( 'modules/geo_widget/wordlift_geo_widget.php' );
637
-require_once( 'shortcodes/wordlift_shortcode_chord.php' );
638
-require_once( 'shortcodes/wordlift_shortcode_geomap.php' );
639
-require_once( 'shortcodes/wordlift_shortcode_field.php' );
640
-require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' );
641
-require_once( 'shortcodes/wordlift_shortcode_navigator.php' );
636
+require_once('modules/geo_widget/wordlift_geo_widget.php');
637
+require_once('shortcodes/wordlift_shortcode_chord.php');
638
+require_once('shortcodes/wordlift_shortcode_geomap.php');
639
+require_once('shortcodes/wordlift_shortcode_field.php');
640
+require_once('shortcodes/wordlift_shortcode_faceted_search.php');
641
+require_once('shortcodes/wordlift_shortcode_navigator.php');
642 642
 
643
-require_once( 'widgets/wordlift_widget_geo.php' );
644
-require_once( 'widgets/wordlift_widget_chord.php' );
645
-require_once( 'widgets/wordlift_widget_timeline.php' );
643
+require_once('widgets/wordlift_widget_geo.php');
644
+require_once('widgets/wordlift_widget_chord.php');
645
+require_once('widgets/wordlift_widget_timeline.php');
646 646
 
647
-require_once( 'wordlift_sparql.php' );
648
-require_once( 'wordlift_redlink.php' );
647
+require_once('wordlift_sparql.php');
648
+require_once('wordlift_redlink.php');
649 649
 
650 650
 // Add admin functions.
651 651
 // TODO: find a way to make 'admin' UI tests work.
652 652
 //if ( is_admin() ) {
653 653
 
654
-require_once( 'admin/wordlift_admin.php' );
655
-require_once( 'admin/wordlift_admin_edit_post.php' );
656
-require_once( 'admin/wordlift_admin_save_post.php' );
654
+require_once('admin/wordlift_admin.php');
655
+require_once('admin/wordlift_admin_edit_post.php');
656
+require_once('admin/wordlift_admin_save_post.php');
657 657
 
658 658
 // add the entities meta box.
659
-require_once( 'admin/wordlift_admin_meta_box_entities.php' );
659
+require_once('admin/wordlift_admin_meta_box_entities.php');
660 660
 
661 661
 // add the entity creation AJAX.
662
-require_once( 'admin/wordlift_admin_ajax_related_posts.php' );
662
+require_once('admin/wordlift_admin_ajax_related_posts.php');
663 663
 
664 664
 // Load the wl_chord TinyMCE button and configuration dialog.
665
-require_once( 'admin/wordlift_admin_shortcodes.php' );
665
+require_once('admin/wordlift_admin_shortcodes.php');
666 666
 
667 667
 // Provide syncing features.
668
-require_once( 'admin/wordlift_admin_sync.php' );
668
+require_once('admin/wordlift_admin_sync.php');
669 669
 //}
670 670
 
671 671
 // load languages.
672 672
 // TODO: the following call gives for granted that the plugin is in the wordlift directory,
673 673
 //       we're currently doing this because wordlift is symbolic linked.
674
-load_plugin_textdomain( 'wordlift', FALSE, '/wordlift/languages' );
674
+load_plugin_textdomain('wordlift', FALSE, '/wordlift/languages');
675 675
 
676 676
 
677 677
 /**
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
  * This action is documented in includes/class-wordlift-activator.php
680 680
  */
681 681
 function activate_wordlift() {
682
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
682
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
683 683
 	Wordlift_Activator::activate();
684 684
 }
685 685
 
@@ -688,18 +688,18 @@  discard block
 block discarded – undo
688 688
  * This action is documented in includes/class-wordlift-deactivator.php
689 689
  */
690 690
 function deactivate_wordlift() {
691
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
691
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
692 692
 	Wordlift_Deactivator::deactivate();
693 693
 }
694 694
 
695
-register_activation_hook( __FILE__, 'activate_wordlift' );
696
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
695
+register_activation_hook(__FILE__, 'activate_wordlift');
696
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
697 697
 
698 698
 /**
699 699
  * The core plugin class that is used to define internationalization,
700 700
  * admin-specific hooks, and public-facing site hooks.
701 701
  */
702
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
702
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
703 703
 
704 704
 /**
705 705
  * Begins execution of the plugin.
Please login to merge, or discard this patch.
src/admin/WL_Metabox/WL_Metabox_Field_coordinates.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 
4 4
 class WL_Metabox_Field_coordinates extends WL_Metabox_Field {
5 5
 
6
-	public function __construct( $args ) {
6
+	public function __construct($args) {
7 7
 
8 8
 		// Just set up the necessary info without calling the parent constructor.
9 9
 		// TODO: write a parent class for grouped properties
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 	public function get_data() {
17 17
 		$entity_id  = get_the_ID();
18
-		$this->data = wl_get_coordinates( $entity_id );
18
+		$this->data = wl_get_coordinates($entity_id);
19 19
 	}
20 20
 
21 21
 	public function html() {
@@ -33,20 +33,20 @@  discard block
 block discarded – undo
33 33
 		$data        = $this->data;
34 34
 		// TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we
35 35
 		// want to use the current user location for the marker.
36
-		$coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' );
36
+		$coordinates = ( ! empty($data['latitude']) && ! empty($data['longitude']) ? sprintf('[%f,%f]', $data['latitude'], $data['longitude']) : '[0,0]');
37 37
 		$map_init    = '[0,0]' === $coordinates
38 38
 			? 'locate( {setView: true, maxZoom: 16} )'
39
-			: sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] );
39
+			: sprintf("setView( [%f,%f], 9 )", $data['latitude'], $data['longitude']);
40 40
 
41 41
 		// Print input fields
42
-		$html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>';
43
-		$html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />';
42
+		$html .= '<label for="wl_place_lat">'.__('Latitude', 'wordlift').'</label>';
43
+		$html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="'.$data['latitude'].'" style="width:100%" />';
44 44
 
45
-		$html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>';
46
-		$html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />';
45
+		$html .= '<label for="wl_place_lon">'.__('Longitude', 'wordlift').'</label>';
46
+		$html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="'.$data['longitude'].'" style="width:100%" />';
47 47
 
48 48
 		// Show Leaflet map to pick coordinates
49
-		$element_id = uniqid( 'wl-gep-map-' );
49
+		$element_id = uniqid('wl-gep-map-');
50 50
 		$html .= <<<EOF
51 51
 
52 52
 <div id="$element_id"></div>
@@ -84,23 +84,23 @@  discard block
 block discarded – undo
84 84
 		return $html;
85 85
 	}
86 86
 
87
-	public function save_data( $coords ) {
87
+	public function save_data($coords) {
88 88
 
89
-		$this->sanitize_data( $coords );
89
+		$this->sanitize_data($coords);
90 90
 
91 91
 		$entity_id = get_the_ID();
92 92
 
93 93
 		// Take away old values
94
-		delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE );
95
-		delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE );
94
+		delete_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE);
95
+		delete_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE);
96 96
 
97 97
 		$latitude  = $this->data[0];
98 98
 		$longitude = $this->data[1];
99 99
 
100 100
 		// insert new coordinate values
101
-		if ( ! empty( $latitude ) && ! empty( $longitude ) ) {
102
-			add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true );
103
-			add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true );
101
+		if ( ! empty($latitude) && ! empty($longitude)) {
102
+			add_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true);
103
+			add_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true);
104 104
 		}
105 105
 
106 106
 	}
@@ -108,11 +108,11 @@  discard block
 block discarded – undo
108 108
 	/**
109 109
 	 * Only accept float numbers
110 110
 	 */
111
-	public function sanitize_data_filter( $value ) {
111
+	public function sanitize_data_filter($value) {
112 112
 
113 113
 		// DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
114 114
 		// "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
115
-		if ( ! is_numeric( $value ) ) {
115
+		if ( ! is_numeric($value)) {
116 116
 			return '';
117 117
 		}
118 118
 
Please login to merge, or discard this patch.
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -3,51 +3,51 @@  discard block
 block discarded – undo
3 3
 
4 4
 class WL_Metabox_Field_coordinates extends WL_Metabox_Field {
5 5
 
6
-	public function __construct( $args ) {
6
+    public function __construct( $args ) {
7 7
 
8
-		// Just set up the necessary info without calling the parent constructor.
9
-		// TODO: write a parent class for grouped properties
8
+        // Just set up the necessary info without calling the parent constructor.
9
+        // TODO: write a parent class for grouped properties
10 10
 
11
-		// we use 'coordinates' to namespace the Field in $_POST data.
12
-		// In  the DB the correct meta names will be used.
13
-		$this->meta_name = 'coordinates';
14
-	}
11
+        // we use 'coordinates' to namespace the Field in $_POST data.
12
+        // In  the DB the correct meta names will be used.
13
+        $this->meta_name = 'coordinates';
14
+    }
15 15
 
16
-	public function get_data() {
17
-		$entity_id  = get_the_ID();
18
-		$this->data = wl_get_coordinates( $entity_id );
19
-	}
16
+    public function get_data() {
17
+        $entity_id  = get_the_ID();
18
+        $this->data = wl_get_coordinates( $entity_id );
19
+    }
20 20
 
21
-	public function html() {
21
+    public function html() {
22 22
 
23
-		// Open main <div> for the Field
24
-		$html = $this->html_wrapper_open();
23
+        // Open main <div> for the Field
24
+        $html = $this->html_wrapper_open();
25 25
 
26
-		// Label
27
-		$html .= '<h3>coordinates</h3>';
26
+        // Label
27
+        $html .= '<h3>coordinates</h3>';
28 28
 
29
-		// print nonce
30
-		$html .= $this->html_nonce();
29
+        // print nonce
30
+        $html .= $this->html_nonce();
31 31
 
32
-		// Get coordinates
33
-		$data        = $this->data;
34
-		// TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we
35
-		// want to use the current user location for the marker.
36
-		$coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' );
37
-		$map_init    = '[0,0]' === $coordinates
38
-			? 'locate( {setView: true, maxZoom: 16} )'
39
-			: sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] );
32
+        // Get coordinates
33
+        $data        = $this->data;
34
+        // TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we
35
+        // want to use the current user location for the marker.
36
+        $coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' );
37
+        $map_init    = '[0,0]' === $coordinates
38
+            ? 'locate( {setView: true, maxZoom: 16} )'
39
+            : sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] );
40 40
 
41
-		// Print input fields
42
-		$html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>';
43
-		$html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />';
41
+        // Print input fields
42
+        $html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>';
43
+        $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />';
44 44
 
45
-		$html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>';
46
-		$html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />';
45
+        $html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>';
46
+        $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />';
47 47
 
48
-		// Show Leaflet map to pick coordinates
49
-		$element_id = uniqid( 'wl-gep-map-' );
50
-		$html .= <<<EOF
48
+        // Show Leaflet map to pick coordinates
49
+        $element_id = uniqid( 'wl-gep-map-' );
50
+        $html .= <<<EOF
51 51
 
52 52
 <div id="$element_id"></div>
53 53
 
@@ -79,44 +79,44 @@  discard block
 block discarded – undo
79 79
 EOF;
80 80
 
81 81
 
82
-		$html .= $this->html_wrapper_close();
82
+        $html .= $this->html_wrapper_close();
83 83
 
84
-		return $html;
85
-	}
84
+        return $html;
85
+    }
86 86
 
87
-	public function save_data( $coords ) {
87
+    public function save_data( $coords ) {
88 88
 
89
-		$this->sanitize_data( $coords );
89
+        $this->sanitize_data( $coords );
90 90
 
91
-		$entity_id = get_the_ID();
91
+        $entity_id = get_the_ID();
92 92
 
93
-		// Take away old values
94
-		delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE );
95
-		delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE );
93
+        // Take away old values
94
+        delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE );
95
+        delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE );
96 96
 
97
-		$latitude  = $this->data[0];
98
-		$longitude = $this->data[1];
97
+        $latitude  = $this->data[0];
98
+        $longitude = $this->data[1];
99 99
 
100
-		// insert new coordinate values
101
-		if ( ! empty( $latitude ) && ! empty( $longitude ) ) {
102
-			add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true );
103
-			add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true );
104
-		}
100
+        // insert new coordinate values
101
+        if ( ! empty( $latitude ) && ! empty( $longitude ) ) {
102
+            add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true );
103
+            add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true );
104
+        }
105 105
 
106
-	}
106
+    }
107 107
 
108
-	/**
109
-	 * Only accept float numbers
110
-	 */
111
-	public function sanitize_data_filter( $value ) {
108
+    /**
109
+     * Only accept float numbers
110
+     */
111
+    public function sanitize_data_filter( $value ) {
112 112
 
113
-		// DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
114
-		// "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
115
-		if ( ! is_numeric( $value ) ) {
116
-			return '';
117
-		}
113
+        // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
114
+        // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
115
+        if ( ! is_numeric( $value ) ) {
116
+            return '';
117
+        }
118 118
 
119
-		return $value;
120
-	}
119
+        return $value;
120
+    }
121 121
 }
122 122
 
Please login to merge, or discard this patch.
src/admin/wordlift_admin_ajax_related_posts.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,54 +1,54 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-function wordlift_ajax_related_posts( $http_raw_data = null ) {
3
+function wordlift_ajax_related_posts($http_raw_data = null) {
4 4
     
5 5
     // Extract filtering conditions
6
-    if( !isset( $_GET["post_id"] ) || !is_numeric( $_GET["post_id"] ) ) {
6
+    if ( ! isset($_GET["post_id"]) || ! is_numeric($_GET["post_id"])) {
7 7
         wp_die('Post id missing or invalid!');
8 8
         return;
9 9
     }
10 10
 
11 11
     $post_id = $_GET["post_id"]; 
12 12
     // Get the current post
13
-    $post = get_post( $post_id );
13
+    $post = get_post($post_id);
14 14
 
15
-    wl_write_log( "Going to find posts related to current with post id: $post_id ..." );
15
+    wl_write_log("Going to find posts related to current with post id: $post_id ...");
16 16
     
17 17
     // Extract filtering conditions
18
-    $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents("php://input") : $http_raw_data;
19
-    $filtering_entity_uris = json_decode( $filtering_entity_uris );
18
+    $filtering_entity_uris = (null == $http_raw_data) ? file_get_contents("php://input") : $http_raw_data;
19
+    $filtering_entity_uris = json_decode($filtering_entity_uris);
20 20
    
21
-    $filtering_entity_ids = wl_get_entity_post_ids_by_uris( $filtering_entity_uris );
21
+    $filtering_entity_ids = wl_get_entity_post_ids_by_uris($filtering_entity_uris);
22 22
     $related_posts = array();
23 23
     
24 24
     // If the current post is an antity 
25 25
     // related posts to the current entity are returned
26
-    if ( Wordlift_Entity_Service::TYPE_NAME == $post->post_type ) {
27
-        $filtering_entity_ids = array( $post_id );        
26
+    if (Wordlift_Entity_Service::TYPE_NAME == $post->post_type) {
27
+        $filtering_entity_ids = array($post_id);        
28 28
     }
29 29
 
30
-    if ( !empty( $filtering_entity_ids ) ) {
30
+    if ( ! empty($filtering_entity_ids)) {
31 31
     
32
-        $related_posts = wl_core_get_posts( array(
32
+        $related_posts = wl_core_get_posts(array(
33 33
             'get'             =>    'posts',  
34 34
             'related_to__in'  =>    $filtering_entity_ids,
35
-            'post__not_in'    =>    array( $post_id ),
35
+            'post__not_in'    =>    array($post_id),
36 36
             'post_type'       =>    'post',
37 37
             'post_status'     =>    'publish',
38 38
             'as'              =>    'subject',
39
-        ) );
39
+        ));
40 40
         
41
-        foreach ( $related_posts as $post_obj ) {
41
+        foreach ($related_posts as $post_obj) {
42 42
                 
43
-            $thumbnail = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) );
44
-            $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; 
45
-            $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' );  
46
-            $post_obj->permalink = get_post_permalink( $post_obj->ID );  
43
+            $thumbnail = wp_get_attachment_url(get_post_thumbnail_id($post_obj->ID, 'thumbnail'));
44
+            $post_obj->thumbnail = ($thumbnail) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; 
45
+            $post_obj->link = get_edit_post_link($post_obj->ID, 'none');  
46
+            $post_obj->permalink = get_post_permalink($post_obj->ID);  
47 47
         
48 48
         }
49 49
     }
50 50
 
51
-    wl_core_send_json( $related_posts );
51
+    wl_core_send_json($related_posts);
52 52
 }
53 53
 
54
-add_action( 'wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts' );
54
+add_action('wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts');
Please login to merge, or discard this patch.
src/admin/wordlift_admin_save_post.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -23,19 +23,19 @@  discard block
 block discarded – undo
23 23
  */
24 24
 function wl_transition_post_status( $new_status, $old_status, $post ) {
25 25
 
26
-	// wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" );
27
-
28
-	// transition from *published* to any other status: delete the post.
29
-	if ( 'publish' === $old_status && 'publish' !== $new_status ) {
30
-		rl_delete_post( $post );
31
-	}
32
-
33
-	// when a post is published, then all the referenced entities must be published.
34
-	if ( 'publish' !== $old_status && 'publish' === $new_status ) {
35
-		foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) {
36
-			wl_update_post_status( $entity_id, 'publish' );
37
-		}
38
-	}
26
+    // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" );
27
+
28
+    // transition from *published* to any other status: delete the post.
29
+    if ( 'publish' === $old_status && 'publish' !== $new_status ) {
30
+        rl_delete_post( $post );
31
+    }
32
+
33
+    // when a post is published, then all the referenced entities must be published.
34
+    if ( 'publish' !== $old_status && 'publish' === $new_status ) {
35
+        foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) {
36
+            wl_update_post_status( $entity_id, 'publish' );
37
+        }
38
+    }
39 39
 }
40 40
 
41 41
 // hook save events.
@@ -49,49 +49,49 @@  discard block
 block discarded – undo
49 49
  */
50 50
 function rl_delete_post( $post ) {
51 51
 
52
-	$post_id = ( is_numeric( $post ) ? $post : $post->ID );
52
+    $post_id = ( is_numeric( $post ) ? $post : $post->ID );
53 53
 
54
-	// hide all entities that are not referenced by any published post.
55
-	foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) {
54
+    // hide all entities that are not referenced by any published post.
55
+    foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) {
56 56
 
57
-		// check if there is at least one referencing post published.
58
-		$is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) {
57
+        // check if there is at least one referencing post published.
58
+        $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) {
59 59
                     $post = get_post( $item );
60 60
                     return ( $carry || ( 'publish' === $post->post_status ) );
61
-		} );
62
-		// set the entity to draft if no referencing posts are published.
63
-		if ( ! $is_published ) {
64
-			wl_update_post_status( $entity_id, 'draft' );
65
-		}
66
-	}
67
-
68
-	// get the entity URI (valid also for posts)
69
-	$uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) );
70
-
71
-	wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" );
72
-
73
-	// create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate.
74
-	$stmt = rl_sparql_prefixes();
75
-	foreach ( wl_predicates() as $predicate ) {
76
-		$stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" .
77
-		         "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n";
78
-	}
79
-
80
-	// if the post is an entity and has exported properties, delete the related predicates.
81
-	if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) {
82
-		$type = wl_entity_type_taxonomy_get_type( $post->ID );
83
-
84
-		if ( isset( $type['custom_fields'] ) ) {
85
-			foreach ( $type['custom_fields'] as $field => $params ) {
86
-				// TODO: enclose in <> only if predicate starts with http(s)://
87
-				$predicate = '<' . $params['predicate'] . '>';
88
-				$stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n";
89
-			}
90
-		}
91
-	}
92
-
93
-	// finally execute the query.
94
-	rl_execute_sparql_update_query( $stmt );
61
+        } );
62
+        // set the entity to draft if no referencing posts are published.
63
+        if ( ! $is_published ) {
64
+            wl_update_post_status( $entity_id, 'draft' );
65
+        }
66
+    }
67
+
68
+    // get the entity URI (valid also for posts)
69
+    $uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) );
70
+
71
+    wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" );
72
+
73
+    // create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate.
74
+    $stmt = rl_sparql_prefixes();
75
+    foreach ( wl_predicates() as $predicate ) {
76
+        $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" .
77
+                    "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n";
78
+    }
79
+
80
+    // if the post is an entity and has exported properties, delete the related predicates.
81
+    if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) {
82
+        $type = wl_entity_type_taxonomy_get_type( $post->ID );
83
+
84
+        if ( isset( $type['custom_fields'] ) ) {
85
+            foreach ( $type['custom_fields'] as $field => $params ) {
86
+                // TODO: enclose in <> only if predicate starts with http(s)://
87
+                $predicate = '<' . $params['predicate'] . '>';
88
+                $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n";
89
+            }
90
+        }
91
+    }
92
+
93
+    // finally execute the query.
94
+    rl_execute_sparql_update_query( $stmt );
95 95
 }
96 96
 
97 97
 /**
@@ -102,34 +102,34 @@  discard block
 block discarded – undo
102 102
  */
103 103
 function wl_update_post_status( $post_id, $status ) {
104 104
 
105
-	wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" );
105
+    wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" );
106 106
 
107
-	global $wpdb;
107
+    global $wpdb;
108 108
 
109
-	if ( ! $post = get_post( $post_id ) ) {
110
-		return;
111
-	}
109
+    if ( ! $post = get_post( $post_id ) ) {
110
+        return;
111
+    }
112 112
 
113
-	if ( $status === $post->post_status ) {
114
-		return;
115
-	}
113
+    if ( $status === $post->post_status ) {
114
+        return;
115
+    }
116 116
 
117
-	$wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) );
117
+    $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) );
118 118
 
119
-	clean_post_cache( $post->ID );
119
+    clean_post_cache( $post->ID );
120 120
 
121
-	$old_status        = $post->post_status;
122
-	$post->post_status = $status;
121
+    $old_status        = $post->post_status;
122
+    $post->post_status = $status;
123 123
 
124
-	wp_transition_post_status( $status, $old_status, $post );
124
+    wp_transition_post_status( $status, $old_status, $post );
125 125
 
126
-	/** This action is documented in wp-includes/post.php */
127
-	do_action( 'edit_post', $post->ID, $post );
128
-	/** This action is documented in wp-includes/post.php */
129
-	do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
130
-	/** This action is documented in wp-includes/post.php */
131
-	do_action( 'wl_linked_data_save_post', $post->ID );
132
-	/** This action is documented in wp-includes/post.php */
133
-	do_action( 'wp_insert_post', $post->ID, $post, true );
126
+    /** This action is documented in wp-includes/post.php */
127
+    do_action( 'edit_post', $post->ID, $post );
128
+    /** This action is documented in wp-includes/post.php */
129
+    do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
130
+    /** This action is documented in wp-includes/post.php */
131
+    do_action( 'wl_linked_data_save_post', $post->ID );
132
+    /** This action is documented in wp-includes/post.php */
133
+    do_action( 'wp_insert_post', $post->ID, $post, true );
134 134
 }
135 135
 
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -21,25 +21,25 @@  discard block
 block discarded – undo
21 21
  * @param string $old_status The old post status
22 22
  * @param array $post An array with the post data
23 23
  */
24
-function wl_transition_post_status( $new_status, $old_status, $post ) {
24
+function wl_transition_post_status($new_status, $old_status, $post) {
25 25
 
26 26
 	// wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" );
27 27
 
28 28
 	// transition from *published* to any other status: delete the post.
29
-	if ( 'publish' === $old_status && 'publish' !== $new_status ) {
30
-		rl_delete_post( $post );
29
+	if ('publish' === $old_status && 'publish' !== $new_status) {
30
+		rl_delete_post($post);
31 31
 	}
32 32
 
33 33
 	// when a post is published, then all the referenced entities must be published.
34
-	if ( 'publish' !== $old_status && 'publish' === $new_status ) {
35
-		foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) {
36
-			wl_update_post_status( $entity_id, 'publish' );
34
+	if ('publish' !== $old_status && 'publish' === $new_status) {
35
+		foreach (wl_core_get_related_entity_ids($post->ID) as $entity_id) {
36
+			wl_update_post_status($entity_id, 'publish');
37 37
 		}
38 38
 	}
39 39
 }
40 40
 
41 41
 // hook save events.
42
-add_action( 'transition_post_status', 'wl_transition_post_status', 10, 3 );
42
+add_action('transition_post_status', 'wl_transition_post_status', 10, 3);
43 43
 
44 44
 
45 45
 /**
@@ -47,51 +47,51 @@  discard block
 block discarded – undo
47 47
  *
48 48
  * @param array|int $post An array of post data
49 49
  */
50
-function rl_delete_post( $post ) {
50
+function rl_delete_post($post) {
51 51
 
52
-	$post_id = ( is_numeric( $post ) ? $post : $post->ID );
52
+	$post_id = (is_numeric($post) ? $post : $post->ID);
53 53
 
54 54
 	// hide all entities that are not referenced by any published post.
55
-	foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) {
55
+	foreach (wl_core_get_related_entity_ids($post_id) as $entity_id) {
56 56
 
57 57
 		// check if there is at least one referencing post published.
58
-		$is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) {
59
-                    $post = get_post( $item );
60
-                    return ( $carry || ( 'publish' === $post->post_status ) );
58
+		$is_published = array_reduce(wl_core_get_related_post_ids($entity_id), function($carry, $item) {
59
+                    $post = get_post($item);
60
+                    return ($carry || ('publish' === $post->post_status));
61 61
 		} );
62 62
 		// set the entity to draft if no referencing posts are published.
63
-		if ( ! $is_published ) {
64
-			wl_update_post_status( $entity_id, 'draft' );
63
+		if ( ! $is_published) {
64
+			wl_update_post_status($entity_id, 'draft');
65 65
 		}
66 66
 	}
67 67
 
68 68
 	// get the entity URI (valid also for posts)
69
-	$uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) );
69
+	$uri_esc = wl_sparql_escape_uri(wl_get_entity_uri($post_id));
70 70
 
71
-	wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" );
71
+	wl_write_log("rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]");
72 72
 
73 73
 	// create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate.
74 74
 	$stmt = rl_sparql_prefixes();
75
-	foreach ( wl_predicates() as $predicate ) {
76
-		$stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" .
75
+	foreach (wl_predicates() as $predicate) {
76
+		$stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n".
77 77
 		         "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n";
78 78
 	}
79 79
 
80 80
 	// if the post is an entity and has exported properties, delete the related predicates.
81
-	if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) {
82
-		$type = wl_entity_type_taxonomy_get_type( $post->ID );
81
+	if (Wordlift_Entity_Service::TYPE_NAME === $post->post_type) {
82
+		$type = wl_entity_type_taxonomy_get_type($post->ID);
83 83
 
84
-		if ( isset( $type['custom_fields'] ) ) {
85
-			foreach ( $type['custom_fields'] as $field => $params ) {
84
+		if (isset($type['custom_fields'])) {
85
+			foreach ($type['custom_fields'] as $field => $params) {
86 86
 				// TODO: enclose in <> only if predicate starts with http(s)://
87
-				$predicate = '<' . $params['predicate'] . '>';
87
+				$predicate = '<'.$params['predicate'].'>';
88 88
 				$stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n";
89 89
 			}
90 90
 		}
91 91
 	}
92 92
 
93 93
 	// finally execute the query.
94
-	rl_execute_sparql_update_query( $stmt );
94
+	rl_execute_sparql_update_query($stmt);
95 95
 }
96 96
 
97 97
 /**
@@ -100,36 +100,36 @@  discard block
 block discarded – undo
100 100
  * @param int $post_id The post ID
101 101
  * @param string $status The new status
102 102
  */
103
-function wl_update_post_status( $post_id, $status ) {
103
+function wl_update_post_status($post_id, $status) {
104 104
 
105
-	wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" );
105
+	wl_write_log("wl_update_post_status [ post ID :: $post_id ][ status :: $status ]");
106 106
 
107 107
 	global $wpdb;
108 108
 
109
-	if ( ! $post = get_post( $post_id ) ) {
109
+	if ( ! $post = get_post($post_id)) {
110 110
 		return;
111 111
 	}
112 112
 
113
-	if ( $status === $post->post_status ) {
113
+	if ($status === $post->post_status) {
114 114
 		return;
115 115
 	}
116 116
 
117
-	$wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) );
117
+	$wpdb->update($wpdb->posts, array('post_status' => $status), array('ID' => $post->ID));
118 118
 
119
-	clean_post_cache( $post->ID );
119
+	clean_post_cache($post->ID);
120 120
 
121 121
 	$old_status        = $post->post_status;
122 122
 	$post->post_status = $status;
123 123
 
124
-	wp_transition_post_status( $status, $old_status, $post );
124
+	wp_transition_post_status($status, $old_status, $post);
125 125
 
126 126
 	/** This action is documented in wp-includes/post.php */
127
-	do_action( 'edit_post', $post->ID, $post );
127
+	do_action('edit_post', $post->ID, $post);
128 128
 	/** This action is documented in wp-includes/post.php */
129
-	do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
129
+	do_action("save_post_{$post->post_type}", $post->ID, $post, true);
130 130
 	/** This action is documented in wp-includes/post.php */
131
-	do_action( 'wl_linked_data_save_post', $post->ID );
131
+	do_action('wl_linked_data_save_post', $post->ID);
132 132
 	/** This action is documented in wp-includes/post.php */
133
-	do_action( 'wp_insert_post', $post->ID, $post, true );
133
+	do_action('wp_insert_post', $post->ID, $post, true);
134 134
 }
135 135
 
Please login to merge, or discard this patch.
src/admin/wordlift_admin_shortcodes.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
  * Loads the buttons in TinyMCE.
10 10
  */
11 11
 function wl_admin_shortcode_buttons() {
12
-	// Only add hooks when the current user has permissions AND is in Rich Text editor mode
13
-	if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
14
-		add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' );
15
-		add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' );
16
-		add_action( 'admin_footer', 'wl_admin_inject_chord_dialog_dependencies' );
17
-	}
12
+    // Only add hooks when the current user has permissions AND is in Rich Text editor mode
13
+    if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
14
+        add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' );
15
+        add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' );
16
+        add_action( 'admin_footer', 'wl_admin_inject_chord_dialog_dependencies' );
17
+    }
18 18
 }
19 19
 
20 20
 /**
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
  */
27 27
 function wl_admin_shortcode_buttons_register_tinymce_javascript( $plugin_array ) {
28 28
 
29
-	$plugin_array['wl_shortcodes'] = plugin_dir_url( __FILE__ ) . 'js/wordlift_shortcode_tinymce_plugin.js';
29
+    $plugin_array['wl_shortcodes'] = plugin_dir_url( __FILE__ ) . 'js/wordlift_shortcode_tinymce_plugin.js';
30 30
 
31
-	return $plugin_array;
31
+    return $plugin_array;
32 32
 }
33 33
 
34 34
 /**
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
  * @return array The buttons array including the *wl_shortcodes_menu*.
40 40
  */
41 41
 function wl_admin_shortcode_register_buttons( $buttons ) {
42
-	array_push( $buttons, 'wl_shortcodes_menu' );
42
+    array_push( $buttons, 'wl_shortcodes_menu' );
43 43
 
44
-	return $buttons;
44
+    return $buttons;
45 45
 }
46 46
 
47 47
 // init process for button control
@@ -55,16 +55,16 @@  discard block
 block discarded – undo
55 55
  */
56 56
 function wl_admin_inject_chord_dialog_dependencies() {
57 57
 
58
-	wp_enqueue_style( 'wp-color-picker' );
59
-	wp_enqueue_script( 'wp-color-picker' );
60
-	wp_enqueue_style( 'jquery-ui-slider' );
61
-	// Not included by default :|
62
-	// TODO include jquery ui css from the plugin creates css issues on the slider
63
-	// wp_enqueue_style('jquery-ui-css', plugins_url( 'css/jquery-ui/jquery-ui.min.css', __FILE__ ) );
64
-	wp_enqueue_style( 'wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css' );
58
+    wp_enqueue_style( 'wp-color-picker' );
59
+    wp_enqueue_script( 'wp-color-picker' );
60
+    wp_enqueue_style( 'jquery-ui-slider' );
61
+    // Not included by default :|
62
+    // TODO include jquery ui css from the plugin creates css issues on the slider
63
+    // wp_enqueue_style('jquery-ui-css', plugins_url( 'css/jquery-ui/jquery-ui.min.css', __FILE__ ) );
64
+    wp_enqueue_style( 'wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css' );
65 65
 
66
-	wp_enqueue_script( 'jquery' );
67
-	wp_enqueue_script( 'jquery-ui-core' );
68
-	wp_enqueue_script( 'jquery-ui-slider' );
66
+    wp_enqueue_script( 'jquery' );
67
+    wp_enqueue_script( 'jquery-ui-core' );
68
+    wp_enqueue_script( 'jquery-ui-slider' );
69 69
 
70 70
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -10,10 +10,10 @@  discard block
 block discarded – undo
10 10
  */
11 11
 function wl_admin_shortcode_buttons() {
12 12
 	// Only add hooks when the current user has permissions AND is in Rich Text editor mode
13
-	if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
14
-		add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' );
15
-		add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' );
16
-		add_action( 'admin_footer', 'wl_admin_inject_chord_dialog_dependencies' );
13
+	if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) {
14
+		add_filter('mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript');
15
+		add_filter('mce_buttons', 'wl_admin_shortcode_register_buttons');
16
+		add_action('admin_footer', 'wl_admin_inject_chord_dialog_dependencies');
17 17
 	}
18 18
 }
19 19
 
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
  *
25 25
  * @return array The TinyMCE plugins array including WordLift shortcodes plugin.
26 26
  */
27
-function wl_admin_shortcode_buttons_register_tinymce_javascript( $plugin_array ) {
27
+function wl_admin_shortcode_buttons_register_tinymce_javascript($plugin_array) {
28 28
 
29
-	$plugin_array['wl_shortcodes'] = plugin_dir_url( __FILE__ ) . 'js/wordlift_shortcode_tinymce_plugin.js';
29
+	$plugin_array['wl_shortcodes'] = plugin_dir_url(__FILE__).'js/wordlift_shortcode_tinymce_plugin.js';
30 30
 
31 31
 	return $plugin_array;
32 32
 }
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
  *
39 39
  * @return array The buttons array including the *wl_shortcodes_menu*.
40 40
  */
41
-function wl_admin_shortcode_register_buttons( $buttons ) {
42
-	array_push( $buttons, 'wl_shortcodes_menu' );
41
+function wl_admin_shortcode_register_buttons($buttons) {
42
+	array_push($buttons, 'wl_shortcodes_menu');
43 43
 
44 44
 	return $buttons;
45 45
 }
46 46
 
47 47
 // init process for button control
48
-add_action( 'admin_init', 'wl_admin_shortcode_buttons' );
48
+add_action('admin_init', 'wl_admin_shortcode_buttons');
49 49
 
50 50
 
51 51
 /**
@@ -55,16 +55,16 @@  discard block
 block discarded – undo
55 55
  */
56 56
 function wl_admin_inject_chord_dialog_dependencies() {
57 57
 
58
-	wp_enqueue_style( 'wp-color-picker' );
59
-	wp_enqueue_script( 'wp-color-picker' );
60
-	wp_enqueue_style( 'jquery-ui-slider' );
58
+	wp_enqueue_style('wp-color-picker');
59
+	wp_enqueue_script('wp-color-picker');
60
+	wp_enqueue_style('jquery-ui-slider');
61 61
 	// Not included by default :|
62 62
 	// TODO include jquery ui css from the plugin creates css issues on the slider
63 63
 	// wp_enqueue_style('jquery-ui-css', plugins_url( 'css/jquery-ui/jquery-ui.min.css', __FILE__ ) );
64
-	wp_enqueue_style( 'wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css' );
64
+	wp_enqueue_style('wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css');
65 65
 
66
-	wp_enqueue_script( 'jquery' );
67
-	wp_enqueue_script( 'jquery-ui-core' );
68
-	wp_enqueue_script( 'jquery-ui-slider' );
66
+	wp_enqueue_script('jquery');
67
+	wp_enqueue_script('jquery-ui-core');
68
+	wp_enqueue_script('jquery-ui-slider');
69 69
 
70 70
 }
Please login to merge, or discard this patch.