Time Since 2 is a small and tells you how long ago a entry or comment was made in english “1 month ago” or french “il y a 1 mois”. Portions of the code are borrowed from Steve P. Sharpe.
You can donwload it here: http://benoitmeunier.info/ee/plugins/timesince2/
This is my first plugin. Be kind.
Usage
Here a example how you can integrate it:
{exp:timesince}{entry_date}{/exp:timesince}Here the best way to do it:
<abbr title="{entry_date format='%Y/%m/%d'}EDT{entry_date format='%g:%i:%s'}-05:00">{exp:timesince}{entry_date}{/exp:timesince}</abbr>Files
pi.timesince.php /french/lang.timesince.php /english/lang.timesince.php
Sequence
1 hour ago 2 hours ago X hours ago 23 hours ago 1 day ago 2 days ago 3 days ago 4 days ago 5 days ago 6 days ago 1 week ago 2 weeks ago 3 weeks ago 1 month ago Day, Month XX, 200
I have to thanks the Kindo team for helping me getting this plugin out.
BMeunier, this is a great addon.. I was looking for a way to do it, and this is perfect.
One request, can it do minutes underneith the hour? So if it’s been 5 minutes, it says ‘5 minutes ago’..
Besides that, this is nice little plugin. The best ones are usually the simplest & easiest to use in my opinion!
Thanks! Chuck
Here is a little dirty hack to make it EE2 compatible.
EDIT pi.timesince
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$plugin_info = array(
'pi_name' => 'Timesince',
'pi_version' => '2.0',
'pi_author' => 'Benoit Meunier',
'pi_author_url' => 'http://www.benoitmeunier.info/ee/plugins/timesince2/',
'pi_description' => 'Tells you how long ago a comment or entry was made in english or french',
'pi_usage' => Timesince::usage()
);
class Timesince
{
var $return_data = "";
function Timesince()
{
global $TMPL, $LOC, $LANG;
$this->EE =& get_instance();
$this->EE->lang->loadfile('timesince');
$date = $this->EE->TMPL->tagdata;
$chunks = array(array(60 * 60 * 24 * 365 , $this->EE->lang->line('year')),
array(60 * 60 * 24 * 30 , $this->EE->lang->line('month')),
array(60 * 60 * 24 * 7, $this->EE->lang->line('week')),
array(60 * 60 * 24 , $this->EE->lang->line('day')),
array(60 * 60 , $this->EE->lang->line('hour')),
array(60 , $this->EE->lang->line('minute'))
);
$newer_date = $this->EE->localize->now;
$since = $newer_date - $date;
// step one: the first chunk
for ($i = 0, $j = count($chunks); $i < $j; $i++) {
$seconds = $chunks[$i][0];
$name = $chunks[$i][1];
// finding the biggest chunk (if the chunk fits, break)
if (($count = floor($since / $seconds)) != 0) {
break;
}
}
// set output var
$output = "";
//setlocale(LC_TIME, $this->EE->lang->line('locale'));
if (($name == $this->EE->lang->line('day')) && ($count == 1)) { $name = $this->EE->lang->line('one_day'); }
if ($this->EE->lang->line('since') == ' ago') {
$output = ($count == 1) ? '1 '.$name : "$count {$name}s";
$output .= $this->EE->lang->line('since');
}
else {
$output = $this->EE->lang->line('since');
$output .= ($count == 1) ? '1 '.$name : "$count {$name}s";
}
if (($name == $this->EE->lang->line('minute')) && ($count == 0)) { $output = $this->EE->lang->line('since_short'); }
//if (($name == $this->EE->lang->line('month')) && ($count == 1)) { $output = $this->EE->lang->line('since_long'); }
if ((($name == $this->EE->lang->line('month')) && ($count > 1)) || ($name == $this->EE->lang->line('year'))) {
$output = $LOC->decode_date($this->EE->lang->line('date'), $date);
// $output = strftime($this->EE->lang->line('date'), $date);
}
$this->return_data = $output;
}// function
// ----------------------------------------
// Plugin Usage
// ----------------------------------------
// This function describes how the plugin is used.
// Make sure and use output buffering
function usage()
{
ob_start();
?>
/***********************************************/
Description:
Tells you how long ago a comment or entry was made in english or french.
/***********************************************/
Example:
Simply put the following code where you want the timesince text to appear, you can use either in entries or comments:
{exp:timesince}
{entry_date}
{/exp:timesince}
{exp:timesince}
{comment_date}
{/exp:timesince}
/***********************************************/
Credits:
This plugin is modified from the original code from Steve P. Sharpe.
http://stevepsharpe.com/blog/permalink/ee-timesince-plugin/
http://expressionengine.com/downloads/details/timesince/
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
// END
} // class
?>Just for future reference, the language file will also need to be updated to be compatible with EE 2.0. Here’s the code to replace lang.timesince.php:
<?php
$lang = array(
//----------------------------
// Timesince (english)
//----------------------------
'year' =>
'year',
'month' =>
'month',
'week' =>
'week',
'day' =>
'day',
'hour' =>
'hour',
'minute' =>
'minute',
'since' =>
' ago',
'since_short' =>
'less than a minute ago',
'since_long' =>
'more than 1 month ago',
'one_day' =>
'day',
'date' =>
'%l, %F %d, %Y',
'locale' =>
'en_US',
//----------------------------------------
''=>''
);
/* End of file lang.timesince.php */
/* Location: ./system/expressionengine/language/english/lang.timesince.php */I modified both files as per the posted instructions, but am having no luck using the plugin. I am receiving the following error whenever I try to call the plugin:
Fatal error: Call to a member function decode_date() on a non-object in /home/jrich/jeremiahrich_system/expressionengine/third_party/timesince/pi.timesince.php on line 62I am on EE 2.01 build 20100215. Any ideas?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.