PluginProbe
Customify / 1.2.5
Customify v1.2.5
2.10.9 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.7.1 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.0.1 1.6.5 1.7.0 1.7.1 All 77 releases
customify / class-pixcustomify.php

class-pixcustomify.php in Customify 1.2.5, at class-pixcustomify.php

1,814 lines 51.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PixCustomify.
4 * @package PixCustomify
5 * @author Pixelgrade <contact@pixelgrade.com>
6 * @license GPL-2.0+
7 * @link http://pixelgrade.com
8 * @copyright 2014 Pixelgrade
9 */
10
11 /**
12 * Plugin class.
13 * @package PixCustomify
14 * @author Pixelgrade <contact@pixelgrade.com>
15 */
16 class PixCustomifyPlugin {
17
18 /**
19 * Plugin version, used for cache-busting of style and script file references.
20 * @since 1.0.0
21 * @const string
22 */
23 protected $version = '1.2.5';
24 /**
25 * Unique identifier for your plugin.
26 * Use this value (not the variable name) as the text domain when internationalizing strings of text. It should
27 * match the Text Domain file header in the main plugin file.
28 * @since 1.0.0
29 * @var string
30 */
31 protected $plugin_slug = 'customify';
32
33 /**
34 * Instance of this class.
35 * @since 1.0.0
36 * @var object
37 */
38 protected static $instance = null;
39
40 /**
41 * Slug of the plugin screen.
42 * @since 1.0.0
43 * @var string
44 */
45 protected $plugin_screen_hook_suffix = null;
46
47 /**
48 * Path to the plugin.
49 * @since 1.0.0
50 * @var string
51 */
52 protected $plugin_basepath = null;
53
54 public $display_admin_menu = false;
55
56 protected static $config;
57
58 protected static $customizer_config;
59
60 public static $plugin_settings;
61
62 protected static $localized = array();
63
64 protected static $current_values = array();
65
66 protected static $options_list = array();
67
68 protected static $media_queries = array();
69
70 protected static $customizer_values;
71
72 protected static $opt_name;
73
74 protected static $typo_settings;
75
76 protected static $google_fonts = null;
77
78 // these properties will get 'px' as a default unit
79 protected static $pixel_dependent_css_properties = array(
80 'width',
81 'max-width',
82 'min-width',
83
84 'height',
85 'max-height',
86 'min-height',
87
88 'padding',
89 'padding-left',
90 'padding-right',
91 'padding-top',
92 'padding-bottom',
93
94 'margin',
95 'margin-right',
96 'margin-left',
97 'margin-top',
98 'margin-bottom',
99
100 'right',
101 'left',
102 'top',
103 'bottom',
104
105 'font-size',
106 'letter-spacing',
107
108 'border-size',
109 'border-width',
110 'border-bottom-width',
111 'border-left-width',
112 'border-right-width',
113 'border-top-width'
114 );
115
116 /**
117 * Initialize the plugin by setting localization, filters, and administration functions.
118 * @since 1.0.0
119 */
120 protected function __construct() {
121
122 $this->plugin_basepath = plugin_dir_path( __FILE__ );
123 self::$config = self::get_config();
124 self::$plugin_settings = get_option( 'pixcustomify_settings' );
125
126 self::check_for_customizer_values();
127
128 // Load plugin text domain
129 add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
130 add_action( 'wp_loaded', array( $this, 'init_plugin_configs' ), 5 );
131
132 add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) );
133
134 // Add an action link pointing to the options page.
135 $plugin_basename = plugin_basename( plugin_dir_path( __FILE__ ) . 'pixcustomify.php' );
136 add_filter( 'plugin_action_links_' . $plugin_basename, array( $this, 'add_action_links' ) );
137
138
139 // Load admin style sheet and JavaScript.
140 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
141 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
142
143 // add_action( 'plugins_loaded', array( $this, 'register_metaboxes' ), 14 );
144 add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_admin_customizer_styles' ), 10 );
145 add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_admin_customizer_scripts' ), 10 );
146 add_action( 'customize_preview_init', array( $this, 'customizer_live_preview_enqueue_scripts' ), 99999 );
147
148 $load_location = self::get_plugin_option( 'style_resources_location', 'wp_head' );
149
150 add_action( $load_location, array( $this, 'output_dynamic_style' ), 99999 );
151 add_action( 'wp_head', array( $this, 'output_typography_dynamic_style' ), 10 );
152
153 // add things to the previewer
154 // add_action( 'customize_preview_init', array( $this, 'customize_preview_js' ) );
155
156 add_action( 'customize_register', array( $this, 'remove_default_sections' ), 11 );
157 add_action( 'customize_register', array( $this, 'register_customizer' ), 12 );
158
159 if ( self::get_plugin_option( 'enable_editor_style', true ) ) {
160 add_action( 'admin_head', array( $this, 'add_customizer_settings_into_wp_editor' ) );
161 }
162
163 /**
164 * Ajax Callbacks
165 */
166 // add_action( 'wp_ajax_pixcustomify_image_click', array( &$this, 'ajax_click_on_photo' ) );
167 // add_action( 'wp_ajax_nopriv_pixcustomify_image_click', array( &$this, 'ajax_click_on_photo' ) );
168 }
169
170 /**
171 * Return an instance of this class.
172 * @since 1.0.0
173 * @return object A single instance of this class.
174 */
175 public static function get_instance() {
176
177 // If the single instance hasn't been set, set it now.
178 if ( null == self::$instance ) {
179 self::$instance = new self;
180 }
181
182 return self::$instance;
183 }
184
185 /**
186 * Configs, Options and Values methods
187 */
188
189 function init_plugin_configs() {
190 self::$customizer_config = get_option( 'pixcustomify_config' );
191
192 // no option so go for default
193 if ( empty( self::$customizer_config ) ) {
194 self::$customizer_config = self::get_config_option( 'default_options' );
195 }
196
197 if ( empty( self::$customizer_config ) ) {
198 self::$customizer_config = array();
199 }
200
201 // allow themes or other plugins to filter the config
202 self::$customizer_config = apply_filters( 'customify_filter_fields', self::$customizer_config );
203
204 self::$opt_name = self::$localized['options_name'] = self::$customizer_config['opt-name'];
205
206 self::get_current_values();
207 self::$options_list = $this->get_options();
208
209 if ( $this->import_button_exists() ) {
210 self::$opt_name = self::$localized['import_rest_url'] = get_rest_url( '/customify/1.0/' );
211 self::$opt_name = self::$localized['import_rest_nonce'] = wp_create_nonce( 'wp_rest' );
212
213 $this->register_import_api();
214 }
215
216 // load custom modules
217 include_once( self::get_base_path() . '/features/class-CSS_Editor.php' );
218 }
219
220 protected static function check_for_customizer_values() {
221 if ( isset( $_POST['customized'] ) && $_POST['customized'] !== '{}' ) {
222 $the_value = $_POST['customized'];
223 self::$customizer_values = json_decode( $the_value, true );
224
225 /**
226 * if still empty, use stripslashes_deep to ensure compatibility with 5.2
227 * http://stackoverflow.com/questions/28698165/json-data-cannot-be-accessed-in-php-version-5-2-17
228 */
229 if ( empty( self::$customizer_values ) ) {
230 $stripped_value = stripslashes_deep( $the_value );
231 self::$customizer_values = json_decode( $stripped_value, true );
232 }
233 } else {
234 self::$customizer_values = false;
235 }
236 }
237
238 protected static function get_current_values() {
239 $store_type = self::get_plugin_option( 'values_store_mod', 'option' );
240 if ( $store_type === 'option' ) {
241 self::$current_values = get_option( self::$opt_name );
242 } elseif ( $store_type === 'theme_mod' ) {
243 self::$current_values = get_theme_mod( self::$opt_name );
244 }
245 }
246
247 public function get_options() {
248
249 $settings = array();
250
251 if ( isset ( self::$customizer_config['panels'] ) ) {
252
253 foreach ( self::$customizer_config['panels'] as $pane_id => $panel_settings ) {
254
255 if ( isset( $panel_settings['sections'] ) ) {
256 foreach ( $panel_settings['sections'] as $section_id => $section_settings ) {
257 if ( isset( $section_settings['options'] ) ) {
258 foreach ( $section_settings['options'] as $option_id => $option ) {
259 $settings[ $option_id ] = $option;
260 if ( isset( self::$current_values[ $option_id ] ) ) {
261 $settings[ $option_id ]['value'] = self::$current_values[ $option_id ];
262 }
263 }
264 }
265 }
266 }
267 }
268 }
269
270 if ( isset ( self::$customizer_config['sections'] ) ) {
271 foreach ( self::$customizer_config['sections'] as $section_id => $section_settings ) {
272 if ( isset( $section_settings['options'] ) ) {
273 foreach ( $section_settings['options'] as $option_id => $option ) {
274 $settings[ $option_id ] = $option;
275 if ( isset( self::$current_values[ $option_id ] ) ) {
276 $settings[ $option_id ]['value'] = self::$current_values[ $option_id ];
277 }
278 }
279 }
280 }
281 }
282
283 return $settings;
284 }
285
286 protected static function get_value( $option ) {
287
288 if ( isset( self::$customizer_values[ self::$opt_name . '[' . $option . ']' ] ) ) {
289 return self::$customizer_values[ self::$opt_name . '[' . $option . ']' ];
290 }
291
292 if ( strpos( $option, self::$opt_name . '[' ) !== false ) {
293 var_dump( 'this is old and it shouldn\'t be here!' );
294
295 // get only the setting id
296 $option = explode( '[', $option );
297 $option = rtrim( $option[1], ']' );
298 }
299
300 if ( isset( self::$current_values[ $option ] ) ) {
301 return self::$current_values[ $option ];
302 }
303
304 return null;
305 }
306
307 /**
308 * A public function to retreat an option's value
309 * If there is a value and return it
310 * Otherwise try to get the default parameter or the default from config
311 *
312 * @param $option
313 * @param null $default
314 *
315 * @return bool|null|string
316 */
317 static function get_option( $option, $default = null ) {
318
319 $return = self::get_value( $option );
320
321 if ( $return !== null ) {
322 return $return;
323 } elseif ( $default !== null ) {
324 return $default;
325 } elseif ( isset( self::$options_list[ $option ] ) && isset( self::$options_list[ $option ]['default'] ) ) {
326 return self::$options_list[ $option ]['default'];
327 }
328
329 return null;
330 }
331
332 static function has_option( $option ) {
333
334 if ( isset( self::$options_list[ $option ] ) ) {
335 return true;
336 }
337
338 return false;
339 }
340
341 protected static function get_config() {
342 // @TODO maybe check this
343 return include 'plugin-config.php';
344 }
345
346 /**
347 * Get an option's value from the config file
348 *
349 * @param $option
350 * @param null $default
351 *
352 * @return bool|null
353 */
354 public static function get_config_option( $option, $default = null ) {
355
356 if ( isset( self::$config[ $option ] ) ) {
357 return self::$config[ $option ];
358 } elseif ( $default !== null ) {
359 return $default;
360 }
361
362 return false;
363 }
364
365 static function get_plugin_option( $option, $default = null ) {
366
367 if ( isset( self::$plugin_settings[ $option ] ) ) {
368 return self::$plugin_settings[ $option ];
369 } elseif ( $default !== null ) {
370 return $default;
371 }
372
373 return false;
374 }
375
376 /**
377 * Fired when the plugin is activated.
378 * @since 1.0.0
379 *
380 * @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog.
381 */
382 public static function activate( $network_wide ) {
383
384 }
385
386 /**
387 * Fired when the plugin is deactivated.
388 * @since 1.0.0
389 *
390 * @param boolean $network_wide True if WPMU superadmin uses "Network Deactivate" action, false if WPMU is disabled or plugin is deactivated on an individual blog.
391 */
392 static function deactivate( $network_wide ) {
393 // TODO: Define deactivation functionality here
394 }
395
396 /**
397 * Load the plugin text domain for translation.
398 * @since 1.0.0
399 */
400 function load_plugin_textdomain() {
401
402 $domain = $this->plugin_slug;
403 $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
404
405 load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
406 load_plugin_textdomain( $domain, false, basename( dirname( __FILE__ ) ) . '/lang/' );
407 }
408
409 /** === RESOURCES === **/
410
411 /**
412 * Customizer admin styles
413 */
414 function enqueue_admin_customizer_styles() {
415 wp_enqueue_style( 'select2', plugins_url( 'js/select2/select2.css', __FILE__ ), array(), $this->version );
416 wp_enqueue_style( 'customify_style', plugins_url( 'css/customizer.css', __FILE__ ), array(), $this->version );
417 }
418
419 /**
420 * Customizer admin scripts
421 */
422 function enqueue_admin_customizer_scripts() {
423
424 wp_enqueue_script( 'select2', plugins_url( 'js/select2/select2.js', __FILE__ ), array( 'jquery' ), $this->version );
425 wp_enqueue_script( 'jquery-react', plugins_url( 'js/jquery-react.js', __FILE__ ), array( 'jquery' ), $this->version );
426 wp_enqueue_script( $this->plugin_slug . '-customizer-scripts', plugins_url( 'js/customizer.js', __FILE__ ), array(
427 'jquery',
428 'select2',
429 'underscore',
430 ), $this->version );
431
432 wp_localize_script( $this->plugin_slug . '-customizer-scripts', 'customify_settings', self::$localized );
433
434 }
435
436
437 /** Customizer scripts loaded only on previewer page */
438 function customizer_live_preview_enqueue_scripts() {
439
440 wp_register_script( $this->plugin_slug . 'CSSOM', plugins_url( 'js/CSSOM.js', __FILE__ ), array( 'jquery' ), $this->version, true );
441 wp_register_script( $this->plugin_slug . 'cssUpdate', plugins_url( 'js/jquery.cssUpdate.js', __FILE__ ), array(), $this->version, true );
442 wp_enqueue_script( $this->plugin_slug . '-previewer-scripts', plugins_url( 'js/customizer_preview.js', __FILE__ ), array(
443 'jquery',
444 $this->plugin_slug . 'CSSOM',
445 $this->plugin_slug . 'cssUpdate'
446 ), $this->version, true );
447
448 // when a live preview field is in action we need to know which props need 'px' as defaults
449 self::$localized['px_dependent_css_props'] = self::$pixel_dependent_css_properties;
450
451 wp_localize_script( $this->plugin_slug . '-previewer-scripts', 'customify_settings', self::$localized );
452 }
453
454 /**
455 * Add dynamic style only on the previewer page
456 */
457
458 /**
459 * Settings page styles
460 */
461 function enqueue_admin_styles() {
462
463 if ( ! isset( $this->plugin_screen_hook_suffix ) ) {
464 return;
465 }
466
467 $screen = get_current_screen();
468 if ( $screen->id == $this->plugin_screen_hook_suffix ) {
469 wp_enqueue_style( $this->plugin_slug . '-admin-styles', plugins_url( 'css/admin.css', __FILE__ ), array(), $this->version );
470 }
471 }
472
473 /**
474 * Settings page scripts
475 */
476 function enqueue_admin_scripts() {
477
478 if ( ! isset( $this->plugin_screen_hook_suffix ) ) {
479 return;
480 }
481
482 $screen = get_current_screen();
483 if ( $screen->id == $this->plugin_screen_hook_suffix ) {
484 wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ), $this->version );
485 wp_localize_script( $this->plugin_slug . '-admin-script', 'locals', array(
486 'ajax_url' => admin_url( 'admin-ajax.php' )
487 ) );
488 }
489
490
491 wp_localize_script( $this->plugin_slug . '-customizer-scripts', 'WP_API_Settings', array( 'root' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ) ) );
492 }
493
494 /**
495 * Register and enqueue public-facing style sheet.
496 * @since 1.0.0
497 */
498 function enqueue_styles() {
499 // wp_enqueue_style( $this->plugin_slug . '-plugin-styles', plugins_url( 'css/public.css', __FILE__ ), array(), $this->version );
500 }
501
502 /**
503 * Register and enqueues public-facing JavaScript files.
504 * @since 1.0.0
505 */
506 public function enqueue_scripts() {
507 //wp_enqueue_script( $this->plugin_slug . '-plugin-script', plugins_url( 'js/public.js', __FILE__ ), array( 'jquery' ), $this->version, true );
508
509 // quit adding google fonts as a static resource ... we will add it dynamically as a fallback when the typekit library isn't used
510 // wp_enqueue_script( 'google-fonts', '//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js' );
511 }
512
513 /**
514 * Public style generated by customizer
515 */
516 function output_dynamic_style() {
517 $custom_css = "\n";
518
519 foreach ( self::$options_list as $option_id => $option ) {
520
521 if ( isset( $option['css'] ) && ! empty( $option['css'] ) ) {
522 // now process each
523 $custom_css .= $this->convert_setting_to_css( $option_id, $option['css'] );
524 }
525
526 if ( $option['type'] === 'custom_background' ) {
527 $custom_css .= $this->process_custom_background_field_output( $option_id, $option );
528 }
529 }
530
531 if ( ! empty( self::$media_queries ) ) {
532
533 foreach ( self::$media_queries as $media_query => $properties ) {
534
535 if ( empty( $properties ) ) {
536 continue;
537 }
538
539 $custom_css .= '@media ' . $media_query . " {\n";
540
541 foreach ( $properties as $key => $property ) {
542 $property_settings = $property['property'];
543 $property_value = $property['value'];
544 $custom_css .= "\t" . self::proccess_css_property( $property_settings, $property_value );
545 }
546
547 $custom_css .= "\n}\n";
548
549 }
550 }
551
552 $custom_css .= "\n";
553
554 //@todo maybe add a filter to this output ?>
555 <style id="customify_output_style">
556 <?php echo( $custom_css ); ?>
557 </style>
558 <?php
559
560
561 /**
562 * from now on we output only style tags only for the preview purpose
563 * so don't cry if you see 30+ style tags for each section
564 */
565 if ( ! isset( $GLOBALS['wp_customize'] ) ) {
566 return;
567 }
568
569 foreach ( self::$options_list as $option_id => $options ) {
570
571 if ( $options['type'] === 'custom_background' ) {
572 $options['value'] = self::get_option( $option_id );
573 $custom_background_output = $this->process_custom_background_field_output( $option_id, $options ); ?>
574
575 <style id="custom_backgorund_output_for_<?php echo $option_id; ?>">
576 <?php
577 if ( isset( $custom_background_output ) && ! empty( $custom_background_output )) {
578 echo $custom_background_output;
579 } ?>
580 </style>
581 <?php }
582
583 if ( ! isset( $options['live'] ) || $options['live'] !== true ) {
584 continue;
585 }
586
587 $this_value = self::get_option( $option_id );
588 foreach ( $options['css'] as $key => $properties_set ) { ?>
589 <style id="dynamic_setting_<?php echo $option_id . '_property_' . str_replace( '-', '_', $properties_set['property'] ); ?>" type="text/css"><?php
590
591 if ( isset( $properties_set['media'] ) && ! empty( $properties_set['media'] ) ) {
592 echo '@media '. $properties_set['media'] . " {\n";
593 }
594
595 if ( isset( $properties_set['selector'] ) && isset( $properties_set['property'] ) ) {
596 echo self::proccess_css_property($properties_set, $this_value);
597 }
598
599 if ( isset( $properties_set['media'] ) && ! empty( $properties_set['media'] ) ) {
600 echo "}\n";
601 } ?>
602 </style>
603 <?php }
604 }
605
606 if ( ! empty( self::$media_queries ) ) {
607
608 foreach ( self::$media_queries as $media_query => $properties ) {
609
610 if ( empty( $properties ) ) {
611 continue;
612 }
613
614 $display = false;
615 $media_q = '@media ' . $media_query . " {\n";
616
617 foreach ( $properties as $key => $property ) {
618
619 if ( ! isset( $options['live'] ) || $options['live'] !== true ) {
620 continue;
621 }
622
623 $display = true; ?>
624 <style id="dynamic_setting_<?php echo $key; ?>" type="text/css"><?php
625 $property_settings = $property['property'];
626 $property_value = $property['value'];
627 $media_q .= "\t" . self::proccess_css_property( $property_settings, $property_value );?>
628 </style>
629 <?php }
630
631 $media_q .= "\n}\n";
632
633 if ( $display ) {
634 $custom_css .= $media_q;
635 }
636 }
637 }
638 }
639
640 protected function load_google_fonts() {
641
642 $fonts_path = plugin_dir_path( __FILE__ ) . 'features/customizer/controls/resources/google.fonts.php';
643
644 if ( file_exists( $fonts_path ) ) {
645 self::$google_fonts = require( $fonts_path );
646 }
647
648 if ( ! empty( self::$google_fonts ) ) {
649 return self::$google_fonts;
650 }
651
652 return false;
653 }
654
655 function output_typography_dynamic_style() {
656
657 self::get_typography_fields( self::$options_list, 'type', 'typography', self::$typo_settings );
658
659 if ( empty( self::$typo_settings ) ) {
660 return;
661 }
662
663 $families = '';
664
665 foreach ( self::$typo_settings as $id => $font ) {
666 if ( isset ( $font['value'] ) ) {
667
668 $load_all_weights = false;
669
670 if ( isset( $font['load_all_weights'] ) && $font['load_all_weights'] == 'true' ) {
671 $load_all_weights = true;
672 }
673
674 // shim the time when this was an array
675 if ( is_array( $font['value'] ) ) {
676 // $font['value']['font_family'] = $font['value']['font-family'];
677 // unset( $font['value']['font-family'] );
678 //
679 // if ( isset( $font['value']['google'] ) && $font['value']['google'] ) {
680 // $font['value']['type'] = 'google';
681 // unset($font['value']['type']);
682 // }
683 //
684 // foreach ($font['value']['font-options']['variants'] as $variant ) {
685 // $font['value']['variants'][$variant['id']] = $variant['name'];
686 // }
687 //
688 // foreach ($font['value']['font-options']['subsets'] as $subsets ) {
689 // $font['value']['subsets'][$subsets['id']] = $subsets['name'];
690 // }
691 //
692 // unset( $font['value']['font-options'] );
693
694 $font['value'] = stripslashes_deep( $font['value'] );
695 $font['value'] = json_encode( $font['value'] );
696 }
697
698 $value = json_decode( wp_unslash( PixCustomifyPlugin::decodeURIComponent( $font['value'] ) ), true );
699
700 // in case the value is still null, try default value(mostly for google fonts)
701 if ( ! is_array( $value ) || $value === null ) {
702 $value = $this->get_font_defaults_value( str_replace( '"', '', $font['value'] ) );
703 }
704
705 //bail if by this time we don't have a value of some sort
706 if ( empty( $value ) ) {
707 continue;
708 }
709
710 //Handle special logic for when the $value array is not an associative array
711 if ( ! self::is_assoc( $value ) ) {
712 $value = $this->process_a_not_associative_font_default( $value );
713 }
714
715 if ( isset( $value['font_family'] ) && isset( $value['type'] ) && $value['type'] == 'google' ) {
716 $families .= "'" . $value['font_family'];
717
718 if ( $load_all_weights && is_array( $value['variants'] ) ) {
719 $families .= ":" . implode( ',', $value['variants'] );
720 } elseif ( isset( $value['selected_variants'] ) && ! empty( $value['selected_variants'] ) ) {
721 if ( is_array( $value['selected_variants'] ) ) {
722 $families .= ":" . implode( ',', $value['selected_variants'] );
723 } elseif ( is_string( $value['selected_variants'] ) || is_numeric( $value['selected_variants'] ) ) {
724 $families .= ":" . $value['selected_variants'];
725 }
726 } elseif ( isset( $value['variants'] ) && ! empty( $value['variants'] ) ) {
727 if ( is_array( $value['variants'] ) ) {
728 $families .= ":" . implode( ',', $value['variants'] );
729 } else {
730 $families .= ":" . $value['variants'];
731 }
732 }
733
734 if ( isset( $value['selected_subsets'] ) && ! empty( $value['selected_subsets'] ) ) {
735 if ( is_array( $value['selected_subsets'] ) ) {
736 $families .= ":" . implode( ',', $value['selected_subsets'] );
737 } else {
738 $families .= ":" . $value['selected_subsets'];
739 }
740 } elseif ( isset( $value['subsets'] ) && ! empty( $value['subsets'] ) ) {
741 if ( is_array( $value['subsets'] ) ) {
742 $families .= ":" . implode( ',', $value['subsets'] );
743 } else {
744 $families .= ":" . $value['subsets'];
745 }
746 }
747
748 $families .= '\',';
749 }
750 }
751 }
752
753
754 if ( ! empty ( $families ) && self::get_plugin_option( 'typography', '1' ) && self::get_plugin_option( 'typography_google_fonts', 1 ) ) { ?>
755 <script type="text/javascript">
756 if ( typeof WebFont !== 'undefined' ) {<?php // if there is a WebFont object, use it ?>
757 WebFont.load( {
758 google: {families: [<?php echo( rtrim( $families, ',' ) ); ?>]},
759 classes: false,
760 events: false
761 } );
762 } else {<?php // basically when we don't have the WebFont object we create the google script dynamically ?>
763
764 var tk = document.createElement( 'script' );
765 tk.src = '//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
766 tk.type = 'text/javascript';
767
768 tk.onload = tk.onreadystatechange = function() {
769 WebFont.load( {
770 google: {families: [<?php echo( rtrim( $families, ',' ) ); ?>]},
771 classes: false,
772 events: false
773 } );
774 };
775
776 var s = document.getElementsByTagName( 'script' )[0];
777 s.parentNode.insertBefore( tk, s );
778 }
779 </script>
780 <?php } ?>
781 <style id="customify_typography_output_style">
782 <?php
783 foreach ( self::$typo_settings as $key => $font ) {
784 $load_all_weights = false;
785 if ( isset( $font['load_all_weights'] ) && $font['load_all_weights'] == 'true' ) {
786 $load_all_weights = true;
787 }
788
789 if ( isset( $font['selector'] ) && isset( $font['value'] ) && ! empty( $font['value'] ) ) {
790
791 $value = json_decode( PixCustomifyPlugin::decodeURIComponent( $font['value'] ), true );
792 // in case the value is still null, try default value(mostly for google fonts)
793 if ( $value === null ) {
794 $value = $this->get_font_defaults_value( $font['value'] );
795 }
796
797 // shim the old case when the default was only the font name
798 if ( is_string( $value ) && ! empty( $value ) ) {
799 $value = array( 'font_family' => $value );
800 }
801
802 //Handle special logic for when the $value array is not an associative array
803 if ( ! self::is_assoc( $value ) ) {
804 $value = $this->process_a_not_associative_font_default( $value );
805 }
806
807 $selected_variant = '';
808 if ( ! empty( $value['selected_variants'] ) ) {
809 if ( is_array( $value['selected_variants'] ) ) {
810 $selected_variant = $value['selected_variants'][0];
811 } else {
812 $selected_variant = $value['selected_variants'];
813 }
814 }
815
816 // First handle the case where we have the font-family in the selected variant (usually this means a custom font from our Fonto plugin)
817 if ( ! empty( $selected_variant ) && is_array( $selected_variant ) && ! empty( $selected_variant['font-family'] ) ) {
818 //the variant's font-family
819 echo $font['selector'] . " {\nfont-family: " . $selected_variant['font-family'] . ";\n";
820
821 if ( ! $load_all_weights ) {
822 // if this is a custom font (like from our plugin Fonto) with individual styles & weights - i.e. the font-family says it all
823 // we need to "force" the font-weight and font-style
824 if ( ! empty( $value['type'] ) && 'custom_individual' == $value['type'] ) {
825 $selected_variant['font-weight'] = '400 !important';
826 $selected_variant['font-style'] = 'normal !important';
827 }
828
829 // output the font weight, if available
830 if ( ! empty( $selected_variant['font-weight'] ) ) {
831 echo "font-weight: " . $selected_variant['font-weight'] . ";\n";
832 }
833
834 // output the font style, if available
835 if ( ! empty( $selected_variant['font-style'] ) ) {
836 echo "font-style: " . $selected_variant['font-style'] . ";\n";
837 }
838 }
839
840 echo "}\n";
841 } elseif ( isset( $value['font_family'] ) ) {
842 // the selected font family
843 echo $font['selector'] . " {\n font-family: " . $value['font_family'] . ";\n";
844
845 if ( ! empty( $selected_variant ) && ! $load_all_weights ) {
846 $weight_and_style = strtolower( $selected_variant );
847
848 $italic_font = false;
849
850 //determine if this is an italic font (the $weight_and_style is usually like '400' or '400italic' )
851 if ( strpos( $weight_and_style, 'italic' ) !== false ) {
852 $weight_and_style = str_replace( 'italic', '', $weight_and_style);
853 $italic_font = true;
854 }
855
856 if ( ! empty( $weight_and_style ) ) {
857 //a little bit of sanity check - in case it's not a number
858 if( $weight_and_style === 'regular' ) {
859 $weight_and_style = 'normal';
860 }
861 echo "font-weight: " . $weight_and_style . ";\n";
862 }
863
864 if ( $italic_font ) {
865 echo "font-style: italic;\n";
866 }
867 }
868
869 echo "}\n";
870 }
871 }
872 } ?>
873 </style>
874 <?php }
875
876 /**
877 * Handle special logic for when the $value array is not an associative array
878 * Return a new associative array with proper keys
879 */
880 protected function process_a_not_associative_font_default( $value ) {
881
882 $new_value = array();
883
884 //Let's determine some type of font
885 if ( ! isset( $value[2] ) || ( isset( $value[2] ) && 'google' == $value[2] ) ) {
886 $new_value = $this->get_font_defaults_value( $value[0] );
887 } else {
888 $new_value['type'] = $value[2];
889 }
890
891 if ( null == $new_value ) {
892 $new_value = array();
893 }
894
895 //The first entry is the font-family
896 if ( isset( $value[0] ) ) {
897 $new_value['font_family'] = $value[0];
898 }
899
900 //In case we don't have an associative array
901 //The second entry is the variants
902 if ( isset( $value[1] ) ) {
903 $new_value['selected_variants'] = $value[1];
904 }
905
906 return $new_value;
907 }
908
909 /**
910 *
911 * @param $font_name
912 *
913 * @return null
914 */
915 protected function get_font_defaults_value( $font_name ) {
916
917 if ( empty( self::$google_fonts ) ) {
918 $this->load_google_fonts();
919 }
920
921 if ( isset( self::$google_fonts[ $font_name ] ) ) {
922 $value = self::$google_fonts[ $font_name ];
923 $value['font_family'] = $font_name;
924 $value['type'] = 'google';
925
926 return $value;
927 }
928
929 return null;
930 }
931
932 /**
933 * Turn css options into a valid CSS output
934 *
935 * @param $option_id
936 * @param array $css_config
937 *
938 * @return string
939 */
940 protected function convert_setting_to_css( $option_id, $css_config = array() ) {
941 $output = '';
942
943 $this_value = self::get_option( $option_id );
944
945 if ( empty( $css_config ) ) {
946 return $output;
947 }
948
949 foreach ( $css_config as $css_property ) {
950
951 if ( isset( $css_property['media'] ) && ! empty( $css_property['media'] ) ) {
952 self::$media_queries[ $css_property['media'] ][ $option_id ] = array(
953 'property' => $css_property,
954 'value' => $this_value
955 );
956 continue;
957 }
958
959 if ( ! isset( $css_property['selector'] ) || isset( $css_property['property'] ) ) {
960 $output .= self::proccess_css_property( $css_property, $this_value );
961 }
962 }
963
964 return $output;
965 }
966
967 protected function proccess_css_property( $css_property, $this_value ) {
968 $unit = '';
969
970 if ( isset( $css_property['unit'] ) ) {
971 $unit = $css_property['unit'];
972 }
973
974 // if the unit isn't specified but the property should have a unit force 'px' as it
975 if ( empty( $unit ) && in_array( $css_property['property'], self::$pixel_dependent_css_properties ) ) {
976 $unit = 'px';
977 }
978
979 $this_property_output = $css_property['selector'] . ' { ' . $css_property['property'] . ': ' . $this_value . $unit . "; } \n";
980
981 if ( isset( $css_property['callback_filter'] ) && function_exists( $css_property['callback_filter'] ) ) {
982 $this_property_output = call_user_func( $css_property['callback_filter'], $this_value, $css_property['selector'], $css_property['property'], $unit );
983 }
984
985 return $this_property_output;
986 }
987
988 protected function process_custom_background_field_output( $option_id, $options ) {
989 $selector = '';
990
991 if ( ! isset( $options['value'] ) ) {
992 return false;
993 }
994 $value = $options['value'];
995
996 if ( ! isset( $options['output'] ) ) {
997 return $selector;
998 } elseif ( is_string( $options['output'] ) ) {
999 $selector = $options['output'];
1000 } elseif ( is_array( $options['output'] ) ) {
1001 $selector = implode( ' ', $options['output'] );
1002 }
1003 ob_start();
1004
1005 echo "\n" . $selector . " { \n";
1006 if ( isset( $value['background-image'] ) && ! empty( $value['background-image'] ) ) {
1007 echo "background-image: url( " . $value['background-image'] . ");\n";
1008 } else {
1009 echo "background-image: none;\n";
1010 }
1011
1012 if ( isset( $value['background-repeat'] ) && ! empty( $value['background-repeat'] ) ) {
1013 echo "background-repeat:" . $value['background-repeat'] . ";\n";
1014 }
1015
1016 if ( isset( $value['background-position'] ) && ! empty( $value['background-position'] ) ) {
1017 echo "background-position:" . $value['background-position'] . ";\n";
1018 }
1019
1020 if ( isset( $value['background-size'] ) && ! empty( $value['background-size'] ) ) {
1021 echo "background-size:" . $value['background-size'] . ";\n";
1022 }
1023
1024 if ( isset( $value['background-attachment'] ) && ! empty( $value['background-attachment'] ) ) {
1025 echo "background-attachment:" . $value['background-attachment'] . ";\n";
1026 }
1027 echo "\n}\n";
1028
1029 return ob_get_clean();
1030 }
1031
1032 // addd editor style
1033
1034 /**
1035 * add our customizer styling edits into the wp_editor
1036 */
1037 function add_customizer_settings_into_wp_editor() {
1038
1039 ob_start();
1040 $this->output_typography_dynamic_style();
1041 $this->output_dynamic_style();
1042
1043 $custom_css = ob_get_clean(); ?>
1044 <script type="text/javascript">
1045 /* <![CDATA[ */
1046 (function( $ ) {
1047 $( window ).load( function() {
1048 /**
1049 * @param iframe_id the id of the frame you whant to append the style
1050 * @param style_element the style element you want to append
1051 */
1052 var append_script_to_iframe = function( ifrm_id, scriptEl ) {
1053 var myIframe = document.getElementById( ifrm_id );
1054
1055 var script = myIframe.contentWindow.document.createElement( "script" );
1056 script.type = "text/javascript";
1057 script.innerHTML = scriptEl.innerHTML;
1058
1059 myIframe.contentWindow.document.head.appendChild( script );
1060 };
1061
1062 var append_style_to_iframe = function( ifrm_id, styleElment ) {
1063 var ifrm = window.frames[ifrm_id];
1064 ifrm = ( ifrm.contentDocument || ifrm.contentDocument || ifrm.document );
1065 var head = ifrm.getElementsByTagName( 'head' )[0];
1066
1067 if ( typeof styleElment !== "undefined" ) {
1068 head.appendChild( styleElment );
1069 }
1070 };
1071
1072 var xmlString = <?php echo json_encode( str_replace( "\n", "", $custom_css ) ); ?>,
1073 parser = new DOMParser(),
1074 doc = parser.parseFromString( xmlString, "text/html" );
1075
1076 if ( typeof window.frames['content_ifr'] !== 'undefined' ) {
1077
1078 $.each( doc.head.childNodes, function( key, el ) {
1079
1080 if ( typeof el !== "undefined" && typeof el.tagName !== "undefined" ) {
1081
1082 switch ( el.tagName ) {
1083
1084 case 'STYLE' :
1085 append_style_to_iframe( 'content_ifr', el );
1086 break;
1087
1088 case 'SCRIPT' :
1089 append_script_to_iframe( 'content_ifr', el );
1090 break;
1091 default:
1092 break;
1093 }
1094 }
1095 } );
1096 }
1097 } );
1098 })( jQuery );
1099 /* ]]> */
1100 </script>
1101 <?php }
1102
1103 /**
1104 * Register the administration menu for this plugin into the WordPress Dashboard menu.
1105 */
1106 function add_plugin_admin_menu() {
1107 $this->plugin_screen_hook_suffix = add_options_page( __( 'Customify', $this->plugin_slug ), __( 'Customify', $this->plugin_slug ), 'edit_plugins', $this->plugin_slug, array(
1108 $this,
1109 'display_plugin_admin_page'
1110 ) );
1111 }
1112
1113 /**
1114 * Render the settings page for this plugin.
1115 */
1116 function display_plugin_admin_page() {
1117 include_once( 'views/admin.php' );
1118 }
1119
1120 /**
1121 * Add settings action link to the plugins page.
1122 */
1123 function add_action_links( $links ) {
1124 return array_merge( array( 'settings' => '<a href="' . admin_url( 'options-general.php?page=pixcustomify' ) . '">' . __( 'Settings', $this->plugin_slug ) . '</a>' ), $links );
1125 }
1126
1127 protected function register_customizer_controls() {
1128
1129 // first get the base customizer extend class
1130 require_once( self::get_base_path() . '/features/customizer/class-Pix_Customize_Control.php' );
1131
1132 // now get all the controls
1133 $path = self::get_base_path() . '/features/customizer/controls/';
1134 pixcustomify::require_all( $path );
1135 }
1136
1137 function register_customizer( $wp_customize ) {
1138
1139 $this->register_customizer_controls();
1140
1141 $customizer_settings = self::$customizer_config;
1142
1143 if ( ! empty ( $customizer_settings ) ) {
1144
1145 // first check the very needed options name
1146 if ( ! isset ( $customizer_settings['opt-name'] ) || empty( $customizer_settings['opt-name'] ) ) {
1147 return;
1148 }
1149 $options_name = $customizer_settings['opt-name'];
1150 $wp_customize->options_key = $options_name;
1151
1152 // let's check if we have sections or panels
1153 if ( isset( $customizer_settings['panels'] ) && ! empty( $customizer_settings['panels'] ) ) {
1154
1155 foreach ( $customizer_settings['panels'] as $panel_id => $panel_settings ) {
1156
1157 if ( ! empty( $panel_id ) && isset( $panel_settings['sections'] ) && ! empty( $panel_settings['sections'] ) ) {
1158
1159 $panel_id = $options_name . '[' . $panel_id . ']';
1160 $panel_args = array(
1161 'priority' => 10,
1162 'capability' => 'edit_theme_options',
1163 'title' => __( 'Panel title is required', 'textdomain' ),
1164 'description' => __( 'Description of what this panel does.', 'textdomain' ),
1165 );
1166
1167 if ( isset( $panel_settings['priority'] ) && ! empty( $panel_settings['priority'] ) ) {
1168 $panel_args['priority'] = $panel_settings['priority'];
1169 }
1170
1171 if ( isset( $panel_settings['title'] ) && ! empty( $panel_settings['title'] ) ) {
1172 $panel_args['title'] = $panel_settings['title'];
1173 }
1174
1175 if ( isset( $panel_settings['description'] ) && ! empty( $panel_settings['description'] ) ) {
1176 $panel_args[10] = $panel_settings['description'];
1177 }
1178
1179 $wp_customize->add_panel( $panel_id, $panel_args );
1180
1181 foreach ( $panel_settings['sections'] as $section_id => $section_settings ) {
1182 if ( ! empty( $section_id ) && isset( $section_settings['options'] ) && ! empty( $section_settings['options'] ) ) {
1183 $this->register_section( $panel_id, $section_id, $options_name, $section_settings, $wp_customize );
1184 }
1185 }
1186 }
1187 }
1188 }
1189
1190 if ( isset( $customizer_settings['sections'] ) && ! empty( $customizer_settings['sections'] ) ) {
1191
1192 foreach ( $customizer_settings['sections'] as $section_id => $section_settings ) {
1193 if ( ! empty( $section_id ) && isset( $section_settings['options'] ) && ! empty( $section_settings['options'] ) ) {
1194 $this->register_section( $panel_id = false, $section_id, $options_name, $section_settings, $wp_customize );
1195 }
1196 }
1197 }
1198
1199 if ( self::$plugin_settings['enable_reset_buttons'] ) {
1200 // create a toolbar section which will be present all the time
1201 $reset_section_settings = array(
1202 'title' => 'Customify toolbar',
1203 'options' => array(
1204 'reset_all_button' => array(
1205 'type' => 'button',
1206 'label' => 'Reset Customify',
1207 'action' => 'reset_customify',
1208 'value' => 'Reset'
1209 ),
1210 )
1211 );
1212
1213 $wp_customize->add_section(
1214 'customify_toolbar',
1215 array(
1216 'title' => '',
1217 'priority' => 999999999
1218 )
1219 );
1220
1221 $wp_customize->add_setting(
1222 'reset_customify',
1223 array()
1224 );
1225 $wp_customize->add_control( new Pix_Customize_Button_Control(
1226 $wp_customize,
1227 'reset_customify',
1228 array(
1229 'label' => __( 'Reset Customify to Defaults', 'customify_txtd' ),
1230 'section' => 'customify_toolbar',
1231 'settings' => 'reset_customify',
1232 'action' => 'reset_customify',
1233 )
1234 ) );
1235 }
1236
1237 // register typekit options
1238 if ( isset( $customizer_settings['typekit_options'] ) ) {
1239
1240 // create a toolbar section which will be present all the time
1241 $reset_section_settings = array(
1242 'title' => 'Customify Typekit Options',
1243 'capability' => 'manage_options',
1244 'options' => array(
1245 'typkit_user' => array(
1246 'type' => 'text',
1247 'label' => 'Typekit Username',
1248 ),
1249 'typkit_password' => array(
1250 'type' => 'text',
1251 'label' => 'Typekit Username',
1252 ),
1253 )
1254 );
1255 }
1256 }
1257
1258 do_action( 'customify_create_custom_control', $wp_customize );
1259 }
1260
1261 protected function register_section( $panel_id, $section_key, $options_name, $section_settings, $wp_customize ) {
1262
1263 if ( isset( self::$plugin_settings['disable_customify_sections'] ) && isset( self::$plugin_settings['disable_customify_sections'][ $section_key ] ) ) {
1264 return;
1265 }
1266
1267 $section_args = array(
1268 'priority' => 10,
1269 'capability' => 'edit_theme_options',
1270 'title' => __( 'Title Section is required', 'textdomain' ),
1271 'panel' => $panel_id,
1272 );
1273 $section_id = $options_name . '[' . $section_key . ']';
1274
1275 if ( isset( $section_settings['priority'] ) && ! empty( $section_settings['priority'] ) ) {
1276 $section_args['priority'] = $section_settings['priority'];
1277 }
1278
1279 if ( isset( $section_settings['title'] ) && ! empty( $section_settings['title'] ) ) {
1280 $section_args['title'] = $section_settings['title'];
1281 }
1282
1283 if ( isset( $section_settings['theme_supports'] ) && ! empty( $section_settings['theme_supports'] ) ) {
1284 $section_args['theme_supports'] = $section_settings['theme_supports'];
1285 }
1286
1287 if ( isset( $section_settings['description'] ) && ! empty( $section_settings['description'] ) ) {
1288 $section_args['description'] = $section_settings['description'];
1289 }
1290
1291 $wp_customize->add_section( $section_id, $section_args );
1292
1293 foreach ( $section_settings['options'] as $option_id => $option_config ) {
1294
1295 if ( empty( $option_id ) || ! isset( $option_config['type'] ) ) {
1296 continue;
1297 }
1298
1299 $option_id = $options_name . '[' . $option_id . ']';
1300
1301 $this->register_field( $section_id, $option_id, $option_config, $wp_customize );
1302 }
1303
1304 }
1305
1306 protected function register_field( $section_id, $setting_id, $setting_config, $wp_customize ) {
1307
1308 $add_control = true;
1309 // defaults
1310 $setting_args = array(
1311 'default' => '',
1312 'capability' => 'edit_theme_options',
1313 'transport' => 'refresh',
1314 );
1315 $control_args = array(
1316 'label' => '',
1317 'section' => $section_id,
1318 'settings' => $setting_id,
1319 );
1320
1321 self::$localized['settings'][ $setting_id ] = $setting_config;
1322
1323 // sanitize settings
1324 if ( isset( $setting_config['live'] ) && $setting_config['live'] ) {
1325 $setting_args['transport'] = 'postMessage';
1326 }
1327
1328 if ( isset( $setting_config['default'] ) ) {
1329 $setting_args['default'] = $setting_config['default'];
1330 }
1331
1332 if ( isset( $setting_config['capability'] ) && ! empty( $setting_config['capability'] ) ) {
1333 $setting_args['capability'] = $setting_config['capability'];
1334 }
1335
1336 if ( self::$plugin_settings['values_store_mod'] == 'option' ) {
1337 $setting_args['type'] = 'option';
1338 }
1339
1340 // if we arrive here this means we have a custom field control
1341 switch ( $setting_config['type'] ) {
1342
1343 case 'checkbox':
1344
1345 $setting_args['sanitize_callback'] = array( $this, 'setting_sanitize_checkbox' );
1346 break;
1347
1348 default:
1349 break;
1350 }
1351
1352 if ( isset( $setting_config['sanitize_callback'] ) && ! empty( $setting_config['sanitize_callback'] ) && function_exists( $setting_config['sanitize_callback'] ) ) {
1353 $setting_args['sanitize_callback'] = $setting_config['sanitize_callback'];
1354 }
1355
1356 // and add it
1357 $wp_customize->add_setting( $setting_id, $setting_args );
1358
1359 // now sanitize the control
1360 if ( isset( $setting_config['label'] ) && ! empty( $setting_config['label'] ) ) {
1361 $control_args['label'] = $setting_config['label'];
1362 }
1363
1364 if ( isset( $setting_config['priority'] ) && ! empty( $setting_config['priority'] ) ) {
1365 $control_args['priority'] = $setting_config['priority'];
1366 }
1367
1368 if ( isset( $setting_config['desc'] ) && ! empty( $setting_config['desc'] ) ) {
1369 $control_args['description'] = $setting_config['desc'];
1370 }
1371
1372
1373 $control_args['type'] = $setting_config['type'];
1374
1375 // select the control type
1376 // but first init a default
1377 $control_class_name = 'Pix_Customize_Text_Control';
1378
1379 // if is a standard wp field type call it here and skip the rest
1380 if ( in_array( $setting_config['type'], array(
1381 'checkbox',
1382 'dropdown-pages',
1383 'url',
1384 'date',
1385 'time',
1386 'datetime',
1387 'week',
1388 'search'
1389 ) ) ) {
1390 $wp_customize->add_control( $setting_id . '_control', $control_args );
1391
1392 return;
1393 } elseif ( in_array( $setting_config['type'], array(
1394 'radio',
1395 'select'
1396 ) ) && isset( $setting_config['choices'] ) && ! empty( $setting_config['choices'] )
1397 ) {
1398 $control_args['choices'] = $setting_config['choices'];
1399 $wp_customize->add_control( $setting_id . '_control', $control_args );
1400
1401 return;
1402 } elseif ( in_array( $setting_config['type'], array( 'range' ) ) && isset( $setting_config['input_attrs'] ) && ! empty( $setting_config['input_attrs'] ) ) {
1403
1404 $control_args['input_attrs'] = $setting_config['input_attrs'];
1405
1406 $wp_customize->add_control( $setting_id . '_control', $control_args );
1407 }
1408
1409 // if we arrive here this means we have a custom field control
1410 switch ( $setting_config['type'] ) {
1411
1412 case 'text':
1413
1414 if ( isset( $setting_config['live'] ) ) {
1415 $control_args['live'] = $setting_config['live'];
1416 }
1417
1418 $control_class_name = 'Pix_Customize_Text_Control';
1419 break;
1420
1421 case 'textarea':
1422
1423 if ( isset( $setting_config['live'] ) ) {
1424 $control_args['live'] = $setting_config['live'];
1425 }
1426
1427 $control_class_name = 'Pix_Customize_Textarea_Control';
1428 break;
1429
1430 case 'color':
1431
1432 $control_class_name = 'WP_Customize_Color_Control';
1433 break;
1434
1435 case 'color_drop':
1436
1437 $control_class_name = 'Pix_Customize_Color_Drop_Control';
1438 break;
1439
1440 case 'ace_editor':
1441
1442 if ( isset( $setting_config['live'] ) ) {
1443 $control_args['live'] = $setting_config['live'];
1444 }
1445
1446 if ( isset( $setting_config['editor_type'] ) ) {
1447 $control_args['editor_type'] = $setting_config['editor_type'];
1448 }
1449
1450 $control_class_name = 'Pix_Customize_Ace_Editor_Control';
1451 break;
1452
1453 case 'upload':
1454
1455 $control_class_name = 'WP_Customize_Upload_Control';
1456 break;
1457
1458 case 'image':
1459
1460 $control_class_name = 'WP_Customize_Image_Control';
1461 break;
1462
1463 case 'media':
1464
1465 $control_class_name = 'WP_Customize_Media_Control';
1466 break;
1467
1468 case 'custom_background':
1469 if ( isset( $setting_config['field'] ) ) {
1470 $control_args['field'] = $setting_config['field'];
1471 }
1472
1473 $control_class_name = 'Pix_Customize_Background_Control';
1474 break;
1475
1476 case 'cropped_media':
1477
1478 if ( isset( $setting_config['width'] ) ) {
1479 $control_args['width'] = $setting_config['width'];
1480 }
1481
1482 if ( isset( $setting_config['height'] ) ) {
1483 $control_args['height'] = $setting_config['height'];
1484 }
1485
1486 if ( isset( $setting_config['flex_width'] ) ) {
1487 $control_args['flex_width'] = $setting_config['flex_width'];
1488 }
1489
1490 if ( isset( $setting_config['flex_height'] ) ) {
1491 $control_args['flex_height'] = $setting_config['flex_height'];
1492 }
1493
1494 $control_class_name = 'WP_Customize_Cropped_Image_Control';
1495 break;
1496
1497 // Custom types
1498 case 'typography' :
1499
1500 $use_typography = self::get_plugin_option( 'typography', '1' );
1501
1502 if ( $use_typography === false ) {
1503 $add_control = false;
1504 continue;
1505 }
1506
1507 $control_class_name = 'Pix_Customize_Typography_Control';
1508
1509 if ( isset( $setting_config['backup'] ) ) {
1510 $control_args['backup'] = $setting_config['backup'];
1511 }
1512
1513 if ( isset( $setting_config['font_weight'] ) ) {
1514 $control_args['font_weight'] = $setting_config['font_weight'];
1515 }
1516
1517 if ( isset( $setting_config['subsets'] ) ) {
1518 $control_args['subsets'] = $setting_config['subsets'];
1519 }
1520
1521 if ( isset( $setting_config['recommended'] ) ) {
1522 $control_args['recommended'] = array_flip( $setting_config['recommended'] );
1523 }
1524
1525 if ( isset( $setting_config['load_all_weights'] ) ) {
1526 $control_args['load_all_weights'] = $setting_config['load_all_weights'];
1527 }
1528
1529 if ( isset( $setting_config['default'] ) ) {
1530 $control_args['default'] = $setting_config['default'];
1531 }
1532
1533 break;
1534
1535 case 'select2' :
1536
1537 if ( ! isset( $setting_config['choices'] ) || empty( $setting_config['choices'] ) ) {
1538 return;
1539 }
1540
1541 $control_args['choices'] = $setting_config['choices'];
1542
1543 $control_class_name = 'Pix_Customize_Select2_Control';
1544 break;
1545
1546 case 'preset' :
1547
1548 if ( ! isset( $setting_config['choices'] ) || empty( $setting_config['choices'] ) ) {
1549 return;
1550 }
1551
1552 $control_args['choices'] = $setting_config['choices'];
1553
1554 if ( isset( $setting_config['choices_type'] ) || ! empty( $setting_config['choices_type'] ) ) {
1555 $control_args['choices_type'] = $setting_config['choices_type'];
1556 }
1557
1558 if ( isset( $setting_config['desc'] ) || ! empty( $setting_config['desc'] ) ) {
1559 $control_args['description'] = $setting_config['desc'];
1560 }
1561
1562
1563 $control_class_name = 'Pix_Customize_Preset_Control';
1564 break;
1565
1566 case 'radio_image' :
1567
1568 if ( ! isset( $setting_config['choices'] ) || empty( $setting_config['choices'] ) ) {
1569 return;
1570 }
1571
1572 $control_args['choices'] = $setting_config['choices'];
1573
1574 if ( isset( $setting_config['choices_type'] ) || ! empty( $setting_config['choices_type'] ) ) {
1575 $control_args['choices_type'] = $setting_config['choices_type'];
1576 }
1577
1578 if ( isset( $setting_config['desc'] ) || ! empty( $setting_config['desc'] ) ) {
1579 $control_args['description'] = $setting_config['desc'];
1580 }
1581
1582
1583 $control_class_name = 'Pix_Customize_Radio_Image_Control';
1584 break;
1585
1586 case 'button' :
1587
1588 if ( ! isset( $setting_config['action'] ) || empty( $setting_config['action'] ) ) {
1589 return;
1590 }
1591
1592 $control_args['action'] = $setting_config['action'];
1593
1594 $control_class_name = 'Pix_Customize_Button_Control';
1595
1596 break;
1597
1598 case 'html' :
1599
1600 if ( isset( $setting_config['html'] ) || ! empty( $setting_config['html'] ) ) {
1601 $control_args['html'] = $setting_config['html'];
1602 }
1603
1604 $control_class_name = 'Pix_Customize_HTML_Control';
1605 break;
1606
1607 case 'import_demo_data' :
1608
1609 if ( isset( $setting_config['html'] ) || ! empty( $setting_config['html'] ) ) {
1610 $control_args['html'] = $setting_config['html'];
1611 }
1612
1613 if ( ! isset( $setting_config['label'] ) || empty( $setting_config['label'] ) ) {
1614 $control_args['label'] = esc_html__( 'Import', 'customify' );
1615 } else {
1616 $control_args['label'] = $setting_config['label'];
1617 }
1618
1619 if ( isset( $setting_config['notices'] ) && ! empty( $setting_config['notices'] ) ) {
1620 $control_args['notices'] = $setting_config['notices'];
1621 }
1622
1623 $control_class_name = 'Pix_Customize_Import_Demo_Data_Control';
1624 break;
1625
1626 default:
1627 // if we don't have a real control just quit, it doesn't even matter
1628 return;
1629 break;
1630 }
1631
1632 $this_control = new $control_class_name(
1633 $wp_customize,
1634 $setting_id . '_control',
1635 $control_args
1636 );
1637
1638 if ( $add_control ) {
1639 $wp_customize->add_control( $this_control );
1640 }
1641 }
1642
1643 function do_nothing_jon_snow() {
1644 echo '1';
1645 }
1646
1647 /**
1648 * Remove the sections selected by user
1649 *
1650 * @param $wp_customize
1651 */
1652 function remove_default_sections( $wp_customize ) {
1653 global $wp_registered_sidebars;
1654
1655 $to_remove = self::get_plugin_option( 'disable_default_sections' );
1656
1657 if ( ! empty( $to_remove ) ) {
1658 foreach ( $to_remove as $section => $nothing ) {
1659
1660 if ( $section === 'widgets' ) {
1661 foreach ( $wp_registered_sidebars as $widget => $settings ) {
1662 $wp_customize->remove_section( 'sidebar-widgets-' . $widget );
1663 }
1664 continue;
1665 }
1666
1667 $wp_customize->remove_section( $section );
1668 }
1669 }
1670 }
1671
1672 static function get_base_path() {
1673 return plugin_dir_path( __FILE__ );
1674 }
1675
1676 protected static function get_typography_fields( $array, $key, $value, &$results, $input_key = 0 ) {
1677 if ( ! is_array( $array ) ) {
1678 return;
1679 }
1680
1681 if ( isset( $array[ $key ] ) && $array[ $key ] == $value ) {
1682 $results[ $input_key ] = $array;
1683
1684 $default = null;
1685
1686 if ( isset( $array['default'] ) && is_array( $array['default'] ) ) {
1687 $default = json_encode( $array['default'] );
1688 }
1689
1690 $results[ $input_key ]['value'] = self::get_option( $input_key, $default );
1691 }
1692
1693 foreach ( $array as $i => $subarray ) {
1694 self::get_typography_fields( $subarray, $key, $value, $results, $i );
1695 }
1696 }
1697
1698 function get_options_key() {
1699 if ( ! empty( self::$opt_name ) ) {
1700 return self::$opt_name;
1701 }
1702
1703 return false;
1704 }
1705
1706 /**
1707 * Use this function when you need to know if an import button is used
1708 * @return bool
1709 */
1710 function import_button_exists() {
1711
1712 if ( empty( self::$options_list ) ) {
1713 self::$options_list = $this->get_options();
1714 }
1715
1716 foreach ( self::$options_list as $option ) {
1717 if ( isset( $option['type'] ) && 'import_demo_data' === $option['type'] ) {
1718 return true;
1719 break;
1720 }
1721 }
1722
1723 return false;
1724 }
1725
1726 /**
1727 * Sanitize functions
1728 */
1729
1730 /**
1731 * Sanitize the checkbox.
1732 *
1733 * @param boolean $input .
1734 *
1735 * @return boolean true if is 1 or '1', false if anything else
1736 */
1737 function setting_sanitize_checkbox( $input ) {
1738 if ( 1 == $input ) {
1739 return true;
1740 } else {
1741 return false;
1742 }
1743 }
1744
1745 /**
1746 * Checks whether an array is associative or not
1747 *
1748 * @param array $array
1749 *
1750 * @return bool
1751 */
1752 public static function is_assoc( $array ) {
1753
1754 if ( ! is_array( $array ) ) {
1755 return false;
1756 }
1757
1758 // Keys of the array
1759 $keys = array_keys( $array );
1760
1761 // If the array keys of the keys match the keys, then the array must
1762 // not be associative (e.g. the keys array looked like {0:0, 1:1...}).
1763 return array_keys( $keys ) !== $keys;
1764 }
1765
1766 function register_import_api(){
1767
1768 include_once( self::get_base_path() . '/features/class-Customify_Importer.php' );
1769 $controller = new Customify_Importer_Controller();
1770 $controller->init();
1771 }
1772
1773 function get_options_configs () {
1774 return self::$options_list;
1775 }
1776
1777 /**
1778 * Does the same thing the JS encodeURIComponent() does
1779 *
1780 * @param string $str
1781 *
1782 * @return string
1783 */
1784 public static function encodeURIComponent( $str ) {
1785 //if we get an array we just let it be
1786 if ( is_string( $str ) ) {
1787 $revert = array( '%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')' );
1788
1789 $str = strtr( rawurlencode( $str ), $revert );
1790 } else {
1791 var_dump('boooom');die;
1792 }
1793
1794 return $str;
1795 }
1796
1797 /**
1798 * Does the same thing the JS decodeURIComponent() does
1799 *
1800 * @param string $str
1801 *
1802 * @return string
1803 */
1804 public static function decodeURIComponent( $str ) {
1805 //if we get an array we just let it be
1806 if ( is_string( $str ) ) {
1807 $revert = array( '!' => '%21', '*' => '%2A', "'" => '%27', '(' => '%28', ')' => '%29' );
1808 $str = rawurldecode( strtr( $str, $revert ) );
1809 }
1810
1811 return $str;
1812 }
1813 }
1814