Advertisement
Guest User

Untitled

a guest
Dec 17th, 2012
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.22 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Starkers functions and definitions
  4.  *
  5.  * @package WordPress
  6.  * @subpackage Starkers
  7.  * @since Starkers HTML5 3.0
  8.  */
  9.  
  10. /** Tell WordPress to run starkers_setup() when the 'after_setup_theme' hook is run. */
  11. add_action( 'after_setup_theme', 'starkers_setup' );
  12.  
  13. if ( ! function_exists( 'starkers_setup' ) ):
  14. /**
  15.  * Sets up theme defaults and registers support for various WordPress features.
  16.  *
  17.  * @since Starkers HTML5 3.0
  18.  */
  19. function starkers_setup() {
  20.  
  21.     // This theme uses post thumbnails
  22.     add_theme_support( 'post-thumbnails' );
  23.  
  24.     // Add default posts and comments RSS feed links to head
  25.     add_theme_support( 'automatic-feed-links' );
  26.        
  27.         // Add support for visual editor stylesheet
  28.         add_editor_style('editor-style.css');
  29.  
  30.     // Make theme available for translation
  31.     // Translations can be filed in the /languages/ directory
  32.     load_theme_textdomain( 'starkers', TEMPLATEPATH . '/languages' );
  33.  
  34.     $locale = get_locale();
  35.     $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  36.     if ( is_readable( $locale_file ) )
  37.         require_once( $locale_file );
  38.  
  39.     // This theme uses wp_nav_menu() in one location.
  40.     register_nav_menus( array(
  41.         'primary' => __( 'Primary Navigation', 'starkers' ),
  42.     ) );
  43. }
  44. endif;
  45.  
  46.  
  47. function appglobe_jquery_enqueue() {
  48.    if (is_admin()) return;
  49.    global $wp_scripts;
  50.    $cdn_script_in_footer = false;
  51.  
  52.    if (is_a($wp_scripts, 'WP_Scripts') && isset($wp_scripts->registered['jquery'])) {
  53.       $registered_jquery_version = $wp_scripts -> registered[jquery] -> ver;
  54.  
  55.       if($registered_jquery_version) {
  56.          $google_jquery_url = ($_SERVER['SERVER_PORT'] == 443 ? "https" : "http") .
  57.          "://ajax.googleapis.com/ajax/libs/jquery/$registered_jquery_version/jquery.min.js";
  58.  
  59.          if(200 === wp_remote_retrieve_response_code(wp_remote_head($google_jquery_url))) {
  60.          wp_deregister_script('jquery');
  61.          wp_register_script('jquery', $google_jquery_url , false, null, $cdn_script_in_footer);
  62.          }
  63.       }
  64.    }
  65.     wp_enqueue_script('jquery');
  66.     wp_enqueue_style('jscrollpane', get_bloginfo('template_directory') . '/js/jScrollPane.css' );
  67.     wp_enqueue_script('jscrollpane', get_bloginfo('template_directory') . '/js/jScrollPane.js', array('jquery') );
  68.     wp_enqueue_script('jscroll', get_bloginfo('template_directory') . '/js/jScroll.js', array('jquery') );
  69.     wp_enqueue_script('wpa_script', get_bloginfo('template_directory') . '/js/wpascript.js', array('jquery') );
  70. }
  71. add_action('wp_enqueue_scripts', 'appglobe_jquery_enqueue', 11);
  72.  
  73. /**
  74.  * Set our wp_nav_menu() fallback, starkers_menu().
  75.  *
  76.  * @since Starkers HTML5 3.0
  77.  */
  78. function starkers_menu() {
  79.     echo '<nav><ul><li><a href="'.get_bloginfo('url').'">Home</a></li>';
  80.     wp_list_pages('title_li=');
  81.     echo '</ul></nav>';
  82. }
  83.  
  84. /**
  85.  * Remove inline styles printed when the gallery shortcode is used.
  86.  *
  87.  * @since Starkers HTML5 3.2
  88.  */
  89. add_filter( 'use_default_gallery_style', '__return_false' );
  90.  
  91. /**
  92.  * @since Starkers HTML5 3.0
  93.  * @deprecated in Starkers HTML5 3.2 for WordPress 3.1
  94.  *
  95.  * @return string The gallery style filter, with the styles themselves removed.
  96.  */
  97. function starkers_remove_gallery_css( $css ) {
  98.     return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  99. }
  100. // Backwards compatibility with WordPress 3.0.
  101. if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
  102.     add_filter( 'gallery_style', 'starkers_remove_gallery_css' );
  103.  
  104. if ( ! function_exists( 'starkers_comment' ) ) :
  105. /**
  106.  * Template for comments and pingbacks.
  107.  *
  108.  * @since Starkers HTML5 3.0
  109.  */
  110. function starkers_comment( $comment, $args, $depth ) {
  111.     $GLOBALS['comment'] = $comment;
  112.     switch ( $comment->comment_type ) :
  113.         case '' :
  114.     ?>
  115.     <article <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
  116.             <?php echo get_avatar( $comment, 40 ); ?>
  117.             <?php printf( __( '%s says:', 'starkers' ), sprintf( '%s', get_comment_author_link() ) ); ?>
  118.         <?php if ( $comment->comment_approved == '0' ) : ?>
  119.             <?php _e( 'Your comment is awaiting moderation.', 'starkers' ); ?>
  120.             <br />
  121.         <?php endif; ?>
  122.  
  123.         <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  124.             <?php
  125.                 /* translators: 1: date, 2: time */
  126.                 printf( __( '%1$s at %2$s', 'starkers' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'starkers' ), ' ' );
  127.             ?>
  128.  
  129.         <?php comment_text(); ?>
  130.  
  131.             <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  132.  
  133.     <?php
  134.             break;
  135.         case 'pingback'  :
  136.         case 'trackback' :
  137.     ?>
  138.     <article <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
  139.         <p><?php _e( 'Pingback:', 'starkers' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'starkers'), ' ' ); ?></p>
  140.     <?php
  141.             break;
  142.     endswitch;
  143. }
  144. endif;
  145.  
  146. /**
  147.  * Closes comments and pingbacks with </article> instead of </li>.
  148.  *
  149.  * @since Starkers HTML5 3.0
  150.  */
  151. function starkers_comment_close() {
  152.     echo '</article>';
  153. }
  154.  
  155. /**
  156.  * Adjusts the comment_form() input types for HTML5.
  157.  *
  158.  * @since Starkers HTML5 3.0
  159.  */
  160. function starkers_fields($fields) {
  161. $commenter = wp_get_current_commenter();
  162. $req = get_option( 'require_name_email' );
  163. $aria_req = ( $req ? " aria-required='true'" : '' );
  164. $fields =  array(
  165.     'author' => '<p><label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '*' : '' ) .
  166.     '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
  167.     'email'  => '<p><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '*' : '' ) .
  168.     '<input id="email" name="email" type="email" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
  169.     'url'    => '<p><label for="url">' . __( 'Website' ) . '</label>' .
  170.     '<input id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
  171. );
  172. return $fields;
  173. }
  174. add_filter('comment_form_default_fields','starkers_fields');
  175.  
  176. /**
  177.  * Register widgetized areas.
  178.  *
  179.  * @since Starkers HTML5 3.0
  180.  */
  181. function starkers_widgets_init() {
  182.  
  183.     register_sidebar( array(
  184.         'name' => __( 'Laurel Widget Area', 'starkers' ),
  185.         'id' => 'laurel-widget-area',
  186.         'description' => __( 'Laurels in the header - use one image, and make sure it is a transparent PNG no larger than 165px tall by 540px wide.', 'starkers' ),
  187.         'before_widget' => '<div id="laurels">',
  188.         'after_widget' => '</div><!-- #laurels -->',
  189.         'before_title' => '<h3>',
  190.         'after_title' => '</h3>',
  191.     ) );
  192.  
  193.  
  194.     register_sidebar( array(
  195.         'name' => __( 'Social Media Widget Area', 'starkers' ),
  196.         'id' => 'social-widget-area',
  197.         'description' => __( 'Social media icons in the navigation bar', 'starkers' ),
  198.         'before_widget' => '<div id="social-nav">',
  199.         'after_widget' => '</div><!-- #social-nav -->',
  200.         'before_title' => '<h3>',
  201.         'after_title' => '</h3>',
  202.     ) );
  203.  
  204.  
  205.     register_sidebar( array(
  206.         'name' => __( 'Donate Widget Area', 'starkers' ),
  207.         'id' => 'donate-widget-area',
  208.         'description' => __( 'The donate section of the page sidebar', 'starkers' ),
  209.         'before_widget' => '<div id="donate">',
  210.         'after_widget' => '</div>',
  211.         'before_title' => '<h3>',
  212.         'after_title' => '</h3>',
  213.     ) );
  214.  
  215.  
  216.     register_sidebar( array(
  217.         'name' => __( 'Buy Widget Area', 'starkers' ),
  218.         'id' => 'buy-widget-area',
  219.         'description' => __( 'The buy DVD and soundtrack sections of the page sidebar', 'starkers' ),
  220.         'before_widget' => '<div class="buy">',
  221.         'after_widget' => '</div>',
  222.         'before_title' => '<h3>',
  223.         'after_title' => '</h3>',
  224.     ) );
  225.  
  226.     register_sidebar( array(
  227.         'name' => __( 'Blog Widget Area', 'starkers' ),
  228.         'id' => 'blog-widget-area',
  229.         'description' => __( 'Widgets that appear in the sidebar on blog pages', 'starkers' ),
  230.         'before_widget' => '<div class="blogwidget %2$s">',
  231.         'after_widget' => '</div>',
  232.         'before_title' => '<h3>',
  233.         'after_title' => '</h3>',
  234.     ) );
  235.  
  236.  
  237.     register_sidebar( array(
  238.         'name' => __( 'Footer Widget Area', 'starkers' ),
  239.         'id' => 'footer-widget-area',
  240.         'description' => __( 'The footer widget area for logos of supporting organizations', 'starkers' ),
  241.         'before_widget' => '<div id="supporters">',
  242.         'after_widget' => '</div><!-- #supporters -->',
  243.         'before_title' => '<h3>',
  244.         'after_title' => '</h3>',
  245.     ) );
  246. }
  247. /** Register sidebars by running starkers_widgets_init() on the widgets_init hook. */
  248. add_action( 'widgets_init', 'starkers_widgets_init' );
  249.  
  250. /**
  251.  * Removes the default styles that are packaged with the Recent Comments widget.
  252.  *
  253.  * @updated Starkers HTML5 3.2
  254.  */
  255. function starkers_remove_recent_comments_style() {
  256.     add_filter( 'show_recent_comments_widget_style', '__return_false' );
  257. }
  258. add_action( 'widgets_init', 'starkers_remove_recent_comments_style' );
  259.  
  260. if ( ! function_exists( 'starkers_posted_on' ) ) :
  261. /**
  262.  * Prints HTML with meta information for the current post—date/time and author.
  263.  *
  264.  * @since Starkers HTML5 3.0
  265.  */
  266. function starkers_posted_on() {
  267.     printf( __( 'Posted on %2$s by %3$s', 'starkers' ),
  268.         'meta-prep meta-prep-author',
  269.         sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time datetime="%3$s" pubdate>%4$s</time></a>',
  270.             get_permalink(),
  271.             esc_attr( get_the_time() ),
  272.             get_the_date('Y-m-d'),
  273.             get_the_date()
  274.         ),
  275.         sprintf( '<a href="%1$s" title="%2$s">%3$s</a>',
  276.             get_author_posts_url( get_the_author_meta( 'ID' ) ),
  277.             sprintf( esc_attr__( 'View all posts by %s', 'starkers' ), get_the_author() ),
  278.             get_the_author()
  279.         )
  280.     );
  281. }
  282. endif;
  283.  
  284. if ( ! function_exists( 'starkers_posted_in' ) ) :
  285. /**
  286.  * Prints HTML with meta information for the current post (category, tags and permalink).
  287.  *
  288.  * @since Starkers HTML5 3.0
  289.  */
  290. function starkers_posted_in() {
  291.     // Retrieves tag list of current post, separated by commas.
  292.     $tag_list = get_the_tag_list( '', ', ' );
  293.     if ( $tag_list ) {
  294.         $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'starkers' );
  295.     } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
  296.         $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'starkers' );
  297.     } else {
  298.         $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'starkers' );
  299.     }
  300.     // Prints the string, replacing the placeholders.
  301.     printf(
  302.         $posted_in,
  303.         get_the_category_list( ', ' ),
  304.         $tag_list,
  305.         get_permalink(),
  306.         the_title_attribute( 'echo=0' )
  307.     );
  308. }
  309. endif;
  310.  
  311.  
  312. // change excerpt length
  313.  
  314. function custom_excerpt_length( $length ) {
  315.     return 50;
  316. }
  317. add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
  318.  
  319.  
  320. function getTopParentPostID($myid){
  321.         $mypage = get_page($myid);
  322.  
  323.         if ($mypage->post_parent == 0){
  324.                 return $mypage->ID;
  325.         }
  326.         else{
  327.                 return getTopParentPostID($mypage->post_parent);
  328.         }
  329. }
  330.  
  331. function depthToRoot($myid,$depth){
  332.         $mypage = get_page($myid);
  333.  
  334.         if ($mypage->post_parent == 0){
  335.                 return $depth;
  336.         }
  337.         else{
  338.                 $depth++;
  339.                 return depthToRoot($mypage->post_parent, $depth);
  340.         }
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement