From 780f83a118146cf67509574ac88024c2cb03cf3a Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sat, 25 Jun 2016 06:27:14 -0500 Subject: Post generation about new wiki is optional, default is NOT to post. Fixed bug in wiki creation. Added embed image dialog and album browser. --- Zotlabs/Module/Wiki.php | 31 ++++++------ include/wiki.php | 6 +-- view/tpl/wiki.tpl | 131 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 146 insertions(+), 22 deletions(-) diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php index bef831de8..1c3add38f 100644 --- a/Zotlabs/Module/Wiki.php +++ b/Zotlabs/Module/Wiki.php @@ -145,7 +145,7 @@ class Wiki extends \Zotlabs\Web\Controller { '$cancel' => t('Cancel') ) ); - + $o .= replace_macros(get_markup_template('wiki.tpl'),array( '$wikiheaderName' => $wikiheaderName, '$wikiheaderPage' => $wikiheaderPage, @@ -170,7 +170,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; @@ -202,6 +212,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 +246,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 +480,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..fdbc704dc 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); } diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl index aa0b88545..11c12e628 100644 --- a/view/tpl/wiki.tpl +++ b/view/tpl/wiki.tpl @@ -32,8 +32,20 @@
{{include file="field_input.tpl" field=$wikiName}} + +
+ Send notification post? +
+ + +
+
+
-
+
@@ -80,6 +92,9 @@
  • Save
  • Rename
  • Delete
  • +
  • +
  • Embed image
  • + {{/if}} @@ -111,6 +126,29 @@ {{$wikiModal}} + + + -- cgit v1.2.3 From 241b257556826e172707689b89e6f07687f8f556 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sat, 25 Jun 2016 06:50:24 -0500 Subject: Insert image links wherever cursor is in the editor --- view/tpl/wiki.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl index 11c12e628..d0744009d 100644 --- a/view/tpl/wiki.tpl +++ b/view/tpl/wiki.tpl @@ -423,8 +423,8 @@ function wiki_delete_wiki(wikiHtmlName, resource_id) { $.post("embedphotos/photolink", {href: href}, function(ddata) { if (ddata['status']) { - var imgURL = ddata['photolink'].replace( /\[.*\]\[.*\](.*)\[.*\]\[.*\]/, '![image]($1)' ) - editor.getSession().setValue(editor.getValue() + imgURL); + var imgURL = ddata['photolink'].replace( /\[.*\]\[.*\](.*)\[.*\]\[.*\]/, '\n![image]($1)' ) + editor.getSession().insert(editor.getCursorPosition(), imgURL) } else { window.console.log('{{$modalerrorlink}}' + ':' + ddata['errormsg']); } -- cgit v1.2.3 From 2dc1236dcae487bf3887942a2e58a240157bb896 Mon Sep 17 00:00:00 2001 From: Treer Date: Sat, 25 Jun 2016 22:38:15 +1000 Subject: Allow absolute links to css and js files --- include/plugin.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/include/plugin.php b/include/plugin.php index c95f8cbf9..3f60e5e04 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -551,15 +551,21 @@ function head_get_css() { } function format_css_if_exists($source) { - if (strpos($source[0], '/') !== false) + $path_prefix = script_path() . '/'; + + if (strpos($source[0], '/') !== false) { + // The source is a URL $path = $source[0]; - else + // If the url starts with // then it's an absolute URL + if($source[0][0] === '/' && $source[0][1] === '/') $path_prefix = ''; + } else { + // It's a file from the theme $path = theme_include($source[0]); + } if($path) { - $path = script_path() . '/' . $path; $qstring = ((parse_url($path, PHP_URL_QUERY)) ? '&' : '?') . 'v=' . STD_VERSION; - return '' . "\r\n"; + return '' . "\r\n"; } } @@ -643,14 +649,20 @@ function head_get_main_js() { } function format_js_if_exists($source) { - if(strpos($source,'/') !== false) + $path_prefix = script_path() . '/'; + + if(strpos($source,'/') !== false) { + // The source is a URL $path = $source; - else + // If the url starts with // then it's an absolute URL + if($source[0][0] === '/' && $source[0][1] === '/') $path_prefix = ''; + } else { + // It's a file from the theme $path = theme_include($source); + } if($path) { - $path = script_path() . '/' . $path; $qstring = ((parse_url($path, PHP_URL_QUERY)) ? '&' : '?') . 'v=' . STD_VERSION; - return '' . "\r\n" ; + return '' . "\r\n" ; } } -- cgit v1.2.3 From bd4a88cd3e4d636178430539435879b30dbd7af2 Mon Sep 17 00:00:00 2001 From: Treer Date: Sun, 26 Jun 2016 03:17:10 +1000 Subject: fix help link --- view/tpl/pdledit.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/tpl/pdledit.tpl b/view/tpl/pdledit.tpl index 3e1f5a3fc..cef93d324 100644 --- a/view/tpl/pdledit.tpl +++ b/view/tpl/pdledit.tpl @@ -4,7 +4,7 @@

    {{$mname}} {{$module}}


    -{{$help}} +{{$help}}

    -- cgit v1.2.3 From 0df3978cc5891f1383dd0dbcdc1c6b4c0010e645 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sat, 25 Jun 2016 14:29:52 -0500 Subject: A page name wrapped in double brackets is converted into a link to another page in the current wiki --- Zotlabs/Module/Wiki.php | 15 +++++++++++---- include/wiki.php | 20 ++++++++++++++++++++ view/tpl/wiki.tpl | 2 +- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php index 1c3add38f..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( @@ -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:'), '', ''), @@ -193,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)); } diff --git a/include/wiki.php b/include/wiki.php index fdbc704dc..63cf70f3c 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -473,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 = ''.$pages[$idx].''; + $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 d0744009d..1d8570828 100644 --- a/view/tpl/wiki.tpl +++ b/view/tpl/wiki.tpl @@ -200,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 { -- cgit v1.2.3 From e0a76376265937a62c48fde03c7947cde972f8b7 Mon Sep 17 00:00:00 2001 From: Treer Date: Sun, 26 Jun 2016 13:08:40 +1000 Subject: fix absolute .js urls --- include/plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/plugin.php b/include/plugin.php index 3f60e5e04..6dfda1cc9 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -655,7 +655,7 @@ function format_js_if_exists($source) { // The source is a URL $path = $source; // If the url starts with // then it's an absolute URL - if($source[0][0] === '/' && $source[0][1] === '/') $path_prefix = ''; + if($source[0] === '/' && $source[1] === '/') $path_prefix = ''; } else { // It's a file from the theme $path = theme_include($source); -- cgit v1.2.3