summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorAlexander Sulfrian <alex@spline.inf.fu-berlin.de>2013-08-30 15:20:30 +0000
committerAlexander Sulfrian <alex@spline.inf.fu-berlin.de>2013-08-30 15:20:30 +0000
commita1e990177b94299d00ff72125bb1d4ea6a05fd73 (patch)
treec80f394163dd5a5efb9cdf144d577938ec85c8bc /plugins
parent1c70b0447570619f537147db8ca491c054467a12 (diff)
downloaddokuwiki-a1e990177b94299d00ff72125bb1d4ea6a05fd73.tar.gz
dokuwiki-a1e990177b94299d00ff72125bb1d4ea6a05fd73.tar.bz2
dokuwiki-a1e990177b94299d00ff72125bb1d4ea6a05fd73.zip
use smarty to render templates from wikipages
Diffstat (limited to 'plugins')
-rw-r--r--plugins/function.parse_service.php25
-rw-r--r--plugins/modifier.contact_info.php12
-rw-r--r--plugins/modifier.count.php8
-rw-r--r--plugins/modifier.group_by.php23
-rw-r--r--plugins/modifier.key_not_exists.php11
-rw-r--r--plugins/prefilter.whitespace_control.php63
-rw-r--r--plugins/resource.dokuwiki.php33
7 files changed, 175 insertions, 0 deletions
diff --git a/plugins/function.parse_service.php b/plugins/function.parse_service.php
new file mode 100644
index 0000000..1b02886
--- /dev/null
+++ b/plugins/function.parse_service.php
@@ -0,0 +1,25 @@
+<?php
+
+function smarty_function_parse_service($params, Smarty_Internal_Template $template)
+{
+ if (empty($params['var'])) {
+ trigger_error("assign: missing 'var' parameter");
+ return;
+ }
+
+ if (!in_array('value', array_keys($params))) {
+ trigger_error("assign: missing 'value' parameter");
+ return;
+ }
+
+ $name = $params['value'];
+ $port = null;
+ if (preg_match('/(.*): (.*)/', $params['value'], $match)) {
+ $name = $match[1];
+ $port = $match[2];
+ }
+
+ $template->assign($params['var'], array('name' => $name, 'port' => $port));
+}
+
+?>
diff --git a/plugins/modifier.contact_info.php b/plugins/modifier.contact_info.php
new file mode 100644
index 0000000..89b16a4
--- /dev/null
+++ b/plugins/modifier.contact_info.php
@@ -0,0 +1,12 @@
+<?php
+
+function smarty_modifier_contact_info($value)
+{
+ if (preg_match('/^([^:]*): (.*@.*)$/', $value, $match)) {
+ return '[[' . $match[2] . '|' . $match[1] . ']]';
+ }
+
+ return '[[' . $value . '@spline.inf.fu-berlin.de' . '|' . $value . ']]';
+}
+
+?>
diff --git a/plugins/modifier.count.php b/plugins/modifier.count.php
new file mode 100644
index 0000000..c077c11
--- /dev/null
+++ b/plugins/modifier.count.php
@@ -0,0 +1,8 @@
+<?php
+
+function smarty_modifier_count($value)
+{
+ return count($value);
+}
+
+?>
diff --git a/plugins/modifier.group_by.php b/plugins/modifier.group_by.php
new file mode 100644
index 0000000..74bf045
--- /dev/null
+++ b/plugins/modifier.group_by.php
@@ -0,0 +1,23 @@
+<?php
+
+function smarty_modifier_group_by($value, $key)
+{
+ $array = array();
+
+ foreach ($value as $k => $v) {
+ if (array_key_exists($key, $v)) {
+ if (is_array($v[$key])) {
+ foreach ($v[$key] as $key_part) {
+ $array[$key_part][$k] = $v;
+ }
+ }
+ else {
+ $array[$v[$key]][$k] = $v;
+ }
+ }
+ }
+
+ return $array;
+}
+
+?>
diff --git a/plugins/modifier.key_not_exists.php b/plugins/modifier.key_not_exists.php
new file mode 100644
index 0000000..f6906cd
--- /dev/null
+++ b/plugins/modifier.key_not_exists.php
@@ -0,0 +1,11 @@
+<?php
+
+function smarty_modifier_key_not_exists($value, $key)
+{
+ return array_filter($value,
+ function($v) use ($key) {
+ return !array_key_exists($key, $v);
+ });
+}
+
+?>
diff --git a/plugins/prefilter.whitespace_control.php b/plugins/prefilter.whitespace_control.php
new file mode 100644
index 0000000..fa6b854
--- /dev/null
+++ b/plugins/prefilter.whitespace_control.php
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * Smarty Whitespace Control
+ *
+ * {-tag} remove white space infront of tag up to the previous non-whitespace character or beginning of the line
+ * "text \n\n\t {-tag}" -> "text \n\n{tag}"
+ * "text \n\n\t text\t {-tag}" -> "text \n\n\t text{tag}"
+ * {--tag} remove white space infront of tag up to the previous non-whitespace character
+ * "text \n\n\t {--tag}" -> "text{tag}"
+ * "text \n\n\t text\t {--tag}" -> "text \n\n\t text{tag}"
+ * {+-tag}
+ * {-+tag} replace white space infront of tag up to the previous non-whitespace character by a single line-break
+ * "text \n\n\t {-+tag}" -> "text\n{tag}"
+ * "text \n\n\t text\t {-+tag}" -> "text \n\n\t text\n{tag}"
+ *
+ * {tag-} remove white space after tag up to the next non-whitespace character or end of the line
+ * "{tag-} \n\n\t text" -> "{tag}\n\n\t text"
+ * "{tag-} text \n\n\t text" -> "{tag}text \n\n\t text"
+ * {tag--} remove white space after tag up to the next non-whitespace character
+ * "{tag--} \n\n\t text" -> "{tag}text"
+ * "{tag--} text \n\n\t text" -> "{tag}text \n\n\t text"
+ * {tag+-}
+ * {tag-+} replace white space after tag up to the next non-whitespace character by a single line-break
+ * "{tag-+} \n\n\t text" -> "{tag}\n\ntext"
+ * "{tag-+} text \n\n\t text" -> "{tag}\n\ntext \n\n\t text"
+ *
+ * {tag+} replace white space after tag up to the end of the line with an additional line-break
+ * "{tag+} \n\t text" -> "{tag}\n\n\t text"
+ * "{tag+} text \n\n\t text" -> "{tag}\n\ntext \n\n\t text"
+ *
+ * Any combination of the above, say {--tag+} is possible. Any + modifiers are executed before - modifiers, so
+ * "{tag+-}{--tag}" will lead to "{tag}{tag}"
+ *
+ * NOTE: {tag+} and {tag-+} cause two trailing \n. This is done because PHP itself throws away the first \n.
+ * So \n\n in the template will lead to \n in the output
+ *
+ * @param string $string raw template source
+ * @param Smarty_Internal_Template $template Template instance
+ * @return string raw template source after whitespace control was applied
+ * @author Rodney Rehm
+ */
+function smarty_prefilter_whitespace_control($string, Smarty_Internal_Template $template) {
+ $ldelim = $template->smarty->left_delimiter;
+ $rdelim = $template->smarty->right_delimiter;
+ $_ldelim = preg_quote($ldelim);
+ $_rdelim = preg_quote($rdelim);
+
+ // remove preceeding whitepsace preserving a single line-break
+ $string = preg_replace('#\s*'. $_ldelim .'(?:-\+|\+-)#', "\n" . $ldelim, $string);
+ // remove trailing whitespace preserving s single line-break
+ $string = preg_replace('#(?:\+-|-\+)'. $_rdelim .'\s*#', $rdelim . "\n\n", $string);
+
+ // remove preceeding whitepsace
+ $string = preg_replace('#\s*'. $_ldelim .'--|[^\S\r\n]*'. $_ldelim .'-#', $ldelim, $string);
+ // remove trailing whitespace
+ $string = preg_replace('#--'. $_rdelim .'\s*|-'. $_rdelim .'[^\S\r\n]*#', $rdelim, $string);
+
+ // force trailing line-break
+ $string = preg_replace('#\+'. $_rdelim .'(?:\s*[\r\n]|[^\S\r\n]*)#', $rdelim . "\n\n", $string);
+
+ return $string;
+}
diff --git a/plugins/resource.dokuwiki.php b/plugins/resource.dokuwiki.php
new file mode 100644
index 0000000..4842524
--- /dev/null
+++ b/plugins/resource.dokuwiki.php
@@ -0,0 +1,33 @@
+<?php
+
+class Smarty_Resource_Dokuwiki extends Smarty_Resource_Custom {
+
+ private function build_pagename($name) {
+ return 'hostinfo:templates:' . cleanID($name);
+ }
+
+ protected function fetch($name, &$source, &$mtime)
+ {
+ $page = $this->build_pagename($name);
+ if (page_exists($page)) {
+ $source = rawWiki($page);
+ $mtime = p_get_metadata($page, 'last_change date');
+ }
+ else {
+ $source = null;
+ $mtime = null;
+ }
+ }
+
+ protected function fetchTimestamp($name) {
+ $page = $this->build_pagename($name);
+ if (page_exists($page)) {
+ return p_get_metadata($page, 'last_change date');
+ }
+ else {
+ return null;
+ }
+ }
+}
+
+?>