From a36bef7979aecd72751d319f85b7037991979e35 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sat, 21 May 2016 21:55:09 -0400 Subject: List of wikis populates with links according to observer permissions. --- Zotlabs/Module/Wiki.php | 15 +++++++++++++++ include/widgets.php | 14 ++++++++++---- include/wiki.php | 12 ++++++++++-- view/tpl/wiki.tpl | 4 ++-- view/tpl/wikilist.tpl | 7 ++----- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php index c4546e5ef..53a3eb26b 100644 --- a/Zotlabs/Module/Wiki.php +++ b/Zotlabs/Module/Wiki.php @@ -48,7 +48,22 @@ class Wiki extends \Zotlabs\Web\Controller { 'acl' => populate_acl($channel_acl), 'bang' => '' ); +// $wikiheader = t('Wiki Sandbox'); +// $hide_editor = false; + if(argc()<3) { + $wikiheader = t('Wiki Sandbox'); + $hide_editor = false; + } elseif (argc()<4) { + $wikiheader = 'Empty wiki: ' . rawurldecode(argv(2)); // show wiki name + $hide_editor = true; + } elseif (argc()<5) { + $wikiheader = rawurldecode(argv(2)) . ': ' . rawurldecode(argv(3)); // show wiki name and page + $hide_editor = false; + } + $o .= replace_macros(get_markup_template('wiki.tpl'),array( + '$wikiheader' => $wikiheader, + '$hideEditor' => $hide_editor, '$channel' => $channel['channel_address'], '$lockstate' => $x['lockstate'], '$acl' => $x['acl'], diff --git a/include/widgets.php b/include/widgets.php index acbd9bcd3..cff58d225 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -860,13 +860,19 @@ function widget_chatroom_members() { function widget_wiki_list($arr) { require_once("include/wiki.php"); - $r = wiki_list(App::$profile['channel_hash']); + if(argc()>1) { + $nick = argv(1); + } else { + $channel = \App::get_channel(); + $nick = $channel['channel_address']; + } + $wikis = wiki_list($nick, get_observer_hash()); - if($r) { + if($wikis) { return replace_macros(get_markup_template('wikilist.tpl'), array( '$header' => t('Wiki List'), - '$read' => $r['read'], - '$write' => $r['write'] + '$channel' => $nick, + '$wikis' => $wikis['wikis'] )); } } diff --git a/include/wiki.php b/include/wiki.php index 32caa98e8..7cd838f95 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -15,9 +15,17 @@ function wiki_delete() { } -function wiki_list($observer_hash) { +function wiki_list($nick, $observer_hash) { + if (local_channel() || remote_channel()) { + $sql_extra = item_permissions_sql(get_channel_by_nick($nick)['channel_id'], $observer_hash); + } else { + $sql_extra = " AND item_private = 0 "; + } + $wikis = q("SELECT * FROM item WHERE resource_type = '%s' AND mid = parent_mid AND item_deleted = 0 $sql_extra", + dbesc(WIKI_ITEM_RESOURCE_TYPE) + ); // TODO: query db for wikis the observer can access. Return with two lists, for read and write access - return array('write' => array('wiki1'), 'read' => array('wiki1', 'wiki2')); + return array('wikis' => $wikis); } function wiki_pages() { diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl index f96270856..641b3256a 100644 --- a/view/tpl/wiki.tpl +++ b/view/tpl/wiki.tpl @@ -15,7 +15,7 @@ -

Wiki

+

{{$wikiheader}}

-
+