PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/wp-foundation/admin/options-interface.php

https://gitlab.com/Blueprint-Marketing/interoccupy.net
PHP | 349 lines | 240 code | 70 blank | 39 comment | 47 complexity | 73602038e61eccd6979678051e2999cb MD5 | raw file
  1. <?php
  2. /**
  3. * Generates the options fields that are used in the form.
  4. */
  5. function optionsframework_fields() {
  6. global $allowedtags;
  7. $optionsframework_settings = get_option('optionsframework');
  8. // Get the theme name so we can display it up top
  9. $the_theme = wp_get_theme();
  10. $themename = $the_theme->Name;
  11. // Gets the unique option id
  12. if (isset($optionsframework_settings['id'])) {
  13. $option_name = $optionsframework_settings['id'];
  14. }
  15. else {
  16. $option_name = 'optionsframework';
  17. };
  18. $settings = get_option($option_name);
  19. $options = optionsframework_options();
  20. $counter = 0;
  21. $menu = '';
  22. $output = '';
  23. foreach ($options as $value) {
  24. $counter++;
  25. $val = '';
  26. $select_value = '';
  27. $checked = '';
  28. // Wrap all options
  29. if ( ($value['type'] != "heading") && ($value['type'] != "info") ) {
  30. // Keep all ids lowercase with no spaces
  31. $value['id'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($value['id']) );
  32. $id = 'section-' . $value['id'];
  33. $class = 'section ';
  34. if ( isset( $value['type'] ) ) {
  35. $class .= ' section-' . $value['type'];
  36. }
  37. if ( isset( $value['class'] ) ) {
  38. $class .= ' ' . $value['class'];
  39. }
  40. $output .= '<div id="' . esc_attr( $id ) .'" class="' . esc_attr( $class ) . '">'."\n";
  41. $output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n";
  42. $output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
  43. }
  44. // Set default value to $val
  45. if ( isset( $value['std']) ) {
  46. $val = $value['std'];
  47. }
  48. // If the option is already saved, ovveride $val
  49. if ( ($value['type'] != 'heading') && ($value['type'] != 'info')) {
  50. if ( isset($settings[($value['id'])]) ) {
  51. $val = $settings[($value['id'])];
  52. // Striping slashes of non-array options
  53. if (!is_array($val)) {
  54. $val = stripslashes($val);
  55. }
  56. }
  57. }
  58. // If there is a description save it for labels
  59. $explain_value = '';
  60. if ( isset( $value['desc'] ) ) {
  61. $explain_value = $value['desc'];
  62. }
  63. switch ( $value['type'] ) {
  64. // Basic text input
  65. case 'text':
  66. $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="text" value="' . esc_attr( $val ) . '" />';
  67. break;
  68. // Textarea
  69. case 'textarea':
  70. $cols = '8';
  71. $ta_value = '';
  72. if(isset($value['options'])){
  73. $ta_options = $value['options'];
  74. if(isset($ta_options['cols'])){
  75. $cols = $ta_options['cols'];
  76. } else { $cols = '8'; }
  77. }
  78. $val = stripslashes( $val );
  79. $output .= '<textarea id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" cols="'. esc_attr( $cols ) . '" rows="8">' . esc_textarea( $val ) . '</textarea>';
  80. break;
  81. // Select Box
  82. case ($value['type'] == 'select'):
  83. $output .= '<select class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '">';
  84. foreach ($value['options'] as $key => $option ) {
  85. $selected = '';
  86. if( $val != '' ) {
  87. if ( $val == $key) { $selected = ' selected="selected"';}
  88. }
  89. $output .= '<option'. $selected .' value="' . esc_attr( $key ) . '">' . esc_html( $option ) . '</option>';
  90. }
  91. $output .= '</select>';
  92. break;
  93. // Radio Box
  94. case "radio":
  95. $name = $option_name .'['. $value['id'] .']';
  96. foreach ($value['options'] as $key => $option) {
  97. $id = $option_name . '-' . $value['id'] .'-'. $key;
  98. $output .= '<input class="of-input of-radio" type="radio" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="'. esc_attr( $key ) . '" '. checked( $val, $key, false) .' /><label for="' . esc_attr( $id ) . '">' . esc_html( $option ) . '</label>';
  99. }
  100. break;
  101. // Image Selectors
  102. case "images":
  103. $name = $option_name .'['. $value['id'] .']';
  104. foreach ( $value['options'] as $key => $option ) {
  105. $selected = '';
  106. $checked = '';
  107. if ( $val != '' ) {
  108. if ( $val == $key ) {
  109. $selected = ' of-radio-img-selected';
  110. $checked = ' checked="checked"';
  111. }
  112. }
  113. $output .= '<input type="radio" id="' . esc_attr( $value['id'] .'_'. $key) . '" class="of-radio-img-radio" value="' . esc_attr( $key ) . '" name="' . esc_attr( $name ) . '" '. $checked .' />';
  114. $output .= '<div class="of-radio-img-label">' . esc_html( $key ) . '</div>';
  115. $output .= '<img src="' . esc_url( $option ) . '" alt="' . $option .'" class="of-radio-img-img' . $selected .'" onclick="document.getElementById(\''. esc_attr($value['id'] .'_'. $key) .'\').checked=true;" />';
  116. }
  117. break;
  118. // Checkbox
  119. case "checkbox":
  120. $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" '. checked( $val, 1, false) .' />';
  121. $output .= '<label class="explain" for="' . esc_attr( $value['id'] ) . '">' . wp_kses( $explain_value, $allowedtags) . '</label>';
  122. break;
  123. // Multicheck
  124. case "multicheck":
  125. foreach ($value['options'] as $key => $option) {
  126. $checked = '';
  127. $label = $option;
  128. $option = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($key));
  129. $id = $option_name . '-' . $value['id'] . '-'. $option;
  130. $name = $option_name . '[' . $value['id'] . '][' . $option .']';
  131. if ( isset($val[$option]) ) {
  132. $checked = checked($val[$option], 1, false);
  133. }
  134. $output .= '<input id="' . esc_attr( $id ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $name ) . '" ' . $checked . ' /><label for="' . esc_attr( $id ) . '">' . esc_html( $label ) . '</label>';
  135. }
  136. break;
  137. // Color picker
  138. case "color":
  139. $output .= '<div id="' . esc_attr( $value['id'] . '_picker' ) . '" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $val ) . '"></div></div>';
  140. $output .= '<input class="of-color" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '" type="text" value="' . esc_attr( $val ) . '" />';
  141. break;
  142. // Uploader
  143. case "upload":
  144. $output .= optionsframework_medialibrary_uploader( $value['id'], $val, null ); // New AJAX Uploader using Media Library
  145. break;
  146. // Typography
  147. case 'typography':
  148. $typography_stored = $val;
  149. // Font Size
  150. $output .= '<select class="of-typography of-typography-size" name="' . esc_attr( $option_name . '[' . $value['id'] . '][size]' ) . '" id="' . esc_attr( $value['id'] . '_size' ) . '">';
  151. for ($i = 9; $i < 71; $i++) {
  152. $size = $i . 'px';
  153. $output .= '<option value="' . esc_attr( $size ) . '" ' . selected( $typography_stored['size'], $size, false ) . '>' . esc_html( $size ) . '</option>';
  154. }
  155. $output .= '</select>';
  156. // Font Face
  157. $output .= '<select class="of-typography of-typography-face" name="' . esc_attr( $option_name . '[' . $value['id'] . '][face]' ) . '" id="' . esc_attr( $value['id'] . '_face' ) . '">';
  158. $faces = of_recognized_font_faces();
  159. foreach ( $faces as $key => $face ) {
  160. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['face'], $key, false ) . '>' . esc_html( $face ) . '</option>';
  161. }
  162. $output .= '</select>';
  163. // Font Weight
  164. $output .= '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'][style]" id="'. $value['id'].'_style">';
  165. /* Font Style */
  166. $styles = of_recognized_font_styles();
  167. foreach ( $styles as $key => $style ) {
  168. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['style'], $key, false ) . '>'. $style .'</option>';
  169. }
  170. $output .= '</select>';
  171. // Font Color
  172. $output .= '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $typography_stored['color'] ) . '"></div></div>';
  173. $output .= '<input class="of-color of-typography of-typography-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $typography_stored['color'] ) . '" />';
  174. break;
  175. // WPBS Typography - removed font size from std typography set of fields
  176. case 'wpbs_typography':
  177. $wpbs_typography_stored = $val;
  178. // Font Face
  179. $output .= '<select class="of-typography of-typography-face" name="' . esc_attr( $option_name . '[' . $value['id'] . '][face]' ) . '" id="' . esc_attr( $value['id'] . '_face' ) . '">';
  180. $faces = of_recognized_font_faces();
  181. foreach ( $faces as $key => $face ) {
  182. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $wpbs_typography_stored['face'], $key, false ) . '>' . esc_html( $face ) . '</option>';
  183. }
  184. $output .= '</select>';
  185. // Font Weight
  186. $output .= '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'][style]" id="'. $value['id'].'_style">';
  187. /* Font Style */
  188. $styles = of_recognized_font_styles();
  189. foreach ( $styles as $key => $style ) {
  190. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $wpbs_typography_stored['style'], $key, false ) . '>'. $style .'</option>';
  191. }
  192. $output .= '</select>';
  193. // Font Color
  194. $output .= '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $wpbs_typography_stored['color'] ) . '"></div></div>';
  195. $output .= '<input class="of-color of-typography of-typography-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $wpbs_typography_stored['color'] ) . '" />';
  196. break;
  197. // Background
  198. case 'background':
  199. $background = $val;
  200. // Background Color
  201. $output .= '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $background['color'] ) . '"></div></div>';
  202. $output .= '<input class="of-color of-background of-background-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $background['color'] ) . '" />';
  203. // Background Image - New AJAX Uploader using Media Library
  204. if (!isset($background['image'])) {
  205. $background['image'] = '';
  206. }
  207. $output .= optionsframework_medialibrary_uploader( $value['id'], $background['image'], null, '',0,'image');
  208. $class = 'of-background-properties';
  209. if ( '' == $background['image'] ) {
  210. $class .= ' hide';
  211. }
  212. $output .= '<div class="' . esc_attr( $class ) . '">';
  213. // Background Repeat
  214. $output .= '<select class="of-background of-background-repeat" name="' . esc_attr( $option_name . '[' . $value['id'] . '][repeat]' ) . '" id="' . esc_attr( $value['id'] . '_repeat' ) . '">';
  215. $repeats = of_recognized_background_repeat();
  216. foreach ($repeats as $key => $repeat) {
  217. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['repeat'], $key, false ) . '>'. esc_html( $repeat ) . '</option>';
  218. }
  219. $output .= '</select>';
  220. // Background Position
  221. $output .= '<select class="of-background of-background-position" name="' . esc_attr( $option_name . '[' . $value['id'] . '][position]' ) . '" id="' . esc_attr( $value['id'] . '_position' ) . '">';
  222. $positions = of_recognized_background_position();
  223. foreach ($positions as $key=>$position) {
  224. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['position'], $key, false ) . '>'. esc_html( $position ) . '</option>';
  225. }
  226. $output .= '</select>';
  227. // Background Attachment
  228. $output .= '<select class="of-background of-background-attachment" name="' . esc_attr( $option_name . '[' . $value['id'] . '][attachment]' ) . '" id="' . esc_attr( $value['id'] . '_attachment' ) . '">';
  229. $attachments = of_recognized_background_attachment();
  230. foreach ($attachments as $key => $attachment) {
  231. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['attachment'], $key, false ) . '>' . esc_html( $attachment ) . '</option>';
  232. }
  233. $output .= '</select>';
  234. $output .= '</div>';
  235. break;
  236. // Info
  237. case "info":
  238. $class = 'section';
  239. if ( isset( $value['type'] ) ) {
  240. $class .= ' section-' . $value['type'];
  241. }
  242. if ( isset( $value['class'] ) ) {
  243. $class .= ' ' . $value['class'];
  244. }
  245. $output .= '<div class="' . esc_attr( $class ) . '">' . "\n";
  246. if ( isset($value['name']) ) {
  247. $output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n";
  248. }
  249. if ( $value['desc'] ) {
  250. $output .= apply_filters('of_sanitize_info', $value['desc'] ) . "\n";
  251. }
  252. $output .= '<div class="clear"></div></div>' . "\n";
  253. break;
  254. // Heading for Navigation
  255. case "heading":
  256. if ($counter >= 2) {
  257. $output .= '</div>'."\n";
  258. }
  259. $jquery_click_hook = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($value['name']) );
  260. $jquery_click_hook = "of-option-" . $jquery_click_hook;
  261. $menu .= '<a id="'. esc_attr( $jquery_click_hook ) . '-tab" class="nav-tab" title="' . esc_attr( $value['name'] ) . '" href="' . esc_attr( '#'. $jquery_click_hook ) . '">' . esc_html( $value['name'] ) . '</a>';
  262. $output .= '<div class="group" id="' . esc_attr( $jquery_click_hook ) . '">';
  263. $output .= '<h3>' . esc_html( $value['name'] ) . '</h3>' . "\n";
  264. break;
  265. }
  266. if ( ( $value['type'] != "heading" ) && ( $value['type'] != "info" ) ) {
  267. if ( $value['type'] != "checkbox" ) {
  268. $output .= '<br/>';
  269. }
  270. $output .= '</div>';
  271. if ( $value['type'] != "checkbox" ) {
  272. $output .= '<div class="explain">' . wp_kses( $explain_value, $allowedtags) . '</div>'."\n";
  273. }
  274. $output .= '<div class="clear"></div></div></div>'."\n";
  275. }
  276. }
  277. $output .= '</div>';
  278. return array($output,$menu);
  279. }