aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Module/Wiki.php46
-rw-r--r--include/wiki.php26
-rw-r--r--view/tpl/wiki.tpl133
3 files changed, 178 insertions, 27 deletions
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
index bef831de8..de5863d2e 100644
--- a/Zotlabs/Module/Wiki.php
+++ b/Zotlabs/Module/Wiki.php
@@ -74,7 +74,9 @@ class Wiki extends \Zotlabs\Web\Controller {
// Configure page template
$wikiheaderName = t('Wiki');
$wikiheaderPage = t('Sandbox');
- $content = '"# Wiki Sandbox\n\nContent you **edit** and **preview** here *will not be saved*."';
+ require_once('library/markdown.php');
+ $content = t('"# Wiki Sandbox\n\nContent you **edit** and **preview** here *will not be saved*."');
+ $renderedContent = Markdown(json_decode($content));
$hide_editor = false;
$showPageControls = false;
$showNewWikiButton = $wiki_owner;
@@ -122,6 +124,9 @@ class Wiki extends \Zotlabs\Web\Controller {
goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName);
}
$content = ($p['content'] !== '' ? $p['content'] : '"# New page\n"');
+ // Render the Markdown-formatted page content in HTML
+ require_once('library/markdown.php');
+ $renderedContent = wiki_convert_links(Markdown(json_decode($content)),argv(0).'/'.argv(1).'/'.$wikiUrlName);
$hide_editor = false;
$showPageControls = $wiki_editor;
$showNewWikiButton = $wiki_owner;
@@ -133,8 +138,6 @@ class Wiki extends \Zotlabs\Web\Controller {
default: // Strip the extraneous URL components
goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName.'/'.$pageUrlName);
}
- // Render the Markdown-formatted page content in HTML
- require_once('library/markdown.php');
$wikiModalID = random_string(3);
$wikiModal = replace_macros(
@@ -145,7 +148,7 @@ class Wiki extends \Zotlabs\Web\Controller {
'$cancel' => t('Cancel')
)
);
-
+
$o .= replace_macros(get_markup_template('wiki.tpl'),array(
'$wikiheaderName' => $wikiheaderName,
'$wikiheaderPage' => $wikiheaderPage,
@@ -162,7 +165,7 @@ class Wiki extends \Zotlabs\Web\Controller {
'$acl' => $x['acl'],
'$bang' => $x['bang'],
'$content' => $content,
- '$renderedContent' => Markdown(json_decode($content)),
+ '$renderedContent' => $renderedContent,
'$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''),
'$pageName' => array('pageName', t('Enter the name of the new page:'), '', ''),
'$pageRename' => array('pageRename', t('Enter the new name:'), '', ''),
@@ -170,7 +173,17 @@ class Wiki extends \Zotlabs\Web\Controller {
'$pageHistory' => $pageHistory['history'],
'$wikiModal' => $wikiModal,
'$wikiModalID' => $wikiModalID,
- '$commit' => 'HEAD'
+ '$commit' => 'HEAD',
+ '$embedPhotos' => t('Embed image from photo albums'),
+ '$embedPhotosModalTitle' => t('Embed an image from your albums'),
+ '$embedPhotosModalCancel' => t('Cancel'),
+ '$embedPhotosModalOK' => t('OK'),
+ '$modalchooseimages' => t('Choose images to embed'),
+ '$modalchoosealbum' => t('Choose an album'),
+ '$modaldiffalbum' => t('Choose a different album...'),
+ '$modalerrorlist' => t('Error getting album list'),
+ '$modalerrorlink' => t('Error getting photo link'),
+ '$modalerroralbum' => t('Error getting album'),
));
head_add_js('library/ace/ace.js'); // Ace Code Editor
return $o;
@@ -183,8 +196,12 @@ 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');
$html = purify_html(Markdown($content));
+ $w = wiki_get_wiki($resource_id);
+ $wikiURL = argv(0).'/'.argv(1).'/'.$w['urlName'];
+ $html = wiki_convert_links($html,$wikiURL);
json_return_and_die(array('html' => $html, 'success' => true));
}
@@ -202,6 +219,7 @@ class Wiki extends \Zotlabs\Web\Controller {
}
$wiki = array();
// Generate new wiki info from input name
+ $wiki['postVisible'] = ((intval($_POST['postVisible']) === 0) ? 0 : 1);
$wiki['rawName'] = $_POST['wikiName'];
$wiki['htmlName'] = escape_tags($_POST['wikiName']);
$wiki['urlName'] = urlencode($_POST['wikiName']);
@@ -235,20 +253,7 @@ class Wiki extends \Zotlabs\Web\Controller {
if (local_channel() !== intval($channel['channel_id'])) {
logger('Wiki delete permission denied.' . EOL);
json_return_and_die(array('message' => 'Wiki delete permission denied.', 'success' => false));
- } else {
- /*
- $channel = get_channel_by_nick($nick);
- $observer_hash = get_observer_hash();
- // Figure out who the page owner is.
- $perms = get_all_perms(intval($channel['channel_id']), $observer_hash);
- // TODO: Create a new permission setting for wiki analogous to webpages. Until
- // then, use webpage permissions
- if (!$perms['write_pages']) {
- logger('Wiki delete permission denied.' . EOL);
- json_return_and_die(array('success' => false));
- }
- */
- }
+ }
$resource_id = $_POST['resource_id'];
$deleted = wiki_delete_wiki($resource_id);
if ($deleted['success']) {
@@ -482,7 +487,6 @@ class Wiki extends \Zotlabs\Web\Controller {
}
}
$renamed = wiki_rename_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName, 'pageNewName' => $pageNewName));
- logger('$renamed: ' . json_encode($renamed));
if($renamed['success']) {
$ob = \App::get_observer();
$commit = wiki_git_commit(array(
diff --git a/include/wiki.php b/include/wiki.php
index a89db3358..63cf70f3c 100644
--- a/include/wiki.php
+++ b/include/wiki.php
@@ -51,7 +51,7 @@ function wiki_init_wiki($channel, $wiki) {
return null;
}
// Create GitRepo object
- $git = new GitRepo($channel['channel_address'], null, false, $name, __DIR__ . '/../' . $path);
+ $git = new GitRepo($channel['channel_address'], null, false, $wiki['urlName'], __DIR__ . '/../' . $path);
if(!$git->initRepo()) {
logger('Error creating new git repo in ' . $git->path);
return null;
@@ -82,7 +82,7 @@ function wiki_create_wiki($channel, $observer_hash, $wiki, $acl) {
$ac = $acl->get();
$mid = item_message_id();
$arr = array(); // Initialize the array of parameters for the post
- $item_hidden = 0; // TODO: Allow form creator to send post to ACL about new game automatically
+ $item_hidden = ((intval($wiki['postVisible']) === 0) ? 1 : 0);
$wiki_url = z_root() . '/wiki/' . $channel['channel_address'] . '/' . $wiki['urlName'];
$arr['aid'] = $channel['channel_account_id'];
$arr['uid'] = $channel['channel_id'];
@@ -240,13 +240,11 @@ function wiki_rename_page($arr) {
return array('message' => 'Wiki not found.', 'success' => false);
}
$page_path_old = $w['path'].'/'.$pageUrlName.'.md';
- logger('$page_path_old: ' . $page_path_old);
if (!is_readable($page_path_old) === true) {
return array('message' => 'Cannot read wiki page: ' . $page_path_old, 'success' => false);
}
$page = array('rawName' => $pageNewName, 'htmlName' => escape_tags($pageNewName), 'urlName' => urlencode(escape_tags($pageNewName)), 'fileName' => urlencode(escape_tags($pageNewName)).'.md');
$page_path_new = $w['path'] . '/' . $page['fileName'] ;
- logger('$page_path_new: ' . $page_path_new);
if (is_file($page_path_new)) {
return array('message' => 'Page already exists.', 'success' => false);
}
@@ -475,4 +473,24 @@ function wiki_generate_page_filename($name) {
} else {
return $file . '.md';
}
+}
+
+function wiki_convert_links($s, $wikiURL) {
+
+ if (strpos($s,'[[') !== false) {
+ preg_match_all("/\[\[(.*?)\]\]/", $s, $match);
+ $pages = $pageURLs = array();
+ foreach ($match[1] as $m) {
+ // TODO: Why do we need to double urlencode for this to work?
+ $pageURLs[] = urlencode(urlencode(escape_tags($m)));
+ $pages[] = $m;
+ }
+ $idx = 0;
+ while(strpos($s,'[[') !== false) {
+ $replace = '<a href="'.$wikiURL.'/'.$pageURLs[$idx].'">'.$pages[$idx].'</a>';
+ $s = preg_replace("/\[\[(.*?)\]\]/", $replace, $s, 1);
+ $idx++;
+ }
+ }
+ return $s;
} \ No newline at end of file
diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl
index aa0b88545..1d8570828 100644
--- a/view/tpl/wiki.tpl
+++ b/view/tpl/wiki.tpl
@@ -32,8 +32,20 @@
<form id="new-wiki-form" action="wiki/{{$channel}}/create/wiki" method="post" >
<div class="clear"></div>
{{include file="field_input.tpl" field=$wikiName}}
+
+ <div id="post-visible-container" class="form-group field checkbox">
+ <span style="font-size:1.2em;" class="pull-left">Send notification post?</span>
+ <div style="margin-left:20px" class="pull-left">
+ <input name="postVisible" id="postVisible" value="0" type="checkbox">
+ <label class="switchlabel" for="postVisible">
+ <span class="onoffswitch-inner" data-on="Post" data-off="None"></span>
+ <span class="onoffswitch-switch"></span>
+ </label>
+ </div>
+ </div>
+
<div class="btn-group pull-right">
- <div id="profile-jot-submit-right" class="btn-group">
+ <div id="profile-jot-submit-right" class="btn-group" style="margin-right: 20px;">
<button id="dbtn-acl" class="btn btn-default btn-sm" data-toggle="modal" data-target="#aclModal" title="Permission settings" onclick="return false;">
<i id="jot-perms-icon" class="fa fa-{{$lockstate}} jot-icons">{{$bang}}</i>
</button>
@@ -80,6 +92,9 @@
<li><a id="save-page" data-toggle="tab" href="#">Save</a></li>
<li><a id="rename-page" data-toggle="tab" href="#">Rename</a></li>
<li><a id="delete-page" data-toggle="tab" href="#">Delete</a></li>
+ <li class="divider"></li>
+ <li><a id="embed-image" data-toggle="tab" href="#">Embed image</a></li>
+
</ul>
</li>
{{/if}}
@@ -111,6 +126,29 @@
{{$wikiModal}}
+
+<div class="modal" id="embedPhotoModal" tabindex="-1" role="dialog" aria-labelledby="embedPhotoLabel" aria-hidden="true">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
+ <h4 class="modal-title" id="embedPhotoModalLabel">{{$embedPhotosModalTitle}}</h4>
+ </div>
+ <div class="modal-body" id="embedPhotoModalBody" >
+ <div id="embedPhotoModalBodyAlbumListDialog" class="hide">
+ <div id="embedPhotoModalBodyAlbumList"></div>
+ </div>
+ <div id="embedPhotoModalBodyAlbumDialog" class="hide">
+ </div>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default" data-dismiss="modal">{{$embedPhotosModalCancel}}</button>
+ <button id="embed-photo-OKButton" type="button" class="btn btn-primary">{{$embedPhotosModalOK}}</button>
+ </div>
+ </div><!-- /.modal-content -->
+ </div><!-- /.modal-dialog -->
+</div><!-- /.modal -->
+
<script>
window.wiki_resource_id = '{{$resource_id}}';
window.wiki_page_name = '{{$page}}';
@@ -162,7 +200,7 @@
editor.getSession().setValue(window.wiki_page_content);
$('#wiki-get-preview').click(function (ev) {
- $.post("wiki/{{$channel}}/preview", {content: editor.getValue()}, function (data) {
+ $.post("wiki/{{$channel}}/preview", {content: editor.getValue(), resource_id: window.wiki_resource_id}, function (data) {
if (data.success) {
$('#wiki-preview').html(data.html);
} else {
@@ -339,4 +377,95 @@ function wiki_delete_wiki(wikiHtmlName, resource_id) {
}
}, 'json');
}
+
+ $('#embed-image').click(function (ev) {
+ initializeEmbedPhotoDialog();
+ ev.preventDefault();
+ });
+
+
+ var initializeEmbedPhotoDialog = function () {
+ $('.embed-photo-selected-photo').each(function (index) {
+ $(this).removeClass('embed-photo-selected-photo');
+ });
+ getPhotoAlbumList();
+ $('#embedPhotoModalBodyAlbumDialog').off('click');
+ $('#embedPhotoModal').modal();
+ };
+
+ var choosePhotoFromAlbum = function (album) {
+ $.post("embedphotos/album", {name: album},
+ function(data) {
+ if (data['status']) {
+ $('#embedPhotoModalLabel').html('{{$modalchooseimages}}');
+ $('#embedPhotoModalBodyAlbumDialog').html('\
+ <div><ul class="nav">\n\
+ <li><a href="#" onclick="initializeEmbedPhotoDialog();return false;">\n\
+ <i class="fa fa-chevron-left"></i>&nbsp\n\
+ {{$modaldiffalbum}}\n\
+ </a>\n\
+ </li>\n\
+ </ul><br></div>')
+ $('#embedPhotoModalBodyAlbumDialog').append(data['content']);
+ $('#embedPhotoModalBodyAlbumDialog').click(function (evt) {
+ evt.preventDefault();
+ var image = document.getElementById(evt.target.id);
+ if (typeof($(image).parent()[0]) !== 'undefined') {
+ var imageparent = document.getElementById($(image).parent()[0].id);
+ $(imageparent).toggleClass('embed-photo-selected-photo');
+ }
+ });
+ $('#embedPhotoModalBodyAlbumListDialog').addClass('hide');
+ $('#embedPhotoModalBodyAlbumDialog').removeClass('hide');
+ $('#embed-photo-OKButton').click(function () {
+ $('.embed-photo-selected-photo').each(function (index) {
+ var href = $(this).attr('href');
+ $.post("embedphotos/photolink", {href: href},
+ function(ddata) {
+ if (ddata['status']) {
+ var imgURL = ddata['photolink'].replace( /\[.*\]\[.*\](.*)\[.*\]\[.*\]/, '\n![image]($1)' )
+ editor.getSession().insert(editor.getCursorPosition(), imgURL)
+ } else {
+ window.console.log('{{$modalerrorlink}}' + ':' + ddata['errormsg']);
+ }
+ return false;
+ },
+ 'json');
+ });
+ $('#embedPhotoModalBodyAlbumDialog').html('');
+ $('#embedPhotoModalBodyAlbumDialog').off('click');
+ $('#embedPhotoModal').modal('hide');
+ });
+ } else {
+ window.console.log('{{$modalerroralbum}} ' + JSON.stringify(album) + ':' + data['errormsg']);
+ }
+ return false;
+ },
+ 'json');
+ };
+
+ var getPhotoAlbumList = function () {
+ $.post("embedphotos/albumlist", {},
+ function(data) {
+ if (data['status']) {
+ var albums = data['albumlist']; //JSON.parse(data['albumlist']);
+ $('#embedPhotoModalLabel').html('{{$modalchoosealbum}}');
+ $('#embedPhotoModalBodyAlbumList').html('<ul class="nav"></ul>');
+ for(var i=0; i<albums.length; i++) {
+ var albumName = albums[i].text;
+ var albumLink = '<li>';
+ albumLink += '<a href="#" onclick="choosePhotoFromAlbum(\'' + albumName + '\');return false;">' + albumName + '</a>';
+ albumLink += '</li>';
+ $('#embedPhotoModalBodyAlbumList').find('ul').append(albumLink);
+ }
+ $('#embedPhotoModalBodyAlbumDialog').addClass('hide');
+ $('#embedPhotoModalBodyAlbumListDialog').removeClass('hide');
+ } else {
+ window.console.log('{{$modalerrorlist}}' + ':' + data['errormsg']);
+ }
+ return false;
+ },
+ 'json');
+ };
+
</script>