2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: new.inc.php,v 1.9 2005/06/16 15:04:08 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
34 // Show 'New!' message by the time of the $date string
35 if (func_num_args() > 2) return '&new([nodate]){date};';
37 $timestamp = strtotime($date);
38 if ($timestamp === -1) return '&new([nodate]){date}: Invalid date string;';
39 $timestamp -= ZONETIME;
41 $retval = in_array('nodate', $args) ? '' : htmlspecialchars($date);
43 // Show 'New!' message by the timestamp of the page
44 if (func_num_args() > 3) return '&new(pagename[,nolink]);';
46 $name = strip_bracket(! empty($args) ? array_shift($args) : $vars['page']);
47 $page = get_fullname($name, $vars['page']);
48 $nolink = in_array('nolink', $args);
50 if (substr($page, -1) == '/') {
51 // Check multiple pages started with "$page"
53 $regex = '/^' . preg_quote($page, '/') . '/';
54 foreach (preg_grep($regex, get_existpages()) as $page) {
55 // Get the latest pagename and its timestamp
56 $_timestamp = get_filetime($page);
57 if ($timestamp < $_timestamp) {
58 $timestamp = $_timestamp;
59 $retval = $nolink ? '' : make_pagelink($page);
63 return '&new(pagename/[,nolink]): No such pages;';
67 $timestamp = get_filetime($page);
68 $retval = $nolink ? '' : make_pagelink($page, $name);
70 return '&new(pagename[,nolink]): No such page;';
75 // Add 'New!' string by the elapsed time
76 $erapse = UTIME - $timestamp;
77 foreach ($_plugin_new_elapses as $limit=>$tag) {
78 if ($erapse <= $limit) {
79 $retval .= sprintf($tag, get_passage($timestamp));
86 return sprintf(PLUGIN_NEW_DATE_FORMAT, $retval);