diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/widgets.php | 19 | ||||
-rw-r--r-- | include/wiki.php | 38 |
2 files changed, 47 insertions, 10 deletions
diff --git a/include/widgets.php b/include/widgets.php index 1cc6dfc28..0d734d6cf 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -877,14 +877,21 @@ function widget_wiki_list($arr) { function widget_wiki_pages($arr) { require_once("include/wiki.php"); - $r = wiki_pages(App::$profile['channel_hash']); - if($r) { - return replace_macros(get_markup_template('wiki_page_list.tpl'), array( - '$header' => t('Wiki Pages'), - '$pages' => $r['pages'] - )); + $pages = array(); + if (!array_key_exists('resource_id', $arr)) { + $hide = true; + } else { + $p = wiki_page_list($arr['resource_id']); + if ($p['pages']) { + $pages = $p['pages']; + } } + return replace_macros(get_markup_template('wiki_page_list.tpl'), array( + '$hide' => $hide, + '$header' => t('Wiki Pages'), + '$pages' => $pages + )); } function widget_bookmarkedchats($arr) { diff --git a/include/wiki.php b/include/wiki.php index 317db1239..c1779e208 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -20,9 +20,20 @@ function wiki_list($nick, $observer_hash) { return array('wikis' => $wikis); } -function wiki_pages() { - // TODO: scan wiki folder for pages - return array('pages' => array('page1.md', 'page2.md')); +function wiki_page_list($resource_id) { + // TODO: Create item table records for pages so that metadata like title can be applied + $w = wiki_get_wiki($resource_id); + if (!$w['path']) { + return array('pages' => null); + } + $pages = array(); + if (is_dir($w['path']) === true) { + $files = array_diff(scandir($w['path']), array('.', '..', '.git')); + // TODO: Check that the files are all text files + $pages = $files; + } + + return array('pages' => $pages); } function wiki_init_wiki($channel, $name) { @@ -125,6 +136,25 @@ function wiki_delete_wiki($resource_id) { } } +function wiki_get_wiki($resource_id) { + $item = q("SELECT * FROM item WHERE resource_type = '%s' AND resource_id = '%s' AND item_deleted = 0 limit 1", + dbesc(WIKI_ITEM_RESOURCE_TYPE), + dbesc($resource_id) + ); + if (!$item) { + return array('wiki' => null, 'path' => null); + } else { + $w = $item[0]; + $object = json_decode($w['object'], true); + if (!realpath(__DIR__ . '/../' . $object['path'])) { + return array('wiki' => null, 'path' => null); + } + // Path to wiki exists + $abs_path = realpath(__DIR__ . '/../' . $object['path']); + return array('wiki' => $w, 'path' => $abs_path); + } +} + function wiki_exists_by_name($uid, $name) { $item = q("SELECT id,resource_id FROM item WHERE resource_type = '%s' AND title = '%s' AND uid = '%s' AND item_deleted = 0 limit 1", dbesc(WIKI_ITEM_RESOURCE_TYPE), @@ -147,7 +177,7 @@ function wiki_get_permissions($resource_id, $owner_id, $observer_hash) { dbesc($resource_id) ); if(!$r) { - return array('read' => false, 'write' => false, 'success' => false); + return array('read' => false, 'write' => false, 'success' => true); } else { return array('read' => true, 'write' => false, 'success' => true); } |