summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-02-02 15:41:47 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-02-02 15:41:47 +0000
commitef58ac91e8c23832e657a4f8dee57fe0b7733ae8 (patch)
tree4c5979f253d66cba03731261d04cf5a0621b7816
parent89edd4d3ff307d79b82a3eb196b6bdad5be26804 (diff)
Notifications now send emails when a comment is published. It won't
send the email if the comment status is not published. This gives the administrator to moderate the comments prior to being published.
-rw-r--r--modules/notification/helpers/notification.php26
-rw-r--r--modules/notification/helpers/notification_event.php8
-rw-r--r--modules/notification/views/comment_added.html.php1
-rw-r--r--modules/notification/views/comment_changed.html.php1
-rw-r--r--modules/notification/views/comment_published.html.php19
5 files changed, 39 insertions, 16 deletions
diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php
index 5f46a58d..1b5b1b8f 100644
--- a/modules/notification/helpers/notification.php
+++ b/modules/notification/helpers/notification.php
@@ -119,20 +119,22 @@ class notification {
self::_send_message($item, $body);
}
- static function send_comment_added($comment) {
- $body = new View("comment_added.html");
- $body->subject = sprintf(t("Comment added to %s"), $comment->item()->title);
-
- self::_send_message($comment->item(), $body);
- }
-
- static function send_comment_changed($old, $new) {
- $body = new View("comment_changed.html");
- $body->subject = sprintf(t("Comment changed on %s"), $old->item()->title);
+ static function send_comment_published($comment) {
+ $item = $comment->item();
+ $body = new View("comment_published.html");
+ $body->subject = sprintf(t("A new comment for %s was published"), $item->title);
+ $body->text = $comment->text;
+ if (!empty($comment->author_id)) {
+ $author = ORM::factory("user", $comment->author_id);
+ $body->author = empty($author->full_name) ? $author->name : $author->full_name;
+ } else {
+ $body->author = $comment->guest_name;
+ }
+ $body->url = url::site("albums/$item->id#comments", "http");
- self::_send_message($old->item(), $body);
+ self::_send_message($item, $body);
}
-
+
private static function _send_message($item, $body) {
$users = self::get_subscribers($item);
if (!empty($users)) {
diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php
index e7c7aac1..6336733a 100644
--- a/modules/notification/helpers/notification_event.php
+++ b/modules/notification/helpers/notification_event.php
@@ -35,10 +35,14 @@ class notification_event_Core {
}
static function comment_created($comment) {
- notification::send_comment_added($comment);
+ if ($comment->state == "published") {
+ notification::send_comment_published($comment);
+ }
}
static function comment_updated($old, $new) {
- notification::send_comment_changed($old, $new);
+ if ($new->state == "published" && $old->state != "published") {
+ notification::send_comment_published($new);
+ }
}
}
diff --git a/modules/notification/views/comment_added.html.php b/modules/notification/views/comment_added.html.php
deleted file mode 100644
index 115bfc86..00000000
--- a/modules/notification/views/comment_added.html.php
+++ /dev/null
@@ -1 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.") ?>
diff --git a/modules/notification/views/comment_changed.html.php b/modules/notification/views/comment_changed.html.php
deleted file mode 100644
index 115bfc86..00000000
--- a/modules/notification/views/comment_changed.html.php
+++ /dev/null
@@ -1 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.") ?>
diff --git a/modules/notification/views/comment_published.html.php b/modules/notification/views/comment_published.html.php
new file mode 100644
index 00000000..4a7936e6
--- /dev/null
+++ b/modules/notification/views/comment_published.html.php
@@ -0,0 +1,19 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<html>
+<head>
+ <title><?= $subject ?> </title>
+</head>
+<body>
+ <h2><?= sprintf(t("A new comment was added by %s"), $author); ?></h2>
+ <table>
+ <tr>
+ <td><?= t("Comment:") ?></td>
+ <td><?= $text ?></td>
+ </tr>
+ <tr>
+ <td><?= t("Url:") ?></td>
+ <td><a href="<?= $url ?>"><?= $url ?></a></td>
+ </tr>
+ </table>
+</body>
+</html>