<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [2217] trunk:
Removing activity comment posting logic from the theme, where it doesn'
t belong.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>2217</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-12-27 15:05:26 +0000 (Sun, 27 Dec 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Removing activity comment posting logic from the theme, where it doesn't belong. Removing duplication of activity item template.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivityphp">trunk/bp-activity.php</a></li>
<li><a href="#trunkbpgroupsphp">trunk/bp-groups.php</a></li>
<li><a href="#trunkbpthemesbpdefault_incajaxphp">trunk/bp-themes/bp-default/_inc/ajax.php</a></li>
<li><a href="#trunkbpthemesbpdefaultactivityactivityloopphp">trunk/bp-themes/bp-default/activity/activity-loop.php</a></li>
<li><a href="#trunkbpthemesbpdefaultactivityentryphp">trunk/bp-themes/bp-default/activity/entry.php</a></li>
<li><a href="#trunkbpxprofilephp">trunk/bp-xprofile.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivityphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity.php (2216 => 2217)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity.php        2009-12-27 14:46:30 UTC (rev 2216)
+++ trunk/bp-activity.php        2009-12-27 15:05:26 UTC (rev 2217)
</span><span class="lines">@@ -395,6 +395,42 @@
</span><span class="cx">         return $activity->id;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+function bp_activity_new_comment( $args = '' ) {
+        global $bp;
+
+        $defaults = array(
+                'content' => false,
+                'user_id' => $bp->loggedin_user->id,
+                'activity_id' => false, // ID of the root activity item
+                'parent_id' => false // ID of a parent comment (optional)
+        );
+
+        $r = wp_parse_args( $args, $defaults );
+        extract( $r, EXTR_SKIP );
+
+        if ( empty($content) || empty($user_id) || empty($activity_id) )
+                return false;
+
+        if ( empty($parent_id) )
+                $parent_id = $activity_id;
+
+        /* Insert the "user posted a new activity comment header text" */
+        $comment_header = '<div class="comment-header">' . sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) . ' <span class="time-since">%s</span></div> ';
+
+        /* Insert the activity comment */
+        $comment_id = bp_activity_add( array(
+                'content' => apply_filters( 'bp_activity_comment_content', $comment_header . '<div class="activity-inner">' . $content . '</div>' ),
+                'primary_link' => '',
+                'component_name' => $bp->activity->id,
+                'component_action' => 'activity_comment',
+                'user_id' => $user_id,
+                'item_id' => $activity_id,
+                'secondary_item_id' => $parent_id
+        ) );
+
+        return $comment_id;
+}
+
</ins><span class="cx"> /* There are multiple ways to delete activity items, depending on the information you have at the time. */
</span><span class="cx">
</span><span class="cx"> function bp_activity_delete_by_item_id( $args = '' ) {
</span></span></pre></div>
<a id="trunkbpgroupsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups.php (2216 => 2217)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups.php        2009-12-27 14:46:30 UTC (rev 2216)
+++ trunk/bp-groups.php        2009-12-27 15:05:26 UTC (rev 2217)
</span><span class="lines">@@ -1978,29 +1978,31 @@
</span><span class="cx">
</span><span class="cx"> /*** Group Activity Posting **************************************************/
</span><span class="cx">
</span><del>-function groups_post_update( $content, $user_id = false, $group_id = false ) {
</del><ins>+function groups_post_update( $args = '' ) {
</ins><span class="cx">         global $bp;
</span><span class="cx">
</span><del>-        if ( !$user_id )
-                $user_id = $bp->loggedin_user->id;
</del><ins>+        $defaults = array(
+                'content' => false,
+                'user_id' => $bp->loggedin_user->id,
+                'group_id' => false
+        );
</ins><span class="cx">
</span><del>-        if ( !$group_id )
-                $group_id = $bp->groups->current_group->id;
</del><ins>+        $r = wp_parse_args( $args, $defaults );
+        extract( $r, EXTR_SKIP );
</ins><span class="cx">
</span><del>-        if ( !$group_id )
</del><ins>+        if ( empty($content) || empty($user_id) || empty($group_id) )
</ins><span class="cx">                 return false;
</span><span class="cx">
</span><del>-        if ( !$bp->groups->current_group )
-                $bp->groups->current_group = new BP_Groups_Group( $group_id );
</del><ins>+        $group = new BP_Groups_Group( $group_id );
</ins><span class="cx">
</span><span class="cx">         /* Record this in activity streams */
</span><del>-        $activity_content = sprintf( __( '%s posted an update in the group %s:', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' );
</del><ins>+        $activity_content = sprintf( __( '%s posted an update in the group %s:', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . attribute_escape( $group->name ) . '</a>' );
</ins><span class="cx">         $activity_content .= '<div class="activity-inner">' . $content . '</div>';
</span><span class="cx">
</span><span class="cx">         $activity_id = groups_record_activity( array(
</span><span class="cx">                 'user_id' => $user_id,
</span><span class="cx">                 'content' => apply_filters( 'groups_activity_new_wire_post', $activity_content ),
</span><del>-                'primary_link' => apply_filters( 'groups_activity_new_wire_post_primary_link', bp_get_group_permalink( $bp->groups->current_group ) ),
</del><ins>+                'primary_link' => apply_filters( 'groups_activity_new_wire_post_primary_link', bp_get_group_permalink( $group ) ),
</ins><span class="cx">                 'component_action' => 'new_wire_post',
</span><span class="cx">                 'item_id' => $item_id
</span><span class="cx">         ) );
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_incajaxphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/ajax.php (2216 => 2217)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/ajax.php        2009-12-27 14:46:30 UTC (rev 2216)
+++ trunk/bp-themes/bp-default/_inc/ajax.php        2009-12-27 15:05:26 UTC (rev 2217)
</span><span class="lines">@@ -177,10 +177,16 @@
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if ( (int)$_POST['group'] )
-                $activity_id = groups_post_update( $_POST['content'], $bp->loggedin_user->id, $_POST['group'] );
-        else
-                $activity_id = xprofile_post_update( $_POST['content'], $bp->loggedin_user->id );
</del><ins>+        if ( (int)$_POST['group'] ) {
+                $activity_id = groups_post_update( array(
+                        'content' => $_POST['content'],
+                        'group_id' => $_POST['group']
+                ));
+        } else {
+                $activity_id = xprofile_post_update( array(
+                        'content' => $_POST['content']
+                ));
+        }
</ins><span class="cx">
</span><span class="cx">         if ( !$activity_id ) {
</span><span class="cx">                 echo '-1<div id="message" class="error"><p>' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '</p></div>';
</span><span class="lines">@@ -216,22 +222,12 @@
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        /* TODO - move the business logic to the activity plugin */
</del><ins>+        $comment_id = bp_activity_new_comment( array(
+                'content' => $_POST['content'],
+                'activity_id' => $_POST['form_id'],
+                'parent_id' => $_POST['comment_id']
+        ));
</ins><span class="cx">
</span><del>-        /* Insert the "user posted a new activity comment header text" */
-        $comment_header = '<div class="comment-header">' . sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $bp->loggedin_user->id ) ) . ' <span class="time-since">%s</span></div> ';
-
-        /* Insert the activity comment */
-        $comment_id = bp_activity_add( array(
-                'content' => apply_filters( 'bp_activity_comment_content', $comment_header . '<div class="activity-inner">' . $_POST['content'] . '</div>' ),
-                'primary_link' => '',
-                'component_name' => $bp->activity->id,
-                'component_action' => 'activity_comment',
-                'user_id' => $bp->loggedin_user->id,
-                'item_id' => $_POST['form_id'],
-                'secondary_item_id' => $_POST['comment_id']
-        ) );
-
</del><span class="cx">         if ( !$comment_id ) {
</span><span class="cx">                 echo '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>';
</span><span class="cx">                 return false;
</span></span></pre></div>
<a id="trunkbpthemesbpdefaultactivityactivityloopphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/activity/activity-loop.php (2216 => 2217)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/activity/activity-loop.php        2009-12-27 14:46:30 UTC (rev 2216)
+++ trunk/bp-themes/bp-default/activity/activity-loop.php        2009-12-27 15:05:26 UTC (rev 2217)
</span><span class="lines">@@ -7,59 +7,8 @@
</span><span class="cx">
</span><span class="cx">         <?php while ( bp_activities() ) : bp_the_activity(); ?>
</span><span class="cx">
</span><del>-                <li class="<?php bp_activity_css_class() ?>" id="activity-<?php bp_activity_id() ?>">
-                        <div class="activity-avatar">
-                                <?php bp_activity_avatar( 'type=full&width=60&height=60' ) ?>
-                        </div>
</del><ins>+                <?php include( locate_template( array( 'activity/entry.php' ), false ) ) ?>
</ins><span class="cx">
</span><del>-                        <div class="activity-content">
-                                <?php bp_activity_content() ?>
-
-                                <div class="activity-meta">
-                                        <?php if ( is_user_logged_in() && bp_activity_can_comment() ) : ?>
-                                                <a href="#acomment-<?php bp_activity_id() ?>" class="acomment-reply" id="acomment-comment-<?php bp_activity_id() ?>"><?php _e( 'Comment', 'buddypress' ) ?> (<?php bp_activity_comment_count() ?>)</a>
-                                        <?php endif; ?>
-
-                                        <?php if ( !bp_is_activity_permalink() ) : ?>
-                                                <a href="<?php bp_activity_thread_permalink() ?>" class="view" title="<?php _e( 'View Thread', 'buddypress' ) ?>"><?php _e( 'View Thread', 'buddypress' ) ?></a>
-                                        <?php endif; ?>
-
-                                        <?php if ( is_user_logged_in() ) : ?>
-                                                <?php if ( !bp_get_activity_is_favorite() ) : ?>
-                                                        <a href="" class="fav" title="<?php _e( 'Mark Favorite', 'buddypress' ) ?>"><?php _e( 'Mark Favorite', 'buddypress' ) ?></a>
-                                                <?php else : ?>
-                                                        <a href="" class="unfav" title="<?php _e( 'Remove Favorite', 'buddypress' ) ?>"><?php _e( 'Remove Favorite', 'buddypress' ) ?></a>
-                                                <?php endif; ?>
-                                        <?php endif;?>
-                                </div>
-                        </div>
-
-                        <?php if ( 'activity_comment' == bp_get_activity_action_name() ) : ?>
-                                <div class="activity-inreplyto">
-                                        <strong><?php _e( 'In reply to', 'buddypress' ) ?></strong> - <?php bp_activity_parent_content() ?>
-                                </div>
-                        <?php endif; ?>
-
-                        <?php if ( bp_activity_can_comment() ) : ?>
-                                <div class="activity-comments">
-                                        <?php bp_activity_comments() ?>
-
-                                        <?php if ( is_user_logged_in() ) : ?>
-                                        <form action="" method="post" name="activity-comment-form" id="ac-form-<?php bp_activity_id() ?>" class="ac-form">
-                                                <div class="ac-reply-avatar"><?php bp_loggedin_user_avatar( 'width=25&height=25' ) ?></div>
-                                                <div class="ac-reply-content">
-                                                        <div class="ac-textarea">
-                                                                <textarea id="ac-input-<?php bp_activity_id() ?>" class="ac-input" name="ac-input-<?php bp_activity_id() ?>"></textarea>
-                                                        </div>
-                                                        <input type="submit" name="ac-form-submit" value="<?php _e( 'Post', 'buddypress' ) ?> &rarr;" /> &nbsp; <?php _e( 'or press esc to cancel.', 'buddypress' ) ?>
-                                                </div>
-                                                <?php wp_nonce_field( 'new_activity_comment', '_wpnonce_new_activity_comment' ) ?>
-                                        </form>
-                                        <?php endif; ?>
-                                </div>
-                        <?php endif; ?>
-                </li>
-
</del><span class="cx">         <?php endwhile; ?>
</span><span class="cx">
</span><span class="cx">                 <li class="load-more">
</span></span></pre></div>
<a id="trunkbpthemesbpdefaultactivityentryphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/activity/entry.php (2216 => 2217)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/activity/entry.php        2009-12-27 14:46:30 UTC (rev 2216)
+++ trunk/bp-themes/bp-default/activity/entry.php        2009-12-27 15:05:26 UTC (rev 2217)
</span><span class="lines">@@ -1,34 +1,53 @@
</span><span class="cx"> <?php /* This template is used by permalink pages and AJAX functions to load in new updates */ ?>
</span><span class="cx"> <li class="<?php bp_activity_css_class() ?> new-update" id="activity-<?php bp_activity_id() ?>">
</span><span class="cx">         <div class="activity-avatar">
</span><del>-                <?php bp_activity_avatar('width=40&height=40') ?>
</del><ins>+                <?php bp_activity_avatar( 'type=full&width=60&height=60' ) ?>
</ins><span class="cx">         </div>
</span><span class="cx">
</span><span class="cx">         <div class="activity-content">
</span><span class="cx">                 <?php bp_activity_content() ?>
</span><span class="cx">
</span><del>-                <?php if ( is_user_logged_in() ) : ?>
</del><span class="cx">                 <div class="activity-meta">
</span><del>-                        <a href="#acomment-<?php bp_activity_id() ?>" class="acomment-reply" id="acomment-comment-<?php bp_activity_id() ?>"><?php _e( 'Comment', 'buddypress' ) ?> (<?php bp_activity_comment_count() ?>)</a>
</del><ins>+                        <?php if ( is_user_logged_in() && bp_activity_can_comment() ) : ?>
+                                <a href="#acomment-<?php bp_activity_id() ?>" class="acomment-reply" id="acomment-comment-<?php bp_activity_id() ?>"><?php _e( 'Comment', 'buddypress' ) ?> (<?php bp_activity_comment_count() ?>)</a>
+                        <?php endif; ?>
+
+                        <?php if ( !bp_is_activity_permalink() ) : ?>
+                                <a href="<?php bp_activity_thread_permalink() ?>" class="view" title="<?php _e( 'View Thread', 'buddypress' ) ?>"><?php _e( 'View Thread', 'buddypress' ) ?></a>
+                        <?php endif; ?>
+
+                        <?php if ( is_user_logged_in() ) : ?>
+                                <?php if ( !bp_get_activity_is_favorite() ) : ?>
+                                        <a href="" class="fav" title="<?php _e( 'Mark Favorite', 'buddypress' ) ?>"><?php _e( 'Mark Favorite', 'buddypress' ) ?></a>
+                                <?php else : ?>
+                                        <a href="" class="unfav" title="<?php _e( 'Remove Favorite', 'buddypress' ) ?>"><?php _e( 'Remove Favorite', 'buddypress' ) ?></a>
+                                <?php endif; ?>
+                        <?php endif;?>
</ins><span class="cx">                 </div>
</span><del>-                <?php endif; ?>
</del><span class="cx">         </div>
</span><span class="cx">
</span><del>-        <div class="activity-comments">
-                <?php bp_activity_comments() ?>
</del><ins>+        <?php if ( 'activity_comment' == bp_get_activity_action_name() ) : ?>
+                <div class="activity-inreplyto">
+                        <strong><?php _e( 'In reply to', 'buddypress' ) ?></strong> - <?php bp_activity_parent_content() ?>
+                </div>
+        <?php endif; ?>
</ins><span class="cx">
</span><del>-                <?php if ( is_user_logged_in() ) : ?>
-                <form action="" method="post" name="activity-comment-form" id="ac-form-<?php bp_activity_id() ?>" class="ac-form">
-                        <div class="ac-reply-avatar"><?php bp_loggedin_user_avatar( 'width=25&height=25' ) ?></div>
-                        <div class="ac-reply-content">
-                                <div class="ac-textarea">
-                                        <textarea id="ac-input-<?php bp_activity_id() ?>" class="ac-input" name="ac-input-<?php bp_activity_id() ?>"></textarea>
</del><ins>+        <?php if ( bp_activity_can_comment() ) : ?>
+                <div class="activity-comments">
+                        <?php bp_activity_comments() ?>
+
+                        <?php if ( is_user_logged_in() ) : ?>
+                        <form action="" method="post" name="activity-comment-form" id="ac-form-<?php bp_activity_id() ?>" class="ac-form">
+                                <div class="ac-reply-avatar"><?php bp_loggedin_user_avatar( 'width=25&height=25' ) ?></div>
+                                <div class="ac-reply-content">
+                                        <div class="ac-textarea">
+                                                <textarea id="ac-input-<?php bp_activity_id() ?>" class="ac-input" name="ac-input-<?php bp_activity_id() ?>"></textarea>
+                                        </div>
+                                        <input type="submit" name="ac-form-submit" value="<?php _e( 'Post', 'buddypress' ) ?> &rarr;" /> &nbsp; <?php _e( 'or press esc to cancel.', 'buddypress' ) ?>
</ins><span class="cx">                                 </div>
</span><del>-
-                                <input type="submit" name="ac-form-submit" value="<?php _e( 'Post', 'buddypress' ) ?> &rarr;" /> &nbsp; <?php _e( 'or press esc to cancel.', 'buddypress' ) ?>
-                        </div>
-                        <?php wp_nonce_field( 'new_activity_comment', '_wpnonce_new_activity_comment' ) ?>
-                </form>
-                <?php endif; ?>
-        </div>
-</li>
</del><span class="cx">\ No newline at end of file
</span><ins>+                                <?php wp_nonce_field( 'new_activity_comment', '_wpnonce_new_activity_comment' ) ?>
+                        </form>
+                        <?php endif; ?>
+                </div>
+        <?php endif; ?>
+</li>
</ins></span></pre></div>
<a id="trunkbpxprofilephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile.php (2216 => 2217)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile.php        2009-12-27 14:46:30 UTC (rev 2216)
+++ trunk/bp-xprofile.php        2009-12-27 15:05:26 UTC (rev 2217)
</span><span class="lines">@@ -742,12 +742,20 @@
</span><span class="cx"> * true or false on success or failure.
</span><span class="cx"> */
</span><span class="cx">
</span><del>-function xprofile_post_update( $content, $user_id = false ) {
</del><ins>+function xprofile_post_update( $args = '' ) {
</ins><span class="cx">         global $bp;
</span><span class="cx">
</span><del>-        if ( !$user_id )
-                $user_id = $bp->loggedin_user->id;
</del><ins>+        $defaults = array(
+                'content' => false,
+                'user_id' => $bp->loggedin_user->id
+        );
</ins><span class="cx">
</span><ins>+        $r = wp_parse_args( $args, $defaults );
+        extract( $r, EXTR_SKIP );
+
+        if ( empty($content) || empty($content) )
+                return false;
+
</ins><span class="cx">         /* Record this on the user's profile */
</span><span class="cx">         $from_user_link = bp_core_get_userlink( $user_id );
</span><span class="cx">         $activity_content = sprintf( __('%s posted an update:', 'buddypress'), $from_user_link );
</span></span></pre>
</div>
</div>
</body>
</html>