Wiki page list is fetched and the page widget is updated
This commit is contained in:
parent
4691c3ec01
commit
f884fa6678
@ -92,8 +92,6 @@ class Wiki extends \Zotlabs\Web\Controller {
|
||||
function post() {
|
||||
require_once('include/wiki.php');
|
||||
|
||||
// TODO: Implement wiki API
|
||||
|
||||
// Render mardown-formatted text in HTML
|
||||
if((argc() > 2) && (argv(2) === 'preview')) {
|
||||
$content = $_POST['content'];
|
||||
@ -212,8 +210,22 @@ class Wiki extends \Zotlabs\Web\Controller {
|
||||
}
|
||||
}
|
||||
|
||||
notice('You must be authenticated.');
|
||||
goaway('/wiki');
|
||||
// Fetch page list for a wiki
|
||||
if ((argc() === 5) && (argv(2) === 'get') && (argv(3) === 'page') && (argv(4) === 'list')) {
|
||||
$resource_id = $_POST['resource_id']; // resource_id for wiki in db
|
||||
$channel = get_channel_by_nick(argv(1));
|
||||
$observer_hash = get_observer_hash();
|
||||
$perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
|
||||
if(!$perms['read']) {
|
||||
logger('Wiki read permission denied.' . EOL);
|
||||
json_return_and_die(array('pages' => null, 'message' => 'Permission denied.', 'success' => false));
|
||||
}
|
||||
$page_list_html = widget_wiki_pages(array('resource_id' => $resource_id));
|
||||
json_return_and_die(array('pages' => $page_list_html, 'message' => '', 'success' => true));
|
||||
}
|
||||
|
||||
//notice('You must be authenticated.');
|
||||
json_return_and_die(array('message' => 'You must be authenticated.', 'success' => false));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -877,14 +877,21 @@ function widget_wiki_list($arr) {
|
||||
function widget_wiki_pages($arr) {
|
||||
|
||||
require_once("include/wiki.php");
|
||||
$r = wiki_pages(App::$profile['channel_hash']);
|
||||
|
||||
if($r) {
|
||||
return replace_macros(get_markup_template('wiki_page_list.tpl'), array(
|
||||
'$header' => t('Wiki Pages'),
|
||||
'$pages' => $r['pages']
|
||||
));
|
||||
$pages = array();
|
||||
if (!array_key_exists('resource_id', $arr)) {
|
||||
$hide = true;
|
||||
} else {
|
||||
$p = wiki_page_list($arr['resource_id']);
|
||||
if ($p['pages']) {
|
||||
$pages = $p['pages'];
|
||||
}
|
||||
}
|
||||
return replace_macros(get_markup_template('wiki_page_list.tpl'), array(
|
||||
'$hide' => $hide,
|
||||
'$header' => t('Wiki Pages'),
|
||||
'$pages' => $pages
|
||||
));
|
||||
}
|
||||
|
||||
function widget_bookmarkedchats($arr) {
|
||||
|
@ -20,9 +20,20 @@ function wiki_list($nick, $observer_hash) {
|
||||
return array('wikis' => $wikis);
|
||||
}
|
||||
|
||||
function wiki_pages() {
|
||||
// TODO: scan wiki folder for pages
|
||||
return array('pages' => array('page1.md', 'page2.md'));
|
||||
function wiki_page_list($resource_id) {
|
||||
// TODO: Create item table records for pages so that metadata like title can be applied
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
return array('pages' => null);
|
||||
}
|
||||
$pages = array();
|
||||
if (is_dir($w['path']) === true) {
|
||||
$files = array_diff(scandir($w['path']), array('.', '..', '.git'));
|
||||
// TODO: Check that the files are all text files
|
||||
$pages = $files;
|
||||
}
|
||||
|
||||
return array('pages' => $pages);
|
||||
}
|
||||
|
||||
function wiki_init_wiki($channel, $name) {
|
||||
@ -125,6 +136,25 @@ function wiki_delete_wiki($resource_id) {
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_get_wiki($resource_id) {
|
||||
$item = q("SELECT * FROM item WHERE resource_type = '%s' AND resource_id = '%s' AND item_deleted = 0 limit 1",
|
||||
dbesc(WIKI_ITEM_RESOURCE_TYPE),
|
||||
dbesc($resource_id)
|
||||
);
|
||||
if (!$item) {
|
||||
return array('wiki' => null, 'path' => null);
|
||||
} else {
|
||||
$w = $item[0];
|
||||
$object = json_decode($w['object'], true);
|
||||
if (!realpath(__DIR__ . '/../' . $object['path'])) {
|
||||
return array('wiki' => null, 'path' => null);
|
||||
}
|
||||
// Path to wiki exists
|
||||
$abs_path = realpath(__DIR__ . '/../' . $object['path']);
|
||||
return array('wiki' => $w, 'path' => $abs_path);
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_exists_by_name($uid, $name) {
|
||||
$item = q("SELECT id,resource_id FROM item WHERE resource_type = '%s' AND title = '%s' AND uid = '%s' AND item_deleted = 0 limit 1",
|
||||
dbesc(WIKI_ITEM_RESOURCE_TYPE),
|
||||
@ -147,7 +177,7 @@ function wiki_get_permissions($resource_id, $owner_id, $observer_hash) {
|
||||
dbesc($resource_id)
|
||||
);
|
||||
if(!$r) {
|
||||
return array('read' => false, 'write' => false, 'success' => false);
|
||||
return array('read' => false, 'write' => false, 'success' => true);
|
||||
} else {
|
||||
return array('read' => true, 'write' => false, 'success' => true);
|
||||
}
|
||||
|
@ -78,6 +78,7 @@
|
||||
<script>
|
||||
window.wiki_resource_id = '{{$resource_id}}';
|
||||
$(document).ready(function () {
|
||||
wiki_refresh_page_list();
|
||||
// Show Edit tab first. Otherwise the Ace editor does not load.
|
||||
$("#wiki-nav-tabs li:eq(0) a").tab('show');
|
||||
});
|
||||
@ -131,4 +132,20 @@ function wiki_delete_wiki(wikiName, resource_id) {
|
||||
}, 'json');
|
||||
ev.preventDefault();
|
||||
});
|
||||
|
||||
function wiki_refresh_page_list() {
|
||||
if (window.wiki_resource_id === '') {
|
||||
return false;
|
||||
}
|
||||
$.post("wiki/{{$channel}}/get/page/list/", {resource_id: window.wiki_resource_id}, function (data) {
|
||||
if (data.success) {
|
||||
$('#wiki_page_list').html(data.pages);
|
||||
$('#wiki_page_list').show();
|
||||
} else {
|
||||
alert('Error fetching page list!');
|
||||
window.console.log('Error fetching page list!');
|
||||
}
|
||||
}, 'json');
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div id="wiki_page_list" class="widget">
|
||||
<div id="wiki_page_list" class="widget" {{if $hide}} style="display: none;" {{/if}}>
|
||||
<h3>{{$header}}</h3>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
{{foreach $pages as $page}}
|
||||
|
Reference in New Issue
Block a user