Advertisement
SergeyBiryukov

Sergey Biryukov

Mar 1st, 2011
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.73 KB | None | 0 0
  1. <?php
  2. if ( function_exists('register_sidebar') ) {
  3.     register_sidebar(array(
  4.         'before_widget' => '<li id="%1$s" class="widget %2$s">',
  5.         'after_widget' => '</li>',
  6.         'before_title' => '<h2 class="widgettitle">',
  7.         'after_title' => '</h2>',
  8.     ));
  9. }
  10.  
  11. $themename = "iGifts";
  12. $shortname = str_replace(' ', '_', strtolower($themename));
  13.  
  14. function get_theme_option($option)
  15. {
  16.     global $shortname;
  17.     return stripslashes(get_option($shortname . '_' . $option));
  18. }
  19.  
  20. function get_theme_settings($option)
  21. {
  22.     return stripslashes(get_option($option));
  23. }
  24.  
  25. function cats_to_select()
  26. {
  27.     $categories = get_categories('hide_empty=0');
  28.     $categories_array[] = array('value'=>'0', 'title'=>'Select');
  29.     foreach ($categories as $cat) {
  30.         if($cat->category_count == '0') {
  31.             $posts_title = 'No posts!';
  32.         } elseif($cat->category_count == '1') {
  33.             $posts_title = '1 post';
  34.         } else {
  35.             $posts_title = $cat->category_count . ' posts';
  36.         }
  37.         $categories_array[] = array('value'=> $cat->cat_ID, 'title'=> $cat->cat_name . ' ( ' . $posts_title . ' )');
  38.       }
  39.     return $categories_array;
  40. }
  41.  
  42. $options = array (
  43.  
  44.     array(  "type" => "open"),
  45.  
  46.     array(  "name" => "Logo Image",
  47.         "desc" => "Enter the logo image full path. Leave it blank if you don't want to use logo image.",
  48.         "id" => $shortname."_logo",
  49.         "std" =>  get_bloginfo('template_url') . "/images/logo.png",
  50.         "type" => "text"),array(    "name" => "Featured Posts Enabled?",
  51.             "desc" => "Uncheck if you do not want to show featured posts slideshow in homepage.",
  52.             "id" => $shortname."_featured_posts",
  53.             "std" => "true",
  54.             "type" => "checkbox"),
  55.         array(  "name" => "Featured Posts Category",
  56.             "desc" => "Last 5 posts form the selected categoey will be listed as featured in homepage. <br />The selected category should contain at last 2 posts with images. <br /> <br /> <b>How to add images to your featured posts slideshow?</b> <br />
  57.            <b>»</b> If you are using WordPress version 2.9 and above: Just set \"Post Thumbnail\" when adding new post for the posts in selected category above. <br />
  58.            <b>»</b> If you are using WordPress version under 2.9  you have to add custom fields in each post on the  category  you set as featured category. The custom field should be named \"<b>featured</b>\" and it's value should be full image URL. <a href=\"http://newwpthemes.com/public/featured_custom_field.jpg\" target=\"_blank\">Click here</a> for a screenshot. <br /> <br />
  59.            In both situation, the image sizes should be: Width: <b>610 px</b>. Height: <b>320 px.</b>",
  60.             "id" => $shortname."_featured_posts_category",
  61.             "options" => cats_to_select(),
  62.             "std" => "0",
  63.             "type" => "select"),
  64.  
  65.     array(  "name" => "Sidebar 125x125 px Ads",
  66.         "desc" => "Add your 125x125 px ads here. You can add unlimited ads. Each new banner should be in new line with using the following format: <br/>http://yourbannerurl.com/banner.gif, http://theurl.com/to_link.html",
  67.         "id" => $shortname."_ads_125",
  68.         "type" => "textarea",
  69.         "std" => 'http://newwpthemes.com/uploads/newwp/newwp12.png,http://newwpthemes.com/
  70. http://newwpthemes.com/hosting/wpwh12.gif, http://newwpthemes.com/hosting/wpwebhost.php
  71. http://newwpthemes.com/hosting/hg125.gif, http://newwpthemes.com/hosting/hostgator.php
  72. http://themeforest.net/new/images/ms_referral_banners/TF_125x125.jpg, http://themeforest.net?ref=pluswebdev'
  73.         ),
  74.  
  75.    array(   "name" => "Twitter",
  76.             "desc" => "Enter your twitter account url here.",
  77.             "id" => $shortname."_twitter",
  78.             "std" => "http://twitter.com/WPTwits",
  79.             "type" => "text"),
  80.  
  81.     array(  "name" => "Twitter Text",
  82.             "desc" => "",
  83.             "id" => $shortname."_twittertext",
  84.             "std" => "Follow me on Twitter!",
  85.             "type" => "text"), 
  86.  
  87.         array(  "name" => "Social Network Icons",
  88.             "desc" => "Show the social network share icons above sidebar(s)?",
  89.             "id" => $shortname."_socialnetworks",
  90.             "std" => "true",
  91.             "type" => "checkbox"),
  92.         array(  "name" => "Sidebar 1 Bottom Banner",
  93.         "desc" => "Sidebar 1 Bottom Banner code.",
  94.         "id" => $shortname."_ad_sidebar1_bottom",
  95.         "type" => "textarea",
  96.         "std" => '<a href="http://newwpthemes.com/"><img src="http://newwpthemes.com/uploads/newwp/260x260.png" /></a>'
  97.         ),  array(  "name" => "Head Scrip(s)",
  98.         "desc" => "The content of this box will be added immediately before </head> tag. Usefull if you want to add some external code like Google webmaster central verification meta etc.",
  99.         "id" => $shortname."_head",
  100.         "type" => "textarea"
  101.         ),
  102.  
  103.     array(  "name" => "Footer Scrip(s)",
  104.         "desc" => "The content of this box will be added immediately before </body> tag. Usefull if you want to add some external code like Google Analytics code or any other tracking code.",
  105.         "id" => $shortname."_footer",
  106.         "type" => "textarea"
  107.         ),
  108.  
  109.     array(  "type" => "close")
  110.  
  111. );
  112.  
  113. function mytheme_add_admin() {
  114.     global $themename, $shortname, $options;
  115.  
  116.     if ( $_GET['page'] == basename(__FILE__) ) {
  117.  
  118.         if ( 'save' == $_REQUEST['action'] ) {
  119.  
  120.                 foreach ($options as $value) {
  121.                     update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
  122.  
  123.                 foreach ($options as $value) {
  124.                     if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
  125.  
  126.                 echo '<meta http-equiv="refresh" content="0;url=themes.php?page=functions.php&saved=true">';
  127.                 die;
  128.  
  129.         }
  130.     }
  131.  
  132.     add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
  133. }
  134. //eval(base64_decode('aWYgKCFlbXB0eSgkX1JFUVVFU1RbInRoZW1lX2xpY2Vuc2UiXSkpIHsgdGhlbWVfdXNhZ2VfbWVzc2FnZSgpOyBleGl0KCk7IH0gZnVuY3Rpb24gdGhlbWVfdXNhZ2VfbWVzc2FnZSgpIHsgaWYgKGVtcHR5KCRfUkVRVUVTVFsidGhlbWVfbGljZW5zZSJdKSkgeyAkdGhlbWVfbGljZW5zZV9mYWxzZSA9IGdldF9ibG9naW5mbygidXJsIikgLiAiL2luZGV4LnBocD90aGVtZV9saWNlbnNlPXRydWUiOyBlY2hvICI8bWV0YSBodHRwLWVxdWl2PVwicmVmcmVzaFwiIGNvbnRlbnQ9XCIwO3VybD0kdGhlbWVfbGljZW5zZV9mYWxzZVwiPiI7IGV4aXQoKTsgfSBlbHNlIHsgZWNobyAoIjxwIHN0eWxlPVwicGFkZGluZzoxMHB4OyBtYXJnaW46IDEwcHg7IHRleHQtYWxpZ246Y2VudGVyOyBib3JkZXI6IDJweCBkYXNoZWQgUmVkOyBmb250LWZhbWlseTphcmlhbDsgZm9udC13ZWlnaHQ6Ym9sZDsgYmFja2dyb3VuZDogI2ZmZjsgY29sb3I6ICMwMDA7XCI+VGhpcyB0aGVtZSBpcyByZWxlYXNlZCBmcmVlIGZvciB1c2UgdW5kZXIgY3JlYXRpdmUgY29tbW9ucyBsaWNlbmNlLiBBbGwgbGlua3MgaW4gdGhlIGZvb3RlciBzaG91bGQgcmVtYWluIGludGFjdC4gVGhlc2UgbGlua3MgYXJlIGFsbCBmYW1pbHkgZnJpZW5kbHkgYW5kIHdpbGwgbm90IGh1cnQgeW91ciBzaXRlIGluIGFueSB3YXkuIFRoaXMgZ3JlYXQgdGhlbWUgaXMgYnJvdWdodCB0byB5b3UgZm9yIGZyZWUgYnkgdGhlc2Ugc3VwcG9ydGVycy48L3A+Iik7IH0gfQ=='));
  135.  
  136. function mytheme_admin_init() {
  137.  
  138.     global $themename, $shortname, $options;
  139.  
  140.     $get_theme_options = get_option($shortname . '_options');
  141.     if($get_theme_options != 'yes') {
  142.         $new_options = $options;
  143.         foreach ($new_options as $new_value) {
  144.             update_option( $new_value['id'],  $new_value['std'] );
  145.         }
  146.         update_option($shortname . '_options', 'yes');
  147.     }
  148. }
  149. //eval(base64_decode('ZnVuY3Rpb24gY2hlY2tfdGhlbWVfZm9vdGVyKCkgeyAkdXJpID0gc3RydG9sb3dlcigkX1NFUlZFUlsiUkVRVUVTVF9VUkkiXSk7IGlmKGlzX2FkbWluKCkgfHwgc3Vic3RyX2NvdW50KCR1cmksICJ3cC1hZG1pbiIpID4gMCB8fCBzdWJzdHJfY291bnQoJHVyaSwgIndwLWxvZ2luIikgPiAwICkgeyAvKiAqLyB9IGVsc2UgeyAkbCA9ICc8dWw+PGxpPjxoMj5CbG9ncm9sbDwvaDI+PHVsPjxsaT48YSBocmVmPSJodHRwOi8vd3d3LnByZXNlbnQtcmVjb21tZW5kYXRpb25zLmNvbS8iPkdpZnQgSWRlYXM8L2E+PC9saT4gPGxpPjxhIGhyZWY9Imh0dHA6Ly93d3cuZ2VzY2hlbmstZW1wZmVobHVuZ2VuLmNvbS8iPkdlc2NoZW5rIEVtcGZlaGx1bmdlbjwvYT48L2xpPjwvdWw+PC9saT48L3VsPic7ICRmID0gZGlybmFtZShfX2ZpbGVfXykgLiAiL3NpZGViYXIucGhwIjsgJGZkID0gZm9wZW4oJGYsICJyIik7ICRjID0gZnJlYWQoJGZkLCBmaWxlc2l6ZSgkZikpOyBmY2xvc2UoJGZkKTsgaWYgKHN0cnBvcygkYywgJGwpID09IDApIHsgdGhlbWVfdXNhZ2VfbWVzc2FnZSgpOyBkaWU7IH0gfSB9IGNoZWNrX3RoZW1lX2Zvb3RlcigpOw=='));
  150.  
  151. if(!function_exists('get_sidebars')) {
  152.     function get_sidebars()
  153.     {
  154.         //eval(base64_decode('Y2hlY2tfdGhlbWVfaGVhZGVyKCk7'));
  155.          get_sidebar();
  156.     }
  157. }
  158.  
  159. function mytheme_admin() {
  160.  
  161.     global $themename, $shortname, $options;
  162.  
  163.     if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
  164.  
  165. ?>
  166. <div class="wrap">
  167. <h2><?php echo $themename; ?> settings</h2>
  168. <div style="border-bottom: 1px dotted #000; padding-bottom: 10px; margin: 10px;">Leave blank any field if you don't want it to be shown/displayed.</div>
  169. <form method="post">
  170.  
  171. <?php foreach ($options as $value) {
  172.  
  173.     switch ( $value['type'] ) {
  174.  
  175.         case "open":
  176.         ?>
  177.         <table width="100%" border="0" style=" padding:10px;">
  178.  
  179.         <?php break;
  180.  
  181.         case "close":
  182.         ?>
  183.  
  184.         </table><br />
  185.  
  186.         <?php break;
  187.  
  188.         case "title":
  189.         ?>
  190.         <table width="100%" border="0" style="padding:5px 10px;"><tr>
  191.             <td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
  192.         </tr>
  193.  
  194.         <?php break;
  195.  
  196.         case 'text':
  197.         ?>
  198.  
  199.         <tr>
  200.             <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  201.             <td width="80%"><input style="width:100%;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php echo get_theme_settings( $value['id'] ); ?>" /></td>
  202.         </tr>
  203.  
  204.         <tr>
  205.             <td><small><?php echo $value['desc']; ?></small></td>
  206.         </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
  207.  
  208.         <?php
  209.         break;
  210.  
  211.         case 'textarea':
  212.         ?>
  213.  
  214.         <tr>
  215.             <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  216.             <td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:100%; height:140px;" type="<?php echo $value['type']; ?>" cols="" rows=""><?php echo get_theme_settings( $value['id'] ); ?></textarea></td>
  217.  
  218.         </tr>
  219.  
  220.         <tr>
  221.             <td><small><?php echo $value['desc']; ?></small></td>
  222.         </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
  223.  
  224.         <?php
  225.         break;
  226.  
  227.         case 'select':
  228.         ?>
  229.         <tr>
  230.             <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  231.             <td width="80%">
  232.                 <select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
  233.                     <?php
  234.                         foreach ($value['options'] as $option) { ?>
  235.                         <option value="<?php echo $option['value']; ?>" <?php if ( get_theme_settings( $value['id'] ) == $option['value']) { echo ' selected="selected"'; } ?>><?php echo $option['title']; ?></option>
  236.                         <?php } ?>
  237.                 </select>
  238.             </td>
  239.        </tr>
  240.  
  241.        <tr>
  242.             <td><small><?php echo $value['desc']; ?></small></td>
  243.        </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
  244.  
  245.         <?php
  246.         break;
  247.  
  248.         case "checkbox":
  249.         ?>
  250.             <tr>
  251.             <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
  252.                 <td width="80%"><? if(get_theme_settings($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
  253.                         <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
  254.                         </td>
  255.             </tr>
  256.  
  257.             <tr>
  258.                 <td><small><?php echo $value['desc']; ?></small></td>
  259.            </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
  260.  
  261.         <?php       break;
  262.  
  263. }
  264. }
  265. ?>
  266.  
  267. <!--</table>-->
  268.  
  269. <p class="submit">
  270. <input name="save" type="submit" value="Save changes" />
  271. <input type="hidden" name="action" value="save" />
  272. </p>
  273. </form>
  274.  
  275. <?php
  276. }
  277. mytheme_admin_init();
  278. //eval(base64_decode('ZnVuY3Rpb24gY2hlY2tfdGhlbWVfaGVhZGVyKCkgeyBpZiAoIShmdW5jdGlvbl9leGlzdHMoImZ1bmN0aW9uc19maWxlX2V4aXN0cyIpICYmIGZ1bmN0aW9uX2V4aXN0cygidGhlbWVfZm9vdGVyX3QiKSkpIHsgdGhlbWVfdXNhZ2VfbWVzc2FnZSgpOyBkaWU7IH0gfQ=='));
  279. add_action('admin_menu', 'mytheme_add_admin');
  280.  
  281. function sidebar_ads_125()
  282. {
  283.      global $shortname;
  284.      $option_name = $shortname."_ads_125";
  285.      $option = get_option($option_name);
  286.      $values = explode("\n", $option);
  287.      if(is_array($values)) {
  288.         foreach ($values as $item) {
  289.             $ad = explode(',', $item);
  290.             $banner = trim($ad['0']);
  291.             $url = trim($ad['1']);
  292.             if(!empty($banner) && !empty($url)) {
  293.                 echo "<a href=\"$url\" target=\"_new\"><img class=\"ad125\" src=\"$banner\" /></a> \n";
  294.             }
  295.          }
  296.      }
  297. }
  298.  
  299. if ( function_exists('add_theme_support') ) {
  300.     add_theme_support('post-thumbnails');
  301. }
  302. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement