OSDN Git Service

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