ReduxFramework_border

The Gravity Forms Advanced File Uploader ReduxFramework border class.

Defined (1)

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

/inc/ReduxFramework/ReduxCore/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-icon-fullscreen icon-large"></i></span><input type="text" class="redux-border-all redux-border-input mini' . $this->field['class'] . '" placeholder="' . __( 'All', 'redux-framework' ) . '" 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="' . ( $this->value['top'] ? $this->value['top'] . 'px' : 0 ) . '">'; 
  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="' . ( $this->value['right'] ? $this->value['right'] . 'px' : 0 ) . '">'; 
  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="' . ( $this->value['bottom'] ? $this->value['bottom'] . 'px' : 0 ) . '">'; 
  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="' . ( $this->value['left'] ? $this->value['left'] . 'px' : 0 ) . '">'; 
  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-icon-arrow-up icon-large"></i></span><input type="text" class="redux-border-top redux-border-input mini' . $this->field['class'] . '" placeholder="' . __( 'Top', 'redux-framework' ) . '" 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-icon-arrow-right icon-large"></i></span><input type="text" class="redux-border-right redux-border-input mini' . $this->field['class'] . '" placeholder="' . __( 'Right', 'redux-framework' ) . '" 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-icon-arrow-down icon-large"></i></span><input type="text" class="redux-border-bottom redux-border-input mini' . $this->field['class'] . '" placeholder="' . __( 'Bottom', 'redux-framework' ) . '" 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-icon-arrow-left icon-large"></i></span><input type="text" class="redux-border-left redux-border-input mini ' . $this->field['class'] . '" placeholder="' . __( 'Left', 'redux-framework' ) . '" 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. 'none' => 'None' 
  134. ); 
  135. echo '<select original-title="' . __( 'Border style', 'redux-framework' ) . '" 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'] . '">'; 
  136. foreach ( $options as $k => $v ) { 
  137. echo '<option value="' . $k . '"' . selected( $value['style'], $k, false ) . '>' . $v . '</option>'; 
  138. echo '</select>'; 
  139. } else { 
  140. 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'] . '">'; 
  141.  
  142. /** 
  143. * Color 
  144. * */ 
  145. if ( $this->field['color'] != false ) { 
  146. $default = isset( $this->field['default']['border-color'] ) ? $this->field['default']['border-color'] : ''; 
  147.  
  148.  
  149. if ( empty( $default ) ) { 
  150. $default = ( isset( $this->field['default']['color'] ) ) ? $this->field['default']['color'] : '#ffffff'; 
  151.  
  152. 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'] . '" />'; 
  153. } else { 
  154. echo '<input type="hidden" id="' . $this->field['id'] . '[border-color]" name="' . $this->field['name'] . $this->field['name_suffix'] . '[border-color]" value="' . $this->value['style'] . '" data-id="' . $this->field['id'] . '">'; 
  155.  
  156. //function 
  157.  
  158. /** 
  159. * Enqueue Function. 
  160. * If this field requires any scripts, or css define this function and register/enqueue the scripts/css 
  161. * @since ReduxFramework 1.0.0 
  162. */ 
  163. function enqueue() { 
  164. $min = Redux_Functions::isMin(); 
  165.  
  166. wp_enqueue_script( 
  167. 'redux-field-border-js',  
  168. ReduxFramework::$_url . 'inc/fields/border/field_border' . $min . '.js',  
  169. array( 'jquery', 'select2-js', 'wp-color-picker', 'redux-js' ),  
  170. time(),  
  171. true 
  172. ); 
  173.  
  174. redux_enqueue_style( 
  175. $this->parent,  
  176. 'redux-field-border-css',  
  177. ReduxFramework::$_url . 'inc/fields/border/field_border.css',  
  178. ReduxFramework::$_dir . 'inc/fields/border',  
  179. array(),  
  180. time(),  
  181. false 
  182. );  
  183.  
  184. // wp_enqueue_style( 
  185. // 'redux-field-border-css',  
  186. // ReduxFramework::$_url . 'inc/fields/border/field_border.css',  
  187. // time(),  
  188. // true 
  189. // ); 
  190. } //function 
  191.  
  192. public function output() { 
  193. if ( isset( $this->field['all'] ) && true == $this->field['all'] ) { 
  194. $borderWidth = isset( $this->value['border-width'] ) ? $this->value['border-width'] : '0px'; 
  195. $val = isset( $this->value['border-top'] ) ? $this->value['border-top'] : $borderWidth; 
  196.  
  197. $this->value['border-top'] = $val; 
  198. $this->value['border-bottom'] = $val; 
  199. $this->value['border-left'] = $val; 
  200. $this->value['border-right'] = $val; 
  201.  
  202. $cleanValue = array( 
  203. 'color' => ! empty( $this->value['border-color'] ) ? $this->value['border-color'] : 'inherit',  
  204. 'style' => ! empty( $this->value['border-style'] ) ? $this->value['border-style'] : 'inherit' 
  205. ); 
  206.  
  207. $borderWidth = '0px'; 
  208. if ( isset( $this->value['border-width'] ) ) { 
  209. $borderWidth = $this->value['border-width']; 
  210.  
  211. $this->field['top'] = isset( $this->field['top'] ) ? $this->field['top'] : true; 
  212. $this->field['bottom'] = isset( $this->field['bottom'] ) ? $this->field['bottom'] : true; 
  213. $this->field['left'] = isset( $this->field['left'] ) ? $this->field['left'] : true; 
  214. $this->field['right'] = isset( $this->field['right'] ) ? $this->field['right'] : true; 
  215.  
  216. if ( $this->field['top'] === true ) { 
  217. $cleanValue['top'] = ! empty( $this->value['border-top'] ) ? $this->value['border-top'] : $borderWidth; 
  218.  
  219. if ( $this->field['bottom'] == true ) { 
  220. $cleanValue['bottom'] = ! empty( $this->value['border-bottom'] ) ? $this->value['border-bottom'] : $borderWidth; 
  221.  
  222. if ( $this->field['left'] === true ) { 
  223. $cleanValue['left'] = ! empty( $this->value['border-left'] ) ? $this->value['border-left'] : $borderWidth; 
  224.  
  225. if ( $this->field['right'] === true ) { 
  226. $cleanValue['right'] = ! empty( $this->value['border-right'] ) ? $this->value['border-right'] : $borderWidth; 
  227.  
  228. $style = ""; 
  229.  
  230. //absolute, padding, margin 
  231. if ( ! isset( $this->field['all'] ) || $this->field['all'] != true ) { 
  232. foreach ( $cleanValue as $key => $value ) { 
  233. if ( $key == "color" || $key == "style" ) { 
  234. continue; 
  235. $style .= 'border-' . $key . ':' . $value . ' ' . $cleanValue['style'] . ' ' . $cleanValue['color'] . ';'; 
  236. } else { 
  237. $style .= 'border:' . $cleanValue['top'] . ' ' . $cleanValue['style'] . ' ' . $cleanValue['color'] . ';'; 
  238.  
  239. if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { 
  240. $keys = implode( ", ", $this->field['output'] ); 
  241. $this->parent->outputCSS .= $keys . "{" . $style . '}'; 
  242.  
  243. if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { 
  244. $keys = implode( ", ", $this->field['compiler'] ); 
  245. $this->parent->compilerCSS .= $keys . "{" . $style . '}'; 
  246. } //class