<!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->primary_link )
</span><span class="cx">                         $this->primary_link = $bp->loggedin_user->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->id )
</span><span class="cx">                         $q = $wpdb->prepare( "UPDATE {$bp->activity->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", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->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 = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
</span><span class="cx">
</span><span class="cx">                 $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
</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->escape( $search_terms );
</span><span class="cx">                         $where_conditions['search_sql'] = "a.content LIKE '%%" . like_escape( $search_terms ) . "%%'";
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-                /* Filtering */
</del><ins>+                // Filtering
</ins><span class="cx">                 if ( $filter && $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' && $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'] = "a.hide_sitewide = 0";
</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'] = "a.id NOT IN ({$exclude})";
+
+                // 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[] = "a.type != 'activity_comment'";
</span><span class="cx">                 }
</span><span class="lines">@@ -133,7 +137,7 @@
</span><span class="cx">
</span><span class="cx">                 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}" ) );
</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' ) && $activities ) {
</span><span class="cx">                         foreach ( (array)$activities as $activity ) {
</span><span class="cx">                                 if ( (int)$activity->user_id )
</span><span class="lines">@@ -160,7 +164,7 @@
</span><span class="cx">                 if ( $activities && $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 > (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 > (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->pag_page = isset( $_REQUEST['acpage'] ) ? intval( $_REQUEST['acpage'] ) : $page;
</span><span class="lines">@@ -32,7 +32,7 @@
</span><span class="cx">                         $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments ) );
</span><span class="cx">                 // Fetch all activity items
</span><span class="cx">                 else
</span><del>-                        $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden ) );
</del><ins>+                        $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude ) );
</ins><span class="cx">
</span><span class="cx">                 if ( !$max || $max >= (int)$this->activities['total'] )
</span><span class="cx">                         $this->total_activity_count = (int)$this->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' => 'threaded', // false for none, stream/threaded - show comments in the stream or threaded under items
</span><del>-                'include' => $include, // pass an activity_id or string of ID's comma separated
</del><ins>+                'include' => $include, // pass an activity_id or string of IDs comma-separated
+                'exclude' => $exclude, // pass an activity_id or string of IDs comma-separated
</ins><span class="cx">                 'sort' => 'DESC', // sort DESC or ASC
</span><span class="cx">                 'page' => 1, // which page to load
</span><span class="cx">                 'per_page' => 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' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $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->has_activities(), &$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' => false, // Pass search terms as a string
</span><span class="cx">                 'show_hidden' => false, // Show activity items that are hidden site-wide?
</span><ins>+                'exclude' => 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 && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort ) {
</del><ins>+        if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort && 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, &$r );
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>