go live with wiki mimetypes - you can now choose if a wiki will contain markdown or bb-code markup
This commit is contained in:
parent
53e4b55ea3
commit
afffbb6487
@ -202,11 +202,20 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
notice(t('Error retrieving page content') . EOL);
|
notice(t('Error retrieving page content') . EOL);
|
||||||
goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName);
|
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
|
// Render the Markdown-formatted page content in HTML
|
||||||
|
if($mimeType == 'text/bbcode') {
|
||||||
|
$renderedContent = purify_html(bbcode($content));
|
||||||
|
}
|
||||||
|
else {
|
||||||
require_once('library/markdown.php');
|
require_once('library/markdown.php');
|
||||||
$html = wiki_generate_toc(zidify_text(purify_html(Markdown(wiki_bbcode(json_decode($content))))));
|
$html = wiki_generate_toc(zidify_text(purify_html(Markdown(wiki_bbcode(json_decode($content))))));
|
||||||
$renderedContent = wiki_convert_links($html,argv(0).'/'.argv(1).'/'.$wikiUrlName);
|
$renderedContent = wiki_convert_links($html,argv(0).'/'.argv(1).'/'.$wikiUrlName);
|
||||||
|
}
|
||||||
$hide_editor = false;
|
$hide_editor = false;
|
||||||
$showPageControls = $wiki_editor;
|
$showPageControls = $wiki_editor;
|
||||||
$showNewWikiButton = $wiki_owner;
|
$showNewWikiButton = $wiki_owner;
|
||||||
@ -220,14 +229,13 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$wikiModalID = random_string(3);
|
$wikiModalID = random_string(3);
|
||||||
$wikiModal = replace_macros(
|
|
||||||
get_markup_template('generic_modal.tpl'), array(
|
$wikiModal = replace_macros(get_markup_template('generic_modal.tpl'), array(
|
||||||
'$id' => $wikiModalID,
|
'$id' => $wikiModalID,
|
||||||
'$title' => t('Revision Comparison'),
|
'$title' => t('Revision Comparison'),
|
||||||
'$ok' => t('Revert'),
|
'$ok' => t('Revert'),
|
||||||
'$cancel' => t('Cancel')
|
'$cancel' => t('Cancel')
|
||||||
)
|
));
|
||||||
);
|
|
||||||
|
|
||||||
$o .= replace_macros(get_markup_template('wiki.tpl'),array(
|
$o .= replace_macros(get_markup_template('wiki.tpl'),array(
|
||||||
'$wikiheaderName' => $wikiheaderName,
|
'$wikiheaderName' => $wikiheaderName,
|
||||||
@ -251,6 +259,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
'$deny_cid' => $x['deny_cid'],
|
'$deny_cid' => $x['deny_cid'],
|
||||||
'$deny_gid' => $x['deny_gid'],
|
'$deny_gid' => $x['deny_gid'],
|
||||||
'$bang' => $x['bang'],
|
'$bang' => $x['bang'],
|
||||||
|
'$mimeType' => $mimeType,
|
||||||
'$content' => $content,
|
'$content' => $content,
|
||||||
'$renderedContent' => $renderedContent,
|
'$renderedContent' => $renderedContent,
|
||||||
'$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''),
|
'$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''),
|
||||||
@ -294,12 +303,20 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
if((argc() > 2) && (argv(2) === 'preview')) {
|
if((argc() > 2) && (argv(2) === 'preview')) {
|
||||||
$content = $_POST['content'];
|
$content = $_POST['content'];
|
||||||
$resource_id = $_POST['resource_id'];
|
$resource_id = $_POST['resource_id'];
|
||||||
|
$w = wiki_get_wiki($resource_id);
|
||||||
|
$wikiURL = argv(0).'/'.argv(1).'/'.$w['urlName'];
|
||||||
|
|
||||||
|
$mimeType = $w['mimeType'];
|
||||||
|
|
||||||
|
if($mimeType == 'text/bbcode') {
|
||||||
|
$html = purify_html(bbcode($content));
|
||||||
|
}
|
||||||
|
else {
|
||||||
require_once('library/markdown.php');
|
require_once('library/markdown.php');
|
||||||
$content = wiki_bbcode($content);
|
$content = wiki_bbcode($content);
|
||||||
$html = wiki_generate_toc(zidify_text(purify_html(Markdown($content))));
|
$html = wiki_generate_toc(zidify_text(purify_html(Markdown($content))));
|
||||||
$w = wiki_get_wiki($resource_id);
|
|
||||||
$wikiURL = argv(0).'/'.argv(1).'/'.$w['urlName'];
|
|
||||||
$html = wiki_convert_links($html,$wikiURL);
|
$html = wiki_convert_links($html,$wikiURL);
|
||||||
|
}
|
||||||
json_return_and_die(array('html' => $html, 'success' => true));
|
json_return_and_die(array('html' => $html, 'success' => true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ function wiki_get_page_content($arr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Check that the files are all text files
|
// 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
|
* @return string
|
||||||
*/
|
*/
|
||||||
function wiki_generate_toc($s) {
|
function wiki_generate_toc($s) {
|
||||||
|
|
||||||
if (strpos($s,'[toc]') !== false) {
|
if (strpos($s,'[toc]') !== false) {
|
||||||
//$toc_md = wiki_toc($s); // Generate Markdown-formatted list prior to HTML render
|
//$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/
|
$toc_md = '<ul id="wiki-toc"></ul>'; // use the available jQuery plugin http://ndabas.github.io/toc/
|
||||||
|
@ -4,6 +4,11 @@
|
|||||||
height: 500px;
|
height: 500px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#editor {
|
||||||
|
width: 100%;
|
||||||
|
height: 500px;
|
||||||
|
}
|
||||||
|
|
||||||
.fade.in {
|
.fade.in {
|
||||||
-webkit-transition: opacity 0.5s 0.5s ease;
|
-webkit-transition: opacity 0.5s 0.5s ease;
|
||||||
-moz-transition: opacity 0.5s 0.5s ease;
|
-moz-transition: opacity 0.5s 0.5s ease;
|
||||||
|
@ -42,7 +42,11 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content" id="wiki-page-tabs">
|
<div class="tab-content" id="wiki-page-tabs">
|
||||||
<div id="edit-pane" class="tab-pane fade">
|
<div id="edit-pane" class="tab-pane fade">
|
||||||
|
{{if !$mimeType || $mimeType == 'text/markdown'}}
|
||||||
<div id="ace-editor"></div>
|
<div id="ace-editor"></div>
|
||||||
|
{{else}}
|
||||||
|
<textarea id="editor">{{$content}}</textarea>
|
||||||
|
{{/if}}
|
||||||
{{if $showCommitMsg}}
|
{{if $showCommitMsg}}
|
||||||
{{if $showPageControls}}
|
{{if $showPageControls}}
|
||||||
<div>
|
<div>
|
||||||
@ -50,7 +54,7 @@
|
|||||||
<div class="input-group">
|
<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}}>
|
<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">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -98,7 +102,7 @@
|
|||||||
<script>
|
<script>
|
||||||
window.wiki_resource_id = '{{$resource_id}}';
|
window.wiki_resource_id = '{{$resource_id}}';
|
||||||
window.wiki_page_name = '{{$page}}';
|
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}}';
|
window.wiki_page_commit = '{{$commit}}';
|
||||||
|
|
||||||
if (window.wiki_page_name === 'Home') {
|
if (window.wiki_page_name === 'Home') {
|
||||||
@ -135,6 +139,7 @@
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
{{if !$mimeType || $mimeType == 'text/markdown'}}
|
||||||
var editor = ace.edit("ace-editor");
|
var editor = ace.edit("ace-editor");
|
||||||
editor.setOptions({
|
editor.setOptions({
|
||||||
theme: "ace/theme/github",
|
theme: "ace/theme/github",
|
||||||
@ -153,12 +158,26 @@
|
|||||||
{{if !$showPageControls}}
|
{{if !$showPageControls}}
|
||||||
editor.setReadOnly(true); // Disable editing if the viewer lacks edit permission
|
editor.setReadOnly(true); // Disable editing if the viewer lacks edit permission
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
|
||||||
|
{{else}}
|
||||||
|
window.editor = editor = $('#editor');
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
$('#edit-pane-tab').click(function (ev) {
|
$('#edit-pane-tab').click(function (ev) {
|
||||||
setTimeout(function() {window.editor.focus();}, 500); // Return the focus to the editor allowing immediate text entry
|
setTimeout(function() {window.editor.focus();}, 500); // Return the focus to the editor allowing immediate text entry
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#wiki-get-preview').click(function (ev) {
|
$('#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) {
|
if (data.success) {
|
||||||
$('#wiki-preview').html(data.html);
|
$('#wiki-preview').html(data.html);
|
||||||
$("#wiki-toc").toc({content: "#wiki-preview", headings: "h1,h2,h3,h4"});
|
$("#wiki-toc").toc({content: "#wiki-preview", headings: "h1,h2,h3,h4"});
|
||||||
@ -207,7 +226,12 @@
|
|||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
{{if !$mimeType || $mimeType == 'text/markdown'}}
|
||||||
var currentContent = editor.getValue();
|
var currentContent = editor.getValue();
|
||||||
|
{{else}}
|
||||||
|
var currentContent = editor.val();
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
if (window.wiki_page_content === currentContent) {
|
if (window.wiki_page_content === currentContent) {
|
||||||
window.console.log('No edits to save.');
|
window.console.log('No edits to save.');
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
@ -224,8 +248,12 @@
|
|||||||
window.console.log('Page saved successfully.');
|
window.console.log('Page saved successfully.');
|
||||||
window.wiki_page_content = currentContent;
|
window.wiki_page_content = currentContent;
|
||||||
$('#id_commitMsg').val(''); // Clear the commit message box
|
$('#id_commitMsg').val(''); // Clear the commit message box
|
||||||
|
|
||||||
|
{{if !$mimeType || $mimeType == 'text/markdown'}}
|
||||||
$('#save-page').addClass('disabled'); // Disable the save button
|
$('#save-page').addClass('disabled'); // Disable the save button
|
||||||
window.editor.getSession().getUndoManager().markClean(); // Reset the undo history for the editor
|
window.editor.getSession().getUndoManager().markClean(); // Reset the undo history for the editor
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
window.editor.focus(); // Return focus to the editor for continued editing
|
window.editor.focus(); // Return focus to the editor for continued editing
|
||||||
// $('#wiki-get-history').click();
|
// $('#wiki-get-history').click();
|
||||||
} else {
|
} else {
|
||||||
@ -400,6 +428,7 @@
|
|||||||
$('#new-wiki-button').hide();
|
$('#new-wiki-button').hide();
|
||||||
{{/if}}
|
{{/if}}
|
||||||
// using input event instead of change since it's called with some timeout
|
// using input event instead of change since it's called with some timeout
|
||||||
|
{{if !$mimeType || $mimeType == 'text/markdown'}}
|
||||||
window.editor.on("input", function() {
|
window.editor.on("input", function() {
|
||||||
if(window.editor.getSession().getUndoManager().isClean()) {
|
if(window.editor.getSession().getUndoManager().isClean()) {
|
||||||
$('#save-page').addClass('disabled');
|
$('#save-page').addClass('disabled');
|
||||||
@ -407,6 +436,10 @@
|
|||||||
$('#save-page').removeClass('disabled');
|
$('#save-page').removeClass('disabled');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
{{else}}
|
||||||
|
window.editor.bbco_autocomplete('bbcode');
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -9,8 +9,7 @@
|
|||||||
<div id="new-wiki-form-wrapper" class="section-content-tools-wrapper">
|
<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}}'>
|
<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_input.tpl" field=$wikiName}}
|
||||||
{{* include file="field_select.tpl" field=$mimeType *}}
|
{{include file="field_select.tpl" field=$mimeType}}
|
||||||
<input type="hidden" name="mimeType" value="text/markdown">
|
|
||||||
{{include file="field_checkbox.tpl" field=$notify}}
|
{{include file="field_checkbox.tpl" field=$notify}}
|
||||||
<div>
|
<div>
|
||||||
<div class="btn-group pull-right">
|
<div class="btn-group pull-right">
|
||||||
|
Reference in New Issue
Block a user