From 05a9f0aa1473e155c7f0ac27ef733bf174e49abd Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Wed, 3 Aug 2016 20:53:51 -0400 Subject: Convert select bbcode tags including [observer], [baseurl], [sitename] --- Zotlabs/Module/Wiki.php | 1 + include/wiki.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php index 55a52ea6d..2e3dbb673 100644 --- a/Zotlabs/Module/Wiki.php +++ b/Zotlabs/Module/Wiki.php @@ -221,6 +221,7 @@ class Wiki extends \Zotlabs\Web\Controller { $content = $_POST['content']; $resource_id = $_POST['resource_id']; require_once('library/markdown.php'); + $content = wiki_bbcode($content); $html = wiki_generate_toc(purify_html(Markdown($content))); $w = wiki_get_wiki($resource_id); $wikiURL = argv(0).'/'.argv(1).'/'.$w['urlName']; diff --git a/include/wiki.php b/include/wiki.php index 424b2d9a0..494ff835e 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -505,6 +505,39 @@ function wiki_generate_toc($s) { return $s; } +/** + * Converts a select set of bbcode tags. Much of the code is copied from include/bbcode.php + * @param string $s + * @return string + */ +function wiki_bbcode($s) { + + $s = str_replace(array('[baseurl]', '[sitename]'), array(z_root(), get_config('system', 'sitename')), $s); + + $observer = App::get_observer(); + if ($observer) { + $s1 = ''; + $s2 = ''; + $obsBaseURL = $observer['xchan_connurl']; + $obsBaseURL = preg_replace("/\/poco\/.*$/", '', $obsBaseURL); + $s = str_replace('[observer.baseurl]', $obsBaseURL, $s); + $s = str_replace('[observer.url]', $observer['xchan_url'], $s); + $s = str_replace('[observer.name]', $s1 . $observer['xchan_name'] . $s2, $s); + $s = str_replace('[observer.address]', $s1 . $observer['xchan_addr'] . $s2, $s); + $s = str_replace('[observer.webname]', substr($observer['xchan_addr'], 0, strpos($observer['xchan_addr'], '@')), $s); + $s = str_replace('[observer.photo]', '', $s); + } else { + $s = str_replace('[observer.baseurl]', '', $s); + $s = str_replace('[observer.url]', '', $s); + $s = str_replace('[observer.name]', '', $s); + $s = str_replace('[observer.address]', '', $s); + $s = str_replace('[observer.webname]', '', $s); + $s = str_replace('[observer.photo]', '', $s); + } + + return $s; +} + // This function is derived from // http://stackoverflow.com/questions/32068537/generate-table-of-contents-from-markdown-in-php function wiki_toc($content) { -- cgit v1.2.3 From 6a82ff871f56233756c2036d307e5cfffbfab325 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Thu, 4 Aug 2016 19:45:35 -0400 Subject: Parse bbcode when page loads --- Zotlabs/Module/Wiki.php | 4 ++-- include/wiki.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php index 2e3dbb673..24a0b6e1c 100644 --- a/Zotlabs/Module/Wiki.php +++ b/Zotlabs/Module/Wiki.php @@ -142,8 +142,8 @@ class Wiki extends \Zotlabs\Web\Controller { } $content = ($p['content'] !== '' ? htmlspecialchars_decode($p['content'],ENT_COMPAT) : '"# New page\n"'); // Render the Markdown-formatted page content in HTML - require_once('library/markdown.php'); - $html = wiki_generate_toc(purify_html(Markdown(json_decode($content)))); + require_once('library/markdown.php'); + $html = wiki_generate_toc(purify_html(Markdown(wiki_bbcode(json_decode($content))))); $renderedContent = wiki_convert_links($html,argv(0).'/'.argv(1).'/'.$wikiUrlName); $hide_editor = false; $showPageControls = $wiki_editor; diff --git a/include/wiki.php b/include/wiki.php index 494ff835e..d52308b08 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -495,6 +495,12 @@ function wiki_convert_links($s, $wikiURL) { return $s; } +/** + * Replace the instances of the string [toc] with a list element that will be populated by + * a table of contents by the JavaScript library + * @param string $s + * @return string + */ function wiki_generate_toc($s) { if (strpos($s,'[toc]') !== false) { -- cgit v1.2.3