Completed
Push — develop ( f65bd6...158ffc )
by David
08:55
created
src/modules/core/wordlift_core_schema_api.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@
 block discarded – undo
122 122
  * @param int   $post_id    The numeric post ID
123 123
  * @param array $type_names An array of strings, each defining a type (e.g. Type, for the http://schema.org/Type)
124 124
  *
125
- * @return boolean True if everything went ok, an error string otherwise.
125
+ * @return boolean|null True if everything went ok, an error string otherwise.
126 126
  */
127 127
 function wl_schema_set_types( $post_id, $type_names ) {
128 128
 
Please login to merge, or discard this patch.
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -17,34 +17,34 @@  discard block
 block discarded – undo
17 17
  */
18 18
 function wl_schema_get_value( $post_id, $property_name ) {
19 19
 
20
-	// Property name must be defined.
21
-	if ( ! isset( $property_name ) || is_null( $property_name ) ) {
22
-		return null;
23
-	}
24
-
25
-	// store eventual schema name in  different variable
26
-	$property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
27
-
28
-	// Establish entity id.
29
-	if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
30
-		$post_id = get_the_ID();
31
-		if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
32
-			return null;
33
-		}
34
-	}
35
-
36
-	// Get custom fields.
37
-	$term_mapping = wl_entity_taxonomy_get_custom_fields( $post_id );
38
-	// Search for the required meta value (by constant name or schema name)
39
-	foreach ( $term_mapping as $wl_constant => $property_info ) {
40
-		$found_constant  = ( $wl_constant == $property_name );
41
-		$found_predicate = ( isset( $property_info['predicate'] ) && $property_info['predicate'] == $property_schema_name );
42
-		if ( $found_constant || $found_predicate ) {
43
-			return get_post_meta( $post_id, $wl_constant );
44
-		}
45
-	}
46
-
47
-	return null;
20
+    // Property name must be defined.
21
+    if ( ! isset( $property_name ) || is_null( $property_name ) ) {
22
+        return null;
23
+    }
24
+
25
+    // store eventual schema name in  different variable
26
+    $property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
27
+
28
+    // Establish entity id.
29
+    if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
30
+        $post_id = get_the_ID();
31
+        if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
32
+            return null;
33
+        }
34
+    }
35
+
36
+    // Get custom fields.
37
+    $term_mapping = wl_entity_taxonomy_get_custom_fields( $post_id );
38
+    // Search for the required meta value (by constant name or schema name)
39
+    foreach ( $term_mapping as $wl_constant => $property_info ) {
40
+        $found_constant  = ( $wl_constant == $property_name );
41
+        $found_predicate = ( isset( $property_info['predicate'] ) && $property_info['predicate'] == $property_schema_name );
42
+        if ( $found_constant || $found_predicate ) {
43
+            return get_post_meta( $post_id, $wl_constant );
44
+        }
45
+    }
46
+
47
+    return null;
48 48
 }
49 49
 
50 50
 /**
@@ -58,38 +58,38 @@  discard block
 block discarded – undo
58 58
  */
59 59
 function wl_schema_set_value( $post_id, $property_name, $property_value ) {
60 60
 
61
-	// Some checks on the parameters
62
-	if ( ! is_numeric( $post_id ) || is_null( $property_name ) || empty( $property_value ) || is_null( $property_value ) ) {
63
-		return false;
64
-	}
61
+    // Some checks on the parameters
62
+    if ( ! is_numeric( $post_id ) || is_null( $property_name ) || empty( $property_value ) || is_null( $property_value ) ) {
63
+        return false;
64
+    }
65 65
 
66
-	// Build full schema uri if necessary
67
-	$property_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
66
+    // Build full schema uri if necessary
67
+    $property_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
68 68
 
69
-	// Get accepted properties
70
-	$accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id );
69
+    // Get accepted properties
70
+    $accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id );
71 71
 
72
-	// Find the name of the custom-field managing the schema property
73
-	foreach ( $accepted_fields as $wl_constant => $field ) {
74
-		if ( $field['predicate'] == $property_name ) {
72
+    // Find the name of the custom-field managing the schema property
73
+    foreach ( $accepted_fields as $wl_constant => $field ) {
74
+        if ( $field['predicate'] == $property_name ) {
75 75
 
76
-			// Deal with single values
77
-			if ( ! is_array( $property_value ) ) {
78
-				$property_value = array( $property_value );
79
-			}
76
+            // Deal with single values
77
+            if ( ! is_array( $property_value ) ) {
78
+                $property_value = array( $property_value );
79
+            }
80 80
 
81
-			// Delete present meta
82
-			delete_post_meta( $post_id, $wl_constant );
81
+            // Delete present meta
82
+            delete_post_meta( $post_id, $wl_constant );
83 83
 
84
-			foreach ( $property_value as $value ) {
85
-				add_post_meta( $post_id, $wl_constant, $value );
86
-			}
84
+            foreach ( $property_value as $value ) {
85
+                add_post_meta( $post_id, $wl_constant, $value );
86
+            }
87 87
 
88
-			return true;
89
-		}
90
-	}
88
+            return true;
89
+        }
90
+    }
91 91
 
92
-	return false;
92
+    return false;
93 93
 }
94 94
 
95 95
 /**
@@ -102,18 +102,18 @@  discard block
 block discarded – undo
102 102
  */
103 103
 function wl_schema_get_types( $post_id ) {
104 104
 
105
-	// Some checks on the parameters
106
-	if ( ! is_numeric( $post_id ) ) {
107
-		return null;
108
-	}
105
+    // Some checks on the parameters
106
+    if ( ! is_numeric( $post_id ) ) {
107
+        return null;
108
+    }
109 109
 
110
-	$type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
110
+    $type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
111 111
 
112
-	if ( isset( $type['uri'] ) ) {
113
-		return array( $type['uri'] );
114
-	}
112
+    if ( isset( $type['uri'] ) ) {
113
+        return array( $type['uri'] );
114
+    }
115 115
 
116
-	return null;
116
+    return null;
117 117
 }
118 118
 
119 119
 /**
@@ -126,21 +126,21 @@  discard block
 block discarded – undo
126 126
  */
127 127
 function wl_schema_set_types( $post_id, $type_names ) {
128 128
 
129
-	// Some checks on the parameters
130
-	if ( ! is_numeric( $post_id ) || empty( $type_names ) || is_null( $type_names ) ) {
131
-		return null;
132
-	}
129
+    // Some checks on the parameters
130
+    if ( ! is_numeric( $post_id ) || empty( $type_names ) || is_null( $type_names ) ) {
131
+        return null;
132
+    }
133 133
 
134
-	// TODO: support more than one type.
135
-	if ( is_array( $type_names ) ) {
136
-		$type_names = $type_names[0];
137
-	}
134
+    // TODO: support more than one type.
135
+    if ( is_array( $type_names ) ) {
136
+        $type_names = $type_names[0];
137
+    }
138 138
 
139
-	// Get the schema URI (e.g. http://schema.org/Thing)
140
-	$type_names = wl_build_full_schema_uri_from_schema_slug( $type_names );
139
+    // Get the schema URI (e.g. http://schema.org/Thing)
140
+    $type_names = wl_build_full_schema_uri_from_schema_slug( $type_names );
141 141
 
142
-	// Actually sets the taxonomy type
143
-	wl_set_entity_main_type( $post_id, $type_names );
142
+    // Actually sets the taxonomy type
143
+    wl_set_entity_main_type( $post_id, $type_names );
144 144
 
145 145
 }
146 146
 
@@ -153,11 +153,11 @@  discard block
 block discarded – undo
153 153
  */
