more work on db storage of doco

This commit is contained in:
redmatrix 2015-07-05 19:52:41 -07:00
parent df8f6e45e2
commit f20933e1e0
5 changed files with 92 additions and 7 deletions

View File

@ -1,4 +1,3 @@
[img][baseurl]/assets/hashlogo.png[/img]
[zrl=[baseurl]/help/about][b]What is the $Projectname?[/b][/zrl]
$Projectname is a decentralized communication and publishing platform that enables you to keep in control of your communication needs by automatic encryption and finely grained access control. It's you, and only you who decides who is allowed to see your stuff.

View File

@ -4911,6 +4911,8 @@ function update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remo
$page_type = 'BUILDBLOCK';
elseif($webpage == ITEM_TYPE_PDL)
$page_type = 'PDL';
elseif($webpage == ITEM_TYPE_DOC)
$page_type = 'docfile';
elseif($namespace && $remote_id) {
$page_type = $namespace;
$pagetitle = $remote_id;

View File

@ -157,7 +157,7 @@ EOT;
$nav['apps'] = array('apps', t('Apps'), "", t('Applications, utilities, links, games'),'apps_nav_btn');
$nav['search'] = array('search', t('Search'), "", t('Search site content'));
$nav['search'] = array('search', t('Search'), "", t('Search site @name, #tag, ?docs, content'));
$nav['directory'] = array('directory', t('Directory'), "", t('Channel Directory'),'directory_nav_btn');
@ -244,7 +244,7 @@ $powered_by = '';
'$localuser' => local_channel(),
'$sel' => $a->nav_sel,
'$powered_by' => $powered_by,
'$help' => t('@name, #tag, content'),
'$help' => t('@name, #tag, ?doc, content'),
'$pleasewait' => t('Please wait...')
));

View File

@ -33,13 +33,14 @@ 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)
$r = q("select item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and
sid = '%s' and item_type = %d limit 1",
dbesc($s),
intval(ITEM_TYPE_DOC)
);
if($r) {
if($file_exists($s) && (filemtime($s) > datetime_convert('UTC','UTC',$r[0]['edited'],'U')))
if(file_exists($s) && (filemtime($s) > datetime_convert('UTC','UTC',$r[0]['edited'],'U')))
return file_get_contents($s);
return($r[0]['body']);
}
@ -49,6 +50,56 @@ function find_doc_file($s) {
}
function store_doc_file($s) {
if(is_dir($s))
return;
$item = array();
$sys = get_sys_channel();
$item['aid'] = 0;
$item['uid'] = $sys['channel_id'];
if(strpos($s,'.md'))
$item['mimetype'] = 'text/markdown';
elseif(strpos($s,'.html'))
$item['mimetype'] = 'text/html';
else
$item['mimetype'] = 'text/bbcode';
$item['body'] = file_get_contents($s);
$item['plink'] = z_root() . '/' . str_replace('doc','help',$s);
$item['owner_xchan'] = $item['author_xchan'] = $sys['channel_hash'];
$item['item_type'] = ITEM_TYPE_DOC;
$r = q("select item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and
sid = '%s' and item_type = %d limit 1",
dbesc($s),
intval(ITEM_TYPE_DOC)
);
if($r) {
$item['id'] = $r[0]['id'];
$item['mid'] = $item['parent_mid'] = $r[0]['mid'];
$x = item_store_update($item);
}
else {
$item['mid'] = $item['parent_mid'] = item_message_id();
$x = item_store($item);
}
if($x['success']) {
update_remote_id($sys['channel_id'],$x['item_id'],ITEM_TYPE_DOC,$s,'docfile',0,$item['mid']);
}
}
function help_content(&$a) {
nav_set_selected('help');

33
util/importdoc Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env php
<?php
require_once('include/cli_startup.php');
cli_startup();
require_once('mod/help.php');
function update_docs_dir($s) {
$f = basename($s);
$d = dirname($s);
if($s === 'doc/html')
return;
$files = glob("$d/$f");
if($files) {
foreach($files as $fi) {
if($fi === 'doc/html')
continue;
echo $fi . "\n";
if(is_dir($fi))
update_docs_dir("$fi/*");
else
store_doc_file($fi);
}
}
}
update_docs_dir('doc/*');