OSDN Git Service

BugTrack/2470 Lengthen Footnote title max-length to 100 chars
[pukiwiki/pukiwiki.git] / plugin / recent.inc.php
index 897832a..f90b916 100644 (file)
@@ -1,62 +1,89 @@
 <?php
-/*
- * PukiWiki ºÇ¿·¤Î?·ï¤òɽ¼¨¤¹¤ë¥×¥é¥°¥¤¥ó
- *
- * CopyRight 2002 Y.MASUI GPL2
- * http://masui.net/pukiwiki/ masui@masui.net
- *
- * Êѹ¹ÍúÎò:
- *  2002.04.08: pat¤µ¤ó¡¢¤ß¤Î¤ë¤µ¤ó¤Î»ØŦ¤Ë¤è¤ê¡¢¥ê¥ó¥¯À褬ÆüËܸì¤Î¾ì¹ç¤Ë
- *              ²½¤±¤ë¤Î¤ò½¤Àµ
- *
- *  2002.06.17: plugin_recent_init()¤òÀßÄê
- *  2002.07.02: <ul>¤Ë¤è¤ë½ÐÎϤËÊѹ¹¤·¹½Â¤²½
- *
- * $Id: recent.inc.php,v 1.13 2004/09/04 14:26:52 henoheno Exp $
- */
-
-// RecentChanges¤Î¥­¥ã¥Ã¥·¥å
+// PukiWiki - Yet another WikiWikiWeb clone
+// recent.inc.php
+// Copyright
+//   2002-2017 PukiWiki Development Team
+//   2002      Y.MASUI http://masui.net/pukiwiki/ masui@masui.net
+// License: GPL v2 or (at your option) any later version
+//
+// Recent plugin -- Show RecentChanges list
+//   * Usually used at 'MenuBar' page
+//   * Also used at special-page, without no #recnet at 'MenuBar'
+
+// Default number of 'Show latest N changes'
+define('PLUGIN_RECENT_DEFAULT_LINES', 10);
+
+// Limit number of executions
+define('PLUGIN_RECENT_EXEC_LIMIT', 2); // N times per one output
+
+// ----
+
+define('PLUGIN_RECENT_USAGE', '#recent(number-to-show)');
+
+// Place of the cache of 'RecentChanges'
 define('PLUGIN_RECENT_CACHE', CACHE_DIR . 'recent.dat');
 
 function plugin_recent_convert()
 {
-       global $script, $vars, $date_format;
-       global $_recent_plugin_frame;
-
-       if (! file_exists(PLUGIN_RECENT_CACHE)) return '';
+       global $vars, $date_format, $_recent_plugin_frame;
+       static $exec_count = 1;
 
-       $recent_lines = 10;
+       $recent_lines = PLUGIN_RECENT_DEFAULT_LINES;
        if (func_num_args()) {
                $args = func_get_args();
-               if (is_numeric($args[0]))
+               if (! is_numeric($args[0]) || isset($args[1])) {
+                       return PLUGIN_RECENT_USAGE . '<br />';
+               } else {
                        $recent_lines = $args[0];
+               }
        }
 
-       // ÀèƬ¤ÎN·ï(¹Ô)¤ò¼è¤ê½Ð¤¹
-       $lines = array_splice(file(PLUGIN_RECENT_CACHE), 0, $recent_lines);
+       // Show only N times
+       if ($exec_count > PLUGIN_RECENT_EXEC_LIMIT) {
+               return '#recent(): You called me too much' . '<br />' . "\n";
+       } else {
+               ++$exec_count;
+       }
+
+       if (! file_exists(PLUGIN_RECENT_CACHE)) {
+               put_lastmodified();
+               if (! file_exists(PLUGIN_RECENT_CACHE)) {
+                       return '#recent(): Cache file of RecentChanges not found' . '<br />';
+               }
+       }
 
+       // Get latest N changes
+       $lines = file_head(PLUGIN_RECENT_CACHE, $recent_lines);
+       if ($lines == FALSE) return '#recent(): File can not open' . '<br />' . "\n";
        $date = $items = '';
        foreach ($lines as $line) {
                list($time, $page) = explode("\t", rtrim($line));
+
                $_date = get_date($date_format, $time);
                if ($date != $_date) {
-                       if ($date != '') $items .= '</ul>';
+                       // End of the day
+                       if ($date != '') $items .= '</ul>' . "\n";
+
+                       // New day
                        $date = $_date;
-                       $items .= "<strong>$date</strong>\n" .
-                               "<ul class=\"recent_list\">\n";
+                       $items .= '<strong>' . $date . '</strong>' . "\n" .
+                               '<ul class="recent_list">' . "\n";
                }
-               $s_page = htmlspecialchars($page);
-               $r_page = rawurlencode($page);
-               $pg_passage = get_pg_passage($page, FALSE);
-               if($page == $vars['page']) {
-                       // No need to link itself, notifies where you just read
-                       $items .= " <li><span title=\"$s_page $pg_passage\">$s_page</span></li>\n";
+
+               $s_page = htmlsc($page);
+
+               if ($page === $vars['page']) {
+                       // No need to link to the page you just read, or notify where you just read
+                       $items .= ' <li>' . $s_page . '</li>' . "\n";
                } else {
-                       $items .= " <li><a href=\"$script?$r_page\" title=\"$s_page $pg_passage\">$s_page</a></li>\n";
+                       $attrs = get_page_link_a_attrs($page);
+                       $items .= ' <li><a href="' . get_page_uri($page) . '" class="' .
+                               $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] .
+                               '">' . $s_page . '</a></li>' . "\n";
                }
        }
-       if (! empty($lines)) $items .= "</ul>\n";
+       // End of the day
+       if ($date != '') $items .= '</ul>' . "\n";
 
        return sprintf($_recent_plugin_frame, count($lines), $items);
 }
-?>