From 3decf67e6d6aa0ae077aa48bcdd37afc05a36dd1 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 23 Jul 2012 04:11:59 -0700 Subject: realtime updates of "6 minutes ago" with fallback to iso8601 timestamps (available on tooltip) --- include/conversation.php | 12 +++++++++--- index.php | 24 +++++++++++++++++++++++- js/main.js | 28 ++++++++++++++++++++++++++++ library/jquery.timeago.js | 2 +- view/head.tpl | 20 ++++++++++++++++++++ view/search_item.tpl | 3 ++- view/wall_item.tpl | 2 +- view/wallwall_item.tpl | 2 +- 8 files changed, 85 insertions(+), 8 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 06b643a05..958400db3 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -457,7 +457,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $body = prepare_body($item,true); - + //$tmp_item = replace_macros($tpl,array( $tmp_item = array( 'template' => $tpl, @@ -473,7 +473,10 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { 'title' => template_escape($item['title']), 'body' => template_escape($body), 'text' => strip_tags(template_escape($body)), - 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), + 'ago' => relative_date($item['created']), + 'app' => $item['app'], + 'str_app' => sprintf( t(' from %s'), $item['app']), + 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'), 'location' => template_escape($location), 'indent' => '', 'owner_name' => template_escape($owner_name), @@ -832,7 +835,10 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => template_escape($item['title']), - 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), + 'ago' => datetime_convert('UTC',date_default_timezone_get(),$item['created'],'r'), // relative_date($item['created']), + 'app' => $item['app'], + 'str_app' => sprintf( t(' from %s'), $item['app']), + 'localtime' => datetime_convert('UTC', 'UTC', $item['created'], 'c'), 'lock' => $lock, 'location' => template_escape($location), 'indent' => $indent, diff --git a/index.php b/index.php index a20cb4fc1..15d2eb460 100644 --- a/index.php +++ b/index.php @@ -390,7 +390,29 @@ if(! file_exists($module_css)) '$page_css' => $a->get_baseurl() . '/' . $page_css, '$module_css' => (($module_css) ? $a->get_baseurl() . '/' . $module_css : null), '$stylesheet' => current_theme_url(), - '$theme' => current_theme() + '$theme' => current_theme(), + +// localisations for jquery.timeago.js, see https://github.com/rmm5t/jquery-timeago +// TRANSLATORS - only translate the conditionals if you require them! + + '$t01' => ((t('timeago.prefixAgo') != 'timeago.prefixAgo') ? t('timeago.prefixAgo') : 'null'), + '$t02' => ((t('timeago.suffixAgo') != 'timeago.suffixAgo') ? t('timeago.suffixAgo') : 'null'), + '$t03' => t('ago'), + '$t04' => t('from now'), + '$t05' => t('less than a minute'), + '$t06' => t('about a minute'), + '$t07' => t('%d minutes'), + '$t08' => t('about an hour'), + '$t09' => t('about %d hours'), + '$t10' => t('a day'), + '$t11' => t('%d days'), + '$t12' => t('about a month'), + '$t13' => t('%d months'), + '$t14' => t('about a year'), + '$t15' => t('%d years'), + '$t16' => t(' '), // wordSeparator + '$t17' => ((t('timeago.numbers') != 'timeago.numbers') ? t('timeago.numbers') : '[]') + )); $page = $a->page; diff --git a/js/main.js b/js/main.js index e8c5b060e..e434ee4a5 100644 --- a/js/main.js +++ b/js/main.js @@ -686,3 +686,31 @@ function previewTheme(elm) { }); }; })(jQuery); + + + +$(document).ready(function() { + +jQuery.timeago.settings.strings = { + prefixAgo: t01, + prefixFromNow: t02, + suffixAgo: t03, + suffixFromNow: t04, + seconds: t05, + minute: t06, + minutes: t07, + hour: t08, + hours: t09, + day: t10, + days: t11, + month: t12, + months: t13, + year: t14, + years: t15, + wordSeparator: t16, + numbers: t17 +}; + + +$("abbr.wall-item-ago-time").timeago(); +}); \ No newline at end of file diff --git a/library/jquery.timeago.js b/library/jquery.timeago.js index c61405dfc..f7a657e93 100644 --- a/library/jquery.timeago.js +++ b/library/jquery.timeago.js @@ -121,7 +121,7 @@ function refresh() { var data = prepareData(this); if (!isNaN(data.datetime)) { - $(this).text(inWords(data.atetime)); + $(this).text(inWords(data.datetime)); } return this; } diff --git a/view/head.tpl b/view/head.tpl index 78e2a2abc..fbe2ded83 100644 --- a/view/head.tpl +++ b/view/head.tpl @@ -26,6 +26,7 @@ + @@ -104,6 +105,25 @@ } } + // jquery.timeago localisations + + var t01 = $t01 ; + var t02 = $t02 ; + var t03 = "$t03" ; + var t04 = "$t04" ; + var t05 = "$t05" ; + var t06 = "$t06" ; + var t07 = "$t07" ; + var t08 = "$t08" ; + var t09 = "$t09" ; + var t10 = "$t10" ; + var t11 = "$t11" ; + var t12 = "$t12" ; + var t13 = "$t13" ; + var t14 = "$t14" ; + var t15 = "$t15" ; + var t16 = "$t16" ; + var t17 = $t17 ; diff --git a/view/search_item.tpl b/view/search_item.tpl index 8089d306e..e13c1e5a7 100644 --- a/view/search_item.tpl +++ b/view/search_item.tpl @@ -23,7 +23,8 @@
$item.name -
$item.ago
+ +
$item.ago{{ if $item.app }}$item.str_app{{ endif }}
diff --git a/view/wall_item.tpl b/view/wall_item.tpl index 60dde7600..2510a8c0d 100644 --- a/view/wall_item.tpl +++ b/view/wall_item.tpl @@ -24,7 +24,7 @@
$item.name -
$item.ago
+
$item.ago{{ if $item.app }}$item.str_app{{ endif }}
diff --git a/view/wallwall_item.tpl b/view/wallwall_item.tpl index b7cca3fab..478df8e88 100644 --- a/view/wallwall_item.tpl +++ b/view/wallwall_item.tpl @@ -29,7 +29,7 @@
$item.name $item.to $item.owner_name $item.vwall
-
$item.ago
+
$item.ago{{ if $item.app }}$item.str_app{{ endif }}
$item.title
-- cgit v1.2.3