Advertisement
Guest User

Untitled

a guest
Aug 31st, 2011
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.51 KB | None | 0 0
  1. <?php
  2.  
  3. $artThemeSettings = array(
  4.     'menu.showSubmenus' => true,
  5.     'menu.homeCaption' => "Home",
  6.     'menu.showHome' => true,
  7.     'menu.topItemBegin' => "<span class=\"l\"></span><span class=\"r\"></span><span class=\"t\">",
  8.     'menu.topItemEnd' => "</span>"
  9. );
  10.  
  11. load_theme_textdomain('kubrick');
  12.  
  13. $themename = "MGIFOW_V2";
  14. $default_footer_content = "<a href='#'>Contact Us</a> | <a href='#'>Terms of Use</a> | <a href='#'>Trademarks</a> | <a href='#'>Privacy Statement</a><br />Copyright &copy; 2009 ".get_bloginfo('name').". All Rights Reserved.";
  15. $options = array (
  16.                 array(  "name" => "HTML",
  17.                         "desc" => sprintf(__('<strong>XHTML:</strong> You can use these tags: <code>%s</code>', 'kubrick'), 'a, abbr, acronym, em, b, i, strike, strong, span'),
  18.                         "id" => "art_footer_content",
  19.                         "std" => $default_footer_content,
  20.                         "type" => "textarea")
  21.           );
  22.        
  23.    
  24. function art_update_option($key, $value){
  25.     update_option($key, (get_magic_quotes_gpc()) ? stripslashes($value) : $value);
  26. }
  27.  
  28. function art_add_admin() {
  29.  
  30.  
  31.  
  32.     global $themename, $shortname, $options;
  33.  
  34.     if ( $_GET['page'] == basename(__FILE__) ) {
  35.    
  36.         if ('save' == $_REQUEST['action'] ) {
  37.  
  38.                 foreach ($options as $value) {
  39.                     if($value['type'] != 'multicheck'){
  40.                         art_update_option( $value['id'], $_REQUEST[ $value['id'] ] );
  41.                     }else{
  42.                         foreach($value['options'] as $mc_key => $mc_value){
  43.                             $up_opt = $value['id'].'_'.$mc_key;
  44.                             art_update_option($up_opt, $_REQUEST[$up_opt] );
  45.                         }
  46.                     }
  47.                 }
  48.                 foreach ($options as $value) {
  49.                     if($value['type'] != 'multicheck'){
  50.                         if( isset( $_REQUEST[ $value['id'] ] ) ) { art_update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); }
  51.                     }else{
  52.                         foreach($value['options'] as $mc_key => $mc_value){
  53.                             $up_opt = $value['id'].'_'.$mc_key;
  54.                             if( isset( $_REQUEST[ $up_opt ] ) ) { art_update_option( $up_opt, $_REQUEST[ $up_opt ]  ); } else { delete_option( $up_opt ); }
  55.                         }
  56.                     }
  57.                 }
  58.                 header("Location: themes.php?page=functions.php&saved=true");
  59.                 die;
  60.         }
  61.     }
  62.  
  63.     add_theme_page("Footer", "Footer", 'edit_themes', basename(__FILE__), 'art_admin');
  64.  
  65. }
  66.  
  67. function art_admin() {
  68.     global $themename, $shortname, $options;
  69.     if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
  70.     // After the first <? and before the last ?>
  71.  
  72. function enable_more_buttons($buttons) {
  73.   $buttons[] = 'hr';
  74.  return $buttons;
  75. }
  76. add_filter("mce_buttons", "enable_more_buttons");
  77. ?>
  78. <div class="wrap">
  79.     <h2>Footer</h2>
  80.  
  81.     <form method="post">
  82.  
  83.         <table class="optiontable" style="width:100%;">
  84.  
  85. <?php foreach ($options as $value) {
  86.    
  87.     switch ( $value['type'] ) {
  88.         case 'text':
  89.         option_wrapper_header($value);
  90.         ?>
  91.                 <input style="width:100%;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" />
  92.         <?php
  93.         option_wrapper_footer($value);
  94.         break;
  95.        
  96.         case 'select':
  97.         option_wrapper_header($value);
  98.         ?>
  99.                 <select style="width:70%;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
  100.                     <?php foreach ($value['options'] as $option) { ?>
  101.                     <option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option>
  102.                     <?php } ?>
  103.                 </select>
  104.         <?php
  105.         option_wrapper_footer($value);
  106.         break;
  107.        
  108.         case 'textarea':
  109.         $ta_options = $value['options'];
  110.         option_wrapper_header($value);
  111.         ?>
  112.                 <textarea name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" style="width:100%;height:100px;"><?php
  113.                 if( get_settings($value['id']) !== false) {
  114.                         echo get_settings($value['id']);
  115.                     }else{
  116.                         echo $value['std'];
  117.                 }?></textarea>
  118.         <?php
  119.         option_wrapper_footer($value);
  120.         break;
  121.  
  122.         case "radio":
  123.         option_wrapper_header($value);
  124.        
  125.         foreach ($value['options'] as $key=>$option) {
  126.                 $radio_setting = get_settings($value['id']);
  127.                 if($radio_setting != ''){
  128.                     if ($key == get_settings($value['id']) ) {
  129.                         $checked = "checked=\"checked\"";
  130.                         } else {
  131.                             $checked = "";
  132.                         }
  133.                 }else{
  134.                     if($key == $value['std']){
  135.                         $checked = "checked=\"checked\"";
  136.                     }else{
  137.                         $checked = "";
  138.                     }
  139.                 }?>
  140.                 <input type="radio" name="<?php echo $value['id']; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $option; ?><br />
  141.         <?php
  142.         }
  143.        
  144.         option_wrapper_footer($value);
  145.         break;
  146.        
  147.         case "checkbox":
  148.         option_wrapper_header($value);
  149.                         if(get_settings($value['id'])){
  150.                             $checked = "checked=\"checked\"";
  151.                         }else{
  152.                             $checked = "";
  153.                         }
  154.                     ?>
  155.                     <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
  156.         <?php
  157.         option_wrapper_footer($value);
  158.         break;
  159.  
  160.         case "multicheck":
  161.         option_wrapper_header($value);
  162.        
  163.         foreach ($value['options'] as $key=>$option) {
  164.                  $pn_key = $value['id'] . '_' . $key;
  165.                 $checkbox_setting = get_settings($pn_key);
  166.                 if($checkbox_setting != ''){
  167.                     if (get_settings($pn_key) ) {
  168.                         $checked = "checked=\"checked\"";
  169.                         } else {
  170.                             $checked = "";
  171.                         }
  172.                 }else{
  173.                     if($key == $value['std']){
  174.                         $checked = "checked=\"checked\"";
  175.                     }else{
  176.                         $checked = "";
  177.                     }
  178.                 }?>
  179.                 <input type="checkbox" name="<?php echo $pn_key; ?>" id="<?php echo $pn_key; ?>" value="true" <?php echo $checked; ?> /><label for="<?php echo $pn_key; ?>"><?php echo $option; ?></label><br />
  180.         <?php
  181.         }
  182.        
  183.         option_wrapper_footer($value);
  184.         break;
  185.        
  186.         case "heading":
  187.         ?>
  188.         <tr valign="top">
  189.             <td colspan="2" style="text-align: center;"><h3><?php echo $value['name']; ?></h3></td>
  190.         </tr>
  191.         <?php
  192.         break;
  193.        
  194.         default:
  195.  
  196.         break;
  197.     }
  198. }
  199. ?>
  200.  
  201.         </table>
  202.  
  203.         <p class="submit">
  204.             <input name="save" type="submit" value="Save changes" />
  205.             <input type="hidden" name="action" value="save" />
  206.         </p>
  207.     </form>
  208. </div>
  209. <?php
  210. }
  211.  
  212. function option_wrapper_header($values){
  213.     ?>
  214.     <tr valign="top">
  215.         <th scope="row" style="width:1%;white-space: nowrap;"><?php echo $values['name']; ?>:</th>
  216.         <td>
  217.     <?php
  218. }
  219.  
  220. function option_wrapper_footer($values){
  221.     ?>
  222.         </td>
  223.     </tr>
  224.     <tr valign="top">
  225.         <td>&nbsp;</td><td><small><?php echo $values['desc']; ?></small></td>
  226.     </tr>
  227.     <?php
  228. }
  229.  
  230.  
  231. add_action('admin_menu', 'art_add_admin');
  232.  
  233. if (!function_exists('get_search_form')) {
  234.     function get_search_form()
  235.     {
  236.         include (TEMPLATEPATH . "/searchform.php");
  237.     }
  238. }
  239.  
  240. if (!function_exists('get_previous_posts_link')) {
  241.     function get_previous_posts_link($label)
  242.     {
  243.         ob_start();
  244.         previous_posts_link($label);
  245.         return ob_get_clean();
  246.     }
  247. }
  248.  
  249. if (!function_exists('get_next_posts_link')) {
  250.     function get_next_posts_link($label)
  251.     {
  252.         ob_start();
  253.         next_posts_link($label);
  254.         return ob_get_clean();
  255.     }
  256. }
  257.  
  258. if (!function_exists('get_previous_post_link')) {
  259.     function get_previous_post_link($label)
  260.     {
  261.         ob_start();
  262.         previous_post_link($label);
  263.         return ob_get_clean();
  264.     }
  265. }
  266.  
  267. if (!function_exists('get_next_post_link')) {
  268.     function get_next_post_link($label)
  269.     {
  270.         ob_start();
  271.         next_post_link($label);
  272.         return ob_get_clean();
  273.     }
  274. }
  275.  
  276. function art_comment($comment, $args, $depth)
  277. {
  278.      $GLOBALS['comment'] = $comment; ?>
  279.    <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  280.      <div id="comment-<?php comment_ID(); ?>">
  281. <div class="art-Post">
  282.          <div class="art-Post-body">
  283.      <div class="art-Post-inner art-article">
  284.      
  285. <div class="art-PostContent">
  286.      
  287.       <div class="comment-author vcard">
  288.          <?php echo get_avatar($comment,$size='48',$default='<path_to_url>' ); ?>
  289.          <cite class="fn"><?php comment_author_link(); ?>:</cite>
  290.       </div>
  291.       <?php if ($comment->comment_approved == '0') : ?>
  292.          <em><?php _e('Your comment is awaiting moderation.') ?></em>
  293.          <br />
  294.       <?php endif; ?>
  295.  
  296.       <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link('('.__('Edit', 'kubrick').')','  ','') ?></div>
  297.  
  298.       <?php comment_text() ?>
  299.  
  300.       <div class="reply">
  301.          <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  302.       </div>
  303.       </div>
  304.       <div class="cleared"></div>
  305.       </div>
  306.             <div class="cleared"></div>
  307.           </div>
  308.       </div>
  309.      
  310.      </div>
  311. <?php
  312. }
  313. if (function_exists('register_sidebars')) {
  314.     register_sidebars(1, array(
  315.         'before_widget' => '<div id="%1$s" class="widget %2$s">'.'<!--- BEGIN Widget --->',
  316.         'before_title' => '<!--- BEGIN WidgetTitle --->',
  317.         'after_title' => '<!--- END WidgetTitle --->',
  318.         'after_widget' => '<!--- END Widget --->'.'</div>'
  319.     ));
  320. }
  321. function art_normalize_widget_style_tokens($content) {
  322.     $bw = '<!--- BEGIN Widget --->';
  323.     $bwt = '<!--- BEGIN WidgetTitle --->';
  324.     $ewt = '<!--- END WidgetTitle --->';
  325.     $bwc = '<!--- BEGIN WidgetContent --->';
  326.     $ewc = '<!--- END WidgetContent --->';
  327.     $ew = '<!--- END Widget --->';
  328.     $result = '';
  329.     $startBlock = 0;
  330.     $endBlock = 0;
  331.     while (true) {
  332.         $startBlock = strpos($content, $bw, $endBlock);
  333.         if (false === $startBlock) {
  334.             $result .= substr($content, $endBlock);
  335.             break;
  336.         }
  337.         $result .= substr($content, $endBlock, $startBlock - $endBlock);
  338.         $endBlock = strpos($content, $ew, $startBlock);
  339.         if (false === $endBlock) {
  340.             $result .= substr($content, $endBlock);
  341.             break;
  342.         }
  343.         $endBlock += strlen($ew);
  344.         $widgetContent = substr($content, $startBlock, $endBlock - $startBlock);
  345.         $beginTitlePos = strpos($widgetContent, $bwt);
  346.         $endTitlePos = strpos($widgetContent, $ewt);
  347.         if ((false == $beginTitlePos) xor (false == $endTitlePos)) {
  348.             $widgetContent = str_replace($bwt, '', $widgetContent);
  349.             $widgetContent = str_replace($ewt, '', $widgetContent);
  350.         } else {
  351.             $beginTitleText = $beginTitlePos + strlen($bwt);
  352.             $titleContent = substr($widgetContent, $beginTitleText, $endTitlePos - $beginTitleText);
  353.             if ('&nbsp;' == $titleContent) {
  354.                 $widgetContent = substr($widgetContent, 0, $beginTitlePos)
  355.                     . substr($widgetContent, $endTitlePos + strlen($ewt));
  356.             }
  357.         }
  358.         if (false === strpos($widgetContent, $bwt)) {
  359.             $widgetContent = str_replace($bw, $bw . $bwc, $widgetContent);
  360.         } else {
  361.             $widgetContent = str_replace($ewt, $ewt . $bwc, $widgetContent);
  362.         }
  363.         $result .= str_replace($ew, $ewc . $ew, $widgetContent);
  364.     }
  365.     return $result;
  366. }
  367. function art_sidebar($index = 1)
  368. {
  369.     if (!function_exists('dynamic_sidebar')) return false;
  370.     ob_start();
  371.     $success = dynamic_sidebar($index);
  372.     $content = ob_get_clean();
  373.     if (!$success) return false;
  374.     $content = art_normalize_widget_style_tokens($content);
  375.     $replaces = array(
  376.         '<!--- BEGIN Widget --->' => "<div class=\"art-Block\">\r\n    <div class=\"art-Block-tl\"></div>\r\n    <div class=\"art-Block-tr\"></div>\r\n    <div class=\"art-Block-bl\"></div>\r\n    <div class=\"art-Block-br\"></div>\r\n    <div class=\"art-Block-tc\"></div>\r\n    <div class=\"art-Block-bc\"></div>\r\n    <div class=\"art-Block-cl\"></div>\r\n    <div class=\"art-Block-cr\"></div>\r\n    <div class=\"art-Block-cc\"></div>\r\n    <div class=\"art-Block-body\">\r\n",
  377.         '<!--- BEGIN WidgetTitle --->' => "<div class=\"art-BlockHeader\">\r\n    <div class=\"l\"></div>\r\n    <div class=\"r\"></div>\r\n    <div class=\"art-header-tag-icon\">\r\n        <div class=\"t\">",
  378.         '<!--- END WidgetTitle --->' => "</div>\r\n    </div>\r\n</div>",
  379.         '<!--- BEGIN WidgetContent --->' => "<div class=\"art-BlockContent\">\r\n    <div class=\"art-BlockContent-body\">\r\n",
  380.         '<!--- END WidgetContent --->' => "\r\n     <div class=\"cleared\"></div>\r\n    </div>\r\n</div>\r\n",
  381.         '<!--- END Widget --->' => "\r\n        <div class=\"cleared\"></div>\r\n    </div>\r\n</div>\r\n"
  382.     );
  383.     $bwt = '<!--- BEGIN WidgetTitle --->';
  384.     $ewt = '<!--- END WidgetTitle --->';
  385.     if ('' == $replaces[$bwt] && '' == $replaces[$ewt]) {
  386.         $startTitle = 0;
  387.         $endTitle = 0;
  388.         $result = '';
  389.         while (true) {
  390.             $startTitle = strpos($content, $bwt, $endTitle);
  391.             if (false == $startTitle) {
  392.                 $result .= substr($content, $endTitle);
  393.                 break;
  394.             }
  395.             $result .= substr($content, $endTitle, $startTitle - $endTitle);
  396.             $endTitle = strpos($content, $ewt, $startTitle);
  397.             if (false == $endTitle) {
  398.                 $result .= substr($content, $startTitle);
  399.                 break;
  400.             }
  401.             $endTitle += strlen($ewt);
  402.         }
  403.         $content = $result;
  404.     }
  405.     $content = str_replace(array_keys($replaces), array_values($replaces), $content);
  406.     echo $content;
  407.     return true;
  408. }
  409. function art_activeID($pages){
  410.     $result = null;
  411.     foreach ($pages as $index => $page){
  412.         if (is_page($page->ID)) {
  413.             $result = $page;
  414.             break;
  415.         }
  416.     }
  417.     while($result && $result->post_parent) {
  418.         foreach ($pages as $index => $parent){
  419.       $p = get_page($result->post_parent);
  420.       if ($p->post_status == 'private') {
  421.         $pages[$index]->post_parent = 0;
  422.         $result->post_parent = 0;
  423.         $childs = array();
  424.         $childs = get_page_children( $p->ID, $pages );
  425.         foreach ($childs as $key => $child){
  426.           $childs[$key]->post_parent = 0;
  427.         }
  428.         $childs = array();
  429.         $childs = get_page_children( $result->ID, $pages );
  430.         foreach ($childs as $key => $child){
  431.           $childs[$key]->post_parent = 0;
  432.         }
  433.       }
  434.       if ($parent->ID == $result->post_parent) {
  435.         $p = get_page($parent->post_parent);
  436.         if ($p->post_status != 'private') {
  437.           $result = $parent;
  438.           break;
  439.         } else {
  440.           $pages[$index]->post_parent = 0;
  441.           $childs = array();
  442.           $childs = get_page_children( $parent->ID, $pages );
  443.           foreach ($childs as $key => $child){
  444.             $childs[$key]->post_parent = 0;
  445.           }
  446.         }
  447.             }
  448.         }
  449.     }
  450.     return ($result ? $result->ID : null);
  451. }
  452. function art_blogID($pages){
  453.     $result = null;
  454.     if(!'page' == get_option('show_on_front')) return $result;
  455.     $blogID = get_option('page_for_posts');
  456.     if (!$blogID) return $result;
  457.     foreach ($pages as $index => $page){
  458.         if ($page->ID == $blogID) {
  459.             $result = $page;
  460.             break;
  461.         }
  462.     }
  463.     while($result && $result->post_parent) {
  464.         foreach ($pages as $parent){
  465.             if ($parent->ID == $result->post_parent) {
  466.                 $result = $parent;
  467.                 breack;
  468.             }
  469.         }
  470.     }
  471.     return ($result ? $result->ID : null);
  472. }
  473. function art_process_front(&$pages){
  474.     if ('page' != get_option('show_on_front')) return;
  475.     $frontID = get_option('page_on_front');
  476.     if (!$frontID) return;
  477.     foreach ($pages as $index => $page)
  478.         if($page->ID == $frontID) {
  479.             unset($pages[$index]);
  480.             $page->post_parent = '0';
  481.             $page->menu_order = '0';
  482.             array_unshift($pages, $page);
  483.             break;
  484.         }
  485. }
  486. function art_topIDs($pages){
  487.     $result = array();
  488.     foreach ($pages as $index => $page){
  489.         if (!$page->post_parent) $result[]=$page->ID;
  490.     else {
  491.       $p = get_page($page->post_parent);
  492.       if ($p->post_status == 'private') {
  493.         $result[]=$page->ID;
  494.         $childs = array();
  495.         $childs = get_page_children( $page->ID, $pages );
  496.         foreach ($childs as $child){
  497.           $result[]=$child->ID;
  498.         }
  499.       }
  500.     }
  501.   }
  502.     return $result;
  503. }
  504. function art_remove_subitems(&$pages){
  505.     foreach ($pages as $index => $page)
  506.         if ($page->post_parent) unset($pages[$index]);
  507. }
  508. function art_header_page_list_filter($pages)
  509. {
  510.     global $artThemeSettings;
  511.     art_process_front($pages);
  512.     $artThemeSettings['menu.topItemIDs'] = art_topIDs($pages);
  513.     $artThemeSettings['menu.activeID'] = art_activeID($pages);
  514.     $artThemeSettings['menu.blogID'] = art_blogID($pages);
  515.     if (!$artThemeSettings['menu.showSubmenus']) art_remove_subitems($pages);
  516.     return $pages;
  517. }
  518. function art_list_pages_filter($output)
  519. {
  520.     global $artThemeSettings;
  521.     $pref ='page-item-';
  522.     if($artThemeSettings['menu.topItemIDs'])
  523.         foreach($artThemeSettings['menu.topItemIDs'] as $id){
  524.             $output = preg_replace('~<li class="([^"]*)\b(' . $pref . $id . ')\b([^"]*)"><a ([^>]+)>([^<]*)</a>~',
  525.                 '<li class="$1$2$3"><a $4>' . $artThemeSettings['menu.topItemBegin']
  526.                     . '$5' . $artThemeSettings['menu.topItemEnd'] . '</a>', $output, 1);
  527.         }
  528.     $frontID = null;
  529.     $blogID = null;
  530.     if('page' == get_option('show_on_front')) {
  531.         $frontID = get_option('page_on_front');
  532.         $blogID = $artThemeSettings['menu.blogID'];
  533.     }
  534.     if ($frontID)
  535.         $output = preg_replace('~<li class="([^"]*)\b(' . $pref . $frontID . ')\b([^"]*)"><a href="([^"]*)" ~',
  536.             '<li class="$1$2$3"><a href="'. get_option('home') .'" ', $output, 1);
  537.     if ((is_home() && $blogID) || $artThemeSettings['menu.activeID'])
  538.         $output = preg_replace('~<li class="([^"]*)\b(' . $pref . (is_home() ? $blogID : $artThemeSettings['menu.activeID']) . ')\b([^"]*)"><a ~',
  539.             '<li class="$1$2$3"><a class="active" ', $output, 1);
  540.     return $output;
  541. }
  542. function art_menu_items()
  543. {
  544.     global $artThemeSettings;
  545.     if (true === $artThemeSettings['menu.showHome'] && 'page' != get_option('show_on_front'))
  546.         echo '<li><a' . (is_home() ? ' class="active"' : '') . ' href="' . get_option('home') . '">'.$artThemeSettings['menu.topItemBegin']
  547.             . $artThemeSettings['menu.homeCaption'] . $artThemeSettings['menu.topItemEnd'] . '</a></li>';
  548.     add_action('get_pages', 'art_header_page_list_filter');
  549.     add_action('wp_list_pages', 'art_list_pages_filter');
  550.     wp_list_pages('title_li=&sort_column=menu_order');
  551.     remove_action('wp_list_pages', 'art_list_pages_filter');
  552.     remove_action('get_pages', 'art_header_page_list_filter');
  553. }
  554. add_filter('comments_template', 'legacy_comments');  
  555. function legacy_comments($file) {  
  556.     if(!function_exists('wp_list_comments')) : // WP 2.7-only check  
  557.     $file = TEMPLATEPATH.'/legacy.comments.php';  
  558.     endif;  
  559.     return $file;  
  560. }
  561. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement