SHARE
TWEET

function.php

a guest May 22nd, 2015 13 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*******************************
  4.  MENUS SUPPORT
  5. ********************************/
  6. if ( function_exists( 'wp_nav_menu' ) ){
  7.         if (function_exists('add_theme_support')) {
  8.                 add_theme_support('nav-menus');
  9.                 add_action( 'init', 'register_my_menus' );
  10.                 function register_my_menus() {
  11.                         register_nav_menus(
  12.                                 array(
  13.                                         'primary-menu' => __( 'Primary Menu' ),
  14.                                         'secondary-menu' => __( 'Secondary Menu' )
  15.                                 )
  16.                         );
  17.                 }
  18.         }
  19. }
  20.  
  21.  
  22.  
  23. /*******************************
  24. IF MODIFIED SINCE HTTP HEADER wp_config
  25. ********************************/
  26. add_action('template_redirect', 'cyb_add_last_modified_header');
  27. function cyb_add_last_modified_header($headers) {
  28.  
  29.     //Check if we are in a single post of any type (archive pages has not modified date)
  30.     if( is_singular() ) {
  31.         $post_id = get_queried_object_id();
  32.         if( $post_id ) {
  33.             header("Last-Modified: " . get_the_modified_time("D, d M Y H:i:s", $post_id) );
  34.         }
  35.     }
  36.  
  37. }
  38.  
  39.  
  40.  
  41. /*******************************
  42. DO NOT DISPLAY ADMIN BAR AT ALL
  43. ********************************/
  44.  
  45. add_filter( 'show_admin_bar', '__return_false'  );
  46. add_action( 'admin_print_scripts-profile.php', 'wpbeginner_hide_admin_bar' );
  47. function wpbeginner_hide_admin_bar() { ?>
  48. <style type="text/css">
  49.     .show-admin-bar { display: none; }
  50. </style>
  51. <?php
  52. }
  53.  
  54.  
  55. /*******************************
  56. Remove query strings from static resources
  57. ********************************/
  58. function _remove_script_version( $src ){
  59. $parts = explode( '?ver', $src );
  60. return $parts[0];
  61. }
  62. add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
  63. add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
  64.  
  65.  
  66.  
  67. /*******************************
  68. Remove Jetpack CSS and Javascript
  69. ********************************/
  70. function wsis_remove_jetpack_assets() {
  71.  
  72. // devicepx-jetpack.js, used to optionally load retina/HiDPI versions of files (Gravatars etc) which are known to support it, for devices that run at a higher resolution.
  73.         wp_dequeue_script( 'devicepx' );
  74. }
  75.  
  76. add_action( 'wp_enqueue_scripts', 'wsis_remove_jetpack_assets', 20 );
  77.  
  78. // Remove CSS file, from version 3.2 of Jetpack
  79. add_filter( 'jetpack_implode_frontend_css', '__return_false' );
  80.  
  81.  
  82. /*******************************
  83. DISPLAY MY OWN GRAVATAR FOR USERS
  84. ********************************/
  85.  
  86. add_filter( 'avatar_defaults', 'newgravatar' );
  87.  
  88. function newgravatar ($avatar_defaults) {
  89. $myavatar = get_bloginfo('template_directory') . '/images/usericon.png';
  90. $avatar_defaults[$myavatar] = "ZoomingJapan";
  91. return $avatar_defaults;
  92. }
  93.  
  94. /*******************************
  95. FACEBOOK FANS COUNT    
  96. ********************************/
  97.  
  98. function diww_fb_fan_count($fb_id){
  99.          $count = get_transient('fan_count');
  100.     if ($count !== false) return $count;
  101.          $count = 0;
  102.          $data = wp_remote_get('http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id='.$fb_id.'');
  103.    if (is_wp_error($data)) {
  104.          return 'Error getting number';
  105.    }else{
  106.          $count = strip_tags($data[body]);
  107.    }
  108. set_transient('fan_count', $count, 60*60*24); // 24 hour cache
  109. echo $count;
  110. }
  111.  
  112.  
  113. /*******************************
  114. SHOW HIDDEN BUTTONS IN TINYMCE
  115. ********************************/
  116. function ilc_mce_buttons($buttons){
  117.   array_push($buttons, "backcolor", "hr", "fontselect", "fontsizeselect", "code", "redo", "undo");
  118.   return $buttons;
  119. }
  120. add_filter("mce_buttons", "ilc_mce_buttons");
  121.  
  122.  
  123. /*******************************
  124. ADD MORE ALLOWED HTML TAGS TO COMMENTS
  125. ********************************/
  126. add_filter('comments_open','eg_allow_tags_in_comments');
  127. // For making it sure, we also force the tags again before comment approval
  128. add_filter('pre_comment_approved','eg_allow_tags_in_comments');
  129. function eg_allow_tags_in_comments($data) {  
  130. // This variable is in wp-includes/kses.php file, check it out  
  131. global $allowedtags;  
  132. // You can add HTML tags and their properties by this way  
  133. $allowedtags['span'] = array('style'=>array());  
  134.   $allowedtags['big'] = array();
  135.   $allowedtags['small'] = array();
  136. // And we return our expanded data for comment approval  
  137. return $data; }
  138.  
  139.  
  140.  
  141. /*******************************
  142. REMOVE WORDPRESS VERSION NUMBER
  143. ********************************/
  144.  
  145. function wpbeginner_remove_version() {
  146. return '';
  147. }
  148. add_filter('the_generator', 'wpbeginner_remove_version');
  149.  
  150.  
  151. /*******************************
  152. LIMIT SEARCH: NO PAGES
  153. ********************************/
  154. function searchfilter($query) {
  155.  
  156.     if ($query->is_search) {
  157.         $query->set('post_type',array('post'));
  158.     }
  159.  
  160. return $query;
  161. }
  162.  
  163. add_filter('pre_get_posts','searchfilter');
  164.  
  165.  
  166. /*******************************
  167. OWN TITLE LENGHT
  168. ********************************/
  169.  
  170. function japanworm_get_the_title( $length = null, $id = 0 ) {
  171.     $post = &get_post($id);
  172.  
  173.     $title = isset($post->post_title) ? $post->post_title : '';
  174.     $id = isset($post->ID) ? $post->ID : (int) $id;
  175.  
  176.     if ( !is_admin() ) {
  177.         if ( !empty($post->post_password) ) {
  178.             $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
  179.             $title = sprintf($protected_title_format, $title);
  180.         } else if ( isset($post->post_status) && 'private' == $post->post_status ) {
  181.             $private_title_format = apply_filters('private_title_format', __('Private: %s'));
  182.             $title = sprintf($private_title_format, $title);
  183.         }
  184.     }
  185.  
  186.     // Shorten the title
  187.     if ( null != $length ) {
  188.         $length = (int) $length;
  189.  
  190.         $title = substr( $title, 0, $length ); // Only take the first 20 characters
  191.  
  192.         $title .= " &hellip;";
  193.     }
  194.  
  195.     return apply_filters( 'the_title', $title, $id );
  196. }
  197.  
  198. function japanworm_the_title($before = '', $after = '', $echo = true, $length = null) {
  199.     $title = get_the_title($length);
  200.  
  201.     if ( strlen($title) == 0 )
  202.         return;
  203.  
  204.     $title = $before . $title . $after;
  205.  
  206.     if ( $echo )
  207.         echo $title;
  208.     else
  209.         return $title;
  210. }
  211.  
  212.  
  213. /*******************************
  214. JQUERY ENQUEUE
  215. ********************************/
  216.  
  217. function add_async_forscript($url)
  218. {
  219.     if (strpos($url, '#asyncload')===false)
  220.         return $url;
  221.     else if (is_admin())
  222.         return str_replace('#asyncload', '', $url);
  223.     else
  224.         return str_replace('#asyncload', '', $url)."' async='async";
  225. }
  226. add_filter('clean_url', 'add_async_forscript', 11, 1);
  227.  
  228.  
  229.  
  230. function add_my_javascripts() {
  231.     /* If this is the admin area of WordPress, don't do anything */
  232.     if( is_admin() )
  233.         return;
  234.  
  235.     /* Register all of our scripts */
  236.  
  237.     wp_register_script('jquerytools', 'http://zoomingjapan.com/wp-content/themes/alltuts/js/jquery.tools.min.js', array('jquery'),'1',true);
  238.     wp_register_script('jquery-ui-perso', get_template_directory_uri() . '/js/jquery-ui-personalized-1.5.2.packed.js', array('jquery'),'1',true);
  239.     wp_register_script('jquery.form', get_template_directory_uri() . '/js/jquery.form.js', array('jquery'),'1',true);
  240.     wp_register_script('jquery-slides', get_template_directory_uri() . '/js/slides.min.jquery.js', array('jquery'),'1',true);
  241.     wp_register_script('my-slider', get_template_directory_uri() . '/js/my-slider.js', array('jquery', 'jquery-slides'),'1',true);
  242.     wp_register_script('contact-form', get_template_directory_uri() . '/js/contact-form.js', array('jquery', 'jquery.form'),'1',true);
  243.     wp_register_script('custom', get_template_directory_uri() . '/js/custom.js', array('jquery', 'jquery-ui-perso'),'1',true);
  244.     wp_register_style ('theme-css', 'http://zoomingjapan.com/wp-content/themes/alltuts-child/style.css', false,'1.1','all');
  245.  
  246.  
  247.     /* Enqueue the ones that need to be enqueued */
  248.       wp_enqueue_style( 'theme-css');
  249.     wp_enqueue_script('custom');
  250.  
  251.  
  252.  if ( is_front_page() ) {
  253.   wp_enqueue_script('my-slider');
  254.   }
  255.  
  256.  if ( is_page( 'contact' ) ) {
  257.   wp_enqueue_script('contact-form');
  258.   }
  259.    
  260. }
  261. add_action('wp_enqueue_scripts', 'add_my_javascripts');
  262.  
  263.  
  264. /*******************************
  265. DEQUEUE STYLES AND SCRIPTS FROM PLUGINS
  266. ********************************/
  267.  
  268.  
  269. add_action( 'wp_print_styles', 'my_deregister_styles', 100 );
  270.  
  271. function my_deregister_styles() {
  272.         wp_deregister_style( 'wp-polls' );
  273. }
  274.  
  275. add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
  276.  
  277. function my_deregister_javascript() {
  278.    if ( !is_single( array( 628, 1007 ) )) {
  279.         wp_deregister_script( 'wp-polls' );
  280.      }
  281. }
  282.  
  283.  
  284. /*******************************
  285.   BREADCRUMBS
  286. ********************************/
  287.  
  288. function dimox_breadcrumbs() {
  289.  
  290.   $delimiter = '<span class="delimiter">&raquo;</span>';
  291.   $home = 'Home'; // text for the 'Home' link
  292.   $before = '<span class="current">'; // tag before the current crumb
  293.   $after = '</span>'; // tag after the current crumb
  294.  
  295.   if ( !is_front_page() || is_paged() ) {
  296.  
  297.     echo '<div id="crumbs">';
  298.  
  299. global $post;
  300. $divider = $delimiter;
  301. if (is_home()) $divider = '';
  302. $homeLink = get_bloginfo('url');
  303. echo '<a href="' . $homeLink . '" rel="nofollow">' . $home . '</a> ' . $delimiter . ' <a href="http://zoomingjapan.com/blog/" rel="nofollow">Blog</a> ' . $divider . ' ';
  304.  
  305.     if ( is_category() ) {
  306.       global $wp_query;
  307.       $cat_obj = $wp_query->get_queried_object();
  308.       $thisCat = $cat_obj->term_id;
  309.       $thisCat = get_category($thisCat);
  310.       $parentCat = get_category($thisCat->parent);
  311.       if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
  312.       echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;
  313.  
  314.     } elseif ( is_day() ) {
  315.       echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  316.       echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
  317.       echo $before . get_the_time('d') . $after;
  318.  
  319.     } elseif ( is_month() ) {
  320.       echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  321.       echo $before . get_the_time('F') . $after;
  322.  
  323.     } elseif ( is_year() ) {
  324.       echo $before . get_the_time('Y') . $after;
  325.  
  326.     } elseif ( is_single() && !is_attachment() ) {
  327.       if ( get_post_type() != 'post' ) {
  328.         $post_type = get_post_type_object(get_post_type());
  329.         $slug = $post_type->rewrite;
  330.         echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
  331.         echo $before . get_the_title() . $after;
  332.       } else {
  333.         $cat = get_the_category(); $cat = $cat[0];
  334.         echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  335.         echo $before . get_the_title() . $after;
  336.       }
  337.  
  338.     } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
  339.       $post_type = get_post_type_object(get_post_type());
  340.       echo $before . $post_type->labels->singular_name . $after;
  341.  
  342.     } elseif ( is_attachment() ) {
  343.       $parent = get_post($post->post_parent);
  344.       $cat = get_the_category($parent->ID); $cat = $cat[0];
  345.       echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  346.       echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
  347.       echo $before . get_the_title() . $after;
  348.  
  349.     } elseif ( is_page() && !$post->post_parent ) {
  350.       echo $before . get_the_title() . $after;
  351.  
  352.     } elseif ( is_page() && $post->post_parent ) {
  353.       $parent_id  = $post->post_parent;
  354.       $breadcrumbs = array();
  355.       while ($parent_id) {
  356.         $page = get_page($parent_id);
  357.         $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  358.         $parent_id  = $page->post_parent;
  359.       }
  360.       $breadcrumbs = array_reverse($breadcrumbs);
  361.       foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
  362.       echo $before . get_the_title() . $after;
  363.  
  364.     } elseif ( is_search() ) {
  365.       $searchTerm = get_search_query();
  366. echo $before . 'Search results for "' . $searchTerm . '"' . $after;
  367.  
  368.  
  369.     } elseif ( is_tag() ) {
  370.       echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
  371.  
  372.     } elseif ( is_author() ) {
  373.        global $author;
  374.       $userdata = get_userdata($author);
  375.       echo $before . 'Articles posted by ' . $userdata->display_name . $after;
  376.  
  377.     } elseif ( is_404() ) {
  378.       echo $before . 'Error 404' . $after;
  379.     }
  380.  
  381.     if ( get_query_var('paged') ) {
  382. if (is_home()) echo ' ' . $delimiter . ' ';
  383.       if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
  384.       echo __('Page') . ' ' . get_query_var('paged');
  385.       if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
  386.     }
  387.  
  388.     echo '</div>';
  389.  
  390.   }
  391. } // end dimox_breadcrumbs()
  392.  
  393.  
  394. /*******************************
  395.  THUMBNAIL SUPPORT
  396. ********************************/
  397.  
  398. add_theme_support( 'post-thumbnails' );
  399. set_post_thumbnail_size( 263, 130, true );
  400.  
  401. add_image_size( 'homepage-thumb', 198, 132, true );
  402. add_image_size( 'slider-thumb', 360, 200, true );
  403. add_image_size( 'latestpost-thumb', 584, 197, true );
  404.  
  405.  
  406. /*******************************
  407. DISPLAY USER COMMENT COUNT
  408. ********************************/
  409.  
  410. function commentCount() {
  411.     global $wpdb;
  412.     $count = $wpdb->get_var('SELECT COUNT(comment_ID) FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . get_comment_author_email() . '"');
  413.     echo $count . ' <img src="http://zoomingjapan.com/wp-content/themes/alltuts/images/comment-cat.png" title="comments by this user" alt="comments by this user" width="12" height="11" />';}
  414.  
  415.  
  416. /*******************************
  417.  EXCERPT LENGTH ADJUST
  418. ********************************/
  419. function excerpt($limit) {
  420.       $excerpt = explode(' ', get_the_excerpt(), $limit);
  421.       if (count($excerpt)>=$limit) {
  422.         array_pop($excerpt);
  423.         $excerpt = implode(" ",$excerpt).'&nbsp;(...)';
  424.       } else {
  425.         $excerpt = implode(" ",$excerpt);
  426.       }
  427.       $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
  428.       return $excerpt;
  429.     }
  430.  
  431.     function content($limit) {
  432.       $content = explode(' ', get_the_content(), $limit);
  433.       if (count($content)>=$limit) {
  434.         array_pop($content);
  435.         $content = implode(" ",$content).'&nbsp;(...)';
  436.       } else {
  437.         $content = implode(" ",$content);
  438.       }
  439.       $content = preg_replace('/\[.+\]/','', $content);
  440.       $content = apply_filters('the_content', $content);
  441.       $content = str_replace(']]>', ']]&gt;', $content);
  442.       return $content;
  443.     }
  444.  
  445.  
  446. /*******************************
  447. TOP NAVIGATION MENU WALKER
  448. ********************************/
  449. class description_walker extends Walker_Nav_Menu
  450. {
  451.       function start_el(&$output, $item, $depth, $args)
  452.       {
  453.            global $wp_query;
  454.            $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  455.  
  456.            $class_names = $value = '';
  457.  
  458.            $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  459.  
  460.            $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  461.            $class_names = ' class="'. esc_attr( $class_names ) . '"';
  462.  
  463.            $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
  464.  
  465.            $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
  466.            $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
  467.            $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
  468.            $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
  469.  
  470.            $prepend = '<strong>';
  471.            $append = '</strong>';
  472.            $description  = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';
  473.  
  474.            if($depth != 0)
  475.            {
  476.                      $description = $append = $prepend = "";
  477.            }
  478.  
  479.             $item_output = $args->before;
  480.             $item_output .= '<a'. $attributes .'>';
  481.             $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
  482.             $item_output .= $description.$args->link_after;
  483.             $item_output .= '</a>';
  484.             $item_output .= $args->after;
  485.  
  486.             $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  487.             }
  488. }
  489.  
  490. /*******************************
  491.  WIDGETS AREAS
  492. ********************************/
  493.  
  494. if ( function_exists('register_sidebar') )
  495. register_sidebar(array(
  496.         'name' => 'sidebar',
  497.         'id' => 'sidebar-1',
  498.         'before_widget' => '<div class="rightBox">
  499.                         <div class="rightBoxTop"></div>
  500.                         <div class="rightBoxMid">',
  501.         'after_widget' => '</div>      
  502.                         <div class="rightBoxBottom"></div>
  503.                 </div>',
  504.         'before_title' => '<h2>',
  505.         'after_title' => '</h2>',
  506. ));
  507.  
  508. register_sidebar(array(
  509.         'name' => 'footer',
  510.         'id' => 'sidebar-2',
  511.         'before_widget' => '<div class="boxFooter">',
  512.         'after_widget' => '</div>',
  513.         'before_title' => '<h2>',
  514.         'after_title' => '</h2>',
  515. ));
  516.        
  517. /*******************************
  518.  PAGINATION
  519. ********************************
  520.  * Retrieve or display pagination code.
  521.  *
  522.  * The defaults for overwriting are:
  523.  * 'page' - Default is null (int). The current page. This function will
  524.  *      automatically determine the value.
  525.  * 'pages' - Default is null (int). The total number of pages. This function will
  526.  *      automatically determine the value.
  527.  * 'range' - Default is 3 (int). The number of page links to show before and after
  528.  *      the current page.
  529.  * 'gap' - Default is 3 (int). The minimum number of pages before a gap is
  530.  *      replaced with ellipses (...).
  531.  * 'anchor' - Default is 1 (int). The number of links to always show at begining
  532.  *      and end of pagination
  533.  * 'before' - Default is '<div class="emm-paginate">' (string). The html or text
  534.  *      to add before the pagination links.
  535.  * 'after' - Default is '</div>' (string). The html or text to add after the
  536.  *      pagination links.
  537.  * 'title' - Default is '__('Pages:')' (string). The text to display before the
  538.  *      pagination links.
  539.  * 'next_page' - Default is '__('&raquo;')' (string). The text to use for the
  540.  *      next page link.
  541.  * 'previous_page' - Default is '__('&laquo')' (string). The text to use for the
  542.  *      previous page link.
  543.  * 'echo' - Default is 1 (int). To return the code instead of echo'ing, set this
  544.  *      to 0 (zero).
  545.  *
  546.  * @author Eric Martin <eric@ericmmartin.com>
  547.  * @copyright Copyright (c) 2009, Eric Martin
  548.  * @version 1.0
  549.  *
  550.  * @param array|string $args Optional. Override default arguments.
  551.  * @return string HTML content, if not displaying.
  552.  */
  553.  
  554. function emm_paginate($args = null) {
  555.         $defaults = array(
  556.                 'page' => null, 'pages' => null,
  557.                 'range' => 3, 'gap' => 3, 'anchor' => 1,
  558.                 'before' => '<div class="emm-paginate">', 'after' => '</div>',
  559.                 'title' => __('Pages:'),
  560.                 'nextpage' => __('&raquo;'), 'previouspage' => __('&laquo'),
  561.                 'echo' => 1
  562.         );
  563.  
  564.         $r = wp_parse_args($args, $defaults);
  565.         extract($r, EXTR_SKIP);
  566.  
  567.         if (!$page && !$pages) {
  568.                 global $wp_query;
  569.  
  570.                 $page = get_query_var('paged');
  571.                 $page = !empty($page) ? intval($page) : 1;
  572.  
  573.                 $posts_per_page = intval(get_query_var('posts_per_page'));
  574.                 $pages = intval(ceil($wp_query->found_posts / $posts_per_page));
  575.         }
  576.        
  577.         $output = "";
  578.         if ($pages > 1) {      
  579.                 $output .= "$before<span class='emm-title'>$title</span>";
  580.                 $ellipsis = "<span class='emm-gap'>...</span>";
  581.  
  582.                 if ($page > 1 && !empty($previouspage)) {
  583.                         $output .= "<a href='" . get_pagenum_link($page - 1) . "' class='emm-prev'>$previouspage</a>";
  584.                 }
  585.                
  586.                 $min_links = $range * 2 + 1;
  587.                 $block_min = min($page - $range, $pages - $min_links);
  588.                 $block_high = max($page + $range, $min_links);
  589.                 $left_gap = (($block_min - $anchor - $gap) > 0) ? true : false;
  590.                 $right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false;
  591.  
  592.                 if ($left_gap && !$right_gap) {
  593.                         $output .= sprintf('%s%s%s',
  594.                                 emm_paginate_loop(1, $anchor),
  595.                                 $ellipsis,
  596.                                 emm_paginate_loop($block_min, $pages, $page)
  597.                         );
  598.                 }
  599.                 else if ($left_gap && $right_gap) {
  600.                         $output .= sprintf('%s%s%s%s%s',
  601.                                 emm_paginate_loop(1, $anchor),
  602.                                 $ellipsis,
  603.                                 emm_paginate_loop($block_min, $block_high, $page),
  604.                                 $ellipsis,
  605.                                 emm_paginate_loop(($pages - $anchor + 1), $pages)
  606.                         );
  607.                 }
  608.                 else if ($right_gap && !$left_gap) {
  609.                         $output .= sprintf('%s%s%s',
  610.                                 emm_paginate_loop(1, $block_high, $page),
  611.                                 $ellipsis,
  612.                                 emm_paginate_loop(($pages - $anchor + 1), $pages)
  613.                         );
  614.                 }
  615.                 else {
  616.                         $output .= emm_paginate_loop(1, $pages, $page);
  617.                 }
  618.  
  619.                 if ($page < $pages && !empty($nextpage)) {
  620.                         $output .= "<a href='" . get_pagenum_link($page + 1) . "' class='emm-next'>$nextpage</a>";
  621.                 }
  622.  
  623.                 $output .= $after;
  624.         }
  625.  
  626.         if ($echo) {
  627.                 echo $output;
  628.         }
  629.  
  630.         return $output;
  631. }
  632.  
  633. /**
  634.  * Helper function for pagination which builds the page links.
  635.  *
  636.  * @access private
  637.  *
  638.  * @author Eric Martin <eric@ericmmartin.com>
  639.  * @copyright Copyright (c) 2009, Eric Martin
  640.  * @version 1.0
  641.  *
  642.  * @param int $start The first link page.
  643.  * @param int $max The last link page.
  644.  * @return int $page Optional, default is 0. The current page.
  645.  */
  646. function emm_paginate_loop($start, $max, $page = 0) {
  647.         $output = "";
  648.         for ($i = $start; $i <= $max; $i++) {
  649.                 $output .= ($page === intval($i))
  650.                         ? "<span class='emm-page emm-current'>$i</span>"
  651.                         : "<a href='" . get_pagenum_link($i) . "' class='emm-page'>$i</a>";
  652.         }
  653.         return $output;
  654. }
  655.  
  656. /*******************************
  657.  CUSTOM COMMENTS
  658. ********************************/
  659.  
  660. function mytheme_comment($comment, $args, $depth) {
  661.    $GLOBALS['comment'] = $comment; ?>
  662.    <li <?php comment_class('clearfix'); ?> id="li-comment-<?php comment_ID() ?>">
  663.          <?php echo get_avatar($comment,$size='63'); ?>
  664.      <div id="comment-<?php comment_ID(); ?>">
  665.           <div class="comment-meta commentmetadata clearfix">
  666.             <?php printf(__('<strong>%s</strong>'), get_comment_author_link()) ?> <span class="comment_count"><?php
  667.             commentCount();?></span> <?php edit_comment_link(__('<img src="http://www.zoomingjapan.com/wp-content/themes/alltuts/images/edit.gif" al="edit gif in comments" width="13" height="13" />'),'  ','') ?> <span><?php printf(__('%1$s @ %2$s'), get_comment_date('Y/n/j'),  get_comment_time('G:i')) ?>
  668.           </span>
  669.   <div class="text">
  670.                   <?php comment_text() ?>
  671.           </div>
  672.           </div>
  673.          
  674.    
  675.          
  676.           <?php if ($comment->comment_approved == '0') : ?>
  677.          <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
  678.          <br />
  679.       <?php endif; ?>
  680.  
  681.       <div class="reply">
  682.          <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>  </div>
  683. <div class="link-to-comment"><a href="<?php echo get_permalink($comment->comment_post_ID); ?>#comment-<?php echo $comment->comment_ID; ?>" rel="external nofollow" title="<?php echo $title; ?>">Link</a></div>
  684.      </div>
  685. <?php }
  686.  
  687.  
  688. function list_pings($comment, $args, $depth) {
  689. $GLOBALS['comment'] = $comment;
  690. ?>
  691. <li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
  692. <?php }
  693.  
  694.  
  695.  
  696. function oenology_comment_count( $count ) {  
  697. // Only filter the comments number
  698. // in the front-end display
  699. if (
  700. // WordPress conditional that returns true if
  701. // the current page is in the WP-Admin back-end
  702. ! is_admin()
  703. ) {
  704.     global $id;
  705.     $comments_by_type = &separate_comments( get_comments( 'status=approve&post_id=' . $id ) );
  706.     return count( $comments_by_type['comment'] );
  707. }
  708. // Otherwise, when in the WP-Admin
  709. // back end, don't filter comments
  710. // number
  711. else {
  712.     return $count;
  713. }
  714. }
  715.  
  716.  
  717. // Hook custom comment number into 'get_comments_number'
  718. add_filter('get_comments_number', 'oenology_comment_count', 0);
  719.  
  720. add_filter('get_comments_number', 'comment_count', 0);
  721. function comment_count( $count ) {
  722. if ( ! is_admin() ) {
  723. global $id;
  724. $comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
  725. return count($comments_by_type['comment']);
  726. } else {
  727. return $count;
  728. }
  729. }
  730.  
  731.  
  732.  
  733. /*******************************
  734.   THEME OPTIONS PAGE
  735. ********************************/
  736.  
  737. add_action('admin_menu', 'alltuts_theme_page');
  738. function alltuts_theme_page ()
  739. {
  740.         if ( count($_POST) > 0 && isset($_POST['alltuts_settings']) )
  741.         {
  742.                 $options = array ('logo_img', 'logo_alt','ads','advertise','contact_email','contact_text','cufon','linkedin_link','twitter_user','latest_tweet','number_tweets','facebook_link','keywords','description','analytics','popular_posts', 'copyright');
  743.                
  744.                 foreach ( $options as $opt )
  745.                 {
  746.                         delete_option ( 'alltuts_'.$opt, $_POST[$opt] );
  747.                         add_option ( 'alltuts_'.$opt, $_POST[$opt] );  
  748.                 }                      
  749.                  
  750.         }
  751.         add_menu_page(__('Alltuts Options'), __('Alltuts Options'), 'edit_themes', basename(__FILE__), 'alltuts_settings');
  752.         add_submenu_page(__('Alltuts Options'), __('Alltuts Options'), 'edit_themes', basename(__FILE__), 'alltuts_settings');
  753. }
  754. function alltuts_settings()
  755. {?>
  756. <div class="wrap">
  757.         <h2>AllTuts Options Panel</h2>
  758.        
  759. <form method="post" action="">
  760.        
  761.      <fieldset style="border:1px solid #ddd; padding-bottom:20px; margin-top:20px;">
  762.         <legend style="margin-left:5px; padding:0 5px; color:#2481C6;text-transform:uppercase;"><strong>Contact Page Settings</strong></legend>
  763.                 <table class="form-table">     
  764.         <tr>
  765.                 <td colspan="2"></td>
  766.         </tr>
  767.          <tr valign="top">
  768.                         <th scope="row"><label for="contact_text">Contact Page Text</label></th>
  769.                         <td>
  770.                                 <textarea name="contact_text" id="contact_text" rows="7" cols="70" style="font-size:11px;"><?php echo stripslashes(get_option('alltuts_contact_text')); ?></textarea>
  771.                         </td>
  772.                 </tr>
  773.         <tr valign="top">
  774.                         <th scope="row"><label for="contact_email">Email Address for Contact Form</label></th>
  775.                         <td>
  776.                                 <input name="contact_email" type="text" id="contact_email" value="<?php echo get_option('alltuts_contact_email'); ?>" class="regular-text" />
  777.                         </td>
  778.                 </tr>
  779.         </table>
  780.      </fieldset>
  781.          <p class="submit">
  782.                 <input type="submit" name="Submit" class="button-primary" value="Save Changes" />
  783.                 <input type="hidden" name="alltuts_settings" value="save" style="display:none;" />
  784.         </p>
  785.  
  786. </form>
  787. </div>
  788. <?php }
  789. /*******************************
  790.   CONTACT FORM
  791. ********************************/
  792.  function hexstr($hexstr) {
  793.   $hexstr = str_replace(' ', '', $hexstr);
  794.   $hexstr = str_replace('\x', '', $hexstr);
  795.   $retstr = pack('H*', $hexstr);
  796.   return $retstr;
  797. }
  798.  
  799. function strhex($string) {
  800.   $hexstr = unpack('H*', $string);
  801.   return array_shift($hexstr);
  802. }
  803.  
  804. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top