OSDN Git Service

Simplify. Renive unused global, shrink, rename internal vars...
[pukiwiki/pukiwiki.git] / plugin / new.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: new.inc.php,v 1.4 2004/07/31 03:09:20 henoheno Exp $
6 //
7
8 // Á´ÂΤÎɽ¼¨¥Õ¥©¡¼¥Þ¥Ã¥È
9 define('NEW_MESSAGE','<span class="comment_date">%s</span>');
10
11 function plugin_new_init()
12 {
13         global $_plugin_new_elapses;
14
15         // ·Ð²áÉÿô => ¿·Ãåɽ¼¨¥¿¥°
16         $messages = array(
17                 '_plugin_new_elapses' => array(
18                         1*60*60*24 => ' <span class="new1" title="%s">New!</span>',
19                         5*60*60*24 => ' <span class="new5" title="%s">New</span>',
20                 ),
21         );
22         set_plugin_messages($messages);
23 }
24 function plugin_new_inline()
25 {
26         global $vars,$_plugin_new_elapses;
27
28         if (func_num_args() < 1)
29         {
30                 return FALSE;
31         }
32         $retval = '';
33         $args = func_get_args();
34         $date = strip_htmltag(array_pop($args)); // {}Éôʬ¤Î°ú¿ô
35         if ($date != '' and ($timestamp = strtotime($date)) !== -1)
36         {
37                 $nodate = in_array('nodate',$args);
38                 $timestamp -= ZONETIME;
39                 $retval = $nodate ? '' : htmlspecialchars($date);
40         }
41         else
42         {
43                 $name = strip_bracket(count($args) ? array_shift($args) : $vars['page']);
44                 $page = get_fullname($name,$vars['page']);
45                 $nolink = in_array('nolink',$args);
46                 $timestamp = 0;
47                 if (substr($page,-1) == '/')
48                 {
49                         foreach (preg_grep('/^'.preg_quote($page,'/').'/',get_existpages()) as $page)
50                         {
51                                 $_timestamp = get_filetime($page);
52                                 if ($timestamp < $_timestamp)
53                                 {
54                                         $retval = $nolink ? '' : make_pagelink($page); // ºÇ¤â¿·¤·¤¤¥Ú¡¼¥¸¤òɽ¼¨
55                                         $timestamp = $_timestamp;
56                                 }
57                         }
58                 }
59                 else if (is_page($page))
60                 {
61                         $retval = $nolink ? '' : make_pagelink($page,$name);
62                         $timestamp = get_filetime($page);
63                 }
64                 if ($timestamp == 0)
65                 {
66                         return '';
67                 }
68         }
69
70         $erapse = UTIME - $timestamp;
71         foreach ($_plugin_new_elapses as $limit=>$tag)
72         {
73                 if ($erapse <= $limit)
74                 {
75                         $retval .= sprintf($tag,get_passage($timestamp));
76                         break;
77                 }
78         }
79         return sprintf(NEW_MESSAGE,$retval);
80 }
81 ?>