<!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][9536] trunk/src/bp-activity/bp-activity-template.php: Activity: Clean up `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/9536">9536</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/9536","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>johnjamesjacoby</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-02-23 17:36:57 +0000 (Mon, 23 Feb 2015)</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: Clean up `bp_has_activities()`:
* Remove `$bp` global usage. See <a href="http://buddypress.trac.wordpress.org/ticket/5138">#5138</a>.
* Remove `extract()` usage. See <a href="http://buddypress.trac.wordpress.org/ticket/5698">#5698</a>.
* Remove one-time-use variables.
* Consolidate arrays for improved readability.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpactivitybpactivitytemplatephp">trunk/src/bp-activity/bp-activity-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<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 2015-02-23 16:58:04 UTC (rev 9535)
+++ trunk/src/bp-activity/bp-activity-template.php 2015-02-23 17:36:57 UTC (rev 9536)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -601,62 +601,57 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool Returns true when activities are found, otherwise false.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function bp_has_activities( $args = '' ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- global $activities_template, $bp;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $activities_template;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /***
- * Set the defaults based on the current page. Any of these will be overridden
- * if arguments are directly passed into the loop. Custom plugins should always
- * pass their parameters directly to the loop.
- */
- $user_id = false;
- $include = false;
- $exclude = false;
- $in = false;
- $show_hidden = false;
- $object = false;
- $primary_id = false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Get BuddyPress
+ $bp = buddypress();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /** Smart Defaults ********************************************************/
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // User filtering
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( bp_displayed_user_id() )
- $user_id = bp_displayed_user_id();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user_id = bp_displayed_user_id()
+ ? bp_displayed_user_id()
+ : false;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Group filtering
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( !empty( $bp->groups->current_group ) ) {
- $object = $bp->groups->id;
- $primary_id = $bp->groups->current_group->id;
-
- if ( groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) || bp_current_user_can( 'bp_moderate' ) ) {
- $show_hidden = true;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( groups_get_current_group() ) {
+ $object = $bp->groups->id;
+ $primary_id = bp_current_group_id();
+ $show_hidden = (bool) ( groups_is_user_member( bp_loggedin_user_id(), $primary_id ) || bp_current_user_can( 'bp_moderate' ) );
+ } else {
+ $object = false;
+ $primary_id = false;
+ $show_hidden = 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"> // The default scope should recognize custom slugs
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( array_key_exists( bp_current_action(), (array) $bp->loaded_components ) ) {
- $scope = $bp->loaded_components[bp_current_action()];
- }
- else
- $scope = bp_current_action();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $scope = array_key_exists( bp_current_action(), (array) $bp->loaded_components )
+ ? $bp->loaded_components[ bp_current_action() ]
+ : bp_current_action();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Support for permalinks on single item pages: /groups/my-group/activity/124/
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( bp_is_current_action( bp_get_activity_slug() ) )
- $include = bp_action_variable( 0 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $include = bp_is_current_action( bp_get_activity_slug() )
+ ? bp_action_variable( 0 )
+ : false;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Note: any params used for filtering can be a single value, or multiple values comma separated.
- $defaults = array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /** Parse Args ************************************************************/
+
+ // Note: any params used for filtering can be a single value, or multiple
+ // values comma separated.
+ $r = bp_parse_args( $args, array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'display_comments' => 'threaded', // false for none, stream/threaded - show comments in the stream or threaded under items
</span><span class="cx" style="display: block; padding: 0 10px"> 'include' => $include, // pass an activity_id or string of IDs comma-separated
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'exclude' => $exclude, // pass an activity_id or string of IDs comma-separated
- 'in' => $in, // comma-separated list or array of activity IDs among which to search
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'exclude' => false, // pass an activity_id or string of IDs comma-separated
+ 'in' => false, // comma-separated list or array of activity IDs among which to search
</ins><span class="cx" style="display: block; padding: 0 10px"> 'sort' => 'DESC', // sort DESC or ASC
</span><span class="cx" style="display: block; padding: 0 10px"> 'page' => 1, // which page to load
</span><span class="cx" style="display: block; padding: 0 10px"> 'per_page' => 20, // number of items per page
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'page_arg' => 'acpage', // See https://buddypress.trac.wordpress.org/ticket/3679
</ins><span class="cx" style="display: block; padding: 0 10px"> 'max' => false, // max number to return
</span><span class="cx" style="display: block; padding: 0 10px"> 'count_total' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide?
</span><span class="cx" style="display: block; padding: 0 10px"> 'spam' => 'ham_only', // Hide spammed items
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'page_arg' => 'acpage', // See https://buddypress.trac.wordpress.org/ticket/3679
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions)
</span><span class="cx" style="display: block; padding: 0 10px"> 'scope' => $scope,
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -676,30 +671,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Searching
</span><span class="cx" style="display: block; padding: 0 10px"> 'search_terms' => false, // specify terms to search on
</span><span class="cx" style="display: block; padding: 0 10px"> 'update_meta_cache' => true,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ), 'has_activities' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $r = bp_parse_args( $args, $defaults, 'has_activities' );
- extract( $r );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /** Smart Overrides *******************************************************/
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Translate various values for 'display_comments'
</span><span class="cx" style="display: block; padding: 0 10px"> // This allows disabling comments via ?display_comments=0
</span><span class="cx" style="display: block; padding: 0 10px"> // or =none or =false. Final true is a strict type check. See #5029
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( in_array( $display_comments, array( 0, '0', 'none', 'false' ), true ) ) {
- $display_comments = false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( in_array( $r['display_comments'], array( 0, '0', 'none', 'false' ), true ) ) {
+ $r['display_comments'] = 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"> // Ignore pagination if an offset is passed
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $offset ) ) {
- $page = 0;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $r['offset'] ) ) {
+ $r['page'] = 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"> // Search terms
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $search_terms ) && ! empty( $_REQUEST['s'] ) )
- $search_terms = $_REQUEST['s'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $_REQUEST['s'] ) && empty( $r['search_terms'] ) ) {
+ $r['search_terms'] = $_REQUEST['s'];
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Do not exceed the maximum per page
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( !empty( $max ) && ( (int) $per_page > (int) $max ) )
- $per_page = $max;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $r['max'] ) && ( (int) $r['per_page'] > (int) $r['max'] ) ) {
+ $r['per_page'] = $r['max'];
+ }
</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"> * Filters whether BuddyPress should enable afilter support.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -712,51 +708,44 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $value True if BuddyPress should enable afilter support.
</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 ( isset( $_GET['afilter'] ) && apply_filters( 'bp_activity_enable_afilter_support', false ) )
- $filter = array( 'object' => $_GET['afilter'] );
- elseif ( ! empty( $user_id ) || ! empty( $object ) || ! empty( $action ) || ! empty( $primary_id ) || ! empty( $secondary_id ) || ! empty( $offset ) || ! empty( $since ) )
- $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id, 'offset' => $offset, 'since' => $since );
- else
- $filter = false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( isset( $_GET['afilter'] ) && apply_filters( 'bp_activity_enable_afilter_support', false ) ) {
+ $r['filter'] = array(
+ 'object' => $_GET['afilter']
+ );
+ } elseif ( ! empty( $r['user_id'] ) || ! empty( $r['object'] ) || ! empty( $r['action'] ) || ! empty( $r['primary_id'] ) || ! empty( $r['secondary_id'] ) || ! empty( $r['offset'] ) || ! empty( $r['since'] ) ) {
+ $r['filter'] = array(
+ 'user_id' => $r['user_id'],
+ 'object' => $r['object'],
+ 'action' => $r['action'],
+ 'primary_id' => $r['primary_id'],
+ 'secondary_id' => $r['secondary_id'],
+ 'offset' => $r['offset'],
+ 'since' => $r['since']
+ );
+ } else {
+ $r['filter'] = false;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // If specific activity items have been requested, override the $hide_spam argument. This prevents backpat errors with AJAX.
- if ( !empty( $include ) && ( 'ham_only' == $spam ) )
- $spam = 'all';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If specific activity items have been requested, override the $hide_spam
+ // argument. This prevents backpat errors with AJAX.
+ if ( ! empty( $r['include'] ) && ( 'ham_only' === $r['spam'] ) ) {
+ $r['spam'] = 'all';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $template_args = array(
- 'page' => $page,
- 'per_page' => $per_page,
- 'page_arg' => $page_arg,
- 'max' => $max,
- 'count_total' => $count_total,
- 'sort' => $sort,
- 'include' => $include,
- 'exclude' => $exclude,
- 'in' => $in,
- 'filter' => $filter,
- 'scope' => $scope,
- 'search_terms' => $search_terms,
- 'meta_query' => $meta_query,
- 'date_query' => $date_query,
- 'filter_query' => $filter_query,
- 'display_comments' => $display_comments,
- 'show_hidden' => $show_hidden,
- 'spam' => $spam,
- 'update_meta_cache' => $update_meta_cache,
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /** Query *****************************************************************/
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $activities_template = new BP_Activity_Template( $template_args );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $activities_template = new BP_Activity_Template( $r );
</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"> * Filters whether or not there are activity items to display.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since BuddyPress (1.1.0)
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $has_activities Whether or not there are activity items to display.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param bool $has_activities Whether or not there are activity items to display.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $activities_template Current activities template being used.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $template_args Array of arguments passed into the BP_Activity_Template class.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $template_args Array of arguments passed into the BP_Activity_Template class.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template, $template_args );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template, $r );
</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></pre>
</div>
</div>
</body>
</html>