aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2012-03-03 20:40:30 +0100
committerKevin Chabowski <kevin@kch42.de>2012-03-03 20:40:30 +0100
commitb6416b6ae3723644322855fefa5c5d3dd39e1d8b (patch)
treed9fee36fdbf141f07ad7c3e543b748b5be90d365
downloadnew_comment_notifier-b6416b6ae3723644322855fefa5c5d3dd39e1d8b.tar.gz
new_comment_notifier-b6416b6ae3723644322855fefa5c5d3dd39e1d8b.tar.bz2
new_comment_notifier-b6416b6ae3723644322855fefa5c5d3dd39e1d8b.zip
Initial commit.
-rw-r--r--.gitignore1
-rw-r--r--CONTRIBUTORS6
-rw-r--r--COPYING18
-rw-r--r--README.md4
-rwxr-xr-xbuild.sh3
-rw-r--r--plugin.php96
-rw-r--r--tpls/config.html42
7 files changed, 170 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3dd92af
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+new_comment_notifier.rpk \ No newline at end of file
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
new file mode 100644
index 0000000..495e1bd
--- /dev/null
+++ b/CONTRIBUTORS
@@ -0,0 +1,6 @@
+People who have worked on new_comment_modifier
+==============================================
+
+If you modified something, feel free to append your name to this list.
+
+* Kevin Chabowski <kevin@kch42.de>
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..68adf1f
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,18 @@
+new_comment_notifier: Copyright (c) 2012 The Ratatöskr Team
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7ae2a3d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,4 @@
+new_comment_notifier
+====================
+
+This Ratatöskr plugin sends you a mail, if someone posted a new comment. \ No newline at end of file
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..cb41842
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+r7r-plugin-packer --output=new_comment_notifier.rpk --codefile=plugin.php --classname=new_comment_notifier --pluginname=new_comment_notifier --author='The Ratatöskr Team' --versiontext="0.2" --versioncount=3 --api=5 --shortdesc="new_comment_notifier sends you a mail, if someone has written a comment." --licensefile=COPYING --tpldir=tpls
diff --git a/plugin.php b/plugin.php
new file mode 100644
index 0000000..8a58b55
--- /dev/null
+++ b/plugin.php
@@ -0,0 +1,96 @@
+<?php
+
+class new_comment_notifier extends RatatoeskrPlugin
+{
+ private $config;
+ private $config_modified = False;
+
+ public function on_comment_store($comment)
+ {
+ global $rel_path_to_root;
+
+ $baseurl = explode("/",self_url());
+ $baseurl = array_slice($baseurl, 0, -1);
+ foreach(explode("/", $rel_path_to_root) as $part)
+ {
+ if($part == "..")
+ $baseurl = array_slice($baseurl, 0, -1);
+ }
+ $baseurl = implode("/", $baseurl);
+
+ $article = $comment->get_article();
+
+ $msg = "Hello,
+Someone posted a comment to this article:
+ Title: " . @$article->title[$comment->get_language()]->text . "
+ URL: " . $baseurl . "/" . $comment->get_language() . "/" . $article->get_section()->name . "/" . $article->urlname . "
+The comment:
+ Author Name: " . $comment->author_name . "
+ Author Mail: " . $comment->author_mail . "
+ Comment Text:
+" . implode("\n", array_map(function($l){return " " . $l;}, explode("\n", $comment->text))) . "
+If you are logged in to the Ratatöskr backend, you can view the comment here:
+ " . $baseurl . "/backend/content/comments/" . $comment->get_id();
+
+ $moreheaders = "From: " . $this->config["from"] . "\r\nX-Mailer: new_comment_notifier plugin for Ratatoeskr\r\nContent-Transfer-Encoding: 8bit\r\nContent-Type: text/plain; charset=\"UTF-8\"";
+
+ foreach($this->config["to"] as $to)
+ mail($to, "Comment received", $msg, $moreheaders);
+ }
+
+ public function backend_page(&$data, $url_now, &$url_next)
+ {
+ $this->prepare_backend_pluginpage();
+
+ if(isset($_POST["send_general_settings"]))
+ {
+ if(empty($_POST["mail_from"]))
+ $this->ste->vars["error"] = "Mail From must not be empty.";
+ else
+ {
+ $this->config["from"] = $_POST["mail_from"];
+ $this->config_modified = True;
+ $this->ste->vars["success"] = "Settings saved.";
+ }
+ }
+
+ if(isset($_POST["add_new_recv"]) and (!empty($_POST["new_recv"])))
+ {
+ $this->config["to"][] = $_POST["new_recv"];
+ $this->config_modified = True;
+ $this->ste->vars["success"] = "Address added.";
+ }
+
+ if(isset($_POST["delete_recvs"]) and ($_POST["really_delete"] == "yes"))
+ {
+ $this->config["to"] = array_diff($this->config["to"], $_POST["recvs_multiselect"]);
+ $this->config_modified = True;
+ $this->ste->vars["success"] = "Receivers deleted.";
+ }
+
+ $this->ste->vars["mail_to"] = $this->config["to"];
+ $this->ste->vars["mail_from"] = $this->config["from"];
+
+ echo $this->ste->exectemplate($this->get_template_dir() . "/config.html");
+ }
+
+ public function install()
+ {
+ $this->kvstorage["config"] = array("from" => "nobody@example.com", "to" => array());
+ }
+
+ public function init()
+ {
+ $this->config = $this->kvstorage["config"];
+ $this->register_on_comment_store(array($this, "on_comment_store"));
+ $this->register_backend_pluginpage("New comment notifier", array($this, "backend_page"));
+ }
+
+ public function atexit()
+ {
+ if($this->config_modified)
+ $this->kvstorage["config"] = $this->config;
+ }
+}
+
+?>
diff --git a/tpls/config.html b/tpls/config.html
new file mode 100644
index 0000000..bfdac79
--- /dev/null
+++ b/tpls/config.html
@@ -0,0 +1,42 @@
+<ste:load name="/systemtemplates/master.html" />
+<ste:block name="content">
+ <ste:default_error />
+ <ste:default_success />
+
+ <h3>General settings</h3>
+ <form action="$rel_path_to_pluginpage" method="POST" accept-charset="UTF-8">
+ <p><strong>Mail From address:</strong> <input type="text" name="mail_from" value="<ste:escape>$mail_from</ste:escape>" /></p>
+ <p><input type="submit" name="send_general_settings" /></p>
+ </form>
+
+ <h3>Receivers</h3>
+ <form action="$rel_path_to_pluginpage" method="POST" accept-charset="UTF-8">
+ <p><strong>New receiver:</strong> <input type="text" name="new_recv" /> <input type="submit" name="add_new_recv" value="Add" /></p>
+ </form>
+
+ <form action="$rel_path_to_pluginpage" method="POST" accept-charset="UTF-8">
+ <table class="listtab">
+ <thead>
+ <tr>
+ <th>&nbsp;</th>
+ <th>Mailaddress</th>
+ </tr>
+ </thead>
+ <tbody>
+ <ste:foreach array="mail_to" value="recv">
+ <tr>
+ <td><input type="checkbox" name="recvs_multiselect[]" value="<ste:escape>$recv</ste:escape>" /></td>
+ <td><ste:escape>$recv</ste:escape></td>
+ </tr>
+ </ste:foreach>
+ </tbody>
+ </table>
+ <div>
+ <input type="submit" name="delete_recvs" value="Delete" />
+ <select name="really_delete">
+ <option value="no" selected="selected">No</option>
+ <option value="yes">Yes</option>
+ </select>
+ </div>
+ </form>
+</ste:block>