Advertisement
xcelguy

functions.php

May 11th, 2011
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.05 KB | None | 0 0
  1. <?php
  2.  
  3. add_theme_support( 'post-thumbnails', array( 'post' ) ); // Add it for posts
  4. add_theme_support( 'post-thumbnails', array( 'page' ) ); // Add it for pages
  5. set_post_thumbnail_size( 50, 50, true ); // 50 pixels wide by 50 pixels tall, hard crop mode
  6.  
  7. // Stop the theme from killing WordPress if BuddyPress is not enabled.
  8. if ( !class_exists( 'BP_Core_User' ) )
  9.     return false;
  10.  
  11. // Register the widget columns
  12. register_sidebars( 1,
  13.     array(
  14.         'name'          => 'Sidebar',
  15.         'before_widget' => '<div id="%1$s" class="widget %2$s">',
  16.         'after_widget'  => '</div>',
  17.         'before_title'  => '<h3 class="widgettitle">',
  18.         'after_title'   => '</h3>'
  19.     )
  20. );
  21.  
  22. // Load the AJAX functions for the theme
  23. require_once( TEMPLATEPATH . '/_inc/ajax.php' );
  24.  
  25. // Load the javascript for the theme
  26. wp_enqueue_script( 'dtheme-ajax-js', get_template_directory_uri() . '/_inc/global.js', array( 'jquery' ) );
  27.  
  28. // Add words that we need to use in JS to the end of the page so they can be translated and still used.
  29. $params = array(
  30.     'my_favs'           => __( 'My Favorites', 'buddypress' ),
  31.     'accepted'          => __( 'Accepted', 'buddypress' ),
  32.     'rejected'          => __( 'Rejected', 'buddypress' ),
  33.     'show_all_comments' => __( 'Show all comments for this thread', 'buddypress' ),
  34.     'show_all'          => __( 'Show all', 'buddypress' ),
  35.     'comments'          => __( 'comments', 'buddypress' ),
  36.     'close'             => __( 'Close', 'buddypress' ),
  37.     '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() ) )
  38. );
  39. wp_localize_script( 'dtheme-ajax-js', 'BP_DTheme', $params );
  40.  
  41. /**
  42.  * Add the JS needed for blog comment replies
  43.  *
  44.  * @package BuddyPress Theme
  45.  * @since 1.2
  46.  */
  47. function bp_dtheme_add_blog_comments_js() {
  48.     if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
  49. }
  50. add_action( 'template_redirect', 'bp_dtheme_add_blog_comments_js' );
  51.  
  52. /**
  53.  * HTML for outputting blog comments as defined by the WP comment API
  54.  *
  55.  * @param mixed $comment Comment record from database
  56.  * @param array $args Arguments from wp_list_comments() call
  57.  * @param int $depth Comment nesting level
  58.  * @see wp_list_comments()
  59.  * @package BuddyPress Theme
  60.  * @since 1.2
  61.  */
  62. function bp_dtheme_blog_comments( $comment, $args, $depth ) {
  63.     $GLOBALS['comment'] = $comment; ?>
  64.  
  65.     <?php if ( 'pingback' == $comment->comment_type ) return false; ?>
  66.  
  67.     <li id="comment-<?php comment_ID(); ?>">
  68.         <div class="comment-avatar-box">
  69.             <div class="avb">
  70.                 <a href="<?php echo get_comment_author_url() ?>" rel="nofollow">
  71.                     <?php if ( $comment->user_id ) : ?>
  72.                         <?php echo bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'width' => 50, 'height' => 50, 'email' => $comment->comment_author_email ) ); ?>
  73.                     <?php else : ?>
  74.                         <?php echo get_avatar( $comment, 50 ) ?>
  75.                     <?php endif; ?>
  76.                 </a>
  77.             </div>
  78.         </div>
  79.  
  80.         <div class="comment-content">
  81.  
  82.             <div class="comment-meta">
  83.                 <a href="<?php echo get_comment_author_url() ?>" rel="nofollow"><?php echo get_comment_author(); ?></a> <?php _e( 'said:', 'buddypress' ) ?>
  84.                 <em><?php _e( 'On', 'buddypress' ) ?> <a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date() ?></a></em>
  85.             </div>
  86.  
  87.             <?php if ( $comment->comment_approved == '0' ) : ?>
  88.                 <em class="moderate"><?php _e('Your comment is awaiting moderation.'); ?></em><br />
  89.             <?php endif; ?>
  90.  
  91.             <?php comment_text() ?>
  92.  
  93.             <div class="comment-options">
  94.                 <?php echo comment_reply_link( array('depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ?>
  95.                 <?php edit_comment_link( __( 'Edit' ),'','' ); ?>
  96.             </div>
  97.  
  98.         </div>
  99. <?php
  100. }
  101.  
  102. /**
  103.  * Filter the dropdown for selecting the page to show on front to include "Activity Stream"
  104.  *
  105.  * @param string $page_html A list of pages as a dropdown (select list)
  106.  * @see wp_dropdown_pages()
  107.  * @return string
  108.  * @package BuddyPress Theme
  109.  * @since 1.2
  110.  */
  111. function bp_dtheme_wp_pages_filter( $page_html ) {
  112.     if ( !bp_is_active( 'activity' ) )
  113.         return $page_html;
  114.  
  115.     if ( 'page_on_front' != substr( $page_html, 14, 13 ) )
  116.         return $page_html;
  117.  
  118.     $selected = false;
  119.     $page_html = str_replace( '</select>', '', $page_html );
  120.  
  121.     if ( bp_dtheme_page_on_front() == 'activity' )
  122.         $selected = ' selected="selected"';
  123.  
  124.     $page_html .= '<option class="level-0" value="activity"' . $selected . '>' . __( 'Activity Stream', 'buddypress' ) . '</option></select>';
  125.     return $page_html;
  126. }
  127. add_filter( 'wp_dropdown_pages', 'bp_dtheme_wp_pages_filter' );
  128.  
  129. /**
  130.  * Hijack the saving of page on front setting to save the activity stream setting
  131.  *
  132.  * @param $string $oldvalue Previous value of get_option( 'page_on_front' )
  133.  * @param $string $oldvalue New value of get_option( 'page_on_front' )
  134.  * @return string
  135.  * @package BuddyPress Theme
  136.  * @since 1.2
  137.  */
  138. function bp_dtheme_page_on_front_update( $oldvalue, $newvalue ) {
  139.     if ( !is_admin() || !is_super_admin() )
  140.         return false;
  141.  
  142.     if ( 'activity' == $_POST['page_on_front'] )
  143.         return 'activity';
  144.     else
  145.         return $oldvalue;
  146. }
  147. add_action( 'pre_update_option_page_on_front', 'bp_dtheme_page_on_front_update', 10, 2 );
  148.  
  149. /**
  150.  * Load the activity stream template if settings allow
  151.  *
  152.  * @param string $template Absolute path to the page template
  153.  * @return string
  154.  * @global WP_Query $wp_query WordPress query object
  155.  * @package BuddyPress Theme
  156.  * @since 1.2
  157.  */
  158. function bp_dtheme_page_on_front_template( $template ) {
  159.     global $wp_query;
  160.  
  161.     if ( empty( $wp_query->post->ID ) )
  162.         return locate_template( array( 'activity/index.php' ), false );
  163.     else
  164.         return $template;
  165. }
  166. add_filter( 'page_template', 'bp_dtheme_page_on_front_template' );
  167.  
  168. /**
  169.  * Return the ID of a page set as the home page.
  170.  *
  171.  * @return false|int ID of page set as the home page
  172.  * @package BuddyPress Theme
  173.  * @since 1.2
  174.  */
  175. function bp_dtheme_page_on_front() {
  176.     if ( 'page' != get_option( 'show_on_front' ) )
  177.         return false;
  178.  
  179.     return apply_filters( 'bp_dtheme_page_on_front', get_option( 'page_on_front' ) );
  180. }
  181.  
  182. /**
  183.  * Force the page ID as a string to stop the get_posts query from kicking up a fuss.
  184.  *
  185.  * @global WP_Query $wp_query WordPress query object
  186.  * @package BuddyPress Theme
  187.  * @since 1.2
  188.  */
  189. function bp_dtheme_fix_get_posts_on_activity_front() {
  190.     global $wp_query;
  191.  
  192.     if ( !empty($wp_query->query_vars['page_id']) && 'activity' == $wp_query->query_vars['page_id'] )
  193.         $wp_query->query_vars['page_id'] = '"activity"';
  194. }
  195. add_action( 'pre_get_posts', 'bp_dtheme_fix_get_posts_on_activity_front' );
  196.  
  197. /**
  198.  * WP 3.0 requires there to be a non-null post in the posts array
  199.  *
  200.  * @param array $posts Posts as retrieved by WP_Query
  201.  * @global WP_Query $wp_query WordPress query object
  202.  * @return array
  203.  * @package BuddyPress Theme
  204.  * @since 1.2.5
  205.  */
  206. function bp_dtheme_fix_the_posts_on_activity_front( $posts ) {
  207.     global $wp_query;
  208.  
  209.     // NOTE: the double quotes around '"activity"' are thanks to our previous function bp_dtheme_fix_get_posts_on_activity_front()
  210.     if ( empty( $posts ) && !empty( $wp_query->query_vars['page_id'] ) && '"activity"' == $wp_query->query_vars['page_id'] )
  211.         $posts = array( (object) array( 'ID' => 'activity' ) );
  212.  
  213.     return $posts;
  214. }
  215. add_filter( 'the_posts', 'bp_dtheme_fix_the_posts_on_activity_front' );
  216.  
  217. /**
  218.  * bp_dtheme_activity_secondary_avatars()
  219.  *
  220.  * Add secondary avatar image to this activity stream's record, if supported
  221.  *
  222.  * @param string $action The text of this activity
  223.  * @param BP_Activity_Activity $activity Activity object
  224.  * @return string
  225.  * @package BuddyPress Theme
  226.  * @since 1.2.6
  227.  */
  228. function bp_dtheme_activity_secondary_avatars( $action, $activity ) {
  229.     switch ( $activity->component ) {
  230.         case 'groups' :
  231.         case 'friends' :
  232.             // Only insert avatar if one exists
  233.             if ( $secondary_avatar = bp_get_activity_secondary_avatar() ) {
  234.                 $reverse_content = strrev( $action );
  235.                 $position        = strpos( $reverse_content, 'a<' );
  236.                 $action          = substr_replace( $action, $secondary_avatar, -$position - 2, 0 );
  237.             }
  238.             break;
  239.     }
  240.  
  241.     return $action;
  242. }
  243. add_filter( 'bp_get_activity_action_pre_meta', 'bp_dtheme_activity_secondary_avatars', 10, 2 );
  244.  
  245. /**
  246.  * Custom header image support. You can remove this entirely in a child theme by adding this line
  247.  * to your functions.php: define( 'BP_DTHEME_DISABLE_CUSTOM_HEADER', true );
  248.  *
  249.  * @package BuddyPress Theme
  250.  * @since 1.2
  251.  */
  252. function bp_dtheme_add_custom_header_support() {
  253.     // Set the defaults for the custom header image (http://ryan.boren.me/2007/01/07/custom-image-header-api/)
  254.     define( 'HEADER_TEXTCOLOR', 'FFFFFF' );
  255.     define( 'HEADER_IMAGE', '%s/_inc/images/default_header.jpg' ); // %s is theme dir uri
  256.     define( 'HEADER_IMAGE_WIDTH', 1250 );
  257.     define( 'HEADER_IMAGE_HEIGHT', 125 );
  258.  
  259.     function bp_dtheme_header_style() { ?>
  260.         <style type="text/css">
  261.             #header { background-image: url(<?php header_image() ?>); }
  262.             <?php if ( 'blank' == get_header_textcolor() ) { ?>
  263.             #header h1, #header #desc { display: none; }
  264.             <?php } else { ?>
  265.             #header h1 a, #desc { color:#<?php header_textcolor() ?>; }
  266.             <?php } ?>
  267.         </style>
  268.     <?php
  269.     }
  270.  
  271.     function bp_dtheme_admin_header_style() { ?>
  272.         <style type="text/css">
  273.             #headimg {
  274.                 position: relative;
  275.                 color: #fff;
  276.                 background: url(<?php header_image() ?>);
  277.                 -moz-border-radius-bottomleft: 6px;
  278.                 -webkit-border-bottom-left-radius: 6px;
  279.                 -moz-border-radius-bottomright: 6px;
  280.                 -webkit-border-bottom-right-radius: 6px;
  281.                 margin-bottom: 20px;
  282.                 height: 100px;
  283.                 padding-top: 25px;
  284.             }
  285.  
  286.             #headimg h1{
  287.                 position: absolute;
  288.                 bottom: 15px;
  289.                 left: 15px;
  290.                 width: 44%;
  291.                 margin: 0;
  292.                 font-family: Arial, Tahoma, sans-serif;
  293.             }
  294.             #headimg h1 a{
  295.                 color:#<?php header_textcolor() ?>;
  296.                 text-decoration: none;
  297.                 border-bottom: none;
  298.             }
  299.             #headimg #desc{
  300.                 color:#<?php header_textcolor() ?>;
  301.                 font-size:1em;
  302.                 margin-top:-0.5em;
  303.             }
  304.  
  305.             #desc {
  306.                 display: none;
  307.             }
  308.  
  309.             <?php if ( 'blank' == get_header_textcolor() ) { ?>
  310.             #headimg h1, #headimg #desc {
  311.                 display: none;
  312.             }
  313.             #headimg h1 a, #headimg #desc {
  314.                 color:#<?php echo HEADER_TEXTCOLOR ?>;
  315.             }
  316.             <?php } ?>
  317.         </style>
  318.     <?php
  319.     }
  320.     add_custom_image_header( 'bp_dtheme_header_style', 'bp_dtheme_admin_header_style' );
  321. }
  322. if ( !defined( 'BP_DTHEME_DISABLE_CUSTOM_HEADER' ) )
  323.     add_action( 'init', 'bp_dtheme_add_custom_header_support' );
  324.  
  325. /**
  326.  * Show a notice when the theme is activated - workaround by Ozh (http://old.nabble.com/Activation-hook-exist-for-themes--td25211004.html)
  327.  *
  328.  * @package BuddyPress Theme
  329.  * @since 1.2
  330.  */
  331. function bp_dtheme_show_notice() { ?>
  332.     <div id="message" class="updated fade">
  333.         <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>
  334.     </div>
  335.  
  336.     <style type="text/css">#message2, #message0 { display: none; }</style>
  337.     <?php
  338. }
  339. if ( is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" )
  340.     add_action( 'admin_notices', 'bp_dtheme_show_notice' );
  341.  
  342.  
  343. // Member Buttons
  344. if ( bp_is_active( 'friends' ) )
  345.     add_action( 'bp_member_header_actions',    'bp_add_friend_button' );
  346.  
  347. if ( bp_is_active( 'activity' ) )
  348.     add_action( 'bp_member_header_actions',    'bp_send_public_message_button' );
  349.  
  350. if ( bp_is_active( 'messages' ) )
  351.     add_action( 'bp_member_header_actions',    'bp_send_private_message_button' );
  352.  
  353. // Group Buttons
  354. if ( bp_is_active( 'groups' ) ) {
  355.     add_action( 'bp_group_header_actions',     'bp_group_join_button' );
  356.     add_action( 'bp_group_header_actions',     'bp_group_new_topic_button' );
  357.     add_action( 'bp_directory_groups_actions', 'bp_group_join_button' );
  358. }
  359.  
  360. // Blog Buttons
  361. if ( bp_is_active( 'blogs' ) )
  362.     add_action( 'bp_directory_blogs_actions',  'bp_blogs_visit_blog_button' );
  363.  
  364. ?>
  365. <?php
  366. /* Add these code to your cunctions.php to allow Single Search page for all buddypress components*/
  367. //  Remove Buddypress search drowpdown for selecting members etc
  368. add_filter("bp_search_form_type_select", "bpmag_remove_search_dropdown"  );
  369. function bpmag_remove_search_dropdown($select_html){
  370.     return '';
  371. }
  372.  
  373. remove_action( 'init', 'bp_core_action_search_site', 5 );//force buddypress to not process the search/redirect
  374. add_action( 'init', 'bp_buddydev_search', 10 );// custom handler for the search
  375.  
  376. function bp_buddydev_search(){
  377. global $bp;
  378.     if ( $bp->current_component == BP_SEARCH_SLUG )//if thids is search page
  379.         bp_core_load_template( apply_filters( 'bp_core_template_search_template', 'search-single' ) );//load the single searh template
  380. }
  381. add_action("advance-search","bpmag_show_search_results",1);//highest priority
  382.  
  383. /* we just need to filter the query and change search_term=The search text*/
  384. function bpmag_show_search_results(){
  385.     //filter the ajaxquerystring
  386.      add_filter("bp_ajax_querystring","bpmag_global_search_qs",100,2);
  387. }
  388.  
  389. //show the search results for member*/
  390. function bpmag_show_member_search(){
  391.     ?>
  392.    <div class="memberss-search-result search-result">
  393.    <h2 class="content-title"><?php _e("Members Results","bpmag");?></h2>
  394.   <?php locate_template( array( 'members/members-loop.php' ), true ) ;  ?>
  395.   <?php global $members_template;
  396.     if($members_template->total_member_count>1):?>
  397.         <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>
  398.     <?php   endif; ?>
  399. </div>
  400. <?php  
  401.  }
  402.  
  403. //Hook Member results to search page
  404. 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)
  405. function bpmag_show_groups_search(){
  406.     ?>
  407. <div class="groups-search-result search-result">
  408.     <h2 class="content-title"><?php _e("Group Search","bpmag");?></h2>
  409.     <?php locate_template( array('groups/groups-loop.php' ), true ) ;  ?>
  410.    
  411.     <a href="<?php echo bp_get_root_domain().'/'.BP_GROUPS_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Groups","bpmag");?></a>
  412. </div>
  413.     <?php
  414.  //endif;
  415.   }
  416.  
  417. //Hook Groups results to search page
  418.  if(bp_is_active( 'groups' ))
  419.     add_action("advance-search","bpmag_show_groups_search",50);
  420.  
  421. /**
  422.  *
  423.  * Show blog posts in search
  424.  */
  425. function bpmag_show_site_blog_search(){
  426.     ?>
  427.  <div class="blog-search-result search-result">
  428.  
  429.   <h2 class="content-title"><?php _e("Blog Search","bpmag");?></h2>
  430.    
  431.    <?php locate_template( array( 'search-loop.php' ), true ) ;  ?>
  432.    <a href="<?php echo bp_get_root_domain().'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Posts","bpmag");?></a>
  433. </div>
  434.    <?php
  435.   }
  436.  
  437. //Hook Blog Post results to search page
  438.  add_action("advance-search","bpmag_show_site_blog_search",50);
  439.  
  440. //show forums search
  441. function bpmag_show_forums_search(){
  442.     ?>
  443.  <div class="forums-search-result search-result">
  444.    <h2 class="content-title"><?php _e("Forums Search","bpmag");?></h2>
  445.   <?php locate_template( array( 'forums/forums-loop.php' ), true ) ;  ?>
  446.   <a href="<?php echo bp_get_root_domain().'/'.BP_FORUMS_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched forum posts","bpmag");?></a>
  447. </div>
  448.   <?php
  449.   }
  450.  
  451. //Hook Forums results to search page
  452. if ( bp_is_active( 'forums' ) && bp_is_active( 'groups' ) && ( function_exists( 'bp_forums_is_installed_correctly' )  ) && bp_forums_is_installed_correctly() )
  453.  add_action("advance-search","bpmag_show_forums_search",20);
  454.  
  455.  
  456. //show blogs search result
  457.  
  458. function bpmag_show_gallery_search(){
  459. ?>
  460. <div>
  461. <h2><?php _e("Gallery Search","bpmag");?></h2>
  462. <?php locate_template( array('gallery/gallery-loop.php' ), true ) ;  ?>
  463.  
  464. <a href="<?php echo bp_get_root_domain().'/'.BP_GALLERY_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Galleries","bpmag");?></a>
  465. </div>
  466. <?php
  467. //endif;
  468. }
  469.  
  470. //Hook gallery results to search page
  471.  
  472. add_action("advance-search","bpmag_show_gallery_search",12);
  473.  
  474. function bpmag_show_blogs_search(){
  475.  
  476.     ?>
  477.   <div class="blogs-search-result search-result">
  478.   <h2 class="content-title"><?php _e("Blogs Search","bpmag");?></h2>
  479.   <?php locate_template( array( 'blogs/blogs-loop.php' ), true ) ;  ?>
  480.   <a href="<?php echo bp_get_root_domain().'/'.BP_BLOGS_SLUG.'/?s='.$_REQUEST['search-terms']?>" ><?php _e("View All matched Blogs","bpmag");?></a>
  481.  </div>
  482.   <?php
  483.   }
  484.  
  485. //Hook Blogs results to search page if blogs comonent is active
  486.  if(bp_is_active( 'blogs' ))
  487.     add_action("advance-search","bpmag_show_blogs_search",10);
  488.  
  489.  
  490.  //modify the query string with the search term
  491.  
  492. function bpmag_global_search_qs(){
  493.     return "per_page=100&max=200&search_terms=".$_REQUEST['search-terms'];//change per_page and max
  494. }
  495.  
  496.  
  497.  
  498. function bpmag_is_advance_search(){
  499. global $bp;
  500. if($bp->current_component == BP_SEARCH_SLUG)
  501.     return true;
  502. return false;
  503. }
  504. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement