diff options
author | Mario Vavti <mario@mariovavti.com> | 2016-11-30 13:30:50 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2016-11-30 13:30:50 +0100 |
commit | afffbb6487d8dc1806767ed2b2728ab56bf06669 (patch) | |
tree | 4f24bdcf1d1522c804db4fd0820acca4ffae94a7 | |
parent | 53e4b55ea3722a161b308e4891a2e84ad9ba77af (diff) | |
download | volse-hubzilla-afffbb6487d8dc1806767ed2b2728ab56bf06669.tar.gz volse-hubzilla-afffbb6487d8dc1806767ed2b2728ab56bf06669.tar.bz2 volse-hubzilla-afffbb6487d8dc1806767ed2b2728ab56bf06669.zip |
go live with wiki mimetypes - you can now choose if a wiki will contain markdown or bb-code markup
-rw-r--r-- | Zotlabs/Module/Wiki.php | 51 | ||||
-rw-r--r-- | include/wiki.php | 3 | ||||
-rw-r--r-- | view/css/mod_wiki.css | 7 | ||||
-rw-r--r-- | view/tpl/wiki.tpl | 41 | ||||
-rw-r--r-- | view/tpl/wikilist.tpl | 3 |
5 files changed, 79 insertions, 26 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php index edd783a62..c4cc72ae8 100644 --- a/Zotlabs/Module/Wiki.php +++ b/Zotlabs/Module/Wiki.php @@ -202,11 +202,20 @@ class Wiki extends \Zotlabs\Web\Controller { notice(t('Error retrieving page content') . EOL); goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName); } - $content = ($p['content'] !== '' ? htmlspecialchars_decode($p['content'],ENT_COMPAT) : '"# New page\n"'); + + $mimeType = $p['mimeType']; + + $rawContent = $p['mimeType'] == 'text/bbcode' ? htmlspecialchars_decode(json_decode($p['content']),ENT_COMPAT) : htmlspecialchars_decode($p['content'],ENT_COMPAT); + $content = ($p['content'] !== '' ? $rawContent : '"# New page\n"'); // Render the Markdown-formatted page content in HTML - require_once('library/markdown.php'); - $html = wiki_generate_toc(zidify_text(purify_html(Markdown(wiki_bbcode(json_decode($content)))))); - $renderedContent = wiki_convert_links($html,argv(0).'/'.argv(1).'/'.$wikiUrlName); + if($mimeType == 'text/bbcode') { + $renderedContent = purify_html(bbcode($content)); + } + else { + require_once('library/markdown.php'); + $html = wiki_generate_toc(zidify_text(purify_html(Markdown(wiki_bbcode(json_decode($content)))))); + $renderedContent = wiki_convert_links($html,argv(0).'/'.argv(1).'/'.$wikiUrlName); + } $hide_editor = false; $showPageControls = $wiki_editor; $showNewWikiButton = $wiki_owner; @@ -220,14 +229,13 @@ class Wiki extends \Zotlabs\Web\Controller { } $wikiModalID = random_string(3); - $wikiModal = replace_macros( - get_markup_template('generic_modal.tpl'), array( - '$id' => $wikiModalID, - '$title' => t('Revision Comparison'), - '$ok' => t('Revert'), - '$cancel' => t('Cancel') - ) - ); + + $wikiModal = replace_macros(get_markup_template('generic_modal.tpl'), array( + '$id' => $wikiModalID, + '$title' => t('Revision Comparison'), + '$ok' => t('Revert'), + '$cancel' => t('Cancel') + )); $o .= replace_macros(get_markup_template('wiki.tpl'),array( '$wikiheaderName' => $wikiheaderName, @@ -251,6 +259,7 @@ class Wiki extends \Zotlabs\Web\Controller { '$deny_cid' => $x['deny_cid'], '$deny_gid' => $x['deny_gid'], '$bang' => $x['bang'], + '$mimeType' => $mimeType, '$content' => $content, '$renderedContent' => $renderedContent, '$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''), @@ -293,13 +302,21 @@ class Wiki extends \Zotlabs\Web\Controller { // Render mardown-formatted text in HTML for preview if((argc() > 2) && (argv(2) === 'preview')) { $content = $_POST['content']; - $resource_id = $_POST['resource_id']; - require_once('library/markdown.php'); - $content = wiki_bbcode($content); - $html = wiki_generate_toc(zidify_text(purify_html(Markdown($content)))); + $resource_id = $_POST['resource_id']; $w = wiki_get_wiki($resource_id); $wikiURL = argv(0).'/'.argv(1).'/'.$w['urlName']; - $html = wiki_convert_links($html,$wikiURL); + + $mimeType = $w['mimeType']; + + if($mimeType == 'text/bbcode') { + $html = purify_html(bbcode($content)); + } + else { + require_once('library/markdown.php'); + $content = wiki_bbcode($content); + $html = wiki_generate_toc(zidify_text(purify_html(Markdown($content)))); + $html = wiki_convert_links($html,$wikiURL); + } json_return_and_die(array('html' => $html, 'success' => true)); } diff --git a/include/wiki.php b/include/wiki.php index ac35c8546..dd5dbbe11 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -303,7 +303,7 @@ function wiki_get_page_content($arr) { } } // TODO: Check that the files are all text files - return array('content' => json_encode($content), 'message' => '', 'success' => true); + return array('content' => json_encode($content), 'mimeType' => $w['mimeType'], 'message' => '', 'success' => true); } } @@ -523,7 +523,6 @@ function wiki_convert_links($s, $wikiURL) { * @return string */ function wiki_generate_toc($s) { - if (strpos($s,'[toc]') !== false) { //$toc_md = wiki_toc($s); // Generate Markdown-formatted list prior to HTML render $toc_md = '<ul id="wiki-toc"></ul>'; // use the available jQuery plugin http://ndabas.github.io/toc/ diff --git a/view/css/mod_wiki.css b/view/css/mod_wiki.css index 1abb0b3b4..b29957090 100644 --- a/view/css/mod_wiki.css +++ b/view/css/mod_wiki.css @@ -1,9 +1,14 @@ -#ace-editor { +#ace-editor { position: relative; width: 100%; height: 500px; } +#editor { + width: 100%; + height: 500px; +} + .fade.in { -webkit-transition: opacity 0.5s 0.5s ease; -moz-transition: opacity 0.5s 0.5s ease; diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl index bdce4f4be..726494883 100644 --- a/view/tpl/wiki.tpl +++ b/view/tpl/wiki.tpl @@ -42,7 +42,11 @@ </ul> <div class="tab-content" id="wiki-page-tabs"> <div id="edit-pane" class="tab-pane fade"> + {{if !$mimeType || $mimeType == 'text/markdown'}} <div id="ace-editor"></div> + {{else}} + <textarea id="editor">{{$content}}</textarea> + {{/if}} {{if $showCommitMsg}} {{if $showPageControls}} <div> @@ -50,7 +54,7 @@ <div class="input-group"> <input class="widget-input" name="{{$commitMsg.0}}" id="id_{{$commitMsg.0}}" type="text" value="{{$commitMsg.2}}"{{if $commitMsg.5}} {{$commitMsg.5}}{{/if}}> <div class="input-group-btn"> - <button id="save-page" type="button" class="btn btn-primary btn-sm disabled">Save</button> + <button id="save-page" type="button" class="btn btn-primary btn-sm{{if !$mimeType || $mimeType == 'text/markdown'}} disabled{{/if}}">Save</button> </div> </div> </div> @@ -98,7 +102,7 @@ <script> window.wiki_resource_id = '{{$resource_id}}'; window.wiki_page_name = '{{$page}}'; - window.wiki_page_content = {{$content}}; + window.wiki_page_content = {{if !$mimeType || $mimeType == 'text/markdown'}}{{$content}}{{else}}`{{$content}}`{{/if}}; window.wiki_page_commit = '{{$commit}}'; if (window.wiki_page_name === 'Home') { @@ -135,6 +139,7 @@ event.preventDefault(); }); + {{if !$mimeType || $mimeType == 'text/markdown'}} var editor = ace.edit("ace-editor"); editor.setOptions({ theme: "ace/theme/github", @@ -153,12 +158,26 @@ {{if !$showPageControls}} editor.setReadOnly(true); // Disable editing if the viewer lacks edit permission {{/if}} + + + {{else}} + window.editor = editor = $('#editor'); + {{/if}} + $('#edit-pane-tab').click(function (ev) { setTimeout(function() {window.editor.focus();}, 500); // Return the focus to the editor allowing immediate text entry }); $('#wiki-get-preview').click(function (ev) { - $.post("wiki/{{$channel}}/preview", {content: editor.getValue(), resource_id: window.wiki_resource_id}, function (data) { + $.post("wiki/{{$channel}}/preview", { + {{if !$mimeType || $mimeType == 'text/markdown'}} + content: editor.getValue(), + {{else}} + content: editor.val(), + {{/if}} + resource_id: window.wiki_resource_id + }, + function (data) { if (data.success) { $('#wiki-preview').html(data.html); $("#wiki-toc").toc({content: "#wiki-preview", headings: "h1,h2,h3,h4"}); @@ -207,7 +226,12 @@ ev.preventDefault(); return false; } - var currentContent = editor.getValue(); + {{if !$mimeType || $mimeType == 'text/markdown'}} + var currentContent = editor.getValue(); + {{else}} + var currentContent = editor.val(); + {{/if}} + if (window.wiki_page_content === currentContent) { window.console.log('No edits to save.'); ev.preventDefault(); @@ -224,8 +248,12 @@ window.console.log('Page saved successfully.'); window.wiki_page_content = currentContent; $('#id_commitMsg').val(''); // Clear the commit message box + + {{if !$mimeType || $mimeType == 'text/markdown'}} $('#save-page').addClass('disabled'); // Disable the save button window.editor.getSession().getUndoManager().markClean(); // Reset the undo history for the editor + {{/if}} + window.editor.focus(); // Return focus to the editor for continued editing // $('#wiki-get-history').click(); } else { @@ -400,6 +428,7 @@ $('#new-wiki-button').hide(); {{/if}} // using input event instead of change since it's called with some timeout + {{if !$mimeType || $mimeType == 'text/markdown'}} window.editor.on("input", function() { if(window.editor.getSession().getUndoManager().isClean()) { $('#save-page').addClass('disabled'); @@ -407,6 +436,10 @@ $('#save-page').removeClass('disabled'); } }); + {{else}} + window.editor.bbco_autocomplete('bbcode'); + {{/if}} + }); </script> diff --git a/view/tpl/wikilist.tpl b/view/tpl/wikilist.tpl index c7cdfaa43..68aa41e7c 100644 --- a/view/tpl/wikilist.tpl +++ b/view/tpl/wikilist.tpl @@ -9,8 +9,7 @@ <div id="new-wiki-form-wrapper" class="section-content-tools-wrapper"> <form id="new-wiki-form" action="wiki/{{$channel}}/create/wiki" method="post" class="acl-form" data-form_id="new-wiki-form" data-allow_cid='{{$allow_cid}}' data-allow_gid='{{$allow_gid}}' data-deny_cid='{{$deny_cid}}' data-deny_gid='{{$deny_gid}}'> {{include file="field_input.tpl" field=$wikiName}} - {{* include file="field_select.tpl" field=$mimeType *}} - <input type="hidden" name="mimeType" value="text/markdown"> + {{include file="field_select.tpl" field=$mimeType}} {{include file="field_checkbox.tpl" field=$notify}} <div> <div class="btn-group pull-right"> |