2 // PukiWiki - Yet another WikiWikiWeb clone
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
9 // Recent plugin -- Show RecentChanges list
10 // * Usually used at 'MenuBar' page
11 // * Also used at special-page, without no #recnet at 'MenuBar'
13 // Default number of 'Show latest N changes'
14 define('PLUGIN_RECENT_DEFAULT_LINES', 10);
16 // Limit number of executions
17 define('PLUGIN_RECENT_EXEC_LIMIT', 2); // N times per one output
21 define('PLUGIN_RECENT_USAGE', '#recent(number-to-show)');
23 // Place of the cache of 'RecentChanges'
24 define('PLUGIN_RECENT_CACHE', CACHE_DIR . 'recent.dat');
26 function plugin_recent_convert()
28 global $vars, $date_format, $_recent_plugin_frame;
29 static $exec_count = 1;
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 />';
37 $recent_lines = $args[0];
42 if ($exec_count > PLUGIN_RECENT_EXEC_LIMIT) {
43 return '#recent(): You called me too much' . '<br />' . "\n";
48 if (! file_exists(PLUGIN_RECENT_CACHE)) {
50 if (! file_exists(PLUGIN_RECENT_CACHE)) {
51 return '#recent(): Cache file of RecentChanges not found' . '<br />';
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";
59 foreach ($lines as $line) {
60 list($time, $page) = explode("\t", rtrim($line));
62 $_date = get_date($date_format, $time);
63 if ($date != $_date) {
65 if ($date != '') $items .= '</ul>' . "\n";
69 $items .= '<strong>' . $date . '</strong>' . "\n" .
70 '<ul class="recent_list">' . "\n";
73 $s_page = htmlsc($page);
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";
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";
86 if ($date != '') $items .= '</ul>' . "\n";
88 return sprintf($_recent_plugin_frame, count($lines), $items);