static function item_before_delete($item) { notification::send_item_deleted($item); if (notification::is_watching($item)) { notification::remove_watch($item); } }
static function album($menu, $theme) { if (!user::active()->guest) { $item = $theme->item(); if ($item) { $watching = notification::is_watching($item); $menu->append(Menu::factory("link")->id("watch")->label(t("Enable notifications for this album"))->url(url::site("notification/watch/{$item->id}?csrf=" . access::csrf_token()))->css_id($watching ? "gRemoveWatchLink" : "gAddWatchLink")); } } }
static function site_menu($menu, $theme) { if (!user::active()->guest) { $item = $theme->item(); if ($item && $item->is_album() && access::can("view", $item)) { $watching = notification::is_watching($item); $label = $watching ? t("Remove notifications") : t("Enable notifications"); $menu->get("options_menu")->append(Menu::factory("link")->id("watch")->label($label)->css_id("gNotifyLink")->url(url::site("notification/watch/{$item->id}?csrf=" . access::csrf_token()))); } } }
function watch($id) { access::verify_csrf(); $item = ORM::factory("item", $id); access::required("view", $item); if (notification::is_watching($item)) { notification::remove_watch($item); message::success(sprintf(t("You are no longer watching %s"), $item->title)); } else { notification::add_watch($item); message::success(sprintf(t("You are now watching %s"), $item->title)); } url::redirect($item->url(array(), true)); }
function watch($id) { access::verify_csrf(); $item = ORM::factory("item", $id); access::required("view", $item); $watching = notification::is_watching($item); if (!$watching) { notification::add_watch($item); message::success(sprintf(t("Watch Enabled on %s!"), $item->title)); } else { notification::remove_watch($item); message::success(sprintf(t("Watch Removed on %s!"), $item->title)); } url::redirect($item->url()); }
public static function send_notifications($recipient_id, $item_id, $mailtype) { //Load the item $item = ORM::factory("item")->where("id", "=", $item_id)->find(); if (!$item->loaded()) { return false; } //Load the user $recipient = ORM::factory("user")->where("id", "=", $recipient_id)->find(); if (!$recipient->loaded()) { return false; } //Only send mail if the notifications are switched on globally if (!module::get_var("photoannotation", "nonotifications", false)) { //Check if the use has a valid e-mail if (!valid::email($recipient->email)) { return false; } //Get the users settings $notification_settings = self::get_user_notification_settings($recipient); //Check which type of mail to send switch ($mailtype) { case "newtag": //Only send if user has this option enabled if ($notification_settings->newtag) { //Get subject and body and send the mail $subject = module::get_var("photoannotation", "newtagsubject", "Someone tagged a photo of you"); $body = module::get_var("photoannotation", "newtagbody", "Hello %name, please visit %url to view the photo."); $body = str_ireplace(array("%url", "%name"), array($item->abs_url(), $recipient->display_name()), $body); return self::_send_mail($recipient->email, $subject, $body); } break; case "newcomment": //Only send if user has this option enabled if ($notification_settings->comment) { //Don't send if the notification module is active and the user is watching this item if (module::is_active("notification")) { if (notification::is_watching($item, $recipient)) { return false; } } //Get subject and body and send the mail $subject = module::get_var("photoannotation", "newcommentsubject", "Someone added a comment to photo of you"); $body = module::get_var("photoannotation", "newcommentbody", "Hello %name, please visit %url to read the comment."); $body = str_ireplace(array("%url", "%name"), array($item->abs_url(), $recipient->display_name()), $body); return self::_send_mail($recipient->email, $subject, $body); } break; case "updatecomment": //Only send if user has this option enabled if ($notification_settings->comment) { //Don't send if the notification module is active and the user is watching this item if (module::is_active("notification")) { if (notification::is_watching($item, $recipient)) { return false; } } //Get subject and body and send the mail $subject = module::get_var("photoannotation", "updatedcommentsubject", "Someone updated a comment to photo of you"); $body = module::get_var("photoannotation", "updatedcommentbody", "Hello %name, please visit %url to read the comment."); $body = str_ireplace(array("%url", "%name"), array($item->abs_url(), $recipient->display_name()), $body); return self::_send_mail($recipient->email, $subject, $body); } } } return false; }