mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 12:35:13 +00:00
mod/help: read doc files from the database if present and newer than the copy in the filesystem.
This commit is contained in:
parent
a74631b554
commit
df8f6e45e2
1 changed files with 27 additions and 5 deletions
32
mod/help.php
32
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) {
|
||||
|
|
Loading…
Reference in a new issue