PluginProbe ʕ •ᴥ•ʔ
DearFlip – PDF Flipbook, 3D Flipbook, PDF embed, PDF viewer / 2.2.41
DearFlip – PDF Flipbook, 3D Flipbook, PDF embed, PDF viewer v2.2.41
2.4.30 trunk 1.7.16 1.7.35 2.0.86 2.2.32 2.2.39 2.2.41 2.2.47 2.2.54 2.2.55 2.2.56 2.3.24 2.3.32 2.3.52 2.3.53 2.3.54 2.3.55 2.3.57 2.3.74 2.3.75 2.4.20 2.4.27
3d-flipbook-dflip-lite / inc / metaboxes.php
3d-flipbook-dflip-lite / inc Last commit date
index.php 2 years ago metaboxes.php 2 years ago post-type.php 2 years ago settings.php 2 years ago shortcode.php 2 years ago
metaboxes.php
826 lines
1 <?php
2
3 /**
4 * dFlip Metaboxes
5 *
6 * creates, displays and saves metaboxes and their values
7 *
8 * @since 1.0.0
9 *
10 * @package dFlip
11 * @author Deepak Ghimire
12 */
13 class DFlip_Meta_boxes {
14
15 /**
16 * Holds the singleton class object.
17 *
18 * @since 1.0.0
19 *
20 * @var object
21 */
22 public static $instance;
23
24 /**
25 * Holds the base DFlip class object.
26 *
27 * @since 1.0.0
28 *
29 * @var object
30 */
31 public $base;
32
33 /**
34 * Holds the base DFlip class fields.
35 *
36 * @since 1.0.0
37 *
38 * @var object
39 */
40 public $fields;
41
42 /**
43 * Primary class constructor.
44 *
45 * @since 1.0.0
46 */
47 public function __construct() {
48
49 // Load the base class object.
50 $this->base = DFlip::get_instance();
51
52 $this->fields = $this->base->defaults;
53
54 // Load metabox assets.
55 add_action( 'admin_enqueue_scripts', array( $this, 'meta_box_styles_scripts' ) );
56
57 // Load the metabox hooks and filters.
58 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 100 );
59
60 // Add action to save metabox config options.
61 add_action( 'save_post', array( $this, 'save_meta_boxes' ), 10, 2 );
62 }
63
64 /**
65 * Loads styles and scripts for our metaboxes.
66 *
67 * @return null Bail out if not on the proper screen.
68 * @since 1.0.0
69 *
70 */
71 public function meta_box_styles_scripts() {
72
73 global $id, $post;
74
75 if ( isset( get_current_screen()->base ) && 'post' !== get_current_screen()->base ) {
76 return;
77 }
78 if ( isset( get_current_screen()->post_type )
79 && $this->base->plugin_slug !== get_current_screen()->post_type ) {
80 return;
81 }
82
83 // Set the post_id for localization.
84 $post_id = isset( $post->ID ) ? $post->ID : (int) $id;
85
86 // Load necessary metabox styles.
87 wp_register_style( $this->base->plugin_slug . '-metabox-style', plugins_url( '../assets/css/metaboxes.css', __FILE__ ), array(), $this->base->version );
88 wp_enqueue_style( $this->base->plugin_slug . '-metabox-style' );
89 wp_enqueue_style( 'wp-color-picker' );
90
91 // Load necessary metabox scripts.
92 wp_register_script( $this->base->plugin_slug . '-metabox-script', plugins_url( '../assets/js/metaboxes.js', __FILE__ ),
93 array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-resizable', 'wp-color-picker' ), $this->base->version );
94 wp_enqueue_script( $this->base->plugin_slug . '-metabox-script' );
95
96 wp_enqueue_media( array( 'post' => $post_id ) );
97
98 }
99
100 /**
101 * Adds metaboxes for handling settings
102 *
103 * @since 1.0.0
104 */
105 public function add_meta_boxes() {
106 add_meta_box( 'dflip_post_meta_box_support_us', __( 'More Features in FULL VERSION!', '3d-flipbook-dflip-lite' ), array( $this, 'create_meta_boxes_support_us' ), 'dflip', 'normal', 'high' );
107
108 add_meta_box( 'dflip_post_meta_box', __( 'dFlip Settings', '3d-flipbook-dflip-lite' ), array( $this, 'create_meta_boxes' ), 'dflip', 'normal', 'high' );
109
110 add_meta_box( 'dflip_post_meta_box_shortcode', __( 'Shortcode', '3d-flipbook-dflip-lite' ), array( $this, 'create_meta_boxes_shortcode' ), 'dflip', 'side', 'high' );
111
112 add_meta_box( 'dflip_post_meta_box_video', __( 'Useful Links', '3d-flipbook-dflip-lite' ), array( $this, 'create_meta_boxes_video' ), 'dflip', 'side', 'low' );
113
114 }
115
116 /**
117 * Creates metaboxes for shortcode display
118 *
119 * @param object $post The current post object.
120 *
121 * @since 1.2.4
122 *
123 */
124 public function create_meta_boxes_support_us( $post ) {
125 ?>
126 <div class="dflip-notice lite-limits" style="padding:10px;">
127
128 <div>
129 With DearFlip Full version you will have further more possibility of handling flipbooks.
130 <ol>
131 <li> Ability to change settings for all flipbooks</li>
132 <li><strong>PDF LINKS</strong>, translate, analytics, custom share prefix, zoom settings, controls
133 customization, etc.
134 </li>
135 <li><strong>Popup lightboxes for button and custom types</strong></li>
136 <li> And more...</li>
137 </ol>
138 <strong style="text-transform: uppercase;"><a href="https://dearflip.com/go/wp-lite-vs-premium" target="_blank">See
139 Full Comparision</a> | <a href="https://dearflip.com/go/wp-lite-full-version" target="_blank">
140 Get Full Version</a></strong>
141 </div>
142 </div>
143
144 <?php
145
146 }
147
148 /**
149 * Creates metaboxes for shortcode display
150 *
151 * @param object $post The current post object.
152 *
153 * @since 1.2.4
154 *
155 */
156 public function create_meta_boxes_shortcode( $post ) {
157 global $current_screen;
158
159 $postId = $post->ID;
160 $tabs = array(
161 'lightbox' => array(
162 'title' => __( 'LightBox(Popup)', '3d-flipbook-dflip-lite' ),
163 'content' => 'Thumb:<br><code>[dflip id="{id}" type="thumb"][/dflip]</code>'
164 ),
165 'embed' => array(
166 'title' => __( 'Embed', '3d-flipbook-dflip-lite' ),
167 'content' => '<code>[dflip id="{id}" ][/dflip]</code><hr>
168 <a class="df-notice" href="https://wordpress.dearflip.com/docs/multiple-flipbooks-in-a-page/" target="_blank">Not best for multiple viewers in a page.</a>'
169 )
170 );
171
172 if ( $current_screen->post_type == 'dflip' ) {
173 if ( $current_screen->action == 'add' ) {
174 echo "Save Post to generate shortcode.";
175 } else {
176 ?>
177
178 <div class="dflip-tabs normal-tabs">
179 <ul class="dflip-tabs-list">
180 <?php
181 //create tabs
182 $active_set = false;
183 foreach ( (array) $tabs as $id => $tab ) {
184 ?>
185 <li class="dflip-tab <?php echo( $active_set == false ? 'dflip-active' : '' ) ?>">
186 <a href="#dflip-tab-content-<?php echo $id ?>"><?php echo $tab['title'] ?></a></li>
187 <?php $active_set = true;
188 }
189 ?>
190 </ul>
191 <?php
192
193 $active_set = false;
194 foreach ( (array) $tabs as $id => $tab ) {
195 ?>
196 <div id="dflip-tab-content-<?php echo $id ?>"
197 class="dflip-tab-content <?php echo( $active_set == false ? "dflip-active" : "" ) ?>">
198 <?php echo str_replace( "{id}", $postId, $tab['content'] ) ?>
199 <?php $active_set = true; ?>
200 </div>
201 <?php } ?>
202 <br>
203 <a target="_blank" href="https://wordpress.dearflip.com/docs/shortcode-options/">More Shortcode Options</a>
204 </div>
205 <?php
206 }
207 }
208
209 }
210
211
212 /**
213 * Creates metaboxes for video
214 *
215 * @param object $post The current post object.
216 *
217 * @since 1.2.4
218 *
219 */
220 public function create_meta_boxes_video( $post ) {
221 global $current_screen;
222
223 if ( $current_screen->post_type == 'dflip' ) {
224 ?>
225 <ul>
226 <li>
227 <a class="video-tutorial" href="https://dearflip.com/go/wp-lite-video-tutorial" target="_blank"><span
228 class="dashicons dashicons-video-alt3"></span>See Video Tutorial</a>
229 </li>
230 <li>
231 <a class="video-tutorial" href="
232 https://dearflip.com/go/wp-lite-docs" target="_blank"><span class="dashicons dashicons-book"></span>Live
233 Documentation</a>
234 </li>
235 <li>
236 <a class="video-tutorial df-chrome" href="https://chrome.google.com/webstore/detail/pdf-viewer-pdf-flipbook-d/bbbnbmpdkfkndckfmcndgabefnmdedfp/?page=post" target="_blank">FREE Flipbook
237 for Chrome</a>
238 </li>
239 </ul>
240 <?php
241 }
242
243 }
244
245
246 /**
247 * Creates metaboxes for handling settings
248 *
249 * @param object $post The current post object.
250 *
251 * @since 1.0.0
252 *
253 */
254 public function create_meta_boxes( $post ) {
255
256 // Keep security first.
257 wp_nonce_field( $this->base->plugin_slug, $this->base->plugin_slug );
258
259 $tabs = array(
260 'source' => __( 'Source', '3d-flipbook-dflip-lite' ),
261 'layout' => __( 'General/Layout', '3d-flipbook-dflip-lite' ),
262 'flipbook' => __( 'Flipbook', '3d-flipbook-dflip-lite' ),
263 'outline' => __( 'Outline', '3d-flipbook-dflip-lite' )
264 );
265
266 if ( $error = get_transient( "my_save_post_errors_{$post->ID}" ) ) { ?>
267 <div class="info hidden">
268 <p><?php echo esc_attr( $error ); ?></p>
269 </div><?php
270
271 delete_transient( "my_save_post_errors_{$post->ID}" );
272 }
273
274 //create tabs and content
275 ?>
276 <div class="dflip-tabs">
277 <ul class="dflip-tabs-list">
278 <?php
279 //create tabs
280 $active_set = false;
281 foreach ( (array) $tabs as $id => $title ) {
282 ?>
283 <li class="dflip-update-hash dflip-tab <?php echo( $active_set == false ? 'dflip-active' : '' ) ?>">
284 <a href="#dflip-tab-content-<?php echo esc_attr( $id ) ?>"><?php echo esc_attr( $title ) ?></a></li>
285 <?php $active_set = true;
286 }
287 ?>
288 </ul>
289 <?php
290
291 $active_set = false;
292 foreach ( (array) $tabs as $id => $title ) {
293 ?>
294 <div id="dflip-tab-content-<?php echo esc_attr( $id ) ?>"
295 class="dflip-tab-content <?php echo( $active_set == false ? "dflip-active" : "" ) ?>">
296
297 <?php
298 $active_set = true;
299
300 //create content for tab
301 $function = $id . "_tab";
302 call_user_func( array( $this, $function ), $post );
303
304 ?>
305 </div>
306 <?php } ?>
307 </div>
308 <?php
309
310 }
311
312 /**
313 * Creates the UI for Source tab
314 *
315 * @param object $post The current post object.
316 *
317 * @since 1.0.0
318 *
319 */
320 public function source_tab( $post ) {
321
322 $this->create_normal_setting( 'source_type', $post );
323 $this->create_normal_setting( 'pdf_source', $post );
324 $this->create_normal_setting( 'pdf_thumb', $post );
325
326 ?>
327
328 <!--Pages for the book-->
329 <div id="dflip_pages_box" class="df-box hide-on-fail " data-condition="dflip_source_type:is(image)" data-operator="and">
330
331 <label for="dflip_pages" class="dflip-label">
332 <?php echo __( 'Custom Pages', '3d-flipbook-dflip-lite' ); ?>
333 </label>
334
335 <div class="dflip-desc">
336 <?php echo __( 'Add or remove pages as per your requirement. Plus reorder them in the order needed.', '3d-flipbook-dflip-lite' ); ?>
337 </div>
338 <div class="dflip-option dflip-page-list">
339 <a href="javascript:void(0);" class="dflip-page-list-add button button-primary"
340 title="Add New Page">
341 <?php echo __( 'Add New Page', '3d-flipbook-dflip-lite' ); ?>
342 </a>
343 <ul id="dflip_page_list">
344 <?php
345 $page_list = $this->get_config( 'pages', $post );
346 $index = 0;
347 foreach ( (array) $page_list as $page ) {
348
349 /* build the arguments*/
350 $title = isset( $page['title'] ) ? $page['title'] : '';
351 $url = isset( $page['url'] ) ? $page['url'] : '';
352 $content = isset( $page['content'] ) ? $page['content'] : '';
353
354 if ( $url != '' ) {
355 ?>
356 <li class="dflip-page-item">
357 <img class="dflip-page-thumb" src="<?php echo esc_attr( $url ); ?>" alt=""/>
358
359 <div class="dflip-page-options">
360
361 <label for="dflip-page-<?php echo esc_attr( $index ); ?>-title">
362 <?php echo __( 'Title', '3d-flipbook-dflip-lite' ); ?>
363 </label>
364 <input type="text"
365 name="_dflip[pages][<?php echo esc_attr( $index ); ?>][url]"
366 id="dflip-page-<?php echo esc_attr( $index ); ?>-url"
367 value="<?php echo esc_attr( $url ); ?>"
368 class="widefat">
369
370 <label for="dflip-page-<?php echo esc_attr( $index ); ?>-content">
371 <?php echo __( 'Content', '3d-flipbook-dflip-lite' ); ?>
372 </label>
373 <textarea rows="10" cols="40"
374 name="_dflip[pages][<?php echo esc_attr( $index ); ?>][content]"
375 id="dflip-page-<?php echo esc_attr( $index ); ?>-content">
376 <?php echo esc_textarea( $content ); ?>
377 </textarea>
378 <?php
379 if ( isset( $page['hotspots'] ) ) {
380 $spotindex = 0;
381 foreach (
382 (array) $page['hotspots'] as $spot
383 ) {
384 ?>
385 <input class="dflip-hotspot-input"
386 name="_dflip[pages][<?php echo esc_attr( $index ); ?>][hotspots][<?php echo esc_attr( $spotindex ); ?>]"
387 value="<?php echo htmlspecialchars( $spot ); ?>">
388 <?php
389 $spotindex ++;
390 }
391 }
392 ?>
393 </div>
394 </li>
395 <?php
396 }
397 $index ++;
398 } ?>
399 </ul>
400 </div>
401 </div>
402
403 <!--Clear-fix-->
404 <div class="dflip-box"></div>
405 <div class="dflip-support-box" style="padding:10px;line-height:1.7em;">
406 Thank you for using our little flipbook plugin :) We hope it has been useful for you and keeps helping you with
407 your cause.
408 <br>We love supporting and improving our plugin. <strong>You too can <a
409 href="https://wordpress.org/support/plugin/3d-flipbook-dflip-lite/reviews/?filter=5#new-post"
410 target="_blank">SHARE <span
411 style="color:#ffa000; font-size:1.2em;">&#9733;&#9733;&#9733;&#9733;&#9733;</span> REVIEW SUPPORT</a> on
412 WordPress.org!</strong> It would mean a lot to us!
413 </div>
414
415 <?php
416
417 }
418
419 /**
420 * Sanitizes an array value even if not existent
421 *
422 * @param object $arr The array to lookup
423 * @param mixed $key The key to look into array
424 * @param mixed $default Default value in-case value is not found in array
425 *
426 * @return mixed appropriate value if exists else default value
427 * @since 1.0.0
428 *
429 */
430 private function val( $arr, $key, $default = '' ) {
431 return isset( $arr[ $key ] ) ? $arr[ $key ] : $default;
432 }
433
434 private function create_global_setting( $key, $post, $global_key ) {
435 $this->base->create_setting( $key, null, $this->get_config( $key, $post, $global_key ), $global_key, $this->global_config( $key ) );
436
437 }
438
439 private function create_normal_setting( $key, $post ) {
440 $this->base->create_setting( $key, null, $this->get_config( $key, $post ) );
441
442 }
443
444 /**
445 * Creates the UI for layout tab
446 *
447 * @param object $post The current post object.
448 *
449 * @since 1.0.0
450 *
451 */
452 public function layout_tab( $post ) {
453 $this->create_global_setting( 'texture_size', $post, 'global' );
454 $this->base->create_separator( 'Layout' );
455 $this->create_global_setting( 'height', $post, '' );
456 $this->create_global_setting( 'bg_color', $post, '' );
457 $this->create_global_setting( 'bg_image', $post, '' );
458 $this->base->create_separator( 'Controls' );
459 $this->create_global_setting( 'auto_sound', $post, 'global' );
460 $this->create_global_setting( 'enable_download', $post, 'global' );
461 $this->create_global_setting( 'controls_position', $post, 'global' );
462 ?>
463
464 <!--Clear-fix-->
465 <div class="dflip-box"></div>
466 <?php
467
468 }
469
470 public function flipbook_tab( $post ) {
471 $this->create_global_setting( 'webgl', $post, 'global' );
472 $this->create_global_setting( 'hard', $post, 'global' );
473 $this->create_global_setting( 'duration', $post, '' );
474 $this->create_global_setting( 'page_mode', $post, 'global' );
475 $this->create_global_setting( 'single_page_mode', $post, 'global' );
476 $this->create_normal_setting( 'page_size', $post );
477 $this->create_global_setting( 'direction', $post, 'global' );
478
479 $this->base->create_separator( 'Misc' );
480 $this->create_global_setting( 'autoplay', $post, 'global' );
481 $this->create_global_setting( 'autoplay_duration', $post, '' );
482 $this->create_global_setting( 'autoplay_start', $post, 'global' );
483 ?><!--Clear-fix-->
484 <div class="dflip-box"></div>
485 <?php
486 }
487
488
489 /**
490 * Creates the UI for outline tab
491 *
492 * @param object $post The current post object.
493 *
494 * @since 1.0.0
495 *
496 */
497 public function outline_tab( $post ) {
498
499 $this->create_normal_setting( 'auto_outline', $post );
500 $this->create_normal_setting( 'auto_thumbnail', $post );
501 $this->create_normal_setting( 'overwrite_outline', $post );
502 ?>
503
504 <!--Outline/Bookmark-->
505 <div id="dflip_outline_box" class="dflip-box dflip-js-code">
506
507 <div class="dflip-desc">
508 <p>
509 <?php echo sprintf( __( 'Create a tree structure bookmark/outline of your book for easy access:<br>%s', '3d-flipbook-dflip-lite' ),
510 '<code> Outline Name : (destination as blank or link to url or page number)</code>' ); ?>
511 </p>
512 </div>
513
514 <div class="dflip-option dflip-textarea-simple">
515 <script class="df-post-script" type="application/javascript">window.dflip_flipbook_post_outline = <?php echo json_encode( $this->get_config( 'outline', $post ) ); ?></script>
516 </div>
517 </div>
518
519 <!--Clear-fix-->
520 <div class="dflip-box"></div>
521 <?php
522 }
523
524 /**
525 * Helper method for retrieving config values.
526 *
527 * @param string $key The config key to retrieve.
528 * @param object $post The current post object.
529 *
530 * @param null $_default
531 *
532 * @return string Key value on success, empty string on failure.
533 * @since 1.0.0
534 *
535 */
536 public function get_config( $key, $post, $_default = null ) {
537
538 $values = get_post_meta( $post->ID, '_dflip_data', true );
539 $value = isset( $values[ $key ] ) ? $values[ $key ] : '';
540
541 $default = $_default === null ? isset( $this->fields[ $key ] ) ? is_array( $this->fields[ $key ] ) ? isset( $this->fields[ $key ]['std'] ) ? $this->fields[ $key ]['std'] : ''
542 : $this->fields[ $key ] : '' : $_default;
543
544 /* set standard value */
545 if ( $default !== null ) {
546 $value = $this->filter_std_value( $value, $default );
547 }
548
549 return $value;
550
551 }
552
553 /**
554 * Helper function to filter standard option values.
555 *
556 * @param mixed $value Saved string or array value
557 * @param mixed $std Standard string or array value
558 *
559 * @return mixed String or array
560 *
561 * @access public
562 * @since 1.0.0
563 */
564 public function filter_std_value( $value = '', $std = '' ) {
565
566 $std = maybe_unserialize( $std );
567
568 if ( is_array( $value ) && is_array( $std ) ) {
569
570 foreach ( $value as $k => $v ) {
571
572 if ( '' === $value[ $k ] && isset( $std[ $k ] ) ) {
573
574 $value[ $k ] = $std[ $k ];
575
576 }
577
578 }
579
580 } else {
581 if ( '' === $value && $std !== null ) {
582
583 $value = $std;
584
585 }
586 }
587
588 return $value;
589
590 }
591
592 /**
593 * Saves values from dFlip metaboxes.
594 *
595 * @param int $post_id The current post ID.
596 * @param object $post The current post object.
597 *
598 * @since 1.0.0
599 *
600 */
601 public function save_meta_boxes( $post_id, $post ) {
602
603 // Bail out if we fail a security check.
604 if ( !isset( $_POST['dflip'] )
605 || !wp_verify_nonce( $_POST['dflip'], 'dflip' )
606 || !isset( $_POST['_dflip'] ) ) {
607 set_transient( "my_save_post_errors_{$post_id}", "Security Check Failed", 10 );
608
609 return;
610 }
611
612 // Bail out if running an autosave, ajax, cron or revision.
613 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
614 set_transient( "my_save_post_errors_{$post_id}", "Autosave", 10 );
615
616 return;
617 }
618 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
619 set_transient( "my_save_post_errors_{$post_id}", "Ajax", 10 );
620
621 return;
622 }
623 /* if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
624 set_transient("my_save_post_errors_{$post_id}", "Cron", 10);
625 return;
626 }*/
627 if ( wp_is_post_revision( $post_id ) ) {
628 set_transient( "my_save_post_errors_{$post_id}", "revision", 10 );
629
630 return;
631 }
632
633 // Bail if this is not the correct post type.
634 if ( isset( $post->post_type )
635 && $this->base->plugin_slug !== $post->post_type ) {
636 set_transient( "my_save_post_errors_{$post_id}", "Incorrect Post Type", 10 );
637
638 return;
639 }
640
641 // Bail out if user is not authorized
642 if ( !current_user_can( 'edit_post', $post_id ) ) {
643 set_transient( "my_save_post_errors_{$post_id}", "UnAuthorized User", 10 );
644
645 return;
646 }
647
648 // Sanitize all user inputs.
649
650 $sanitized_data = array();
651
652 //Source Tab
653 $sanitized_data['source_type'] = sanitize_text_field( $_POST['_dflip']['source_type'] );
654 $sanitized_data['pdf_source'] = esc_url_raw( $_POST['_dflip']['pdf_source'] );
655 $sanitized_data['pdf_thumb'] = esc_url_raw( $_POST['_dflip']['pdf_thumb'] );
656
657 $page_list = array();
658 if ( is_array( $_POST['_dflip']['pages'] ) ) {
659 foreach ( (array) $_POST['_dflip']['pages'] as $page_key => $page_value ) {
660 $page = array();
661 $page['url'] = isset( $page_value['url'] ) ? esc_url_raw( $page_value['url'] ) : '';
662 $page['hotspots'] = array();
663 if ( isset( $page_value['hotspots'] ) ) {
664 foreach ( (array) $page_value['hotspots'] as $spot_key => $spot_value ) {
665 array_push( $page['hotspots'], sanitize_text_field( $spot_value ) );
666 }
667 }
668 array_push( $page_list, $page );
669 }
670 }
671 $sanitized_data['pages'] = $page_list;
672
673 //Layout tab
674 $sanitized_data['webgl'] = sanitize_text_field( $_POST['_dflip']['webgl'] );
675 $sanitized_data['hard'] = sanitize_text_field( $_POST['_dflip']['hard'] );
676 $sanitized_data['bg_color'] = sanitize_text_field( $_POST['_dflip']['bg_color'] );
677 $sanitized_data['bg_image'] = esc_url_raw( $_POST['_dflip']['bg_image'] );
678 $sanitized_data['duration'] = sanitize_text_field( $_POST['_dflip']['duration'] );
679 $sanitized_data['height'] = sanitize_text_field( $_POST['_dflip']['height'] );
680 $sanitized_data['texture_size'] = sanitize_text_field( $_POST['_dflip']['texture_size'] );
681 $sanitized_data['auto_sound'] = sanitize_text_field( $_POST['_dflip']['auto_sound'] );
682 $sanitized_data['enable_download'] = sanitize_text_field( $_POST['_dflip']['enable_download'] );
683 $sanitized_data['page_mode'] = sanitize_text_field( $_POST['_dflip']['page_mode'] );
684 $sanitized_data['single_page_mode'] = sanitize_text_field( $_POST['_dflip']['single_page_mode'] );
685 $sanitized_data['controls_position'] = sanitize_text_field( $_POST['_dflip']['controls_position'] );
686 $sanitized_data['direction'] = sanitize_text_field( $_POST['_dflip']['direction'] );
687 // $sanitized_data['force_fit'] = sanitize_text_field( $_POST['_dflip']['force_fit'] );
688 $sanitized_data['autoplay'] = sanitize_text_field( $_POST['_dflip']['autoplay'] );
689 $sanitized_data['autoplay_duration'] = sanitize_text_field( $_POST['_dflip']['autoplay_duration'] );
690 $sanitized_data['autoplay_start'] = sanitize_text_field( $_POST['_dflip']['autoplay_start'] );
691 $sanitized_data['page_size'] = sanitize_text_field( $_POST['_dflip']['page_size'] );
692
693 //Outline/sidemenu tab
694 $sanitized_data['auto_outline'] = sanitize_text_field( $_POST['_dflip']['auto_outline'] );
695 $sanitized_data['auto_thumbnail'] = sanitize_text_field( $_POST['_dflip']['auto_thumbnail'] );
696 $sanitized_data['overwrite_outline'] = sanitize_text_field( $_POST['_dflip']['overwrite_outline'] );
697
698 $sanitized_data['outline'] = isset( $_POST['_dflip']['outline'] ) ? $this->array_text_sanitize( $_POST['_dflip']['outline'] ) : array();
699 $sanitized_data['outline'] = $this->array_val($sanitized_data['outline'],'items');
700
701 $settings = get_post_meta( $post_id, '_dflip_data', true );
702 if ( empty( $settings ) ) {
703 $settings = array();
704 }
705 $settings = array_merge( $settings, $sanitized_data );
706
707 //These values are from postObject
708 if ( isset( $post->post_type ) && 'dflip' == $post->post_type ) {
709 if ( empty( $settings['title'] ) ) {
710 $settings['title'] = trim( strip_tags( $post->post_title ) );
711 }
712
713 if ( empty( $settings['slug'] ) ) {
714 $settings['slug'] = sanitize_text_field( $post->post_name );
715 }
716 }
717
718 // Get publish/draft status from Post
719 $settings['status'] = $post->post_status;
720
721 // Update the post meta.
722 update_post_meta( $post_id, '_dflip_data', $settings );
723
724 }
725
726 /**
727 * Sanitizes and returns values of an array. The values should be text only
728 *
729 * @param array Array to be sanitized
730 *
731 * @return array sanitized array
732 * @since 1.0.0
733 *
734 */
735 private function array_text_sanitize( $arr = array() ) {
736
737 if ( is_null( $arr ) ) {
738 return array();
739 }
740
741 foreach ( (array) $arr as $k => $val ) {
742 if ( is_array( $val ) ) {
743 $arr[ $k ] = $this->array_text_sanitize( $val );
744 } else {
745 $arr[ $k ] = sanitize_text_field( $val );
746 }
747 }
748
749 return $arr;
750
751 }
752
753 /**
754 * Removes index of array and returns only values array
755 *
756 * @param array Array to be de-ordered
757 * @param string $scan key index that needs to be de-ordered
758 *
759 * @return array sanitized array
760 * @since 1.0.0
761 *
762 */
763 private function array_val( $arr = array(), $scan = '' ) {
764
765 if ( is_null( $arr ) ) {
766 return array();
767 }
768
769 $_arr = array_values( $arr );
770 if ( $_arr != null && $scan !== '' ) {
771 foreach ( $_arr as &$val ) {
772 if ( is_array( $val ) ) {
773 if ( isset( $val[ $scan ] ) ) {
774 $val[ $scan ] = $this->array_val( $val[ $scan ], $scan );
775 }
776 }
777 }
778 }
779
780 return $_arr;
781
782 }
783
784 /**
785 * Helper method for retrieving global check values.
786 *
787 * @param string $key The config key to retrieve.
788 * @param object $post The current post object.
789 *
790 * @return string Key value on success, empty string on failure.
791 * @since 1.0.0
792 *
793 */
794 public function global_config( $key ) {
795
796 $global_value = $this->base->get_config( $key );
797 $value = isset( $this->fields[ $key ] ) ? is_array( $this->fields[ $key ] ) ? isset( $this->fields[ $key ]['choices'][ $global_value ] ) ? $this->fields[ $key ]['choices'][ $global_value ]
798 : $global_value : $global_value : $global_value;
799
800 return $value;
801
802 }
803
804 /**
805 * Returns the singleton instance of the class.
806 *
807 * @return object dFlip_PostType object.
808 * @since 1.0.0
809 *
810 */
811 public static function get_instance() {
812
813 if ( !isset( self::$instance )
814 && !( self::$instance instanceof DFlip_Meta_Boxes ) ) {
815 self::$instance = new DFlip_Meta_Boxes();
816 }
817
818 return self::$instance;
819
820 }
821 }
822
823 // Load the DFlip_Metaboxes class.
824 $dflip_meta_boxes = DFlip_Meta_Boxes::get_instance();
825
826