aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2011-10-05 14:36:01 +0200
committerKevin Chabowski <kevin@kch42.de>2011-10-05 14:36:01 +0200
commit0f185543bb9851fddc137f81a1e2a1d21589bc83 (patch)
treec9a3c56ba2166defac508f8d1c67ef81fe4e9789 /ratatoeskr/sys
parentafe436b25dd935aa2ae3a327027ea04b3c82e5ac (diff)
downloadratatoeskr-cms-0f185543bb9851fddc137f81a1e2a1d21589bc83.tar.gz
ratatoeskr-cms-0f185543bb9851fddc137f81a1e2a1d21589bc83.tar.bz2
ratatoeskr-cms-0f185543bb9851fddc137f81a1e2a1d21589bc83.zip
Backend, frontend and 404 handlers partially implemented.
* Backend layout done. * Frontend theoretically done (untested). * 404 handler done * Added textprocessors.php
Diffstat (limited to 'ratatoeskr/sys')
-rw-r--r--ratatoeskr/sys/default_settings.php3
-rw-r--r--ratatoeskr/sys/textprocessors.php78
2 files changed, 80 insertions, 1 deletions
diff --git a/ratatoeskr/sys/default_settings.php b/ratatoeskr/sys/default_settings.php
index 7b42028..cb755cb 100644
--- a/ratatoeskr/sys/default_settings.php
+++ b/ratatoeskr/sys/default_settings.php
@@ -4,7 +4,8 @@ $default_settings = array(
"comment_visible_default" => False,
"default_language" => "en",
"default_section" => 0/* Must be created */
- "allow_comments_default" => True
+ "allow_comments_default" => True,
+ "comment_textprocessor" => "Markdown"
);
?>
diff --git a/ratatoeskr/sys/textprocessors.php b/ratatoeskr/sys/textprocessors.php
new file mode 100644
index 0000000..3e67b01
--- /dev/null
+++ b/ratatoeskr/sys/textprocessors.php
@@ -0,0 +1,78 @@
+<?php
+/*
+ * File: ratatoeskr/textprocessors.php
+ * Manage text processors (functions that transform text to HTML) and implement some default ones.
+ *
+ * License:
+ * This file is part of Ratatöskr.
+ * Ratatöskr is licensed unter the MIT / X11 License.
+ * See "ratatoeskr/licenses/ratatoeskr" for more information.
+ */
+
+require_once(dirname(__FILE__) . "/../libs/markdown.php");
+require_once(dirname(__FILE__) . "/utils.php");
+
+/*
+ * Function: textprocessor_register
+ * Register a textprocessor.
+ *
+ * Parameters:
+ * $namen - The name of the textprocessor
+ * $fx - The textprocessor function (function($input), returns HTML)
+ * $visible_in_backend - Should this textprocessor be visible in the backend? Defaults to True.
+ */
+function textprocessor_register($name, $fx, $visible_in_backend=True)
+{
+ global $textprocessors;
+ $textprocessors[$name] = array($fx, $visible_in_backend);
+}
+
+/*
+ * Function: textprocessor_apply
+ * Apply a textprocessor on a text.
+ *
+ * Parameters:
+ * $text - The input text.
+ * $textprocessor - The name of the textprocessor.
+ *
+ * Returns:
+ * HTML
+ */
+function textprocessor_apply($text, $textprocessor)
+{
+ global $textprocessors;
+ if(!isset($textprocessors[$textprocessor]))
+ throw new Exception("Unknown Textprocessor: $textprocessor");
+
+ $fx = @$textprocessors[$textprocessor][0];
+ if(!is_callable($fx))
+ throw new Exception("Invalid Textprocessor: $textprocessor");
+
+ return call_user_func($fx, $text);
+}
+
+/*
+ * Function: textprocessor_apply_translation
+ * Applys a textprocessor automatically on a <Translation> object. The used textprocessor is determined by the $texttype property.
+ *
+ * Parameters:
+ * $translationobj - The <Translation> object.
+ *
+ * Returns:
+ * HTML
+ */
+function textprocessor_apply_translation($translationobj)
+{
+ return textprocessor_apply($translationobj->text, $translationobj->texttype);
+}
+
+if(!isset($textprocessors))
+{
+ $textprocessors = array(
+ "Markdown" => array("Markdown", True),
+ "Plain Text" => array(function($text) { return str_replace(array("\r\n", "\n"), array("<br />", "<br />"), htmlesc($text)); }, True),
+ "HTML" => array(function($text) { return $text; }, True)
+ );
+}
+
+?>