<!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] [2152] trunk:
  Replaced pagination on sitewide activity widget with a 'Load More'
  link at the bottom</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2152</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-11-28 16:54:24 +0000 (Sat, 28 Nov 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Replaced pagination on sitewide activity widget with a 'Load More' link at the bottom</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivitywidgetsphp">trunk/bp-activity/bp-activity-widgets.php</a></li>
<li><a href="#trunkbpactivityjswidgetactivityjs">trunk/bp-activity/js/widget-activity.js</a></li>
<li><a href="#trunkbpthemesbpdefault_inccssscreencss">trunk/bp-themes/bp-default/_inc/css/screen.css</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivitywidgetsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-widgets.php (2151 => 2152)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-widgets.php        2009-11-28 14:11:07 UTC (rev 2151)
+++ trunk/bp-activity/bp-activity-widgets.php        2009-11-28 16:54:24 UTC (rev 2152)
</span><span class="lines">@@ -53,6 +53,12 @@
</span><span class="cx">                 &lt;?php // The loop will be loaded here via AJAX on page load to retain settings. ?&gt;
</span><span class="cx">         &lt;/div&gt;
</span><span class="cx"> 
</span><ins>+        &lt;form action=&quot;&quot; name=&quot;activity-widget-form&quot; id=&quot;activity-widget-form&quot; method=&quot;post&quot;&gt;
+                &lt;?php wp_nonce_field( 'activity_filter', '_wpnonce_activity_filter' ) ?&gt;
+                &lt;input type=&quot;hidden&quot; id=&quot;aw-querystring&quot; name=&quot;aw-querystring&quot; value=&quot;&quot; /&gt;
+                &lt;input type=&quot;hidden&quot; id=&quot;aw-oldestpage&quot; name=&quot;aw-oldestpage&quot; value=&quot;1&quot; /&gt;
+        &lt;/div&gt;
+
</ins><span class="cx">         &lt;?php echo $after_widget; ?&gt;
</span><span class="cx">         &lt;?php
</span><span class="cx">         }
</span><span class="lines">@@ -77,37 +83,44 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function bp_activity_widget_loop( $type = 'all', $filter = false, $per_page = 20 ) {
</del><ins>+function bp_activity_widget_loop( $type = 'all', $filter = false, $query_string = false, $per_page = 20 ) {
</ins><span class="cx">         global $bp;
</span><span class="cx"> 
</span><del>-        /* Set a valid type */
-        if ( !$type || ( 'all' != $type &amp;&amp; 'friends' != $type &amp;&amp; 'groups' != $type ) )
-                $type = 'all';
</del><ins>+        if ( !$query_string ) {
+                /* Set a valid type */
+                if ( !$type || ( 'all' != $type &amp;&amp; 'friends' != $type &amp;&amp; 'groups' != $type ) )
+                        $type = 'all';
</ins><span class="cx"> 
</span><del>-        if ( ( 'friends' == $type || 'groups' == $type ) &amp;&amp; !is_user_logged_in() )
-                $type = 'all';
</del><ins>+                if ( ( 'friends' == $type || 'groups' == $type ) &amp;&amp; !is_user_logged_in() )
+                        $type = 'all';
</ins><span class="cx"> 
</span><del>-        switch( $type ) {
-                case 'friends':
-                        $friend_ids = implode( ',', friends_get_friend_user_ids( $bp-&gt;loggedin_user-&gt;id ) );
-                        $query_string = 'user_id=' . $friend_ids;
-                        break;
-                case 'groups':
-                        $groups = groups_get_user_groups( $bp-&gt;loggedin_user-&gt;id );
-                        $group_ids = implode( ',', $groups['groups'] );
-                        $query_string = 'object=groups&amp;primary_id=' . $group_ids;
-                        break;
</del><ins>+                switch( $type ) {
+                        case 'friends':
+                                $friend_ids = implode( ',', friends_get_friend_user_ids( $bp-&gt;loggedin_user-&gt;id ) );
+                                $query_string = 'user_id=' . $friend_ids;
+                                break;
+                        case 'groups':
+                                $groups = groups_get_user_groups( $bp-&gt;loggedin_user-&gt;id );
+                                $group_ids = implode( ',', $groups['groups'] );
+                                $query_string = 'object=groups&amp;primary_id=' . $group_ids;
+                                break;
+                }
+
+                /* Build the filter */
+                if ( $filter &amp;&amp; $filter != '-1' )
+                        $query_string .= '&amp;action=' . $filter;
+
+                /* Add the per_page param */
+                $query_string .= '&amp;per_page=' . $per_page;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        /* Build the filter */
-        if ( $filter &amp;&amp; $filter != '-1' )
-                $query_string .= '&amp;action=' . $filter;
</del><ins>+        if ( bp_has_activities( $query_string . '&amp;display_comments=threaded' ) ) : ?&gt;
+                &lt;?php echo $query_string . '&amp;display_comments=threaded||'; // Pass the qs back to the JS. ?&gt;
</ins><span class="cx"> 
</span><del>-        /* Add the per_page param */
-        $query_string .= '&amp;per_page=' . $per_page;
</del><ins>+                &lt;?php if ( !$_POST['acpage'] || 1 == $_POST['acpage'] ) : ?&gt;
+                        &lt;ul id=&quot;site-wide-stream&quot; class=&quot;activity-list&quot;&gt;
+                &lt;?php endif; ?&gt;
</ins><span class="cx"> 
</span><del>-        if ( bp_has_activities( $query_string . '&amp;display_comments=threaded' ) ) : ?&gt;
-                &lt;ul id=&quot;site-wide-stream&quot; class=&quot;activity-list&quot;&gt;
</del><span class="cx">                 &lt;?php while ( bp_activities() ) : bp_the_activity(); ?&gt;
</span><span class="cx">                         &lt;li class=&quot;&lt;?php bp_activity_css_class() ?&gt;&quot; id=&quot;activity-&lt;?php bp_activity_id() ?&gt;&quot;&gt;
</span><span class="cx">                                 &lt;div class=&quot;activity-avatar&quot;&gt;
</span><span class="lines">@@ -141,8 +154,14 @@
</span><span class="cx"> 
</span><span class="cx">                         &lt;/li&gt;
</span><span class="cx">                 &lt;?php endwhile; ?&gt;
</span><del>-                &lt;/ul&gt;
</del><ins>+                        &lt;li class=&quot;load-more&quot;&gt;
+                                &lt;a href=&quot;#more&quot;&gt;&lt;?php _e( 'Load More', 'buddypress' ) ?&gt;&lt;/a&gt; &amp;nbsp; &lt;span class=&quot;ajax-loader&quot;&gt;&lt;/span&gt;
+                        &lt;/li&gt;
</ins><span class="cx"> 
</span><ins>+                &lt;?php if ( !$_POST['acpage'] || 1 == $_POST['acpage']  ) : ?&gt;
+                        &lt;/ul&gt;
+                &lt;?php endif; ?&gt;
+
</ins><span class="cx">         &lt;?php else: ?&gt;
</span><span class="cx"> &lt;?php echo &quot;-1&lt;div id='message' class='info'&gt;&lt;p&gt;&quot; . __( 'No activity found', 'buddypress' ) . '&lt;/p&gt;&lt;/div&gt;'; ?&gt;
</span><span class="cx">         &lt;?php endif;
</span><span class="lines">@@ -154,6 +173,12 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'wp_ajax_activity_widget_filter', 'bp_activity_ajax_widget_filter' );
</span><span class="cx"> 
</span><ins>+/* The ajax function to load older updates at the end of the list */
+function bp_activity_ajax_load_older_updates() {
+        bp_activity_widget_loop( false, false, $_POST['query_string'] );
+}
+add_action( 'wp_ajax_aw_get_older_updates', 'bp_activity_ajax_load_older_updates' );
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> ?&gt;
</span></span></pre></div>
<a id="trunkbpactivityjswidgetactivityjs"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/js/widget-activity.js (2151 => 2152)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/js/widget-activity.js        2009-11-28 14:11:07 UTC (rev 2151)
+++ trunk/bp-activity/js/widget-activity.js        2009-11-28 16:54:24 UTC (rev 2152)
</span><span class="lines">@@ -32,6 +32,42 @@
</span><span class="cx">                 return false;
</span><span class="cx">         });
</span><span class="cx"> 
</span><ins>+        /* Stream event delegation */
+        j('div.widget_bp_activity_widget').click( function(event) {
+                var target = j(event.target).parent();
+
+                /* Load more updates at the end of the page */
+                if ( target.attr('class') == 'load-more' ) {
+                        j(&quot;li.load-more span.ajax-loader&quot;).show();
+                        var oldest_page = ( j(&quot;input#aw-oldestpage&quot;).val() * 1 ) + 1;
+
+                        j.post( ajaxurl, {
+                                action: 'aw_get_older_updates',
+                                'cookie': encodeURIComponent(document.cookie),
+                                'query_string': j(&quot;input#aw-querystring&quot;).val(),
+                                'acpage': oldest_page
+                        },
+                        function(response)
+                        {
+                                j(&quot;li.load-more span.ajax-loader&quot;).hide();
+
+                                /* Check for errors and append if found. */
+                                if ( response[0] + response[1] != '-1' ) {
+                                        var response = response.split('||');
+                                        j(&quot;input#aw-querystring&quot;).val(response[0]);
+
+                                        j(&quot;ul.activity-list&quot;).append(response[1]);
+                                        j(&quot;input#aw-oldestpage&quot;).val( oldest_page );
+                                }
+
+                                target.hide();
+                        });
+
+                        return false;
+                }
+        });
+
+
</ins><span class="cx">         function bp_activity_widget_post(type, filter) {
</span><span class="cx">                 if ( null == type )
</span><span class="cx">                         var type = 'all';
</span><span class="lines">@@ -71,8 +107,11 @@
</span><span class="cx">                                         j(this).fadeIn(100);
</span><span class="cx">                                 });
</span><span class="cx">                         } else {
</span><ins>+                                var response = response.split('||');
+                                j(&quot;input#aw-querystring&quot;).val(response[0]);
+
</ins><span class="cx">                                 j('div.activity').fadeOut( 100, function() {
</span><del>-                                        j(this).html(response);
</del><ins>+                                        j(this).html(response[1]);
</ins><span class="cx">                                         j(this).fadeIn(100);
</span><span class="cx">                                 });
</span><span class="cx">                         }
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_inccssscreencss"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/css/screen.css (2151 => 2152)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/css/screen.css        2009-11-28 14:11:07 UTC (rev 2151)
+++ trunk/bp-themes/bp-default/_inc/css/screen.css        2009-11-28 16:54:24 UTC (rev 2152)
</span><span class="lines">@@ -1366,6 +1366,19 @@
</span><span class="cx">                 margin: 0;
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+.activity-list li.load-more {
+        margin: 15px !important;
+        padding: 10px 15px !important;
+        background: #f0f0f0 !important;
+        text-align: center;
+        font-size: 1.2em;
+        border-right: 1px solid #ddd;
+        border-bottom: 1px solid #ddd;
+}
+        .activity-list li.load-more a {
+                color: #555;
+        }
+
</ins><span class="cx"> div.item-list-tabs ul {
</span><span class="cx">         margin: 0;
</span><span class="cx">         padding: 0;
</span></span></pre>
</div>
</div>

</body>
</html>