<?php
-/////////////////////////////////////////////////
// PukiWiki - Yet another WikiWikiWeb clone.
+// $Id: new.inc.php,v 1.9 2005/06/16 15:04:08 henoheno Exp $
//
-// $Id: new.inc.php,v 1.4 2004/07/31 03:09:20 henoheno Exp $
+// New! plugin
//
+// Usage:
+// &new([nodate]){date}; // Check the date string
+// &new(pagename[,nolink]); // Check the pages's timestamp
+// &new(pagename/[,nolink]);
+// // Check multiple pages started with 'pagename/',
+// // and show the latest one
-// Á´ÂΤÎɽ¼¨¥Õ¥©¡¼¥Þ¥Ã¥È
-define('NEW_MESSAGE','<span class="comment_date">%s</span>');
+define('PLUGIN_NEW_DATE_FORMAT', '<span class="comment_date">%s</span>');
function plugin_new_init()
{
- global $_plugin_new_elapses;
-
- // ·Ð²áÉÿô => ¿·Ãåɽ¼¨¥¿¥°
- $messages = array(
- '_plugin_new_elapses' => array(
- 1*60*60*24 => ' <span class="new1" title="%s">New!</span>',
- 5*60*60*24 => ' <span class="new5" title="%s">New</span>',
- ),
- );
+ // Elapsed time => New! message with CSS
+ $messages['_plugin_new_elapses'] = array(
+ 60 * 60 * 24 * 1 => ' <span class="new1" title="%s">New!</span>', // 1day
+ 60 * 60 * 24 * 5 => ' <span class="new5" title="%s">New</span>'); // 5days
set_plugin_messages($messages);
}
+
function plugin_new_inline()
{
- global $vars,$_plugin_new_elapses;
+ global $vars, $_plugin_new_elapses;
- if (func_num_args() < 1)
- {
- return FALSE;
- }
$retval = '';
$args = func_get_args();
- $date = strip_htmltag(array_pop($args)); // {}Éôʬ¤Î°ú¿ô
- if ($date != '' and ($timestamp = strtotime($date)) !== -1)
- {
- $nodate = in_array('nodate',$args);
+ $date = strip_autolink(array_pop($args)); // {date} always exists
+
+ if($date !== '') {
+ // Show 'New!' message by the time of the $date string
+ if (func_num_args() > 2) return '&new([nodate]){date};';
+
+ $timestamp = strtotime($date);
+ if ($timestamp === -1) return '&new([nodate]){date}: Invalid date string;';
$timestamp -= ZONETIME;
- $retval = $nodate ? '' : htmlspecialchars($date);
- }
- else
- {
- $name = strip_bracket(count($args) ? array_shift($args) : $vars['page']);
- $page = get_fullname($name,$vars['page']);
- $nolink = in_array('nolink',$args);
- $timestamp = 0;
- if (substr($page,-1) == '/')
- {
- foreach (preg_grep('/^'.preg_quote($page,'/').'/',get_existpages()) as $page)
- {
+
+ $retval = in_array('nodate', $args) ? '' : htmlspecialchars($date);
+ } else {
+ // Show 'New!' message by the timestamp of the page
+ if (func_num_args() > 3) return '&new(pagename[,nolink]);';
+
+ $name = strip_bracket(! empty($args) ? array_shift($args) : $vars['page']);
+ $page = get_fullname($name, $vars['page']);
+ $nolink = in_array('nolink', $args);
+
+ if (substr($page, -1) == '/') {
+ // Check multiple pages started with "$page"
+ $timestamp = 0;
+ $regex = '/^' . preg_quote($page, '/') . '/';
+ foreach (preg_grep($regex, get_existpages()) as $page) {
+ // Get the latest pagename and its timestamp
$_timestamp = get_filetime($page);
- if ($timestamp < $_timestamp)
- {
- $retval = $nolink ? '' : make_pagelink($page); // ºÇ¤â¿·¤·¤¤¥Ú¡¼¥¸¤òɽ¼¨
+ if ($timestamp < $_timestamp) {
$timestamp = $_timestamp;
+ $retval = $nolink ? '' : make_pagelink($page);
}
}
- }
- else if (is_page($page))
- {
- $retval = $nolink ? '' : make_pagelink($page,$name);
- $timestamp = get_filetime($page);
- }
- if ($timestamp == 0)
- {
- return '';
+ if ($timestamp == 0)
+ return '&new(pagename/[,nolink]): No such pages;';
+ } else {
+ // Check a page
+ if (is_page($page)) {
+ $timestamp = get_filetime($page);
+ $retval = $nolink ? '' : make_pagelink($page, $name);
+ } else {
+ return '&new(pagename[,nolink]): No such page;';
+ }
}
}
+ // Add 'New!' string by the elapsed time
$erapse = UTIME - $timestamp;
- foreach ($_plugin_new_elapses as $limit=>$tag)
- {
- if ($erapse <= $limit)
- {
- $retval .= sprintf($tag,get_passage($timestamp));
+ foreach ($_plugin_new_elapses as $limit=>$tag) {
+ if ($erapse <= $limit) {
+ $retval .= sprintf($tag, get_passage($timestamp));
break;
}
}
- return sprintf(NEW_MESSAGE,$retval);
+
+ if($date !== '') {
+ // Show a date string
+ return sprintf(PLUGIN_NEW_DATE_FORMAT, $retval);
+ } else {
+ // Show a page name
+ return $retval;
+ }
}
?>