Completed
Push — develop ( 07b04d...d513ba )
by David
03:56
created
src/modules/configuration/wordlift_configuration.php 2 patches
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -18,15 +18,15 @@  discard block
 block discarded – undo
18 18
  */
19 19
 function wl_configuration_admin_menu( $parent_slug, $capability ) {
20 20
 
21
-	// see http://codex.wordpress.org/Function_Reference/add_submenu_page
22
-	add_submenu_page(
23
-		$parent_slug, // The parent menu slug, provided by the calling hook.
24
-		__( 'Settings', 'wordlift' ),  // page title
25
-		__( 'Settings', 'wordlift' ),  // menu title
26
-		$capability,                   // The required capability, provided by the calling hook.
27
-		'wl_configuration_admin_menu',      // the menu slug
28
-		'wl_configuration_admin_menu_callback' // the menu callback for displaying the page content
29
-	);
21
+    // see http://codex.wordpress.org/Function_Reference/add_submenu_page
22
+    add_submenu_page(
23
+        $parent_slug, // The parent menu slug, provided by the calling hook.
24
+        __( 'Settings', 'wordlift' ),  // page title
25
+        __( 'Settings', 'wordlift' ),  // menu title
26
+        $capability,                   // The required capability, provided by the calling hook.
27
+        'wl_configuration_admin_menu',      // the menu slug
28
+        'wl_configuration_admin_menu_callback' // the menu callback for displaying the page content
29
+    );
30 30
 
31 31
 }
32 32
 
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
  */
42 42
 function wl_configuration_admin_menu_callback( $display_page_title = true ) {
43 43
 
44
-	if ( ! current_user_can( 'manage_options' ) ) {
45
-		wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
46
-	}
44
+    if ( ! current_user_can( 'manage_options' ) ) {
45
+        wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
46
+    }
47 47
 
48
-	// Ony show advanced settings tab if the relative constant exists and is set to true.
49
-	$can_show_advanced_settings = defined( 'WL_ENABLE_ADVANCED_CONFIGURATION' ) && WL_ENABLE_ADVANCED_CONFIGURATION;
48
+    // Ony show advanced settings tab if the relative constant exists and is set to true.
49
+    $can_show_advanced_settings = defined( 'WL_ENABLE_ADVANCED_CONFIGURATION' ) && WL_ENABLE_ADVANCED_CONFIGURATION;
50 50
 
51
-	?>
51
+    ?>
52 52
 
53 53
 	<div class="wrap">
54 54
 
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 		<?php settings_errors(); ?>
61 61
 
62 62
 		<?php
63
-		$active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general_settings';
64
-		?>
63
+        $active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general_settings';
64
+        ?>
65 65
 
66 66
 		<h2 class="nav-tab-wrapper">
67 67
 			<a href="?page=<?php echo( $_GET['page'] ); ?>&tab=general_settings"
@@ -75,17 +75,17 @@  discard block
 block discarded – undo
75 75
 
76 76
 		<form action="options.php" method="post">
77 77
 			<?php
78
-			if ( 'general_settings' === $active_tab ) {
79
-				settings_fields( 'wl_general_settings' );
80
-				do_settings_sections( 'wl_general_settings' );
78
+            if ( 'general_settings' === $active_tab ) {
79
+                settings_fields( 'wl_general_settings' );
80
+                do_settings_sections( 'wl_general_settings' );
81 81
 
82
-			} else if ( $can_show_advanced_settings && 'advanced_settings' === $active_tab ) {
83
-				settings_fields( 'wl_advanced_settings' );
84
-				do_settings_sections( 'wl_advanced_settings' );
85
-			}
82
+            } else if ( $can_show_advanced_settings && 'advanced_settings' === $active_tab ) {
83
+                settings_fields( 'wl_advanced_settings' );
84
+                do_settings_sections( 'wl_advanced_settings' );
85
+            }
86 86
 
87
-			submit_button();
88
-			?>
87
+            submit_button();
88
+            ?>
89 89
 		</form>
90 90
 
91 91
 		<div style="margin-top: 100px; font-size: 10px;">The entities blocks are designed by Lukasz M. Pogoda from the
@@ -108,148 +108,148 @@  discard block
 block discarded – undo
108 108
  */
109 109
 function wl_configuration_settings() {
110 110
 
111
-	register_setting(
112
-		'wl_general_settings',
113
-		'wl_general_settings',
114
-		'wl_configuration_sanitize_settings'
115
-	);
116
-
117
-	add_settings_section(
118
-		'wl_general_settings_section',          // ID used to identify this section and with which to register options
119
-		'General Settings',                              // Title to be displayed on the administration page
120
-		'wl_configuration_general_settings_section_callback', // Callback used to render the description of the section
121
-		'wl_general_settings'              // Page on which to add this section of options
122
-	);
123
-
124
-	add_settings_field(
125
-		WL_CONFIG_WORDLIFT_KEY,             // ID used to identify the field throughout the theme
126
-		__( 'WordLift Key', 'wordlift' ),   // The label to the left of the option interface element
127
-		'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
128
-		'wl_general_settings',         // The page on which this option will be displayed
129
-		'wl_general_settings_section',      // The name of the section to which this field belongs
130
-		array(                              // The array of arguments to pass to the callback. In this case, just a description.
131
-			'id'          => 'wl-key',
132
-			'name'        => 'wl_general_settings[key]',
133
-			'value'       => wl_configuration_get_key(),
134
-			'description' => __( 'Insert the WordLift Key', 'wordlift' )
135
-		)
136
-	);
137
-
138
-	add_settings_field(
139
-		WL_CONFIG_SITE_LANGUAGE_NAME,
140
-		__( 'Site Language', 'wordlift' ),
141
-		'wl_configuration_select',
142
-		'wl_general_settings',
143
-		'wl_general_settings_section',
144
-		array(                              // The array of arguments to pass to the callback. In this case, just a description.
145
-			'id'          => 'wl-site-language',
146
-			'name'        => 'wl_general_settings[site_language]',
147
-			'value'       => wl_configuration_get_site_language(),
148
-			'description' => __( 'The site language', 'wordlift' ),
149
-			'options'     => wl_configuration_get_languages()
150
-		)
151
-	);
152
-
153
-
154
-	if ( defined( 'WL_ENABLE_ADVANCED_CONFIGURATION' ) && WL_ENABLE_ADVANCED_CONFIGURATION ) {
155
-
156
-		register_setting(
157
-			'wl_advanced_settings',
158
-			'wl_advanced_settings',
159
-			'wl_configuration_sanitize_settings'
160
-		);
161
-
162
-		add_settings_section(
163
-			'wl_advanced_settings_section',          // ID used to identify this section and with which to register options
164
-			'Advanced',                              // Title to be displayed on the administration page
165
-			'wl_configuration_advanced_settings_section_callback', // Callback used to render the description of the section
166
-			'wl_advanced_settings'              // Page on which to add this section of options
167
-		);
168
-
169
-		add_settings_field(
170
-			WL_CONFIG_API_URL,             // ID used to identify the field throughout the theme
171
-			__( 'API URL', 'wordlift' ),   // The label to the left of the option interface element
172
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
173
-			'wl_advanced_settings',         // The page on which this option will be displayed
174
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
175
-			array(                              // The array of arguments to pass to the callback. In this case, just a description.
176
-				'id'          => 'wl-api-url',
177
-				'name'        => 'wl_advanced_settings[api_url]',
178
-				'value'       => wl_configuration_get_api_url(),
179
-				'description' => __( 'The API URL', 'wordlift' )
180
-			)
181
-		);
182
-
183
-		add_settings_field(
184
-			WL_CONFIG_APPLICATION_KEY_NAME,             // ID used to identify the field throughout the theme
185
-			__( 'Redlink Key', 'wordlift' ),   // The label to the left of the option interface element
186
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
187
-			'wl_advanced_settings',         // The page on which this option will be displayed
188
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
189
-			array(                              // The array of arguments to pass to the callback. In this case, just a description.
190
-				'id'          => 'wl-redlink-key',
191
-				'name'        => 'wl_advanced_settings[redlink_key]',
192
-				'value'       => wl_configuration_get_redlink_key(),
193
-				'description' => __( 'The Redlink key', 'wordlift' )
194
-			)
195
-		);
196
-
197
-		add_settings_field(
198
-			WL_CONFIG_USER_ID_NAME,             // ID used to identify the field throughout the theme
199
-			__( 'Redlink User Id', 'wordlift' ),   // The label to the left of the option interface element
200
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
201
-			'wl_advanced_settings',         // The page on which this option will be displayed
202
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
203
-			array(                              // The array of arguments to pass to the callback. In this case, just a description.
204
-				'id'          => 'wl-redlink-user-id',
205
-				'name'        => 'wl_advanced_settings[redlink_user_id]',
206
-				'value'       => wl_configuration_get_redlink_user_id(),
207
-				'description' => __( 'The Redlink User Id', 'wordlift' )
208
-			)
209
-		);
210
-
211
-		add_settings_field(
212
-			WL_CONFIG_DATASET_NAME,             // ID used to identify the field throughout the theme
213
-			__( 'Redlink Dataset name', 'wordlift' ),   // The label to the left of the option interface element
214
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
215
-			'wl_advanced_settings',         // The page on which this option will be displayed
216
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
217
-			array(                              // The array of arguments to pass to the callback. In this case, just a description.
218
-				'id'          => 'wl-redlink-dataset-name',
219
-				'name'        => 'wl_advanced_settings[redlink_dataset_name]',
220
-				'value'       => wl_configuration_get_redlink_dataset_name(),
221
-				'description' => __( 'The Redlink Dataset Name', 'wordlift' )
222
-			)
223
-		);
224
-
225
-		add_settings_field(
226
-			WL_CONFIG_DATASET_BASE_URI_NAME,             // ID used to identify the field throughout the theme
227
-			__( 'Redlink Dataset URI', 'wordlift' ),   // The label to the left of the option interface element
228
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
229
-			'wl_advanced_settings',         // The page on which this option will be displayed
230
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
231
-			array(                              // The array of arguments to pass to the callback. In this case, just a description.
232
-				'id'          => 'wl-redlink-dataset-uri',
233
-				'name'        => 'wl_advanced_settings[redlink_dataset_uri]',
234
-				'value'       => wl_configuration_get_redlink_dataset_uri(),
235
-				'description' => __( 'The Redlink Dataset URI', 'wordlift' )
236
-			)
237
-		);
238
-
239
-		add_settings_field(
240
-			WL_CONFIG_ANALYSIS_NAME,             // ID used to identify the field throughout the theme
241
-			__( 'Redlink Application Name', 'wordlift' ),   // The label to the left of the option interface element
242
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
243
-			'wl_advanced_settings',         // The page on which this option will be displayed
244
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
245
-			array(                              // The array of arguments to pass to the callback. In this case, just a description.
246
-				'id'          => 'wl-redlink-application-name',
247
-				'name'        => 'wl_advanced_settings[redlink_application_name]',
248
-				'value'       => wl_configuration_get_redlink_application_name(),
249
-				'description' => __( 'The Redlink Application Name', 'wordlift' )
250
-			)
251
-		);
252
-	}
111
+    register_setting(
112
+        'wl_general_settings',
113
+        'wl_general_settings',
114
+        'wl_configuration_sanitize_settings'
115
+    );
116
+
117
+    add_settings_section(
118
+        'wl_general_settings_section',          // ID used to identify this section and with which to register options
119
+        'General Settings',                              // Title to be displayed on the administration page
120
+        'wl_configuration_general_settings_section_callback', // Callback used to render the description of the section
121
+        'wl_general_settings'              // Page on which to add this section of options
122
+    );
123
+
124
+    add_settings_field(
125
+        WL_CONFIG_WORDLIFT_KEY,             // ID used to identify the field throughout the theme
126
+        __( 'WordLift Key', 'wordlift' ),   // The label to the left of the option interface element
127
+        'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
128
+        'wl_general_settings',         // The page on which this option will be displayed
129
+        'wl_general_settings_section',      // The name of the section to which this field belongs
130
+        array(                              // The array of arguments to pass to the callback. In this case, just a description.
131
+            'id'          => 'wl-key',
132
+            'name'        => 'wl_general_settings[key]',
133
+            'value'       => wl_configuration_get_key(),
134
+            'description' => __( 'Insert the WordLift Key', 'wordlift' )
135
+        )
136
+    );
137
+
138
+    add_settings_field(
139
+        WL_CONFIG_SITE_LANGUAGE_NAME,
140
+        __( 'Site Language', 'wordlift' ),
141
+        'wl_configuration_select',
142
+        'wl_general_settings',
143
+        'wl_general_settings_section',
144
+        array(                              // The array of arguments to pass to the callback. In this case, just a description.
145
+            'id'          => 'wl-site-language',
146
+            'name'        => 'wl_general_settings[site_language]',
147
+            'value'       => wl_configuration_get_site_language(),
148
+            'description' => __( 'The site language', 'wordlift' ),
149
+            'options'     => wl_configuration_get_languages()
150
+        )
151
+    );
152
+
153
+
154
+    if ( defined( 'WL_ENABLE_ADVANCED_CONFIGURATION' ) && WL_ENABLE_ADVANCED_CONFIGURATION ) {
155
+
156
+        register_setting(
157
+            'wl_advanced_settings',
158
+            'wl_advanced_settings',
159
+            'wl_configuration_sanitize_settings'
160
+        );
161
+
162
+        add_settings_section(
163
+            'wl_advanced_settings_section',          // ID used to identify this section and with which to register options
164
+            'Advanced',                              // Title to be displayed on the administration page
165
+            'wl_configuration_advanced_settings_section_callback', // Callback used to render the description of the section
166
+            'wl_advanced_settings'              // Page on which to add this section of options
167
+        );
168
+
169
+        add_settings_field(
170
+            WL_CONFIG_API_URL,             // ID used to identify the field throughout the theme
171
+            __( 'API URL', 'wordlift' ),   // The label to the left of the option interface element
172
+            'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
173
+            'wl_advanced_settings',         // The page on which this option will be displayed
174
+            'wl_advanced_settings_section',      // The name of the section to which this field belongs
175
+            array(                              // The array of arguments to pass to the callback. In this case, just a description.
176
+                'id'          => 'wl-api-url',
177
+                'name'        => 'wl_advanced_settings[api_url]',
178
+                'value'       => wl_configuration_get_api_url(),
179
+                'description' => __( 'The API URL', 'wordlift' )
180
+            )
181
+        );
182
+
183
+        add_settings_field(
184
+            WL_CONFIG_APPLICATION_KEY_NAME,             // ID used to identify the field throughout the theme
185
+            __( 'Redlink Key', 'wordlift' ),   // The label to the left of the option interface element
186
+            'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
187
+            'wl_advanced_settings',         // The page on which this option will be displayed
188
+            'wl_advanced_settings_section',      // The name of the section to which this field belongs
189
+            array(                              // The array of arguments to pass to the callback. In this case, just a description.
190
+                'id'          => 'wl-redlink-key',
191
+                'name'        => 'wl_advanced_settings[redlink_key]',
192
+                'value'       => wl_configuration_get_redlink_key(),
193
+                'description' => __( 'The Redlink key', 'wordlift' )
194
+            )
195
+        );
196
+
197
+        add_settings_field(
198
+            WL_CONFIG_USER_ID_NAME,             // ID used to identify the field throughout the theme
199
+            __( 'Redlink User Id', 'wordlift' ),   // The label to the left of the option interface element
200
+            'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
201
+            'wl_advanced_settings',         // The page on which this option will be displayed
202
+            'wl_advanced_settings_section',      // The name of the section to which this field belongs
203
+            array(                              // The array of arguments to pass to the callback. In this case, just a description.
204
+                'id'          => 'wl-redlink-user-id',
205
+                'name'        => 'wl_advanced_settings[redlink_user_id]',
206
+                'value'       => wl_configuration_get_redlink_user_id(),
207
+                'description' => __( 'The Redlink User Id', 'wordlift' )
208
+            )
209
+        );
210
+
211
+        add_settings_field(
212
+            WL_CONFIG_DATASET_NAME,             // ID used to identify the field throughout the theme
213
+            __( 'Redlink Dataset name', 'wordlift' ),   // The label to the left of the option interface element
214
+            'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
215
+            'wl_advanced_settings',         // The page on which this option will be displayed
216
+            'wl_advanced_settings_section',      // The name of the section to which this field belongs
217
+            array(                              // The array of arguments to pass to the callback. In this case, just a description.
218
+                'id'          => 'wl-redlink-dataset-name',
219
+                'name'        => 'wl_advanced_settings[redlink_dataset_name]',
220
+                'value'       => wl_configuration_get_redlink_dataset_name(),
221
+                'description' => __( 'The Redlink Dataset Name', 'wordlift' )
222
+            )
223
+        );
224
+
225
+        add_settings_field(
226
+            WL_CONFIG_DATASET_BASE_URI_NAME,             // ID used to identify the field throughout the theme
227
+            __( 'Redlink Dataset URI', 'wordlift' ),   // The label to the left of the option interface element
228
+            'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
229
+            'wl_advanced_settings',         // The page on which this option will be displayed
230
+            'wl_advanced_settings_section',      // The name of the section to which this field belongs
231
+            array(                              // The array of arguments to pass to the callback. In this case, just a description.
232
+                'id'          => 'wl-redlink-dataset-uri',
233
+                'name'        => 'wl_advanced_settings[redlink_dataset_uri]',
234
+                'value'       => wl_configuration_get_redlink_dataset_uri(),
235
+                'description' => __( 'The Redlink Dataset URI', 'wordlift' )
236
+            )
237
+        );
238
+
239
+        add_settings_field(
240
+            WL_CONFIG_ANALYSIS_NAME,             // ID used to identify the field throughout the theme
241
+            __( 'Redlink Application Name', 'wordlift' ),   // The label to the left of the option interface element
242
+            'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
243
+            'wl_advanced_settings',         // The page on which this option will be displayed
244
+            'wl_advanced_settings_section',      // The name of the section to which this field belongs
245
+            array(                              // The array of arguments to pass to the callback. In this case, just a description.
246
+                'id'          => 'wl-redlink-application-name',
247
+                'name'        => 'wl_advanced_settings[redlink_application_name]',
248
+                'value'       => wl_configuration_get_redlink_application_name(),
249
+                'description' => __( 'The Redlink Application Name', 'wordlift' )
250
+            )
251
+        );
252
+    }
253 253
 }
254 254
 
255 255
 add_action( 'admin_init', 'wl_configuration_settings' );
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
  */
262 262
 function wl_configuration_general_settings_section_callback() {
263 263
 
264
-	// TODO: set the following text.
265
-	?>
264
+    // TODO: set the following text.
265
+    ?>
266 266
 	Configure WordLift general options.
267 267
 	<?php
268 268
 }
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
  */
275 275
 function wl_configuration_advanced_settings_section_callback() {
276 276
 
277
-	// TODO: set the following text.
278
-	?>
277
+    // TODO: set the following text.
278
+    ?>
279 279
 	Configure WordLift advanced options.
280 280
 	<?php
281 281
 }
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
  */
292 292
 function wl_configuration_sanitize_settings( $input ) {
293 293
 
294
-	// TODO: add sanitization checks.
295
-	return apply_filters( 'wl_configuration_sanitize_settings', $input, $input );
294
+    // TODO: add sanitization checks.
295
+    return apply_filters( 'wl_configuration_sanitize_settings', $input, $input );
296 296
 
297 297
 }
298 298
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
  * @param array $args An array of configuration parameters.
305 305
  */
306 306
 function wl_configuration_input_box( $args ) {
307
-	?>
307
+    ?>
308 308
 
309 309
 	<input type="text" id="<?php echo esc_attr( $args['id'] ); ?>"
310 310
 	       name="<?php echo esc_attr( $args['name'] ); ?>"
@@ -321,15 +321,15 @@  discard block
 block discarded – undo
321 321
  * @param array $args The select configuration parameters.
322 322
  */
323 323
 function wl_configuration_select( $args ) {
324
-	?>
324
+    ?>
325 325
 
326 326
 	<select id="<?php echo esc_attr( $args['id'] ); ?>"
327 327
 	        name="<?php echo esc_attr( $args['name'] ); ?>">
328 328
 		<?php foreach ( $args['options'] as $value => $label ) { ?>
329 329
 			<option value="<?php echo esc_attr( $value ); ?>" <?php if ( $args['value'] === $value ) {
330
-				echo 'selected';
331
-			}
332
-			?>><?php echo esc_html( $label ); ?></option>
330
+                echo 'selected';
331
+            }
332
+            ?>><?php echo esc_html( $label ); ?></option>
333 333
 		<?php } ?>
334 334
 	</select>
335 335
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
  * @param array $args The checkbox parameters.
345 345
  */
346 346
 function wl_configuration_checkbox( $args ) {
347
-	?>
347
+    ?>
348 348
 
349 349
 	<input type="checkbox" id="<?php echo esc_attr( $args['id'] ); ?>"
350 350
 	       name="<?php echo esc_attr( $args['name'] ); ?>"
@@ -364,10 +364,10 @@  discard block
 block discarded – undo
364 364
  */
365 365
 function wl_configuration_settings_links( $links ) {
366 366
 
367
-	// TODO: this link is different within SEO Ultimate.
368
-	array_push( $links, '<a href="' . get_admin_url( null, 'admin.php?page=wl_configuration_admin_menu' ) . '">Settings</a>' );
367
+    // TODO: this link is different within SEO Ultimate.
368
+    array_push( $links, '<a href="' . get_admin_url( null, 'admin.php?page=wl_configuration_admin_menu' ) . '">Settings</a>' );
369 369
 
370
-	return $links;
370
+    return $links;
371 371
 }
372 372
 
373 373
 // add the settings link for the plugin.
@@ -383,27 +383,27 @@  discard block
 block discarded – undo
383 383
  */
384 384
 function wl_configuration_get_languages() {
385 385
 
386
-	// prepare the language array.
387
-	$langs = array();
386
+    // prepare the language array.
387
+    $langs = array();
388 388
 
389
-	// set the path to the language file.
390
-	$filename = dirname( __FILE__ ) . '/ISO-639-2_utf-8.txt';
389
+    // set the path to the language file.
390
+    $filename = dirname( __FILE__ ) . '/ISO-639-2_utf-8.txt';
391 391
 
392
-	if ( ( $handle = fopen( $filename, 'r' ) ) !== false ) {
393
-		while ( ( $data = fgetcsv( $handle, 1000, '|' ) ) !== false ) {
394
-			if ( ! empty( $data[2] ) ) {
395
-				$code           = $data[2];
396
-				$label          = htmlentities( $data[3] );
397
-				$langs[ $code ] = $label;
398
-			}
399
-		}
400
-		fclose( $handle );
401
-	}
392
+    if ( ( $handle = fopen( $filename, 'r' ) ) !== false ) {
393
+        while ( ( $data = fgetcsv( $handle, 1000, '|' ) ) !== false ) {
394
+            if ( ! empty( $data[2] ) ) {
395
+                $code           = $data[2];
396
+                $label          = htmlentities( $data[3] );
397
+                $langs[ $code ] = $label;
398
+            }
399
+        }
400
+        fclose( $handle );
401
+    }
402 402
 
403
-	// sort the languages;
404
-	asort( $langs );
403
+    // sort the languages;
404
+    asort( $langs );
405 405
 
406
-	return $langs;
406
+    return $langs;
407 407
 
408 408
 }
409 409
 
@@ -415,13 +415,13 @@  discard block
 block discarded – undo
415 415
  */
416 416
 function wl_config_get_recursion_depth() {
417 417
 
418
-	// get the plugin options.
419
-	$options = get_option( WL_OPTIONS_NAME );
418
+    // get the plugin options.
419
+    $options = get_option( WL_OPTIONS_NAME );
420 420
 
421
-	return ( isset( $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ] )
422
-	         && is_numeric( $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ] )
423
-		? $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ]
424
-		: WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING );
421
+    return ( isset( $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ] )
422
+             && is_numeric( $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ] )
423
+        ? $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ]
424
+        : WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING );
425 425
 }
