Completed
Push — develop ( d513ba...161245 )
by David
05:02 queued 32s
created
src/includes/class-wordlift-entity-service.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@
 block discarded – undo
131 131
 	 *
132 132
 	 * @param int $post_id A post id.
133 133
 	 *
134
-	 * @return true if the post is an entity otherwise false.
134
+	 * @return boolean if the post is an entity otherwise false.
135 135
 	 */
136 136
 	public function is_entity( $post_id ) {
137 137
 
Please login to merge, or discard this patch.
Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -7,240 +7,240 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Entity_Service {
9 9
 
10
-	/**
11
-	 * The Log service.
12
-	 *
13
-	 * @since 3.2.0
14
-	 * @access private
15
-	 * @var \Wordlift_Log_Service $log_service The Log service.
16
-	 */
17
-	private $log_service;
18
-
19
-	/**
20
-	 * The UI service.
21
-	 *
22
-	 * @since 3.2.0
23
-	 * @access private
24
-	 * @var \Wordlift_UI_Service $ui_service The UI service.
25
-	 */
26
-	private $ui_service;
27
-
28
-	/**
29
-	 * The entity post type name.
30
-	 *
31
-	 * @since 3.1.0
32
-	 */
33
-	const TYPE_NAME = 'entity';
34
-
35
-	/**
36
-	 * The alternate label meta key.
37
-	 *
38
-	 * @since 3.2.0
39
-	 */
40
-	const ALTERNATE_LABEL_META_KEY = '_wl_alt_label';
41
-
42
-	/**
43
-	 * The alternative label input template.
44
-	 *
45
-	 * @since 3.2.0
46
-	 */
47
-	// TODO: this should be moved to a class that deals with HTML code.
48
-	const ALTERNATIVE_LABEL_INPUT_TEMPLATE = '<div class="wl-alternative-label">
10
+    /**
11
+     * The Log service.
12
+     *
13
+     * @since 3.2.0
14
+     * @access private
15
+     * @var \Wordlift_Log_Service $log_service The Log service.
16
+     */
17
+    private $log_service;
18
+
19
+    /**
20
+     * The UI service.
21
+     *
22
+     * @since 3.2.0
23
+     * @access private
24
+     * @var \Wordlift_UI_Service $ui_service The UI service.
25
+     */
26
+    private $ui_service;
27
+
28
+    /**
29
+     * The entity post type name.
30
+     *
31
+     * @since 3.1.0
32
+     */
33
+    const TYPE_NAME = 'entity';
34
+
35
+    /**
36
+     * The alternate label meta key.
37
+     *
38
+     * @since 3.2.0
39
+     */
40
+    const ALTERNATE_LABEL_META_KEY = '_wl_alt_label';
41
+
42
+    /**
43
+     * The alternative label input template.
44
+     *
45
+     * @since 3.2.0
46
+     */
47
+    // TODO: this should be moved to a class that deals with HTML code.
48
+    const ALTERNATIVE_LABEL_INPUT_TEMPLATE = '<div class="wl-alternative-label">
49 49
                 <label class="screen-reader-text" id="wl-alternative-label-prompt-text" for="wl-alternative-label">Enter alternative label here</label>
50 50
                 <input name="wl_alternative_label[]" size="30" value="%s" id="wl-alternative-label" type="text">
51 51
                 <button class="button wl-delete-button">%s</button>
52 52
                 </div>';
53 53
 
54
-	/**
55
-	 * A singleton instance of the Entity service.
56
-	 *
57
-	 * @since 3.2.0
58
-	 * @access private
59
-	 * @var \Wordlift_Entity_Service $instance A singleton instance of the Entity service.
60
-	 */
61
-	private static $instance;
62
-
63
-	/**
64
-	 * Create a Wordlift_Entity_Service instance.
65
-	 *
66
-	 * @since 3.2.0
67
-	 *
68
-	 * @param \Wordlift_UI_Service $ui_service The UI service.
69
-	 */
70
-	public function __construct( $ui_service ) {
71
-
72
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
73
-
74
-		// Set the UI service.
75
-		$this->ui_service = $ui_service;
76
-
77
-		// Set the singleton instance.
78
-		self::$instance = $this;
79
-
80
-	}
81
-
82
-	/**
83
-	 * Get the singleton instance of the Entity service.
84
-	 *
85
-	 * @since 3.2.0
86
-	 * @return \Wordlift_Entity_Service The singleton instance of the Entity service.
87
-	 */
88
-	public static function get_instance() {
89
-
90
-		return self::$instance;
91
-	}
92
-
93
-	/**
94
-	 * Get the entities related to the last 50 posts published on this blog (we're keeping a long function name due to
95
-	 * its specific function).
96
-	 *
97
-	 * @since 3.1.0
98
-	 *
99
-	 * @return array An array of post IDs.
100
-	 */
101
-	public function get_all_related_to_last_50_published_posts() {
102
-
103
-		// Global timeline. Get entities from the latest posts.
104
-		$latest_posts_ids = get_posts( array(
105
-			'numberposts' => 50,
106
-			'fields'      => 'ids', //only get post IDs
107
-			'post_type'   => 'post',
108
-			'post_status' => 'publish'
109
-		) );
110
-
111
-		if ( empty( $latest_posts_ids ) ) {
112
-			// There are no posts.
113
-			return array();
114
-		}
115
-
116
-		// Collect entities related to latest posts
117
-		$entity_ids = array();
118
-		foreach ( $latest_posts_ids as $id ) {
119
-			$entity_ids = array_merge( $entity_ids, wl_core_get_related_entity_ids( $id, array(
120
-				'status' => 'publish'
121
-			) ) );
122
-		}
123
-
124
-		return $entity_ids;
125
-	}
126
-
127
-	/**
128
-	 * Determines whether a post is an entity or not.
129
-	 *
130
-	 * @since 3.1.0
131
-	 *
132
-	 * @param int $post_id A post id.
133
-	 *
134
-	 * @return true if the post is an entity otherwise false.
135
-	 */
136
-	public function is_entity( $post_id ) {
137
-
138
-		return ( self::TYPE_NAME === get_post_type( $post_id ) );
139
-	}
140
-
141
-	/**
142
-	 * Fires once a post has been saved.
143
-	 *
144
-	 * @since 3.2.0
145
-	 *
146
-	 * @param int $post_id Post ID.
147
-	 * @param WP_Post $post Post object.
148
-	 * @param bool $update Whether this is an existing post being updated or not.
149
-	 */
150
-	public function save_post( $post_id, $post, $update ) {
151
-
152
-		// If it's not an entity, return.
153
-		if ( ! $this->is_entity( $post_id ) ) {
154
-			return;
155
-		}
156
-
157
-		// Get the alt labels from the request (or empty array).
158
-		$alt_labels = isset( $_REQUEST['wl_alternative_label'] ) ? $_REQUEST['wl_alternative_label'] : array();
159
-
160
-		// Set the alternative labels.
161
-		$this->set_alternative_labels( $post_id, $alt_labels );
162
-
163
-	}
164
-
165
-	/**
166
-	 * Set the alternative labels.
167
-	 *
168
-	 * @since 3.2.0
169
-	 *
170
-	 * @param int $post_id The post id.
171
-	 * @param array $alt_labels An array of labels.
172
-	 */
173
-	private function set_alternative_labels( $post_id, $alt_labels ) {
174
-
175
-		$this->log_service->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . " ]" );
176
-
177
-		// Delete all the existing alternate labels.
178
-		delete_post_meta( $post_id, self::ALTERNATE_LABEL_META_KEY );
179
-
180
-		// Set the alternative labels.
181
-		foreach ( $alt_labels as $alt_label ) {
182
-			if ( ! empty( $alt_label ) ) {
183
-				add_post_meta( $post_id, self::ALTERNATE_LABEL_META_KEY, $alt_label );
184
-			}
185
-		}
186
-
187
-	}
188
-
189
-	/**
190
-	 * Retrieve the alternate labels.
191
-	 *
192
-	 * @since 3.2.0
193
-	 *
194
-	 * @param int $post_id Post id.
195
-	 *
196
-	 * @return mixed An array  of alternative labels.
197
-	 */
198
-	public function get_alternate_labels( $post_id ) {
199
-
200
-		return get_post_meta( $post_id, self::ALTERNATE_LABEL_META_KEY );
201
-	}
202
-
203
-	/**
204
-	 * Fires before the permalink field in the edit form (this event is available in WP from 4.1.0).
205
-	 *
206
-	 * @since 3.2.0
207
-	 *
208
-	 * @param WP_Post $post Post object.
209
-	 */
210
-	public function edit_form_before_permalink( $post ) {
211
-
212
-		// If it's not an entity, return.
213
-		if ( ! $this->is_entity( $post->ID ) ) {
214
-			return;
215
-		}
216
-
217
-		// Print the input template.
218
-		$this->ui_service->print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
219
-
220
-		// Print all the currently set alternative labels.
221
-		foreach ( $this->get_alternate_labels( $post->ID ) as $alt_label ) {
222
-
223
-			echo $this->get_alternative_label_input( $alt_label );
224
-
225
-		};
226
-
227
-		// Print the button.
228
-		$this->ui_service->print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
229
-
230
-	}
231
-
232
-	/**
233
-	 * Get the alternative label input HTML code.
234
-	 *
235
-	 * @since 3.2.0
236
-	 *
237
-	 * @param string $value The input value.
238
-	 *
239
-	 * @return string The input HTML code.
240
-	 */
241
-	private function get_alternative_label_input( $value = '' ) {
242
-
243
-		return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), __( 'Delete', 'wordlift' ) );
244
-	}
54
+    /**
55
+     * A singleton instance of the Entity service.
56
+     *
57
+     * @since 3.2.0
58
+     * @access private
59
+     * @var \Wordlift_Entity_Service $instance A singleton instance of the Entity service.
60
+     */
61
+    private static $instance;
62
+
63
+    /**
64
+     * Create a Wordlift_Entity_Service instance.
65
+     *
66
+     * @since 3.2.0
67
+     *
68
+     * @param \Wordlift_UI_Service $ui_service The UI service.
69
+     */
70
+    public function __construct( $ui_service ) {
71
+
72
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
73
+
74
+        // Set the UI service.
75
+        $this->ui_service = $ui_service;
76
+
77
+        // Set the singleton instance.
78
+        self::$instance = $this;
79
+
80
+    }
81
+
82
+    /**
83
+     * Get the singleton instance of the Entity service.
84
+     *
85
+     * @since 3.2.0
86
+     * @return \Wordlift_Entity_Service The singleton instance of the Entity service.
87
+     */
88
+    public static function get_instance() {
89
+
90
+        return self::$instance;
91
+    }
92
+
93
+    /**
94
+     * Get the entities related to the last 50 posts published on this blog (we're keeping a long function name due to
95
+     * its specific function).
96
+     *
97
+     * @since 3.1.0
98
+     *
99
+     * @return array An array of post IDs.
100
+     */
101
+    public function get_all_related_to_last_50_published_posts() {
102
+
103
+        // Global timeline. Get entities from the latest posts.
104
+        $latest_posts_ids = get_posts( array(
105
+            'numberposts' => 50,
106
+            'fields'      => 'ids', //only get post IDs
107
+            'post_type'   => 'post',
108
+            'post_status' => 'publish'
109
+        ) );
110
+
111
+        if ( empty( $latest_posts_ids ) ) {
112
+            // There are no posts.
113
+            return array();
114
+        }
115
+
116
+        // Collect entities related to latest posts
117
+        $entity_ids = array();
118
+        foreach ( $latest_posts_ids as $id ) {
119
+            $entity_ids = array_merge( $entity_ids, wl_core_get_related_entity_ids( $id, array(
120
+                'status' => 'publish'
121
+            ) ) );
122
+        }
123
+
124
+        return $entity_ids;
125
+    }
126
+
127
+    /**
128
+     * Determines whether a post is an entity or not.
129
+     *
130
+     * @since 3.1.0
131
+     *
132
+     * @param int $post_id A post id.
133
+     *
134
+     * @return true if the post is an entity otherwise false.
135
+     */
136
+    public function is_entity( $post_id ) {
137
+
138
+        return ( self::TYPE_NAME === get_post_type( $post_id ) );
139
+    }
140
+
141
+    /**
142
+     * Fires once a post has been saved.
143
+     *
144
+     * @since 3.2.0
145
+     *
146
+     * @param int $post_id Post ID.
147
+     * @param WP_Post $post Post object.
148
+     * @param bool $update Whether this is an existing post being updated or not.
149
+     */
150
+    public function save_post( $post_id, $post, $update ) {
151
+
152
+        // If it's not an entity, return.
153
+        if ( ! $this->is_entity( $post_id ) ) {
154
+            return;
155
+        }
156
+
157
+        // Get the alt labels from the request (or empty array).
158
+        $alt_labels = isset( $_REQUEST['wl_alternative_label'] ) ? $_REQUEST['wl_alternative_label'] : array();
159
+
160
+        // Set the alternative labels.
161
+        $this->set_alternative_labels( $post_id, $alt_labels );
162
+
163
+    }
164
+
165
+    /**
166
+     * Set the alternative labels.
167
+     *
168
+     * @since 3.2.0
169
+     *
170
+     * @param int $post_id The post id.
171
+     * @param array $alt_labels An array of labels.
172
+     */
173
+    private function set_alternative_labels( $post_id, $alt_labels ) {
174
+
175
+        $this->log_service->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . " ]" );
176
+
177
+        // Delete all the existing alternate labels.
178
+        delete_post_meta( $post_id, self::ALTERNATE_LABEL_META_KEY );
179
+
180
+        // Set the alternative labels.
181
+        foreach ( $alt_labels as $alt_label ) {
182
+            if ( ! empty( $alt_label ) ) {
183
+                add_post_meta( $post_id, self::ALTERNATE_LABEL_META_KEY, $alt_label );
184
+            }
185
+        }
186
+
187
+    }
188
+
189
+    /**
190
+     * Retrieve the alternate labels.
191
+     *
192
+     * @since 3.2.0
193
+     *
194
+     * @param int $post_id Post id.
195
+     *
196
+     * @return mixed An array  of alternative labels.
197
+     */
198
+    public function get_alternate_labels( $post_id ) {
199
+
200
+        return get_post_meta( $post_id, self::ALTERNATE_LABEL_META_KEY );
201
+    }
202
+
203
+    /**
204
+     * Fires before the permalink field in the edit form (this event is available in WP from 4.1.0).
205
+     *
206
+     * @since 3.2.0
207
+     *
208
+     * @param WP_Post $post Post object.
209
+     */
210
+    public function edit_form_before_permalink( $post ) {
211
+
212
+        // If it's not an entity, return.
213
+        if ( ! $this->is_entity( $post->ID ) ) {
214
+            return;
215
+        }
216
+
217
+        // Print the input template.
218
+        $this->ui_service->print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
219
+
220
+        // Print all the currently set alternative labels.
221
+        foreach ( $this->get_alternate_labels( $post->ID ) as $alt_label ) {
222
+
223
+            echo $this->get_alternative_label_input( $alt_label );
224
+
225
+        };
226
+
227
+        // Print the button.
228
+        $this->ui_service->print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
229
+
230
+    }
231
+
232
+    /**
233
+     * Get the alternative label input HTML code.
234
+     *
235
+     * @since 3.2.0
236
+     *
237
+     * @param string $value The input value.
238
+     *
239
+     * @return string The input HTML code.
240
+     */
241
+    private function get_alternative_label_input( $value = '' ) {
242
+
243
+        return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), __( 'Delete', 'wordlift' ) );
244
+    }
245 245
 
246 246
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @param \Wordlift_UI_Service $ui_service The UI service.
69 69
 	 */
