OSDN Git Service

BugTrack/2401 Locked file_get_contents/file_put_contents on bugtrack
[pukiwiki/pukiwiki.git] / lib / file.php
index 79c7ad7..b90a2f8 100644 (file)
@@ -44,7 +44,7 @@ function get_source($page = NULL, $lock = TRUE, $join = FALSE)
                        } else {
                                $result = fread($fp, $size);
                                if ($result !== FALSE) {
-                                       // Removing line-feeds
+                                       // Removing Carriage-Return
                                        $result = str_replace("\r", '', $result);
                                }
                        }
@@ -52,7 +52,7 @@ function get_source($page = NULL, $lock = TRUE, $join = FALSE)
                        // Returns an array
                        $result = file($path);
                        if ($result !== FALSE) {
-                               // Removing line-feeds
+                               // Removing Carriage-Return
                                $result = str_replace("\r", '', $result);
                        }
                }
@@ -169,10 +169,7 @@ function make_str_rules($source)
 
 function add_author_info($wikitext)
 {
-       global $auth_user, $auth_user_fullname, $auth_type, $ldap_user_account;
-       global $auth_provider_user_prefix_default;
-       global $auth_provider_user_prefix_ldap;
-       global $auth_provider_user_prefix_external;
+       global $auth_user, $auth_user_fullname;
        $author = preg_replace('/"/', '', $auth_user);
        $fullname = $auth_user_fullname;
        if (!$fullname && $author) {
@@ -180,24 +177,7 @@ function add_author_info($wikitext)
                $fullname = preg_replace('/^[^:]*:/', '', $author);
        }
        $displayname = preg_replace('/"/', '', $fullname);
-       $user_prefix = '';
-       switch ($auth_type) {
-               case AUTH_TYPE_BASIC:
-                       $user_prefix = $auth_provider_user_prefix_default;
-                       break;
-               case AUTH_TYPE_EXTERNAL:
-               case AUTH_TYPE_EXTERNAL_REMOTE_USER:
-               case AUTH_TYPE_EXTERNAL_X_FORWARDED_USER:
-                       $user_prefix = $auth_provider_user_prefix_external;
-                       break;
-               case AUTH_TYPE_FORM:
-                       if ($ldap_user_account) {
-                               $user_prefix = $auth_provider_user_prefix_ldap;
-                       } else {
-                               $user_prefix = $auth_provider_user_prefix_default;
-                       }
-                       break;
-       }
+       $user_prefix = get_auth_user_prefix();
        $author_text = sprintf('#author("%s","%s","%s")',
                get_date_atom(UTIME + LOCALZONE),
                ($author ? $user_prefix . $author : ''),
@@ -861,3 +841,19 @@ function pkwk_touch_file($filename, $time = FALSE, $atime = FALSE)
                        htmlsc(basename($filename)));
        }
 }
+
+/**
+ * Lock-enabled file_get_contents
+ *
+ * Require: PHP5+
+ */
+function pkwk_file_get_contents($filename) {
+       if (! file_exists($filename)) {
+               return false;
+       }
+       $fp   = fopen($filename, 'rb');
+       flock($fp, LOCK_SH);
+       $file = file_get_contents($filename);
+       flock($fp, LOCK_UN);
+       return $file;
+}