Completed
Push — develop ( 565960...e2f469 )
by David
03: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   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -16,23 +16,23 @@  discard block
 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' 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' 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' 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' 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 );
@@ -43,24 +43,24 @@  discard block
 block discarded – undo
43 43
  */
44 44
 function wl_admin_search_duplicated_entity_while_editing_title( $hook ) {
45 45
 
46
-	// Only enqueueing script when editing an entity
47
-	if ( $hook == 'post.php' ) {
46
+    // Only enqueueing script when editing an entity
47
+    if ( $hook == 'post.php' ) {
48 48
 
49
-		// Get entity object (the auto-draft created automagically by WP)
50
-		$entity_being_edited = get_post();
49
+        // Get entity object (the auto-draft created automagically by WP)
50
+        $entity_being_edited = get_post();
51 51
 
52
-		// Exit if we are not dealing with an entity
53
-		if ( $entity_being_edited->post_type == Wordlift_Entity_Service::TYPE_NAME ) {
52
+        // Exit if we are not dealing with an entity
53
+        if ( $entity_being_edited->post_type == Wordlift_Entity_Service::TYPE_NAME ) {
54 54
 
55
-			wp_enqueue_script( 'wl-entity-duplicated-titles-live-search', plugin_dir_url( __FILE__ ) . 'js/wl_entity-duplicated-titles-live-search.js' );
56
-			wp_localize_script( 'wl-entity-duplicated-titles-live-search', 'wlEntityDuplicatedTitlesLiveSearchParams', array(
57
-					'ajax_url' => admin_url( 'admin-ajax.php' ),
58
-					'action'   => 'entity_by_title',
59
-					'post_id'  => get_the_ID()
60
-				)
61
-			);
62
-		}
63
-	}
55
+            wp_enqueue_script( 'wl-entity-duplicated-titles-live-search', plugin_dir_url( __FILE__ ) . 'js/wl_entity-duplicated-titles-live-search.js' );
56
+            wp_localize_script( 'wl-entity-duplicated-titles-live-search', 'wlEntityDuplicatedTitlesLiveSearchParams', array(
57
+                    'ajax_url' => admin_url( 'admin-ajax.php' ),
58
+                    'action'   => 'entity_by_title',
59
+                    'post_id'  => get_the_ID()
60
+                )
61
+            );
62
+        }
63
+    }
64 64
 }
65 65
 
66 66
 add_action( 'admin_enqueue_scripts', 'wl_admin_search_duplicated_entity_while_editing_title' );
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -14,47 +14,47 @@  discard block
 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' 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' 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' 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' 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 );
38
+add_filter('get_sample_permalink_html', 'wl_admin_permalink_html', 10, 4);
39 39
 
40 40
 
41 41
 /*
42 42
  * Let user know if he is creating a duplicated entity (performing a live AJAX check on the entity title)
43 43
  */
