Advertisement
simonwheatley

functions.php

Oct 11th, 2011
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.56 KB | None | 0 0
  1. <?php
  2.  
  3.     /**
  4.      * Tokokoo Framework
  5.      *
  6.      * @package    Tokokoo
  7.      * @copyright  Copyright (c) 2011 Tokokoo
  8.      * @license    http://www.opensource.org/licenses/gpl-2.0.php GNU GPL version 2
  9.      * @version    $Id:$
  10.      *
  11.      * @developer Onnay Okheng (@onnayokheng)
  12.      * @front-end Satrya Bima (@satryawp)
  13.      */
  14.  
  15. ################################################################################
  16. // including other file
  17. ################################################################################
  18.    
  19.     include_once("functions/init.php");
  20.     include_once(TK_FUNC_DIR . "/theme-functions.php");
  21.     include_once(TK_FUNC_DIR . "/theme-enqueue.php");
  22.     include_once(TK_FUNC_DIR . "/theme-options.php");
  23.    
  24.     // register and unregister widget
  25.     include_once(TK_FUNC_DIR . "/widget/specials_widget.php");
  26.     include_once(TK_FUNC_DIR . "/widget/donations_widget.php");
  27.  
  28.     // load textdomain
  29.     load_theme_textdomain('tokokoo', get_template_directory().'/language');
  30.  
  31. ################################################################################
  32. // Add theme sidebars
  33. ################################################################################
  34.  
  35.     if ( function_exists('register_sidebar') ) {
  36.             register_sidebar(array(
  37.                 'name'          => __( 'Home Area' ),
  38.                 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  39.                 'after_widget'  => '</section>',
  40.                 'before_title'  => '<h3 class="widget_title">',
  41.                 'after_title'   => '</h3>',
  42.             ));
  43.             register_sidebar(array(
  44.                 'name'          => __( 'Post Area' ),
  45.                 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  46.                 'after_widget'  => '</section>',
  47.                 'before_title'  => '<h3 class="widget_title">',
  48.                 'after_title'   => '</h3>',
  49.             ));
  50.             register_sidebar(array(
  51.                 'name'          => __( 'Page Area' ),
  52.                 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  53.                 'after_widget'  => '</section>',
  54.                 'before_title'  => '<h3 class="widget_title">',
  55.                 'after_title'   => '</h3>',
  56.             ));
  57.             register_sidebar(array(
  58.                 'name'          => __( 'WPSC Area' ),
  59.                 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  60.                 'after_widget'  => '</section>',
  61.                 'before_title'  => '<h3 class="widget_title">',
  62.                 'after_title'   => '</h3>',
  63.             ));
  64.     }
  65.  
  66. ################################################################################
  67. // Add theme support
  68. ################################################################################
  69.  
  70.     if ( function_exists( 'add_theme_support' ) ) {
  71.         add_theme_support( 'automatic-feed-links' );
  72.         add_theme_support( 'nav-menus' );
  73.         add_theme_support( 'post-thumbnails' );
  74.         set_post_thumbnail_size( 100, 100, true );
  75.  
  76.         register_nav_menus( array(
  77.                 'primary' => __( 'Primary Navigation' ),
  78.         ) );
  79.     }
  80.  
  81. ################################################################################
  82. // Comment formatting
  83. ################################################################################
  84.  
  85.     /**
  86.      * Comment for themming
  87.      *
  88.      * @param object $comment
  89.      * @param array $args
  90.      * @param string $depth
  91.      */
  92.     function tk_theme_comments($comment, $args, $depth) {
  93.             $GLOBALS['comment'] = $comment; ?>
  94.             <li>
  95.                 <article <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
  96.                    <header class="comment-author vcard">
  97.                       <?php echo get_avatar($comment,$size='48',$default='<path_to_url>' ); ?>
  98.                       <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
  99.                       <time><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></time>
  100.                       <?php edit_comment_link(__('(Edit)'),'  ','') ?>
  101.                    </header>
  102.                    <?php if ($comment->comment_approved == '0') : ?>
  103.                       <em><?php _e('Your comment is awaiting moderation.') ?></em>
  104.                       <br />
  105.                    <?php endif; ?>
  106.                    <?php comment_text() ?>
  107.                    <nav>
  108.                      <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  109.                    </nav>
  110.                 </article>
  111.         <!-- </li> is added by wordpress automatically -->
  112.         <?php
  113.     }
  114.  
  115. ################################################################################
  116. // Filters
  117. ################################################################################
  118.  
  119.     function tk_custom_excerpt($text) {
  120.         return str_replace('[...]', ' <a href="'. get_permalink($post->ID) . '" class="more">' . 'More&nbsp;&raquo;' . '</a>', $text);
  121.     }
  122.     add_filter('the_excerpt', 'tk_custom_excerpt');
  123.  
  124.     // Allow HTML in descriptions
  125.     $filters = array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description');
  126.     foreach ( $filters as $filter ) {
  127.             remove_filter($filter, 'wp_filter_kses');
  128.     }
  129.  
  130. ################################################################################
  131. // Filters
  132. ################################################################################
  133.  
  134.     function tk_print_background_color_style(){
  135.         $options            = tokokoo_get_theme_options();
  136.         $background_color   = $options['link_color'];
  137.  
  138.         $default_background_color = tokokoo_get_default_theme_options();
  139.  
  140.         if ($default_background_color['link_color'] == $background_color )
  141.             return;
  142. ?>
  143.         <style>
  144.             body{background-color: <?php echo $background_color; ?> !important;}
  145.         </style>
  146. <?php
  147.     }
  148.     add_action( 'wp_head', 'tk_print_background_color_style' );
  149.  
  150. ################################################################################
  151. // Put your script here
  152. ################################################################################
  153.  
  154.     /**
  155.      * Funtion for checking post nav
  156.      *
  157.      * @global object $wp_query
  158.      * @return boolean
  159.      */
  160.     function tk_show_posts_nav() {
  161.        global $wp_query;
  162.        return ($wp_query->max_num_pages > 1);
  163.     }
  164.    
  165.     /**
  166.      * For updating cart count live Query
  167.      */
  168.     function tk_update_cart_count(){
  169.         $output = sprintf( _n('%d item', '%d items in cart', wpsc_cart_item_count(), 'wpsc'), wpsc_cart_item_count());
  170.         $totalprice = wpsc_cart_total_widget();
  171.         echo "jQuery('span.totalitems').html('$output');jQuery('span.totalprice').html(\"$totalprice\");";
  172.         exit;
  173.     }
  174.     if (isset($_GET['tk_ajax_action']) && 'status_cart' == $_GET['tk_ajax_action'])
  175.         add_action( 'init', 'tk_update_cart_count' );
  176.  
  177.     // add script js for live cart
  178.     function tk_add_script_cart(){
  179. ?>
  180.        
  181. <script type="text/javascript">
  182.   jQuery(document).ready(function() {
  183.  
  184.       // put all your jQuery goodness in here.
  185.       var $hasCheck = false;
  186.       jQuery('.wpsc_buy_button').click(function() {
  187.           $hasCheck = false;
  188.           jQuery('.wpsc_buy_button').ajaxSuccess(function() {
  189.               if (!$hasCheck){
  190.                       $hasCheck = true;
  191.                       jQuery.get('index.php?tk_ajax_action=status_cart', function(data) {
  192.                             eval(data);
  193.                       });
  194.               }
  195.           });
  196.       });
  197.   });
  198. </script>
  199. <?php }
  200.         add_action('wp_head', 'tk_add_script_cart');
  201.    
  202.  
  203.     // checking if the plugin has installed.
  204.     if ( function_exists('wpsc_core_setup_globals') ) {
  205.  
  206.         // get option setup themes.
  207.         $setup  = get_option('tk_setup_themes');
  208.  
  209.         if(empty($setup)){
  210.             add_option('tk_setup_themes', 0);
  211.             add_action('init', 'tk_setup_themes' );
  212.         }
  213.  
  214.         function tk_setup_themes(){
  215.            
  216.             // get option setup themes.
  217.             $setup  = get_option('tk_setup_themes');
  218.            
  219.             if($setup != 1){
  220.                 update_option('product_image_height', 100);
  221.                 update_option('product_image_width', 100);
  222.                 update_option('single_view_image_width', 350);
  223.                 update_option('single_view_image_height', 300);
  224.                
  225.                 update_option('tk_setup_themes', 1);
  226.             }
  227.         }
  228.     }
  229.  
  230.  
  231.     // remove admin bar for buddypress.
  232.     if ( function_exists( 'bp_core_load_admin_bar' ) ):
  233.  
  234.                 // REMOVE BUDDYPRESS ADMIN BAR
  235.                 define( 'BP_DISABLE_ADMIN_BAR', true );
  236.                 define( 'BP_SILENCE_THEME_NOTICE', true );
  237.                
  238.         // Load the AJAX functions for the theme
  239.         require_once( TEMPLATEPATH . '/_inc/ajax.php' );
  240.         // Load the javascript for the theme
  241.         wp_enqueue_script( 'dtheme-ajax-js', get_template_directory_uri() . '/_inc/global.js', array( 'jquery' ) );
  242.  
  243.         // Add words that we need to use in JS to the end of the page so they can be translated and still used.
  244.         $params = array(
  245.                 'my_favs'           => __( 'My Favorites', 'buddypress' ),
  246.                 'accepted'          => __( 'Accepted', 'buddypress' ),
  247.                 'rejected'          => __( 'Rejected', 'buddypress' ),
  248.                 'show_all_comments' => __( 'Show all comments for this thread', 'buddypress' ),
  249.                 'show_all'          => __( 'Show all', 'buddypress' ),
  250.                 'comments'          => __( 'comments', 'buddypress' ),
  251.                 'close'             => __( 'Close', 'buddypress' ),
  252.                 'mention_explain'   => sprintf( __( "%s is a unique identifier for %s that you can type into any message on this site. %s will be sent a notification and a link to your message any time you use it.", 'buddypress' ), '@' . bp_get_displayed_user_username(), bp_get_user_firstname( bp_get_displayed_user_fullname() ), bp_get_user_firstname( bp_get_displayed_user_fullname() ) )
  253.         );
  254.         wp_localize_script( 'dtheme-ajax-js', 'BP_DTheme', $params );
  255.  
  256.         /**
  257.          * Filter the dropdown for selecting the page to show on front to include "Activity Stream"
  258.          *
  259.          * @param string $page_html A list of pages as a dropdown (select list)
  260.          * @see wp_dropdown_pages()
  261.          * @return string
  262.          * @package BuddyPress Theme
  263.          * @since 1.2
  264.          */
  265.         function bp_dtheme_wp_pages_filter( $page_html ) {
  266.                 if ( !bp_is_active( 'activity' ) )
  267.                         return $page_html;
  268.  
  269.                 if ( 'page_on_front' != substr( $page_html, 14, 13 ) )
  270.                         return $page_html;
  271.  
  272.                 $selected = false;
  273.                 $page_html = str_replace( '</select>', '', $page_html );
  274.  
  275.                 if ( bp_dtheme_page_on_front() == 'activity' )
  276.                         $selected = ' selected="selected"';
  277.  
  278.                 $page_html .= '<option class="level-0" value="activity"' . $selected . '>' . __( 'Activity Stream', 'buddypress' ) . '</option></select>';
  279.                 return $page_html;
  280.         }
  281.         add_filter( 'wp_dropdown_pages', 'bp_dtheme_wp_pages_filter' );
  282.  
  283.         /**
  284.          * Hijack the saving of page on front setting to save the activity stream setting
  285.          *
  286.          * @param $string $oldvalue Previous value of get_option( 'page_on_front' )
  287.          * @param $string $oldvalue New value of get_option( 'page_on_front' )
  288.          * @return string
  289.          * @package BuddyPress Theme
  290.          * @since 1.2
  291.          */
  292.         function bp_dtheme_page_on_front_update( $oldvalue, $newvalue ) {
  293.                 if ( !is_admin() || !is_super_admin() )
  294.                         return false;
  295.  
  296.                 if ( 'activity' == $_POST['page_on_front'] )
  297.                         return 'activity';
  298.                 else
  299.                         return $oldvalue;
  300.         }
  301.         add_action( 'pre_update_option_page_on_front', 'bp_dtheme_page_on_front_update', 10, 2 );
  302.  
  303.         /**
  304.          * Load the activity stream template if settings allow
  305.          *
  306.          * @param string $template Absolute path to the page template
  307.          * @return string
  308.          * @global WP_Query $wp_query WordPress query object
  309.          * @package BuddyPress Theme
  310.          * @since 1.2
  311.          */
  312.         function bp_dtheme_page_on_front_template( $template ) {
  313.                 global $wp_query;
  314.  
  315.                 if ( empty( $wp_query->post->ID ) )
  316.                         return locate_template( array( 'activity/index.php' ), false );
  317.                 else
  318.                         return $template;
  319.         }
  320.         add_filter( 'page_template', 'bp_dtheme_page_on_front_template' );
  321.  
  322.         /**
  323.          * Return the ID of a page set as the home page.
  324.          *
  325.          * @return false|int ID of page set as the home page
  326.          * @package BuddyPress Theme
  327.          * @since 1.2
  328.          */
  329.         function bp_dtheme_page_on_front() {
  330.                 if ( 'page' != get_option( 'show_on_front' ) )
  331.                         return false;
  332.  
  333.                 return apply_filters( 'bp_dtheme_page_on_front', get_option( 'page_on_front' ) );
  334.         }
  335.  
  336.         /**
  337.          * Force the page ID as a string to stop the get_posts query from kicking up a fuss.
  338.          *
  339.          * @global WP_Query $wp_query WordPress query object
  340.          * @package BuddyPress Theme
  341.          * @since 1.2
  342.          */
  343.         function bp_dtheme_fix_get_posts_on_activity_front() {
  344.                 global $wp_query;
  345.  
  346.                 if ( !empty($wp_query->query_vars['page_id']) && 'activity' == $wp_query->query_vars['page_id'] )
  347.                         $wp_query->query_vars['page_id'] = '"activity"';
  348.         }
  349.         add_action( 'pre_get_posts', 'bp_dtheme_fix_get_posts_on_activity_front' );
  350.  
  351.         /**
  352.          * WP 3.0 requires there to be a non-null post in the posts array
  353.          *
  354.          * @param array $posts Posts as retrieved by WP_Query
  355.          * @global WP_Query $wp_query WordPress query object
  356.          * @return array
  357.          * @package BuddyPress Theme
  358.          * @since 1.2.5
  359.          */
  360.         function bp_dtheme_fix_the_posts_on_activity_front( $posts ) {
  361.                 global $wp_query;
  362.  
  363.                 // NOTE: the double quotes around '"activity"' are thanks to our previous function bp_dtheme_fix_get_posts_on_activity_front()
  364.                 if ( empty( $posts ) && !empty( $wp_query->query_vars['page_id'] ) && '"activity"' == $wp_query->query_vars['page_id'] )
  365.                         $posts = array( (object) array( 'ID' => 'activity' ) );
  366.  
  367.                 return $posts;
  368.         }
  369.         add_filter( 'the_posts', 'bp_dtheme_fix_the_posts_on_activity_front' );
  370.  
  371.         /**
  372.          * bp_dtheme_activity_secondary_avatars()
  373.          *
  374.          * Add secondary avatar image to this activity stream's record, if supported
  375.          *
  376.          * @param string $action The text of this activity
  377.          * @param BP_Activity_Activity $activity Activity object
  378.          * @return string
  379.          * @package BuddyPress Theme
  380.          * @since 1.2.6
  381.          */
  382.         function bp_dtheme_activity_secondary_avatars( $action, $activity ) {
  383.                 switch ( $activity->component ) {
  384.                         case 'groups' :
  385.                         case 'friends' :
  386.                                 // Only insert avatar if one exists
  387.                                 if ( $secondary_avatar = bp_get_activity_secondary_avatar() ) {
  388.                                         $reverse_content = strrev( $action );
  389.                                         $position        = strpos( $reverse_content, 'a<' );
  390.                                         $action          = substr_replace( $action, $secondary_avatar, -$position - 2, 0 );
  391.                                 }
  392.                                 break;
  393.                 }
  394.  
  395.                 return $action;
  396.         }
  397.         add_filter( 'bp_get_activity_action_pre_meta', 'bp_dtheme_activity_secondary_avatars', 10, 2 );
  398.  
  399.         /**
  400.          * Show a notice when the theme is activated - workaround by Ozh (http://old.nabble.com/Activation-hook-exist-for-themes--td25211004.html)
  401.          *
  402.          * @package BuddyPress Theme
  403.          * @since 1.2
  404.          */
  405.         function bp_dtheme_show_notice() { ?>
  406.                 <div id="message" class="updated fade">
  407.                         <p><?php printf( __( 'Theme activated! This theme contains <a href="%s">custom header image</a> support and <a href="%s">sidebar widgets</a>.', 'buddypress' ), admin_url( 'themes.php?page=custom-header' ), admin_url( 'widgets.php' ) ) ?></p>
  408.                 </div>
  409.  
  410.                 <style type="text/css">#message2, #message0 { display: none; }</style>
  411.                 <?php
  412.         }
  413.         if ( is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" )
  414.                 add_action( 'admin_notices', 'bp_dtheme_show_notice' );
  415.  
  416.  
  417.         // Member Buttons
  418.         if ( bp_is_active( 'friends' ) )
  419.                 add_action( 'bp_member_header_actions',    'bp_add_friend_button' );
  420.  
  421.         if ( bp_is_active( 'activity' ) )
  422.                 add_action( 'bp_member_header_actions',    'bp_send_public_message_button' );
  423.  
  424.         if ( bp_is_active( 'messages' ) )
  425.                 add_action( 'bp_member_header_actions',    'bp_send_private_message_button' );
  426.  
  427.         // Group Buttons
  428.         if ( bp_is_active( 'groups' ) ) {
  429.                 add_action( 'bp_group_header_actions',     'bp_group_join_button' );
  430.                 add_action( 'bp_group_header_actions',     'bp_group_new_topic_button' );
  431.                 add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
  432.         }
  433.  
  434.         // Blog Buttons
  435.         if ( bp_is_active( 'blogs' ) )
  436.                 add_action( 'bp_directory_blogs_actions',  'bp_blogs_visit_blog_button' );
  437.  
  438.  
  439.     endif;
  440.  
  441. ?>
  442.  
  443.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement