From df8f6e45e244be95dd8ddc51e1f0b1245eaebc6e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sat, 4 Jul 2015 14:46:40 -0700 Subject: [PATCH 1/9] mod/help: read doc files from the database if present and newer than the copy in the filesystem. --- mod/help.php | 32 +++++++++++++++++++++++++++----- 1 file 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) { From 2011784faf68dd97241318a9d14fcecc354c5118 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 5 Jul 2015 22:37:52 +0200 Subject: [PATCH 2/9] schema focus: adjust default width --- view/theme/redbasic/schema/focus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/theme/redbasic/schema/focus.php b/view/theme/redbasic/schema/focus.php index 2a6900271..d93ee003e 100644 --- a/view/theme/redbasic/schema/focus.php +++ b/view/theme/redbasic/schema/focus.php @@ -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) From f20933e1e0f955d49fff3780c367ea2edf581728 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 5 Jul 2015 19:52:41 -0700 Subject: [PATCH 3/9] more work on db storage of doco --- doc/main.bb | 1 - include/items.php | 2 ++ include/nav.php | 4 ++-- mod/help.php | 59 +++++++++++++++++++++++++++++++++++++++++++---- util/importdoc | 33 ++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 7 deletions(-) create mode 100755 util/importdoc diff --git a/doc/main.bb b/doc/main.bb index d71f819b2..4428b152b 100644 --- a/doc/main.bb +++ b/doc/main.bb @@ -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. diff --git a/include/items.php b/include/items.php index 5e584b09c..c067d3c1e 100755 --- a/include/items.php +++ b/include/items.php @@ -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; diff --git a/include/nav.php b/include/nav.php index 0ca554897..898805bba 100644 --- a/include/nav.php +++ b/include/nav.php @@ -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...') )); diff --git a/mod/help.php b/mod/help.php index ff51799d9..7d024a725 100644 --- a/mod/help.php +++ b/mod/help.php @@ -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'); diff --git a/util/importdoc b/util/importdoc new file mode 100755 index 000000000..b89e12e97 --- /dev/null +++ b/util/importdoc @@ -0,0 +1,33 @@ +#!/usr/bin/env php + Date: Sun, 5 Jul 2015 21:09:04 -0700 Subject: [PATCH 4/9] very crude but working doc search --- install/INSTALL.txt | 8 ++++++++ mod/help.php | 48 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/install/INSTALL.txt b/install/INSTALL.txt index 003defeed..65df17fdd 100644 --- a/install/INSTALL.txt +++ b/install/INSTALL.txt @@ -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). diff --git a/mod/help.php b/mod/help.php index 7d024a725..2ced3d30a 100644 --- a/mod/help.php +++ b/mod/help.php @@ -12,6 +12,9 @@ + + + function load_doc_file($s) { $lang = get_app()->language; if(! isset($lang)) @@ -49,6 +52,30 @@ function find_doc_file($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. + + $r = q("select item_id.sid, item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and + body regexp '%s' and item_type = %d order by created desc $pager_sql", + dbesc($s), + intval(ITEM_TYPE_DOC) + ); + + return $r; +} + + + + + function store_doc_file($s) { @@ -93,7 +120,7 @@ function store_doc_file($s) { } if($x['success']) { - update_remote_id($sys['channel_id'],$x['item_id'],ITEM_TYPE_DOC,$s,'docfile',0,$item['mid']); + update_remote_id($sys,$x['item_id'],ITEM_TYPE_DOC,$s,'docfile',0,$item['mid']); } @@ -103,6 +130,25 @@ function store_doc_file($s) { function help_content(&$a) { nav_set_selected('help'); + if($_REQUEST['search']) { + $r = search_doc_files($_REQUEST['search']); + if($r) { + $o .= '
    '; + foreach($r as $rr) { + $dirname = dirname($rr['sid']); + $fname = basename($rr['sid']); + $fname = substr($fname,0,strrpos($fname,'.')); + $path = trim(substr($dirname,4),'/'); + + $o .= '
  • ' . ucwords(str_replace('_',' ',notags($fname))) . '
  • '; + + } + $o .= '
'; + } + return $o; + } + + global $lang; $doctype = 'markdown'; From f7c562fd21c79e86bf40f04ba0bf543fb6c05dd8 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 5 Jul 2015 21:37:04 -0700 Subject: [PATCH 5/9] version update --- version.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.inc b/version.inc index 39bb632b7..fde4576cc 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2015-07-03.1082 +2015-07-05.1084 From 05b231b087a5e2d11199351db35cd84a171c8197 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 6 Jul 2015 10:36:57 +0200 Subject: [PATCH 6/9] fix word wrapping in tagblock and dirtagblock and possibly other places --- view/css/widgets.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/view/css/widgets.css b/view/css/widgets.css index 0a901b1f9..63c380c75 100644 --- a/view/css/widgets.css +++ b/view/css/widgets.css @@ -13,6 +13,10 @@ border-bottom-right-radius: 0px; } +.tags { + word-wrap: break-word; +} + /* suggest */ .suggest-widget-more { From 48972d1e8a4761150e31e0322647387adccc735e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 6 Jul 2015 17:38:50 -0700 Subject: [PATCH 7/9] version update --- version.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.inc b/version.inc index fde4576cc..fe5a631ad 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2015-07-05.1084 +2015-07-06.1085 From 7cfaae8d4fb8402c78a707e73b4dd64c568c4c8c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 6 Jul 2015 20:21:41 -0700 Subject: [PATCH 8/9] ok that's wretchedly inefficient but provides a basic relevance search for strings in doc files. --- mod/help.php | 32 ++++++++++++++++++++++++++++++-- mod/search.php | 4 ++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/mod/help.php b/mod/help.php index 2ced3d30a..809313a3e 100644 --- a/mod/help.php +++ b/mod/help.php @@ -63,16 +63,43 @@ function search_doc_files($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. + $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 regexp '%s' and item_type = %d order by created desc $pager_sql", + 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)); +} @@ -140,7 +167,8 @@ function help_content(&$a) { $fname = substr($fname,0,strrpos($fname,'.')); $path = trim(substr($dirname,4),'/'); - $o .= '
  • ' . ucwords(str_replace('_',' ',notags($fname))) . '
  • '; + $o .= '
  • ' . ucwords(str_replace('_',' ',notags($fname))) . '
    ' . + str_replace('$Projectname',PLATFORM_NAME,substr($rr['text'],0,200)) . '...

  • '; } $o .= ''; diff --git a/mod/search.php b/mod/search.php index dceb7d72a..ce8357fb9 100644 --- a/mod/search.php +++ b/mod/search.php @@ -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) { From 862bfbdd2bc60b201918d02351f2591ccf5aea04 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 6 Jul 2015 20:29:21 -0700 Subject: [PATCH 9/9] incorrectly named doc file --- doc/{Primary-Directory => Primary-Directory.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename doc/{Primary-Directory => Primary-Directory.md} (100%) diff --git a/doc/Primary-Directory b/doc/Primary-Directory.md similarity index 100% rename from doc/Primary-Directory rename to doc/Primary-Directory.md