Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_theme_support( 'post-thumbnails', array( 'post' ) ); // Add it for posts
- add_theme_support( 'post-thumbnails', array( 'page' ) ); // Add it for pages
- set_post_thumbnail_size( 50, 50, true ); // 50 pixels wide by 50 pixels tall, hard crop mode
- // Stop the theme from killing WordPress if BuddyPress is not enabled.
- if ( !class_exists( 'BP_Core_User' ) )
- return false;
- // Register the widget columns
- register_sidebars( 1,
- array(
- 'name' => 'Sidebar',
- 'before_widget' => '<div id="%1$s" class="widget %2$s">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="widgettitle">',
- 'after_title' => '</h3>'
- )
- );
- // 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 );
- /**
- * Add the JS needed for blog comment replies
- *
- * @package BuddyPress Theme
- * @since 1.2
- */
- function bp_dtheme_add_blog_comments_js() {
- if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
- }
- add_action( 'template_redirect', 'bp_dtheme_add_blog_comments_js' );
- /**
- * HTML for outputting blog comments as defined by the WP comment API
- *
- * @param mixed $comment Comment record from database
- * @param array $args Arguments from wp_list_comments() call
- * @param int $depth Comment nesting level
- * @see wp_list_comments()
- * @package BuddyPress Theme
- * @since 1.2
- */
- function bp_dtheme_blog_comments( $comment, $args, $depth ) {
- $GLOBALS['comment'] = $comment; ?>
- <?php if ( 'pingback' == $comment->comment_type ) return false; ?>
- <li id="comment-<?php comment_ID(); ?>">
- <div class="comment-avatar-box">
- <div class="avb">
- <a href="<?php echo get_comment_author_url() ?>" rel="nofollow">
- <?php if ( $comment->user_id ) : ?>
- <?php echo bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'width' => 50, 'height' => 50, 'email' => $comment->comment_author_email ) ); ?>
- <?php else : ?>
- <?php echo get_avatar( $comment, 50 ) ?>
- <?php endif; ?>
- </a>
- </div>
- </div>
- <div class="comment-content">
- <div class="comment-meta">
- <a href="<?php echo get_comment_author_url() ?>" rel="nofollow"><?php echo get_comment_author(); ?></a> <?php _e( 'said:', 'buddypress' ) ?>
- <em><?php _e( 'On', 'buddypress' ) ?> <a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date() ?></a></em>
- </div>
- <?php if ( $comment->comment_approved == '0' ) : ?>
- <em class="moderate"><?php _e('Your comment is awaiting moderation.'); ?></em><br />
- <?php endif; ?>
- <?php comment_text() ?>
- <div class="comment-options">
- <?php echo comment_reply_link( array('depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ?>
- <?php edit_comment_link( __( 'Edit' ),'','' ); ?>
- </div>
- </div>
- <?php
- }
- /**
- * 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 );
- /**
- * Custom header image support. You can remove this entirely in a child theme by adding this line
- * to your functions.php: define( 'BP_DTHEME_DISABLE_CUSTOM_HEADER', true );
- *
- * @package BuddyPress Theme
- * @since 1.2
- */
- function bp_dtheme_add_custom_header_support() {
- // Set the defaults for the custom header image (http://ryan.boren.me/2007/01/07/custom-image-header-api/)
- define( 'HEADER_TEXTCOLOR', 'FFFFFF' );
- define( 'HEADER_IMAGE', '%s/_inc/images/default_header.jpg' ); // %s is theme dir uri
- define( 'HEADER_IMAGE_WIDTH', 1250 );
- define( 'HEADER_IMAGE_HEIGHT', 125 );
- function bp_dtheme_header_style() { ?>
- <style type="text/css">
- #header { background-image: url(<?php header_image() ?>); }
- <?php if ( 'blank' == get_header_textcolor() ) { ?>
- #header h1, #header #desc { display: none; }
- <?php } else { ?>
- #header h1 a, #desc { color:#<?php header_textcolor() ?>; }
- <?php } ?>
- </style>
- <?php
- }
- function bp_dtheme_admin_header_style() { ?>
- <style type="text/css">
- #headimg {
- position: relative;
- color: #fff;
- background: url(<?php header_image() ?>);
- -moz-border-radius-bottomleft: 6px;
- -webkit-border-bottom-left-radius: 6px;
- -moz-border-radius-bottomright: 6px;
- -webkit-border-bottom-right-radius: 6px;
- margin-bottom: 20px;
- height: 100px;
- padding-top: 25px;
- }
- #headimg h1{
- position: absolute;
- bottom: 15px;
- left: 15px;
- width: 44%;
- margin: 0;
- font-family: Arial, Tahoma, sans-serif;
- }
- #headimg h1 a{
- color:#<?php header_textcolor() ?>;
- text-decoration: none;
- border-bottom: none;
- }
- #headimg #desc{
- color:#<?php header_textcolor() ?>;
- font-size:1em;
- margin-top:-0.5em;
- }
- #desc {
- display: none;
- }
- <?php if ( 'blank' == get_header_textcolor() ) { ?>
- #headimg h1, #headimg #desc {
- display: none;
- }
- #headimg h1 a, #headimg #desc {
- color:#<?php echo HEADER_TEXTCOLOR ?>;
- }
- <?php } ?>
- </style>
- <?php
- }
- add_custom_image_header( 'bp_dtheme_header_style', 'bp_dtheme_admin_header_style' );
- }
- if ( !defined( 'BP_DTHEME_DISABLE_CUSTOM_HEADER' ) )
- add_action( 'init', 'bp_dtheme_add_custom_header_support' );
- /**
- * 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' );
- ?>
- <?php
- /* Add these code to your cunctions.php to allow Single Search page for all buddypress components*/
- // Remove Buddypress search drowpdown for selecting members etc
- add_filter("bp_search_form_type_select", "bpmag_remove_search_dropdown" );
- function bpmag_remove_search_dropdown($select_html){
- return '';
- }
- remove_action( 'init', 'bp_core_action_search_site', 5 );//force buddypress to not process the search/redirect
- add_action( 'init', 'bp_buddydev_search', 10 );// custom handler for the search
- function bp_buddydev_search(){
- global $bp;
- if ( $bp->current_component == BP_SEARCH_SLUG )//if thids is search page
- bp_core_load_template( apply_filters( 'bp_core_template_search_template', 'search-single' ) );//load the single searh template
- }
- add_action("advance-search","bpmag_show_search_results",1);//highest priority
- /* we just need to filter the query and change search_term=The search text*/
- function bpmag_show_search_results(){
- //filter the ajaxquerystring
- add_filter("bp_ajax_querystring","bpmag_global_search_qs",100,2);
- }
- //show the search results for member*/
- function bpmag_show_member_search(){
- ?>
- <div class="memberss-search-result search-result">
- <h2 class="content-title"><?php _e("Members Results","bpmag");?></h2>
- <?php locate_template( array( 'members/members-loop.php' ), true ) ; ?>
- <?php global $members_template;
- if($members_template->total_member_count>1):?>
- <a href="<?php echo bp_get_root_domain().'/'.BP_MEMBERS_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e(sprintf("View all %d matched Members",$members_template->total_member_count),"bpmag");?></a>
- <?php endif; ?>
- </div>
- <?php
- }
- //Hook Member results to search page
- add_action("advance-search","bpmag_show_member_search",10); //the priority defines where in page this result will show up(the order of member search in other searchs)
- function bpmag_show_groups_search(){
- ?>
- <div class="groups-search-result search-result">
- <h2 class="content-title"><?php _e("Group Search","bpmag");?></h2>
- <?php locate_template( array('groups/groups-loop.php' ), true ) ; ?>
- <a href="<?php echo bp_get_root_domain().'/'.BP_GROUPS_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Groups","bpmag");?></a>
- </div>
- <?php
- //endif;
- }
- //Hook Groups results to search page
- if(bp_is_active( 'groups' ))
- add_action("advance-search","bpmag_show_groups_search",50);
- /**
- *
- * Show blog posts in search
- */
- function bpmag_show_site_blog_search(){
- ?>
- <div class="blog-search-result search-result">
- <h2 class="content-title"><?php _e("Blog Search","bpmag");?></h2>
- <?php locate_template( array( 'search-loop.php' ), true ) ; ?>
- <a href="<?php echo bp_get_root_domain().'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Posts","bpmag");?></a>
- </div>
- <?php
- }
- //Hook Blog Post results to search page
- add_action("advance-search","bpmag_show_site_blog_search",50);
- //show forums search
- function bpmag_show_forums_search(){
- ?>
- <div class="forums-search-result search-result">
- <h2 class="content-title"><?php _e("Forums Search","bpmag");?></h2>
- <?php locate_template( array( 'forums/forums-loop.php' ), true ) ; ?>
- <a href="<?php echo bp_get_root_domain().'/'.BP_FORUMS_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched forum posts","bpmag");?></a>
- </div>
- <?php
- }
- //Hook Forums results to search page
- if ( bp_is_active( 'forums' ) && bp_is_active( 'groups' ) && ( function_exists( 'bp_forums_is_installed_correctly' ) ) && bp_forums_is_installed_correctly() )
- add_action("advance-search","bpmag_show_forums_search",20);
- //show blogs search result
- function bpmag_show_gallery_search(){
- ?>
- <div>
- <h2><?php _e("Gallery Search","bpmag");?></h2>
- <?php locate_template( array('gallery/gallery-loop.php' ), true ) ; ?>
- <a href="<?php echo bp_get_root_domain().'/'.BP_GALLERY_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Galleries","bpmag");?></a>
- </div>
- <?php
- //endif;
- }
- //Hook gallery results to search page
- add_action("advance-search","bpmag_show_gallery_search",12);
- function bpmag_show_blogs_search(){
- ?>
- <div class="blogs-search-result search-result">
- <h2 class="content-title"><?php _e("Blogs Search","bpmag");?></h2>
- <?php locate_template( array( 'blogs/blogs-loop.php' ), true ) ; ?>
- <a href="<?php echo bp_get_root_domain().'/'.BP_BLOGS_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Blogs","bpmag");?></a>
- </div>
- <?php
- }
- //Hook Blogs results to search page if blogs comonent is active
- if(bp_is_active( 'blogs' ))
- add_action("advance-search","bpmag_show_blogs_search",10);
- //modify the query string with the search term
- function bpmag_global_search_qs(){
- return "per_page=100&max=200&search_terms=".$_REQUEST['search-terms'];//change per_page and max
- }
- function bpmag_is_advance_search(){
- global $bp;
- if($bp->current_component == BP_SEARCH_SLUG)
- return true;
- return false;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement