<!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][4840] trunk: Introduces wrapper functions for retrieving and checking items in bp->action_variables.</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/4840">4840</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2011-07-24 22:22:55 +0000 (Sun, 24 Jul 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Introduces wrapper functions for retrieving and checking items in bp->action_variables. action_variables audit for xprofile component. See <a href="http://buddypress.trac.wordpress.org/ticket/3325">#3325</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorebpcoretemplatephp">trunk/bp-core/bp-core-template.php</a></li>
<li><a href="#trunkbpxprofilebpxprofileactionsphp">trunk/bp-xprofile/bp-xprofile-actions.php</a></li>
<li><a href="#trunkbpxprofilebpxprofilescreensphp">trunk/bp-xprofile/bp-xprofile-screens.php</a></li>
<li><a href="#trunkbpxprofilebpxprofiletemplatephp">trunk/bp-xprofile/bp-xprofile-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorebpcoretemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-template.php (4839 => 4840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-template.php        2011-07-24 19:45:09 UTC (rev 4839)
+++ trunk/bp-core/bp-core-template.php        2011-07-24 22:22:55 UTC (rev 4840)
</span><span class="lines">@@ -470,12 +470,36 @@
</span><span class="cx">         return apply_filters( 'bp_current_item', $current_item );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Return the value of $bp->action_variables
+ *
+ * @package BuddyPress
+ *
+ * @param mixed $action_variables The action variables array, or false if the array is empty
+ */
</ins><span class="cx"> function bp_action_variables() {
</span><span class="cx">         global $bp;
</span><span class="cx">         $action_variables = !empty( $bp->action_variables ) ? $bp->action_variables : false;
</span><span class="cx">         return apply_filters( 'bp_action_variables', $action_variables );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Return the value of a given action variable
+ *
+ * @package BuddyPress
+ * @since 1.3
+ *
+ * @param int $position The key of the action_variables array that you want
+ * @return str $action_variable The value of that position in the array
+ */
+function bp_action_variable( $position = 0 ) {
+        $action_variables = bp_action_variables();
+        
+        $action_variable = isset( $action_variables[$position] ) ? $action_variables[$position] : false;
+        
+        return apply_filters( 'bp_action_variable', $action_variable, $position );
+}
+
</ins><span class="cx"> function bp_root_domain() {
</span><span class="cx">         echo bp_get_root_domain();
</span><span class="cx"> }
</span><span class="lines">@@ -676,6 +700,23 @@
</span><span class="cx">         return apply_filters( 'bp_is_current_component', $is_current_component, $component );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Check to see whether the current page matches a given action.
+ *
+ * Along with bp_is_current_component() and bp_is_action_variable(), this function is mostly used
+ * to help determine when to use a given screen function.
+ *
+ * In BP parlance, the current_action is the URL chunk that comes directly after the
+ * current item slug. E.g., in
+ * http://example.com/groups/my-group/members
+ * the current_action is 'members'.
+ *
+ * @package BuddyPress
+ * @since 1.3
+ *
+ * @param str $action The action being tested against
+ * @return bool True if the current action matches $action
+ */
</ins><span class="cx"> function bp_is_current_action( $action = '' ) {
</span><span class="cx">         global $bp;
</span><span class="cx">
</span><span class="lines">@@ -685,6 +726,46 @@
</span><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Check to see whether the current page matches a given action_variable.
+ *
+ * Along with bp_is_current_component() and bp_is_current_action(), this function is mostly used
+ * to help determine when to use a given screen function.
+ *
+ * In BP parlance, action_variables are an array made up of the URL chunks appearing after the
+ * current_action in a URL. For example,
+ * http://example.com/groups/my-group/admin/group-settings
+ * $action_variables[0] is 'group-settings'.
+ *
+ * @package BuddyPress
+ * @since 1.3
+ *
+ * @param str $action_variable The action_variable being tested against
+ * @param int $position The array key you're testing against. If you don't provide a $position,
+ * the function will return true if the $action_variable is found *anywhere* in the action
+ * variables array.
+ * @return bool
+ */
+function bp_is_action_variable( $action_variable = '', $position = false ) {
+        $is_action_variable = false;
+        
+        if ( false !== $position ) {
+                // When a $position is specified, check that slot in the action_variables array                
+                if ( $action_variable ) {
+                        $is_action_variable = $action_variable == bp_action_variable( $position );
+                } else {
+                        // If no $action_variable is provided, we are essentially checking to see
+                        // whether the slot is empty
+                        $is_action_variable = !bp_action_variable( $position );
+                }
+        } else {
+                // When no $position is specified, check the entire array
+                $is_action_variable = in_array( $action_variable, bp_action_variables() );
+        }
+        
+        return apply_filters( 'bp_is_action_variable', $is_action_variable, $action_variable, $position );
+}
+
</ins><span class="cx"> function bp_is_current_item( $item = '' ) {
</span><span class="cx">         if ( !empty( $item ) && $item == bp_current_item() )
</span><span class="cx">                 return true;
</span></span></pre></div>
<a id="trunkbpxprofilebpxprofileactionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-actions.php (4839 => 4840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-actions.php        2011-07-24 19:45:09 UTC (rev 4839)
+++ trunk/bp-xprofile/bp-xprofile-actions.php        2011-07-24 22:22:55 UTC (rev 4840)
</span><span class="lines">@@ -22,8 +22,8 @@
</span><span class="cx"> */
</span><span class="cx"> function xprofile_action_delete_avatar() {
</span><span class="cx">         global $bp;
</span><del>-
-        if ( $bp->profile->id != $bp->current_component || 'change-avatar' != $bp->current_action || !isset( $bp->action_variables[0] ) || 'delete-avatar' != $bp->action_variables[0] )
</del><ins>+        
+        if ( !bp_is_current_component( 'profile' ) || !bp_is_current_action( 'change-avatar' ) || !bp_is_action_variable( 'delete-avatar', 0 ) )
</ins><span class="cx">                 return false;
</span><span class="cx">
</span><span class="cx">         // Check the nonce
</span></span></pre></div>
<a id="trunkbpxprofilebpxprofilescreensphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-screens.php (4839 => 4840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-screens.php        2011-07-24 19:45:09 UTC (rev 4839)
+++ trunk/bp-xprofile/bp-xprofile-screens.php        2011-07-24 22:22:55 UTC (rev 4840)
</span><span class="lines">@@ -36,11 +36,11 @@
</span><span class="cx">                 return false;
</span><span class="cx">
</span><span class="cx">         // Make sure a group is set.
</span><del>-        if ( empty( $bp->action_variables[1] ) )
-                bp_core_redirect( $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/1' );
</del><ins>+        if ( !bp_action_variable( 1 ) )
+                bp_core_redirect( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/1' );
</ins><span class="cx">
</span><span class="cx">         // Check the field group exists
</span><del>-        if ( ( !empty( $bp->action_variables[0] ) && 'group' != $bp->action_variables[0] ) || !xprofile_get_field_group( $bp->action_variables[1] ) ) {
</del><ins>+        if ( !bp_is_action_variable( 'group' ) || !xprofile_get_field_group( bp_action_variable( 1 ) ) ) {
</ins><span class="cx">                 bp_do_404();
</span><span class="cx">                 return;
</span><span class="cx">         }
</span><span class="lines">@@ -53,7 +53,7 @@
</span><span class="cx">
</span><span class="cx">                 // Check we have field ID's
</span><span class="cx">                 if ( empty( $_POST['field_ids'] ) )
</span><del>-                        bp_core_redirect( trailingslashit( $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . $bp->action_variables[1] ) );
</del><ins>+                        bp_core_redirect( trailingslashit( $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . bp_action_variable( 1 ) ) );
</ins><span class="cx">
</span><span class="cx">                 // Explode the posted field IDs into an array so we know which
</span><span class="cx">                 // fields have been submitted
</span><span class="lines">@@ -67,9 +67,7 @@
</span><span class="cx">
</span><span class="cx">                                 if ( !empty( $_POST['field_' . $field_id . '_day'] ) && is_numeric( $_POST['field_' . $field_id . '_day'] ) ) {
</span><span class="cx">                                         // Concatenate the values
</span><del>-                                        $date_value = $_POST['field_' . $field_id . '_day'] . ' ' .
-                                                                        $_POST['field_' . $field_id . '_month'] . ' ' .
-                                                                        $_POST['field_' . $field_id . '_year'];
</del><ins>+                                        $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
</ins><span class="cx">
</span><span class="cx">                                         // Turn the concatenated value into a timestamp
</span><span class="cx">                                         $_POST['field_' . $field_id] = strtotime( $date_value );
</span><span class="lines">@@ -115,7 +113,7 @@
</span><span class="cx">                                 bp_core_add_message( __( 'Changes saved.', 'buddypress' ) );
</span><span class="cx">
</span><span class="cx">                         // Redirect back to the edit screen to display the updates and message
</span><del>-                        bp_core_redirect( trailingslashit( $bp->displayed_user->domain . $bp->profile->slug . '/edit/group/' . $bp->action_variables[1] ) );
</del><ins>+                        bp_core_redirect( trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable( 1 ) ) );
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -136,7 +134,7 @@
</span><span class="cx">         if ( !bp_is_my_profile() && !is_super_admin() )
</span><span class="cx">                 return false;
</span><span class="cx">
</span><del>-        if ( !empty( $bp->action_variables ) ) {
</del><ins>+        if ( bp_action_variables() ) {
</ins><span class="cx">                 bp_do_404();
</span><span class="cx">                 return;
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkbpxprofilebpxprofiletemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-template.php (4839 => 4840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-template.php        2011-07-24 19:45:09 UTC (rev 4839)
+++ trunk/bp-xprofile/bp-xprofile-template.php        2011-07-24 22:22:55 UTC (rev 4840)
</span><span class="lines">@@ -694,18 +694,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function bp_profile_group_name( $deprecated = true ) {
</span><del>-        global $bp;
-
-        $group_id = !empty( $bp->action_variables[1] ) ? $bp->action_variables[1] : 1;
-
-        if ( !is_numeric( $group_id ) )
-                $group_id = 1;
-
-        if ( !$group = wp_cache_get( 'xprofile_group_' . $group_id, 'bp' ) ) {
-                $group = new BP_XProfile_Group($group_id);
-                wp_cache_set( 'xprofile_group_' . $group_id, $group, 'bp' );
-        }
-
</del><span class="cx">         if ( !$deprecated ) {
</span><span class="cx">                 return bp_get_profile_group_name();
</span><span class="cx">         } else {
</span><span class="lines">@@ -713,10 +701,9 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx">         function bp_get_profile_group_name() {
</span><del>-                global $bp;
-
-                $group_id = !empty( $bp->action_variables[1] ) ? $bp->action_variables[1] : 1;
-
</del><ins>+                if ( !$group_id = bp_action_variable( 1 ) )
+                        $group_id = 1;
+                        
</ins><span class="cx">                 if ( !is_numeric( $group_id ) )
</span><span class="cx">                         $group_id = 1;
</span><span class="cx">
</span><span class="lines">@@ -763,9 +750,7 @@
</span><span class="cx">         echo bp_get_current_profile_group_id();
</span><span class="cx"> }
</span><span class="cx">         function bp_get_current_profile_group_id() {
</span><del>-                global $bp;
-
-                if ( empty( $bp->action_variables[1] ) || !$profile_group_id = $bp->action_variables[1] )
</del><ins>+                if ( !$profile_group_id = bp_action_variable( 1 ) )
</ins><span class="cx">                         $profile_group_id = 1;
</span><span class="cx">
</span><span class="cx">                 return apply_filters( 'bp_get_current_profile_group_id', $profile_group_id ); // admin/profile/edit/[group-id]
</span></span></pre>
</div>
</div>
</body>
</html>