Guest User

Untitled

a guest
Sep 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.60 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 input_tool( $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. foreach ( $group as $field_key => $field ) {
  19. $options[ $group_key . '_' . $field_key ] = stripslashes_deep( $field );
  20. }
  21. }
  22. return $options;
  23. }
  24. return false;
  25. }
  26.  
  27. function get_saved_meta_option() {
  28. global $post;
  29. $keys = get_post_custom_keys( $post->ID );
  30. if( is_array($keys) ) {
  31. foreach ( $keys as $key ) {
  32. $metas[ $key ] = get_post_meta( $post->ID, $key, true );
  33. }
  34. return $metas;
  35. }
  36. return false;
  37. }
  38.  
  39. function generate_theme_option() {
  40. $this->saved_data = $this->get_saved_theme_option();
  41.  
  42. $pane_active = ( isset($this->config['active_first']) && $this->config['active_first'] ) ? 'active' : '';
  43. echo '<div class="theme-box-content-pane theme-input ' . $pane_active . '" id="' . $this->config['group_id'] . '-pane">';
  44.  
  45. foreach( $this->options as $group ){
  46.  
  47.  
  48. //echo '<h3 class="section-title">' . $group['title'] . '</h3>';
  49. echo '<table class="option-table widefat">';
  50.  
  51. echo '<tbody>';
  52. echo '<tr class="separator"><td colspan="100"><strong>' . $group['title'] . '</strong></td></tr>';
  53. foreach( $group['options'] as $option ){
  54. $toggle_group = ( isset($option['toggle_group']) ) ? ' input-list-toggle ' . $option['toggle_group'] : '';
  55.  
  56. echo '<tr class="input-list' . $toggle_group . '">';
  57. echo '<td class="input-detail">';
  58. echo '<label for="' . $this->id( $option ) . '">' . $option['title'] . '</label>';
  59. echo '<small>' . $option['description'];
  60.  
  61. if( isset($option['tip']) ) echo ' <a class="tips" title="' . $option['tip'] . '">[?]</a>';
  62.  
  63. echo '</small>';
  64. echo '</td>';
  65. echo '<td class="input-field">';
  66. $this->{$option['type']}($option);
  67. echo '</td>';
  68. echo '</tr>';
  69. } // end sub foreach
  70. echo '</tbody>';
  71. echo '</table>';
  72. echo '<div class="spacer-20"></div>';
  73. } // end main foreach
  74.  
  75. echo '</div>';
  76. }
  77.  
  78. function generate_meta_option() {
  79. $this->saved_data = $this->get_saved_meta_option();
  80. echo '<table class="option-table theme-input widefat">';
  81. foreach( $this->options as $option ){
  82. $toggle_group = ( isset($option['toggle_group']) ) ? ' input-list-toggle ' . $option['toggle_group'] : '';
  83.  
  84. if( $option['type'] == 'separator' ) {
  85.  
  86. echo '<tr class="separator"><td colspan="100"><strong>';
  87. if( isset( $option['title'] ) ) echo $option['title'];
  88. echo '</strong></td></tr>';
  89.  
  90. } else {
  91.  
  92. echo '<tr class="input-list' . $toggle_group . '">';
  93. echo '<td class="input-detail">';
  94. echo '<label for="' . $this->id( $option ) . '">' . $option['title'] . '</label>';
  95. echo '<small>' . $option['description'];
  96.  
  97. if( isset($option['tip']) ) echo ' <a class="tips" title="' . $option['tip'] . '">[?]</a>';
  98.  
  99. echo '</small>';
  100. echo '</td>';
  101. echo '<td class="input-field">';
  102. $this->{$option['type']}($option);
  103. echo '</td>';
  104. echo '</tr>';
  105.  
  106. }
  107.  
  108. }
  109. echo '</table>';
  110. }
  111.  
  112. function generate_meta_option_for_side() {
  113. $this->saved_data = $this->get_saved_meta_option();
  114.  
  115. echo '<table class="option-table theme-input widefat sidebar-table">';
  116. foreach( $this->options as $option ){
  117. echo '<tr class="input-list">';
  118. echo '<td class="input-detail input-field">';
  119. echo '<label for="' . $this->id( $option ) . '">' . $option['title'] . '</label>';
  120. echo ' <small>' . $option['description'];
  121.  
  122. if( isset($option['tip']) ) echo ' <a class="tips" title="' . $option['tip'] . '">[?]</a>';
  123.  
  124. echo '</small><div class="spacer-10"></div>';
  125. $this->{$option['type']}($option);
  126. echo '</td>';
  127. echo '</tr>';
  128. }
  129. echo '</table>';
  130. }
  131.  
  132. function generate_meta_list() {
  133. $this->saved_data = $this->get_saved_meta_option();
  134. $counter = 1;
  135. if( isset( $this->saved_data[$this->config['group_id']] ) && is_array( $this->saved_data[$this->config['group_id']] ) ) {
  136. foreach ( $this->saved_data[$this->config['group_id']] as $list_index => $list ){
  137. echo '<tr class="meta-row sortable" index="' . $list_index . '" id="row-' . $this->config['group_id'] . '-' . $list_index . '">';
  138. echo '<td>' . $counter . '</td>';
  139. foreach ( $this->config['table_content'] as $option_key ){
  140. if( isset($list[$option_key]) ) echo '<td>' . $list[$option_key] . '</td>';
  141. else echo '<td></td>';
  142. }
  143.  
  144. echo '<td>';
  145. echo '<ul class="row-tools">';
  146. echo '<li class="meta-edit-row-bt"><a href="#">Edit</a></li>';
  147. echo '<li class="meta-delete-row-bt last"><a href="#">Delete</a></li>';
  148. echo '</ul>';
  149. echo '</td>';
  150.  
  151. echo '</tr>';
  152.  
  153. echo '<tr class="meta-edit-row" index="' . $list_index . '" id="edit-' . $this->config['group_id'] . '-' . $list_index . '">';
  154. echo '<td colspan="100%">';
  155.  
  156. echo '<div class="post-meta-options">';
  157. $this->multi_counter = $list_index;
  158. $this->generate_meta_option();
  159. echo '</div>';
  160.  
  161. echo '</td>';
  162. echo '</tr>';
  163. $counter++;
  164. }
  165. }
  166. }
  167.  
  168. ///////////////////////////////////////////////////////////////////////////////
  169.  
  170. function name( $option ) {
  171. if( isset($this->config['multi']) )
  172. if( $this->config['multi'] ) return $this->config['group_id'] . '[' . $this->multi_counter . '][' . $option['id'] . ']';
  173.  
  174. return $this->config['group_id'] . '[' . $option['id'] . ']';
  175. }
  176.  
  177. function id( $option ) {
  178. if( isset($this->config['multi']) )
  179. if( $this->config['multi'] ) return $this->config['group_id'] . '-' . $this->multi_counter . '-' . $option['id'];
  180.  
  181. return $this->config['group_id'] . '-' . $option['id'];
  182. }
  183.  
  184. ///////////////////////////////////////////////////////////////////////////////
  185.  
  186. function text( $option ) {
  187. $default = ( isset($option['default']) ) ? $option['default'] : '';
  188. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  189. $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;
  190. } else {
  191. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  192. }
  193. echo '<input type="text" class="input-text" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" value="' . stripslashes(htmlspecialchars($value)) . '">';
  194. }
  195.  
  196. function textarea( $option ) {
  197. $default = ( isset($option['default']) ) ? $option['default'] : '';
  198. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  199. $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;
  200. } else {
  201. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  202. }
  203.  
  204. // Rows
  205. $row = isset( $option['row'] ) ? 'rows="' . $option['row'] . '"' : '';
  206.  
  207. // Theme Option Export/Import
  208. if( $option['id'] == 'theme_export_option' ) $value = base64_encode( serialize( theme_options() ) );
  209.  
  210. echo '<textarea class="input-textarea" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" ' . $row . '>' . $value . '</textarea>';
  211. }
  212.  
  213. function radio( $option ) {
  214. $default = ( isset($option['default']) ) ? $option['default'] : '';
  215. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  216. $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;
  217. } else {
  218. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  219. }
  220.  
  221. $toggle = ( isset($option['toggle']) ) ? ' toggle="' . $option['toggle'] . '"' : '';
  222.  
  223. foreach( $option['options'] as $radio_slug => $radio_title ){
  224. $checked = ( $radio_slug == $value ) ? 'checked="checked"' : '';
  225. echo '<div class="input-field-row">';
  226. echo '<input type="radio" name="' . $this->name( $option ) . '" value="' . $radio_slug . '" id="' . $this->id( $option ) . '-' . $radio_slug . '" class="input-radio" ' . $checked . $toggle . ' />';
  227. echo ' <label for="' . $this->id( $option ) . '-' . $radio_slug . '">' . $radio_title . '</label>';
  228. echo '</div>';
  229. }
  230. }
  231.  
  232. function checkbox( $option ) {
  233. $default = ( isset($option['default']) ) ? $option['default'] : '';
  234. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  235. $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;
  236. } else {
  237. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  238. }
  239.  
  240. foreach( $option['options'] as $checkbox_slug => $checkbox_title ) {
  241. $checked = ( is_array($value) && in_array( $checkbox_slug, $value ) ) ? 'checked="checked"' : '';
  242. echo '<div class="input-field-row">';
  243. echo '<input type="checkbox" name="' . $this->name( $option ) . '[]" value="' . $checkbox_slug . '" id="' . $this->id( $option ) . '-' . $checkbox_slug . '" class="input-checkbox" ' . $checked . ' />';
  244. echo '<label for="' . $this->id( $option ) . '-' . $checkbox_slug . '">' . $checkbox_title . '</label>';
  245. echo '</div>';
  246. }
  247. }
  248.  
  249. function select( $option ) {
  250. $default = ( isset($option['default']) ) ? $option['default'] : '';
  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. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  255. }
  256.  
  257. // Source : Post Type
  258. if( isset ( $option['source']['post_type'] ) ) {
  259. $args = array( 'post_type' => $option['source']['post_type'], 'numberposts' => -1, 'orderby' => 'parent', 'order'=> 'DESC' );
  260. $posts = get_posts( $args );
  261. // $source[''] = '';
  262. foreach( $posts as $post ) {
  263. /*$source[ $post->ID ] = '';
  264. $parent = $post->post_parent;
  265. while( $parent > 0 ) {
  266. $page = get_page($parent_id);
  267. $parent = isset( $page->post_parent ) ? $page->post_parent : '0';
  268. $source[ $post->ID ] .= '-';
  269. }*/
  270. $source[ $post->ID ] = $post->post_title . ' (' . $post->ID . ')';
  271. }
  272. }
  273.  
  274. // Source : Category
  275. if( isset ( $option['source']['category'] ) ) {
  276. $args = array( 'type' => $option['source']['category'], 'orderby' => 'term_group' );
  277. $taxanomies = get_categories( $args );
  278. foreach( $taxanomies as $taxanomy ) {
  279. $source[ $taxanomy->term_id ] = $taxanomy->category_nicename;
  280. }
  281. }
  282.  
  283. // Multiple
  284. $multiple = ( isset ( $option['multiple'] ) ) ? ' multiple size="'.$option['multiple'].'"' : '';
  285. //var_dump($value);
  286. $name = ( isset ( $option['multiple'] ) ) ? 'name="' . $this->name( $option ) . '[]"' : 'name="' . $this->name( $option ) . '"';
  287.  
  288. echo '<select '.$multiple.' class="input-select" ' . $name . '" id="' . $this->id( $option ) . '">';
  289. if( isset($option['options']) ) {
  290. foreach( $option['options'] as $select_slug => $select_title ){
  291. $selected = ( $select_slug == $value || ( is_array($value) && in_array( $select_slug, $value) ) ) ? 'selected="selected"' : '';
  292. echo '<option value="' . $select_slug . '" ' . $selected . '>' . $select_title . '</option>';
  293. }
  294. }
  295. if( isset($source) ) {
  296. foreach( $source as $select_slug => $select_title ){
  297. $selected = ( $select_slug == $value || ( is_array($value) && in_array( $select_slug, $value) ) ) ? 'selected="selected"' : '';
  298. echo '<option value="' . $select_slug . '" ' . $selected . '>' . $select_title . '</option>';
  299. }
  300. }
  301. echo '</select>';
  302.  
  303. }
  304.  
  305. function input_file( $option ) {
  306. $default = ( isset($option['default']) ) ? $option['default'] : '';
  307. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  308. $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;
  309. } else {
  310. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  311. }
  312.  
  313. echo '<input type="hidden" class="dummy-input" name="' . $this->name( $option ) . '" />';
  314. echo '<div class="file-extensions" value="' . $option['extensions'] . '"></div>';
  315. echo '<div class="uploaded-file-container">';
  316. if( $value ) {
  317. echo '<div class="uploaded-file">';
  318. echo '<span>'.theme_get_attachment_src( $value ).'</span>';
  319. echo '<a class="remove" href="#">remove</a>';
  320. echo '<input type="hidden" name="' . $this->name( $option ) . '" value="' . $value . '" />';
  321. echo '</div>';
  322. }
  323. echo '</div>';
  324. echo '<div class="clear"></div>';
  325. echo '<div class="ajax-load-icon upload-image-bt-ajax-load"></div>';
  326. echo '<div class="upload-file-bt-box"><input type="button" value="Upload File" class="button-secondary upload-file-bt" /></div>';
  327. }
  328.  
  329. function image( $option ) {
  330. $default = ( isset($option['default']) ) ? $option['default'] : '';
  331. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  332. $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;
  333. } else {
  334. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  335. }
  336. echo '<input type="hidden" class="dummy-input" name="' . $this->name( $option ) . '" />';
  337. echo '<div class="uploaded-image-container">';
  338. if( $value ) {
  339. $resized_image_src = theme_get_image( $value, 80, 80, true );
  340. echo '<div class="uploaded-image">';
  341. echo '<img src="' . $resized_image_src . '" />';
  342. echo '<a class="remove" href="#">remove</a>';
  343. echo '<input type="hidden" class="upload-img-path" name="' . $this->name( $option ) . '" value="' . $value . '" />';
  344. echo '</div>';
  345. }
  346. echo '</div>';
  347. echo '<div class="clear"></div>';
  348.  
  349. echo '<div class="ajax-load-icon upload-image-bt-ajax-load"></div>';
  350. echo '<div class="upload-file-bt-box"><input type="button" value="Upload Image" class="button-secondary upload-image-bt" /></div>';
  351. }
  352.  
  353. function images( $option ) {
  354.  
  355. $default = ( isset($option['default']) ) ? $option['default'] : '';
  356. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  357. $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;
  358. } else {
  359. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  360. }
  361.  
  362. echo '<input type="hidden" class="dummy-input" name="' . $this->name( $option ) . '" />';
  363. echo '<div class="uploaded-images-container">';
  364. //var_dump($value);
  365. if( is_array( $value ) )
  366. foreach ( $value as $image ) {
  367. $resized_image_src = theme_get_image( $image, 80, 80, true );
  368. echo '<div class="uploaded-image">';
  369. echo '<img src="' . $resized_image_src . '" />';
  370. echo '<a class="remove" href="#">remove</a>';
  371. echo '<input type="hidden" name="' . $this->name( $option ) . '[]" value="' . $image . '" />';
  372. echo '</div>';
  373. }
  374. echo '</div>';
  375. echo '<div class="clear"></div>';
  376. echo '<div class="ajax-load-icon upload-image-bt-ajax-load"></div>';
  377. echo '<div class="upload-file-bt-box"><input type="button" value="Upload Images" class="button-secondary upload-images-bt" /></div>';
  378. }
  379.  
  380. function show( $option ) {
  381. $default = ( isset($option['default']) ) ? $option['default'] : '';
  382. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  383. $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;
  384. } else {
  385. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  386. }
  387. echo stripslashes(htmlspecialchars($value));
  388. echo '<input type="hidden" class="input-hidden" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" value="' . stripslashes(htmlspecialchars($value)) . '">';
  389. }
  390.  
  391.  
  392. ///////////////////////////////////////////////////////////////////////////////
  393.  
  394. function color( $option ) {
  395. $default = ( isset($option['default']) ) ? $option['default'] : '';
  396. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  397. $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;
  398. } else {
  399. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  400. }
  401.  
  402. echo '<input type="text" class="input-color" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" value="' . $value . '" data-hex="true">';
  403. }
  404.  
  405. function date( $option ) {
  406. $default = ( isset($option['default']) ) ? $option['default'] : '';
  407. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  408. $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;
  409. } else {
  410. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : '';
  411. }
  412.  
  413. $time_string = ($value != '') ? date('d F Y', $value) : '';
  414. echo '<input type="text" class="input-date" id="' . $this->id( $option ) . '" value="' . $time_string . '" >';
  415. echo '<input type="hidden" class="input-date-value" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" value="' . $value . '" >';
  416. }
  417.  
  418. function time( $option ) {
  419. $default = ( isset($option['default']) ) ? $option['default'] : '';
  420. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  421. $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;
  422. } else {
  423. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  424. }
  425.  
  426. echo '<input type="text" class="input-time" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" value="' . $value . '" ><a href="#" class="time-trigger"></a>';
  427. }
  428.  
  429. function range( $option ) {
  430. $default = ( isset($option['default']) ) ? $option['default'] : '';
  431. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  432. $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;
  433. } else {
  434. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  435. }
  436.  
  437. echo '<input type="text" class="input-range" id="' . $this->id( $option ) . '" name="' . $this->name( $option ) . '" value="' . $value . '" min="' . $option['min'] . '" max="' . $option['max'] . '" step="' . $option['step'] . '">';
  438. echo '<span class="input-range-unit">' . $option['unit'] . '</span>';
  439. }
  440.  
  441. function on_off( $option ) {
  442. $default = ( isset($option['default']) ) ? $option['default'] : '';
  443. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  444. $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;
  445. } else {
  446. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  447. }
  448.  
  449. $checked = ( 'on' == $value ) ? 'checked="checked"' : '';
  450. $toggle = ( isset($option['toggle']) ) ? ' toggle="' . $option['toggle'] . '"' : '';
  451.  
  452. // Sent value even the checkbox is unchecked http://stackoverflow.com/questions/476426/submit-an-html-form-with-empty-checkboxes
  453. echo '<input type="hidden" name="' . $this->name( $option ) . '" value="off" />';
  454.  
  455. echo '<input type="checkbox" class="input-on-off" name="' . $this->name( $option ) . '" id="' . $this->id( $option ) . '" value="on" ' . $checked . $toggle . ' />';
  456. }
  457.  
  458. function radio_img( $option ) {
  459. $default = ( isset($option['default']) ) ? $option['default'] : '';
  460. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  461. $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;
  462. } else {
  463. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  464. }
  465.  
  466. $toggle = ( isset($option['toggle']) ) ? ' toggle="' . $option['toggle'] . '"' : '';
  467.  
  468. foreach( $option['options'] as $radio_slug => $radio_title ){
  469. $checked = ( $radio_slug == $value ) ? 'checked="checked"' : '';
  470. $active = ( $radio_slug == $value ) ? 'active' : '';
  471. echo '<div class="radio-img-list">';
  472. echo '<input type="radio" name="' . $this->name( $option ) . '" value="' . $radio_slug . '" id="' . $this->id( $option ) . '-' . $radio_slug . '" class="input-radio" ' . $checked . $toggle . ' />';
  473. echo '<label for="' . $this->id( $option ) . '-' . $radio_slug . '" class="' . $active . '"><img src="' . THEME_CUSTOM_ASSETS_URI . '/images/list-images/' . $option['images'][$radio_slug] . '" /></label>';
  474. echo '<div class="radio-img-list-desc">' . $radio_title . '</div>';
  475. echo '</div>';
  476. }
  477. }
  478.  
  479. function checkbox_img( $option ) {
  480. $default = ( isset($option['default']) ) ? $option['default'] : '';
  481. if( isset( $this->config['multi'] ) && $this->config['multi'] ) {
  482. $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;
  483. } else {
  484. $value = ( isset( $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] ) ) ? $this->saved_data[ $this->config['group_id'] . '_' . $option['id'] ] : $default;
  485. }
  486.  
  487. $toggle = ( isset($option['toggle']) ) ? ' toggle="' . $option['toggle'] . '"' : '';
  488.  
  489. foreach( $option['options'] as $checkbox_slug => $checkbox_title ){
  490. $checked = ( is_array( $value ) && in_array( $checkbox_slug, $value ) ) ? 'checked="checked"' : '';
  491. $active = ( is_array( $value ) && in_array( $checkbox_slug, $value ) ) ? 'active' : '';
  492. echo '<div class="checkbox-img-list">';
  493. echo '<input type="checkbox" name="' . $this->name( $option ) . '[]" value="' . $checkbox_slug . '" id="' . $this->id( $option ) . '-' . $checkbox_slug . '" class="input-checkbox" ' . $checked . $toggle . ' />';
  494. echo '<label for="' . $this->id( $option ) . '-' . $checkbox_slug . '" class="' . $active . '"><img src="' . THEME_CUSTOM_ASSETS_URI . '/images/list-images/' . $option['images'][$checkbox_slug] . '" /></label>';
  495. echo '<div class="checkbox-img-list-desc">' . $checkbox_title . '</div>';
  496. echo '</div>';
  497. }
  498. }
  499.  
  500.  
  501.  
  502.  
  503. }
  504.  
  505. ?>
Add Comment
Please, Sign In to add comment