ReduxFramework_dimensions

The Gravity Forms Advanced File Uploader ReduxFramework dimensions class.

Defined (1)

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

/inc/ReduxFramework/ReduxCore/inc/fields/dimensions/field_dimensions.php  
  1. class ReduxFramework_dimensions { 
  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. $this->parent = $parent; 
  10. $this->field = $field; 
  11. $this->value = $value; 
  12. } //function 
  13.  
  14. /** 
  15. * Field Render Function. 
  16. * Takes the vars and outputs the HTML for the field in the settings 
  17. * @since ReduxFramework 1.0.0 
  18. */ 
  19. function render() { 
  20.  
  21. /** 
  22. * So, in_array() wasn't doing it's job for checking a passed array for a proper value. 
  23. * It's wonky. It only wants to check the keys against our array of acceptable values, and not the key's 
  24. * value. So we'll use this instead. Fortunately, a single no array value can be passed and it won't 
  25. * take a dump. 
  26. */ 
  27.  
  28. // No errors please 
  29. $defaults = array( 
  30. 'width' => true,  
  31. 'height' => true,  
  32. 'units_extended' => false,  
  33. 'units' => 'px',  
  34. 'mode' => array( 
  35. 'width' => false,  
  36. 'height' => false,  
  37. ),  
  38. ); 
  39.  
  40. $this->field = wp_parse_args( $this->field, $defaults ); 
  41.  
  42. $defaults = array( 
  43. 'width' => '',  
  44. 'height' => '',  
  45. 'units' => 'px' 
  46. ); 
  47.  
  48. $this->value = wp_parse_args( $this->value, $defaults ); 
  49.  
  50. if ( isset( $this->value['unit'] ) ) { 
  51. $this->value['units'] = $this->value['unit']; 
  52.  
  53. /** 
  54. * Acceptable values checks. If the passed variable doesn't pass muster, we unset them 
  55. * and reset them with default values to avoid errors. 
  56. */ 
  57.  
  58. // If units field has a value but is not an acceptable value, unset the variable 
  59. if ( isset( $this->field['units'] ) && ! Redux_Helpers::array_in_array( $this->field['units'], array( 
  60. '',  
  61. false,  
  62. '%',  
  63. 'in',  
  64. 'cm',  
  65. 'mm',  
  66. 'em',  
  67. 'ex',  
  68. 'pt',  
  69. 'pc',  
  70. 'px' 
  71. ) ) 
  72. ) { 
  73. unset( $this->field['units'] ); 
  74.  
  75. //if there is a default unit value but is not an accepted value, unset the variable 
  76. if ( isset( $this->value['units'] ) && ! Redux_Helpers::array_in_array( $this->value['units'], array( 
  77. '',  
  78. '%',  
  79. 'in',  
  80. 'cm',  
  81. 'mm',  
  82. 'em',  
  83. 'ex',  
  84. 'pt',  
  85. 'pc',  
  86. 'px' 
  87. ) ) 
  88. ) { 
  89. unset( $this->value['units'] ); 
  90.  
  91. /** 
  92. * Since units field could be an array, string value or bool (to hide the unit field) 
  93. * we need to separate our functions to avoid those nasty PHP index notices! 
  94. */ 
  95.  
  96. // if field units has a value and IS an array, then evaluate as needed. 
  97. if ( isset( $this->field['units'] ) && ! is_array( $this->field['units'] ) ) { 
  98.  
  99. //if units fields has a value but units value does not then make units value the field value 
  100. if ( isset( $this->field['units'] ) && ! isset( $this->value['units'] ) || $this->field['units'] == false ) { 
  101. $this->value['units'] = $this->field['units']; 
  102.  
  103. // If units field does NOT have a value and units value does NOT have a value, set both to blank (default?) 
  104. } else if ( ! isset( $this->field['units'] ) && ! isset( $this->value['units'] ) ) { 
  105. $this->field['units'] = 'px'; 
  106. $this->value['units'] = 'px'; 
  107.  
  108. // If units field has NO value but units value does, then set unit field to value field 
  109. } else if ( ! isset( $this->field['units'] ) && isset( $this->value['units'] ) ) { 
  110. $this->field['units'] = $this->value['units']; 
  111.  
  112. // if unit value is set and unit value doesn't equal unit field (coz who knows why) 
  113. // then set unit value to unit field 
  114. } elseif ( isset( $this->value['units'] ) && $this->value['units'] !== $this->field['units'] ) { 
  115. $this->value['units'] = $this->field['units']; 
  116.  
  117. // do stuff based on unit field NOT set as an array 
  118. } elseif ( isset( $this->field['units'] ) && is_array( $this->field['units'] ) ) { 
  119. // nothing to do here, but I'm leaving the construct just in case I have to debug this again. 
  120.  
  121. echo '<fieldset id="' . $this->field['id'] . '" class="redux-dimensions-container" data-id="' . $this->field['id'] . '">'; 
  122.  
  123. if ( isset( $this->field['select2'] ) ) { // if there are any let's pass them to js 
  124. $select2_params = json_encode( $this->field['select2'] ); 
  125. $select2_params = htmlspecialchars( $select2_params, ENT_QUOTES ); 
  126.  
  127. echo '<input type="hidden" class="select2_params" value="' . $select2_params . '">'; 
  128.  
  129.  
  130. // This used to be unit field, but was giving the PHP index error when it was an array,  
  131. // so I changed it. 
  132. echo '<input type="hidden" class="field-units" value="' . $this->value['units'] . '">'; 
  133.  
  134. /** 
  135. * Width 
  136. * */ 
  137. if ( $this->field['width'] === true ) { 
  138. if ( ! empty( $this->value['width'] ) && strpos( $this->value['width'], $this->value['units'] ) === false ) { 
  139. $this->value['width'] = filter_var( $this->value['width'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ); 
  140. if ( $this->field['units'] !== false ) { 
  141. $this->value['width'] .= $this->value['units']; 
  142. echo '<div class="field-dimensions-input input-prepend">'; 
  143. echo '<span class="add-on"><i class="el-icon-resize-horizontal icon-large"></i></span>'; 
  144. echo '<input type="text" class="redux-dimensions-input redux-dimensions-width mini' . $this->field['class'] . '" placeholder="' . __( 'Width', 'redux-framework' ) . '" rel="' . $this->field['id'] . '-width" value="' . filter_var( $this->value['width'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) . '">'; 
  145. echo '<input data-id="' . $this->field['id'] . '" type="hidden" id="' . $this->field['id'] . '-width" name="' . $this->field['name'] . $this->field['name_suffix']. '[width]' . '" value="' . $this->value['width'] . '"></div>'; 
  146.  
  147. /** 
  148. * Height 
  149. * */ 
  150. if ( $this->field['height'] === true ) { 
  151. if ( ! empty( $this->value['height'] ) && strpos( $this->value['height'], $this->value['units'] ) === false ) { 
  152. $this->value['height'] = filter_var( $this->value['height'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ); 
  153. if ( $this->field['units'] !== false ) { 
  154. $this->value['height'] .= $this->value['units']; 
  155. echo '<div class="field-dimensions-input input-prepend">'; 
  156. echo '<span class="add-on"><i class="el-icon-resize-vertical icon-large"></i></span>'; 
  157. echo '<input type="text" class="redux-dimensions-input redux-dimensions-height mini' . $this->field['class'] . '" placeholder="' . __( 'Height', 'redux-framework' ) . '" rel="' . $this->field['id'] . '-height" value="' . filter_var( $this->value['height'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) . '">'; 
  158. echo '<input data-id="' . $this->field['id'] . '" type="hidden" id="' . $this->field['id'] . '-height" name="' . $this->field['name'] . $this->field['name_suffix']. '[height]' . '" value="' . $this->value['height'] . '"></div>'; 
  159.  
  160. /** 
  161. * Units 
  162. * */ 
  163. // If units field is set and units field NOT false then 
  164. // fill out the options object and show it, otherwise it's hidden 
  165. // and the default units value will apply. 
  166. if ( isset( $this->field['units'] ) && $this->field['units'] !== false ) { 
  167. echo '<div class="select_wrapper dimensions-units" original-title="' . __( 'Units', 'redux-framework' ) . '">'; 
  168. echo '<select data-id="' . $this->field['id'] . '" data-placeholder="' . __( 'Units', 'redux-framework' ) . '" class="redux-dimensions redux-dimensions-units select' . $this->field['class'] . '" original-title="' . __( 'Units', 'redux-framework' ) . '" name="' . $this->field['name'] . $this->field['name_suffix']. '[units]' . '">'; 
  169.  
  170. // Extended units, show 'em all 
  171. if ( $this->field['units_extended'] ) { 
  172. $testUnits = array( 'px', 'em', 'rem', '%', 'in', 'cm', 'mm', 'ex', 'pt', 'pc' ); 
  173. } else { 
  174. $testUnits = array( 'px', 'em', 'rem', '%' ); 
  175.  
  176. if ( $this->field['units'] != "" && is_array( $this->field['units'] ) ) { 
  177. $testUnits = $this->field['units']; 
  178.  
  179. if ( in_array( $this->field['units'], $testUnits ) ) { 
  180. echo '<option value="' . $this->field['units'] . '" selected="selected">' . $this->field['units'] . '</option>'; 
  181. } else { 
  182. foreach ( $testUnits as $aUnit ) { 
  183. echo '<option value="' . $aUnit . '" ' . selected( $this->value['units'], $aUnit, false ) . '>' . $aUnit . '</option>'; 
  184. echo '</select></div>'; 
  185. }; 
  186. echo "</fieldset>"; 
  187. } //function 
  188.  
  189. /** 
  190. * Enqueue Function. 
  191. * If this field requires any scripts, or css define this function and register/enqueue the scripts/css 
  192. * @since ReduxFramework 1.0.0 
  193. */ 
  194. function enqueue() { 
  195. wp_enqueue_script( 
  196. 'redux-field-dimensions-js',  
  197. ReduxFramework::$_url . 'inc/fields/dimensions/field_dimensions' . Redux_Functions::isMin() . '.js',  
  198. array( 'jquery', 'select2-js', 'redux-js' ),  
  199. time(),  
  200. true 
  201. ); 
  202.  
  203. redux_enqueue_style( 
  204. $this->parent,  
  205. 'redux-field-dimensions-css',  
  206. ReduxFramework::$_url . 'inc/fields/dimensions/field_dimensions.css',  
  207. ReduxFramework::$_dir . 'inc/fields/dimensions',  
  208. array(),  
  209. time(),  
  210. false 
  211. );  
  212.  
  213. // wp_enqueue_style( 
  214. // 'redux-field-dimensions-css',  
  215. // ReduxFramework::$_url . 'inc/fields/dimensions/field_dimensions.css',  
  216. // time(),  
  217. // true 
  218. // ); 
  219.  
  220. public function output() { 
  221.  
  222. // if field units has a value and IS an array, then evaluate as needed. 
  223. if ( isset( $this->field['units'] ) && ! is_array( $this->field['units'] ) ) { 
  224.  
  225. //if units fields has a value but units value does not then make units value the field value 
  226. if ( isset( $this->field['units'] ) && ! isset( $this->value['units'] ) || $this->field['units'] == false ) { 
  227. $this->value['units'] = $this->field['units']; 
  228.  
  229. // If units field does NOT have a value and units value does NOT have a value, set both to blank (default?) 
  230. } else if ( ! isset( $this->field['units'] ) && ! isset( $this->value['units'] ) ) { 
  231. $this->field['units'] = 'px'; 
  232. $this->value['units'] = 'px'; 
  233.  
  234. // If units field has NO value but units value does, then set unit field to value field 
  235. } else if ( ! isset( $this->field['units'] ) && isset( $this->value['units'] ) ) { 
  236. $this->field['units'] = $this->value['units']; 
  237.  
  238. // if unit value is set and unit value doesn't equal unit field (coz who knows why) 
  239. // then set unit value to unit field 
  240. } elseif ( isset( $this->value['units'] ) && $this->value['units'] !== $this->field['units'] ) { 
  241. $this->value['units'] = $this->field['units']; 
  242.  
  243. // do stuff based on unit field NOT set as an array 
  244. } elseif ( isset( $this->field['units'] ) && is_array( $this->field['units'] ) ) { 
  245. // nothing to do here, but I'm leaving the construct just in case I have to debug this again. 
  246.  
  247. $units = isset( $this->value['units'] ) ? $this->value['units'] : ""; 
  248.  
  249. $height = isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'height'; 
  250. $width = isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'width'; 
  251.  
  252. $cleanValue = array( 
  253. $height => isset( $this->value['height'] ) ? filter_var( $this->value['height'], FILTER_SANITIZE_NUMBER_INT ) : '',  
  254. $width => isset( $this->value['width'] ) ? filter_var( $this->value['width'], FILTER_SANITIZE_NUMBER_INT ) : '',  
  255. ); 
  256.  
  257. $style = ""; 
  258.  
  259. foreach ( $cleanValue as $key => $value ) { 
  260. // Output if it's a numeric entry 
  261. if ( isset( $value ) && is_numeric( $value ) ) { 
  262. $style .= $key . ':' . $value . $units . ';'; 
  263.  
  264. if ( ! empty( $style ) ) { 
  265. if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { 
  266. $keys = implode( ", ", $this->field['output'] ); 
  267. $this->parent->outputCSS .= $keys . "{" . $style . '}'; 
  268.  
  269. if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { 
  270. $keys = implode( ", ", $this->field['compiler'] ); 
  271. $this->parent->compilerCSS .= $keys . "{" . $style . '}'; 
  272. } //function 
  273. } //class