2 // PukiWiki - Yet another WikiWikiWeb clone.
4 // Copyright 2003-2017 PukiWiki Development Team
5 // License: GPL v2 or (at your option) any later version
10 // &new([nodate]){date}; // Check the date string
11 // &new(pagename[,nolink]); // Check the pages's timestamp
12 // &new(pagename/[,nolink]);
13 // // Check multiple pages started with 'pagename/',
14 // // and show the latest one
16 define('PLUGIN_NEW_DATE_FORMAT', '<span class="comment_date">%s</span>');
18 function plugin_new_init()
20 // Elapsed time => New! message with CSS
21 $messages['_plugin_new_elapses'] = array(
22 60 * 60 * 24 * 1 => ' <span class="new1" title="%s">New!</span>', // 1day
23 60 * 60 * 24 * 5 => ' <span class="new5" title="%s">New</span>'); // 5days
24 set_plugin_messages($messages);
27 function plugin_new_inline()
29 global $vars, $_plugin_new_elapses;
32 $args = func_get_args();
33 $date = strip_autolink(array_pop($args)); // {date} always exists
35 // Show 'New!' message by the time of the $date string
36 if (func_num_args() > 2) return '&new([nodate]){date};';
39 if (preg_match('/^\D*(\d{4})\D+(\d{1,2})\D+(\d{1,2})\D+(\d{1,2}:\d{2}:\d{2})\D*$/', $date, $dm)) {
40 $iso8601_date = $dm[1]
41 . '-' . substr('0' . $dm[2], -2)
42 . '-' . substr('0' . $dm[3], -2)
44 $timestamp = strtotime($iso8601_date);
46 $timestamp = strtotime($date);
48 if ($timestamp === -1 || $timestamp === FALSE) {
49 return '&new([nodate]){date}: Invalid date string;';
51 $timestamp -= ZONETIME;
53 $retval = in_array('nodate', $args) ? '' : htmlsc($date);
55 // Show 'New!' message by the timestamp of the page
56 if (func_num_args() > 3) return '&new(pagename[,nolink]);';
58 $name = strip_bracket(! empty($args) ? array_shift($args) : $vars['page']);
59 $page = get_fullname($name, $vars['page']);
60 $nolink = in_array('nolink', $args);
62 if (substr($page, -1) == '/') {
63 // Check multiple pages started with "$page"
65 $regex = '/^' . preg_quote($page, '/') . '/';
66 foreach (preg_grep($regex, get_existpages()) as $page) {
67 // Get the latest pagename and its timestamp
68 $_timestamp = get_filetime($page);
69 if ($timestamp < $_timestamp) {
70 $timestamp = $_timestamp;
71 $retval = $nolink ? '' : make_pagelink($page);
75 return '&new(pagename/[,nolink]): No such pages;';
79 $timestamp = get_filetime($page);
80 $retval = $nolink ? '' : make_pagelink($page, $name);
82 return '&new(pagename[,nolink]): No such page;';
87 // Add 'New!' string by the elapsed time
88 $erapse = UTIME - $timestamp;
89 foreach ($_plugin_new_elapses as $limit=>$tag) {
90 if ($erapse <= $limit) {
91 $retval .= sprintf($tag, get_passage($timestamp));
98 return sprintf(PLUGIN_NEW_DATE_FORMAT, $retval);