1. <?php
  2.  
  3. define("THEMENAME", "Pleng");
  4. define("SHORTNAME", "pp");
  5.  
  6. //If delete sidebar
  7. if(isset($_POST['sidebar_id']) && !empty($_POST['sidebar_id']))
  8. {
  9.     $current_sidebar = get_option('pp_sidebar');
  10.    
  11.     if(isset($current_sidebar[ $_POST['sidebar_id'] ]))
  12.     {
  13.         unset($current_sidebar[ $_POST['sidebar_id'] ]);
  14.         update_option( "pp_sidebar", $current_sidebar );
  15.     }
  16.    
  17.     echo 1;
  18.     exit;
  19. }
  20.  
  21. /*
  22.  *  Setup main navigation menu
  23.  */
  24. add_action( 'init', 'register_my_menu' );
  25. function register_my_menu() {
  26.     register_nav_menu( 'primary-menu', __( 'Primary Menu' ) );
  27. }
  28.  
  29. if ( function_exists( 'add_theme_support' ) ) {
  30.     // Setup thumbnail support
  31.     add_theme_support( 'post-thumbnails' );
  32. }
  33.  
  34. /**
  35. *   Setup all theme's library
  36. **/
  37.  
  38. /**
  39. *   Setup admin setting
  40. **/
  41. include (TEMPLATEPATH . "/lib/admin.lib.php");
  42. include (TEMPLATEPATH . "/lib/twitter.lib.php");
  43.  
  44. /**
  45. *   Setup Sidebar
  46. **/
  47. include (TEMPLATEPATH . "/lib/sidebar.lib.php");
  48.  
  49.  
  50. //Get custom function
  51. include (TEMPLATEPATH . "/lib/custom.lib.php");
  52.  
  53.  
  54. //Get custom shortcode
  55. include (TEMPLATEPATH . "/lib/shortcode.lib.php");
  56.  
  57.  
  58. // Setup theme custom widgets
  59. include (TEMPLATEPATH . "/lib/widgets.lib.php");
  60.  
  61.  
  62. $pp_handle = opendir(TEMPLATEPATH.'/fields');
  63. $pp_font_arr = array();
  64.  
  65. while (false!==($pp_file = readdir($pp_handle))) {
  66.     if ($pp_file != "." && $pp_file != ".." && $pp_file != ".DS_Store") {
  67.         include (TEMPLATEPATH . "/fields/".$pp_file);
  68.     }
  69. }
  70. closedir($pp_handle);
  71.  
  72.  
  73. function pp_add_admin() {
  74.  
  75. global $themename, $shortname, $options;
  76.  
  77. if ( isset($_GET['page']) && $_GET['page'] == basename(__FILE__) ) {
  78.  
  79.     if ( isset($_REQUEST['action']) && 'save' == $_REQUEST['action'] ) {
  80.  
  81.         foreach ($options as $value)
  82.         {
  83.             update_option( $value['id'], $_REQUEST[ $value['id'] ] );
  84.         }
  85.  
  86. foreach ($options as $value) {
  87.     if( isset( $_REQUEST[ $value['id'] ] ) ) {
  88.         if($value['id'] != $shortname."_sidebar0")
  89.         {
  90.             update_option( $value['id'], $_REQUEST[ $value['id'] ]  );
  91.         }
  92.         elseif(isset($_REQUEST[ $value['id'] ]) && !empty($_REQUEST[ $value['id'] ]))
  93.         {
  94.             //get last sidebar serialize array
  95.             $current_sidebar = get_option($shortname."_sidebar");
  96.             $current_sidebar[ $_REQUEST[ $value['id'] ] ] = $_REQUEST[ $value['id'] ];
  97.  
  98.             update_option( $shortname."_sidebar", $current_sidebar );
  99.         }
  100.     }
  101.     else
  102.     {
  103.         delete_option( $value['id'] );
  104.     }
  105. }
  106.  
  107.  
  108.     header("Location: admin.php?page=functions.php&saved=true".$_REQUEST['current_tab']);
  109.  
  110. }
  111. else if( isset($_REQUEST['action']) && 'reset' == $_REQUEST['action'] ) {
  112.  
  113.     foreach ($options as $value) {
  114.         delete_option( $value['id'] ); }
  115.  
  116.     header("Location: admin.php?page=functions.php&reset=true");
  117.  
  118. }
  119. }
  120.  
  121. add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'pp_admin');
  122. }
  123.  
  124. function pp_add_init() {
  125.  
  126. $file_dir=get_bloginfo('template_directory');
  127. wp_enqueue_style("functions", $file_dir."/functions/functions.css", false, "1.0", "all");
  128. wp_enqueue_style("colorpicker_css", $file_dir."/functions/colorpicker/css/colorpicker.css", false, "1.0", "all");
  129. wp_enqueue_script("colorpicker_script", $file_dir."/functions/colorpicker/js/colorpicker.js", false, "1.0");
  130. wp_enqueue_script("eye_script", $file_dir."/functions/colorpicker/js/eye.js", false, "1.0");
  131. wp_enqueue_script("utils_script", $file_dir."/functions/colorpicker/js/utils.js", false, "1.0");
  132. wp_enqueue_script("iphone_checkboxes", $file_dir."/functions/iphone-style-checkboxes.js", false, "1.0");
  133. wp_enqueue_script("jslider_depend", $file_dir."/functions/jquery.dependClass.js", false, "1.0");
  134. wp_enqueue_script("jslider", $file_dir."/functions/jquery.slider-min.js", false, "1.0");
  135. wp_enqueue_script("rm_script", $file_dir."/functions/rm_script.js", false, "1.0");
  136.  
  137. }
  138. function pp_admin() {
  139.  
  140. global $themename, $shortname, $options;
  141. $i=0;
  142.  
  143. $cache_dir = TEMPLATEPATH.'/cache';
  144.  
  145. if(!is_writable($cache_dir))
  146. {
  147. ?>
  148.  
  149.     <div id="message" class="error fade">
  150.     <p style="line-height:1.5em"><strong>
  151.         The path <?php echo $cache_dir; ?> is not writable, please login with your FTP account and make it writable (chmod 777) otherwise all images won't display.
  152.     </p></strong>
  153.     </div>
  154.  
  155. <?php
  156. }
  157. ?>
  158.     <div class="wrap rm_wrap">
  159.     <h2><?php echo $themename; ?> Settings</h2>
  160.     For future updates follow me <a href="http://themeforest.net/user/peerapong">@themeforest</a> or <a href="http://twitter.com/ipeerapong">@twitter</a>
  161.     <br/><br/><br/>
  162.    
  163.     <?php
  164.         if ( isset($_REQUEST['saved']) &&  $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div><br/>';
  165. if ( isset($_REQUEST['reset']) &&  $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div><br/>';
  166.     ?>
  167.    
  168.     <div class="wrap">
  169.     <div id="pp_panel" style="border-bottom:1px solid #ccc;padding-left: 10px">
  170.     <?php
  171.         foreach ($options as $value) {
  172.             /*print '<pre>';
  173.             print_r($value);
  174.             print '</pre>';*/
  175.            
  176.             $active = '';
  177.            
  178.             if($value['type'] == 'section')
  179.             {
  180.                 if($value['name'] == 'General')
  181.                 {
  182.                     $active = 'nav-tab-active';
  183.                 }
  184.                 echo '<a id="pp_panel_'.strtolower($value['name']).'_a" href="#pp_panel_'.strtolower($value['name']).'" class="nav-tab '.$active.'">'.$value['name'].'</a>';
  185.             }
  186.         }
  187.     ?>
  188.     </h2>
  189.     </div>
  190.  
  191.     <div class="rm_opts">
  192.     <form method="post">
  193.    
  194. <?php foreach ($options as $value) {
  195. switch ( $value['type'] ) {
  196.  
  197. case "open":
  198. ?> <?php break;
  199.  
  200. case "close":
  201. ?>
  202.    
  203.     </div>
  204.     </div>
  205.  
  206.  
  207.     <?php break;
  208.  
  209. case "title":
  210. ?>
  211.     <br />
  212.  
  213.  
  214. <?php break;
  215.  
  216. case 'text':
  217.    
  218.     //if sidebar input then not show default value
  219.     if($value['id'] != $shortname."_sidebar0")
  220.     {
  221.         $default_val = get_settings( $value['id'] );
  222.     }
  223.     else
  224.     {
  225.         $default_val = ''; 
  226.     }
  227. ?>
  228.  
  229.     <div class="rm_input rm_text"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  230.     <input name="<?php echo $value['id']; ?>"
  231.         id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>"
  232.         value="<?php if ($default_val != "") { echo stripslashes(get_settings( $value['id'])  ); } else { echo $value['std']; } ?>"
  233.         <?php if(!empty($value['size'])) { echo 'style="width:'.$value['size'].'"'; } ?> />
  234.         <small><?php echo $value['desc']; ?></small>
  235.     <div class="clearfix"></div>
  236.    
  237.     <?php
  238.     if($value['id'] == $shortname."_sidebar0")
  239.     {
  240.         $current_sidebar = get_option($shortname."_sidebar");
  241.        
  242.         if(!empty($current_sidebar))
  243.         {
  244.     ?>
  245.         <ul id="current_sidebar" class="rm_list">
  246.  
  247.     <?php
  248.         $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  249.    
  250.         foreach($current_sidebar as $sidebar)
  251.         {
  252.     ?>
  253.            
  254.             <li id="<?=$sidebar?>"><?=$sidebar?> ( <a href="<?php echo $url; ?>" class="sidebar_del" rel="<?=$sidebar?>">Delete</a> )</li>
  255.    
  256.     <?php
  257.         }
  258.     ?>
  259.    
  260.         </ul>
  261.    
  262.     <?php
  263.         }
  264.     }
  265.     ?>
  266.  
  267.     </div>
  268.     <?php
  269. break;
  270.  
  271. case 'password':
  272. ?>
  273.  
  274.     <div class="rm_input rm_text"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  275.     <input name="<?php echo $value['id']; ?>"
  276.         id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>"
  277.         value="<?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id'])  ); } else { echo $value['std']; } ?>"
  278.         <?php if(!empty($value['size'])) { echo 'style="width:'.$value['size'].'"'; } ?> />
  279.     <small><?php echo $value['desc']; ?></small>
  280.     <div class="clearfix"></div>
  281.  
  282.     </div>
  283.     <?php
  284. break;
  285.  
  286. case 'jslider':
  287. ?>
  288.  
  289.     <div class="rm_input rm_text"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  290.     <div style="float:left;width:270px;padding-left:10px">
  291.     <input name="<?php echo $value['id']; ?>"
  292.         id="<?php echo $value['id']; ?>" type="text" class="jslider"
  293.         value="<?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id'])  ); } else { echo $value['std']; } ?>"
  294.         <?php if(!empty($value['size'])) { echo 'style="width:'.$value['size'].'"'; } ?> />
  295.     </div>
  296.     <small><?php echo $value['desc']; ?></small>
  297.     <div class="clearfix"></div>
  298.    
  299.     <script>jQuery("#<?php echo $value['id']; ?>").slider({ from: <?php echo $value['from']; ?>, to: <?php echo $value['to']; ?>, step: <?php echo $value['step']; ?>, smooth: true });</script>
  300.  
  301.     </div>
  302.     <?php
  303. break;
  304.  
  305. case 'colorpicker':
  306. ?>
  307.     <div class="rm_input rm_text"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  308.     <div id="<?php echo $value['id']; ?>_bg" class="colorpicker_bg" onclick="jQuery('#<?php echo $value['id']; ?>').click()" style="background:<?php if (get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id'])  ); } else { echo $value['std']; } ?>">&nbsp;</div>
  309.     <input name="<?php echo $value['id']; ?>"
  310.         id="<?php echo $value['id']; ?>" type="text"
  311.         value="<?php if ( get_settings( $value['id'] ) != "" ) { echo stripslashes(get_settings( $value['id'])  ); } else { echo $value['std']; } ?>"
  312.         <?php if(!empty($value['size'])) { echo 'style="width:'.$value['size'].'"'; } ?>  class="color_picker"/>
  313.         <small><?php echo $value['desc']; ?></small>
  314.     <div class="clearfix"></div>
  315.    
  316.     </div>
  317.    
  318. <?php
  319. break;
  320.  
  321. case 'textarea':
  322. ?>
  323.  
  324.     <div class="rm_input rm_textarea"><label
  325.         for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  326.     <textarea name="<?php echo $value['id']; ?>"
  327.         type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id']) ); } else { echo $value['std']; } ?></textarea>
  328.     <small><?php echo $value['desc']; ?></small>
  329.     <div class="clearfix"></div>
  330.  
  331.     </div>
  332.  
  333.     <?php
  334. break;
  335.  
  336. case 'select':
  337. ?>
  338.  
  339.     <div class="rm_input rm_select"><label
  340.         for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  341.  
  342.     <select name="<?php echo $value['id']; ?>"
  343.         id="<?php echo $value['id']; ?>">
  344.         <?php foreach ($value['options'] as $key => $option) { ?>
  345.         <option
  346.         <?php if (get_settings( $value['id'] ) == $key) { echo 'selected="selected"'; } ?>
  347.             value="<?php echo $key; ?>"><?php echo $option; ?></option>
  348.         <?php } ?>
  349.     </select> <small><?php echo $value['desc']; ?></small>
  350.     <div class="clearfix"></div>
  351.     </div>
  352.     <?php
  353. break;
  354.  
  355. case 'radio':
  356. ?>
  357.  
  358.     <div class="rm_input rm_select"><label
  359.         for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  360.  
  361.     <div style="float:left;width:350px">
  362.     <?php foreach ($value['options'] as $key => $option) { ?>
  363.     <div style="float:left;margin:0 20px 20px 0">
  364.         <input style="float:left;" id="<?php echo $value['id']; ?>" name="<?php echo $value['id']; ?>" type="radio"
  365.         <?php if (get_settings( $value['id'] ) == $key) { echo 'checked="checked"'; } ?>
  366.             value="<?php echo $key; ?>"/><?php echo html_entity_decode($option); ?>
  367.     </div>
  368.     <?php } ?>
  369.     </div>
  370.    
  371.         <small><?php echo $value['desc']; ?></small>
  372.     <div class="clearfix"></div>
  373.     </div>
  374.     <?php
  375. break;
  376.  
  377. case "checkbox":
  378. ?>
  379.  
  380.     <div class="rm_input rm_checkbox"><label
  381.         for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  382.  
  383.     <?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>
  384.     <input type="checkbox" name="<?php echo $value['id']; ?>"
  385.         id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
  386.  
  387.  
  388.     <small><?php echo $value['desc']; ?></small>
  389.     <div class="clearfix"></div>
  390.     </div>
  391. <?php break;
  392.  
  393. case "iphone_checkboxes":
  394. ?>
  395.  
  396.     <div class="rm_input rm_checkbox"><label
  397.         for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  398.  
  399.     <?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>
  400.     <input type="checkbox" class="iphone_checkboxes" name="<?php echo $value['id']; ?>"
  401.         id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
  402.  
  403.  
  404.     <small><?php echo $value['desc']; ?></small>
  405.     <div class="clearfix"></div>
  406.     </div>
  407.  
  408. <?php break;
  409.    
  410. case "section":
  411.  
  412. $i++;
  413.  
  414. ?>
  415.  
  416.     <div id="pp_panel_<?php echo strtolower($value['name']); ?>" class="rm_section">
  417.     <div class="rm_title">
  418.     <h3><img
  419.         src="<?php bloginfo('template_directory')?>/functions/images/trans.png"
  420.         class="inactive" alt="""><?php echo $value['name']; ?></h3>
  421.     <span class="submit"><input class="button-primary" name="save<?php echo $i; ?>" type="submit"
  422.         value="Save changes" /> </span>
  423.     <div class="clearfix"></div>
  424.     </div>
  425.     <div class="rm_options"><?php break;
  426.  
  427. }
  428. }
  429. ?>
  430. <br/><br/>
  431.  <input class="button-primary" name="save<?php echo $i; ?>" type="submit"
  432.         value="Save changes" /><br/><br/><br/><br/>
  433.  <input type="hidden" name="action" value="save" />
  434.  <input type="hidden" name="current_tab" id="current_tab" value="#pp_panel_general" />
  435.     </form>
  436.     <form method="post"><!-- p class="submit">
  437. <input name="reset" type="submit" value="Reset" />
  438. <input type="hidden" name="action" value="reset" />
  439. </p --></form>
  440.     </div>
  441.  
  442.  
  443.     <?php
  444. }
  445.  
  446. add_action('admin_init', 'pp_add_init');
  447. add_action('admin_menu', 'pp_add_admin');
  448.  
  449.  
  450. /**
  451. *   Setup all theme's plugins
  452. **/
  453. // Setup shortcode generator plugin
  454. include (TEMPLATEPATH . "/plugins/troubleshooting.php");
  455. include (TEMPLATEPATH . "/plugins/shortcode_generator.php");
  456.  
  457.  
  458. //Make widget support shortcode
  459. add_filter('widget_text', 'do_shortcode');
  460.  
  461. if ($_GET['activated']){
  462.     wp_redirect(admin_url("themes.php?page=functions.php"));
  463. }
  464. ?>