1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8//this script may only be included - so its better to die if called directly.
9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
10	header("location: index.php");
11	exit;
12}
13
14/**
15 * @param string $string
16 * @param string $intro
17 * @param string $same if set to 'n' will bypass timeago preferences. Useful when markup is illegal in date
18 *
19 * @return string
20 */
21
22
23function smarty_modifier_tiki_short_datetime($string, $intro = '', $same = 'y')
24{
25	global $prefs;
26	$smarty = TikiLib::lib('smarty');
27	$smarty->loadPlugin('smarty_modifier_tiki_date_format');
28	$date = smarty_modifier_tiki_date_format($string, $prefs['short_date_format']);
29	$time = smarty_modifier_tiki_date_format($string, $prefs['short_time_format']);
30
31	$intro = ! empty($intro) ? tra($intro) . ' ' : '';
32
33	if ($prefs['jquery_timeago'] === 'y' && $same === 'y') {
34		TikiLib::lib('header')->add_jq_onready('$("time.timeago").timeago();');
35		return '<time class="timeago" datetime="' . TikiLib::date_format('c', $string, false, 5, false) . '">' . $date . ' ' . $time . '</time>';
36	} elseif ($same != 'n' && $prefs['tiki_same_day_time_only'] == 'y' && $date == smarty_modifier_tiki_date_format(time(), $prefs['short_date_format'])) {
37		//tra('on') tra('on:') tra('at') tra('at:')
38		return str_replace(['on', 'On'], ['at', 'At'], $intro) . $time;
39	} else {
40		// if you change the separator do not forget to change the translation instruction in lib/prefs/short.php
41		$time = $date . ' ' . $time;
42		return $intro . ' ' . $time;
43	}
44}
45