• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonwindowsphpgamebathyscaphegui翻訳comegattwitterframeworkbtronvb.net計画中(planning stage)testdomarduinodirectxpreviewerゲームエンジン

Commit MetaInfo

Revisiona61cb590fa96e5b69075771124df1879ae0e35df (tree)
Time2014-11-30 09:39:28
Authorhenoheno <henoheno>
Commiterumorigu

Log Message

get_source(): Returns FALSE if error occurerd. Cleanup. Remove redundant is_page()

Change Summary

Incremental Difference

--- a/lib/file.php
+++ b/lib/file.php
@@ -16,31 +16,43 @@ define('PKWK_MAXSHOW_CACHE', 'recent.dat');
1616 define('PKWK_AUTOLINK_REGEX_CACHE', 'autolink.dat');
1717
1818 // Get source(wiki text) data of the page
19+// Returns FALSE if error occurerd
1920 function get_source($page = NULL, $lock = TRUE, $join = FALSE)
2021 {
22+ //$result = NULL; // File is not found
2123 $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
2227
23- if (is_page($page)) {
24- $path = get_filename($page);
28+ $path = get_filename($page);
29+ if (file_exists($path)) {
2530
2631 if ($lock) {
2732 $fp = @fopen($path, 'r');
28- if ($fp == FALSE) return $result;
33+ if ($fp == FALSE) return FALSE;
2934 flock($fp, LOCK_SH);
3035 }
3136
3237 if ($join) {
3338 // Returns a value
3439 $size = filesize($path);
35- if ($size > 0) {
36- $result = str_replace("\r", '', fread($fp, filesize($path)));
40+ if ($size === FALSE) {
41+ $result = FALSE;
3742 } else {
38- $result = '';
43+ $result = fread($fp, $size);
44+ if ($result !== FALSE) {
45+ // Removing line-feeds
46+ $result = str_replace("\r", '', $result);
47+ }
3948 }
4049 } else {
4150 // 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+ }
4456 }
4557
4658 if ($lock) {