<!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][12002] trunk/src/bp-templates/bp-nouveau: BP Nouveau: use Moment.js & Livestamp.js to update activity timestamps</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 { white-space: pre-line; 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/12002">12002</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/12002","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>imath</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-04-27 16:52:27 +0000 (Fri, 27 Apr 2018)</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'>BP Nouveau: use Moment.js & Livestamp.js to update activity timestamps

Before these two JavaScript libraries were introduced in BuddyPress Core (2.7.0), i added some custom JavaScript code to perform the dynamic activity timestamp update task. Now these two libraries are available and do the job way better, it is about time to say goodbye to this code.

Fixes <a href="http://buddypress.trac.wordpress.org/ticket/7772">#7772</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbptemplatesbpnouveaubuddypressfunctionsphp">trunk/src/bp-templates/bp-nouveau/buddypress-functions.php</a></li>
<li><a href="#trunksrcbptemplatesbpnouveauincludesactivityfunctionsphp">trunk/src/bp-templates/bp-nouveau/includes/activity/functions.php</a></li>
<li><a href="#trunksrcbptemplatesbpnouveauincludesactivityloaderphp">trunk/src/bp-templates/bp-nouveau/includes/activity/loader.php</a></li>
<li><a href="#trunksrcbptemplatesbpnouveaujsbuddypressactivityjs">trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js</a></li>
<li><a href="#trunksrcbptemplatesbpnouveaujsbuddypressnouveaujs">trunk/src/bp-templates/bp-nouveau/js/buddypress-nouveau.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbptemplatesbpnouveaubuddypressfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-nouveau/buddypress-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/buddypress-functions.php        2018-04-27 15:39:20 UTC (rev 12001)
+++ trunk/src/bp-templates/bp-nouveau/buddypress-functions.php  2018-04-27 16:52:27 UTC (rev 12002)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -382,35 +382,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'unsaved_changes'     => __( 'Your profile has unsaved changes. If you leave the page, the changes will be lost.', 'buddypress' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'view'                => __( 'View', 'buddypress' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'object_nav_parent'   => '#buddypress',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'time_since'          => array(
-                               'sometime'    => _x( 'sometime', 'javascript time since', 'buddypress' ),
-                               'now'         => _x( 'right now', 'javascript time since', 'buddypress' ),
-                               'ago'         => _x( '% ago', 'javascript time since', 'buddypress' ),
-                               'separator'   => _x( ',', 'Separator in javascript time since', 'buddypress' ),
-                               'year'        => _x( '% year', 'javascript time since singular', 'buddypress' ),
-                               'years'       => _x( '% years', 'javascript time since plural', 'buddypress' ),
-                               'month'       => _x( '% month', 'javascript time since singular', 'buddypress' ),
-                               'months'      => _x( '% months', 'javascript time since plural', 'buddypress' ),
-                               'week'        => _x( '% week', 'javascript time since singular', 'buddypress' ),
-                               'weeks'       => _x( '% weeks', 'javascript time since plural', 'buddypress' ),
-                               'day'         => _x( '% day', 'javascript time since singular', 'buddypress' ),
-                               'days'        => _x( '% days', 'javascript time since plural', 'buddypress' ),
-                               'hour'        => _x( '% hour', 'javascript time since singular', 'buddypress' ),
-                               'hours'       => _x( '% hours', 'javascript time since plural', 'buddypress' ),
-                               'minute'      => _x( '% minute', 'javascript time since singular', 'buddypress' ),
-                               'minutes'     => _x( '% minutes', 'javascript time since plural', 'buddypress' ),
-                               'second'      => _x( '% second', 'javascript time since singular', 'buddypress' ),
-                               'seconds'     => _x( '% seconds', 'javascript time since plural', 'buddypress' ),
-                               'time_chunks' => array(
-                                       'a_year'   => YEAR_IN_SECONDS,
-                                       'b_month'  => 30 * DAY_IN_SECONDS,
-                                       'c_week'   => WEEK_IN_SECONDS,
-                                       'd_day'    => DAY_IN_SECONDS,
-                                       'e_hour'   => HOUR_IN_SECONDS,
-                                       'f_minute' => MINUTE_IN_SECONDS,
-                                       'g_second' => 1,
-                               ),
-                       ),
</del><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">                // If the Object/Item nav are in the sidebar
</span></span></pre></div>
<a id="trunksrcbptemplatesbpnouveauincludesactivityfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-nouveau/includes/activity/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/includes/activity/functions.php 2018-04-27 15:39:20 UTC (rev 12001)
+++ trunk/src/bp-templates/bp-nouveau/includes/activity/functions.php   2018-04-27 16:52:27 UTC (rev 12002)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -428,36 +428,6 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 3.0.0
- */
-function bp_nouveau_activity_time_since( $time_since, $activity = null ) {
-       if ( ! isset( $activity->date_recorded ) ) {
-               return $time_since;
-       }
-
-       return apply_filters(
-               'bp_nouveau_activity_time_since', sprintf(
-                       '<time class="time-since" datetime="%1$s" data-bp-timestamp="%2$d">%3$s</time>',
-                       esc_attr( $activity->date_recorded ),
-                       esc_attr( strtotime( $activity->date_recorded ) ),
-                       esc_attr( bp_core_time_since( $activity->date_recorded ) )
-               )
-       );
-}
-
-/**
- * @since 3.0.0
- */
-function bp_nouveau_activity_allowed_tags( $activity_allowedtags = array() ) {
-       $activity_allowedtags['time']                      = array();
-       $activity_allowedtags['time']['class']             = array();
-       $activity_allowedtags['time']['datetime']          = array();
-       $activity_allowedtags['time']['data-bp-timestamp'] = array();
-
-       return $activity_allowedtags;
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px">  * Get the activity query args for the widget.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 3.0.0
</span></span></pre></div>
<a id="trunksrcbptemplatesbpnouveauincludesactivityloaderphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-nouveau/includes/activity/loader.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/includes/activity/loader.php    2018-04-27 15:39:20 UTC (rev 12001)
+++ trunk/src/bp-templates/bp-nouveau/includes/activity/loader.php      2018-04-27 16:52:27 UTC (rev 12002)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -96,8 +96,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'bp_get_activity_action_pre_meta', 'bp_nouveau_activity_secondary_avatars', 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'bp_get_activity_css_class', 'bp_nouveau_activity_scope_newest_class', 10, 1 );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                add_filter( 'bp_activity_time_since', 'bp_nouveau_activity_time_since', 10, 2 );
-               add_filter( 'bp_activity_allowed_tags', 'bp_nouveau_activity_allowed_tags', 10, 1 );
</del><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>
<a id="trunksrcbptemplatesbpnouveaujsbuddypressactivityjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js       2018-04-27 15:39:20 UTC (rev 12001)
+++ trunk/src/bp-templates/bp-nouveau/js/buddypress-activity.js 2018-04-27 16:52:27 UTC (rev 12002)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -95,13 +95,6 @@
</span><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">                        $.extend( data, { bp_heartbeat: bp.Nouveau.getStorage( 'bp-activity' ) } );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                       // Update all displayed time
-                       $.each( $( '#buddypress time' ), function( t, time ) {
-                               if ( $( time ).data( 'bp-timestamp' ) ) {
-                                       $( time ).html( bp.Nouveau.updateTimeSince( Number( $( time ).data( 'bp-timestamp' ) ) ) );
-                               }
-                       } );
</del><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>
<a id="trunksrcbptemplatesbpnouveaujsbuddypressnouveaujs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-nouveau/js/buddypress-nouveau.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-nouveau/js/buddypress-nouveau.js        2018-04-27 15:39:20 UTC (rev 12001)
+++ trunk/src/bp-templates/bp-nouveau/js/buddypress-nouveau.js  2018-04-27 16:52:27 UTC (rev 12002)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,7 +48,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        // Object Globals
</span><span class="cx" style="display: block; padding: 0 10px">                        this.objects                = $.map( BP_Nouveau.objects, function( value ) { return value; } );
</span><span class="cx" style="display: block; padding: 0 10px">                        this.objectNavParent        = BP_Nouveau.object_nav_parent;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        this.time_since             = BP_Nouveau.time_since;
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // HeartBeat Global
</span><span class="cx" style="display: block; padding: 0 10px">                        this.heartbeat              = wp.heartbeat || {};
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -209,75 +208,6 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * [updateTimeSince description]
-                * @param  {[type]} timestamp [description]
-                * @return {[type]}           [description]
-                */
-               updateTimeSince: function( timestamp ) {
-                       var now = new Date( $.now() ), diff, count_1, chunk_1, count_2, chunk_2,
-                               time_since = [], time_chunks = $.extend( {}, this.time_since.time_chunks ), ms;
-
-                       // Returns sometime
-                       if ( undefined === timestamp ) {
-                               return this.time_since.sometime;
-                       }
-
-                       // Javascript timestamps are in ms.
-                       timestamp = new Date( timestamp * 1000 );
-
-                       // Calculate the diff
-                       diff = now - timestamp;
-
-                       // Returns right now
-                       if ( 0 === diff ) {
-                               return this.time_since.now;
-                       }
-
-                       $.each( time_chunks, function( c, chunk ) {
-                               var milliseconds = chunk * 1000;
-                               var rounded_time = Math.floor( diff / milliseconds );
-
-                               if ( 0 !== rounded_time && ! chunk_1 ) {
-                                       chunk_1 = c;
-                                       count_1 = rounded_time;
-                                       ms      = milliseconds;
-                               }
-                       } );
-
-                       // First chunk
-                       chunk_1 = chunk_1.substr( 2 );
-                       time_since.push( ( 1 === count_1 ) ? this.time_since[ chunk_1 ].replace( '%', count_1 ) : this.time_since[ chunk_1 + 's' ].replace( '%', count_1 ) );
-
-                       // Remove Year from chunks
-                       delete time_chunks.a_year;
-
-                       $.each( time_chunks, function( c, chunk ) {
-                               var milliseconds = chunk * 1000;
-                               var rounded_time = Math.floor( ( diff - ( ms * count_1 ) ) / milliseconds );
-
-                               if ( 0 !== rounded_time && ! chunk_2 ) {
-                                       chunk_2 = c;
-                                       count_2 = rounded_time;
-                               }
-                       } );
-
-                       // Second chunk
-                       if ( undefined !== chunk_2 ) {
-                               chunk_2 = chunk_2.substr( 2 );
-                               time_since.push( ( 1 === count_2 ) ? this.time_since[ chunk_2 ].replace( '%', count_2 ) : this.time_since[ chunk_2 + 's' ].replace( '%', count_2 ) );
-                       }
-
-                       // Returns x time, y time ago
-                       if ( time_since.length >= 1 ) {
-                               return this.time_since.ago.replace( '%', time_since.join( this.time_since.separator + ' ' ) );
-
-                       // Returns sometime
-                       } else {
-                               return this.time_since.sometime;
-                       }
-               },
-
-               /**
</del><span class="cx" style="display: block; padding: 0 10px">                  * [objectRequest description]
</span><span class="cx" style="display: block; padding: 0 10px">                 * @param  {[type]} data [description]
</span><span class="cx" style="display: block; padding: 0 10px">                 * @return {[type]}      [description]
</span></span></pre>
</div>
</div>

</body>
</html>