<!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][9257] trunk/src: Activity: Support multiple scopes in `bp_has_activities()`.</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 { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { 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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/9257">9257</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/9257","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>r-a-y</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2014-12-22 21:46:50 +0000 (Mon, 22 Dec 2014)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Activity: Support multiple scopes in `bp_has_activities()`.
This commit:
* Allows the `'scope'` parameter to support multiple scopes. For example, `scope=friends,mentions`. This can be a comma-delimited string or an array.
* Makes the `'scope'` parameter available across the `bp_has_activities()` stack. Previously, `'scope'` was only available for use in the `bp_has_activities()` loop.
* Parses scopes using the `BP_Activity_Query` class to handle complex conditions.
* Allows components to declare their own custom activity scopes. Components can also override existing activity arguments by setting the `'override'` key in their scope callback. For an example, see how the friends component declares the `'friends'` scope in `bp_friends_filter_activity_scope()`. Previously, it was not possible for components or third-party plugins to declare their own scopes without doing a fair bit of workarounds.
See <a href="http://buddypress.trac.wordpress.org/ticket/4988">#4988</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpactivitybpactivityclassesphp">trunk/src/bp-activity/bp-activity-classes.php</a></li>
<li><a href="#trunksrcbpactivitybpactivityfunctionsphp">trunk/src/bp-activity/bp-activity-functions.php</a></li>
<li><a href="#trunksrcbpactivitybpactivitytemplatephp">trunk/src/bp-activity/bp-activity-template.php</a></li>
<li><a href="#trunksrcbpfriendsbpfriendsactivityphp">trunk/src/bp-friends/bp-friends-activity.php</a></li>
<li><a href="#trunksrcbpgroupsbpgroupsactivityphp">trunk/src/bp-groups/bp-groups-activity.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpactivitybpactivityclassesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/bp-activity-classes.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-classes.php 2014-12-22 21:38:24 UTC (rev 9256)
+++ trunk/src/bp-activity/bp-activity-classes.php 2014-12-22 21:46:50 UTC (rev 9257)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -260,25 +260,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $args {
</span><span class="cx" style="display: block; padding: 0 10px"> * An array of arguments. All items are optional.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type int $page Which page of results to fetch. Using page=1 without per_page will result
- * in no pagination. Default: 1.
- * @type int|bool $per_page Number of results per page. Default: 25.
- * @type int|bool $max Maximum number of results to return. Default: false (unlimited).
- * @type string $sort ASC or DESC. Default: 'DESC'.
- * @type array $exclude Array of activity IDs to exclude. Default: false.
- * @type array $in Array of ids to limit query by (IN). Default: false.
- * @type array $meta_query Array of meta_query conditions. See WP_Meta_Query::queries.
- * @type array $date_query Array of date_query conditions. See first parameter of
- * WP_Date_Query::__construct().
- * @type array $filter_query Array of advanced query conditions. See BP_Activity_Query::__construct().
- * @type array $filter See BP_Activity_Activity::get_filter_sql().
- * @type string $search_terms Limit results by a search term. Default: false.
- * @type bool $display_comments Whether to include activity comments. Default: false.
- * @type bool $show_hidden Whether to show items marked hide_sitewide. Default: false.
- * @type string $spam Spam status. Default: 'ham_only'.
- * @type bool $update_meta_cache Whether to pre-fetch metadata for queried activity items. Default: true.
- * @type string|bool $count_total If true, an additional DB query is run to count the total activity items
- * for the query. Default: false.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type int $page Which page of results to fetch. Using page=1 without per_page will result
+ * in no pagination. Default: 1.
+ * @type int|bool $per_page Number of results per page. Default: 25.
+ * @type int|bool $max Maximum number of results to return. Default: false (unlimited).
+ * @type string $sort ASC or DESC. Default: 'DESC'.
+ * @type array $exclude Array of activity IDs to exclude. Default: false.
+ * @type array $in Array of ids to limit query by (IN). Default: false.
+ * @type array $meta_query Array of meta_query conditions. See WP_Meta_Query::queries.
+ * @type array $date_query Array of date_query conditions. See first parameter of
+ * WP_Date_Query::__construct().
+ * @type array $filter_query Array of advanced query conditions. See BP_Activity_Query::__construct().
+ * @type string|array $scope Pre-determined set of activity arguments.
+ * @type array $filter See BP_Activity_Activity::get_filter_sql().
+ * @type string $search_terms Limit results by a search term. Default: false.
+ * @type bool $display_comments Whether to include activity comments. Default: false.
+ * @type bool $show_hidden Whether to show items marked hide_sitewide. Default: false.
+ * @type string $spam Spam status. Default: 'ham_only'.
+ * @type bool $update_meta_cache Whether to pre-fetch metadata for queried activity items. Default: true.
+ * @type string|bool $count_total If true, an additional DB query is run to count the total activity items
+ * for the query. Default: false.
</ins><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array The array returned has two keys:
</span><span class="cx" style="display: block; padding: 0 10px"> * - 'total' is the count of located activities
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -320,6 +321,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'date_query' => false, // Filter by date
</span><span class="cx" style="display: block; padding: 0 10px"> 'filter_query' => false, // Advanced filtering - see BP_Activity_Query
</span><span class="cx" style="display: block; padding: 0 10px"> 'filter' => false, // See self::get_filter_sql()
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'scope' => false, // Preset activity arguments
</ins><span class="cx" style="display: block; padding: 0 10px"> 'search_terms' => false, // Terms to search by
</span><span class="cx" style="display: block; padding: 0 10px"> 'display_comments' => false, // Whether to include activity comments
</span><span class="cx" style="display: block; padding: 0 10px"> 'show_hidden' => false, // Show items marked hide_sitewide
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -342,8 +344,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Excluded types
</span><span class="cx" style="display: block; padding: 0 10px"> $excluded_types = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Scope takes precedence
+ if ( ! empty( $r['scope'] ) ) {
+ $scope_query = self::get_scope_query_sql( $r['scope'], $r );
+
+ if ( ! empty( $scope_query['sql'] ) ) {
+ $where_conditions['scope_query_sql'] = $scope_query['sql'];
+ }
+
+ // override some arguments if needed
+ if ( ! empty( $scope_query['override'] ) ) {
+ $r = array_replace_recursive( $r, $scope_query['override'] );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> // Advanced filtering
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $r['filter_query'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( ! empty( $r['filter_query'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $filter_query = new BP_Activity_Query( $r['filter_query'] );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $sql = $filter_query->get_sql() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $where_conditions['filter_query_sql'] = $sql;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -520,7 +534,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> // Query first for activity IDs
</span><span class="cx" style="display: block; padding: 0 10px"> $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}";
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -821,6 +834,161 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Get the SQL for the 'scope' param in BP_Activity_Activity::get().
+ *
+ * A scope is a predetermined set of activity arguments. This method is used
+ * to grab these activity arguments and override any existing args if needed.
+ *
+ * Can handle multple scopes.
+ *
+ * @since BuddyPress (2.2.0)
+ *
+ * @param string $scope The activity scope
+ * @param array $r Current activity arguments. Same as those of BP_Activity_Activity::get(),
+ * but merged with defaults.
+ * @return array 'sql' WHERE SQL string and 'override' activity args
+ */
+ public static function get_scope_query_sql( $scope = '', $r = array() ) {
+ $query_args = array();
+ $override = array();
+ $retval = array();
+
+ if ( ! is_array( $scope ) ) {
+ $scopes = explode( ',', $scope );
+ } else {
+ $scopes = $scope;
+ }
+
+ if ( empty( $scopes ) ) {
+ return $sql;
+ }
+
+ // helper to easily grab the 'user_id'
+ if ( ! empty( $r['filter']['user_id'] ) ) {
+ $r['user_id'] = $r['filter']['user_id'];
+ }
+
+ // parse each scope; yes! we handle multiples!
+ foreach ( $scopes as $scope ) {
+ $scope_args = array();
+
+ switch ( $scope ) {
+ case 'just-me' :
+ $scope_args = array(
+ 'column' => 'user_id',
+ 'value' => $r['user_id']
+ );
+
+ $scope_args['override']['display_comments'] = 'stream';
+
+ // wipe out the user ID
+ $scope_args['override']['filter']['user_id'] = 0;
+
+ break;
+
+ case 'favorites':
+ $favs = bp_activity_get_user_favorites( $r['user_id'] );
+ if ( empty( $favs ) ) {
+ return $scope_args;
+ }
+
+ $scope_args = array(
+ 'column' => 'id',
+ 'compare' => 'IN',
+ 'value' => (array) $favs
+ );
+ $scope_args['override']['display_comments'] = true;
+
+ // wipe out the user ID
+ $scope_args['override']['filter']['user_id'] = 0;
+
+ break;
+
+ case 'mentions':
+ // Are mentions disabled?
+ if ( ! bp_activity_do_mentions() ) {
+ return $scope_args;
+ }
+
+ $scope_args = array(
+ 'column' => 'content',
+ 'compare' => 'LIKE',
+
+ // Start search at @ symbol and stop search at closing tag delimiter.
+ 'value' => '@' . bp_activity_get_user_mentionname( $r['user_id'] ) . '<'
+ );
+
+ // wipe out current search terms if any
+ // this is so the 'mentions' scope can be combined with other scopes
+ $scope_args['override']['search_terms'] = false;
+
+ $scope_args['override']['display_comments'] = 'stream';
+ $scope_args['override']['filter']['user_id'] = 0;
+
+ break;
+
+ default :
+ /**
+ * Plugins can hook here to set their activity arguments for custom scopes.
+ *
+ * This is a dynamic filter based on the activity scope. eg:
+ * - 'bp_activity_set_groups_scope_args'
+ * - 'bp_activity_set_friends_scope_args'
+ *
+ * To see how this filter is used, plugin devs should check out:
+ * - bp_groups_filter_activity_scope() - used for 'groups' scope
+ * - bp_friends_filter_activity_scope() - used for 'friends' scope
+ *
+ * @since BuddyPress (2.2.0)
+ *
+ * @param array {
+ * Activity query clauses.
+ *
+ * @type array {
+ * Activity arguments for your custom scope.
+ * See {@link BP_Activity_Query::_construct()} for more details.
+ * }
+ * @type array $override Optional. Override existing activity arguments passed by $r.
+ * }
+ * @param array $r Current activity arguments passed in BP_Activity_Activity::get()
+ */
+ $scope_args = apply_filters( "bp_activity_set_{$scope}_scope_args", array(), $r );
+ break;
+ }
+
+ if ( ! empty( $scope_args ) ) {
+ // merge override properties from other scopes
+ // this might be a problem...
+ if ( ! empty( $scope_args['override'] ) ) {
+ $override = array_merge( $override, $scope_args['override'] );
+ unset( $scope_args['override'] );
+ }
+
+ // save scope args
+ if ( ! empty( $scope_args ) ) {
+ $query_args[] = $scope_args;
+ }
+ }
+ }
+
+ if ( ! empty( $query_args ) ) {
+ // set relation to OR
+ $query_args['relation'] = 'OR';
+
+ $query = new BP_Activity_Query( $query_args );
+ if ( $sql = $query->get_sql() ) {
+ $retval['sql'] = $sql;
+ }
+ }
+
+ if ( ! empty( $override ) ) {
+ $retval['override'] = $override;
+ }
+
+ return $retval;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * In BuddyPress 1.2.x, this was used to retrieve specific activity stream items (for example, on an activity's permalink page).
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * As of 1.5.x, use BP_Activity_Activity::get() with an 'in' parameter instead.
</span></span></pre></div>
<a id="trunksrcbpactivitybpactivityfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/bp-activity-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-functions.php 2014-12-22 21:38:24 UTC (rev 9256)
+++ trunk/src/bp-activity/bp-activity-functions.php 2014-12-22 21:46:50 UTC (rev 9257)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1423,6 +1423,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'spam' => 'ham_only', // 'ham_only' (default), 'spam_only' or 'all'.
</span><span class="cx" style="display: block; padding: 0 10px"> 'update_meta_cache' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> 'count_total' => false,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'scope' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Pass filters as an array -- all filter items can be multiple values comma separated:
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1438,7 +1439,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Attempt to return a cached copy of the first page of sitewide activity.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ( 1 === (int) $r['page'] ) && empty( $r['max'] ) && empty( $r['search_terms'] ) && empty( $r['meta_query'] ) && empty( $r['date_query'] ) && empty( $r['filter_query'] ) && empty( $r['filter'] ) && empty( $r['exclude'] ) && empty( $r['in'] ) && ( 'DESC' === $r['sort'] ) && empty( $r['exclude'] ) && ( 'ham_only' === $r['spam'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ( 1 === (int) $r['page'] ) && empty( $r['max'] ) && empty( $r['search_terms'] ) && empty( $r['meta_query'] ) && empty( $r['date_query'] ) && empty( $r['filter_query'] ) && empty( $r['filter'] ) && empty( $r['scope'] )&& empty( $r['exclude'] ) && empty( $r['in'] ) && ( 'DESC' === $r['sort'] ) && empty( $r['exclude'] ) && ( 'ham_only' === $r['spam'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( false === $activity ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1453,6 +1454,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'date_query' => $r['date_query'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'filter_query' => $r['filter_query'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'filter' => $r['filter'],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'scope' => $r['scope'],
</ins><span class="cx" style="display: block; padding: 0 10px"> 'display_comments' => $r['display_comments'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'show_hidden' => $r['show_hidden'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'spam' => $r['spam'],
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1474,6 +1476,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'date_query' => $r['date_query'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'filter_query' => $r['filter_query'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'filter' => $r['filter'],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'scope' => $r['scope'],
</ins><span class="cx" style="display: block; padding: 0 10px"> 'display_comments' => $r['display_comments'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'show_hidden' => $r['show_hidden'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'exclude' => $r['exclude'],
</span></span></pre></div>
<a id="trunksrcbpactivitybpactivitytemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-activity/bp-activity-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-activity/bp-activity-template.php 2014-12-22 21:38:24 UTC (rev 9256)
+++ trunk/src/bp-activity/bp-activity-template.php 2014-12-22 21:46:50 UTC (rev 9257)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -201,6 +201,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'exclude' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'in' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'filter' => false,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'scope' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'search_terms' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'meta_query' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'date_query' => false,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -252,6 +253,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'date_query' => $date_query,
</span><span class="cx" style="display: block; padding: 0 10px"> 'filter_query' => $filter_query,
</span><span class="cx" style="display: block; padding: 0 10px"> 'filter' => $filter,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'scope' => $scope,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'show_hidden' => $show_hidden,
</span><span class="cx" style="display: block; padding: 0 10px"> 'exclude' => $exclude,
</span><span class="cx" style="display: block; padding: 0 10px"> 'in' => $in,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -613,65 +615,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $page = 0;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Search terms
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $search_terms ) && ! empty( $_REQUEST['s'] ) )
</span><span class="cx" style="display: block; padding: 0 10px"> $search_terms = $_REQUEST['s'];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // If you have passed a "scope" then this will override any filters you have passed.
- if ( 'just-me' == $scope || 'friends' == $scope || 'groups' == $scope || 'favorites' == $scope || 'mentions' == $scope ) {
- if ( 'just-me' == $scope )
- $display_comments = 'stream';
-
- // determine which user_id applies
- if ( empty( $user_id ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Set some default arguments when using a scope
+ if ( ! empty( $scope ) ) {
+ // Determine which user ID applies
+ if ( empty( $user_id ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // are we displaying user specific activity?
- if ( is_numeric( $user_id ) ) {
- $show_hidden = ( $user_id == bp_loggedin_user_id() && $scope != 'friends' ) ? 1 : 0;
-
- switch ( $scope ) {
- case 'friends':
- if ( bp_is_active( 'friends' ) )
- $friends = friends_get_friend_user_ids( $user_id );
- if ( empty( $friends ) )
- return false;
-
- $user_id = implode( ',', (array) $friends );
- break;
- case 'groups':
- if ( bp_is_active( 'groups' ) ) {
- $groups = groups_get_user_groups( $user_id );
- if ( empty( $groups['groups'] ) )
- return false;
-
- $object = $bp->groups->id;
- $primary_id = implode( ',', (array) $groups['groups'] );
-
- $user_id = 0;
- }
- break;
- case 'favorites':
- $favs = bp_activity_get_user_favorites( $user_id );
- if ( empty( $favs ) )
- return false;
-
- $in = implode( ',', (array) $favs );
- $display_comments = true;
- $user_id = 0;
- break;
- case 'mentions':
-
- // Are mentions disabled?
- if ( ! bp_activity_do_mentions() ) {
- return false;
- }
-
- // Start search at @ symbol and stop search at closing tag delimiter.
- $search_terms = '@' . bp_activity_get_user_mentionname( $user_id ) . '<';
- $display_comments = 'stream';
- $user_id = 0;
- break;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Should we show all items regardless of sitewide visibility?
+ if ( ! empty( $user_id ) ) {
+ $show_hidden = ( $user_id == bp_loggedin_user_id() ) ? 1 : 0;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -712,6 +669,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'exclude' => $exclude,
</span><span class="cx" style="display: block; padding: 0 10px"> 'in' => $in,
</span><span class="cx" style="display: block; padding: 0 10px"> 'filter' => $filter,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'scope' => $scope,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'search_terms' => $search_terms,
</span><span class="cx" style="display: block; padding: 0 10px"> 'meta_query' => $meta_query,
</span><span class="cx" style="display: block; padding: 0 10px"> 'date_query' => $date_query,
</span></span></pre></div>
<a id="trunksrcbpfriendsbpfriendsactivityphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-friends/bp-friends-activity.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-friends/bp-friends-activity.php 2014-12-22 21:38:24 UTC (rev 9256)
+++ trunk/src/bp-friends/bp-friends-activity.php 2014-12-22 21:46:50 UTC (rev 9257)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -228,6 +228,49 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_activity_prefetch_object_data', 'bp_friends_prefetch_activity_object_data' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Set up activity arguments for use with the 'friends' scope.
+ *
+ * For details on the syntax, see {@link BP_Activity_Query}.
+ *
+ * @since BuddyPress (2.2.0)
+ *
+ * @param array $retval Empty array by default
+ * @param array $filter Current activity arguments
+ * @return array
+ */
+function bp_friends_filter_activity_scope( $retval, $filter ) {
+ $friends = friends_get_friend_user_ids( $filter['user_id'] );
+
+ if ( empty( $friends ) ) {
+ return $retval;
+ }
+
+ $retval= array(
+ 'relation' => 'AND',
+ array(
+ 'column' => 'user_id',
+ 'compare' => 'IN',
+ 'value' => (array) $friends
+ ),
+ // we should only be able to view sitewide activity content for friends
+ array(
+ 'column' => 'hide_sitewide',
+ 'value' => 0
+ ),
+ );
+
+ // wipe out the user ID
+ $retval['override']['filter']['user_id'] = 0;
+
+ // make sure we aren't limiting items by 'hide_sitewide' since we're already
+ // limiting it above
+ $scope_args['override']['show_hidden'] = true;
+
+ return $retval;
+}
+add_filter( 'bp_activity_set_friends_scope_args', 'bp_friends_filter_activity_scope', 10, 2 );
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Add activity stream items when one members accepts another members request
</span><span class="cx" style="display: block; padding: 0 10px"> * for virtual friendship.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span></span></pre></div>
<a id="trunksrcbpgroupsbpgroupsactivityphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-groups/bp-groups-activity.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-groups/bp-groups-activity.php 2014-12-22 21:38:24 UTC (rev 9256)
+++ trunk/src/bp-groups/bp-groups-activity.php 2014-12-22 21:46:50 UTC (rev 9257)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -234,6 +234,42 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_activity_prefetch_object_data', 'bp_groups_prefetch_activity_object_data' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Set up activity arguments for use with the 'groups' scope.
+ *
+ * @since BuddyPress (2.2.0)
+ *
+ * @param array $retval Empty array by default
+ * @param array $filter Current activity arguments
+ * @return array
+ */
+function bp_groups_filter_activity_scope( $retval, $filter ) {
+ $groups = groups_get_user_groups( $filter['user_id'] );
+
+ if ( empty( $groups['groups'] ) ) {
+ return $retval;
+ }
+
+ $retval= array(
+ 'relation' => 'AND',
+ array(
+ 'column' => 'component',
+ 'value' => buddypress()->groups->id
+ ),
+ array(
+ 'column' => 'item_id',
+ 'compare' => 'IN',
+ 'value' => (array) $groups['groups']
+ ),
+ );
+
+ // wipe out the user ID
+ $retval['override']['filter']['user_id'] = 0;
+
+ return $retval;
+}
+add_filter( 'bp_activity_set_groups_scope_args', 'bp_groups_filter_activity_scope', 10, 2 );
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Record an activity item related to the Groups component.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * A wrapper for {@link bp_activity_add()} that provides some Groups-specific
</span></span></pre>
</div>
</div>
</body>
</html>