70
-	public function __construct( $ui_service ) {
70
+	public function __construct($ui_service) {
71 71
 
72
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
72
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Entity_Service');
73 73
 
74 74
 		// Set the UI service.
75 75
 		$this->ui_service = $ui_service;
@@ -101,24 +101,24 @@  discard block
 block discarded – undo
101 101
 	public function get_all_related_to_last_50_published_posts() {
102 102
 
103 103
 		// Global timeline. Get entities from the latest posts.
104
-		$latest_posts_ids = get_posts( array(
104
+		$latest_posts_ids = get_posts(array(
105 105
 			'numberposts' => 50,
106 106
 			'fields'      => 'ids', //only get post IDs
107 107
 			'post_type'   => 'post',
108 108
 			'post_status' => 'publish'
109
-		) );
109
+		));
110 110
 
111
-		if ( empty( $latest_posts_ids ) ) {
111
+		if (empty($latest_posts_ids)) {
112 112
 			// There are no posts.
113 113
 			return array();
114 114
 		}
115 115
 
116 116
 		// Collect entities related to latest posts
117 117
 		$entity_ids = array();
118
-		foreach ( $latest_posts_ids as $id ) {
119
-			$entity_ids = array_merge( $entity_ids, wl_core_get_related_entity_ids( $id, array(
118
+		foreach ($latest_posts_ids as $id) {
119
+			$entity_ids = array_merge($entity_ids, wl_core_get_related_entity_ids($id, array(
120 120
 				'status' => 'publish'
121
-			) ) );
121
+			)));
122 122
 		}
123 123
 
124 124
 		return $entity_ids;
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
 	 *
134 134
 	 * @return true if the post is an entity otherwise false.
135 135
 	 */
136
-	public function is_entity( $post_id ) {
136
+	public function is_entity($post_id) {
137 137
 
138
-		return ( self::TYPE_NAME === get_post_type( $post_id ) );
138
+		return (self::TYPE_NAME === get_post_type($post_id));
139 139
 	}
140 140
 
141 141
 	/**
@@ -147,18 +147,18 @@  discard block
 block discarded – undo
147 147
 	 * @param WP_Post $post Post object.
148 148
 	 * @param bool $update Whether this is an existing post being updated or not.
149 149
 	 */
150
-	public function save_post( $post_id, $post, $update ) {
150
+	public function save_post($post_id, $post, $update) {
151 151
 
152 152
 		// If it's not an entity, return.
153
-		if ( ! $this->is_entity( $post_id ) ) {
153
+		if ( ! $this->is_entity($post_id)) {
154 154
 			return;
155 155
 		}
156 156
 
157 157
 		// Get the alt labels from the request (or empty array).
158
-		$alt_labels = isset( $_REQUEST['wl_alternative_label'] ) ? $_REQUEST['wl_alternative_label'] : array();
158
+		$alt_labels = isset($_REQUEST['wl_alternative_label']) ? $_REQUEST['wl_alternative_label'] : array();
159 159
 
160 160
 		// Set the alternative labels.
161
-		$this->set_alternative_labels( $post_id, $alt_labels );
161
+		$this->set_alternative_labels($post_id, $alt_labels);
162 162
 
163 163
 	}
164 164
 
@@ -170,17 +170,17 @@  discard block
 block discarded – undo
170 170
 	 * @param int $post_id The post id.
171 171
 	 * @param array $alt_labels An array of labels.
172 172
 	 */
173
-	private function set_alternative_labels( $post_id, $alt_labels ) {
173
+	private function set_alternative_labels($post_id, $alt_labels) {
174 174
 
175
-		$this->log_service->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . " ]" );
175
+		$this->log_service->debug("Setting alternative labels [ post id :: $post_id ][ alt labels :: ".implode(',', $alt_labels)." ]");
176 176
 
177 177
 		// Delete all the existing alternate labels.
178
-		delete_post_meta( $post_id, self::ALTERNATE_LABEL_META_KEY );
178
+		delete_post_meta($post_id, self::ALTERNATE_LABEL_META_KEY);
179 179
 
180 180
 		// Set the alternative labels.
181
-		foreach ( $alt_labels as $alt_label ) {
182
-			if ( ! empty( $alt_label ) ) {
183
-				add_post_meta( $post_id, self::ALTERNATE_LABEL_META_KEY, $alt_label );
181
+		foreach ($alt_labels as $alt_label) {
182
+			if ( ! empty($alt_label)) {
183
+				add_post_meta($post_id, self::ALTERNATE_LABEL_META_KEY, $alt_label);
184 184
 			}
185 185
 		}
186 186
 
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
 	 *
196 196
 	 * @return mixed An array  of alternative labels.
197 197
 	 */
198
-	public function get_alternate_labels( $post_id ) {
198
+	public function get_alternate_labels($post_id) {
199 199
 
200
-		return get_post_meta( $post_id, self::ALTERNATE_LABEL_META_KEY );
200
+		return get_post_meta($post_id, self::ALTERNATE_LABEL_META_KEY);
201 201
 	}
202 202
 
203 203
 	/**
@@ -207,25 +207,25 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 * @param WP_Post $post Post object.
209 209
 	 */
210
-	public function edit_form_before_permalink( $post ) {
210
+	public function edit_form_before_permalink($post) {
211 211
 
212 212
 		// If it's not an entity, return.
213
-		if ( ! $this->is_entity( $post->ID ) ) {
213
+		if ( ! $this->is_entity($post->ID)) {
214 214
 			return;
215 215
 		}
216 216
 
217 217
 		// Print the input template.
218
-		$this->ui_service->print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
218
+		$this->ui_service->print_template('wl-tmpl-alternative-label-input', $this->get_alternative_label_input());
219 219
 
220 220
 		// Print all the currently set alternative labels.
221
-		foreach ( $this->get_alternate_labels( $post->ID ) as $alt_label ) {
221
+		foreach ($this->get_alternate_labels($post->ID) as $alt_label) {
222 222
 
223
-			echo $this->get_alternative_label_input( $alt_label );
223
+			echo $this->get_alternative_label_input($alt_label);
224 224
 
225 225
 		};
226 226
 
227 227
 		// Print the button.
228
-		$this->ui_service->print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
228
+		$this->ui_service->print_button('wl-add-alternative-labels-button', __('Add more titles', 'wordlift'));
229 229
 
230 230
 	}
231 231
 
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
 	 *
239 239
 	 * @return string The input HTML code.
240 240
 	 */
241
-	private function get_alternative_label_input( $value = '' ) {
241
+	private function get_alternative_label_input($value = '') {
242 242
 
243
-		return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), __( 'Delete', 'wordlift' ) );
243
+		return sprintf(self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr($value), __('Delete', 'wordlift'));
244 244
 	}
245 245
 
246 246
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-query-builder.php 2 patches
Indentation   +273 added lines, -273 removed lines patch added patch discarded remove patch
@@ -7,278 +7,278 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Query_Builder {
9 9
 
10
-	/**
11
-	 * The INSERT statement template.
12
-	 *
13
-	 * @since 3.1.7
14
-	 */
15
-	const INSERT = 'INSERT DATA { %s };';
16
-
17
-	/**
18
-	 * The DELETE statement template (it repeats the statements in the WHERE clause.
19
-	 *
20
-	 * @since 3.1.7
21
-	 */
22
-	const DELETE = 'DELETE { %s } WHERE { %1$s };';
23
-
24
-	/**
25
-	 * Tell the statement function to guess the object type (URI, value or parameter).
26
-	 *
27
-	 * @since 3.1.7
28
-	 */
29
-	const OBJECT_AUTO = - 1;
30
-
31
-	/**
32
-	 * Tell the statement function that the object is a URI.
33
-	 *
34
-	 * @since 3.1.7
35
-	 */
36
-	const OBJECT_URI = 0;
37
-
38
-	/**
39
-	 * Tell the statement function that the object is a value.
40
-	 *
41
-	 * @since 3.1.7
42
-	 */
43
-	const OBJECT_VALUE = 1;
44
-
45
-	/**
46
-	 * Tell the statement function that the object is a parameter.
47
-	 *
48
-	 * @since 3.1.7
49
-	 */
50
-	const OBJECT_PARAMETER = 2;
51
-
52
-	/**
53
-	 * The RDFS type.
54
-	 *
55
-	 * @since 3.1.7
56
-	 */
57
-	const RDFS_TYPE_URI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
58
-
59
-	/**
60
-	 * The schema.org/Person type.
61
-	 *
62
-	 * @since 3.1.7
63
-	 */
64
-	const SCHEMA_PERSON_URI = 'http://schema.org/Person';
65
-
66
-	/**
67
-	 * The schema.org given name predicate.
68
-	 *
69
-	 * @since 3.1.7
70
-	 */
71
-	const SCHEMA_GIVEN_NAME_URI = 'http://schema.org/givenName';
72
-
73
-	/**
74
-	 * The schema.org family name predicate.
75
-	 *
76
-	 * @since 3.1.7
77
-	 */
78
-	const SCHEMA_FAMILY_NAME_URI = 'http://schema.org/familyName';
79
-
80
-	/**
81
-	 * The schema.org url predicate.
82
-	 *
83
-	 * @since 3.1.7
84
-	 */
85
-	const SCHEMA_URL_URI = 'http://schema.org/url';
86
-
87
-	/**
88
-	 * The RDF label.
89
-	 *
90
-	 * @since 3.1.7
91
-	 */
92
-	const RDFS_LABEL_URI = 'http://www.w3.org/2000/01/rdf-schema#label';
93
-
94
-	/**
95
-	 * Hold the template (INSERT or DELETE).
96
-	 *
97
-	 * @since 3.1.7
98
-	 * @access private
99
-	 * @var string $template The query template.
100
-	 */
101
-	private $template;
102
-
103
-	/**
104
-	 * An array of statements (in the form of subject, predicate, object).
105
-	 *
106
-	 * @since 3.1.7
107
-	 * @access private
108
-	 * @var array $statements An array of statements.
109
-	 */
110
-	private $statements = array();
111
-
112
-	/**
113
-	 * Create a new instance of the Query builder (compatible with PHP 5.3).
114
-	 *
115
-	 * @since 3.1.7
116
-	 * @return Wordlift_Query_Builder A new instance of the Query builder.
117
-	 */
118
-	public static function new_instance() {
119
-
120
-		return new Wordlift_Query_Builder();
121
-	}
122
-
123
-	/**
124
-	 * Set the query to INSERT.
125
-	 *
126
-	 * @since 3.1.7
127
-	 * @return $this \Wordlift_Query_Builder The Query builder.
128
-	 */
129
-	public function insert() {
130
-
131
-		$this->template = self::INSERT;
132
-
133
-		return $this;
134
-	}
135
-
136
-	/**
137
-	 * Set the query to DELETE.
138
-	 *
139
-	 * @since 3.1.7
140
-	 * @return $this \Wordlift_Query_Builder The Query builder.
141
-	 */
142
-	public function delete() {
143
-
144
-		$this->template = self::DELETE;
145
-
146
-		return $this;
147
-	}
148
-
149
-	/**
150
-	 * Add a statement.
151
-	 *
152
-	 * @since 3.1.7
153
-	 *
154
-	 * @param string $subject The subject of the statement (must be a URI).
155
-	 * @param string $predicate The predicate (must be a URI).
156
-	 * @param string $object The object, can be a URI or a value.
157
-	 * @param int $object_type The object type, either a {@link OBJECT_URI} or a value {@link OBJECT_VALUE}. If set to {@link OBJECT_AUTO}, the Query builder will try to guess.
158
-	 * @param string|null $data_type The data type (or null).
159
-	 * @param string|null $language The language code (or null).
160
-	 *
161
-	 * @return $this \Wordlift_Query_Builder The Query builder.
162
-	 */
163
-	public function statement( $subject, $predicate, $object, $object_type = self::OBJECT_AUTO, $data_type = null, $language = null ) {
164
-
165
-		// If no value has been provided, we don't set any statement.
166
-		if ( empty( $object ) ) {
167
-			return $this;
168
-		}
169
-
170
-		// Get the object type if set, otherwise try to guess it.
171
-		$object_value_type = ( self::OBJECT_AUTO !== $object_type ?: $this->guess_object_type( $predicate, $object ) );
172
-
173
-		// Prepare the statement template.
174
-		$template = '<%1$s> <%2$s> ' . (
175
-			self::OBJECT_URI === $object_value_type ? '<%3$s>' : (
176
-			self::OBJECT_PARAMETER === $object_value_type ? '%3$s' :
177
-				// self::OBJECT_VALUE === $object_value_type
178
-				'"%3$s"' . ( isset( $data_type ) ? '^^%4$s' : '' ) . ( isset( $language ) ? '@%5$s' : '' ) ) );
179
-
180
-		// Escape the subject, predicate and object.
181
-		$escaped_subject   = $this->escape_uri( $subject );
182
-		$escaped_predicate = $this->escape_uri( $predicate );
183
-		$escaped_object    = ( self::OBJECT_URI === $object_value_type ? $this->escape_uri( $object ) : self::escape_value( $object ) );
184
-
185
-		// Prepare the statement and add it to the list of statements.
186
-		$this->statements[] = sprintf( $template, $escaped_subject, $escaped_predicate, $escaped_object, $data_type, $language );
187
-
188
-		return $this;
189
-	}
190
-
191
-	/**
192
-	 * Build the query.
193
-	 *
194
-	 * @since 3.1.7
195
-	 * @return string The query string.
196
-	 */
197
-	public function build() {
198
-
199
-		return sprintf( $this->template, implode( ' . ', $this->statements ) ) . "\n";
200
-	}
201
-
202
-	/**
203
-	 * Guess the statement object type.
204
-	 *
205
-	 * @since 3.1.7
206
-	 *
207
-	 * @param string $predicate The predicate.
208
-	 * @param string $object The object.
209
-	 *
210
-	 * @return int {@link Wordlift_Query_Builder::OBJECT_URI} if the Query builder thinks the object must be an URI, {@link Wordlift_Query_Builder::OBJECT_VALUE} otherwise.
211
-	 */
212
-	private function guess_object_type( $predicate, $object ) {
213
-
214
-		// If the object starts with a question mark, it's a parameter.
215
-		if ( 0 === strpos( $object, '?' ) ) {
216
-			return self::OBJECT_PARAMETER;
217
-		}
218
-
219
-		// Guess based on the predicate.
220
-		switch ( $predicate ) {
221
-
222
-			case self::RDFS_TYPE_URI:
223
-			case self::SCHEMA_URL_URI:
224
-				return self::OBJECT_URI;
225
-
226
-		}
227
-
228
-		return self::OBJECT_VALUE;
229
-	}
230
-
231
-	/**
232
-	 * Escape a URI.
233
-	 *
234
-	 * @since 3.1.7
235
-	 *
236
-	 * @param string $uri The URI to escape.
237
-	 *
238
-	 * @return string The escaped URI.
239
-	 */
240
-	private function escape_uri( $uri ) {
241
-
242
-		// Should we validate the IRI?
243
-		// http://www.w3.org/TR/sparql11-query/#QSynIRI
244
-
245
-		$escaped_uri = str_replace( '<', '\<', $uri );
246
-		$escaped_uri = str_replace( '>', '\>', $escaped_uri );
247
-
248
-		return $escaped_uri;
249
-	}
250
-
251
-	/**
252
-	 * Escape a value.
253
-	 *
254
-	 * @since 3.1.7
255
-	 *
256
-	 * @param string $value The value to escape.
257
-	 *
258
-	 * @return string The escaped value.
259
-	 */
260
-	public static function escape_value( $value ) {
261
-
262
-		// see http://www.w3.org/TR/rdf-sparql-query/
263
-		//    '\t'	U+0009 (tab)
264
-		//    '\n'	U+000A (line feed)
265
-		//    '\r'	U+000D (carriage return)
266
-		//    '\b'	U+0008 (backspace)
267
-		//    '\f'	U+000C (form feed)
268
-		//    '\"'	U+0022 (quotation mark, double quote mark)
269
-		//    "\'"	U+0027 (apostrophe-quote, single quote mark)
270
-		//    '\\'	U+005C (backslash)
271
-
272
-		$escaped_value = str_replace( '\\', '\\\\', $value );
273
-		$escaped_value = str_replace( '\'', '\\\'', $escaped_value );
274
-		$escaped_value = str_replace( '"', '\\"', $escaped_value );
275
-		$escaped_value = str_replace( "\f", '\\f', $escaped_value );
276
-		$escaped_value = str_replace( "\b", '\\b', $escaped_value );
277
-		$escaped_value = str_replace( "\r", '\\r', $escaped_value );
278
-		$escaped_value = str_replace( "\n", '\\n', $escaped_value );
279
-		$escaped_value = str_replace( "\t", '\\t', $escaped_value );
280
-
281
-		return $escaped_value;
282
-	}
10
+    /**
11
+     * The INSERT statement template.
12
+     *
13
+     * @since 3.1.7
14
+     */
15
+    const INSERT = 'INSERT DATA { %s };';
16
+
17
+    /**
18
+     * The DELETE statement template (it repeats the statements in the WHERE clause.
19
+     *
20
+     * @since 3.1.7
21
+     */
22
+    const DELETE = 'DELETE { %s } WHERE { %1$s };';
23
+
24
+    /**
25
+     * Tell the statement function to guess the object type (URI, value or parameter).
26
+     *
27
+     * @since 3.1.7
28
+     */
29
+    const OBJECT_AUTO = - 1;
30
+
31
+    /**
32
+     * Tell the statement function that the object is a URI.
33
+     *
34
+     * @since 3.1.7
35
+     */
36
+    const OBJECT_URI = 0;
37
+
38
+    /**
39
+     * Tell the statement function that the object is a value.
40
+     *
41
+     * @since 3.1.7
42
+     */
43
+    const OBJECT_VALUE = 1;
44
+
45
+    /**
46
+     * Tell the statement function that the object is a parameter.
47
+     *
48
+     * @since 3.1.7
49
+     */
50
+    const OBJECT_PARAMETER = 2;
51
+
52
+    /**
53
+     * The RDFS type.
54
+     *
55
+     * @since 3.1.7
56
+     */
57
+    const RDFS_TYPE_URI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
58
+
59
+    /**
60
+     * The schema.org/Person type.
61
+     *
62
+     * @since 3.1.7
63
+     */
64
+    const SCHEMA_PERSON_URI = 'http://schema.org/Person';
65
+
66
+    /**
67
+     * The schema.org given name predicate.
68
+     *
69
+     * @since 3.1.7
70
+     */
71
+    const SCHEMA_GIVEN_NAME_URI = 'http://schema.org/givenName';
72
+
73
+    /**
74
+     * The schema.org family name predicate.
75
+     *
76
+     * @since 3.1.7
77
+     */
78
+    const SCHEMA_FAMILY_NAME_URI = 'http://schema.org/familyName';
79
+
80
+    /**
81
+     * The schema.org url predicate.
82
+     *
83
+     * @since 3.1.7
84
+     */
85
+    const SCHEMA_URL_URI = 'http://schema.org/url';
86
+
87
+    /**
88
+     * The RDF label.
89
+     *
90
+     * @since 3.1.7
91
+     */
92
+    const RDFS_LABEL_URI = 'http://www.w3.org/2000/01/rdf-schema#label';
93
+
94
+    /**
95
+     * Hold the template (INSERT or DELETE).
96
+     *
97
+     * @since 3.1.7
98
+     * @access private
99
+     * @var string $template The query template.
100
+     */
101
+    private $template;
102
+
103
+    /**
104
+     * An array of statements (in the form of subject, predicate, object).
105
+     *
106
+     * @since 3.1.7
107
+     * @access private
108
+     * @var array $statements An array of statements.
109
+     */
110
+    private $statements = array();
111
+
112
+    /**
113
+     * Create a new instance of the Query builder (compatible with PHP 5.3).
114
+     *
115
+     * @since 3.1.7
116
+     * @return Wordlift_Query_Builder A new instance of the Query builder.
117
+     */
118
+    public static function new_instance() {
119
+
120
+        return new Wordlift_Query_Builder();
121
+    }
122
+
123
+    /**
124
+     * Set the query to INSERT.
125
+     *
126
+     * @since 3.1.7
127
+     * @return $this \Wordlift_Query_Builder The Query builder.
128
+     */
129
+    public function insert() {
130
+
131
+        $this->template = self::INSERT;
132
+
133
+        return $this;
134
+    }
135
+
136
+    /**
137
+     * Set the query to DELETE.
138
+     *
139
+     * @since 3.1.7
140
+     * @return $this \Wordlift_Query_Builder The Query builder.
141
+     */
142
+    public function delete() {
143
+
144
+        $this->template = self::DELETE;
145
+
146
+        return $this;
147
+    }
148
+
149
+    /**
150
+     * Add a statement.
151
+     *
152
+     * @since 3.1.7
153
+     *
154
+     * @param string $subject The subject of the statement (must be a URI).
155
+     * @param string $predicate The predicate (must be a URI).
156
+     * @param string $object The object, can be a URI or a value.
157
+     * @param int $object_type The object type, either a {@link OBJECT_URI} or a value {@link OBJECT_VALUE}. If set to {@link OBJECT_AUTO}, the Query builder will try to guess.
158
+     * @param string|null $data_type The data type (or null).
159
+     * @param string|null $language The language code (or null).
160
+     *
161
+     * @return $this \Wordlift_Query_Builder The Query builder.
162
+     */
163
+    public function statement( $subject, $predicate, $object, $object_type = self::OBJECT_AUTO, $data_type = null, $language = null ) {
164
+
165
+        // If no value has been provided, we don't set any statement.
166
+        if ( empty( $object ) ) {
167
+            return $this;
168
+        }
169
+
170
+        // Get the object type if set, otherwise try to guess it.
171
+        $object_value_type = ( self::OBJECT_AUTO !== $object_type ?: $this->guess_object_type( $predicate, $object ) );
172
+
173
+        // Prepare the statement template.
174
+        $template = '<%1$s> <%2$s> ' . (
175
+            self::OBJECT_URI === $object_value_type ? '<%3$s>' : (
176
+            self::OBJECT_PARAMETER === $object_value_type ? '%3$s' :
177
+                // self::OBJECT_VALUE === $object_value_type
178
+                '"%3$s"' . ( isset( $data_type ) ? '^^%4$s' : '' ) . ( isset( $language ) ? '@%5$s' : '' ) ) );
179
+
180
+        // Escape the subject, predicate and object.
181
+        $escaped_subject   = $this->escape_uri( $subject );
182
+        $escaped_predicate = $this->escape_uri( $predicate );
183
+        $escaped_object    = ( self::OBJECT_URI === $object_value_type ? $this->escape_uri( $object ) : self::escape_value( $object ) );
184
+
185
+        // Prepare the statement and add it to the list of statements.
186
+        $this->statements[] = sprintf( $template, $escaped_subject, $escaped_predicate, $escaped_object, $data_type, $language );
187
+
188
+        return $this;
189
+    }
190
+
191
+    /**
192
+     * Build the query.
193
+     *
194
+     * @since 3.1.7
195
+     * @return string The query string.
196
+     */
197
+    public function build() {
198
+
199
+        return sprintf( $this->template, implode( ' . ', $this->statements ) ) . "\n";
200
+    }
201
+
202
+    /**
203
+     * Guess the statement object type.
204
+     *
205
+     * @since 3.1.7
206
+     *
207
+     * @param string $predicate The predicate.
208
+     * @param string $object The object.
209
+     *
210
+     * @return int {@link Wordlift_Query_Builder::OBJECT_URI} if the Query builder thinks the object must be an URI, {@link Wordlift_Query_Builder::OBJECT_VALUE} otherwise.
211
+     */
212
+    private function guess_object_type( $predicate, $object ) {
213
+
214
+        // If the object starts with a question mark, it's a parameter.
215
+        if ( 0 === strpos( $object, '?' ) ) {
216
+            return self::OBJECT_PARAMETER;
217
+        }
218
+
219
+        // Guess based on the predicate.
220
+        switch ( $predicate ) {
221
+
222
+            case self::RDFS_TYPE_URI:
223
+            case self::SCHEMA_URL_URI:
224
+                return self::OBJECT_URI;
225
+
226
+        }
227
+
228
+        return self::OBJECT_VALUE;
229
+    }
230
+
231
+    /**
232
+     * Escape a URI.
233
+     *
234
+     * @since 3.1.7
235
+     *
236
+     * @param string $uri The URI to escape.
237
+     *
238
+     * @return string The escaped URI.
239
+     */
240
+    private function escape_uri( $uri ) {
241
+
242
+        // Should we validate the IRI?
243
+        // http://www.w3.org/TR/sparql11-query/#QSynIRI
244
+
245
+        $escaped_uri = str_replace( '<', '\<', $uri );
246
+        $escaped_uri = str_replace( '>', '\>', $escaped_uri );
247
+
248
+        return $escaped_uri;
249
+    }
250
+
251
+    /**
252
+     * Escape a value.
253
+     *
254
+     * @since 3.1.7
255
+     *
256
+     * @param string $value The value to escape.
257
+     *
258
+     * @return string The escaped value.
259
+     */
260
+    public static function escape_value( $value ) {
261
+
262
+        // see http://www.w3.org/TR/rdf-sparql-query/
263
+        //    '\t'	U+0009 (tab)
264
+        //    '\n'	U+000A (line feed)
265
+        //    '\r'	U+000D (carriage return)
266
+        //    '\b'	U+0008 (backspace)
267
+        //    '\f'	U+000C (form feed)
268
+        //    '\"'	U+0022 (quotation mark, double quote mark)
269
+        //    "\'"	U+0027 (apostrophe-quote, single quote mark)
270
+        //    '\\'	U+005C (backslash)
271
+
272
+        $escaped_value = str_replace( '\\', '\\\\', $value );
273
+        $escaped_value = str_replace( '\'', '\\\'', $escaped_value );
274
+        $escaped_value = str_replace( '"', '\\"', $escaped_value );
275
+        $escaped_value = str_replace( "\f", '\\f', $escaped_value );
276
+        $escaped_value = str_replace( "\b", '\\b', $escaped_value );
277
+        $escaped_value = str_replace( "\r", '\\r', $escaped_value );
278
+        $escaped_value = str_replace( "\n", '\\n', $escaped_value );
279
+        $escaped_value = str_replace( "\t", '\\t', $escaped_value );
280
+
281
+        return $escaped_value;
282
+    }
283 283
 
284 284
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -27 removed lines patch added patch discarded remove patch
@@ -160,30 +160,29 @@  discard block
 block discarded – undo
160 160
 	 *
161 161
 	 * @return $this \Wordlift_Query_Builder The Query builder.
162 162
 	 */
163
-	public function statement( $subject, $predicate, $object, $object_type = self::OBJECT_AUTO, $data_type = null, $language = null ) {
163
+	public function statement($subject, $predicate, $object, $object_type = self::OBJECT_AUTO, $data_type = null, $language = null) {
164 164
 
165 165
 		// If no value has been provided, we don't set any statement.
166
-		if ( empty( $object ) ) {
166
+		if (empty($object)) {
167 167
 			return $this;
168 168
 		}
169 169
 
170 170
 		// Get the object type if set, otherwise try to guess it.
171
-		$object_value_type = ( self::OBJECT_AUTO !== $object_type ?: $this->guess_object_type( $predicate, $object ) );
171
+		$object_value_type = (self::OBJECT_AUTO !== $object_type ?: $this->guess_object_type($predicate, $object));
172 172
 
173 173
 		// Prepare the statement template.
174
-		$template = '<%1$s> <%2$s> ' . (
174
+		$template = '<%1$s> <%2$s> '.(
175 175
 			self::OBJECT_URI === $object_value_type ? '<%3$s>' : (
176
-			self::OBJECT_PARAMETER === $object_value_type ? '%3$s' :
177
-				// self::OBJECT_VALUE === $object_value_type
178
-				'"%3$s"' . ( isset( $data_type ) ? '^^%4$s' : '' ) . ( isset( $language ) ? '@%5$s' : '' ) ) );
176
+			self::OBJECT_PARAMETER === $object_value_type ? '%3$s' : // self::OBJECT_VALUE === $object_value_type
177
+				'"%3$s"'.(isset($data_type) ? '^^%4$s' : '').(isset($language) ? '@%5$s' : '') ) );
179 178
 
180 179
 		// Escape the subject, predicate and object.
181
-		$escaped_subject   = $this->escape_uri( $subject );
182
-		$escaped_predicate = $this->escape_uri( $predicate );
183
-		$escaped_object    = ( self::OBJECT_URI === $object_value_type ? $this->escape_uri( $object ) : self::escape_value( $object ) );
180
+		$escaped_subject   = $this->escape_uri($subject);
181
+		$escaped_predicate = $this->escape_uri($predicate);
182
+		$escaped_object    = (self::OBJECT_URI === $object_value_type ? $this->escape_uri($object) : self::escape_value($object));
184 183
 
185 184
 		// Prepare the statement and add it to the list of statements.
186
-		$this->statements[] = sprintf( $template, $escaped_subject, $escaped_predicate, $escaped_object, $data_type, $language );
185
+		$this->statements[] = sprintf($template, $escaped_subject, $escaped_predicate, $escaped_object, $data_type, $language);
187 186
 
188 187
 		return $this;
189 188
 	}
@@ -196,7 +195,7 @@  discard block
 block discarded – undo
196 195
 	 */
197 196
 	public function build() {
198 197
 
199
-		return sprintf( $this->template, implode( ' . ', $this->statements ) ) . "\n";
198
+		return sprintf($this->template, implode(' . ', $this->statements))."\n";
200 199
 	}
201 200
 
202 201
 	/**
@@ -209,15 +208,15 @@  discard block
 block discarded – undo
209 208
 	 *
210 209
 	 * @return int {@link Wordlift_Query_Builder::OBJECT_URI} if the Query builder thinks the object must be an URI, {@link Wordlift_Query_Builder::OBJECT_VALUE} otherwise.
211 210
 	 */
212
-	private function guess_object_type( $predicate, $object ) {
211
+	private function guess_object_type($predicate, $object) {
213 212
 
214 213
 		// If the object starts with a question mark, it's a parameter.
215
-		if ( 0 === strpos( $object, '?' ) ) {
214
+		if (0 === strpos($object, '?')) {
216 215
 			return self::OBJECT_PARAMETER;
217 216
 		}
218 217
 
219 218
 		// Guess based on the predicate.
220
-		switch ( $predicate ) {
219
+		switch ($predicate) {
221 220
 
222 221
 			case self::RDFS_TYPE_URI:
223 222
 			case self::SCHEMA_URL_URI:
@@ -237,13 +236,13 @@  discard block
 block discarded – undo
237 236
 	 *
238 237
 	 * @return string The escaped URI.
239 238
 	 */
240
-	private function escape_uri( $uri ) {
239
+	private function escape_uri($uri) {
241 240
 
242 241
 		// Should we validate the IRI?
243 242
 		// http://www.w3.org/TR/sparql11-query/#QSynIRI
244 243
 
245
-		$escaped_uri = str_replace( '<', '\<', $uri );
246
-		$escaped_uri = str_replace( '>', '\>', $escaped_uri );
244
+		$escaped_uri = str_replace('<', '\<', $uri);
245
+		$escaped_uri = str_replace('>', '\>', $escaped_uri);
247 246
 
248 247
 		return $escaped_uri;
249 248
 	}
@@ -257,7 +256,7 @@  discard block
 block discarded – undo
257 256
 	 *
258 257
 	 * @return string The escaped value.
259 258
 	 */
260
-	public static function escape_value( $value ) {
259
+	public static function escape_value($value) {
261 260
 
262 261
 		// see http://www.w3.org/TR/rdf-sparql-query/
263 262
 		//    '\t'	U+0009 (tab)
@@ -269,14 +268,14 @@  discard block
 block discarded – undo
269 268
 		//    "\'"	U+0027 (apostrophe-quote, single quote mark)
270 269
 		//    '\\'	U+005C (backslash)
271 270
 
272
-		$escaped_value = str_replace( '\\', '\\\\', $value );
273
-		$escaped_value = str_replace( '\'', '\\\'', $escaped_value );
274
-		$escaped_value = str_replace( '"', '\\"', $escaped_value );
275
-		$escaped_value = str_replace( "\f", '\\f', $escaped_value );
276
-		$escaped_value = str_replace( "\b", '\\b', $escaped_value );
277
-		$escaped_value = str_replace( "\r", '\\r', $escaped_value );
278
-		$escaped_value = str_replace( "\n", '\\n', $escaped_value );
279
-		$escaped_value = str_replace( "\t", '\\t', $escaped_value );
271
+		$escaped_value = str_replace('\\', '\\\\', $value);
272
+		$escaped_value = str_replace('\'', '\\\'', $escaped_value);
273
+		$escaped_value = str_replace('"', '\\"', $escaped_value);
274
+		$escaped_value = str_replace("\f", '\\f', $escaped_value);
275
+		$escaped_value = str_replace("\b", '\\b', $escaped_value);
276
+		$escaped_value = str_replace("\r", '\\r', $escaped_value);
277
+		$escaped_value = str_replace("\n", '\\n', $escaped_value);
278
+		$escaped_value = str_replace("\t", '\\t', $escaped_value);
280 279
 
281 280
 		return $escaped_value;
282 281
 	}
Please login to merge, or discard this patch.
src/includes/class-wordlift-ui-service.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -7,80 +7,80 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_UI_Service {
9 9
 
10
-	/**
11
-	 * The button element HTML code.
12
-	 *
13
-	 * @since 3.2.0
14
-	 */
15
-	const BUTTON_HTML = '<a id="%s" class="button wl-button">%s</a>';
10
+    /**
11
+     * The button element HTML code.
12
+     *
13
+     * @since 3.2.0
14
+     */
15
+    const BUTTON_HTML = '<a id="%s" class="button wl-button">%s</a>';
16 16
 
17
-	/**
18
-	 * The template HTML code.
19
-	 *
20
-	 * @since 3.2.0
21
-	 */
22
-	const TEMPLATE_HTML = '<script id="%s" type="text/template">%s</script>';
17
+    /**
18
+     * The template HTML code.
19
+     *
20
+     * @since 3.2.0
21
+     */
22
+    const TEMPLATE_HTML = '<script id="%s" type="text/template">%s</script>';
23 23
 
24
-	/**
25
-	 * Get the button HTML.
26
-	 *
27
-	 * @since 3.2.0
28
-	 *
29
-	 * @param string $element_id The button element id.
30
-	 * @param string $label The button (translated) label.
31
-	 *
32
-	 * @return string The button HTML code.
33
-	 */
34
-	public function get_button_html( $element_id, $label ) {
24
+    /**
25
+     * Get the button HTML.
26
+     *
27
+     * @since 3.2.0
28
+     *
29
+     * @param string $element_id The button element id.
30
+     * @param string $label The button (translated) label.
31
+     *
32
+     * @return string The button HTML code.
33
+     */
34
+    public function get_button_html( $element_id, $label ) {
35 35
 
36
-		return sprintf( self::BUTTON_HTML, $element_id, esc_html( $label ) );
37
-	}
36
+        return sprintf( self::BUTTON_HTML, $element_id, esc_html( $label ) );
37
+    }
38 38
 
39
-	/**
40
-	 * Echo the button HTML.
41
-	 *
42
-	 * @since 3.2.0
43
-	 *
44
-	 * @param string $element_id The button element id.
45
-	 * @param string $label The button (translated) label.
46
-	 *
47
-	 * @return string The button HTML code.
48
-	 */
49
-	public function print_button( $element_id, $label ) {
39
+    /**
40
+     * Echo the button HTML.
41
+     *
42
+     * @since 3.2.0
43
+     *
44
+     * @param string $element_id The button element id.
45
+     * @param string $label The button (translated) label.
46
+     *
47
+     * @return string The button HTML code.
48
+     */
49
+    public function print_button( $element_id, $label ) {
50 50
 
51
-		echo( $this->get_button_html( $element_id, $label ) );
51
+        echo( $this->get_button_html( $element_id, $label ) );
52 52
 
53
-	}
53
+    }
54 54
 
55
-	/**
56
-	 * Get the HTML code for a template tag.
57
-	 *
58
-	 * @since 3.2.0
59
-	 *
60
-	 * @param string $element_id The element id.
61
-	 * @param string $body The element content.
62
-	 *
63
-	 * @return string The HTML code.
64
-	 */
65
-	public function get_template_html( $element_id, $body ) {
55
+    /**
56
+     * Get the HTML code for a template tag.
57
+     *
58
+     * @since 3.2.0
59
+     *
60
+     * @param string $element_id The element id.
61
+     * @param string $body The element content.
62
+     *
63
+     * @return string The HTML code.
64
+     */
65
+    public function get_template_html( $element_id, $body ) {
66 66
 
67
-		return sprintf( self::TEMPLATE_HTML, $element_id, $body );
68
-	}
67
+        return sprintf( self::TEMPLATE_HTML, $element_id, $body );
68
+    }
69 69
 
70
-	/**
71
-	 * Echo the HTML code for a template tag.
72
-	 *
73
-	 * @since 3.2.0
74
-	 *
75
-	 * @param string $element_id The element id.
76
-	 * @param string $body The element content.
77
-	 *
78
-	 * @return string The HTML code.
79
-	 */
80
-	public function print_template( $element_id, $body ) {
70
+    /**
71
+     * Echo the HTML code for a template tag.
72
+     *
73
+     * @since 3.2.0
74
+     *
75
+     * @param string $element_id The element id.
76
+     * @param string $body The element content.
77
+     *
78
+     * @return string The HTML code.
79
+     */
80
+    public function print_template( $element_id, $body ) {
81 81
 
82
-		echo( $this->get_template_html( $element_id, $body ) );
82
+        echo( $this->get_template_html( $element_id, $body ) );
83 83
 
84
-	}
84
+    }
85 85
 
86 86
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @return string The button HTML code.
33 33
 	 */
34
-	public function get_button_html( $element_id, $label ) {
34
+	public function get_button_html($element_id, $label) {
35 35
 
36
-		return sprintf( self::BUTTON_HTML, $element_id, esc_html( $label ) );
36
+		return sprintf(self::BUTTON_HTML, $element_id, esc_html($label));
37 37
 	}
38 38
 
39 39
 	/**
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 * @return string The button HTML code.
48 48
 	 */
49
-	public function print_button( $element_id, $label ) {
49
+	public function print_button($element_id, $label) {
50 50
 
51
-		echo( $this->get_button_html( $element_id, $label ) );
51
+		echo($this->get_button_html($element_id, $label));
52 52
 
53 53
 	}
54 54
 
@@ -62,9 +62,9 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * @return string The HTML code.
64 64
 	 */
65
-	public function get_template_html( $element_id, $body ) {
65
+	public function get_template_html($element_id, $body) {
66 66
 
67
-		return sprintf( self::TEMPLATE_HTML, $element_id, $body );
67
+		return sprintf(self::TEMPLATE_HTML, $element_id, $body);
68 68
 	}
69 69
 
70 70
 	/**
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
 	 *
78 78
 	 * @return string The HTML code.
79 79
 	 */
80
-	public function print_template( $element_id, $body ) {
80
+	public function print_template($element_id, $body) {
81 81
 
82
-		echo( $this->get_template_html( $element_id, $body ) );
82
+		echo($this->get_template_html($element_id, $body));
83 83
 
84 84
 	}
85 85
 
Please login to merge, or discard this patch.
src/includes/class-wordlift.php 2 patches
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -29,374 +29,374 @@
 block discarded – undo
29 29
  */
30 30
 class Wordlift {
31 31
 
32
-	/**
33
-	 * The loader that's responsible for maintaining and registering all hooks that power
34
-	 * the plugin.
35
-	 *
36
-	 * @since    1.0.0
37
-	 * @access   protected
38
-	 * @var      Wordlift_Loader $loader Maintains and registers all hooks for the plugin.
39
-	 */
40
-	protected $loader;
41
-
42
-	/**
43
-	 * The unique identifier of this plugin.
44
-	 *
45
-	 * @since    1.0.0
46
-	 * @access   protected
47
-	 * @var      string $plugin_name The string used to uniquely identify this plugin.
48
-	 */
49
-	protected $plugin_name;
50
-
51
-	/**
52
-	 * The current version of the plugin.
53
-	 *
54
-	 * @since    1.0.0
55
-	 * @access   protected
56
-	 * @var      string $version The current version of the plugin.
57
-	 */
58
-	protected $version;
59
-
60
-	/**
61
-	 * The Thumbnail service.
62
-	 *
63
-	 * @since 3.1.5
64
-	 * @access private
65
-	 * @var \Wordlift_Thumbnail_Service $thumbnail_service The Thumbnail service.
66
-	 */
67
-	private $thumbnail_service;
68
-
69
-	/**
70
-	 * The UI service.
71
-	 *
72
-	 * @since 3.2.0
73
-	 * @access private
74
-	 * @var \Wordlift_UI_Service $ui_service The UI service.
75
-	 */
76
-	private $ui_service;
77
-
78
-	/**
79
-	 * The Entity service.
80
-	 *
81
-	 * @since 3.1.0
82
-	 * @access private
83
-	 * @var \Wordlift_Entity_Service $entity_service The Entity service.
84
-	 */
85
-	private $entity_service;
86
-
87
-	/**
88
-	 * The User service.
89
-	 *
90
-	 * @since 3.1.7
91
-	 * @access private
92
-	 * @var \Wordlift_User_Service $user_service The User service.
93
-	 */
94
-	private $user_service;
95
-
96
-	/**
97
-	 * The Timeline service.
98
-	 *
99
-	 * @since 3.1.0
100
-	 * @access private
101
-	 * @var \Wordlift_Timeline_Service $timeline_service The Timeline service.
102
-	 */
103
-	private $timeline_service;
104
-
105
-	/**
106
-	 * The Entity Types Taxonomy Walker.
107
-	 *
108
-	 * @since 3.1.0
109
-	 * @access private
110
-	 * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker
111
-	 */
112
-	private $entity_types_taxonomy_walker;
113
-
114
-	/**
115
-	 * The ShareThis service.
116
-	 *
117
-	 * @since 3.2.0
118
-	 * @access private
119
-	 * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service.
120
-	 */
121
-	private $sharethis_service;
122
-
123
-	/**
124
-	 * Define the core functionality of the plugin.
125
-	 *
126
-	 * Set the plugin name and the plugin version that can be used throughout the plugin.
127
-	 * Load the dependencies, define the locale, and set the hooks for the admin area and
128
-	 * the public-facing side of the site.
129
-	 *
130
-	 * @since    1.0.0
131
-	 */
132
-	public function __construct() {
133
-
134
-		$this->plugin_name = 'wordlift';
135
-
136
-		$this->version = '3.2.0-dev';
137
-
138
-		$this->load_dependencies();
139
-		$this->set_locale();
140
-		$this->define_admin_hooks();
141
-		$this->define_public_hooks();
142
-
143
-	}
144
-
145
-	/**
146
-	 * Load the required dependencies for this plugin.
147
-	 *
148
-	 * Include the following files that make up the plugin:
149
-	 *
150
-	 * - Wordlift_Loader. Orchestrates the hooks of the plugin.
151
-	 * - Wordlift_i18n. Defines internationalization functionality.
152
-	 * - Wordlift_Admin. Defines all hooks for the admin area.
153
-	 * - Wordlift_Public. Defines all hooks for the public side of the site.
154
-	 *
155
-	 * Create an instance of the loader which will be used to register the hooks
156
-	 * with WordPress.
157
-	 *
158
-	 * @since    1.0.0
159
-	 * @access   private
160
-	 */
161
-	private function load_dependencies() {
162
-
163
-		/**
164
-		 * The class responsible for orchestrating the actions and filters of the
165
-		 * core plugin.
166
-		 */
167
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php';
168
-
169
-		/**
170
-		 * The class responsible for defining internationalization functionality
171
-		 * of the plugin.
172
-		 */
173
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php';
174
-
175
-		/**
176
-		 * The Log service.
177
-		 */
178
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php';
179
-
180
-		/**
181
-		 * The Query builder.
182
-		 */
183
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php';
184
-
185
-		/**
186
-		 * The Schema service.
187
-		 */
188
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php';
189
-
190
-		/**
191
-		 * The UI service.
192
-		 */
193
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php';
194
-
195
-		/**
196
-		 * The Thumbnail service.
197
-		 */
198
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php';
199
-
200
-		/**
201
-		 * The Entity Types Taxonomy service.
202
-		 */
203
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php';
204
-
205
-		/**
206
-		 * The Entity service.
207
-		 */
208
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php';
209
-
210
-		/**
211
-		 * The User service.
212
-		 */
213
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php';
214
-
215
-		/**
216
-		 * The Timeline service.
217
-		 */
218
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php';
219
-
220
-		/**
221
-		 * The class responsible for defining all actions that occur in the admin area.
222
-		 */
223
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php';
224
-
225
-		/**
226
-		 * The Entity Types Taxonomy Walker (transforms checkboxes into radios).
227
-		 */
228
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php';
229
-
230
-		/**
231
-		 * The Notice service.
232
-		 */
233
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php';
234
-
235
-		/**
236
-		 * The class responsible for defining all actions that occur in the public-facing
237
-		 * side of the site.
238
-		 */
239
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php';
240
-
241
-		/**
242
-		 * The Timeline shortcode.
243
-		 */
244
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php';
245
-
246
-		/**
247
-		 * The ShareThis service.
248
-		 */
249
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php';
250
-
251
-		$this->loader = new Wordlift_Loader();
252
-
253
-		// Instantiate a global logger.
254
-		global $wl_logger;
255
-		$wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' );
256
-
257
-		// Create an instance of the UI service.
258
-		$this->ui_service = new Wordlift_UI_Service();
259
-
260
-		// Create an instance of the Thumbnail service. Later it'll be hooked to post meta events.
261
-		$this->thumbnail_service = new Wordlift_Thumbnail_Service();
262
-
263
-		// Create an instance of the Schema service.
264
-		new Wordlift_Schema_Service();
265
-
266
-		// Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page.
267
-		$this->entity_service = new Wordlift_Entity_Service( $this->ui_service );
268
-
269
-		// Create an instance of the User service.
270
-		$this->user_service = new Wordlift_User_Service();
271
-
272
-		// Create a new instance of the Timeline service and Timeline shortcode.
273
-		$this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service );
274
-
275
-		// Create an instance of the Timeline shortcode.
276
-		new Wordlift_Timeline_Shortcode();
277
-
278
-		$this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker();
279
-
280
-		// Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters.
281
-		$this->sharethis_service = new Wordlift_ShareThis_Service();
282
-
283
-		// Create an instance of the Notice service.
284
-		new Wordlift_Notice_Service();
285
-	}
286
-
287
-	/**
288
-	 * Define the locale for this plugin for internationalization.
289
-	 *
290
-	 * Uses the Wordlift_i18n class in order to set the domain and to register the hook
291
-	 * with WordPress.
292
-	 *
293
-	 * @since    1.0.0
294
-	 * @access   private
295
-	 */
296
-	private function set_locale() {
297
-
298
-		$plugin_i18n = new Wordlift_i18n();
299
-		$plugin_i18n->set_domain( $this->get_plugin_name() );
300
-
301
-		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
302
-
303
-	}
304
-
305
-	/**
306
-	 * Register all of the hooks related to the admin area functionality
307
-	 * of the plugin.
308
-	 *
309
-	 * @since    1.0.0
310
-	 * @access   private
311
-	 */
312
-	private function define_admin_hooks() {
313
-
314
-		$plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() );
315
-
316
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
317
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
318
-
319
-		// Hook the deleted_post_meta action to the Thumbnail service.
320
-		$this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 );
321
-
322
-		// Hook the added_post_meta action to the Thumbnail service.
323
-		$this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4 );
324
-
325
-		// Hook posts inserts (or updates) to the user service.
326
-		$this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 );
327
-
328
-		// Hook the AJAX wl_timeline action to the Timeline service.
329
-		$this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' );
330
-
331
-		// Hook save_post to the entity service to update custom fields (such as alternate labels).
332
-		// We have a priority of 9 because we want to be executed before data is sent to Redlink.
333
-		$this->loader->add_filter( 'save_post', $this->entity_service, 'save_post', 9, 3 );
334
-		$this->loader->add_filter( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 );
335
-
336
-		$this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' );
337
-
338
-	}
339
-
340
-	/**
341
-	 * Register all of the hooks related to the public-facing functionality
342
-	 * of the plugin.
343
-	 *
344
-	 * @since    1.0.0
345
-	 * @access   private
346
-	 */
347
-	private function define_public_hooks() {
348
-
349
-		$plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() );
350
-
351
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
352
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
353
-
354
-		// Hook the AJAX wl_timeline action to the Timeline service.
355
-		$this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' );
356
-
357
-		// Hook the ShareThis service.
358
-		$this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 );
359
-		$this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 );
360
-	}
361
-
362
-	/**
363
-	 * Run the loader to execute all of the hooks with WordPress.
364
-	 *
365
-	 * @since    1.0.0
366
-	 */
367
-	public function run() {
368
-		$this->loader->run();
369
-	}
370
-
371
-	/**
372
-	 * The name of the plugin used to uniquely identify it within the context of
373
-	 * WordPress and to define internationalization functionality.
374
-	 *
375
-	 * @since     1.0.0
376
-	 * @return    string    The name of the plugin.
377
-	 */
378
-	public function get_plugin_name() {
379
-		return $this->plugin_name;
380
-	}
381
-
382
-	/**
383
-	 * The reference to the class that orchestrates the hooks with the plugin.
384
-	 *
385
-	 * @since     1.0.0
386
-	 * @return    Wordlift_Loader    Orchestrates the hooks of the plugin.
387
-	 */
388
-	public function get_loader() {
389
-		return $this->loader;
390
-	}
391
-
392
-	/**
393
-	 * Retrieve the version number of the plugin.
394
-	 *
395
-	 * @since     1.0.0
396
-	 * @return    string    The version number of the plugin.
397
-	 */
398
-	public function get_version() {
399
-		return $this->version;
400
-	}
32
+    /**
33
+     * The loader that's responsible for maintaining and registering all hooks that power
34
+     * the plugin.
35
+     *
36
+     * @since    1.0.0
37
+     * @access   protected
38
+     * @var      Wordlift_Loader $loader Maintains and registers all hooks for the plugin.
39
+     */
40
+    protected $loader;
41
+
42
+    /**
43
+     * The unique identifier of this plugin.
44
+     *
45
+     * @since    1.0.0
46
+     * @access   protected
47
+     * @var      string $plugin_name The string used to uniquely identify this plugin.
48
+     */
49
+    protected $plugin_name;
50
+
51
+    /**
52
+     * The current version of the plugin.
53
+     *
54
+     * @since    1.0.0
55
+     * @access   protected
56
+     * @var      string $version The current version of the plugin.
57
+     */
58
+    protected $version;
59
+
60
+    /**
61
+     * The Thumbnail service.
62
+     *
63
+     * @since 3.1.5
64
+     * @access private
65
+     * @var \Wordlift_Thumbnail_Service $thumbnail_service The Thumbnail service.
66
+     */
67
+    private $thumbnail_service;
68
+
69
+    /**
70
+     * The UI service.
71
+     *
72
+     * @since 3.2.0
73
+     * @access private
74
+     * @var \Wordlift_UI_Service $ui_service The UI service.
75
+     */
76
+    private $ui_service;
77
+
78
+    /**
79
+     * The Entity service.
80
+     *
81
+     * @since 3.1.0
82
+     * @access private
83
+     * @var \Wordlift_Entity_Service $entity_service The Entity service.
84
+     */
85
+    private $entity_service;
86
+
87
+    /**
88
+     * The User service.
89
+     *
90
+     * @since 3.1.7
91
+     * @access private
92
+     * @var \Wordlift_User_Service $user_service The User service.
93
+     */
94
+    private $user_service;
95
+
96
+    /**
97
+     * The Timeline service.
98
+     *
99
+     * @since 3.1.0
100
+     * @access private
101
+     * @var \Wordlift_Timeline_Service $timeline_service The Timeline service.
102
+     */
103
+    private $timeline_service;
104
+
105
+    /**
106
+     * The Entity Types Taxonomy Walker.
107
+     *
108
+     * @since 3.1.0
109
+     * @access private
110
+     * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker
111
+     */
112
+    private $entity_types_taxonomy_walker;
113
+
114
+    /**
115
+     * The ShareThis service.
116
+     *
117
+     * @since 3.2.0
118
+     * @access private
119
+     * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service.
120
+     */
121
+    private $sharethis_service;
122
+
123
+    /**
124
+     * Define the core functionality of the plugin.
125
+     *
126
+     * Set the plugin name and the plugin version that can be used throughout the plugin.
127
+     * Load the dependencies, define the locale, and set the hooks for the admin area and
128
+     * the public-facing side of the site.
129
+     *
130
+     * @since    1.0.0
131
+     */
132
+    public function __construct() {
133
+
134
+        $this->plugin_name = 'wordlift';
135
+
136
+        $this->version = '3.2.0-dev';
137
+
138
+        $this->load_dependencies();
139
+        $this->set_locale();
140
+        $this->define_admin_hooks();
141
+        $this->define_public_hooks();
142
+
143
+    }
144
+
145
+    /**
146
+     * Load the required dependencies for this plugin.
147
+     *
148
+     * Include the following files that make up the plugin:
149
+     *
150
+     * - Wordlift_Loader. Orchestrates the hooks of the plugin.
151
+     * - Wordlift_i18n. Defines internationalization functionality.
152
+     * - Wordlift_Admin. Defines all hooks for the admin area.
153
+     * - Wordlift_Public. Defines all hooks for the public side of the site.
154
+     *
155
+     * Create an instance of the loader which will be used to register the hooks
156
+     * with WordPress.
157
+     *
158
+     * @since    1.0.0
159
+     * @access   private
160
+     */
161
+    private function load_dependencies() {
162
+
163
+        /**
164
+         * The class responsible for orchestrating the actions and filters of the
165
+         * core plugin.
166
+         */
167
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php';
168
+
169
+        /**
170
+         * The class responsible for defining internationalization functionality
171
+         * of the plugin.
172
+         */
173
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php';
174
+
175
+        /**
176
+         * The Log service.
177
+         */
178
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php';
179
+
180
+        /**
181
+         * The Query builder.
182
+         */
183
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php';
184
+
185
+        /**
186
+         * The Schema service.
187
+         */
188
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php';
189
+
190
+        /**
191
+         * The UI service.
192
+         */
193
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php';
194
+
195
+        /**
196
+         * The Thumbnail service.
197
+         */
198
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php';
199
+
200
+        /**
201
+         * The Entity Types Taxonomy service.
202
+         */
203
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php';
204
+
205
+        /**
206
+         * The Entity service.
207
+         */
208
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php';
209
+
210
+        /**
211
+         * The User service.
212
+         */
213
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php';
214
+
215
+        /**
216
+         * The Timeline service.
217
+         */
218
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php';
219
+
220
+        /**
221
+         * The class responsible for defining all actions that occur in the admin area.
222
+         */
223
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php';
224
+
225
+        /**
226
+         * The Entity Types Taxonomy Walker (transforms checkboxes into radios).
227
+         */
228
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php';
229
+
230
+        /**
231
+         * The Notice service.
232
+         */
233
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php';
234
+
235
+        /**
236
+         * The class responsible for defining all actions that occur in the public-facing
237
+         * side of the site.
238
+         */
239
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php';
240
+
241
+        /**
242
+         * The Timeline shortcode.
243
+         */
244
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php';
245
+
246
+        /**
247
+         * The ShareThis service.
248
+         */
249
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php';
250
+
251
+        $this->loader = new Wordlift_Loader();
252
+
253
+        // Instantiate a global logger.
254
+        global $wl_logger;
255
+        $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' );
256
+
257
+        // Create an instance of the UI service.
258
+        $this->ui_service = new Wordlift_UI_Service();
259
+
260
+        // Create an instance of the Thumbnail service. Later it'll be hooked to post meta events.
261
+        $this->thumbnail_service = new Wordlift_Thumbnail_Service();
262
+
263
+        // Create an instance of the Schema service.
264
+        new Wordlift_Schema_Service();
265
+
266
+        // Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page.
267
+        $this->entity_service = new Wordlift_Entity_Service( $this->ui_service );
268
+
269
+        // Create an instance of the User service.
270
+        $this->user_service = new Wordlift_User_Service();
271
+
272
+        // Create a new instance of the Timeline service and Timeline shortcode.
273
+        $this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service );
274
+
275
+        // Create an instance of the Timeline shortcode.
276
+        new Wordlift_Timeline_Shortcode();
277
+
278
+        $this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker();
279
+
280
+        // Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters.
281
+        $this->sharethis_service = new Wordlift_ShareThis_Service();
282
+
283
+        // Create an instance of the Notice service.
284
+        new Wordlift_Notice_Service();
285
+    }
286
+
287
+    /**
288
+     * Define the locale for this plugin for internationalization.
289
+     *
290
+     * Uses the Wordlift_i18n class in order to set the domain and to register the hook
291
+     * with WordPress.
292
+     *
293
+     * @since    1.0.0
294
+     * @access   private
295
+     */
296
+    private function set_locale() {
297
+
298
+        $plugin_i18n = new Wordlift_i18n();
299
+        $plugin_i18n->set_domain( $this->get_plugin_name() );
300
+
301
+        $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
302
+
303
+    }
304
+
305
+    /**
306
+     * Register all of the hooks related to the admin area functionality
307
+     * of the plugin.
308
+     *
309
+     * @since    1.0.0
310
+     * @access   private
311
+     */
312
+    private function define_admin_hooks() {
313
+
314
+        $plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() );
315
+
316
+        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
317
+        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
318
+
319
+        // Hook the deleted_post_meta action to the Thumbnail service.
320
+        $this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 );
321
+
322
+        // Hook the added_post_meta action to the Thumbnail service.
323
+        $this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4 );
324
+
325
+        // Hook posts inserts (or updates) to the user service.
326
+        $this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 );
327
+
328
+        // Hook the AJAX wl_timeline action to the Timeline service.
329
+        $this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' );
330
+
331
+        // Hook save_post to the entity service to update custom fields (such as alternate labels).
332
+        // We have a priority of 9 because we want to be executed before data is sent to Redlink.
333
+        $this->loader->add_filter( 'save_post', $this->entity_service, 'save_post', 9, 3 );
334
+        $this->loader->add_filter( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 );
335
+
336
+        $this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' );
337
+
338
+    }
339
+
340
+    /**
341
+     * Register all of the hooks related to the public-facing functionality
342
+     * of the plugin.
343
+     *
344
+     * @since    1.0.0
345
+     * @access   private
346
+     */
347
+    private function define_public_hooks() {
348
+
349
+        $plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() );
350
+
351
+        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
352
+        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
353
+
354
+        // Hook the AJAX wl_timeline action to the Timeline service.
355
+        $this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' );
356
+
357
+        // Hook the ShareThis service.
358
+        $this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 );
359
+        $this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 );
360
+    }
361
+
362
+    /**
363
+     * Run the loader to execute all of the hooks with WordPress.
364
+     *
365
+     * @since    1.0.0
366
+     */
367
+    public function run() {
368
+        $this->loader->run();
369
+    }
370
+
371
+    /**
372
+     * The name of the plugin used to uniquely identify it within the context of
373
+     * WordPress and to define internationalization functionality.
374
+     *
375
+     * @since     1.0.0
376
+     * @return    string    The name of the plugin.
377
+     */
378
+    public function get_plugin_name() {
379
+        return $this->plugin_name;
380
+    }
381
+
382
+    /**
383
+     * The reference to the class that orchestrates the hooks with the plugin.
384
+     *
385
+     * @since     1.0.0
386
+     * @return    Wordlift_Loader    Orchestrates the hooks of the plugin.
387
+     */
388
+    public function get_loader() {
389
+        return $this->loader;
390
+    }
391
+
392
+    /**
393
+     * Retrieve the version number of the plugin.
394
+     *
395
+     * @since     1.0.0
396
+     * @return    string    The version number of the plugin.
397
+     */
398
+    public function get_version() {
399
+        return $this->version;
400
+    }
401 401
 
402 402
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -164,95 +164,95 @@  discard block
 block discarded – undo
164 164
 		 * The class responsible for orchestrating the actions and filters of the
165 165
 		 * core plugin.
166 166
 		 */
167
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php';
167
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-loader.php';
168 168
 
169 169
 		/**
170 170
 		 * The class responsible for defining internationalization functionality
171 171
 		 * of the plugin.
172 172
 		 */
173
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php';
173
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-i18n.php';
174 174
 
175 175
 		/**
176 176
 		 * The Log service.
177 177
 		 */
178
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php';
178
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-log-service.php';
179 179
 
180 180
 		/**
181 181
 		 * The Query builder.
182 182
 		 */
183
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php';
183
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-query-builder.php';
184 184
 
185 185
 		/**
186 186
 		 * The Schema service.
187 187
 		 */
188
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php';
188
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-schema-service.php';
189 189
 
190 190
 		/**
191 191
 		 * The UI service.
192 192
 		 */
193
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php';
193
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-ui-service.php';
194 194
 
195 195
 		/**
196 196
 		 * The Thumbnail service.
197 197
 		 */
198
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php';
198
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-thumbnail-service.php';
199 199
 
200 200
 		/**
201 201
 		 * The Entity Types Taxonomy service.
202 202
 		 */
203
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php';
203
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-entity-types-taxonomy-service.php';
204 204
 
205 205
 		/**
206 206
 		 * The Entity service.
207 207
 		 */
208
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php';
208
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-entity-service.php';
209 209
 
210 210
 		/**
211 211
 		 * The User service.
212 212
 		 */
213
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php';
213
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-user-service.php';
214 214
 
215 215
 		/**
216 216
 		 * The Timeline service.
217 217
 		 */
218
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php';
218
+		require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-timeline-service.php';
219 219
 
220 220
 		/**
221 221
 		 * The class responsible for defining all actions that occur in the admin area.
222 222
 		 */
223
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php';
223
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin.php';
224 224
 
225 225
 		/**
226 226
 		 * The Entity Types Taxonomy Walker (transforms checkboxes into radios).
227 227
 		 */
228
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php';
228
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-entity-types-taxonomy-walker.php';
229 229
 
230 230
 		/**
231 231
 		 * The Notice service.
232 232
 		 */
233
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php';
233
+		require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-notice-service.php';
234 234
 
235 235
 		/**
236 236
 		 * The class responsible for defining all actions that occur in the public-facing
237 237
 		 * side of the site.
238 238
 		 */
239
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php';
239
+		require_once plugin_dir_path(dirname(__FILE__)).'public/class-wordlift-public.php';
240 240
 
241 241
 		/**
242 242
 		 * The Timeline shortcode.
243 243
 		 */
244
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php';
244
+		require_once plugin_dir_path(dirname(__FILE__)).'public/class-wordlift-timeline-shortcode.php';
245 245
 
246 246
 		/**
247 247
 		 * The ShareThis service.
248 248
 		 */
249
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php';
249
+		require_once plugin_dir_path(dirname(__FILE__)).'public/class-wordlift-sharethis-service.php';
250 250
 
251 251
 		$this->loader = new Wordlift_Loader();
252 252
 
253 253
 		// Instantiate a global logger.
254 254
 		global $wl_logger;
255
-		$wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' );
255
+		$wl_logger = Wordlift_Log_Service::get_logger('WordLift');
256 256
 
257 257
 		// Create an instance of the UI service.
258 258
 		$this->ui_service = new Wordlift_UI_Service();
@@ -264,13 +264,13 @@  discard block
 block discarded – undo
264 264
 		new Wordlift_Schema_Service();
265 265
 
266 266
 		// Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page.
267
-		$this->entity_service = new Wordlift_Entity_Service( $this->ui_service );
267
+		$this->entity_service = new Wordlift_Entity_Service($this->ui_service);
268 268
 
269 269
 		// Create an instance of the User service.
270 270
 		$this->user_service = new Wordlift_User_Service();
271 271
 
272 272
 		// Create a new instance of the Timeline service and Timeline shortcode.
273
-		$this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service );
273
+		$this->timeline_service = new Wordlift_Timeline_Service($this->entity_service);
274 274
 
275 275
 		// Create an instance of the Timeline shortcode.
276 276
 		new Wordlift_Timeline_Shortcode();
@@ -296,9 +296,9 @@  discard block
 block discarded – undo
296 296
 	private function set_locale() {
297 297
 
298 298
 		$plugin_i18n = new Wordlift_i18n();
299
-		$plugin_i18n->set_domain( $this->get_plugin_name() );
299
+		$plugin_i18n->set_domain($this->get_plugin_name());
300 300
 
301
-		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
301
+		$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
302 302
 
303 303
 	}
304 304
 
@@ -311,29 +311,29 @@  discard block
 block discarded – undo
311 311
 	 */
312 312
 	private function define_admin_hooks() {
313 313
 
314
-		$plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() );
314
+		$plugin_admin = new Wordlift_Admin($this->get_plugin_name(), $this->get_version());
315 315
 
316
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
317
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
316
+		$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
317
+		$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
318 318
 
319 319
 		// Hook the deleted_post_meta action to the Thumbnail service.
320
-		$this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 );
320
+		$this->loader->add_action('deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4);
321 321
 
322 322
 		// Hook the added_post_meta action to the Thumbnail service.
323
-		$this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4 );
323
+		$this->loader->add_action('added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4);
324 324
 
325 325
 		// Hook posts inserts (or updates) to the user service.
326
-		$this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 );
326
+		$this->loader->add_action('wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3);
327 327
 
328 328
 		// Hook the AJAX wl_timeline action to the Timeline service.
329
-		$this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' );
329
+		$this->loader->add_action('wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline');
330 330
 
331 331
 		// Hook save_post to the entity service to update custom fields (such as alternate labels).
332 332
 		// We have a priority of 9 because we want to be executed before data is sent to Redlink.
333
-		$this->loader->add_filter( 'save_post', $this->entity_service, 'save_post', 9, 3 );
334
-		$this->loader->add_filter( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 );
333
+		$this->loader->add_filter('save_post', $this->entity_service, 'save_post', 9, 3);
334
+		$this->loader->add_filter('edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1);
335 335
 
336
-		$this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' );
336
+		$this->loader->add_filter('wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args');
337 337
 
338 338
 	}
339 339
 
@@ -346,17 +346,17 @@  discard block
 block discarded – undo
346 346
 	 */
347 347
 	private function define_public_hooks() {
348 348
 
349
-		$plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() );
349
+		$plugin_public = new Wordlift_Public($this->get_plugin_name(), $this->get_version());
350 350
 
351
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
352
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
351
+		$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
352
+		$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
353 353
 
354 354
 		// Hook the AJAX wl_timeline action to the Timeline service.
355
-		$this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' );
355
+		$this->loader->add_action('wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline');
356 356
 
357 357
 		// Hook the ShareThis service.
358
-		$this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 );
359
-		$this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 );
358
+		$this->loader->add_filter('the_content', $this->sharethis_service, 'the_content', 99);
359
+		$this->loader->add_filter('the_excerpt', $this->sharethis_service, 'the_excerpt', 99);
360 360
 	}
361 361
 
362 362
 	/**
Please login to merge, or discard this patch.
src/wordlift_to_redlink_data_push_callbacks.php 2 patches
Indentation   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -8,67 +8,67 @@  discard block
 block discarded – undo
8 8
 function wl_push_post_to_redlink( $post ) {
9 9
 
10 10
 
11
-	// Only handle published posts.
12
-	if ( 'post' !== $post->post_type or 'publish' !== $post->post_status ) {
13
-		wl_write_log( "wl_push_post_to_redlink : not a post or not published [ post type :: $post->post_type ][ post status :: $post->post_status ]" );
11
+    // Only handle published posts.
12
+    if ( 'post' !== $post->post_type or 'publish' !== $post->post_status ) {
13
+        wl_write_log( "wl_push_post_to_redlink : not a post or not published [ post type :: $post->post_type ][ post status :: $post->post_status ]" );
14 14
 
15
-		return;
16
-	}
15
+        return;
16
+    }
17 17
 
18
-	// Get the post URI.
19
-	$uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
18
+    // Get the post URI.
19
+    $uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
20 20
 
21
-	// If the URI ends with a trailing slash, then we have a problem.
22
-	if ( '/' === substr( $uri, - 1, 1 ) ) {
21
+    // If the URI ends with a trailing slash, then we have a problem.
22
+    if ( '/' === substr( $uri, - 1, 1 ) ) {
23 23
 
24
-		wl_write_log( "wl_push_post_to_redlink : the URI is invalid [ post ID :: $post->ID ][ URI :: $uri ]" );
24
+        wl_write_log( "wl_push_post_to_redlink : the URI is invalid [ post ID :: $post->ID ][ URI :: $uri ]" );
25 25
 
26
-		return;
27
-	}
26
+        return;
27
+    }
28 28
 
29
-	// wl_write_log( "wl_push_post_to_redlink [ post id :: $post->ID ][ uri :: $uri ]" );
29
+    // wl_write_log( "wl_push_post_to_redlink [ post id :: $post->ID ][ uri :: $uri ]" );
30 30
 
31
-	// Get the site language in order to define the literals language.
32
-	$site_language = wl_configuration_get_site_language();
31
+    // Get the site language in order to define the literals language.
32
+    $site_language = wl_configuration_get_site_language();
33 33
 
34
-	// save the author and get the author URI.
35
-	$author_uri = wl_sparql_escape_uri( Wordlift_User_Service::get_instance()->get_uri( $post->post_author ) );
34
+    // save the author and get the author URI.
35
+    $author_uri = wl_sparql_escape_uri( Wordlift_User_Service::get_instance()->get_uri( $post->post_author ) );
36 36
 
37
-	// Get other post properties.
38
-	$date_published      = wl_get_sparql_time( get_the_time( 'c', $post ) );
39
-	$date_modified       = wl_get_sparql_time( wl_get_post_modified_time( $post ) );
40
-	$title               = wordlift_esc_sparql( $post->post_title );
41
-	$permalink           = wl_sparql_escape_uri( get_permalink( $post->ID ) );
42
-	$user_comments_count = $post->comment_count;
37
+    // Get other post properties.
38
+    $date_published      = wl_get_sparql_time( get_the_time( 'c', $post ) );
39
+    $date_modified       = wl_get_sparql_time( wl_get_post_modified_time( $post ) );
40
+    $title               = wordlift_esc_sparql( $post->post_title );
41
+    $permalink           = wl_sparql_escape_uri( get_permalink( $post->ID ) );
42
+    $user_comments_count = $post->comment_count;
43 43
 
44
-	wl_write_log( "wl_push_post_to_redlink [ post_id :: $post->ID ][ type :: $post->post_type ][ slug :: $post->post_name ][ title :: $post->post_title ][ date modified :: $date_modified ][ date published :: $date_published ]" );
44
+    wl_write_log( "wl_push_post_to_redlink [ post_id :: $post->ID ][ type :: $post->post_type ][ slug :: $post->post_name ][ title :: $post->post_title ][ date modified :: $date_modified ][ date published :: $date_published ]" );
45 45
 
46
-	// create the SPARQL query.
47
-	$sparql = '';
48
-	if ( ! empty( $title ) ) {
49
-		$sparql .= "<$uri> rdfs:label '$title'@$site_language . \n";
50
-	}
46
+    // create the SPARQL query.
47
+    $sparql = '';
48
+    if ( ! empty( $title ) ) {
49
+        $sparql .= "<$uri> rdfs:label '$title'@$site_language . \n";
50
+    }
51 51
 
52
-	$sparql .= "<$uri> a <http://schema.org/BlogPosting> . \n";
53
-	$sparql .= "<$uri> schema:url <$permalink> . \n";
54
-	$sparql .= "<$uri> schema:datePublished $date_published . \n";
55
-	$sparql .= "<$uri> schema:dateModified $date_modified . \n";
56
-	if ( ! empty( $author_uri ) ) {
57
-		$sparql .= "<$uri> schema:author <$author_uri> . \n";
58
-	}
59
-	$sparql .= "<$uri> schema:interactionCount 'UserComments:$user_comments_count' . \n";
52
+    $sparql .= "<$uri> a <http://schema.org/BlogPosting> . \n";
53
+    $sparql .= "<$uri> schema:url <$permalink> . \n";
54
+    $sparql .= "<$uri> schema:datePublished $date_published . \n";
55
+    $sparql .= "<$uri> schema:dateModified $date_modified . \n";
56
+    if ( ! empty( $author_uri ) ) {
57
+        $sparql .= "<$uri> schema:author <$author_uri> . \n";
58
+    }
59
+    $sparql .= "<$uri> schema:interactionCount 'UserComments:$user_comments_count' . \n";
60 60
 
61 61
 
62
-	// Add SPARQL stmts to write the schema:image.
63
-	$sparql .= wl_get_sparql_images( $uri, $post->ID );
62
+    // Add SPARQL stmts to write the schema:image.
63
+    $sparql .= wl_get_sparql_images( $uri, $post->ID );
64 64
 
65
-	// Get the SPARQL fragment with the dcterms:references statement.
66
-	$sparql .= wl_get_sparql_post_references( $post->ID );
65
+    // Get the SPARQL fragment with the dcterms:references statement.
66
+    $sparql .= wl_get_sparql_post_references( $post->ID );
67 67
 
68
-	// create the query:
69
-	//  - remove existing references to entities.
70
-	//  - set the new post information (including references).
71
-	$query = rl_sparql_prefixes() . <<<EOF
68
+    // create the query:
69
+    //  - remove existing references to entities.
70
+    //  - set the new post information (including references).
71
+    $query = rl_sparql_prefixes() . <<<EOF
72 72
             DELETE { <$uri> dct:references ?o . }
73 73
             WHERE  { <$uri> dct:references ?o . };
74 74
             DELETE { <$uri> schema:url ?o . }
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
             INSERT DATA { $sparql };
91 91
 EOF;
92 92
 
93
-	// execute the query.
94
-	rl_execute_sparql_update_query( $query );
93
+    // execute the query.
94
+    rl_execute_sparql_update_query( $query );
95 95
 }
96 96
 
97 97
 /**
@@ -101,153 +101,153 @@  discard block
 block discarded – undo
101 101
  */
102 102
 function wl_push_entity_post_to_redlink( $entity_post ) {
103 103
 
104
-	// Get the Entity service instance to perform actions related to entities.
105
-	$entity_service = Wordlift_Entity_Service::get_instance();
104
+    // Get the Entity service instance to perform actions related to entities.
105
+    $entity_service = Wordlift_Entity_Service::get_instance();
106 106
 
107
-	// Only handle published entities.
108
-	if ( ! $entity_service->is_entity( $entity_post->ID ) || 'publish' !== $entity_post->post_status ) {
107
+    // Only handle published entities.
108
+    if ( ! $entity_service->is_entity( $entity_post->ID ) || 'publish' !== $entity_post->post_status ) {
109 109
 
110
-		wl_write_log( "wl_push_entity_post_to_redlink : not an entity or not published [ post type :: $entity_post->post_type ][ post status :: $entity_post->post_status ]" );
110
+        wl_write_log( "wl_push_entity_post_to_redlink : not an entity or not published [ post type :: $entity_post->post_type ][ post status :: $entity_post->post_status ]" );
111 111
 
112
-		return;
113
-	}
112
+        return;
113
+    }
114 114
 
115
-	// get the entity URI and the SPARQL escaped version.
116
-	$uri   = wl_get_entity_uri( $entity_post->ID );
117
-	$uri_e = wl_sparql_escape_uri( $uri );
115
+    // get the entity URI and the SPARQL escaped version.
116
+    $uri   = wl_get_entity_uri( $entity_post->ID );
117
+    $uri_e = wl_sparql_escape_uri( $uri );
118 118
 
119
-	// If the URI ends with a trailing slash, then we have a problem.
120
-	if ( '/' === substr( $uri, - 1, 1 ) ) {
119
+    // If the URI ends with a trailing slash, then we have a problem.
120
+    if ( '/' === substr( $uri, - 1, 1 ) ) {
121 121
 
122
-		wl_write_log( "wl_push_entity_post_to_redlink : the URI is invalid [ post ID :: $entity_post->ID ][ URI :: $uri ]" );
122
+        wl_write_log( "wl_push_entity_post_to_redlink : the URI is invalid [ post ID :: $entity_post->ID ][ URI :: $uri ]" );
123 123
 
124
-		return;
125
-	}
124
+        return;
125
+    }
126 126
 
127
-	// Get the site language in order to define the literals language.
128
-	$site_language = wl_configuration_get_site_language();
127
+    // Get the site language in order to define the literals language.
128
+    $site_language = wl_configuration_get_site_language();
129 129
 
130
-	// get the title and content as label and description.
131
-	$label     = wordlift_esc_sparql( $entity_post->post_title );
132
-	$descr     = wordlift_esc_sparql( wp_strip_all_tags( strip_shortcodes( $entity_post->post_content ) ) );
133
-	$permalink = wl_sparql_escape_uri( get_permalink( $entity_post->ID ) );
130
+    // get the title and content as label and description.
131
+    $label     = wordlift_esc_sparql( $entity_post->post_title );
132
+    $descr     = wordlift_esc_sparql( wp_strip_all_tags( strip_shortcodes( $entity_post->post_content ) ) );
133
+    $permalink = wl_sparql_escape_uri( get_permalink( $entity_post->ID ) );
134 134
 
135
-	// wl_write_log( "wl_push_entity_post_to_redlink [ entity post id :: $entity_post->ID ][ uri :: $uri ][ label :: $label ]" );
135
+    // wl_write_log( "wl_push_entity_post_to_redlink [ entity post id :: $entity_post->ID ][ uri :: $uri ][ label :: $label ]" );
136 136
 
137
-	// create a new empty statement.
138
-	$delete_stmt = '';
139
-	$sparql      = '';
137
+    // create a new empty statement.
138
+    $delete_stmt = '';
139
+    $sparql      = '';
140 140
 
141
-	// delete on RL all statements regarding properties set from WL (necessary when changing entity type)
142
-	$all_custom_fields        = wl_entity_taxonomy_get_custom_fields();
143
-	$predicates_to_be_deleted = array();
144
-	foreach ( $all_custom_fields as $type => $fields ) {
145
-		foreach ( $fields as $cf ) {
146
-			$predicate = $cf['predicate'];
147
-			if ( ! in_array( $predicate, $predicates_to_be_deleted ) ) {
148
-				$predicates_to_be_deleted[] = $predicate;
149
-				$delete_stmt .= "DELETE { <$uri_e> <$predicate> ?o } WHERE  { <$uri_e> <$predicate> ?o };\n";
150
-			}
151
-		}
152
-	}
141
+    // delete on RL all statements regarding properties set from WL (necessary when changing entity type)
142
+    $all_custom_fields        = wl_entity_taxonomy_get_custom_fields();
143
+    $predicates_to_be_deleted = array();
144
+    foreach ( $all_custom_fields as $type => $fields ) {
145
+        foreach ( $fields as $cf ) {
146
+            $predicate = $cf['predicate'];
147
+            if ( ! in_array( $predicate, $predicates_to_be_deleted ) ) {
148
+                $predicates_to_be_deleted[] = $predicate;
149
+                $delete_stmt .= "DELETE { <$uri_e> <$predicate> ?o } WHERE  { <$uri_e> <$predicate> ?o };\n";
150
+            }
151
+        }
152
+    }
153 153
 
154
-	// set the same as.
155
-	$same_as = wl_schema_get_value( $entity_post->ID, 'sameAs' );
156
-	foreach ( $same_as as $same_as_uri ) {
157
-		$same_as_uri_esc = wl_sparql_escape_uri( $same_as_uri );
158
-		$sparql .= "<$uri_e> owl:sameAs <$same_as_uri_esc> . \n";
159
-	}
154
+    // set the same as.
155
+    $same_as = wl_schema_get_value( $entity_post->ID, 'sameAs' );
156
+    foreach ( $same_as as $same_as_uri ) {
157
+        $same_as_uri_esc = wl_sparql_escape_uri( $same_as_uri );
158
+        $sparql .= "<$uri_e> owl:sameAs <$same_as_uri_esc> . \n";
159
+    }
160 160
 
161
-	// set the label
162
-	$sparql .= "<$uri_e> rdfs:label \"$label\"@$site_language . \n";
161
+    // set the label
162
+    $sparql .= "<$uri_e> rdfs:label \"$label\"@$site_language . \n";
163 163
 
164
-	// Set the alternative labels.
165
-	$alt_labels = $entity_service->get_alternate_labels( $entity_post->ID );
166
-	foreach ( $alt_labels as $alt_label ) {
167
-		$sparql .= sprintf( '<%s> rdfs:label "%s"@%s . ', $uri_e, Wordlift_Query_Builder::escape_value( $alt_label ), $site_language );
168
-	}
164
+    // Set the alternative labels.
165
+    $alt_labels = $entity_service->get_alternate_labels( $entity_post->ID );
166
+    foreach ( $alt_labels as $alt_label ) {
167
+        $sparql .= sprintf( '<%s> rdfs:label "%s"@%s . ', $uri_e, Wordlift_Query_Builder::escape_value( $alt_label ), $site_language );
168
+    }
169 169
 
170
-	// set the URL
171
-	$sparql .= "<$uri_e> schema:url <$permalink> . \n";
170
+    // set the URL
171
+    $sparql .= "<$uri_e> schema:url <$permalink> . \n";
172 172
 
173
-	// set the description.
174
-	if ( ! empty( $descr ) ) {
175
-		$sparql .= "<$uri_e> schema:description \"$descr\"@$site_language . \n";
176
-	}
173
+    // set the description.
174
+    if ( ! empty( $descr ) ) {
175
+        $sparql .= "<$uri_e> schema:description \"$descr\"@$site_language . \n";
176
+    }
177 177
 
178
-	$main_type = wl_entity_type_taxonomy_get_type( $entity_post->ID );
178
+    $main_type = wl_entity_type_taxonomy_get_type( $entity_post->ID );
179 179
 
180
-	if ( null != $main_type ) {
181
-		$main_type_uri = wl_sparql_escape_uri( $main_type['uri'] );
182
-		$sparql .= " <$uri_e> a <$main_type_uri> . \n";
180
+    if ( null != $main_type ) {
181
+        $main_type_uri = wl_sparql_escape_uri( $main_type['uri'] );
182
+        $sparql .= " <$uri_e> a <$main_type_uri> . \n";
183 183
 
184
-		// The type define custom fields that hold additional data about the entity.
185
-		// For example Events may have start/end dates, Places may have coordinates.
186
-		// The value in the export fields must be rewritten as triple predicates, this
187
-		// is what we're going to do here.
184
+        // The type define custom fields that hold additional data about the entity.
185
+        // For example Events may have start/end dates, Places may have coordinates.
186
+        // The value in the export fields must be rewritten as triple predicates, this
187
+        // is what we're going to do here.
188 188
 
189 189
 //		wl_write_log( 'wl_push_entity_post_to_redlink : checking if entity has export fields [ type :: ' . var_export( $main_type, true ) . ' ]' );
190 190
 
191
-		if ( isset( $main_type['custom_fields'] ) ) {
192
-			foreach ( $main_type['custom_fields'] as $field => $settings ) {
193
-
194
-				// wl_write_log( "wl_push_entity_post_to_redlink : entity has export fields" );
195
-
196
-				$predicate = wordlift_esc_sparql( $settings['predicate'] );
197
-				if ( ! isset( $settings['export_type'] ) || empty( $settings['export_type'] ) ) {
198
-					$type = null;
199
-				} else {
200
-					$type = $settings['export_type'];
201
-				}
202
-
203
-				foreach ( get_post_meta( $entity_post->ID, $field ) as $value ) {
204
-					$sparql .= " <$uri_e> <$predicate> ";
205
-
206
-					if ( ! is_null( $type ) && ( substr( $type, 0, 4 ) == 'http' ) ) {
207
-						// Type is defined by a raw uri (es. http://schema.org/PostalAddress)
208
-
209
-						// Extract uri if the value is numeric
210
-						if ( is_numeric( $value ) ) {
211
-							$value = wl_get_entity_uri( $value );
212
-						}
213
-
214
-						$sparql .= '<' . wl_sparql_escape_uri( $value ) . '>';
215
-					} else {
216
-						// Type is defined in another way (es. xsd:double)
217
-						$sparql .= '"' . wordlift_esc_sparql( $value ) . '"^^' . wordlift_esc_sparql( $type );
218
-					}
219
-
220
-					$sparql .= " . \n";
221
-				}
222
-			}
223
-		}
224
-	}
225
-
226
-	// Get the entity types.
227
-	$type_uris = wl_get_entity_rdf_types( $entity_post->ID );
228
-
229
-	// Support type are only schema.org ones: it could be null
230
-	foreach ( $type_uris as $type_uri ) {
231
-		$type_uri = wl_sparql_escape_uri( $type_uri );
232
-		$sparql .= "<$uri_e> a <$type_uri> . \n";
233
-	}
234
-
235
-	// get related entities.
236
-	$related_entities_ids = wl_core_get_related_entity_ids( $entity_post->ID );
237
-
238
-	if ( is_array( $related_entities_ids ) ) {
239
-		foreach ( $related_entities_ids as $entity_post_id ) {
240
-			$related_entity_uri = wl_sparql_escape_uri( wl_get_entity_uri( $entity_post_id ) );
241
-			// create a two-way relationship.
242
-			$sparql .= " <$uri_e> dct:relation <$related_entity_uri> . \n";
243
-			$sparql .= " <$related_entity_uri> dct:relation <$uri_e> . \n";
244
-		}
245
-	}
246
-
247
-	// Add SPARQL stmts to write the schema:image.
248
-	$sparql .= wl_get_sparql_images( $uri, $entity_post->ID );
249
-
250
-	$query = rl_sparql_prefixes() . <<<EOF
191
+        if ( isset( $main_type['custom_fields'] ) ) {
192
+            foreach ( $main_type['custom_fields'] as $field => $settings ) {
193
+
194
+                // wl_write_log( "wl_push_entity_post_to_redlink : entity has export fields" );
195
+
196
+                $predicate = wordlift_esc_sparql( $settings['predicate'] );
197
+                if ( ! isset( $settings['export_type'] ) || empty( $settings['export_type'] ) ) {
198
+                    $type = null;
199
+                } else {
200
+                    $type = $settings['export_type'];
201
+                }
202
+
203
+                foreach ( get_post_meta( $entity_post->ID, $field ) as $value ) {
204
+                    $sparql .= " <$uri_e> <$predicate> ";
205
+
206
+                    if ( ! is_null( $type ) && ( substr( $type, 0, 4 ) == 'http' ) ) {
207
+                        // Type is defined by a raw uri (es. http://schema.org/PostalAddress)
208
+
209
+                        // Extract uri if the value is numeric
210
+                        if ( is_numeric( $value ) ) {
211
+                            $value = wl_get_entity_uri( $value );
212
+                        }
213
+
214
+                        $sparql .= '<' . wl_sparql_escape_uri( $value ) . '>';
215
+                    } else {
216
+                        // Type is defined in another way (es. xsd:double)
217
+                        $sparql .= '"' . wordlift_esc_sparql( $value ) . '"^^' . wordlift_esc_sparql( $type );
218
+                    }
219
+
220
+                    $sparql .= " . \n";
221
+                }
222
+            }
223
+        }
224
+    }
225
+
226
+    // Get the entity types.
227
+    $type_uris = wl_get_entity_rdf_types( $entity_post->ID );
228
+
229
+    // Support type are only schema.org ones: it could be null
230
+    foreach ( $type_uris as $type_uri ) {
231
+        $type_uri = wl_sparql_escape_uri( $type_uri );
232
+        $sparql .= "<$uri_e> a <$type_uri> . \n";
233
+    }
234
+
235
+    // get related entities.
236
+    $related_entities_ids = wl_core_get_related_entity_ids( $entity_post->ID );
237
+
238
+    if ( is_array( $related_entities_ids ) ) {
239
+        foreach ( $related_entities_ids as $entity_post_id ) {
240
+            $related_entity_uri = wl_sparql_escape_uri( wl_get_entity_uri( $entity_post_id ) );
241
+            // create a two-way relationship.
242
+            $sparql .= " <$uri_e> dct:relation <$related_entity_uri> . \n";
243
+            $sparql .= " <$related_entity_uri> dct:relation <$uri_e> . \n";
244
+        }
245
+    }
246
+
247
+    // Add SPARQL stmts to write the schema:image.
248
+    $sparql .= wl_get_sparql_images( $uri, $entity_post->ID );
249
+
250
+    $query = rl_sparql_prefixes() . <<<EOF
251 251
     $delete_stmt
252 252
     DELETE { <$uri_e> rdfs:label ?o } WHERE  { <$uri_e> rdfs:label ?o };
253 253
     DELETE { <$uri_e> owl:sameAs ?o . } WHERE  { <$uri_e> owl:sameAs ?o . };
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
     INSERT DATA { $sparql };
260 260
 EOF;
261 261
 
262
-	rl_execute_sparql_update_query( $query );
262
+    rl_execute_sparql_update_query( $query );
263 263
 }
264 264
 
265 265
 /**
@@ -271,20 +271,20 @@  discard block
 block discarded – undo
271 271
  */
272 272
 function wl_get_sparql_post_references( $post_id ) {
273 273
 
274
-	// Get the post URI.
275
-	$post_uri = wordlift_esc_sparql( wl_get_entity_uri( $post_id ) );
274
+    // Get the post URI.
275
+    $post_uri = wordlift_esc_sparql( wl_get_entity_uri( $post_id ) );
276 276
 
277
-	// Get the related entities IDs.
278
-	$related = wl_core_get_related_entity_ids( $post_id );
277
+    // Get the related entities IDs.
278
+    $related = wl_core_get_related_entity_ids( $post_id );
279 279
 
280
-	// Build the SPARQL fragment.
281
-	$sparql = '';
282
-	foreach ( $related as $id ) {
283
-		$uri = wordlift_esc_sparql( wl_get_entity_uri( $id ) );
284
-		$sparql .= "<$post_uri> dct:references <$uri> . ";
285
-	}
280
+    // Build the SPARQL fragment.
281
+    $sparql = '';
282
+    foreach ( $related as $id ) {
283
+        $uri = wordlift_esc_sparql( wl_get_entity_uri( $id ) );
284
+        $sparql .= "<$post_uri> dct:references <$uri> . ";
285
+    }
286 286
 
287
-	return $sparql;
287
+    return $sparql;
288 288
 }
289 289
 
290 290
 /**
@@ -294,12 +294,12 @@  discard block
 block discarded – undo
294 294
  */
295 295
 function rl_sparql_prefixes() {
296 296
 
297
-	$prefixes = '';
298
-	foreach ( wl_prefixes() as $prefix => $uri ) {
299
-		$prefixes .= "PREFIX $prefix: <$uri>\n";
300
-	}
297
+    $prefixes = '';
298
+    foreach ( wl_prefixes() as $prefix => $uri ) {
299
+        $prefixes .= "PREFIX $prefix: <$uri>\n";
300
+    }
301 301
 
302
-	return $prefixes;
302
+    return $prefixes;
303 303
 }
304 304
 
305 305
 /**
@@ -310,26 +310,26 @@  discard block
 block discarded – undo
310 310
  * @return string The escaped string.
311 311
  */
312 312
 function wordlift_esc_sparql( $string ) {
313
-	// see http://www.w3.org/TR/rdf-sparql-query/
314
-	//    '\t'	U+0009 (tab)
315
-	//    '\n'	U+000A (line feed)
316
-	//    '\r'	U+000D (carriage return)
317
-	//    '\b'	U+0008 (backspace)
318
-	//    '\f'	U+000C (form feed)
319
-	//    '\"'	U+0022 (quotation mark, double quote mark)
320
-	//    "\'"	U+0027 (apostrophe-quote, single quote mark)
321
-	//    '\\'	U+005C (backslash)
322
-
323
-	$string = str_replace( '\\', '\\\\', $string );
324
-	$string = str_replace( '\'', '\\\'', $string );
325
-	$string = str_replace( '"', '\\"', $string );
326
-	$string = str_replace( "\f", '\\f', $string );
327
-	$string = str_replace( "\b", '\\b', $string );
328
-	$string = str_replace( "\r", '\\r', $string );
329
-	$string = str_replace( "\n", '\\n', $string );
330
-	$string = str_replace( "\t", '\\t', $string );
331
-
332
-	return $string;
313
+    // see http://www.w3.org/TR/rdf-sparql-query/
314
+    //    '\t'	U+0009 (tab)
315
+    //    '\n'	U+000A (line feed)
316
+    //    '\r'	U+000D (carriage return)
317
+    //    '\b'	U+0008 (backspace)
318
+    //    '\f'	U+000C (form feed)
319
+    //    '\"'	U+0022 (quotation mark, double quote mark)
320
+    //    "\'"	U+0027 (apostrophe-quote, single quote mark)
321
+    //    '\\'	U+005C (backslash)
322
+
323
+    $string = str_replace( '\\', '\\\\', $string );
324
+    $string = str_replace( '\'', '\\\'', $string );
325
+    $string = str_replace( '"', '\\"', $string );
326
+    $string = str_replace( "\f", '\\f', $string );
327
+    $string = str_replace( "\b", '\\b', $string );
328
+    $string = str_replace( "\r", '\\r', $string );
329
+    $string = str_replace( "\n", '\\n', $string );
330
+    $string = str_replace( "\t", '\\t', $string );
331
+
332
+    return $string;
333 333
 }
334 334
 
335 335
 /**
@@ -343,13 +343,13 @@  discard block
 block discarded – undo
343 343
  */
344 344
 function wl_sparql_escape_uri( $string ) {
345 345
 
346
-	// Should we validate the IRI?
347
-	// http://www.w3.org/TR/sparql11-query/#QSynIRI
346
+    // Should we validate the IRI?
347
+    // http://www.w3.org/TR/sparql11-query/#QSynIRI
348 348
 
349
-	$string = str_replace( '<', '\<', $string );
350
-	$string = str_replace( '>', '\>', $string );
349
+    $string = str_replace( '<', '\<', $string );
350
+    $string = str_replace( '>', '\>', $string );
351 351
 
352
-	return $string;
352
+    return $string;
353 353
 
354 354
 }
355 355
 
@@ -358,35 +358,35 @@  discard block
 block discarded – undo
358 358
  */
359 359
 function wordlift_reindex_triple_store() {
360 360
 
361
-	// Get the reindex URL.
362
-	$url = wl_configuration_get_dataset_index_url();
361
+    // Get the reindex URL.
362
+    $url = wl_configuration_get_dataset_index_url();
363 363
 
364
-	// Post the request.
365
-	// wl_write_log( "wordlift_reindex_triple_store" );
364
+    // Post the request.
365
+    // wl_write_log( "wordlift_reindex_triple_store" );
366 366
 
367
-	// Prepare the request.
368
-	$args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array(
369
-		'method'  => 'POST',
370
-		'headers' => array()
371
-	) );
367
+    // Prepare the request.
368
+    $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array(
369
+        'method'  => 'POST',
370
+        'headers' => array()
371
+    ) );
372 372
 
373
-	$response = wp_remote_request( $url, $args );
373
+    $response = wp_remote_request( $url, $args );
374 374
 
375
-	// If an error has been raised, return the error.
376
-	if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) {
375
+    // If an error has been raised, return the error.
376
+    if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) {
377 377
 
378
-		$body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] );
378
+        $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] );
379 379
 
380
-		wl_write_log( "wordlift_reindex_triple_store : error [ url :: $url ][ args :: " );
381
-		wl_write_log( "\n" . var_export( $args, true ) );
382
-		wl_write_log( "[ response :: " );
383
-		wl_write_log( "\n" . var_export( $response, true ) );
384
-		wl_write_log( "][ body :: " );
385
-		wl_write_log( "\n" . $body );
386
-		wl_write_log( "]" );
380
+        wl_write_log( "wordlift_reindex_triple_store : error [ url :: $url ][ args :: " );
381
+        wl_write_log( "\n" . var_export( $args, true ) );
382
+        wl_write_log( "[ response :: " );
383
+        wl_write_log( "\n" . var_export( $response, true ) );
384
+        wl_write_log( "][ body :: " );
385
+        wl_write_log( "\n" . $body );
386
+        wl_write_log( "]" );
387 387
 
388
-		return false;
389
-	}
388
+        return false;
389
+    }
390 390
 
391
-	return true;
391
+    return true;
392 392
 }
393 393
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -5,23 +5,23 @@  discard block
 block discarded – undo
5 5
  *
6 6
  * @param object $post A post instance.
7 7
  */
8
-function wl_push_post_to_redlink( $post ) {
8
+function wl_push_post_to_redlink($post) {
9 9
 
10 10
 
11 11
 	// Only handle published posts.
12
-	if ( 'post' !== $post->post_type or 'publish' !== $post->post_status ) {
13
-		wl_write_log( "wl_push_post_to_redlink : not a post or not published [ post type :: $post->post_type ][ post status :: $post->post_status ]" );
12
+	if ('post' !== $post->post_type or 'publish' !== $post->post_status) {
13
+		wl_write_log("wl_push_post_to_redlink : not a post or not published [ post type :: $post->post_type ][ post status :: $post->post_status ]");
14 14
 
15 15
 		return;
16 16
 	}
17 17
 
18 18
 	// Get the post URI.
19
-	$uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) );
19
+	$uri = wl_sparql_escape_uri(wl_get_entity_uri($post->ID));
20 20
 
21 21
 	// If the URI ends with a trailing slash, then we have a problem.
22
-	if ( '/' === substr( $uri, - 1, 1 ) ) {
22
+	if ('/' === substr($uri, - 1, 1)) {
23 23
 
24
-		wl_write_log( "wl_push_post_to_redlink : the URI is invalid [ post ID :: $post->ID ][ URI :: $uri ]" );
24
+		wl_write_log("wl_push_post_to_redlink : the URI is invalid [ post ID :: $post->ID ][ URI :: $uri ]");
25 25
 
26 26
 		return;
27 27
 	}
@@ -32,20 +32,20 @@  discard block
 block discarded – undo
32 32
 	$site_language = wl_configuration_get_site_language();
33 33
 
34 34
 	// save the author and get the author URI.
35
-	$author_uri = wl_sparql_escape_uri( Wordlift_User_Service::get_instance()->get_uri( $post->post_author ) );
35
+	$author_uri = wl_sparql_escape_uri(Wordlift_User_Service::get_instance()->get_uri($post->post_author));
36 36
 
37 37
 	// Get other post properties.
38
-	$date_published      = wl_get_sparql_time( get_the_time( 'c', $post ) );
39
-	$date_modified       = wl_get_sparql_time( wl_get_post_modified_time( $post ) );
40
-	$title               = wordlift_esc_sparql( $post->post_title );
41
-	$permalink           = wl_sparql_escape_uri( get_permalink( $post->ID ) );
38
+	$date_published      = wl_get_sparql_time(get_the_time('c', $post));
39
+	$date_modified       = wl_get_sparql_time(wl_get_post_modified_time($post));
40
+	$title               = wordlift_esc_sparql($post->post_title);
41
+	$permalink           = wl_sparql_escape_uri(get_permalink($post->ID));
42 42
 	$user_comments_count = $post->comment_count;
43 43
 
44
-	wl_write_log( "wl_push_post_to_redlink [ post_id :: $post->ID ][ type :: $post->post_type ][ slug :: $post->post_name ][ title :: $post->post_title ][ date modified :: $date_modified ][ date published :: $date_published ]" );
44
+	wl_write_log("wl_push_post_to_redlink [ post_id :: $post->ID ][ type :: $post->post_type ][ slug :: $post->post_name ][ title :: $post->post_title ][ date modified :: $date_modified ][ date published :: $date_published ]");
45 45
 
46 46
 	// create the SPARQL query.
47 47
 	$sparql = '';
48
-	if ( ! empty( $title ) ) {
48
+	if ( ! empty($title)) {
49 49
 		$sparql .= "<$uri> rdfs:label '$title'@$site_language . \n";
50 50
 	}
51 51
 
@@ -53,22 +53,22 @@  discard block
 block discarded – undo
53 53
 	$sparql .= "<$uri> schema:url <$permalink> . \n";
54 54
 	$sparql .= "<$uri> schema:datePublished $date_published . \n";
55 55
 	$sparql .= "<$uri> schema:dateModified $date_modified . \n";
56
-	if ( ! empty( $author_uri ) ) {
56
+	if ( ! empty($author_uri)) {
57 57
 		$sparql .= "<$uri> schema:author <$author_uri> . \n";
58 58
 	}
59 59
 	$sparql .= "<$uri> schema:interactionCount 'UserComments:$user_comments_count' . \n";
60 60
 
61 61
 
62 62
 	// Add SPARQL stmts to write the schema:image.
63
-	$sparql .= wl_get_sparql_images( $uri, $post->ID );
63
+	$sparql .= wl_get_sparql_images($uri, $post->ID);
64 64
 
65 65
 	// Get the SPARQL fragment with the dcterms:references statement.
66
-	$sparql .= wl_get_sparql_post_references( $post->ID );
66
+	$sparql .= wl_get_sparql_post_references($post->ID);
67 67
 
68 68
 	// create the query:
69 69
 	//  - remove existing references to entities.
70 70
 	//  - set the new post information (including references).
71
-	$query = rl_sparql_prefixes() . <<<EOF
71
+	$query = rl_sparql_prefixes().<<<EOF
72 72
             DELETE { <$uri> dct:references ?o . }
73 73
             WHERE  { <$uri> dct:references ?o . };
74 74
             DELETE { <$uri> schema:url ?o . }
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 EOF;
92 92
 
93 93
 	// execute the query.
94
-	rl_execute_sparql_update_query( $query );
94
+	rl_execute_sparql_update_query($query);
95 95
 }
96 96
 
97 97
 /**
@@ -99,27 +99,27 @@  discard block
 block discarded – undo
99 99
  *
100 100
  * @param object $entity_post An entity post instance.
101 101
  */
102
-function wl_push_entity_post_to_redlink( $entity_post ) {
102
+function wl_push_entity_post_to_redlink($entity_post) {
103 103
 
104 104
 	// Get the Entity service instance to perform actions related to entities.
105 105
 	$entity_service = Wordlift_Entity_Service::get_instance();
106 106
 
107 107
 	// Only handle published entities.
108
-	if ( ! $entity_service->is_entity( $entity_post->ID ) || 'publish' !== $entity_post->post_status ) {
108
+	if ( ! $entity_service->is_entity($entity_post->ID) || 'publish' !== $entity_post->post_status) {
109 109
 
110
-		wl_write_log( "wl_push_entity_post_to_redlink : not an entity or not published [ post type :: $entity_post->post_type ][ post status :: $entity_post->post_status ]" );
110
+		wl_write_log("wl_push_entity_post_to_redlink : not an entity or not published [ post type :: $entity_post->post_type ][ post status :: $entity_post->post_status ]");
111 111
 
112 112
 		return;
113 113
 	}
114 114
 
115 115
 	// get the entity URI and the SPARQL escaped version.
116
-	$uri   = wl_get_entity_uri( $entity_post->ID );
117
-	$uri_e = wl_sparql_escape_uri( $uri );
116
+	$uri   = wl_get_entity_uri($entity_post->ID);
117
+	$uri_e = wl_sparql_escape_uri($uri);
118 118
 
119 119
 	// If the URI ends with a trailing slash, then we have a problem.
120
-	if ( '/' === substr( $uri, - 1, 1 ) ) {
120
+	if ('/' === substr($uri, - 1, 1)) {
121 121
 
122
-		wl_write_log( "wl_push_entity_post_to_redlink : the URI is invalid [ post ID :: $entity_post->ID ][ URI :: $uri ]" );
122
+		wl_write_log("wl_push_entity_post_to_redlink : the URI is invalid [ post ID :: $entity_post->ID ][ URI :: $uri ]");
123 123
 
124 124
 		return;
125 125
 	}
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
 	$site_language = wl_configuration_get_site_language();
129 129
 
130 130
 	// get the title and content as label and description.
131
-	$label     = wordlift_esc_sparql( $entity_post->post_title );
132
-	$descr     = wordlift_esc_sparql( wp_strip_all_tags( strip_shortcodes( $entity_post->post_content ) ) );
133
-	$permalink = wl_sparql_escape_uri( get_permalink( $entity_post->ID ) );
131
+	$label     = wordlift_esc_sparql($entity_post->post_title);
132
+	$descr     = wordlift_esc_sparql(wp_strip_all_tags(strip_shortcodes($entity_post->post_content)));
133
+	$permalink = wl_sparql_escape_uri(get_permalink($entity_post->ID));
134 134
 
135 135
 	// wl_write_log( "wl_push_entity_post_to_redlink [ entity post id :: $entity_post->ID ][ uri :: $uri ][ label :: $label ]" );
136 136
 
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
 	// delete on RL all statements regarding properties set from WL (necessary when changing entity type)
142 142
 	$all_custom_fields        = wl_entity_taxonomy_get_custom_fields();
143 143
 	$predicates_to_be_deleted = array();
144
-	foreach ( $all_custom_fields as $type => $fields ) {
145
-		foreach ( $fields as $cf ) {
144
+	foreach ($all_custom_fields as $type => $fields) {
145
+		foreach ($fields as $cf) {
146 146
 			$predicate = $cf['predicate'];
147
-			if ( ! in_array( $predicate, $predicates_to_be_deleted ) ) {
147
+			if ( ! in_array($predicate, $predicates_to_be_deleted)) {
148 148
 				$predicates_to_be_deleted[] = $predicate;
149 149
 				$delete_stmt .= "DELETE { <$uri_e> <$predicate> ?o } WHERE  { <$uri_e> <$predicate> ?o };\n";
150 150
 			}
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	}
153 153
 
154 154
 	// set the same as.
155
-	$same_as = wl_schema_get_value( $entity_post->ID, 'sameAs' );
156
-	foreach ( $same_as as $same_as_uri ) {
157
-		$same_as_uri_esc = wl_sparql_escape_uri( $same_as_uri );
155
+	$same_as = wl_schema_get_value($entity_post->ID, 'sameAs');
156
+	foreach ($same_as as $same_as_uri) {
157
+		$same_as_uri_esc = wl_sparql_escape_uri($same_as_uri);
158 158
 		$sparql .= "<$uri_e> owl:sameAs <$same_as_uri_esc> . \n";
159 159
 	}
160 160
 
@@ -162,23 +162,23 @@  discard block
 block discarded – undo
162 162
 	$sparql .= "<$uri_e> rdfs:label \"$label\"@$site_language . \n";
163 163
 
164 164
 	// Set the alternative labels.
165
-	$alt_labels = $entity_service->get_alternate_labels( $entity_post->ID );
166
-	foreach ( $alt_labels as $alt_label ) {
167
-		$sparql .= sprintf( '<%s> rdfs:label "%s"@%s . ', $uri_e, Wordlift_Query_Builder::escape_value( $alt_label ), $site_language );
165
+	$alt_labels = $entity_service->get_alternate_labels($entity_post->ID);
166
+	foreach ($alt_labels as $alt_label) {
167
+		$sparql .= sprintf('<%s> rdfs:label "%s"@%s . ', $uri_e, Wordlift_Query_Builder::escape_value($alt_label), $site_language);
168 168
 	}
169 169
 
170 170
 	// set the URL
171 171
 	$sparql .= "<$uri_e> schema:url <$permalink> . \n";
172 172
 
173 173
 	// set the description.
174
-	if ( ! empty( $descr ) ) {
174
+	if ( ! empty($descr)) {
175 175
 		$sparql .= "<$uri_e> schema:description \"$descr\"@$site_language . \n";
176 176
 	}
177 177
 
178
-	$main_type = wl_entity_type_taxonomy_get_type( $entity_post->ID );
178
+	$main_type = wl_entity_type_taxonomy_get_type($entity_post->ID);
179 179
 
180
-	if ( null != $main_type ) {
181
-		$main_type_uri = wl_sparql_escape_uri( $main_type['uri'] );
180
+	if (null != $main_type) {
181
+		$main_type_uri = wl_sparql_escape_uri($main_type['uri']);
182 182
 		$sparql .= " <$uri_e> a <$main_type_uri> . \n";
183 183
 
184 184
 		// The type define custom fields that hold additional data about the entity.
@@ -188,33 +188,33 @@  discard block
 block discarded – undo
188 188
 
189 189
 //		wl_write_log( 'wl_push_entity_post_to_redlink : checking if entity has export fields [ type :: ' . var_export( $main_type, true ) . ' ]' );
190 190
 
191
-		if ( isset( $main_type['custom_fields'] ) ) {
192
-			foreach ( $main_type['custom_fields'] as $field => $settings ) {
191
+		if (isset($main_type['custom_fields'])) {
192
+			foreach ($main_type['custom_fields'] as $field => $settings) {
193 193
 
194 194
 				// wl_write_log( "wl_push_entity_post_to_redlink : entity has export fields" );
195 195
 
196
-				$predicate = wordlift_esc_sparql( $settings['predicate'] );
197
-				if ( ! isset( $settings['export_type'] ) || empty( $settings['export_type'] ) ) {
196
+				$predicate = wordlift_esc_sparql($settings['predicate']);
197
+				if ( ! isset($settings['export_type']) || empty($settings['export_type'])) {
198 198
 					$type = null;
199 199
 				} else {
200 200
 					$type = $settings['export_type'];
201 201
 				}
202 202
 
203
-				foreach ( get_post_meta( $entity_post->ID, $field ) as $value ) {
203
+				foreach (get_post_meta($entity_post->ID, $field) as $value) {
204 204
 					$sparql .= " <$uri_e> <$predicate> ";
205 205
 
206
-					if ( ! is_null( $type ) && ( substr( $type, 0, 4 ) == 'http' ) ) {
206
+					if ( ! is_null($type) && (substr($type, 0, 4) == 'http')) {
207 207
 						// Type is defined by a raw uri (es. http://schema.org/PostalAddress)
208 208
 
209 209
 						// Extract uri if the value is numeric
210
-						if ( is_numeric( $value ) ) {
211
-							$value = wl_get_entity_uri( $value );
210
+						if (is_numeric($value)) {
211
+							$value = wl_get_entity_uri($value);
212 212
 						}
213 213
 
214
-						$sparql .= '<' . wl_sparql_escape_uri( $value ) . '>';
214
+						$sparql .= '<'.wl_sparql_escape_uri($value).'>';
215 215
 					} else {
216 216
 						// Type is defined in another way (es. xsd:double)
217
-						$sparql .= '"' . wordlift_esc_sparql( $value ) . '"^^' . wordlift_esc_sparql( $type );
217
+						$sparql .= '"'.wordlift_esc_sparql($value).'"^^'.wordlift_esc_sparql($type);
218 218
 					}
219 219
 
220 220
 					$sparql .= " . \n";
@@ -224,20 +224,20 @@  discard block
 block discarded – undo
224 224
 	}
225 225
 
226 226
 	// Get the entity types.
227
-	$type_uris = wl_get_entity_rdf_types( $entity_post->ID );
227
+	$type_uris = wl_get_entity_rdf_types($entity_post->ID);
228 228
 
229 229
 	// Support type are only schema.org ones: it could be null
230
-	foreach ( $type_uris as $type_uri ) {
231
-		$type_uri = wl_sparql_escape_uri( $type_uri );
230
+	foreach ($type_uris as $type_uri) {
231
+		$type_uri = wl_sparql_escape_uri($type_uri);
232 232
 		$sparql .= "<$uri_e> a <$type_uri> . \n";
233 233
 	}
234 234
 
235 235
 	// get related entities.
236
-	$related_entities_ids = wl_core_get_related_entity_ids( $entity_post->ID );
236
+	$related_entities_ids = wl_core_get_related_entity_ids($entity_post->ID);
237 237
 
238
-	if ( is_array( $related_entities_ids ) ) {
239
-		foreach ( $related_entities_ids as $entity_post_id ) {
240
-			$related_entity_uri = wl_sparql_escape_uri( wl_get_entity_uri( $entity_post_id ) );
238
+	if (is_array($related_entities_ids)) {
239
+		foreach ($related_entities_ids as $entity_post_id) {
240
+			$related_entity_uri = wl_sparql_escape_uri(wl_get_entity_uri($entity_post_id));
241 241
 			// create a two-way relationship.
242 242
 			$sparql .= " <$uri_e> dct:relation <$related_entity_uri> . \n";
243 243
 			$sparql .= " <$related_entity_uri> dct:relation <$uri_e> . \n";
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
 	}
246 246
 
247 247
 	// Add SPARQL stmts to write the schema:image.
248
-	$sparql .= wl_get_sparql_images( $uri, $entity_post->ID );
248
+	$sparql .= wl_get_sparql_images($uri, $entity_post->ID);
249 249
 
250
-	$query = rl_sparql_prefixes() . <<<EOF
250
+	$query = rl_sparql_prefixes().<<<EOF
251 251
     $delete_stmt
252 252
     DELETE { <$uri_e> rdfs:label ?o } WHERE  { <$uri_e> rdfs:label ?o };
253 253
     DELETE { <$uri_e> owl:sameAs ?o . } WHERE  { <$uri_e> owl:sameAs ?o . };
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
     INSERT DATA { $sparql };
260 260
 EOF;
261 261
 
262
-	rl_execute_sparql_update_query( $query );
262
+	rl_execute_sparql_update_query($query);
263 263
 }
264 264
 
265 265
 /**
@@ -269,18 +269,18 @@  discard block
 block discarded – undo
269 269
  *
270 270
  * @return string The SPARQL fragment (or an empty string).
271 271
  */
272
-function wl_get_sparql_post_references( $post_id ) {
272
+function wl_get_sparql_post_references($post_id) {
273 273
 
274 274
 	// Get the post URI.
275
-	$post_uri = wordlift_esc_sparql( wl_get_entity_uri( $post_id ) );
275
+	$post_uri = wordlift_esc_sparql(wl_get_entity_uri($post_id));
276 276
 
277 277
 	// Get the related entities IDs.
278
-	$related = wl_core_get_related_entity_ids( $post_id );
278
+	$related = wl_core_get_related_entity_ids($post_id);
279 279
 
280 280
 	// Build the SPARQL fragment.
281 281
 	$sparql = '';
282
-	foreach ( $related as $id ) {
283
-		$uri = wordlift_esc_sparql( wl_get_entity_uri( $id ) );
282
+	foreach ($related as $id) {
283
+		$uri = wordlift_esc_sparql(wl_get_entity_uri($id));
284 284
 		$sparql .= "<$post_uri> dct:references <$uri> . ";
285 285
 	}
286 286
 
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 function rl_sparql_prefixes() {
296 296
 
297 297
 	$prefixes = '';
298
-	foreach ( wl_prefixes() as $prefix => $uri ) {
298
+	foreach (wl_prefixes() as $prefix => $uri) {
299 299
 		$prefixes .= "PREFIX $prefix: <$uri>\n";
300 300
 	}
301 301
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
  *
310 310
  * @return string The escaped string.
311 311
  */
312
-function wordlift_esc_sparql( $string ) {
312
+function wordlift_esc_sparql($string) {
313 313
 	// see http://www.w3.org/TR/rdf-sparql-query/
314 314
 	//    '\t'	U+0009 (tab)
315 315
 	//    '\n'	U+000A (line feed)
@@ -320,14 +320,14 @@  discard block
 block discarded – undo
320 320
 	//    "\'"	U+0027 (apostrophe-quote, single quote mark)
321 321
 	//    '\\'	U+005C (backslash)
322 322
 
323
-	$string = str_replace( '\\', '\\\\', $string );
324
-	$string = str_replace( '\'', '\\\'', $string );
325
-	$string = str_replace( '"', '\\"', $string );
326
-	$string = str_replace( "\f", '\\f', $string );
327
-	$string = str_replace( "\b", '\\b', $string );
328
-	$string = str_replace( "\r", '\\r', $string );
329
-	$string = str_replace( "\n", '\\n', $string );
330
-	$string = str_replace( "\t", '\\t', $string );
323
+	$string = str_replace('\\', '\\\\', $string);
324
+	$string = str_replace('\'', '\\\'', $string);
325
+	$string = str_replace('"', '\\"', $string);
326
+	$string = str_replace("\f", '\\f', $string);
327
+	$string = str_replace("\b", '\\b', $string);
328
+	$string = str_replace("\r", '\\r', $string);
329
+	$string = str_replace("\n", '\\n', $string);
330
+	$string = str_replace("\t", '\\t', $string);
331 331
 
332 332
 	return $string;
333 333
 }
@@ -341,13 +341,13 @@  discard block
 block discarded – undo
341 341
  *
342 342
  * @return string The escaped URI.
343 343
  */
344
-function wl_sparql_escape_uri( $string ) {
344
+function wl_sparql_escape_uri($string) {
345 345
 
346 346
 	// Should we validate the IRI?
347 347
 	// http://www.w3.org/TR/sparql11-query/#QSynIRI
348 348
 
349
-	$string = str_replace( '<', '\<', $string );
350
-	$string = str_replace( '>', '\>', $string );
349
+	$string = str_replace('<', '\<', $string);
350
+	$string = str_replace('>', '\>', $string);
351 351
 
352 352
 	return $string;
353 353
 
@@ -365,25 +365,25 @@  discard block
 block discarded – undo
365 365
 	// wl_write_log( "wordlift_reindex_triple_store" );
366 366
 
367 367
 	// Prepare the request.
368
-	$args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array(
368
+	$args = array_merge_recursive(unserialize(WL_REDLINK_API_HTTP_OPTIONS), array(
369 369
 		'method'  => 'POST',
370 370
 		'headers' => array()
371
-	) );
371
+	));
372 372
 
373
-	$response = wp_remote_request( $url, $args );
373
+	$response = wp_remote_request($url, $args);
374 374
 
375 375
 	// If an error has been raised, return the error.
376
-	if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) {
376
+	if (is_wp_error($response) || 200 !== $response['response']['code']) {
377 377
 
378
-		$body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] );
378
+		$body = (is_wp_error($response) ? $response->get_error_message() : $response['body']);
379 379
 
380
-		wl_write_log( "wordlift_reindex_triple_store : error [ url :: $url ][ args :: " );
381
-		wl_write_log( "\n" . var_export( $args, true ) );
382
-		wl_write_log( "[ response :: " );
383
-		wl_write_log( "\n" . var_export( $response, true ) );
384
-		wl_write_log( "][ body :: " );
385
-		wl_write_log( "\n" . $body );
386
-		wl_write_log( "]" );
380
+		wl_write_log("wordlift_reindex_triple_store : error [ url :: $url ][ args :: ");
381
+		wl_write_log("\n".var_export($args, true));
382
+		wl_write_log("[ response :: ");
383
+		wl_write_log("\n".var_export($response, true));
384
+		wl_write_log("][ body :: ");
385
+		wl_write_log("\n".$body);
386
+		wl_write_log("]");
387 387
 
388 388
 		return false;
389 389
 	}
Please login to merge, or discard this patch.