OSDN Git Service

lastmodified_add(): Just a cleanup
authorhenoheno <henoheno>
Sat, 29 Apr 2006 02:32:49 +0000 (11:32 +0900)
committerhenoheno <henoheno>
Sat, 29 Apr 2006 02:32:49 +0000 (11:32 +0900)
lib/file.php

index b307d1e..748b069 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: file.php,v 1.64 2006/04/25 13:51:56 henoheno Exp $
+// $Id: file.php,v 1.65 2006/04/29 02:32:49 henoheno Exp $
 // Copyright (C)
 //   2002-2006 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -309,11 +309,17 @@ function lastmodified_add($page = '')
 {
        global $maxshow, $whatsnew, $autolink;
 
-       $file = CACHE_DIR . PKWK_MAXSHOW_CACHE;
-       if ($autolink || ! file_exists($file)) {
+       // AutoLink implimentation needs everything, for now
+       if ($autolink) {
                put_lastmodified(); // Try to (re)create ALL
                return;
-       } else if (check_non_list($page)) {
+       }
+
+       if (check_non_list($page)) return; // No need
+
+       $file = CACHE_DIR . PKWK_MAXSHOW_CACHE;
+       if (! file_exists($file)) {
+               put_lastmodified(); // Try to (re)create ALL
                return;
        }
 
@@ -324,16 +330,16 @@ function lastmodified_add($page = '')
        set_file_buffer($fp, 0);
        flock($fp, LOCK_EX);
 
-       // Read
+       // Read (keep the order of the lines)
        $recent_pages = $matches = array();
        foreach(file_head($file, $maxshow + PKWK_MAXSHOW_ALLOWANCE, FALSE) as $line)
                if (preg_match('/^([0-9]+)\t(.+)/', $line, $matches))
                        $recent_pages[$matches[2]] = $matches[1];
 
-       // Remove if exists
+       // Remove if it exists inside
        if (isset($recent_pages[$page])) unset($recent_pages[$page]);
 
-       // Add: array_unshift()
+       // Add to the top: like array_unshift()
        $recent_pages = array($page => get_filetime($page)) + $recent_pages;
 
        // Write
@@ -359,7 +365,7 @@ function lastmodified_add($page = '')
        set_file_buffer($fp, 0);
        flock($fp, LOCK_EX);
 
-       // Write
+       // Recreate
        ftruncate($fp, 0);
        rewind($fp);
        foreach ($recent_pages as $_page=>$time)