2 // $Id: recent.inc.php,v 1.27 2011/01/25 15:01:01 henoheno Exp $
4 // 2002-2007 PukiWiki Developers Team
5 // 2002 Y.MASUI http://masui.net/pukiwiki/ masui@masui.net
6 // License: GPL version 2
8 // Recent plugin -- Show RecentChanges list
9 // * Usually used at 'MenuBar' page
10 // * Also used at special-page, without no #recnet at 'MenuBar'
12 // Default number of 'Show latest N changes'
13 define('PLUGIN_RECENT_DEFAULT_LINES', 10);
15 // Limit number of executions
16 define('PLUGIN_RECENT_EXEC_LIMIT', 2); // N times per one output
20 define('PLUGIN_RECENT_USAGE', '#recent(number-to-show)');
22 // Place of the cache of 'RecentChanges'
23 define('PLUGIN_RECENT_CACHE', CACHE_DIR . 'recent.dat');
25 function plugin_recent_convert()
27 global $vars, $date_format, $_recent_plugin_frame, $show_passage;
28 static $exec_count = 1;
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 />';
36 $recent_lines = $args[0];
41 if ($exec_count > PLUGIN_RECENT_EXEC_LIMIT) {
42 return '#recent(): You called me too much' . '<br />' . "\n";
47 if (! file_exists(PLUGIN_RECENT_CACHE))
48 return '#recent(): Cache file of RecentChanges not found' . '<br />';
50 // Get latest N changes
51 $lines = file_head(PLUGIN_RECENT_CACHE, $recent_lines);
52 if ($lines == FALSE) return '#recent(): File can not open' . '<br />' . "\n";
54 $script = get_script_uri();
56 foreach ($lines as $line) {
57 list($time, $page) = explode("\t", rtrim($line));
59 $_date = get_date($date_format, $time);
60 if ($date != $_date) {
62 if ($date != '') $items .= '</ul>' . "\n";
66 $items .= '<strong>' . $date . '</strong>' . "\n" .
67 '<ul class="recent_list">' . "\n";
70 $s_page = htmlsc($page);
72 if ($page === $vars['page']) {
73 // No need to link to the page you just read, or notify where you just read
74 $items .= ' <li>' . $s_page . '</li>' . "\n";
76 $r_page = rawurlencode($page);
77 $passage = $show_passage ? ' ' . get_passage($time) : '';
78 $items .= ' <li><a href="' . $script . '?' . $r_page . '"' .
79 ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n";
83 if ($date != '') $items .= '</ul>' . "\n";
85 return sprintf($_recent_plugin_frame, count($lines), $items);