<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][4764] trunk: Fixes sticky logic on group forum directories so that stickies always appear at the top of the order, without breaking pagination.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/4764">4764</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2011-07-21 14:14:16 +0000 (Thu, 21 Jul 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fixes sticky logic on group forum directories so that stickies always appear at the top of the order, without breaking pagination. Fixes <a href="http://buddypress.trac.wordpress.org/ticket/3059">#3059</a>. Props sushkov for the inital patch. Introduces bp_forums_enable_global_directory_stickies() to allow easy modification of the default global forum directory behavior, which is to show group stickies in their normal freshness-based position.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpforumsbpforumsfunctionsphp">trunk/bp-forums/bp-forums-functions.php</a></li>
<li><a href="#trunkbpforumsbpforumstemplatephp">trunk/bp-forums/bp-forums-template.php</a></li>
<li><a href="#trunkbpgroupsbpgroupsclassesphp">trunk/bp-groups/bp-groups-classes.php</a></li>
<li><a href="#trunkbpgroupsbpgroupsforumsphp">trunk/bp-groups/bp-groups-forums.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpforumsbpforumsfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-forums/bp-forums-functions.php (4763 => 4764)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-forums/bp-forums-functions.php        2011-07-21 10:30:56 UTC (rev 4763)
+++ trunk/bp-forums/bp-forums-functions.php        2011-07-21 14:14:16 UTC (rev 4764)
</span><span class="lines">@@ -80,6 +80,8 @@
</span><span class="cx">                 'user_id'       =&gt; false,
</span><span class="cx">                 'page'          =&gt; 1,
</span><span class="cx">                 'per_page'      =&gt; 15,
</span><ins>+                'offset'        =&gt; false,
+                'number'        =&gt; false,
</ins><span class="cx">                 'exclude'       =&gt; false,
</span><span class="cx">                 'show_stickies' =&gt; 'all',
</span><span class="cx">                 'filter'        =&gt; false // if $type = tag then filter is the tag name, otherwise it's terms to search on.
</span><span class="lines">@@ -91,7 +93,7 @@
</span><span class="cx">         if ( class_exists( 'BB_Query' ) ) {
</span><span class="cx">                 switch ( $type ) {
</span><span class="cx">                         case 'newest':
</span><del>-                                $query = new BB_Query( 'topic', array( 'forum_id' =&gt; $forum_id, 'topic_author_id' =&gt; $user_id, 'per_page' =&gt; $per_page, 'page' =&gt; $page, 'number' =&gt; $per_page, 'exclude' =&gt; $exclude, 'topic_title' =&gt; $filter, 'sticky' =&gt; $show_stickies ), 'get_latest_topics' );
</del><ins>+                                $query = new BB_Query( 'topic', array( 'forum_id' =&gt; $forum_id, 'topic_author_id' =&gt; $user_id, 'per_page' =&gt; $per_page, 'page' =&gt; $page, 'number' =&gt; $per_page, 'exclude' =&gt; $exclude, 'topic_title' =&gt; $filter, 'sticky' =&gt; $show_stickies, 'offset' =&gt; $offset, 'number' =&gt; $number ), 'get_latest_topics' );
</ins><span class="cx">                                 $topics =&amp; $query-&gt;results;
</span><span class="cx">                                 break;
</span><span class="cx"> 
</span><span class="lines">@@ -490,7 +492,7 @@
</span><span class="cx"> add_filter( 'user_has_cap', 'bp_forums_filter_caps' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Returs the parent forum id for the bbPress abstraction layer
</del><ins>+ * Returns the parent forum id for the bbPress abstraction layer
</ins><span class="cx">  *
</span><span class="cx">  * @package BuddyPress
</span><span class="cx">  * @since 1.3
</span><span class="lines">@@ -501,7 +503,23 @@
</span><span class="cx">         return apply_filters( 'bp_forums_parent_forum_id', BP_FORUMS_PARENT_FORUM_ID );
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**
+ * Should sticky topics be broken out of regular topic order on forum directories?
+ *
+ * Defaults to false. Define BP_FORUMS_ENABLE_GLOBAL_DIRECTORY_STICKIES, or filter
+ * bp_forums_enable_global_directory_stickies, to change this behavior.
+ *
+ * @package BuddyPress
+ * @since 1.3
+ *
+ * @return bool True if stickies should be displayed at the top of the global directory, false
+ *    otherwise.
+ */
+function bp_forums_enable_global_directory_stickies() {
+        return apply_filters( 'bp_forums_enable_global_directory_stickies', defined( 'BP_FORUMS_ENABLE_GLOBAL_DIRECTORY_STICKIES' ) &amp;&amp; BP_FORUMS_ENABLE_GLOBAL_DIRECTORY_STICKIES );
+}
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> /********************************************************************************
</span><span class="cx">  * Caching
</span><span class="cx">  *
</span></span></pre></div>
<a id="trunkbpforumsbpforumstemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-forums/bp-forums-template.php (4763 => 4764)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-forums/bp-forums-template.php        2011-07-21 10:30:56 UTC (rev 4763)
+++ trunk/bp-forums/bp-forums-template.php        2011-07-21 14:14:16 UTC (rev 4764)
</span><span class="lines">@@ -68,22 +68,24 @@
</span><span class="cx">         var $sort_by;
</span><span class="cx">         var $order;
</span><span class="cx"> 
</span><del>-        function BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms ) {
-                $this-&gt;__construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms );
</del><ins>+        function BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) {
+                $this-&gt;__construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset, $number );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function __construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms ) {        
</del><ins>+        function __construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) {        
</ins><span class="cx">                 global $bp;
</span><span class="cx"> 
</span><del>-                $this-&gt;pag_page     = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : $page;
-                $this-&gt;pag_num      = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page;
</del><ins>+                $this-&gt;pag_page     = $page;
+                $this-&gt;pag_num      = $per_page;
</ins><span class="cx">                 $this-&gt;type         = $type;
</span><span class="cx">                 $this-&gt;search_terms = $search_terms;
</span><span class="cx">                 $this-&gt;forum_id     = $forum_id;
</span><ins>+                $this-&gt;offset            = $offset;
+                $this-&gt;number            = $number;
</ins><span class="cx"> 
</span><span class="cx">                 switch ( $type ) {
</span><del>-                        case 'newest': default:
-                                $this-&gt;topics = bp_forums_get_forum_topics( array( 'user_id' =&gt; $user_id, 'forum_id' =&gt; $forum_id, 'filter' =&gt; $search_terms, 'page' =&gt; $this-&gt;pag_page, 'per_page' =&gt; $this-&gt;pag_num, 'show_stickies' =&gt; $no_stickies ) );
</del><ins>+                        case 'newest': default:                                
+                                $this-&gt;topics = bp_forums_get_forum_topics( array( 'user_id' =&gt; $user_id, 'forum_id' =&gt; $forum_id, 'filter' =&gt; $search_terms, 'page' =&gt; $this-&gt;pag_page, 'per_page' =&gt; $this-&gt;pag_num, 'show_stickies' =&gt; $no_stickies, 'offset' =&gt; $offset, 'number' =&gt; $number ) );
</ins><span class="cx">                                 break;
</span><span class="cx"> 
</span><span class="cx">                         case 'popular':
</span><span class="lines">@@ -111,7 +113,9 @@
</span><span class="cx">                         } else if ( !empty( $bp-&gt;groups-&gt;current_group ) ) {
</span><span class="cx">                                 $topic_count = (int)groups_total_public_forum_topic_count( $type );
</span><span class="cx">                         } else {
</span><del>-                                $topic_count = count( $this-&gt;topics );
</del><ins>+                                // For forum directories, get a true count
+                                $status = is_super_admin() ? 'all' : 'public'; // todo: member-of
+                                $topic_count = (int)groups_total_forum_topic_count( $status );
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         if ( !$max || $max &gt;= $topic_count ) {
</span><span class="lines">@@ -119,7 +123,7 @@
</span><span class="cx">                         } else {
</span><span class="cx">                                 $this-&gt;total_topic_count = (int)$max;
</span><span class="cx">                         }
</span><del>-
</del><ins>+                        
</ins><span class="cx">                         if ( $max ) {
</span><span class="cx">                                 if ( $max &gt;= count($this-&gt;topics) ) {
</span><span class="cx">                                         $this-&gt;topic_count = count( $this-&gt;topics );
</span><span class="lines">@@ -134,22 +138,6 @@
</span><span class="cx">                 $this-&gt;topic_count       = apply_filters_ref_array( 'bp_forums_template_topic_count',                                 array( $this-&gt;topic_count, &amp;$this-&gt;topics, $type, $forum_id, $per_page, $max, $no_stickies ) );
</span><span class="cx">                 $this-&gt;total_topic_count = apply_filters_ref_array( 'bp_forums_template_total_topic_count', array( $this-&gt;total_topic_count, $this-&gt;topic_count, &amp;$this-&gt;topics, $type, $forum_id, $per_page, $max, $no_stickies ) );
</span><span class="cx"> 
</span><del>-                if ( !$no_stickies ) {
-                        $stickies = array();
-                        $standard = array();
-
-                        // Place stickies at the top - not sure why bbPress doesn't do this?
-                        foreach( (array)$this-&gt;topics as $topic ) {
-                                if ( isset( $topic-&gt;topic_sticky ) &amp;&amp; 1 == (int)$topic-&gt;topic_sticky ) {
-                                        $stickies[] = $topic;
-                                } else {
-                                        $standard[] = $topic;
-                                }
-                        }
-
-                        $this-&gt;topics = array_merge( (array)$stickies, (array)$standard );
-                }
-
</del><span class="cx">                 // Fetch extra information for topics, so we don't have to query inside the loop
</span><span class="cx">                 $this-&gt;topics = bp_forums_get_topic_extras( $this-&gt;topics );
</span><span class="cx"> 
</span><span class="lines">@@ -212,6 +200,20 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**
+ * Initiate the forum topics loop.
+ *
+ * Like other BuddyPress custom loops, the default arguments for this function are determined
+ * dynamically, depending on your current page. All of these $defaults can be overridden in the
+ * $args parameter.
+ *
+ * @package BuddyPress
+ * @uses apply_filters() Filter bp_has_topics to manipulate the $forums_template global before
+ *   it's rendered, or to modify the value of has_topics().
+ *
+ * @param array $args See inline definition of $defaults for explanation of arguments
+ * @return bool Returns true when forum topics are found corresponding to the args, false otherwise.
+ */
</ins><span class="cx"> function bp_has_forum_topics( $args = '' ) {
</span><span class="cx">         global $forum_template, $bp;
</span><span class="cx"> 
</span><span class="lines">@@ -224,7 +226,7 @@
</span><span class="cx">         $user_id      = 0;
</span><span class="cx">         $forum_id     = false;
</span><span class="cx">         $search_terms = false;
</span><del>-        $no_stickies  = 'all';
</del><ins>+        $do_stickies  = true;
</ins><span class="cx"> 
</span><span class="cx">         // User filtering
</span><span class="cx">         if ( !empty( $bp-&gt;displayed_user-&gt;id ) )
</span><span class="lines">@@ -254,20 +256,26 @@
</span><span class="cx">         // If $_GET['fs'] is set, let's auto populate the search_terms var
</span><span class="cx">         if ( bp_is_directory() &amp;&amp; !empty( $_GET['fs'] ) )
</span><span class="cx">                 $search_terms = $_GET['fs'];
</span><ins>+        
+        // Get the pagination arguments from $_REQUEST
+        $page     = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : 1;
+        $per_page = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : 20;
+        
+        // Unless set otherwise, stickies appear in normal order on the global forum directory
+        if ( bp_is_directory() &amp;&amp; bp_is_forums_component() &amp;&amp; !bp_forums_enable_global_directory_stickies() )
+                $do_stickies = false;
</ins><span class="cx"> 
</span><del>-        // Show stickies on a group forum
-        if ( isset( $bp-&gt;groups-&gt;current_group ) )
-                $no_stickies = null;
-
</del><span class="cx">         $defaults = array(
</span><span class="cx">                 'type'         =&gt; $type,
</span><span class="cx">                 'forum_id'     =&gt; $forum_id,
</span><span class="cx">                 'user_id'      =&gt; $user_id,
</span><del>-                'page'         =&gt; 1,
-                'per_page'     =&gt; 20,
</del><ins>+                'page'         =&gt; $page,
+                'per_page'     =&gt; $per_page,
</ins><span class="cx">                 'max'          =&gt; false,
</span><del>-                'no_stickies'  =&gt; $no_stickies,
-                'search_terms' =&gt; $search_terms
</del><ins>+                'number'       =&gt; false,
+                'offset'       =&gt; false,
+                'search_terms' =&gt; $search_terms,
+                'do_stickies'  =&gt; $do_stickies
</ins><span class="cx">         );
</span><span class="cx"> 
</span><span class="cx">         $r = wp_parse_args( $args, $defaults );
</span><span class="lines">@@ -279,8 +287,97 @@
</span><span class="cx">                 $search_terms = $bp-&gt;action_variables[0];
</span><span class="cx">                 $type = 'tags';
</span><span class="cx">         }
</span><del>-
-        $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms );
</del><ins>+        
+        /** Sticky logic ******************************************************************/
+        
+        if ( $do_stickies ) {
+                // Fetch the stickies
+                $stickies_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, 0, 0, $max, 'sticky', $search_terms );
+                
+                // If stickies are found, try merging them
+                if ( $stickies_template-&gt;has_topics() ) {
+                
+                        // If stickies are for current $page                
+                        $page_start_num = ( ( $page - 1 ) * $per_page ) + 1;
+                        $page_end_num         = $page * $per_page &lt;= $stickies_template-&gt;total_topic_count ? $page * $per_page : $stickies_template-&gt;total_topic_count;
+                        
+                        // Calculate the number of sticky topics that will be shown on this page
+                        if ( $stickies_template-&gt;topic_count &lt; $page_start_num ) {
+                                $this_page_stickies = 0;
+                        } else {                        
+                                $this_page_stickies = $stickies_template-&gt;topic_count - $per_page * floor( $stickies_template-&gt;topic_count / $per_page ) * ( $page - 1 ); // Total stickies minus sticky count through this page
+                                
+                                // $this_page_stickies cannot be more than $per_page or less than 0
+                                if ( $this_page_stickies &gt; $per_page )
+                                        $this_page_stickies = $per_page;
+                                else if ( $this_page_stickies &lt; 0 )
+                                        $this_page_stickies = 0;
+                        }
+                        
+                        // Calculate the total number of topics that will be shown on this page
+                        $this_page_topics = $stickies_template-&gt;total_topic_count &gt;= ( $page * $per_page ) ? $per_page : $page_end_num - ( $page_start_num - 1 );
+                        
+                        // If the number of stickies to be shown is less than $per_page, fetch some
+                        // non-stickies to fill in the rest
+                        if ( $this_page_stickies &lt; $this_page_topics ) {
+                                // How many non-stickies do we need?
+                                $non_sticky_number = $this_page_topics - $this_page_stickies;
+                                
+                                // Calculate the non-sticky offset                        
+                                // How many non-stickies on all pages up to this point?
+                                $non_sticky_total = $page_end_num - $stickies_template-&gt;topic_count;
+                                
+                                // The offset is the number of total non-stickies, less the number
+                                // to be shown on this page
+                                $non_sticky_offset = $non_sticky_total - $non_sticky_number;
+                                
+                                // Fetch the non-stickies
+                                $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, 1, $per_page, $max, 'no', $search_terms, $non_sticky_offset, $non_sticky_number );
+                                
+                                // If there are stickies to merge on this page, do it now
+                                if ( $this_page_stickies ) {
+                                        // Correct the topic_count
+                                        $forum_template-&gt;topic_count += (int)$this_page_stickies;
+                                        
+                                        // Figure out which stickies need to be included
+                                        $this_page_sticky_topics = array_slice( $stickies_template-&gt;topics, 0 - $this_page_stickies );
+                                        
+                                        // Merge these topics into the forum template
+                                        $forum_template-&gt;topics = array_merge( $this_page_sticky_topics, (array)$forum_template-&gt;topics );
+                                }
+                        } else {
+                                // This page has no non-stickies
+                                $forum_template = $stickies_template;
+                                
+                                // Adjust the topic count and trim the topics
+                                $forum_template-&gt;topic_count = $this_page_stickies;
+                                $forum_template-&gt;topics      = array_slice( $forum_template-&gt;topics, $page - 1 );        
+                        }
+                                        
+                        // Because we're using a manual offset and number for the topic query, we
+                        // must set the page number manually, and recalculate the pagination links
+                        $forum_template-&gt;pag_num     = $per_page;
+                        $forum_template-&gt;pag_page    = $page;
+                        
+                        $forum_template-&gt;pag_links = paginate_links( array(
+                                'base'      =&gt; add_query_arg( array( 'p' =&gt; '%#%', 'n' =&gt; $forum_template-&gt;pag_num ) ),
+                                'format'    =&gt; '',
+                                'total'     =&gt; ceil( (int)$forum_template-&gt;total_topic_count / (int)$forum_template-&gt;pag_num ),
+                                'current'   =&gt; $forum_template-&gt;pag_page,
+                                'prev_text' =&gt; '&amp;larr;',
+                                'next_text' =&gt; '&amp;rarr;',
+                                'mid_size'  =&gt; 1
+                        ) );
+                        
+                } else {
+                        // Fetch the non-sticky topics if no stickies were found
+                        $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, 'all', $search_terms );
+                }
+        } else {
+                // When skipping the sticky logic, just pull up the forum topics like usual
+                $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, 'all', $search_terms );
+        }
+                
</ins><span class="cx">         return apply_filters( 'bp_has_topics', $forum_template-&gt;has_topics(), $forum_template );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1283,4 +1380,4 @@
</span><span class="cx">         function bp_get_forum_topic_count( $user_id = 0 ) {
</span><span class="cx">                 return apply_filters( 'bp_get_forum_topic_count', bp_forums_total_topic_count( $user_id ) );
</span><span class="cx">         }
</span><del>-?&gt;
</del><span class="cx">\ No newline at end of file
</span><ins>+?&gt;
</ins></span></pre></div>
<a id="trunkbpgroupsbpgroupsclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-classes.php (4763 => 4764)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-classes.php        2011-07-21 10:30:56 UTC (rev 4763)
+++ trunk/bp-groups/bp-groups-classes.php        2011-07-21 14:14:16 UTC (rev 4764)
</span><span class="lines">@@ -595,6 +595,41 @@
</span><span class="cx"> 
</span><span class="cx">                 return $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT COUNT(id) FROM {$bp-&gt;groups-&gt;table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0&quot;, $group_id ) );
</span><span class="cx">         }
</span><ins>+        
+        
+        /**
+         * Get a total count of all topics of a given status, across groups/forums
+         *
+         * @package BuddyPress
+         * @since 1.3
+         *
+         * @param str $status 'public', 'private', 'hidden', 'all' Which group types to count
+         * @return int The topic count
+         */
+        function get_global_topic_count( $status = 'public' ) {
+                global $bbdb, $wpdb, $bp;
+                
+                switch ( $status ) {
+                        case 'all' :
+                                $status_sql = '';
+                                break;
+                                
+                        case 'hidden' :
+                                $status_sql = $wpdb-&gt;prepare( &quot;AND g.status = 'hidden'&quot; );
+                                break;
+                                
+                        case 'private' :
+                                $status_sql = $wpdb-&gt;prepare( &quot;AND g.status = 'private'&quot; );
+                                break;
+                                
+                        case 'public' :
+                        default :
+                                $status_sql = $wpdb-&gt;prepare( &quot;AND g.status = 'public'&quot; );
+                                break;
+                }
+                
+                return $wpdb-&gt;get_var( &quot;SELECT COUNT(t.topic_id) FROM {$bbdb-&gt;topics} AS t INNER JOIN {$bp-&gt;groups-&gt;table_name_groupmeta} AS gm ON t.forum_id = gm.meta_value INNER JOIN {$bp-&gt;groups-&gt;table_name} AS g ON gm.group_id = g.id WHERE gm.meta_key = 'forum_id' {$status_sql} AND t.topic_status = '0' AND t.topic_sticky != '2' &quot; );
+        }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Class BP_Groups_Member {
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupsforumsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-forums.php (4763 => 4764)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-forums.php        2011-07-21 10:30:56 UTC (rev 4763)
+++ trunk/bp-groups/bp-groups-forums.php        2011-07-21 14:14:16 UTC (rev 4764)
</span><span class="lines">@@ -244,9 +244,21 @@
</span><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> function groups_total_public_forum_topic_count( $type = 'newest' ) {
</span><span class="cx">         return apply_filters( 'groups_total_public_forum_topic_count', BP_Groups_Group::get_global_forum_topic_count( $type ) );
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**
+ * Get a total count of all topics of a given status, across groups/forums
+ *
+ * @package BuddyPress
+ * @since 1.3
+ *
+ * @param str $status 'public', 'private', 'hidden', 'all' Which group types to count
+ * @return int The topic count
+ */
+function groups_total_forum_topic_count( $status = 'public' ) {
+        return apply_filters( 'groups_total_forum_topic_count', BP_Groups_Group::get_global_topic_count( $status ) );
+}
+
</ins><span class="cx"> ?&gt;
</span></span></pre>
</div>
</div>

</body>
</html>