154 154
 function wl_build_full_schema_uri_from_schema_slug( $schema_name ) {
155 155
 
156
-	$schema_root_address = 'http://schema.org/';
156
+    $schema_root_address = 'http://schema.org/';
157 157
 
158
-	if ( strpos( $schema_name, $schema_root_address ) === false ) {   // === necessary
159
-		$schema_name = $schema_root_address . $schema_name;
160
-	}
158
+    if ( strpos( $schema_name, $schema_root_address ) === false ) {   // === necessary
159
+        $schema_name = $schema_root_address . $schema_name;
160
+    }
161 161
 
162
-	return $schema_name;
162
+    return $schema_name;
163 163
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -15,32 +15,32 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @return array|null An array of values or NULL in case of no values (or error).
17 17
  */
18
-function wl_schema_get_value( $post_id, $property_name ) {
18
+function wl_schema_get_value($post_id, $property_name) {
19 19
 
20 20
 	// Property name must be defined.
21
-	if ( ! isset( $property_name ) || is_null( $property_name ) ) {
21
+	if ( ! isset($property_name) || is_null($property_name)) {
22 22
 		return null;
23 23
 	}
24 24
 
25 25
 	// store eventual schema name in  different variable
26
-	$property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
26
+	$property_schema_name = wl_build_full_schema_uri_from_schema_slug($property_name);
27 27
 
28 28
 	// Establish entity id.
29
-	if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
29
+	if (is_null($post_id) || ! is_numeric($post_id)) {
30 30
 		$post_id = get_the_ID();
31
-		if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
31
+		if (is_null($post_id) || ! is_numeric($post_id)) {
32 32
 			return null;
33 33
 		}
34 34
 	}
35 35
 
36 36
 	// Get custom fields.
37
-	$term_mapping = wl_entity_taxonomy_get_custom_fields( $post_id );
37
+	$term_mapping = wl_entity_taxonomy_get_custom_fields($post_id);
38 38
 	// Search for the required meta value (by constant name or schema name)
39
-	foreach ( $term_mapping as $wl_constant => $property_info ) {
40
-		$found_constant  = ( $wl_constant == $property_name );
41
-		$found_predicate = ( isset( $property_info['predicate'] ) && $property_info['predicate'] == $property_schema_name );
42
-		if ( $found_constant || $found_predicate ) {
43
-			return get_post_meta( $post_id, $wl_constant );
39
+	foreach ($term_mapping as $wl_constant => $property_info) {
40
+		$found_constant  = ($wl_constant == $property_name);
41
+		$found_predicate = (isset($property_info['predicate']) && $property_info['predicate'] == $property_schema_name);
42
+		if ($found_constant || $found_predicate) {
43
+			return get_post_meta($post_id, $wl_constant);
44 44
 		}
45 45
 	}
46 46
 
@@ -56,33 +56,33 @@  discard block
 block discarded – undo
56 56
  *
57 57
  * @return boolean The method returns true if everything went ok, an error string otherwise.
58 58
  */
59
-function wl_schema_set_value( $post_id, $property_name, $property_value ) {
59
+function wl_schema_set_value($post_id, $property_name, $property_value) {
60 60
 
61 61
 	// Some checks on the parameters
62
-	if ( ! is_numeric( $post_id ) || is_null( $property_name ) || empty( $property_value ) || is_null( $property_value ) ) {
62
+	if ( ! is_numeric($post_id) || is_null($property_name) || empty($property_value) || is_null($property_value)) {
63 63
 		return false;
64 64
 	}
65 65
 
66 66
 	// Build full schema uri if necessary
67
-	$property_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
67
+	$property_name = wl_build_full_schema_uri_from_schema_slug($property_name);
68 68
 
69 69
 	// Get accepted properties
70
-	$accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id );
70
+	$accepted_fields = wl_entity_taxonomy_get_custom_fields($post_id);
71 71
 
72 72
 	// Find the name of the custom-field managing the schema property
73
-	foreach ( $accepted_fields as $wl_constant => $field ) {
74
-		if ( $field['predicate'] == $property_name ) {
73
+	foreach ($accepted_fields as $wl_constant => $field) {
74
+		if ($field['predicate'] == $property_name) {
75 75
 
76 76
 			// Deal with single values
77
-			if ( ! is_array( $property_value ) ) {
78
-				$property_value = array( $property_value );
77
+			if ( ! is_array($property_value)) {
78
+				$property_value = array($property_value);
79 79
 			}
80 80
 
81 81
 			// Delete present meta
82
-			delete_post_meta( $post_id, $wl_constant );
82
+			delete_post_meta($post_id, $wl_constant);
83 83
 
84
-			foreach ( $property_value as $value ) {
85
-				add_post_meta( $post_id, $wl_constant, $value );
84
+			foreach ($property_value as $value) {
85
+				add_post_meta($post_id, $wl_constant, $value);
86 86
 			}
87 87
 
88 88
 			return true;
@@ -100,17 +100,17 @@  discard block
 block discarded – undo
100 100
  * @return array Array of type(s) (e.g. Type, for the http://schema.org/Type)
101 101
  *               or NULL in case of no values (or error).
102 102
  */
103
-function wl_schema_get_types( $post_id ) {
103
+function wl_schema_get_types($post_id) {
104 104
 
105 105
 	// Some checks on the parameters
106
-	if ( ! is_numeric( $post_id ) ) {
106
+	if ( ! is_numeric($post_id)) {
107 107
 		return null;
108 108
 	}
109 109
 
110
-	$type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
110
+	$type = Wordlift_Entity_Type_Service::get_instance()->get($post_id);
111 111
 
112
-	if ( isset( $type['uri'] ) ) {
113
-		return array( $type['uri'] );
112
+	if (isset($type['uri'])) {
113
+		return array($type['uri']);
114 114
 	}
115 115
 
116 116
 	return null;
@@ -124,23 +124,23 @@  discard block
 block discarded – undo
124 124
  *
125 125
  * @return boolean True if everything went ok, an error string otherwise.
126 126
  */
127
-function wl_schema_set_types( $post_id, $type_names ) {
127
+function wl_schema_set_types($post_id, $type_names) {
128 128
 
129 129
 	// Some checks on the parameters
130
-	if ( ! is_numeric( $post_id ) || empty( $type_names ) || is_null( $type_names ) ) {
130
+	if ( ! is_numeric($post_id) || empty($type_names) || is_null($type_names)) {
131 131
 		return null;
132 132
 	}
133 133
 
134 134
 	// TODO: support more than one type.
135
-	if ( is_array( $type_names ) ) {
135
+	if (is_array($type_names)) {
136 136
 		$type_names = $type_names[0];
137 137
 	}
138 138
 
139 139
 	// Get the schema URI (e.g. http://schema.org/Thing)
140
-	$type_names = wl_build_full_schema_uri_from_schema_slug( $type_names );
140
+	$type_names = wl_build_full_schema_uri_from_schema_slug($type_names);
141 141
 
142 142
 	// Actually sets the taxonomy type
143
-	wl_set_entity_main_type( $post_id, $type_names );
143
+	wl_set_entity_main_type($post_id, $type_names);
144 144
 
145 145
 }
146 146
 
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
  *
152 152
  * @return string The full schema uri (es. 'latitude' returns 'http://schema.org/latitude')
153 153
  */
154
-function wl_build_full_schema_uri_from_schema_slug( $schema_name ) {
154
+function wl_build_full_schema_uri_from_schema_slug($schema_name) {
155 155
 
156 156
 	$schema_root_address = 'http://schema.org/';
157 157
 
158
-	if ( strpos( $schema_name, $schema_root_address ) === false ) {   // === necessary
159
-		$schema_name = $schema_root_address . $schema_name;
158
+	if (strpos($schema_name, $schema_root_address) === false) {   // === necessary
159
+		$schema_name = $schema_root_address.$schema_name;
160 160
 	}
161 161
 
162 162
 	return $schema_name;
Please login to merge, or discard this patch.
src/wordlift_redlink.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -19,57 +19,57 @@
 block discarded – undo
19 19
  */
20 20
 function rl_execute_sparql_update_query( $query, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) {
21 21
 
22
-	$log = Wordlift_Log_Service::get_logger( 'rl_execute_sparql_update_query' );
22
+    $log = Wordlift_Log_Service::get_logger( 'rl_execute_sparql_update_query' );
23 23
 
24
-	if ( get_transient( 'DISABLE_ENTITY_PUSH' ) ) {
25
-		return true;
26
-	}
24
+    if ( get_transient( 'DISABLE_ENTITY_PUSH' ) ) {
25
+        return true;
26
+    }
27 27
 
28
-	// Queue the update query.
29
-	if ( $queue ) {
30
-		$log->debug( 'Queueing query...' );
28
+    // Queue the update query.
29
+    if ( $queue ) {
30
+        $log->debug( 'Queueing query...' );
31 31
 
32
-		Wordlift_Sparql_Service::get_instance()->queue( $query );
32
+        Wordlift_Sparql_Service::get_instance()->queue( $query );
33 33
 
34
-		return true;
35
-	}
34
+        return true;
35
+    }
36 36
 
37
-	// Get the update end-point.
38
-	$url = wl_configuration_get_query_update_url();
37
+    // Get the update end-point.
38
+    $url = wl_configuration_get_query_update_url();
39 39
 
40
-	// Prepare the request.
41
-	$args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array(
42
-		'method'  => 'POST',
43
-		'headers' => array(
44
-			'Accept'       => 'application/json',
45
-			'Content-type' => 'application/sparql-update; charset=utf-8',
46
-		),
47
-		'body'    => $query,
48
-	) );
40
+    // Prepare the request.
41
+    $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array(
42
+        'method'  => 'POST',
43
+        'headers' => array(
44
+            'Accept'       => 'application/json',
45
+            'Content-type' => 'application/sparql-update; charset=utf-8',
46
+        ),
47
+        'body'    => $query,
48
+    ) );
49 49
 
50
-	// Send the request.
51
-	$response = wp_remote_post( $url, $args );
50
+    // Send the request.
51
+    $response = wp_remote_post( $url, $args );
52 52
 
53
-	// If an error has been raised, return the error.
54
-	if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) {
53
+    // If an error has been raised, return the error.
54
+    if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) {
55 55
 
56
-		$body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] );
56
+        $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] );
57 57
 
58
-		$log->debug( "rl_execute_sparql_update_query : error [ url :: $url ][ args :: " );
59
-		$log->debug( "\n" . var_export( $args, true ) );
60
-		$log->debug( "[ response :: " );
61
-		$log->debug( "\n" . var_export( $response, true ) );
62
-		$log->debug( "][ body :: " );
63
-		$log->debug( "\n" . $body );
64
-		$log->debug( "]" );
58
+        $log->debug( "rl_execute_sparql_update_query : error [ url :: $url ][ args :: " );
59
+        $log->debug( "\n" . var_export( $args, true ) );
60
+        $log->debug( "[ response :: " );
61
+        $log->debug( "\n" . var_export( $response, true ) );
62
+        $log->debug( "][ body :: " );
63
+        $log->debug( "\n" . $body );
64
+        $log->debug( "]" );
65 65
 
66
-		return false;
67
-	}
66
+        return false;
67
+    }
68 68
 
69
-	if ( WP_DEBUG ) {
70
-		global $wl_logger;
71
-		$wl_logger->trace( "Query executed successfully [ query :: $query ]" );
72
-	}
69
+    if ( WP_DEBUG ) {
70
+        global $wl_logger;
71
+        $wl_logger->trace( "Query executed successfully [ query :: $query ]" );
72
+    }
73 73
 
74
-	return true;
74
+    return true;
75 75
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -17,19 +17,19 @@  discard block
 block discarded – undo
17 17
  *
18 18
  * @return bool True if successful otherwise false.
19 19
  */
20
-function rl_execute_sparql_update_query( $query, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) {
20
+function rl_execute_sparql_update_query($query, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING) {
21 21
 
22
-	$log = Wordlift_Log_Service::get_logger( 'rl_execute_sparql_update_query' );
22
+	$log = Wordlift_Log_Service::get_logger('rl_execute_sparql_update_query');
23 23
 
24
-	if ( get_transient( 'DISABLE_ENTITY_PUSH' ) ) {
24
+	if (get_transient('DISABLE_ENTITY_PUSH')) {
25 25
 		return true;
26 26
 	}
27 27
 
28 28
 	// Queue the update query.
29
-	if ( $queue ) {
30
-		$log->debug( 'Queueing query...' );
29
+	if ($queue) {
30
+		$log->debug('Queueing query...');
31 31
 
32
-		Wordlift_Sparql_Service::get_instance()->queue( $query );
32
+		Wordlift_Sparql_Service::get_instance()->queue($query);
33 33
 
34 34
 		return true;
35 35
 	}
@@ -38,37 +38,37 @@  discard block
 block discarded – undo
38 38
 	$url = wl_configuration_get_query_update_url();
39 39
 
40 40
 	// Prepare the request.
41
-	$args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array(
41
+	$args = array_merge_recursive(unserialize(WL_REDLINK_API_HTTP_OPTIONS), array(
42 42
 		'method'  => 'POST',
43 43
 		'headers' => array(
44 44
 			'Accept'       => 'application/json',
45 45
 			'Content-type' => 'application/sparql-update; charset=utf-8',
46 46
 		),
47 47
 		'body'    => $query,
48
-	) );
48
+	));
49 49
 
50 50
 	// Send the request.
51
-	$response = wp_remote_post( $url, $args );
51
+	$response = wp_remote_post($url, $args);
52 52
 
53 53
 	// If an error has been raised, return the error.
54
-	if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) {
54
+	if (is_wp_error($response) || 200 !== (int) $response['response']['code']) {
55 55
 
56
-		$body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] );
56
+		$body = (is_wp_error($response) ? $response->get_error_message() : $response['body']);
57 57
 
58
-		$log->debug( "rl_execute_sparql_update_query : error [ url :: $url ][ args :: " );
59
-		$log->debug( "\n" . var_export( $args, true ) );
60
-		$log->debug( "[ response :: " );
61
-		$log->debug( "\n" . var_export( $response, true ) );
62
-		$log->debug( "][ body :: " );
63
-		$log->debug( "\n" . $body );
64
-		$log->debug( "]" );
58
+		$log->debug("rl_execute_sparql_update_query : error [ url :: $url ][ args :: ");
59
+		$log->debug("\n".var_export($args, true));
60
+		$log->debug("[ response :: ");
61
+		$log->debug("\n".var_export($response, true));
62
+		$log->debug("][ body :: ");
63
+		$log->debug("\n".$body);
64
+		$log->debug("]");
65 65
 
66 66
 		return false;
67 67
 	}
68 68
 
69
-	if ( WP_DEBUG ) {
69
+	if (WP_DEBUG) {
70 70
 		global $wl_logger;
71
-		$wl_logger->trace( "Query executed successfully [ query :: $query ]" );
71
+		$wl_logger->trace("Query executed successfully [ query :: $query ]");
72 72
 	}
73 73
 
74 74
 	return true;
Please login to merge, or discard this patch.
src/modules/core/wordlift_core_install.php 2 patches
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -12,93 +12,93 @@  discard block
 block discarded – undo
12 12
  */
13 13
 function wl_core_install_entity_type_data() {
14 14
 
15
-	Wordlift_Log_Service::get_instance()->debug( 'Installing Entity Type data...' );
16
-
17
-	// Set the taxonomy data.
18
-	// Note: parent types must be defined before child types.
19
-	$terms = array(
20
-		'thing'         => array(
21
-			'label'       => 'Thing',
22
-			'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
23
-		),
24
-		'creative-work' => array(
25
-			'label'       => 'CreativeWork',
26
-			'description' => 'A creative work (or a Music Album).',
27
-		),
28
-		'event'         => array(
29
-			'label'       => 'Event',
30
-			'description' => 'An event.',
31
-		),
32
-		'organization'  => array(
33
-			'label'       => 'Organization',
34
-			'description' => 'An organization, including a government or a newspaper.',
35
-		),
36
-		'person'        => array(
37
-			'label'       => 'Person',
38
-			'description' => 'A person (or a music artist).',
39
-		),
40
-		'place'         => array(
41
-			'label'       => 'Place',
42
-			'description' => 'A place.',
43
-		),
44
-		'localbusiness' => array(
45
-			'label'       => 'LocalBusiness',
46
-			'description' => 'A local business.',
47
-		),
48
-	);
49
-
50
-	foreach ( $terms as $slug => $term ) {
51
-
52
-		// Create the term if it does not exist, then get its ID
53
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
54
-
55
-		if ( 0 == $term_id || is_null( $term_id ) ) {
56
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
57
-		} else {
58
-			$term_id = $term_id['term_id'];
59
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
60
-		}
61
-
62
-		// Check for errors.
63
-		if ( is_wp_error( $result ) ) {
64
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
65
-			continue;
66
-		}
67
-
68
-		// Check if 'parent' corresponds to an actual term and get its ID.
69
-		if ( ! isset( $term['parents'] ) ) {
70
-			$term['parents'] = array();
71
-		}
72
-
73
-		$parent_ids = array();
74
-		foreach ( $term['parents'] as $parent_slug ) {
75
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
76
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
77
-		}
78
-
79
-		// Define a parent in the WP taxonomy style (not important for WL)
80
-		if ( empty( $parent_ids ) ) {
81
-			// No parent
82
-			$parent_id = 0;
83
-		} else {
84
-			// Get first parent
85
-			$parent_id = $parent_ids[0];
86
-		}
87
-
88
-		// Update term with description, slug and parent
89
-		$term = wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
90
-			'name'        => $term['label'],
91
-			'slug'        => $slug,
92
-			'description' => $term['description'],
93
-			// We give to WP taxonomy just one parent. TODO: see if can give more than one
94
-			'parent'      => $parent_id,
95
-		) );
96
-
97
-		Wordlift_Log_Service::get_instance()->trace( "Entity Type $slug installed with ID {$term['term_id']}." );
98
-
99
-	}
100
-
101
-	Wordlift_Log_Service::get_instance()->debug( 'Entity Type data installed.' );
15
+    Wordlift_Log_Service::get_instance()->debug( 'Installing Entity Type data...' );
16
+
17
+    // Set the taxonomy data.
18
+    // Note: parent types must be defined before child types.
19
+    $terms = array(
20
+        'thing'         => array(
21
+            'label'       => 'Thing',
22
+            'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
23
+        ),
24
+        'creative-work' => array(
25
+            'label'       => 'CreativeWork',
26
+            'description' => 'A creative work (or a Music Album).',
27
+        ),
28
+        'event'         => array(
29
+            'label'       => 'Event',
30
+            'description' => 'An event.',
31
+        ),
32
+        'organization'  => array(
33
+            'label'       => 'Organization',
34
+            'description' => 'An organization, including a government or a newspaper.',
35
+        ),
36
+        'person'        => array(
37
+            'label'       => 'Person',
38
+            'description' => 'A person (or a music artist).',
39
+        ),
40
+        'place'         => array(
41
+            'label'       => 'Place',
42
+            'description' => 'A place.',
43
+        ),
44
+        'localbusiness' => array(
45
+            'label'       => 'LocalBusiness',
46
+            'description' => 'A local business.',
47
+        ),
48
+    );
49
+
50
+    foreach ( $terms as $slug => $term ) {
51
+
52
+        // Create the term if it does not exist, then get its ID
53
+        $term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
54
+
55
+        if ( 0 == $term_id || is_null( $term_id ) ) {
56
+            $result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
57
+        } else {
58
+            $term_id = $term_id['term_id'];
59
+            $result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
60
+        }
61
+
62
+        // Check for errors.
63
+        if ( is_wp_error( $result ) ) {
64
+            wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
65
+            continue;
66
+        }
67
+
68
+        // Check if 'parent' corresponds to an actual term and get its ID.
69
+        if ( ! isset( $term['parents'] ) ) {
70
+            $term['parents'] = array();
71
+        }
72
+
73
+        $parent_ids = array();
74
+        foreach ( $term['parents'] as $parent_slug ) {
75
+            $parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
76
+            $parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
77
+        }
78
+
79
+        // Define a parent in the WP taxonomy style (not important for WL)
80
+        if ( empty( $parent_ids ) ) {
81
+            // No parent
82
+            $parent_id = 0;
83
+        } else {
84
+            // Get first parent
85
+            $parent_id = $parent_ids[0];
86
+        }
87
+
88
+        // Update term with description, slug and parent
89
+        $term = wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
90
+            'name'        => $term['label'],
91
+            'slug'        => $slug,
92
+            'description' => $term['description'],
93
+            // We give to WP taxonomy just one parent. TODO: see if can give more than one
94
+            'parent'      => $parent_id,
95
+        ) );
96
+
97
+        Wordlift_Log_Service::get_instance()->trace( "Entity Type $slug installed with ID {$term['term_id']}." );
98
+
99
+    }
100
+
101
+    Wordlift_Log_Service::get_instance()->debug( 'Entity Type data installed.' );
102 102
 
103 103
 }
104 104
 
@@ -107,16 +107,16 @@  discard block
 block discarded – undo
107 107
  */
108 108
 function wl_core_install_create_relation_instance_table() {
109 109
 
110
-	global $wpdb;
111
-	// global $wl_db_version;
112
-	$installed_version = get_option( 'wl_db_version' );
110
+    global $wpdb;
111
+    // global $wl_db_version;
112
+    $installed_version = get_option( 'wl_db_version' );
113 113
 
114
-	if ( WL_DB_VERSION != $installed_version ) {
115
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
116
-		$charset_collate = $wpdb->get_charset_collate();
114
+    if ( WL_DB_VERSION != $installed_version ) {
115
+        $table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
116
+        $charset_collate = $wpdb->get_charset_collate();
117 117
 
118
-		// Sql statement for the relation instances custom table
119
-		$sql = <<<EOF
118
+        // Sql statement for the relation instances custom table
119
+        $sql = <<<EOF
120 120
 			CREATE TABLE $table_name (
121 121
   				id int(11) NOT NULL AUTO_INCREMENT,
122 122
   				subject_id int(11) NOT NULL,
@@ -128,14 +128,14 @@  discard block
 block discarded – undo
128 128
 			) $charset_collate;
129 129
 EOF;
130 130
 
131
-		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
132
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
133
-		$results = dbDelta( $sql );
131
+        // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
132
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
133
+        $results = dbDelta( $sql );
134 134
 
135
-		wl_write_log( $results );
135
+        wl_write_log( $results );
136 136
 
137
-		update_option( 'wl_db_version', WL_DB_VERSION );
138
-	}
137
+        update_option( 'wl_db_version', WL_DB_VERSION );
138
+    }
139 139
 }
140 140
 
141 141
 /**
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
  */
147 147
 function wl_core_upgrade_db_to_1_0() {
148 148
 
149
-	if ( ! get_option( 'wl_db_version' ) ) {
150
-		wl_core_install_create_relation_instance_table();
151
-	}
149
+    if ( ! get_option( 'wl_db_version' ) ) {
150
+        wl_core_install_create_relation_instance_table();
151
+    }
152 152
 
153 153
 }
154 154
 
@@ -161,31 +161,31 @@  discard block
 block discarded – undo
161 161
  */
162 162
 function wl_core_upgrade_db_1_0_to_3_10() {
163 163
 
164
-	// If the DB version is less than 3.10, than flatten the txonomy.
165
-	if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
164
+    // If the DB version is less than 3.10, than flatten the txonomy.
165
+    if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
166 166
 
167
-		$term_slugs = array(
168
-			'thing',
169
-			'creative-work',
170
-			'event',
171
-			'organization',
172
-			'person',
173
-			'place',
174
-			'localbusiness',
175
-		);
167
+        $term_slugs = array(
168
+            'thing',
169
+            'creative-work',
170
+            'event',
171
+            'organization',
172
+            'person',
173
+            'place',
174
+            'localbusiness',
175
+        );
176 176
 
177
-		foreach ( $term_slugs as $slug ) {
177
+        foreach ( $term_slugs as $slug ) {
178 178
 
179
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
179
+            $term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
180 180
 
181
-			// Set the term's parent to 0.
182
-			if ( $term ) {
183
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
184
-					'parent' => 0,
185
-				) );
186
-			}
187
-		}
188
-	}
181
+            // Set the term's parent to 0.
182
+            if ( $term ) {
183
+                wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
184
+                    'parent' => 0,
185
+                ) );
186
+            }
187
+        }
188
+    }
189 189
 
190 190
 }
191 191
 
@@ -198,14 +198,14 @@  discard block
 block discarded – undo
198 198
  * @since 3.12.0
199 199
  */
200 200
 function wl_core_upgrade_db_3_10_3_12() {
201
-	/*
201
+    /*
202 202
 	 * As this upgrade functionality runs on the init hook, and the AMP plugin
203 203
 	 * initialization does the same, avoid possible race conditions by
204 204
 	 * deferring the actual flush to a later hook.
205 205
 	 */
206
-	add_action( 'wp_loaded', function () {
207
-		flush_rewrite_rules();
208
-	} );
206
+    add_action( 'wp_loaded', function () {
207
+        flush_rewrite_rules();
208
+    } );
209 209
 }
210 210
 
211 211
 /**
@@ -216,42 +216,42 @@  discard block
 block discarded – undo
216 216
  * @since 3.14.0
217 217
  */
218 218
 function wl_core_upgrade_db_3_12_3_14() {
219
-	$result = wp_insert_term(
220
-		'Recipe',
221
-		Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
222
-		array(
223
-			'slug'        => 'recipe',
224
-			'description' => 'A Recipe.',
225
-		)
226
-	);
227
-
228
-	// Assign capabilities to manipulate entities to admins.
229
-	$admins = get_role( 'administrator' );
230
-
231
-	$admins->add_cap( 'edit_wordlift_entity' );
232
-	$admins->add_cap( 'edit_wordlift_entities' );
233
-	$admins->add_cap( 'edit_others_wordlift_entities' );
234
-	$admins->add_cap( 'publish_wordlift_entities' );
235
-	$admins->add_cap( 'read_private_wordlift_entities' );
236
-	$admins->add_cap( 'delete_wordlift_entity' );
237
-	$admins->add_cap( 'delete_wordlift_entities' );
238
-	$admins->add_cap( 'delete_others_wordlift_entities' );
239
-	$admins->add_cap( 'delete_published_wordlift_entities' );
240
-	$admins->add_cap( 'delete_private_wordlift_entities' );
241
-
242
-	// Assign capabilities to manipulate entities to editors.
243
-	$editors = get_role( 'editor' );
244
-
245
-	$editors->add_cap( 'edit_wordlift_entity' );
246
-	$editors->add_cap( 'edit_wordlift_entities' );
247
-	$editors->add_cap( 'edit_others_wordlift_entities' );
248
-	$editors->add_cap( 'publish_wordlift_entities' );
249
-	$editors->add_cap( 'read_private_wordlift_entities' );
250
-	$editors->add_cap( 'delete_wordlift_entity' );
251
-	$editors->add_cap( 'delete_wordlift_entities' );
252
-	$editors->add_cap( 'delete_others_wordlift_entities' );
253
-	$editors->add_cap( 'delete_published_wordlift_entities' );
254
-	$editors->add_cap( 'delete_private_wordlift_entities' );
219
+    $result = wp_insert_term(
220
+        'Recipe',
221
+        Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
222
+        array(
223
+            'slug'        => 'recipe',
224
+            'description' => 'A Recipe.',
225
+        )
226
+    );
227
+
228
+    // Assign capabilities to manipulate entities to admins.
229
+    $admins = get_role( 'administrator' );
230
+
231
+    $admins->add_cap( 'edit_wordlift_entity' );
232
+    $admins->add_cap( 'edit_wordlift_entities' );
233
+    $admins->add_cap( 'edit_others_wordlift_entities' );
234
+    $admins->add_cap( 'publish_wordlift_entities' );
235
+    $admins->add_cap( 'read_private_wordlift_entities' );
236
+    $admins->add_cap( 'delete_wordlift_entity' );
237
+    $admins->add_cap( 'delete_wordlift_entities' );
238
+    $admins->add_cap( 'delete_others_wordlift_entities' );
239
+    $admins->add_cap( 'delete_published_wordlift_entities' );
240
+    $admins->add_cap( 'delete_private_wordlift_entities' );
241
+
242
+    // Assign capabilities to manipulate entities to editors.
243
+    $editors = get_role( 'editor' );
244
+
245
+    $editors->add_cap( 'edit_wordlift_entity' );
246
+    $editors->add_cap( 'edit_wordlift_entities' );
247
+    $editors->add_cap( 'edit_others_wordlift_entities' );
248
+    $editors->add_cap( 'publish_wordlift_entities' );
249
+    $editors->add_cap( 'read_private_wordlift_entities' );
250
+    $editors->add_cap( 'delete_wordlift_entity' );
251
+    $editors->add_cap( 'delete_wordlift_entities' );
252
+    $editors->add_cap( 'delete_others_wordlift_entities' );
253
+    $editors->add_cap( 'delete_published_wordlift_entities' );
254
+    $editors->add_cap( 'delete_private_wordlift_entities' );
255 255
 }
256 256
 
257 257
 /**
@@ -262,27 +262,27 @@  discard block
 block discarded – undo
262 262
  * @since 3.15.0
263 263
  */
264 264
 function wl_core_upgrade_db_3_14_3_15() {
265
-	global $wpdb;
266
-
267
-	if ( version_compare( get_option( 'wl_db_version' ), '3.15', '<=' ) ) {
268
-		$article = get_term_by( 'slug', 'article', Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
269
-		if ( ! $article ) {
270
-			$article    = wp_insert_term(
271
-				'Article',
272
-				Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
273
-				array(
274
-					'slug'        => 'article',
275
-					'description' => 'An Article.',
276
-				)
277
-			);
278
-			$article_id = $article['term_id'];
279
-		} else {
280
-			$article_id = $article->term_id;
281
-		}
282
-
283
-		// An sql that will assign the article term to all posts and pages
284
-		$wpdb->query( $wpdb->prepare(
285
-			"
265
+    global $wpdb;
266
+
267
+    if ( version_compare( get_option( 'wl_db_version' ), '3.15', '<=' ) ) {
268
+        $article = get_term_by( 'slug', 'article', Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
269
+        if ( ! $article ) {
270
+            $article    = wp_insert_term(
271
+                'Article',
272
+                Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
273
+                array(
274
+                    'slug'        => 'article',
275
+                    'description' => 'An Article.',
276
+                )
277
+            );
278
+            $article_id = $article['term_id'];
279
+        } else {
280
+            $article_id = $article->term_id;
281
+        }
282
+
283
+        // An sql that will assign the article term to all posts and pages
284
+        $wpdb->query( $wpdb->prepare(
285
+            "
286 286
 			INSERT INTO $wpdb->term_relationships( object_id, term_taxonomy_id )
287 287
 			SELECT id, %d
288 288
 			FROM $wpdb->posts
@@ -296,33 +296,33 @@  discard block
 block discarded – undo
296 296
 						AND tt.taxonomy = 'wl_entity_type'
297 297
 			)
298 298
 			",
299
-			$article_id
300
-		) );
301
-	}
299
+            $article_id
300
+        ) );
301
+    }
302 302
 }
303 303
 
304 304
 // Check db status on automated plugins updates
305 305
 function wl_core_update_db_check() {
306 306
 
307
-	// Ensure the custom type and the taxonomy are registered.
308
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
309
-
310
-	// Commenting this out because this function is already called by init
311
-	// with priority 0 at wordlift_entity_type.php.
312
-	wl_entity_type_taxonomy_register();
313
-
314
-	// Ensure the custom taxonomy for dbpedia topics is registered
315
-	Wordlift_Topic_Taxonomy_Service::get_instance()->init();
316
-
317
-	if ( get_option( 'wl_db_version' ) !== WL_DB_VERSION ) {
318
-		wl_core_install_entity_type_data();
319
-		wl_core_upgrade_db_to_1_0();
320
-		wl_core_upgrade_db_1_0_to_3_10();
321
-		wl_core_upgrade_db_3_10_3_12();
322
-		wl_core_upgrade_db_3_12_3_14();
323
-		wl_core_upgrade_db_3_14_3_15();
324
-		update_option( 'wl_db_version', WL_DB_VERSION );
325
-	}
307
+    // Ensure the custom type and the taxonomy are registered.
308
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
309
+
310
+    // Commenting this out because this function is already called by init
311
+    // with priority 0 at wordlift_entity_type.php.
312
+    wl_entity_type_taxonomy_register();
313
+
314
+    // Ensure the custom taxonomy for dbpedia topics is registered
315
+    Wordlift_Topic_Taxonomy_Service::get_instance()->init();
316
+
317
+    if ( get_option( 'wl_db_version' ) !== WL_DB_VERSION ) {
318
+        wl_core_install_entity_type_data();
319
+        wl_core_upgrade_db_to_1_0();
320
+        wl_core_upgrade_db_1_0_to_3_10();
321
+        wl_core_upgrade_db_3_10_3_12();
322
+        wl_core_upgrade_db_3_12_3_14();
323
+        wl_core_upgrade_db_3_14_3_15();
324
+        update_option( 'wl_db_version', WL_DB_VERSION );
325
+    }
326 326
 
327 327
 }
328 328
 
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 function wl_core_install_entity_type_data() {
14 14
 
15
-	Wordlift_Log_Service::get_instance()->debug( 'Installing Entity Type data...' );
15
+	Wordlift_Log_Service::get_instance()->debug('Installing Entity Type data...');
16 16
 
17 17
 	// Set the taxonomy data.
18 18
 	// Note: parent types must be defined before child types.
@@ -47,37 +47,37 @@  discard block
 block discarded – undo
47 47
 		),
48 48
 	);
49 49
 
50
-	foreach ( $terms as $slug => $term ) {
50
+	foreach ($terms as $slug => $term) {
51 51
 
52 52
 		// Create the term if it does not exist, then get its ID
53
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
53
+		$term_id = term_exists($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
54 54
 
55
-		if ( 0 == $term_id || is_null( $term_id ) ) {
56
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
55
+		if (0 == $term_id || is_null($term_id)) {
56
+			$result = wp_insert_term($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
57 57
 		} else {
58 58
 			$term_id = $term_id['term_id'];
59
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
59
+			$result  = get_term($term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A);
60 60
 		}
61 61
 
62 62
 		// Check for errors.
63
-		if ( is_wp_error( $result ) ) {
64
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
63
+		if (is_wp_error($result)) {
64
+			wl_write_log('wl_install_entity_type_data [ '.$result->get_error_message().' ]');
65 65
 			continue;
66 66
 		}
67 67
 
68 68
 		// Check if 'parent' corresponds to an actual term and get its ID.
69
-		if ( ! isset( $term['parents'] ) ) {
69
+		if ( ! isset($term['parents'])) {
70 70
 			$term['parents'] = array();
71 71
 		}
72 72
 
73 73
 		$parent_ids = array();
74
-		foreach ( $term['parents'] as $parent_slug ) {
75
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
76
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
74
+		foreach ($term['parents'] as $parent_slug) {
75
+			$parent_id    = get_term_by('slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
76
+			$parent_ids[] = intval($parent_id->term_id); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
77 77
 		}
78 78
 
79 79
 		// Define a parent in the WP taxonomy style (not important for WL)
80
-		if ( empty( $parent_ids ) ) {
80
+		if (empty($parent_ids)) {
81 81
 			// No parent
82 82
 			$parent_id = 0;
83 83
 		} else {
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
 		}
87 87
 
88 88
 		// Update term with description, slug and parent
89
-		$term = wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
89
+		$term = wp_update_term($result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
90 90
 			'name'        => $term['label'],
91 91
 			'slug'        => $slug,
92 92
 			'description' => $term['description'],
93 93
 			// We give to WP taxonomy just one parent. TODO: see if can give more than one
94 94
 			'parent'      => $parent_id,
95
-		) );
95
+		));
96 96
 
97
-		Wordlift_Log_Service::get_instance()->trace( "Entity Type $slug installed with ID {$term['term_id']}." );
97
+		Wordlift_Log_Service::get_instance()->trace("Entity Type $slug installed with ID {$term['term_id']}.");
98 98
 
99 99
 	}
100 100
 
101
-	Wordlift_Log_Service::get_instance()->debug( 'Entity Type data installed.' );
101
+	Wordlift_Log_Service::get_instance()->debug('Entity Type data installed.');
102 102
 
103 103
 }
104 104
 
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
 
110 110
 	global $wpdb;
111 111
 	// global $wl_db_version;
112
-	$installed_version = get_option( 'wl_db_version' );
112
+	$installed_version = get_option('wl_db_version');
113 113
 
114
-	if ( WL_DB_VERSION != $installed_version ) {
115
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
114
+	if (WL_DB_VERSION != $installed_version) {
115
+		$table_name      = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME;
116 116
 		$charset_collate = $wpdb->get_charset_collate();
117 117
 
118 118
 		// Sql statement for the relation instances custom table
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 EOF;
130 130
 
131 131
 		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
132
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
133
-		$results = dbDelta( $sql );
132
+		require_once(ABSPATH.'wp-admin/includes/upgrade.php');
133
+		$results = dbDelta($sql);
134 134
 
135
-		wl_write_log( $results );
135
+		wl_write_log($results);
136 136
 
137
-		update_option( 'wl_db_version', WL_DB_VERSION );
137
+		update_option('wl_db_version', WL_DB_VERSION);
138 138
 	}
139 139
 }
140 140
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
  */
147 147
 function wl_core_upgrade_db_to_1_0() {
148 148
 
149
-	if ( ! get_option( 'wl_db_version' ) ) {
149
+	if ( ! get_option('wl_db_version')) {
150 150
 		wl_core_install_create_relation_instance_table();
151 151
 	}
152 152
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 function wl_core_upgrade_db_1_0_to_3_10() {
163 163
 
164 164
 	// If the DB version is less than 3.10, than flatten the txonomy.
165
-	if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
165
+	if (version_compare(get_option('wl_db_version'), '3.9', '<=')) {
166 166
 
167 167
 		$term_slugs = array(
168 168
 			'thing',
@@ -174,15 +174,15 @@  discard block
 block discarded – undo
174 174
 			'localbusiness',
175 175
 		);
176 176
 
177
-		foreach ( $term_slugs as $slug ) {
177
+		foreach ($term_slugs as $slug) {
178 178
 
179
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
179
+			$term = get_term_by('slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
180 180
 
181 181
 			// Set the term's parent to 0.
182
-			if ( $term ) {
183
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
182
+			if ($term) {
183
+				wp_update_term($term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
184 184
 					'parent' => 0,
185
-				) );
185
+				));
186 186
 			}
187 187
 		}
188 188
 	}
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * initialization does the same, avoid possible race conditions by
204 204
 	 * deferring the actual flush to a later hook.
205 205
 	 */
206
-	add_action( 'wp_loaded', function () {
206
+	add_action('wp_loaded', function() {
207 207
 		flush_rewrite_rules();
208 208
 	} );
209 209
 }
@@ -226,32 +226,32 @@  discard block
 block discarded – undo
226 226
 	);
227 227
 
228 228
 	// Assign capabilities to manipulate entities to admins.
229
-	$admins = get_role( 'administrator' );
230
-
231
-	$admins->add_cap( 'edit_wordlift_entity' );
232
-	$admins->add_cap( 'edit_wordlift_entities' );
233
-	$admins->add_cap( 'edit_others_wordlift_entities' );
234
-	$admins->add_cap( 'publish_wordlift_entities' );
235
-	$admins->add_cap( 'read_private_wordlift_entities' );
236
-	$admins->add_cap( 'delete_wordlift_entity' );
237
-	$admins->add_cap( 'delete_wordlift_entities' );
238
-	$admins->add_cap( 'delete_others_wordlift_entities' );
239
-	$admins->add_cap( 'delete_published_wordlift_entities' );
240
-	$admins->add_cap( 'delete_private_wordlift_entities' );
229
+	$admins = get_role('administrator');
230
+
231
+	$admins->add_cap('edit_wordlift_entity');
232
+	$admins->add_cap('edit_wordlift_entities');
233
+	$admins->add_cap('edit_others_wordlift_entities');
234
+	$admins->add_cap('publish_wordlift_entities');
235
+	$admins->add_cap('read_private_wordlift_entities');
236
+	$admins->add_cap('delete_wordlift_entity');
237
+	$admins->add_cap('delete_wordlift_entities');
238
+	$admins->add_cap('delete_others_wordlift_entities');
239
+	$admins->add_cap('delete_published_wordlift_entities');
240
+	$admins->add_cap('delete_private_wordlift_entities');
241 241
 
242 242
 	// Assign capabilities to manipulate entities to editors.
243
-	$editors = get_role( 'editor' );
244
-
245
-	$editors->add_cap( 'edit_wordlift_entity' );
246
-	$editors->add_cap( 'edit_wordlift_entities' );
247
-	$editors->add_cap( 'edit_others_wordlift_entities' );
248
-	$editors->add_cap( 'publish_wordlift_entities' );
249
-	$editors->add_cap( 'read_private_wordlift_entities' );
250
-	$editors->add_cap( 'delete_wordlift_entity' );
251
-	$editors->add_cap( 'delete_wordlift_entities' );
252
-	$editors->add_cap( 'delete_others_wordlift_entities' );
253
-	$editors->add_cap( 'delete_published_wordlift_entities' );
254
-	$editors->add_cap( 'delete_private_wordlift_entities' );
243
+	$editors = get_role('editor');
244
+
245
+	$editors->add_cap('edit_wordlift_entity');
246
+	$editors->add_cap('edit_wordlift_entities');
247
+	$editors->add_cap('edit_others_wordlift_entities');
248
+	$editors->add_cap('publish_wordlift_entities');
249
+	$editors->add_cap('read_private_wordlift_entities');
250
+	$editors->add_cap('delete_wordlift_entity');
251
+	$editors->add_cap('delete_wordlift_entities');
252
+	$editors->add_cap('delete_others_wordlift_entities');
253
+	$editors->add_cap('delete_published_wordlift_entities');
254
+	$editors->add_cap('delete_private_wordlift_entities');
255 255
 }
256 256
 
257 257
 /**
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
 function wl_core_upgrade_db_3_14_3_15() {
265 265
 	global $wpdb;
266 266
 
267
-	if ( version_compare( get_option( 'wl_db_version' ), '3.15', '<=' ) ) {
268
-		$article = get_term_by( 'slug', 'article', Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
269
-		if ( ! $article ) {
270
-			$article    = wp_insert_term(
267
+	if (version_compare(get_option('wl_db_version'), '3.15', '<=')) {
268
+		$article = get_term_by('slug', 'article', Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
269
+		if ( ! $article) {
270
+			$article = wp_insert_term(
271 271
 				'Article',
272 272
 				Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
273 273
 				array(
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 		}
282 282
 
283 283
 		// An sql that will assign the article term to all posts and pages
284
-		$wpdb->query( $wpdb->prepare(
284
+		$wpdb->query($wpdb->prepare(
285 285
 			"
286 286
 			INSERT INTO $wpdb->term_relationships( object_id, term_taxonomy_id )
287 287
 			SELECT id, %d
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 			)
298 298
 			",
299 299
 			$article_id
300
-		) );
300
+		));
301 301
 	}
302 302
 }
303 303
 
@@ -314,16 +314,16 @@  discard block
 block discarded – undo
314 314
 	// Ensure the custom taxonomy for dbpedia topics is registered
315 315
 	Wordlift_Topic_Taxonomy_Service::get_instance()->init();
316 316
 
317
-	if ( get_option( 'wl_db_version' ) !== WL_DB_VERSION ) {
317
+	if (get_option('wl_db_version') !== WL_DB_VERSION) {
318 318
 		wl_core_install_entity_type_data();
319 319
 		wl_core_upgrade_db_to_1_0();
320 320
 		wl_core_upgrade_db_1_0_to_3_10();
321 321
 		wl_core_upgrade_db_3_10_3_12();
322 322
 		wl_core_upgrade_db_3_12_3_14();
323 323
 		wl_core_upgrade_db_3_14_3_15();
324
-		update_option( 'wl_db_version', WL_DB_VERSION );
324
+		update_option('wl_db_version', WL_DB_VERSION);
325 325
 	}
326 326
 
327 327
 }
328 328
 
329
-add_action( 'init', 'wl_core_update_db_check', 11 ); // need taxonomies and post type to be defined first
329
+add_action('init', 'wl_core_update_db_check', 11); // need taxonomies and post type to be defined first
Please login to merge, or discard this patch.
src/modules/core/wordlift_core_functions.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,9 +7,9 @@
 block discarded – undo
7 7
  * @param mixed $response The response to send to the client as JSON.
8 8
  */
9 9
 function wl_core_send_json( $response ) {
10
-	if ( ob_get_contents() ) {
11
-		ob_clean();
12
-	}
10
+    if ( ob_get_contents() ) {
11
+        ob_clean();
12
+    }
13 13
 
14
-	wp_send_json( $response );
14
+    wp_send_json( $response );
15 15
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,10 +6,10 @@
 block discarded – undo
6 6
  *
7 7
  * @param mixed $response The response to send to the client as JSON.
8 8
  */
9
-function wl_core_send_json( $response ) {
10
-	if ( ob_get_contents() ) {
9
+function wl_core_send_json($response) {
10
+	if (ob_get_contents()) {
11 11
 		ob_clean();
12 12
 	}
13 13
 
14
-	wp_send_json( $response );
14
+	wp_send_json($response);
15 15
 }
Please login to merge, or discard this patch.
src/modules/core/wordlift_core_constants.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,37 +1,37 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-define( 'WL_DEFAULT_THUMBNAIL_PATH', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/public/images/missing-image-150x150.png' );
4
-define( 'WL_DEFAULT_PATH', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/' );
3
+define('WL_DEFAULT_THUMBNAIL_PATH', dirname(dirname(plugin_dir_url(__FILE__))).'/public/images/missing-image-150x150.png');
4
+define('WL_DEFAULT_PATH', dirname(dirname(plugin_dir_url(__FILE__))).'/');
5 5
 
6 6
 // Database version
7
-define( 'WL_DB_VERSION', '3.15' );
7
+define('WL_DB_VERSION', '3.15');
8 8
 // Custom table name
9
-define( 'WL_DB_RELATION_INSTANCES_TABLE_NAME', 'wl_relation_instances' );
9
+define('WL_DB_RELATION_INSTANCES_TABLE_NAME', 'wl_relation_instances');
10 10
 
11
-define( 'WL_WHAT_RELATION', 'what' );
12
-define( 'WL_WHO_RELATION', 'who' );
13
-define( 'WL_WHERE_RELATION', 'where' );
14
-define( 'WL_WHEN_RELATION', 'when' );
11
+define('WL_WHAT_RELATION', 'what');
12
+define('WL_WHO_RELATION', 'who');
13
+define('WL_WHERE_RELATION', 'where');
14
+define('WL_WHEN_RELATION', 'when');
15 15
 
16 16
 // Mapping options / validations rules used by wl_core_get_posts to perform validation on args
17 17
 // The array is serialized because array constants are only from php 5.6 on.
18
-define( 'WL_CORE_GET_POSTS_VALIDATION_RULES', serialize( array(
19
-	'get'            => array( 'posts', 'post_ids' ),
20
-	'as'             => array( 'object', 'subject' ),
21
-	'post_type'      => array( 'post', 'entity' ),
22
-	'post_status'    => array( 'draft', 'trash', 'publish' ),
18
+define('WL_CORE_GET_POSTS_VALIDATION_RULES', serialize(array(
19
+	'get'            => array('posts', 'post_ids'),
20
+	'as'             => array('object', 'subject'),
21
+	'post_type'      => array('post', 'entity'),
22
+	'post_status'    => array('draft', 'trash', 'publish'),
23 23
 	'with_predicate' => array(
24 24
 		WL_WHAT_RELATION,
25 25
 		WL_WHEN_RELATION,
26 26
 		WL_WHERE_RELATION,
27 27
 		WL_WHO_RELATION,
28 28
 	),
29
-) ) );
29
+)));
30 30
 
31 31
 // Classification boxes configuration for angularjs edit-post widget
32 32
 // The array is serialized because array constants are only from php 5.6 on.
33 33
 
34
-define( 'WL_CORE_POST_CLASSIFICATION_BOXES', serialize( array(
34
+define('WL_CORE_POST_CLASSIFICATION_BOXES', serialize(array(
35 35
 	array(
36 36
 		'id'               => WL_WHAT_RELATION,
37 37
 		'label'            => 'What',
@@ -59,13 +59,13 @@  discard block
 block discarded – undo
59 59
 	array(
60 60
 		'id'               => WL_WHERE_RELATION,
61 61
 		'label'            => 'Where',
62
-		'registeredTypes'  => array( 'place' ),
62
+		'registeredTypes'  => array('place'),
63 63
 		'selectedEntities' => array(),
64 64
 	),
65 65
 	array(
66 66
 		'id'               => WL_WHEN_RELATION,
67 67
 		'label'            => 'When',
68
-		'registeredTypes'  => array( 'event' ),
68
+		'registeredTypes'  => array('event'),
69 69
 		'selectedEntities' => array(),
70 70
 	),
71
-) ) );
71
+)));
Please login to merge, or discard this patch.
src/modules/core/wordlift_core_post_entity_relations.php 2 patches
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -16,12 +16,12 @@  discard block
 block discarded – undo
16 16
  */
17 17
 function wl_core_check_relation_predicate_is_supported( $predicate ) {
18 18
 
19
-	return in_array( $predicate, array(
20
-		WL_WHAT_RELATION,
21
-		WL_WHEN_RELATION,
22
-		WL_WHERE_RELATION,
23
-		WL_WHO_RELATION,
24
-	) );
19
+    return in_array( $predicate, array(
20
+        WL_WHAT_RELATION,
21
+        WL_WHEN_RELATION,
22
+        WL_WHERE_RELATION,
23
+        WL_WHO_RELATION,
24
+    ) );
25 25
 }
26 26
 
27 27
 /**
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
  */
32 32
 function wl_core_get_validation_rules() {
33 33
 
34
-	return unserialize( WL_CORE_GET_POSTS_VALIDATION_RULES );
34
+    return unserialize( WL_CORE_GET_POSTS_VALIDATION_RULES );
35 35
 }
36 36
 
37 37
 /**
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
  */
42 42
 function wl_core_get_relation_instances_table_name() {
43 43
 
44
-	global $wpdb;
45
-	$table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
44
+    global $wpdb;
45
+    $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
46 46
 
47
-	return $table_name;
47
+    return $table_name;
48 48
 }
49 49
 
50 50
 /**
@@ -59,33 +59,33 @@  discard block
 block discarded – undo
59 59
  */
60 60
 function wl_core_add_relation_instance( $subject_id, $predicate, $object_id ) {
61 61
 
62
-	// Checks on subject and object
63
-	if ( ! is_numeric( $subject_id ) || ! is_numeric( $object_id ) ) {
64
-		return false;
65
-	}
66
-
67
-	// Checks on the given relation
68
-	if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) {
69
-		return false;
70
-	}
71
-
72
-	// Prepare interaction with db
73
-	global $wpdb;
74
-
75
-	// Checks passed. Add relation if not exists:
76
-	// See https://codex.wordpress.org/Class_Reference/wpdb#REPLACE_row
77
-	$wpdb->replace(
78
-		wl_core_get_relation_instances_table_name(),
79
-		array(
80
-			'subject_id' => $subject_id,
81
-			'predicate'  => $predicate,
82
-			'object_id'  => $object_id,
83
-		),
84
-		array( '%d', '%s', '%d' )
85
-	);
86
-
87
-	// Return record id
88
-	return $wpdb->insert_id;
62
+    // Checks on subject and object
63
+    if ( ! is_numeric( $subject_id ) || ! is_numeric( $object_id ) ) {
64
+        return false;
65
+    }
66
+
67
+    // Checks on the given relation
68
+    if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) {
69
+        return false;
70
+    }
71
+
72
+    // Prepare interaction with db
73
+    global $wpdb;
74
+
75
+    // Checks passed. Add relation if not exists:
76
+    // See https://codex.wordpress.org/Class_Reference/wpdb#REPLACE_row
77
+    $wpdb->replace(
78
+        wl_core_get_relation_instances_table_name(),
79
+        array(
80
+            'subject_id' => $subject_id,
81
+            'predicate'  => $predicate,
82
+            'object_id'  => $object_id,
83
+        ),
84
+        array( '%d', '%s', '%d' )
85
+    );
86
+
87
+    // Return record id
88
+    return $wpdb->insert_id;
89 89
 }
90 90
 
91 91
 /**
@@ -98,26 +98,26 @@  discard block
 block discarded – undo
98 98
  */
99 99
 function wl_core_delete_relation_instances( $subject_id ) {
100 100
 
101
-	// Checks on subject and object
102
-	if ( ! is_numeric( $subject_id ) ) {
103
-		return false;
104
-	}
101
+    // Checks on subject and object
102
+    if ( ! is_numeric( $subject_id ) ) {
103
+        return false;
104
+    }
105 105
 
106
-	// Prepare interaction with db
107
-	global $wpdb;
106
+    // Prepare interaction with db
107
+    global $wpdb;
108 108
 
109
-	// wl_write_log( "Going to delete relation instances [ subject_id :: $subject_id ]");
109
+    // wl_write_log( "Going to delete relation instances [ subject_id :: $subject_id ]");
110 110
 
111
-	// @see https://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe
112
-	$wpdb->delete(
113
-		wl_core_get_relation_instances_table_name(),
114
-		array(
115
-			'subject_id' => $subject_id,
116
-		),
117
-		array( '%d' )
118
-	);
111
+    // @see https://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe
112
+    $wpdb->delete(
113
+        wl_core_get_relation_instances_table_name(),
114
+        array(
115
+            'subject_id' => $subject_id,
116
+        ),
117
+        array( '%d' )
118
+    );
119 119
 
120
-	return true;
120
+    return true;
121 121
 }
122 122
 
123 123
 /**
@@ -133,18 +133,18 @@  discard block
 block discarded – undo
133 133
  */
134 134
 function wl_core_validate_filters_for_related( $filters ) {
135 135
 
136
-	if ( ! is_array( $filters ) ) {
137
-		$filters = array();
138
-	}
136
+    if ( ! is_array( $filters ) ) {
137
+        $filters = array();
138
+    }
139 139
 
140
-	if ( ! isset( $filters['predicate'] ) ) {
141
-		$filters['predicate'] = null;
142
-	}
143
-	if ( ! isset( $filters['status'] ) ) {
144
-		$filters['status'] = null;
145
-	}
140
+    if ( ! isset( $filters['predicate'] ) ) {
141
+        $filters['predicate'] = null;
142
+    }
143
+    if ( ! isset( $filters['status'] ) ) {
144
+        $filters['status'] = null;
145
+    }
146 146
 
147
-	return $filters;
147
+    return $filters;
148 148
 }
149 149
 
150 150
 ///**
@@ -191,10 +191,10 @@  discard block
 block discarded – undo
191 191
  */
192 192
 function wl_core_get_related_entity_ids( $subject_id, $filters = array() ) {
193 193
 
194
-	$status    = isset( $filters['status'] ) ? $filters['status'] : null;
195
-	$predicate = isset( $filters['predicate'] ) ? $filters['predicate'] : null;
194
+    $status    = isset( $filters['status'] ) ? $filters['status'] : null;
195
+    $predicate = isset( $filters['predicate'] ) ? $filters['predicate'] : null;
196 196
 
197
-	return Wordlift_Relation_Service::get_instance()->get_objects( $subject_id, 'ids', $predicate, $status );
197
+    return Wordlift_Relation_Service::get_instance()->get_objects( $subject_id, 'ids', $predicate, $status );
198 198
 
199 199
 //	$filters = wl_core_validate_filters_for_related( $filters );
200 200
 //
@@ -215,11 +215,11 @@  discard block
 block discarded – undo
215 215
  */
216 216
 function wl_core_get_related_entities( $subject_id, $filters = array() ) {
217 217
 
218
-	$ids = wl_core_get_related_entity_ids( $subject_id, $filters );
218
+    $ids = wl_core_get_related_entity_ids( $subject_id, $filters );
219 219
 
220
-	return array_map( function ( $item ) {
221
-		return get_post( $item );
222
-	}, $ids );
220
+    return array_map( function ( $item ) {
221
+        return get_post( $item );
222
+    }, $ids );
223 223
 }
224 224
 
225 225
 //
@@ -297,12 +297,12 @@  discard block
 block discarded – undo
297 297
  */
298 298
 function wl_core_get_related_post_ids( $object_id, $filters = array() ) {
299 299
 
300
-	$relation_service = Wordlift_Relation_Service::get_instance();
300
+    $relation_service = Wordlift_Relation_Service::get_instance();
301 301
 
302
-	$status    = isset( $filters['status'] ) ? $filters['status'] : null;
303
-	$predicate = isset( $filters['predicate'] ) ? $filters['predicate'] : null;
302
+    $status    = isset( $filters['status'] ) ? $filters['status'] : null;
303
+    $predicate = isset( $filters['predicate'] ) ? $filters['predicate'] : null;
304 304
 
305
-	return $relation_service->get_article_subjects( $object_id, 'ids', $predicate, $status );
305
+    return $relation_service->get_article_subjects( $object_id, 'ids', $predicate, $status );
306 306
 //
307 307
 //	$filters = wl_core_validate_filters_for_related( $filters );
308 308
 //
@@ -326,11 +326,11 @@  discard block
 block discarded – undo
326 326
  */
327 327
 function wl_core_get_related_posts( $subject_id, $filters = array() ) {
328 328
 
329
-	$ids = wl_core_get_related_post_ids( $subject_id, $filters );
329
+    $ids = wl_core_get_related_post_ids( $subject_id, $filters );
330 330
 
331
-	return array_map( function ( $item ) {
332
-		return get_post( $item );
333
-	}, $ids );
331
+    return array_map( function ( $item ) {
332
+        return get_post( $item );
333
+    }, $ids );
334 334
 }
335 335
 
336 336
 ///**
@@ -415,108 +415,108 @@  discard block
 block discarded – undo
415 415
  */
416 416
 function wl_core_sql_query_builder( $args ) {
417 417
 
418
-	// Prepare interaction with db
419
-	global $wpdb;
420
-
421
-	// Retrieve Wordlift relation instances table name
422
-	$table_name = wl_core_get_relation_instances_table_name();
423
-
424
-	// When type is set to `post` we're looking for `post`s that are not
425
-	// configured as entities.
426
-	// When the type is set to `entity` we're looking also for `post`s that are
427
-	// configured as entities.
428
-
429
-	// Since we want Find only articles, based on the entity type, we need
430
-	// to figure out the relevant sql statements to add to the join and where
431
-	// parts.
432
-	$tax_query = array(
433
-		array(
434
-			'taxonomy' => Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
435
-			'field'    => 'slug',
436
-			'terms'    => 'article',
437
-			'operator' => 'entity' === $args['post_type'] ? 'NOT IN' : 'IN',
438
-		),
439
-	);
440
-
441
-	// Use "p" as the table to match the initial join.
442
-	$tax_sql = get_tax_sql( $tax_query, 'p', 'ID' );
443
-
444
-	// Sql Action
445
-	$sql = 'SELECT ';
446
-	// Determine what has to be returned depending on 'get' argument value
447
-	switch ( $args['get'] ) {
448
-		case 'posts':
449
-			$sql .= 'p.*';
450
-			break;
451
-		case 'post_ids':
452
-			$sql .= 'p.id';
453
-			break;
454
-	}
455
-
456
-	// If we look for posts related as objects the JOIN has to be done with the object_id column and viceversa
457
-	$join_column = $args['as'] . '_id';
458
-
459
-	$sql .= " FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.$join_column";
460
-
461
-	// Changing left join generate by the tax query into an inner since the term relationship has to exist.
462
-	$sql .= str_replace( 'LEFT JOIN', 'INNER JOIN', $tax_sql['join'] );
463
-
464
-	// Sql add post type filter
465
-	$post_types = Wordlift_Entity_Service::valid_entity_post_types();
466
-	$sql        .= " AND p.post_type IN ('" . join( "', '", esc_sql( $post_types ) ) . "') AND";
467
-
468
-	// Sql add post status filter
469
-	if ( isset( $args['post_status'] ) && ! is_null( $args['post_status'] ) ) {
470
-		$sql .= $wpdb->prepare( ' p.post_status = %s AND', $args['post_status'] );
471
-	}
472
-
473
-	// Add filtering conditions
474
-	// If we look for posts related as objects this means that
475
-	// related_to is a reference for a subject: subject_id is the filtering column
476
-	// If we look for posts related as subject this means that
477
-	// related_to is reference for an object: object_id is the filtering column
478
-
479
-	$filtering_column = ( 'object' == $args['as'] ) ? 'subject_id' : 'object_id';
480
-
481
-	if ( isset( $args['related_to'] ) ) {
482
-		$sql .= $wpdb->prepare( " r.$filtering_column = %d", $args['related_to'] );
483
-	}
484
-	if ( isset( $args['related_to'] ) && isset( $args['related_to__in'] ) ) {
485
-		$sql .= ' AND';
486
-	}
487
-	if ( isset( $args['related_to__in'] ) ) {
488
-		$sql .= " r.$filtering_column IN (" . implode( ',', $args['related_to__in'] ) . ')';
489
-		// The IDs used for filtering shouldn't be in the results.
490
-		$sql .= " AND p.ID NOT IN (" . implode( ',', $args['related_to__in'] ) . ')';
491
-	}
492
-	if ( isset( $args['post__not_in'] ) ) {
493
-		$sql .= ' AND r.' . $args['as'] . '_id NOT IN (' . implode( ',', $args['post__not_in'] ) . ')';
494
-	}
495
-	if ( isset( $args['post__in'] ) ) {
496
-		$sql .= ' AND r.' . $args['as'] . '_id IN (' . implode( ',', $args['post__in'] ) . ')';
497
-	}
498
-	// Add predicate filter if required.
499
-	if ( isset( $args['with_predicate'] ) ) {
500
-		// Sql Inner Join clause.
501
-		$sql .= $wpdb->prepare( ' AND r.predicate = %s', $args['with_predicate'] );
502
-	}
503
-
504
-	// Add the taxonomy related sql.
505
-	$sql .= $tax_sql['where'];
506
-
507
-	// Add a group by clause to avoid duplicated rows
508
-	// @todo: isn't a distinct a better choice?
509
-	$sql .= ' GROUP BY p.id';
510
-
511
-	// @todo: how does `first` represent the limit?
512
-	if ( isset( $args['first'] ) && is_numeric( $args['first'] ) ) {
513
-		// Sql Inner Join clause.
514
-		$sql .= $wpdb->prepare( ' LIMIT %d', $args['first'] );
515
-	}
516
-	// Close sql statement
517
-	$sql .= ';';
518
-
519
-	return $sql;
418
+    // Prepare interaction with db
419
+    global $wpdb;
420
+
421
+    // Retrieve Wordlift relation instances table name
422
+    $table_name = wl_core_get_relation_instances_table_name();
423
+
424
+    // When type is set to `post` we're looking for `post`s that are not
425
+    // configured as entities.
426
+    // When the type is set to `entity` we're looking also for `post`s that are
427
+    // configured as entities.
428
+
429
+    // Since we want Find only articles, based on the entity type, we need
430
+    // to figure out the relevant sql statements to add to the join and where
431
+    // parts.
432
+    $tax_query = array(
433
+        array(
434
+            'taxonomy' => Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
435
+            'field'    => 'slug',
436
+            'terms'    => 'article',
437
+            'operator' => 'entity' === $args['post_type'] ? 'NOT IN' : 'IN',
438
+        ),
439
+    );
440
+
441
+    // Use "p" as the table to match the initial join.
442
+    $tax_sql = get_tax_sql( $tax_query, 'p', 'ID' );
443
+
444
+    // Sql Action
445
+    $sql = 'SELECT ';
446
+    // Determine what has to be returned depending on 'get' argument value
447
+    switch ( $args['get'] ) {
448
+        case 'posts':
449
+            $sql .= 'p.*';
450
+            break;
451
+        case 'post_ids':
452
+            $sql .= 'p.id';
453
+            break;
454
+    }
455
+
456
+    // If we look for posts related as objects the JOIN has to be done with the object_id column and viceversa
457
+    $join_column = $args['as'] . '_id';
458
+
459
+    $sql .= " FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.$join_column";
460
+
461
+    // Changing left join generate by the tax query into an inner since the term relationship has to exist.
462
+    $sql .= str_replace( 'LEFT JOIN', 'INNER JOIN', $tax_sql['join'] );
463
+
464
+    // Sql add post type filter
465
+    $post_types = Wordlift_Entity_Service::valid_entity_post_types();
466
+    $sql        .= " AND p.post_type IN ('" . join( "', '", esc_sql( $post_types ) ) . "') AND";
467
+
468
+    // Sql add post status filter
469
+    if ( isset( $args['post_status'] ) && ! is_null( $args['post_status'] ) ) {
470
+        $sql .= $wpdb->prepare( ' p.post_status = %s AND', $args['post_status'] );
471
+    }
472
+
473
+    // Add filtering conditions
474
+    // If we look for posts related as objects this means that
475
+    // related_to is a reference for a subject: subject_id is the filtering column
476
+    // If we look for posts related as subject this means that
477
+    // related_to is reference for an object: object_id is the filtering column
478
+
479
+    $filtering_column = ( 'object' == $args['as'] ) ? 'subject_id' : 'object_id';
480
+
481
+    if ( isset( $args['related_to'] ) ) {
482
+        $sql .= $wpdb->prepare( " r.$filtering_column = %d", $args['related_to'] );
483
+    }
484
+    if ( isset( $args['related_to'] ) && isset( $args['related_to__in'] ) ) {
485
+        $sql .= ' AND';
486
+    }
487
+    if ( isset( $args['related_to__in'] ) ) {
488
+        $sql .= " r.$filtering_column IN (" . implode( ',', $args['related_to__in'] ) . ')';
489
+        // The IDs used for filtering shouldn't be in the results.
490
+        $sql .= " AND p.ID NOT IN (" . implode( ',', $args['related_to__in'] ) . ')';
491
+    }
492
+    if ( isset( $args['post__not_in'] ) ) {
493
+        $sql .= ' AND r.' . $args['as'] . '_id NOT IN (' . implode( ',', $args['post__not_in'] ) . ')';
494
+    }
495
+    if ( isset( $args['post__in'] ) ) {
496
+        $sql .= ' AND r.' . $args['as'] . '_id IN (' . implode( ',', $args['post__in'] ) . ')';
497
+    }
498
+    // Add predicate filter if required.
499
+    if ( isset( $args['with_predicate'] ) ) {
500
+        // Sql Inner Join clause.
501
+        $sql .= $wpdb->prepare( ' AND r.predicate = %s', $args['with_predicate'] );
502
+    }
503
+
504
+    // Add the taxonomy related sql.
505
+    $sql .= $tax_sql['where'];
506
+
507
+    // Add a group by clause to avoid duplicated rows
508
+    // @todo: isn't a distinct a better choice?
509
+    $sql .= ' GROUP BY p.id';
510
+
511
+    // @todo: how does `first` represent the limit?
512
+    if ( isset( $args['first'] ) && is_numeric( $args['first'] ) ) {
513
+        // Sql Inner Join clause.
514
+        $sql .= $wpdb->prepare( ' LIMIT %d', $args['first'] );
515
+    }
516
+    // Close sql statement
517
+    $sql .= ';';
518
+
519
+    return $sql;
520 520
 
521 521
 }
522 522
 
@@ -534,70 +534,70 @@  discard block
 block discarded – undo
534 534
  */
535 535
 function wl_core_get_posts( $args, $returned_type = OBJECT ) {
536 536
 
537
-	// Merge given args with defaults args value
538
-	$args = array_merge( array(
539
-		'with_predicate' => null,
540
-		'as'             => 'subject',
541
-		'post_type'      => 'post',
542
-		'get'            => 'posts',
543
-		'post_status'    => null,
544
-	), $args );
545
-
546
-	// Arguments validation rules
547
-	// At least one between related_to and related_to__in has to be set
548
-	if ( ! isset( $args['related_to'] ) && ! isset( $args['related_to__in'] ) ) {
549
-		return false;
550
-	}
551
-	if ( isset( $args['related_to'] ) && ! is_numeric( $args['related_to'] ) ) {
552
-		return false;
553
-	}
554
-
555
-	// The same check is applied to post_in, post__not_in and related_to__in options
556
-	// Only arrays with at least one numeric value are considerad valid
557
-	// The argument value is further sanitized in order to clean up not numeric values
558
-	foreach (
559
-		array(
560
-			'post__in',
561
-			'post__not_in',
562
-			'related_to__in',
563
-		) as $option_name
564
-	) {
565
-		if ( isset( $args[ $option_name ] ) ) {
566
-			if ( ! is_array( $args[ $option_name ] ) || 0 == count( array_filter( $args[ $option_name ], "is_numeric" ) ) ) {
567
-				return false;
568
-			}
569
-			// Sanitize value removing non numeric values from the array
570
-			$args[ $option_name ] = array_filter( $args[ $option_name ], "is_numeric" );
571
-		}
572
-	}
573
-	// Performing validation rules
574
-	foreach ( wl_core_get_validation_rules() as $option_name => $accepeted_values ) {
575
-		if ( isset( $args[ $option_name ] ) && ! is_null( $args[ $option_name ] ) ) {
576
-			if ( ! in_array( $args[ $option_name ], $accepeted_values ) ) {
577
-				return false;
578
-			}
579
-		}
580
-	}
581
-
582
-	// Prepare interaction with db
583
-	global $wpdb;
584
-
585
-	// Build sql statement with given arguments
586
-	$sql_statement = wl_core_sql_query_builder( $args );
587
-
588
-	// If ids are required, returns a one-dimensional array containing ids.
589
-	// Otherwise an array of associative arrays representing the post | relation object
590
-	if ( 'post_ids' == $args['get'] ) {
591
-		# See https://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Column
592
-		$results = $wpdb->get_col( $sql_statement );
593
-	} else {
594
-		$results = $wpdb->get_results( $sql_statement, $returned_type );
595
-	}
596
-	// If there were an error performing the query then false is returned
597
-	if ( ! empty( $wpdb->last_error ) ) {
598
-		return false;
599
-	}
600
-
601
-	// Finally
602
-	return $results;
537
+    // Merge given args with defaults args value
538
+    $args = array_merge( array(
539
+        'with_predicate' => null,
540
+        'as'             => 'subject',
541
+        'post_type'      => 'post',
542
+        'get'            => 'posts',
543
+        'post_status'    => null,
544
+    ), $args );
545
+
546
+    // Arguments validation rules
547
+    // At least one between related_to and related_to__in has to be set
548
+    if ( ! isset( $args['related_to'] ) && ! isset( $args['related_to__in'] ) ) {
549
+        return false;
550
+    }
551
+    if ( isset( $args['related_to'] ) && ! is_numeric( $args['related_to'] ) ) {
552
+        return false;
553
+    }
554
+
555
+    // The same check is applied to post_in, post__not_in and related_to__in options
556
+    // Only arrays with at least one numeric value are considerad valid
557
+    // The argument value is further sanitized in order to clean up not numeric values
558
+    foreach (
559
+        array(
560
+            'post__in',
561
+            'post__not_in',
562
+            'related_to__in',
563
+        ) as $option_name
564
+    ) {
565
+        if ( isset( $args[ $option_name ] ) ) {
566
+            if ( ! is_array( $args[ $option_name ] ) || 0 == count( array_filter( $args[ $option_name ], "is_numeric" ) ) ) {
567
+                return false;
568
+            }
569
+            // Sanitize value removing non numeric values from the array
570
+            $args[ $option_name ] = array_filter( $args[ $option_name ], "is_numeric" );
571
+        }
572
+    }
573
+    // Performing validation rules
574
+    foreach ( wl_core_get_validation_rules() as $option_name => $accepeted_values ) {
575
+        if ( isset( $args[ $option_name ] ) && ! is_null( $args[ $option_name ] ) ) {
576
+            if ( ! in_array( $args[ $option_name ], $accepeted_values ) ) {
577
+                return false;
578
+            }
579
+        }
580
+    }
581
+
582
+    // Prepare interaction with db
583
+    global $wpdb;
584
+
585
+    // Build sql statement with given arguments
586
+    $sql_statement = wl_core_sql_query_builder( $args );
587
+
588
+    // If ids are required, returns a one-dimensional array containing ids.
589
+    // Otherwise an array of associative arrays representing the post | relation object
590
+    if ( 'post_ids' == $args['get'] ) {
591
+        # See https://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Column
592
+        $results = $wpdb->get_col( $sql_statement );
593
+    } else {
594
+        $results = $wpdb->get_results( $sql_statement, $returned_type );
595
+    }
596
+    // If there were an error performing the query then false is returned
597
+    if ( ! empty( $wpdb->last_error ) ) {
598
+        return false;
599
+    }
600
+
601
+    // Finally
602
+    return $results;
603 603
 }
Please login to merge, or discard this patch.
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
  *
15 15
  * @return boolean Return true if supported, false otherwise
16 16
  */
17
-function wl_core_check_relation_predicate_is_supported( $predicate ) {
17
+function wl_core_check_relation_predicate_is_supported($predicate) {
18 18
 
19
-	return in_array( $predicate, array(
19
+	return in_array($predicate, array(
20 20
 		WL_WHAT_RELATION,
21 21
 		WL_WHEN_RELATION,
22 22
 		WL_WHERE_RELATION,
23 23
 		WL_WHO_RELATION,
24
-	) );
24
+	));
25 25
 }
26 26
 
27 27
 /**
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
  */
32 32
 function wl_core_get_validation_rules() {
33 33
 
34
-	return unserialize( WL_CORE_GET_POSTS_VALIDATION_RULES );
34
+	return unserialize(WL_CORE_GET_POSTS_VALIDATION_RULES);
35 35
 }
36 36
 
37 37
 /**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 function wl_core_get_relation_instances_table_name() {
43 43
 
44 44
 	global $wpdb;
45
-	$table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
45
+	$table_name = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME;
46 46
 
47 47
 	return $table_name;
48 48
 }
@@ -57,15 +57,15 @@  discard block
 block discarded – undo
57 57
  * @uses   $wpdb->replace() to perform the query
58 58
  * @return integer|boolean Return then relation instance ID or false.
59 59
  */
60
-function wl_core_add_relation_instance( $subject_id, $predicate, $object_id ) {
60
+function wl_core_add_relation_instance($subject_id, $predicate, $object_id) {
61 61
 
62 62
 	// Checks on subject and object
63
-	if ( ! is_numeric( $subject_id ) || ! is_numeric( $object_id ) ) {
63
+	if ( ! is_numeric($subject_id) || ! is_numeric($object_id)) {
64 64
 		return false;
65 65
 	}
66 66
 
67 67
 	// Checks on the given relation
68
-	if ( ! wl_core_check_relation_predicate_is_supported( $predicate ) ) {
68
+	if ( ! wl_core_check_relation_predicate_is_supported($predicate)) {
69 69
 		return false;
70 70
 	}
71 71
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 			'predicate'  => $predicate,
82 82
 			'object_id'  => $object_id,
83 83
 		),
84
-		array( '%d', '%s', '%d' )
84
+		array('%d', '%s', '%d')
85 85
 	);
86 86
 
87 87
 	// Return record id
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
  *
97 97
  * @return boolean False for failure. True for success.
98 98
  */
99
-function wl_core_delete_relation_instances( $subject_id ) {
99
+function wl_core_delete_relation_instances($subject_id) {
100 100
 
101 101
 	// Checks on subject and object
102
-	if ( ! is_numeric( $subject_id ) ) {
102
+	if ( ! is_numeric($subject_id)) {
103 103
 		return false;
104 104
 	}
105 105
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 		array(
115 115
 			'subject_id' => $subject_id,
116 116
 		),
117
-		array( '%d' )
117
+		array('%d')
118 118
 	);
119 119
 
120 120
 	return true;
@@ -131,16 +131,16 @@  discard block
 block discarded – undo
131 131
  *      'status'    => null
132 132
  *  );
133 133
  */
134
-function wl_core_validate_filters_for_related( $filters ) {
134
+function wl_core_validate_filters_for_related($filters) {
135 135
 
136
-	if ( ! is_array( $filters ) ) {
136
+	if ( ! is_array($filters)) {
137 137
 		$filters = array();
138 138
 	}
139 139
 
140
-	if ( ! isset( $filters['predicate'] ) ) {
140
+	if ( ! isset($filters['predicate'])) {
141 141
 		$filters['predicate'] = null;
142 142
 	}
143
-	if ( ! isset( $filters['status'] ) ) {
143
+	if ( ! isset($filters['status'])) {
144 144
 		$filters['status'] = null;
145 145
 	}
146 146
 
@@ -189,12 +189,12 @@  discard block
 block discarded – undo
189 189
  *
190 190
  * @return array Array of post entity objects.
191 191
  */
192
-function wl_core_get_related_entity_ids( $subject_id, $filters = array() ) {
192
+function wl_core_get_related_entity_ids($subject_id, $filters = array()) {
193 193
 
194
-	$status    = isset( $filters['status'] ) ? $filters['status'] : null;
195
-	$predicate = isset( $filters['predicate'] ) ? $filters['predicate'] : null;
194
+	$status    = isset($filters['status']) ? $filters['status'] : null;
195
+	$predicate = isset($filters['predicate']) ? $filters['predicate'] : null;
196 196
 
197
-	return Wordlift_Relation_Service::get_instance()->get_objects( $subject_id, 'ids', $predicate, $status );
197
+	return Wordlift_Relation_Service::get_instance()->get_objects($subject_id, 'ids', $predicate, $status);
198 198
 
199 199
 //	$filters = wl_core_validate_filters_for_related( $filters );
200 200
 //
@@ -213,13 +213,13 @@  discard block
 block discarded – undo
213 213
  *
214 214
  * @return array An array of {@link WP_Post}s.
215 215
  */
216
-function wl_core_get_related_entities( $subject_id, $filters = array() ) {
216
+function wl_core_get_related_entities($subject_id, $filters = array()) {
217 217
 
218
-	$ids = wl_core_get_related_entity_ids( $subject_id, $filters );
218
+	$ids = wl_core_get_related_entity_ids($subject_id, $filters);
219 219
 
220
-	return array_map( function ( $item ) {
221
-		return get_post( $item );
222
-	}, $ids );
220
+	return array_map(function($item) {
221
+		return get_post($item);
222
+	}, $ids);
223 223
 }
224 224
 
225 225
 //
@@ -295,14 +295,14 @@  discard block
 block discarded – undo
295 295
  *
296 296
  * @return array Array of objects.
297 297
  */
298
-function wl_core_get_related_post_ids( $object_id, $filters = array() ) {
298
+function wl_core_get_related_post_ids($object_id, $filters = array()) {
299 299
 
300 300
 	$relation_service = Wordlift_Relation_Service::get_instance();
301 301
 
302
-	$status    = isset( $filters['status'] ) ? $filters['status'] : null;
303
-	$predicate = isset( $filters['predicate'] ) ? $filters['predicate'] : null;
302
+	$status    = isset($filters['status']) ? $filters['status'] : null;
303
+	$predicate = isset($filters['predicate']) ? $filters['predicate'] : null;
304 304
 
305
-	return $relation_service->get_article_subjects( $object_id, 'ids', $predicate, $status );
305
+	return $relation_service->get_article_subjects($object_id, 'ids', $predicate, $status);
306 306
 //
307 307
 //	$filters = wl_core_validate_filters_for_related( $filters );
308 308
 //
@@ -324,13 +324,13 @@  discard block
 block discarded – undo
324 324
  *
325 325
  * @return array An array of {@link WP_Post}s.
326 326
  */
327
-function wl_core_get_related_posts( $subject_id, $filters = array() ) {
327
+function wl_core_get_related_posts($subject_id, $filters = array()) {
328 328
 
329
-	$ids = wl_core_get_related_post_ids( $subject_id, $filters );
329
+	$ids = wl_core_get_related_post_ids($subject_id, $filters);
330 330
 
331
-	return array_map( function ( $item ) {
332
-		return get_post( $item );
333
-	}, $ids );
331
+	return array_map(function($item) {
332
+		return get_post($item);
333
+	}, $ids);
334 334
 }
335 335
 
336 336
 ///**
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
  *
414 414
  * @return string|false String representing a sql statement, or false in case of error
415 415
  */
416
-function wl_core_sql_query_builder( $args ) {
416
+function wl_core_sql_query_builder($args) {
417 417
 
418 418
 	// Prepare interaction with db
419 419
 	global $wpdb;
@@ -439,12 +439,12 @@  discard block
 block discarded – undo
439 439
 	);
440 440
 
441 441
 	// Use "p" as the table to match the initial join.
442
-	$tax_sql = get_tax_sql( $tax_query, 'p', 'ID' );
442
+	$tax_sql = get_tax_sql($tax_query, 'p', 'ID');
443 443
 
444 444
 	// Sql Action
445 445
 	$sql = 'SELECT ';
446 446
 	// Determine what has to be returned depending on 'get' argument value
447
-	switch ( $args['get'] ) {
447
+	switch ($args['get']) {
448 448
 		case 'posts':
449 449
 			$sql .= 'p.*';
450 450
 			break;
@@ -454,20 +454,20 @@  discard block
 block discarded – undo
454 454
 	}
455 455
 
456 456
 	// If we look for posts related as objects the JOIN has to be done with the object_id column and viceversa
457
-	$join_column = $args['as'] . '_id';
457
+	$join_column = $args['as'].'_id';
458 458
 
459 459
 	$sql .= " FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.$join_column";
460 460
 
461 461
 	// Changing left join generate by the tax query into an inner since the term relationship has to exist.
462
-	$sql .= str_replace( 'LEFT JOIN', 'INNER JOIN', $tax_sql['join'] );
462
+	$sql .= str_replace('LEFT JOIN', 'INNER JOIN', $tax_sql['join']);
463 463
 
464 464
 	// Sql add post type filter
465 465
 	$post_types = Wordlift_Entity_Service::valid_entity_post_types();
466
-	$sql        .= " AND p.post_type IN ('" . join( "', '", esc_sql( $post_types ) ) . "') AND";
466
+	$sql .= " AND p.post_type IN ('".join("', '", esc_sql($post_types))."') AND";
467 467
 
468 468
 	// Sql add post status filter
469
-	if ( isset( $args['post_status'] ) && ! is_null( $args['post_status'] ) ) {
470
-		$sql .= $wpdb->prepare( ' p.post_status = %s AND', $args['post_status'] );
469
+	if (isset($args['post_status']) && ! is_null($args['post_status'])) {
470
+		$sql .= $wpdb->prepare(' p.post_status = %s AND', $args['post_status']);
471 471
 	}
472 472
 
473 473
 	// Add filtering conditions
@@ -476,29 +476,29 @@  discard block
 block discarded – undo
476 476
 	// If we look for posts related as subject this means that
477 477
 	// related_to is reference for an object: object_id is the filtering column
478 478
 
479
-	$filtering_column = ( 'object' == $args['as'] ) ? 'subject_id' : 'object_id';
479
+	$filtering_column = ('object' == $args['as']) ? 'subject_id' : 'object_id';
480 480
 
481
-	if ( isset( $args['related_to'] ) ) {
482
-		$sql .= $wpdb->prepare( " r.$filtering_column = %d", $args['related_to'] );
481
+	if (isset($args['related_to'])) {
482
+		$sql .= $wpdb->prepare(" r.$filtering_column = %d", $args['related_to']);
483 483
 	}
484
-	if ( isset( $args['related_to'] ) && isset( $args['related_to__in'] ) ) {
484
+	if (isset($args['related_to']) && isset($args['related_to__in'])) {
485 485
 		$sql .= ' AND';
486 486
 	}
487
-	if ( isset( $args['related_to__in'] ) ) {
488
-		$sql .= " r.$filtering_column IN (" . implode( ',', $args['related_to__in'] ) . ')';
487
+	if (isset($args['related_to__in'])) {
488
+		$sql .= " r.$filtering_column IN (".implode(',', $args['related_to__in']).')';
489 489
 		// The IDs used for filtering shouldn't be in the results.
490
-		$sql .= " AND p.ID NOT IN (" . implode( ',', $args['related_to__in'] ) . ')';
490
+		$sql .= " AND p.ID NOT IN (".implode(',', $args['related_to__in']).')';
491 491
 	}
492
-	if ( isset( $args['post__not_in'] ) ) {
493
-		$sql .= ' AND r.' . $args['as'] . '_id NOT IN (' . implode( ',', $args['post__not_in'] ) . ')';
492
+	if (isset($args['post__not_in'])) {
493
+		$sql .= ' AND r.'.$args['as'].'_id NOT IN ('.implode(',', $args['post__not_in']).')';
494 494
 	}
495
-	if ( isset( $args['post__in'] ) ) {
496
-		$sql .= ' AND r.' . $args['as'] . '_id IN (' . implode( ',', $args['post__in'] ) . ')';
495
+	if (isset($args['post__in'])) {
496
+		$sql .= ' AND r.'.$args['as'].'_id IN ('.implode(',', $args['post__in']).')';
497 497
 	}
498 498
 	// Add predicate filter if required.
499
-	if ( isset( $args['with_predicate'] ) ) {
499
+	if (isset($args['with_predicate'])) {
500 500
 		// Sql Inner Join clause.
501
-		$sql .= $wpdb->prepare( ' AND r.predicate = %s', $args['with_predicate'] );
501
+		$sql .= $wpdb->prepare(' AND r.predicate = %s', $args['with_predicate']);
502 502
 	}
503 503
 
504 504
 	// Add the taxonomy related sql.
@@ -509,9 +509,9 @@  discard block
 block discarded – undo
509 509
 	$sql .= ' GROUP BY p.id';
510 510
 
511 511
 	// @todo: how does `first` represent the limit?
512
-	if ( isset( $args['first'] ) && is_numeric( $args['first'] ) ) {
512
+	if (isset($args['first']) && is_numeric($args['first'])) {
513 513
 		// Sql Inner Join clause.
514
-		$sql .= $wpdb->prepare( ' LIMIT %d', $args['first'] );
514
+		$sql .= $wpdb->prepare(' LIMIT %d', $args['first']);
515 515
 	}
516 516
 	// Close sql statement
517 517
 	$sql .= ';';
@@ -532,23 +532,23 @@  discard block
 block discarded – undo
532 532
  *
533 533
  * @return array|false List of WP_Post objects or list of WP_Post ids. False in case of error or invalid params
534 534
  */
535
-function wl_core_get_posts( $args, $returned_type = OBJECT ) {
535
+function wl_core_get_posts($args, $returned_type = OBJECT) {
536 536
 
537 537
 	// Merge given args with defaults args value
538
-	$args = array_merge( array(
538
+	$args = array_merge(array(
539 539
 		'with_predicate' => null,
540 540
 		'as'             => 'subject',
541 541
 		'post_type'      => 'post',
542 542
 		'get'            => 'posts',
543 543
 		'post_status'    => null,
544
-	), $args );
544
+	), $args);
545 545
 
546 546
 	// Arguments validation rules
547 547
 	// At least one between related_to and related_to__in has to be set
548
-	if ( ! isset( $args['related_to'] ) && ! isset( $args['related_to__in'] ) ) {
548
+	if ( ! isset($args['related_to']) && ! isset($args['related_to__in'])) {
549 549
 		return false;
550 550
 	}
551
-	if ( isset( $args['related_to'] ) && ! is_numeric( $args['related_to'] ) ) {
551
+	if (isset($args['related_to']) && ! is_numeric($args['related_to'])) {
552 552
 		return false;
553 553
 	}
554 554
 
@@ -562,18 +562,18 @@  discard block
 block discarded – undo
562 562
 			'related_to__in',
563 563
 		) as $option_name
564 564
 	) {
565
-		if ( isset( $args[ $option_name ] ) ) {
566
-			if ( ! is_array( $args[ $option_name ] ) || 0 == count( array_filter( $args[ $option_name ], "is_numeric" ) ) ) {
565
+		if (isset($args[$option_name])) {
566
+			if ( ! is_array($args[$option_name]) || 0 == count(array_filter($args[$option_name], "is_numeric"))) {
567 567
 				return false;
568 568
 			}
569 569
 			// Sanitize value removing non numeric values from the array
570
-			$args[ $option_name ] = array_filter( $args[ $option_name ], "is_numeric" );
570
+			$args[$option_name] = array_filter($args[$option_name], "is_numeric");
571 571
 		}
572 572
 	}
573 573
 	// Performing validation rules
574
-	foreach ( wl_core_get_validation_rules() as $option_name => $accepeted_values ) {
575
-		if ( isset( $args[ $option_name ] ) && ! is_null( $args[ $option_name ] ) ) {
576
-			if ( ! in_array( $args[ $option_name ], $accepeted_values ) ) {
574
+	foreach (wl_core_get_validation_rules() as $option_name => $accepeted_values) {
575
+		if (isset($args[$option_name]) && ! is_null($args[$option_name])) {
576
+			if ( ! in_array($args[$option_name], $accepeted_values)) {
577 577
 				return false;
578 578
 			}
579 579
 		}
@@ -583,18 +583,18 @@  discard block
 block discarded – undo
583 583
 	global $wpdb;
584 584
 
585 585
 	// Build sql statement with given arguments
586
-	$sql_statement = wl_core_sql_query_builder( $args );
586
+	$sql_statement = wl_core_sql_query_builder($args);
587 587
 
588 588
 	// If ids are required, returns a one-dimensional array containing ids.
589 589
 	// Otherwise an array of associative arrays representing the post | relation object
590
-	if ( 'post_ids' == $args['get'] ) {
590
+	if ('post_ids' == $args['get']) {
591 591
 		# See https://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Column
592
-		$results = $wpdb->get_col( $sql_statement );
592
+		$results = $wpdb->get_col($sql_statement);
593 593
 	} else {
594
-		$results = $wpdb->get_results( $sql_statement, $returned_type );
594
+		$results = $wpdb->get_results($sql_statement, $returned_type);
595 595
 	}
596 596
 	// If there were an error performing the query then false is returned
597
-	if ( ! empty( $wpdb->last_error ) ) {
597
+	if ( ! empty($wpdb->last_error)) {
598 598
 		return false;
599 599
 	}
600 600
 
Please login to merge, or discard this patch.
src/modules/linked_data/wordlift_linked_data.php 2 patches
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -18,19 +18,19 @@  discard block
 block discarded – undo
18 18
  */
19 19
 function wl_linked_data_save_post( $post_id ) {
20 20
 
21
-	// If it's not numeric exit from here.
22
-	if ( ! is_numeric( $post_id ) || is_numeric( wp_is_post_revision( $post_id ) ) ) {
23
-		return;
24
-	}
21
+    // If it's not numeric exit from here.
22
+    if ( ! is_numeric( $post_id ) || is_numeric( wp_is_post_revision( $post_id ) ) ) {
23
+        return;
24
+    }
25 25
 
26
-	// unhook this function so it doesn't loop infinitely
27
-	remove_action( 'save_post', 'wl_linked_data_save_post' );
26
+    // unhook this function so it doesn't loop infinitely
27
+    remove_action( 'save_post', 'wl_linked_data_save_post' );
28 28
 
29
-	// raise the *wl_linked_data_save_post* event.
30
-	do_action( 'wl_linked_data_save_post', $post_id );
29
+    // raise the *wl_linked_data_save_post* event.
30
+    do_action( 'wl_linked_data_save_post', $post_id );
31 31
 
32
-	// re-hook this function
33
-	add_action( 'save_post', 'wl_linked_data_save_post' );
32
+    // re-hook this function
33
+    add_action( 'save_post', 'wl_linked_data_save_post' );
34 34
 }
35 35
 
36 36
 add_action( 'save_post', 'wl_linked_data_save_post' );
@@ -44,143 +44,143 @@  discard block
 block discarded – undo
44 44
  */
45 45
 function wl_linked_data_save_post_and_related_entities( $post_id ) {
46 46
 
47
-	// Ignore auto-saves
48
-	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
49
-		return;
50
-	}
47
+    // Ignore auto-saves
48
+    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
49
+        return;
50
+    }
51 51
 
52
-	// get the current post.
53
-	$post = get_post( $post_id );
52
+    // get the current post.
53
+    $post = get_post( $post_id );
54 54
 
55
-	remove_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
55
+    remove_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
56 56
 
57
-	// wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" );
57
+    // wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" );
58 58
 
59
-	// Store mapping between tmp new entities uris and real new entities uri
60
-	$entities_uri_mapping = array();
59
+    // Store mapping between tmp new entities uris and real new entities uri
60
+    $entities_uri_mapping = array();
61 61
 
62
-	// Save the entities coming with POST data.
63
-	if ( isset( $_POST['wl_entities'] ) && isset( $_POST['wl_boxes'] ) ) {
62
+    // Save the entities coming with POST data.
63
+    if ( isset( $_POST['wl_entities'] ) && isset( $_POST['wl_boxes'] ) ) {
64 64
 
65
-		wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " );
66
-		wl_write_log( json_encode( $_POST['wl_entities'] ) );
67
-		wl_write_log( "]" );
68
-		wl_write_log( "[ post id :: $post_id ][ POST(wl_boxes) :: " );
69
-		wl_write_log( json_encode( $_POST['wl_boxes'], true ) );
70
-		wl_write_log( "]" );
65
+        wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " );
66
+        wl_write_log( json_encode( $_POST['wl_entities'] ) );
67
+        wl_write_log( "]" );
68
+        wl_write_log( "[ post id :: $post_id ][ POST(wl_boxes) :: " );
69
+        wl_write_log( json_encode( $_POST['wl_boxes'], true ) );
70
+        wl_write_log( "]" );
71 71
 
72
-		$entities_via_post = $_POST['wl_entities'];
73
-		$boxes_via_post    = $_POST['wl_boxes'];
72
+        $entities_via_post = $_POST['wl_entities'];
73
+        $boxes_via_post    = $_POST['wl_boxes'];
74 74
 
75
-		foreach ( $entities_via_post as $entity_uri => $entity ) {
75
+        foreach ( $entities_via_post as $entity_uri => $entity ) {
76 76
 
77
-			// Only if the current entity is created from scratch let's avoid to
78
-			// create more than one entity with same label & entity type.
79
-			$entity_type = ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) ?
80
-				$entity['main_type'] : null;
81
-
82
-			// Look if current entity uri matches an internal existing entity, meaning:
83
-			// 1. when $entity_uri is an internal uri
84
-			// 2. when $entity_uri is an external uri used as sameAs of an internal entity
85
-			$ie = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $entity_uri );
77
+            // Only if the current entity is created from scratch let's avoid to
78
+            // create more than one entity with same label & entity type.
79
+            $entity_type = ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) ?
80
+                $entity['main_type'] : null;
81
+
82
+            // Look if current entity uri matches an internal existing entity, meaning:
83
+            // 1. when $entity_uri is an internal uri
84
+            // 2. when $entity_uri is an external uri used as sameAs of an internal entity
85
+            $ie = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $entity_uri );
86 86
 
87
-			// Detect the uri depending if is an existing or a new entity
88
-			$uri = ( null === $ie ) ?
89
-				Wordlift_Uri_Service::get_instance()->build_uri(
90
-					$entity['label'],
91
-					Wordlift_Entity_Service::TYPE_NAME,
92
-					$entity_type
93
-				) : wl_get_entity_uri( $ie->ID );
87
+            // Detect the uri depending if is an existing or a new entity
88
+            $uri = ( null === $ie ) ?
89
+                Wordlift_Uri_Service::get_instance()->build_uri(
90
+                    $entity['label'],
91
+                    Wordlift_Entity_Service::TYPE_NAME,
92
+                    $entity_type
93
+                ) : wl_get_entity_uri( $ie->ID );
94 94
 
95
-			wl_write_log( "Map $entity_uri on $uri" );
96
-			$entities_uri_mapping[ $entity_uri ] = $uri;
95
+            wl_write_log( "Map $entity_uri on $uri" );
96
+            $entities_uri_mapping[ $entity_uri ] = $uri;
97 97
 
98
-			// Local entities have a tmp uri with 'local-entity-' prefix
99
-			// These uris need to be rewritten here and replaced in the content
100
-			if ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) {
101
-				// Override the entity obj
102
-				$entity['uri'] = $uri;
103
-			}
98
+            // Local entities have a tmp uri with 'local-entity-' prefix
99
+            // These uris need to be rewritten here and replaced in the content
100
+            if ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) {
101
+                // Override the entity obj
102
+                $entity['uri'] = $uri;
103
+            }
104 104
 
105
-			// Update entity data with related post
106
-			$entity['related_post_id'] = $post_id;
105
+            // Update entity data with related post
106
+            $entity['related_post_id'] = $post_id;
107 107
 
108
-			// Save the entity if is a new entity
109
-			if ( null === $ie ) {
110
-				wl_save_entity( $entity );
111
-			}
108
+            // Save the entity if is a new entity
109
+            if ( null === $ie ) {
110
+                wl_save_entity( $entity );
111
+            }
112 112
 
113
-		}
113
+        }
114 114
 
115
-	}
115
+    }
116 116
 
117
-	// Replace tmp uris in content post if needed
118
-	$updated_post_content = $post->post_content;
119
-	// Save each entity and store the post id.
120
-	foreach ( $entities_uri_mapping as $tmp_uri => $uri ) {
121
-		$updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content );
122
-	}
117
+    // Replace tmp uris in content post if needed
118
+    $updated_post_content = $post->post_content;
119
+    // Save each entity and store the post id.
120
+    foreach ( $entities_uri_mapping as $tmp_uri => $uri ) {
121
+        $updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content );
122
+    }
123 123
 
124
-	// Update the post content
125
-	wp_update_post( array(
126
-		'ID'           => $post->ID,
127
-		'post_content' => $updated_post_content,
128
-	) );
124
+    // Update the post content
125
+    wp_update_post( array(
126
+        'ID'           => $post->ID,
127
+        'post_content' => $updated_post_content,
128
+    ) );
129 129
 
130
-	// Extract related/referenced entities from text.
131
-	$disambiguated_entities = wl_linked_data_content_get_embedded_entities( $updated_post_content );
130
+    // Extract related/referenced entities from text.
131
+    $disambiguated_entities = wl_linked_data_content_get_embedded_entities( $updated_post_content );
132 132
 
133
-	// Reset previously saved instances
134
-	wl_core_delete_relation_instances( $post_id );
133
+    // Reset previously saved instances
134
+    wl_core_delete_relation_instances( $post_id );
135 135
 
136
-	// Save relation instances
137
-	foreach ( array_unique( $disambiguated_entities ) as $referenced_entity_id ) {
136
+    // Save relation instances
137
+    foreach ( array_unique( $disambiguated_entities ) as $referenced_entity_id ) {
138 138
 
139
-		wl_core_add_relation_instance(
140
-			$post_id,
141
-			Wordlift_Entity_Service::get_instance()->get_classification_scope_for( $referenced_entity_id ),
142
-			$referenced_entity_id
143
-		);
139
+        wl_core_add_relation_instance(
140
+            $post_id,
141
+            Wordlift_Entity_Service::get_instance()->get_classification_scope_for( $referenced_entity_id ),
142
+            $referenced_entity_id
143
+        );
144 144
 
145
-	}
145
+    }
146 146
 
147
-	if ( isset( $_POST['wl_entities'] ) ) {
148
-		// Save post metadata if available
149
-		$metadata_via_post = ( isset( $_POST['wl_metadata'] ) ) ?
150
-			$_POST['wl_metadata'] : array();
147
+    if ( isset( $_POST['wl_entities'] ) ) {
148
+        // Save post metadata if available
149
+        $metadata_via_post = ( isset( $_POST['wl_metadata'] ) ) ?
150
+            $_POST['wl_metadata'] : array();
151 151
 
152
-		$fields = array(
153
-			Wordlift_Schema_Service::FIELD_LOCATION_CREATED,
154
-			Wordlift_Schema_Service::FIELD_TOPIC,
155
-		);
156
-
157
-		// Unlink topic taxonomy terms
158
-		Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for( $post->ID );
159
-
160
-		foreach ( $fields as $field ) {
161
-
162
-			// Delete current values
163
-			delete_post_meta( $post->ID, $field );
164
-			// Retrieve the entity uri
165
-			$uri = ( isset( $metadata_via_post[ $field ] ) ) ?
166
-				stripslashes( $metadata_via_post[ $field ] ) : '';
167
-
168
-			$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri );
169
-
170
-			if ( $entity ) {
171
-				add_post_meta( $post->ID, $field, $entity->ID, true );
172
-				// Set also the topic taxonomy
173
-				if ( $field === Wordlift_Schema_Service::FIELD_TOPIC ) {
174
-					Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for( $post->ID, $entity );
175
-				}
176
-			}
177
-		}
178
-	}
179
-
180
-	// Push the post to Redlink.
181
-	Wordlift_Linked_Data_Service::get_instance()->push( $post->ID );
182
-
183
-	add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
152
+        $fields = array(
153
+            Wordlift_Schema_Service::FIELD_LOCATION_CREATED,
154
+            Wordlift_Schema_Service::FIELD_TOPIC,
155
+        );
156
+
157
+        // Unlink topic taxonomy terms
158
+        Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for( $post->ID );
159
+
160
+        foreach ( $fields as $field ) {
161
+
162
+            // Delete current values
163
+            delete_post_meta( $post->ID, $field );
164
+            // Retrieve the entity uri
165
+            $uri = ( isset( $metadata_via_post[ $field ] ) ) ?
166
+                stripslashes( $metadata_via_post[ $field ] ) : '';
167
+
168
+            $entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri );
169
+
170
+            if ( $entity ) {
171
+                add_post_meta( $post->ID, $field, $entity->ID, true );
172
+                // Set also the topic taxonomy
173
+                if ( $field === Wordlift_Schema_Service::FIELD_TOPIC ) {
174
+                    Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for( $post->ID, $entity );
175
+                }
176
+            }
177
+        }
178
+    }
179
+
180
+    // Push the post to Redlink.
181
+    Wordlift_Linked_Data_Service::get_instance()->push( $post->ID );
182
+
183
+    add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
184 184
 }
185 185
 
186 186
 add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
@@ -203,185 +203,185 @@  discard block
 block discarded – undo
203 203
  */
204 204
 function wl_save_entity( $entity_data ) {
205 205
 
206
-	$uri              = $entity_data['uri'];
207
-	$label            = $entity_data['label'];
208
-	$type_uri         = $entity_data['main_type'];
209
-	$entity_types     = isset( $entity_data['type'] ) ? $entity_data['type'] : array();
210
-	$description      = $entity_data['description'];
211
-	$images           = isset( $entity_data['image'] ) ? (array) $entity_data['image'] : array();
212
-	$same_as          = isset( $entity_data['sameas'] ) ? (array) $entity_data['sameas'] : array();
213
-	$related_post_id  = isset( $entity_data['related_post_id'] ) ? $entity_data['related_post_id'] : null;
214
-	$other_properties = isset( $entity_data['properties'] ) ? $entity_data['properties'] : array();
215
-
216
-	// Get the synonyms.
217
-	$synonyms = isset( $entity_data['synonym'] ) ? $entity_data['synonym'] : array();
218
-
219
-	// Check whether an entity already exists with the provided URI.
220
-	if ( null !== $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri ) ) {
221
-		return $post;
222
-	}
223
-
224
-	// Prepare properties of the new entity.
225
-	$params = array(
226
-		'post_status'  => ( is_numeric( $related_post_id ) ? get_post_status( $related_post_id ) : 'draft' ),
227
-		'post_type'    => Wordlift_Entity_Service::TYPE_NAME,
228
-		'post_title'   => $label,
229
-		'post_content' => $description,
230
-		'post_excerpt' => '',
231
-		// Ensure we're using a valid slug. We're not overwriting an existing
232
-		// entity with a post_name already set, since this call is made only for
233
-		// new entities.
234
-		//
235
-		// See https://github.com/insideout10/wordlift-plugin/issues/282
236
-		'post_name'    => sanitize_title( $label ),
237
-	);
238
-
239
-	// If Yoast is installed and active, we temporary remove the save_postdata hook which causes Yoast to "pass over"
240
-	// the local SEO form values to the created entity (https://github.com/insideout10/wordlift-plugin/issues/156)
241
-	// Same thing applies to SEO Ultimate (https://github.com/insideout10/wordlift-plugin/issues/148)
242
-	// This does NOT affect saving an entity from the entity admin page since this function is called when an entity
243
-	// is created when saving a post.
244
-	global $wpseo_metabox, $seo_ultimate;
245
-	if ( isset( $wpseo_metabox ) ) {
246
-		remove_action( 'wp_insert_post', array(
247
-			$wpseo_metabox,
248
-			'save_postdata',
249
-		) );
250
-	}
251
-
252
-	if ( isset( $seo_ultimate ) ) {
253
-		remove_action( 'save_post', array(
254
-			$seo_ultimate,
255
-			'save_postmeta_box',
256
-		) );
257
-	}
258
-
259
-	// The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to
260
-	// save_post in order to save additional inputs from the edit page. In order to avoid issues, we pop all the hooks
261
-	// to the save_post and restore them after we saved the entity.
262
-	// see https://github.com/insideout10/wordlift-plugin/issues/203
263
-	// see https://github.com/insideout10/wordlift-plugin/issues/156
264
-	// see https://github.com/insideout10/wordlift-plugin/issues/148
265
-	global $wp_filter;
266
-	$save_post_filters = is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks;
267
-	is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters();
268
-
269
-	// create or update the post.
270
-	$post_id = wp_insert_post( $params, true );
271
-
272
-	// Setting the alternative labels for this entity.
273
-	Wordlift_Entity_Service::get_instance()
274
-	                       ->set_alternative_labels( $post_id, $synonyms );
275
-
276
-	// Restore all the existing filters.
277
-	is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters;
278
-
279
-	// If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156)
280
-	if ( isset( $wpseo_metabox ) ) {
281
-		add_action( 'wp_insert_post', array(
282
-			$wpseo_metabox,
283
-			'save_postdata',
284
-		) );
285
-	}
286
-
287
-	// If SEO Ultimate is installed, add back the hook we removed a few lines above.
288
-	if ( isset( $seo_ultimate ) ) {
289
-		add_action( 'save_post', array(
290
-			$seo_ultimate,
291
-			'save_postmeta_box',
292
-		), 10, 2 );
293
-	}
294
-
295
-	// TODO: handle errors.
296
-	if ( is_wp_error( $post_id ) ) {
297
-		wl_write_log( ': error occurred' );
298
-
299
-		// inform an error occurred.
300
-		return null;
301
-	}
302
-
303
-	wl_set_entity_main_type( $post_id, $type_uri );
304
-
305
-	// Save the entity types.
306
-	wl_set_entity_rdf_types( $post_id, $entity_types );
307
-
308
-	// Get a dataset URI for the entity.
309
-	$wl_uri = wl_build_entity_uri( $post_id );
310
-
311
-	// Save the entity URI.
312
-	wl_set_entity_uri( $post_id, $wl_uri );
313
-
314
-	// Add the uri to the sameAs data if it's not a local URI.
315
-	if ( $wl_uri !== $uri ) {
316
-		array_push( $same_as, $uri );
317
-	}
318
-
319
-	$new_uri = wl_get_entity_uri( $post_id );
320
-
321
-	// Save the sameAs data for the entity.
322
-	wl_schema_set_value( $post_id, 'sameAs', $same_as );
323
-
324
-	// Save the other properties (latitude, langitude, startDate, endDate, etc.)
325
-	foreach ( $other_properties as $property_name => $property_value ) {
326
-		wl_schema_set_value( $post_id, $property_name, $property_value );
327
-	}
328
-
329
-	// Call hooks.
330
-	do_action( 'wl_save_entity', $post_id );
331
-
332
-	foreach ( $images as $image_remote_url ) {
333
-
334
-		// Check if image is already present in local DB
335
-		if ( strpos( $image_remote_url, site_url() ) !== false ) {
336
-			// Do nothing.
337
-			continue;
338
-		}
339
-
340
-		// Check if there is an existing attachment for this post ID and source URL.
341
-		$existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url );
342
-
343
-		// Skip if an existing image is found.
344
-		if ( null !== $existing_image ) {
345
-			continue;
346
-		}
347
-
348
-		// Save the image and get the local path.
349
-		$image = wl_save_image( $image_remote_url );
350
-
351
-		// Get the local URL.
352
-		$filename     = $image['path'];
353
-		$url          = $image['url'];
354
-		$content_type = $image['content_type'];
355
-
356
-		$attachment = array(
357
-			'guid'           => $url,
358
-			// post_title, post_content (the value for this key should be the empty string), post_status and post_mime_type
359
-			'post_title'     => $label,
360
-			// Set the title to the post title.
361
-			'post_content'   => '',
362
-			'post_status'    => 'inherit',
363
-			'post_mime_type' => $content_type,
364
-		);
365
-
366
-		// Create the attachment in WordPress and generate the related metadata.
367
-		$attachment_id = wp_insert_attachment( $attachment, $filename, $post_id );
206
+    $uri              = $entity_data['uri'];
207
+    $label            = $entity_data['label'];
208
+    $type_uri         = $entity_data['main_type'];
209
+    $entity_types     = isset( $entity_data['type'] ) ? $entity_data['type'] : array();
210
+    $description      = $entity_data['description'];
211
+    $images           = isset( $entity_data['image'] ) ? (array) $entity_data['image'] : array();
212
+    $same_as          = isset( $entity_data['sameas'] ) ? (array) $entity_data['sameas'] : array();
213
+    $related_post_id  = isset( $entity_data['related_post_id'] ) ? $entity_data['related_post_id'] : null;
214
+    $other_properties = isset( $entity_data['properties'] ) ? $entity_data['properties'] : array();
215
+
216
+    // Get the synonyms.
217
+    $synonyms = isset( $entity_data['synonym'] ) ? $entity_data['synonym'] : array();
218
+
219
+    // Check whether an entity already exists with the provided URI.
220
+    if ( null !== $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri ) ) {
221
+        return $post;
222
+    }
223
+
224
+    // Prepare properties of the new entity.
225
+    $params = array(
226
+        'post_status'  => ( is_numeric( $related_post_id ) ? get_post_status( $related_post_id ) : 'draft' ),
227
+        'post_type'    => Wordlift_Entity_Service::TYPE_NAME,
228
+        'post_title'   => $label,
229
+        'post_content' => $description,
230
+        'post_excerpt' => '',
231
+        // Ensure we're using a valid slug. We're not overwriting an existing
232
+        // entity with a post_name already set, since this call is made only for
233
+        // new entities.
234
+        //
235
+        // See https://github.com/insideout10/wordlift-plugin/issues/282
236
+        'post_name'    => sanitize_title( $label ),
237
+    );
238
+
239
+    // If Yoast is installed and active, we temporary remove the save_postdata hook which causes Yoast to "pass over"
240
+    // the local SEO form values to the created entity (https://github.com/insideout10/wordlift-plugin/issues/156)
241
+    // Same thing applies to SEO Ultimate (https://github.com/insideout10/wordlift-plugin/issues/148)
242
+    // This does NOT affect saving an entity from the entity admin page since this function is called when an entity
243
+    // is created when saving a post.
244
+    global $wpseo_metabox, $seo_ultimate;
245
+    if ( isset( $wpseo_metabox ) ) {
246
+        remove_action( 'wp_insert_post', array(
247
+            $wpseo_metabox,
248
+            'save_postdata',
249
+        ) );
250
+    }
251
+
252
+    if ( isset( $seo_ultimate ) ) {
253
+        remove_action( 'save_post', array(
254
+            $seo_ultimate,
255
+            'save_postmeta_box',
256
+        ) );
257
+    }
258
+
259
+    // The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to
260
+    // save_post in order to save additional inputs from the edit page. In order to avoid issues, we pop all the hooks
261
+    // to the save_post and restore them after we saved the entity.
262
+    // see https://github.com/insideout10/wordlift-plugin/issues/203
263
+    // see https://github.com/insideout10/wordlift-plugin/issues/156
264
+    // see https://github.com/insideout10/wordlift-plugin/issues/148
265
+    global $wp_filter;
266
+    $save_post_filters = is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks;
267
+    is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters();
268
+
269
+    // create or update the post.
270
+    $post_id = wp_insert_post( $params, true );
271
+
272
+    // Setting the alternative labels for this entity.
273
+    Wordlift_Entity_Service::get_instance()
274
+                            ->set_alternative_labels( $post_id, $synonyms );
275
+
276
+    // Restore all the existing filters.
277
+    is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters;
278
+
279
+    // If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156)
280
+    if ( isset( $wpseo_metabox ) ) {
281
+        add_action( 'wp_insert_post', array(
282
+            $wpseo_metabox,
283
+            'save_postdata',
284
+        ) );
285
+    }
286
+
287
+    // If SEO Ultimate is installed, add back the hook we removed a few lines above.
288
+    if ( isset( $seo_ultimate ) ) {
289
+        add_action( 'save_post', array(
290
+            $seo_ultimate,
291
+            'save_postmeta_box',
292
+        ), 10, 2 );
293
+    }
294
+
295
+    // TODO: handle errors.
296
+    if ( is_wp_error( $post_id ) ) {
297
+        wl_write_log( ': error occurred' );
298
+
299
+        // inform an error occurred.
300
+        return null;
301
+    }
302
+
303
+    wl_set_entity_main_type( $post_id, $type_uri );
304
+
305
+    // Save the entity types.
306
+    wl_set_entity_rdf_types( $post_id, $entity_types );
307
+
308
+    // Get a dataset URI for the entity.
309
+    $wl_uri = wl_build_entity_uri( $post_id );
310
+
311
+    // Save the entity URI.
312
+    wl_set_entity_uri( $post_id, $wl_uri );
313
+
314
+    // Add the uri to the sameAs data if it's not a local URI.
315
+    if ( $wl_uri !== $uri ) {
316
+        array_push( $same_as, $uri );
317
+    }
318
+
319
+    $new_uri = wl_get_entity_uri( $post_id );
320
+
321
+    // Save the sameAs data for the entity.
322
+    wl_schema_set_value( $post_id, 'sameAs', $same_as );
323
+
324
+    // Save the other properties (latitude, langitude, startDate, endDate, etc.)
325
+    foreach ( $other_properties as $property_name => $property_value ) {
326
+        wl_schema_set_value( $post_id, $property_name, $property_value );
327
+    }
328
+
329
+    // Call hooks.
330
+    do_action( 'wl_save_entity', $post_id );
331
+
332
+    foreach ( $images as $image_remote_url ) {
333
+
334
+        // Check if image is already present in local DB
335
+        if ( strpos( $image_remote_url, site_url() ) !== false ) {
336
+            // Do nothing.
337
+            continue;
338
+        }
339
+
340
+        // Check if there is an existing attachment for this post ID and source URL.
341
+        $existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url );
342
+
343
+        // Skip if an existing image is found.
344
+        if ( null !== $existing_image ) {
345
+            continue;
346
+        }
347
+
348
+        // Save the image and get the local path.
349
+        $image = wl_save_image( $image_remote_url );
350
+
351
+        // Get the local URL.
352
+        $filename     = $image['path'];
353
+        $url          = $image['url'];
354
+        $content_type = $image['content_type'];
355
+
356
+        $attachment = array(
357
+            'guid'           => $url,
358
+            // post_title, post_content (the value for this key should be the empty string), post_status and post_mime_type
359
+            'post_title'     => $label,
360
+            // Set the title to the post title.
361
+            'post_content'   => '',
362
+            'post_status'    => 'inherit',
363
+            'post_mime_type' => $content_type,
364
+        );
365
+
366
+        // Create the attachment in WordPress and generate the related metadata.
367
+        $attachment_id = wp_insert_attachment( $attachment, $filename, $post_id );
368 368
 
369
-		// Set the source URL for the image.
370
-		wl_set_source_url( $attachment_id, $image_remote_url );
369
+        // Set the source URL for the image.
370
+        wl_set_source_url( $attachment_id, $image_remote_url );
371 371
 
372
-		$attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
373
-		wp_update_attachment_metadata( $attachment_id, $attachment_data );
372
+        $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
373
+        wp_update_attachment_metadata( $attachment_id, $attachment_data );
374 374
 
375
-		// Set it as the featured image.
376
-		set_post_thumbnail( $post_id, $attachment_id );
377
-	}
375
+        // Set it as the featured image.
376
+        set_post_thumbnail( $post_id, $attachment_id );
377
+    }
378 378
 
379
-	// The entity is pushed to Redlink on save by the function hooked to save_post.
380
-	// save the entity in the triple store.
381
-	Wordlift_Linked_Data_Service::get_instance()->push( $post_id );
379
+    // The entity is pushed to Redlink on save by the function hooked to save_post.
380
+    // save the entity in the triple store.
381
+    Wordlift_Linked_Data_Service::get_instance()->push( $post_id );
382 382
 
383
-	// finally return the entity post.
384
-	return get_post( $post_id );
383
+    // finally return the entity post.
384
+    return get_post( $post_id );
385 385
 }
386 386
 
387 387
 /**
@@ -395,40 +395,40 @@  discard block
 block discarded – undo
395 395
  */
396 396
 function wl_linked_data_content_get_embedded_entities( $content ) {
397 397
 
398
-	// Remove quote escapes.
399
-	$content = str_replace( '\\"', '"', $content );
398
+    // Remove quote escapes.
399
+    $content = str_replace( '\\"', '"', $content );
400 400
 
401
-	// Match all itemid attributes.
402
-	$pattern = '/<\w+[^>]*\sitemid="([^"]+)"[^>]*>/im';
401
+    // Match all itemid attributes.
402
+    $pattern = '/<\w+[^>]*\sitemid="([^"]+)"[^>]*>/im';
403 403
 
404
-	//	wl_write_log( "Getting entities embedded into content [ pattern :: $pattern ]" );
404
+    //	wl_write_log( "Getting entities embedded into content [ pattern :: $pattern ]" );
405 405
 
406
-	// Remove the pattern while it is found (match nested annotations).
407
-	$matches = array();
406
+    // Remove the pattern while it is found (match nested annotations).
407
+    $matches = array();
408 408
 
409
-	// In case of errors, return an empty array.
410
-	if ( false === preg_match_all( $pattern, $content, $matches ) ) {
411
-		wl_write_log( "Found no entities embedded in content" );
409
+    // In case of errors, return an empty array.
410
+    if ( false === preg_match_all( $pattern, $content, $matches ) ) {
411
+        wl_write_log( "Found no entities embedded in content" );
412 412
 
413
-		return array();
414
-	}
413
+        return array();
414
+    }
415 415
 
416 416
 //    wl_write_log("wl_update_related_entities [ content :: $content ][ data :: " . var_export($data, true). " ][ matches :: " . var_export($matches, true) . " ]");
417 417
 
418
-	// Collect the entities.
419
-	$entities = array();
420
-	foreach ( $matches[1] as $uri ) {
421
-		$uri_d = html_entity_decode( $uri );
418
+    // Collect the entities.
419
+    $entities = array();
420
+    foreach ( $matches[1] as $uri ) {
421
+        $uri_d = html_entity_decode( $uri );
422 422
 
423
-		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri_d );
423
+        $entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri_d );
424 424
 
425
-		if ( null !== $entity ) {
426
-			array_push( $entities, $entity->ID );
427
-		}
428
-	}
425
+        if ( null !== $entity ) {
426
+            array_push( $entities, $entity->ID );
427
+        }
428
+    }
429 429
 
430
-	// $count = sizeof( $entities );
431
-	// wl_write_log( "Found $count entities embedded in content" );
430
+    // $count = sizeof( $entities );
431
+    // wl_write_log( "Found $count entities embedded in content" );
432 432
 
433
-	return $entities;
433
+    return $entities;
434 434
 }
Please login to merge, or discard this patch.
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @subpackage Wordlift/modules/linked_data
8 8
  */
9 9
 
10
-require_once( 'wordlift_linked_data_images.php' );
10
+require_once('wordlift_linked_data_images.php');
11 11
 
12 12
 /**
13 13
  * Receive events from post saves, and split them according to the post type.
@@ -16,24 +16,24 @@  discard block
 block discarded – undo
16 16
  *
17 17
  * @param int $post_id The post id.
18 18
  */
19
-function wl_linked_data_save_post( $post_id ) {
19
+function wl_linked_data_save_post($post_id) {
20 20
 
21 21
 	// If it's not numeric exit from here.
22
-	if ( ! is_numeric( $post_id ) || is_numeric( wp_is_post_revision( $post_id ) ) ) {
22
+	if ( ! is_numeric($post_id) || is_numeric(wp_is_post_revision($post_id))) {
23 23
 		return;
24 24
 	}
25 25
 
26 26
 	// unhook this function so it doesn't loop infinitely
27
-	remove_action( 'save_post', 'wl_linked_data_save_post' );
27
+	remove_action('save_post', 'wl_linked_data_save_post');
28 28
 
29 29
 	// raise the *wl_linked_data_save_post* event.
30
-	do_action( 'wl_linked_data_save_post', $post_id );
30
+	do_action('wl_linked_data_save_post', $post_id);
31 31
 
32 32
 	// re-hook this function
33
-	add_action( 'save_post', 'wl_linked_data_save_post' );
33
+	add_action('save_post', 'wl_linked_data_save_post');
34 34
 }
35 35
 
36
-add_action( 'save_post', 'wl_linked_data_save_post' );
36
+add_action('save_post', 'wl_linked_data_save_post');
37 37
 
38 38
 /**
39 39
  * Save the post to the triple store. Also saves the entities locally and on the triple store.
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
  *
43 43
  * @param int $post_id The post id being saved.
44 44
  */
45
-function wl_linked_data_save_post_and_related_entities( $post_id ) {
45
+function wl_linked_data_save_post_and_related_entities($post_id) {
46 46
 
47 47
 	// Ignore auto-saves
48
-	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
48
+	if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
49 49
 		return;
50 50
 	}
51 51
 
52 52
 	// get the current post.
53
-	$post = get_post( $post_id );
53
+	$post = get_post($post_id);
54 54
 
55
-	remove_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
55
+	remove_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities');
56 56
 
57 57
 	// wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" );
58 58
 
@@ -60,44 +60,44 @@  discard block
 block discarded – undo
60 60
 	$entities_uri_mapping = array();
61 61
 
62 62
 	// Save the entities coming with POST data.
63
-	if ( isset( $_POST['wl_entities'] ) && isset( $_POST['wl_boxes'] ) ) {
63
+	if (isset($_POST['wl_entities']) && isset($_POST['wl_boxes'])) {
64 64
 
65
-		wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " );
66
-		wl_write_log( json_encode( $_POST['wl_entities'] ) );
67
-		wl_write_log( "]" );
68
-		wl_write_log( "[ post id :: $post_id ][ POST(wl_boxes) :: " );
69
-		wl_write_log( json_encode( $_POST['wl_boxes'], true ) );
70
-		wl_write_log( "]" );
65
+		wl_write_log("[ post id :: $post_id ][ POST(wl_entities) :: ");
66
+		wl_write_log(json_encode($_POST['wl_entities']));
67
+		wl_write_log("]");
68
+		wl_write_log("[ post id :: $post_id ][ POST(wl_boxes) :: ");
69
+		wl_write_log(json_encode($_POST['wl_boxes'], true));
70
+		wl_write_log("]");
71 71
 
72 72
 		$entities_via_post = $_POST['wl_entities'];
73 73
 		$boxes_via_post    = $_POST['wl_boxes'];
74 74
 
75
-		foreach ( $entities_via_post as $entity_uri => $entity ) {
75
+		foreach ($entities_via_post as $entity_uri => $entity) {
76 76
 
77 77
 			// Only if the current entity is created from scratch let's avoid to
78 78
 			// create more than one entity with same label & entity type.
79
-			$entity_type = ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) ?
79
+			$entity_type = (preg_match('/^local-entity-.+/', $entity_uri) > 0) ?
80 80
 				$entity['main_type'] : null;
81 81
 
82 82
 			// Look if current entity uri matches an internal existing entity, meaning:
83 83
 			// 1. when $entity_uri is an internal uri
84 84
 			// 2. when $entity_uri is an external uri used as sameAs of an internal entity
85
-			$ie = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $entity_uri );
85
+			$ie = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri($entity_uri);
86 86
 
87 87
 			// Detect the uri depending if is an existing or a new entity
88
-			$uri = ( null === $ie ) ?
88
+			$uri = (null === $ie) ?
89 89
 				Wordlift_Uri_Service::get_instance()->build_uri(
90 90
 					$entity['label'],
91 91
 					Wordlift_Entity_Service::TYPE_NAME,
92 92
 					$entity_type
93
-				) : wl_get_entity_uri( $ie->ID );
93
+				) : wl_get_entity_uri($ie->ID);
94 94
 
95
-			wl_write_log( "Map $entity_uri on $uri" );
96
-			$entities_uri_mapping[ $entity_uri ] = $uri;
95
+			wl_write_log("Map $entity_uri on $uri");
96
+			$entities_uri_mapping[$entity_uri] = $uri;
97 97
 
98 98
 			// Local entities have a tmp uri with 'local-entity-' prefix
99 99
 			// These uris need to be rewritten here and replaced in the content
100
-			if ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) {
100
+			if (preg_match('/^local-entity-.+/', $entity_uri) > 0) {
101 101
 				// Override the entity obj
102 102
 				$entity['uri'] = $uri;
103 103
 			}
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
 			$entity['related_post_id'] = $post_id;
107 107
 
108 108
 			// Save the entity if is a new entity
109
-			if ( null === $ie ) {
110
-				wl_save_entity( $entity );
109
+			if (null === $ie) {
110
+				wl_save_entity($entity);
111 111
 			}
112 112
 
113 113
 		}
@@ -117,36 +117,36 @@  discard block
 block discarded – undo
117 117
 	// Replace tmp uris in content post if needed
118 118
 	$updated_post_content = $post->post_content;
119 119
 	// Save each entity and store the post id.
120
-	foreach ( $entities_uri_mapping as $tmp_uri => $uri ) {
121
-		$updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content );
120
+	foreach ($entities_uri_mapping as $tmp_uri => $uri) {
121
+		$updated_post_content = str_replace($tmp_uri, $uri, $updated_post_content);
122 122
 	}
123 123
 
124 124
 	// Update the post content
125
-	wp_update_post( array(
125
+	wp_update_post(array(
126 126
 		'ID'           => $post->ID,
127 127
 		'post_content' => $updated_post_content,
128
-	) );
128
+	));
129 129
 
130 130
 	// Extract related/referenced entities from text.
131
-	$disambiguated_entities = wl_linked_data_content_get_embedded_entities( $updated_post_content );
131
+	$disambiguated_entities = wl_linked_data_content_get_embedded_entities($updated_post_content);
132 132
 
133 133
 	// Reset previously saved instances
134
-	wl_core_delete_relation_instances( $post_id );
134
+	wl_core_delete_relation_instances($post_id);
135 135
 
136 136
 	// Save relation instances
137
-	foreach ( array_unique( $disambiguated_entities ) as $referenced_entity_id ) {
137
+	foreach (array_unique($disambiguated_entities) as $referenced_entity_id) {
138 138
 
139 139
 		wl_core_add_relation_instance(
140 140
 			$post_id,
141
-			Wordlift_Entity_Service::get_instance()->get_classification_scope_for( $referenced_entity_id ),
141
+			Wordlift_Entity_Service::get_instance()->get_classification_scope_for($referenced_entity_id),
142 142
 			$referenced_entity_id
143 143
 		);
144 144
 
145 145
 	}
146 146
 
147
-	if ( isset( $_POST['wl_entities'] ) ) {
147
+	if (isset($_POST['wl_entities'])) {
148 148
 		// Save post metadata if available
149
-		$metadata_via_post = ( isset( $_POST['wl_metadata'] ) ) ?
149
+		$metadata_via_post = (isset($_POST['wl_metadata'])) ?
150 150
 			$_POST['wl_metadata'] : array();
151 151
 
152 152
 		$fields = array(
@@ -155,35 +155,35 @@  discard block
 block discarded – undo
155 155
 		);
156 156
 
157 157
 		// Unlink topic taxonomy terms
158
-		Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for( $post->ID );
158
+		Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for($post->ID);
159 159
 
160
-		foreach ( $fields as $field ) {
160
+		foreach ($fields as $field) {
161 161
 
162 162
 			// Delete current values
163
-			delete_post_meta( $post->ID, $field );
163
+			delete_post_meta($post->ID, $field);
164 164
 			// Retrieve the entity uri
165
-			$uri = ( isset( $metadata_via_post[ $field ] ) ) ?
166
-				stripslashes( $metadata_via_post[ $field ] ) : '';
165
+			$uri = (isset($metadata_via_post[$field])) ?
166
+				stripslashes($metadata_via_post[$field]) : '';
167 167
 
168
-			$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri );
168
+			$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri($uri);
169 169
 
170
-			if ( $entity ) {
171
-				add_post_meta( $post->ID, $field, $entity->ID, true );
170
+			if ($entity) {
171
+				add_post_meta($post->ID, $field, $entity->ID, true);
172 172
 				// Set also the topic taxonomy
173
-				if ( $field === Wordlift_Schema_Service::FIELD_TOPIC ) {
174
-					Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for( $post->ID, $entity );
173
+				if ($field === Wordlift_Schema_Service::FIELD_TOPIC) {
174
+					Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for($post->ID, $entity);
175 175
 				}
176 176
 			}
177 177
 		}
178 178
 	}
179 179
 
180 180
 	// Push the post to Redlink.
181
-	Wordlift_Linked_Data_Service::get_instance()->push( $post->ID );
181
+	Wordlift_Linked_Data_Service::get_instance()->push($post->ID);
182 182
 
183
-	add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
183
+	add_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities');
184 184
 }
185 185
 
186
-add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
186
+add_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities');
187 187
 
188 188
 /**
189 189
  * Save the specified data as an entity in WordPress. This method only create new entities. When an existing entity is
@@ -201,29 +201,29 @@  discard block
 block discarded – undo
201 201
  *
202 202
  * @return null|WP_Post A post instance or null in case of failure.
203 203
  */
204
-function wl_save_entity( $entity_data ) {
204
+function wl_save_entity($entity_data) {
205 205
 
206 206
 	$uri              = $entity_data['uri'];
207 207
 	$label            = $entity_data['label'];
208 208
 	$type_uri         = $entity_data['main_type'];
209
-	$entity_types     = isset( $entity_data['type'] ) ? $entity_data['type'] : array();
209
+	$entity_types     = isset($entity_data['type']) ? $entity_data['type'] : array();
210 210
 	$description      = $entity_data['description'];
211
-	$images           = isset( $entity_data['image'] ) ? (array) $entity_data['image'] : array();
212
-	$same_as          = isset( $entity_data['sameas'] ) ? (array) $entity_data['sameas'] : array();
213
-	$related_post_id  = isset( $entity_data['related_post_id'] ) ? $entity_data['related_post_id'] : null;
214
-	$other_properties = isset( $entity_data['properties'] ) ? $entity_data['properties'] : array();
211
+	$images           = isset($entity_data['image']) ? (array) $entity_data['image'] : array();
212
+	$same_as          = isset($entity_data['sameas']) ? (array) $entity_data['sameas'] : array();
213
+	$related_post_id  = isset($entity_data['related_post_id']) ? $entity_data['related_post_id'] : null;
214
+	$other_properties = isset($entity_data['properties']) ? $entity_data['properties'] : array();
215 215
 
216 216
 	// Get the synonyms.
217
-	$synonyms = isset( $entity_data['synonym'] ) ? $entity_data['synonym'] : array();
217
+	$synonyms = isset($entity_data['synonym']) ? $entity_data['synonym'] : array();
218 218
 
219 219
 	// Check whether an entity already exists with the provided URI.
220
-	if ( null !== $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri ) ) {
220
+	if (null !== $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri($uri)) {
221 221
 		return $post;
222 222
 	}
223 223
 
224 224
 	// Prepare properties of the new entity.
225 225
 	$params = array(
226
-		'post_status'  => ( is_numeric( $related_post_id ) ? get_post_status( $related_post_id ) : 'draft' ),
226
+		'post_status'  => (is_numeric($related_post_id) ? get_post_status($related_post_id) : 'draft'),
227 227
 		'post_type'    => Wordlift_Entity_Service::TYPE_NAME,
228 228
 		'post_title'   => $label,
229 229
 		'post_content' => $description,
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 		// new entities.
234 234
 		//
235 235
 		// See https://github.com/insideout10/wordlift-plugin/issues/282
236
-		'post_name'    => sanitize_title( $label ),
236
+		'post_name'    => sanitize_title($label),
237 237
 	);
238 238
 
239 239
 	// If Yoast is installed and active, we temporary remove the save_postdata hook which causes Yoast to "pass over"
@@ -242,18 +242,18 @@  discard block
 block discarded – undo
242 242
 	// This does NOT affect saving an entity from the entity admin page since this function is called when an entity
243 243
 	// is created when saving a post.
244 244
 	global $wpseo_metabox, $seo_ultimate;
245
-	if ( isset( $wpseo_metabox ) ) {
246
-		remove_action( 'wp_insert_post', array(
245
+	if (isset($wpseo_metabox)) {
246
+		remove_action('wp_insert_post', array(
247 247
 			$wpseo_metabox,
248 248
 			'save_postdata',
249
-		) );
249
+		));
250 250
 	}
251 251
 
252
-	if ( isset( $seo_ultimate ) ) {
253
-		remove_action( 'save_post', array(
252
+	if (isset($seo_ultimate)) {
253
+		remove_action('save_post', array(
254 254
 			$seo_ultimate,
255 255
 			'save_postmeta_box',
256
-		) );
256
+		));
257 257
 	}
258 258
 
259 259
 	// The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to
@@ -263,90 +263,90 @@  discard block
 block discarded – undo
263 263
 	// see https://github.com/insideout10/wordlift-plugin/issues/156
264 264
 	// see https://github.com/insideout10/wordlift-plugin/issues/148
265 265
 	global $wp_filter;
266
-	$save_post_filters = is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks;
267
-	is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters();
266
+	$save_post_filters = is_array($wp_filter['save_post']) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks;
267
+	is_array($wp_filter['save_post']) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters();
268 268
 
269 269
 	// create or update the post.
270
-	$post_id = wp_insert_post( $params, true );
270
+	$post_id = wp_insert_post($params, true);
271 271
 
272 272
 	// Setting the alternative labels for this entity.
273 273
 	Wordlift_Entity_Service::get_instance()
274
-	                       ->set_alternative_labels( $post_id, $synonyms );
274
+	                       ->set_alternative_labels($post_id, $synonyms);
275 275
 
276 276
 	// Restore all the existing filters.
277
-	is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters;
277
+	is_array($wp_filter['save_post']) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters;
278 278
 
279 279
 	// If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156)
280
-	if ( isset( $wpseo_metabox ) ) {
281
-		add_action( 'wp_insert_post', array(
280
+	if (isset($wpseo_metabox)) {
281
+		add_action('wp_insert_post', array(
282 282
 			$wpseo_metabox,
283 283
 			'save_postdata',
284
-		) );
284
+		));
285 285
 	}
286 286
 
287 287
 	// If SEO Ultimate is installed, add back the hook we removed a few lines above.
288
-	if ( isset( $seo_ultimate ) ) {
289
-		add_action( 'save_post', array(
288
+	if (isset($seo_ultimate)) {
289
+		add_action('save_post', array(
290 290
 			$seo_ultimate,
291 291
 			'save_postmeta_box',
292
-		), 10, 2 );
292
+		), 10, 2);
293 293
 	}
294 294
 
295 295
 	// TODO: handle errors.
296
-	if ( is_wp_error( $post_id ) ) {
297
-		wl_write_log( ': error occurred' );
296
+	if (is_wp_error($post_id)) {
297
+		wl_write_log(': error occurred');
298 298
 
299 299
 		// inform an error occurred.
300 300
 		return null;
301 301
 	}
302 302
 
303
-	wl_set_entity_main_type( $post_id, $type_uri );
303
+	wl_set_entity_main_type($post_id, $type_uri);
304 304
 
305 305
 	// Save the entity types.
306
-	wl_set_entity_rdf_types( $post_id, $entity_types );
306
+	wl_set_entity_rdf_types($post_id, $entity_types);
307 307
 
308 308
 	// Get a dataset URI for the entity.
309
-	$wl_uri = wl_build_entity_uri( $post_id );
309
+	$wl_uri = wl_build_entity_uri($post_id);
310 310
 
311 311
 	// Save the entity URI.
312
-	wl_set_entity_uri( $post_id, $wl_uri );
312
+	wl_set_entity_uri($post_id, $wl_uri);
313 313
 
314 314
 	// Add the uri to the sameAs data if it's not a local URI.
315
-	if ( $wl_uri !== $uri ) {
316
-		array_push( $same_as, $uri );
315
+	if ($wl_uri !== $uri) {
316
+		array_push($same_as, $uri);
317 317
 	}
318 318
 
319
-	$new_uri = wl_get_entity_uri( $post_id );
319
+	$new_uri = wl_get_entity_uri($post_id);
320 320
 
321 321
 	// Save the sameAs data for the entity.
322
-	wl_schema_set_value( $post_id, 'sameAs', $same_as );
322
+	wl_schema_set_value($post_id, 'sameAs', $same_as);
323 323
 
324 324
 	// Save the other properties (latitude, langitude, startDate, endDate, etc.)
325
-	foreach ( $other_properties as $property_name => $property_value ) {
326
-		wl_schema_set_value( $post_id, $property_name, $property_value );
325
+	foreach ($other_properties as $property_name => $property_value) {
326
+		wl_schema_set_value($post_id, $property_name, $property_value);
327 327
 	}
328 328
 
329 329
 	// Call hooks.
330
-	do_action( 'wl_save_entity', $post_id );
330
+	do_action('wl_save_entity', $post_id);
331 331
 
332
-	foreach ( $images as $image_remote_url ) {
332
+	foreach ($images as $image_remote_url) {
333 333
 
334 334
 		// Check if image is already present in local DB
335
-		if ( strpos( $image_remote_url, site_url() ) !== false ) {
335
+		if (strpos($image_remote_url, site_url()) !== false) {
336 336
 			// Do nothing.
337 337
 			continue;
338 338
 		}
339 339
 
340 340
 		// Check if there is an existing attachment for this post ID and source URL.
341
-		$existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url );
341
+		$existing_image = wl_get_attachment_for_source_url($post_id, $image_remote_url);
342 342
 
343 343
 		// Skip if an existing image is found.
344
-		if ( null !== $existing_image ) {
344
+		if (null !== $existing_image) {
345 345
 			continue;
346 346
 		}
347 347
 
348 348
 		// Save the image and get the local path.
349
-		$image = wl_save_image( $image_remote_url );
349
+		$image = wl_save_image($image_remote_url);
350 350
 
351 351
 		// Get the local URL.
352 352
 		$filename     = $image['path'];
@@ -364,24 +364,24 @@  discard block
 block discarded – undo
364 364
 		);
365 365
 
366 366
 		// Create the attachment in WordPress and generate the related metadata.
367
-		$attachment_id = wp_insert_attachment( $attachment, $filename, $post_id );
367
+		$attachment_id = wp_insert_attachment($attachment, $filename, $post_id);
368 368
 
369 369
 		// Set the source URL for the image.
370
-		wl_set_source_url( $attachment_id, $image_remote_url );
370
+		wl_set_source_url($attachment_id, $image_remote_url);
371 371
 
372
-		$attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
373
-		wp_update_attachment_metadata( $attachment_id, $attachment_data );
372
+		$attachment_data = wp_generate_attachment_metadata($attachment_id, $filename);
373
+		wp_update_attachment_metadata($attachment_id, $attachment_data);
374 374
 
375 375
 		// Set it as the featured image.
376
-		set_post_thumbnail( $post_id, $attachment_id );
376
+		set_post_thumbnail($post_id, $attachment_id);
377 377
 	}
378 378
 
379 379
 	// The entity is pushed to Redlink on save by the function hooked to save_post.
380 380
 	// save the entity in the triple store.
381
-	Wordlift_Linked_Data_Service::get_instance()->push( $post_id );
381
+	Wordlift_Linked_Data_Service::get_instance()->push($post_id);
382 382
 
383 383
 	// finally return the entity post.
384
-	return get_post( $post_id );
384
+	return get_post($post_id);
385 385
 }
386 386
 
387 387
 /**
@@ -393,10 +393,10 @@  discard block
 block discarded – undo
393 393
  *
394 394
  * @return array An array of entity posts.
395 395
  */
396
-function wl_linked_data_content_get_embedded_entities( $content ) {
396
+function wl_linked_data_content_get_embedded_entities($content) {
397 397
 
398 398
 	// Remove quote escapes.
399
-	$content = str_replace( '\\"', '"', $content );
399
+	$content = str_replace('\\"', '"', $content);
400 400
 
401 401
 	// Match all itemid attributes.
402 402
 	$pattern = '/<\w+[^>]*\sitemid="([^"]+)"[^>]*>/im';
@@ -407,8 +407,8 @@  discard block
 block discarded – undo
407 407
 	$matches = array();
408 408
 
409 409
 	// In case of errors, return an empty array.
410
-	if ( false === preg_match_all( $pattern, $content, $matches ) ) {
411
-		wl_write_log( "Found no entities embedded in content" );
410
+	if (false === preg_match_all($pattern, $content, $matches)) {
411
+		wl_write_log("Found no entities embedded in content");
412 412
 
413 413
 		return array();
414 414
 	}
@@ -417,13 +417,13 @@  discard block
 block discarded – undo
417 417
 
418 418
 	// Collect the entities.
419 419
 	$entities = array();
420
-	foreach ( $matches[1] as $uri ) {
421
-		$uri_d = html_entity_decode( $uri );
420
+	foreach ($matches[1] as $uri) {
421
+		$uri_d = html_entity_decode($uri);
422 422
 
423
-		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri_d );
423
+		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri($uri_d);
424 424
 
425
-		if ( null !== $entity ) {
426
-			array_push( $entities, $entity->ID );
425
+		if (null !== $entity) {
426
+			array_push($entities, $entity->ID);
427 427
 		}
428 428
 	}
429 429
 
Please login to merge, or discard this patch.
src/modules/geo_widget/wordlift_geo_widget.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -9,32 +9,32 @@  discard block
 block discarded – undo
9 9
 
10 10
 function wordlift_geo_widget_shortcode( $atts, $content = null ) {
11 11
 
12
-	// Extract attributes and set default values.
13
-	$params = shortcode_atts( array(
14
-		'width'     => '100%',
15
-		'height'    => '300px',
16
-		'latitude'  => 0.0,
17
-		'longitude' => 0.0,
18
-		'zoom'      => 5,
19
-
20
-	), $atts );
21
-
22
-	// Add leaflet css and library.
23
-	wp_enqueue_style( 'leaflet_css', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
24
-	wp_enqueue_script( 'leaflet_js', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js' );
25
-
26
-	ob_start(); // Collect the buffer.
27
-	wordlift_geo_widget_html(
28
-		$params['width'],
29
-		$params['height'],
30
-		$params['latitude'],
31
-		$params['longitude'],
32
-		$params['zoom'],
33
-		$content
34
-	);
35
-
36
-	// Return the accumulated buffer.
37
-	return ob_get_clean();
12
+    // Extract attributes and set default values.
13
+    $params = shortcode_atts( array(
14
+        'width'     => '100%',
15
+        'height'    => '300px',
16
+        'latitude'  => 0.0,
17
+        'longitude' => 0.0,
18
+        'zoom'      => 5,
19
+
20
+    ), $atts );
21
+
22
+    // Add leaflet css and library.
23
+    wp_enqueue_style( 'leaflet_css', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
24
+    wp_enqueue_script( 'leaflet_js', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js' );
25
+
26
+    ob_start(); // Collect the buffer.
27
+    wordlift_geo_widget_html(
28
+        $params['width'],
29
+        $params['height'],
30
+        $params['latitude'],
31
+        $params['longitude'],
32
+        $params['zoom'],
33
+        $content
34
+    );
35
+
36
+    // Return the accumulated buffer.
37
+    return ob_get_clean();
38 38
 
39 39
 }
40 40
 
@@ -42,24 +42,24 @@  discard block
 block discarded – undo
42 42
 
43 43
 function wl_geo_widget_layer_shortcode( $atts ) {
44 44
 
45
-	// Extract attributes and set default values.
46
-	$params = shortcode_atts( array(
47
-		'name'  => '',
48
-		'label' => '',
49
-	), $atts );
45
+    // Extract attributes and set default values.
46
+    $params = shortcode_atts( array(
47
+        'name'  => '',
48
+        'label' => '',
49
+    ), $atts );
50 50
 
51
-	// Return if a SPARQL Query name hasn't been provided.
52
-	if ( empty( $params['name'] ) ) {
53
-		return;
54
-	}
51
+    // Return if a SPARQL Query name hasn't been provided.
52
+    if ( empty( $params['name'] ) ) {
53
+        return;
54
+    }
55 55
 
56
-	// Set the layer label.
57
-	$label_j = json_encode( empty( $params['label'] ) ? $params['name'] : $params['label'] );
56
+    // Set the layer label.
57
+    $label_j = json_encode( empty( $params['label'] ) ? $params['name'] : $params['label'] );
58 58
 
59
-	// Define the AJAX Url.
60
-	$ajax_url = admin_url( 'admin-ajax.php?action=wl_sparql&format=geojson&slug=' . urlencode( $params['name'] ) );
59
+    // Define the AJAX Url.
60
+    $ajax_url = admin_url( 'admin-ajax.php?action=wl_sparql&format=geojson&slug=' . urlencode( $params['name'] ) );
61 61
 
62
-	echo <<<EOF
62
+    echo <<<EOF
63 63
 
64 64
         $.ajax( '$ajax_url', {
65 65
             success: function( data ) {
@@ -90,21 +90,21 @@  discard block
 block discarded – undo
90 90
 
91 91
 function wl_geo_widget_marker_shortcode( $atts ) {
92 92
 
93
-	// Extract attributes and set default values.
94
-	$params = shortcode_atts( array(
95
-		'latitude'  => null,
96
-		'longitude' => null,
97
-	), $atts );
93
+    // Extract attributes and set default values.
94
+    $params = shortcode_atts( array(
95
+        'latitude'  => null,
96
+        'longitude' => null,
97
+    ), $atts );
98 98
 
99
-	// Return if either latitude or longitude haven't been provided.
100
-	if ( empty( $params['latitude'] ) || empty( $params['longitude'] ) ) {
101
-		return;
102
-	}
99
+    // Return if either latitude or longitude haven't been provided.
100
+    if ( empty( $params['latitude'] ) || empty( $params['longitude'] ) ) {
101
+        return;
102
+    }
103 103
 
104
-	$latitude_j  = json_encode( $params['latitude'] );
105
-	$longitude_j = json_encode( $params['longitude'] );
104
+    $latitude_j  = json_encode( $params['latitude'] );
105
+    $longitude_j = json_encode( $params['longitude'] );
106 106
 
107
-	echo <<<EOF
107
+    echo <<<EOF
108 108
 
109 109
 		L.marker([$latitude_j, $longitude_j]).addTo(map);
110 110
 EOF;
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
 
117 117
 function wordlift_geo_widget_html( $width, $height, $latitude, $longitude, $zoom, $content ) {
118 118
 
119
-	// Create a unique Id for this widget.
120
-	$div_id = uniqid( 'wl-geo-' );
119
+    // Create a unique Id for this widget.
120
+    $div_id = uniqid( 'wl-geo-' );
121 121
 
122
-	echo <<<EOF
122
+    echo <<<EOF
123 123
 <div id="$div_id" style="width: $width; height: $height;"></div>
124 124
 
125 125
 <script type="text/javascript">
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 
145 145
 EOF;
146 146
 
147
-	// Run inner shortcodes.
148
-	do_shortcode( $content );
147
+    // Run inner shortcodes.
148
+    do_shortcode( $content );
149 149
 
150
-	echo <<<EOF
150
+    echo <<<EOF
151 151
 
152 152
     } );
153 153
 </script>
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -7,21 +7,21 @@  discard block
 block discarded – undo
7 7
  * @subpackage Wordlift/modules/geo_widget
8 8
  */
9 9
 
10
-function wordlift_geo_widget_shortcode( $atts, $content = null ) {
10
+function wordlift_geo_widget_shortcode($atts, $content = null) {
11 11
 
12 12
 	// Extract attributes and set default values.
13
-	$params = shortcode_atts( array(
13
+	$params = shortcode_atts(array(
14 14
 		'width'     => '100%',
15 15
 		'height'    => '300px',
16 16
 		'latitude'  => 0.0,
17 17
 		'longitude' => 0.0,
18 18
 		'zoom'      => 5,
19 19
 
20
-	), $atts );
20
+	), $atts);
21 21
 
22 22
 	// Add leaflet css and library.
23
-	wp_enqueue_style( 'leaflet_css', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.css' );
24
-	wp_enqueue_script( 'leaflet_js', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/bower_components/leaflet/dist/leaflet.js' );
23
+	wp_enqueue_style('leaflet_css', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.css');
24
+	wp_enqueue_script('leaflet_js', dirname(dirname(plugin_dir_url(__FILE__))).'/bower_components/leaflet/dist/leaflet.js');
25 25
 
26 26
 	ob_start(); // Collect the buffer.
27 27
 	wordlift_geo_widget_html(
@@ -38,26 +38,26 @@  discard block
 block discarded – undo
38 38
 
39 39
 }
40 40
 
41
-add_shortcode( 'wl_geo', 'wordlift_geo_widget_shortcode' );
41
+add_shortcode('wl_geo', 'wordlift_geo_widget_shortcode');
42 42
 
43
-function wl_geo_widget_layer_shortcode( $atts ) {
43
+function wl_geo_widget_layer_shortcode($atts) {
44 44
 
45 45
 	// Extract attributes and set default values.
46
-	$params = shortcode_atts( array(
46
+	$params = shortcode_atts(array(
47 47
 		'name'  => '',
48 48
 		'label' => '',
49
-	), $atts );
49
+	), $atts);
50 50
 
51 51
 	// Return if a SPARQL Query name hasn't been provided.
52
-	if ( empty( $params['name'] ) ) {
52
+	if (empty($params['name'])) {
53 53
 		return;
54 54
 	}
55 55
 
56 56
 	// Set the layer label.
57
-	$label_j = json_encode( empty( $params['label'] ) ? $params['name'] : $params['label'] );
57
+	$label_j = json_encode(empty($params['label']) ? $params['name'] : $params['label']);
58 58
 
59 59
 	// Define the AJAX Url.
60
-	$ajax_url = admin_url( 'admin-ajax.php?action=wl_sparql&format=geojson&slug=' . urlencode( $params['name'] ) );
60
+	$ajax_url = admin_url('admin-ajax.php?action=wl_sparql&format=geojson&slug='.urlencode($params['name']));
61 61
 
62 62
 	echo <<<EOF
63 63
 
@@ -85,24 +85,24 @@  discard block
 block discarded – undo
85 85
 
86 86
 }
87 87
 
88
-add_shortcode( 'wl_geo_layer', 'wl_geo_widget_layer_shortcode' );
88
+add_shortcode('wl_geo_layer', 'wl_geo_widget_layer_shortcode');
89 89
 
90 90
 
91
-function wl_geo_widget_marker_shortcode( $atts ) {
91
+function wl_geo_widget_marker_shortcode($atts) {
92 92
 
93 93
 	// Extract attributes and set default values.
94
-	$params = shortcode_atts( array(
94
+	$params = shortcode_atts(array(
95 95
 		'latitude'  => null,
96 96
 		'longitude' => null,
97
-	), $atts );
97
+	), $atts);
98 98
 
99 99
 	// Return if either latitude or longitude haven't been provided.
100
-	if ( empty( $params['latitude'] ) || empty( $params['longitude'] ) ) {
100
+	if (empty($params['latitude']) || empty($params['longitude'])) {
101 101
 		return;
102 102
 	}
103 103
 
104
-	$latitude_j  = json_encode( $params['latitude'] );
105
-	$longitude_j = json_encode( $params['longitude'] );
104
+	$latitude_j  = json_encode($params['latitude']);
105
+	$longitude_j = json_encode($params['longitude']);
106 106
 
107 107
 	echo <<<EOF
108 108
 
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
 
112 112
 }
113 113
 
114
-add_shortcode( 'wl_geo_marker', 'wl_geo_widget_marker_shortcode' );
114
+add_shortcode('wl_geo_marker', 'wl_geo_widget_marker_shortcode');
115 115
 
116 116
 
117
-function wordlift_geo_widget_html( $width, $height, $latitude, $longitude, $zoom, $content ) {
117
+function wordlift_geo_widget_html($width, $height, $latitude, $longitude, $zoom, $content) {
118 118
 
119 119
 	// Create a unique Id for this widget.
120
-	$div_id = uniqid( 'wl-geo-' );
120
+	$div_id = uniqid('wl-geo-');
121 121
 
122 122
 	echo <<<EOF
123 123
 <div id="$div_id" style="width: $width; height: $height;"></div>
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 EOF;
146 146
 
147 147
 	// Run inner shortcodes.
148
-	do_shortcode( $content );
148
+	do_shortcode($content);
149 149
 
150 150
 	echo <<<EOF
151 151
 
Please login to merge, or discard this patch.
src/public/class-wordlift-related-entities-cloud-shortcode.php 2 patches
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -16,110 +16,110 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Related_Entities_Cloud_Shortcode extends Wordlift_Shortcode {
18 18
 
19
-	/**
20
-	 * {@inheritdoc}
21
-	 */
22
-	const SHORTCODE = 'wl_cloud';
23
-
24
-	/**
25
-	 * The {@link Wordlift_Relation_Service} instance.
26
-	 *
27
-	 * @since  3.15.0
28
-	 * @access private
29
-	 * @var \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
30
-	 */
31
-	private $relation_service;
32
-
33
-	/**
34
-	 * Create a {@link Wordlift_Related_Entities_Cloud_Shortcode} instance.
35
-	 *
36
-	 * @since 3.15.0
37
-	 *
38
-	 * @param \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
39
-	 */
40
-	public function __construct( $relation_service ) {
41
-		parent::__construct();
42
-
43
-		$this->relation_service = $relation_service;
44
-
45
-	}
46
-
47
-	/**
48
-	 * {@inheritdoc}
49
-	 */
50
-	public function render( $atts ) {
51
-
52
-		$tags = $this->get_related_entities_tags();
53
-
54
-		// Bail out if there are no associated entities.
55
-		if ( empty( $tags ) ) {
56
-			return '';
57
-		}
58
-
59
-		/*
19
+    /**
20
+     * {@inheritdoc}
21
+     */
22
+    const SHORTCODE = 'wl_cloud';
23
+
24
+    /**
25
+     * The {@link Wordlift_Relation_Service} instance.
26
+     *
27
+     * @since  3.15.0
28
+     * @access private
29
+     * @var \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
30
+     */
31
+    private $relation_service;
32
+
33
+    /**
34
+     * Create a {@link Wordlift_Related_Entities_Cloud_Shortcode} instance.
35
+     *
36
+     * @since 3.15.0
37
+     *
38
+     * @param \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
39
+     */
40
+    public function __construct( $relation_service ) {
41
+        parent::__construct();
42
+
43
+        $this->relation_service = $relation_service;
44
+
45
+    }
46
+
47
+    /**
48
+     * {@inheritdoc}
49
+     */
50
+    public function render( $atts ) {
51
+
52
+        $tags = $this->get_related_entities_tags();
53
+
54
+        // Bail out if there are no associated entities.
55
+        if ( empty( $tags ) ) {
56
+            return '';
57
+        }
58
+
59
+        /*
60 60
 		 * Since the output is use in the widget as well, we need to have the
61 61
 		 * same class as the core tagcloud widget, to easily inherit its styling.
62 62
 		 */
63 63
 
64
-		return '<div class="tagcloud wl-related-entities-cloud">' .
65
-		       wp_generate_tag_cloud( $tags ) .
66
-		       '</div>';
67
-	}
68
-
69
-	/**
70
-	 * Find the related entities to the currently displayed post and
71
-	 * calculate the "tags" for them as wp_generate_tag_cloud expects to get.
72
-	 *
73
-	 * @since 3.11.0
74
-	 *
75
-	 * @return array    Array of tags. Empty array in case we re not in a context
76
-	 *                  of a post, or it has no related entities.
77
-	 */
78
-	public function get_related_entities_tags() {
79
-
80
-		// Define the supported types list.
81
-		$supported_types = Wordlift_Entity_Service::valid_entity_post_types();
82
-
83
-		// Show nothing if not on a post or entity page.
84
-		if ( ! is_singular( $supported_types ) ) {
85
-			return array();
86
-		}
87
-
88
-		// Get the IDs of entities related to current post.
89
-		$related_entities = wl_core_get_related_entity_ids( get_the_ID(), array( 'status' => 'publish' ) );
90
-
91
-		// Bail out if there are no associated entities.
92
-		if ( empty( $related_entities ) ) {
93
-			return array();
94
-		}
95
-
96
-		/*
64
+        return '<div class="tagcloud wl-related-entities-cloud">' .
65
+                wp_generate_tag_cloud( $tags ) .
66
+                '</div>';
67
+    }
68
+
69
+    /**
70
+     * Find the related entities to the currently displayed post and
71
+     * calculate the "tags" for them as wp_generate_tag_cloud expects to get.
72
+     *
73
+     * @since 3.11.0
74
+     *
75
+     * @return array    Array of tags. Empty array in case we re not in a context
76
+     *                  of a post, or it has no related entities.
77
+     */
78
+    public function get_related_entities_tags() {
79
+
80
+        // Define the supported types list.
81
+        $supported_types = Wordlift_Entity_Service::valid_entity_post_types();
82
+
83
+        // Show nothing if not on a post or entity page.
84
+        if ( ! is_singular( $supported_types ) ) {
85
+            return array();
86
+        }
87
+
88
+        // Get the IDs of entities related to current post.
89
+        $related_entities = wl_core_get_related_entity_ids( get_the_ID(), array( 'status' => 'publish' ) );
90
+
91
+        // Bail out if there are no associated entities.
92
+        if ( empty( $related_entities ) ) {
93
+            return array();
94
+        }
95
+
96
+        /*
97 97
 		 * Create an array of "tags" to feed to wp_generate_tag_cloud.
98 98
 		 * Use the number of posts and entities connected to the entity as a weight.
99 99
 		 */
100
-		$tags = array();
101
-
102
-		foreach ( $related_entities as $entity_id ) {
103
-
104
-			$connected_entities = count( wl_core_get_related_entity_ids( $entity_id, array( 'status' => 'publish' ) ) );
105
-			$connected_posts    = count( $this->relation_service->get_article_subjects( $entity_id, '*', null,'publish' ) );
106
-
107
-			$tags[] = (object) array(
108
-				'id'    => $entity_id,
109
-				// Used to give a unique class on the tag.
110
-				'name'  => get_the_title( $entity_id ),
111
-				// The text of the tag.
112
-				'slug'  => get_the_title( $entity_id ),
113
-				// Required but not seem to be relevant
114
-				'link'  => get_permalink( $entity_id ),
115
-				// the url the tag links to.
116
-				'count' => $connected_entities + $connected_posts,
117
-				// The weight.
118
-			);
119
-
120
-		}
121
-
122
-		return $tags;
123
-	}
100
+        $tags = array();
101
+
102
+        foreach ( $related_entities as $entity_id ) {
103
+
104
+            $connected_entities = count( wl_core_get_related_entity_ids( $entity_id, array( 'status' => 'publish' ) ) );
105
+            $connected_posts    = count( $this->relation_service->get_article_subjects( $entity_id, '*', null,'publish' ) );
106
+
107
+            $tags[] = (object) array(
108
+                'id'    => $entity_id,
109
+                // Used to give a unique class on the tag.
110
+                'name'  => get_the_title( $entity_id ),
111
+                // The text of the tag.
112
+                'slug'  => get_the_title( $entity_id ),
113
+                // Required but not seem to be relevant
114
+                'link'  => get_permalink( $entity_id ),
115
+                // the url the tag links to.
116
+                'count' => $connected_entities + $connected_posts,
117
+                // The weight.
118
+            );
119
+
120
+        }
121
+
122
+        return $tags;
123
+    }
124 124
 
125 125
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
39 39
 	 */
40
-	public function __construct( $relation_service ) {
40
+	public function __construct($relation_service) {
41 41
 		parent::__construct();
42 42
 
43 43
 		$this->relation_service = $relation_service;
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
 	/**
48 48
 	 * {@inheritdoc}
49 49
 	 */
50
-	public function render( $atts ) {
50
+	public function render($atts) {
51 51
 
52 52
 		$tags = $this->get_related_entities_tags();
53 53
 
54 54
 		// Bail out if there are no associated entities.
55
-		if ( empty( $tags ) ) {
55
+		if (empty($tags)) {
56 56
 			return '';
57 57
 		}
58 58
 
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 		 * same class as the core tagcloud widget, to easily inherit its styling.
62 62
 		 */
63 63
 
64
-		return '<div class="tagcloud wl-related-entities-cloud">' .
65
-		       wp_generate_tag_cloud( $tags ) .
64
+		return '<div class="tagcloud wl-related-entities-cloud">'.
65
+		       wp_generate_tag_cloud($tags).
66 66
 		       '</div>';
67 67
 	}
68 68
 
@@ -81,15 +81,15 @@  discard block
 block discarded – undo
81 81
 		$supported_types = Wordlift_Entity_Service::valid_entity_post_types();
82 82
 
83 83
 		// Show nothing if not on a post or entity page.
84
-		if ( ! is_singular( $supported_types ) ) {
84
+		if ( ! is_singular($supported_types)) {
85 85
 			return array();
86 86
 		}
87 87
 
88 88
 		// Get the IDs of entities related to current post.
89
-		$related_entities = wl_core_get_related_entity_ids( get_the_ID(), array( 'status' => 'publish' ) );
89
+		$related_entities = wl_core_get_related_entity_ids(get_the_ID(), array('status' => 'publish'));
90 90
 
91 91
 		// Bail out if there are no associated entities.
92
-		if ( empty( $related_entities ) ) {
92
+		if (empty($related_entities)) {
93 93
 			return array();
94 94
 		}
95 95
 
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 		 */
100 100
 		$tags = array();
101 101
 
102
-		foreach ( $related_entities as $entity_id ) {
102
+		foreach ($related_entities as $entity_id) {
103 103
 
104
-			$connected_entities = count( wl_core_get_related_entity_ids( $entity_id, array( 'status' => 'publish' ) ) );
105
-			$connected_posts    = count( $this->relation_service->get_article_subjects( $entity_id, '*', null,'publish' ) );
104
+			$connected_entities = count(wl_core_get_related_entity_ids($entity_id, array('status' => 'publish')));
105
+			$connected_posts    = count($this->relation_service->get_article_subjects($entity_id, '*', null, 'publish'));
106 106
 
107 107
 			$tags[] = (object) array(
108 108
 				'id'    => $entity_id,
109 109
 				// Used to give a unique class on the tag.
110
-				'name'  => get_the_title( $entity_id ),
110
+				'name'  => get_the_title($entity_id),
111 111
 				// The text of the tag.
112
-				'slug'  => get_the_title( $entity_id ),
112
+				'slug'  => get_the_title($entity_id),
113 113
 				// Required but not seem to be relevant
114
-				'link'  => get_permalink( $entity_id ),
114
+				'link'  => get_permalink($entity_id),
115 115
 				// the url the tag links to.
116 116
 				'count' => $connected_entities + $connected_posts,
117 117
 				// The weight.
Please login to merge, or discard this patch.