44
-function wl_admin_search_duplicated_entity_while_editing_title( $hook ) {
44
+function wl_admin_search_duplicated_entity_while_editing_title($hook) {
45 45
 
46 46
 	// Only enqueueing script when editing an entity
47
-	if ( $hook == 'post.php' ) {
47
+	if ($hook == 'post.php') {
48 48
 
49 49
 		// Get entity object (the auto-draft created automagically by WP)
50 50
 		$entity_being_edited = get_post();
51 51
 
52 52
 		// Exit if we are not dealing with an entity
53
-		if ( $entity_being_edited->post_type == Wordlift_Entity_Service::TYPE_NAME ) {
53
+		if ($entity_being_edited->post_type == Wordlift_Entity_Service::TYPE_NAME) {
54 54
 
55
-			wp_enqueue_script( 'wl-entity-duplicated-titles-live-search', plugin_dir_url( __FILE__ ) . 'js/wl_entity-duplicated-titles-live-search.js' );
56
-			wp_localize_script( 'wl-entity-duplicated-titles-live-search', 'wlEntityDuplicatedTitlesLiveSearchParams', array(
57
-					'ajax_url' => admin_url( 'admin-ajax.php' ),
55
+			wp_enqueue_script('wl-entity-duplicated-titles-live-search', plugin_dir_url(__FILE__).'js/wl_entity-duplicated-titles-live-search.js');
56
+			wp_localize_script('wl-entity-duplicated-titles-live-search', 'wlEntityDuplicatedTitlesLiveSearchParams', array(
57
+					'ajax_url' => admin_url('admin-ajax.php'),
58 58
 					'action'   => 'entity_by_title',
59 59
 					'post_id'  => get_the_ID()
60 60
 				)
@@ -63,4 +63,4 @@  discard block
 block discarded – undo
63 63
 	}
64 64
 }
65 65
 
66
-add_action( 'admin_enqueue_scripts', 'wl_admin_search_duplicated_entity_while_editing_title' );
67 66
\ No newline at end of file
67
+add_action('admin_enqueue_scripts', 'wl_admin_search_duplicated_entity_while_editing_title');
68 68
\ 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.
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@  discard block
 block discarded – undo
14 14
     ) );
15 15
 }
16 16
 /**
17
- * Return an array of validation rules used by wl_core_get_posts
18
- * 
19
- * @return array in the format field => (array) accepeted_values 
20
- */
17
+     * Return an array of validation rules used by wl_core_get_posts
18
+     * 
19
+     * @return array in the format field => (array) accepeted_values 
20
+     */
21 21
 function wl_core_get_validation_rules() { 
22 22
 
23 23
     return unserialize( WL_CORE_GET_POSTS_VALIDATION_RULES );
24 24
 }
25 25
 /**
26
- * Return the wordlift relation instances table name
27
- * 
28
- * @return string Return the wordlift relation instances table name
29
- */
26
+     * Return the wordlift relation instances table name
27
+     * 
28
+     * @return string Return the wordlift relation instances table name
29
+     */
30 30
 function wl_core_get_relation_instances_table_name() { 
31 31
 
32 32
     global $wpdb;
@@ -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.
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.
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   +114 added lines, -114 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,21 +176,21 @@  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
-	// Build full schema uri if necessary
190
-	$type_names = wl_build_full_schema_uri_from_schema_slug( $type_names );
189
+    // Build full schema uri if necessary
190
+    $type_names = wl_build_full_schema_uri_from_schema_slug( $type_names );
191 191
 
192
-	// Actually sets the taxonomy type
193
-	wl_set_entity_main_type( $post_id, $type_names );
192
+    // Actually sets the taxonomy type
193
+    wl_set_entity_main_type( $post_id, $type_names );
194 194
 }
195 195
 
196 196
 /**
@@ -205,24 +205,24 @@  discard block
 block discarded – undo
205 205
  */
206 206
 function wl_schema_get_type_properties( $type_name ) {
207 207
 
208
-	// Build full schema uri if necessary
209
-	$type_name = wl_build_full_schema_uri_from_schema_slug( $type_name );
208
+    // Build full schema uri if necessary
209
+    $type_name = wl_build_full_schema_uri_from_schema_slug( $type_name );
210 210
 
211
-	// Get all custom fields
212
-	$all_types_and_fields = wl_entity_taxonomy_get_custom_fields();
211
+    // Get all custom fields
212
+    $all_types_and_fields = wl_entity_taxonomy_get_custom_fields();
213 213
 
214
-	$schema_root_address = 'http://schema.org/';
215
-	$type_properties     = array();
214
+    $schema_root_address = 'http://schema.org/';
215
+    $type_properties     = array();
216 216
 
217
-	// Search for the entity type which has the requested name as uri
218
-	if ( isset( $all_types_and_fields[ $type_name ] ) ) {
219
-		foreach ( $all_types_and_fields[ $type_name ] as $field ) {
220
-			// Convert to schema slug and store in array
221
-			$type_properties[] = str_replace( $schema_root_address, '', $field['predicate'] );
222
-		}
223
-	}
217
+    // Search for the entity type which has the requested name as uri
218
+    if ( isset( $all_types_and_fields[ $type_name ] ) ) {
219
+        foreach ( $all_types_and_fields[ $type_name ] as $field ) {
220
+            // Convert to schema slug and store in array
221
+            $type_properties[] = str_replace( $schema_root_address, '', $field['predicate'] );
222
+        }
223
+    }
224 224
 
225
-	return $type_properties;
225
+    return $type_properties;
226 226
 }
227 227
 
228 228
 /**
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
  */
235 235
 function wl_build_full_schema_uri_from_schema_slug( $schema_name ) {
236 236
 
237
-	$schema_root_address = 'http://schema.org/';
237
+    $schema_root_address = 'http://schema.org/';
238 238
 
239
-	if ( strpos( $schema_name, $schema_root_address ) === false ) {   // === necessary
240
-		$schema_name = $schema_root_address . $schema_name;
241
-	}
239
+    if ( strpos( $schema_name, $schema_root_address ) === false ) {   // === necessary
240
+        $schema_name = $schema_root_address . $schema_name;
241
+    }
242 242
 
243
-	return $schema_name;
243
+    return $schema_name;
244 244
 }
245 245
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 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,23 +174,23 @@  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
 	// Build full schema uri if necessary
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 192
 	// Actually sets the taxonomy type
193
-	wl_set_entity_main_type( $post_id, $type_names );
193
+	wl_set_entity_main_type($post_id, $type_names);
194 194
 }
195 195
 
196 196
 /**
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
  * @return array The method returns an array of supported properties for the type, e.g. (‘startDate’, ‘endDate’) for an Event.
204 204
  * You can call wl_schema_get_property_expected_type on each to know which data type they expect.
205 205
  */
206
-function wl_schema_get_type_properties( $type_name ) {
206
+function wl_schema_get_type_properties($type_name) {
207 207
 
208 208
 	// Build full schema uri if necessary
209
-	$type_name = wl_build_full_schema_uri_from_schema_slug( $type_name );
209
+	$type_name = wl_build_full_schema_uri_from_schema_slug($type_name);
210 210
 
211 211
 	// Get all custom fields
212 212
 	$all_types_and_fields = wl_entity_taxonomy_get_custom_fields();
@@ -215,10 +215,10 @@  discard block
 block discarded – undo
215 215
 	$type_properties     = array();
216 216
 
217 217
 	// Search for the entity type which has the requested name as uri
218
-	if ( isset( $all_types_and_fields[ $type_name ] ) ) {
219
-		foreach ( $all_types_and_fields[ $type_name ] as $field ) {
218
+	if (isset($all_types_and_fields[$type_name])) {
219
+		foreach ($all_types_and_fields[$type_name] as $field) {
220 220
 			// Convert to schema slug and store in array
221
-			$type_properties[] = str_replace( $schema_root_address, '', $field['predicate'] );
221
+			$type_properties[] = str_replace($schema_root_address, '', $field['predicate']);
222 222
 		}
223 223
 	}
224 224
 
@@ -232,12 +232,12 @@  discard block
 block discarded – undo
232 232
  *
233 233
  * @return string The full schema uri (es. 'latitude' returns 'http://schema.org/latitude')
234 234
  */
235
-function wl_build_full_schema_uri_from_schema_slug( $schema_name ) {
235
+function wl_build_full_schema_uri_from_schema_slug($schema_name) {
236 236
 
237 237
 	$schema_root_address = 'http://schema.org/';
238 238
 
239
-	if ( strpos( $schema_name, $schema_root_address ) === false ) {   // === necessary
240
-		$schema_name = $schema_root_address . $schema_name;
239
+	if (strpos($schema_name, $schema_root_address) === false) {   // === necessary
240
+		$schema_name = $schema_root_address.$schema_name;
241 241
 	}
242 242
 
243 243
 	return $schema_name;
Please login to merge, or discard this patch.
src/modules/entity_view/class-wl-view.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -132,6 +132,9 @@
 block discarded – undo
132 132
 
133 133
 	}
134 134
 
135
+	/**
136
+	 * @param string $expr
137
+	 */
135 138
 	function expand( $expr ) {
136 139
 
137 140
 		foreach ( wl_prefixes_list() as $item ) {
Please login to merge, or discard this patch.
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -2,17 +2,17 @@  discard block
 block discarded – undo
2 2
 
3 3
 // Load JsonPath.
4 4
 if ( ! class_exists( 'JSONPath' ) ) {
5
-	require_once( 'JSONPath/JSONPath.php' );
6
-	require_once( 'JSONPath/JSONPathLexer.php' );
7
-	require_once( 'JSONPath/JSONPathException.php' );
8
-	require_once( 'JSONPath/Filters/AbstractFilter.php' );
9
-	require_once( 'JSONPath/Filters/IndexesFilter.php' );
10
-	require_once( 'JSONPath/Filters/IndexFilter.php' );
11
-	require_once( 'JSONPath/Filters/QueryMatchFilter.php' );
12
-	require_once( 'JSONPath/Filters/QueryResultFilter.php' );
13
-	require_once( 'JSONPath/Filters/RecursiveFilter.php' );
14
-	require_once( 'JSONPath/Filters/SliceFilter.php' );
15
-	require_once( 'JSONPath/Filters/LoadFilter.php' );
5
+    require_once( 'JSONPath/JSONPath.php' );
6
+    require_once( 'JSONPath/JSONPathLexer.php' );
7
+    require_once( 'JSONPath/JSONPathException.php' );
8
+    require_once( 'JSONPath/Filters/AbstractFilter.php' );
9
+    require_once( 'JSONPath/Filters/IndexesFilter.php' );
10
+    require_once( 'JSONPath/Filters/IndexFilter.php' );
11
+    require_once( 'JSONPath/Filters/QueryMatchFilter.php' );
12
+    require_once( 'JSONPath/Filters/QueryResultFilter.php' );
13
+    require_once( 'JSONPath/Filters/RecursiveFilter.php' );
14
+    require_once( 'JSONPath/Filters/SliceFilter.php' );
15
+    require_once( 'JSONPath/Filters/LoadFilter.php' );
16 16
 }
17 17
 
18 18
 
@@ -25,219 +25,219 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class WL_View {
27 27
 
28
-	var $base_uri, $suffix, $title, $language, $graph, $url;
29
-
30
-	var $json_path;
31
-
32
-	/**
33
-	 * Create an instance of WL_View.
34
-	 *
35
-	 * @since 3.0.0
36
-	 *
37
-	 * @uses wl_configuration_get_redlink_dataset_uri() to get the default dataset URI.
38
-	 *
39
-	 * @param string $base_uri The base URI for resources, default the WordLift dataset.
40
-	 * @param string $suffix The suffix to append to URI in order to load the JSON-LD file, default *.json*.
41
-	 * @param string $title The predicate used to set the title of the page, default *rdfs:label*.
42
-	 * @param string $language The language for values, default *en*.
43
-	 */
44
-	function __construct( $base_uri = null, $suffix = '.json', $title = 'rdfs:label', $language = 'en' ) {
45
-
46
-		// Set the instance variables.
47
-		$this->base_uri = ( null === $base_uri ? wl_configuration_get_redlink_dataset_uri() : $base_uri );
48
-		$this->suffix   = $suffix;
49
-		$this->title    = $title;
50
-		$this->language = $language;
51
-
52
-		wl_write_log( "[ base URI :: $this->base_uri ][ suffix :: $this->suffix ][ title :: $this->title ][ language :: $this->language ]" );
53
-
54
-		add_filter( 'wp_title', array( $this, 'filter_page_title' ), 10, 2 );
55
-	}
56
-
57
-
58
-
59
-	/**
60
-	 * Set the page title using the provided title.
61
-	 *
62
-	 * @since 3.0.0
63
-	 *
64
-	 * @see wp_title the WordPress filter that calls this method.
65
-	 * @see http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title
66
-	 *
67
-	 * @param string $title The existing title.
68
-	 * @param string $sep   The title separator.
69
-	 * @return string The new title.
70
-	 */
71
-	function filter_page_title( $title, $sep ) {
72
-
73
-		$expr       = "$['$this->title'][?(@.@language=='$this->language')].@value";
74
-		$view_title = $this->get_first_property_html( $expr );
75
-
76
-		return $view_title . " $sep $title";
77
-
78
-	}
79
-
80
-	/**
81
-	 * Load the JSON-LD at the specified path (the path is appended to the *base_uri*). If the path is empty or null
82
-	 * it is loaded from the query variables (via WordPress).
83
-	 *
84
-	 * @since 3.0.0
85
-	 *
86
-	 * @uses wl_configuration_get_redlink_dataset_uri() to get the default dataset URI.
87
-	 * @uses wl_jsonld_load_remote() to load a remote JSON-LD file.
88
-	 *
89
-	 * @param string $path The entity path.
90
-	 */
91
-	function load( $path = null ) {
92
-
93
-		// If the path is empty, load the resource from the query string variable.
94
-		if ( empty( $path ) ) {
95
-			$path = get_query_var( WL_ENTITY_VIEW_ENTITY_ID_QUERY_VAR );
96
-		}
97
-
98
-		// If a base URI has been set, append the path, otherwise use the path.
99
-		$this->url = ( ! empty( $this->base_uri )
100
-			? $this->base_uri . ( '/' !== substr( $this->base_uri, - 1, 1 ) ? '/' : '' ) . $path
101
-			: $path );
102
-
103
-		$this->graph     = wl_jsonld_load_remote( $this->url . $this->suffix );
104
-		$this->json_path = new JSONPath( $this->graph );
105
-
106
-	}
107
-
108
-	/**
109
-	 * Get the property with the specified name. The value at the specified index will be returned.
110
-	 *
111
-	 * @since 3.0.0
112
-	 *
113
-	 * @uses expand() to expand the property name.
114
-	 *
115
-	 * @param string $name          The property name.
116
-	 * @param int $index            The value index (default NULL, returns an array of properties).
117
-	 *
118
-	 * @return string|array The property value.
119
-	 */
120
-	function get_property( $name, $index = NULL ) {
121
-
122
-
123
-		$values = $this->json_path->find( $this->expand( $name ) );
124
-
125
-		wl_write_log( "[ name :: $name ][ index :: $index ][ value :: " . var_export( $values, true ) . " ]" );
126
-
127
-
128
-		return ( NULL !== $index ? $values[ $index ] : $values );
28
+    var $base_uri, $suffix, $title, $language, $graph, $url;
29
+
30
+    var $json_path;
31
+
32
+    /**
33
+     * Create an instance of WL_View.
34
+     *
35
+     * @since 3.0.0
36
+     *
37
+     * @uses wl_configuration_get_redlink_dataset_uri() to get the default dataset URI.
38
+     *
39
+     * @param string $base_uri The base URI for resources, default the WordLift dataset.
40
+     * @param string $suffix The suffix to append to URI in order to load the JSON-LD file, default *.json*.
41
+     * @param string $title The predicate used to set the title of the page, default *rdfs:label*.
42
+     * @param string $language The language for values, default *en*.
43
+     */
44
+    function __construct( $base_uri = null, $suffix = '.json', $title = 'rdfs:label', $language = 'en' ) {
45
+
46
+        // Set the instance variables.
47
+        $this->base_uri = ( null === $base_uri ? wl_configuration_get_redlink_dataset_uri() : $base_uri );
48
+        $this->suffix   = $suffix;
49
+        $this->title    = $title;
50
+        $this->language = $language;
51
+
52
+        wl_write_log( "[ base URI :: $this->base_uri ][ suffix :: $this->suffix ][ title :: $this->title ][ language :: $this->language ]" );
53
+
54
+        add_filter( 'wp_title', array( $this, 'filter_page_title' ), 10, 2 );
55
+    }
56
+
57
+
58
+
59
+    /**
60
+     * Set the page title using the provided title.
61
+     *
62
+     * @since 3.0.0
63
+     *
64
+     * @see wp_title the WordPress filter that calls this method.
65
+     * @see http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title
66
+     *
67
+     * @param string $title The existing title.
68
+     * @param string $sep   The title separator.
69
+     * @return string The new title.
70
+     */
71
+    function filter_page_title( $title, $sep ) {
72
+
73
+        $expr       = "$['$this->title'][?(@.@language=='$this->language')].@value";
74
+        $view_title = $this->get_first_property_html( $expr );
75
+
76
+        return $view_title . " $sep $title";
77
+
78
+    }
79
+
80
+    /**
81
+     * Load the JSON-LD at the specified path (the path is appended to the *base_uri*). If the path is empty or null
82
+     * it is loaded from the query variables (via WordPress).
83
+     *
84
+     * @since 3.0.0
85
+     *
86
+     * @uses wl_configuration_get_redlink_dataset_uri() to get the default dataset URI.
87
+     * @uses wl_jsonld_load_remote() to load a remote JSON-LD file.
88
+     *
89
+     * @param string $path The entity path.
90
+     */
91
+    function load( $path = null ) {
92
+
93
+        // If the path is empty, load the resource from the query string variable.
94
+        if ( empty( $path ) ) {
95
+            $path = get_query_var( WL_ENTITY_VIEW_ENTITY_ID_QUERY_VAR );
96
+        }
97
+
98
+        // If a base URI has been set, append the path, otherwise use the path.
99
+        $this->url = ( ! empty( $this->base_uri )
100
+            ? $this->base_uri . ( '/' !== substr( $this->base_uri, - 1, 1 ) ? '/' : '' ) . $path
101
+            : $path );
102
+
103
+        $this->graph     = wl_jsonld_load_remote( $this->url . $this->suffix );
104
+        $this->json_path = new JSONPath( $this->graph );
105
+
106
+    }
107
+
108
+    /**
109
+     * Get the property with the specified name. The value at the specified index will be returned.
110
+     *
111
+     * @since 3.0.0
112
+     *
113
+     * @uses expand() to expand the property name.
114
+     *
115
+     * @param string $name          The property name.
116
+     * @param int $index            The value index (default NULL, returns an array of properties).
117
+     *
118
+     * @return string|array The property value.
119
+     */
120
+    function get_property( $name, $index = NULL ) {
121
+
122
+
123
+        $values = $this->json_path->find( $this->expand( $name ) );
124
+
125
+        wl_write_log( "[ name :: $name ][ index :: $index ][ value :: " . var_export( $values, true ) . " ]" );
126
+
127
+
128
+        return ( NULL !== $index ? $values[ $index ] : $values );
129 129
 
130 130
 //		$value = wl_jsonld_get_property( $this->graph, $name, $language, $this->suffix, $index );
131 131
 //		return $value;
132 132
 
133
-	}
133
+    }
134 134
 
135
-	function expand( $expr ) {
135
+    function expand( $expr ) {
136 136
 
137
-		foreach ( wl_prefixes_list() as $item ) {
138
-			$prefix    = $item['prefix'];
139
-			$namespace = $item['namespace'];
140
-			$expr      = preg_replace( "/(['\"])$prefix:/", "\${1}$namespace", $expr );
141
-			$expr      = preg_replace( "/\\.$prefix:([^.]+)\\./", "['$namespace\${1}']", $expr );
142
-		}
137
+        foreach ( wl_prefixes_list() as $item ) {
138
+            $prefix    = $item['prefix'];
139
+            $namespace = $item['namespace'];
140
+            $expr      = preg_replace( "/(['\"])$prefix:/", "\${1}$namespace", $expr );
141
+            $expr      = preg_replace( "/\\.$prefix:([^.]+)\\./", "['$namespace\${1}']", $expr );
142
+        }
143 143
 
144 144
 
145
-		return $expr;
146
-	}
145
+        return $expr;
146
+    }
147 147
 
148
-	function get_property_html( $name, $index = 0 ) {
148
+    function get_property_html( $name, $index = 0 ) {
149 149
 
150
-		return esc_html( $this->get_property( $name, $index ) );
150
+        return esc_html( $this->get_property( $name, $index ) );
151 151
 
152
-	}
152
+    }
153 153
 
154
-	/**
155
-	 * Gets the first property with the provided name.
156
-	 *
157
-	 * @since 3.0.0
158
-	 *
159
-	 * @uses get_first_property() to get the first property value.
160
-	 *
161
-	 * @param string $name The predicate name.
162
-	 *
163
-	 * @return string The value.
164
-	 */
165
-	function get_first_property_html( $name ) {
154
+    /**
155
+     * Gets the first property with the provided name.
156
+     *
157
+     * @since 3.0.0
158
+     *
159
+     * @uses get_first_property() to get the first property value.
160
+     *
161
+     * @param string $name The predicate name.
162
+     *
163
+     * @return string The value.
164
+     */
165
+    function get_first_property_html( $name ) {
166 166
 
167
-		return esc_html( $this->get_first_property( $name ) );
167
+        return esc_html( $this->get_first_property( $name ) );
168 168
 
169
-	}
169
+    }
170 170
 
171
-	/**
172
-	 * Gets the first property with the provided name and returns it HTML escaped.
173
-	 *
174
-	 * @since 3.0.0
175
-	 *
176
-	 * @uses get_property() to get the property value.
177
-	 *
178
-	 * @param string $name The predicate name.
179
-	 *
180
-	 * @return string The value.
181
-	 */
182
-	function get_first_property( $name ) {
171
+    /**
172
+     * Gets the first property with the provided name and returns it HTML escaped.
173
+     *
174
+     * @since 3.0.0
175
+     *
176
+     * @uses get_property() to get the property value.
177
+     *
178
+     * @param string $name The predicate name.
179
+     *
180
+     * @return string The value.
181
+     */
182
+    function get_first_property( $name ) {
183 183
 
184
-		return $this->get_property( $name, 0 );
184
+        return $this->get_property( $name, 0 );
185 185
 
186
-	}
186
+    }
187 187
 
188 188
 
189
-	function echo_property( $name, $index = 0 ) {
189
+    function echo_property( $name, $index = 0 ) {
190 190
 
191
-		echo $this->get_property( $name, $index );
191
+        echo $this->get_property( $name, $index );
192 192
 
193
-	}
193
+    }
194 194
 
195
-	/**
196
-	 * @since 3.0.0
197
-	 *
198
-	 * @param $name
199
-	 *
200
-	 * @return string
201
-	 */
202
-	function get_property_localized( $name ) {
195
+    /**
196
+     * @since 3.0.0
197
+     *
198
+     * @param $name
199
+     *
200
+     * @return string
201
+     */
202
+    function get_property_localized( $name ) {
203 203
 
204
-		return $this->get_property( $this->localize_expression( $name ) );
204
+        return $this->get_property( $this->localize_expression( $name ) );
205 205
 
206
-	}
206
+    }
207 207
 
208
-	function get_first_property_localized( $name ) {
208
+    function get_first_property_localized( $name ) {
209 209
 
210
-		return $this->get_first_property( $this->localize_expression( $name ) );
210
+        return $this->get_first_property( $this->localize_expression( $name ) );
211 211
 
212
-	}
212
+    }
213 213
 
214
-	/**
215
-	 * @since 3.0.0
216
-	 *
217
-	 * @param $name
218
-	 *
219
-	 * @return string
220
-	 */
221
-	function get_first_property_html_localized( $name ) {
214
+    /**
215
+     * @since 3.0.0
216
+     *
217
+     * @param $name
218
+     *
219
+     * @return string
220
+     */
221
+    function get_first_property_html_localized( $name ) {
222 222
 
223
-		return esc_html( $this->get_first_property_localized( $name ) );
223
+        return esc_html( $this->get_first_property_localized( $name ) );
224 224
 
225
-	}
225
+    }
226 226
 
227
-	/**
228
-	 * Localizes the expression using the language set when creating the view instance.
229
-	 *
230
-	 * @since 3.0.0
231
-	 *
232
-	 * @param string $name The expression to localize.
233
-	 *
234
-	 * @return string The localized expression.
235
-	 */
236
-	function localize_expression( $name ) {
227
+    /**
228
+     * Localizes the expression using the language set when creating the view instance.
229
+     *
230
+     * @since 3.0.0
231
+     *
232
+     * @param string $name The expression to localize.
233
+     *
234
+     * @return string The localized expression.
235
+     */
236
+    function localize_expression( $name ) {
237 237
 
238
-		return $name . "[?(@.@language=='$this->language')].@value";
238
+        return $name . "[?(@.@language=='$this->language')].@value";
239 239
 
240
-	}
240
+    }
241 241
 
242 242
 
243 243
 } 
244 244
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Load JsonPath.
4
-if ( ! class_exists( 'JSONPath' ) ) {
5
-	require_once( 'JSONPath/JSONPath.php' );
6
-	require_once( 'JSONPath/JSONPathLexer.php' );
7
-	require_once( 'JSONPath/JSONPathException.php' );
8
-	require_once( 'JSONPath/Filters/AbstractFilter.php' );
9
-	require_once( 'JSONPath/Filters/IndexesFilter.php' );
10
-	require_once( 'JSONPath/Filters/IndexFilter.php' );
11
-	require_once( 'JSONPath/Filters/QueryMatchFilter.php' );
12
-	require_once( 'JSONPath/Filters/QueryResultFilter.php' );
13
-	require_once( 'JSONPath/Filters/RecursiveFilter.php' );
14
-	require_once( 'JSONPath/Filters/SliceFilter.php' );
15
-	require_once( 'JSONPath/Filters/LoadFilter.php' );
4
+if ( ! class_exists('JSONPath')) {
5
+	require_once('JSONPath/JSONPath.php');
6
+	require_once('JSONPath/JSONPathLexer.php');
7
+	require_once('JSONPath/JSONPathException.php');
8
+	require_once('JSONPath/Filters/AbstractFilter.php');
9
+	require_once('JSONPath/Filters/IndexesFilter.php');
10
+	require_once('JSONPath/Filters/IndexFilter.php');
11
+	require_once('JSONPath/Filters/QueryMatchFilter.php');
12
+	require_once('JSONPath/Filters/QueryResultFilter.php');
13
+	require_once('JSONPath/Filters/RecursiveFilter.php');
14
+	require_once('JSONPath/Filters/SliceFilter.php');
15
+	require_once('JSONPath/Filters/LoadFilter.php');
16 16
 }
17 17
 
18 18
 
@@ -41,17 +41,17 @@  discard block
 block discarded – undo
41 41
 	 * @param string $title The predicate used to set the title of the page, default *rdfs:label*.
42 42
 	 * @param string $language The language for values, default *en*.
43 43
 	 */
44
-	function __construct( $base_uri = null, $suffix = '.json', $title = 'rdfs:label', $language = 'en' ) {
44
+	function __construct($base_uri = null, $suffix = '.json', $title = 'rdfs:label', $language = 'en') {
45 45
 
46 46
 		// Set the instance variables.
47
-		$this->base_uri = ( null === $base_uri ? wl_configuration_get_redlink_dataset_uri() : $base_uri );
47
+		$this->base_uri = (null === $base_uri ? wl_configuration_get_redlink_dataset_uri() : $base_uri);
48 48
 		$this->suffix   = $suffix;
49 49
 		$this->title    = $title;
50 50
 		$this->language = $language;
51 51
 
52
-		wl_write_log( "[ base URI :: $this->base_uri ][ suffix :: $this->suffix ][ title :: $this->title ][ language :: $this->language ]" );
52
+		wl_write_log("[ base URI :: $this->base_uri ][ suffix :: $this->suffix ][ title :: $this->title ][ language :: $this->language ]");
53 53
 
54
-		add_filter( 'wp_title', array( $this, 'filter_page_title' ), 10, 2 );
54
+		add_filter('wp_title', array($this, 'filter_page_title'), 10, 2);
55 55
 	}
56 56
 
57 57
 
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
 	 * @param string $sep   The title separator.
69 69
 	 * @return string The new title.
70 70
 	 */
71
-	function filter_page_title( $title, $sep ) {
71
+	function filter_page_title($title, $sep) {
72 72
 
73 73
 		$expr       = "$['$this->title'][?(@.@language=='$this->language')].@value";
74
-		$view_title = $this->get_first_property_html( $expr );
74
+		$view_title = $this->get_first_property_html($expr);
75 75
 
76
-		return $view_title . " $sep $title";
76
+		return $view_title." $sep $title";
77 77
 
78 78
 	}
79 79
 
@@ -88,20 +88,20 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @param string $path The entity path.
90 90
 	 */
91
-	function load( $path = null ) {
91
+	function load($path = null) {
92 92
 
93 93
 		// If the path is empty, load the resource from the query string variable.
94
-		if ( empty( $path ) ) {
95
-			$path = get_query_var( WL_ENTITY_VIEW_ENTITY_ID_QUERY_VAR );
94
+		if (empty($path)) {
95
+			$path = get_query_var(WL_ENTITY_VIEW_ENTITY_ID_QUERY_VAR);
96 96
 		}
97 97
 
98 98
 		// If a base URI has been set, append the path, otherwise use the path.
99
-		$this->url = ( ! empty( $this->base_uri )
100
-			? $this->base_uri . ( '/' !== substr( $this->base_uri, - 1, 1 ) ? '/' : '' ) . $path
101
-			: $path );
99
+		$this->url = ( ! empty($this->base_uri)
100
+			? $this->base_uri.('/' !== substr($this->base_uri, - 1, 1) ? '/' : '').$path
101
+			: $path);
102 102
 
103
-		$this->graph     = wl_jsonld_load_remote( $this->url . $this->suffix );
104
-		$this->json_path = new JSONPath( $this->graph );
103
+		$this->graph     = wl_jsonld_load_remote($this->url.$this->suffix);
104
+		$this->json_path = new JSONPath($this->graph);
105 105
 
106 106
 	}
107 107
 
@@ -117,37 +117,37 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @return string|array The property value.
119 119
 	 */
120
-	function get_property( $name, $index = NULL ) {
120
+	function get_property($name, $index = NULL) {
121 121
 
122 122
 
123
-		$values = $this->json_path->find( $this->expand( $name ) );
123
+		$values = $this->json_path->find($this->expand($name));
124 124
 
125
-		wl_write_log( "[ name :: $name ][ index :: $index ][ value :: " . var_export( $values, true ) . " ]" );
125
+		wl_write_log("[ name :: $name ][ index :: $index ][ value :: ".var_export($values, true)." ]");
126 126
 
127 127
 
128
-		return ( NULL !== $index ? $values[ $index ] : $values );
128
+		return (NULL !== $index ? $values[$index] : $values);
129 129
 
130 130
 //		$value = wl_jsonld_get_property( $this->graph, $name, $language, $this->suffix, $index );
131 131
 //		return $value;
132 132
 
133 133
 	}
134 134
 
135
-	function expand( $expr ) {
135
+	function expand($expr) {
136 136
 
137
-		foreach ( wl_prefixes_list() as $item ) {
137
+		foreach (wl_prefixes_list() as $item) {
138 138
 			$prefix    = $item['prefix'];
139 139
 			$namespace = $item['namespace'];
140
-			$expr      = preg_replace( "/(['\"])$prefix:/", "\${1}$namespace", $expr );
141
-			$expr      = preg_replace( "/\\.$prefix:([^.]+)\\./", "['$namespace\${1}']", $expr );
140
+			$expr      = preg_replace("/(['\"])$prefix:/", "\${1}$namespace", $expr);
141
+			$expr      = preg_replace("/\\.$prefix:([^.]+)\\./", "['$namespace\${1}']", $expr);
142 142
 		}
143 143
 
144 144
 
145 145
 		return $expr;
146 146
 	}
147 147
 
148
-	function get_property_html( $name, $index = 0 ) {
148
+	function get_property_html($name, $index = 0) {
149 149
 
150
-		return esc_html( $this->get_property( $name, $index ) );
150
+		return esc_html($this->get_property($name, $index));
151 151
 
152 152
 	}
153 153
 
@@ -162,9 +162,9 @@  discard block
 block discarded – undo
162 162
 	 *
163 163
 	 * @return string The value.
164 164
 	 */
165
-	function get_first_property_html( $name ) {
165
+	function get_first_property_html($name) {
166 166
 
167
-		return esc_html( $this->get_first_property( $name ) );
167
+		return esc_html($this->get_first_property($name));
168 168
 
169 169
 	}
170 170
 
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
 	 *
180 180
 	 * @return string The value.
181 181
 	 */
182
-	function get_first_property( $name ) {
182
+	function get_first_property($name) {
183 183
 
184
-		return $this->get_property( $name, 0 );
184
+		return $this->get_property($name, 0);
185 185
 
186 186
 	}
187 187
 
188 188
 
189
-	function echo_property( $name, $index = 0 ) {
189
+	function echo_property($name, $index = 0) {
190 190
 
191
-		echo $this->get_property( $name, $index );
191
+		echo $this->get_property($name, $index);
192 192
 
193 193
 	}
194 194
 
@@ -199,15 +199,15 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @return string
201 201
 	 */
202
-	function get_property_localized( $name ) {
202
+	function get_property_localized($name) {
203 203
 
204
-		return $this->get_property( $this->localize_expression( $name ) );
204
+		return $this->get_property($this->localize_expression($name));
205 205
 
206 206
 	}
207 207
 
208
-	function get_first_property_localized( $name ) {
208
+	function get_first_property_localized($name) {
209 209
 
210
-		return $this->get_first_property( $this->localize_expression( $name ) );
210
+		return $this->get_first_property($this->localize_expression($name));
211 211
 
212 212
 	}
213 213
 
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
 	 *
219 219
 	 * @return string
220 220
 	 */
221
-	function get_first_property_html_localized( $name ) {
221
+	function get_first_property_html_localized($name) {
222 222
 
223
-		return esc_html( $this->get_first_property_localized( $name ) );
223
+		return esc_html($this->get_first_property_localized($name));
224 224
 
225 225
 	}
226 226
 
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 	 *
234 234
 	 * @return string The localized expression.
235 235
 	 */
236
-	function localize_expression( $name ) {
236
+	function localize_expression($name) {
237 237
 
238
-		return $name . "[?(@.@language=='$this->language')].@value";
238
+		return $name."[?(@.@language=='$this->language')].@value";
239 239
 
240 240
 	}
241 241
 
Please login to merge, or discard this patch.
src/modules/entity_view/JSONPath/JSONPathLexer.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -36,6 +36,9 @@
 block discarded – undo
36 36
     const MATCH_LOAD         = '\s* !\(.+?\) \s*';
37 37
 
38 38
 
39
+    /**
40
+     * @param string $expression
41
+     */
39 42
     public function __construct($expression)
40 43
     {
41 44
         $this->expression = $expression;
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     {
46 46
         $tokens = [];
47 47
 
48
-        $regex = '/(' . implode(')|(', $this->getCatchablePatterns()) . ')/i';
48
+        $regex = '/('.implode(')|(', $this->getCatchablePatterns()).')/i';
49 49
 
50 50
         $flags   = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE;
51 51
         $matches = preg_split($regex, $this->expression, -1, $flags);
@@ -84,20 +84,20 @@  discard block
 block discarded – undo
84 84
     protected function getType(&$value)
85 85
     {
86 86
 
87
-        if (preg_match('/^' . static::GROUP_DOT_INDEX . '$/x', $value)) {
87
+        if (preg_match('/^'.static::GROUP_DOT_INDEX.'$/x', $value)) {
88 88
             $value = substr($value, 1);
89 89
             return self::T_INDEX;
90 90
         }
91 91
 
92
-        if (preg_match('/^' . static::GROUP_RECURSIVE_INDEX . '$/x', $value)) {
92
+        if (preg_match('/^'.static::GROUP_RECURSIVE_INDEX.'$/x', $value)) {
93 93
             $value = substr($value, 2);
94 94
             return self::T_RECURSIVE;
95 95
         }
96 96
 
97
-        if (preg_match('/^' . static::GROUP_BRACKET . '$/x', $value)) {
97
+        if (preg_match('/^'.static::GROUP_BRACKET.'$/x', $value)) {
98 98
             $value = substr($value, 1, -1);
99 99
 
100
-            if (preg_match('/^' . static::MATCH_LOAD . '$/x', $value)) {
100
+            if (preg_match('/^'.static::MATCH_LOAD.'$/x', $value)) {
101 101
 
102 102
 //                var_dump( 'I am a remote load' );
103 103
                 $value = substr($value, 2, -1);
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 
107 107
             }
108 108
 
109
-            if (preg_match('/^(' . static::MATCH_INDEX . ')$/x', $value, $bracketMatches)) {
109
+            if (preg_match('/^('.static::MATCH_INDEX.')$/x', $value, $bracketMatches)) {
110 110
                 return self::T_INDEX;
111 111
             }
112 112
 
113
-            if (preg_match('/^' . static::MATCH_INDEXES . '$/x', $value, $bracketMatches)) {
113
+            if (preg_match('/^'.static::MATCH_INDEXES.'$/x', $value, $bracketMatches)) {
114 114
                 $value = explode(',', $value);
115 115
                 foreach ($value as & $v) {
116 116
                     $v = (int) trim($v);
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
                 return self::T_INDEXES;
119 119
             }
120 120
 
121
-            if (preg_match('/^' . static::MATCH_SLICE . '$/x', $value, $bracketMatches)) {
121
+            if (preg_match('/^'.static::MATCH_SLICE.'$/x', $value, $bracketMatches)) {
122 122
                 $parts = explode(':', $value);
123 123
 
124 124
                 $value = [
@@ -130,19 +130,19 @@  discard block
 block discarded – undo
130 130
                 return self::T_SLICE;
131 131
             }
132 132
 
133
-            if (preg_match('/^' . static::MATCH_QUERY_RESULT . '$/x', $value)) {
133
+            if (preg_match('/^'.static::MATCH_QUERY_RESULT.'$/x', $value)) {
134 134
                 $value = substr($value, 1, -1);
135 135
 
136 136
                 return self::T_QUERY_RESULT;
137 137
             }
138 138
 
139
-            if (preg_match('/^' . static::MATCH_QUERY_MATCH . '$/x', $value)) {
139
+            if (preg_match('/^'.static::MATCH_QUERY_MATCH.'$/x', $value)) {
140 140
                 $value = substr($value, 2, -1);
141 141
 
142 142
                 return self::T_QUERY_MATCH;
143 143
             }
144 144
 
145
-            if (preg_match('/^' . static::MATCH_INDEX_ALT . '$/x', $value, $bracketMatches)) {
145
+            if (preg_match('/^'.static::MATCH_INDEX_ALT.'$/x', $value, $bracketMatches)) {
146 146
                 $value = $bracketMatches[1];
147 147
                 $value = trim($value);
148 148
 
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   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -14,48 +14,48 @@  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 );
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
-		) );
27
-	}
28
-
29
-	// If is not a global geomap, an empty $related_ids means that no entities are related to the post
30
-	// An empty array can be returned in this case
31
-	if ( ! $is_global && empty( $related_ids ) ) {
32
-		return array();
33
-	}
34
-
35
-	// Retrieve all 'published' places with geo coordinates defined
36
-	// If $place_ids is not empty, it's used to limit query results to the current post related places
37
-	// Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query
38
-	$places = get_posts( array(
39
-		'post__in'    => $related_ids,
40
-		'post_type'   => Wordlift_Entity_Service::TYPE_NAME,
41
-		'nopaging'    => true,
42
-		'post_status' => 'published',
43
-		'meta_query'  => array(
44
-			'relation' => 'AND',
45
-			array(
46
-				'key'     => Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
47
-				'value'   => null,
48
-				'compare' => '!=',
49
-			),
50
-			array(
51
-				'key'     => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
52
-				'value'   => null,
53
-				'compare' => '!=',
54
-			)
55
-		)
56
-	) );
57
-
58
-	return $places;
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
+
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
+    }
28
+
29
+    // If is not a global geomap, an empty $related_ids means that no entities are related to the post
30
+    // An empty array can be returned in this case
31
+    if ( ! $is_global && empty( $related_ids ) ) {
32
+        return array();
33
+    }
34
+
35
+    // Retrieve all 'published' places with geo coordinates defined
36
+    // If $place_ids is not empty, it's used to limit query results to the current post related places
37
+    // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query
38
+    $places = get_posts( array(
39
+        'post__in'    => $related_ids,
40
+        'post_type'   => Wordlift_Entity_Service::TYPE_NAME,
41
+        'nopaging'    => true,
42
+        'post_status' => 'published',
43
+        'meta_query'  => array(
44
+            'relation' => 'AND',
45
+            array(
46
+                'key'     => Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
47
+                'value'   => null,
48
+                'compare' => '!=',
49
+            ),
50
+            array(
51
+                'key'     => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
52
+                'value'   => null,
53
+                'compare' => '!=',
54
+            )
55
+        )
56
+    ) );
57
+
58
+    return $places;
59 59
 }
60 60
 
61 61
 /**
@@ -70,88 +70,88 @@  discard block
 block discarded – undo
70 70
  */
71 71
 function wl_shortcode_geomap_prepare_map( $places ) {
72 72
 
73
-	// Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript.
74
-	$min_latitude  = PHP_INT_MAX;
75
-	$min_longitude = PHP_INT_MAX;
76
-	$max_latitude  = ~PHP_INT_MAX;
77
-	$max_longitude = ~PHP_INT_MAX;
78
-
79
-	// Prepare an empty array of POIs in geoJSON format.
80
-	$pois = array();
81
-	// And store list of points to allow Leaflet compute the optimal bounding box.
82
-	// The main reason for this is that geoJSON has swapped coordinates (lon. lat)
83
-	$boundaries = array();
84
-
85
-	// Add a POI for each entity that has coordinates.
86
-	foreach ( $places as $entity ) {
87
-
88
-		// Get the coordinates.
89
-		$coordinates = wl_get_coordinates( $entity->ID );
90
-
91
-		// Don't show the widget if the coordinates aren't set.
92
-		if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) {
93
-			continue;
94
-		}
95
-
96
-		// TODO Map html rendering should be delegated to the wordlift js ui layer
97
-		// This function should be focused on returning pure data instead
98
-
99
-		// Get the title, URL and thumb of the entity.
100
-		$title = esc_attr( $entity->post_title );
101
-		$link  = esc_attr( get_permalink( $entity->ID ) );
102
-		if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) &&
103
-		     false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) )
104
-		) {
105
-			$img_src = esc_attr( $attachment[0] );
106
-		}
107
-
108
-		// Build HTML popup. TODO: move thumb width in css
109
-		$content = "<a href=$link><h6>$title</h6>";
110
-		if ( isset( $img_src ) ) {
111
-			$content = $content . "<img src=$img_src style='width:100%'/>";
112
-		}
113
-		$content = $content . "</a><ul>";
114
-		// Get the related posts (published) and print them in the popup.
115
-		$related_posts = wl_core_get_related_post_ids( $entity->ID, array(
116
-			'status' => 'publish'
117
-		) );
118
-		foreach ( $related_posts as $rp_id ) {
119
-
120
-			$rp      = get_post( $rp_id );
121
-			$title   = esc_attr( $rp->post_title );
122
-			$link    = esc_attr( get_permalink( $rp->ID ) );
123
-			$content = $content . "<li><a href=$link>$title</a></li>";
124
-		}
125
-		$content = $content . "</ul>";
126
-
127
-		// Formatting POI in geoJSON.
128
-		// http://leafletjs.com/examples/geojson.html
129
-		$poi = array(
130
-			'type'       => 'Feature',
131
-			'properties' => array( 'popupContent' => $content ),
132
-			'geometry'   => array(
133
-				'type'        => 'Point',
134
-				'coordinates' => array(
135
-					// Leaflet geoJSON wants them swapped
136
-					$coordinates['longitude'],
137
-					$coordinates['latitude']
138
-				)
139
-			)
140
-		);
141
-
142
-		$pois[] = $poi;
143
-
144
-		// Formatting boundaries in a Leaflet-like format (see LatLngBounds).
145
-		// http://leafletjs.com/reference.html#latlngbounds
146
-		$boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] );
147
-
148
-	}
149
-
150
-	$map_data               = array();
151
-	$map_data['features']   = $pois;
152
-	$map_data['boundaries'] = $boundaries;
153
-
154
-	return $map_data;
73
+    // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript.
74
+    $min_latitude  = PHP_INT_MAX;
75
+    $min_longitude = PHP_INT_MAX;
76
+    $max_latitude  = ~PHP_INT_MAX;
77
+    $max_longitude = ~PHP_INT_MAX;
78
+
79
+    // Prepare an empty array of POIs in geoJSON format.
80
+    $pois = array();
81
+    // And store list of points to allow Leaflet compute the optimal bounding box.
82
+    // The main reason for this is that geoJSON has swapped coordinates (lon. lat)
83
+    $boundaries = array();
84
+
85
+    // Add a POI for each entity that has coordinates.
86
+    foreach ( $places as $entity ) {
87
+
88
+        // Get the coordinates.
89
+        $coordinates = wl_get_coordinates( $entity->ID );
90
+
91
+        // Don't show the widget if the coordinates aren't set.
92
+        if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) {
93
+            continue;
94
+        }
95
+
96
+        // TODO Map html rendering should be delegated to the wordlift js ui layer
97
+        // This function should be focused on returning pure data instead
98
+
99
+        // Get the title, URL and thumb of the entity.
100
+        $title = esc_attr( $entity->post_title );
101
+        $link  = esc_attr( get_permalink( $entity->ID ) );
102
+        if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) &&
103
+             false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) )
104
+        ) {
105
+            $img_src = esc_attr( $attachment[0] );
106
+        }
107
+
108
+        // Build HTML popup. TODO: move thumb width in css
109
+        $content = "<a href=$link><h6>$title</h6>";
110
+        if ( isset( $img_src ) ) {
111
+            $content = $content . "<img src=$img_src style='width:100%'/>";
112
+        }
113
+        $content = $content . "</a><ul>";
114
+        // Get the related posts (published) and print them in the popup.
115
+        $related_posts = wl_core_get_related_post_ids( $entity->ID, array(
116
+            'status' => 'publish'
117
+        ) );
118
+        foreach ( $related_posts as $rp_id ) {
119
+
120
+            $rp      = get_post( $rp_id );
121
+            $title   = esc_attr( $rp->post_title );
122
+            $link    = esc_attr( get_permalink( $rp->ID ) );
123
+            $content = $content . "<li><a href=$link>$title</a></li>";
124
+        }
125
+        $content = $content . "</ul>";
126
+
127
+        // Formatting POI in geoJSON.
128
+        // http://leafletjs.com/examples/geojson.html
129
+        $poi = array(
130
+            'type'       => 'Feature',
131
+            'properties' => array( 'popupContent' => $content ),
132
+            'geometry'   => array(
133
+                'type'        => 'Point',
134
+                'coordinates' => array(
135
+                    // Leaflet geoJSON wants them swapped
136
+                    $coordinates['longitude'],
137
+                    $coordinates['latitude']
138
+                )
139
+            )
140
+        );
141
+
142
+        $pois[] = $poi;
143
+
144
+        // Formatting boundaries in a Leaflet-like format (see LatLngBounds).
145
+        // http://leafletjs.com/reference.html#latlngbounds
146
+        $boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] );
147
+
148
+    }
149
+
150
+    $map_data               = array();
151
+    $map_data['features']   = $pois;
152
+    $map_data['boundaries'] = $boundaries;
153
+
154
+    return $map_data;
155 155
 }
156 156
 
157 157
 /**
@@ -165,13 +165,13 @@  discard block
 block discarded – undo
165 165
  * @return array An array of place posts.
166 166
  */
167 167
 function wl_shortcode_geomap_ajax() {
168
-	// Get the post Id.
169
-	$post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null );
168
+    // Get the post Id.
169
+    $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null );
170 170
 
171
-	$places   = wl_shortcode_geomap_get_places( $post_id );
172
-	$map_data = wl_shortcode_geomap_prepare_map( $places );
171
+    $places   = wl_shortcode_geomap_get_places( $post_id );
172
+    $map_data = wl_shortcode_geomap_prepare_map( $places );
173 173
 
174
-	wl_core_send_json( $map_data );
174
+    wl_core_send_json( $map_data );
175 175
 }
176 176
 
177 177
 add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' );
@@ -186,54 +186,54 @@  discard block
 block discarded – undo
186 186
  */
187 187
 function wl_shortcode_geomap( $atts ) {
188 188
 
189
-	// Extract attributes and set default values.
190
-	$geomap_atts = shortcode_atts( array(
191
-		'width'  => '100%',
192
-		'height' => '300px',
193
-		'global' => false
194
-	), $atts );
195
-
196
-	// Get id of the post
197
-	$post_id = get_the_ID();
198
-
199
-	if ( $geomap_atts['global'] || is_null( $post_id ) ) {
200
-		// Global geomap
201
-		$geomap_id = 'wl_geomap_global';
202
-		$post_id   = null;
203
-	} else {
204
-		// Post-specific geomap
205
-		$geomap_id = 'wl_geomap_' . $post_id;
206
-	}
207
-
208
-	// Add leaflet css and library.
209
-	wp_enqueue_style(
210
-		'leaflet',
211
-		dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.css'
212
-	);
213
-	wp_enqueue_script(
214
-		'leaflet',
215
-		dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.js'
216
-	);
217
-
218
-	// Add wordlift-ui css and library.
219
-	wp_enqueue_style( 'wordlift-ui-css', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' );
220
-
221
-	wp_enqueue_script( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-ui.min.js', array( 'jquery' ) );
222
-
223
-	wp_localize_script( 'wordlift-ui', 'wl_geomap_params', array(
224
-		'ajax_url' => admin_url( 'admin-ajax.php' ),    // Global param
225
-		'action'   => 'wl_geomap'            // Global param
226
-	) );
227
-
228
-	// Escaping atts.
229
-	$esc_class   = esc_attr( 'wl-geomap' );
230
-	$esc_id      = esc_attr( $geomap_id );
231
-	$esc_width   = esc_attr( $geomap_atts['width'] );
232
-	$esc_height  = esc_attr( $geomap_atts['height'] );
233
-	$esc_post_id = esc_attr( $post_id );
234
-
235
-	// Return HTML template.
236
-	return <<<EOF
189
+    // Extract attributes and set default values.
190
+    $geomap_atts = shortcode_atts( array(
191
+        'width'  => '100%',
192
+        'height' => '300px',
193
+        'global' => false
194
+    ), $atts );
195
+
196
+    // Get id of the post
197
+    $post_id = get_the_ID();
198
+
199
+    if ( $geomap_atts['global'] || is_null( $post_id ) ) {
200
+        // Global geomap
201
+        $geomap_id = 'wl_geomap_global';
202
+        $post_id   = null;
203
+    } else {
204
+        // Post-specific geomap
205
+        $geomap_id = 'wl_geomap_' . $post_id;
206
+    }
207
+
208
+    // Add leaflet css and library.
209
+    wp_enqueue_style(
210
+        'leaflet',
211
+        dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.css'
212
+    );
213
+    wp_enqueue_script(
214
+        'leaflet',
215
+        dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.js'
216
+    );
217
+
218
+    // Add wordlift-ui css and library.
219
+    wp_enqueue_style( 'wordlift-ui-css', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' );
220
+
221
+    wp_enqueue_script( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-ui.min.js', array( 'jquery' ) );
222
+
223
+    wp_localize_script( 'wordlift-ui', 'wl_geomap_params', array(
224
+        'ajax_url' => admin_url( 'admin-ajax.php' ),    // Global param
225
+        'action'   => 'wl_geomap'            // Global param
226
+    ) );
227
+
228
+    // Escaping atts.
229
+    $esc_class   = esc_attr( 'wl-geomap' );
230
+    $esc_id      = esc_attr( $geomap_id );
231
+    $esc_width   = esc_attr( $geomap_atts['width'] );
232
+    $esc_height  = esc_attr( $geomap_atts['height'] );
233
+    $esc_post_id = esc_attr( $post_id );
234
+
235
+    // Return HTML template.
236
+    return <<<EOF
237 237
 <div class="$esc_class" 
238 238
 	id="$esc_id"
239 239
 	data-post-id="$esc_post_id"
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -12,30 +12,30 @@  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
 
29 29
 	// If is not a global geomap, an empty $related_ids means that no entities are related to the post
30 30
 	// An empty array can be returned in this case
31
-	if ( ! $is_global && empty( $related_ids ) ) {
31
+	if ( ! $is_global && empty($related_ids)) {
32 32
 		return array();
33 33
 	}
34 34
 
35 35
 	// Retrieve all 'published' places with geo coordinates defined
36 36
 	// If $place_ids is not empty, it's used to limit query results to the current post related places
37 37
 	// Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query
38
-	$places = get_posts( array(
38
+	$places = get_posts(array(
39 39
 		'post__in'    => $related_ids,
40 40
 		'post_type'   => Wordlift_Entity_Service::TYPE_NAME,
41 41
 		'nopaging'    => true,
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 				'compare' => '!=',
54 54
 			)
55 55
 		)
56
-	) );
56
+	));
57 57
 
58 58
 	return $places;
59 59
 }
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
  *
69 69
  * @return array An array of markers and boundaries for Leaflet.
70 70
  */
71
-function wl_shortcode_geomap_prepare_map( $places ) {
71
+function wl_shortcode_geomap_prepare_map($places) {
72 72
 
73 73
 	// Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript.
74 74
 	$min_latitude  = PHP_INT_MAX;
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
 	$boundaries = array();
84 84
 
85 85
 	// Add a POI for each entity that has coordinates.
86
-	foreach ( $places as $entity ) {
86
+	foreach ($places as $entity) {
87 87
 
88 88
 		// Get the coordinates.
89
-		$coordinates = wl_get_coordinates( $entity->ID );
89
+		$coordinates = wl_get_coordinates($entity->ID);
90 90
 
91 91
 		// Don't show the widget if the coordinates aren't set.
92
-		if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) {
92
+		if ($coordinates['latitude'] == 0 || $coordinates['longitude'] == 0) {
93 93
 			continue;
94 94
 		}
95 95
 
@@ -97,38 +97,38 @@  discard block
 block discarded – undo
97 97
 		// This function should be focused on returning pure data instead
98 98
 
99 99
 		// Get the title, URL and thumb of the entity.
100
-		$title = esc_attr( $entity->post_title );
101
-		$link  = esc_attr( get_permalink( $entity->ID ) );
102
-		if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) &&
103
-		     false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) )
100
+		$title = esc_attr($entity->post_title);
101
+		$link  = esc_attr(get_permalink($entity->ID));
102
+		if ('' !== ($thumbnail_id = get_post_thumbnail_id($entity->ID)) &&
103
+		     false !== ($attachment = wp_get_attachment_image_src($thumbnail_id))
104 104
 		) {
105
-			$img_src = esc_attr( $attachment[0] );
105
+			$img_src = esc_attr($attachment[0]);
106 106
 		}
107 107
 
108 108
 		// Build HTML popup. TODO: move thumb width in css
109 109
 		$content = "<a href=$link><h6>$title</h6>";
110
-		if ( isset( $img_src ) ) {
111
-			$content = $content . "<img src=$img_src style='width:100%'/>";
110
+		if (isset($img_src)) {
111
+			$content = $content."<img src=$img_src style='width:100%'/>";
112 112
 		}
113
-		$content = $content . "</a><ul>";
113
+		$content = $content."</a><ul>";
114 114
 		// Get the related posts (published) and print them in the popup.
115
-		$related_posts = wl_core_get_related_post_ids( $entity->ID, array(
115
+		$related_posts = wl_core_get_related_post_ids($entity->ID, array(
116 116
 			'status' => 'publish'
117
-		) );
118
-		foreach ( $related_posts as $rp_id ) {
117
+		));
118
+		foreach ($related_posts as $rp_id) {
119 119
 
120
-			$rp      = get_post( $rp_id );
121
-			$title   = esc_attr( $rp->post_title );
122
-			$link    = esc_attr( get_permalink( $rp->ID ) );
123
-			$content = $content . "<li><a href=$link>$title</a></li>";
120
+			$rp      = get_post($rp_id);
121
+			$title   = esc_attr($rp->post_title);
122
+			$link    = esc_attr(get_permalink($rp->ID));
123
+			$content = $content."<li><a href=$link>$title</a></li>";
124 124
 		}
125
-		$content = $content . "</ul>";
125
+		$content = $content."</ul>";
126 126
 
127 127
 		// Formatting POI in geoJSON.
128 128
 		// http://leafletjs.com/examples/geojson.html
129 129
 		$poi = array(
130 130
 			'type'       => 'Feature',
131
-			'properties' => array( 'popupContent' => $content ),
131
+			'properties' => array('popupContent' => $content),
132 132
 			'geometry'   => array(
133 133
 				'type'        => 'Point',
134 134
 				'coordinates' => array(
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 
144 144
 		// Formatting boundaries in a Leaflet-like format (see LatLngBounds).
145 145
 		// http://leafletjs.com/reference.html#latlngbounds
146
-		$boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] );
146
+		$boundaries[] = array($coordinates['latitude'], $coordinates['longitude']);
147 147
 
148 148
 	}
149 149
 
@@ -166,16 +166,16 @@  discard block
 block discarded – undo
166 166
  */
167 167
 function wl_shortcode_geomap_ajax() {
168 168
 	// Get the post Id.
169
-	$post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null );
169
+	$post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : null);
170 170
 
171
-	$places   = wl_shortcode_geomap_get_places( $post_id );
172
-	$map_data = wl_shortcode_geomap_prepare_map( $places );
171
+	$places   = wl_shortcode_geomap_get_places($post_id);
172
+	$map_data = wl_shortcode_geomap_prepare_map($places);
173 173
 
174
-	wl_core_send_json( $map_data );
174
+	wl_core_send_json($map_data);
175 175
 }
176 176
 
177
-add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' );
178
-add_action( 'wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax' );
177
+add_action('wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax');
178
+add_action('wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax');
179 179
 
180 180
 /**
181 181
  * Print geomap shortcode
@@ -184,53 +184,53 @@  discard block
 block discarded – undo
184 184
  *
185 185
  * @return string A dom element represneting a geomap.
186 186
  */
187
-function wl_shortcode_geomap( $atts ) {
187
+function wl_shortcode_geomap($atts) {
188 188
 
189 189
 	// Extract attributes and set default values.
190
-	$geomap_atts = shortcode_atts( array(
190
+	$geomap_atts = shortcode_atts(array(
191 191
 		'width'  => '100%',
192 192
 		'height' => '300px',
193 193
 		'global' => false
194
-	), $atts );
194
+	), $atts);
195 195
 
196 196
 	// Get id of the post
197 197
 	$post_id = get_the_ID();
198 198
 
199
-	if ( $geomap_atts['global'] || is_null( $post_id ) ) {
199
+	if ($geomap_atts['global'] || is_null($post_id)) {
200 200
 		// Global geomap
201 201
 		$geomap_id = 'wl_geomap_global';
202 202
 		$post_id   = null;
203 203
 	} else {
204 204
 		// Post-specific geomap
205
-		$geomap_id = 'wl_geomap_' . $post_id;
205
+		$geomap_id = 'wl_geomap_'.$post_id;
206 206
 	}
207 207
 
208 208
 	// Add leaflet css and library.
209 209
 	wp_enqueue_style(
210 210
 		'leaflet',
211
-		dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.css'
211
+		dirname(plugin_dir_url(__FILE__)).'/bower_components/leaflet/dist/leaflet.css'
212 212
 	);
213 213
 	wp_enqueue_script(
214 214
 		'leaflet',
215
-		dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.js'
215
+		dirname(plugin_dir_url(__FILE__)).'/bower_components/leaflet/dist/leaflet.js'
216 216
 	);
217 217
 
218 218
 	// Add wordlift-ui css and library.
219
-	wp_enqueue_style( 'wordlift-ui-css', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' );
219
+	wp_enqueue_style('wordlift-ui-css', dirname(plugin_dir_url(__FILE__)).'/css/wordlift-ui.min.css');
220 220
 
221
-	wp_enqueue_script( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-ui.min.js', array( 'jquery' ) );
221
+	wp_enqueue_script('wordlift-ui', dirname(plugin_dir_url(__FILE__)).'/js/wordlift-ui.min.js', array('jquery'));
222 222
 
223
-	wp_localize_script( 'wordlift-ui', 'wl_geomap_params', array(
224
-		'ajax_url' => admin_url( 'admin-ajax.php' ),    // Global param
223
+	wp_localize_script('wordlift-ui', 'wl_geomap_params', array(
224
+		'ajax_url' => admin_url('admin-ajax.php'), // Global param
225 225
 		'action'   => 'wl_geomap'            // Global param
226
-	) );
226
+	));
227 227
 
228 228
 	// Escaping atts.
229
-	$esc_class   = esc_attr( 'wl-geomap' );
230
-	$esc_id      = esc_attr( $geomap_id );
231
-	$esc_width   = esc_attr( $geomap_atts['width'] );
232
-	$esc_height  = esc_attr( $geomap_atts['height'] );
233
-	$esc_post_id = esc_attr( $post_id );
229
+	$esc_class   = esc_attr('wl-geomap');
230
+	$esc_id      = esc_attr($geomap_id);
231
+	$esc_width   = esc_attr($geomap_atts['width']);
232
+	$esc_height  = esc_attr($geomap_atts['height']);
233
+	$esc_post_id = esc_attr($post_id);
234 234
 
235 235
 	// Return HTML template.
236 236
 	return <<<EOF
@@ -246,4 +246,4 @@  discard block
 block discarded – undo
246 246
 
247 247
 }
248 248
 
249
-add_shortcode( 'wl_geomap', 'wl_shortcode_geomap' );
250 249
\ No newline at end of file
250
+add_shortcode('wl_geomap', 'wl_shortcode_geomap');
251 251
\ No newline at end of file
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   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 
27 27
 // If this file is called directly, abort.
28 28
 if ( ! defined( 'WPINC' ) ) {
29
-	die;
29
+    die;
30 30
 }
31 31
 
32 32
 // Include WordLift constants.
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
  */
48 48
 function wl_write_log( $log ) {
49 49
 
50
-	$handler = apply_filters( 'wl_write_log_handler', null );
50
+    $handler = apply_filters( 'wl_write_log_handler', null );
51 51
 
52
-	$callers         = debug_backtrace();
53
-	$caller_function = $callers[1]['function'];
52
+    $callers         = debug_backtrace();
53
+    $caller_function = $callers[1]['function'];
54 54
 
55
-	if ( is_null( $handler ) ) {
56
-		wl_write_log_handler( $log, $caller_function );
55
+    if ( is_null( $handler ) ) {
56
+        wl_write_log_handler( $log, $caller_function );
57 57
 
58
-		return;
59
-	}
58
+        return;
59
+    }
60 60
 
61
-	call_user_func( $handler, $log, $caller_function );
61
+    call_user_func( $handler, $log, $caller_function );
62 62
 }
63 63
 
64 64
 /**
@@ -71,20 +71,20 @@  discard block
 block discarded – undo
71 71
  */
72 72
 function wl_write_log_handler( $log, $caller = null ) {
73 73
 
74
-	global $wl_logger;
74
+    global $wl_logger;
75 75
 
76
-	if ( true === WP_DEBUG ) {
76
+    if ( true === WP_DEBUG ) {
77 77
 
78
-		$message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
79
-		           ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
78
+        $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
79
+                    ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
80 80
 
81
-		if ( isset( $wl_logger ) ) {
82
-			$wl_logger->info( $message );
83
-		} else {
84
-			error_log( $message );
85
-		}
81
+        if ( isset( $wl_logger ) ) {
82
+            $wl_logger->info( $message );
83
+        } else {
84
+            error_log( $message );
85
+        }
86 86
 
87
-	}
87
+    }
88 88
 
89 89
 }
90 90
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
  */
100 100
 function wl_write_log_hide_key( $text ) {
101 101
 
102
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
102
+    return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
103 103
 }
104 104
 
105 105
 /**
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
  */
112 112
 function wl_queue_sparql_update_query( $query ) {
113 113
 
114
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
115
-	file_put_contents( $filename, $query . "\n", FILE_APPEND );
114
+    $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
115
+    file_put_contents( $filename, $query . "\n", FILE_APPEND );
116 116
 
117
-	wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" );
117
+    wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" );
118 118
 }
119 119
 
120 120
 /**
@@ -124,28 +124,28 @@  discard block
 block discarded – undo
124 124
  */
125 125
 function wl_execute_saved_sparql_update_query( $request_id ) {
126 126
 
127
-	$filename = WL_TEMP_DIR . $request_id . '.sparql';
127
+    $filename = WL_TEMP_DIR . $request_id . '.sparql';
128 128
 
129
-	// If the file doesn't exist, exit.
130
-	if ( ! file_exists( $filename ) ) {
131
-		wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" );
129
+    // If the file doesn't exist, exit.
130
+    if ( ! file_exists( $filename ) ) {
131
+        wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" );
132 132
 
133
-		return;
134
-	}
133
+        return;
134
+    }
135 135
 
136
-	wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" );
136
+    wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" );
137 137
 
138
-	// Get the query saved in the file.
139
-	$query = file_get_contents( $filename );
138
+    // Get the query saved in the file.
139
+    $query = file_get_contents( $filename );
140 140
 
141
-	// Execute the SPARQL query.
142
-	rl_execute_sparql_update_query( $query, false );
141
+    // Execute the SPARQL query.
142
+    rl_execute_sparql_update_query( $query, false );
143 143
 
144
-	// Reindex the triple store.
145
-	wordlift_reindex_triple_store();
144
+    // Reindex the triple store.
145
+    wordlift_reindex_triple_store();
146 146
 
147
-	// Delete the temporary file.
148
-	unlink( $filename );
147
+    // Delete the temporary file.
148
+    unlink( $filename );
149 149
 }
150 150
 
151 151
 add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 );
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
  */
156 156
 function wordlift_buttonhooks() {
157 157
 
158
-	// Only add hooks when the current user has permissions AND is in Rich Text editor mode
159
-	if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
160
-		add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' );
161
-	}
158
+    // Only add hooks when the current user has permissions AND is in Rich Text editor mode
159
+    if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
160
+        add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' );
161
+    }
162 162
 }
163 163
 
164 164
 /**
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
  */
171 171
 function wordlift_register_tinymce_javascript( $plugin_array ) {
172 172
 
173
-	// add the wordlift plugin.
174
-	$plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
173
+    // add the wordlift plugin.
174
+    $plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
175 175
 
176
-	return $plugin_array;
176
+    return $plugin_array;
177 177
 }
178 178
 
179 179
 /**
@@ -181,21 +181,21 @@  discard block
 block discarded – undo
181 181
  * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
182 182
  */
183 183
 function wordlift_allowed_post_tags() {
184
-	global $allowedposttags;
185
-
186
-	$tags           = array( 'span' );
187
-	$new_attributes = array(
188
-		'itemscope' => array(),
189
-		'itemtype'  => array(),
190
-		'itemprop'  => array(),
191
-		'itemid'    => array()
192
-	);
193
-
194
-	foreach ( $tags as $tag ) {
195
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
196
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
197
-		}
198
-	}
184
+    global $allowedposttags;
185
+
186
+    $tags           = array( 'span' );
187
+    $new_attributes = array(
188
+        'itemscope' => array(),
189
+        'itemtype'  => array(),
190
+        'itemprop'  => array(),
191
+        'itemid'    => array()
192
+    );
193
+
194
+    foreach ( $tags as $tag ) {
195
+        if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
196
+            $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
197
+        }
198
+    }
199 199
 }
200 200
 
201 201
 // init process for button control
@@ -209,21 +209,21 @@  discard block
 block discarded – undo
209 209
  */
210 210
 function wordlift_admin_enqueue_scripts() {
211 211
 
212
-	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
213
-	wp_enqueue_script( 'wpdialogs' );
214
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
212
+    // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
213
+    wp_enqueue_script( 'wpdialogs' );
214
+    wp_enqueue_style( 'wp-jquery-ui-dialog' );
215 215
 
216
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
216
+    wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
217 217
 
218
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
219
-	wp_enqueue_script( 'angularjs', plugin_dir_url( __FILE__ ) . 'bower_components/angular/angular.min.js' );
218
+    wp_enqueue_script( 'jquery-ui-autocomplete' );
219
+    wp_enqueue_script( 'angularjs', plugin_dir_url( __FILE__ ) . 'bower_components/angular/angular.min.js' );
220 220
 
221 221
 }
222 222
 
223 223
 add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
224 224
 
225 225
 function wl_enqueue_scripts() {
226
-	wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
226
+    wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
227 227
 }
228 228
 
229 229
 add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' );
@@ -238,18 +238,18 @@  discard block
 block discarded – undo
238 238
  */
239 239
 function wordlift_allowed_html( $allowedtags, $context ) {
240 240
 
241
-	if ( 'post' !== $context ) {
242
-		return $allowedtags;
243
-	}
244
-
245
-	return array_merge_recursive( $allowedtags, array(
246
-		'span' => array(
247
-			'itemscope' => true,
248
-			'itemtype'  => true,
249
-			'itemid'    => true,
250
-			'itemprop'  => true
251
-		)
252
-	) );
241
+    if ( 'post' !== $context ) {
242
+        return $allowedtags;
243
+    }
244
+
245
+    return array_merge_recursive( $allowedtags, array(
246
+        'span' => array(
247
+            'itemscope' => true,
248
+            'itemtype'  => true,
249
+            'itemid'    => true,
250
+            'itemprop'  => true
251
+        )
252
+    ) );
253 253
 }
254 254
 
255 255
 add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
@@ -263,15 +263,15 @@  discard block
 block discarded – undo
263 263
  */
264 264
 function wl_get_coordinates( $post_id ) {
265 265
 
266
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
267
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
266
+    $latitude  = wl_schema_get_value( $post_id, 'latitude' );
267
+    $longitude = wl_schema_get_value( $post_id, 'longitude' );
268 268
 
269
-	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
270
-	// "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
271
-	return array(
272
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
273
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : ''
274
-	);
269
+    // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
270
+    // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
271
+    return array(
272
+        'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
273
+        'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : ''
274
+    );
275 275
 }
276 276
 
277 277
 /**
@@ -283,13 +283,13 @@  discard block
 block discarded – undo
283 283
  */
284 284
 function wl_get_post_modified_time( $post ) {
285 285
 
286
-	$date_modified = get_post_modified_time( 'c', true, $post );
286
+    $date_modified = get_post_modified_time( 'c', true, $post );
287 287
 
288
-	if ( '-' === substr( $date_modified, 0, 1 ) ) {
289
-		return get_the_time( 'c', $post );
290
-	}
288
+    if ( '-' === substr( $date_modified, 0, 1 ) ) {
289
+        return get_the_time( 'c', $post );
290
+    }
291 291
 
292
-	return $date_modified;
292
+    return $date_modified;
293 293
 }
294 294
 
295 295
 /**
@@ -301,34 +301,34 @@  discard block
 block discarded – undo
301 301
  */
302 302
 function wl_get_image_urls( $post_id ) {
303 303
 
304
-	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
304
+    // wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
305 305
 
306
-	$images = get_children( array(
307
-		'post_parent'    => $post_id,
308
-		'post_type'      => 'attachment',
309
-		'post_mime_type' => 'image'
310
-	) );
306
+    $images = get_children( array(
307
+        'post_parent'    => $post_id,
308
+        'post_type'      => 'attachment',
309
+        'post_mime_type' => 'image'
310
+    ) );
311 311
 
312
-	// Return an empty array if no image is found.
313
-	if ( empty( $images ) ) {
314
-		return array();
315
-	}
312
+    // Return an empty array if no image is found.
313
+    if ( empty( $images ) ) {
314
+        return array();
315
+    }
316 316
 
317
-	// Prepare the return array.
318
-	$image_urls = array();
317
+    // Prepare the return array.
318
+    $image_urls = array();
319 319
 
320
-	// Collect the URLs.
321
-	foreach ( $images as $attachment_id => $attachment ) {
322
-		$image_url = wp_get_attachment_url( $attachment_id );
323
-		// Ensure the URL isn't collected already.
324
-		if ( ! in_array( $image_url, $image_urls ) ) {
325
-			array_push( $image_urls, $image_url );
326
-		}
327
-	}
320
+    // Collect the URLs.
321
+    foreach ( $images as $attachment_id => $attachment ) {
322
+        $image_url = wp_get_attachment_url( $attachment_id );
323
+        // Ensure the URL isn't collected already.
324
+        if ( ! in_array( $image_url, $image_urls ) ) {
325
+            array_push( $image_urls, $image_url );
326
+        }
327
+    }
328 328
 
329
-	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" );
329
+    // wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" );
330 330
 
331
-	return $image_urls;
331
+    return $image_urls;
332 332
 }
333 333
 
334 334
 /**
@@ -341,19 +341,19 @@  discard block
 block discarded – undo
341 341
  */
342 342
 function wl_get_sparql_images( $uri, $post_id ) {
343 343
 
344
-	$sparql = '';
344
+    $sparql = '';
345 345
 
346
-	// Get the escaped URI.
347
-	$uri_e = esc_html( $uri );
346
+    // Get the escaped URI.
347
+    $uri_e = esc_html( $uri );
348 348
 
349
-	// Add SPARQL stmts to write the schema:image.
350
-	$image_urls = wl_get_image_urls( $post_id );
351
-	foreach ( $image_urls as $image_url ) {
352
-		$image_url_esc = wl_sparql_escape_uri( $image_url );
353
-		$sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
354
-	}
349
+    // Add SPARQL stmts to write the schema:image.
350
+    $image_urls = wl_get_image_urls( $post_id );
351
+    foreach ( $image_urls as $image_url ) {
352
+        $image_url_esc = wl_sparql_escape_uri( $image_url );
353
+        $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
354
+    }
355 355
 
356
-	return $sparql;
356
+    return $sparql;
357 357
 }
358 358
 
359 359
 /**
@@ -366,24 +366,24 @@  discard block
 block discarded – undo
366 366
  */
367 367
 function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
368 368
 
369
-	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
369
+    // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
370 370
 
371
-	$posts = get_posts( array(
372
-		'post_type'      => 'attachment',
373
-		'posts_per_page' => 1,
374
-		'post_status'    => 'any',
375
-		'post_parent'    => $parent_post_id,
376
-		'meta_key'       => 'wl_source_url',
377
-		'meta_value'     => $source_url
378
-	) );
371
+    $posts = get_posts( array(
372
+        'post_type'      => 'attachment',
373
+        'posts_per_page' => 1,
374
+        'post_status'    => 'any',
375
+        'post_parent'    => $parent_post_id,
376
+        'meta_key'       => 'wl_source_url',
377
+        'meta_value'     => $source_url
378
+    ) );
379 379
 
380
-	// Return the found post.
381
-	if ( 1 === count( $posts ) ) {
382
-		return $posts[0];
383
-	}
380
+    // Return the found post.
381
+    if ( 1 === count( $posts ) ) {
382
+        return $posts[0];
383
+    }
384 384
 
385
-	// Return null.
386
-	return null;
385
+    // Return null.
386
+    return null;
387 387
 }
388 388
 
389 389
 /**
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
  */
395 395
 function wl_set_source_url( $post_id, $source_url ) {
396 396
 
397
-	delete_post_meta( $post_id, 'wl_source_url' );
398
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
397
+    delete_post_meta( $post_id, 'wl_source_url' );
398
+    add_post_meta( $post_id, 'wl_source_url', $source_url );
399 399
 }
400 400
 
401 401
 
@@ -413,43 +413,43 @@  discard block
 block discarded – undo
413 413
  */
414 414
 function wl_flush_rewrite_rules_hard( $hard ) {
415 415
 
416
-	// Get all published posts.
417
-	$posts = get_posts( array(
418
-		'posts_per_page' => - 1,
419
-		'post_type'      => 'any',
420
-		'post_status'    => 'publish'
421
-	) );
416
+    // Get all published posts.
417
+    $posts = get_posts( array(
418
+        'posts_per_page' => - 1,
419
+        'post_type'      => 'any',
420
+        'post_status'    => 'publish'
421
+    ) );
422 422
 
423
-	// Holds the delete part of the query.
424
-	$delete_query = rl_sparql_prefixes();
425
-	// Holds the insert part of the query.
426
-	$insert_query = 'INSERT DATA { ';
423
+    // Holds the delete part of the query.
424
+    $delete_query = rl_sparql_prefixes();
425
+    // Holds the insert part of the query.
426
+    $insert_query = 'INSERT DATA { ';
427 427
 
428
-	// Cycle in each post to build the query.
429
-	foreach ( $posts as $post ) {
428
+    // Cycle in each post to build the query.
429
+    foreach ( $posts as $post ) {
430 430
 
431
-		// Ignore revisions.
432
-		if ( wp_is_post_revision( $post->ID ) ) {
433
-			continue;
434
-		}
431
+        // Ignore revisions.
432
+        if ( wp_is_post_revision( $post->ID ) ) {
433
+            continue;
434
+        }
435 435
 
436
-		// Get the entity URI.
437
-		$uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
436
+        // Get the entity URI.
437
+        $uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
438 438
 
439
-		// Get the post URL.
440
-		$url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
439
+        // Get the post URL.
440
+        $url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
441 441
 
442
-		// Prepare the DELETE and INSERT commands.
443
-		$delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE  { <$uri> schema:url ?u . };\n";
444
-		$insert_query .= " <$uri> schema:url <$url> . \n";
442
+        // Prepare the DELETE and INSERT commands.
443
+        $delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE  { <$uri> schema:url ?u . };\n";
444
+        $insert_query .= " <$uri> schema:url <$url> . \n";
445 445
 
446
-		// wl_write_log( "[ uri :: $uri ][ url :: $url ]" );
447
-	}
446
+        // wl_write_log( "[ uri :: $uri ][ url :: $url ]" );
447
+    }
448 448
 
449
-	$insert_query .= ' };';
449
+    $insert_query .= ' };';
450 450
 
451
-	// Execute the query.
452
-	rl_execute_sparql_update_query( $delete_query . $insert_query );
451
+    // Execute the query.
452
+    rl_execute_sparql_update_query( $delete_query . $insert_query );
453 453
 }
454 454
 
455 455
 add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 );
@@ -466,15 +466,15 @@  discard block
 block discarded – undo
466 466
  */
467 467
 function wl_sanitize_uri_path( $path, $char = '_' ) {
468 468
 
469
-	// wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" );
469
+    // wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" );
470 470
 
471
-	// According to RFC2396 (http://www.ietf.org/rfc/rfc2396.txt) these characters are reserved:
472
-	// ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
473
-	// "$" | ","
474
-	// Plus the ' ' (space).
475
-	// TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex)
471
+    // According to RFC2396 (http://www.ietf.org/rfc/rfc2396.txt) these characters are reserved:
472
+    // ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
473
+    // "$" | ","
474
+    // Plus the ' ' (space).
475
+    // TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex)
476 476
 
477
-	return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) );
477
+    return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) );
478 478
 }
479 479
 
480 480
 /**
@@ -482,26 +482,26 @@  discard block
 block discarded – undo
482 482
  */
483 483
 function wl_shutdown() {
484 484
 
485
-	// Get the filename to the temporary SPARQL file.
486
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
485
+    // Get the filename to the temporary SPARQL file.
486
+    $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
487 487
 
488
-	// If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
489
-	if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
488
+    // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
489
+    if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
490 490
 
491
-		// The request ID.
492
-		$args = array( WL_REQUEST_ID );
491
+        // The request ID.
492
+        $args = array( WL_REQUEST_ID );
493 493
 
494
-		// Schedule the execution of the SPARQL query with the request ID.
495
-		wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
494
+        // Schedule the execution of the SPARQL query with the request ID.
495
+        wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
496 496
 
497
-		// Check that the request is scheduled.
498
-		$timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
497
+        // Check that the request is scheduled.
498
+        $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
499 499
 
500
-		// Spawn the cron.
501
-		spawn_cron();
500
+        // Spawn the cron.
501
+        spawn_cron();
502 502
 
503
-		wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
504
-	}
503
+        wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
504
+    }
505 505
 }
506 506
 
507 507
 add_action( 'shutdown', 'wl_shutdown' );
@@ -515,45 +515,45 @@  discard block
 block discarded – undo
515 515
  */
516 516
 function wl_replace_item_id_with_uri( $content ) {
517 517
 
518
-	// wl_write_log( "wl_replace_item_id_with_uri" );
518
+    // wl_write_log( "wl_replace_item_id_with_uri" );
519 519
 
520
-	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
521
-	$content = stripslashes( $content );
520
+    // Strip slashes, see https://core.trac.wordpress.org/ticket/21767
521
+    $content = stripslashes( $content );
522 522
 
523
-	// If any match are found.
524
-	$matches = array();
525
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
523
+    // If any match are found.
524
+    $matches = array();
525
+    if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
526 526
 
527
-		foreach ( $matches as $match ) {
527
+        foreach ( $matches as $match ) {
528 528
 
529
-			// Get the item ID.
530
-			$item_id = $match[1];
529
+            // Get the item ID.
530
+            $item_id = $match[1];
531 531
 
532
-			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
533
-			$post = wl_get_entity_post_by_uri( $item_id );
532
+            // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
533
+            $post = wl_get_entity_post_by_uri( $item_id );
534 534
 
535
-			// If no entity is found, continue to the next one.
536
-			if ( null === $post ) {
537
-				continue;
538
-			}
535
+            // If no entity is found, continue to the next one.
536
+            if ( null === $post ) {
537
+                continue;
538
+            }
539 539
 
540
-			// Get the URI for that post.
541
-			$uri = wl_get_entity_uri( $post->ID );
540
+            // Get the URI for that post.
541
+            $uri = wl_get_entity_uri( $post->ID );
542 542
 
543
-			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
543
+            // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
544 544
 
545
-			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
546
-			if ( $item_id !== $uri ) {
547
-				$uri_e   = esc_html( $uri );
548
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
549
-			}
550
-		}
551
-	}
545
+            // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
546
+            if ( $item_id !== $uri ) {
547
+                $uri_e   = esc_html( $uri );
548
+                $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
549
+            }
550
+        }
551
+    }
552 552
 
553
-	// Reapply slashes.
554
-	$content = addslashes( $content );
553
+    // Reapply slashes.
554
+    $content = addslashes( $content );
555 555
 
556
-	return $content;
556
+    return $content;
557 557
 }
558 558
 
559 559
 add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
 
586 586
 // Entity view shortcode just with php >= 5.4
587 587
 if ( version_compare( phpversion(), '5.4.0', '>=' ) ) {
588
-	require_once( 'modules/entity_view/wordlift_entity_view.php' );
588
+    require_once( 'modules/entity_view/wordlift_entity_view.php' );
589 589
 }
590 590
 
591 591
 require_once( 'modules/geo_widget/wordlift_geo_widget.php' );
@@ -642,8 +642,8 @@  discard block
 block discarded – undo
642 642
  * This action is documented in includes/class-wordlift-activator.php
643 643
  */
644 644
 function activate_wordlift() {
645
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
646
-	Wordlift_Activator::activate();
645
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
646
+    Wordlift_Activator::activate();
647 647
 }
648 648
 
649 649
 /**
@@ -651,8 +651,8 @@  discard block
 block discarded – undo
651 651
  * This action is documented in includes/class-wordlift-deactivator.php
652 652
  */
653 653
 function deactivate_wordlift() {
654
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
655
-	Wordlift_Deactivator::deactivate();
654
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
655
+    Wordlift_Deactivator::deactivate();
656 656
 }
657 657
 
658 658
 register_activation_hook( __FILE__, 'activate_wordlift' );
@@ -675,8 +675,8 @@  discard block
 block discarded – undo
675 675
  */
676 676
 function run_wordlift() {
677 677
 
678
-	$plugin = new Wordlift();
679
-	$plugin->run();
678
+    $plugin = new Wordlift();
679
+    $plugin->run();
680 680
 
681 681
 }
682 682
 
Please login to merge, or discard this patch.
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -25,16 +25,16 @@  discard block
 block discarded – undo
25 25
  */
26 26
 
27 27
 // If this file is called directly, abort.
28
-if ( ! defined( 'WPINC' ) ) {
28
+if ( ! defined('WPINC')) {
29 29
 	die;
30 30
 }
31 31
 
32 32
 // Include WordLift constants.
33
-require_once( 'wordlift_constants.php' );
33
+require_once('wordlift_constants.php');
34 34
 
35 35
 // Load modules
36
-require_once( 'modules/core/wordlift_core.php' );
37
-require_once( 'modules/configuration/wordlift_configuration.php' );
36
+require_once('modules/core/wordlift_core.php');
37
+require_once('modules/configuration/wordlift_configuration.php');
38 38
 
39 39
 /**
40 40
  * Log to the debug.log file.
@@ -45,20 +45,20 @@  discard block
 block discarded – undo
45 45
  *
46 46
  * @param string|mixed $log The log data.
47 47
  */
48
-function wl_write_log( $log ) {
48
+function wl_write_log($log) {
49 49
 
50
-	$handler = apply_filters( 'wl_write_log_handler', null );
50
+	$handler = apply_filters('wl_write_log_handler', null);
51 51
 
52 52
 	$callers         = debug_backtrace();
53 53
 	$caller_function = $callers[1]['function'];
54 54
 
55
-	if ( is_null( $handler ) ) {
56
-		wl_write_log_handler( $log, $caller_function );
55
+	if (is_null($handler)) {
56
+		wl_write_log_handler($log, $caller_function);
57 57
 
58 58
 		return;
59 59
 	}
60 60
 
61
-	call_user_func( $handler, $log, $caller_function );
61
+	call_user_func($handler, $log, $caller_function);
62 62
 }
63 63
 
64 64
 /**
@@ -69,19 +69,19 @@  discard block
 block discarded – undo
69 69
  * @param string|array $log The log data.
70 70
  * @param string $caller The calling function.
71 71
  */
72
-function wl_write_log_handler( $log, $caller = null ) {
72
+function wl_write_log_handler($log, $caller = null) {
73 73
 
74 74
 	global $wl_logger;
75 75
 
76
-	if ( true === WP_DEBUG ) {
76
+	if (true === WP_DEBUG) {
77 77
 
78
-		$message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) .
79
-		           ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) );
78
+		$message = (isset($caller) ? sprintf('[%-40.40s] ', $caller) : '').
79
+		           (is_array($log) || is_object($log) ? print_r($log, true) : wl_write_log_hide_key($log));
80 80
 
81
-		if ( isset( $wl_logger ) ) {
82
-			$wl_logger->info( $message );
81
+		if (isset($wl_logger)) {
82
+			$wl_logger->info($message);
83 83
 		} else {
84
-			error_log( $message );
84
+			error_log($message);
85 85
 		}
86 86
 
87 87
 	}
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
  *
98 98
  * @return string A text with the key hidden.
99 99
  */
100
-function wl_write_log_hide_key( $text ) {
100
+function wl_write_log_hide_key($text) {
101 101
 
102
-	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
102
+	return str_ireplace(wl_configuration_get_key(), '<hidden>', $text);
103 103
 }
104 104
 
105 105
 /**
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
  *
110 110
  * @param string $query A SPARQL query.
111 111
  */
112
-function wl_queue_sparql_update_query( $query ) {
112
+function wl_queue_sparql_update_query($query) {
113 113
 
114
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
115
-	file_put_contents( $filename, $query . "\n", FILE_APPEND );
114
+	$filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql';
115
+	file_put_contents($filename, $query."\n", FILE_APPEND);
116 116
 
117
-	wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" );
117
+	wl_write_log("wl_queue_sparql_update_query [ filename :: $filename ]");
118 118
 }
119 119
 
120 120
 /**
@@ -122,33 +122,33 @@  discard block
 block discarded – undo
122 122
  *
123 123
  * @param int $request_id The request ID.
124 124
  */
125
-function wl_execute_saved_sparql_update_query( $request_id ) {
125
+function wl_execute_saved_sparql_update_query($request_id) {
126 126
 
127
-	$filename = WL_TEMP_DIR . $request_id . '.sparql';
127
+	$filename = WL_TEMP_DIR.$request_id.'.sparql';
128 128
 
129 129
 	// If the file doesn't exist, exit.
130
-	if ( ! file_exists( $filename ) ) {
131
-		wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" );
130
+	if ( ! file_exists($filename)) {
131
+		wl_write_log("wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]");
132 132
 
133 133
 		return;
134 134
 	}
135 135
 
136
-	wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" );
136
+	wl_write_log("wl_execute_saved_sparql_update_query [ filename :: $filename ]");
137 137
 
138 138
 	// Get the query saved in the file.
139
-	$query = file_get_contents( $filename );
139
+	$query = file_get_contents($filename);
140 140
 
141 141
 	// Execute the SPARQL query.
142
-	rl_execute_sparql_update_query( $query, false );
142
+	rl_execute_sparql_update_query($query, false);
143 143
 
144 144
 	// Reindex the triple store.
145 145
 	wordlift_reindex_triple_store();
146 146
 
147 147
 	// Delete the temporary file.
148
-	unlink( $filename );
148
+	unlink($filename);
149 149
 }
150 150
 
151
-add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 );
151
+add_action('wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1);
152 152
 
153 153
 /**
154 154
  * Add buttons hook for the TinyMCE editor. This method is called by the WP init hook.
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 function wordlift_buttonhooks() {
157 157
 
158 158
 	// Only add hooks when the current user has permissions AND is in Rich Text editor mode
159
-	if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) {
160
-		add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' );
159
+	if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) {
160
+		add_filter('mce_external_plugins', 'wordlift_register_tinymce_javascript');
161 161
 	}
162 162
 }
163 163
 
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
  *
169 169
  * @return array The modified plugins array.
170 170
  */
171
-function wordlift_register_tinymce_javascript( $plugin_array ) {
171
+function wordlift_register_tinymce_javascript($plugin_array) {
172 172
 
173 173
 	// add the wordlift plugin.
174
-	$plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js';
174
+	$plugin_array['wordlift'] = plugin_dir_url(__FILE__).'js/wordlift-reloaded.js';
175 175
 
176 176
 	return $plugin_array;
177 177
 }
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 function wordlift_allowed_post_tags() {
184 184
 	global $allowedposttags;
185 185
 
186
-	$tags           = array( 'span' );
186
+	$tags           = array('span');
187 187
 	$new_attributes = array(
188 188
 		'itemscope' => array(),
189 189
 		'itemtype'  => array(),
@@ -191,17 +191,17 @@  discard block
 block discarded – undo
191 191
 		'itemid'    => array()
192 192
 	);
193 193
 
194
-	foreach ( $tags as $tag ) {
195
-		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
196
-			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
194
+	foreach ($tags as $tag) {
195
+		if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) {
196
+			$allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes);
197 197
 		}
198 198
 	}
199 199
 }
200 200
 
201 201
 // init process for button control
202
-add_action( 'init', 'wordlift_buttonhooks' );
202
+add_action('init', 'wordlift_buttonhooks');
203 203
 // add allowed post tags.
204
-add_action( 'init', 'wordlift_allowed_post_tags' );
204
+add_action('init', 'wordlift_allowed_post_tags');
205 205
 
206 206
 
207 207
 /**
@@ -210,23 +210,23 @@  discard block
 block discarded – undo
210 210
 function wordlift_admin_enqueue_scripts() {
211 211
 
212 212
 	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
213
-	wp_enqueue_script( 'wpdialogs' );
214
-	wp_enqueue_style( 'wp-jquery-ui-dialog' );
213
+	wp_enqueue_script('wpdialogs');
214
+	wp_enqueue_style('wp-jquery-ui-dialog');
215 215
 
216
-	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
216
+	wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css');
217 217
 
218
-	wp_enqueue_script( 'jquery-ui-autocomplete' );
219
-	wp_enqueue_script( 'angularjs', plugin_dir_url( __FILE__ ) . 'bower_components/angular/angular.min.js' );
218
+	wp_enqueue_script('jquery-ui-autocomplete');
219
+	wp_enqueue_script('angularjs', plugin_dir_url(__FILE__).'bower_components/angular/angular.min.js');
220 220
 
221 221
 }
222 222
 
223
-add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
223
+add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts');
224 224
 
225 225
 function wl_enqueue_scripts() {
226
-	wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' );
226
+	wp_enqueue_style('wordlift-ui', plugin_dir_url(__FILE__).'css/wordlift-ui.min.css');
227 227
 }
228 228
 
229
-add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' );
229
+add_action('wp_enqueue_scripts', 'wl_enqueue_scripts');
230 230
 
231 231
 /**
232 232
  * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes.
@@ -236,23 +236,23 @@  discard block
 block discarded – undo
236 236
  *
237 237
  * @return array An array which contains allowed microdata attributes.
238 238
  */
239
-function wordlift_allowed_html( $allowedtags, $context ) {
239
+function wordlift_allowed_html($allowedtags, $context) {
240 240
 
241
-	if ( 'post' !== $context ) {
241
+	if ('post' !== $context) {
242 242
 		return $allowedtags;
243 243
 	}
244 244
 
245
-	return array_merge_recursive( $allowedtags, array(
245
+	return array_merge_recursive($allowedtags, array(
246 246
 		'span' => array(
247 247
 			'itemscope' => true,
248 248
 			'itemtype'  => true,
249 249
 			'itemid'    => true,
250 250
 			'itemprop'  => true
251 251
 		)
252
-	) );
252
+	));
253 253
 }
254 254
 
255
-add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
255
+add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2);
256 256
 
257 257
 /**
258 258
  * Get the coordinates for the specified post ID.
@@ -261,16 +261,16 @@  discard block
 block discarded – undo
261 261
  *
262 262
  * @return array|null An array of coordinates or null.
263 263
  */
264
-function wl_get_coordinates( $post_id ) {
264
+function wl_get_coordinates($post_id) {
265 265
 
266
-	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
267
-	$longitude = wl_schema_get_value( $post_id, 'longitude' );
266
+	$latitude  = wl_schema_get_value($post_id, 'latitude');
267
+	$longitude = wl_schema_get_value($post_id, 'longitude');
268 268
 
269 269
 	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe:
270 270
 	// "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
271 271
 	return array(
272
-		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
273
-		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : ''
272
+		'latitude'  => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '',
273
+		'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : ''
274 274
 	);
275 275
 }
276 276
 
@@ -281,12 +281,12 @@  discard block
 block discarded – undo
281 281
  *
282 282
  * @return string A datetime.
283 283
  */
284
-function wl_get_post_modified_time( $post ) {
284
+function wl_get_post_modified_time($post) {
285 285
 
286
-	$date_modified = get_post_modified_time( 'c', true, $post );
286
+	$date_modified = get_post_modified_time('c', true, $post);
287 287
 
288
-	if ( '-' === substr( $date_modified, 0, 1 ) ) {
289
-		return get_the_time( 'c', $post );
288
+	if ('-' === substr($date_modified, 0, 1)) {
289
+		return get_the_time('c', $post);
290 290
 	}
291 291
 
292 292
 	return $date_modified;
@@ -299,18 +299,18 @@  discard block
 block discarded – undo
299 299
  *
300 300
  * @return array An array of image URLs.
301 301
  */
302
-function wl_get_image_urls( $post_id ) {
302
+function wl_get_image_urls($post_id) {
303 303
 
304 304
 	// wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" );
305 305
 
306
-	$images = get_children( array(
306
+	$images = get_children(array(
307 307
 		'post_parent'    => $post_id,
308 308
 		'post_type'      => 'attachment',
309 309
 		'post_mime_type' => 'image'
310
-	) );
310
+	));
311 311
 
312 312
 	// Return an empty array if no image is found.
313
-	if ( empty( $images ) ) {
313
+	if (empty($images)) {
314 314
 		return array();
315 315
 	}
316 316
 
@@ -318,11 +318,11 @@  discard block
 block discarded – undo
318 318
 	$image_urls = array();
319 319
 
320 320
 	// Collect the URLs.
321
-	foreach ( $images as $attachment_id => $attachment ) {
322
-		$image_url = wp_get_attachment_url( $attachment_id );
321
+	foreach ($images as $attachment_id => $attachment) {
322
+		$image_url = wp_get_attachment_url($attachment_id);
323 323
 		// Ensure the URL isn't collected already.
324
-		if ( ! in_array( $image_url, $image_urls ) ) {
325
-			array_push( $image_urls, $image_url );
324
+		if ( ! in_array($image_url, $image_urls)) {
325
+			array_push($image_urls, $image_url);
326 326
 		}
327 327
 	}
328 328
 
@@ -339,17 +339,17 @@  discard block
 block discarded – undo
339 339
  *
340 340
  * @return string The SPARQL fragment.
341 341
  */
342
-function wl_get_sparql_images( $uri, $post_id ) {
342
+function wl_get_sparql_images($uri, $post_id) {
343 343
 
344 344
 	$sparql = '';
345 345
 
346 346
 	// Get the escaped URI.
347
-	$uri_e = esc_html( $uri );
347
+	$uri_e = esc_html($uri);
348 348
 
349 349
 	// Add SPARQL stmts to write the schema:image.
350
-	$image_urls = wl_get_image_urls( $post_id );
351
-	foreach ( $image_urls as $image_url ) {
352
-		$image_url_esc = wl_sparql_escape_uri( $image_url );
350
+	$image_urls = wl_get_image_urls($post_id);
351
+	foreach ($image_urls as $image_url) {
352
+		$image_url_esc = wl_sparql_escape_uri($image_url);
353 353
 		$sparql .= " <$uri_e> schema:image <$image_url_esc> . \n";
354 354
 	}
355 355
 
@@ -364,21 +364,21 @@  discard block
 block discarded – undo
364 364
  *
365 365
  * @return WP_Post|null A post instance or null if not found.
366 366
  */
367
-function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
367
+function wl_get_attachment_for_source_url($parent_post_id, $source_url) {
368 368
 
369 369
 	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
370 370
 
371
-	$posts = get_posts( array(
371
+	$posts = get_posts(array(
372 372
 		'post_type'      => 'attachment',
373 373
 		'posts_per_page' => 1,
374 374
 		'post_status'    => 'any',
375 375
 		'post_parent'    => $parent_post_id,
376 376
 		'meta_key'       => 'wl_source_url',
377 377
 		'meta_value'     => $source_url
378
-	) );
378
+	));
379 379
 
380 380
 	// Return the found post.
381
-	if ( 1 === count( $posts ) ) {
381
+	if (1 === count($posts)) {
382 382
 		return $posts[0];
383 383
 	}
384 384
 
@@ -392,10 +392,10 @@  discard block
 block discarded – undo
392 392
  * @param int $post_id The post ID.
393 393
  * @param string $source_url The source URL.
394 394
  */
395
-function wl_set_source_url( $post_id, $source_url ) {
395
+function wl_set_source_url($post_id, $source_url) {
396 396
 
397
-	delete_post_meta( $post_id, 'wl_source_url' );
398
-	add_post_meta( $post_id, 'wl_source_url', $source_url );
397
+	delete_post_meta($post_id, 'wl_source_url');
398
+	add_post_meta($post_id, 'wl_source_url', $source_url);
399 399
 }
400 400
 
401 401
 
@@ -411,14 +411,14 @@  discard block
 block discarded – undo
411 411
  *
412 412
  * @param bool $hard True if the rewrite involves configuration updates in Apache/IIS.
413 413
  */
414
-function wl_flush_rewrite_rules_hard( $hard ) {
414
+function wl_flush_rewrite_rules_hard($hard) {
415 415
 
416 416
 	// Get all published posts.
417
-	$posts = get_posts( array(
418
-		'posts_per_page' => - 1,
417
+	$posts = get_posts(array(
418
+		'posts_per_page' => -1,
419 419
 		'post_type'      => 'any',
420 420
 		'post_status'    => 'publish'
421
-	) );
421
+	));
422 422
 
423 423
 	// Holds the delete part of the query.
424 424
 	$delete_query = rl_sparql_prefixes();
@@ -426,18 +426,18 @@  discard block
 block discarded – undo
426 426
 	$insert_query = 'INSERT DATA { ';
427 427
 
428 428
 	// Cycle in each post to build the query.
429
-	foreach ( $posts as $post ) {
429
+	foreach ($posts as $post) {
430 430
 
431 431
 		// Ignore revisions.
432
-		if ( wp_is_post_revision( $post->ID ) ) {
432
+		if (wp_is_post_revision($post->ID)) {
433 433
 			continue;
434 434
 		}
435 435
 
436 436
 		// Get the entity URI.
437
-		$uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
437
+		$uri = wl_sparql_escape_uri(wl_get_entity_uri($post->ID));
438 438
 
439 439
 		// Get the post URL.
440
-		$url = wl_sparql_escape_uri( get_permalink( $post->ID ) );
440
+		$url = wl_sparql_escape_uri(get_permalink($post->ID));
441 441
 
442 442
 		// Prepare the DELETE and INSERT commands.
443 443
 		$delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE  { <$uri> schema:url ?u . };\n";
@@ -449,10 +449,10 @@  discard block
 block discarded – undo
449 449
 	$insert_query .= ' };';
450 450
 
451 451
 	// Execute the query.
452
-	rl_execute_sparql_update_query( $delete_query . $insert_query );
452
+	rl_execute_sparql_update_query($delete_query.$insert_query);
453 453
 }
454 454
 
455
-add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 );
455
+add_filter('flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1);
456 456
 
457 457
 /**
458 458
  * Sanitizes an URI path by replacing the non allowed characters with an underscore.
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
  *
465 465
  * @return The sanitized path.
466 466
  */
467
-function wl_sanitize_uri_path( $path, $char = '_' ) {
467
+function wl_sanitize_uri_path($path, $char = '_') {
468 468
 
469 469
 	// wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" );
470 470
 
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 	// Plus the ' ' (space).
475 475
 	// TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex)
476 476
 
477
-	return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) );
477
+	return sanitize_title(preg_replace('/[;\/?:@&=+$,\s]/', $char, stripslashes($path)));
478 478
 }
479 479
 
480 480
 /**
@@ -483,28 +483,28 @@  discard block
 block discarded – undo
483 483
 function wl_shutdown() {
484 484
 
485 485
 	// Get the filename to the temporary SPARQL file.
486
-	$filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql';
486
+	$filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql';
487 487
 
488 488
 	// If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it.
489
-	if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) {
489
+	if (WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists($filename)) {
490 490
 
491 491
 		// The request ID.
492
-		$args = array( WL_REQUEST_ID );
492
+		$args = array(WL_REQUEST_ID);
493 493
 
494 494
 		// Schedule the execution of the SPARQL query with the request ID.
495
-		wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args );
495
+		wp_schedule_single_event(time(), 'wl_execute_saved_sparql_update_query', $args);
496 496
 
497 497
 		// Check that the request is scheduled.
498
-		$timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args );
498
+		$timestamp = wp_next_scheduled('wl_execute_saved_sparql_update_query', $args);
499 499
 
500 500
 		// Spawn the cron.
501 501
 		spawn_cron();
502 502
 
503
-		wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" );
503
+		wl_write_log("wl_shutdown [ request id :: ".WL_REQUEST_ID." ][ timestamp :: $timestamp ]");
504 504
 	}
505 505
 }
506 506
 
507
-add_action( 'shutdown', 'wl_shutdown' );
507
+add_action('shutdown', 'wl_shutdown');
508 508
 
509 509
 /**
510 510
  * Replaces the *itemid* attributes URIs with the WordLift URIs.
@@ -513,128 +513,128 @@  discard block
 block discarded – undo
513 513
  *
514 514
  * @return string The updated post content.
515 515
  */
516
-function wl_replace_item_id_with_uri( $content ) {
516
+function wl_replace_item_id_with_uri($content) {
517 517
 
518 518
 	// wl_write_log( "wl_replace_item_id_with_uri" );
519 519
 
520 520
 	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
521
-	$content = stripslashes( $content );
521
+	$content = stripslashes($content);
522 522
 
523 523
 	// If any match are found.
524 524
 	$matches = array();
525
-	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
525
+	if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) {
526 526
 
527
-		foreach ( $matches as $match ) {
527
+		foreach ($matches as $match) {
528 528
 
529 529
 			// Get the item ID.
530 530
 			$item_id = $match[1];
531 531
 
532 532
 			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
533
-			$post = wl_get_entity_post_by_uri( $item_id );
533
+			$post = wl_get_entity_post_by_uri($item_id);
534 534
 
535 535
 			// If no entity is found, continue to the next one.
536
-			if ( null === $post ) {
536
+			if (null === $post) {
537 537
 				continue;
538 538
 			}
539 539
 
540 540
 			// Get the URI for that post.
541
-			$uri = wl_get_entity_uri( $post->ID );
541
+			$uri = wl_get_entity_uri($post->ID);
542 542
 
543 543
 			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
544 544
 
545 545
 			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
546
-			if ( $item_id !== $uri ) {
547
-				$uri_e   = esc_html( $uri );
548
-				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
546
+			if ($item_id !== $uri) {
547
+				$uri_e   = esc_html($uri);
548
+				$content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content);
549 549
 			}
550 550
 		}
551 551
 	}
552 552
 
553 553
 	// Reapply slashes.
554
-	$content = addslashes( $content );
554
+	$content = addslashes($content);
555 555
 
556 556
 	return $content;
557 557
 }
558 558
 
559
-add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
559
+add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1);
560 560
 
561
-require_once( 'wordlift_entity_functions.php' );
561
+require_once('wordlift_entity_functions.php');
562 562
 
563 563
 // add editor related methods.
564
-require_once( 'wordlift_editor.php' );
564
+require_once('wordlift_editor.php');
565 565
 
566 566
 // add the WordLift entity custom type.
567
-require_once( 'wordlift_entity_type.php' );
568
-require_once( 'wordlift_entity_type_taxonomy.php' );
567
+require_once('wordlift_entity_type.php');
568
+require_once('wordlift_entity_type_taxonomy.php');
569 569
 
570 570
 // filters the post content when saving posts.
571
-require_once( 'wordlift_content_filter.php' );
571
+require_once('wordlift_content_filter.php');
572 572
 // add callbacks on post save to notify data changes from wp to redlink triple store
573
-require_once( 'wordlift_to_redlink_data_push_callbacks.php' );
573
+require_once('wordlift_to_redlink_data_push_callbacks.php');
574 574
 
575 575
 // Load modules
576
-require_once( 'modules/analyzer/wordlift_analyzer.php' );
577
-require_once( 'modules/linked_data/wordlift_linked_data.php' );
578
-require_once( 'modules/prefixes/wordlift_prefixes.php' );
579
-require_once( 'modules/caching/wordlift_caching.php' );
580
-require_once( 'modules/profiling/wordlift_profiling.php' );
581
-require_once( 'modules/redirector/wordlift_redirector.php' );
582
-require_once( 'modules/freebase_image_proxy/wordlift_freebase_image_proxy.php' );
576
+require_once('modules/analyzer/wordlift_analyzer.php');
577
+require_once('modules/linked_data/wordlift_linked_data.php');
578
+require_once('modules/prefixes/wordlift_prefixes.php');
579
+require_once('modules/caching/wordlift_caching.php');
580
+require_once('modules/profiling/wordlift_profiling.php');
581
+require_once('modules/redirector/wordlift_redirector.php');
582
+require_once('modules/freebase_image_proxy/wordlift_freebase_image_proxy.php');
583 583
 
584 584
 // Shortcodes
585 585
 
586 586
 // Entity view shortcode just with php >= 5.4
587
-if ( version_compare( phpversion(), '5.4.0', '>=' ) ) {
588
-	require_once( 'modules/entity_view/wordlift_entity_view.php' );
587
+if (version_compare(phpversion(), '5.4.0', '>=')) {
588
+	require_once('modules/entity_view/wordlift_entity_view.php');
589 589
 }
590 590
 
591
-require_once( 'modules/geo_widget/wordlift_geo_widget.php' );
592
-require_once( 'shortcodes/wordlift_shortcode_chord.php' );
593
-require_once( 'shortcodes/wordlift_shortcode_geomap.php' );
594
-require_once( 'shortcodes/wordlift_shortcode_field.php' );
595
-require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' );
596
-require_once( 'shortcodes/wordlift_shortcode_navigator.php' );
597
-require_once( 'shortcodes/wordlift_shortcode_blog_map.php' );
591
+require_once('modules/geo_widget/wordlift_geo_widget.php');
592
+require_once('shortcodes/wordlift_shortcode_chord.php');
593
+require_once('shortcodes/wordlift_shortcode_geomap.php');
594
+require_once('shortcodes/wordlift_shortcode_field.php');
595
+require_once('shortcodes/wordlift_shortcode_faceted_search.php');
596
+require_once('shortcodes/wordlift_shortcode_navigator.php');
597
+require_once('shortcodes/wordlift_shortcode_blog_map.php');
598 598
 
599 599
 // disable In-Depth Articles
600 600
 //require_once('wordlift_indepth_articles.php');
601 601
 
602
-require_once( 'wordlift_user.php' );
602
+require_once('wordlift_user.php');
603 603
 
604
-require_once( 'widgets/wordlift_widget_geo.php' );
605
-require_once( 'widgets/wordlift_widget_chord.php' );
606
-require_once( 'widgets/wordlift_widget_timeline.php' );
604
+require_once('widgets/wordlift_widget_geo.php');
605
+require_once('widgets/wordlift_widget_chord.php');
606
+require_once('widgets/wordlift_widget_timeline.php');
607 607
 
608
-require_once( 'wordlift_sparql.php' );
609
-require_once( 'wordlift_redlink.php' );
608
+require_once('wordlift_sparql.php');
609
+require_once('wordlift_redlink.php');
610 610
 
611
-require_once( 'modules/sparql/wordlift_sparql.php' );
611
+require_once('modules/sparql/wordlift_sparql.php');
612 612
 
613 613
 // Add admin functions.
614 614
 // TODO: find a way to make 'admin' UI tests work.
615 615
 //if ( is_admin() ) {
616 616
 
617
-require_once( 'admin/wordlift_admin.php' );
618
-require_once( 'admin/wordlift_admin_edit_post.php' );
619
-require_once( 'admin/wordlift_admin_save_post.php' );
617
+require_once('admin/wordlift_admin.php');
618
+require_once('admin/wordlift_admin_edit_post.php');
619
+require_once('admin/wordlift_admin_save_post.php');
620 620
 
621 621
 // add the entities meta box.
622
-require_once( 'admin/wordlift_admin_meta_box_entities.php' );
622
+require_once('admin/wordlift_admin_meta_box_entities.php');
623 623
 
624 624
 // add the entity creation AJAX.
625
-require_once( 'admin/wordlift_admin_ajax_related_posts.php' );
625
+require_once('admin/wordlift_admin_ajax_related_posts.php');
626 626
 
627 627
 // Load the wl_chord TinyMCE button and configuration dialog.
628
-require_once( 'admin/wordlift_admin_shortcodes.php' );
628
+require_once('admin/wordlift_admin_shortcodes.php');
629 629
 
630 630
 // Provide syncing features.
631
-require_once( 'admin/wordlift_admin_sync.php' );
631
+require_once('admin/wordlift_admin_sync.php');
632 632
 //}
633 633
 
634 634
 // load languages.
635 635
 // TODO: the following call gives for granted that the plugin is in the wordlift directory,
636 636
 //       we're currently doing this because wordlift is symbolic linked.
637
-load_plugin_textdomain( 'wordlift', false, '/wordlift/languages' );
637
+load_plugin_textdomain('wordlift', false, '/wordlift/languages');
638 638
 
639 639
 
640 640
 /**
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
  * This action is documented in includes/class-wordlift-activator.php
643 643
  */
644 644
 function activate_wordlift() {
645
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
645
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
646 646
 	Wordlift_Activator::activate();
647 647
 }
648 648
 
@@ -651,18 +651,18 @@  discard block
 block discarded – undo
651 651
  * This action is documented in includes/class-wordlift-deactivator.php
652 652
  */
653 653
 function deactivate_wordlift() {
654
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
654
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
655 655
 	Wordlift_Deactivator::deactivate();
656 656
 }
657 657
 
658
-register_activation_hook( __FILE__, 'activate_wordlift' );
659
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
658
+register_activation_hook(__FILE__, 'activate_wordlift');
659
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
660 660
 
661 661
 /**
662 662
  * The core plugin class that is used to define internationalization,
663 663
  * admin-specific hooks, and public-facing site hooks.
664 664
  */
665
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
665
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
666 666
 
667 667
 /**
668 668
  * Begins execution of the plugin.
Please login to merge, or discard this patch.
src/admin/WL_Metabox/WL_Metabox.php 2 patches
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -13,253 +13,253 @@
 block discarded – undo
13 13
  */
14 14
 class WL_Metabox {
15 15
 
16
-	public $fields;
17
-
18
-	/**
19
-	 * The Log service.
20
-	 *
21
-	 * @since 3.1.0
22
-	 * @access private
23
-	 * @var Wordlift_Log_Service $log_service The Log service.
24
-	 */
25
-	private $log_service;
26
-
27
-	/**
28
-	 * WL_Metabox constructor.
29
-	 *
30
-	 * @since 3.1.0
31
-	 */
32
-	public function __construct() {
33
-
34
-		// Create a logger instance.
35
-		$this->log_service = Wordlift_Log_Service::get_logger( 'WL_Metabox' );
36
-
37
-		// Add hooks to print metaboxes and save submitted data.
38
-		add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
39
-		add_action( 'wl_linked_data_save_post', array( &$this, 'save_form_data' ) );
40
-
41
-		// Enqueue js and css
42
-		$this->enqueue_scripts_and_styles();
43
-
44
-	}
45
-
46
-	/**
47
-	 * Add a callback to print the metabox in page.
48
-	 * Wordpress will fire the $this->html() callback at the right time.
49
-	 */
50
-	public function add_main_metabox() {
51
-
52
-		// Add main metabox (will print also the inner fields)
53
-		$id		= uniqid( 'wl-metabox-' );
54
-		$title	= 'WordLift - ' . get_the_title() . ' ' . __('properties', 'wordlift');
55
-		add_meta_box( $id, $title, array(
56
-			$this,
57
-			'html'
58
-		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
59
-
60
-	}
61
-
62
-	/**
63
-	 * Called from WP to print the metabox content in page.
64
-	 *
65
-	 * @since 3.1.0
66
-	 *
67
-	 * @param WP_Post $post The post.
68
-	 */
69
-	public function html( $post ) {
70
-
71
-		// Build the fields we need to print.
72
-		$this->instantiate_fields( $post->ID );
73
-
74
-		// Loop over the fields
75
-		foreach ( $this->fields as $field ) {
76
-
77
-			// load data from DB (values will be available in $field->data)
78
-			$field->get_data();
79
-
80
-			// print field HTML (nonce included)
81
-			echo $field->html();
82
-		}
83
-
84
-	}
85
-
86
-	/**
87
-	 * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
88
-	 *
89
-	 * Note: the first function that calls this method will instantiate the fields.
90
-	 * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
91
-	 *
92
-	 * @since 3.1.0
93
-	 *
94
-	 * @param int $post_id The post id.
95
-	 */
96
-	public function instantiate_fields( $post_id ) {
97
-
98
-		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering
99
-		if ( isset( $this->fields ) ) {
100
-			return;
101
-		}
102
-
103
-		$entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
104
-
105
-		if ( isset( $entity_type ) ) {
106
-
107
-			/**
108
-			 * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
109
-			 * We must divide fields in two groups:
110
-			 * - simple: accept values for one property
111
-			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
112
-			 */
113
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
114
-			$simple_metaboxes  = $metaboxes[0];
115
-			$grouped_metaboxes = $metaboxes[1];
116
-
117
-			// Loop over simple entity properties
118
-			foreach ( $simple_metaboxes as $key => $property ) {
119
-
120
-				// Info passed to the metabox
121
-				$info         = array();
122
-				$info[ $key ] = $property;
123
-
124
-				// Build the requested field as WL_Metabox_Field_ object
125
-				$this->add_field( $info );
126
-			}
127
-
128
-			// Loop over grouped properties
129
-			foreach ( $grouped_metaboxes as $key => $property ) {
130
-
131
-				// Info passed to the metabox
132
-				$info         = array();
133
-				$info[ $key ] = $property;
134
-
135
-				// Build the requested field group as WL_Metabox_Field_ object
136
-				$this->add_field( $info, true );
137
-			}
138
-
139
-		}
140
-	}
141
-
142
-	/**
143
-	 * Separes metaboxes in simple and grouped.
144
-	 *
145
-	 * @param array $custom_fields Information on the entity type.
146
-	 */
147
-	public function group_properties_by_input_field( $custom_fields ) {
148
-
149
-		$simple_properties  = array();
150
-		$grouped_properties = array();
151
-
152
-		// Loop over possible entity properties
153
-		foreach ( $custom_fields as $key => $property ) {
154
-
155
-			// Check presence of predicate and type
156
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
157
-
158
-				// Check if input_field is defined
159
-				if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
160
-
161
-					$grouped_key = $property['input_field'];
162
-
163
-					// Update list of grouped properties
164
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
165
-
166
-				} else {
167
-
168
-					// input_field not defined, add simple metabox
169
-					$simple_properties[ $key ] = $property;
170
-				}
171
-			}
172
-		}
173
-
174
-		return array( $simple_properties, $grouped_properties );
175
-	}
176
-
177
-	/**
178
-	 * Add a Field to the current Metabox, based on the description of the Field.
179
-	 * This method is a rude factory for Field objects.
180
-	 *
181
-	 * @param type $args
182
-	 * @param type $grouped Flag to distinguish between simple and grouped Fields
183
-	 */
184
-	public function add_field( $args, $grouped = false ) {
185
-
186
-		if ( $grouped ) {
187
-			// Special fields (sameas, coordinates, etc.)
188
-
189
-			// Build Field with a custom class (e.g. WL_Metabox_Field_date)
190
-			$field_class = 'WL_Metabox_Field_' . key( $args );
191
-
192
-		} else {
193
-			// Simple fields (string, uri, boolean, etc.)
194
-
195
-			// Which field? We want to use the class that is specific for the field.
196
-			$meta = key( $args );
197
-			if ( ! isset( $args[ $meta ]['type'] ) || ( $args[ $meta ]['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
198
-				// Use default WL_Metabox_Field (manages strings)
199
-				$field_class = 'WL_Metabox_Field';
200
-			} else {
201
-				// Build Field with a custom class (e.g. WL_Metabox_Field_date)
202
-				$field_class = 'WL_Metabox_Field_' . $args[ $meta ]['type'];
203
-			}
204
-		}
205
-
206
-		// Call apropriate constructor (e.g. WL_Metabox_Field_... )
207
-		$this->fields[] = new $field_class( $args );
208
-	}
209
-
210
-	public function save_form_data( $entity_id ) {
211
-
212
-		// Build Field objects
213
-		$this->instantiate_fields( $entity_id );
16
+    public $fields;
17
+
18
+    /**
19
+     * The Log service.
20
+     *
21
+     * @since 3.1.0
22
+     * @access private
23
+     * @var Wordlift_Log_Service $log_service The Log service.
24
+     */
25
+    private $log_service;
26
+
27
+    /**
28
+     * WL_Metabox constructor.
29
+     *
30
+     * @since 3.1.0
31
+     */
32
+    public function __construct() {
33
+
34
+        // Create a logger instance.
35
+        $this->log_service = Wordlift_Log_Service::get_logger( 'WL_Metabox' );
36
+
37
+        // Add hooks to print metaboxes and save submitted data.
38
+        add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
39
+        add_action( 'wl_linked_data_save_post', array( &$this, 'save_form_data' ) );
40
+
41
+        // Enqueue js and css
42
+        $this->enqueue_scripts_and_styles();
43
+
44
+    }
45
+
46
+    /**
47
+     * Add a callback to print the metabox in page.
48
+     * Wordpress will fire the $this->html() callback at the right time.
49
+     */
50
+    public function add_main_metabox() {
51
+
52
+        // Add main metabox (will print also the inner fields)
53
+        $id		= uniqid( 'wl-metabox-' );
54
+        $title	= 'WordLift - ' . get_the_title() . ' ' . __('properties', 'wordlift');
55
+        add_meta_box( $id, $title, array(
56
+            $this,
57
+            'html'
58
+        ), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
59
+
60
+    }
61
+
62
+    /**
63
+     * Called from WP to print the metabox content in page.
64
+     *
65
+     * @since 3.1.0
66
+     *
67
+     * @param WP_Post $post The post.
68
+     */
69
+    public function html( $post ) {
70
+
71
+        // Build the fields we need to print.
72
+        $this->instantiate_fields( $post->ID );
73
+
74
+        // Loop over the fields
75
+        foreach ( $this->fields as $field ) {
76
+
77
+            // load data from DB (values will be available in $field->data)
78
+            $field->get_data();
79
+
80
+            // print field HTML (nonce included)
81
+            echo $field->html();
82
+        }
83
+
84
+    }
85
+
86
+    /**
87
+     * Read the WL <-> Schema mapping and build the Fields for the entity being edited.
88
+     *
89
+     * Note: the first function that calls this method will instantiate the fields.
90
+     * Why it isn't called from the constructor? Because we need to hook this process as late as possible.
91
+     *
92
+     * @since 3.1.0
93
+     *
94
+     * @param int $post_id The post id.
95
+     */
96
+    public function instantiate_fields( $post_id ) {
97
+
98
+        // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering
99
+        if ( isset( $this->fields ) ) {
100
+            return;
101
+        }
102
+
103
+        $entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
104
+
105
+        if ( isset( $entity_type ) ) {
106
+
107
+            /**
108
+             * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
109
+             * We must divide fields in two groups:
110
+             * - simple: accept values for one property
111
+             * - grouped: accept values for more properties, or for one property that needs a specific metabox.
112
+             */
113
+            $metaboxes         = $this->group_properties_by_input_field( $entity_type );
114
+            $simple_metaboxes  = $metaboxes[0];
115
+            $grouped_metaboxes = $metaboxes[1];
116
+
117
+            // Loop over simple entity properties
118
+            foreach ( $simple_metaboxes as $key => $property ) {
119
+
120
+                // Info passed to the metabox
121
+                $info         = array();
122
+                $info[ $key ] = $property;
123
+
124
+                // Build the requested field as WL_Metabox_Field_ object
125
+                $this->add_field( $info );
126
+            }
127
+
128
+            // Loop over grouped properties
129
+            foreach ( $grouped_metaboxes as $key => $property ) {
130
+
131
+                // Info passed to the metabox
132
+                $info         = array();
133
+                $info[ $key ] = $property;
134
+
135
+                // Build the requested field group as WL_Metabox_Field_ object
136
+                $this->add_field( $info, true );
137
+            }
138
+
139
+        }
140
+    }
141
+
142
+    /**
143
+     * Separes metaboxes in simple and grouped.
144
+     *
145
+     * @param array $custom_fields Information on the entity type.
146
+     */
147
+    public function group_properties_by_input_field( $custom_fields ) {
148
+
149
+        $simple_properties  = array();
150
+        $grouped_properties = array();
151
+
152
+        // Loop over possible entity properties
153
+        foreach ( $custom_fields as $key => $property ) {
154
+
155
+            // Check presence of predicate and type
156
+            if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
157
+
158
+                // Check if input_field is defined
159
+                if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
160
+
161
+                    $grouped_key = $property['input_field'];
162
+
163
+                    // Update list of grouped properties
164
+                    $grouped_properties[ $grouped_key ][ $key ] = $property;
165
+
166
+                } else {
167
+
168
+                    // input_field not defined, add simple metabox
169
+                    $simple_properties[ $key ] = $property;
170
+                }
171
+            }
172
+        }
173
+
174
+        return array( $simple_properties, $grouped_properties );
175
+    }
176
+
177
+    /**
178
+     * Add a Field to the current Metabox, based on the description of the Field.
179
+     * This method is a rude factory for Field objects.
180
+     *
181
+     * @param type $args
182
+     * @param type $grouped Flag to distinguish between simple and grouped Fields
183
+     */
184
+    public function add_field( $args, $grouped = false ) {
185
+
186
+        if ( $grouped ) {
187
+            // Special fields (sameas, coordinates, etc.)
188
+
189
+            // Build Field with a custom class (e.g. WL_Metabox_Field_date)
190
+            $field_class = 'WL_Metabox_Field_' . key( $args );
191
+
192
+        } else {
193
+            // Simple fields (string, uri, boolean, etc.)
194
+
195
+            // Which field? We want to use the class that is specific for the field.
196
+            $meta = key( $args );
197
+            if ( ! isset( $args[ $meta ]['type'] ) || ( $args[ $meta ]['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
198
+                // Use default WL_Metabox_Field (manages strings)
199
+                $field_class = 'WL_Metabox_Field';
200
+            } else {
201
+                // Build Field with a custom class (e.g. WL_Metabox_Field_date)
202
+                $field_class = 'WL_Metabox_Field_' . $args[ $meta ]['type'];
203
+            }
204
+        }
205
+
206
+        // Call apropriate constructor (e.g. WL_Metabox_Field_... )
207
+        $this->fields[] = new $field_class( $args );
208
+    }
209
+
210
+    public function save_form_data( $entity_id ) {
211
+
212
+        // Build Field objects
213
+        $this->instantiate_fields( $entity_id );
214 214
 
215
-		// Check if WL metabox form was posted
216
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
217
-			return;
218
-		}
215
+        // Check if WL metabox form was posted
216
+        if ( ! isset( $_POST['wl_metaboxes'] ) ) {
217
+            return;
218
+        }
219 219
 
220
-		foreach ( $this->fields as $field ) {
221
-
222
-			// Verify nonce
223
-			$valid_nonce = $field->verify_nonce();
224
-			if ( $valid_nonce ) {
225
-
226
-				$posted_data = $_POST['wl_metaboxes'];
227
-				$field_name  = $field->meta_name;
228
-
229
-				// Each Filed only deals with its values.
230
-				if ( isset( $posted_data[ $field_name ] ) ) {
231
-
232
-					$values = $posted_data[ $field_name ];
233
-					if ( ! is_array( $values ) ) {
234
-						$values = array( $values );
235
-					}
236
-
237
-					// Save data permanently
238
-					$field->save_data( $values );
239
-				}
240
-			}
241
-		}
242
-
243
-		wl_linked_data_push_to_redlink( $entity_id );
244
-	}
245
-
246
-	// print on page all the js and css the fields will need
247
-	public function enqueue_scripts_and_styles() {
220
+        foreach ( $this->fields as $field ) {
221
+
222
+            // Verify nonce
223
+            $valid_nonce = $field->verify_nonce();
224
+            if ( $valid_nonce ) {
225
+
226
+                $posted_data = $_POST['wl_metaboxes'];
227
+                $field_name  = $field->meta_name;
228
+
229
+                // Each Filed only deals with its values.
230
+                if ( isset( $posted_data[ $field_name ] ) ) {
231
+
232
+                    $values = $posted_data[ $field_name ];
233
+                    if ( ! is_array( $values ) ) {
234
+                        $values = array( $values );
235
+                    }
236
+
237
+                    // Save data permanently
238
+                    $field->save_data( $values );
239
+                }
240
+            }
241
+        }
242
+
243
+        wl_linked_data_push_to_redlink( $entity_id );
244
+    }
245
+
246
+    // print on page all the js and css the fields will need
247
+    public function enqueue_scripts_and_styles() {
248 248
 
249
-		// dateTimePicker
250
-		wp_enqueue_style( 'datetimepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/css/jquery.datetimepicker.css' );
251
-		wp_enqueue_script( 'datetimepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.full.min.js', array( 'jquery' ) );
252
-
253
-		// Leaflet.
254
-		wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
255
-		wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
256
-
257
-		// Add AJAX autocomplete to facilitate metabox editing
258
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
259
-		wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
260
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
261
-				'action'   => 'entity_by_title'
262
-			)
263
-		);
264
-	}
249
+        // dateTimePicker
250
+        wp_enqueue_style( 'datetimepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/css/jquery.datetimepicker.css' );
251
+        wp_enqueue_script( 'datetimepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.full.min.js', array( 'jquery' ) );
252
+
253
+        // Leaflet.
254
+        wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
255
+        wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
256
+
257
+        // Add AJAX autocomplete to facilitate metabox editing
258
+        wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
259
+        wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
260
+                'ajax_url' => admin_url( 'admin-ajax.php' ),
261
+                'action'   => 'entity_by_title'
262
+            )
263
+        );
264
+    }
265 265
 }
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once( 'WL_Metabox_Field.php' );
4
-require_once( 'WL_Metabox_Field_date.php' );
5
-require_once( 'WL_Metabox_Field_uri.php' );
6
-require_once( 'WL_Metabox_Field_coordinates.php' );
7
-require_once( 'WL_Metabox_Field_sameas.php' );
3
+require_once('WL_Metabox_Field.php');
4
+require_once('WL_Metabox_Field_date.php');
5
+require_once('WL_Metabox_Field_uri.php');
6
+require_once('WL_Metabox_Field_coordinates.php');
7
+require_once('WL_Metabox_Field_sameas.php');
8 8
 
9 9
 /**
10 10
  * Class WL_Metabox
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
 	public function __construct() {
33 33
 
34 34
 		// Create a logger instance.
35
-		$this->log_service = Wordlift_Log_Service::get_logger( 'WL_Metabox' );
35
+		$this->log_service = Wordlift_Log_Service::get_logger('WL_Metabox');
36 36
 
37 37
 		// Add hooks to print metaboxes and save submitted data.
38
-		add_action( 'add_meta_boxes', array( &$this, 'add_main_metabox' ) );
39
-		add_action( 'wl_linked_data_save_post', array( &$this, 'save_form_data' ) );
38
+		add_action('add_meta_boxes', array(&$this, 'add_main_metabox'));
39
+		add_action('wl_linked_data_save_post', array(&$this, 'save_form_data'));
40 40
 
41 41
 		// Enqueue js and css
42 42
 		$this->enqueue_scripts_and_styles();
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
 	public function add_main_metabox() {
51 51
 
52 52
 		// Add main metabox (will print also the inner fields)
53
-		$id		= uniqid( 'wl-metabox-' );
54
-		$title	= 'WordLift - ' . get_the_title() . ' ' . __('properties', 'wordlift');
55
-		add_meta_box( $id, $title, array(
53
+		$id = uniqid('wl-metabox-');
54
+		$title = 'WordLift - '.get_the_title().' '.__('properties', 'wordlift');
55
+		add_meta_box($id, $title, array(
56 56
 			$this,
57 57
 			'html'
58
-		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high' );
58
+		), Wordlift_Entity_Service::TYPE_NAME, 'normal', 'high');
59 59
 
60 60
 	}
61 61
 
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 * @param WP_Post $post The post.
68 68
 	 */
69
-	public function html( $post ) {
69
+	public function html($post) {
70 70
 
71 71
 		// Build the fields we need to print.
72
-		$this->instantiate_fields( $post->ID );
72
+		$this->instantiate_fields($post->ID);
73 73
 
74 74
 		// Loop over the fields
75
-		foreach ( $this->fields as $field ) {
75
+		foreach ($this->fields as $field) {
76 76
 
77 77
 			// load data from DB (values will be available in $field->data)
78 78
 			$field->get_data();
@@ -93,16 +93,16 @@  discard block
 block discarded – undo
93 93
 	 *
94 94
 	 * @param int $post_id The post id.
95 95
 	 */
96
-	public function instantiate_fields( $post_id ) {
96
+	public function instantiate_fields($post_id) {
97 97
 
98 98
 		// This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering
99
-		if ( isset( $this->fields ) ) {
99
+		if (isset($this->fields)) {
100 100
 			return;
101 101
 		}
102 102
 
103
-		$entity_type = wl_entity_taxonomy_get_custom_fields( $post_id );
103
+		$entity_type = wl_entity_taxonomy_get_custom_fields($post_id);
104 104
 
105
-		if ( isset( $entity_type ) ) {
105
+		if (isset($entity_type)) {
106 106
 
107 107
 			/**
108 108
 			 * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods.
@@ -110,30 +110,30 @@  discard block
 block discarded – undo
110 110
 			 * - simple: accept values for one property
111 111
 			 * - grouped: accept values for more properties, or for one property that needs a specific metabox.
112 112
 			 */
113
-			$metaboxes         = $this->group_properties_by_input_field( $entity_type );
113
+			$metaboxes         = $this->group_properties_by_input_field($entity_type);
114 114
 			$simple_metaboxes  = $metaboxes[0];
115 115
 			$grouped_metaboxes = $metaboxes[1];
116 116
 
117 117
 			// Loop over simple entity properties
118
-			foreach ( $simple_metaboxes as $key => $property ) {
118
+			foreach ($simple_metaboxes as $key => $property) {
119 119
 
120 120
 				// Info passed to the metabox
121 121
 				$info         = array();
122
-				$info[ $key ] = $property;
122
+				$info[$key] = $property;
123 123
 
124 124
 				// Build the requested field as WL_Metabox_Field_ object
125
-				$this->add_field( $info );
125
+				$this->add_field($info);
126 126
 			}
127 127
 
128 128
 			// Loop over grouped properties
129
-			foreach ( $grouped_metaboxes as $key => $property ) {
129
+			foreach ($grouped_metaboxes as $key => $property) {
130 130
 
131 131
 				// Info passed to the metabox
132 132
 				$info         = array();
133
-				$info[ $key ] = $property;
133
+				$info[$key] = $property;
134 134
 
135 135
 				// Build the requested field group as WL_Metabox_Field_ object
136
-				$this->add_field( $info, true );
136
+				$this->add_field($info, true);
137 137
 			}
138 138
 
139 139
 		}
@@ -144,34 +144,34 @@  discard block
 block discarded – undo
144 144
 	 *
145 145
 	 * @param array $custom_fields Information on the entity type.
146 146
 	 */
147
-	public function group_properties_by_input_field( $custom_fields ) {
147
+	public function group_properties_by_input_field($custom_fields) {
148 148
 
149 149
 		$simple_properties  = array();
150 150
 		$grouped_properties = array();
151 151
 
152 152
 		// Loop over possible entity properties
153
-		foreach ( $custom_fields as $key => $property ) {
153
+		foreach ($custom_fields as $key => $property) {
154 154
 
155 155
 			// Check presence of predicate and type
156
-			if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) {
156
+			if (isset($property['predicate']) && isset($property['type'])) {
157 157
 
158 158
 				// Check if input_field is defined
159
-				if ( isset( $property['input_field'] ) && $property['input_field'] !== '' ) {
159
+				if (isset($property['input_field']) && $property['input_field'] !== '') {
160 160
 
161 161
 					$grouped_key = $property['input_field'];
162 162
 
163 163
 					// Update list of grouped properties
164
-					$grouped_properties[ $grouped_key ][ $key ] = $property;
164
+					$grouped_properties[$grouped_key][$key] = $property;
165 165
 
166 166
 				} else {
167 167
 
168 168
 					// input_field not defined, add simple metabox
169
-					$simple_properties[ $key ] = $property;
169
+					$simple_properties[$key] = $property;
170 170
 				}
171 171
 			}
172 172
 		}
173 173
 
174
-		return array( $simple_properties, $grouped_properties );
174
+		return array($simple_properties, $grouped_properties);
175 175
 	}
176 176
 
177 177
 	/**
@@ -181,83 +181,83 @@  discard block
 block discarded – undo
181 181
 	 * @param type $args
182 182
 	 * @param type $grouped Flag to distinguish between simple and grouped Fields
183 183
 	 */
184
-	public function add_field( $args, $grouped = false ) {
184
+	public function add_field($args, $grouped = false) {
185 185
 
186
-		if ( $grouped ) {
186
+		if ($grouped) {
187 187
 			// Special fields (sameas, coordinates, etc.)
188 188
 
189 189
 			// Build Field with a custom class (e.g. WL_Metabox_Field_date)
190
-			$field_class = 'WL_Metabox_Field_' . key( $args );
190
+			$field_class = 'WL_Metabox_Field_'.key($args);
191 191
 
192 192
 		} else {
193 193
 			// Simple fields (string, uri, boolean, etc.)
194 194
 
195 195
 			// Which field? We want to use the class that is specific for the field.
196
-			$meta = key( $args );
197
-			if ( ! isset( $args[ $meta ]['type'] ) || ( $args[ $meta ]['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING ) ) {
196
+			$meta = key($args);
197
+			if ( ! isset($args[$meta]['type']) || ($args[$meta]['type'] == Wordlift_Schema_Service::DATA_TYPE_STRING)) {
198 198
 				// Use default WL_Metabox_Field (manages strings)
199 199
 				$field_class = 'WL_Metabox_Field';
200 200
 			} else {
201 201
 				// Build Field with a custom class (e.g. WL_Metabox_Field_date)
202
-				$field_class = 'WL_Metabox_Field_' . $args[ $meta ]['type'];
202
+				$field_class = 'WL_Metabox_Field_'.$args[$meta]['type'];
203 203
 			}
204 204
 		}
205 205
 
206 206
 		// Call apropriate constructor (e.g. WL_Metabox_Field_... )
207
-		$this->fields[] = new $field_class( $args );
207
+		$this->fields[] = new $field_class($args);
208 208
 	}
209 209
 
210
-	public function save_form_data( $entity_id ) {
210
+	public function save_form_data($entity_id) {
211 211
 
212 212
 		// Build Field objects
213
-		$this->instantiate_fields( $entity_id );
213
+		$this->instantiate_fields($entity_id);
214 214
 
215 215
 		// Check if WL metabox form was posted
216
-		if ( ! isset( $_POST['wl_metaboxes'] ) ) {
216
+		if ( ! isset($_POST['wl_metaboxes'])) {
217 217
 			return;
218 218
 		}
219 219
 
220
-		foreach ( $this->fields as $field ) {
220
+		foreach ($this->fields as $field) {
221 221
 
222 222
 			// Verify nonce
223 223
 			$valid_nonce = $field->verify_nonce();
224
-			if ( $valid_nonce ) {
224
+			if ($valid_nonce) {
225 225
 
226 226
 				$posted_data = $_POST['wl_metaboxes'];
227 227
 				$field_name  = $field->meta_name;
228 228
 
229 229
 				// Each Filed only deals with its values.
230
-				if ( isset( $posted_data[ $field_name ] ) ) {
230
+				if (isset($posted_data[$field_name])) {
231 231
 
232
-					$values = $posted_data[ $field_name ];
233
-					if ( ! is_array( $values ) ) {
234
-						$values = array( $values );
232
+					$values = $posted_data[$field_name];
233
+					if ( ! is_array($values)) {
234
+						$values = array($values);
235 235
 					}
236 236
 
237 237
 					// Save data permanently
238
-					$field->save_data( $values );
238
+					$field->save_data($values);
239 239
 				}
240 240
 			}
241 241
 		}
242 242
 
243
-		wl_linked_data_push_to_redlink( $entity_id );
243
+		wl_linked_data_push_to_redlink($entity_id);
244 244
 	}
245 245
 
246 246
 	// print on page all the js and css the fields will need
247 247
 	public function enqueue_scripts_and_styles() {
248 248
 
249 249
 		// dateTimePicker
250
-		wp_enqueue_style( 'datetimepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/css/jquery.datetimepicker.css' );
251
-		wp_enqueue_script( 'datetimepicker', dirname( plugin_dir_url( __FILE__ ) ) . '/js/jquery.datetimepicker.full.min.js', array( 'jquery' ) );
250
+		wp_enqueue_style('datetimepicker', dirname(plugin_dir_url(__FILE__)).'/css/jquery.datetimepicker.css');
251
+		wp_enqueue_script('datetimepicker', dirname(plugin_dir_url(__FILE__)).'/js/jquery.datetimepicker.full.min.js', array('jquery'));
252 252
 
253 253
 		// Leaflet.
254
-		wp_enqueue_style( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
255
-		wp_enqueue_script( 'leaflet', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js', __FILE__ );
254
+		wp_enqueue_style('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.css');
255
+		wp_enqueue_script('leaflet', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.js', __FILE__);
256 256
 
257 257
 		// Add AJAX autocomplete to facilitate metabox editing
258
-		wp_enqueue_script( 'wl-entity-metabox-utility', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wl_entity_metabox_utilities.js' );
259
-		wp_localize_script( 'wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
260
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
258
+		wp_enqueue_script('wl-entity-metabox-utility', dirname(plugin_dir_url(__FILE__)).'/js/wl_entity_metabox_utilities.js');
259
+		wp_localize_script('wl-entity-metabox-utility', 'wlEntityMetaboxParams', array(
260
+				'ajax_url' => admin_url('admin-ajax.php'),
261 261
 				'action'   => 'entity_by_title'
262 262
 			)
263 263
 		);
Please login to merge, or discard this patch.
src/admin/WL_Metabox/WL_Metabox_Field.php 2 patches
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -7,257 +7,257 @@
 block discarded – undo
7 7
  */
8 8
 class WL_Metabox_Field {
9 9
 
10
-	public $meta_name;
11
-	public $raw_custom_field;
12
-	public $predicate;
13
-	public $label;
14
-	public $expected_wl_type;
15
-	public $expected_uri_type;
16
-	public $cardinality;
17
-	public $data;
18
-
19
-	/**
20
-	 * The Log service.
21
-	 *
22
-	 * @since 3.1.0
23
-	 * @access private
24
-	 * @var \Wordlift_Log_Service $log_service The Log service.
25
-	 */
26
-	private $log_service;
27
-
28
-	/**
29
-	 * Constructor. Recevies.... TODO write docs
30
-	 */
31
-	public function __construct( $args ) {
32
-
33
-		$this->log_service = Wordlift_Log_Service::get_logger( 'WL_Metabox_Field' );
34
-
35
-		if ( empty( $args ) ) {
36
-			return;
37
-		}
38
-
39
-		// Save a copy of the custom field's params
40
-		$this->raw_custom_field = reset( $args );
41
-
42
-		// Extract meta name (post_meta key for the DB)
43
-		$this->meta_name = key( $args );
44
-
45
-		// Extract linked data predicate
46
-		if ( isset( $this->raw_custom_field['predicate'] ) ) {
47
-			$this->predicate = $this->raw_custom_field['predicate'];
48
-		} else {
49
-			return;
50
-		}
51
-
52
-		// Extract human readable label
53
-		$exploded_predicate = explode( '/', $this->predicate );
54
-		$this->label        = end( $exploded_predicate );
55
-
56
-		// Extract field constraints (numerosity, expected type)
57
-		// Default constaints: accept one string.
58
-		if ( isset( $this->raw_custom_field['type'] ) ) {
59
-			$this->expected_wl_type = $this->raw_custom_field['type'];
60
-		} else {
61
-			$this->expected_wl_type = Wordlift_Schema_Service::DATA_TYPE_STRING;
62
-		}
63
-
64
-		$this->cardinality = 1;
65
-		if ( isset( $this->raw_custom_field['constraints'] ) ) {
66
-
67
-			$constraints = $this->raw_custom_field['constraints'];
68
-
69
-			// Extract cardinality
70
-			if ( isset( $constraints['cardinality'] ) ) {
71
-				$this->cardinality = $constraints['cardinality'];
72
-			}
73
-
74
-			// Which type of entity can we accept (e.g. Place, Event, ecc.)?
75
-			if ( $this->expected_wl_type === Wordlift_Schema_Service::DATA_TYPE_URI && isset( $constraints['uri_type'] ) ) {
76
-				$this->expected_uri_type = is_array( $constraints['uri_type'] ) ? $constraints['uri_type'] : array( $constraints['uri_type'] );
77
-			}
78
-
79
-		}
80
-	}
81
-
82
-	/**
83
-	 * Return nonce HTML.
84
-	 * Overwrite this method in a child class to obtain custom behaviour.
85
-	 */
86
-	public function html_nonce() {
87
-
88
-		return wp_nonce_field( 'wordlift_' . $this->meta_name . '_entity_box', 'wordlift_' . $this->meta_name . '_entity_box_nonce', true, false );
89
-	}
90
-
91
-	/**
92
-	 * Verify nonce.
93
-	 * Overwrite this method in a child class to obtain custom behaviour.
94
-	 *
95
-	 * @return boolean Nonce verification
96
-	 */
97
-	public function verify_nonce() {
98
-
99
-		$nonce_name   = 'wordlift_' . $this->meta_name . '_entity_box_nonce';
100
-		$nonce_verify = 'wordlift_' . $this->meta_name . '_entity_box';
101
-
102
-		if ( ! isset( $_POST[ $nonce_name ] ) ) {
103
-			return false;
104
-		}
105
-
106
-		// Verify that the nonce is valid.
107
-		return wp_verify_nonce( $_POST[ $nonce_name ], $nonce_verify );
108
-	}
109
-
110
-	/**
111
-	 * Load data from DB and store the resulting array in $this->data.
112
-	 * Overwrite this method in a child class to obtain custom behaviour.
113
-	 */
114
-	public function get_data() {
115
-
116
-		$data = get_post_meta( get_the_ID(), $this->meta_name );
117
-
118
-		// Values are always contained in an array (makes it easier to manage cardinality)
119
-		if ( ! is_array( $data ) ) {
120
-			$data = array( $data );
121
-		}
122
-
123
-		$this->data = $data;
124
-	}
125
-
126
-	/**
127
-	 * Sanitizes data before saving to DB. Default sanitization trashes empty values.
128
-	 * Stores the sanitized values into $this->data so they can be later processed.
129
-	 * Overwrite this method in a child class to obtain custom behaviour.
130
-	 *
131
-	 * @param array $values Array of values to be sanitized and then stored into $this->data
132
-	 *
133
-	 */
134
-	public function sanitize_data( $values ) {
135
-
136
-		$sanitized_data = array();
137
-
138
-		if ( ! is_array( $values ) ) {
139
-			$values = array( $values );
140
-		}
141
-
142
-		foreach ( $values as $value ) {
143
-			$sanitized_value = $this->sanitize_data_filter( $value );
144
-			if ( ! is_null( $sanitized_value ) ) {
145
-				$sanitized_data[] = $sanitized_value;
146
-			}
147
-		}
148
-
149
-		$this->data = $sanitized_data;
150
-	}
151
-
152
-	/**
153
-	 * Sanitize a single value. Called from $this->sanitize_data. Default sanitization excludes empty values.
154
-	 * Overwrite this method in a child class to obtain custom behaviour.
155
-	 *
156
-	 * @return mixed Returns sanitized value, or null.
157
-	 */
158
-	public function sanitize_data_filter( $value ) {
159
-
160
-		if ( ! is_null( $value ) && $value !== '' ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/
161
-			return $value;
162
-		}
163
-
164
-		return null;
165
-	}
166
-
167
-	/**
168
-	 * Save data to DB.
169
-	 * Overwrite this method in a child class to obtain custom behaviour.
170
-	 */
171
-	public function save_data( $values ) {
172
-
173
-		// Will sanitize data and store them in $field->data
174
-		$this->sanitize_data( $values );
175
-
176
-		$entity_id = get_the_ID();
177
-
178
-		// Take away old values
179
-		delete_post_meta( $entity_id, $this->meta_name );
180
-
181
-		// insert new values, respecting cardinality
182
-		$single = ( $this->cardinality == 1 );
183
-		foreach ( $this->data as $value ) {
184
-			add_post_meta( $entity_id, $this->meta_name, $value, $single );
185
-		}
186
-	}
187
-
188
-	/**
189
-	 * Returns the HTML tag that will contain the Field. By default the we return a <div> with data- attributes on cardinality and expected types.
190
-	 * It is useful to provide data- attributes for the JS scripts.
191
-	 * Overwrite this method in a child class to obtain custom behaviour.
192
-	 */
193
-	public function html_wrapper_open() {
194
-
195
-		return '<div class="wl-metabox" data-cardinality="' . $this->cardinality . '">';
196
-	}
197
-
198
-	/**
199
-	 * Returns Field HTML (nonce included).
200
-	 * Overwrite this method (or methods called from this method) in a child class to obtain custom behaviour.
201
-	 */
202
-	public function html() {
203
-
204
-		// Open main <div> for the Field
205
-		$html = $this->html_wrapper_open();
206
-
207
-		// Label
208
-		$html .= '<h3>' . $this->label . '</h3>';
209
-
210
-		// print nonce
211
-		$html .= $this->html_nonce();
212
-
213
-		// print data loaded from DB
214
-		$count = 0;
215
-		if ( $this->data ) {
216
-			foreach ( $this->data as $value ) {
217
-				if ( $count < $this->cardinality ) {
218
-					$html .= $this->html_input( $value );
219
-				}
220
-				$count ++;
221
-			}
222
-		}
223
-
224
-		// Print the empty <input> to add new values
225
-		if ( $count === 0 || $count < $this->cardinality ) {
226
-			$html .= $this->html_input( '' );    // Will print an empty <input>
227
-			$count ++;
228
-		}
229
-
230
-		// If cardiality allows it, print button to add new values.
231
-		if ( $count < $this->cardinality ) {
232
-			$html .= '<button class="button wl-add-input" type="button">Add</button>';
233
-		}
234
-
235
-		// Close the HTML wrapper
236
-		$html .= $this->html_wrapper_close();
237
-
238
-		return $html;
239
-	}
240
-
241
-	/**
242
-	 * Return a single <input> tag for the Field.
243
-	 *
244
-	 * @param mixed $value Input value
245
-	 */
246
-	public function html_input( $value ) {
247
-		$html = '<div class="wl-input-wrapper">
10
+    public $meta_name;
11
+    public $raw_custom_field;
12
+    public $predicate;
13
+    public $label;
14
+    public $expected_wl_type;
15
+    public $expected_uri_type;
16
+    public $cardinality;
17
+    public $data;
18
+
19
+    /**
20
+     * The Log service.
21
+     *
22
+     * @since 3.1.0
23
+     * @access private
24
+     * @var \Wordlift_Log_Service $log_service The Log service.
25
+     */
26
+    private $log_service;
27
+
28
+    /**
29
+     * Constructor. Recevies.... TODO write docs
30
+     */
31
+    public function __construct( $args ) {
32
+
33
+        $this->log_service = Wordlift_Log_Service::get_logger( 'WL_Metabox_Field' );
34
+
35
+        if ( empty( $args ) ) {
36
+            return;
37
+        }
38
+
39
+        // Save a copy of the custom field's params
40
+        $this->raw_custom_field = reset( $args );
41
+
42
+        // Extract meta name (post_meta key for the DB)
43
+        $this->meta_name = key( $args );
44
+
45
+        // Extract linked data predicate
46
+        if ( isset( $this->raw_custom_field['predicate'] ) ) {
47
+            $this->predicate = $this->raw_custom_field['predicate'];
48
+        } else {
49
+            return;
50
+        }
51
+
52
+        // Extract human readable label
53
+        $exploded_predicate = explode( '/', $this->predicate );
54
+        $this->label        = end( $exploded_predicate );
55
+
56
+        // Extract field constraints (numerosity, expected type)
57
+        // Default constaints: accept one string.
58
+        if ( isset( $this->raw_custom_field['type'] ) ) {
59
+            $this->expected_wl_type = $this->raw_custom_field['type'];
60
+        } else {
61
+            $this->expected_wl_type = Wordlift_Schema_Service::DATA_TYPE_STRING;
62
+        }
63
+
64
+        $this->cardinality = 1;
65
+        if ( isset( $this->raw_custom_field['constraints'] ) ) {
66
+
67
+            $constraints = $this->raw_custom_field['constraints'];
68
+
69
+            // Extract cardinality
70
+            if ( isset( $constraints['cardinality'] ) ) {
71
+                $this->cardinality = $constraints['cardinality'];
72
+            }
73
+
74
+            // Which type of entity can we accept (e.g. Place, Event, ecc.)?
75
+            if ( $this->expected_wl_type === Wordlift_Schema_Service::DATA_TYPE_URI && isset( $constraints['uri_type'] ) ) {
76
+                $this->expected_uri_type = is_array( $constraints['uri_type'] ) ? $constraints['uri_type'] : array( $constraints['uri_type'] );
77
+            }
78
+
79
+        }
80
+    }
81
+
82
+    /**
83
+     * Return nonce HTML.
84
+     * Overwrite this method in a child class to obtain custom behaviour.
85
+     */
86
+    public function html_nonce() {
87
+
88
+        return wp_nonce_field( 'wordlift_' . $this->meta_name . '_entity_box', 'wordlift_' . $this->meta_name . '_entity_box_nonce', true, false );
89
+    }
90
+
91
+    /**
92
+     * Verify nonce.
93
+     * Overwrite this method in a child class to obtain custom behaviour.
94
+     *
95
+     * @return boolean Nonce verification
96
+     */
97
+    public function verify_nonce() {
98
+
99
+        $nonce_name   = 'wordlift_' . $this->meta_name . '_entity_box_nonce';
100
+        $nonce_verify = 'wordlift_' . $this->meta_name . '_entity_box';
101
+
102
+        if ( ! isset( $_POST[ $nonce_name ] ) ) {
103
+            return false;
104
+        }
105
+
106
+        // Verify that the nonce is valid.
107
+        return wp_verify_nonce( $_POST[ $nonce_name ], $nonce_verify );
108
+    }
109
+
110
+    /**
111
+     * Load data from DB and store the resulting array in $this->data.
112
+     * Overwrite this method in a child class to obtain custom behaviour.
113
+     */
114
+    public function get_data() {
115
+
116
+        $data = get_post_meta( get_the_ID(), $this->meta_name );
117
+
118
+        // Values are always contained in an array (makes it easier to manage cardinality)
119
+        if ( ! is_array( $data ) ) {
120
+            $data = array( $data );
121
+        }
122
+
123
+        $this->data = $data;
124
+    }
125
+
126
+    /**
127
+     * Sanitizes data before saving to DB. Default sanitization trashes empty values.
128
+     * Stores the sanitized values into $this->data so they can be later processed.
129
+     * Overwrite this method in a child class to obtain custom behaviour.
130
+     *
131
+     * @param array $values Array of values to be sanitized and then stored into $this->data
132
+     *
133
+     */
134
+    public function sanitize_data( $values ) {
135
+
136
+        $sanitized_data = array();
137
+
138
+        if ( ! is_array( $values ) ) {
139
+            $values = array( $values );
140
+        }
141
+
142
+        foreach ( $values as $value ) {
143
+            $sanitized_value = $this->sanitize_data_filter( $value );
144
+            if ( ! is_null( $sanitized_value ) ) {
145
+                $sanitized_data[] = $sanitized_value;
146
+            }
147
+        }
148
+
149
+        $this->data = $sanitized_data;
150
+    }
151
+
152
+    /**
153
+     * Sanitize a single value. Called from $this->sanitize_data. Default sanitization excludes empty values.
154
+     * Overwrite this method in a child class to obtain custom behaviour.
155
+     *
156
+     * @return mixed Returns sanitized value, or null.
157
+     */
158
+    public function sanitize_data_filter( $value ) {
159
+
160
+        if ( ! is_null( $value ) && $value !== '' ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/
161
+            return $value;
162
+        }
163
+
164
+        return null;
165
+    }
166
+
167
+    /**
168
+     * Save data to DB.
169
+     * Overwrite this method in a child class to obtain custom behaviour.
170
+     */
171
+    public function save_data( $values ) {
172
+
173
+        // Will sanitize data and store them in $field->data
174
+        $this->sanitize_data( $values );
175
+
176
+        $entity_id = get_the_ID();
177
+
178
+        // Take away old values
179
+        delete_post_meta( $entity_id, $this->meta_name );
180
+
181
+        // insert new values, respecting cardinality
182
+        $single = ( $this->cardinality == 1 );
183
+        foreach ( $this->data as $value ) {
184
+            add_post_meta( $entity_id, $this->meta_name, $value, $single );
185
+        }
186
+    }
187
+
188
+    /**
189
+     * Returns the HTML tag that will contain the Field. By default the we return a <div> with data- attributes on cardinality and expected types.
190
+     * It is useful to provide data- attributes for the JS scripts.
191
+     * Overwrite this method in a child class to obtain custom behaviour.
192
+     */
193
+    public function html_wrapper_open() {
194
+
195
+        return '<div class="wl-metabox" data-cardinality="' . $this->cardinality . '">';
196
+    }
197
+
198
+    /**
199
+     * Returns Field HTML (nonce included).
200
+     * Overwrite this method (or methods called from this method) in a child class to obtain custom behaviour.
201
+     */
202
+    public function html() {
203
+
204
+        // Open main <div> for the Field
205
+        $html = $this->html_wrapper_open();
206
+
207
+        // Label
208
+        $html .= '<h3>' . $this->label . '</h3>';
209
+
210
+        // print nonce
211
+        $html .= $this->html_nonce();
212
+
213
+        // print data loaded from DB
214
+        $count = 0;
215
+        if ( $this->data ) {
216
+            foreach ( $this->data as $value ) {
217
+                if ( $count < $this->cardinality ) {
218
+                    $html .= $this->html_input( $value );
219
+                }
220
+                $count ++;
221
+            }
222
+        }
223
+
224
+        // Print the empty <input> to add new values
225
+        if ( $count === 0 || $count < $this->cardinality ) {
226
+            $html .= $this->html_input( '' );    // Will print an empty <input>
227
+            $count ++;
228
+        }
229
+
230
+        // If cardiality allows it, print button to add new values.
231
+        if ( $count < $this->cardinality ) {
232
+            $html .= '<button class="button wl-add-input" type="button">Add</button>';
233
+        }
234
+
235
+        // Close the HTML wrapper
236
+        $html .= $this->html_wrapper_close();
237
+
238
+        return $html;
239
+    }
240
+
241
+    /**
242
+     * Return a single <input> tag for the Field.
243
+     *
244
+     * @param mixed $value Input value
245
+     */
246
+    public function html_input( $value ) {
247
+        $html = '<div class="wl-input-wrapper">
248 248
             <input type="text" id="' . $this->meta_name . '" name="wl_metaboxes[' . $this->meta_name . '][]" value="' . $value . '" style="width:88%" />
249 249
             <button class="button wl-remove-input" type="button" style="width:10 % ">Remove</button>
250 250
         </div>';
251 251
 
252
-		return $html;
253
-	}
252
+        return $html;
253
+    }
254 254
 
255
-	/**
256
-	 * Returns closing for the wrapper HTML tag.
257
-	 */
258
-	public function html_wrapper_close() {
255
+    /**
256
+     * Returns closing for the wrapper HTML tag.
257
+     */
258
+    public function html_wrapper_close() {
259 259
 
260
-		return '</div><hr>';
261
-	}
260
+        return '</div><hr>';
261
+    }
262 262
 }
263 263
 
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -28,52 +28,52 @@  discard block
 block discarded – undo
28 28
 	/**
29 29
 	 * Constructor. Recevies.... TODO write docs
30 30
 	 */
31
-	public function __construct( $args ) {
31
+	public function __construct($args) {
32 32
 
33
-		$this->log_service = Wordlift_Log_Service::get_logger( 'WL_Metabox_Field' );
33
+		$this->log_service = Wordlift_Log_Service::get_logger('WL_Metabox_Field');
34 34
 
35
-		if ( empty( $args ) ) {
35
+		if (empty($args)) {
36 36
 			return;
37 37
 		}
38 38
 
39 39
 		// Save a copy of the custom field's params
40
-		$this->raw_custom_field = reset( $args );
40
+		$this->raw_custom_field = reset($args);
41 41
 
42 42
 		// Extract meta name (post_meta key for the DB)
43
-		$this->meta_name = key( $args );
43
+		$this->meta_name = key($args);
44 44
 
45 45
 		// Extract linked data predicate
46
-		if ( isset( $this->raw_custom_field['predicate'] ) ) {
46
+		if (isset($this->raw_custom_field['predicate'])) {
47 47
 			$this->predicate = $this->raw_custom_field['predicate'];
48 48
 		} else {
49 49
 			return;
50 50
 		}
51 51
 
52 52
 		// Extract human readable label
53
-		$exploded_predicate = explode( '/', $this->predicate );
54
-		$this->label        = end( $exploded_predicate );
53
+		$exploded_predicate = explode('/', $this->predicate);
54
+		$this->label        = end($exploded_predicate);
55 55
 
56 56
 		// Extract field constraints (numerosity, expected type)
57 57
 		// Default constaints: accept one string.
58
-		if ( isset( $this->raw_custom_field['type'] ) ) {
58
+		if (isset($this->raw_custom_field['type'])) {
59 59
 			$this->expected_wl_type = $this->raw_custom_field['type'];
60 60
 		} else {
61 61
 			$this->expected_wl_type = Wordlift_Schema_Service::DATA_TYPE_STRING;
62 62
 		}
63 63
 
64 64
 		$this->cardinality = 1;
65
-		if ( isset( $this->raw_custom_field['constraints'] ) ) {
65
+		if (isset($this->raw_custom_field['constraints'])) {
66 66
 
67 67
 			$constraints = $this->raw_custom_field['constraints'];
68 68
 
69 69
 			// Extract cardinality
70
-			if ( isset( $constraints['cardinality'] ) ) {
70
+			if (isset($constraints['cardinality'])) {
71 71
 				$this->cardinality = $constraints['cardinality'];
72 72
 			}
73 73
 
74 74
 			// Which type of entity can we accept (e.g. Place, Event, ecc.)?
75
-			if ( $this->expected_wl_type === Wordlift_Schema_Service::DATA_TYPE_URI && isset( $constraints['uri_type'] ) ) {
76
-				$this->expected_uri_type = is_array( $constraints['uri_type'] ) ? $constraints['uri_type'] : array( $constraints['uri_type'] );
75
+			if ($this->expected_wl_type === Wordlift_Schema_Service::DATA_TYPE_URI && isset($constraints['uri_type'])) {
76
+				$this->expected_uri_type = is_array($constraints['uri_type']) ? $constraints['uri_type'] : array($constraints['uri_type']);
77 77
 			}
78 78
 
79 79
 		}
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	public function html_nonce() {
87 87
 
88
-		return wp_nonce_field( 'wordlift_' . $this->meta_name . '_entity_box', 'wordlift_' . $this->meta_name . '_entity_box_nonce', true, false );
88
+		return wp_nonce_field('wordlift_'.$this->meta_name.'_entity_box', 'wordlift_'.$this->meta_name.'_entity_box_nonce', true, false);
89 89
 	}
90 90
 
91 91
 	/**
@@ -96,15 +96,15 @@  discard block
 block discarded – undo
96 96
 	 */
97 97
 	public function verify_nonce() {
98 98
 
99
-		$nonce_name   = 'wordlift_' . $this->meta_name . '_entity_box_nonce';
100
-		$nonce_verify = 'wordlift_' . $this->meta_name . '_entity_box';
99
+		$nonce_name   = 'wordlift_'.$this->meta_name.'_entity_box_nonce';
100
+		$nonce_verify = 'wordlift_'.$this->meta_name.'_entity_box';
101 101
 
102
-		if ( ! isset( $_POST[ $nonce_name ] ) ) {
102
+		if ( ! isset($_POST[$nonce_name])) {
103 103
 			return false;
104 104
 		}
105 105
 
106 106
 		// Verify that the nonce is valid.
107
-		return wp_verify_nonce( $_POST[ $nonce_name ], $nonce_verify );
107
+		return wp_verify_nonce($_POST[$nonce_name], $nonce_verify);
108 108
 	}
109 109
 
110 110
 	/**
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public function get_data() {
115 115
 
116
-		$data = get_post_meta( get_the_ID(), $this->meta_name );
116
+		$data = get_post_meta(get_the_ID(), $this->meta_name);
117 117
 
118 118
 		// Values are always contained in an array (makes it easier to manage cardinality)
119
-		if ( ! is_array( $data ) ) {
120
-			$data = array( $data );
119
+		if ( ! is_array($data)) {
120
+			$data = array($data);
121 121
 		}
122 122
 
123 123
 		$this->data = $data;
@@ -131,17 +131,17 @@  discard block
 block discarded – undo
131 131
 	 * @param array $values Array of values to be sanitized and then stored into $this->data
132 132
 	 *
133 133
 	 */
134
-	public function sanitize_data( $values ) {
134
+	public function sanitize_data($values) {
135 135
 
136 136
 		$sanitized_data = array();
137 137
 
138
-		if ( ! is_array( $values ) ) {
139
-			$values = array( $values );
138
+		if ( ! is_array($values)) {
139
+			$values = array($values);
140 140
 		}
141 141
 
142
-		foreach ( $values as $value ) {
143
-			$sanitized_value = $this->sanitize_data_filter( $value );
144
-			if ( ! is_null( $sanitized_value ) ) {
142
+		foreach ($values as $value) {
143
+			$sanitized_value = $this->sanitize_data_filter($value);
144
+			if ( ! is_null($sanitized_value)) {
145 145
 				$sanitized_data[] = $sanitized_value;
146 146
 			}
147 147
 		}
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 	 *
156 156
 	 * @return mixed Returns sanitized value, or null.
157 157
 	 */
158
-	public function sanitize_data_filter( $value ) {
158
+	public function sanitize_data_filter($value) {
159 159
 
160
-		if ( ! is_null( $value ) && $value !== '' ) {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/
160
+		if ( ! is_null($value) && $value !== '') {         // do not use 'empty()' -> https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/
161 161
 			return $value;
162 162
 		}
163 163
 
@@ -168,20 +168,20 @@  discard block
 block discarded – undo
168 168
 	 * Save data to DB.
169 169
 	 * Overwrite this method in a child class to obtain custom behaviour.
170 170
 	 */
171
-	public function save_data( $values ) {
171
+	public function save_data($values) {
172 172
 
173 173
 		// Will sanitize data and store them in $field->data
174
-		$this->sanitize_data( $values );
174
+		$this->sanitize_data($values);
175 175
 
176 176
 		$entity_id = get_the_ID();
177 177
 
178 178
 		// Take away old values
179
-		delete_post_meta( $entity_id, $this->meta_name );
179
+		delete_post_meta($entity_id, $this->meta_name);
180 180
 
181 181
 		// insert new values, respecting cardinality
182
-		$single = ( $this->cardinality == 1 );
183
-		foreach ( $this->data as $value ) {
184
-			add_post_meta( $entity_id, $this->meta_name, $value, $single );
182
+		$single = ($this->cardinality == 1);
183
+		foreach ($this->data as $value) {
184
+			add_post_meta($entity_id, $this->meta_name, $value, $single);
185 185
 		}
186 186
 	}
187 187
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	 */
193 193
 	public function html_wrapper_open() {
194 194
 
195
-		return '<div class="wl-metabox" data-cardinality="' . $this->cardinality . '">';
195
+		return '<div class="wl-metabox" data-cardinality="'.$this->cardinality.'">';
196 196
 	}
197 197
 
198 198
 	/**
@@ -205,30 +205,30 @@  discard block
 block discarded – undo
205 205
 		$html = $this->html_wrapper_open();
206 206
 
207 207
 		// Label
208
-		$html .= '<h3>' . $this->label . '</h3>';
208
+		$html .= '<h3>'.$this->label.'</h3>';
209 209
 
210 210
 		// print nonce
211 211
 		$html .= $this->html_nonce();
212 212
 
213 213
 		// print data loaded from DB
214 214
 		$count = 0;
215
-		if ( $this->data ) {
216
-			foreach ( $this->data as $value ) {
217
-				if ( $count < $this->cardinality ) {
218
-					$html .= $this->html_input( $value );
215
+		if ($this->data) {
216
+			foreach ($this->data as $value) {
217
+				if ($count < $this->cardinality) {
218
+					$html .= $this->html_input($value);
219 219
 				}
220
-				$count ++;
220
+				$count++;
221 221
 			}
222 222
 		}
223 223
 
224 224
 		// Print the empty <input> to add new values
225
-		if ( $count === 0 || $count < $this->cardinality ) {
226
-			$html .= $this->html_input( '' );    // Will print an empty <input>
227
-			$count ++;
225
+		if ($count === 0 || $count < $this->cardinality) {
226
+			$html .= $this->html_input(''); // Will print an empty <input>
227
+			$count++;
228 228
 		}
229 229
 
230 230
 		// If cardiality allows it, print button to add new values.
231
-		if ( $count < $this->cardinality ) {
231
+		if ($count < $this->cardinality) {
232 232
 			$html .= '<button class="button wl-add-input" type="button">Add</button>';
233 233
 		}
234 234
 
@@ -243,9 +243,9 @@  discard block
 block discarded – undo
243 243
 	 *
244 244
 	 * @param mixed $value Input value
245 245
 	 */
246
-	public function html_input( $value ) {
246
+	public function html_input($value) {
247 247
 		$html = '<div class="wl-input-wrapper">
248
-            <input type="text" id="' . $this->meta_name . '" name="wl_metaboxes[' . $this->meta_name . '][]" value="' . $value . '" style="width:88%" />
248
+            <input type="text" id="' . $this->meta_name.'" name="wl_metaboxes['.$this->meta_name.'][]" value="'.$value.'" style="width:88%" />
249 249
             <button class="button wl-remove-input" type="button" style="width:10 % ">Remove</button>
250 250
         </div>';
251 251
 
Please login to merge, or discard this patch.