customizer-controls.php (16285B)
1 <?php 2 3 namespace Materialis; 4 5 class BaseControl extends \WP_Customize_Control { 6 protected $data = null; 7 8 public function init() { 9 return true; 10 } 11 12 public function __construct( $manager, $id, $data = array() ) { 13 $this->data = $data; 14 parent::__construct( $manager, $id, $data ); 15 $this->init(); 16 } 17 } 18 19 class BackgroundTypesControl extends BaseControl { 20 21 public function init() { 22 $this->type = 'select'; 23 foreach ( $this->data['choices'] as $key => $value ) { 24 $this->choices[ $key ] = $value['label']; 25 } 26 } 27 28 public function render_content() { 29 parent::render_content(); ?> 30 <script> 31 jQuery(document).ready(function ($) { 32 $('[<?php $this->link();?>]').data('controlBinds', <?php echo json_encode( $this->data['choices'] ) ?>); 33 34 function updateControlBinds() { 35 var controlBinds = $('[<?php $this->link();?>]').data('controlBinds'); 36 var currentType = $('[<?php $this->link();?>]').val(); 37 38 for (var type in controlBinds) { 39 var controls = controlBinds[type].control; 40 if (!_.isArray(controls)) { 41 controls = [controls]; 42 } 43 44 for (var i = 0; i < controls.length; i++) { 45 var control = wp.customize.control(controls[i]); 46 47 if (control) { 48 var container = control.container.eq(0); 49 if (type === currentType) { 50 container.show(); 51 } else { 52 container.hide(); 53 } 54 } 55 56 } 57 } 58 } 59 60 wp.customize('<?php echo esc_html( $this->settings['default']->id ); ?>').bind(updateControlBinds); 61 $('[<?php $this->link(); ?>]').change(updateControlBinds); 62 updateControlBinds(); 63 }); 64 </script> 65 <?php 66 } 67 } 68 69 class RowsListControl extends BaseControl { 70 71 public function enqueue() { 72 73 $jsUrl = get_template_directory_uri() . "/customizer/js/"; 74 wp_enqueue_script( 'materialis-row-list-control', $jsUrl . "/row-list-control.js" ); 75 } 76 77 public function getSettingAttr( $setting_key = 'default' ) { 78 if ( ! isset( $this->settings[ $setting_key ] ) ) { 79 return ''; 80 } 81 82 echo 'data-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"'; 83 } 84 85 public function dataAttrs() { 86 $data = 'data-name="' . esc_attr( $this->id ) . '"'; 87 88 echo $data; 89 } 90 91 public function dateSelection() { 92 $data = 'data-selection="radio"'; 93 94 if ( isset( $this->data['selection'] ) ) { 95 $data = 'data-selection="' . esc_attr( $this->data['selection'] ) . '"'; 96 } 97 98 echo $data; 99 } 100 101 public function getSourceData() { 102 return $this->data['dataSource']; 103 } 104 105 106 public function render_content() { 107 ?> 108 <div <?php $this->dateSelection(); ?> data-type="row-list-control" 109 data-apply="<?php echo esc_attr( $this->data['type'] ) ?>" 110 class="list-holder"> 111 <?php ( $this->data['type'] === "mod_changer" ) ? $this->renderModChanger() : $this->renderPresetsChanger() ?> 112 </div> 113 114 <?php $proMessage = isset( $this->data['pro_message'] ) ? $this->data['pro_message'] : false; ?> 115 116 <?php if ( $proMessage && apply_filters( 'materialis_show_inactive_plugin_infos', true ) ): ?> 117 <div class="list-control-pro-message"> 118 <?php echo wp_kses_post( $proMessage ); ?> 119 </div> 120 <?php endif; ?> 121 122 <?php 123 } 124 125 public function filterDefault( $data ) { 126 if ( is_array( $data ) ) { 127 $data = $this->filterArrayDefaults( $data ); 128 } else { 129 $data = str_replace( '[tag_companion_uri]', get_template_directory_uri(), $data ); 130 $data = str_replace( '[tag_theme_uri]', get_template_directory_uri(), $data ); 131 $data = str_replace( '[tag_style_uri]', get_stylesheet_directory_uri(), $data ); 132 } 133 134 return $data; 135 } 136 137 public function filterArrayDefaults( $data ) { 138 foreach ( $data as $key => $value ) { 139 $data[ $key ] = $this->filterDefault( $value ); 140 } 141 142 return $data; 143 } 144 145 public function renderPresetsChanger() { 146 $items = $this->getSourceData(); 147 $optionsVar = uniqid( 'cp_' . $this->id . '_' ); ?> 148 <script> 149 var <?php echo esc_html( $optionsVar ) ?> = 150 { 151 } 152 ; 153 </script> 154 <ul <?php $this->dataAttrs(); ?> class="list rows-list from-theme"> 155 <?php foreach ( $items as $item ): 156 ?> 157 <script> 158 <?php $settingsData = $this->filterArrayDefaults( $item['settings'] ); ?> 159 <?php echo esc_html( $optionsVar ); ?>["<?php echo esc_html( $item['id'] ); ?>"] = <?php echo json_encode( $settingsData ) ?>; 160 </script> 161 162 <?php 163 $proOnly = isset( $item['pro-only'] ) ? "pro-only" : ""; 164 $titleAttr = $item['id']; 165 $titleAttr = str_replace( "pro_", "", $item['id'] ); 166 $titleAttr = str_replace( "free_", "", $titleAttr ); 167 ?> 168 169 170 <li class="item available-item <?php echo esc_attr( $proOnly ); ?>" 171 title="<?php echo esc_attr( $titleAttr ); ?>" data-varname="<?php echo esc_attr( $optionsVar ); ?>" 172 data-id="<?php echo esc_attr( $item['id'] ); ?>"> 173 <div class="image-holder" style="background-position:center center;background-image:url()"> 174 <img data-src="<?php echo esc_url( $item['thumb'] ); ?>" src=""/> 175 </div> 176 177 <?php if ( $proOnly ) : ?> 178 <span data-id="<?php echo esc_attr( $item['id'] ); ?>" data-pro-only="true" 179 class="available-item-hover-button" <?php $this->getSettingAttr(); ?> > 180 <?php esc_html_e( 'Available in PRO', 'materialis' ); ?> 181 </span> 182 <?php else : ?> 183 <span data-id="<?php echo esc_attr( $item['id'] ); ?>" 184 class="available-item-hover-button" <?php $this->getSettingAttr(); ?> > 185 <?php echo esc_html( $this->data['insertText'] ); ?> 186 </span> 187 <?php endif; ?> 188 189 <div title="<?php esc_attr_e( 'Section is already in page', 'materialis' ); ?>" 190 class="checked-icon"></div> 191 <div title="<?php esc_attr_e( 'Pro Only', 'materialis' ); ?>" class="pro-icon"></div> 192 <span class="item-preview" data-preview="<?php echo esc_attr( $item['preview'] ); ?>"> 193 <i class="icon"></i> 194 </span> 195 <?php if ( isset( $item['description'] ) ): ?> 196 <span class="description"> <?php echo esc_html( $item['description'] ); ?> </span> 197 <?php endif; ?> 198 </li> 199 <?php endforeach; ?> 200 </ul> 201 <input type="hidden" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> /> 202 203 <?php ; 204 } 205 } 206 207 class Activate_Companion_Control extends BaseControl { 208 public function get_link( $slug = false ) { 209 $tgmpa = \TGM_Plugin_Activation::get_instance(); 210 $path = $tgmpa->plugins[ $slug ]['file_path']; 211 212 return add_query_arg( array( 213 'action' => 'activate', 214 'plugin' => rawurlencode( $path ), 215 'plugin_status' => 'all', 216 'paged' => '1', 217 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $path ), 218 ), network_admin_url( 'plugins.php' ) ); 219 } 220 221 public function render_content() { 222 $data = $this->data; 223 $label = $data['label']; 224 $msg = $data['msg']; 225 $slug = $data['slug']; 226 ?> 227 <div class="one-page-express-enable-companion"> 228 <?php 229 printf( '<p>%1$s</p>', $msg ); 230 printf( '<a class="%1$s button" href="%2$s">%3$s</a>', "activate", esc_url( $this->get_link( $slug ) ), 231 $label ); 232 ?> 233 </div> 234 <?php 235 } 236 } 237 238 239 class Install_Companion_Control extends BaseControl { 240 public function get_link( $slug = false ) { 241 return add_query_arg( 242 array( 243 'action' => 'install-plugin', 244 'plugin' => $slug, 245 '_wpnonce' => wp_create_nonce( 'install-plugin_' . $slug ), 246 ), 247 network_admin_url( 'update.php' ) 248 ); 249 } 250 251 public function render_content() { 252 $data = $this->data; 253 $label = $data['label']; 254 $msg = $data['msg']; 255 $slug = $data['slug']; 256 ?> 257 <div class="one-page-express-enable-companion"> 258 <?php 259 printf( '<p>%1$s</p>', $msg ); 260 printf( '<a class="%1$s button" href="%2$s">%3$s</a>', "install-now", esc_url( $this->get_link( $slug ) ), 261 $label ); 262 ?> 263 </div> 264 <?php 265 } 266 } 267 268 class Kirki_Controls_Radio_HTML_Control extends \Kirki_Controls_Radio_Image_Control { 269 public $type = 'radio-html'; 270 271 protected function content_template() { 272 ?> 273 <# if ( data.tooltip ) { #> 274 <a href="#" class="tooltip hint--left" data-hint="{{ data.tooltip }}"><span 275 class='dashicons dashicons-info'></span></a> 276 <# } #> 277 <label class="customizer-text"> 278 <# if ( data.label ) { #> 279 <span class="customize-control-title">{{{ data.label }}}</span> 280 <# } #> 281 <# if ( data.description ) { #> 282 <span class="description customize-control-description">{{{ data.description }}}</span> 283 <# } #> 284 </label> 285 <div id="input_{{ data.id }}" class="image"> 286 <# for ( key in data.choices ) { #> 287 <input {{{ data.inputAttrs }}} class="image-select" type="radio" value="{{ key }}" 288 name="_customize-radio-{{ data.id }}" id="{{ data.id }}{{ key }}" {{{ data.link }}}<# if ( data.value 289 === key ) { #> checked="checked" <# } #>> 290 <label for="{{ data.id }}{{ key }}"> 291 <div class="{{ data.choices[ key ] }} image-clickable"></div> 292 </label> 293 </input> 294 <# } #> 295 </div> 296 <?php 297 } 298 } 299 300 301 class Kirki_Controls_Separator_Control extends \WP_Customize_Control { 302 public $type = 'sectionseparator'; 303 304 public function content_template() { 305 ?> 306 <# if ( data.tooltip ) { #> 307 <a href="#" class="tooltip hint--left" data-hint="{{ data.tooltip }}"><span 308 class='dashicons dashicons-info'></span></a> 309 <# } #> 310 <div class="materialis-separator"> 311 <# if ( data.label ) { #> 312 <span class="customize-control-title">{{{ data.label }}}</span> 313 <# } #> 314 </div> 315 <?php 316 } 317 } 318 319 320 class Info_Control extends \WP_Customize_Control { 321 public $type = 'ope-info'; 322 323 324 public function render_content() { 325 326 $proLink = esc_url( "https://extendthemes.com/go/materialis-upgrade" ); 327 $proText = esc_html__( 'Check all PRO features', 'materialis' ); 328 $proButton = "<br/><a href='$proLink' class='button button-small button-orange upgrade-to-pro' target='_blank'>$proText</a>"; 329 $label = str_replace( "@BTN@", $proButton, $this->label ); 330 ?> 331 <p><?php echo $label ?></p> 332 <?php 333 } 334 } 335 336 class Info_PRO_Control extends Info_Control { 337 public $type = 'ope-info-pro'; 338 339 340 protected function render() { 341 if ( ! $this->active_callback() ) { 342 return; 343 } 344 parent::render(); 345 } 346 347 348 public function active_callback() { 349 $active = apply_filters( 'materialis_show_info_pro_messages', true ); 350 351 return $active; 352 } 353 354 } 355 356 class Info_PRO_Section extends \WP_Customize_Section { 357 public $type = "themes"; 358 359 protected function render() { 360 if ( ! $this->active_callback() ) { 361 echo ""; 362 363 return; 364 } 365 366 $classes = 'try-pro accordion-section control-section control-section-' . $this->type; 367 ?> 368 <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>"> 369 <div class="ope-pro-header accordion-section-title"> 370 <a href="//extendthemes.com/go/materialis-upgrade/#pricing" target="_blank" 371 class="button"><?php _e( "Upgrade to PRO", 'materialis' ) ?></a> 372 </div> 373 </li> 374 375 <?php ; 376 } 377 378 public function active_callback() { 379 $active = apply_filters( 'materialis_show_main_info_pro_messages', true ); 380 381 return $active; 382 } 383 384 } 385 386 class MaterialIconsIconControl extends \Kirki_Customize_Control { 387 public $type = 'material-icons-icon-control'; 388 public $button_label = ''; 389 390 391 public function __construct( $manager, $id, $args = array() ) { 392 $this->button_label = esc_html__( 'Change Icon', 'materialis' ); 393 394 parent::__construct( $manager, $id, $args ); 395 } 396 397 398 public function enqueue() { 399 wp_enqueue_style( 'material-icons', get_template_directory_uri() . '/assets/css/material-icons.min.css' ); 400 wp_enqueue_style( 'material-icons-media-tab', get_template_directory_uri() . "/customizer/css/mdi-tab.css", 401 array( 'media-views' ) ); 402 wp_enqueue_script( 'material-icons-media-tab', get_template_directory_uri() . "/customizer/js/mdi-tab.js", 403 array( 'media-views' ) ); 404 wp_enqueue_script( 'material-icons-icon-control', 405 get_template_directory_uri() . "/customizer/js/material-icons-icon-control.js" ); 406 wp_localize_script( 'material-icons-icon-control', 'ficTexts', array( 407 'media_title' => esc_html__( 'Select Material Icon', 'materialis' ), 408 'media_button_label' => esc_html__( 'Choose Icon', 'materialis' ), 409 ) ); 410 } 411 412 413 public function to_json() { 414 parent::to_json(); 415 $this->json['button_label'] = $this->button_label; 416 } 417 418 419 protected function content_template() { 420 ?> 421 <label for="{{ data.settings['default'] }}-button"> 422 <# if ( data.label ) { #> 423 <span class="customize-control-title">{{ data.label }}</span> 424 <# } #> 425 <# if ( data.description ) { #> 426 <span class="description customize-control-description">{{{ data.description }}}</span> 427 <# } #> 428 </label> 429 430 <div class="fic-icon-container"> 431 <div class="fic-icon-preview"> 432 <i class="mdi {{data.value}}"></i> 433 <input type="hidden" value="{{ data.value }}" name="_customize-input-{{ data.id }}" {{{ data.link }}}/> 434 </div> 435 <div class="fic-controls"> 436 <button type="button" class="button upload-button control-focus" id="_customize-button-{{ data.id }}"> 437 {{{ data.button_label }}} 438 </button> 439 </div> 440 </div> 441 <?php 442 443 } 444 } 445 446 class FrontPageSection extends \WP_Customize_Section { 447 protected function render() { 448 ?> 449 <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" 450 class="accordion-section control-section control-section-<?php echo esc_attr( $this->type ); ?> companion-needed-section"> 451 <h3 class="accordion-section-title" tabindex="0"> 452 <?php echo esc_html( $this->title ); ?> 453 <span class="screen-reader-text"><?php _e( 'Press return or enter to open this section', 454 'materialis' ); ?></span> 455 </h3> 456 457 <div class="sections-list-reorder"> 458 <span class="customize-control-title"><?php _e( 'Manage page sections', 'materialis' ); ?></span> 459 <ul id="page_full_rows" class="list list-order"> 460 <li class="empty"><?php _e( 'No section added', 'materialis' ) ?></li> 461 </ul> 462 <div class="add-section-container"> 463 <a class="cp-add-section button-primary"><?php _e( 'Add Section', 'materialis' ); ?></a> 464 </div> 465 </div> 466 <script type="text/javascript"> 467 jQuery(function () { 468 jQuery('.companion-needed-section,.companion-needed-section > *').off(); 469 470 jQuery('body').on('click', '.companion-needed-section h3', function (event) { 471 event.preventDefault(); 472 event.stopPropagation(); 473 }); 474 475 }) 476 </script> 477 <style> 478 #accordion-section-<?php echo esc_attr($this->id);?> h3.accordion-section-title:after { 479 display: none; 480 } 481 </style> 482 </li> 483 484 485 <?php 486 487 } 488 }