OSDN Git Service

BugTrack2/361 Simplify URL. Keep slash / and colon : in page name URL
[pukiwiki/pukiwiki.git] / plugin / recent.inc.php
1 <?php
2 // $Id: recent.inc.php,v 1.27 2011/01/25 15:01:01 henoheno Exp $
3 // Copyright (C)
4 //   2002-2007 PukiWiki Developers Team
5 //   2002      Y.MASUI http://masui.net/pukiwiki/ masui@masui.net
6 // License: GPL version 2
7 //
8 // Recent plugin -- Show RecentChanges list
9 //   * Usually used at 'MenuBar' page
10 //   * Also used at special-page, without no #recnet at 'MenuBar'
11
12 // Default number of 'Show latest N changes'
13 define('PLUGIN_RECENT_DEFAULT_LINES', 10);
14
15 // Limit number of executions
16 define('PLUGIN_RECENT_EXEC_LIMIT', 2); // N times per one output
17
18 // ----
19
20 define('PLUGIN_RECENT_USAGE', '#recent(number-to-show)');
21
22 // Place of the cache of 'RecentChanges'
23 define('PLUGIN_RECENT_CACHE', CACHE_DIR . 'recent.dat');
24
25 function plugin_recent_convert()
26 {
27         global $vars, $date_format, $_recent_plugin_frame, $show_passage;
28         static $exec_count = 1;
29
30         $recent_lines = PLUGIN_RECENT_DEFAULT_LINES;
31         if (func_num_args()) {
32                 $args = func_get_args();
33                 if (! is_numeric($args[0]) || isset($args[1])) {
34                         return PLUGIN_RECENT_USAGE . '<br />';
35                 } else {
36                         $recent_lines = $args[0];
37                 }
38         }
39
40         // Show only N times
41         if ($exec_count > PLUGIN_RECENT_EXEC_LIMIT) {
42                 return '#recent(): You called me too much' . '<br />' . "\n";
43         } else {
44                 ++$exec_count;
45         }
46
47         if (! file_exists(PLUGIN_RECENT_CACHE)) {
48                 put_lastmodified();
49                 if (! file_exists(PLUGIN_RECENT_CACHE)) {
50                         return '#recent(): Cache file of RecentChanges not found' . '<br />';
51                 }
52         }
53
54         // Get latest N changes
55         $lines = file_head(PLUGIN_RECENT_CACHE, $recent_lines);
56         if ($lines == FALSE) return '#recent(): File can not open' . '<br />' . "\n";
57
58         $script = get_script_uri();
59         $date = $items = '';
60         foreach ($lines as $line) {
61                 list($time, $page) = explode("\t", rtrim($line));
62
63                 $_date = get_date($date_format, $time);
64                 if ($date != $_date) {
65                         // End of the day
66                         if ($date != '') $items .= '</ul>' . "\n";
67
68                         // New day
69                         $date = $_date;
70                         $items .= '<strong>' . $date . '</strong>' . "\n" .
71                                 '<ul class="recent_list">' . "\n";
72                 }
73
74                 $s_page = htmlsc($page);
75
76                 if ($page === $vars['page']) {
77                         // No need to link to the page you just read, or notify where you just read
78                         $items .= ' <li>' . $s_page . '</li>' . "\n";
79                 } else {
80                         $r_page = pagename_urlencode($page);
81                         $passage = $show_passage ? ' ' . get_passage($time) : '';
82                         $items .= ' <li><a href="' . $script . '?' . $r_page . '"' . 
83                                 ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n";
84                 }
85         }
86         // End of the day
87         if ($date != '') $items .= '</ul>' . "\n";
88
89         return sprintf($_recent_plugin_frame, count($lines), $items);
90 }
91