aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2012-02-01 21:47:40 +0100
committerKevin Chabowski <kevin@kch42.de>2012-02-01 21:47:40 +0100
commite4e0bf836669b5419a0e2c86409c46898beef5b4 (patch)
tree9560aaed15f3e2c28c4d4a3a09fb317e05ee848b
parentf1391f02d0167fd24b0bda731a20a972cb0a8163 (diff)
downloadratatoeskr-cms-e4e0bf836669b5419a0e2c86409c46898beef5b4.tar.gz
ratatoeskr-cms-e4e0bf836669b5419a0e2c86409c46898beef5b4.tar.bz2
ratatoeskr-cms-e4e0bf836669b5419a0e2c86409c46898beef5b4.zip
Added on_comment_store event.
-rw-r--r--ratatoeskr/frontend.php26
-rw-r--r--ratatoeskr/sys/plugin_api.php21
2 files changed, 25 insertions, 22 deletions
diff --git a/ratatoeskr/frontend.php b/ratatoeskr/frontend.php
index 8aca311..b89fe3a 100644
--- a/ratatoeskr/frontend.php
+++ b/ratatoeskr/frontend.php
@@ -82,8 +82,7 @@ function tag_transform_ste($tag, $lang)
* * custom (array: name=>value)
* * status (numeric)
* * section (sub-fields: <section_transform_ste>)
- * * timestamp
- * * tags (sub-fields: <tag_transform_ste>)
+ * * timestamp, tags (array(sub-fields: <tag_transform_ste>))
* * languages (array: language name=>url)
* * comments_allowed
*/
@@ -397,6 +396,8 @@ $ste->register_tag("article_comments", function($ste, $params, $sub)
* You might also want to define this:
*
* * <input type="submit" name="preview_comment" /> - For a preview of the comment.
+ *
+ * If the parameter default is not empty, the tag's content will be thrown away.
*
* Returns:
* The finished HTML form.
@@ -680,30 +681,17 @@ $comment_validators = array(
if(time() - $_SESSION["ratatoeskr_comment_tokens"][$_POST["comment_token"]] < 10) /* Comment filled in in under 10 seconds? Most likely a spambot. */
throw new CommentRejected($translation["comment_too_fast"]);
unset($_SESSION["ratatoeskr_comment_tokens"][$_POST["comment_token"]]);
- },
+ }
);
-/*
- * 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 - The validator function (function()).
- */
-function register_comment_validator($fx)
-{
- global $comment_validators;
- $comment_validators[] = $fx;
-}
+$on_comment_store = array();
/*
* Function: frontend_url_handler
*/
function frontend_url_handler(&$data, $url_now, &$url_next)
{
- global $ste, $ratatoeskr_settings, $languages, $metasections, $comment_validators;
+ global $ste, $ratatoeskr_settings, $languages, $metasections, $comment_validators, $on_comment_store;
$path = array_merge(array($url_now), $url_next);
$url_next = array();
@@ -793,6 +781,8 @@ function frontend_url_handler(&$data, $url_now, &$url_next)
$comment->text = $_POST["comment_text"];
$comment->save();
$ste->vars["current"]["commented"] = "Yes";
+ foreach($on_comment_store as $ocs_fx)
+ call_user_func($ocs_fx, $comment);
}
}
}
diff --git a/ratatoeskr/sys/plugin_api.php b/ratatoeskr/sys/plugin_api.php
index 7a80a5b..c592db3 100644
--- a/ratatoeskr/sys/plugin_api.php
+++ b/ratatoeskr/sys/plugin_api.php
@@ -15,15 +15,15 @@ require_once(dirname(__FILE__) . "/../frontend.php");
/*
* Constant: APIVERSION
- * The current API version (4).
+ * The current API version (5).
*/
-define("APIVERSION", 4);
+define("APIVERSION", 5);
/*
* Array: $api_compat
* Array of API versions, this version is compatible to (including itself).
*/
-$api_compat = array(3, 4);
+$api_compat = array(3, 4, 5);
$url_handlers = array();
/*
@@ -145,7 +145,20 @@ abstract class RatatoeskrPlugin
*/
final protected function register_comment_validator($fx)
{
- register_comment_validator($fx);
+ global $comment_validators;
+ $comment_validators[] = $fx;
+ }
+ /*
+ * Function: register_on_comment_store
+ * Register a function that will be called, after a comment was saved.
+ *
+ * Parameters:
+ * $fx - Function, that accepts one parameter (a <Comment> object).
+ */
+ final protected function register_on_comment_store($fx)
+ {
+ global $on_comment_store;
+ $on_comment_store[] = $fx;
}
/*