Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Haakon Meland Eriksen 2015-07-07 19:24:36 +02:00
commit 3f9e39a9e3
11 changed files with 206 additions and 9 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

@ -137,6 +137,14 @@ use SSL, your webserver must not listen on port 443 at all.
cd mywebsite
util/update_addon_repo matrix
- Create searchable represenations of the online documentation. You may do this any time
that the documentation is updated.
cd mywebsite
util/importdoc
3. Create an empty database and note the access details (hostname, username,
password, database name).

View File

@ -11,25 +11,172 @@
*/
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 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')))
return file_get_contents($s);
return($r[0]['body']);
}
if(file_exists($s))
return file_get_contents($s);
return '';
}}
}
function search_doc_files($s) {
$a = get_app();
$itemspage = get_pconfig(local_channel(),'system','itemspage');
$a->set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20));
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->pager['start']));
// 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.
$regexop = db_getfunc('REGEXP');
$r = q("select item_id.sid, item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and
body $regexop '%s' and item_type = %d $pager_sql",
dbesc($s),
intval(ITEM_TYPE_DOC)
);
$r = fetch_post_tags($r,true);
require_once('include/html2plain.php');
for($x = 0; $x < count($r); $x ++) {
$r[$x]['text'] = html2plain(prepare_text($r[$x]['body'],$r[$x]['mimetype'], true));
$r[$x]['rank'] = 0;
if($r[$x]['term']) {
foreach($r[$x]['term'] as $t) {
if(stristr($t['term'],$s)) {
$r[$x]['rank'] ++;
}
}
}
if(stristr($r[$x]['sid'],$s))
$r[$x]['rank'] ++;
$r[$x]['rank'] += substr_count(strtolower($r[$x]['text']),strtolower($s));
}
usort($r,'doc_rank_sort');
return $r;
}
function doc_rank_sort($a,$b) {
if($a['rank'] == $b['rank'])
return 0;
return (($a['rank'] < $b['rank']) ? 1 : (-1));
}
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,$x['item_id'],ITEM_TYPE_DOC,$s,'docfile',0,$item['mid']);
}
}
function help_content(&$a) {
nav_set_selected('help');
if($_REQUEST['search']) {
$r = search_doc_files($_REQUEST['search']);
if($r) {
$o .= '<ul>';
foreach($r as $rr) {
$dirname = dirname($rr['sid']);
$fname = basename($rr['sid']);
$fname = substr($fname,0,strrpos($fname,'.'));
$path = trim(substr($dirname,4),'/');
$o .= '<li><a href="help/' . (($path) ? $path . '/' : '') . $fname . '" >' . ucwords(str_replace('_',' ',notags($fname))) . '</a><br />' .
str_replace('$Projectname',PLATFORM_NAME,substr($rr['text'],0,200)) . '...<br /><br /></li>';
}
$o .= '</ul>';
}
return $o;
}
global $lang;
$doctype = 'markdown';

View File

@ -59,6 +59,10 @@ function search_content(&$a,$update = 0, $load = false) {
$search = substr($search,1);
goaway(z_root() . '/directory' . '?f=1&navsearch=1&search=' . $search);
}
if(strpos($search,'?') === 0) {
$search = substr($search,1);
goaway(z_root() . '/help' . '?f=1&navsearch=1&search=' . $search);
}
// look for a naked webbie
if(strpos($search,'@') !== false) {

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/*');

View File

@ -1 +1 @@
2015-07-03.1082
2015-07-06.1085

View File

@ -13,6 +13,10 @@
border-bottom-right-radius: 0px;
}
.tags {
word-wrap: break-word;
}
/* suggest */
.suggest-widget-more {

View File

@ -46,7 +46,7 @@ if (! $radius)
if (! $shadow)
$shadow = "0";
if (! $converse_width)
$converse_width = "640";
$converse_width = "676";
if(! $top_photo)
$top_photo = '48px';
if(! $comment_indent)