426 426
 
427 427
 
@@ -434,13 +434,13 @@  discard block
 block discarded – undo
434 434
  */
435 435
 function wl_configuration_validate() {
436 436
 
437
-	// Check that the WordLift key has been set or show a notice.
438
-	if ( '' !== wl_configuration_get_key() ) {
439
-		return;
440
-	}
437
+    // Check that the WordLift key has been set or show a notice.
438
+    if ( '' !== wl_configuration_get_key() ) {
439
+        return;
440
+    }
441 441
 
442
-	Wordlift_Notice_Service::get_instance()
443
-	                       ->add_error( sprintf( __( 'application-key-not-set', 'wordlift' ), 'http://join.wordlift.it' ) );
442
+    Wordlift_Notice_Service::get_instance()
443
+                            ->add_error( sprintf( __( 'application-key-not-set', 'wordlift' ), 'http://join.wordlift.it' ) );
444 444
 
445 445
 }
446 446
 
@@ -456,37 +456,37 @@  discard block
 block discarded – undo
456 456
  */
457 457
 function wl_configuration_update_key( $old_value, $new_value ) {
458 458
 
459
-	// wl_write_log( "Going to request set redlink dataset uri if needed" );
459
+    // wl_write_log( "Going to request set redlink dataset uri if needed" );
460 460
 
461
-	// Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed.
462
-	$old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
463
-	$new_key = isset( $new_value['key'] ) ? $new_value['key'] : '';
461
+    // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed.
462
+    $old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
463
+    $new_key = isset( $new_value['key'] ) ? $new_value['key'] : '';
464 464
 
465
-	// wl_write_log( "[ old value :: $old_key ][ new value :: $new_key ]" );
465
+    // wl_write_log( "[ old value :: $old_key ][ new value :: $new_key ]" );
466 466
 
467
-	// If the key hasn't changed, don't do anything.
468
-	// WARN The 'update_option' hook is fired only if the new and old value are not equal
469
-	if ( $old_key === $new_key ) {
470
-		return;
471
-	}
467
+    // If the key hasn't changed, don't do anything.
468
+    // WARN The 'update_option' hook is fired only if the new and old value are not equal
469
+    if ( $old_key === $new_key ) {
470
+        return;
471
+    }
472 472
 
473
-	// If the key is empty, empty the dataset URI.
474
-	if ( '' === $new_key ) {
475
-		wl_configuration_set_redlink_dataset_uri( '' );
476
-	}
473
+    // If the key is empty, empty the dataset URI.
474
+    if ( '' === $new_key ) {
475
+        wl_configuration_set_redlink_dataset_uri( '' );
476
+    }
477 477
 
478
-	// Request the dataset URI.
479
-	$response = wp_remote_get( wl_configuration_get_accounts_by_key_dataset_uri( $new_key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) );
478
+    // Request the dataset URI.
479
+    $response = wp_remote_get( wl_configuration_get_accounts_by_key_dataset_uri( $new_key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) );
480 480
 
481
-	// If the response is valid, then set the value.
482
-	if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
481
+    // If the response is valid, then set the value.
482
+    if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
483 483
 
484
-		// wl_write_log( "[ Retrieved dataset :: " . $response['body'] . " ]" );
485
-		wl_configuration_set_redlink_dataset_uri( $response['body'] );
484
+        // wl_write_log( "[ Retrieved dataset :: " . $response['body'] . " ]" );
485
+        wl_configuration_set_redlink_dataset_uri( $response['body'] );
486 486
 
487
-	} else {
488
-		wl_write_log( "Error on dataset uri remote retrieving [ " . var_export( $response, true ) . " ]" );
489
-	}
487
+    } else {
488
+        wl_write_log( "Error on dataset uri remote retrieving [ " . var_export( $response, true ) . " ]" );
489
+    }
490 490
 
491 491
 }
492 492
 
Please login to merge, or discard this patch.
Spacing   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@  discard block
 block discarded – undo
5 5
  *  * methods for retrieving configuration data
6 6
  */
7 7
 
8
-require_once( 'wordlift_configuration_constants.php' );
9
-require_once( 'wordlift_configuration_settings.php' );
8
+require_once('wordlift_configuration_constants.php');
9
+require_once('wordlift_configuration_settings.php');
10 10
 
11 11
 /**
12 12
  * This function is called by the *wl_admin_menu* hook which is raised when WordLift builds the admin_menu.
@@ -16,21 +16,21 @@  discard block
 block discarded – undo
16 16
  * @param string $parent_slug The parent slug for the menu.
17 17
  * @param string $capability The required capability to access the page.
18 18
  */
