Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Tokokoo Framework
- *
- * @package Tokokoo
- * @copyright Copyright (c) 2011 Tokokoo
- * @license http://www.opensource.org/licenses/gpl-2.0.php GNU GPL version 2
- * @version $Id:$
- *
- * @developer Onnay Okheng (@onnayokheng)
- * @front-end Satrya Bima (@satryawp)
- */
- ################################################################################
- // including other file
- ################################################################################
- include_once("functions/init.php");
- include_once(TK_FUNC_DIR . "/theme-functions.php");
- include_once(TK_FUNC_DIR . "/theme-enqueue.php");
- include_once(TK_FUNC_DIR . "/theme-options.php");
- // register and unregister widget
- include_once(TK_FUNC_DIR . "/widget/specials_widget.php");
- include_once(TK_FUNC_DIR . "/widget/donations_widget.php");
- // load textdomain
- load_theme_textdomain('tokokoo', get_template_directory().'/language');
- ################################################################################
- // Add theme sidebars
- ################################################################################
- if ( function_exists('register_sidebar') ) {
- register_sidebar(array(
- 'name' => __( 'Home Area' ),
- 'before_widget' => '<section id="%1$s" class="widget %2$s">',
- 'after_widget' => '</section>',
- 'before_title' => '<h3 class="widget_title">',
- 'after_title' => '</h3>',
- ));
- register_sidebar(array(
- 'name' => __( 'Post Area' ),
- 'before_widget' => '<section id="%1$s" class="widget %2$s">',
- 'after_widget' => '</section>',
- 'before_title' => '<h3 class="widget_title">',
- 'after_title' => '</h3>',
- ));
- register_sidebar(array(
- 'name' => __( 'Page Area' ),
- 'before_widget' => '<section id="%1$s" class="widget %2$s">',
- 'after_widget' => '</section>',
- 'before_title' => '<h3 class="widget_title">',
- 'after_title' => '</h3>',
- ));
- register_sidebar(array(
- 'name' => __( 'WPSC Area' ),
- 'before_widget' => '<section id="%1$s" class="widget %2$s">',
- 'after_widget' => '</section>',
- 'before_title' => '<h3 class="widget_title">',
- 'after_title' => '</h3>',
- ));
- }
- ################################################################################
- // Add theme support
- ################################################################################
- if ( function_exists( 'add_theme_support' ) ) {
- add_theme_support( 'automatic-feed-links' );
- add_theme_support( 'nav-menus' );
- add_theme_support( 'post-thumbnails' );
- set_post_thumbnail_size( 100, 100, true );
- register_nav_menus( array(
- 'primary' => __( 'Primary Navigation' ),
- ) );
- }
- ################################################################################
- // Comment formatting
- ################################################################################
- /**
- * Comment for themming
- *
- * @param object $comment
- * @param array $args
- * @param string $depth
- */
- function tk_theme_comments($comment, $args, $depth) {
- $GLOBALS['comment'] = $comment; ?>
- <li>
- <article <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
- <header class="comment-author vcard">
- <?php echo get_avatar($comment,$size='48',$default='<path_to_url>' ); ?>
- <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
- <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>
- <?php edit_comment_link(__('(Edit)'),' ','') ?>
- </header>
- <?php if ($comment->comment_approved == '0') : ?>
- <em><?php _e('Your comment is awaiting moderation.') ?></em>
- <br />
- <?php endif; ?>
- <?php comment_text() ?>
- <nav>
- <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
- </nav>
- </article>
- <!-- </li> is added by wordpress automatically -->
- <?php
- }
- ################################################################################
- // Filters
- ################################################################################
- function tk_custom_excerpt($text) {
- return str_replace('[...]', ' <a href="'. get_permalink($post->ID) . '" class="more">' . 'More »' . '</a>', $text);
- }
- add_filter('the_excerpt', 'tk_custom_excerpt');
- // Allow HTML in descriptions
- $filters = array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description');
- foreach ( $filters as $filter ) {
- remove_filter($filter, 'wp_filter_kses');
- }
- ################################################################################
- // Filters
- ################################################################################
- function tk_print_background_color_style(){
- $options = tokokoo_get_theme_options();
- $background_color = $options['link_color'];
- $default_background_color = tokokoo_get_default_theme_options();
- if ($default_background_color['link_color'] == $background_color )
- return;
- ?>
- <style>
- body{background-color: <?php echo $background_color; ?> !important;}
- </style>
- <?php
- }
- add_action( 'wp_head', 'tk_print_background_color_style' );
- ################################################################################
- // Put your script here
- ################################################################################
- /**
- * Funtion for checking post nav
- *
- * @global object $wp_query
- * @return boolean
- */
- function tk_show_posts_nav() {
- global $wp_query;
- return ($wp_query->max_num_pages > 1);
- }
- /**
- * For updating cart count live Query
- */
- function tk_update_cart_count(){
- $output = sprintf( _n('%d item', '%d items in cart', wpsc_cart_item_count(), 'wpsc'), wpsc_cart_item_count());
- $totalprice = wpsc_cart_total_widget();
- echo "jQuery('span.totalitems').html('$output');jQuery('span.totalprice').html(\"$totalprice\");";
- exit;
- }
- if (isset($_GET['tk_ajax_action']) && 'status_cart' == $_GET['tk_ajax_action'])
- add_action( 'init', 'tk_update_cart_count' );
- // add script js for live cart
- function tk_add_script_cart(){
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function() {
- // put all your jQuery goodness in here.
- var $hasCheck = false;
- jQuery('.wpsc_buy_button').click(function() {
- $hasCheck = false;
- jQuery('.wpsc_buy_button').ajaxSuccess(function() {
- if (!$hasCheck){
- $hasCheck = true;
- jQuery.get('index.php?tk_ajax_action=status_cart', function(data) {
- eval(data);
- });
- }
- });
- });
- });
- </script>
- <?php }
- add_action('wp_head', 'tk_add_script_cart');
- // checking if the plugin has installed.
- if ( function_exists('wpsc_core_setup_globals') ) {
- // get option setup themes.
- $setup = get_option('tk_setup_themes');
- if(empty($setup)){
- add_option('tk_setup_themes', 0);
- add_action('init', 'tk_setup_themes' );
- }
- function tk_setup_themes(){
- // get option setup themes.
- $setup = get_option('tk_setup_themes');
- if($setup != 1){
- update_option('product_image_height', 100);
- update_option('product_image_width', 100);
- update_option('single_view_image_width', 350);
- update_option('single_view_image_height', 300);
- update_option('tk_setup_themes', 1);
- }
- }
- }
- // remove admin bar for buddypress.
- if ( function_exists( 'bp_core_load_admin_bar' ) ):
- // REMOVE BUDDYPRESS ADMIN BAR
- define( 'BP_DISABLE_ADMIN_BAR', true );
- define( 'BP_SILENCE_THEME_NOTICE', true );
- // Load the AJAX functions for the theme
- require_once( TEMPLATEPATH . '/_inc/ajax.php' );
- // Load the javascript for the theme
- wp_enqueue_script( 'dtheme-ajax-js', get_template_directory_uri() . '/_inc/global.js', array( 'jquery' ) );
- // Add words that we need to use in JS to the end of the page so they can be translated and still used.
- $params = array(
- 'my_favs' => __( 'My Favorites', 'buddypress' ),
- 'accepted' => __( 'Accepted', 'buddypress' ),
- 'rejected' => __( 'Rejected', 'buddypress' ),
- 'show_all_comments' => __( 'Show all comments for this thread', 'buddypress' ),
- 'show_all' => __( 'Show all', 'buddypress' ),
- 'comments' => __( 'comments', 'buddypress' ),
- 'close' => __( 'Close', 'buddypress' ),
- '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() ) )
- );
- wp_localize_script( 'dtheme-ajax-js', 'BP_DTheme', $params );
- /**
- * Filter the dropdown for selecting the page to show on front to include "Activity Stream"
- *
- * @param string $page_html A list of pages as a dropdown (select list)
- * @see wp_dropdown_pages()
- * @return string
- * @package BuddyPress Theme
- * @since 1.2
- */
- function bp_dtheme_wp_pages_filter( $page_html ) {
- if ( !bp_is_active( 'activity' ) )
- return $page_html;
- if ( 'page_on_front' != substr( $page_html, 14, 13 ) )
- return $page_html;
- $selected = false;
- $page_html = str_replace( '</select>', '', $page_html );
- if ( bp_dtheme_page_on_front() == 'activity' )
- $selected = ' selected="selected"';
- $page_html .= '<option class="level-0" value="activity"' . $selected . '>' . __( 'Activity Stream', 'buddypress' ) . '</option></select>';
- return $page_html;
- }
- add_filter( 'wp_dropdown_pages', 'bp_dtheme_wp_pages_filter' );
- /**
- * Hijack the saving of page on front setting to save the activity stream setting
- *
- * @param $string $oldvalue Previous value of get_option( 'page_on_front' )
- * @param $string $oldvalue New value of get_option( 'page_on_front' )
- * @return string
- * @package BuddyPress Theme
- * @since 1.2
- */
- function bp_dtheme_page_on_front_update( $oldvalue, $newvalue ) {
- if ( !is_admin() || !is_super_admin() )
- return false;
- if ( 'activity' == $_POST['page_on_front'] )
- return 'activity';
- else
- return $oldvalue;
- }
- add_action( 'pre_update_option_page_on_front', 'bp_dtheme_page_on_front_update', 10, 2 );
- /**
- * Load the activity stream template if settings allow
- *
- * @param string $template Absolute path to the page template
- * @return string
- * @global WP_Query $wp_query WordPress query object
- * @package BuddyPress Theme
- * @since 1.2
- */
- function bp_dtheme_page_on_front_template( $template ) {
- global $wp_query;
- if ( empty( $wp_query->post->ID ) )
- return locate_template( array( 'activity/index.php' ), false );
- else
- return $template;
- }
- add_filter( 'page_template', 'bp_dtheme_page_on_front_template' );
- /**
- * Return the ID of a page set as the home page.
- *
- * @return false|int ID of page set as the home page
- * @package BuddyPress Theme
- * @since 1.2
- */
- function bp_dtheme_page_on_front() {
- if ( 'page' != get_option( 'show_on_front' ) )
- return false;
- return apply_filters( 'bp_dtheme_page_on_front', get_option( 'page_on_front' ) );
- }
- /**
- * Force the page ID as a string to stop the get_posts query from kicking up a fuss.
- *
- * @global WP_Query $wp_query WordPress query object
- * @package BuddyPress Theme
- * @since 1.2
- */
- function bp_dtheme_fix_get_posts_on_activity_front() {
- global $wp_query;
- if ( !empty($wp_query->query_vars['page_id']) && 'activity' == $wp_query->query_vars['page_id'] )
- $wp_query->query_vars['page_id'] = '"activity"';
- }
- add_action( 'pre_get_posts', 'bp_dtheme_fix_get_posts_on_activity_front' );
- /**
- * WP 3.0 requires there to be a non-null post in the posts array
- *
- * @param array $posts Posts as retrieved by WP_Query
- * @global WP_Query $wp_query WordPress query object
- * @return array
- * @package BuddyPress Theme
- * @since 1.2.5
- */
- function bp_dtheme_fix_the_posts_on_activity_front( $posts ) {
- global $wp_query;
- // NOTE: the double quotes around '"activity"' are thanks to our previous function bp_dtheme_fix_get_posts_on_activity_front()
- if ( empty( $posts ) && !empty( $wp_query->query_vars['page_id'] ) && '"activity"' == $wp_query->query_vars['page_id'] )
- $posts = array( (object) array( 'ID' => 'activity' ) );
- return $posts;
- }
- add_filter( 'the_posts', 'bp_dtheme_fix_the_posts_on_activity_front' );
- /**
- * bp_dtheme_activity_secondary_avatars()
- *
- * Add secondary avatar image to this activity stream's record, if supported
- *
- * @param string $action The text of this activity
- * @param BP_Activity_Activity $activity Activity object
- * @return string
- * @package BuddyPress Theme
- * @since 1.2.6
- */
- function bp_dtheme_activity_secondary_avatars( $action, $activity ) {
- switch ( $activity->component ) {
- case 'groups' :
- case 'friends' :
- // Only insert avatar if one exists
- if ( $secondary_avatar = bp_get_activity_secondary_avatar() ) {
- $reverse_content = strrev( $action );
- $position = strpos( $reverse_content, 'a<' );
- $action = substr_replace( $action, $secondary_avatar, -$position - 2, 0 );
- }
- break;
- }
- return $action;
- }
- add_filter( 'bp_get_activity_action_pre_meta', 'bp_dtheme_activity_secondary_avatars', 10, 2 );
- /**
- * Show a notice when the theme is activated - workaround by Ozh (http://old.nabble.com/Activation-hook-exist-for-themes--td25211004.html)
- *
- * @package BuddyPress Theme
- * @since 1.2
- */
- function bp_dtheme_show_notice() { ?>
- <div id="message" class="updated fade">
- <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>
- </div>
- <style type="text/css">#message2, #message0 { display: none; }</style>
- <?php
- }
- if ( is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" )
- add_action( 'admin_notices', 'bp_dtheme_show_notice' );
- // Member Buttons
- if ( bp_is_active( 'friends' ) )
- add_action( 'bp_member_header_actions', 'bp_add_friend_button' );
- if ( bp_is_active( 'activity' ) )
- add_action( 'bp_member_header_actions', 'bp_send_public_message_button' );
- if ( bp_is_active( 'messages' ) )
- add_action( 'bp_member_header_actions', 'bp_send_private_message_button' );
- // Group Buttons
- if ( bp_is_active( 'groups' ) ) {
- add_action( 'bp_group_header_actions', 'bp_group_join_button' );
- add_action( 'bp_group_header_actions', 'bp_group_new_topic_button' );
- add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
- }
- // Blog Buttons
- if ( bp_is_active( 'blogs' ) )
- add_action( 'bp_directory_blogs_actions', 'bp_blogs_visit_blog_button' );
- endif;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement