Guest User

Untitled

a guest
Aug 29th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.49 KB | None | 0 0
  1. <?php
  2.  
  3. class input_tool {
  4. var $options;
  5. var $config;
  6. var $saved_data;
  7. var $multi_counter = 0;
  8.  
  9. function __construct( $options, $config ) {
  10. $this->options = $options;
  11. $this->config = $config;
  12. }
  13.  
  14. function get_saved_theme_option() {
  15. $groups = get_option( THEME_SLUG . '_options' );
  16. if( is_array($groups) ) {
  17. foreach ( $groups as $group_key => $group ) {
  18. if( is_array( $group ) ) {
  19. foreach ( $group as $field_key => $field ) {
  20. $options[ $group_key . '_' . $field_key ] = stripslashes_deep( $field );
  21. }
  22. }
  23. }
  24. return $options;
  25. }
  26. return false;
  27. }
  28.  
  29. function get_saved_meta_option() {
  30. global $post;
  31. $keys = @get_post_custom_keys( $post->ID );
  32. if( is_array($keys) ) {
  33. foreach ( $keys as $key ) {
  34. $metas[ preg_replace('/_/', '', $key, 1) ] = get_post_meta( $post->ID, $key, true );
  35. }
  36. return $metas;
  37. }
  38. return false;
  39. }
  40.  
  41. function generate_theme_option() {
  42. $this->saved_data = $this->get_saved_theme_option();
  43.  
  44. $pane_active = ( isset($this->config['active_first']) && $this->config['active_first'] ) ? 'active' : '';
  45. echo '<div class="theme-box-content-pane theme-input ' . $pane_active . '" id="' . $this->config['group_id'] . '-pane">';
  46.  
  47. foreach( $this->options as $group ){
  48. echo '<table class="option-table widefat">';
  49.  
  50. echo '<tbody>';
  51. echo '<tr class="separator"><td colspan="100"><strong>' . $group['title'] . '</strong></td></tr>';
  52. foreach( $group['options'] as $option ){
  53. $toggle_group = ( isset($option['toggle_group']) ) ? ' input-list-toggle ' . $this->toggle_group($option) : '';
  54.  
  55. echo '<tr class="input-list' . $toggle_group . '">';
  56. echo '<td class="input-detail">';
  57. echo '<label for="' . $this->id( $option ) . '">' . $option['title'] . '</label>';
  58. echo '<small>' . $option['description'];
  59.  
  60. if( isset($option['tip']) ) echo ' <a class="tips" title="' . $option['tip'] . '">[?]</a>';
  61.  
  62. echo '</small>';
  63. echo '</td>';
  64. echo '<td class="input-field">';
  65. $this->{$option['type']}($option);
  66. echo '</td>';
  67. echo '</tr>';
  68. } // end sub foreach
  69. echo '</tbody>';
  70. echo '</table>';
  71. echo '<div class="spacer-20"></div>';
  72. } // end main foreach
  73.  
  74. echo '</div>';
  75. }
  76.  
  77. function generate_meta_option( $options = null, $saved_data = null ) {
  78. // if no $options passed then use $this->options
  79. $options = ( $options !== null ) ? $options : $this->options;
  80.  
  81. $this->saved_data = ( $saved_data !== null ) ? $saved_data : $this->get_saved_meta_option();
  82.  
  83. echo '<table class="option-table theme-input widefat custom-meta-table">';
  84.  
  85. foreach( $options as $option ){
  86. $toggle_group = ( isset($option['toggle_group']) ) ? ' input-list-toggle ' . $this->toggle_group($option) : '';
  87.  
  88. if( $option['type'] == 'separator' ) {
  89.  
  90. echo '<tr class="separator"><td colspan="100"><strong>';
  91. if( isset( $option['title'] ) ) echo $option['title'];
  92. echo '</strong></td></tr>';
  93.  
  94. } else {
  95.  
  96. echo '<tr class="input-list' . $toggle_group . '">';
  97.  
  98. if( !isset( $option['stack_builder'] ) ) {
  99. echo '<td class="input-detail">';
  100. echo '<label for="' . $this->id( $option ) . '">' . $option['title'] . '</label>';
  101. echo '<small>' . $option['description'];
  102.  
  103. if( isset($option['tip']) ) echo ' <a class="tips" title="' . $option['tip'] . '">[?]</a>';
  104.  
  105. echo '</small>';
  106. echo '</td>';
  107. }
  108.  
  109. echo '<td class="input-field">';
  110. $this->{$option['type']}($option);
  111. echo '</td>';
  112. echo '</tr>';
  113.  
  114. }
  115.  
  116. }
  117. echo '</table>';
  118. }
  119.  
  120. function generate_meta_option_for_side() {
  121. $this->saved_data = $this->get_saved_meta_option();
  122.  
  123. echo '<table class="option-table theme-input widefat sidebar-table custom-meta-table">';
  124. foreach( $this->options as $option ){
  125. echo '<tr class="input-list">';
  126. echo '<td class="input-detail input-field">';
  127. echo '<label for="' . $this->id( $option ) . '">' . $option['title'] . '</label>';
  128. echo ' <small>' . $option['description'];
  129.  
  130. if( isset($option['tip']) ) echo ' <a class="tips" title="' . $option['tip'] . '">[?]</a>';
  131.  
  132. echo '</small><div class="spacer-10"></div>';
  133. $this->$option['type']($option);
  134. echo '</td>';
  135. echo '</tr>';
  136. }
  137. echo '</table>';
  138. }
  139.  
  140. function generate_stack_option( $saved_data = null ) {
  141. $this->saved_data = ( $saved_data != null ) ? $saved_data : $this->get_saved_meta_option();
  142. //$this->saved_data = $this->get_saved_meta_option();
  143. $stack_id = (isset($this->config['stack_id']))?'stack_id="' . $this->config['stack_id'] . '"':'';
  144. $template_id = (isset($this->config['template_id']))?'template_id="' . $this->options['id'] . '"':'';
  145.  
  146. echo '<div class="stack stack-'.$this->options['id'].'">';
  147. echo '<div class="stack_header"><i class="icon icon-reorder"></i><span class="stack_header_type">'.$this->options['title'].'</span> <span class="stack_header_name"></span><i class="icon icon-times-circle stack_remove_button"></i></div>';
  148. echo '<div class="inside">';
  149. echo '<input type="hidden" class="stack_id" name="'.$this->name(array()).'[stack_id]" value="'.$this->config['stack_id'].'" />';
  150. echo '<input type="hidden" name="'.$this->name(array()).'[template_id]" value="'.$this->options['id'].'" />';
  151. $this->generate_meta_option( $this->options['options'], $this->saved_data );
  152. echo '</div>';
  153. echo '</div>';
  154. }
  155.  
  156. //////////////////////////////////////////////////////////////////////////
  157.  
  158. function name( $option ) {
  159. $subgroup = '';
  160. if( isset($this->config['subgroup']) && is_array($this->config['subgroup']) ){
  161. foreach($this->config['subgroup'] as $sub) {
  162. $subgroup .= '[' . $sub . ']';
  163. }
  164. }
  165.  
  166. $option_id = '';
  167. if( isset($option['id']) ){
  168. $option_id = '[' . $option['id'] . ']';
  169. }
  170.  
  171. $name = '';
  172. $name = $this->config['group_id'] . $subgroup . $option_id;
  173. return $name;
  174. }
  175.  
  176. function id( $option ) {
  177. $subgroup = '';
  178. if( isset($this->config['subgroup']) && is_array($this->config['subgroup']) ){
  179. foreach($this->config['subgroup'] as $sub) {
  180. $subgroup .= '-' . $sub;
  181. }
  182. }
  183.  
  184. $option_id = '';
  185. if( isset($option['id']) ){
  186. $option_id = '-' . $option['id'];
  187. }
  188.  
  189. $id = '';
  190. $id = $this->config['group_id'] . $subgroup . $option_id;
  191. return $id;
  192. }
  193.  
  194. function toggle( $option ) {
  195. $subgroup = '';
  196. if( isset($this->config['subgroup']) && is_array($this->config['subgroup']) ){
  197. foreach($this->config['subgroup'] as $sub) {
  198. $subgroup .= '-' . $sub;
  199. }
  200. }
  201.  
  202. $option_toggle = '';
  203. if( isset($option['toggle']) ){
  204. $option_toggle = '-' . $option['toggle'];
  205. }
  206.  
  207. $toggle = '';
  208. if( isset($this->config['multi']) && $this->config['multi'] ) {
  209. $toggle = $this->config['group_id'] . '-' . $this->multi_counter . $subgroup . $option_toggle;
  210. } else {
  211. $toggle = $this->config['group_id'] . $subgroup . $option_toggle;
  212. }
  213. return $toggle;
  214. }
  215.  
  216. function toggle_group( $option ) {
  217. // Return if toggle_group has not been set
  218. if(!isset( $option['toggle_group'] ))
  219. return;
  220.  
  221. // Explode to Array, many toggle_group is possible
  222. $toggle_groups = explode(' ', $option['toggle_group']);
  223.  
  224. $subgroup = '';
  225. if( isset($this->config['subgroup']) && is_array($this->config['subgroup']) ){
  226. foreach($this->config['subgroup'] as $sub) {
  227. $subgroup .= '-' . $sub;
  228. }
  229. }
  230.  
  231. $ret_toggle_group = '';
  232. if( isset($this->config['multi']) && $this->config['multi'] ) {
  233. foreach ($toggle_groups as $toggle_group) {
  234. $ret_toggle_group .= $this->config['group_id'] . '-' . $this->multi_counter . $subgroup . '-' . $toggle_group . ' ';
  235. }
  236. } else {
  237. foreach ($toggle_groups as $toggle_group) {
  238. $ret_toggle_group .= $this->config['group_id'] . $subgroup . '-' . $toggle_group . ' ';
  239. }
  240. }
  241. return $ret_toggle_group;
  242. }
  243.  
  244. function value( $option )
  245. {
  246. $default = ( isset($option['default']) ) ? $option['default'] : '';
  247.  
  248. $value = '';
  249. if( isset($this->config['subgroup']) && is_array($this->config['subgroup']) ) {
  250.  
  251. if( isset($this->config['multi']) && $this->config['multi'] ) {
  252. // $value = ( isset( $this->saved_data[$this->config['group_id']][$this->multi_counter][$option['id']] ) ) ? $this->saved_data[$this->config['group_id']][$this->multi_counter][$option['id']] : $default;
  253. } else {
  254. $subgroup = $this->config['subgroup'];
  255. $subgroup[] = $option['id'];
  256.  
  257. $temp = '';
  258. $success = true;
  259. $firstsub = array_shift($subgroup);
  260.  
  261. if( isset( $this->saved_data[$this->config['group_id'] . '_' . $firstsub] ) ) {
  262. $temp = $this->saved_data[$this->config['group_id'] . '_' . $firstsub];
  263. foreach ($subgroup as $sub) {
  264. if( isset( $temp[$sub] ) ) {
  265. $temp = $temp[$sub];
  266. } else {
  267. $success = false;
  268. break;
  269. }
  270. }
  271. } else {
  272. $success = false;
  273. }
  274.  
  275. $value = ($success) ? $temp : $default;
  276.  
  277. }
  278.  
  279. } else {
  280. $value = ( isset( $this->saved_data[$this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  281. }
  282. return $value;
  283. }
  284.  
  285. ///////////////////////////////////////////////////////////////////////////////
  286.  
  287. function text( $option ) {
  288. $value = $this->value($option);
  289.  
  290. echo '<input type="text" class="input-text" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" value="' . stripslashes(htmlspecialchars($value)) . '" />';
  291. }
  292.  
  293. function textarea( $option ) {
  294. $value = $this->value($option);
  295.  
  296. // Rows
  297. $row = isset( $option['row'] ) ? 'rows="' . $option['row'] . '"' : '';
  298.  
  299. // Theme Option Export/Import
  300. if( $option['id'] == 'theme_export_option' ) $value = base64_encode( serialize( theme_options() ) );
  301.  
  302. echo '<textarea class="input-textarea" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" ' . $row . '>' . $value . '</textarea>';
  303. }
  304.  
  305. function radio( $option ) {
  306. $value = $this->value($option);
  307.  
  308. $toggle = ( isset($option['toggle']) ) ? ' toggle="' . $this->toggle($option) . '"' : '';
  309.  
  310. foreach( $option['options'] as $radio_slug => $radio_title ){
  311. $checked = ( $radio_slug == $value ) ? 'checked="checked"' : '';
  312. echo '<div class="input-field-row">';
  313. echo '<input type="radio" name="' . $this->name( $option ) . '" value="' . $radio_slug . '" id="' . $this->id( $option ) . '-' . $radio_slug . '" class="input-radio" ' . $checked . $toggle . ' />';
  314. echo ' <label for="' . $this->id( $option ) . '-' . $radio_slug . '">' . $radio_title . '</label>';
  315. echo '</div>';
  316. }
  317. }
  318.  
  319. function checkbox( $option ) {
  320. $value = $this->value($option);
  321.  
  322. foreach( $option['options'] as $checkbox_slug => $checkbox_title ) {
  323. $checked = ( is_array($value) && in_array( $checkbox_slug, $value ) ) ? 'checked="checked"' : '';
  324. echo '<div class="input-field-row">';
  325. echo '<input type="checkbox" name="' . $this->name( $option ) . '[]" value="' . $checkbox_slug . '" id="' . $this->id( $option ) . '-' . $checkbox_slug . '" class="input-checkbox" ' . $checked . ' />';
  326. echo '<label for="' . $this->id( $option ) . '-' . $checkbox_slug . '">' . $checkbox_title . '</label>';
  327. echo '</div>';
  328. }
  329. }
  330.  
  331. function select( $option ) {
  332. $value = $this->value($option);
  333.  
  334. $toggle = ( isset($option['toggle']) ) ? ' toggle="' . $this->toggle($option) . '"' : '';
  335.  
  336. // Source : Post Type
  337. if( isset ( $option['source']['post_type'] ) ) {
  338. $source[ '' ] = '';
  339. $args = array(
  340. 'post_type' => $option['source']['post_type'],
  341. 'numberposts' => -1,
  342. 'orderby' => 'parent',
  343. 'order'=> 'DESC',
  344. 'suppress_filters' => 0,
  345. );
  346. $posts = get_posts( $args );
  347. foreach( $posts as $post ) {
  348. $source[ $post->ID ] = $post->post_title . ' (' . $post->ID . ')';
  349. }
  350. }
  351.  
  352. // Source : RevSlider
  353. if( isset( $option['source']['revslider']) && class_exists('RevSlider') ) {
  354. $slider = new RevSlider();
  355. $revsliders = $slider->getArrSlidersShort();
  356. foreach( $revsliders as $id => $name ) {
  357. $source[ $id ] = $name . ' (' . $id . ')';
  358. }
  359. }
  360.  
  361. // Source : Layer Slider
  362. if( isset( $option['source']['layer_slider']) ) {
  363. global $wpdb;
  364. $table_name = $wpdb->prefix . "layerslider";
  365. if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
  366. $sliders = $wpdb->get_results( "SELECT * FROM $table_name
  367. WHERE flag_hidden = '0' AND flag_deleted = '0'
  368. ORDER BY id ASC LIMIT 200" );
  369. if(!empty($sliders)){
  370. foreach( $sliders as $slider ) {
  371. $source[ $slider->id ] = $slider->name . ' (' . $slider->id . ')';
  372. }
  373. }
  374. }
  375. }
  376.  
  377. // Source : Category
  378. if( isset ( $option['source']['category'] ) ) {
  379. $args = array( 'type' => $option['source']['category'], 'orderby' => 'term_group' );
  380. $taxanomies = get_categories( $args );
  381. foreach( $taxanomies as $taxanomy ) {
  382. $source[ $taxanomy->term_id ] = $taxanomy->category_nicename;
  383. }
  384. }
  385.  
  386. // Source : Taxonomy
  387. if( isset ( $option['source']['taxonomy'] ) ) {
  388. $args = array( 'taxonomy' => $option['source']['taxonomy'], 'orderby' => 'term_group' );
  389. $taxanomies = get_categories( $args );
  390. foreach( $taxanomies as $taxanomy ) {
  391. $source[ $taxanomy->term_id ] = $taxanomy->category_nicename;
  392. }
  393. }
  394.  
  395. // Source : Font Awesome
  396. if( isset( $option['source']['font-awesome'] ) ) {
  397. $source[ '' ] = 'Select icon ...';
  398. asort($GLOBALS['font_awesome_list']);
  399. foreach( $GLOBALS['font_awesome_list'] as $key => $val ) {
  400. $source[ $key ] = str_replace('icon-','',$val);
  401. }
  402. }
  403.  
  404. // Source : Option Custom Sidebar
  405. if( isset( $option['source']['option-custom-sidebar'] ) ) {
  406. if( is_array( theme_options('sidebar', 'custom_sidebars') ) )
  407. foreach( theme_options('sidebar', 'custom_sidebars') as $list ) {
  408. $source[ preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', strtolower( $list['stack_title'] )) ) ] = $list['stack_title'];
  409. }
  410. }
  411.  
  412. // Source : Google Web Font
  413. if( isset ( $option['source']['gfonts'] ) ) {
  414. $items = get_transient( THEME_SLUG . 'gfont_items' );
  415.  
  416. if( !$items ){ // No transient, request the new one
  417. $google_api_url =
  418. 'https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyALn_gIORMu90pZJhO4-z5xULIWH9Lce-A';
  419. $response = wp_remote_retrieve_body( wp_remote_get($google_api_url, array('sslverify' => false )));
  420. if( is_wp_error( $response ) ) { // Failed, get from option
  421. $items = get_option( THEME_SLUG . 'gfont_items' );
  422. } else { // Success
  423. $response = json_decode($response);
  424. $items = $response->items;
  425.  
  426. // Store
  427. set_transient( THEME_SLUG . 'gfont_items', $items, 60*60*12 );
  428. if( !add_option( THEME_SLUG . 'gfont_items', $items ) ) {
  429. update_option( THEME_SLUG . 'gfont_items', $items );
  430. }
  431. }
  432. }
  433.  
  434. // Add to source
  435. $source[ '' ] = __('Please Select','stack');
  436. if( $items ) {
  437. foreach( $items as $item ) {
  438. $source[ $item->family ] = $item->family;
  439. }
  440. } else {
  441. $source[ $value ] = $value;
  442. }
  443. }
  444.  
  445. // Multiple
  446. $multiple = ( isset ( $option['multiple'] ) ) ? ' multiple size="'.$option['multiple'].'"' : '';
  447.  
  448. $name = ( isset ( $option['multiple'] ) ) ? 'name="' . $this->name( $option ) . '[]"' : 'name="' . $this->name( $option ) . '"';
  449.  
  450. // Generate
  451. echo '<select '.$multiple.' class="input-select" ' . $name . '" id="' . $this->id( $option ) . '" '.$toggle.'>';
  452. if( isset($option['options']) ) {
  453. foreach( $option['options'] as $select_slug => $select_title ){
  454. $selected = ( $select_slug == $value || ( is_array($value) && in_array( $select_slug, $value) ) ) ? 'selected="selected"' : '';
  455. echo '<option value="' . $select_slug . '" ' . $selected . '>' . $select_title . '</option>';
  456. }
  457. }
  458. if( isset($source) ) {
  459. foreach( $source as $select_slug => $select_title ){
  460. $selected = ( $select_slug == $value || ( is_array($value) && in_array( $select_slug, $value) ) ) ? 'selected="selected"' : '';
  461. echo '<option value="' . $select_slug . '" ' . $selected . '>' . $select_title . '</option>';
  462. }
  463. }
  464. echo '</select>';
  465.  
  466. }
  467.  
  468. function input_file( $option ) {
  469. $value = $this->value($option);
  470.  
  471. echo '<input type="hidden" class="dummy-input" name="' . $this->name( $option ) . '" />';
  472. echo '<div class="file-extensions" value="' . $option['extensions'] . '"></div>';
  473. echo '<div class="uploaded-file-container">';
  474. if( $value ) {
  475. echo '<div class="uploaded-file">';
  476. echo '<span>'.theme_get_attachment_src( $value ).'</span>';
  477. echo '<a class="remove" href="#">remove</a>';
  478. echo '<input type="hidden" name="' . $this->name( $option ) . '" value="' . $value . '" />';
  479. echo '</div>';
  480. }
  481. echo '</div>';
  482. echo '<div class="clear"></div>';
  483. echo '<div class="ajax-load-icon upload-image-bt-ajax-load"></div>';
  484. echo '<div class="upload-file-bt-box"><input type="button" value="' . __('Upload File', 'stack') . '" class="button-secondary upload-file-bt" /></div>';
  485. }
  486.  
  487.  
  488. function image( $option ) {
  489. $value = $this->value($option);
  490.  
  491. echo '<input type="hidden" name="' . $this->name($option) . '" />';
  492. echo '<div id="' . $this->id($option) . '_image_container" class="image_container clear" value="custom_media">';
  493.  
  494. if( $value != '' ) {
  495. echo '<div class="uploaded-image" attachment_id="'.$value.'">';
  496. echo '<input type="hidden" id="'.$this->id($option).'" name="' . $this->name($option) . '" value="'.$value.'"/>';
  497. echo wp_get_attachment_image($value, 'thumbnail');
  498. echo '<div class="image-action-box"><i class="icon icon-times-circle"></i></div>';
  499. echo '</div>';
  500. }
  501.  
  502. echo '</div><div class="clear"></div>';
  503. echo '<div multi="no" data-field-name="' . $this->name($option) . '" class="images_add_button button">'.__('Upload Image', 'stack').'</div>';
  504. }
  505.  
  506.  
  507. function images( $option ) {
  508. $value = $this->value($option);
  509.  
  510. echo '<input type="hidden" name="' . $this->name($option) . '" />';
  511. echo '<div id="' . $this->id($option) . '_images_container" class="images_container image_container clear" value="custom_media">';
  512. $images = ($value!='') ? $value : array();
  513. foreach ($images as $key => $value) {
  514. echo '<div class="uploaded-image" attachment_id="'.$value.'" style="float: left;">';
  515. echo '<input type="hidden" id="'.$this->id($option).'" name="'.$this->name($option).'[]" value="'.$value.'"/>';
  516. echo wp_get_attachment_image($value, 'thumbnail');
  517. echo '<div class="image-action-box"><i class="icon icon-times-circle"></i></div>';
  518. echo '</div>';
  519. }
  520. echo '</div><div class="clear"></div>';
  521. echo '<div multi="yes" data-field-name="' . $this->name($option) . '" class="images_add_button button">'.__('Upload Images', 'stack').'</div>';
  522. }
  523.  
  524. // Export Options
  525. function export_options( $option ) {
  526. echo '<a href="'.THEME_FUNCTIONS_URI.'/admin-options-export.php" target="_blank" class="button">' . __('Download Backup', 'stack') . 'File</a>';
  527. }
  528. function import_options( $option ) {
  529. echo '<div class="input-file-wrap"><input type="file" accept="txt" class="input-file-real" name="import_options_file"><a href="#" class="input-file-bt button">' . __('Browse' , 'stack') . '</a><span class="input-file-name">' . __('please select backup file', 'stack') . '</span></div><input type="submit" class="button-primary" value="' . __('Import Options', 'stack') . '" name="import_options" />';
  530. }
  531.  
  532. // Import Content
  533. function import_content( $option ) {
  534. echo '<input type="button" value="' . __('Import Demo Content', 'stack') . '" class="button first-click" /><input type="submit" name="import_content" value="' . __('Confirm Import Demo Content' , 'stack') . '" class="button second-click button-primary" />';
  535. }
  536.  
  537. function show( $option ) {
  538. $value = $this->value($option);
  539.  
  540. echo stripslashes(htmlspecialchars($value));
  541. echo '<input type="hidden" class="input-hidden" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" value="' . stripslashes(htmlspecialchars($value)) . '">';
  542. }
  543.  
  544. // Separator
  545. function separator( $option ) {
  546.  
  547. }
  548.  
  549. ///////////////////////////////////////////////////////////////////////////////
  550.  
  551. function color( $option ) {
  552. $value = $this->value($option);
  553.  
  554. echo '<div class="color-indicator" style="background: '.$value.';"></div><input type="text" class="input-color" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" value="' . $value . '">';
  555. }
  556.  
  557. function date( $option ) {
  558. $value = $this->value($option);
  559.  
  560. $time_string = ($value != '') ? date('m/d/Y', $value) : '';
  561. echo '<input type="text" class="input-date" id="' . $this->id( $option ) . '" value="' . $time_string . '" >';
  562. echo '<input type="hidden" class="input-date-value" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" value="' . $value . '" >';
  563. }
  564.  
  565. function time( $option ) {
  566. $value = $this->value($option);
  567.  
  568. echo '<input type="text" class="input-time" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" value="' . $value . '" ><a href="#" class="time-trigger"></a>';
  569. }
  570.  
  571. function range( $option ) {
  572. $value = $this->value($option);
  573.  
  574. echo '<input type="text" class="input-range" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" data-slider-value="' . $value . '" data-range="' . $option['min'] . ',' . $option['max'] . '" data-step="' . $option['step'] . '" value="'. $value .'">';
  575. echo '<span class="input-range-value">' . $value . '</span>';
  576. echo '<span class="input-range-unit">' . $option['unit'] . '</span>';
  577. }
  578.  
  579. function on_off( $option ) {
  580. $value = $this->value($option);
  581.  
  582. $checked = ( 'on' == $value ) ? 'checked="checked"' : '';
  583. $toggle = ( isset($option['toggle']) ) ? ' toggle="' . $this->toggle($option) . '"' : '';
  584.  
  585. // Sent value even the checkbox is unchecked http://stackoverflow.com/questions/476426/submit-an-html-form-with-empty-checkboxes
  586. echo '<input type="hidden" name="' . $this->name( $option ) . '" value="off" />';
  587.  
  588. echo '<input type="checkbox" class="input-on-off" name="' . $this->name( $option ) . '" id="' . $this->id( $option ) . '" value="on" ' . $checked . $toggle . ' />';
  589. }
  590.  
  591. function radio_img( $option ) {
  592. $value = $this->value($option);
  593.  
  594. $toggle = ( isset($option['toggle']) ) ? ' toggle="' . $this->toggle($option) . '"' : '';
  595.  
  596. foreach( $option['options'] as $radio_slug => $radio_title ){
  597. $checked = ( $radio_slug == $value ) ? 'checked="checked"' : '';
  598. $active = ( $radio_slug == $value ) ? 'active' : '';
  599. echo '<div class="radio-img-list">';
  600. echo '<input type="radio" name="' . $this->name( $option ) . '" value="' . $radio_slug . '" id="' . $this->id( $option ) . '-' . $radio_slug . '" class="input-radio" ' . $checked . $toggle . ' />';
  601. echo '<label for="' . $this->id( $option ) . '-' . $radio_slug . '" class="' . $active . '"><div class="radio-img" style="background-image:url('. $option['images'][$radio_slug] .');"></div><div class="radio-img-list-desc">' . $radio_title . '</div></label>';
  602. echo '</div>';
  603. }
  604. }
  605.  
  606. function checkbox_img( $option ) {
  607. $value = $this->value($option);
  608.  
  609. $toggle = ( isset($option['toggle']) ) ? ' toggle="' . $this->toggle($option) . '"' : '';
  610.  
  611. foreach( $option['options'] as $checkbox_slug => $checkbox_title ){
  612. $checked = ( is_array( $value ) && in_array( $checkbox_slug, $value ) ) ? 'checked="checked"' : '';
  613. $active = ( is_array( $value ) && in_array( $checkbox_slug, $value ) ) ? 'active' : '';
  614. echo '<div class="checkbox-img-list">';
  615. echo '<input type="checkbox" name="' . $this->name( $option ) . '[]" value="' . $checkbox_slug . '" id="' . $this->id( $option ) . '-' . $checkbox_slug . '" class="input-checkbox" ' . $checked . $toggle . ' />';
  616. echo '<label for="' . $this->id( $option ) . '-' . $checkbox_slug . '" class="' . $active . '"><img src="' . THEME_CUSTOM_ASSETS_URI . '/images/list-images/' . $option['images'][$checkbox_slug] . '" /></label>';
  617. echo '<div class="checkbox-img-list-desc">' . $checkbox_title . '</div>';
  618. echo '</div>';
  619. }
  620. }
  621.  
  622. function stack( $option ) {
  623.  
  624. $value = $this->value($option);
  625. if($value==''){$value=array();} // workaround for no stack
  626.  
  627. // workaround for remove all stacks
  628. echo '<input type="hidden" name="'.$this->name($option).'" />';
  629.  
  630. echo '<div class="stack_container" id="' . $this->id( $option ) . '-stack_container" name="' . $this->id( $option ) . '-stack_container">';
  631.  
  632. // Default Page Content Stack
  633. $page_content_stack = array('stack_id' => 0, 'template_id' => 'page_content');
  634. if( isset( $option['stack_builder'] ) && $option['stack_builder'] && !in_array($page_content_stack, $value) ) {
  635. $value[] = $page_content_stack;
  636. }
  637.  
  638. $subgroup = array();
  639. if( isset($this->config['subgroup']) && is_array($this->config['subgroup']) ) {
  640. $subgroup = $this->config['subgroup'];
  641. }
  642. $subgroup[] = $option['id'];
  643.  
  644. // Empty Stack
  645. if( count($value) == 0 ) {
  646. echo '<div class="dummy-stack"></div>';
  647. }
  648.  
  649. foreach ($value as $stack) {
  650. if(!is_array($stack)){continue;}
  651.  
  652. $stack_stack_id = $stack['stack_id'];
  653. $stack_template_id = $stack['template_id'];
  654. $stack_template_title = '';
  655. $stack_config = json_decode(json_encode($this->config),true);
  656. $stack_option = array();
  657.  
  658. // find template
  659. foreach ($option['templates'] as $template) {
  660. if($template['id'] == $stack_template_id) {
  661. $stack_option = $template;
  662. break;
  663. }
  664. }
  665.  
  666. // modify option id, toggle, toggle_group
  667. $extend = '-' . $stack_stack_id;
  668. $stack_config['stack_id'] = $stack_stack_id;
  669. $stack_config['subgroup'] = array_merge($subgroup,array($stack_stack_id));
  670.  
  671. // generate stack option
  672. $stack_input_tool = new input_tool($stack_option, $stack_config);
  673. $stack_input_tool->generate_stack_option( $this->saved_data );
  674. }
  675.  
  676. echo '</div>';
  677. echo '<div class="stack_menu">';
  678. $show_stack_select_template = (count($option['templates'])>1) ? '' : ' hidden';
  679. echo '<select class="stack_select_template '.$show_stack_select_template.'" id="' . $this->id( $option ) . '-stack_select">';
  680. foreach ($option['templates'] as $template) {
  681. if( !in_array( $template['id'], array('page_content') ) ) {
  682. echo '<option value="' . $template['id'] . '" opt="'.htmlspecialchars(json_encode($template),ENT_QUOTES).'" conf="'.htmlspecialchars(json_encode($this->config),ENT_QUOTES).'">' . $template['title'] . '</option>';
  683. }
  684. }
  685. echo '</select>';
  686. echo '<input class="button stack_add_button" type="button" id="' . $this->id( $option ) . '-add_button" subgroup="' . htmlspecialchars(json_encode($subgroup),ENT_QUOTES) . '" value="'.$option['stack_button'].'" />';
  687. echo '</div>';
  688. }
  689.  
  690. ///////////////////////////////////////////////////////////////////////////////
  691.  
  692. }
  693.  
  694.  
  695.  
  696. ?>
Add Comment
Please, Sign In to add comment