diff options
author | redmatrix <redmatrix@redmatrix.me> | 2015-07-04 14:46:40 -0700 |
---|---|---|
committer | redmatrix <redmatrix@redmatrix.me> | 2015-07-04 14:46:40 -0700 |
commit | df8f6e45e244be95dd8ddc51e1f0b1245eaebc6e (patch) | |
tree | 2f1d40e2a175ec8b388613da49667d698f65ff3f /mod | |
parent | a74631b55456bdbe24594bfc40c6e12bfa44c196 (diff) | |
download | volse-hubzilla-df8f6e45e244be95dd8ddc51e1f0b1245eaebc6e.tar.gz volse-hubzilla-df8f6e45e244be95dd8ddc51e1f0b1245eaebc6e.tar.bz2 volse-hubzilla-df8f6e45e244be95dd8ddc51e1f0b1245eaebc6e.zip |
mod/help: read doc files from the database if present and newer than the copy in the filesystem.
Diffstat (limited to 'mod')
-rw-r--r-- | mod/help.php | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/mod/help.php b/mod/help.php index 694b356aa..ff51799d9 100644 --- a/mod/help.php +++ b/mod/help.php @@ -11,20 +11,42 @@ */ -if(! function_exists('load_doc_file')) { + function load_doc_file($s) { $lang = get_app()->language; if(! isset($lang)) $lang = 'en'; $b = basename($s); $d = dirname($s); - if(file_exists("$d/$lang/$b")) - return file_get_contents("$d/$lang/$b"); + + $c = find_doc_file("$d/$lang/$b"); + if($c) + return $c; + $c = find_doc_file($s); + if($c) + return $c; + return ''; +} + +function find_doc_file($s) { + + // If the file was edited more recently than we've stored a copy in the database, use the file. + // The stored database item will be searchable, the file won't be. + + $r = q("select * from item left join item_id on item.id = item.iid where service = 'docfile' and + sid = '%s' limit 1", + dbesc($s) + ); + + if($r) { + if($file_exists($s) && (filemtime($s) > datetime_convert('UTC','UTC',$r[0]['edited'],'U'))) + return file_get_contents($s); + return($r[0]['body']); + } if(file_exists($s)) return file_get_contents($s); return ''; -}} - +} function help_content(&$a) { |