Layers_Design_Controller

Widget Design Controller Class.

Defined (1)

The class is defined in the following location(s).

/core/helpers/design-bar.php  
  1. class Layers_Design_Controller { 
  2.  
  3. /** 
  4. * Generate Design Options 
  5. * @param string $type Sidebar type, side/top 
  6. * @param array $args Args for name, id, etc 
  7. * @param array $instance Widget $instance 
  8. * @param array $components Array of standard components to support 
  9. * @param array $custom_components Array of custom components and elements 
  10. */ 
  11.  
  12. public function __construct( $type = 'side' , $args = NULL, $instance = array(), $components = array( 'columns' , 'background' , 'imagealign' ) , $custom_components = array() ) { 
  13.  
  14. // Initiate Widget Inputs 
  15. $this->form_elements = new Layers_Form_Elements(); 
  16.  
  17. // If there is no args information provided, can the operation 
  18. if( NULL == $args ) return; 
  19.  
  20. // Store args (merged with defaults) 
  21. $defaults = array( 
  22. 'container_class' => '', // Optional unique css classes 
  23. 'align' => 'left', // left | right 
  24. 'inline' => FALSE, // Inline will make the buttons appear interface-y - as one individual button after the next. 
  25. ); 
  26. $this->args = wp_parse_args( $args, $defaults ); 
  27.  
  28. // Store type (side | top) 
  29. $this->type = $type; 
  30.  
  31. // Store widget instance 
  32. $this->instance = $instance; 
  33.  
  34. // Store widget values 
  35. if( empty( $instance ) ) { 
  36. $this->values = array( 'design' => NULL ); 
  37. } elseif( isset( $instance[ 'design' ] ) ) { 
  38. $this->values = $instance[ 'design' ]; 
  39. } else { 
  40. $this->values = NULL; 
  41.  
  42. // Store components & custom_components 
  43. $this->components = $components; 
  44. $this->custom_components = $custom_components; 
  45.  
  46. // Setup the controls 
  47. $this->setup_controls(); 
  48.  
  49. // Fire off the design bar 
  50. $this->render_design_bar(); 
  51.  
  52. public function render_design_bar() { 
  53.  
  54. $container_class = array(); 
  55. $container_class[] = 'layers-design-bar'; 
  56. $container_class[] = ( 'side' == $this->type ? 'layers-design-bar-right' : 'layers-design-bar-horizontal' ); 
  57. $container_class[] = ( 'side' == $this->type ? 'layers-pull-right' : 'layers-visuals-horizontal' ); 
  58. $container_class[] = 'layers-visuals'; 
  59.  
  60. // Apply custom container classes passed by args. 
  61. $container_class[] = $this->args['container_class']; 
  62.  
  63. // Apply `left`, `right`, align to the container class. 
  64. switch ( $this->args['align'] ) { 
  65. case 'left': 
  66. // This is the default state so no unique class-name needed. 
  67. break; 
  68. case 'right': 
  69. $container_class[] = 'layers-align-right'; 
  70. break; 
  71.  
  72. // Apply `inline`. 
  73. if ( TRUE === $this->args['inline'] ) { 
  74. $container_class[] = 'layers-visuals-inline'; 
  75. ?> 
  76. <div class="<?php echo esc_attr( implode( ' ', $container_class ) ); ?>"> 
  77. <div class="layers-visuals-title"> 
  78. <span class="icon-settings layers-small"></span> 
  79. </div> 
  80. <ul class="layers-design-bar-nav layers-visuals-wrapper layers-clearfix"> 
  81. <?php // Render Design Controls 
  82. $this->render_controls(); ?> 
  83. <?php // Show trash icon (for use when in an accordian) 
  84. $this->render_trash_control(); ?> 
  85. <?php if( 'side' == $this->type && !class_exists( 'Layers_Pro' ) ) { ?> 
  86. <li class="layers-visuals-item layers-pro-upsell"> 
  87. <a href="https://www.layerswp.com/layers-pro/?ref=obox&utm_source=layers%20theme&utm_medium=link&utm_campaign=Layers%20Pro%20Upsell&utm_content=Widget%20Design%20Bar" target="_blank"> 
  88. <?php _e( 'Upgrade to Layers Pro', 'layerswp' ); ?> 
  89. </a> 
  90. </li> 
  91. <?php } ?> 
  92. </ul> 
  93. </div> 
  94. <?php } 
  95.  
  96. private function setup_controls() { 
  97.  
  98. $this->controls = array(); 
  99.  
  100. foreach( (array) $this->components as $component_key => $component_value ) { 
  101.  
  102. if ( is_array( $component_value ) ) { 
  103.  
  104. // This case allows for overriding of existing Design Bar Component types, and the creating of new custom Components. 
  105. $method = "{$component_key}_component"; 
  106.  
  107. if ( method_exists( $this, $method ) ) { 
  108.  
  109. // This is the overriding existing component case. 
  110. ob_start(); 
  111. $this->$method( $component_value ); 
  112. $this->controls[] = trim( ob_get_clean() ); 
  113. else { 
  114.  
  115. // This is the creating of new custom component case. 
  116. ob_start(); 
  117. $this->custom_component( 
  118. $component_key, // Give the component a key (will be used as class name too) 
  119. $component_value // Send through the inputs that will be used 
  120. ); 
  121. $this->controls[] = trim( ob_get_clean() ); 
  122. elseif ( 'custom' === $component_value && !empty( $this->custom_components ) ) { 
  123.  
  124. // This case is legacy - the old method of creating custom components. 
  125. foreach ( $this->custom_components as $key => $custom_component_args ) { 
  126.  
  127. ob_start(); 
  128. $this->custom_component( 
  129. $key, // Give the component a key (will be used as class name too) 
  130. $custom_component_args // Send through the inputs that will be used 
  131. ); 
  132. $this->controls[] = trim( ob_get_clean() ); 
  133. elseif ( method_exists( $this, "{$component_value}_component" ) ) { 
  134.  
  135. // This is the standard method of calling a component that already exists 
  136. $method = "{$component_value}_component"; 
  137.  
  138. ob_start(); 
  139. $this->$method(); 
  140. $this->controls[] = trim( ob_get_clean() ); 
  141.  
  142.  
  143. private function render_controls() { 
  144.  
  145. // If there are no controls to render, do nothing 
  146. if( empty( $this->controls ) ) return; 
  147.  
  148. echo implode( '', $this->controls ); 
  149.  
  150. /** 
  151. * Custom Compontent 
  152. * @param string $key Simply the key and classname for the icon,  
  153. * @param array $args Component arguments, including the form items 
  154. */ 
  155.  
  156. public function render_control( $key = NULL, $args = array() ) { 
  157.  
  158. if( empty( $args ) ) return; 
  159.  
  160. // Setup variables from $args 
  161. $icon_css = $args[ 'icon-css' ]; 
  162. $label = $args[ 'label' ]; 
  163. $menu_wrapper_class = ( isset( $args[ 'wrapper-class' ] ) ? $args[ 'wrapper-class' ] : 'layers-pop-menu-wrapper layers-content-small' ); 
  164.  
  165. // Add a fallback to the elements arguments 
  166. $element_args = ( isset( $args[ 'elements' ] ) ? $args[ 'elements' ] : array() ); 
  167.  
  168. // Return filtered element array 
  169. $elements = apply_filters( 'layers_design_bar_' . $key . '_elements', $element_args ); 
  170.  
  171.  
  172. if( isset( $this->args[ 'widget_id' ] ) ) { 
  173. // echo 'layers_design_bar_' . $key . '_' . $this->args[ 'widget_id' ] . '_elements'; 
  174. $elements = apply_filters( 
  175. 'layers_design_bar_' . $key . '_' . $this->args[ 'widget_id' ] . '_elements',  
  176. $elements,  
  177. $this 
  178. ); 
  179. } ?> 
  180.  
  181. <li class="layers-design-bar-nav-item layers-visuals-item"> 
  182. <a href="" class="layers-icon-wrapper"> 
  183. <span class="<?php echo esc_attr( $icon_css ); ?>"></span> 
  184. <span class="layers-icon-description"> 
  185. <?php echo $label; ?> 
  186. </span> 
  187. </a> 
  188. <?php if( isset( $elements ) ) { ?> 
  189. <div class="<?php echo esc_attr( $menu_wrapper_class ); ?>"> 
  190. <div class="layers-pop-menu-setting"> 
  191. <?php foreach( $elements as $key => $form_args ) { ?> 
  192. <?php echo $this->render_input( $form_args ); ?> 
  193. <?php } ?> 
  194. </div> 
  195. </div> 
  196. <?php } // if we have elements ?> 
  197. </li> 
  198. <?php } 
  199.  
  200. private function render_trash_control() { 
  201.  
  202. if( isset( $this->args['show_trash'] ) && TRUE === $this->args['show_trash'] ) { ?> 
  203. <li class="layers-visuals-item layers-pull-right"> 
  204. <a href="" class="layers-icon-wrapper layers-icon-error"> 
  205. <span class="icon-trash" data-number="<?php echo $this->args['number']; ?>"></span> 
  206. </a> 
  207. </li> 
  208. <?php } 
  209.  
  210.  
  211. /** 
  212. * Load input HTML 
  213. * @param array $array() Existing option array if exists (optional) 
  214. * @return array $array Array of options, all standard DOM input options 
  215. */ 
  216. public function render_input( $form_args = array() ) { 
  217.  
  218. // If input-class then set it to 'class' arg that the form->input expects. 
  219. if ( isset( $form_args['input-class'] ) ) { 
  220. $form_args['class'] = $form_args['input-class']; 
  221.  
  222. $data_show_if = array(); 
  223. if ( isset( $form_args['data']['show-if-selector'] ) ) { 
  224. $data_show_if['show-if-selector'] = 'data-show-if-selector="' . esc_attr( $form_args['data']['show-if-selector'] ) . '"'; 
  225. unset( $form_args['data']['show-if-selector'] ); 
  226. if ( isset( $form_args['data']['show-if-value'] ) ) { 
  227. $data_show_if['show-if-value'] = 'data-show-if-value="' . esc_attr( $form_args['data']['show-if-value'] ) . '"'; 
  228. unset( $form_args['data']['show-if-value'] ); 
  229. if ( isset( $form_args['data']['show-if-operator'] ) ) { 
  230. $data_show_if['show-if-operator'] = 'data-show-if-operator="' . esc_attr( $form_args['data']['show-if-operator'] ) . '"'; 
  231. unset( $form_args['data']['show-if-operator'] ); 
  232.  
  233. // Prep Class 
  234. $class = array(); 
  235. $class[] = 'layers-form-item'; 
  236. $class[] = 'layers-' . $form_args['type'] . '-wrapper'; 
  237. $class[] = 'layers-design-bar-form-item'; 
  238. if ( isset( $form_args['class'] ) ) { 
  239. // Grab the class if specified. 
  240. $class[] = $form_args['class']; 
  241. unset( $form_args['class'] ); 
  242. ?> 
  243. <div class="<?php echo esc_attr( implode( ' ', $class ) ); ?>" <?php echo implode( ' ', $data_show_if ); ?> > 
  244.  
  245. <?php if ( 'checkbox' != $form_args['type'] && isset( $form_args['label'] ) && '' != $form_args['label'] ) { ?> 
  246. <label><?php echo esc_html( $form_args['label'] ); ?></label> 
  247. <?php } ?> 
  248.  
  249. <?php if ( isset( $form_args['wrapper'] ) ) { ?> 
  250. <<?php echo $form_args['wrapper']; ?> <?php if ( $form_args['wrapper-class'] ) echo 'class="' . $form_args['wrapper-class'] . '"'; ?>> 
  251. <?php } ?> 
  252.  
  253. <?php if( isset( $form_args['group'] ) && is_array( $form_args['group'] ) ) { 
  254. foreach( $form_args[ 'group' ] as $input_key => $input_args ) { 
  255. echo $this->form_elements->input( $input_args ); 
  256. } else { 
  257. echo $this->form_elements->input( $form_args ); 
  258. }?> 
  259.  
  260. <?php if ( isset( $form_args['wrapper'] ) ) { ?> 
  261. </<?php echo $form_args['wrapper']; ?>> 
  262. <?php } ?> 
  263.  
  264. <?php if ( isset( $form_args['description'] ) ) { ?> 
  265. <div class="layers-form-item-description"><?php echo $form_args['description']; ?></div> 
  266. <?php } ?> 
  267.  
  268. </div> 
  269. <?php 
  270.  
  271. /** 
  272. * Layout Options 
  273. * @param array $args Additional arguments to pass to this function 
  274. */ 
  275. public function layout_component( $args = array() ) { 
  276.  
  277. // If there is no args information provided, can the operation 
  278. if ( NULL == $this->args ) 
  279. return; 
  280.  
  281. // Set a key for this input 
  282. $key = 'layout'; 
  283.  
  284. // Setup icon CSS 
  285. $defaults['icon-css'] = ( isset( $this->values['layout'] ) && NULL != $this->values ? 'icon-' . $this->values['layout'] : 'icon-layout-fullwidth' ); 
  286.  
  287. // Add a Label 
  288. $defaults['label'] = __( 'Layout', 'layerswp' ); 
  289.  
  290. // Add a Wrapper Class 
  291. $defaults['wrapper-class'] = 'layers-pop-menu-wrapper layers-animate layers-small'; 
  292.  
  293. // Add elements 
  294. $defaults['elements'] = array( 
  295. 'layout' => array( 
  296. 'type' => 'select-icons',  
  297. 'name' => $this->get_layers_field_name( 'layout' ),  
  298. 'id' => $this->get_layers_field_id( 'layout' ),  
  299. 'value' => ( isset( $this->values['layout'] ) ) ? $this->values['layout'] : NULL,  
  300. 'options' => array( 
  301. 'layout-boxed' => __( 'Boxed', 'layerswp' ),  
  302. 'layout-fullwidth' => __( 'Full Width', 'layerswp' ) 
  303. ); 
  304.  
  305. $args = $this->merge_component( $defaults, $args ); 
  306.  
  307. $this->render_control( $key, apply_filters( 'layerswp_layout_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  308.  
  309. /** 
  310. * List Style - Static Option 
  311. * @param array $args Additional arguments to pass to this function 
  312. */ 
  313. public function liststyle_component( $args = array() ) { 
  314.  
  315. // If there is no args information provided, can the operation 
  316. if ( NULL == $this->args ) 
  317. return; 
  318.  
  319. // Set a key for this input 
  320. $key = 'liststyle'; 
  321.  
  322. // Setup icon CSS 
  323. $defaults['icon-css'] = ( isset( $this->values['liststyle'] ) && NULL != $this->values ? 'icon-' . $this->values['liststyle'] : 'icon-list-masonry' ); 
  324.  
  325. // Add a Label 
  326. $defaults['label'] = __( 'List Style', 'layerswp' ); 
  327.  
  328. // Add a Wrapper Class 
  329. $defaults['wrapper-class'] = 'layers-pop-menu-wrapper layers-animate layers-small'; 
  330.  
  331. // Add elements 
  332. $defaults['elements'] = array( 
  333. 'liststyle' => array( 
  334. 'type' => 'select-icons',  
  335. 'name' => $this->get_layers_field_name( 'liststyle' ),  
  336. 'id' => $this->get_layers_field_id( 'liststyle' ),  
  337. 'value' => ( isset( $this->values['liststyle'] ) ) ? $this->values['liststyle'] : NULL,  
  338. 'options' => array( 
  339. 'list-grid' => __( 'Grid', 'layerswp' ),  
  340. 'list-list' => __( 'List', 'layerswp' ),  
  341. 'list-masonry' => __( 'Masonry', 'layerswp' ) 
  342. ); 
  343.  
  344. $args = $this->merge_component( $defaults, $args ); 
  345.  
  346. $this->render_control( $key, apply_filters( 'layerswp_liststyle_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  347.  
  348. /** 
  349. * Columns - Static Option 
  350. * @param array $args Additional arguments to pass to this function 
  351. */ 
  352. public function columns_component( $args = array() ) { 
  353.  
  354. // If there is no args information provided, can the operation 
  355. if ( NULL == $this->args ) 
  356. return; 
  357.  
  358. // Set a key for this input 
  359. $key = 'columns'; 
  360.  
  361. // Setup icon CSS 
  362. $defaults['icon-css'] = 'icon-columns'; 
  363.  
  364. // Add a Label 
  365. $defaults['label'] = __( 'Columns', 'layerswp' ); 
  366.  
  367. // Add a Wrapper Class 
  368. $defaults['wrapper-class'] = 'layers-pop-menu-wrapper layers-animate layers-content-small'; 
  369.  
  370. // Add elements 
  371. $defaults['elements'] = array( 
  372. 'columns' => array( 
  373. 'type' => 'select',  
  374. 'label' => __( 'Columns', 'layerswp' ),  
  375. 'name' => $this->get_layers_field_name( 'columns' ),  
  376. 'id' => $this->get_layers_field_id( 'columns' ),  
  377. 'value' => ( isset( $this->values['columns'] ) ) ? $this->values['columns'] : NULL,  
  378. 'options' => array( 
  379. '1' => __( '1 Column', 'layerswp' ),  
  380. '2' => __( '2 Columns', 'layerswp' ),  
  381. '3' => __( '3 Columns', 'layerswp' ),  
  382. '4' => __( '4 Columns', 'layerswp' ),  
  383. '6' => __( '6 Columns', 'layerswp' ),  
  384. ),  
  385. 'color' => array( 
  386. 'type' => 'color',  
  387. 'label' => __( 'Background Color', 'layerswp' ),  
  388. 'name' => $this->get_layers_field_name( 'column-background-color' ),  
  389. 'id' => $this->get_layers_field_id( 'columns-background-color' ),  
  390. 'value' => ( isset( $this->values['column-background-color'] ) ) ? $this->values['column-background-color'] : NULL 
  391. ),  
  392. 'gutter' => array( 
  393. 'type' => 'checkbox',  
  394. 'label' => __( 'Gutter', 'layerswp' ),  
  395. 'name' => $this->get_layers_field_name( 'gutter' ),  
  396. 'id' => $this->get_layers_field_id( 'gutter' ),  
  397. 'value' => ( isset( $this->values['gutter'] ) ) ? $this->values['gutter'] : NULL 
  398. ); 
  399.  
  400. $args = $this->merge_component( $defaults, $args ); 
  401.  
  402. $this->render_control( $key, apply_filters( 'layerswp_columns_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  403.  
  404. /** 
  405. * Text Align - Static Option 
  406. * @param array $args Additional arguments to pass to this function 
  407. */ 
  408. public function textalign_component( $args = array() ) { 
  409.  
  410. // If there is no args information provided, can the operation 
  411. if ( NULL == $this->args ) 
  412. return; 
  413.  
  414. // Set a key for this input 
  415. $key = 'textalign'; 
  416.  
  417. // Setup icon CSS 
  418. $defaults['icon-css'] = ( isset( $this->values['textalign'] ) && NULL != $this->values ? 'icon-' . $this->values['textalign'] : 'icon-text-center' ); 
  419.  
  420. // Add a Label 
  421. $defaults['label'] = __( 'Text Align', 'layerswp' ); 
  422.  
  423. // Add a Wrapper Class 
  424. $defaults['wrapper-class'] = 'layers-pop-menu-wrapper layers-animate layers-content-small'; 
  425.  
  426. // Add elements 
  427. $defaults['elements'] = array( 
  428. 'textalign' => array( 
  429. 'type' => 'select-icons',  
  430. 'name' => $this->get_layers_field_name( 'textalign' ),  
  431. 'id' => $this->get_layers_field_id( 'textalign' ),  
  432. 'value' => ( isset( $this->values['textalign'] ) ) ? $this->values['textalign'] : NULL,  
  433. 'options' => array( 
  434. 'text-left' => __( 'Left', 'layerswp' ),  
  435. 'text-center' => __( 'Center', 'layerswp' ),  
  436. 'text-right' => __( 'Right', 'layerswp' ),  
  437. 'text-justify' => __( 'Justify', 'layerswp' ) 
  438. ); 
  439.  
  440. $args = $this->merge_component( $defaults, $args ); 
  441.  
  442. $this->render_control( $key, apply_filters( 'layerswp_textalign_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  443.  
  444. /** 
  445. * Image Align - Static Option 
  446. * @param array $args Additional arguments to pass to this function 
  447. */ 
  448. public function imagealign_component( $args = array() ) { 
  449.  
  450. // If there is no args information provided, can the operation 
  451. if ( NULL == $this->args ) 
  452. return; 
  453.  
  454. // Set a key for this input 
  455. $key = 'imagealign'; 
  456.  
  457. // Setup icon CSS 
  458. $defaults['icon-css'] = ( isset( $this->values['imagealign'] ) && NULL != $this->values ? 'icon-' . $this->values['imagealign'] : 'icon-image-left' ); 
  459.  
  460. // Add a Label 
  461. $defaults['label'] = __( 'Image Align', 'layerswp' ); 
  462.  
  463. // Add a Wrapper Class 
  464. $defaults['wrapper-class'] = 'layers-pop-menu-wrapper layers-animate layers-small'; 
  465.  
  466. // Add elements 
  467. $defaults['elements'] = array( 
  468. 'imagealign' => array( 
  469. 'type' => 'select-icons',  
  470. 'name' => $this->get_layers_field_name( 'imagealign' ),  
  471. 'id' => $this->get_layers_field_id( 'imagealign' ),  
  472. 'value' => ( isset( $this->values['imagealign'] ) ) ? $this->values['imagealign'] : NULL,  
  473. 'options' => array( 
  474. 'image-left' => __( 'Left', 'layerswp' ),  
  475. 'image-right' => __( 'Right', 'layerswp' ),  
  476. 'image-top' => __( 'Top', 'layerswp' ),  
  477. ),  
  478. ); 
  479.  
  480. $args = $this->merge_component( $defaults, $args ); 
  481.  
  482. $this->render_control( $key, apply_filters( 'layerswp_imagealign_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  483.  
  484. /** 
  485. * Featured Image - Static Option 
  486. * @param array $args Additional arguments to pass to this function 
  487. */ 
  488. public function featuredimage_component( $args = array() ) { 
  489.  
  490. // If there is no args information provided, can the operation 
  491. if ( NULL == $this->args ) 
  492. return; 
  493.  
  494. // Set a key for this input 
  495. $key = 'featuredimage'; 
  496.  
  497. // Setup icon CSS 
  498. $defaults['icon-css'] = 'icon-featured-image'; 
  499.  
  500. // Add a Label 
  501. $defaults['label'] = __( 'Featured Media', 'layerswp' ); 
  502.  
  503. // Add a Wrapper Class 
  504. $defaults['wrapper-class'] = 'layers-pop-menu-wrapper layers-animate layers-content-small'; 
  505.  
  506. // Add elements 
  507. $defaults['elements'] = array( 
  508. 'featuredimage' => array( 
  509. 'type' => 'image',  
  510. 'label' => __( 'Featured Media', 'layerswp' ),  
  511. 'name' => $this->get_layers_field_name( 'featuredimage' ),  
  512. 'id' => $this->get_layers_field_id( 'featuredimage' ),  
  513. 'value' => ( isset( $this->values['featuredimage'] ) ) ? $this->values['featuredimage'] : NULL 
  514. ),  
  515. 'featuredimage' => array( 
  516. 'type' => 'image',  
  517. 'label' => __( 'Featured Media', 'layerswp' ),  
  518. 'name' => $this->get_layers_field_name( 'featuredimage' ),  
  519. 'id' => $this->get_layers_field_id( 'featuredimage' ),  
  520. 'value' => ( isset( $this->values['featuredimage'] ) ) ? $this->values['featuredimage'] : NULL 
  521. ),  
  522. 'featuredvideo' => array( 
  523. 'type' => 'text',  
  524. 'label' => __( 'Video URL (oEmbed)', 'layerswp' ),  
  525. 'name' => $this->get_layers_field_name( 'featuredvideo' ),  
  526. 'id' => $this->get_layers_field_id( 'featuredvideo' ),  
  527. 'value' => ( isset( $this->values['featuredvideo'] ) ) ? $this->values['featuredvideo'] : NULL 
  528. ),  
  529. 'imageratios' => array( 
  530. 'type' => 'select-icons',  
  531. 'label' => __( 'Image Ratio', 'layerswp' ),  
  532. 'name' => $this->get_layers_field_name( 'imageratios' ),  
  533. 'id' => $this->get_layers_field_id( 'imageratios' ),  
  534. 'value' => ( isset( $this->values['imageratios'] ) ) ? $this->values['imageratios'] : NULL,  
  535. 'options' => array( 
  536. 'image-portrait' => __( 'Portrait', 'layerswp' ),  
  537. 'image-landscape' => __( 'Landscape', 'layerswp' ),  
  538. 'image-square' => __( 'Square', 'layerswp' ),  
  539. 'image-no-crop' => __( 'None', 'layerswp' ),  
  540. 'image-round' => __( 'Round', 'layerswp' ),  
  541. ),  
  542. 'wrapper' => 'div',  
  543. 'wrapper-class' => 'layers-icon-group layers-icon-group-outline' 
  544. ),  
  545. ); 
  546.  
  547. $args = $this->merge_component( $defaults, $args ); 
  548.  
  549. $this->render_control( $key, apply_filters( 'layerswp_featuredimage_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  550.  
  551. /** 
  552. * Image Size - Static Option 
  553. * @param array $args Additional arguments to pass to this function 
  554. */ 
  555. public function imageratios_component( $args = array() ) { 
  556.  
  557. // If there is no args information provided, can the operation 
  558. if ( NULL == $this->args ) 
  559. return; 
  560.  
  561. // Set a key for this input 
  562. $key = 'imageratios'; 
  563.  
  564. // Setup icon CSS 
  565. $defaults['icon-css'] = ( isset( $this->values['imageratios'] ) && NULL != $this->values ? 'icon-' . $this->values['imageratios'] : 'icon-image-size' ); 
  566.  
  567. // Add a Label 
  568. $defaults['label'] = __( 'Image Ratio', 'layerswp' ); 
  569.  
  570. // Add a Wrapper Class 
  571. $defaults['wrapper-class'] = 'layers-pop-menu-wrapper layers-animate layers-small'; 
  572.  
  573. // Add elements 
  574. $defaults['elements'] = array( 
  575. 'imageratio' => array( 
  576. 'type' => 'select-icons',  
  577. 'name' => $this->get_layers_field_name( 'imageratios' ),  
  578. 'id' => $this->get_layers_field_id( 'imageratios' ),  
  579. 'value' => ( isset( $this->values['imageratios'] ) ) ? $this->values['imageratios'] : NULL,  
  580. 'options' => array( 
  581. 'image-portrait' => __( 'Portrait', 'layerswp' ),  
  582. 'image-landscape' => __( 'Landscape', 'layerswp' ),  
  583. 'image-square' => __( 'Square', 'layerswp' ),  
  584. 'image-no-crop' => __( 'None', 'layerswp' ),  
  585. 'image-round' => __( 'Round', 'layerswp' ) 
  586. ),  
  587. ); 
  588.  
  589. $args = $this->merge_component( $defaults, $args ); 
  590.  
  591. $this->render_control( $key, apply_filters( 'layerswp_imageratios_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  592.  
  593. /** 
  594. * Fonts - Static Option 
  595. * @param array $args Additional arguments to pass to this function 
  596. */ 
  597. public function fonts_component( $args = array() ) { 
  598.  
  599. // If there is no args information provided, can the operation 
  600. if ( NULL == $this->args ) 
  601. return; 
  602.  
  603. // Set a key for this input 
  604. $key = 'fonts'; 
  605.  
  606. // Setup icon CSS 
  607. $defaults['icon-css'] = 'icon-font-size'; 
  608.  
  609. // Add a Label 
  610. $defaults['label'] = __( 'Text', 'layerswp' ); 
  611.  
  612. // Add a Wrapper Class 
  613. $defaults['wrapper-class'] = 'layers-pop-menu-wrapper layers-animate layers-content-small'; 
  614.  
  615. // Add elements 
  616. $defaults['elements'] = array( 
  617. 'fonts-align' => array( 
  618. 'type' => 'select-icons',  
  619. 'label' => __( 'Text Align', 'layerswp' ),  
  620. 'name' => $this->get_layers_field_name( 'fonts', 'align' ),  
  621. 'id' => $this->get_layers_field_id( 'fonts', 'align' ),  
  622. 'value' => ( isset( $this->values['fonts']['align'] ) ) ? $this->values['fonts']['align'] : NULL,  
  623. 'options' => array( 
  624. 'text-left' => __( 'Left', 'layerswp' ),  
  625. 'text-center' => __( 'Center', 'layerswp' ),  
  626. 'text-right' => __( 'Right', 'layerswp' ),  
  627. 'text-justify' => __( 'Justify', 'layerswp' ) 
  628. ),  
  629. 'wrapper' => 'div',  
  630. 'wrapper-class' => 'layers-icon-group layers-icon-group-outline' 
  631. ),  
  632. 'fonts-size' => array( 
  633. 'type' => 'select',  
  634. 'label' => __( 'Text Size', 'layerswp' ),  
  635. 'name' => $this->get_layers_field_name( 'fonts', 'size' ),  
  636. 'id' => $this->get_layers_field_id( 'fonts', 'size' ),  
  637. 'value' => ( isset( $this->values['fonts']['size'] ) ) ? $this->values['fonts']['size'] : NULL,  
  638. 'options' => array( 
  639. 'small' => __( 'Small', 'layerswp' ),  
  640. 'medium' => __( 'Medium', 'layerswp' ),  
  641. 'large' => __( 'Large', 'layerswp' ) 
  642. ),  
  643. 'fonts-color' => array( 
  644. 'type' => 'color',  
  645. 'label' => __( 'Text Color', 'layerswp' ),  
  646. 'name' => $this->get_layers_field_name( 'fonts', 'color' ),  
  647. 'id' => $this->get_layers_field_id( 'fonts', 'color' ),  
  648. 'value' => ( isset( $this->values['fonts']['color'] ) ) ? $this->values['fonts']['color'] : NULL 
  649. ); 
  650.  
  651. $args = $this->merge_component( $defaults, $args ); 
  652.  
  653. $this->render_control( $key, apply_filters( 'layerswp_font_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  654.  
  655. /** 
  656. * Background - Static Option 
  657. * @param array $args Additional arguments to pass to this function 
  658. */ 
  659. public function background_component( $args = array() ) { 
  660.  
  661. // If there is no args information provided, can the operation 
  662. if ( NULL == $this->args ) 
  663. return; 
  664.  
  665. // Set a key for this input 
  666. $key = 'background'; 
  667.  
  668. // Setup icon CSS 
  669. $defaults['icon-css'] = 'icon-photo'; 
  670.  
  671. // Add a Label 
  672. $defaults['label'] = __( 'Background', 'layerswp' ); 
  673.  
  674. // Add elements 
  675. $defaults['elements']['background-color'] = array( 
  676. 'type' => 'color',  
  677. 'label' => __( 'Background Color', 'layerswp' ),  
  678. 'name' => $this->get_layers_field_name( 'background', 'color' ),  
  679. 'id' => $this->get_layers_field_id( 'background', 'color' ),  
  680. 'value' => ( isset( $this->values['background']['color'] ) ) ? $this->values['background']['color'] : NULL 
  681. ); 
  682. $defaults['elements']['background-image'] = array( 
  683. 'type' => 'image',  
  684. 'label' => __( 'Background Image', 'layerswp' ),  
  685. 'button_label' => __( 'Choose Image', 'layerswp' ),  
  686. 'name' => $this->get_layers_field_name( 'background', 'image' ),  
  687. 'id' => $this->get_layers_field_id( 'background', 'image' ),  
  688. 'value' => ( isset( $this->values['background']['image'] ) ) ? $this->values['background']['image'] : NULL,  
  689. ); 
  690. $defaults['elements']['background-repeat'] = array( 
  691. 'type' => 'select',  
  692. 'label' => __( 'Background Repeat', 'layerswp' ),  
  693. 'name' => $this->get_layers_field_name( 'background', 'repeat' ),  
  694. 'id' => $this->get_layers_field_id( 'background', 'repeat' ),  
  695. 'value' => ( isset( $this->values['background']['repeat'] ) ) ? $this->values['background']['repeat'] : NULL,  
  696. 'options' => array( 
  697. 'no-repeat' => __( 'No Repeat', 'layerswp' ),  
  698. 'repeat' => __( 'Repeat', 'layerswp' ),  
  699. 'repeat-x' => __( 'Repeat Horizontal', 'layerswp' ),  
  700. 'repeat-y' => __( 'Repeat Vertical', 'layerswp' ) 
  701. ),  
  702. 'data' => array( 
  703. 'show-if-selector' => '#' . $this->get_layers_field_id( 'background', 'image' ),  
  704. 'show-if-value' => '',  
  705. 'show-if-operator' => '!==' 
  706. ),  
  707. ); 
  708. $defaults['elements']['background-position'] = array( 
  709. 'type' => 'select',  
  710. 'label' => __( 'Background Position', 'layerswp' ),  
  711. 'name' => $this->get_layers_field_name( 'background', 'position' ),  
  712. 'id' => $this->get_layers_field_id( 'background', 'position' ),  
  713. 'value' => ( isset( $this->values['background']['position'] ) ) ? $this->values['background']['position'] : NULL,  
  714. 'options' => array( 
  715. 'center' => __( 'Center', 'layerswp' ),  
  716. 'top' => __( 'Top', 'layerswp' ),  
  717. 'bottom' => __( 'Bottom', 'layerswp' ),  
  718. 'left' => __( 'Left', 'layerswp' ),  
  719. 'right' => __( 'Right', 'layerswp' ) 
  720. ),  
  721. 'data' => array( 
  722. 'show-if-selector' => '#' . $this->get_layers_field_id( 'background', 'image' ),  
  723. 'show-if-value' => '',  
  724. 'show-if-operator' => '!==' 
  725. ),  
  726. ); 
  727. if( !class_exists( 'Layers_Pro' ) ) { 
  728. $defaults['elements']['background-parallax'] = array( 
  729. 'type' => 'checkbox',  
  730. 'label' => __( 'Parallax <span class="layers-inline-upsell">Available in <a href="https://www.layerswp.com/layers-pro/?ref=obox&utm_source=layers%20theme&utm_medium=link&utm_campaign=Layers%20Pro%20Upsell&utm_content=Widget%20Parallax%20Upsell" target="_blank">Pro</a></span>', 'layerswp' ),  
  731. 'name' => $this->get_layers_field_name( 'background', 'parallax' ),  
  732. 'id' => $this->get_layers_field_id( 'background', 'parallax' ),  
  733. 'data' => array( 
  734. 'show-if-selector' => '#' . $this->get_layers_field_id( 'background', 'image' ),  
  735. 'show-if-value' => '',  
  736. 'show-if-operator' => '!==' 
  737. ),  
  738. 'disabled' => true 
  739. ); 
  740. $defaults['elements']['background-stretch'] = array( 
  741. 'type' => 'checkbox',  
  742. 'label' => __( 'Stretch', 'layerswp' ),  
  743. 'name' => $this->get_layers_field_name( 'background', 'stretch' ),  
  744. 'id' => $this->get_layers_field_id( 'background', 'stretch' ),  
  745. 'value' => ( isset( $this->values['background']['stretch'] ) ) ? $this->values['background']['stretch'] : NULL,  
  746. 'data' => array( 
  747. 'show-if-selector' => '#' . $this->get_layers_field_id( 'background', 'image' ),  
  748. 'show-if-value' => '',  
  749. 'show-if-operator' => '!==' 
  750. ),  
  751. ); 
  752. $defaults['elements']['background-darken'] = array( 
  753. 'type' => 'checkbox',  
  754. 'label' => __( 'Darken', 'layerswp' ),  
  755. 'name' => $this->get_layers_field_name( 'background', 'darken' ),  
  756. 'id' => $this->get_layers_field_id( 'background', 'darken' ),  
  757. 'value' => ( isset( $this->values['background']['darken'] ) ) ? $this->values['background']['darken'] : NULL,  
  758. ); 
  759.  
  760. $args = $this->merge_component( $defaults, $args ); 
  761.  
  762. $this->render_control( $key, apply_filters( 'layerswp_background_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  763.  
  764. /** 
  765. * Call To Action Customization - Static Option 
  766. * @param array $args Additional arguments to pass to this function 
  767. */ 
  768. public function buttons_component( $args = array() ) { 
  769.  
  770. // If there is no args information provided, can the operation 
  771. if ( NULL == $this->args ) 
  772. return; 
  773.  
  774. // Set a key for this input 
  775. $key = 'buttons'; 
  776.  
  777. // Setup icon CSS 
  778. $defaults['icon-css'] = 'icon-call-to-action'; 
  779.  
  780. // Add a Label 
  781. $defaults['label'] = __( 'Buttons', 'layerswp' ); 
  782.  
  783. // Add elements 
  784. $defaults['elements'] = array( 
  785.  
  786. // New 
  787. 'buttons-size' => array( 
  788. 'type' => 'select',  
  789. 'label' => __( 'Size', 'layerswp' ),  
  790. 'name' => $this->get_layers_field_name( 'buttons', 'buttons-size' ),  
  791. 'id' => $this->get_layers_field_id( 'buttons', 'buttons-size' ),  
  792. 'value' => ( isset( $this->values['buttons']['buttons-size'] ) ) ? $this->values['buttons']['buttons-size'] : NULL,  
  793. 'options' => array( 
  794. 'small' => __( 'Small', 'layerswp' ),  
  795. 'medium' => __( 'Medium', 'layerswp' ),  
  796. 'large' => __( 'Large', 'layerswp' ) 
  797. ),  
  798.  
  799. // Only this one used to be here. 
  800. 'buttons-background-color' => array( 
  801. 'type' => 'color',  
  802. 'label' => __( 'Background Color', 'layerswp' ),  
  803. 'name' => $this->get_layers_field_name( 'buttons', 'background-color' ),  
  804. 'id' => $this->get_layers_field_id( 'buttons', 'background-color' ),  
  805. 'value' => ( isset( $this->values['buttons']['background-color'] ) ) ? $this->values['buttons']['background-color'] : NULL 
  806. ),  
  807.  
  808. ); 
  809.  
  810. if( !class_exists( 'Layers_Pro' ) ) { 
  811. $defaults['elements']['buttons-upsell'] = array( 
  812. 'type' => 'html',  
  813. 'html' => '<div class="layers-upsell-tag"> 
  814. <span class="layers-upsell-title">Upgrade to Layers Pro</span> 
  815. <div class="description customize-control-description"> 
  816. Want more control over your button styling and sizes? <a target="_blank" href="https://www.layerswp.com/layers-pro/?ref=obox&utm_source=layers%20theme&utm_medium=link&utm_campaign=Layers%20Pro%20Upsell&utm_content=Widget%20Button%20Control">Purchase Layers Pro</a> to unlock the full power of Layers! 
  817. </div> 
  818. </div>' 
  819. ); 
  820.  
  821. $args = $this->merge_component( $defaults, $args ); 
  822.  
  823. $this->render_control( $key, apply_filters( 'layerswp_button_colors_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  824. /** 
  825. * Advanced - Static Option 
  826. * @param array $args Additional arguments to pass to this function 
  827. */ 
  828. public function advanced_component( $args = array() ) { 
  829.  
  830. // If there is no args information provided, can the operation 
  831. if ( NULL == $this->args ) 
  832. return; 
  833.  
  834. // Set a key for this input 
  835. $key = 'advanced'; 
  836.  
  837. // Setup icon CSS 
  838. $defaults['icon-css'] = 'icon-settings'; 
  839.  
  840. // Add a Label 
  841. $defaults['label'] = __( 'Advanced', 'layerswp' ); 
  842.  
  843. // Add elements 
  844. $defaults['elements'] = array( 
  845. 'padding' => array( 
  846. 'type' => 'trbl-fields',  
  847. 'label' => __( 'Padding (px)', 'layerswp' ),  
  848. 'name' => $this->get_layers_field_name( 'advanced', 'padding' ),  
  849. 'id' => $this->get_layers_field_id( 'advanced', 'padding' ),  
  850. 'value' => ( isset( $this->values['advanced']['padding'] ) ) ? $this->values['advanced']['padding'] : NULL 
  851. ),  
  852. 'margin' => array( 
  853. 'type' => 'trbl-fields',  
  854. 'label' => __( 'Margin (px)', 'layerswp' ),  
  855. 'name' => $this->get_layers_field_name( 'advanced', 'margin' ),  
  856. 'id' => $this->get_layers_field_id( 'advanced', 'margin' ),  
  857. 'value' => ( isset( $this->values['advanced']['margin'] ) ) ? $this->values['advanced']['margin'] : NULL 
  858. ),  
  859. 'anchor' => array( 
  860. 'type' => 'text',  
  861. 'label' => __( 'Custom Anchor', 'layerswp' ),  
  862. 'name' => $this->get_layers_field_name( 'advanced', 'anchor' ) ,  
  863. 'id' => $this->get_layers_field_id( 'advanced', 'anchor' ) ,  
  864. 'value' => ( isset( $this->values['advanced']['anchor'] ) ) ? $this->values['advanced']['anchor'] : NULL 
  865. ),  
  866. 'customclass' => array( 
  867. 'type' => 'text',  
  868. 'label' => __( 'Custom Class(es)', 'layerswp' ),  
  869. 'name' => $this->get_layers_field_name( 'advanced', 'customclass' ),  
  870. 'id' => $this->get_layers_field_id( 'advanced', 'customclass' ),  
  871. 'value' => ( isset( $this->values['advanced']['customclass'] ) ) ? $this->values['advanced']['customclass'] : NULL,  
  872. 'placeholder' => 'example-class' 
  873. ),  
  874. 'customcss' => array( 
  875. 'type' => 'textarea',  
  876. 'label' => __( 'Custom CSS', 'layerswp' ),  
  877. 'name' => $this->get_layers_field_name( 'advanced', 'customcss' ),  
  878. 'id' => $this->get_layers_field_id( 'advanced', 'customcss' ),  
  879. 'value' => ( isset( $this->values['advanced']['customcss'] ) ) ? $this->values['advanced']['customcss'] : NULL,  
  880. 'placeholder' => ".classname { color: #333; }" 
  881. ),  
  882. 'widget-id' => array( 
  883. 'type' => 'text',  
  884. 'label' => __( 'Widget ID', 'layerswp' ),  
  885. 'disabled' => FALSE,  
  886. 'value' => '#' . str_replace( 'widget-layers', 'layers', str_ireplace( '-design' , '', $this->args['id'] ) ) 
  887. ); 
  888.  
  889. $args = $this->merge_component( $defaults, $args ); 
  890.  
  891. $this->render_control( $key, apply_filters( 'layerswp_advanced_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  892.  
  893. /** 
  894. * Custom Compontent 
  895. * @param string $key Simply the key and classname for the icon,  
  896. * @param array $args Component arguments, including the form items 
  897. */ 
  898. public function custom_component( $key = NULL, $args = array() ) { 
  899.  
  900. if ( empty( $args ) ) 
  901. return; 
  902.  
  903. // If there is no args information provided, can the operation 
  904. if ( NULL == $this->args ) 
  905. return; 
  906.  
  907. // Render Control 
  908. $this->render_control( $key, apply_filters( 'layerswp_custom_component_args', $args, $key, $this->type, $this->args, $this->values ) ); 
  909.  
  910. /** 
  911. * Merge Compontent 
  912. */ 
  913. public function merge_component( $defaults, $args ) { 
  914.  
  915. // Grab the elements and unset them - so we can work with them individually. 
  916. $defaults_elements = isset( $defaults['elements'] ) ? $defaults['elements'] : array() ; 
  917. if ( isset( $defaults['elements'] ) ) unset( $defaults['elements'] ); 
  918.  
  919. $args_elements = isset( $args['elements'] ) ? $args['elements'] : array() ; 
  920. if ( isset( $args['elements'] ) ) unset( $args['elements'] ); 
  921.  
  922. // New collection of elements consisting of a specific combo of the $defaults and the $args. 
  923. $new_elements = array(); 
  924.  
  925. foreach ( $args_elements as $args_key => $args_value ) { 
  926.  
  927. if ( is_string( $args_value ) && isset( $defaults_elements[ $args_value ] ) ) { 
  928.  
  929. // This case means the caller has specified a custom $args 'elements' config 
  930. // but has only passed a ref to the input by it's 'string 'background-image' 
  931. // allowing them to reposition the input without redefining all the settings 
  932. // the input. 
  933. $new_elements[ $args_value ] = $defaults_elements[ $args_value ]; 
  934.  
  935. // We've got what we needed from this element so remove it from the reference array. 
  936. if ( isset( $defaults_elements[ $args_key ] ) ) { 
  937. unset( $defaults_elements[ $args_value ] ); 
  938. else if( isset( $defaults_elements[ $args_key ] ) && is_array( $defaults_elements[ $args_key ] ) && is_array( $args_elements[ $args_key ] ) ) { 
  939.  
  940. // This case means the caller intends to combine the defaults with new 
  941. // parameters, keeping the existing fields but adding new things to it 
  942. $new_elements[ $args_key ] = $args_elements[ $args_key ] + $defaults_elements[ $args_key ]; 
  943. else if ( is_array( $args_value ) ) { 
  944.  
  945. // This case means the caller has specified a custom $args 'elements' config 
  946. // and has specified their own custom input field config - allowing them to 
  947. // create a new custom field. 
  948. $new_elements[ $args_key ] = $args_value; 
  949.  
  950. // We've got what we needed from this element so remove it from the reference array. 
  951. if ( isset( $defaults_elements[ $args_key ] ) ) { 
  952. unset( $defaults_elements[ $args_key ] ); 
  953.  
  954. // This handles merging the important non-elements like 'icon-css' and 'title' 
  955. $args = array_merge( $defaults, $args ); 
  956.  
  957. // Either 'replace' or 'merge' the new input - so either show only the ones you have chosen 
  958. // or show the ones you have chosen after the defaults of the component. 
  959. if ( isset( $args['elements_combine'] ) && 'replace' === $args['elements_combine'] ) { 
  960. $args['elements'] = $new_elements; 
  961. else{ // 'merge' or anything else. 
  962. $args['elements'] = array_merge( $defaults_elements, $new_elements ); 
  963.  
  964. return $args; 
  965.  
  966. /** 
  967. * Widget name generation (replaces get_custom_field_id) 
  968. * @param string $field_name_1 Level 1 name 
  969. * @param string $field_name_2 Level 2 name 
  970. * @param string $field_name_3 Level 3 name 
  971. * @return string Name attribute 
  972. */ 
  973. function get_layers_field_name( $field_name_1 = '', $field_name_2 = '', $field_name_3 = '' ) { 
  974.  
  975. // If we don't have these important args details then bail. 
  976. if ( ! isset( $this->args['name'] ) ) return; 
  977.  
  978. // Compile the first part. 
  979. $string = $this->args['name']; 
  980.  
  981. // Now add any custom strings passed as args. 
  982. if( '' != $field_name_1 ) $string .= '[' . $field_name_1 . ']'; 
  983. if( '' != $field_name_2 ) $string .= '[' . $field_name_2 . ']'; 
  984. if( '' != $field_name_3 ) $string .= '[' . $field_name_3 . ']'; 
  985.  
  986. if ( (bool) layers_get_theme_mod( 'dev-switch-widget-field-names' ) ) { 
  987. $debug_string = substr( $string, ( strpos( $string, ']' ) + 1 ), strlen( $string ) ); 
  988. echo '<span class="layers-widget-defaults-debug">' . $debug_string . '</span><br />'; 
  989.  
  990. return $string; 
  991.  
  992. /** 
  993. * Widget id generation (replaces get_custom_field_id) 
  994. * @param string $field_name_1 Level 1 id 
  995. * @param string $field_name_2 Level 2 id 
  996. * @param string $field_name_3 Level 3 id 
  997. * @return string Id attribute 
  998. */ 
  999. function get_layers_field_id( $field_name_1 = '', $field_name_2 = '', $field_id = '' ) { 
  1000.  
  1001. // If we don't have these important args details then bail. 
  1002. if ( ! isset( $this->args['id'] ) ) return; 
  1003.  
  1004. // Compile the first part. 
  1005. $string = $this->args['id']; 
  1006.  
  1007. // Now add any custom strings passed as args. 
  1008. if( '' != $field_name_1 ) $string .= '-' . $field_name_1; 
  1009. if( '' != $field_name_2 ) $string .= '-' . $field_name_2; 
  1010. if( '' != $field_id ) $string .= '-' . $field_id; 
  1011.  
  1012. return $string; 
  1013.  
  1014. } //class Layers_Design_Controller