<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[BuddyPress] [3373] trunk: Adds exclude parameter to bp_has_activities.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>3373</dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2010-11-07 11:33:21 +0000 (Sun, 07 Nov 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Adds exclude parameter to bp_has_activities. Fixes #2646</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivityclassesphp">trunk/bp-activity/bp-activity-classes.php</a></li>
<li><a href="#trunkbpactivitybpactivitytemplatetagsphp">trunk/bp-activity/bp-activity-templatetags.php</a></li>
<li><a href="#trunkbpactivityphp">trunk/bp-activity.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivityclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-classes.php (3372 => 3373)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-classes.php        2010-11-07 11:25:07 UTC (rev 3372)
+++ trunk/bp-activity/bp-activity-classes.php        2010-11-07 11:33:21 UTC (rev 3373)
</span><span class="lines">@@ -70,7 +70,7 @@
</span><span class="cx">                 if ( !$this-&gt;primary_link )
</span><span class="cx">                         $this-&gt;primary_link = $bp-&gt;loggedin_user-&gt;domain;
</span><span class="cx"> 
</span><del>-                /* If we have an existing ID, update the activity item, otherwise insert it. */
</del><ins>+                // If we have an existing ID, update the activity item, otherwise insert it.
</ins><span class="cx">                 if ( $this-&gt;id )
</span><span class="cx">                         $q = $wpdb-&gt;prepare( &quot;UPDATE {$bp-&gt;activity-&gt;table_name} SET user_id = %d, component = %s, type = %s, action = %s, content = %s, primary_link = %s, date_recorded = %s, item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d&quot;, $this-&gt;user_id, $this-&gt;component, $this-&gt;type, $this-&gt;action, $this-&gt;content, $this-&gt;primary_link, $this-&gt;date_recorded, $this-&gt;item_id, $this-&gt;secondary_item_id, $this-&gt;hide_sitewide, $this-&gt;id );
</span><span class="cx">                 else
</span><span class="lines">@@ -86,38 +86,42 @@
</span><span class="cx">                 return true;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        /* Static Functions */
</del><ins>+        // Static Functions
</ins><span class="cx"> 
</span><del>-        function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
</del><ins>+        function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false, $exclude = false ) {
</ins><span class="cx">                 global $wpdb, $bp;
</span><span class="cx"> 
</span><del>-                /* Select conditions */
</del><ins>+                // Select conditions
</ins><span class="cx">                 $select_sql = &quot;SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name&quot;;
</span><span class="cx"> 
</span><span class="cx">                 $from_sql = &quot; FROM {$bp-&gt;activity-&gt;table_name} a LEFT JOIN {$wpdb-&gt;users} u ON a.user_id = u.ID&quot;;
</span><span class="cx"> 
</span><del>-                /* Where conditions */
</del><ins>+                // Where conditions
</ins><span class="cx">                 $where_conditions = array();
</span><span class="cx"> 
</span><del>-                /* Searching */
</del><ins>+                // Searching
</ins><span class="cx">                 if ( $search_terms ) {
</span><span class="cx">                         $search_terms = $wpdb-&gt;escape( $search_terms );
</span><span class="cx">                         $where_conditions['search_sql'] = &quot;a.content LIKE '%%&quot; . like_escape( $search_terms ) . &quot;%%'&quot;;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                /* Filtering */
</del><ins>+                // Filtering
</ins><span class="cx">                 if ( $filter &amp;&amp; $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) )
</span><span class="cx">                         $where_conditions['filter_sql'] = $filter_sql;
</span><span class="cx"> 
</span><del>-                /* Sorting */
</del><ins>+                // Sorting
</ins><span class="cx">                 if ( $sort != 'ASC' &amp;&amp; $sort != 'DESC' )
</span><span class="cx">                         $sort = 'DESC';
</span><span class="cx"> 
</span><del>-                /* Hide Hidden Items? */
</del><ins>+                // Hide Hidden Items?
</ins><span class="cx">                 if ( !$show_hidden )
</span><span class="cx">                         $where_conditions['hidden_sql'] = &quot;a.hide_sitewide = 0&quot;;
</span><span class="cx"> 
</span><del>-                /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
</del><ins>+                // Exclude specified items
+                if ( $exclude )
+                        $where_conditions['exclude'] = &quot;a.id NOT IN ({$exclude})&quot;;
+
+                // Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity
</ins><span class="cx">                 if ( !$display_comments || 'threaded' == $display_comments ) {
</span><span class="cx">                         $where_conditions[] = &quot;a.type != 'activity_comment'&quot;;
</span><span class="cx">                 }
</span><span class="lines">@@ -133,7 +137,7 @@
</span><span class="cx"> 
</span><span class="cx">                 $total_activities = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT count(a.id) FROM {$bp-&gt;activity-&gt;table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}&quot; ) );
</span><span class="cx"> 
</span><del>-                /* Get the fullnames of users so we don't have to query in the loop */
</del><ins>+                // Get the fullnames of users so we don't have to query in the loop
</ins><span class="cx">                 if ( bp_is_active( 'xprofile' ) &amp;&amp; $activities ) {
</span><span class="cx">                         foreach ( (array)$activities as $activity ) {
</span><span class="cx">                                 if ( (int)$activity-&gt;user_id )
</span><span class="lines">@@ -160,7 +164,7 @@
</span><span class="cx">                 if ( $activities &amp;&amp; $display_comments )
</span><span class="cx">                         $activities = BP_Activity_Activity::append_comments( &amp;$activities );
</span><span class="cx"> 
</span><del>-                /* If $max is set, only return up to the max results */
</del><ins>+                // If $max is set, only return up to the max results
</ins><span class="cx">                 if ( !empty( $max ) ) {
</span><span class="cx">                         if ( (int)$total_activities &gt; (int)$max )
</span><span class="cx">                                 $total_activities = $max;
</span><span class="lines">@@ -193,7 +197,7 @@
</span><span class="cx">                 if ( $display_comments )
</span><span class="cx">                         $activities = BP_Activity_Activity::append_comments( $activities );
</span><span class="cx"> 
</span><del>-                /* If $max is set, only return up to the max results */
</del><ins>+                // If $max is set, only return up to the max results
</ins><span class="cx">                 if ( !empty( $max ) ) {
</span><span class="cx">                         if ( (int)$total_activities &gt; (int)$max )
</span><span class="cx">                                 $total_activities = $max;
</span></span></pre></div>
<a id="trunkbpactivitybpactivitytemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-templatetags.php (3372 => 3373)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-templatetags.php        2010-11-07 11:25:07 UTC (rev 3372)
+++ trunk/bp-activity/bp-activity-templatetags.php        2010-11-07 11:33:21 UTC (rev 3373)
</span><span class="lines">@@ -15,7 +15,7 @@
</span><span class="cx"> 
</span><span class="cx">         var $full_name;
</span><span class="cx"> 
</span><del>-        function bp_activity_template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden ) {
</del><ins>+        function bp_activity_template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude ) {
</ins><span class="cx">                 global $bp;
</span><span class="cx"> 
</span><span class="cx">                 $this-&gt;pag_page = isset( $_REQUEST['acpage'] ) ? intval( $_REQUEST['acpage'] ) : $page;
</span><span class="lines">@@ -32,7 +32,7 @@
</span><span class="cx">                         $this-&gt;activities = bp_activity_get_specific( array( 'activity_ids' =&gt; explode( ',', $include ), 'max' =&gt; $max, 'page' =&gt; $this-&gt;pag_page, 'per_page' =&gt; $this-&gt;pag_num, 'sort' =&gt; $sort, 'display_comments' =&gt; $display_comments ) );
</span><span class="cx">                 // Fetch all activity items
</span><span class="cx">                 else
</span><del>-                        $this-&gt;activities = bp_activity_get( array( 'display_comments' =&gt; $display_comments, 'max' =&gt; $max, 'per_page' =&gt; $this-&gt;pag_num, 'page' =&gt; $this-&gt;pag_page, 'sort' =&gt; $sort, 'search_terms' =&gt; $search_terms, 'filter' =&gt; $filter, 'show_hidden' =&gt; $show_hidden ) );
</del><ins>+                        $this-&gt;activities = bp_activity_get( array( 'display_comments' =&gt; $display_comments, 'max' =&gt; $max, 'per_page' =&gt; $this-&gt;pag_num, 'page' =&gt; $this-&gt;pag_page, 'sort' =&gt; $sort, 'search_terms' =&gt; $search_terms, 'filter' =&gt; $filter, 'show_hidden' =&gt; $show_hidden, 'exclude' =&gt; $exclude ) );
</ins><span class="cx"> 
</span><span class="cx">                 if ( !$max || $max &gt;= (int)$this-&gt;activities['total'] )
</span><span class="cx">                         $this-&gt;total_activity_count = (int)$this-&gt;activities['total'];
</span><span class="lines">@@ -142,6 +142,7 @@
</span><span class="cx">          */
</span><span class="cx">         $user_id = false;
</span><span class="cx">         $include = false;
</span><ins>+        $exclude = false;
</ins><span class="cx">         $show_hidden = false;
</span><span class="cx">         $object = false;
</span><span class="cx">         $primary_id = false;
</span><span class="lines">@@ -166,7 +167,8 @@
</span><span class="cx">         /* Note: any params used for filtering can be a single value, or multiple values comma separated. */
</span><span class="cx">         $defaults = array(
</span><span class="cx">                 'display_comments' =&gt; 'threaded', // false for none, stream/threaded - show comments in the stream or threaded under items
</span><del>-                'include' =&gt; $include, // pass an activity_id or string of ID's comma separated
</del><ins>+                'include' =&gt; $include, // pass an activity_id or string of IDs comma-separated
+                'exclude' =&gt; $exclude, // pass an activity_id or string of IDs comma-separated
</ins><span class="cx">                 'sort' =&gt; 'DESC', // sort DESC or ASC
</span><span class="cx">                 'page' =&gt; 1, // which page to load
</span><span class="cx">                 'per_page' =&gt; 20, // number of items per page
</span><span class="lines">@@ -254,7 +256,7 @@
</span><span class="cx">         else if ( !empty( $user_id ) || !empty( $object ) || !empty( $action ) || !empty( $primary_id ) || !empty( $secondary_id ) )
</span><span class="cx">                 $filter = array( 'user_id' =&gt; $user_id, 'object' =&gt; $object, 'action' =&gt; $action, 'primary_id' =&gt; $primary_id, 'secondary_id' =&gt; $secondary_id );
</span><span class="cx"> 
</span><del>-        $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden );
</del><ins>+        $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude );
</ins><span class="cx"> 
</span><span class="cx">         return apply_filters( 'bp_has_activities', $activities_template-&gt;has_activities(), &amp;$activities_template );
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkbpactivityphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity.php (3372 => 3373)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity.php        2010-11-07 11:25:07 UTC (rev 3372)
+++ trunk/bp-activity.php        2010-11-07 11:33:21 UTC (rev 3373)
</span><span class="lines">@@ -503,6 +503,7 @@
</span><span class="cx"> 
</span><span class="cx">                 'search_terms' =&gt; false, // Pass search terms as a string
</span><span class="cx">                 'show_hidden' =&gt; false, // Show activity items that are hidden site-wide?
</span><ins>+                'exclude' =&gt; false, // Comma-separated list of activity IDs to exclude
</ins><span class="cx"> 
</span><span class="cx">                 /**
</span><span class="cx">                  * Pass filters as an array -- all filter items can be multiple values comma separated:
</span><span class="lines">@@ -521,13 +522,13 @@
</span><span class="cx">         extract( $r, EXTR_SKIP );
</span><span class="cx"> 
</span><span class="cx">         /* Attempt to return a cached copy of the first page of sitewide activity. */
</span><del>-        if ( 1 == (int)$page &amp;&amp; empty( $max ) &amp;&amp; empty( $search_terms ) &amp;&amp; empty( $filter ) &amp;&amp; 'DESC' == $sort ) {
</del><ins>+        if ( 1 == (int)$page &amp;&amp; empty( $max ) &amp;&amp; empty( $search_terms ) &amp;&amp; empty( $filter ) &amp;&amp; 'DESC' == $sort &amp;&amp; empty( $exclude ) ) {
</ins><span class="cx">                 if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
</span><span class="cx">                         $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
</span><span class="cx">                         wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
</span><span class="cx">                 }
</span><span class="cx">         } else
</span><del>-                $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
</del><ins>+                $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden, $exclude );
</ins><span class="cx"> 
</span><span class="cx">         return apply_filters( 'bp_activity_get', $activity, &amp;$r );
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>