19
-function wl_configuration_admin_menu( $parent_slug, $capability ) {
19
+function wl_configuration_admin_menu($parent_slug, $capability) {
20 20
 
21 21
 	// see http://codex.wordpress.org/Function_Reference/add_submenu_page
22 22
 	add_submenu_page(
23 23
 		$parent_slug, // The parent menu slug, provided by the calling hook.
24
-		__( 'Settings', 'wordlift' ),  // page title
25
-		__( 'Settings', 'wordlift' ),  // menu title
26
-		$capability,                   // The required capability, provided by the calling hook.
27
-		'wl_configuration_admin_menu',      // the menu slug
24
+		__('Settings', 'wordlift'), // page title
25
+		__('Settings', 'wordlift'), // menu title
26
+		$capability, // The required capability, provided by the calling hook.
27
+		'wl_configuration_admin_menu', // the menu slug
28 28
 		'wl_configuration_admin_menu_callback' // the menu callback for displaying the page content
29 29
 	);
30 30
 
31 31
 }
32 32
 
33
-add_action( 'wl_admin_menu', 'wl_configuration_admin_menu', 10, 2 );
33
+add_action('wl_admin_menu', 'wl_configuration_admin_menu', 10, 2);
34 34
 
35 35
 /**
36 36
  * Displays the page content.
@@ -39,20 +39,20 @@  discard block
 block discarded – undo
39 39
  *
40 40
  * @param boolean $display_page_title If true, prints out the page title.
41 41
  */
42
-function wl_configuration_admin_menu_callback( $display_page_title = true ) {
42
+function wl_configuration_admin_menu_callback($display_page_title = true) {
43 43
 
44
-	if ( ! current_user_can( 'manage_options' ) ) {
45
-		wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
44
+	if ( ! current_user_can('manage_options')) {
45
+		wp_die(__('You do not have sufficient permissions to access this page.'));
46 46
 	}
47 47
 
48 48
 	// Ony show advanced settings tab if the relative constant exists and is set to true.
49
-	$can_show_advanced_settings = defined( 'WL_ENABLE_ADVANCED_CONFIGURATION' ) && WL_ENABLE_ADVANCED_CONFIGURATION;
49
+	$can_show_advanced_settings = defined('WL_ENABLE_ADVANCED_CONFIGURATION') && WL_ENABLE_ADVANCED_CONFIGURATION;
50 50
 
51 51
 	?>
52 52
 
53 53
 	<div class="wrap">
54 54
 
55
-		<?php if ( $display_page_title ) { ?>
55
+		<?php if ($display_page_title) { ?>
56 56
 			<div id="icon-themes" class="icon32"></div>
57 57
 			<h2>WordLift</h2>
58 58
 		<?php } ?>
@@ -60,28 +60,28 @@  discard block
 block discarded – undo
60 60
 		<?php settings_errors(); ?>
61 61
 
62 62
 		<?php
63
-		$active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general_settings';
63
+		$active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'general_settings';
64 64
 		?>
65 65
 
66 66
 		<h2 class="nav-tab-wrapper">
67
-			<a href="?page=<?php echo( $_GET['page'] ); ?>&tab=general_settings"
68
-			   class="nav-tab <?php echo $active_tab == 'general_settings' ? 'nav-tab-active' : ''; ?>"><?php esc_attr_e( 'General', 'wordlift' ); ?></a>
67
+			<a href="?page=<?php echo($_GET['page']); ?>&tab=general_settings"
68
+			   class="nav-tab <?php echo $active_tab == 'general_settings' ? 'nav-tab-active' : ''; ?>"><?php esc_attr_e('General', 'wordlift'); ?></a>
69 69
 
70
-			<?php if ( $can_show_advanced_settings ): ?>
71
-				<a href="?page=<?php echo( $_GET['page'] ); ?>&tab=advanced_settings"
72
-				   class="nav-tab <?php echo $active_tab == 'advanced_settings' ? 'nav-tab-active' : ''; ?>"><?php esc_attr_e( 'Advanced', 'wordlift' ); ?></a>
70
+			<?php if ($can_show_advanced_settings): ?>
71
+				<a href="?page=<?php echo($_GET['page']); ?>&tab=advanced_settings"
72
+				   class="nav-tab <?php echo $active_tab == 'advanced_settings' ? 'nav-tab-active' : ''; ?>"><?php esc_attr_e('Advanced', 'wordlift'); ?></a>
73 73
 			<?php endif; ?>
74 74
 		</h2>
75 75
 
76 76
 		<form action="options.php" method="post">
77 77
 			<?php
78
-			if ( 'general_settings' === $active_tab ) {
79
-				settings_fields( 'wl_general_settings' );
80
-				do_settings_sections( 'wl_general_settings' );
78
+			if ('general_settings' === $active_tab) {
79
+				settings_fields('wl_general_settings');
80
+				do_settings_sections('wl_general_settings');
81 81
 
82
-			} else if ( $can_show_advanced_settings && 'advanced_settings' === $active_tab ) {
83
-				settings_fields( 'wl_advanced_settings' );
84
-				do_settings_sections( 'wl_advanced_settings' );
82
+			} else if ($can_show_advanced_settings && 'advanced_settings' === $active_tab) {
83
+				settings_fields('wl_advanced_settings');
84
+				do_settings_sections('wl_advanced_settings');
85 85
 			}
86 86
 
87 87
 			submit_button();
@@ -115,29 +115,29 @@  discard block
 block discarded – undo
115 115
 	);
116 116
 
117 117
 	add_settings_section(
118
-		'wl_general_settings_section',          // ID used to identify this section and with which to register options
119
-		'General Settings',                              // Title to be displayed on the administration page
118
+		'wl_general_settings_section', // ID used to identify this section and with which to register options
119
+		'General Settings', // Title to be displayed on the administration page
120 120
 		'wl_configuration_general_settings_section_callback', // Callback used to render the description of the section
121 121
 		'wl_general_settings'              // Page on which to add this section of options
122 122
 	);
123 123
 
124 124
 	add_settings_field(
125
-		WL_CONFIG_WORDLIFT_KEY,             // ID used to identify the field throughout the theme
126
-		__( 'WordLift Key', 'wordlift' ),   // The label to the left of the option interface element
127
-		'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
128
-		'wl_general_settings',         // The page on which this option will be displayed
129
-		'wl_general_settings_section',      // The name of the section to which this field belongs
125
+		WL_CONFIG_WORDLIFT_KEY, // ID used to identify the field throughout the theme
126
+		__('WordLift Key', 'wordlift'), // The label to the left of the option interface element
127
+		'wl_configuration_input_box', // The name of the function responsible for rendering the option interface
128
+		'wl_general_settings', // The page on which this option will be displayed
129
+		'wl_general_settings_section', // The name of the section to which this field belongs
130 130
 		array(                              // The array of arguments to pass to the callback. In this case, just a description.
131 131
 			'id'          => 'wl-key',
132 132
 			'name'        => 'wl_general_settings[key]',
133 133
 			'value'       => wl_configuration_get_key(),
134
-			'description' => __( 'Insert the WordLift Key', 'wordlift' )
134
+			'description' => __('Insert the WordLift Key', 'wordlift')
135 135
 		)
136 136
 	);
137 137
 
138 138
 	add_settings_field(
139 139
 		WL_CONFIG_SITE_LANGUAGE_NAME,
140
-		__( 'Site Language', 'wordlift' ),
140
+		__('Site Language', 'wordlift'),
141 141
 		'wl_configuration_select',
142 142
 		'wl_general_settings',
143 143
 		'wl_general_settings_section',
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
 			'id'          => 'wl-site-language',
146 146
 			'name'        => 'wl_general_settings[site_language]',
147 147
 			'value'       => wl_configuration_get_site_language(),
148
-			'description' => __( 'The site language', 'wordlift' ),
148
+			'description' => __('The site language', 'wordlift'),
149 149
 			'options'     => wl_configuration_get_languages()
150 150
 		)
151 151
 	);
152 152
 
153 153
 
154
-	if ( defined( 'WL_ENABLE_ADVANCED_CONFIGURATION' ) && WL_ENABLE_ADVANCED_CONFIGURATION ) {
154
+	if (defined('WL_ENABLE_ADVANCED_CONFIGURATION') && WL_ENABLE_ADVANCED_CONFIGURATION) {
155 155
 
156 156
 		register_setting(
157 157
 			'wl_advanced_settings',
@@ -160,99 +160,99 @@  discard block
 block discarded – undo
160 160
 		);
161 161
 
162 162
 		add_settings_section(
163
-			'wl_advanced_settings_section',          // ID used to identify this section and with which to register options
164
-			'Advanced',                              // Title to be displayed on the administration page
163
+			'wl_advanced_settings_section', // ID used to identify this section and with which to register options
164
+			'Advanced', // Title to be displayed on the administration page
165 165
 			'wl_configuration_advanced_settings_section_callback', // Callback used to render the description of the section
166 166
 			'wl_advanced_settings'              // Page on which to add this section of options
167 167
 		);
168 168
 
169 169
 		add_settings_field(
170
-			WL_CONFIG_API_URL,             // ID used to identify the field throughout the theme
171
-			__( 'API URL', 'wordlift' ),   // The label to the left of the option interface element
172
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
173
-			'wl_advanced_settings',         // The page on which this option will be displayed
174
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
170
+			WL_CONFIG_API_URL, // ID used to identify the field throughout the theme
171
+			__('API URL', 'wordlift'), // The label to the left of the option interface element
172
+			'wl_configuration_input_box', // The name of the function responsible for rendering the option interface
173
+			'wl_advanced_settings', // The page on which this option will be displayed
174
+			'wl_advanced_settings_section', // The name of the section to which this field belongs
175 175
 			array(                              // The array of arguments to pass to the callback. In this case, just a description.
176 176
 				'id'          => 'wl-api-url',
177 177
 				'name'        => 'wl_advanced_settings[api_url]',
178 178
 				'value'       => wl_configuration_get_api_url(),
179
-				'description' => __( 'The API URL', 'wordlift' )
179
+				'description' => __('The API URL', 'wordlift')
180 180
 			)
181 181
 		);
182 182
 
183 183
 		add_settings_field(
184
-			WL_CONFIG_APPLICATION_KEY_NAME,             // ID used to identify the field throughout the theme
185
-			__( 'Redlink Key', 'wordlift' ),   // The label to the left of the option interface element
186
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
187
-			'wl_advanced_settings',         // The page on which this option will be displayed
188
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
184
+			WL_CONFIG_APPLICATION_KEY_NAME, // ID used to identify the field throughout the theme
185
+			__('Redlink Key', 'wordlift'), // The label to the left of the option interface element
186
+			'wl_configuration_input_box', // The name of the function responsible for rendering the option interface
187
+			'wl_advanced_settings', // The page on which this option will be displayed
188
+			'wl_advanced_settings_section', // The name of the section to which this field belongs
189 189
 			array(                              // The array of arguments to pass to the callback. In this case, just a description.
190 190
 				'id'          => 'wl-redlink-key',
191 191
 				'name'        => 'wl_advanced_settings[redlink_key]',
192 192
 				'value'       => wl_configuration_get_redlink_key(),
193
-				'description' => __( 'The Redlink key', 'wordlift' )
193
+				'description' => __('The Redlink key', 'wordlift')
194 194
 			)
195 195
 		);
196 196
 
197 197
 		add_settings_field(
198
-			WL_CONFIG_USER_ID_NAME,             // ID used to identify the field throughout the theme
199
-			__( 'Redlink User Id', 'wordlift' ),   // The label to the left of the option interface element
200
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
201
-			'wl_advanced_settings',         // The page on which this option will be displayed
202
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
198
+			WL_CONFIG_USER_ID_NAME, // ID used to identify the field throughout the theme
199
+			__('Redlink User Id', 'wordlift'), // The label to the left of the option interface element
200
+			'wl_configuration_input_box', // The name of the function responsible for rendering the option interface
201
+			'wl_advanced_settings', // The page on which this option will be displayed
202
+			'wl_advanced_settings_section', // The name of the section to which this field belongs
203 203
 			array(                              // The array of arguments to pass to the callback. In this case, just a description.
204 204
 				'id'          => 'wl-redlink-user-id',
205 205
 				'name'        => 'wl_advanced_settings[redlink_user_id]',
206 206
 				'value'       => wl_configuration_get_redlink_user_id(),
207
-				'description' => __( 'The Redlink User Id', 'wordlift' )
207
+				'description' => __('The Redlink User Id', 'wordlift')
208 208
 			)
209 209
 		);
210 210
 
211 211
 		add_settings_field(
212
-			WL_CONFIG_DATASET_NAME,             // ID used to identify the field throughout the theme
213
-			__( 'Redlink Dataset name', 'wordlift' ),   // The label to the left of the option interface element
214
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
215
-			'wl_advanced_settings',         // The page on which this option will be displayed
216
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
212
+			WL_CONFIG_DATASET_NAME, // ID used to identify the field throughout the theme
213
+			__('Redlink Dataset name', 'wordlift'), // The label to the left of the option interface element
214
+			'wl_configuration_input_box', // The name of the function responsible for rendering the option interface
215
+			'wl_advanced_settings', // The page on which this option will be displayed
216
+			'wl_advanced_settings_section', // The name of the section to which this field belongs
217 217
 			array(                              // The array of arguments to pass to the callback. In this case, just a description.
218 218
 				'id'          => 'wl-redlink-dataset-name',
219 219
 				'name'        => 'wl_advanced_settings[redlink_dataset_name]',
220 220
 				'value'       => wl_configuration_get_redlink_dataset_name(),
221
-				'description' => __( 'The Redlink Dataset Name', 'wordlift' )
221
+				'description' => __('The Redlink Dataset Name', 'wordlift')
222 222
 			)
223 223
 		);
224 224
 
225 225
 		add_settings_field(
226
-			WL_CONFIG_DATASET_BASE_URI_NAME,             // ID used to identify the field throughout the theme
227
-			__( 'Redlink Dataset URI', 'wordlift' ),   // The label to the left of the option interface element
228
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
229
-			'wl_advanced_settings',         // The page on which this option will be displayed
230
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
226
+			WL_CONFIG_DATASET_BASE_URI_NAME, // ID used to identify the field throughout the theme
227
+			__('Redlink Dataset URI', 'wordlift'), // The label to the left of the option interface element
228
+			'wl_configuration_input_box', // The name of the function responsible for rendering the option interface
229
+			'wl_advanced_settings', // The page on which this option will be displayed
230
+			'wl_advanced_settings_section', // The name of the section to which this field belongs
231 231
 			array(                              // The array of arguments to pass to the callback. In this case, just a description.
232 232
 				'id'          => 'wl-redlink-dataset-uri',
233 233
 				'name'        => 'wl_advanced_settings[redlink_dataset_uri]',
234 234
 				'value'       => wl_configuration_get_redlink_dataset_uri(),
235
-				'description' => __( 'The Redlink Dataset URI', 'wordlift' )
235
+				'description' => __('The Redlink Dataset URI', 'wordlift')
236 236
 			)
237 237
 		);
238 238
 
239 239
 		add_settings_field(
240
-			WL_CONFIG_ANALYSIS_NAME,             // ID used to identify the field throughout the theme
241
-			__( 'Redlink Application Name', 'wordlift' ),   // The label to the left of the option interface element
242
-			'wl_configuration_input_box',       // The name of the function responsible for rendering the option interface
243
-			'wl_advanced_settings',         // The page on which this option will be displayed
244
-			'wl_advanced_settings_section',      // The name of the section to which this field belongs
240
+			WL_CONFIG_ANALYSIS_NAME, // ID used to identify the field throughout the theme
241
+			__('Redlink Application Name', 'wordlift'), // The label to the left of the option interface element
242
+			'wl_configuration_input_box', // The name of the function responsible for rendering the option interface
243
+			'wl_advanced_settings', // The page on which this option will be displayed
244
+			'wl_advanced_settings_section', // The name of the section to which this field belongs
245 245
 			array(                              // The array of arguments to pass to the callback. In this case, just a description.
246 246
 				'id'          => 'wl-redlink-application-name',
247 247
 				'name'        => 'wl_advanced_settings[redlink_application_name]',
248 248
 				'value'       => wl_configuration_get_redlink_application_name(),
249
-				'description' => __( 'The Redlink Application Name', 'wordlift' )
249
+				'description' => __('The Redlink Application Name', 'wordlift')
250 250
 			)
251 251
 		);
252 252
 	}
253 253
 }
254 254
 
255
-add_action( 'admin_init', 'wl_configuration_settings' );
255
+add_action('admin_init', 'wl_configuration_settings');
256 256
 
257 257
 /**
258 258
  * Display the general settings description. Called from a hook set by *wl_configuration_settings*.
@@ -289,10 +289,10 @@  discard block
 block discarded – undo
289 289
  *
290 290
  * @return mixed
291 291
  */
292
-function wl_configuration_sanitize_settings( $input ) {
292
+function wl_configuration_sanitize_settings($input) {
293 293
 
294 294
 	// TODO: add sanitization checks.
295
-	return apply_filters( 'wl_configuration_sanitize_settings', $input, $input );
295
+	return apply_filters('wl_configuration_sanitize_settings', $input, $input);
296 296
 
297 297
 }
298 298
 
@@ -303,12 +303,12 @@  discard block
 block discarded – undo
303 303
  *
304 304
  * @param array $args An array of configuration parameters.
305 305
  */
306
-function wl_configuration_input_box( $args ) {
306
+function wl_configuration_input_box($args) {
307 307
 	?>
308 308
 
309
-	<input type="text" id="<?php echo esc_attr( $args['id'] ); ?>"
310
-	       name="<?php echo esc_attr( $args['name'] ); ?>"
311
-	       value="<?php echo esc_attr( $args['value'] ); ?>"/>
309
+	<input type="text" id="<?php echo esc_attr($args['id']); ?>"
310
+	       name="<?php echo esc_attr($args['name']); ?>"
311
+	       value="<?php echo esc_attr($args['value']); ?>"/>
312 312
 
313 313
 	<?php
314 314
 }
@@ -320,16 +320,16 @@  discard block
 block discarded – undo
320 320
  *
321 321
  * @param array $args The select configuration parameters.
322 322
  */
323
-function wl_configuration_select( $args ) {
323
+function wl_configuration_select($args) {
324 324
 	?>
325 325
 
326
-	<select id="<?php echo esc_attr( $args['id'] ); ?>"
327
-	        name="<?php echo esc_attr( $args['name'] ); ?>">
328
-		<?php foreach ( $args['options'] as $value => $label ) { ?>
329
-			<option value="<?php echo esc_attr( $value ); ?>" <?php if ( $args['value'] === $value ) {
326
+	<select id="<?php echo esc_attr($args['id']); ?>"
327
+	        name="<?php echo esc_attr($args['name']); ?>">
328
+		<?php foreach ($args['options'] as $value => $label) { ?>
329
+			<option value="<?php echo esc_attr($value); ?>" <?php if ($args['value'] === $value) {
330 330
 				echo 'selected';
331 331
 			}
332
-			?>><?php echo esc_html( $label ); ?></option>
332
+			?>><?php echo esc_html($label); ?></option>
333 333
 		<?php } ?>
334 334
 	</select>
335 335
 
@@ -343,12 +343,12 @@  discard block
 block discarded – undo
343 343
  *
344 344
  * @param array $args The checkbox parameters.
345 345
  */
346
-function wl_configuration_checkbox( $args ) {
346
+function wl_configuration_checkbox($args) {
347 347
 	?>
348 348
 
349
-	<input type="checkbox" id="<?php echo esc_attr( $args['id'] ); ?>"
350
-	       name="<?php echo esc_attr( $args['name'] ); ?>"
351
-	       value="1" <?php checked( 1, $args['value'], true ); ?>/>
349
+	<input type="checkbox" id="<?php echo esc_attr($args['id']); ?>"
350
+	       name="<?php echo esc_attr($args['name']); ?>"
351
+	       value="1" <?php checked(1, $args['value'], true); ?>/>
352 352
 
353 353
 	<?php
354 354
 }
@@ -362,16 +362,16 @@  discard block
 block discarded – undo
362 362
  *
363 363
  * @return array An array of links including those added by the plugin.
364 364
  */
365
-function wl_configuration_settings_links( $links ) {
365
+function wl_configuration_settings_links($links) {
366 366
 
367 367
 	// TODO: this link is different within SEO Ultimate.
368
-	array_push( $links, '<a href="' . get_admin_url( null, 'admin.php?page=wl_configuration_admin_menu' ) . '">Settings</a>' );
368
+	array_push($links, '<a href="'.get_admin_url(null, 'admin.php?page=wl_configuration_admin_menu').'">Settings</a>');
369 369
 
370 370
 	return $links;
371 371
 }
372 372
 
373 373
 // add the settings link for the plugin.
374
-add_filter( "plugin_action_links_wordlift/wordlift.php", 'wl_configuration_settings_links' );
374
+add_filter("plugin_action_links_wordlift/wordlift.php", 'wl_configuration_settings_links');
375 375
 
376 376
 
377 377
 /**
@@ -387,21 +387,21 @@  discard block
 block discarded – undo
387 387
 	$langs = array();
388 388
 
389 389
 	// set the path to the language file.
390
-	$filename = dirname( __FILE__ ) . '/ISO-639-2_utf-8.txt';
390
+	$filename = dirname(__FILE__).'/ISO-639-2_utf-8.txt';
391 391
 
392
-	if ( ( $handle = fopen( $filename, 'r' ) ) !== false ) {
393
-		while ( ( $data = fgetcsv( $handle, 1000, '|' ) ) !== false ) {
394
-			if ( ! empty( $data[2] ) ) {
392
+	if (($handle = fopen($filename, 'r')) !== false) {
393
+		while (($data = fgetcsv($handle, 1000, '|')) !== false) {
394
+			if ( ! empty($data[2])) {
395 395
 				$code           = $data[2];
396
-				$label          = htmlentities( $data[3] );
397
-				$langs[ $code ] = $label;
396
+				$label          = htmlentities($data[3]);
397
+				$langs[$code] = $label;
398 398
 			}
399 399
 		}
400
-		fclose( $handle );
400
+		fclose($handle);
401 401
 	}
402 402
 
403 403
 	// sort the languages;
404
-	asort( $langs );
404
+	asort($langs);
405 405
 
406 406
 	return $langs;
407 407
 
@@ -416,12 +416,12 @@  discard block
 block discarded – undo
416 416
 function wl_config_get_recursion_depth() {
417 417
 
418 418
 	// get the plugin options.
419
-	$options = get_option( WL_OPTIONS_NAME );
419
+	$options = get_option(WL_OPTIONS_NAME);
420 420
 
421
-	return ( isset( $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ] )
422
-	         && is_numeric( $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ] )
423
-		? $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ]
424
-		: WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING );
421
+	return (isset($options[WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING])
422
+	         && is_numeric($options[WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING])
423
+		? $options[WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING]
424
+		: WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING);
425 425
 }
426 426
 
427 427
 
@@ -435,16 +435,16 @@  discard block
 block discarded – undo
435 435
 function wl_configuration_validate() {
436 436
 
437 437
 	// Check that the WordLift key has been set or show a notice.
438
-	if ( '' !== wl_configuration_get_key() ) {
438
+	if ('' !== wl_configuration_get_key()) {
439 439
 		return;
440 440
 	}
441 441
 
442 442
 	Wordlift_Notice_Service::get_instance()
443
-	                       ->add_error( sprintf( __( 'application-key-not-set', 'wordlift' ), 'http://join.wordlift.it' ) );
443
+	                       ->add_error(sprintf(__('application-key-not-set', 'wordlift'), 'http://join.wordlift.it'));
444 444
 
445 445
 }
446 446
 
447
-add_action( 'admin_init', 'wl_configuration_validate' );
447
+add_action('admin_init', 'wl_configuration_validate');
448 448
 
449 449
 /**
450 450
  * Intercept the change of the WordLift key in order to set the dataset URI.
@@ -454,40 +454,40 @@  discard block
 block discarded – undo
454 454
  * @param array $old_value The old settings.
455 455
  * @param array $new_value The new settings.
456 456
  */
457
-function wl_configuration_update_key( $old_value, $new_value ) {
457
+function wl_configuration_update_key($old_value, $new_value) {
458 458
 
459 459
 	// wl_write_log( "Going to request set redlink dataset uri if needed" );
460 460
 
461 461
 	// Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed.
462
-	$old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
463
-	$new_key = isset( $new_value['key'] ) ? $new_value['key'] : '';
462
+	$old_key = isset($old_value['key']) ? $old_value['key'] : '';
463
+	$new_key = isset($new_value['key']) ? $new_value['key'] : '';
464 464
 
465 465
 	// wl_write_log( "[ old value :: $old_key ][ new value :: $new_key ]" );
466 466
 
467 467
 	// If the key hasn't changed, don't do anything.
468 468
 	// WARN The 'update_option' hook is fired only if the new and old value are not equal
469
-	if ( $old_key === $new_key ) {
469
+	if ($old_key === $new_key) {
470 470
 		return;
471 471
 	}
472 472
 
473 473
 	// If the key is empty, empty the dataset URI.
474
-	if ( '' === $new_key ) {
475
-		wl_configuration_set_redlink_dataset_uri( '' );
474
+	if ('' === $new_key) {
475
+		wl_configuration_set_redlink_dataset_uri('');
476 476
 	}
477 477
 
478 478
 	// Request the dataset URI.
479
-	$response = wp_remote_get( wl_configuration_get_accounts_by_key_dataset_uri( $new_key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) );
479
+	$response = wp_remote_get(wl_configuration_get_accounts_by_key_dataset_uri($new_key), unserialize(WL_REDLINK_API_HTTP_OPTIONS));
480 480
 
481 481
 	// If the response is valid, then set the value.
482
-	if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
482
+	if ( ! is_wp_error($response) && 200 === (int) $response['response']['code']) {
483 483
 
484 484
 		// wl_write_log( "[ Retrieved dataset :: " . $response['body'] . " ]" );
485
-		wl_configuration_set_redlink_dataset_uri( $response['body'] );
485
+		wl_configuration_set_redlink_dataset_uri($response['body']);
486 486
 
487 487
 	} else {
488
-		wl_write_log( "Error on dataset uri remote retrieving [ " . var_export( $response, true ) . " ]" );
488
+		wl_write_log("Error on dataset uri remote retrieving [ ".var_export($response, true)." ]");
489 489
 	}
490 490
 
491 491
 }
492 492
 
493
-add_action( 'update_option_wl_general_settings', 'wl_configuration_update_key', 10, 2 );
494 493
\ No newline at end of file
494
+add_action('update_option_wl_general_settings', 'wl_configuration_update_key', 10, 2);
495 495
\ No newline at end of file
Please login to merge, or discard this patch.
src/modules/configuration/wordlift_configuration_constants.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@
 block discarded – undo
1 1
 <?php
2 2
 // the WordLift options identifier.
3
-define( 'WL_OPTIONS_NAME', 'wordlift_options' );
3
+define('WL_OPTIONS_NAME', 'wordlift_options');
4 4
 
5 5
 // The WordLift key.
6
-define( 'WL_CONFIG_WORDLIFT_KEY', 'wl_key' );
6
+define('WL_CONFIG_WORDLIFT_KEY', 'wl_key');
7 7
 
8 8
 // Define the field name for the dataset base URI.
9
-define( 'WL_CONFIG_DATASET_BASE_URI_NAME', 'dataset_base_uri' );
9
+define('WL_CONFIG_DATASET_BASE_URI_NAME', 'dataset_base_uri');
10 10
 
11
-define( 'WL_CONFIG_API_URL', 'api_url' );
12
-define( 'WL_CONFIG_APPLICATION_KEY_NAME', 'application_key' );
11
+define('WL_CONFIG_API_URL', 'api_url');
12
+define('WL_CONFIG_APPLICATION_KEY_NAME', 'application_key');
13 13
 
14
-define( 'WL_CONFIG_USER_ID_NAME', 'user_id' );
14
+define('WL_CONFIG_USER_ID_NAME', 'user_id');
15 15
 
16
-define( 'WL_CONFIG_DATASET_NAME', 'dataset_name' );
16
+define('WL_CONFIG_DATASET_NAME', 'dataset_name');
17 17
 
18
-define( 'WL_CONFIG_ANALYSIS_NAME', 'analysis_name' );
18
+define('WL_CONFIG_ANALYSIS_NAME', 'analysis_name');
19 19
 
20
-define( 'WL_CONFIG_SITE_LANGUAGE_NAME', 'site_language' );
20
+define('WL_CONFIG_SITE_LANGUAGE_NAME', 'site_language');
21 21
 
22
-define( 'WL_CONFIG_DEFAULT_SITE_LANGUAGE', 'en' );
22
+define('WL_CONFIG_DEFAULT_SITE_LANGUAGE', 'en');
23 23
 
24
-define( 'WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING', 'recursion_depth_on_metadata_printing' );
24
+define('WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING', 'recursion_depth_on_metadata_printing');
25 25
 
26
-define( 'WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined( 'WORDLIFT_API_URL' ) ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.it/' );
26
+define('WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined('WORDLIFT_API_URL') ? WORDLIFT_API_URL.'/' : 'https://api.wordlift.it/');
27 27
 
28
-define( 'WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url=' );
28
+define('WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url=');
Please login to merge, or discard this patch.
src/modules/configuration/wordlift_configuration_settings.php 2 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -9,10 +9,10 @@  discard block
 block discarded – undo
9 9
  */
10 10
 function wl_configuration_set( $settings, $key, $value ) {
11 11
 
12
-	$options         = get_option( $settings );
13
-	$options         = isset( $options ) ? $options : array();
14
-	$options[ $key ] = $value;
15
-	update_option( $settings, $options );
12
+    $options         = get_option( $settings );
13
+    $options         = isset( $options ) ? $options : array();
14
+    $options[ $key ] = $value;
15
+    update_option( $settings, $options );
16 16
 }
17 17
 
18 18
 
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
  * @return string The configured WordLift key or an empty string.
25 25
  */
26 26
 function wl_configuration_get_key() {
27
-	$options = get_option( 'wl_general_settings' );
27
+    $options = get_option( 'wl_general_settings' );
28 28
 
29
-	if ( isset( $options['key'] ) ) {
30
-		return $options['key'];
31
-	}
29
+    if ( isset( $options['key'] ) ) {
30
+        return $options['key'];
31
+    }
32 32
 
33
-	return '';
33
+    return '';
34 34
 }
35 35
 
36 36
 
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
  */
44 44
 function wl_configuration_set_key( $value ) {
45 45
 
46
-	wl_configuration_set( 'wl_general_settings', 'key', $value );
46
+    wl_configuration_set( 'wl_general_settings', 'key', $value );
47 47
 
48 48
 }
49 49
 
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
  */
57 57
 function wl_configuration_get_site_language() {
58 58
 
59
-	$options = get_option( 'wl_general_settings' );
59
+    $options = get_option( 'wl_general_settings' );
60 60
 
61
-	return ( empty( $options['site_language'] ) ? 'en' : $options['site_language'] );
61
+    return ( empty( $options['site_language'] ) ? 'en' : $options['site_language'] );
62 62
 }
63 63
 
64 64
 /**
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
  */
71 71
 function wl_configuration_set_site_language( $value ) {
72 72
 
73
-	wl_configuration_set( 'wl_general_settings', 'site_language', $value );
73
+    wl_configuration_set( 'wl_general_settings', 'site_language', $value );
74 74
 }
75 75
 
76 76
 /**
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
  */
83 83
 function wl_configuration_get_api_url() {
84 84
 
85
-	$options = get_option( 'wl_advanced_settings', '' );
85
+    $options = get_option( 'wl_advanced_settings', '' );
86 86
 
87
-	return ( empty( $options['api_url'] ) ? '' : $options['api_url'] );
87
+    return ( empty( $options['api_url'] ) ? '' : $options['api_url'] );
88 88
 
89 89
 }
90 90
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
  */
98 98
 function wl_configuration_set_api_url( $value ) {
99 99
 
100
-	wl_configuration_set( 'wl_advanced_settings', 'api_url', $value );
100
+    wl_configuration_set( 'wl_advanced_settings', 'api_url', $value );
101 101
 }
102 102
 
103 103
 /**
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
  */
110 110
 function wl_configuration_get_redlink_key() {
111 111
 
112
-	$options = get_option( 'wl_advanced_settings', '' );
112
+    $options = get_option( 'wl_advanced_settings', '' );
113 113
 
114
-	return ( empty( $options['redlink_key'] ) ? '' : $options['redlink_key'] );
114
+    return ( empty( $options['redlink_key'] ) ? '' : $options['redlink_key'] );
115 115
 
116 116
 }
117 117
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
  */
125 125
 function wl_configuration_set_redlink_key( $value ) {
126 126
 
127
-	wl_configuration_set( 'wl_advanced_settings', 'redlink_key', $value );
127
+    wl_configuration_set( 'wl_advanced_settings', 'redlink_key', $value );
128 128
 }
129 129
 
130 130
 /**
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
  */
137 137
 function wl_configuration_get_redlink_user_id() {
138 138
 
139
-	$options = get_option( 'wl_advanced_settings', '' );
139
+    $options = get_option( 'wl_advanced_settings', '' );
140 140
 
141
-	return ( empty( $options['redlink_user_id'] ) ? '' : $options['redlink_user_id'] );
141
+    return ( empty( $options['redlink_user_id'] ) ? '' : $options['redlink_user_id'] );
142 142
 
143 143
 }
144 144
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
  */
152 152
 function wl_configuration_set_redlink_user_id( $value ) {
153 153
 
154
-	wl_configuration_set( 'wl_advanced_settings', 'redlink_user_id', $value );
154
+    wl_configuration_set( 'wl_advanced_settings', 'redlink_user_id', $value );
155 155
 }
156 156
 
157 157
 /**
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
  */
164 164
 function wl_configuration_get_redlink_dataset_name() {
165 165
 
166
-	$options = get_option( 'wl_advanced_settings', '' );
166
+    $options = get_option( 'wl_advanced_settings', '' );
167 167
 
168
-	return ( empty( $options['redlink_dataset_name'] ) ? '' : $options['redlink_dataset_name'] );
168
+    return ( empty( $options['redlink_dataset_name'] ) ? '' : $options['redlink_dataset_name'] );
169 169
 }
170 170
 
171 171
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
  */
179 179
 function wl_configuration_set_redlink_dataset_name( $value ) {
180 180
 
181
-	wl_configuration_set( 'wl_advanced_settings', 'redlink_dataset_name', $value );
181
+    wl_configuration_set( 'wl_advanced_settings', 'redlink_dataset_name', $value );
182 182
 }
183 183
 
184 184
 
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
  */
192 192
 function wl_configuration_get_redlink_dataset_uri() {
193 193
 
194
-	$options = get_option( 'wl_advanced_settings', '' );
194
+    $options = get_option( 'wl_advanced_settings', '' );
195 195
 
196
-	return ( empty( $options['redlink_dataset_uri'] ) ? '' : $options['redlink_dataset_uri'] );
196
+    return ( empty( $options['redlink_dataset_uri'] ) ? '' : $options['redlink_dataset_uri'] );
197 197
 }
198 198
 
199 199
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
  */
207 207
 function wl_configuration_set_redlink_dataset_uri( $value ) {
208 208
 
209
-	wl_configuration_set( 'wl_advanced_settings', 'redlink_dataset_uri', $value );
209
+    wl_configuration_set( 'wl_advanced_settings', 'redlink_dataset_uri', $value );
210 210
 }
211 211
 
212 212
 /**
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
  */
219 219
 function wl_configuration_get_redlink_application_name() {
220 220
 
221
-	$options = get_option( 'wl_advanced_settings', '' );
221
+    $options = get_option( 'wl_advanced_settings', '' );
222 222
 
223
-	return ( empty( $options['redlink_application_name'] ) ? '' : $options['redlink_application_name'] );
223
+    return ( empty( $options['redlink_application_name'] ) ? '' : $options['redlink_application_name'] );
224 224
 }
225 225
 
226 226
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
  */
234 234
 function wl_configuration_set_redlink_application_name( $value ) {
235 235
 
236
-	wl_configuration_set( 'wl_advanced_settings', 'redlink_application_name', $value );
236
+    wl_configuration_set( 'wl_advanced_settings', 'redlink_application_name', $value );
237 237
 }
238 238
 
239 239
 /**
@@ -250,17 +250,17 @@  discard block
 block discarded – undo
250 250
  */
251 251
 function wl_configuration_get_analyzer_url() {
252 252
 
253
-	// If the WordLift Key is set, we use WordLift.
254
-	$key = wl_configuration_get_key();
255
-	if ( ! empty( $key ) ) {
256
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "analyses?key=$key";
257
-	}
253
+    // If the WordLift Key is set, we use WordLift.
254
+    $key = wl_configuration_get_key();
255
+    if ( ! empty( $key ) ) {
256
+        return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "analyses?key=$key";
257
+    }
258 258
 
259
-	// Otherwise use Redlink.
260
-	$app_key       = wl_configuration_get_redlink_key();
261
-	$analysis_name = wl_configuration_get_redlink_application_name();
259
+    // Otherwise use Redlink.
260
+    $app_key       = wl_configuration_get_redlink_key();
261
+    $analysis_name = wl_configuration_get_redlink_application_name();
262 262
 
263
-	$ldpath = <<<EOF
263
+    $ldpath = <<<EOF
264 264
         @prefix ex: <http://example.org/>;
265 265
         @prefix cal: <http://www.w3.org/2002/12/cal#>;
266 266
         @prefix gn: <http://www.geonames.org/ontology#>;
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
         vcard:locality = lode:atPlace/gn:name :: xsd:string;
270 270
 EOF;
271 271
 
272
-	return wl_configuration_get_api_url() . "/analysis/$analysis_name/enhance?key=$app_key" .
273
-	       '&enhancer.engines.dereference.ldpath=' . urlencode( $ldpath );
272
+    return wl_configuration_get_api_url() . "/analysis/$analysis_name/enhance?key=$app_key" .
273
+            '&enhancer.engines.dereference.ldpath=' . urlencode( $ldpath );
274 274
 
275 275
 }
276 276
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
  */
286 286
 function wl_configuration_get_accounts_by_key_dataset_uri( $key ) {
287 287
 
288
-	return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri";
288
+    return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri";
289 289
 }
290 290
 
291 291
 
@@ -301,19 +301,19 @@  discard block
 block discarded – undo
301 301
  */
302 302
 function wl_configuration_get_query_select_url( $output, $dataset = null ) {
303 303
 
304
-	// If the WordLift Key is set, we use WordLift.
305
-	$key = wl_configuration_get_key();
306
-	if ( ! empty( $key ) ) {
307
-		// TODO: handle the output format for WordLift.
308
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries?q=";
309
-	}
304
+    // If the WordLift Key is set, we use WordLift.
305
+    $key = wl_configuration_get_key();
306
+    if ( ! empty( $key ) ) {
307
+        // TODO: handle the output format for WordLift.
308
+        return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries?q=";
309
+    }
310 310
 
311
-	// If no dataset has been specified then use the default configured, otherwise use the one provided.
312
-	$redlink_dataset = ( empty( $dataset ) ? wl_configuration_get_redlink_dataset_name() : $dataset );
313
-	$redlink_key     = wl_configuration_get_redlink_key();
311
+    // If no dataset has been specified then use the default configured, otherwise use the one provided.
312
+    $redlink_dataset = ( empty( $dataset ) ? wl_configuration_get_redlink_dataset_name() : $dataset );
313
+    $redlink_key     = wl_configuration_get_redlink_key();
314 314
 
315
-	// construct the API URL.
316
-	return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/select?key=$redlink_key&out=$output&query=";
315
+    // construct the API URL.
316
+    return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/select?key=$redlink_key&out=$output&query=";
317 317
 
318 318
 }
319 319
 
@@ -326,18 +326,18 @@  discard block
 block discarded – undo
326 326
  */
327 327
 function wl_configuration_get_query_update_url() {
328 328
 
329
-	// If the WordLift Key is set, we use WordLift.
330
-	$key = wl_configuration_get_key();
331
-	if ( ! empty( $key ) ) {
332
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries";
333
-	}
329
+    // If the WordLift Key is set, we use WordLift.
330
+    $key = wl_configuration_get_key();
331
+    if ( ! empty( $key ) ) {
332
+        return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries";
333
+    }
334 334
 
335
-	// get the configuration.
336
-	$redlink_dataset = wl_configuration_get_redlink_dataset_name();
337
-	$redlink_key     = wl_configuration_get_redlink_key();
335
+    // get the configuration.
336
+    $redlink_dataset = wl_configuration_get_redlink_dataset_name();
337
+    $redlink_key     = wl_configuration_get_redlink_key();
338 338
 
339
-	// construct the API URL.
340
-	return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/update?key=$redlink_key";
339
+    // construct the API URL.
340
+    return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/update?key=$redlink_key";
341 341
 
342 342
 }
343 343
 
@@ -351,17 +351,17 @@  discard block
 block discarded – undo
351 351
  */
352 352
 function wl_configuration_get_dataset_index_url() {
353 353
 
354
-	// If the WordLift Key is set, we use WordLift.
355
-	$key = wl_configuration_get_key();
356
-	if ( ! empty( $key ) ) {
357
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/index";
358
-	}
354
+    // If the WordLift Key is set, we use WordLift.
355
+    $key = wl_configuration_get_key();
356
+    if ( ! empty( $key ) ) {
357
+        return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/index";
358
+    }
359 359
 
360
-	// get the configuration.
361
-	$redlink_dataset = wl_configuration_get_redlink_dataset_name();
362
-	$redlink_key     = wl_configuration_get_redlink_key();
360
+    // get the configuration.
361
+    $redlink_dataset = wl_configuration_get_redlink_dataset_name();
362
+    $redlink_key     = wl_configuration_get_redlink_key();
363 363
 
364
-	// construct the API URL.
365
-	return wl_configuration_get_api_url() . "/data/$redlink_dataset/release?key=$redlink_key";
364
+    // construct the API URL.
365
+    return wl_configuration_get_api_url() . "/data/$redlink_dataset/release?key=$redlink_key";
366 366
 
367 367
 }
368 368
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  * @param string $key The setting name.
8 8
  * @param string $value The setting value.
9 9
  */
10
-function wl_configuration_set( $settings, $key, $value ) {
10
+function wl_configuration_set($settings, $key, $value) {
11 11
 
12
-	$options         = get_option( $settings );
13
-	$options         = isset( $options ) ? $options : array();
14
-	$options[ $key ] = $value;
15
-	update_option( $settings, $options );
12
+	$options         = get_option($settings);
13
+	$options         = isset($options) ? $options : array();
14
+	$options[$key] = $value;
15
+	update_option($settings, $options);
16 16
 }
17 17
 
18 18
 
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
  * @return string The configured WordLift key or an empty string.
25 25
  */
26 26
 function wl_configuration_get_key() {
27
-	$options = get_option( 'wl_general_settings' );
27
+	$options = get_option('wl_general_settings');
28 28
 
29
-	if ( isset( $options['key'] ) ) {
29
+	if (isset($options['key'])) {
30 30
 		return $options['key'];
31 31
 	}
32 32
 
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
  *
42 42
  * @param string $value The WordLift key.
43 43
  */
44
-function wl_configuration_set_key( $value ) {
44
+function wl_configuration_set_key($value) {
45 45
 
46
-	wl_configuration_set( 'wl_general_settings', 'key', $value );
46
+	wl_configuration_set('wl_general_settings', 'key', $value);
47 47
 
48 48
 }
49 49
 
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
  */
57 57
 function wl_configuration_get_site_language() {
58 58
 
59
-	$options = get_option( 'wl_general_settings' );
59
+	$options = get_option('wl_general_settings');
60 60
 
61
-	return ( empty( $options['site_language'] ) ? 'en' : $options['site_language'] );
61
+	return (empty($options['site_language']) ? 'en' : $options['site_language']);
62 62
 }
63 63
 
64 64
 /**
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
  *
69 69
  * @param string $value The two-letter language code.
70 70
  */
71
-function wl_configuration_set_site_language( $value ) {
71
+function wl_configuration_set_site_language($value) {
72 72
 
73
-	wl_configuration_set( 'wl_general_settings', 'site_language', $value );
73
+	wl_configuration_set('wl_general_settings', 'site_language', $value);
74 74
 }
75 75
 
76 76
 /**
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
  */
83 83
 function wl_configuration_get_api_url() {
84 84
 
85
-	$options = get_option( 'wl_advanced_settings', '' );
85
+	$options = get_option('wl_advanced_settings', '');
86 86
 
87
-	return ( empty( $options['api_url'] ) ? '' : $options['api_url'] );
87
+	return (empty($options['api_url']) ? '' : $options['api_url']);
88 88
 
89 89
 }
90 90
 
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
  *
96 96
  * @param string $value The API URL.
97 97
  */
98
-function wl_configuration_set_api_url( $value ) {
98
+function wl_configuration_set_api_url($value) {
99 99
 
100
-	wl_configuration_set( 'wl_advanced_settings', 'api_url', $value );
100
+	wl_configuration_set('wl_advanced_settings', 'api_url', $value);
101 101
 }
102 102
 
103 103
 /**
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
  */
110 110
 function wl_configuration_get_redlink_key() {
111 111
 
112
-	$options = get_option( 'wl_advanced_settings', '' );
112
+	$options = get_option('wl_advanced_settings', '');
113 113
 
114
-	return ( empty( $options['redlink_key'] ) ? '' : $options['redlink_key'] );
114
+	return (empty($options['redlink_key']) ? '' : $options['redlink_key']);
115 115
 
116 116
 }
117 117
 
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
  *
123 123
  * @param string $value The Redlink application key.
124 124
  */
125
-function wl_configuration_set_redlink_key( $value ) {
125
+function wl_configuration_set_redlink_key($value) {
126 126
 
127
-	wl_configuration_set( 'wl_advanced_settings', 'redlink_key', $value );
127
+	wl_configuration_set('wl_advanced_settings', 'redlink_key', $value);
128 128
 }
129 129
 
130 130
 /**
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
  */
137 137
 function wl_configuration_get_redlink_user_id() {
138 138
 
139
-	$options = get_option( 'wl_advanced_settings', '' );
139
+	$options = get_option('wl_advanced_settings', '');
140 140
 
141
-	return ( empty( $options['redlink_user_id'] ) ? '' : $options['redlink_user_id'] );
141
+	return (empty($options['redlink_user_id']) ? '' : $options['redlink_user_id']);
142 142
 
143 143
 }
144 144
 
@@ -149,9 +149,9 @@  discard block
 block discarded – undo
149 149
  *
150 150
  * @param string $value The Redlink user id.
151 151
  */
152
-function wl_configuration_set_redlink_user_id( $value ) {
152
+function wl_configuration_set_redlink_user_id($value) {
153 153
 
154
-	wl_configuration_set( 'wl_advanced_settings', 'redlink_user_id', $value );
154
+	wl_configuration_set('wl_advanced_settings', 'redlink_user_id', $value);
155 155
 }
156 156
 
157 157
 /**
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
  */
164 164
 function wl_configuration_get_redlink_dataset_name() {
165 165
 
166
-	$options = get_option( 'wl_advanced_settings', '' );
166
+	$options = get_option('wl_advanced_settings', '');
167 167
 
168
-	return ( empty( $options['redlink_dataset_name'] ) ? '' : $options['redlink_dataset_name'] );
168
+	return (empty($options['redlink_dataset_name']) ? '' : $options['redlink_dataset_name']);
169 169
 }
170 170
 
171 171
 
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
  *
177 177
  * @param string $value The Redlink dataset name.
178 178
  */
179
-function wl_configuration_set_redlink_dataset_name( $value ) {
179
+function wl_configuration_set_redlink_dataset_name($value) {
180 180
 
181
-	wl_configuration_set( 'wl_advanced_settings', 'redlink_dataset_name', $value );
181
+	wl_configuration_set('wl_advanced_settings', 'redlink_dataset_name', $value);
182 182
 }
183 183
 
184 184
 
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
  */
192 192
 function wl_configuration_get_redlink_dataset_uri() {
193 193
 
194
-	$options = get_option( 'wl_advanced_settings', '' );
194
+	$options = get_option('wl_advanced_settings', '');
195 195
 
196
-	return ( empty( $options['redlink_dataset_uri'] ) ? '' : $options['redlink_dataset_uri'] );
196
+	return (empty($options['redlink_dataset_uri']) ? '' : $options['redlink_dataset_uri']);
197 197
 }
198 198
 
199 199
 
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
  *
205 205
  * @param string $value The Redlink dataset URI.
206 206
  */
207
-function wl_configuration_set_redlink_dataset_uri( $value ) {
207
+function wl_configuration_set_redlink_dataset_uri($value) {
208 208
 
209
-	wl_configuration_set( 'wl_advanced_settings', 'redlink_dataset_uri', $value );
209
+	wl_configuration_set('wl_advanced_settings', 'redlink_dataset_uri', $value);
210 210
 }
211 211
 
212 212
 /**
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
  */
219 219
 function wl_configuration_get_redlink_application_name() {
220 220
 
221
-	$options = get_option( 'wl_advanced_settings', '' );
221
+	$options = get_option('wl_advanced_settings', '');
222 222
 
223
-	return ( empty( $options['redlink_application_name'] ) ? '' : $options['redlink_application_name'] );
223
+	return (empty($options['redlink_application_name']) ? '' : $options['redlink_application_name']);
224 224
 }
225 225
 
226 226
 
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
  *
232 232
  * @param string $value The Redlink application name.
233 233
  */
234
-function wl_configuration_set_redlink_application_name( $value ) {
234
+function wl_configuration_set_redlink_application_name($value) {
235 235
 
236
-	wl_configuration_set( 'wl_advanced_settings', 'redlink_application_name', $value );
236
+	wl_configuration_set('wl_advanced_settings', 'redlink_application_name', $value);
237 237
 }
238 238
 
239 239
 /**
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 
253 253
 	// If the WordLift Key is set, we use WordLift.
254 254
 	$key = wl_configuration_get_key();
255
-	if ( ! empty( $key ) ) {
256
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "analyses?key=$key";
255
+	if ( ! empty($key)) {
256
+		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."analyses?key=$key";
257 257
 	}
258 258
 
259 259
 	// Otherwise use Redlink.
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
         vcard:locality = lode:atPlace/gn:name :: xsd:string;
270 270
 EOF;
271 271
 
272
-	return wl_configuration_get_api_url() . "/analysis/$analysis_name/enhance?key=$app_key" .
273
-	       '&enhancer.engines.dereference.ldpath=' . urlencode( $ldpath );
272
+	return wl_configuration_get_api_url()."/analysis/$analysis_name/enhance?key=$app_key".
273
+	       '&enhancer.engines.dereference.ldpath='.urlencode($ldpath);
274 274
 
275 275
 }
276 276
 
@@ -283,9 +283,9 @@  discard block
 block discarded – undo
283 283
  *
284 284
  * @return string The API URI.
285 285
  */
286
-function wl_configuration_get_accounts_by_key_dataset_uri( $key ) {
286
+function wl_configuration_get_accounts_by_key_dataset_uri($key) {
287 287
 
288
-	return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri";
288
+	return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."accounts/key=$key/dataset_uri";
289 289
 }
290 290
 
291 291
 
@@ -299,21 +299,21 @@  discard block
 block discarded – undo
299 299
  *
300 300
  * @return string The URL to call to perform the SELECT query.
301 301
  */
302
-function wl_configuration_get_query_select_url( $output, $dataset = null ) {
302
+function wl_configuration_get_query_select_url($output, $dataset = null) {
303 303
 
304 304
 	// If the WordLift Key is set, we use WordLift.
305 305
 	$key = wl_configuration_get_key();
306
-	if ( ! empty( $key ) ) {
306
+	if ( ! empty($key)) {
307 307
 		// TODO: handle the output format for WordLift.
308
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries?q=";
308
+		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."datasets/key=$key/queries?q=";
309 309
 	}
310 310
 
311 311
 	// If no dataset has been specified then use the default configured, otherwise use the one provided.
312
-	$redlink_dataset = ( empty( $dataset ) ? wl_configuration_get_redlink_dataset_name() : $dataset );
312
+	$redlink_dataset = (empty($dataset) ? wl_configuration_get_redlink_dataset_name() : $dataset);
313 313
 	$redlink_key     = wl_configuration_get_redlink_key();
314 314
 
315 315
 	// construct the API URL.
316
-	return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/select?key=$redlink_key&out=$output&query=";
316
+	return wl_configuration_get_api_url()."/data/$redlink_dataset/sparql/select?key=$redlink_key&out=$output&query=";
317 317
 
318 318
 }
319 319
 
@@ -328,8 +328,8 @@  discard block
 block discarded – undo
328 328
 
329 329
 	// If the WordLift Key is set, we use WordLift.
330 330
 	$key = wl_configuration_get_key();
331
-	if ( ! empty( $key ) ) {
332
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/queries";
331
+	if ( ! empty($key)) {
332
+		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."datasets/key=$key/queries";
333 333
 	}
334 334
 
335 335
 	// get the configuration.
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 	$redlink_key     = wl_configuration_get_redlink_key();
338 338
 
339 339
 	// construct the API URL.
340
-	return wl_configuration_get_api_url() . "/data/$redlink_dataset/sparql/update?key=$redlink_key";
340
+	return wl_configuration_get_api_url()."/data/$redlink_dataset/sparql/update?key=$redlink_key";
341 341
 
342 342
 }
343 343
 
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 
354 354
 	// If the WordLift Key is set, we use WordLift.
355 355
 	$key = wl_configuration_get_key();
356
-	if ( ! empty( $key ) ) {
357
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "datasets/key=$key/index";
356
+	if ( ! empty($key)) {
357
+		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."datasets/key=$key/index";
358 358
 	}
359 359
 
360 360
 	// get the configuration.
@@ -362,6 +362,6 @@  discard block
 block discarded – undo
362 362
 	$redlink_key     = wl_configuration_get_redlink_key();
363 363
 
364 364
 	// construct the API URL.
365
-	return wl_configuration_get_api_url() . "/data/$redlink_dataset/release?key=$redlink_key";
365
+	return wl_configuration_get_api_url()."/data/$redlink_dataset/release?key=$redlink_key";
366 366
 
367 367
 }
368 368
\ No newline at end of file
Please login to merge, or discard this patch.
src/wordlift_content_filter.php 2 patches
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @param string $uri Uri of the entity to search in the post content.
11 11
  */
12 12
 function wl_content_embed_build_regex_from_uri( $uri ) {
13
-	return '|<(\\w+)[^<]* itemid=\"' . esc_attr( $uri ) . '\"[^>]*>([^<]*)<\\/\\1>|i';
13
+    return '|<(\\w+)[^<]* itemid=\"' . esc_attr( $uri ) . '\"[^>]*>([^<]*)<\\/\\1>|i';
14 14
 }
15 15
 
16 16
 /**
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
  */
23 23
 function wl_content_embed_microdata( $content ) {
24 24
 
25
-	// Apply microdata only to single pages.
26
-	/*if ( ! is_single() ) {
25
+    // Apply microdata only to single pages.
26
+    /*if ( ! is_single() ) {
27 27
 		wl_write_log( "wl_content_embed_microdata : is not single" );
28 28
 
29 29
 		return $content;
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 
32 32
 	global $post;
33 33
         */
34
-	return _wl_content_embed_microdata( get_the_ID(), $content );
34
+    return _wl_content_embed_microdata( get_the_ID(), $content );
35 35
 }
36 36
 
37 37
 /**
@@ -44,31 +44,31 @@  discard block
 block discarded – undo
44 44
  */
45 45
 function _wl_content_embed_microdata( $post_id, $content ) {
46 46
 
47
-	// If it is an entity, add its own microdata to the content.
48
-	if ( get_post_type( $post_id ) == Wordlift_Entity_Service::TYPE_NAME ) {
49
-		$own_uri = wl_get_entity_uri( $post_id );
50
-		$content .= '<span itemid="' . $own_uri . '"></span>';
51
-	}
47
+    // If it is an entity, add its own microdata to the content.
48
+    if ( get_post_type( $post_id ) == Wordlift_Entity_Service::TYPE_NAME ) {
49
+        $own_uri = wl_get_entity_uri( $post_id );
50
+        $content .= '<span itemid="' . $own_uri . '"></span>';
51
+    }
52 52
 
53
-	// Now search in the text entity mentions
54
-	$regex   = '/<(\\w+)[^<]* itemid=\"([^"]+)\"[^>]*>([^<]*)<\\/\\1>/i';
55
-	$matches = array();
53
+    // Now search in the text entity mentions
54
+    $regex   = '/<(\\w+)[^<]* itemid=\"([^"]+)\"[^>]*>([^<]*)<\\/\\1>/i';
55
+    $matches = array();
56 56
 
57
-	// Return the content if not item IDs have been found.
58
-	if ( false === preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) {
59
-		return $content;
60
-	}
57
+    // Return the content if not item IDs have been found.
58
+    if ( false === preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) {
59
+        return $content;
60
+    }
61 61
 
62
-	// TODO: Retrieve here just one time entities type structure to avoid multiple queries.
63
-	foreach ( $matches as $match ) {
64
-		$item_id = $match[2];
62
+    // TODO: Retrieve here just one time entities type structure to avoid multiple queries.
63
+    foreach ( $matches as $match ) {
64
+        $item_id = $match[2];
65 65
 
66
-		// wl_write_log( "_wl_content_embed_microdata [ item ID :: $item_id ]" );
66
+        // wl_write_log( "_wl_content_embed_microdata [ item ID :: $item_id ]" );
67 67
 
68
-		$content = wl_content_embed_item_microdata( $content, $item_id );
69
-	}
68
+        $content = wl_content_embed_item_microdata( $content, $item_id );
69
+    }
70 70
 
71
-	return $content;
71
+    return $content;
72 72
 }
73 73
 
74 74
 /**
@@ -82,68 +82,68 @@  discard block
 block discarded – undo
82 82
  */
83 83
 function wl_content_embed_item_microdata( $content, $uri, $itemprop = null, $recursion_level = 0 ) {
84 84
 
85
-	if ( $recursion_level > wl_config_get_recursion_depth() ) {
86
-		wl_write_log( "recursion depth limit exceeded [ level :: $recursion_level ][ max :: " . wl_config_get_recursion_depth() . " ]" );
85
+    if ( $recursion_level > wl_config_get_recursion_depth() ) {
86
+        wl_write_log( "recursion depth limit exceeded [ level :: $recursion_level ][ max :: " . wl_config_get_recursion_depth() . " ]" );
87 87
 
88
-		return '';
89
-	}
88
+        return '';
89
+    }
90 90
 
91
-	$post = wl_get_entity_post_by_uri( $uri );
91
+    $post = wl_get_entity_post_by_uri( $uri );
92 92
 
93
-	// Entity not found or not published. Delete <span> tags but leave their content on page.
94
-	if ( null === $post || $post->post_status !== 'publish' ) {
93
+    // Entity not found or not published. Delete <span> tags but leave their content on page.
94
+    if ( null === $post || $post->post_status !== 'publish' ) {
95 95
 
96
-		// wl_write_log( "wl_content_embed_item_microdata : entity not found or not published [ uri :: $uri ]" );
96
+        // wl_write_log( "wl_content_embed_item_microdata : entity not found or not published [ uri :: $uri ]" );
97 97
 
98
-		// Replace the original tagging with the new tagging.
99
-		$regex   = wl_content_embed_build_regex_from_uri( $uri );
100
-		$content = preg_replace( $regex, '$2', $content );
98
+        // Replace the original tagging with the new tagging.
99
+        $regex   = wl_content_embed_build_regex_from_uri( $uri );
100
+        $content = preg_replace( $regex, '$2', $content );
101 101
 
102
-		return $content;
103
-	}
102
+        return $content;
103
+    }
104 104
 
105
-	// Get the entity URI and its escaped version for the regex.
106
-	$entity_uri = wl_get_entity_uri( $post->ID );
107
-	// Get the main type.
108
-	$main_type = wl_entity_type_taxonomy_get_type( $post->ID );
105
+    // Get the entity URI and its escaped version for the regex.
106
+    $entity_uri = wl_get_entity_uri( $post->ID );
107
+    // Get the main type.
108
+    $main_type = wl_entity_type_taxonomy_get_type( $post->ID );
109 109
 
110
-	// Set the item type if available.
111
-	$item_type = ( null === $main_type ? '' : ' itemtype="' . esc_attr( $main_type['uri'] ) . '"' );
110
+    // Set the item type if available.
111
+    $item_type = ( null === $main_type ? '' : ' itemtype="' . esc_attr( $main_type['uri'] ) . '"' );
112 112
 
113
-	// Define attribute itemprop if this entity is nested.
114
-	if ( ! is_null( $itemprop ) ) {
115
-		$itemprop = ' itemprop="' . $itemprop . '"';
116
-	}
113
+    // Define attribute itemprop if this entity is nested.
114
+    if ( ! is_null( $itemprop ) ) {
115
+        $itemprop = ' itemprop="' . $itemprop . '"';
116
+    }
117 117
 
118
-	// Get additional properties (this may imply a recursion of this method on a sub-entity).
119
-	$additional_properties = wl_content_embed_compile_microdata_template( $post->ID, $main_type, $recursion_level );
118
+    // Get additional properties (this may imply a recursion of this method on a sub-entity).
119
+    $additional_properties = wl_content_embed_compile_microdata_template( $post->ID, $main_type, $recursion_level );
120 120
 
121
-	$same_as = '';
122
-	// Get the array of sameAs uris.
123
-	$same_as_uris = wl_schema_get_value( $post->ID, 'sameAs' );
124
-	// Prepare the sameAs fragment.
125
-	foreach ( $same_as_uris as $same_as_uri ) {
126
-		$same_as .= "<link itemprop=\"sameAs\" href=\"$same_as_uri\">";
127
-	}
121
+    $same_as = '';
122
+    // Get the array of sameAs uris.
123
+    $same_as_uris = wl_schema_get_value( $post->ID, 'sameAs' );
124
+    // Prepare the sameAs fragment.
125
+    foreach ( $same_as_uris as $same_as_uri ) {
126
+        $same_as .= "<link itemprop=\"sameAs\" href=\"$same_as_uri\">";
127
+    }
128 128
 
129
-	// Get the entity URL.
130
-	$permalink = get_permalink( $post->ID );
131
-	$url       = '<link itemprop="url" href="' . $permalink . '" />';
129
+    // Get the entity URL.
130
+    $permalink = get_permalink( $post->ID );
131
+    $url       = '<link itemprop="url" href="' . $permalink . '" />';
132 132
 
133
-	// Replace the original tagging with the new tagging.
134
-	$regex   = wl_content_embed_build_regex_from_uri( $uri );
135
-	$content = preg_replace( $regex,
136
-		'<$1' . $itemprop . ' itemscope' . $item_type . ' itemid="' . esc_attr( $entity_uri ) . '">'
137
-		. $same_as
138
-		. $additional_properties
139
-		. $url
140
-		. '<a class="wl-entity-page-link" href="' . $permalink . '" itemprop="name" content="' . $post->post_title . '">' . ( is_null( $itemprop ) ? '$2' : '' ) . '</a></$1>',    //Only print name inside <span> for top-level entities
141
-		$content
142
-	);
133
+    // Replace the original tagging with the new tagging.
134
+    $regex   = wl_content_embed_build_regex_from_uri( $uri );
135
+    $content = preg_replace( $regex,
136
+        '<$1' . $itemprop . ' itemscope' . $item_type . ' itemid="' . esc_attr( $entity_uri ) . '">'
137
+        . $same_as
138
+        . $additional_properties
139
+        . $url
140
+        . '<a class="wl-entity-page-link" href="' . $permalink . '" itemprop="name" content="' . $post->post_title . '">' . ( is_null( $itemprop ) ? '$2' : '' ) . '</a></$1>',    //Only print name inside <span> for top-level entities
141
+        $content
142
+    );
143 143
 
144
-	// wl_write_log( "wl_content_embed_item_microdata [ uri :: $uri ][ regex :: $regex ]" );
144
+    // wl_write_log( "wl_content_embed_item_microdata [ uri :: $uri ][ regex :: $regex ]" );
145 145
 
146
-	return $content;
146
+    return $content;
147 147
 }
148 148
 
149 149
 add_filter( 'the_content', 'wl_content_embed_microdata' );
@@ -158,93 +158,93 @@  discard block
 block discarded – undo
158 158
  * @return string The content with embedded microdata.
159 159
  */
160 160
 function wl_content_embed_compile_microdata_template( $entity_id, $entity_type, $recursion_level = 0 ) {
161
-	global $wl_logger;
162
-
163
-	if ( WP_DEBUG ) {
164
-		$wl_logger->trace( "Embedding microdata [ entity id :: $entity_id ][ entity type :: " . var_export( $entity_type, true ) . " ][ recursion level :: $recursion_level ]" );
165
-	}
166
-
167
-	$regex   = '/{{(.*?)}}/';
168
-	$matches = array();
169
-
170
-	if ( null === $entity_type ) {
171
-		return '';
172
-	}
173
-
174
-	$template = $entity_type['microdata_template'];
175
-	// Return empty string if template fields have not been found.
176
-	if ( false === preg_match_all( $regex, $template, $matches, PREG_SET_ORDER ) ) {
177
-		return '';
178
-	}
179
-
180
-	foreach ( $matches as $match ) {
181
-
182
-		$placeholder = $match[0];
183
-		$field_name  = $match[1];
184
-
185
-		// Get property value.
186
-		$meta_collection = wl_schema_get_value( $entity_id, $field_name );
187
-
188
-		// If no value is given, just remove the placeholder from the template
189
-		if ( null == $meta_collection ) {
190
-			$template = str_replace( $placeholder, '', $template );
191
-			continue;
192
-		}
193
-
194
-		// What kind of value is it?
195
-		// TODO: Performance issue here: meta type retrieving should be centralized
196
-		$expected_type = wl_get_meta_type( $field_name );
197
-
198
-		if ( WP_DEBUG ) {
199
-			$wl_logger->trace( "Embedding microdata [ placeholder :: $placeholder ][ field name :: $field_name ][ meta collection :: " . ( is_array( $meta_collection ) ? var_export( $meta_collection, true ) : $meta_collection ) . " ][ expected type :: $expected_type ]" );
200
-		}
201
-
202
-		foreach ( $meta_collection as $field_value ) {
203
-
204
-			// Quick and dirty patch for #163:
205
-			//  - only apply to URIs, i.e. to properties pointing to another post ( $field_value should be a post ID ),
206
-			//  - check that $field_value is actually a number,
207
-			//  - check that the referenced post is published.
208
-			//  OR
209
-			//  - if the value is empty then we don't display it.
210
-			if ( Wordlift_Schema_Service::DATA_TYPE_URI === $expected_type && is_numeric( $field_value ) && 'publish' !== ( $post_status = get_post_status( $field_value ) )
211
-			     || empty( $field_value )
212
-			) {
213
-
214
-				if ( WP_DEBUG ) {
215
-					$wl_logger->trace( "Microdata refers to a non-published post [ field value :: $field_value ][ post status :: $post_status ]" );
216
-				}
217
-
218
-				// Remove the placeholder.
219
-				$template = str_replace( $placeholder, '', $template );
220
-				continue;
221
-			}
222
-
223
-			if ( Wordlift_Schema_Service::DATA_TYPE_URI == $expected_type ) {
224
-				// If is a numeric value we assume it is an ID referencing for an internal entity.
225
-				if ( is_numeric( $field_value ) ) {
226
-					// Found id, get uri.
227
-					$field_value = wl_get_entity_uri( $field_value );
228
-				}
229
-				// Just if the linked entity does exist I can go further with template compiling
230
-				$nested_entity = wl_get_entity_post_by_uri( $field_value );
231
-				if ( ! is_null( $nested_entity ) ) {
232
-					$content           = '<span itemid="' . esc_attr( $field_value ) . '">' . $nested_entity->post_title . '</span>';
233
-					$compiled_template = wl_content_embed_item_microdata( $content, $field_value, $field_name, ++ $recursion_level );
234
-					$template          = str_replace( $placeholder, $compiled_template, $template );
235
-				} else {
236
-					$template = str_replace( $placeholder, '', $template );
237
-				}
238
-				continue;
239
-			}
240
-
241
-			// Standard condition: field containing a raw value
242
-			// For non visible test, schema.org dictates to use the *meta* tag.
243
-			// see http://schema.org/docs/gs.html#advanced_missing
244
-			$value    = '<meta itemprop="' . esc_attr( $field_name ) . '" content="' . esc_attr( $field_value ) . '" />';
245
-			$template = str_replace( $placeholder, $value, $template );
246
-		}
247
-	}
248
-
249
-	return $template;
161
+    global $wl_logger;
162
+
163
+    if ( WP_DEBUG ) {
164
+        $wl_logger->trace( "Embedding microdata [ entity id :: $entity_id ][ entity type :: " . var_export( $entity_type, true ) . " ][ recursion level :: $recursion_level ]" );
165
+    }
166
+
167
+    $regex   = '/{{(.*?)}}/';
168
+    $matches = array();
169
+
170
+    if ( null === $entity_type ) {
171
+        return '';
172
+    }
173
+
174
+    $template = $entity_type['microdata_template'];
175
+    // Return empty string if template fields have not been found.
176
+    if ( false === preg_match_all( $regex, $template, $matches, PREG_SET_ORDER ) ) {
177
+        return '';
178
+    }
179
+
180
+    foreach ( $matches as $match ) {
181
+
182
+        $placeholder = $match[0];
183
+        $field_name  = $match[1];
184
+
185
+        // Get property value.
186
+        $meta_collection = wl_schema_get_value( $entity_id, $field_name );
187
+
188
+        // If no value is given, just remove the placeholder from the template
189
+        if ( null == $meta_collection ) {
190
+            $template = str_replace( $placeholder, '', $template );
191
+            continue;
192
+        }
193
+
194
+        // What kind of value is it?
195
+        // TODO: Performance issue here: meta type retrieving should be centralized
196
+        $expected_type = wl_get_meta_type( $field_name );
197
+
198
+        if ( WP_DEBUG ) {
199
+            $wl_logger->trace( "Embedding microdata [ placeholder :: $placeholder ][ field name :: $field_name ][ meta collection :: " . ( is_array( $meta_collection ) ? var_export( $meta_collection, true ) : $meta_collection ) . " ][ expected type :: $expected_type ]" );
200
+        }
201
+
202
+        foreach ( $meta_collection as $field_value ) {
203
+
204
+            // Quick and dirty patch for #163:
205
+            //  - only apply to URIs, i.e. to properties pointing to another post ( $field_value should be a post ID ),
206
+            //  - check that $field_value is actually a number,
207
+            //  - check that the referenced post is published.
208
+            //  OR
209
+            //  - if the value is empty then we don't display it.
210
+            if ( Wordlift_Schema_Service::DATA_TYPE_URI === $expected_type && is_numeric( $field_value ) && 'publish' !== ( $post_status = get_post_status( $field_value ) )
211
+                 || empty( $field_value )
212
+            ) {
213
+
214
+                if ( WP_DEBUG ) {
215
+                    $wl_logger->trace( "Microdata refers to a non-published post [ field value :: $field_value ][ post status :: $post_status ]" );
216
+                }
217
+
218
+                // Remove the placeholder.
219
+                $template = str_replace( $placeholder, '', $template );
220
+                continue;
221
+            }
222
+
223
+            if ( Wordlift_Schema_Service::DATA_TYPE_URI == $expected_type ) {
224
+                // If is a numeric value we assume it is an ID referencing for an internal entity.
225
+                if ( is_numeric( $field_value ) ) {
226
+                    // Found id, get uri.
227
+                    $field_value = wl_get_entity_uri( $field_value );
228
+                }
229
+                // Just if the linked entity does exist I can go further with template compiling
230
+                $nested_entity = wl_get_entity_post_by_uri( $field_value );
231
+                if ( ! is_null( $nested_entity ) ) {
232
+                    $content           = '<span itemid="' . esc_attr( $field_value ) . '">' . $nested_entity->post_title . '</span>';
233
+                    $compiled_template = wl_content_embed_item_microdata( $content, $field_value, $field_name, ++ $recursion_level );
234
+                    $template          = str_replace( $placeholder, $compiled_template, $template );
235
+                } else {
236
+                    $template = str_replace( $placeholder, '', $template );
237
+                }
238
+                continue;
239
+            }
240
+
241
+            // Standard condition: field containing a raw value
242
+            // For non visible test, schema.org dictates to use the *meta* tag.
243
+            // see http://schema.org/docs/gs.html#advanced_missing
244
+            $value    = '<meta itemprop="' . esc_attr( $field_name ) . '" content="' . esc_attr( $field_value ) . '" />';
245
+            $template = str_replace( $placeholder, $value, $template );
246
+        }
247
+    }
248
+
249
+    return $template;
250 250
 }
251 251
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@  discard block
 block discarded – undo
9 9
  *
10 10
  * @param string $uri Uri of the entity to search in the post content.
11 11
  */
12
-function wl_content_embed_build_regex_from_uri( $uri ) {
13
-	return '|<(\\w+)[^<]* itemid=\"' . esc_attr( $uri ) . '\"[^>]*>([^<]*)<\\/\\1>|i';
12
+function wl_content_embed_build_regex_from_uri($uri) {
13
+	return '|<(\\w+)[^<]* itemid=\"'.esc_attr($uri).'\"[^>]*>([^<]*)<\\/\\1>|i';
14 14
 }
15 15
 
16 16
 /**
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  *
21 21
  * @return string The updated post content.
22 22
  */
23
-function wl_content_embed_microdata( $content ) {
23
+function wl_content_embed_microdata($content) {
24 24
 
25 25
 	// Apply microdata only to single pages.
26 26
 	/*if ( ! is_single() ) {
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 
32 32
 	global $post;
33 33
         */
34
-	return _wl_content_embed_microdata( get_the_ID(), $content );
34
+	return _wl_content_embed_microdata(get_the_ID(), $content);
35 35
 }
36 36
 
37 37
 /**
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
  *
43 43
  * @return string The updated post content.
44 44
  */
45
-function _wl_content_embed_microdata( $post_id, $content ) {
45
+function _wl_content_embed_microdata($post_id, $content) {
46 46
 
47 47
 	// If it is an entity, add its own microdata to the content.
48
-	if ( get_post_type( $post_id ) == Wordlift_Entity_Service::TYPE_NAME ) {
49
-		$own_uri = wl_get_entity_uri( $post_id );
50
-		$content .= '<span itemid="' . $own_uri . '"></span>';
48
+	if (get_post_type($post_id) == Wordlift_Entity_Service::TYPE_NAME) {
49
+		$own_uri = wl_get_entity_uri($post_id);
50
+		$content .= '<span itemid="'.$own_uri.'"></span>';
51 51
 	}
52 52
 
53 53
 	// Now search in the text entity mentions
@@ -55,17 +55,17 @@  discard block
 block discarded – undo
55 55
 	$matches = array();
56 56
 
57 57
 	// Return the content if not item IDs have been found.
58
-	if ( false === preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) {
58
+	if (false === preg_match_all($regex, $content, $matches, PREG_SET_ORDER)) {
59 59
 		return $content;
60 60
 	}
61 61
 
62 62
 	// TODO: Retrieve here just one time entities type structure to avoid multiple queries.
63
-	foreach ( $matches as $match ) {
63
+	foreach ($matches as $match) {
64 64
 		$item_id = $match[2];
65 65
 
66 66
 		// wl_write_log( "_wl_content_embed_microdata [ item ID :: $item_id ]" );
67 67
 
68
-		$content = wl_content_embed_item_microdata( $content, $item_id );
68
+		$content = wl_content_embed_item_microdata($content, $item_id);
69 69
 	}
70 70
 
71 71
 	return $content;
@@ -80,64 +80,64 @@  discard block
 block discarded – undo
80 80
  *
81 81
  * @return string The content with embedded microdata.
82 82
  */
83
-function wl_content_embed_item_microdata( $content, $uri, $itemprop = null, $recursion_level = 0 ) {
83
+function wl_content_embed_item_microdata($content, $uri, $itemprop = null, $recursion_level = 0) {
84 84
 
85
-	if ( $recursion_level > wl_config_get_recursion_depth() ) {
86
-		wl_write_log( "recursion depth limit exceeded [ level :: $recursion_level ][ max :: " . wl_config_get_recursion_depth() . " ]" );
85
+	if ($recursion_level > wl_config_get_recursion_depth()) {
86
+		wl_write_log("recursion depth limit exceeded [ level :: $recursion_level ][ max :: ".wl_config_get_recursion_depth()." ]");
87 87
 
88 88
 		return '';
89 89
 	}
90 90
 
91
-	$post = wl_get_entity_post_by_uri( $uri );
91
+	$post = wl_get_entity_post_by_uri($uri);
92 92
 
93 93
 	// Entity not found or not published. Delete <span> tags but leave their content on page.
94
-	if ( null === $post || $post->post_status !== 'publish' ) {
94
+	if (null === $post || $post->post_status !== 'publish') {
95 95
 
96 96
 		// wl_write_log( "wl_content_embed_item_microdata : entity not found or not published [ uri :: $uri ]" );
97 97
 
98 98
 		// Replace the original tagging with the new tagging.
99
-		$regex   = wl_content_embed_build_regex_from_uri( $uri );
100
-		$content = preg_replace( $regex, '$2', $content );
99
+		$regex   = wl_content_embed_build_regex_from_uri($uri);
100
+		$content = preg_replace($regex, '$2', $content);
101 101
 
102 102
 		return $content;
103 103
 	}
104 104
 
105 105
 	// Get the entity URI and its escaped version for the regex.
106
-	$entity_uri = wl_get_entity_uri( $post->ID );
106
+	$entity_uri = wl_get_entity_uri($post->ID);
107 107
 	// Get the main type.
108
-	$main_type = wl_entity_type_taxonomy_get_type( $post->ID );
108
+	$main_type = wl_entity_type_taxonomy_get_type($post->ID);
109 109
 
110 110
 	// Set the item type if available.
111
-	$item_type = ( null === $main_type ? '' : ' itemtype="' . esc_attr( $main_type['uri'] ) . '"' );
111
+	$item_type = (null === $main_type ? '' : ' itemtype="'.esc_attr($main_type['uri']).'"');
112 112
 
113 113
 	// Define attribute itemprop if this entity is nested.
114
-	if ( ! is_null( $itemprop ) ) {
115
-		$itemprop = ' itemprop="' . $itemprop . '"';
114
+	if ( ! is_null($itemprop)) {
115
+		$itemprop = ' itemprop="'.$itemprop.'"';
116 116
 	}
117 117
 
118 118
 	// Get additional properties (this may imply a recursion of this method on a sub-entity).
119
-	$additional_properties = wl_content_embed_compile_microdata_template( $post->ID, $main_type, $recursion_level );
119
+	$additional_properties = wl_content_embed_compile_microdata_template($post->ID, $main_type, $recursion_level);
120 120
 
121 121
 	$same_as = '';
122 122
 	// Get the array of sameAs uris.
123
-	$same_as_uris = wl_schema_get_value( $post->ID, 'sameAs' );
123
+	$same_as_uris = wl_schema_get_value($post->ID, 'sameAs');
124 124
 	// Prepare the sameAs fragment.
125
-	foreach ( $same_as_uris as $same_as_uri ) {
125
+	foreach ($same_as_uris as $same_as_uri) {
126 126
 		$same_as .= "<link itemprop=\"sameAs\" href=\"$same_as_uri\">";
127 127
 	}
128 128
 
129 129
 	// Get the entity URL.
130
-	$permalink = get_permalink( $post->ID );
131
-	$url       = '<link itemprop="url" href="' . $permalink . '" />';
130
+	$permalink = get_permalink($post->ID);
131
+	$url       = '<link itemprop="url" href="'.$permalink.'" />';
132 132
 
133 133
 	// Replace the original tagging with the new tagging.
134
-	$regex   = wl_content_embed_build_regex_from_uri( $uri );
135
-	$content = preg_replace( $regex,
136
-		'<$1' . $itemprop . ' itemscope' . $item_type . ' itemid="' . esc_attr( $entity_uri ) . '">'
134
+	$regex   = wl_content_embed_build_regex_from_uri($uri);
135
+	$content = preg_replace($regex,
136
+		'<$1'.$itemprop.' itemscope'.$item_type.' itemid="'.esc_attr($entity_uri).'">'
137 137
 		. $same_as
138 138
 		. $additional_properties
139 139
 		. $url
140
-		. '<a class="wl-entity-page-link" href="' . $permalink . '" itemprop="name" content="' . $post->post_title . '">' . ( is_null( $itemprop ) ? '$2' : '' ) . '</a></$1>',    //Only print name inside <span> for top-level entities
140
+		. '<a class="wl-entity-page-link" href="'.$permalink.'" itemprop="name" content="'.$post->post_title.'">'.(is_null($itemprop) ? '$2' : '').'</a></$1>', //Only print name inside <span> for top-level entities
141 141
 		$content
142 142
 	);
143 143
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	return $content;
147 147
 }
148 148
 
149
-add_filter( 'the_content', 'wl_content_embed_microdata' );
149
+add_filter('the_content', 'wl_content_embed_microdata');
150 150
 
151 151
 /**
152 152
  * Fills up the microdata_template with entity's values.
@@ -157,49 +157,49 @@  discard block
 block discarded – undo
157 157
  *
158 158
  * @return string The content with embedded microdata.
159 159
  */
160
-function wl_content_embed_compile_microdata_template( $entity_id, $entity_type, $recursion_level = 0 ) {
160
+function wl_content_embed_compile_microdata_template($entity_id, $entity_type, $recursion_level = 0) {
161 161
 	global $wl_logger;
162 162
 
163
-	if ( WP_DEBUG ) {
164
-		$wl_logger->trace( "Embedding microdata [ entity id :: $entity_id ][ entity type :: " . var_export( $entity_type, true ) . " ][ recursion level :: $recursion_level ]" );
163
+	if (WP_DEBUG) {
164
+		$wl_logger->trace("Embedding microdata [ entity id :: $entity_id ][ entity type :: ".var_export($entity_type, true)." ][ recursion level :: $recursion_level ]");
165 165
 	}
166 166
 
167 167
 	$regex   = '/{{(.*?)}}/';
168 168
 	$matches = array();
169 169
 
170
-	if ( null === $entity_type ) {
170
+	if (null === $entity_type) {
171 171
 		return '';
172 172
 	}
173 173
 
174 174
 	$template = $entity_type['microdata_template'];
175 175
 	// Return empty string if template fields have not been found.
176
-	if ( false === preg_match_all( $regex, $template, $matches, PREG_SET_ORDER ) ) {
176
+	if (false === preg_match_all($regex, $template, $matches, PREG_SET_ORDER)) {
177 177
 		return '';
178 178
 	}
179 179
 
180
-	foreach ( $matches as $match ) {
180
+	foreach ($matches as $match) {
181 181
 
182 182
 		$placeholder = $match[0];
183 183
 		$field_name  = $match[1];
184 184
 
185 185
 		// Get property value.
186
-		$meta_collection = wl_schema_get_value( $entity_id, $field_name );
186
+		$meta_collection = wl_schema_get_value($entity_id, $field_name);
187 187
 
188 188
 		// If no value is given, just remove the placeholder from the template
189
-		if ( null == $meta_collection ) {
190
-			$template = str_replace( $placeholder, '', $template );
189
+		if (null == $meta_collection) {
190
+			$template = str_replace($placeholder, '', $template);
191 191
 			continue;
192 192
 		}
193 193
 
194 194
 		// What kind of value is it?
195 195
 		// TODO: Performance issue here: meta type retrieving should be centralized
196
-		$expected_type = wl_get_meta_type( $field_name );
196
+		$expected_type = wl_get_meta_type($field_name);
197 197
 
198
-		if ( WP_DEBUG ) {
199
-			$wl_logger->trace( "Embedding microdata [ placeholder :: $placeholder ][ field name :: $field_name ][ meta collection :: " . ( is_array( $meta_collection ) ? var_export( $meta_collection, true ) : $meta_collection ) . " ][ expected type :: $expected_type ]" );
198
+		if (WP_DEBUG) {
199
+			$wl_logger->trace("Embedding microdata [ placeholder :: $placeholder ][ field name :: $field_name ][ meta collection :: ".(is_array($meta_collection) ? var_export($meta_collection, true) : $meta_collection)." ][ expected type :: $expected_type ]");
200 200
 		}
201 201
 
202
-		foreach ( $meta_collection as $field_value ) {
202
+		foreach ($meta_collection as $field_value) {
203 203
 
204 204
 			// Quick and dirty patch for #163:
205 205
 			//  - only apply to URIs, i.e. to properties pointing to another post ( $field_value should be a post ID ),
@@ -207,33 +207,33 @@  discard block
 block discarded – undo
207 207
 			//  - check that the referenced post is published.
208 208
 			//  OR
209 209
 			//  - if the value is empty then we don't display it.
210
-			if ( Wordlift_Schema_Service::DATA_TYPE_URI === $expected_type && is_numeric( $field_value ) && 'publish' !== ( $post_status = get_post_status( $field_value ) )
211
-			     || empty( $field_value )
210
+			if (Wordlift_Schema_Service::DATA_TYPE_URI === $expected_type && is_numeric($field_value) && 'publish' !== ($post_status = get_post_status($field_value))
211
+			     || empty($field_value)
212 212
 			) {
213 213
 
214
-				if ( WP_DEBUG ) {
215
-					$wl_logger->trace( "Microdata refers to a non-published post [ field value :: $field_value ][ post status :: $post_status ]" );
214
+				if (WP_DEBUG) {
215
+					$wl_logger->trace("Microdata refers to a non-published post [ field value :: $field_value ][ post status :: $post_status ]");
216 216
 				}
217 217
 
218 218
 				// Remove the placeholder.
219
-				$template = str_replace( $placeholder, '', $template );
219
+				$template = str_replace($placeholder, '', $template);
220 220
 				continue;
221 221
 			}
222 222
 
223
-			if ( Wordlift_Schema_Service::DATA_TYPE_URI == $expected_type ) {
223
+			if (Wordlift_Schema_Service::DATA_TYPE_URI == $expected_type) {
224 224
 				// If is a numeric value we assume it is an ID referencing for an internal entity.
225
-				if ( is_numeric( $field_value ) ) {
225
+				if (is_numeric($field_value)) {
226 226
 					// Found id, get uri.
227
-					$field_value = wl_get_entity_uri( $field_value );
227
+					$field_value = wl_get_entity_uri($field_value);
228 228
 				}
229 229
 				// Just if the linked entity does exist I can go further with template compiling
230
-				$nested_entity = wl_get_entity_post_by_uri( $field_value );
231
-				if ( ! is_null( $nested_entity ) ) {
232
-					$content           = '<span itemid="' . esc_attr( $field_value ) . '">' . $nested_entity->post_title . '</span>';
233
-					$compiled_template = wl_content_embed_item_microdata( $content, $field_value, $field_name, ++ $recursion_level );
234
-					$template          = str_replace( $placeholder, $compiled_template, $template );
230
+				$nested_entity = wl_get_entity_post_by_uri($field_value);
231
+				if ( ! is_null($nested_entity)) {
232
+					$content           = '<span itemid="'.esc_attr($field_value).'">'.$nested_entity->post_title.'</span>';
233
+					$compiled_template = wl_content_embed_item_microdata($content, $field_value, $field_name, ++ $recursion_level);
234
+					$template          = str_replace($placeholder, $compiled_template, $template);
235 235
 				} else {
236
-					$template = str_replace( $placeholder, '', $template );
236
+					$template = str_replace($placeholder, '', $template);
237 237
 				}
238 238
 				continue;
239 239
 			}
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 			// Standard condition: field containing a raw value
242 242
 			// For non visible test, schema.org dictates to use the *meta* tag.
243 243
 			// see http://schema.org/docs/gs.html#advanced_missing
244
-			$value    = '<meta itemprop="' . esc_attr( $field_name ) . '" content="' . esc_attr( $field_value ) . '" />';
245
-			$template = str_replace( $placeholder, $value, $template );
244
+			$value    = '<meta itemprop="'.esc_attr($field_name).'" content="'.esc_attr($field_value).'" />';
245
+			$template = str_replace($placeholder, $value, $template);
246 246
 		}
247 247
 	}
248 248
 
Please login to merge, or discard this patch.