Revision | a61cb590fa96e5b69075771124df1879ae0e35df (tree) |
---|---|
Time | 2014-11-30 09:39:28 |
Author | henoheno <henoheno> |
Commiter | umorigu |
get_source(): Returns FALSE if error occurerd. Cleanup. Remove redundant is_page()
@@ -16,31 +16,43 @@ define('PKWK_MAXSHOW_CACHE', 'recent.dat'); | ||
16 | 16 | define('PKWK_AUTOLINK_REGEX_CACHE', 'autolink.dat'); |
17 | 17 | |
18 | 18 | // Get source(wiki text) data of the page |
19 | +// Returns FALSE if error occurerd | |
19 | 20 | function get_source($page = NULL, $lock = TRUE, $join = FALSE) |
20 | 21 | { |
22 | + //$result = NULL; // File is not found | |
21 | 23 | $result = $join ? '' : array(); |
24 | + // Compat for "implode('', get_source($file))", | |
25 | + // -- this is slower than "get_source($file, TRUE, TRUE)" | |
26 | + // Compat for foreach(get_source($file) as $line) {} not to warns | |
22 | 27 | |
23 | - if (is_page($page)) { | |
24 | - $path = get_filename($page); | |
28 | + $path = get_filename($page); | |
29 | + if (file_exists($path)) { | |
25 | 30 | |
26 | 31 | if ($lock) { |
27 | 32 | $fp = @fopen($path, 'r'); |
28 | - if ($fp == FALSE) return $result; | |
33 | + if ($fp == FALSE) return FALSE; | |
29 | 34 | flock($fp, LOCK_SH); |
30 | 35 | } |
31 | 36 | |
32 | 37 | if ($join) { |
33 | 38 | // Returns a value |
34 | 39 | $size = filesize($path); |
35 | - if ($size > 0) { | |
36 | - $result = str_replace("\r", '', fread($fp, filesize($path))); | |
40 | + if ($size === FALSE) { | |
41 | + $result = FALSE; | |
37 | 42 | } else { |
38 | - $result = ''; | |
43 | + $result = fread($fp, $size); | |
44 | + if ($result !== FALSE) { | |
45 | + // Removing line-feeds | |
46 | + $result = str_replace("\r", '', $result); | |
47 | + } | |
39 | 48 | } |
40 | 49 | } else { |
41 | 50 | // Returns an array |
42 | - // Removing line-feeds: Because file() doesn't remove them. | |
43 | - $result = str_replace("\r", '', file($path)); | |
51 | + $result = file($path); | |
52 | + if ($result !== FALSE) { | |
53 | + // Removing line-feeds | |
54 | + $result = str_replace("\r", '', $result); | |
55 | + } | |
44 | 56 | } |
45 | 57 | |
46 | 58 | if ($lock) { |