aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2011-12-07 23:36:08 +0100
committerKevin Chabowski <kevin@kch42.de>2011-12-07 23:36:08 +0100
commit58ca56ac72724ed86690cbb75f91cdde8f5b2737 (patch)
treebf834eb9c4efd554f754d24f0ff5fdf6eb7a2717
parent1de5c5c1a8d64123444b1f38b5c5a57ba5b92436 (diff)
downloadratatoeskr-cms-58ca56ac72724ed86690cbb75f91cdde8f5b2737.tar.gz
ratatoeskr-cms-58ca56ac72724ed86690cbb75f91cdde8f5b2737.tar.bz2
ratatoeskr-cms-58ca56ac72724ed86690cbb75f91cdde8f5b2737.zip
UNTESTED: Plugin API finished.
-rw-r--r--ratatoeskr/main.php2
-rw-r--r--ratatoeskr/plugin_extradata/private/.htaccess (renamed from ratatoeskr/plugin_extradata/.htaccess)0
-rw-r--r--ratatoeskr/sys/plugin_api.php124
-rw-r--r--ratatoeskr/sys/textprocessors.php2
-rwxr-xr-xratatoeskr/templates/src/systemtemplates/master.html3
5 files changed, 115 insertions, 16 deletions
diff --git a/ratatoeskr/main.php b/ratatoeskr/main.php
index 42913c9..270537d 100644
--- a/ratatoeskr/main.php
+++ b/ratatoeskr/main.php
@@ -10,11 +10,11 @@
*/
require_once(dirname(__FILE__) . "/sys/db.php");
-require_once(dirname(__FILE__) . "/sys/plugin_api.php");
require_once(dirname(__FILE__) . "/sys/models.php");
require_once(dirname(__FILE__) . "/sys/init_ste.php");
require_once(dirname(__FILE__) . "/sys/translation.php");
require_once(dirname(__FILE__) . "/sys/urlprocess.php");
+require_once(dirname(__FILE__) . "/sys/plugin_api.php");
require_once(dirname(__FILE__) . "/frontend.php");
require_once(dirname(__FILE__) . "/backend.php");
diff --git a/ratatoeskr/plugin_extradata/.htaccess b/ratatoeskr/plugin_extradata/private/.htaccess
index 19469bf..19469bf 100644
--- a/ratatoeskr/plugin_extradata/.htaccess
+++ b/ratatoeskr/plugin_extradata/private/.htaccess
diff --git a/ratatoeskr/sys/plugin_api.php b/ratatoeskr/sys/plugin_api.php
index 6293c27..362fd9e 100644
--- a/ratatoeskr/sys/plugin_api.php
+++ b/ratatoeskr/sys/plugin_api.php
@@ -10,6 +10,20 @@
*/
require_once(dirname(__FILE__) . "/models.php");
+require_once(dirname(__FILE__) . "/textprocessors.php");
+require_once(dirname(__FILE__) . "/../frontend.php");
+
+/*
+ * Constant: APIVERSION
+ * The current API version.
+ */
+define("APIVERSION", 1);
+
+/*
+ * Array: $api_compat
+ * Array of API versions, this version is compatible to (including itself).
+ */
+$api_compat = array(1);
$url_handlers = array();
/*
@@ -26,6 +40,8 @@ function register_url_handler($name, $callback)
$url_handlers[$name] = $callback;
}
+$pluginpages_handlers = array();
+
/*
* Class: RatatoeskrPlugin
* An abstract class to be extended in order to write your own Plugin.
@@ -39,10 +55,11 @@ abstract class RatatoeskrPlugin
*
* $kvstorage - The Key-Value-Storage for the Plugin.
* $ste - Access to the global STECore object.
+ * $rel_path_to_root - Relative URL to the root of the page.
*/
protected $kvstorage;
protected $ste;
-
+ protected $rel_path_to_root;
/*
* Constructor: __construct
@@ -54,38 +71,115 @@ abstract class RatatoeskrPlugin
*/
public function __construct($id)
{
- global $ste;
+ global $ste, $rel_path_to_root;
$this->id = $id;
- $this->kvstorage = new PluginKVStorage($id);
- $this->ste = $ste;
+ $this->kvstorage = new PluginKVStorage($id);
+ $this->ste = $ste;
+ $this->rel_path_to_root = $rel_path_to_root;
}
/*
* Functions: Some getters
*
* get_id - get the Plugin-ID
- * get_additional_files_dir - Path to directory with the additional files
- * get_template_dir - Path to template directory
+ * get_custompriv_dir - Get path to the custompriv directory of your plugin.
+ * get_custompub_dir - Get path to the custompub directory of your plugin.
+ * get_custompub_url - Get URL (can be accessed from the web) to the custompub directory of your plugin.
+ * get_template_dir - Get path to your template directory to be used with STE.
*/
- final public function get_id() { return $this->id; }
- final protected function get_additional_files_dir() { return dirname(dirname(__FILE__)) . "/plugin_extradata/" . $this->id; }
- final protected function get_template_dir() { return dirname(dirname(__FILE__)) . "/templates/src/plugintemplates/" . $this->id; }
+ final public function get_id() { return $this->id; }
+ final protected function get_custompriv_dir() { return SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/private/" . $this->id; }
+ final protected function get_custompub_dir() { return SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/public/" . $this->id; }
+ final protected function get_custompub_url() { return $GLOBALS["rel_path_to_root"] . "/ratatoeskr/plugin_extradata/public/" . $this->id; }
+ final protected function get_template_dir() { return "/plugintemplates/" . $this->id; }
/*
* Function: register_url_handler
- * Easy way for register a URL handler
+ * Register a URL handler
*
* Parameters:
* $name - Name of URL
- * $objfunction - Name of object function.
+ * $fx - The function.
+ */
+ final protected function register_url_handler($name, $fx)
+ {
+ register_url_handler($name, $fx);
+ }
+
+ /*
+ * Function: register_ste_tag
+ * Register a custom STE tag.
+ *
+ * Parameters:
+ * $name - Name of your new STE tag.
+ * $fx - Function to register with this tag.
+ */
+ final protected function register_ste_tag($name, $fx)
+ {
+ $this->ste->register_tag($name, $fx);
+ }
+
+ /*
+ * Function: register_textprocessor
+ * Register a textprocessor.
+ *
+ * Parameters:
+ * $name - The name of the textprocessor-
+ * $fx - Function to register (function($input), returns HTML).
+ * $visible_in_backend - Should this textprocessor be visible in the backend? Defaults to True.
*/
- final protected function register_url_handler($name, $objfunction)
+ final protected function register_textprocessor($name, $fx, $visible_in_backend=True)
{
- register_url_handler($name, array($this, $objfunction));
+ textprocessor_register($name, $fx, $visible_in_backend);
}
- /*final protected function register_settings_page($get, $validate, $set, $structure)*/
+ /*
+ * Function: register_comment_validator
+ * Register a comment validator.
+ *
+ * A comment validator is a function, that checks the $_POST fields and decides whether a comment should be stored or not (throws an <CommentRejected> exception with the rejection reason as the message).
+ *
+ * Parameters:
+ * $fx - Validator function.
+ */
+ final protected function register_comment_validator($fx)
+ {
+ register_comment_validator($fx);
+ }
+
+ /*
+ * Function: register_backend_pluginpage
+ * Register a backend subpage for your plugin.
+ *
+ * Parameters:
+ * $label - The label for the page.
+ * $fx - A function for <urlprocess>.
+ *
+ * Your $fx should output output the result of a STE template, which should load "/systemtemplates/master.html" and overwrite the "content" section.
+ *
+ * See also:
+ * <prepare_backend_pluginpage>
+ */
+ final protected function register_backend_pluginpage($label, $fx)
+ {
+ global $pluginpages_handlers;
+
+ $this->ste->vars["pluginpages"][$this->id] = $label;
+ sort($this->ste->vars["pluginpages"]);
+ $pluginpages_handlers["p{$this->id}"] = $fx;
+ }
+
+ /*
+ * Function: prepare_backend_pluginpage
+ * Automatically sets the page title and highlights the menu-entry of your backend subpage.
+ */
+ final protected function prepare_backend_pluginpage()
+ {
+ $this->ste->vars["section"] = "plugins";
+ $this->ste->vars["submenu"] = "plugin" . $this->id;
+ $this->ste->vars["pagetitle"] = $this->ste->vars["pluginpages"][$this->id];
+ }
/*
* Functions: Functions that are called at special events
@@ -93,10 +187,12 @@ abstract class RatatoeskrPlugin
* init - Will be called after plugin is loaded. You should register your stuff here.
* install - Will be called after installation. If your plugin needs to initialize some database stuff or generate files, this is the right function.
* uninstall - Will be called during uninstallation. If you used the install function you should undo your custom installation stuff.
+ * update - Will be called after your plugin was updated to a new version.
*/
public function init() {}
public function install() {}
public function uninstall() {}
+ public function update() {}
}
?>
diff --git a/ratatoeskr/sys/textprocessors.php b/ratatoeskr/sys/textprocessors.php
index 3e67b01..08ea25c 100644
--- a/ratatoeskr/sys/textprocessors.php
+++ b/ratatoeskr/sys/textprocessors.php
@@ -17,7 +17,7 @@ require_once(dirname(__FILE__) . "/utils.php");
* Register a textprocessor.
*
* Parameters:
- * $namen - The name of the textprocessor
+ * $name - 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.
*/
diff --git a/ratatoeskr/templates/src/systemtemplates/master.html b/ratatoeskr/templates/src/systemtemplates/master.html
index 8e3bf64..637f967 100755
--- a/ratatoeskr/templates/src/systemtemplates/master.html
+++ b/ratatoeskr/templates/src/systemtemplates/master.html
@@ -49,6 +49,9 @@
<ul?{~{plugins|eq|$section}| class="active"|}>
<li><a href="$rel_path_to_root/backend/plugin/list"?{~{pluginlist|eq|$submenu}| class="active"|}><ste:get_translation for="menu_pluginlist" /></a></li>
<li><a href="$rel_path_to_root/backend/plugin/install"?{~{installplugins|eq|$submenu}| class="active"|}><ste:get_translation for="menu_plugininstall" /></a></li>
+ <ste:foreach array="pluginpages" value="pname" key="pid">
+ <li><a href="$rel_path_to_root/backend/pluginpages/p$pid"?{~{plugin$pid|eq|$submenu}| class="active"|}><ste:escape>$pname</ste:escape></a></li>
+ </ste:foreach>
</ul>
</li>
</ul>