ReduxFramework_border

The evolve ReduxFramework border class.

Defined (1)

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

/library/admin/redux-framework/inc/fields/border/field_border.php  
  1. class ReduxFramework_border { 
  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 ReduxFramework 1.0.0 
  7. */ 
  8. function __construct( $field = array(), $value = '', $parent ) { 
  9.  
  10. $this->parent = $parent; 
  11. $this->field = $field; 
  12. $this->value = $value; 
  13. } //function 
  14.  
  15. private function stripAlphas($s) { 
  16.  
  17. // Regex is our friend. THERE ARE FOUR LIGHTS!! 
  18. return preg_replace('/[^\d.-]/', '', $s); 
  19. }  
  20.  
  21. /** 
  22. * Field Render Function. 
  23. * Takes the vars and outputs the HTML for the field in the settings 
  24. * @since ReduxFramework 1.0.0 
  25. */ 
  26. function render() { 
  27.  
  28. // No errors please 
  29. $defaults = array( 
  30. 'top' => true,  
  31. 'bottom' => true,  
  32. 'all' => true,  
  33. 'style' => true,  
  34. 'color' => true,  
  35. 'left' => true,  
  36. 'right' => true,  
  37. ); 
  38.  
  39. $this->field = wp_parse_args( $this->field, $defaults ); 
  40.  
  41. $defaults = array( 
  42. 'top' => '',  
  43. 'right' => '',  
  44. 'bottom' => '',  
  45. 'left' => '',  
  46. 'color' => '',  
  47. 'style' => '',  
  48. ); 
  49.  
  50. $this->value = wp_parse_args( $this->value, $defaults ); 
  51.  
  52. $value = array( 
  53. 'top' => isset( $this->value['border-top'] ) ? filter_var( $this->value['border-top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ),  
  54. 'right' => isset( $this->value['border-right'] ) ? filter_var( $this->value['border-right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ),  
  55. 'bottom' => isset( $this->value['border-bottom'] ) ? filter_var( $this->value['border-bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ),  
  56. 'left' => isset( $this->value['border-left'] ) ? filter_var( $this->value['border-left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ),  
  57. 'color' => isset( $this->value['border-color'] ) ? $this->value['border-color'] : $this->value['color'],  
  58. 'style' => isset( $this->value['border-style'] ) ? $this->value['border-style'] : $this->value['style'] 
  59. ); 
  60.  
  61. if ( ( isset( $this->value['width'] ) || isset( $this->value['border-width'] ) ) ) { 
  62. if ( isset( $this->value['border-width'] ) && ! empty( $this->value['border-width'] ) ) { 
  63. $this->value['width'] = $this->value['border-width']; 
  64.  
  65. $this->value['width'] = $this->stripAlphas($this->value['width']); 
  66.  
  67. $value['top'] = $this->value['width']; 
  68. $value['right'] = $this->value['width']; 
  69. $value['bottom'] = $this->value['width']; 
  70. $value['left'] = $this->value['width']; 
  71.  
  72. $this->value = $value; 
  73.  
  74. $defaults = array( 
  75. 'top' => '',  
  76. 'right' => '',  
  77. 'bottom' => '',  
  78. 'left' => '',  
  79. ); 
  80.  
  81. $this->value = wp_parse_args( $this->value, $defaults ); 
  82.  
  83. if ( isset( $this->field['select2'] ) ) { // if there are any let's pass them to js 
  84. $select2_params = json_encode( $this->field['select2'] ); 
  85. $select2_params = htmlspecialchars( $select2_params, ENT_QUOTES ); 
  86.  
  87. echo '<input type="hidden" class="select2_params" value="' . $select2_params . '">'; 
  88.  
  89.  
  90. echo '<input type="hidden" class="field-units" value="px">'; 
  91.  
  92. if ( isset( $this->field['all'] ) && $this->field['all'] == true ) { 
  93. echo '<div class="field-border-input input-prepend"><span class="add-on"><i class="el el-fullscreen icon-large"></i></span><input type="text" class="redux-border-all redux-border-input mini ' . $this->field['class'] . '" placeholder="' . __( 'All', 'evolve' ) . '" rel="' . $this->field['id'] . '-all" value="' . $this->value['top'] . '"></div>'; 
  94.  
  95. echo '<input type="hidden" class="redux-border-value" id="' . $this->field['id'] . '-top" name="' . $this->field['name'] . $this->field['name_suffix'] . '[border-top]" value="' . ( isset($this->value['top']) && $this->value['top'] != '' ? $this->value['top'] . 'px' : '' ) . '">'; 
  96. echo '<input type="hidden" class="redux-border-value" id="' . $this->field['id'] . '-right" name="' . $this->field['name'] . $this->field['name_suffix'] . '[border-right]" value="' . ( isset($this->value['right']) && $this->value['right'] != '' ? $this->value['right'] . 'px' : '' ) . '">'; 
  97. echo '<input type="hidden" class="redux-border-value" id="' . $this->field['id'] . '-bottom" name="' . $this->field['name'] . $this->field['name_suffix'] . '[border-bottom]" value="' . ( isset($this->value['bottom']) && $this->value['bottom'] != '' ? $this->value['bottom'] . 'px' : '' ) . '">'; 
  98. echo '<input type="hidden" class="redux-border-value" id="' . $this->field['id'] . '-left" name="' . $this->field['name'] . $this->field['name_suffix'] . '[border-left]" value="' . ( isset($this->value['left']) && $this->value['left'] != '' ? $this->value['left'] . 'px' : '' ) . '">'; 
  99.  
  100. if ( ! isset( $this->field['all'] ) || $this->field['all'] !== true ) { 
  101. /** 
  102. * Top 
  103. * */ 
  104. if ( $this->field['top'] === true ) { 
  105. echo '<div class="field-border-input input-prepend"><span class="add-on"><i class="el el-arrow-up icon-large"></i></span><input type="text" class="redux-border-top redux-border-input mini ' . $this->field['class'] . '" placeholder="' . __( 'Top', 'evolve' ) . '" rel="' . $this->field['id'] . '-top" value="' . $this->value['top'] . '"></div>'; 
  106.  
  107. /** 
  108. * Right 
  109. * */ 
  110. if ( $this->field['right'] === true ) { 
  111. echo '<div class="field-border-input input-prepend"><span class="add-on"><i class="el el-arrow-right icon-large"></i></span><input type="text" class="redux-border-right redux-border-input mini ' . $this->field['class'] . '" placeholder="' . __( 'Right', 'evolve' ) . '" rel="' . $this->field['id'] . '-right" value="' . $this->value['right'] . '"></div>'; 
  112.  
  113. /** 
  114. * Bottom 
  115. * */ 
  116. if ( $this->field['bottom'] === true ) { 
  117. echo '<div class="field-border-input input-prepend"><span class="add-on"><i class="el el-arrow-down icon-large"></i></span><input type="text" class="redux-border-bottom redux-border-input mini ' . $this->field['class'] . '" placeholder="' . __( 'Bottom', 'evolve' ) . '" rel="' . $this->field['id'] . '-bottom" value="' . $this->value['bottom'] . '"></div>'; 
  118.  
  119. /** 
  120. * Left 
  121. * */ 
  122. if ( $this->field['left'] === true ) { 
  123. echo '<div class="field-border-input input-prepend"><span class="add-on"><i class="el el-arrow-left icon-large"></i></span><input type="text" class="redux-border-left redux-border-input mini ' . $this->field['class'] . '" placeholder="' . __( 'Left', 'evolve' ) . '" rel="' . $this->field['id'] . '-left" value="' . $this->value['left'] . '"></div>'; 
  124.  
  125. /** 
  126. * Border-style 
  127. * */ 
  128. if ( $this->field['style'] != false ) { 
  129. $options = array( 
  130. 'solid' => 'Solid',  
  131. 'dashed' => 'Dashed',  
  132. 'dotted' => 'Dotted',  
  133. 'double' => "Double",  
  134. 'none' => 'None' 
  135. ); 
  136. echo '<select original-title="' . __( 'Border style', 'evolve' ) . '" id="' . $this->field['id'] . '[border-style]" name="' . $this->field['name'] . $this->field['name_suffix'] . '[border-style]" class="tips redux-border-style ' . $this->field['class'] . '" rows="6" data-id="' . $this->field['id'] . '">'; 
  137. foreach ( $options as $k => $v ) { 
  138. echo '<option value="' . $k . '"' . selected( $value['style'], $k, false ) . '>' . $v . '</option>'; 
  139. echo '</select>'; 
  140. } else { 
  141. echo '<input type="hidden" id="' . $this->field['id'] . '[border-style]" name="' . $this->field['name'] . $this->field['name_suffix'] . '[border-style]" value="' . $this->value['style'] . '" data-id="' . $this->field['id'] . '">'; 
  142.  
  143. /** 
  144. * Color 
  145. * */ 
  146. if ( $this->field['color'] != false ) { 
  147. $default = isset( $this->field['default']['border-color'] ) ? $this->field['default']['border-color'] : ''; 
  148.  
  149.  
  150. if ( empty( $default ) ) { 
  151. $default = ( isset( $this->field['default']['color'] ) ) ? $this->field['default']['color'] : '#ffffff'; 
  152.  
  153. echo '<input name="' . $this->field['name'] . $this->field['name_suffix'] . '[border-color]" id="' . $this->field['id'] . '-border" class="redux-border-color redux-color redux-color-init ' . $this->field['class'] . '" type="text" value="' . $this->value['color'] . '" data-default-color="' . $default . '" data-id="' . $this->field['id'] . '" />'; 
  154. } else { 
  155. echo '<input type="hidden" id="' . $this->field['id'] . '[border-color]" name="' . $this->field['name'] . $this->field['name_suffix'] . '[border-color]" value="' . $this->value['color'] . '" data-id="' . $this->field['id'] . '">'; 
  156.  
  157. //function 
  158.  
  159. /** 
  160. * Enqueue Function. 
  161. * If this field requires any scripts, or css define this function and register/enqueue the scripts/css 
  162. * @since ReduxFramework 1.0.0 
  163. */ 
  164. function enqueue() { 
  165. $min = Redux_Functions::isMin(); 
  166.  
  167. if (!wp_style_is ( 'select2-css' )) { 
  168. wp_enqueue_style( 'select2-css' ); 
  169.  
  170. if (!wp_style_is ( 'wp-color-picker' )) { 
  171. wp_enqueue_style( 'wp-color-picker' ); 
  172.  
  173. if (!wp_script_is ( 'redux-field-border-js' )) { 
  174. wp_enqueue_script( 
  175. 'redux-field-border-js',  
  176. ReduxFramework::$_url . 'inc/fields/border/field_border' . $min . '.js',  
  177. array( 'jquery', 'select2-js', 'wp-color-picker', 'redux-js' ),  
  178. time(),  
  179. true 
  180. ); 
  181.  
  182. if ($this->parent->args['dev_mode']) { 
  183. if (!wp_style_is ( 'redux-color-picker-css' )) { 
  184. wp_enqueue_style( 'redux-color-picker-css' ); 
  185.  
  186. if (!wp_style_is ( 'redux-field-border-css' )) { 
  187. wp_enqueue_style( 
  188. 'redux-field-border-css',  
  189. ReduxFramework::$_url . 'inc/fields/border/field_border.css',  
  190. array(),  
  191. time(),  
  192. 'all' 
  193. ); 
  194. } //function 
  195.  
  196. public function output() { 
  197. if ( isset( $this->field['all'] ) && true == $this->field['all'] ) { 
  198. $borderWidth = isset( $this->value['border-width'] ) ? $this->value['border-width'] : '0px'; 
  199. $val = isset( $this->value['border-top'] ) ? $this->value['border-top'] : $borderWidth; 
  200.  
  201. $this->value['border-top'] = $val; 
  202. $this->value['border-bottom'] = $val; 
  203. $this->value['border-left'] = $val; 
  204. $this->value['border-right'] = $val; 
  205.  
  206. $cleanValue = array( 
  207. 'color' => ! empty( $this->value['border-color'] ) ? $this->value['border-color'] : '',  
  208. 'style' => ! empty( $this->value['border-style'] ) ? $this->value['border-style'] : '' 
  209. ); 
  210.  
  211. $borderWidth = ''; 
  212. if ( isset( $this->value['border-width'] ) ) { 
  213. $borderWidth = $this->value['border-width']; 
  214.  
  215. $this->field['top'] = isset( $this->field['top'] ) ? $this->field['top'] : true; 
  216. $this->field['bottom'] = isset( $this->field['bottom'] ) ? $this->field['bottom'] : true; 
  217. $this->field['left'] = isset( $this->field['left'] ) ? $this->field['left'] : true; 
  218. $this->field['right'] = isset( $this->field['right'] ) ? $this->field['right'] : true; 
  219.  
  220. if ( $this->field['top'] === true ) { 
  221. $cleanValue['top'] = ! empty( $this->value['border-top'] ) ? $this->value['border-top'] : $borderWidth; 
  222.  
  223. if ( $this->field['bottom'] == true ) { 
  224. $cleanValue['bottom'] = ! empty( $this->value['border-bottom'] ) ? $this->value['border-bottom'] : $borderWidth; 
  225.  
  226. if ( $this->field['left'] === true ) { 
  227. $cleanValue['left'] = ! empty( $this->value['border-left'] ) ? $this->value['border-left'] : $borderWidth; 
  228.  
  229. if ( $this->field['right'] === true ) { 
  230. $cleanValue['right'] = ! empty( $this->value['border-right'] ) ? $this->value['border-right'] : $borderWidth; 
  231.  
  232. $style = ""; 
  233.  
  234. //absolute, padding, margin 
  235. if ( ! isset( $this->field['all'] ) || $this->field['all'] != true ) { 
  236. foreach ( $cleanValue as $key => $value ) { 
  237. if ( $key == "color" || $key == "style" ) { 
  238. continue; 
  239. if (!empty($value)) { 
  240. $style .= 'border-' . $key . ':' . $value . ' ' . $cleanValue['style'] . ' ' . $cleanValue['color'] . ';'; 
  241. } else { 
  242. if (!empty($cleanValue['top'])) { 
  243. $style .= 'border:' . $cleanValue['top'] . ' ' . $cleanValue['style'] . ' ' . $cleanValue['color'] . ';'; 
  244.  
  245. if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { 
  246. $keys = implode( ", ", $this->field['output'] ); 
  247.  
  248. if (!empty($style)) { 
  249. $this->parent->outputCSS .= $keys . "{" . $style . '}'; 
  250.  
  251. if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { 
  252. $keys = implode( ", ", $this->field['compiler'] ); 
  253.  
  254. if (!empty($style)) { 
  255. $this->parent->compilerCSS .= $keys . "{" . $style . '}'; 
  256. } //class