2 // $Id: recent.inc.php,v 1.22 2006/03/05 13:56:23 henoheno Exp $
4 // 2002-2006 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 // Get latest N changes
48 if (file_exists(PLUGIN_RECENT_CACHE)) {
49 // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
50 $lines = file(PLUGIN_RECENT_CACHE); // with array_splice()
51 $lines = array_splice($lines, 0, $recent_lines);
53 return '#recent(): Cache file of RecentChanges not found' . '<br />';
56 $script = get_script_uri();
58 foreach ($lines as $line) {
59 list($time, $page) = explode("\t", rtrim($line));
61 $_date = get_date($date_format, $time);
62 if ($date != $_date) {
64 if ($date != '') $items .= '</ul>' . "\n";
68 $items .= '<strong>' . $date . '</strong>' . "\n" .
69 '<ul class="recent_list">' . "\n";
72 $s_page = htmlspecialchars($page);
73 if($page == $vars['page']) {
74 // No need to link to the page you just read, or notify where you just read
75 $items .= ' <li>' . $s_page . '</li>' . "\n";
77 $r_page = rawurlencode($page);
78 $passage = $show_passage ? ' ' . get_passage($time) : '';
79 $items .= ' <li><a href="' . $script . '?' . $r_page . '"' .
80 ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n";
84 if ($date != '') $items .= '</ul>' . "\n";
86 return sprintf($_recent_plugin_frame, count($lines), $items);