From 5e99295bf6f85e7a6d50e0c8f0701a9b37f03332 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 12 Sep 2017 22:32:31 -0700 Subject: wiki mimetype selection --- Zotlabs/Lib/NativeWikiPage.php | 8 +++++++- Zotlabs/Module/Wiki.php | 10 ++++++---- Zotlabs/Widget/Wiki_pages.php | 1 + include/text.php | 6 +++--- view/tpl/wiki_page_list.tpl | 3 ++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Zotlabs/Lib/NativeWikiPage.php b/Zotlabs/Lib/NativeWikiPage.php index 78b54ebda..97dad5813 100644 --- a/Zotlabs/Lib/NativeWikiPage.php +++ b/Zotlabs/Lib/NativeWikiPage.php @@ -55,7 +55,12 @@ class NativeWikiPage { } - static public function create_page($channel_id, $observer_hash, $name, $resource_id) { + static public function create_page($channel_id, $observer_hash, $name, $resource_id, $mimetype = 'text/bbcode') { + + logger('mimetype: ' . $mimetype); + + if(! in_array($mimetype,[ 'text/markdown','text/bbcode','text/plain','text/html'])) + $mimetype = 'text/markdown; $w = Zlib\NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); @@ -68,6 +73,7 @@ class NativeWikiPage { $arr = []; $arr['uid'] = $channel_id; $arr['author_xchan'] = $observer_hash; + $arr['mimetype'] = $mimetype; $arr['resource_type'] = 'nwikipage'; $arr['resource_id'] = $resource_id; $arr['allow_cid'] = $w['wiki']['allow_cid']; diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php index 4dc11c683..3fb980955 100644 --- a/Zotlabs/Module/Wiki.php +++ b/Zotlabs/Module/Wiki.php @@ -406,7 +406,7 @@ class Wiki extends \Zotlabs\Web\Controller { $r = Zlib\NativeWiki::create_wiki($owner, $observer_hash, $wiki, $acl); if($r['success']) { Zlib\NativeWiki::sync_a_wiki_item($owner['channel_id'],$r['item_id'],$r['item']['resource_id']); - $homePage = Zlib\NativeWikiPage::create_page($owner['channel_id'],$observer_hash,'Home', $r['item']['resource_id']); + $homePage = Zlib\NativeWikiPage::create_page($owner['channel_id'],$observer_hash,'Home', $r['item']['resource_id'], $wiki['mimeType']); if(! $homePage['success']) { notice( t('Wiki created, but error creating Home page.')); goaway(z_root() . '/wiki/' . $nick . '/' . $wiki['urlName']); @@ -445,11 +445,13 @@ class Wiki extends \Zotlabs\Web\Controller { // Create a page if ((argc() === 4) && (argv(2) === 'create') && (argv(3) === 'page')) { + $mimetype = $_POST['mimetype']; + $resource_id = $_POST['resource_id']; // Determine if observer has permission to create a page + - - $perms = Zlib\NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash); + $perms = Zlib\NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash, $mimetype); if(! $perms['write']) { logger('Wiki write permission denied. ' . EOL); json_return_and_die(array('success' => false)); @@ -459,7 +461,7 @@ class Wiki extends \Zotlabs\Web\Controller { if(urlencode(escape_tags($_POST['pageName'])) === '') { json_return_and_die(array('message' => 'Error creating page. Invalid name.', 'success' => false)); } - $page = Zlib\NativeWikiPage::create_page($owner['channel_id'],$observer_hash, $name, $resource_id); + $page = Zlib\NativeWikiPage::create_page($owner['channel_id'],$observer_hash, $name, $resource_id, $mimetype); if($page['item_id']) { $commit = Zlib\NativeWikiPage::commit(array( diff --git a/Zotlabs/Widget/Wiki_pages.php b/Zotlabs/Widget/Wiki_pages.php index 7285e2b42..ac6549ffd 100644 --- a/Zotlabs/Widget/Wiki_pages.php +++ b/Zotlabs/Widget/Wiki_pages.php @@ -50,6 +50,7 @@ class Wiki_pages { '$canadd' => $can_create, '$candel' => $can_delete, '$addnew' => t('Add new page'), + '$mimetype' => mimetype_select(0,$p['mimeType'], [ 'text/markdown','text/bbcode' ]), '$pageName' => array('pageName', t('Page name')), '$refresh' => $arr['refresh'] )); diff --git a/include/text.php b/include/text.php index 51d711021..58e2b8256 100644 --- a/include/text.php +++ b/include/text.php @@ -1786,15 +1786,15 @@ function layout_select($channel_id, $current = '') { } -function mimetype_select($channel_id, $current = 'text/bbcode') { +function mimetype_select($channel_id, $current = 'text/bbcode', $choices = null) { - $x = array( + $x = (($choices) ? $choices : [ 'text/bbcode', 'text/html', 'text/markdown', 'text/plain', 'application/x-pdl' - ); + ]); if((App::$is_sys) || (channel_codeallowed($channel_id) && $channel_id == local_channel())){ diff --git a/view/tpl/wiki_page_list.tpl b/view/tpl/wiki_page_list.tpl index 6d09fcd5d..2e7fb8b9e 100644 --- a/view/tpl/wiki_page_list.tpl +++ b/view/tpl/wiki_page_list.tpl @@ -21,6 +21,7 @@