Page content is loaded from the file on disk

This commit is contained in:
Andrew Manning 2016-05-28 12:33:07 -04:00
parent ae94e8a855
commit 7393dccde8
3 changed files with 35 additions and 4 deletions

View File

@ -63,12 +63,20 @@ class Wiki extends \Zotlabs\Web\Controller {
} }
if(argc()<3) { if(argc()<3) {
$wikiheader = t('Wiki Sandbox'); $wikiheader = t('Wiki Sandbox');
$content = '# Wiki Sandbox\nContent you **edit** and **preview** here *will not be saved*.';
$hide_editor = false; $hide_editor = false;
} elseif (argc()<4) { } elseif (argc()<4) {
$wikiheader = 'Empty wiki: ' . rawurldecode(argv(2)); // show wiki name $wikiheader = rawurldecode(argv(2)); // show wiki name
$content = '';
$hide_editor = true; $hide_editor = true;
} elseif (argc()<5) { } elseif (argc()<5) {
$wikiheader = rawurldecode(argv(2)) . ': ' . rawurldecode(argv(3)); // show wiki name and page $wikiheader = rawurldecode(argv(2)) . ': ' . rawurldecode(argv(3)); // show wiki name and page
$p = wiki_get_page_content(array('wiki_resource_id' => $resource_id, 'page' => argv(3)));
if(!$p['success']) {
logger('Error getting page content');
$content = 'Error retrieving page content. Try again.';
}
$content = $p['content'];
$hide_editor = false; $hide_editor = false;
} }
@ -80,7 +88,7 @@ class Wiki extends \Zotlabs\Web\Controller {
'$lockstate' => $x['lockstate'], '$lockstate' => $x['lockstate'],
'$acl' => $x['acl'], '$acl' => $x['acl'],
'$bang' => $x['bang'], '$bang' => $x['bang'],
'$content' => '# Start your wiki', '$content' => $content,
'$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''), '$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''),
'$pageName' => array('pageName', t('Enter the name of the new page:'), '', '') '$pageName' => array('pageName', t('Enter the name of the new page:'), '', '')
)); ));

View File

@ -210,3 +210,26 @@ function wiki_create_page($name, $resource_id) {
} }
} }
function wiki_get_page_content($arr) {
$page = ((array_key_exists('page',$arr)) ? $arr['page'] : '');
// TODO: look for page resource_id and retrieve that way alternatively
$wiki_resource_id = ((array_key_exists('wiki_resource_id',$arr)) ? $arr['wiki_resource_id'] : '');
$w = wiki_get_wiki($wiki_resource_id);
if (!$w['path']) {
return array('content' => null, 'message' => 'Error reading wiki', 'success' => false);
}
$page_path = $w['path'].'/'.$page;
if (is_readable($page_path) === true) {
if(filesize($page_path) === 0) {
$content = '';
} else {
$content = file_get_contents($page_path);
if(!$content) {
return array('content' => null, 'message' => 'Error reading page content', 'success' => false);
}
}
// TODO: Check that the files are all text files
return array('content' => json_encode($content), 'message' => '', 'success' => true);
}
}

View File

@ -86,7 +86,7 @@
var editor = ace.edit("ace-editor"); var editor = ace.edit("ace-editor");
editor.setTheme("ace/theme/github"); editor.setTheme("ace/theme/github");
editor.getSession().setMode("ace/mode/markdown"); editor.getSession().setMode("ace/mode/markdown");
editor.getSession().setValue('{{$content}}'); editor.getSession().setValue({{$content}});
$('#wiki-get-preview').click(function (ev) { $('#wiki-get-preview').click(function (ev) {
$.post("wiki/{{$channel}}/preview", {content: editor.getValue()}, function (data) { $.post("wiki/{{$channel}}/preview", {content: editor.getValue()}, function (data) {