OSDN Git Service

htmlsc(): Just sugar for htmlspecialchars(), and a foundation
[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-2006 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                 return '#recent(): Cache file of RecentChanges not found' . '<br />';
49
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";
53
54         $script = get_script_uri();
55         $date = $items = '';
56         foreach ($lines as $line) {
57                 list($time, $page) = explode("\t", rtrim($line));
58
59                 $_date = get_date($date_format, $time);
60                 if ($date != $_date) {
61                         // End of the day
62                         if ($date != '') $items .= '</ul>' . "\n";
63
64                         // New day
65                         $date = $_date;
66                         $items .= '<strong>' . $date . '</strong>' . "\n" .
67                                 '<ul class="recent_list">' . "\n";
68                 }
69
70                 $s_page = htmlsc($page);
71                 if($page == $vars['page']) {
72                         // No need to link to the page you just read, or notify where you just read
73                         $items .= ' <li>' . $s_page . '</li>' . "\n";
74                 } else {
75                         $r_page = rawurlencode($page);
76                         $passage = $show_passage ? ' ' . get_passage($time) : '';
77                         $items .= ' <li><a href="' . $script . '?' . $r_page . '"' . 
78                                 ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n";
79                 }
80         }
81         // End of the day
82         if ($date != '') $items .= '</ul>' . "\n";
83
84         return sprintf($_recent_plugin_frame, count($lines), $items);
85 }
86 ?>