ReduxFramework_image_select

Main ReduxFramework_image_select class.

Defined (1)

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

/inc/ReduxFramework/ReduxCore/inc/fields/image_select/field_image_select.php  
  1. class ReduxFramework_image_select { 
  2.  
  3. /** 
  4. * Field Constructor. 
  5. * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function 
  6. * @since 1.0.0 
  7. * @access public 
  8. * @return void 
  9. */ 
  10. function __construct( $field = array(), $value = '', $parent ) { 
  11. $this->parent = $parent; 
  12. $this->field = $field; 
  13. $this->value = $value; 
  14.  
  15. /** 
  16. * Field Render Function. 
  17. * Takes the vars and outputs the HTML for the field in the settings 
  18. * @since 1.0.0 
  19. * @access public 
  20. * @return void 
  21. */ 
  22. public function render() { 
  23.  
  24. if ( ! empty( $this->field['options'] ) ) { 
  25. echo '<div class="redux-table-container">'; 
  26. echo '<ul class="redux-image-select">'; 
  27.  
  28. $x = 1; 
  29.  
  30. foreach ( $this->field['options'] as $k => $v ) { 
  31.  
  32. if ( ! is_array( $v ) ) { 
  33. $v = array( 'img' => $v ); 
  34.  
  35. if ( ! isset( $v['title'] ) ) { 
  36. $v['title'] = ''; 
  37.  
  38. if ( ! isset( $v['alt'] ) ) { 
  39. $v['alt'] = $v['title']; 
  40.  
  41. $style = ''; 
  42.  
  43. if ( ! empty( $this->field['width'] ) ) { 
  44. $style .= 'width: ' . $this->field['width']; 
  45.  
  46. if ( is_numeric( $this->field['width'] ) ) { 
  47. $style .= 'px'; 
  48.  
  49. $style .= ';'; 
  50. } else { 
  51. $style .= " width: 100%; "; 
  52.  
  53. if ( ! empty( $this->field['height'] ) ) { 
  54. $style .= 'height: ' . $this->field['height']; 
  55.  
  56. if ( is_numeric( $this->field['height'] ) ) { 
  57. $style .= 'px'; 
  58.  
  59. $style .= ';'; 
  60.  
  61. $theValue = $k; 
  62. if ( ! empty( $this->field['tiles'] ) && $this->field['tiles'] == true ) { 
  63. $theValue = $v['img']; 
  64.  
  65. $selected = ( checked( $this->value, $theValue, false ) != '' ) ? ' redux-image-select-selected' : ''; 
  66.  
  67. $presets = ''; 
  68. $is_preset = false; 
  69.  
  70. $this->field['class'] .= ' noUpdate '; 
  71. if ( isset( $this->field['presets'] ) && $this->field['presets'] !== false ) { 
  72. $this->field['class'] = trim($this->field['class']); 
  73. if ( ! isset( $v['presets'] ) ) { 
  74. $v['presets'] = array(); 
  75.  
  76. if ( ! is_array( $v['presets'] ) ) { 
  77. $v['presets'] = json_decode( $v['presets'], true ); 
  78.  
  79. // Only highlight the preset if it's the same 
  80. if ( $selected ) { 
  81. if ( empty( $v['presets'] ) ) { 
  82. $selected = false; 
  83. } else { 
  84. foreach ( $v['presets'] as $pk => $pv ) { 
  85. if ( empty( $pv ) && isset( $this->parent->options[ $pk ] ) && ! empty( $this->parent->options[ $pk ] ) ) { 
  86. $selected = false; 
  87. } else if ( ! empty( $pv ) && ! isset( $this->parent->options[ $pk ] ) ) { 
  88. $selected = false; 
  89. } else if ( isset( $this->parent->options[ $pk ] ) && $this->parent->options[ $pk ] != $pv ) { 
  90. $selected = false; 
  91.  
  92. if ( ! $selected ) { // We're still not using the same preset. Let's unset that shall we? 
  93. $this->value = ""; 
  94. break; 
  95.  
  96. $v['presets']['redux-backup'] = 1; 
  97.  
  98. $presets = ' data-presets="' . htmlspecialchars( json_encode( $v['presets'] ), ENT_QUOTES, 'UTF-8' ) . '"'; 
  99. $is_preset = true; 
  100.  
  101. $this->field['class'] = trim( $this->field['class'] ) . 'redux-presets'; 
  102.  
  103. $is_preset_class = $is_preset ? '-preset-' : ' '; 
  104.  
  105. echo '<li class="redux-image-select">'; 
  106. echo '<label class="' . $selected . ' redux-image-select' . $is_preset_class . $this->field['id'] . '_' . $x . '" for="' . $this->field['id'] . '_' . ( array_search( $k, array_keys( $this->field['options'] ) ) + 1 ) . '">'; 
  107.  
  108. echo '<input type="radio" class="' . $this->field['class'] . '" id="' . $this->field['id'] . '_' . ( array_search( $k, array_keys( $this->field['options'] ) ) + 1 ) . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '" value="' . $theValue . '" ' . checked( $this->value, $theValue, false ) . $presets . '/>'; 
  109. if ( ! empty( $this->field['tiles'] ) && $this->field['tiles'] == true ) { 
  110. echo '<span class="tiles" style="background-image: url(' . $v['img'] . ');" rel="' . $v['img'] . '""> </span>'; 
  111. } else { 
  112. echo '<img src="' . $v['img'] . '" alt="' . $v['alt'] . '" style="' . $style . '"' . $presets . ' />'; 
  113.  
  114. if ( $v['title'] != '' ) { 
  115. echo '<br /><span>' . $v['title'] . '</span>'; 
  116.  
  117. echo '</label>'; 
  118. echo '</li>'; 
  119.  
  120. $x ++; 
  121.  
  122. echo '</ul>'; 
  123. echo '</div>'; 
  124.  
  125. /** 
  126. * Enqueue Function. 
  127. * If this field requires any scripts, or css define this function and register/enqueue the scripts/css 
  128. * @since 1.0.0 
  129. * @access public 
  130. * @return void 
  131. */ 
  132. public function enqueue() { 
  133.  
  134. wp_enqueue_script( 
  135. 'redux-field-image-select-js',  
  136. ReduxFramework::$_url . 'inc/fields/image_select/field_image_select' . Redux_Functions::isMin() . '.js',  
  137. array( 'jquery', 'redux-js' ),  
  138. time(),  
  139. true 
  140. ); 
  141.  
  142. redux_enqueue_style( 
  143. $this->parent,  
  144. 'redux-field-image-select-css',  
  145. ReduxFramework::$_url . 'inc/fields/image_select/field_image_select.css',  
  146. ReduxFramework::$_dir . 'inc/fields/image_select',  
  147. array(),  
  148. time(),  
  149. false 
  150. );  
  151.  
  152. // wp_enqueue_style( 
  153. // 'redux-field-image-select-css',  
  154. // ReduxFramework::$_url . 'inc/fields/image_select/field_image_select.css',  
  155. // time(),  
  156. // true 
  157. // ); 
  158.  
  159. public function getCSS( $mode = '' ) { 
  160. $css = ''; 
  161. $value = $this->value; 
  162.  
  163. $output = ''; 
  164. if ( ! empty( $value ) && ! is_array($value) ) { 
  165. switch ( $mode ) { 
  166. case 'background-image': 
  167. $output = "background-image: url('" . $value . "');"; 
  168. break; 
  169.  
  170. default: 
  171. $output = $mode . ": " . $value . ";"; 
  172.  
  173. $css .= $output; 
  174.  
  175. return $css; 
  176.  
  177. public function output() { 
  178. $mode = ( isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'background-image' ); 
  179.  
  180. if ( ( ! isset( $this->field['output'] ) || ! is_array( $this->field['output'] ) ) && ( ! isset( $this->field['compiler'] ) ) ) { 
  181. return; 
  182.  
  183. $style = $this->getCSS( $mode ); 
  184.  
  185. if ( ! empty( $style ) ) { 
  186.  
  187. if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { 
  188. $keys = implode( ", ", $this->field['output'] ); 
  189. $style = $keys . "{" . $style . '}'; 
  190. $this->parent->outputCSS .= $style; 
  191.  
  192. if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { 
  193. $keys = implode( ", ", $this->field['compiler'] ); 
  194. $style = $keys . "{" . $style . '}'; 
  195. $this->parent->compilerCSS .= $style;