<!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][4337] trunk: Redirects user back to activity stream after single activity item delete.</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>4337</dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2011-05-09 20:40:25 +0000 (Mon, 09 May 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Redirects user back to activity stream after single activity item delete. Removes AJAX from delete link on activity permalink page. Fixes #2002. Props cnorris23</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivityactionsphp">trunk/bp-activity/bp-activity-actions.php</a></li>
<li><a href="#trunkbpactivitybpactivitytemplatephp">trunk/bp-activity/bp-activity-template.php</a></li>
<li><a href="#trunkbpthemesbpdefault_incajaxphp">trunk/bp-themes/bp-default/_inc/ajax.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivityactionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-actions.php (4336 => 4337)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-actions.php        2011-05-08 17:04:21 UTC (rev 4336)
+++ trunk/bp-activity/bp-activity-actions.php        2011-05-09 20:40:25 UTC (rev 4337)
</span><span class="lines">@@ -63,26 +63,38 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
</span><span class="cx"> 
</span><del>-function bp_activity_action_delete_activity() {
</del><ins>+/**
+ * bp_activity_action_delete_activity()
+ *
+ * Delete specific activity item and redirect to previous page.
+ *
+ * @global object $bp
+ * @since 1.1
+ * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow actions to be taken after the activity is deleted.
+ * @uses do_action() Calls 'bp_activity_before_action_delete_activity' hook to allow actions to be taken before the activity is deleted.
+ */
+function bp_activity_action_delete_activity( $activity_id = 0 ) {
</ins><span class="cx">         global $bp;
</span><span class="cx"> 
</span><span class="cx">         // Not viewing activity or action is not delete
</span><del>-        if ( ( $bp-&gt;activity-&gt;slug != bp_current_component() ) || !bp_is_current_action( 'delete' ) )
</del><ins>+        if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><ins>+        if ( empty( $activity_id ) &amp;&amp; !empty( $bp-&gt;action_variables[0] ) &amp;&amp; is_numeric( $bp-&gt;action_variables[0] ) )
+                $activity_id = (int) $bp-&gt;action_variables[0];
+
</ins><span class="cx">         // Not viewing a specific activity item
</span><del>-        if ( empty( $bp-&gt;action_variables[0] ) || !is_numeric( $bp-&gt;action_variables[0] ) )
</del><ins>+        if ( empty( $activity_id ) )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         // Check the nonce
</span><span class="cx">         check_admin_referer( 'bp_activity_delete_link' );
</span><span class="cx"> 
</span><span class="cx">         // Load up the activity item
</span><del>-        $activity_id = $bp-&gt;action_variables[0];
-        $activity    = new BP_Activity_Activity( $activity_id );
</del><ins>+        $activity = new BP_Activity_Activity( $activity_id );
</ins><span class="cx"> 
</span><span class="cx">         // Check access
</span><del>-        if ( !is_super_admin() &amp;&amp; $activity-&gt;user_id != $bp-&gt;loggedin_user-&gt;id )
</del><ins>+        if ( empty( $activity-&gt;user_id ) || !is_super_admin() &amp;&amp; $activity-&gt;user_id != bp_loggedin_user_id() )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         // Call the action before the delete so plugins can still fetch information about it
</span><span class="lines">@@ -90,14 +102,17 @@
</span><span class="cx"> 
</span><span class="cx">         // Delete the activity item and provide user feedback
</span><span class="cx">         if ( bp_activity_delete( array( 'id' =&gt; $activity_id, 'user_id' =&gt; $activity-&gt;user_id ) ) )
</span><del>-                bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
</del><ins>+                bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) );
</ins><span class="cx">         else
</span><span class="cx">                 bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
</span><span class="cx"> 
</span><span class="cx">         do_action( 'bp_activity_action_delete_activity', $activity_id, $activity-&gt;user_id );
</span><span class="cx"> 
</span><del>-        // Redirect
-        bp_core_redirect( wp_get_referer() );
</del><ins>+        // Check for the redirect query arg, otherwise let WP handle things
+         if ( !empty( $_GET['redirect_to'] ) )
+                bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
+        else
+                bp_core_redirect( wp_get_referer() );
</ins><span class="cx"> }
</span><span class="cx"> add_action( 'bp_actions', 'bp_activity_action_delete_activity' );
</span><span class="cx"> 
</span><span class="lines">@@ -218,7 +233,7 @@
</span><span class="cx"> 
</span><span class="cx"> function bp_activity_action_sitewide_feed() {
</span><span class="cx">         global $bp, $wp_query;
</span><del>-        
</del><ins>+
</ins><span class="cx">         if ( !bp_is_current_component( 'activity' ) || !bp_is_current_action( 'feed' ) || bp_is_user() || !empty( $bp-&gt;groups-&gt;current_group ) )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkbpactivitybpactivitytemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-template.php (4336 => 4337)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-template.php        2011-05-08 17:04:21 UTC (rev 4336)
+++ trunk/bp-activity/bp-activity-template.php        2011-05-09 20:40:25 UTC (rev 4337)
</span><span class="lines">@@ -394,10 +394,10 @@
</span><span class="cx">  */
</span><span class="cx"> function bp_activity_has_more_items() {
</span><span class="cx">         global $activities_template;
</span><del>-        
-        $remaining_pages = floor( ( $activities_template-&gt;total_activity_count - 1 ) / ( $activities_template-&gt;pag_num * $activities_template-&gt;pag_page ) ); 
</del><ins>+
+        $remaining_pages = floor( ( $activities_template-&gt;total_activity_count - 1 ) / ( $activities_template-&gt;pag_num * $activities_template-&gt;pag_page ) );
</ins><span class="cx">         $has_more_items  = (int)$remaining_pages ? true : false;
</span><del>-        
</del><ins>+
</ins><span class="cx">         return apply_filters( 'bp_activity_has_more_items', $has_more_items );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -504,7 +504,7 @@
</span><span class="cx"> }
</span><span class="cx">         function bp_get_activity_user_link() {
</span><span class="cx">                 global $activities_template;
</span><del>-                
</del><ins>+
</ins><span class="cx">                 if ( empty( $activities_template-&gt;activity-&gt;user_id ) )
</span><span class="cx">                         $link = $activities_template-&gt;activity-&gt;primary_link;
</span><span class="cx">                 else
</span><span class="lines">@@ -722,13 +722,13 @@
</span><span class="cx"> 
</span><span class="cx">         if ( $bp-&gt;loggedin_user-&gt;is_super_admin )
</span><span class="cx">                 $can_delete = true;
</span><del>-        
</del><ins>+
</ins><span class="cx">         if ( $activities_template-&gt;activity-&gt;user_id == $bp-&gt;loggedin_user-&gt;id )
</span><span class="cx">                 $can_delete = true;
</span><del>-                
</del><ins>+
</ins><span class="cx">         if ( $bp-&gt;is_item_admin &amp;&amp; $bp-&gt;is_single_item )
</span><span class="cx">                 $can_delete = true;
</span><del>-        
</del><ins>+
</ins><span class="cx">         return apply_filters( 'bp_activity_user_can_delete', $can_delete );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -801,7 +801,7 @@
</span><span class="cx">                         foreach ( (array)$comment-&gt;children as $comment_child ) {
</span><span class="cx">                                 // Put the comment into the global so it's available to filters
</span><span class="cx">                                 $activities_template-&gt;activity-&gt;current_comment = $comment_child;
</span><del>-                                
</del><ins>+
</ins><span class="cx">                                 if ( empty( $comment_child-&gt;user_fullname ) )
</span><span class="cx">                                         $comment_child-&gt;user_fullname = $comment_child-&gt;display_name;
</span><span class="cx"> 
</span><span class="lines">@@ -853,7 +853,7 @@
</span><span class="cx"> 
</span><span class="cx">                                 $content .= bp_activity_recurse_comments( $comment_child );
</span><span class="cx">                                 $content .= '&lt;/li&gt;';
</span><del>-                                
</del><ins>+
</ins><span class="cx">                                 // Unset in the global in case of the last iteration
</span><span class="cx">                                 unset( $activities_template-&gt;activity-&gt;current_comment );
</span><span class="cx">                         }
</span><span class="lines">@@ -978,13 +978,42 @@
</span><span class="cx">                 return apply_filters( 'bp_get_activity_css_class', $activities_template-&gt;activity-&gt;component . ' ' . $activities_template-&gt;activity-&gt;type . $class );
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+/**
+ * bp_activity_delete_link()
+ *
+ * Display the activity delete link.
+ *
+ * @since 1.1
+ * @uses bp_get_activity_delete_link()
+ */
</ins><span class="cx"> function bp_activity_delete_link() {
</span><span class="cx">         echo bp_get_activity_delete_link();
</span><span class="cx"> }
</span><ins>+
+        /**
+         * bp_get_activity_delete_link()
+         *
+         * Return the activity delete link.
+         *
+         * @global object $activities_template BuddyPress Activities Template
+         * @global object $bp BuddyPress global settings
+         * @return string $link Activity delete link. Contains $redirect_to arg if on single activity page.
+         * @since 1.1
+         */
</ins><span class="cx">         function bp_get_activity_delete_link() {
</span><span class="cx">                 global $activities_template, $bp;
</span><span class="cx"> 
</span><del>-                return apply_filters( 'bp_get_activity_delete_link', '&lt;a href=&quot;' . wp_nonce_url( bp_get_root_domain() . '/' . $bp-&gt;activity-&gt;slug . '/delete/' . $activities_template-&gt;activity-&gt;id, 'bp_activity_delete_link' ) . '&quot; class=&quot;item-button delete-activity confirm&quot; rel=&quot;nofollow&quot;&gt;' . __( 'Delete', 'buddypress' ) . '&lt;/a&gt;' );
</del><ins>+                $url   = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template-&gt;activity-&gt;id;
+                $class = 'delete-activity';
+
+                // Determine if we're on a single activity page, and customize accordingly
+                if ( bp_is_activity_component() &amp;&amp; is_numeric( bp_current_action() ) ) {
+                        $url   = add_query_arg( array( 'redirect_to' =&gt; wp_get_referer() ), $url );
+                        $class = 'delete-activity-single';
+                }
+
+                $link = '&lt;a href=&quot;' . wp_nonce_url( $url, 'bp_activity_delete_link' ) . '&quot; class=&quot;item-button ' . $class . ' confirm&quot; rel=&quot;nofollow&quot;&gt;' . __( 'Delete', 'buddypress' ) . '&lt;/a&gt;';
+                return apply_filters( 'bp_get_activity_delete_link', $link );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx"> function bp_activity_latest_update( $user_id = 0 ) {
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_incajaxphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/ajax.php (4336 => 4337)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/ajax.php        2011-05-08 17:04:21 UTC (rev 4336)
+++ trunk/bp-themes/bp-default/_inc/ajax.php        2011-05-09 20:40:25 UTC (rev 4337)
</span><span class="lines">@@ -53,8 +53,8 @@
</span><span class="cx">         if ( !empty( $_POST['page'] ) &amp;&amp; '-1' != $_POST['page'] )
</span><span class="cx">                 $qs[] = 'page=' . $_POST['page'];
</span><span class="cx"> 
</span><del>-        $object_search_text = bp_get_search_default_text( $object ); 
-         if ( !empty( $_POST['search_terms'] ) &amp;&amp; $object_search_text != $_POST['search_terms'] &amp;&amp; 'false' != $_POST['search_terms'] &amp;&amp; 'undefined' != $_POST['search_terms'] ) 
</del><ins>+        $object_search_text = bp_get_search_default_text( $object );
+         if ( !empty( $_POST['search_terms'] ) &amp;&amp; $object_search_text != $_POST['search_terms'] &amp;&amp; 'false' != $_POST['search_terms'] &amp;&amp; 'undefined' != $_POST['search_terms'] )
</ins><span class="cx">                 $qs[] = 'search_terms=' . $_POST['search_terms'];
</span><span class="cx"> 
</span><span class="cx">         /* Now pass the querystring to override default values. */
</span><span class="lines">@@ -246,21 +246,21 @@
</span><span class="cx">         if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        $activity = new BP_Activity_Activity( $_POST['id'] );
</del><ins>+        $activity = new BP_Activity_Activity( (int) $_POST['id'] );
</ins><span class="cx"> 
</span><span class="cx">         // Check access
</span><del>-        if ( !is_super_admin() &amp;&amp; $activity-&gt;user_id != $bp-&gt;loggedin_user-&gt;id )
</del><ins>+        if ( !is_super_admin() &amp;&amp; ( $activity-&gt;user_id != bp_loggedin_user_id() ) )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         // Call the action before the delete so plugins can still fetch information about it
</span><del>-        do_action( 'bp_activity_before_action_delete_activity', $_POST['id'], $activity-&gt;user_id );
</del><ins>+        do_action( 'bp_activity_before_action_delete_activity', $activity-&gt;id, $activity-&gt;user_id );
</ins><span class="cx"> 
</span><del>-        if ( !bp_activity_delete( array( 'id' =&gt; $_POST['id'], 'user_id' =&gt; $activity-&gt;user_id ) ) ) {
</del><ins>+        if ( !bp_activity_delete( array( 'id' =&gt; $activity-&gt;id, 'user_id' =&gt; $activity-&gt;user_id ) ) ) {
</ins><span class="cx">                 echo '-1&lt;div id=&quot;message&quot; class=&quot;error&quot;&gt;&lt;p&gt;' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '&lt;/p&gt;&lt;/div&gt;';
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        do_action( 'bp_activity_action_delete_activity', $_POST['id'], $activity-&gt;user_id );
</del><ins>+        do_action( 'bp_activity_action_delete_activity', $activity-&gt;id, $activity-&gt;user_id );
</ins><span class="cx"> 
</span><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="lines">@@ -326,23 +326,23 @@
</span><span class="cx">  * @since 1.3
</span><span class="cx">  */
</span><span class="cx"> function bp_dtheme_get_single_activity_content() {
</span><del>-        $activity_array = bp_activity_get_specific( array( 
-                'activity_ids'                 =&gt; $_POST['activity_id'], 
-                'display_comments'         =&gt; 'stream' 
</del><ins>+        $activity_array = bp_activity_get_specific( array(
+                'activity_ids'                 =&gt; $_POST['activity_id'],
+                'display_comments'         =&gt; 'stream'
</ins><span class="cx">         ) );
</span><del>-        
</del><ins>+
</ins><span class="cx">         $activity = !empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
</span><del>-        
</del><ins>+
</ins><span class="cx">         if ( !$activity )
</span><span class="cx">                 exit(); // todo: error?
</span><del>-        
</del><ins>+
</ins><span class="cx">         // Activity content retrieved through AJAX should run through normal filters, but not be
</span><span class="cx">         // truncated
</span><span class="cx">         remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
</span><span class="cx">         $content = apply_filters( 'bp_get_activity_content_body', $activity-&gt;content );
</span><del>-        
</del><ins>+
</ins><span class="cx">         echo $content;
</span><del>-        
</del><ins>+
</ins><span class="cx">         exit();
</span><span class="cx"> }
</span><span class="cx"> add_action( 'wp_ajax_get_single_activity_content', 'bp_dtheme_get_single_activity_content' );
</span><span class="lines">@@ -647,7 +647,7 @@
</span><span class="cx">                         if ( !$ud )
</span><span class="cx">                                 continue;
</span><span class="cx"> 
</span><del>-                        if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) 
</del><ins>+                        if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
</ins><span class="cx">                                 $username = $ud-&gt;user_login;
</span><span class="cx">                         else
</span><span class="cx">                                 $username = $ud-&gt;user_nicename;
</span></span></pre>
</div>
</div>

</body>
</html>