2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: new.inc.php,v 1.10 2011/01/25 15:01:01 henoheno Exp $
8 // &new([nodate]){date}; // Check the date string
9 // &new(pagename[,nolink]); // Check the pages's timestamp
10 // &new(pagename/[,nolink]);
11 // // Check multiple pages started with 'pagename/',
12 // // and show the latest one
14 define('PLUGIN_NEW_DATE_FORMAT', '<span class="comment_date">%s</span>');
16 function plugin_new_init()
18 // Elapsed time => New! message with CSS
19 $messages['_plugin_new_elapses'] = array(
20 60 * 60 * 24 * 1 => ' <span class="new1" title="%s">New!</span>', // 1day
21 60 * 60 * 24 * 5 => ' <span class="new5" title="%s">New</span>'); // 5days
22 set_plugin_messages($messages);
25 function plugin_new_inline()
27 global $vars, $_plugin_new_elapses;
30 $args = func_get_args();
31 $date = strip_autolink(array_pop($args)); // {date} always exists
33 // Show 'New!' message by the time of the $date string
34 if (func_num_args() > 2) return '&new([nodate]){date};';
37 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)) {
38 $iso8601_date = $dm[1]
39 . '-' . substr('0' . $dm[2], -2)
40 . '-' . substr('0' . $dm[3], -2)
42 $timestamp = strtotime($iso8601_date);
44 if ($timestamp === -1 || $timestamp === FALSE) {
45 return '&new([nodate]){date}: Invalid date string;';
47 $timestamp -= ZONETIME;
49 $retval = in_array('nodate', $args) ? '' : htmlsc($date);
51 // Show 'New!' message by the timestamp of the page
52 if (func_num_args() > 3) return '&new(pagename[,nolink]);';
54 $name = strip_bracket(! empty($args) ? array_shift($args) : $vars['page']);
55 $page = get_fullname($name, $vars['page']);
56 $nolink = in_array('nolink', $args);
58 if (substr($page, -1) == '/') {
59 // Check multiple pages started with "$page"
61 $regex = '/^' . preg_quote($page, '/') . '/';
62 foreach (preg_grep($regex, get_existpages()) as $page) {
63 // Get the latest pagename and its timestamp
64 $_timestamp = get_filetime($page);
65 if ($timestamp < $_timestamp) {
66 $timestamp = $_timestamp;
67 $retval = $nolink ? '' : make_pagelink($page);
71 return '&new(pagename/[,nolink]): No such pages;';
75 $timestamp = get_filetime($page);
76 $retval = $nolink ? '' : make_pagelink($page, $name);
78 return '&new(pagename[,nolink]): No such page;';
83 // Add 'New!' string by the elapsed time
84 $erapse = UTIME - $timestamp;
85 foreach ($_plugin_new_elapses as $limit=>$tag) {
86 if ($erapse <= $limit) {
87 $retval .= sprintf($tag, get_passage($timestamp));
94 return sprintf(PLUGIN_NEW_DATE_FORMAT, $retval);