PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.2.10
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.2.10
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
← All changes | admin/views/sp-framework/classes/metabox.class.php +108 -174 4.0.8 → 2.2.10 View file →
@@ -1,75 +1,24 @@
1 -<?php
1 +<?php if ( ! defined( 'ABSPATH' ) ) {
2 + die;
3 +} // Cannot access directly.
2 4 /**
3 - * The metabox class of the plugin.
4 5 *
5 - * @package Smart_Post_Show
6 - * @subpackage Smart_Post_Show/views/sp-framework/classes
6 + * Metabox Class
7 + *
8 + * @since 1.0.0
9 + * @version 1.0.0
7 10 */
8 -
9 -if ( ! defined( 'ABSPATH' ) ) {
10 - die;
11 -} // Cannot access directly.
12 -
13 11 if ( ! class_exists( 'SP_PC_Metabox' ) ) {
14 - /**
15 - *
16 - * Metabox Class
17 - *
18 - * @since 1.0.0
19 - * @version 1.0.0
20 - */
21 12 class SP_PC_Metabox extends SP_PC_Abstract {
22 13
23 - /**
24 - * Property.
25 - *
26 - * @var string
27 - */
28 - public $unique = '';
29 - /**
30 - * Properties for metabox.
31 - *
32 - * @var string
33 - */
34 - public $abstract = 'metabox';
35 - /**
36 - * Pre fields property.
37 - *
38 - * @var array
39 - */
14 + // constants.
15 + public $unique = '';
16 + public $abstract = 'metabox';
40 17 public $pre_fields = array();
41 -
42 - /**
43 - * Sections.
44 - *
45 - * @var array
46 - */
47 - public $sections = array();
48 - /**
49 - * Post Types.
50 - *
51 - * @var array
52 - */
53 - public $post_type = array();
54 - /**
55 - * Post Formats.
56 - *
57 - * @var array
58 - */
59 - public $post_formats = array();
60 - /**
61 - * Page templates.
62 - *
63 - * @var array
64 - */
65 - public $page_templates = array();
66 - /**
67 - * Arguments.
68 - *
69 - * @var array
70 - */
71 - public $args = array(
18 + public $sections = array();
19 + public $post_type = array();
20 + public $args = array(
72 21 'title' => '',
73 22 'post_type' => 'post',
74 23 'data_type' => 'serialize',
75 24 'context' => 'advanced',
@@ -113,8 +62,9 @@
113 62 }
114 63
115 64 // wp enqeueu for typography and output css.
116 65 parent::__construct();
66 +
117 67 }
118 68
119 69 /**
120 70 * Instance.
@@ -164,11 +114,9 @@
164 114 $saved_post_format = ( ! empty( $saved_post_format ) ) ? $saved_post_format : 'default';
165 115
166 116 $classes[] = 'spf-post-formats';
167 117
168 - /**
169 - * Sanitize post format for standard to default.
170 - */
118 + // Sanitize post format for standard to default.
171 119 if ( ( $key = array_search( 'standard', $this->post_formats ) ) !== false ) {
172 120 $this->post_formats[ $key ] = 'default';
173 121 }
174 122
@@ -204,8 +152,9 @@
204 152 $classes[] = $this->args['class'];
205 153 }
206 154
207 155 return $classes;
156 +
208 157 }
209 158
210 159 /**
211 160 * Add metabox
@@ -216,16 +165,12 @@
216 165
217 166 if ( ! in_array( $post_type, $this->args['exclude_post_types'] ) ) {
218 167 add_meta_box( $this->unique, $this->args['title'], array( &$this, 'add_meta_box_content' ), $this->post_type, $this->args['context'], $this->args['priority'], $this->args );
219 168 }
169 +
220 170 }
221 171
222 - /**
223 - * Get default value.
224 - *
225 - * @param array $field The field value.
226 - * @return mixed
227 - */
172 + // get default value.
228 173 public function get_default( $field ) {
229 174
230 175 // $default = ( isset( $this->args['defaults'][ $field['id'] ] ) ) ? $this->args['defaults'][ $field['id'] ] : '';
231 176 $default = ( isset( $field['id'] ) && isset( $this->args['defaults'][ $field['id'] ] ) ) ? $this->args['defaults'][ $field['id'] ] : null;
@@ -231,8 +176,9 @@
231 176 $default = ( isset( $field['id'] ) && isset( $this->args['defaults'][ $field['id'] ] ) ) ? $this->args['defaults'][ $field['id'] ] : null;
232 177 $default = ( isset( $field['default'] ) ) ? $field['default'] : $default;
233 178
234 179 return $default;
180 +
235 181 }
236 182
237 183 /**
238 184 * Get meta value.
@@ -247,9 +193,9 @@
247 193 $value = null;
248 194
249 195 if ( is_object( $post ) && ! empty( $field['id'] ) ) {
250 196
251 - if ( 'serialize' !== $this->args['data_type'] ) {
197 + if ( $this->args['data_type'] !== 'serialize' ) {
252 198 $meta = get_post_meta( $post->ID, $field['id'] );
253 199 $value = ( isset( $meta[0] ) ) ? $meta[0] : null;
254 200 } else {
255 201 $meta = get_post_meta( $post->ID, $this->unique, true );
@@ -254,23 +200,22 @@
254 200 } else {
255 201 $meta = get_post_meta( $post->ID, $this->unique, true );
256 202 $value = ( isset( $meta[ $field['id'] ] ) ) ? $meta[ $field['id'] ] : null;
257 203 }
258 - } elseif ( 'tabbed' === $field['type'] ) {
259 - $value = get_post_meta( $post->ID, $this->unique, true );
260 204 }
261 205
262 - $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : '';
206 + $default = $this->get_default( $field );
263 207 $value = ( isset( $value ) ) ? $value : $default;
264 208
265 209 return $value;
210 +
266 211 }
267 212
268 213 /**
269 214 * Add metabox content
270 215 *
271 - * @param object $post The post.
272 - * @param array $callback The callback function.
216 + * @param array $post The post.
217 + * @param array $callback The callback function.
273 218 * @return void
274 219 */
275 220 public function add_meta_box_content( $post, $callback ) {
276 221
@@ -275,14 +220,14 @@
275 220 public function add_meta_box_content( $post, $callback ) {
276 221
277 222 global $post;
278 223
279 - $has_nav = ( count( $this->sections ) > 1 && 'side' !== $this->args['context'] ) ? true : false;
224 + $has_nav = ( count( $this->sections ) > 1 && $this->args['context'] !== 'side' ) ? true : false;
280 225 $show_all = ( ! $has_nav ) ? ' spf-show-all' : '';
281 226 $errors = ( is_object( $post ) ) ? get_post_meta( $post->ID, '_spf_errors', true ) : array();
282 227 $errors = ( ! empty( $errors ) ) ? $errors : array();
283 228 $theme = ( $this->args['theme'] ) ? ' spf-theme-' . $this->args['theme'] : '';
284 - // $class = ( $this->args['class'] ) ? ' ' . $this->args['class'] : '';
229 +//$class = ( $this->args['class'] ) ? ' ' . $this->args['class'] : '';
285 230
286 231 if ( is_object( $post ) && ! empty( $errors ) ) {
287 232 delete_post_meta( $post->ID, '_spf_errors' );
288 233 }
@@ -288,15 +233,15 @@
288 233 }
289 234
290 235 wp_nonce_field( 'spf_pcp_metabox_nonce', 'spf_pcp_metabox_nonce' . $this->unique );
291 236
292 - echo '<div class="spf spf-metabox' . esc_attr( $theme ) . '">';
237 + echo '<div class="spf spf-metabox' . $theme . '">';
293 238
294 - echo '<div class="spf-wrapper' . esc_attr( $show_all ) . '">';
239 + echo '<div class="spf-wrapper' . $show_all . '">';
295 240
296 241 if ( $has_nav ) {
297 242
298 - echo '<div class="spf-nav spf-nav-metabox" data-unique="' . esc_attr( $this->unique ) . '">';
243 + echo '<div class="spf-nav spf-nav-metabox" data-unique="' . $this->unique . '">';
299 244
300 245 echo '<ul>';
301 246 $tab_key = 1;
302 247 foreach ( $this->sections as $section ) {
@@ -301,13 +246,13 @@
301 246 $tab_key = 1;
302 247 foreach ( $this->sections as $section ) {
303 248
304 249 $tab_error = ( ! empty( $errors['sections'][ $tab_key ] ) ) ? '<i class="spf-label-error spf-error">!</i>' : '';
305 - $tab_icon = ( ! empty( $section['icon'] ) ) ? '<i class="spf-icon ' . esc_attr( $section['icon'] ) . '"></i>' : '';
250 + $tab_icon = ( ! empty( $section['icon'] ) ) ? '<i class="spf-icon ' . $section['icon'] . '"></i>' : '';
306 251 // Added li class to hide when needs, -ShapedPlugin.
307 - echo '<li class="menu-item_' . esc_attr( $this->unique ) . '_' . esc_attr( $tab_key ) . '"><a href="#" data-section="' . esc_attr( $this->unique ) . '_' . esc_attr( $tab_key ) . '">' . wp_kses_post( $tab_icon ) . esc_html( $section['title'] ) . esc_html( $tab_error ) . '</a></li>';
252 + echo '<li class="menu-item_' . $this->unique . '_' . $tab_key . '"><a href="#" data-section="' . $this->unique . '_' . $tab_key . '">' . $tab_icon . $section['title'] . $tab_error . '</a></li>';
308 253
309 - ++$tab_key;
254 + $tab_key++;
310 255 }
311 256 echo '</ul>';
312 257
313 258 echo '</div>';
@@ -323,14 +268,14 @@
323 268 foreach ( $this->sections as $section ) {
324 269
325 270 $onload = ( ! $has_nav ) ? ' spf-onload' : '';
326 271
327 - echo '<div id="spf-section-' . esc_attr( $this->unique ) . '_' . esc_attr( $section_key ) . '" class="spf-section' . esc_attr( $onload ) . '">';
272 + echo '<div id="spf-section-' . $this->unique . '_' . $section_key . '" class="spf-section' . $onload . '">';
328 273
329 274 $section_icon = ( ! empty( $section['icon'] ) ) ? '<i class="spf-icon ' . $section['icon'] . '"></i>' : '';
330 275 $section_title = ( ! empty( $section['title'] ) ) ? $section['title'] : '';
331 276
332 - echo ( $section_title || $section_icon ) ? '<div class="spf-section-title"><h3>' . esc_html( $section_icon ) . esc_html( $section_title ) . '</h3></div>' : '';
277 + echo ( $section_title || $section_icon ) ? '<div class="spf-section-title"><h3>' . $section_icon . $section_title . '</h3></div>' : '';
333 278
334 279 if ( ! empty( $section['fields'] ) ) {
335 280
336 281 foreach ( $section['fields'] as $field ) {
@@ -343,19 +288,19 @@
343 288
344 289 }
345 290 } else {
346 291
347 - echo '<div class="spf-no-option spf-text-muted">' . esc_html__( 'No option provided by developer.', 'post-carousel' ) . '</div>';
292 + echo '<div class="spf-no-option spf-text-muted">' . esc_html__( 'No option provided by developer.', 'smart-post-show' ) . '</div>';
348 293
349 294 }
350 295
351 296 echo '</div>';
352 297
353 - ++$section_key;
298 + $section_key++;
354 299 }
355 300
356 301 echo '</div>';
357 - echo '<a class="btn btn-success" id="spsp-show-preview" data-id="' . esc_attr( $post->ID ) . '"href=""><i class="fa fa-eye"></i> Show Preview</a>';
302 +
358 303 echo '<div class="clear"></div>';
359 304
360 305 if ( ! empty( $this->args['show_restore'] ) ) {
361 306
@@ -360,11 +305,11 @@
360 305 if ( ! empty( $this->args['show_restore'] ) ) {
361 306
362 307 echo '<div class="spf-restore-wrapper">';
363 308 echo '<label>';
364 - echo '<input type="checkbox" name="' . esc_attr( $this->unique ) . '[_restore]" />';
365 - echo '<span class="button spf-button-restore">' . esc_html__( 'Restore', 'post-carousel' ) . '</span>';
366 - echo '<span class="button spf-button-cancel">' . sprintf( '<small>( %s )</small> %s', esc_html__( 'update post for restore ', 'post-carousel' ), esc_html__( 'Cancel', 'post-carousel' ) ) . '</span>';
309 + echo '<input type="checkbox" name="' . $this->unique . '[_restore]" />';
310 + echo '<span class="button spf-button-restore">' . esc_html__( 'Restore', 'smart-post-show' ) . '</span>';
311 + echo '<span class="button spf-button-cancel">' . sprintf( '<small>( %s )</small> %s', esc_html__( 'update post for restore ', 'smart-post-show' ), esc_html__( 'Cancel', 'smart-post-show' ) ) . '</span>';
367 312 echo '</label>';
368 313 echo '</div>';
369 314
370 315 }
@@ -377,8 +322,9 @@
377 322
378 323 echo '</div>';
379 324
380 325 echo '</div>';
326 +
381 327 }
382 328
383 329 /**
384 330 * Save metabox.
@@ -387,38 +333,80 @@
387 333 * @return statement
388 334 */
389 335 public function save_meta_box( $post_id ) {
390 336
391 - $count = 1;
392 - $data = array();
393 - $errors = array();
394 - $noncekey = 'spf_pcp_metabox_nonce' . $this->unique;
395 - $nonce = ( ! empty( $_POST[ $noncekey ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ $noncekey ] ) ) : '';
396 - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! wp_verify_nonce( $nonce, 'spf_pcp_metabox_nonce' ) ) {
337 + if ( ! wp_verify_nonce( spf_get_var( 'spf_pcp_metabox_nonce' . $this->unique ), 'spf_pcp_metabox_nonce' ) ) {
397 338 return $post_id;
398 339 }
399 340
400 - // XSS ok.
401 - // No worries, This "POST" requests is sanitizing in the below foreach.
402 - // @codingStandardsIgnoreLine
403 - $request = ( ! empty( $_POST[ $this->unique ] ) ) ? wp_unslash( $_POST[ $this->unique ] ) : array();
341 + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
342 + return $post_id;
343 + }
344 +
345 + $errors = array();
346 + $request = spf_get_var( $this->unique );
347 +
404 348 if ( ! empty( $request ) ) {
349 +
350 + // ignore _nonce.
351 + if ( isset( $request['_nonce'] ) ) {
352 + unset( $request['_nonce'] );
353 + }
354 +
355 + // sanitize and validate.
356 + $section_key = 1;
405 357 foreach ( $this->sections as $section ) {
358 +
406 359 if ( ! empty( $section['fields'] ) ) {
360 +
407 361 foreach ( $section['fields'] as $field ) {
408 - $this->process_field( $field, $request, $count, $data, $errors );
362 +
363 + if ( ! empty( $field['id'] ) ) {
364 +
365 + // sanitize.
366 + if ( ! empty( $field['sanitize'] ) ) {
367 +
368 + $sanitize = $field['sanitize'];
369 + $value_sanitize = isset( $request[ $field['id'] ] ) ? $request[ $field['id'] ] : '';
370 + $request[ $field['id'] ] = call_user_func( $sanitize, $value_sanitize );
371 +
372 + }
373 +
374 + // validate.
375 + if ( ! empty( $field['validate'] ) ) {
376 +
377 + $validate = $field['validate'];
378 + $value_validate = isset( $request[ $field['id'] ] ) ? $request[ $field['id'] ] : '';
379 + $has_validated = call_user_func( $validate, $value_validate );
380 +
381 + if ( ! empty( $has_validated ) ) {
382 +
383 + $errors['sections'][ $section_key ] = true;
384 + $errors['fields'][ $field['id'] ] = $has_validated;
385 + $request[ $field['id'] ] = $this->get_meta_value( $field );
386 +
387 + }
388 + }
389 +
390 + // auto sanitize.
391 + if ( ! isset( $request[ $field['id'] ] ) || is_null( $request[ $field['id'] ] ) ) {
392 + $request[ $field['id'] ] = '';
393 + }
394 + }
409 395 }
410 396 }
411 - ++$count;
397 +
398 + $section_key++;
412 399 }
413 400 }
414 - $data = apply_filters( "spf_{$this->unique}_save", $data, $post_id, $this );
401 + $request = apply_filters( "spf_{$this->unique}_save", $request, $post_id, $this );
415 402
416 - do_action( "spf_{$this->unique}_save_before", $data, $post_id, $this );
403 + do_action( "spf_{$this->unique}_save_before", $request, $post_id, $this );
417 404
418 - if ( empty( $data ) || ! empty( $request['_reset'] ) ) {
419 - if ( 'serialize' !== $this->args['data_type'] ) {
420 - foreach ( $data as $key => $value ) {
405 + if ( empty( $request ) || ! empty( $request['_restore'] ) ) {
406 +
407 + if ( $this->args['data_type'] !== 'serialize' ) {
408 + foreach ( $request as $key => $value ) {
421 409 delete_post_meta( $post_id, $key );
422 410 }
423 411 } else {
424 412 delete_post_meta( $post_id, $this->unique );
@@ -423,78 +411,24 @@
423 411 } else {
424 412 delete_post_meta( $post_id, $this->unique );
425 413 }
426 414 } else {
427 - if ( 'serialize' !== $this->args['data_type'] ) {
428 - foreach ( $data as $key => $value ) {
415 +
416 + if ( $this->args['data_type'] !== 'serialize' ) {
417 + foreach ( $request as $key => $value ) {
429 418 update_post_meta( $post_id, $key, $value );
430 419 }
431 420 } else {
432 - update_post_meta( $post_id, $this->unique, $data );
421 + update_post_meta( $post_id, $this->unique, $request );
433 422 }
423 +
434 424 if ( ! empty( $errors ) ) {
435 - update_post_meta( $post_id, '_spf_errors_' . $this->unique, $errors );
425 + update_post_meta( $post_id, '_spf_errors', $errors );
436 426 }
437 427 }
438 428
439 - do_action( "spf_{$this->unique}_saved", $data, $post_id, $this );
429 + do_action( "spf_{$this->unique}_saved", $request, $post_id, $this );
440 430
441 - do_action( "spf_{$this->unique}_save_after", $data, $post_id, $this );
442 - }
443 -
444 - /**
445 - * Process a field, handling tabbed fields if applicable.
446 - *
447 - * @param array $field The field configuration.
448 - * @param array $request The POST request data.
449 - * @param int $count The count value.
450 - * @param array $data The data array to be populated.
451 - * @param array $errors The errors array to be populated.
452 - */
453 - public function process_field( $field, $request, $count, &$data, &$errors ) {
454 - if ( 'tabbed' === $field['type'] && ! empty( $field['tabs'] ) ) {
455 - foreach ( $field['tabs'] as $tab ) {
456 - if ( ! empty( $tab['fields'] ) ) {
457 - foreach ( $tab['fields'] as $tab_field ) {
458 - $this->process_single_field( $tab_field, $request, $count, $data, $errors );
459 - }
460 - }
461 - }
462 - } else {
463 - $this->process_single_field( $field, $request, $count, $data, $errors );
464 - }
465 - }
466 -
467 - /**
468 - * Process a single field, sanitizing and validating its value.
469 - *
470 - * @param array $field The field configuration.
471 - * @param array $request The POST request data.
472 - * @param int $count The count value.
473 - * @param array $data The data array to be populated.
474 - * @param array $errors The errors array to be populated.
475 - */
476 - public function process_single_field( $field, $request, $count, &$data, &$errors ) {
477 - if ( ! empty( $field['id'] ) && ! ( isset( $field['only_pro'] ) ) ) {
478 - $field_id = $field['id'];
479 - $field_value = isset( $request[ $field_id ] ) ? $request[ $field_id ] : '';
480 - // Sanitize "post" request of field.
481 - if ( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) {
482 - $data[ $field_id ] = call_user_func( $field['sanitize'], $field_value );
483 - } else {
484 - $data[ $field_id ] = ( is_array( $field_value ) ) ? wp_kses_post_deep( $field_value ) : wp_kses_post( $field_value );
485 - }
486 -
487 - // Validate "post" request of field.
488 - if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) {
489 - $has_validated = call_user_func( $field['validate'], $field_value );
490 -
491 - if ( ! empty( $has_validated ) ) {
492 - $errors['sections'][ $count ] = true;
493 - $errors['fields'][ $field_id ] = $has_validated;
494 - $data[ $field_id ] = $this->get_meta_value( $field );
495 - }
496 - }
497 - }
431 + do_action( "spf_{$this->unique}_save_after", $request, $post_id, $this );
498 432 }
499 433 }
500 434 }