PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/eclipse/core/classy-options/classy-options-framework/classy-options.php

https://github.com/Bochet/festival_lgbt
PHP | 737 lines | 569 code | 122 blank | 46 comment | 113 complexity | 806c5671578ff438811cfb690a7e80e2 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. global $options, $ec_themeslug, $ec_themenamefull;
  3. class ClassyOptions {
  4. function __construct($id, $name = false) {
  5. $this->id = $id;
  6. $this->name = $name ? $name : $id;
  7. $this->options = array();
  8. $this->data = get_option($this->id);
  9. add_action( 'admin_init', array($this, 'admin_init') );
  10. add_action( 'admin_menu', array($this, 'admin_menu') );
  11. }
  12. function admin_menu() {
  13. global $ec_themenamefull;
  14. $page = add_theme_page( $ec_themenamefull.' Options', $ec_themenamefull.' Options', 'edit_theme_options', $this->id, array( $this, 'render' ) );
  15. add_action( "admin_print_styles-$page", array($this, 'load_styles') );
  16. add_action( "admin_print_scripts-$page", array($this, 'load_scripts') );
  17. add_action( "wp_before_admin_bar_render", array($this, 'add_admin_bar') );
  18. }
  19. function admin_init() {
  20. register_setting( $this->id, $this->id, array($this, 'validate_data') );
  21. }
  22. function load_styles() {
  23. wp_enqueue_style('admin-style', CLASSY_OPTIONS_FRAMEWORK_URL.'css/admin-style.css');
  24. wp_enqueue_style('color-picker', CLASSY_OPTIONS_FRAMEWORK_URL.'css/colorpicker.css');
  25. wp_enqueue_style('thickbox');
  26. }
  27. function load_scripts() {
  28. // Inline scripts from options-interface.php
  29. add_action('admin_head', array($this, 'admin_head'));
  30. // Enqueued scripts
  31. wp_enqueue_script('jquery-ui-core');
  32. wp_enqueue_script('jquery-ui-sortable');
  33. wp_enqueue_script('thickbox');
  34. wp_enqueue_script('color-picker', CLASSY_OPTIONS_FRAMEWORK_URL.'js/colorpicker.js', array('jquery'));
  35. wp_enqueue_script('options-custom', CLASSY_OPTIONS_FRAMEWORK_URL.'js/options-custom.js', array('jquery'));
  36. wp_enqueue_script('theme-options-custom', get_template_directory_uri().'/library/js/theme-options-custom.js', array('jquery'));
  37. wp_enqueue_script('media-uploader', CLASSY_OPTIONS_FRAMEWORK_URL.'js/of-medialibrary-uploader.js', array('jquery'));
  38. }
  39. function add_admin_bar() {
  40. global $wp_admin_bar;
  41. $wp_admin_bar->add_menu( array(
  42. 'parent' => 'appearance',
  43. 'id' => $this->id,
  44. 'title' => $this->name,
  45. 'href' => admin_url( 'themes.php?page=' . $this->id )
  46. ));
  47. }
  48. function admin_head() {
  49. do_action( 'optionsframework_custom_scripts' );
  50. }
  51. function get($id) {
  52. $option = $this->find_option_by_id($id);
  53. return isset( $this->data[$id] ) ? $this->data[$id] :
  54. (( $option && isset($option['default'] )) ? $option['default'] : null);
  55. }
  56. function find_option_by_id($id) {
  57. foreach($this->options as $option) {
  58. if(isset($option['id']) && $option['id'] == $id) {
  59. return $option;
  60. }
  61. }
  62. return false;
  63. }
  64. function add( $option ) {
  65. $this->options[] = $option;
  66. }
  67. function render() {
  68. global $ec_themenamefull;
  69. settings_errors(); ?>
  70. <div class="wrap">
  71. <div class="upgrade-callout">
  72. <p><img src="<?php echo get_template_directory_uri() ;?>/images/chimp.png" alt="CyberChimps" /><strong>Welcome to <?php echo $ec_themenamefull; ?>! Learn more now about upgrading to <a href="http://cyberchimps.com/eclipsepro/" target="_blank"><?php echo $ec_themenamefull; ?> Pro</a> today.</p>
  73. <div class="social-container">
  74. <div class="social">
  75. <a href="https://twitter.com/cyberchimps" class="twitter-follow-button" data-show-count="false" data-size="small">Follow @cyberchimps</a>
  76. <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
  77. </div>
  78. <div class="social">
  79. <iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fcyberchimps.com%2F&amp;send=false&amp;layout=button_count&amp;width=200&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:21px;" allowTransparency="true"></iframe>
  80. </div>
  81. </div>
  82. </div>
  83. <div id="of_container">
  84. <form action="options.php" method="post" enctype="multipart/form-data">
  85. <?php settings_fields($this->id); ?>
  86. <div id="header">
  87. <div class="logo">
  88. <h2><?php echo $ec_themenamefull; ?> Options</h2>
  89. </div>
  90. <div class="upgradepro"><a href="http://cyberchimps.com/eclipsepro/" target="_blank">Upgrade to Eclipse Pro</a>
  91. </div>
  92. <div class="clear"></div>
  93. <p class="submit">
  94. <input type="submit" class="button-primary" name="update" value="<?php esc_attr_e( 'Save Options' ); ?>" />
  95. </p>
  96. <div class="menu">
  97. <ul class="buttons">
  98. <li><a href="http://cyberchimps.com/store/" target="_blank"><?php printf( __( 'CyberChimps Store', 'ifeature' )); ?></a></li>
  99. <li><a href="http://cyberchimps.com/support" target="_blank"><?php printf( __( 'Support', 'ifeature' )); ?></a></li>
  100. <li><a href="http://cyberchimps.com/eclipse/docs/" target="_blank"> <?php printf( __( 'Documentation', 'ifeature' )); ?></a></li>
  101. <li><a href="http://cyberchimps.com/forum/" target="_blank"><?php printf( __( 'Forum', 'ifeature' )); ?></a></li>
  102. <li><a href="http://twitter.com/#!/cyberchimps" target="_blank"><?php printf( __( 'Twitter', 'ifeature' ));?></a></li>
  103. <li><a href="http://facebook.com/cyberchimps/" target="_blank"><?php printf( __( 'Facebook', 'ifeature' ));?></a></li>
  104. </ul>
  105. </div>
  106. </div>
  107. <div id="main">
  108. <?php $return = $this->fields(); ?>
  109. <div id="of-nav">
  110. <ul class="nav">
  111. <?php echo $return[1]; ?>
  112. </ul>
  113. </div>
  114. <div id="content">
  115. <?php echo $return[0]; /* Settings */ ?>
  116. </div>
  117. <div class="clear"></div>
  118. </div>
  119. <div class="of_admin_bar">
  120. <div id="top"><a href='#TOP'><img src="<?php echo get_template_directory_uri() ;?>/images/options/top.png" /></a></div>
  121. <input type="submit" class="reset-button button-secondary" name="reset" value="<?php esc_attr_e( 'Restore Defaults' ); ?>" onclick="return confirm( '<?php print esc_js( __( 'Click OK to reset. Any theme settings will be lost!', 'response' ) ); ?>' );" />
  122. <div class="chimps"><a href="http://cyberchimps.com/" target="_blank"><img src="<?php echo get_template_directory_uri() ;?>/images/options/cyberchimpsmini.png" /></a></div>
  123. </div>
  124. <div class="clear"></div>
  125. </form>
  126. </div> <!-- / #of_container -->
  127. </div> <!-- / .wrap -->
  128. <?php
  129. }
  130. function default_data() {
  131. $ret = array();
  132. foreach($this->options as $option) {
  133. if(isset($option['id']) && isset($option['default'])) {
  134. $ret[$option['id']] = $option['default'];
  135. }
  136. }
  137. return $ret;
  138. }
  139. function validate_data( $input ) {
  140. /*
  141. * Restore Defaults.
  142. *
  143. * In the event that the user clicked the "Restore Defaults"
  144. * button, the options defined in the theme's options.php
  145. * file will be added to the option for the active theme.
  146. */
  147. if ( isset( $_POST['reset'] ) || ! isset( $_POST['update'] ) ) {
  148. add_settings_error( $this->id, 'restore_defaults', __( 'Default options restored.', 'optionsframework' ), 'updated fade' );
  149. return $this->default_data();
  150. }
  151. if( isset( $_POST['import' ] ) ) {
  152. if( trim( $_POST['import' ] ) ) {
  153. $string = stripslashes( trim( $_POST['import'] ) );
  154. $try = unserialize( $string );
  155. if($try) {
  156. add_settings_error( $this->id, 'import', __( 'Options Imported', 'optionsframework' ), 'updated fade' );
  157. return $try;
  158. } else {
  159. add_settings_error( $this->id, 'import', __( 'Invalid Data for Import', 'optionsframework' ), 'updated fade' );
  160. }
  161. }
  162. }
  163. /*
  164. * Update Settings.
  165. */
  166. if ( isset( $_POST['update'] ) ) {
  167. $clean = array();
  168. foreach ( $this->options as $option ) {
  169. if ( ! isset( $option['id'] ) ) {
  170. continue;
  171. }
  172. if ( ! isset( $option['type'] ) ) {
  173. continue;
  174. }
  175. $id = preg_replace( '/\W/', '', strtolower( $option['id'] ) );
  176. // Set checkbox to false if it wasn't sent in the $_POST
  177. if ( 'checkbox' == $option['type'] && ! isset( $input[$id] ) ) {
  178. $input[$id] = '0';
  179. }
  180. // Set each item in the multicheck to false if it wasn't sent in the $_POST
  181. if ( 'multicheck' == $option['type'] && ! isset( $input[$id] ) ) {
  182. foreach ( $option['options'] as $key => $value ) {
  183. $input[$id][$key] = '0';
  184. }
  185. }
  186. if ( 'upload' == $option['type'] ) {
  187. if ($_FILES[$id]['name'] != '') {
  188. $overrides = array('test_form' => false);
  189. $file = wp_handle_upload($_FILES[$id], $overrides);
  190. $clean[$id] = $file;
  191. }
  192. elseif(isset($_POST["{$id}_text"]) && $_POST["{$id}_text"] != '') {
  193. $input['file'] = array('url' => $_POST["{$id}_text"]);
  194. $clean[$id] = array('url' => $_POST["{$id}_text"]); }
  195. else {
  196. $clean[$id] = null;
  197. }
  198. }
  199. // For a value to be submitted to database it must pass through a sanitization filter
  200. if ( has_filter( 'cof_sanitize_' . $option['type'] ) && isset( $input[$id] ) ) {
  201. $clean[$id] = apply_filters( 'cof_sanitize_' . $option['type'], $input[$id], $option );
  202. }
  203. }
  204. add_settings_error( $this->id, 'save_options', __( 'Options saved.', 'optionsframework' ), 'updated fade' );
  205. return $clean;
  206. }
  207. }
  208. function fields() {
  209. global $allowedtags;
  210. $option_name = $this->id;
  211. $settings = $this->data;
  212. $options = $this->options;
  213. $counter = 0;
  214. $menu = '';
  215. $output = '';
  216. foreach ($options as $value) {
  217. $counter++;
  218. $val = '';
  219. $select_value = '';
  220. $checked = '';
  221. // Wrap all options
  222. if ( ($value['type'] != "heading") && ($value['type'] != "info" && $value['type'] != "subsection" && $value['type'] != "subsection_end") && $value['type'] != "open_outersection" && $value['type'] != "close_outersection" ) {
  223. // Keep all ids lowercase with no spaces
  224. $value['id'] = isset( $value['id'] ) ? preg_replace('/\W/', '', strtolower($value['id']) ) : "";
  225. $id = 'section-' . $value['id'];
  226. $class = 'section ';
  227. if ( isset( $value['type'] ) ) {
  228. $class .= ' section-' . $value['type'];
  229. }
  230. if ( isset( $value['class'] ) ) {
  231. $class .= ' ' . $value['class'];
  232. }
  233. $output .= '<div id="' . esc_attr( $id ) .'" class="' . esc_attr( $class ) . '">'."\n";
  234. $output .= '<h3 class="heading">' . esc_html( $value['name'] ) . '</h3>' . "\n";
  235. $output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
  236. }
  237. // Set default value to $val
  238. if ( isset( $value['default']) ) {
  239. $val = $value['default'];
  240. }
  241. // If the option is already saved, ovveride $val
  242. if ( ($value['type'] != "heading") && ($value['type'] != "info" && $value['type'] != "subsection" && $value['type'] != "subsection_end") && $value['type'] != "open_outersection" && $value['type'] != "close_outersection" ) {
  243. if ( isset($settings[($value['id'])]) ) {
  244. $val = $settings[($value['id'])];
  245. // Striping slashes of non-array options
  246. if (!is_array($val)) {
  247. $val = stripslashes($val);
  248. }
  249. }
  250. }
  251. // If there is a description save it for labels
  252. $explain_value = '';
  253. if ( isset( $value['desc'] ) ) {
  254. $explain_value = $value['desc'];
  255. }
  256. switch ( $value['type'] ) {
  257. // Basic text input
  258. case 'text':
  259. $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="text" value="' . esc_attr( $val ) . '" />';
  260. break;
  261. // Textarea
  262. case 'textarea':
  263. $cols = '8';
  264. $ta_value = '';
  265. if(isset($value['options'])){
  266. $ta_options = $value['options'];
  267. if(isset($ta_options['cols'])){
  268. $cols = $ta_options['cols'];
  269. } else { $cols = '8'; }
  270. }
  271. $val = stripslashes( $val );
  272. $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>';
  273. break;
  274. // Select Box
  275. case 'select':
  276. $output .= '<select class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '">';
  277. foreach ($value['options'] as $key => $option ) {
  278. $selected = '';
  279. if( $val != '' ) {
  280. if ( $val == $key) { $selected = ' selected="selected"';}
  281. }
  282. $output .= '<option'. $selected .' value="' . esc_attr( $key ) . '">' . esc_html( $option ) . '</option>';
  283. }
  284. $output .= '</select>';
  285. break;
  286. // Radio Box
  287. case "radio":
  288. $name = $option_name .'['. $value['id'] .']';
  289. foreach ($value['options'] as $key => $option) {
  290. $id = $option_name . '-' . $value['id'] .'-'. $key;
  291. $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><br />';
  292. }
  293. break;
  294. // Image Selectors
  295. case "images":
  296. $name = $option_name .'['. $value['id'] .']';
  297. foreach ( $value['options'] as $key => $option ) {
  298. $selected = '';
  299. $checked = '';
  300. if ( $val != '' ) {
  301. if ( $val == $key ) {
  302. $selected = ' of-radio-img-selected';
  303. $checked = ' checked="checked"';
  304. }
  305. }
  306. $output .= '<input type="radio" id="' . esc_attr( $value['id'] .'_'. $key) . '" class="of-radio-img-radio" value="' . esc_attr( $key ) . '" name="' . esc_attr( $name ) . '" '. $checked .' />';
  307. $output .= '<div class="of-radio-img-label">' . esc_html( $key ) . '</div>';
  308. $output .= '<img src="' . esc_url( $option ) . '" alt="' . $option .'" class="of-radio-img-img' . $selected .'" onclick="document.getElementById(\''. esc_attr($value['id'] .'_'. $key) .'\').checked=true;" />';
  309. }
  310. break;
  311. // Checkbox
  312. case "checkbox":
  313. $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" '. checked( $val, 1, false) .' />';
  314. $output .= '<label class="explain" for="' . esc_attr( $value['id'] ) . '">' . wp_kses( $explain_value, $allowedtags) . '</label>';
  315. break;
  316. // Multicheck
  317. case "multicheck":
  318. foreach ($value['options'] as $key => $option) {
  319. $checked = '';
  320. $label = $option;
  321. $option = preg_replace('/\W/', '', strtolower($key));
  322. $id = $option_name . '-' . $value['id'] . '-'. $option;
  323. $name = $option_name . '[' . $value['id'] . '][' . $option .']';
  324. if ( isset($val[$option]) ) {
  325. $checked = checked($val[$option], 1, false);
  326. }
  327. $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><br />';
  328. }
  329. break;
  330. // Color picker
  331. case "color":
  332. $output .= '<div id="' . esc_attr( $value['id'] . '_picker' ) . '" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $val ) . '"></div></div>';
  333. $output .= '<input class="of-color" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '" type="text" value="' . esc_attr( $val ) . '" />';
  334. break;
  335. // Uploader
  336. case "upload":
  337. // $output .= optionsframework_medialibrary_uploader( $value['id'], $val, null ); // New AJAX Uploader using Media Library
  338. if(isset($val['url'])) {
  339. $output .= "Preview:<br /> " . "<img class='upload' src='{$val['url']}'/><br/>";
  340. }
  341. $output .= " &nbsp;&nbsp;&nbsp;&nbsp; URL <input type='text' name='{$value['id']}_text' size='72' value='" . (isset($val['url']) ? $val['url'] : "") . "'/>";
  342. $output .= " or upload File: <input type='file' id='{$value['id']}' name='{$value['id']}'>";
  343. break;
  344. // Typography
  345. case 'typography':
  346. $typography_stored = $val;
  347. // Font Size
  348. $output .= '<select class="of-typography of-typography-size" name="' . esc_attr( $option_name . '[' . $value['id'] . '][size]' ) . '" id="' . esc_attr( $value['id'] . '_size' ) . '">';
  349. for ($i = 9; $i < 71; $i++) {
  350. $size = $i . 'px';
  351. $output .= '<option value="' . esc_attr( $size ) . '" ' . selected( $typography_stored['size'], $size, false ) . '>' . esc_html( $size ) . '</option>';
  352. }
  353. $output .= '</select>';
  354. // Font Face
  355. $output .= '<select class="of-typography of-typography-face" name="' . esc_attr( $option_name . '[' . $value['id'] . '][face]' ) . '" id="' . esc_attr( $value['id'] . '_face' ) . '">';
  356. $faces = ClassyOptionsSanitize::recognized_font_faces();
  357. foreach ( $faces as $key => $face ) {
  358. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['face'], $key, false ) . '>' . esc_html( $face ) . '</option>';
  359. }
  360. $output .= '</select>';
  361. // Font Weight
  362. $output .= '<select class="of-typography of-typography-style" name="'.$option_name.'['.$value['id'].'][style]" id="'. $value['id'].'_style">';
  363. /* Font Style */
  364. $styles = ClassyOptionsSanitize::recognized_font_styles();
  365. foreach ( $styles as $key => $style ) {
  366. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['style'], $key, false ) . '>'. $style .'</option>';
  367. }
  368. $output .= '</select>';
  369. // Font Color
  370. $output .= '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $typography_stored['color'] ) . '"></div></div>';
  371. $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'] ) . '" />';
  372. break;
  373. // Background
  374. case 'background':
  375. $background = $val;
  376. // Background Color
  377. $output .= '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $background['color'] ) . '"></div></div>';
  378. $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'] ) . '" />';
  379. // Background Image - New AJAX Uploader using Media Library
  380. if (!isset($background['image'])) {
  381. $background['image'] = '';
  382. }
  383. $output .= optionsframework_medialibrary_uploader( $value['id'], $background['image'], null, '',0,'image');
  384. $class = 'of-background-properties';
  385. if ( '' == $background['image'] ) {
  386. $class .= ' hide';
  387. }
  388. $output .= '<div class="' . esc_attr( $class ) . '">';
  389. // Background Repeat
  390. $output .= '<select class="of-background of-background-repeat" name="' . esc_attr( $option_name . '[' . $value['id'] . '][repeat]' ) . '" id="' . esc_attr( $value['id'] . '_repeat' ) . '">';
  391. $repeats = of_recognized_background_repeat();
  392. foreach ($repeats as $key => $repeat) {
  393. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['repeat'], $key, false ) . '>'. esc_html( $repeat ) . '</option>';
  394. }
  395. $output .= '</select>';
  396. // Background Position
  397. $output .= '<select class="of-background of-background-position" name="' . esc_attr( $option_name . '[' . $value['id'] . '][position]' ) . '" id="' . esc_attr( $value['id'] . '_position' ) . '">';
  398. $positions = of_recognized_background_position();
  399. foreach ($positions as $key=>$position) {
  400. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['position'], $key, false ) . '>'. esc_html( $position ) . '</option>';
  401. }
  402. $output .= '</select>';
  403. // Background Attachment
  404. $output .= '<select class="of-background of-background-attachment" name="' . esc_attr( $option_name . '[' . $value['id'] . '][attachment]' ) . '" id="' . esc_attr( $value['id'] . '_attachment' ) . '">';
  405. $attachments = of_recognized_background_attachment();
  406. foreach ($attachments as $key => $attachment) {
  407. $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['attachment'], $key, false ) . '>' . esc_html( $attachment ) . '</option>';
  408. }
  409. $output .= '</select>';
  410. $output .= '</div>';
  411. break;
  412. // Info
  413. case "info":
  414. $class = 'section';
  415. if ( isset( $value['type'] ) ) {
  416. $class .= ' section-' . $value['type'];
  417. }
  418. if ( isset( $value['class'] ) ) {
  419. $class .= ' ' . $value['class'];
  420. }
  421. $output .= '<div class="' . esc_attr( $class ) . '">' . "\n";
  422. if ( isset($value['name']) ) {
  423. $output .= '<h3 class="heading">' . ( $value['name'] ) . '</h3>' . "\n";
  424. }
  425. if ( isset( $value['desc'] ) ) {
  426. $output .= wpautop( wp_kses( $value['desc'], $allowedtags) ) . "\n";
  427. }
  428. $output .= '<div class="clear"></div></div>' . "\n";
  429. break;
  430. case "export":
  431. $output .= "<textarea rows='10'>" . esc_html(serialize($settings)) . "</textarea>";
  432. break;
  433. case "import":
  434. $output .= "<textarea name='import' rows='10'></textarea>";
  435. break;
  436. // Heading for Navigation
  437. case "heading":
  438. if($counter >= 2){
  439. $output .= '</div>'."\n";
  440. }
  441. $jquery_click_hook = preg_replace('/\W/', '', strtolower($value['name']) );
  442. $jquery_click_hook = "of-option-" . $jquery_click_hook;
  443. $menu .= '<li>';
  444. $icon = isset($value['icon']) ? " style=\"background-image: url({$value['icon']}); background-position: 8px center; background-repeat: no-repeat; \"" : "";
  445. $menu .= '<a id="'. esc_attr( $jquery_click_hook ) . '-tab" title="' . esc_attr( $value['name'] ) . '" href="' . esc_attr( '#'. $jquery_click_hook ) . '"' . $icon . '>' . esc_html( $value['name'] ) . ' <span></span></a></li>';
  446. $output .= '<div class="group" id="' . esc_attr( $jquery_click_hook ) . '"><h2>' . esc_html( $value['name'] ) . '</h2>' . "\n";
  447. break;
  448. case "subsection":
  449. $id = strtolower(preg_replace("/\W/", "", $value['name']));
  450. $output .= "<div class='subsection' id='subsection-{$id}'><h3>{$value['name']}<span class='plus'>"
  451. // . "<img src='" . CLASSY_OPTIONS_FRAMEWORK_URL . "/images/downarrow.png'>"
  452. . "</span></h3><div class='subsection-items'>";
  453. break;
  454. case "subsection_end":
  455. $output .= "</div></div>";
  456. break;
  457. case "open_outersection":
  458. $output .= "<div class='outersection'>";
  459. break;
  460. case "close_outersection":
  461. $output .= "</div>";
  462. break;
  463. case "section_order":
  464. $ec_root = get_template_directory_uri();
  465. $values = explode(",", $val);
  466. $output .= "<div class='section_order' id=" . esc_attr($value['id']) . ">";
  467. $output .= "<div class='left_list'>";
  468. $output .= "<div class='inactive'>Inactive Elements</div>";
  469. $output .= "<div class='list_items'>";
  470. foreach($value['options'] as $k => $v) {
  471. if(in_array($k, $values)) continue;
  472. $output .= "<div class='list_item'>";
  473. $output .= "<img src='$ec_root/images/minus.png' class='action' title='Remove'/>";
  474. $output .= "<span data-key='{$k}'>{$v}</span>";
  475. $output .= "</div>";
  476. }
  477. $output .= "</div>";
  478. $output .= "</div>";
  479. $output .= "<div class='arrow'><img src='$ec_root/images/arrowdrag.png' /></div>";
  480. $output .= "<div class='right_list'>";
  481. $output .= "<div class='active'>Active Elements</div>";
  482. $output .= "<div class='drag'>Drag & Drop Elements</div>";
  483. $output .= "<div class='list_items'>";
  484. foreach($values as $k) {
  485. if(!$k) continue;
  486. if(!isset($value['options'][$k])) continue;
  487. $val = $value['options'][$k];
  488. $output .= "<div class='list_item'>";
  489. $output .= "<img src='$ec_root/images/minus.png' class='action' title='Remove'/>";
  490. $output .= "<span data-key='{$k}'>{$val}</span>";
  491. $output .= "</div>";
  492. }
  493. $output .= "</div>";
  494. $output .= "</div>";
  495. $output .= "<input type='hidden' id='{$value['id']}' name='{$option_name}[{$value['id']}]' />";
  496. $output .= "</div>";
  497. break;
  498. }
  499. if ( ($value['type'] != "heading") && ($value['type'] != "info" && $value['type'] != "subsection" && $value['type'] != "subsection_end") && $value['type'] != "open_outersection" && $value['type'] != "close_outersection" ) {
  500. if ( $value['type'] != "checkbox" ) {
  501. $output .= '<br/>';
  502. }
  503. $explain_value = '';
  504. if ( isset( $value['desc'] ) ) {
  505. $explain_value = $value['desc'];
  506. }
  507. $output .= "</div>";
  508. if ( $value['type'] != "checkbox" ) {
  509. $output .= '<div class="explain">' . wp_kses( $explain_value, $allowedtags) . '</div>'."\n";
  510. }
  511. $output .= '<div class="clear"></div></div></div>'."\n";
  512. }
  513. }
  514. $output .= '</div>';
  515. return array($output,$menu);
  516. }
  517. function section($text, $options = array()) {
  518. if(isset($options['icon'])) {
  519. $this->add( array( 'type' => 'heading', 'name' => $text, 'icon' => $options['icon']));
  520. } else {
  521. $this->add( array( 'type' => 'heading', 'name' => $text) );
  522. }
  523. return $this;
  524. }
  525. function subsection($text) {
  526. $this->add( array( 'type' => 'subsection', 'name' => $text) );
  527. return $this;
  528. }
  529. function subsection_end() {
  530. $this->add( array( 'type' => 'subsection_end' ) );
  531. return $this;
  532. }
  533. function info($message) {
  534. $this->add( array( 'type' => 'info', 'name' => $message ) );
  535. return $this;
  536. }
  537. function text( $key, $label = "", $options = array() ) {
  538. $this->add( $options + array( 'id' => $key, 'type' => 'text', 'name' => $label ) );
  539. return $this;
  540. }
  541. function textarea( $key, $label = "", $options = array() ) {
  542. $this->add( $options + array( 'id' => $key, 'type' => 'textarea', 'name' => $label ) );
  543. return $this;
  544. }
  545. function radio( $key, $label = "", $options = array() ) {
  546. $this->add( $options + array( 'id' => $key, 'type' => 'radio', 'name' => $label, 'options' => $options['options'] ) );
  547. return $this;
  548. }
  549. function images( $key, $label = "", $options = array() ) {
  550. $this->add( $options + array( 'id' => $key, 'type' => 'images', 'name' => $label, 'options' => $options['options'] ) );
  551. return $this;
  552. }
  553. function checkbox( $key, $label = "", $options = array() ) {
  554. $this->add( $options + array( 'id' => $key, 'type' => 'checkbox', 'name' => $label ) );
  555. return $this;
  556. }
  557. function multicheck( $key, $label = "", $options = array() ) {
  558. $this->add( $options + array( 'id' => $key, 'type' => 'multicheck', 'name' => $label, 'options' => $options['options'] ) );
  559. return $this;
  560. }
  561. function color( $key, $label = "", $options = array() ) {
  562. $this->add( $options + array( 'id' => $key, 'type' => 'color', 'name' => $label ) );
  563. return $this;
  564. }
  565. function upload( $key, $label = "", $options = array() ) {
  566. $this->add( $options + array( 'id' => $key, 'type' => 'upload', 'name' => $label ) );
  567. return $this;
  568. }
  569. function typography( $key, $label = "", $options = array() ) {
  570. $this->add( $options + array( 'id' => $key, 'type' => 'typography', 'name' => $label ) );
  571. return $this;
  572. }
  573. function select( $key, $label = "", $options = array() ) {
  574. $this->add( $options + array( 'id' => $key, 'type' => 'select', 'name' => $label ) );
  575. return $this;
  576. }
  577. function section_order( $key, $label = "", $options = array() ) {
  578. $this->add( $options + array( 'id' => $key, 'type' => 'section_order', 'name' => $label ) );
  579. return $this;
  580. }
  581. function export( $label ) {
  582. $this->add( array( 'type' => 'export', 'name' => $label ) );
  583. return $this;
  584. }
  585. function import( $label ) {
  586. $this->add( array( 'type' => 'import', 'name' => $label ) );
  587. return $this;
  588. }
  589. function open_outersection() {
  590. $this->add( array( 'type' => 'open_outersection' ) );
  591. return $this;
  592. }
  593. function close_outersection() {
  594. $this->add( array( 'type' => 'close_outersection' ) );
  595. return $this;
  596. }
  597. function remove_section( $name ) {
  598. $started = false;
  599. foreach($this->options as $k => $option) {
  600. if( $started && $option['type'] == 'heading' ) {
  601. $end_index = $k;
  602. break;
  603. }
  604. if($option['type'] == 'heading' && $option['name'] == $name) {
  605. $started = true;
  606. $start_index = $k;
  607. }
  608. }
  609. if(!isset($end_index) ) {
  610. $end_index = count($this->options) - 1;
  611. }
  612. array_splice($this->options, $start_index, $end_index - $start_index );
  613. return $this;
  614. }
  615. }