summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <gohr@cosmocode.de>2009-10-07 15:36:14 +0200
committerAndreas Gohr <gohr@cosmocode.de>2009-10-07 15:36:14 +0200
commitf22635779b10fe3735a11bc1af5c88653e580534 (patch)
tree03322ac39a0a7a644340b45417125ea4c8275b51
parentc57e365ef97272cc08601374e4de2f5bcd614335 (diff)
downloadrpg-f22635779b10fe3735a11bc1af5c88653e580534.tar.gz
rpg-f22635779b10fe3735a11bc1af5c88653e580534.tar.bz2
New dformat() function for fuzzy date support
Ignore-this: 7193cd788fee2c05a9068bf6edd5dc17 It is now possible to use the %f placeholder in $conf['dformat'] to add a fuzzy age string. Template developers and plugin authors should replace their strftime + $conf['dformat'] calls with calls to the new dformat() function. Example: %Y/%m/%d %H:%M (%f) produces dates like this: 2009/09/16 10:36 (3 weeks ago) darcs-hash:20091007133614-6e07b-677108d1b43928ef8fd886813e43514507b5e073.gz
-rw-r--r--inc/common.php22
-rw-r--r--inc/html.php20
-rw-r--r--inc/lang/de/lang.php7
-rw-r--r--inc/lang/en/lang.php12
-rw-r--r--inc/media.php4
-rw-r--r--inc/template.php2
-rw-r--r--inc/toolbar.php2
-rw-r--r--lib/exe/ajax.php2
-rw-r--r--lib/tpl/default/detail.php2
9 files changed, 50 insertions, 23 deletions
diff --git a/inc/common.php b/inc/common.php
index 82d5f69ee..a15cb5c62 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -1082,7 +1082,7 @@ function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){
}
$ip = clientIP();
- $text = str_replace('@DATE@',strftime($conf['dformat']),$text);
+ $text = str_replace('@DATE@',dformat(),$text);
$text = str_replace('@BROWSER@',$_SERVER['HTTP_USER_AGENT'],$text);
$text = str_replace('@IPADDRESS@',$ip,$text);
$text = str_replace('@HOSTNAME@',gethostsbyaddrs($ip),$text);
@@ -1224,6 +1224,26 @@ function datetime_h($dt){
}
/**
+ * Wraps around strftime but provides support for fuzzy dates
+ *
+ * The format default to $conf['dformat']. It is passed to
+ * strftime - %f can be used to get the value from datetime_h()
+ *
+ * @see datetime_h
+ * @author Andreas Gohr <gohr@cosmocode.de>
+ */
+function dformat($dt=null,$format=''){
+ global $conf;
+
+ if(is_null($dt)) $dt = time();
+ $dt = (int) $dt;
+ if(!$format) $format = $conf['dformat'];
+
+ $format = str_replace('%f',datetime_h($dt),$format);
+ return strftime($format,$dt);
+}
+
+/**
* return an obfuscated email address in line with $conf['mailguard'] setting
*
* @author Harry Fuecks <hfuecks@gmail.com>
diff --git a/inc/html.php b/inc/html.php
index 46ced1de1..0ea72c06c 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -249,7 +249,7 @@ function html_draft(){
$form->addHidden('date', $draft['date']);
$form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
$form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
- $form->addElement($lang['draftdate'].' '. strftime($conf['dformat'],filemtime($INFO['draft'])));
+ $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
$form->addElement(form_makeCloseTag('div'));
$form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
$form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
@@ -382,7 +382,7 @@ function html_locked(){
global $INFO;
$locktime = filemtime(wikiLockFN($ID));
- $expire = @strftime($conf['dformat'], $locktime + $conf['locktime'] );
+ $expire = dformat($locktime + $conf['locktime']);
$min = round(($conf['locktime'] - (time() - $locktime) )/60);
print p_locale_xhtml('locked');
@@ -418,7 +418,7 @@ function html_revisions($first=0){
array_pop($revisions); // remove extra log entry
}
- $date = @strftime($conf['dformat'],$INFO['lastmod']);
+ $date = dformat($INFO['lastmod']);
print p_locale_xhtml('revisions');
@@ -466,7 +466,7 @@ function html_revisions($first=0){
}
foreach($revisions as $rev){
- $date = strftime($conf['dformat'],$rev);
+ $date = dformat($rev);
$info = getRevisionInfo($ID,$rev,true);
$exists = page_exists($ID,$rev);
@@ -593,7 +593,7 @@ function html_recent($first=0){
$form->addElement(form_makeOpenTag('ul'));
foreach($recents as $recent){
- $date = strftime($conf['dformat'],$recent['date']);
+ $date = dformat($recent['date']);
if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
$form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
else
@@ -878,7 +878,7 @@ function html_diff($text='',$intro=true){
$l_rev = '';
$l_text = rawWiki($ID,'');
$l_head = '<a class="wikilink1" href="'.wl($ID).'">'.
- $ID.' '.strftime($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
+ $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
$lang['current'];
$r_rev = '';
@@ -925,7 +925,7 @@ function html_diff($text='',$intro=true){
if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
$l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
- $ID.' ['.strftime($conf['dformat'],$l_rev).']</a>'.
+ $ID.' ['.dformat($l_rev).']</a>'.
'<br />'.$l_user.' '.$l_sum;
}
@@ -939,7 +939,7 @@ function html_diff($text='',$intro=true){
if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
$r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
- $ID.' ['.strftime($conf['dformat'],$r_rev).']</a>'.
+ $ID.' ['.dformat($r_rev).']</a>'.
'<br />'.$r_user.' '.$r_sum;
}elseif($_rev = @filemtime(wikiFN($ID))){
$_info = getRevisionInfo($ID,$_rev,true);
@@ -951,7 +951,7 @@ function html_diff($text='',$intro=true){
if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
$r_head = '<a class="wikilink1" href="'.wl($ID).'">'.
- $ID.' ['.strftime($conf['dformat'],$_rev).']</a> '.
+ $ID.' ['.dformat($_rev).']</a> '.
'('.$lang['current'].')'.
'<br />'.$_user.' '.$_sum;
}else{
@@ -1173,7 +1173,7 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed?
<div style="width:99%;">
<div class="toolbar">
- <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.strftime($conf['dformat']);?></div>
+ <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
<div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
diff --git a/inc/lang/de/lang.php b/inc/lang/de/lang.php
index 530b0bc24..1ab03e4c1 100644
--- a/inc/lang/de/lang.php
+++ b/inc/lang/de/lang.php
@@ -247,3 +247,10 @@ $lang['mu_filetypes'] = 'Erlaubte Dateitypen';
$lang['mu_info'] = 'Dateien hochgeladen!';
$lang['mu_lasterr'] = 'Letzter Fehler:';
$lang['recent_global'] = 'Im Moment sehen Sie die Änderungen im Namensraum <b>%s</b>. Sie können auch <a href="%s">die Änderungen im gesamten Wiki sehen</a>.';
+
+$lang['years'] = 'vor %d Jahren';
+$lang['months'] = 'vor %d Monaten';
+$lang['weeks'] = 'vor %d Wochen';
+$lang['days'] = 'vor %d Tagen';
+$lang['hours'] = 'vor %d Stunden';
+$lang['seconds'] = 'vor %d Sekunden';
diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php
index fbde8cab0..dfe45bf83 100644
--- a/inc/lang/en/lang.php
+++ b/inc/lang/en/lang.php
@@ -269,11 +269,11 @@ $lang['mu_lasterr'] = 'Last error:';
$lang['recent_global'] = 'You\'re currently watching the changes inside the <b>%s</b> namespace. You can also <a href="%s">view the recent changes of the whole wiki</a>.';
-$lang['years'] = '%d years';
-$lang['months'] = '%d months';
-$lang['weeks'] = '%d weeks';
-$lang['days'] = '%d days';
-$lang['hours'] = '%d hours';
-$lang['seconds'] = '%d seconds';
+$lang['years'] = '%d years ago';
+$lang['months'] = '%d months ago';
+$lang['weeks'] = '%d weeks ago';
+$lang['days'] = '%d days ago';
+$lang['hours'] = '%d hours ago';
+$lang['seconds'] = '%d seconds ago';
//Setup VIM: ex: et ts=2 enc=utf-8 :
diff --git a/inc/media.php b/inc/media.php
index 4ad7047b2..2a45b6d80 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -404,7 +404,7 @@ function media_notify($id,$file,$mime){
$ip = clientIP();
$text = rawLocale('uploadmail');
- $text = str_replace('@DATE@',strftime($conf['dformat']),$text);
+ $text = str_replace('@DATE@',dformat(),$text);
$text = str_replace('@BROWSER@',$_SERVER['HTTP_USER_AGENT'],$text);
$text = str_replace('@IPADDRESS@',$ip,$text);
$text = str_replace('@HOSTNAME@',gethostsbyaddrs($ip),$text);
@@ -570,7 +570,7 @@ function media_printfile($item,$auth,$jump,$display_namespace=false){
$info .= (int) $item['meta']->getField('File.Height');
$info .= ' ';
}
- $info .= '<i>'.strftime($conf['dformat'],$item['mtime']).'</i>';
+ $info .= '<i>'.dformat($item['mtime']).'</i>';
$info .= ' ';
$info .= filesize_h($item['size']);
diff --git a/inc/template.php b/inc/template.php
index c181c164c..e26c5202a 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -958,7 +958,7 @@ function tpl_pageinfo($ret=false){
}
}
$fn = utf8_decodeFN($fn);
- $date = strftime($conf['dformat'],$INFO['lastmod']);
+ $date = dformat($INFO['lastmod']);
// print it
if($INFO['exists']){
diff --git a/inc/toolbar.php b/inc/toolbar.php
index a1851c746..701723b58 100644
--- a/inc/toolbar.php
+++ b/inc/toolbar.php
@@ -236,7 +236,7 @@ function toolbar_signature(){
$sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
$sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
$sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
- $sig = str_replace('@DATE@',strftime($conf['dformat']),$sig);
+ $sig = str_replace('@DATE@',dformat(),$sig);
$sig = str_replace('\\\\n','\\n',addslashes($sig));
return $sig;
}
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php
index 4d9a8105a..4618abd71 100644
--- a/lib/exe/ajax.php
+++ b/lib/exe/ajax.php
@@ -152,7 +152,7 @@ function ajax_lock(){
);
$cname = getCacheName($draft['client'].$id,'.draft');
if(io_saveFile($cname,serialize($draft))){
- echo $lang['draftdate'].' '.strftime($conf['dformat']);
+ echo $lang['draftdate'].' '.dformat();
}
}
diff --git a/lib/tpl/default/detail.php b/lib/tpl/default/detail.php
index 765358568..4f42b116e 100644
--- a/lib/tpl/default/detail.php
+++ b/lib/tpl/default/detail.php
@@ -53,7 +53,7 @@ if (!defined('DOKU_INC')) die();
<dl class="img_tags">
<?php
$t = tpl_img_getTag('Date.EarliestTime');
- if($t) print '<dt>'.$lang['img_date'].':</dt><dd>'.strftime($conf['dformat'],$t).'</dd>';
+ if($t) print '<dt>'.$lang['img_date'].':</dt><dd>'.dformat($t).'</dd>';
$t = tpl_img_getTag('File.Name');
if($t) print '<dt>'.$lang['img_fname'].':</dt><dd>'.hsc($t).'</dd>';