PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/skeleton/admin/options-interface.php

https://github.com/billortell/skeleton_wp
PHP | 312 lines | 219 code | 60 blank | 33 comment | 45 complexity | 416c180c80636fcea46b6798dc592992 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. $themename = get_theme_data(STYLESHEETPATH . '/style.css');
  10. $themename = $themename['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('/\W/', '', 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. switch ( $value['type'] ) {
  59. // Basic text input
  60. case 'text':
  61. $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="text" value="' . esc_attr( $val ) . '" />';
  62. break;
  63. // Textarea
  64. case 'textarea':
  65. $cols = '8';
  66. $ta_value = '';
  67. if(isset($value['options'])){
  68. $ta_options = $value['options'];
  69. if(isset($ta_options['cols'])){
  70. $cols = $ta_options['cols'];
  71. } else { $cols = '8'; }
  72. }
  73. $val = stripslashes( $val );
  74. $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>';
  75. break;
  76. // Select Box
  77. case ($value['type'] == 'select'):
  78. $output .= '<select class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '">';
  79. foreach ($value['options'] as $key => $option ) {
  80. $selected = '';
  81. if( $val != '' ) {
  82. if ( $val == $key) { $selected = ' selected="selected"';}
  83. }
  84. $output .= '<option'. $selected .' value="' . esc_attr( $key ) . '">' . esc_html( $option ) . '</option>';
  85. }
  86. $output .= '</select>';
  87. break;
  88. // Radio Box
  89. case "radio":
  90. $name = $option_name .'['. $value['id'] .']';
  91. foreach ($value['options'] as $key => $option) {
  92. $id = $option_name . '-' . $value['id'] .'-'. $key;
  93. $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>';
  94. }
  95. break;
  96. // Image Selectors
  97. case "images":
  98. $name = $option_name .'['. $value['id'] .']';
  99. foreach ( $value['options'] as $key => $option ) {
  100. $selected = '';
  101. $checked = '';
  102. if ( $val != '' ) {
  103. if ( $val == $key ) {
  104. $selected = ' of-radio-img-selected';
  105. $checked = ' checked="checked"';
  106. }
  107. }
  108. $output .= '<input type="radio" id="' . esc_attr( $value['id'] .'_'. $key) . '" class="of-radio-img-radio" value="' . esc_attr( $key ) . '" name="' . esc_attr( $name ) . '" '. $checked .' />';
  109. $output .= '<div class="of-radio-img-label">' . esc_html( $key ) . '</div>';
  110. $output .= '<img src="' . esc_url( $option ) . '" alt="' . $option .'" class="of-radio-img-img' . $selected .'" onclick="document.getElementById(\''. esc_attr($value['id'] .'_'. $key) .'\').checked=true;" />';
  111. }
  112. break;
  113. // Checkbox
  114. case "checkbox":
  115. $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" '. checked( $val, 1, false) .' />';
  116. break;
  117. // Multicheck
  118. case "multicheck":
  119. foreach ($value['options'] as $key => $option) {
  120. $checked = '';
  121. $label = $option;
  122. $option = preg_replace('/\W/', '', strtolower($key));
  123. $id = $option_name . '-' . $value['id'] . '-'. $option;
  124. $name = $option_name . '[' . $value['id'] . '][' . $option .']';
  125. if ( isset($val[$option]) ) {
  126. $checked = checked($val[$option], 1, false);
  127. }
  128. $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>';
  129. }
  130. break;
  131. // Color picker
  132. case "color":
  133. $output .= '<div id="' . esc_attr( $value['id'] . '_picker' ) . '" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $val ) . '"></div></div>';
  134. $output .= '<input class="of-color" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '" type="text" value="' . esc_attr( $val ) . '" />';
  135. break;
  136. // Uploader
  137. case "upload":
  138. $output .= optionsframework_medialibrary_uploader( $value['id'], $val, null ); // New AJAX Uploader using Media Library
  139. break;
  140. // Typography
  141. case 'typography':
  142. $typography_stored = $val;
  143. // Font Size
  144. $output .= '<select class="of-typography of-typography-size" name="' . esc_attr( $option_name . '[' . $value['id'] . '][size]' ) . '" id="' . esc_attr( $value['id'] . '_size' ) . '">';
  145. for ($i = 9; $i < 71; $i++) {
  146. $size = $i . 'px';
  147. $output .= '<option value="' . esc_attr( $size ) . '" ' . selected( $typography_stored['size'], $size, false ) . '>' . esc_html( $size ) . '</option>';
  148. }
  149. $output .= '</select>';
  150. // Font Face
  151. $output .= '<select class="of-typography of-typography-face" name="' . esc_attr( $option_name . '[' . $value['id'] . '][face]' ) . '" id="' . esc_attr( $value['id'] . '_face' ) . '">';
  152. $faces = of_recognized_font_faces();
  153. foreach ( $faces as $key => $face ) {
  154. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['face'], $key, false ) . '>' . esc_html( $face ) . '</option>';
  155. }
  156. $output .= '</select>';
  157. // Font Weight
  158. $output .= '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'][style]" id="'. $value['id'].'_style">';
  159. /* Font Style */
  160. $styles = of_recognized_font_styles();
  161. foreach ( $styles as $key => $style ) {
  162. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['style'], $key, false ) . '>'. $style .'</option>';
  163. }
  164. $output .= '</select>';
  165. // Font Color
  166. $output .= '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $typography_stored['color'] ) . '"></div></div>';
  167. $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'] ) . '" />';
  168. break;
  169. // Background
  170. case 'background':
  171. $background = $val;
  172. // Background Color
  173. $output .= '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $background['color'] ) . '"></div></div>';
  174. $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'] ) . '" />';
  175. // Background Image - New AJAX Uploader using Media Library
  176. if (!isset($background['image'])) {
  177. $background['image'] = '';
  178. }
  179. $output .= optionsframework_medialibrary_uploader( $value['id'], $background['image'], null, '',0,'image');
  180. $class = 'of-background-properties';
  181. if ( '' == $background['image'] ) {
  182. $class .= ' hide';
  183. }
  184. $output .= '<div class="' . esc_attr( $class ) . '">';
  185. // Background Repeat
  186. $output .= '<select class="of-background of-background-repeat" name="' . esc_attr( $option_name . '[' . $value['id'] . '][repeat]' ) . '" id="' . esc_attr( $value['id'] . '_repeat' ) . '">';
  187. $repeats = of_recognized_background_repeat();
  188. foreach ($repeats as $key => $repeat) {
  189. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['repeat'], $key, false ) . '>'. esc_html( $repeat ) . '</option>';
  190. }
  191. $output .= '</select>';
  192. // Background Position
  193. $output .= '<select class="of-background of-background-position" name="' . esc_attr( $option_name . '[' . $value['id'] . '][position]' ) . '" id="' . esc_attr( $value['id'] . '_position' ) . '">';
  194. $positions = of_recognized_background_position();
  195. foreach ($positions as $key=>$position) {
  196. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['position'], $key, false ) . '>'. esc_html( $position ) . '</option>';
  197. }
  198. $output .= '</select>';
  199. // Background Attachment
  200. $output .= '<select class="of-background of-background-attachment" name="' . esc_attr( $option_name . '[' . $value['id'] . '][attachment]' ) . '" id="' . esc_attr( $value['id'] . '_attachment' ) . '">';
  201. $attachments = of_recognized_background_attachment();
  202. foreach ($attachments as $key => $attachment) {
  203. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['attachment'], $key, false ) . '>' . esc_html( $attachment ) . '</option>';
  204. }
  205. $output .= '</select>';
  206. $output .= '</div>';
  207. break;
  208. // Info
  209. case "info":
  210. $class = 'section';
  211. if ( isset( $value['type'] ) ) {
  212. $class .= ' section-' . $value['type'];
  213. }
  214. if ( isset( $value['class'] ) ) {
  215. $class .= ' ' . $value['class'];
  216. }
  217. $output .= '<div class="' . esc_attr( $class ) . '">' . "\n";
  218. if ( isset($value['name']) ) {
  219. $output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n";
  220. }
  221. if ( $value['desc'] ) {
  222. $output .= apply_filters('of_sanitize_info', $value['desc'] ) . "\n";
  223. }
  224. $output .= '<div class="clear"></div></div>' . "\n";
  225. break;
  226. // Heading for Navigation
  227. case "heading":
  228. if($counter >= 2){
  229. $output .= '</div>'."\n";
  230. }
  231. $jquery_click_hook = preg_replace('/\W/', '', strtolower($value['name']) );
  232. $jquery_click_hook = "of-option-" . $jquery_click_hook;
  233. $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>';
  234. $output .= '<div class="group" id="' . esc_attr( $jquery_click_hook ) . '">';
  235. $output .= '<h3>' . esc_html( $value['name'] ) . '</h3>' . "\n";
  236. break;
  237. }
  238. if ( ( $value['type'] != "heading" ) && ( $value['type'] != "info" ) ) {
  239. if ( $value['type'] != "checkbox" ) {
  240. $output .= '<br/>';
  241. }
  242. $explain_value = '';
  243. if ( isset( $value['desc'] ) ) {
  244. $explain_value = $value['desc'];
  245. }
  246. $output .= '</div><div class="explain">' . wp_kses( $explain_value, $allowedtags) . '</div>'."\n";
  247. $output .= '<div class="clear"></div></div></div>'."\n";
  248. }
  249. }
  250. $output .= '</div>';
  251. return array($output,$menu);
  252. }