1. <?php
  2.  
  3.  
  4. /*-----------------------------------------------------------------------------------*/
  5. /* Admin Interface
  6. /*-----------------------------------------------------------------------------------*/
  7. $functions_path = get_template_directory() . '/';
  8. function siteoptions_add_admin() {
  9.  
  10. global $query_string;
  11.  
  12. if ( isset($_REQUEST['page']) && $_REQUEST['page'] == 'siteoptions' ) {
  13. if (isset($_REQUEST['of_save']) && 'reset' == $_REQUEST['of_save']) {
  14. $options = get_option('of_template');
  15. of_reset_options($options,'siteoptions');
  16. header("Location: admin.php?page=siteoptions&reset=true");
  17. die;
  18. }
  19. }
  20.  
  21. $tt_page = add_theme_page('Tiger Theme Options', 'Tiger Theme Options', 'edit_theme_options', 'siteoptions','siteoptions_options_page');
  22. add_action("admin_print_scripts-$tt_page", 'of_load_only');
  23. add_action("admin_print_styles-$tt_page",'of_style_only');
  24. }
  25.  
  26. add_action('admin_menu', 'siteoptions_add_admin');
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. /*-----------------------------------------------------------------------------------*/
  35. /* Reset Function
  36. /*-----------------------------------------------------------------------------------*/
  37.  
  38. function of_reset_options($options,$page = ''){
  39.  
  40. global $wpdb;
  41. $query_inner = '';
  42. $count = 0;
  43.  
  44. $excludes = array( 'blogname' , 'blogdescription' );
  45.  
  46. foreach($options as $option){
  47. if(isset($option['id'])){
  48. $count++;
  49. $option_id = $option['id'];
  50. $option_type = $option['type'];
  51.  
  52. //Skip assigned id's
  53. if(in_array($option_id,$excludes)) { continue; }
  54.  
  55. if($count > 1){ $query_inner .= ' OR '; }
  56. if($option_type == 'multicheck'){
  57. $multicount = 0;
  58. foreach($option['options'] as $option_key => $option_option){
  59. $multicount++;
  60. if($multicount > 1){ $query_inner .= ' OR '; }
  61. $query_inner .= "option_name = '" . $option_id . "_" . $option_key . "'";
  62.  
  63. }
  64.  
  65. } else if(is_array($option_type)) {
  66. $type_array_count = 0;
  67. foreach($option_type as $inner_option){
  68. $type_array_count++;
  69. $option_id = $inner_option['id'];
  70. if($type_array_count > 1){ $query_inner .= ' OR '; }
  71. $query_inner .= "option_name = '$option_id'";
  72. }
  73.  
  74. } else {
  75. $query_inner .= "option_name = '$option_id'";
  76. }
  77. }
  78.  
  79. }
  80.  
  81. //When Theme Options page is reset - Add the of_options option
  82. if($page == 'siteoptions'){
  83. $query_inner .= " OR option_name = 'of_options'";
  84. }
  85.  
  86. //echo $query_inner;
  87.  
  88. $query = "DELETE FROM $wpdb->options WHERE $query_inner";
  89. $wpdb->query($query);
  90.  
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. /*-----------------------------------------------------------------------------------*/
  103. /* Build the Options Page
  104. /*-----------------------------------------------------------------------------------*/
  105.  
  106. function siteoptions_options_page(){
  107. $options = get_option('of_template');
  108. $themename = get_option('of_themename');
  109. ?>
  110.  
  111. <div class="wrap" id="truethemes_container">
  112. <div id="of-popup-save" class="of-save-popup">
  113. <div class="of-save-save">Options Updated</div>
  114. </div>
  115. <div id="of-popup-reset" class="of-save-popup">
  116. <div class="of-save-reset">Options Reset</div>
  117. </div>
  118. <form action="" enctype="multipart/form-data" id="ofform">
  119. <div id="header">
  120. <div class="logo">
  121. <h2>Tiger Theme Options</h2>
  122. </div>
  123. <div class="icon-option"> </div>
  124. <div class="clear"></div>
  125. </div>
  126. <?php
  127. // Rev up the Options Machine
  128. $return = siteoptions_machine($options);
  129. ?>
  130. <div id="main">
  131. <div id="of-nav">
  132. <ul>
  133. <?php echo $return[1] ?>
  134. </ul>
  135. </div>
  136. <div id="content"> <?php echo $return[0]; /* Settings */ ?> </div>
  137. <div class="clear"></div>
  138. </div>
  139. <div class="save_bar_top">
  140. <img style="display:none;" src="<?php echo get_template_directory_uri() ?>/admin/images/wpspin_light.gif" class="ajax-loading-img ajax-loading-img-bottom" alt="Working..." />
  141. <input type="submit" value="Save All Changes" class="button-primary" />
  142. </form>
  143. <form action="<?php echo esc_attr( $_SERVER['REQUEST_URI'] ) ?>" method="post" style="display:inline" id="ofform-reset">
  144. <span class="submit-footer-reset">
  145. <input name="reset" type="submit" value="Reset Options" class="button submit-button reset-button" onclick="return confirm('CAUTION: Any and all settings will be lost! Click OK to reset.');" />
  146. <input type="hidden" name="of_save" value="reset" />
  147. </span>
  148. </form>
  149. </div>
  150. <?php if (!empty($update_message)) echo $update_message; ?>
  151. <div style="clear:both;"></div>
  152. </div>
  153. <!--wrap-->
  154. <?php
  155. }
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. /*-----------------------------------------------------------------------------------*/
  165. /* Load required styles for Options Page
  166. /*-----------------------------------------------------------------------------------*/
  167.  
  168. function of_style_only() {
  169. wp_enqueue_style('admin-style', get_template_directory_uri().'/admin/admin-style.css');
  170. wp_enqueue_style('color-picker', get_template_directory_uri().'/admin/colorpicker.css');
  171. $color = get_user_option('admin_color');
  172. if ($color == "fresh")
  173. {
  174. wp_enqueue_style('admin-style-grey', get_template_directory_uri().'/admin/admin-style-grey.css');
  175. wp_enqueue_style('color-picker', get_template_directory_uri().'/admin/colorpicker.css');
  176. }
  177. }
  178.  
  179.  
  180.  
  181.  
  182.  
  183. /*-----------------------------------------------------------------------------------*/
  184. /* Load required javascripts for Options Page
  185. /*-----------------------------------------------------------------------------------*/
  186.  
  187. function of_load_only() {
  188.  
  189. add_action('admin_head', 'of_admin_head');
  190.  
  191. wp_enqueue_script('jquery-ui-core');
  192. wp_register_script('jquery-input-mask', get_template_directory_uri().'/admin/js/jquery.maskedinput-1.2.2.js', array( 'jquery' ));
  193. wp_enqueue_script('jquery-input-mask');
  194. wp_enqueue_script('color-picker', get_template_directory_uri().'/admin/js/colorpicker.js', array('jquery'));
  195. wp_enqueue_script('ajaxupload', get_template_directory_uri().'/admin/js/ajaxupload.js', array('jquery'));
  196.  
  197. function of_admin_head() {
  198. ?>
  199.  
  200.  
  201. <script type="text/javascript" language="javascript">
  202.  
  203. jQuery(document).ready(function(){
  204.  
  205. // Race condition to make sure js files are loaded
  206. if (typeof AjaxUpload != 'function') {
  207. return ++counter < 6 && window.setTimeout(init, counter * 500);
  208. }
  209.  
  210. //Color Picker
  211. <?php $options = get_option('of_template');
  212.  
  213. foreach($options as $option){
  214. if($option['type'] == 'color' OR $option['type'] == 'typography' OR $option['type'] == 'border'){
  215. if($option['type'] == 'typography' OR $option['type'] == 'border'){
  216. $option_id = $option['id'];
  217. $temp_color = get_option($option_id);
  218. $option_id = $option['id'] . '_color';
  219. $color = $temp_color['color'];
  220. }
  221. else {
  222. $option_id = $option['id'];
  223. $color = get_option($option_id);
  224. }
  225. ?>
  226. jQuery('#<?php echo $option_id; ?>_picker').children('div').css('backgroundColor', '<?php echo $color; ?>');
  227. jQuery('#<?php echo $option_id; ?>_picker').ColorPicker({
  228. color: '<?php echo $color; ?>',
  229. onShow: function (colpkr) {
  230. jQuery(colpkr).fadeIn(500);
  231. return false;
  232. },
  233. onHide: function (colpkr) {
  234. jQuery(colpkr).fadeOut(500);
  235. return false;
  236. },
  237. onChange: function (hsb, hex, rgb) {
  238. //jQuery(this).css('border','1px solid red');
  239. jQuery('#<?php echo $option_id; ?>_picker').children('div').css('backgroundColor', '#' + hex);
  240. jQuery('#<?php echo $option_id; ?>_picker').next('input').attr('value','#' + hex);
  241.  
  242. }
  243. });
  244. <?php } } ?>
  245.  
  246. });
  247.  
  248. </script>
  249.  
  250. <?php
  251. //AJAX Upload
  252. ?>
  253. <script type="text/javascript">
  254. jQuery(document).ready(function(){
  255.  
  256. var i = 0;
  257. jQuery('#of-nav li a').attr('id', function() {
  258. i++;
  259. return 'item'+i;
  260. });
  261.  
  262.  
  263. var flip = 0;
  264.  
  265. jQuery('#expand_options').click(function(){
  266. if(flip == 0){
  267. flip = 1;
  268. jQuery('#truethemes_container #of-nav').hide();
  269. jQuery('#truethemes_container #content').width(755);
  270. jQuery('#truethemes_container .group').add('#truethemes_container .group h2').show();
  271.  
  272. jQuery(this).text('[-]');
  273.  
  274. } else {
  275. flip = 0;
  276. jQuery('#truethemes_container #of-nav').show();
  277. jQuery('#truethemes_container #content').width(579);
  278. jQuery('#truethemes_container .group').add('#truethemes_container .group h2').hide();
  279. jQuery('#truethemes_container .group:first').show();
  280. jQuery('#truethemes_container #of-nav li').removeClass('current');
  281. jQuery('#truethemes_container #of-nav li:first').addClass('current');
  282.  
  283. jQuery(this).text('[+]');
  284.  
  285. }
  286.  
  287. });
  288.  
  289. jQuery('.group').hide();
  290. jQuery('.group:first').fadeIn();
  291.  
  292. jQuery('.group .collapsed').each(function(){
  293. jQuery(this).find('input:checked').parent().parent().parent().nextAll().each(
  294. function(){
  295. if (jQuery(this).hasClass('last')) {
  296. jQuery(this).removeClass('hidden');
  297. return false;
  298. }
  299. jQuery(this).filter('.hidden').removeClass('hidden');
  300. });
  301. });
  302.  
  303. jQuery('.group .collapsed input:checkbox').click(unhideHidden);
  304.  
  305. function unhideHidden(){
  306. if (jQuery(this).attr('checked')) {
  307. jQuery(this).parent().parent().parent().nextAll().removeClass('hidden');
  308. }
  309. else {
  310. jQuery(this).parent().parent().parent().nextAll().each(
  311. function(){
  312. if (jQuery(this).filter('.last').length) {
  313. jQuery(this).addClass('hidden');
  314. return false;
  315. }
  316. jQuery(this).addClass('hidden');
  317. });
  318.  
  319. }
  320. }
  321.  
  322. jQuery('.of-radio-img-img').click(function(){
  323. jQuery(this).parent().parent().find('.of-radio-img-img').removeClass('of-radio-img-selected');
  324. jQuery(this).addClass('of-radio-img-selected');
  325.  
  326. });
  327. jQuery('.of-radio-img-label').hide();
  328. jQuery('.of-radio-img-img').show();
  329. jQuery('.of-radio-img-radio').hide();
  330. jQuery('#of-nav li:first').addClass('current');
  331. jQuery('#of-nav li a').click(function(evt){
  332.  
  333. jQuery('#of-nav li').removeClass('current');
  334. jQuery(this).parent().addClass('current');
  335.  
  336. var clicked_group = jQuery(this).attr('href');
  337.  
  338. jQuery('.group').hide();
  339.  
  340. jQuery(clicked_group).fadeIn();
  341.  
  342. evt.preventDefault();
  343.  
  344. });
  345.  
  346. if('<?php if(isset($_REQUEST['reset'])) { echo $_REQUEST['reset'];} else { echo 'false';} ?>' == 'true'){
  347.  
  348. var reset_popup = jQuery('#of-popup-reset');
  349. reset_popup.fadeIn();
  350. window.setTimeout(function(){
  351. reset_popup.fadeOut();
  352. }, 2000);
  353. //alert(response);
  354.  
  355. }
  356.  
  357. //Update Message popup
  358. jQuery.fn.center = function () {
  359. this.animate({"top":( jQuery(window).height() - this.height() - 200 ) / 2+jQuery(window).scrollTop() + "px"},100);
  360. this.css("left", 250 );
  361. return this;
  362. }
  363.  
  364.  
  365. jQuery('#of-popup-save').center();
  366. jQuery('#of-popup-reset').center();
  367. jQuery(window).scroll(function() {
  368.  
  369. jQuery('#of-popup-save').center();
  370. jQuery('#of-popup-reset').center();
  371.  
  372. });
  373.  
  374.  
  375.  
  376. //AJAX Upload
  377. jQuery('.image_upload_button').each(function(){
  378.  
  379. var clickedObject = jQuery(this);
  380. var clickedID = jQuery(this).attr('id');
  381. new AjaxUpload(clickedID, {
  382. action: '<?php echo admin_url("admin-ajax.php"); ?>',
  383. name: clickedID, // File upload name
  384. data: { // Additional data to send
  385. action: 'of_ajax_post_action',
  386. type: 'upload',
  387. data: clickedID },
  388. autoSubmit: true, // Submit file after selection
  389. responseType: false,
  390. onChange: function(file, extension){},
  391. onSubmit: function(file, extension){
  392. clickedObject.text('Uploading'); // change button text, when user selects file
  393. this.disable(); // If you want to allow uploading only 1 file at time, you can disable upload button
  394. interval = window.setInterval(function(){
  395. var text = clickedObject.text();
  396. if (text.length < 13){ clickedObject.text(text + '.'); }
  397. else { clickedObject.text('Uploading'); }
  398. }, 200);
  399. },
  400. onComplete: function(file, response) {
  401.  
  402. window.clearInterval(interval);
  403. clickedObject.text('Upload Image');
  404. this.enable(); // enable upload button
  405.  
  406. // If there was an error
  407. if(response.search('Upload Error') > -1){
  408. var buildReturn = '<span class="upload-error">' + response + '</span>';
  409. jQuery(".upload-error").remove();
  410. clickedObject.parent().after(buildReturn);
  411.  
  412. }
  413. else{
  414. var buildReturn = '<img class="hide of-option-image" id="image_'+clickedID+'" src="'+response+'" alt="" />';
  415.  
  416. jQuery(".upload-error").remove();
  417. jQuery("#image_" + clickedID).remove();
  418. clickedObject.parent().after(buildReturn);
  419. jQuery('img#image_'+clickedID).fadeIn();
  420. clickedObject.next('span').fadeIn();
  421. clickedObject.parent().prev('input').val(response);
  422. }
  423. }
  424. });
  425.  
  426. });
  427.  
  428. //AJAX Remove (clear option value)
  429. jQuery('.image_reset_button').click(function(){
  430.  
  431. var clickedObject = jQuery(this);
  432. var clickedID = jQuery(this).attr('id');
  433. var theID = jQuery(this).attr('title');
  434.  
  435. var ajax_url = '<?php echo admin_url("admin-ajax.php"); ?>';
  436.  
  437. var data = {
  438. action: 'of_ajax_post_action',
  439. type: 'image_reset',
  440. data: theID
  441. };
  442.  
  443. jQuery.post(ajax_url, data, function(response) {
  444. var image_to_remove = jQuery('#image_' + theID);
  445. var button_to_hide = jQuery('#reset_' + theID);
  446. image_to_remove.fadeOut(500,function(){ jQuery(this).remove(); });
  447. button_to_hide.fadeOut();
  448. clickedObject.parent().prev('input').val('');
  449.  
  450.  
  451.  
  452. });
  453.  
  454. return false;
  455.  
  456. });
  457.  
  458.  
  459.  
  460.  
  461. /* Top save button
  462. jQuery(document).ready( function(){
  463. // bind "click" event for links with title="submit"
  464. jQuery("a[title=submit]").click( function(){
  465. // it submits the form it is contained within
  466. jQuery(this).parents("form").submit();
  467. });
  468. }); */
  469.  
  470.  
  471. //Save everything else
  472. jQuery('#ofform').submit(function(){
  473.  
  474. function newValues() {
  475. var serializedValues = jQuery("#ofform").serialize();
  476. return serializedValues;
  477. }
  478. jQuery(":checkbox, :radio").click(newValues);
  479. jQuery("select").change(newValues);
  480. jQuery('.ajax-loading-img').fadeIn();
  481. var serializedReturn = newValues();
  482.  
  483. var ajax_url = '<?php echo admin_url("admin-ajax.php"); ?>';
  484.  
  485. //var data = {data : serializedReturn};
  486. var data = {
  487. <?php if(isset($_REQUEST['page']) && $_REQUEST['page'] == 'siteoptions'){ ?>
  488. type: 'options',
  489. <?php } ?>
  490.  
  491. action: 'of_ajax_post_action',
  492. data: serializedReturn
  493. };
  494.  
  495. jQuery.post(ajax_url, data, function(response) {
  496. var success = jQuery('#of-popup-save');
  497. var loading = jQuery('.ajax-loading-img');
  498. loading.fadeOut();
  499. success.fadeIn();
  500. window.setTimeout(function(){
  501. success.fadeOut();
  502.  
  503.  
  504. }, 2000);
  505. });
  506.  
  507. return false;
  508.  
  509. });
  510.  
  511. });
  512. </script>
  513. <?php }
  514. }
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526. /*-----------------------------------------------------------------------------------*/
  527. /* Ajax Save Action
  528. /*-----------------------------------------------------------------------------------*/
  529.  
  530. add_action('wp_ajax_of_ajax_post_action', 'of_ajax_callback');
  531.  
  532. function of_ajax_callback() {
  533. global $wpdb; // this is how you get access to the database
  534.  
  535.  
  536. $save_type = $_POST['type'];
  537. //Uploads
  538. if($save_type == 'upload'){
  539.  
  540. $clickedID = $_POST['data']; // Acts as the name
  541. $filename = $_FILES[$clickedID];
  542. $filename['name'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', $filename['name']);
  543.  
  544. $override['test_form'] = false;
  545. $override['action'] = 'wp_handle_upload';
  546. $uploaded_file = wp_handle_upload($filename,$override);
  547.  
  548. $upload_tracking[] = $clickedID;
  549. update_option( $clickedID , $uploaded_file['url'] );
  550.  
  551. if(!empty($uploaded_file['error'])) {echo 'Upload Error: ' . $uploaded_file['error']; }
  552. else { echo $uploaded_file['url']; } // Is the Response
  553. }
  554. elseif($save_type == 'image_reset'){
  555.  
  556. $id = $_POST['data']; // Acts as the name
  557. global $wpdb;
  558. $query = "DELETE FROM $wpdb->options WHERE option_name LIKE '$id'";
  559. $wpdb->query($query);
  560.  
  561. }
  562. elseif ($save_type == 'options' OR $save_type == 'framework') {
  563. $data = $_POST['data'];
  564.  
  565. parse_str($data,$output);
  566. //print_r($output);
  567.  
  568. //Pull options
  569. $options = get_option('of_template');
  570.  
  571. foreach($options as $option_array){
  572.  
  573. $id = $option_array['id'];
  574. $old_value = get_option($id);
  575. $new_value = '';
  576.  
  577. if(isset($output[$id])){
  578. $new_value = $output[$option_array['id']];
  579. }
  580.  
  581. if(isset($option_array['id'])) { // Non - Headings...
  582.  
  583.  
  584. $type = $option_array['type'];
  585.  
  586. if ( is_array($type)){
  587. foreach($type as $array){
  588. if($array['type'] == 'text'){
  589. $id = $array['id'];
  590. $std = $array['std'];
  591. $new_value = $output[$id];
  592. if($new_value == ''){ $new_value = $std; }
  593. update_option( $id, stripslashes($new_value));
  594. }
  595. }
  596. }
  597. elseif($new_value == '' && $type == 'checkbox'){ // Checkbox Save
  598.  
  599. update_option($id,'false');
  600. }
  601. elseif ($new_value == 'true' && $type == 'checkbox'){ // Checkbox Save
  602.  
  603. update_option($id,'true');
  604. }
  605. elseif($type == 'multicheck'){ // Multi Check Save
  606.  
  607. $option_options = $option_array['options'];
  608.  
  609. foreach ($option_options as $options_id => $options_value){
  610.  
  611. $multicheck_id = $id . "_" . $options_id;
  612.  
  613. if(!isset($output[$multicheck_id])){
  614. update_option($multicheck_id,'false');
  615. }
  616. else{
  617. update_option($multicheck_id,'true');
  618. }
  619. }
  620. }
  621.  
  622. elseif($type != 'upload_min'){
  623.  
  624. update_option($id,stripslashes($new_value));
  625. }
  626. }
  627. }
  628.  
  629. }
  630.  
  631. die();
  632.  
  633. }
  634.  
  635.  
  636.  
  637. /*-----------------------------------------------------------------------------------*/
  638. /* Cases fpr various option types
  639. /*-----------------------------------------------------------------------------------*/
  640.  
  641. function siteoptions_machine($options) {
  642.  
  643. $counter = 0;
  644. $menu = '';
  645. $output = '';
  646. foreach ($options as $value) {
  647.  
  648. $counter++;
  649. $val = '';
  650. //Start Heading
  651. if ( $value['type'] != "heading" )
  652. {
  653. $class = ''; if(isset( $value['class'] )) { $class = $value['class']; }
  654. //$output .= '<div class="section section-'. $value['type'] .'">'."\n".'<div class="option-inner">'."\n";
  655. $output .= '<div class="section section-'.$value['type'].' '. $class .'">'."\n";
  656. $output .= '<h3 class="heading">'. $value['name'] .'</h3>'."\n";
  657. $output .= '<div class="option">'."\n" . '<div class="controls">'."\n";
  658.  
  659. }
  660. //End Heading
  661. $select_value = '';
  662. switch ( $value['type'] ) {
  663.  
  664. case 'text':
  665. $val = $value['std'];
  666. $std = get_option($value['id']);
  667. if ( $std != "") { $val = $std; }
  668. $output .= '<input class="of-input" name="'. $value['id'] .'" id="'. $value['id'] .'" type="'. $value['type'] .'" value="'. $val .'" />';
  669. break;
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676. case 'select':
  677.  
  678. $output .= '<select class="of-input" name="'. $value['id'] .'" id="'. $value['id'] .'">';
  679.  
  680. $select_value = get_option($value['id']);
  681.  
  682. foreach ($value['options'] as $option) {
  683.  
  684. $selected = '';
  685.  
  686. if($select_value != '') {
  687. if ( $select_value == $option) { $selected = ' selected="selected"';}
  688. } else {
  689. if ( isset($value['std']) )
  690. if ($value['std'] == $option) { $selected = ' selected="selected"'; }
  691. }
  692.  
  693. $output .= '<option'. $selected .'>';
  694. $output .= $option;
  695. $output .= '</option>';
  696.  
  697. }
  698. $output .= '</select>';
  699.  
  700.  
  701. break;
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708. case 'fontsize':
  709.  
  710. /* Font Size */
  711. $val = $default['size'];
  712. if ( $typography_stored['size'] != "") { $val = $typography_stored['size']; }
  713. $output .= '<select class="of-typography of-typography-size" name="'. $value['id'].'_size" id="'. $value['id'].'_size">';
  714. for ($i = 9; $i < 71; $i++){
  715. if($val == $i){ $active = 'selected="selected"'; } else { $active = ''; }
  716. $output .= '<option value="'. $i .'" ' . $active . '>'. $i .'px</option>'; }
  717. $output .= '</select>';
  718.  
  719.  
  720. break;
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728. case "multicheck":
  729.  
  730. $std = $value['std'];
  731.  
  732. foreach ($value['options'] as $key => $option) {
  733.  
  734. $tt_key = $value['id'] . '_' . $key;
  735. $saved_std = get_option($tt_key);
  736.  
  737. if(!empty($saved_std))
  738. {
  739. if($saved_std == 'true'){
  740. $checked = 'checked="checked"';
  741. }
  742. else{
  743. $checked = '';
  744. }
  745. }
  746. elseif( $std == $key) {
  747. $checked = 'checked="checked"';
  748. }
  749. else {
  750. $checked = ''; }
  751. $output .= '<input type="checkbox" class="checkbox of-input" name="'. $tt_key .'" id="'. $tt_key .'" value="true" '. $checked .' /><label for="'. $tt_key .'">'. $option .'</label><br />';
  752.  
  753. }
  754. break;
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763. case 'textarea':
  764.  
  765. $cols = '8';
  766. $ta_value = '';
  767.  
  768. if(isset($value['std'])) {
  769.  
  770. $ta_value = $value['std'];
  771.  
  772. if(isset($value['options'])){
  773. $ta_options = $value['options'];
  774. if(isset($ta_options['cols'])){
  775. $cols = $ta_options['cols'];
  776. } else { $cols = '8'; }
  777. }
  778.  
  779. }
  780. $std = get_option($value['id']);
  781. if( $std != "") { $ta_value = stripslashes( $std ); }
  782. $output .= '<textarea class="of-input" name="'. $value['id'] .'" id="'. $value['id'] .'" cols="'. $cols .'" rows="8">'.$ta_value.'</textarea>';
  783.  
  784.  
  785. break;
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794. case "radio":
  795.  
  796. $select_value = get_option( $value['id']);
  797.  
  798. foreach ($value['options'] as $key => $option)
  799. {
  800.  
  801. $checked = '';
  802. if($select_value != '') {
  803. if ( $select_value == $key) { $checked = ' checked'; }
  804. } else {
  805. if ($value['std'] == $key) { $checked = ' checked'; }
  806. }
  807. $output .= '<input class="of-input of-radio" type="radio" name="'. $value['id'] .'" value="'. $key .'" '. $checked .' />' . $option .'<br />';
  808.  
  809. }
  810.  
  811. break;
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821. case "checkbox":
  822.  
  823. $std = $value['std'];
  824.  
  825. $saved_std = get_option($value['id']);
  826.  
  827. $checked = '';
  828.  
  829. if(!empty($saved_std)) {
  830. if($saved_std == 'true') {
  831. $checked = 'checked="checked"';
  832. }
  833. else{
  834. $checked = '';
  835. }
  836. }
  837. elseif( $std == 'true') {
  838. $checked = 'checked="checked"';
  839. }
  840. else {
  841. $checked = '';
  842. }
  843. $output .= '<input type="checkbox" class="checkbox of-input" name="'. $value['id'] .'" id="'. $value['id'] .'" value="true" '. $checked .' />';
  844.  
  845. break;
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854. case "upload":
  855.  
  856. $output .= siteoptions_uploader_function($value['id'],$value['std'],null);
  857.  
  858. break;
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868. case "upload_min":
  869.  
  870. $output .= siteoptions_uploader_function($value['id'],$value['std'],'min');
  871.  
  872. break;
  873. case "color":
  874. $val = $value['std'];
  875. $stored = get_option( $value['id'] );
  876. if ( $stored != "") { $val = $stored; }
  877. $output .= '<div id="' . $value['id'] . '_picker" class="colorSelector"><div></div></div>';
  878. $output .= '<input class="of-color" name="'. $value['id'] .'" id="'. $value['id'] .'" type="text" value="'. $val .'" />';
  879. break;
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889. case "images":
  890. $i = 0;
  891. $select_value = get_option( $value['id']);
  892.  
  893. foreach ($value['options'] as $key => $option)
  894. {
  895. $i++;
  896.  
  897. $checked = '';
  898. $selected = '';
  899. if($select_value != '') {
  900. if ( $select_value == $key) { $checked = ' checked'; $selected = 'of-radio-img-selected'; }
  901. } else {
  902. if ($value['std'] == $key) { $checked = ' checked'; $selected = 'of-radio-img-selected'; }
  903. elseif ($i == 1 && !isset($select_value)) { $checked = ' checked'; $selected = 'of-radio-img-selected'; }
  904. elseif ($i == 1 && $value['std'] == '') { $checked = ' checked'; $selected = 'of-radio-img-selected'; }
  905. else { $checked = ''; }
  906. }
  907.  
  908. $output .= '<span>';
  909. $output .= '<input type="radio" id="of-radio-img-' . $value['id'] . $i . '" class="checkbox of-radio-img-radio" value="'.$key.'" name="'. $value['id'].'" '.$checked.' />';
  910. $output .= '<div class="of-radio-img-label">'. $key .'</div>';
  911. $output .= '<img src="'.$option.'" alt="" class="of-radio-img-img '. $selected .'" onClick="document.getElementById(\'of-radio-img-'. $value['id'] . $i.'\').checked = true;" />';
  912. $output .= '</span>';
  913.  
  914. }
  915.  
  916. break;
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925. case "info":
  926. $default = $value['std'];
  927. $output .= $default;
  928. break;
  929.  
  930.  
  931.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939. case "heading":
  940.  
  941. if($counter >= 2){
  942. $output .= '</div>'."\n";
  943. }
  944. $jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']) );
  945. $jquery_click_hook = "of-option-" . $jquery_click_hook;
  946. $menu .= '<li><a title="'. $value['name'] .'" href="#'. $jquery_click_hook .'">'. $value['name'] .'</a></li>';
  947. $output .= '<div class="group" id="'. $jquery_click_hook .'"><h2>'.$value['name'].'</h2>'."\n";
  948. break;
  949. }
  950.  
  951. // if TYPE is an array, formatted into smaller inputs... ie smaller values
  952. if ( is_array($value['type'])) {
  953. foreach($value['type'] as $array){
  954.  
  955. $id = $array['id'];
  956. $std = $array['std'];
  957. $saved_std = get_option($id);
  958. if($saved_std != $std){$std = $saved_std;}
  959. $meta = $array['meta'];
  960.  
  961. if($array['type'] == 'text') { // Only text at this point
  962.  
  963. $output .= '<input class="input-text-small of-input" name="'. $id .'" id="'. $id .'" type="text" value="'. $std .'" />';
  964. $output .= '<span class="meta-two">'.$meta.'</span>';
  965. }
  966. }
  967. }
  968. if ( $value['type'] != "heading" ) {
  969. if ( $value['type'] != "checkbox" )
  970. {
  971. $output .= '<br/>';
  972. }
  973. if(!isset($value['desc'])){ $explain_value = ''; } else{ $explain_value = $value['desc']; }
  974. $output .= '</div><div class="explain">'. $explain_value .'</div>'."\n";
  975. $output .= '<div class="clear"> </div></div></div>'."\n";
  976. }
  977.  
  978. }
  979. $output .= '</div>';
  980. return array($output,$menu);
  981.  
  982. }
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993. /*-----------------------------------------------------------------------------------*/
  994. /* File Uploading
  995. /*-----------------------------------------------------------------------------------*/
  996.  
  997. function siteoptions_uploader_function($id,$std,$mod){
  998.  
  999. $uploader = '';
  1000. $upload = get_option($id);
  1001.  
  1002. if($mod != 'min') {
  1003. $val = $std;
  1004. if ( get_option( $id ) != "") { $val = get_option($id); }
  1005. $uploader .= '<input class="of-input" name="'. $id .'" id="'. $id .'_upload" type="text" value="'. $val .'" />';
  1006. }
  1007.  
  1008. $uploader .= '<div class="upload_button_div"><span class="button image_upload_button" id="'.$id.'">Upload Image</span>';
  1009.  
  1010. if(!empty($upload)) {$hide = '';} else { $hide = 'hide';}
  1011.  
  1012. $uploader .= '<span class="button image_reset_button '. $hide.'" id="reset_'. $id .'" title="' . $id . '">Remove</span>';
  1013. $uploader .='</div>' . "\n";
  1014. $uploader .= '<div class="clear"></div>' . "\n";
  1015. if(!empty($upload)){
  1016. $uploader .= '<a class="of-uploaded-image" href="'. $upload . '">';
  1017. $uploader .= '<img class="of-option-image" id="image_'.$id.'" src="'.$upload.'" alt="" />';
  1018. $uploader .= '</a>';
  1019. }
  1020. $uploader .= '<div class="clear"></div>' . "\n";
  1021.  
  1022.  
  1023. return $uploader;
  1024. }
  1025.  
  1026. ?>