Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 26.11 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /**
  3.  * Miscellaneous Theme Functions
  4.  */
  5.  
  6. /**
  7.  * Register widgetized areas, including two sidebars and six widget-ready columns in the footer.
  8.  *
  9.  */
  10. function webtreats_widgets_init() {
  11.         register_sidebar( array(
  12.                 'name' =>  'Primary Widget Area',
  13.                 'description' => 'The primary widget area',
  14.                 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  15.                 'after_widget' => '</div>',
  16.                 'before_title' => '<h3 class="widgettitle">',
  17.                 'after_title' => '</h3>',
  18.         ) );
  19.  
  20.         register_sidebar( array(
  21.                 'name' => 'Homepage Widget Area',
  22.                 'description' => 'The homepage widget area',
  23.                 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  24.                 'after_widget' => '</div>',
  25.                 'before_title' => '<h3 class="widgettitle">',
  26.                 'after_title' => '</h3>',
  27.         ) );
  28.  
  29.         register_sidebar( array(
  30.                 'name' => 'First Footer Widget Area',
  31.                 'description' => 'The first footer widget area',
  32.                 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  33.                 'after_widget' => '</div>',
  34.                 'before_title' => '<h6 class="footer_widgettitle">',
  35.                 'after_title' => '</h6>',
  36.         ) );
  37.  
  38.         register_sidebar( array(
  39.                 'name' => 'Second Footer Widget Area',
  40.                 'description' => 'The second footer widget area',
  41.                 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  42.                 'after_widget' => '</div>',
  43.                 'before_title' => '<h6 class="footer_widgettitle">',
  44.                 'after_title' => '</h6>',
  45.         ) );
  46.  
  47.         register_sidebar( array(
  48.                 'name' => 'Third Footer Widget Area',
  49.                 'description' => 'The third footer widget area',
  50.                 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  51.                 'after_widget' => '</div>',
  52.                 'before_title' => '<h6 class="footer_widgettitle">',
  53.                 'after_title' => '</h6>',
  54.         ) );
  55.  
  56.         register_sidebar( array(
  57.                 'name' => 'Fourth Footer Widget Area',
  58.                 'description' => 'The fourth footer widget area',
  59.                 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  60.                 'after_widget' => '</div>',
  61.                 'before_title' => '<h6 class="footer_widgettitle">',
  62.                 'after_title' => '</h6>',
  63.         ) );
  64.        
  65.         register_sidebar( array(
  66.                 'name' => 'Fifth Footer Widget Area',
  67.                 'description' => 'The fifth footer widget area',
  68.                 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  69.                 'after_widget' => '</div>',
  70.                 'before_title' => '<h6 class="footer_widgettitle">',
  71.                 'after_title' => '</h6>',
  72.         ) );
  73.        
  74.         register_sidebar( array(
  75.                 'name' => 'Sixth Footer Widget Area',
  76.                 'description' => 'The sixth footer widget area',
  77.                 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  78.                 'after_widget' => '</div>',
  79.                 'before_title' => '<h6 class="footer_widgettitle">',
  80.                 'after_title' => '</h6>',
  81.         ) );
  82. }
  83. /** Register sidebars by running webtreats_widgets_init() on the widgets_init hook. */
  84. add_action( 'widgets_init', 'webtreats_widgets_init' );
  85.  
  86.  
  87. function new_more_link( $more_link, $more_link_text ) {
  88.        
  89.         $more_link = '[raw]' .$more_link. '[/raw]';
  90.        
  91.         return str_replace('more-link', 'fancy_link read_more_link', $more_link );
  92. }
  93. add_filter('the_content_more_link', 'new_more_link', 10, 2);
  94.  
  95.  
  96. function new_excerpt_more($excerpt) {
  97.         return str_replace('[...]', '...', $excerpt);
  98. }
  99. add_filter('wp_trim_excerpt', 'new_excerpt_more');
  100.  
  101.  
  102. function new_comment_author_link($return) {
  103.         return str_replace($return, "<span></span>$return", $return);
  104. }
  105. add_filter('get_comment_author_link', 'new_comment_author_link');
  106.  
  107.  
  108. function webtreats_excerpt($length, $ellipsis) {
  109.         $text = get_the_content();
  110.         $text = preg_replace('`\[(.*)]*\]`','',$text);
  111.         $text = strip_tags($text);
  112.         $text = substr($text, 0, $length);
  113.         $text = substr($text, 0, strripos($text, " "));
  114.         $text = $text.$ellipsis;
  115.         return $text;
  116. }
  117.  
  118.  
  119. function webtreats_truncate($string, $limit, $break=".", $pad="...") {
  120.         if(strlen($string) <= $limit) return $string;
  121.        
  122.          if(false !== ($breakpoint = strpos($string, $break, $limit))) {
  123.                 if($breakpoint < strlen($string) - 1) {
  124.                         $string = substr($string, 0, $breakpoint) . $pad;
  125.                 }
  126.           }
  127.         return $string;
  128. }
  129.  
  130.  
  131. function webtreats_image_resize($height,$width,$img_url) {
  132.  
  133.         $image['url'] = $img_url;
  134.         $image_path = explode($_SERVER['SERVER_NAME'], $image['url']);
  135.         $image_path = $_SERVER['DOCUMENT_ROOT'] . $image_path[1];
  136.         $image_info = @getimagesize($image_path);
  137.  
  138.         // If we cannot get the image locally, try for an external URL
  139.         if (!$image_info)
  140.                 $image_info = @getimagesize($image['url']);
  141.  
  142.         $image['width'] = $image_info[0];
  143.         $image['height'] = $image_info[1];
  144.         if($img_url != "" && ($image['width'] != $width || $image['height'] != $height || !isset($image['width']))){
  145.                 $img_url = WEBTREATS_SCRIPTS_FOLDER."/thumb.php?src=$img_url&amp;w=$width&amp;h=$height&amp;zc=1&amp;q=100";
  146.         }
  147.        
  148.         return $img_url;
  149. }
  150.  
  151.  
  152. function webtreats_image_format($img_url, $class, $alt, $title) {
  153.  
  154.         $image['url'] = $img_url;
  155.         $image_path = explode($_SERVER['SERVER_NAME'], $image['url']);
  156.         $image_path = $_SERVER['DOCUMENT_ROOT'] . $image_path[1];
  157.         $image_info = @getimagesize($image_path);
  158.  
  159.         // If we cannot get the image locally, try for an external URL
  160.         if (!$image_info)
  161.                 $image_info = @getimagesize($image['url']);
  162.  
  163.         $image['width'] = $image_info[0];
  164.         $image['height'] = $image_info[1];
  165.        
  166.         return '<img class="' .$class. ' framed" height="' .$image['height']. '" width="' .$image['width']. '" alt="' .$alt. '" title="' .$title. '" src="' . $img_url . '" />';
  167. }
  168.  
  169.  
  170. function webtreats_register_menus() {
  171.         global $themename;
  172.        
  173.         //If WP 3.0 or > include supprot for wp_nav_menu()
  174.         if(webtreats_check_wp_version()){
  175.                 register_nav_menus(
  176.                         array(
  177.                                 'primary-menu' => __( $themename. ' Menu' ),
  178.                         )
  179.                 );
  180.         }
  181.        
  182. }
  183. add_action( 'init', 'webtreats_register_menus' );
  184.  
  185.  
  186. function webtreats_menu() {
  187.         global $show_hide_pg;
  188.        
  189.         //If WP 3.0 or > include supprot for wp_nav_menu()
  190.         if(webtreats_check_wp_version()){
  191.                
  192.                 if ( has_nav_menu( 'primary-menu' ) ) {
  193.                         wp_nav_menu( array( 'menu' => 'primary-menu', 'container_id' => 'main_navigation', 'container_class' =>  'jqueryslidemenu unitPng', 'menu_class' => '', 'fallback_cb' => '' ) );
  194.                         return;
  195.                 }
  196.         }
  197.        
  198.         //Exclude a parent and all of that parent's child Pages
  199.         if($show_hide_pg) {
  200.                 $parent_pages_to_exclude = explode(",", $show_hide_pg);
  201.                 foreach($parent_pages_to_exclude as $parent_page_to_exclude) {
  202.                         if ($page_exclusions) { $page_exclusions .= ',' . $parent_page_to_exclude;
  203.                         }else{
  204.                         $page_exclusions = $parent_page_to_exclude; }
  205.                         $descendants = get_pages('child_of=' . $parent_page_to_exclude);
  206.                         if($descendants){
  207.                                 foreach($descendants as $descendant) {
  208.                                         $page_exclusions .= ',' . $descendant->ID;
  209.                                 }
  210.                         }
  211.                 }      
  212.         }
  213.  
  214.         //If !WP 3.0 or no menu created use wp_list_pages()
  215.         $active_class = (is_front_page()) ? 'class="current_page_item"' : '';
  216.  
  217.         $out .= '<div id="main_navigation" class="jqueryslidemenu unitPng">';
  218.         $out .= '<ul>';
  219.         $out .= '<li><a ' .$active_class. ' href="' .get_option('home'). '">Home</a></li>';
  220.  
  221.         $out .= wp_list_pages("sort_column=menu_order&exclude=$page_exclusions&title_li=&echo=0");
  222.         $out .= '</ul>';
  223.         $out .= '</div>';
  224.        
  225.         echo $out;
  226.                
  227. }
  228.  
  229.  
  230. function webtreats_social_header($variation_imgs) {
  231.         global $header_contact;
  232.        
  233.         require(WEBTREATS_INCLUDES . "/var.php");
  234.        
  235.         $style = ($header_contact) ? '' : ' style="top:35px;"';
  236.        
  237.         $out .= '<div id="social_header"' .$style. '><div class="social_header_background">';
  238.        
  239.         if(!$twitter_sociable_disable){
  240.                 $twitter_sociable = (!$twitter_sociable) ? 'http://twitter.com' : 'http://twitter.com/'.$twitter_sociable;
  241.                 $out .= '<div class="fade_hover"><a class="target_blank" href="' .$twitter_sociable. '"><img alt="" class="unitPng" src="' .$variation_imgs. '/header_sociables_twitter.png" height="22px" width="24px" /></a></div>';
  242.         }
  243.        
  244.         if(!$facebook_sociable_disable){
  245.                 $facebook_sociabl = (!$facebook_sociabl) ? 'http://www.facebook.com' : 'http://www.facebook.com/'.$facebook_sociabl;
  246.                 $out .= '<div class="fade_hover"><a class="target_blank" href="' .$facebook_sociabl. '"><img alt="" class="unitPng" src="' .$variation_imgs. '/header_sociables_facebook.png" height="22px" width="24px" /></a></div>';
  247.         }
  248.        
  249.         if(!$email_sociable_disable){
  250.                 $email_sociable = (!$email_sociable) ? get_option('admin_email') : $email_sociable;
  251.                 $out .= '<div class="fade_hover"><a href="#" rel="' .webtreats_nospam($email_sociable). '" class="email"><img alt="" class="unitPng" src="' .$variation_imgs. '/header_sociables_email.png" height="22" width="24" /></a></div>';
  252.         }
  253.        
  254.         if(!$rss_sociable_disable){
  255.                 $rss_sociable = (!$rss_sociable) ? get_bloginfo('rss2_url') : $rss_sociable;
  256.                 $out .= '<div class="fade_hover"><a href=" ' .$rss_sociable. '"><img alt="" class="unitPng" src="' .$variation_imgs. '/header_sociables_rss.png" height="22px" width="24px" /></a></div>';
  257.         }
  258.        
  259.         $out .= '</div></div>';
  260.        
  261.         echo $out;
  262. }
  263.  
  264.  
  265. function webtreats_title($post_id) {
  266.         global $blog_page;
  267.        
  268.         if(is_single()){
  269.                
  270.                 $portfolio_full = get_post_meta($post_id, 'portfolio_full_img',true);
  271.                 $portfolio_title_disable = get_post_meta($post_id, 'portfolio_title_disable',true);
  272.                 $blog_title_disable = get_post_meta($blog_page, 'disable_title',true);
  273.                
  274.                 if(!$portfolio_full && !$blog_title_disable){
  275.                         $pg_title = get_the_title($blog_page);
  276.                        
  277.                         return '<h1>' .$pg_title. '</h1>';
  278.                 }
  279.                
  280.                 if($portfolio_full && !$portfolio_title_disable){
  281.                         $category = get_the_category($post_id);
  282.                         $pg_title = $category[0]->cat_name;
  283.                        
  284.                         return '<h1>' .$pg_title. '</h1>';
  285.                 }
  286.                
  287.                 return;
  288.         }
  289.        
  290.        
  291.         if(is_page()){
  292.                 $disable_title = get_post_meta($post_id, 'disable_title',true);
  293.                
  294.                 if(!$disable_title){
  295.                         $pg_title = get_the_title($post_id);
  296.                         return '<h1>' .$pg_title. '</h1>';
  297.                 }
  298.                
  299.                 return;
  300.         }
  301.        
  302. }
  303.  
  304.  
  305. /**
  306.  * webtreats_teaser_text() - outputs HTML for teaser text
  307.  *
  308.  * @param int $post_id Post ID
  309.  */
  310. function webtreats_teaser_text($post_id) {
  311.         global $header_teaser, $teaser_custom, $blog_page, $twitter_id;
  312.        
  313.         //get_post_meta teaser text settings
  314.         $teaser_text = (get_post_meta($post_id, 'teaser_text', true)) ? get_post_meta($post_id, 'teaser_text', true) : 'default';
  315.         $teaser_text_custom = get_post_meta($post_id, 'teaser_text_custom', true);
  316.        
  317.         //teaser text disabled
  318.         if ( !is_search() ) {
  319.                 if( $teaser_text == 'default' && $header_teaser == 'disable' || $teaser_text == 'disable' ){
  320.                         return;
  321.                 }
  322.         }
  323.        
  324.         //if page is 404
  325.         if ( is_404() ) {
  326.             echo '<div id="intro_blurb">';
  327.                 echo '<div class="inner">';
  328.                 echo '<h1>404 - Not Found</h1>';
  329.                 echo '<div id="blurb">';
  330.                 echo "Looks like the page you're looking for isn't here anymore. Try using the search box or sitemap below.";
  331.                 echo '</div>';
  332.                 echo '</div>';
  333.                 echo '</div><!-- intro_blurb -->';
  334.                 echo '<div class="clearboth"></div>';
  335.                
  336.                 return;
  337.         }
  338.        
  339.         //if page is search
  340.         if ( is_search() ) {
  341.                
  342.                 if($header_teaser == 'disable'){ return; }
  343.                
  344.             echo '<div id="intro_blurb">';
  345.                 echo '<div class="inner">';
  346.                 echo '<h1>Search</h1>';
  347.                 echo '<div id="blurb">';
  348.                 echo 'Search Results for: &lsquo;'. get_search_query() .'&rsquo;';
  349.                 echo '</div>';
  350.                 echo '</div>';
  351.                 echo '</div><!-- intro_blurb -->';
  352.                 echo '<div class="clearboth"></div>';
  353.                
  354.                 return;
  355.         }
  356.        
  357.         //teaser text meta override
  358.         if( $teaser_text != 'default' && $teaser_text != 'disable'){
  359.                
  360.                 echo '<div id="intro_blurb">';
  361.                 echo '<div class="inner">';
  362.                 echo webtreats_title($post_id);
  363.                
  364.                 if ($teaser_text == 'custom' && $teaser_text_custom) {
  365.                         echo '<div id="blurb">';
  366.                         $teaser_text_custom = stripslashes($teaser_text_custom); echo do_shortcode($teaser_text_custom);
  367.                         echo '</div>';
  368.                 }
  369.                 if ($teaser_text == 'twitter' && !$twitter_id) {
  370.                         echo '<div id="blurb">';
  371.                         echo 'You must have your Twitter user name entered in the "General Settings" tab of your themes options for this to function properly.';
  372.                         echo '</div>';
  373.                 }
  374.                 if ($teaser_text == 'twitter' && $twitter_id) {
  375.                         echo '<div id="blurb">';
  376.                         $usernames = $twitter_id; $limit = '1'; $type = 'teaser';
  377.                         echo parse_cache_twitter_feed($usernames, $limit, $type);
  378.                         echo '</div>';
  379.                 }
  380.                
  381.                 echo '</div>';
  382.                 echo '</div><!-- intro_blurb -->';
  383.                 echo '<div class="clearboth"></div>';
  384.         }
  385.        
  386.        
  387.         //teaser text default
  388.         if( $header_teaser != 'disable' && $teaser_text == 'default' ){
  389.                
  390.                 echo '<div id="intro_blurb">';
  391.                 echo '<div class="inner">';
  392.                 echo webtreats_title($post_id);
  393.                
  394.                 if ($header_teaser == 'customtext' && $teaser_custom) {
  395.                         echo '<div id="blurb">';
  396.                         $teaser_custom = stripslashes($teaser_custom); echo do_shortcode($teaser_custom);
  397.                         echo '</div>';
  398.                 }
  399.                 if ($header_teaser == 'twitter' && !$twitter_id) {
  400.                         echo '<div id="blurb">';
  401.                         echo 'You must have your Twitter user name entered in the "General Settings" tab of your themes options for this to function properly.';
  402.                         echo '</div>';
  403.                 }
  404.                 if ($header_teaser == 'twitter' && $twitter_id) {
  405.                         echo '<div id="blurb">';
  406.                         $usernames = $twitter_id; $limit = '1'; $type = 'teaser';
  407.                         echo parse_cache_twitter_feed($usernames, $limit, $type);
  408.                         echo '</div>';
  409.                 }
  410.                
  411.                 echo '</div>';
  412.                 echo '</div><!-- intro_blurb -->';
  413.                 echo '<div class="clearboth"></div>';
  414.         }
  415.        
  416. }
  417.  
  418.  
  419. function webtreats_contact_form($email) {
  420.  
  421.         $email_adress_reciever = $email != "" ? $email : get_option('admin_email');
  422.        
  423.         //If the form is submitted
  424.         if(isset($_POST['submittedContact'])) {
  425.                 require(WEBTREATS_INCLUDES . "/submit.php");
  426.         }
  427.        
  428.         if(isset($emailSent) && $emailSent == true) {
  429.                
  430.                 $out .= '<a name="contact_"></a>';
  431.                 $out .= '<p class="thanks"><strong>Thanks!</strong> Your email was successfully sent.</p>';
  432.                
  433.         } else {
  434.                
  435.                 if(isset($captchaError)) {
  436.                         $out .= '<a name="contact_"></a>';
  437.                         $out .= '<p class="error">There was an error submitting the form.<p>';
  438.                 }
  439.                
  440.                 $out .= '<a name="contact_"></a>';
  441.                 $out .= '<form action="' .get_permalink(). '#contact_" id="contact_form" method="post">';
  442.                 $out .= '[raw]<p><input type="text" name="contactName" id="contactName" value="';
  443.                
  444.                 if(isset($_POST['contactName'])) {
  445.                         $out .= $_POST['contactName'];
  446.                 }
  447.                 $out .= '"';
  448.                 $out .= ' class="requiredFieldContact textfield';
  449.                
  450.                 if($emailError != '') {
  451.                         $out .= ' inputError';
  452.                 }
  453.                 $out .= '"';
  454.                 $out .= ' size="22" tabindex="1" /><label class="textfield_label" for="contactName">Name *</label></p>[/raw]';
  455.                
  456.                 $out .= '<p><input type="text" name="email" id="email" value="';
  457.                
  458.                 if(isset($_POST['email'])) {
  459.                         $out .= $_POST['email'];
  460.                 }
  461.                 $out .= '"';
  462.                 $out .= ' class="requiredFieldContact email textfield';
  463.                
  464.                 if($emailError != '') {
  465.                         $out .= ' inputError';
  466.                 }
  467.                 $out .= '"';
  468.                 $out .= ' size="22" tabindex="2" /><label class="textfield_label" for="email">Email *</label></p>';
  469.                
  470.                 $out .= '<p><textarea name="comments" id="commentsText" rows="20" cols="30" tabindex="3" class="requiredFieldContact textarea';
  471.                
  472.                 if($commentError != '') {
  473.                         $out .= ' inputError';
  474.                 }
  475.                 $out .= '">';
  476.                
  477.                 if(isset($_POST['comments'])) {
  478.                         if(function_exists('stripslashes')) {
  479.                                 $out .= stripslashes($_POST['comments']);
  480.                                 } else {
  481.                                         $out .= $_POST['comments'];
  482.                                 }
  483.                         }
  484.                 $out .= '</textarea></p>';
  485.                
  486.                 $out .= '<p class="screenReader"><label for="checking" class="screenReader">If you want to submit this form, do not enter anything in this field</label><input type="text" name="checking" id="checking" class="screenReader" value="';
  487.                
  488.                  if(isset($_POST['checking'])) {
  489.                         echo $_POST['checking'];
  490.                 }
  491.                 $out .= '" /></p>';
  492.                
  493.                 $out .= '<p class="loadingImg" style="display:none;"><img src="' .WEBTREATS_IMAGES. '/classic-loader.gif" alt="" /></p>';
  494.                 $out .= '<p><button name="submittedContact" id="submittedContact" type="submit" class="fancy_button" tabindex="4" value="Submit" ><span>Submit</span></button></p>';
  495.                
  496.                 $out .= '<p class="screenReader"><input id="submitUrl" type="hidden" name="submitUrl" value="' .get_template_directory_uri(). '/lib/includes/submit.php" /></p>';
  497.                 $out .= '<p class="screenReader"><input id="emailAddress" type="hidden" name="emailAddress" value="' .webtreats_nospam($email_adress_reciever). '" /></p>';
  498.        
  499.                 $out .= '</form>';
  500.  
  501.         }
  502.         return $out;
  503. }
  504.  
  505.  
  506. function webtreats_portfolio_pagenavi($before = '', $after = '', $portfolio_query, $paged) {
  507.         global $wpdb, $wp_query;
  508.         if (!is_single()) {
  509.                 $request = $wp_query->request;
  510.                 $posts_per_page = 2;
  511.                 $paged = intval(get_query_var('paged'));
  512.                 $pagenavi_options = get_option('pagenavi_options');
  513.                 $numposts = $portfolio_query->found_posts;
  514.                 $max_page = $portfolio_query->max_num_pages;
  515.                 if(empty($paged) || $paged == 0) {
  516.                         $paged = 1;
  517.                 }
  518.                 $pages_to_show = intval($pagenavi_options['num_pages']);
  519.                 $larger_page_to_show = intval($pagenavi_options['num_larger_page_numbers']);
  520.                 $larger_page_multiple = intval($pagenavi_options['larger_page_numbers_multiple']);
  521.                 $pages_to_show_minus_1 = $pages_to_show - 1;
  522.                 $half_page_start = floor($pages_to_show_minus_1/2);
  523.                 $half_page_end = ceil($pages_to_show_minus_1/2);
  524.                 $start_page = $paged - $half_page_start;
  525.                 if($start_page <= 0) {
  526.                         $start_page = 1;
  527.                 }
  528.                 $end_page = $paged + $half_page_end;
  529.                 if(($end_page - $start_page) != $pages_to_show_minus_1) {
  530.                         $end_page = $start_page + $pages_to_show_minus_1;
  531.                 }
  532.                 if($end_page > $max_page) {
  533.                         $start_page = $max_page - $pages_to_show_minus_1;
  534.                         $end_page = $max_page;
  535.                 }
  536.                 if($start_page <= 0) {
  537.                         $start_page = 1;
  538.                 }
  539.                 $larger_per_page = $larger_page_to_show*$larger_page_multiple;
  540.                 $larger_start_page_start = (n_round($start_page, 10) + $larger_page_multiple) - $larger_per_page;
  541.                 $larger_start_page_end = n_round($start_page, 10) + $larger_page_multiple;
  542.                 $larger_end_page_start = n_round($end_page, 10) + $larger_page_multiple;
  543.                 $larger_end_page_end = n_round($end_page, 10) + ($larger_per_page);
  544.                 if($larger_start_page_end - $larger_page_multiple == $start_page) {
  545.                         $larger_start_page_start = $larger_start_page_start - $larger_page_multiple;
  546.                         $larger_start_page_end = $larger_start_page_end - $larger_page_multiple;
  547.                 }
  548.                 if($larger_start_page_start <= 0) {
  549.                         $larger_start_page_start = $larger_page_multiple;
  550.                 }
  551.                 if($larger_start_page_end > $max_page) {
  552.                         $larger_start_page_end = $max_page;
  553.                 }
  554.                 if($larger_end_page_end > $max_page) {
  555.                         $larger_end_page_end = $max_page;
  556.                 }
  557.                 if($max_page > 1 || intval($pagenavi_options['always_show']) == 1) {
  558.                         $pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $pagenavi_options['pages_text']);
  559.                         $pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text);
  560.                         $out .= $before.'<div class="wp-pagenavi">'."\n";
  561.                         switch(intval($pagenavi_options['style'])) {
  562.                                 case 1:
  563.                                         if(!empty($pages_text)) {
  564.                                                 $out .= '<span class="pages">'.$pages_text.'</span>';
  565.                                         }
  566.                                         if ($start_page >= 2 && $pages_to_show < $max_page) {
  567.                                                 $first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['first_text']);
  568.                                                 $out .= '<a href="'.clean_url(get_pagenum_link()).'" class="first" title="'.$first_page_text.'">'.$first_page_text.'</a>';
  569.                                                 if(!empty($pagenavi_options['dotleft_text'])) {
  570.                                                         $out .= '<span class="extend">'.$pagenavi_options['dotleft_text'].'</span>';
  571.                                                 }
  572.                                         }
  573.                                         if($larger_page_to_show > 0 && $larger_start_page_start > 0 && $larger_start_page_end <= $max_page) {
  574.                                                 for($i = $larger_start_page_start; $i < $larger_start_page_end; $i+=$larger_page_multiple) {
  575.                                                         $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
  576.                                                         $out .= '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
  577.                                                 }
  578.                                         }
  579.                                         $out .= get_previous_posts_link($pagenavi_options['prev_text']);
  580.                                         for($i = $start_page; $i  <= $end_page; $i++) {                                        
  581.                                                 if($i == $paged) {
  582.                                                         $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['current_text']);
  583.                                                         $out .= '<span class="current">'.$current_page_text.'</span>';
  584.                                                 } else {
  585.                                                         $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
  586.                                                         $out .= '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
  587.                                                 }
  588.                                         }
  589.                                         $out .= get_next_posts_link($pagenavi_options['next_text'], $max_page);
  590.                                         if($larger_page_to_show > 0 && $larger_end_page_start < $max_page) {
  591.                                                 for($i = $larger_end_page_start; $i <= $larger_end_page_end; $i+=$larger_page_multiple) {
  592.                                                         $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
  593.                                                         $out .= '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
  594.                                                 }
  595.                                         }
  596.                                         if ($end_page < $max_page) {
  597.                                                 if(!empty($pagenavi_options['dotright_text'])) {
  598.                                                         $out .= '<span class="extend">'.$pagenavi_options['dotright_text'].'</span>';
  599.                                                 }
  600.                                                 $last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['last_text']);
  601.                                                 $out .= '<a href="'.clean_url(get_pagenum_link($max_page)).'" class="last" title="'.$last_page_text.'">'.$last_page_text.'</a>';
  602.                                         }
  603.                                         break;
  604.                                 case 2;
  605.                                         $out .= '<form action="'.htmlspecialchars($_SERVER['PHP_SELF']).'" method="get">'."\n";
  606.                                         $out .= '<select size="1" onchange="document.location.href = this.options[this.selectedIndex].value;">'."\n";
  607.                                         for($i = 1; $i  <= $max_page; $i++) {
  608.                                                 $page_num = $i;
  609.                                                 if($page_num == 1) {
  610.                                                         $page_num = 0;
  611.                                                 }
  612.                                                 if($i == $paged) {
  613.                                                         $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['current_text']);
  614.                                                         $out .= '<option value="'.clean_url(get_pagenum_link($page_num)).'" selected="selected" class="current">'.$current_page_text."</option>\n";
  615.                                                 } else {
  616.                                                         $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
  617.                                                         $out .= '<option value="'.clean_url(get_pagenum_link($page_num)).'">'.$page_text."</option>\n";
  618.                                                 }
  619.                                         }
  620.                                         $out .= "</select>\n";
  621.                                         $out .= "</form>\n";
  622.                                         break;
  623.                         }
  624.                         $out .= '</div>'.$after."\n";
  625.                 }
  626.         }
  627.         return $out;
  628. }
  629.  
  630.  
  631. function webtreats_exclude_category_feed() {
  632.         global $exclude_blog_cats;
  633.        
  634.         $exclude_blog_cats = preg_replace("!(\d)+!","-${0}$0", $blog_excludecats);
  635.         if ( is_feed() ) {
  636.                 set_query_var("cat", "$exclude_blog_cats");
  637.         }
  638. }
  639. add_filter('pre_get_posts', 'webtreats_exclude_category_feed');
  640.  
  641.  
  642. function webtreats_body_class() {
  643.         global $post, $homepage_slider, $home_slider_page, $blog_page, $teaser_style;
  644.        
  645.         $is_homepage_slider = ($home_slider_page) ? $homepage_slider .' ': '';
  646.        
  647.         $get_template = get_post_meta($post->ID, '_wp_page_template', true);
  648.        
  649.         if(is_home()){
  650.                 $homepage_sidebar = (is_active_sidebar(2)) ? 'right_sidebar ' : 'full_width ';
  651.                 $body_class = 'class="' .$homepage_sidebar.$homepage_slider. ' ' .$teaser_style. '"';
  652.                 echo $body_class;
  653.                
  654.                 return;
  655.         }
  656.        
  657.         if(is_page() && $post->ID != $blog_page){
  658.                 $sidebar = 'right_sidebar ';
  659.                
  660.                 $is_home_slider = ($home_slider_page) ? $is_homepage_slider .' ' : '';
  661.                
  662.                 $sidebar = ($get_template == 'template-full.php') ? 'full_width ' : $sidebar;
  663.                 $sidebar = ($get_template == 'template-left-sidebar.php') ? 'left_sidebar ' : $sidebar;
  664.                 $sidebar = (is_webtreats_portfolio_gallery($post->ID)) ? 'full_width ' : $sidebar;
  665.                                
  666.                 $body_class = 'class="' .$sidebar.$is_home_slider.$teaser_style. '"';
  667.                 echo $body_class;
  668.                
  669.                 return;
  670.         }
  671.        
  672.         if(is_page() && $post->ID == $blog_page){
  673.                 $sidebar = 'right_sidebar ';
  674.  
  675.                 $sidebar = ($get_template == 'template-full.php') ? 'full_width ' : $sidebar;
  676.                 $sidebar = ($get_template == 'template-left-sidebar.php') ? 'left_sidebar ' : $sidebar;
  677.                
  678.                 $body_class = 'class="' .$sidebar.$is_homepage_slider.$teaser_style. '"';
  679.                 echo $body_class;
  680.                
  681.                 return;
  682.         }
  683.        
  684.         if(is_single()){
  685.                 $sidebar = 'right_sidebar ';
  686.                
  687.                 $portfolio_post = get_post_meta($post->ID, 'portfolio_full_img', true);
  688.                 $portfolio_layout = get_post_meta($post->ID, 'portfolio_post_layout', true);
  689.                 $get_template = get_post_meta($blog_page, '_wp_page_template', true);
  690.  
  691.                 $sidebar = ($get_template == 'template-full.php') ? 'full_width ' : $sidebar;
  692.                 $sidebar = ($get_template == 'template-left-sidebar.php') ? 'left_sidebar ' : $sidebar;
  693.                 $sidebar = ($portfolio_post && !$portfolio_layout) ? 'full_width ' : $sidebar;
  694.                
  695.                 $body_class = 'class="' .$sidebar.$is_homepage_slider.$teaser_style. '"';
  696.                 echo $body_class;
  697.                
  698.                 return;
  699.         }
  700.        
  701.         if(is_archive() || is_search() || is_404()){
  702.                 $is_home_slider = ($home_slider_page) ? $is_homepage_slider .' ' : '';
  703.                
  704.                 $body_class = 'class="right_sidebar ' .$is_home_slider.$teaser_style. '"';
  705.                 echo $body_class;
  706.                
  707.                 return;
  708.         }
  709. }
  710.  
  711.  
  712. function is_webtreats_portfolio_gallery($id){
  713.         $pg = get_page($id);
  714.        
  715.         if ( stristr( $pg->post_content, '[portfolio' )) {
  716.                 $search = "@(?:<p>)*\s*\[portfolio\s*\s*cat\s*=\s*(\w+|^\+)\s*\s*column\s*=\s*(\w+|^\+)\s*\s*link\s*=\s*(\w+|^\+)\s*\s*max\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
  717.                 if      (preg_match_all($search, $pg->post_content, $matches)) {
  718.                         if (is_array($matches)) {
  719.                                 return true;
  720.                         }
  721.                 }
  722.         }
  723.        
  724.         return false;
  725. }
  726.  
  727.  
  728. function webtreats_google_analytics(){
  729.         global $analytics_code;
  730.        
  731.         if($analytics_code){
  732.                
  733.                 echo "<script type=\"text/javascript\">
  734.                 /* <![CDATA[ */
  735.                   var _gaq = _gaq || [];
  736.                   _gaq.push(['_setAccount', '" .$analytics_code. "']);
  737.                   _gaq.push(['_trackPageview']);
  738.  
  739.                   (function() {
  740.                     var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  741.                     ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  742.                     var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  743.                   })();
  744.                 /* ]]> */
  745.                 </script>";
  746.         }
  747. }
  748.  
  749.  
  750. /*
  751.  * PHP integration for No Spam v1.3
  752.  * by Mike Branski (www.leftrightdesigns.com)
  753.  * mikebranski@gmail.com
  754.  *
  755.  * Copyright (c) 2008 Mike Branski (www.leftrightdesigns.com)
  756.  *
  757.  * NOTE: This script is for integrating your dynamic PHP content with No Script.
  758.  *       Download No Spam at www.leftrightdesigns.com/library/jquery/nospam/
  759.  *
  760.  */
  761. function webtreats_nospam($email, $filterLevel = 'normal')
  762. {
  763.         $email = strrev($email);
  764.         $email = preg_replace('[@]', '//', $email);
  765.         $email = preg_replace('[\.]', '/', $email);
  766.  
  767.         if($filterLevel == 'low')
  768.         {
  769.                 $email = strrev($email);
  770.         }
  771.  
  772.         return $email;
  773. }
  774.  
  775.  
  776. ?>