1
0

Version 4 beta 2: Added admin option to customize the notification mails sent to users, bugfixes, code cleanup

This commit is contained in:
hukoeth 2010-09-06 17:16:22 +02:00 committed by Bharat Mediratta
parent 55d9bc4986
commit dfe754d373
5 changed files with 235 additions and 233 deletions

View File

@ -50,33 +50,7 @@ class Admin_Photoannotation_Controller extends Admin_Controller {
$tag_annotations = ORM::factory("items_face")->where("tag_id", "=", $sourcetag->id)->find_all();
foreach ($tag_annotations as $tag_annotation) {
//Check if there are already user annotations of the target user on photo
$user_annotations = ORM::factory("items_user")
->where("item_id", "=", $tag_annotation->item_id)
->where("user_id", "=", $targetuser->id)
->find_all();
if (count($user_annotations) > 1) {
//If there are more than one existing annotations, delete all and create a new one
foreach ($user_annotations as $user_annotation) {
$user_annotation->delete();
}
$target_annotation = ORM::factory("items_user");
} elseif (count($user_annotations) == 1) {
//If there is only one existing annotation, load it and update it
$target_annotation = ORM::factory("items_user", $user_annotations[0]->id);
} else {
//If there are no existing annotations create one
$target_annotation = ORM::factory("items_user");
}
//Save values from tag annotation to user annotation and save it
$target_annotation->user_id = $targetuser->id;
$target_annotation->item_id = $tag_annotation->item_id;
$target_annotation->x1 = $tag_annotation->x1;
$target_annotation->y1 = $tag_annotation->y1;
$target_annotation->x2 = $tag_annotation->x2;
$target_annotation->y2 = $tag_annotation->y2;
$target_annotation->description = $tag_annotation->description;
$target_annotation->save();
photoannotation::saveuser($targetuser->id, $tag_annotation->item_id, $tag_annotation->x1, $tag_annotation->y1, $tag_annotation->x2, $tag_annotation->y2, $tag_annotation->description);
//Delete the old annotation
$tag_annotation->delete();
}
@ -115,6 +89,18 @@ class Admin_Photoannotation_Controller extends Admin_Controller {
"photoannotation", "nonotifications", $form->notifications->nonotifications->value, true);
module::set_var(
"photoannotation", "notificationoptout", $form->notifications->notificationoptout->value, true);
module::set_var(
"photoannotation", "newtagsubject", $form->newtagmail->newtagsubject->value);
module::set_var(
"photoannotation", "newtagbody", $form->newtagmail->newtagbody->value);
module::set_var(
"photoannotation", "newcommentsubject", $form->newcommentmail->newcommentsubject->value);
module::set_var(
"photoannotation", "newcommentbody", $form->newcommentmail->newcommentbody->value);
module::set_var(
"photoannotation", "updatedcommentsubject", $form->updatedcommentmail->updatedcommentsubject->value);
module::set_var(
"photoannotation", "updatedcommentbody", $form->updatedcommentmail->updatedcommentbody->value);
module::set_var(
"photoannotation", "onuserdelete", $form->onuserdelete->onuserdelete->value);
message::success(t("Your settings have been saved."));
@ -240,6 +226,11 @@ class Admin_Photoannotation_Controller extends Admin_Controller {
}
private function _get_form() {
if (module::is_active("comment")) {
$comment_required = "";
} else {
$comment_required = " (comment module required)";
}
$form = new Forge("admin/photoannotation/handler", "", "post", array("id" => "g-admin-form"));
$group = $form->group("hoverphoto")->label(t("Hovering over the photo"));
$group->checkbox("noborder")->label(t("Don't show borders."))
@ -273,6 +264,21 @@ class Admin_Photoannotation_Controller extends Admin_Controller {
->checked(module::get_var("photoannotation", "nonotifications", false));
$group->checkbox("notificationoptout")->label(t("Notify users by default (only applies to new users and user who have not saved their profile after installing this module)."))
->checked(module::get_var("photoannotation", "notificationoptout", false));
$group = $form->group("newtagmail")->label(t("Customize the mail sent to users when a user annotation is created"));
$group->input("newtagsubject")->label(t("Subject"))
->value(module::get_var("photoannotation", "newtagsubject", "Someone tagged a photo of you"));
$group->textarea("newtagbody")->label(t("Body (allowed placeholders: %name = name of the recipient, %url = link to the item that was tagged)"))
->value(module::get_var("photoannotation", "newtagbody", "Hello %name, please visit %url to view the photo."));
$group = $form->group("newcommentmail")->label(t("Customize the mail sent to users when a comment is added". $comment_required));
$group->input("newcommentsubject")->label(t("Subject"))
->value(module::get_var("photoannotation", "newcommentsubject", "Someone added a comment to photo of you"));
$group->textarea("newcommentbody")->label(t("Body (allowed placeholders: %name = name of the recipient, %url = link to the item that was commented on)"))
->value(module::get_var("photoannotation", "newcommentbody", "Hello %name, please visit %url to read the comment."));
$group = $form->group("updatedcommentmail")->label(t("Customize the mail sent to users when a comment is updated". $comment_required));
$group->input("updatedcommentsubject")->label(t("Subject"))
->value(module::get_var("photoannotation", "updatedcommentsubject", "Someone updated a comment to photo of you"));
$group->textarea("updatedcommentbody")->label(t("Body (allowed placeholders: %name = name of the recipient, %url = link to the item that was commented on)"))
->value(module::get_var("photoannotation", "updatedcommentbody", "Hello %name, please visit %url to read the comment."));
$group = $form->group("onuserdelete")->label(t("Auto conversion settings"));
$group->dropdown("onuserdelete")->label(t("When deleting a user do the following with all annotations associated with this user"))
->options(array("0" => t("Delete annotation"), "1" => t("Convert to tag annotation"), "2" => t("Convert to note annotation")))

View File

@ -51,11 +51,11 @@ class photoannotation_Controller extends Controller {
//Save annotation
if ($annotate_id == "new") { //This is a new annotation
if ($user_id > -1) { //Save user
$this->_saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
} elseif ($tag_data > -1) { //Conversion user -> face
$this->_saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
} elseif ($item_title != "") { //Conversion user -> note
$this->_savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
} else { //Somethings wrong
message::error(t("Please select a User or Tag or specify a Title."));
url::redirect($redir_uri);
@ -68,12 +68,12 @@ class photoannotation_Controller extends Controller {
->where("id", "=", $annotate_id)
->find();
if ($user_id > -1) { //Conversion user -> user
$this->_saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
} elseif ($tag_data > -1) { //Conversion user -> face
$this->_saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$updateduser->delete(); //delete old user
} elseif ($item_title != "") { //Conversion user -> note
$this->_savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$updateduser->delete(); //delete old user
} else { //Somethings wrong
message::error(t("Please select a User or Tag or specify a Title."));
@ -86,12 +86,12 @@ class photoannotation_Controller extends Controller {
->where("id", "=", $annotate_id)
->find();
if ($user_id > -1) { //Conversion face -> user
$this->_saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$updatedface->delete(); //delete old face
} elseif ($tag_data > -1) { //Conversion face -> face
$this->_saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id);
photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id);
} elseif ($item_title != "") { //Conversion face -> note
$this->_savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$updatedface->delete(); //delete old face
} else { //Somethings wrong
message::error(t("Please select a User or Tag or specify a Title."));
@ -104,13 +104,13 @@ class photoannotation_Controller extends Controller {
->where("id", "=", $annotate_id)
->find();
if ($user_id > -1) { //Conversion note -> user
$this->_saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
photoannotation::saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$updatednote->delete(); //delete old note
} elseif ($tag_data > -1) { //Conversion note -> face
$this->_saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
photoannotation::saveface($tag_data, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description);
$updatednote->delete(); //delete old note
} elseif ($item_title != "") { //Conversion note -> note
$this->_savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id);
photoannotation::savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id);
} else { //Somethings wrong
message::error(t("Please select a User or Tag or specify a Title."));
url::redirect($redir_uri);
@ -161,106 +161,4 @@ class photoannotation_Controller extends Controller {
message::success(t("Annotation deleted."));
url::redirect($redir_uri);
}
private function _saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description) {
//Since we are associating a user we will remove any old annotation of this user on this photo
$item_old_users = ORM::factory("items_user")
->where("user_id", "=", $user_id)
->where("item_id", "=", $item_id)
->find_all();
if (count($item_old_users) > 1) {
foreach ($item_old_users as $item_old_user) {
$item_old_user->delete();
}
$item_user = ORM::factory("items_user");
} elseif (count($item_old_users) == 1) {
$item_user = ORM::factory("items_user", $item_old_users[0]->id);
} else {
$item_user = ORM::factory("items_user");
if (!module::get_var("photoannotation", "nonotifications", false)) {
$notification_settings = ORM::factory("photoannotation_notification")->where("user_id", "=", $user_id)->find();
if (!$notification_settings->loaded()) {
$notify = module::get_var("photoannotation", "notificationoptout", false);
$notification_settings = ORM::factory("photoannotation_notification");
$notification_settings->user_id = $user_id;
$notification_settings->newtag = $notify;
$notification_settings->comment = $notify;
$notification_settings->save();
}
if ($notification_settings->newtag) {
$user_recipient = ORM::factory("user")->where("id", "=", $user_id)->find();
if ($user_recipient->email != "") {
$recipient = $user_recipient->email;
$subject = t("Somebody has tagged a photo of you");
$item_notify = ORM::factory("item")->where("id", "=", $item_id)->find();
$body = t("Please visit <a href=\"%url\">the gallery</a> to view the photo.", array("url" => $item_notify->resize_url(true)));
Sendmail::factory()
->to($recipient)
->subject($subject)
->header("Mime-Version", "1.0")
->header("Content-type", "text/html; charset=utf-8")
->message($body)
->send();
}
}
}
}
$item_user->user_id = $user_id;
$item_user->item_id = $item_id;
$item_user->x1 = $str_x1;
$item_user->y1 = $str_y1;
$item_user->x2 = $str_x2;
$item_user->y2 = $str_y2;
$item_user->description = $description;
$item_user->save();
}
private function _saveface($tag_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id = "") {
if ($annotate_id == "") {
$item_face = ORM::factory("items_face");
} else {
$item_face = ORM::factory("items_face")
->where("id", "=", $annotate_id)
->find();
}
$item_face->tag_id = $tag_id;
$item_face->item_id = $item_id;
$item_face->x1 = $str_x1;
$item_face->y1 = $str_y1;
$item_face->x2 = $str_x2;
$item_face->y2 = $str_y2;
$item_face->description = $description;
$item_face->save();
}
private function _savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id = "") {
if ($annotate_id == "") {
$item_note = ORM::factory("items_note");
} else {
$item_note = ORM::factory("items_note")
->where("id", "=", $annotate_id)
->find();
}
$item_note->item_id = $item_id;
$item_note->x1 = $str_x1;
$item_note->y1 = $str_y1;
$item_note->x2 = $str_x2;
$item_note->y2 = $str_y2;
$item_note->title = $item_title;
$item_note->description = $description;
$item_note->save();
}
private function _send_tag_created($user_id, $item_id) {
$recipient = ORM::factory("user", $user_id);
if ($recipient->email) {
Sendmail::factory()
->to($recipient->email)
->subject($t("Someone has tagged a photo with you on it"))
->header("Mime-Version", "1.0")
->header("Content-Type", "text/html; charset=UTF-8")
->message($text)
->send();
}
}
}

View File

@ -0,0 +1,171 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class photoannotation_Core {
public static function saveuser($user_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description) {
//Since we are associating a user we will remove any old annotation of this user on this photo
$item_old_users = ORM::factory("items_user")
->where("user_id", "=", $user_id)
->where("item_id", "=", $item_id)
->find_all();
if (count($item_old_users) > 1) {
foreach ($item_old_users as $item_old_user) {
$item_old_user->delete();
}
$item_user = ORM::factory("items_user");
} elseif (count($item_old_users) == 1) {
$item_user = ORM::factory("items_user", $item_old_users[0]->id);
} else {
$item_user = ORM::factory("items_user");
photoannotation::send_notifications($user_id, $item_id, "newtag");
}
$item_user->user_id = $user_id;
$item_user->item_id = $item_id;
$item_user->x1 = $str_x1;
$item_user->y1 = $str_y1;
$item_user->x2 = $str_x2;
$item_user->y2 = $str_y2;
$item_user->description = $description;
$item_user->save();
}
public static function saveface($tag_id, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id = "") {
if ($annotate_id == "") {
$item_face = ORM::factory("items_face");
} else {
$item_face = ORM::factory("items_face")
->where("id", "=", $annotate_id)
->find();
}
$item_face->tag_id = $tag_id;
$item_face->item_id = $item_id;
$item_face->x1 = $str_x1;
$item_face->y1 = $str_y1;
$item_face->x2 = $str_x2;
$item_face->y2 = $str_y2;
$item_face->description = $description;
$item_face->save();
}
public static function savenote($item_title, $item_id, $str_x1, $str_y1, $str_x2, $str_y2, $description, $annotate_id = "") {
if ($annotate_id == "") {
$item_note = ORM::factory("items_note");
} else {
$item_note = ORM::factory("items_note")
->where("id", "=", $annotate_id)
->find();
}
$item_note->item_id = $item_id;
$item_note->x1 = $str_x1;
$item_note->y1 = $str_y1;
$item_note->x2 = $str_x2;
$item_note->y2 = $str_y2;
$item_note->title = $item_title;
$item_note->description = $description;
$item_note->save();
}
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)) {
//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) {
//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) {
//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;
}
private static function _send_mail($mailto, $subject, $message) {
//Send the notification mail
return Sendmail::factory()
->to($mailto)
->subject($subject)
->header("Mime-Version", "1.0")
->header("Content-type", "text/html; charset=utf-8")
->message($message)
->send();
}
public static function get_user_notification_settings($user) {
//Try loading the notification settings of user
$notification_settings = ORM::factory("photoannotation_notification")->where("user_id", "=", $user->id)->find();
if (!$notification_settings->loaded()) {
//If the user did not save his settings use the website default
$notify = module::get_var("photoannotation", "notificationoptout", false);
$notification_settings = ORM::factory("photoannotation_notification");
$notification_settings->user_id = $user->id;
$notification_settings->newtag = $notify;
$notification_settings->comment = $notify;
$notification_settings->save();
}
return $notification_settings;
}
public static function get_user_cloud() {
$users = ORM::factory("user")->order_by("name", "ASC")->find_all();
foreach ($users as $user) {
$items_users_count = ORM::factory("items_user")->where("user_id", "=", $user->id)->count_all();
if ($items_users_count > 0) {
$user_array[] = $user->display_name();
}
}
return $user_array;
}
}

View File

@ -108,30 +108,13 @@ class photoannotation_event_Core {
$tag->add($item);
$tag->count++;
$tag->save();
$new_items_tag = ORM::factory("items_face");
$new_items_tag->item_id = $existingFace->item_id;
$new_items_tag->tag_id = $tag->id;
$new_items_tag->x1 = $existingFace->x1;
$new_items_tag->y1 = $existingFace->y1;
$new_items_tag->x2 = $existingFace->x2;
$new_items_tag->y2 = $existingFace->y2;
$new_items_tag->description = $existingFace->description;
$new_items_tag->save();
photoannotation::saveface($tag->id, $existingFace->item_id, $existingFace->x1, $existingFace->y1, $existingFace->x2, $existingFace->y2, $existingFace->description);
}
break;
case "2":
//convert to note
foreach ($existingFaces as $existingFace) {
$item = ORM::factory("item")->where("id", "=", $existingFace->item_id)->find();
$new_items_tag = ORM::factory("items_note");
$new_items_tag->item_id = $existingFace->item_id;
$new_items_tag->title = $new_tag_name;
$new_items_tag->x1 = $existingFace->x1;
$new_items_tag->y1 = $existingFace->y1;
$new_items_tag->x2 = $existingFace->x2;
$new_items_tag->y2 = $existingFace->y2;
$new_items_tag->description = $existingFace->description;
$new_items_tag->save();
photoannotation::savenote($new_tag_name, $existingFace->item_id, $existingFace->x1, $existingFace->y1, $existingFace->x2, $existingFace->y2, $existingFace->description);
}
}
db::build()->delete("items_users")->where("user_id", "=", $old->id)->execute();
@ -212,15 +195,7 @@ class photoannotation_event_Core {
static function user_edit_form($user, $form) {
// Allow users to modify notification settings.
if (!module::get_var("photoannotation", "nonotifications", false)) {
$notification_settings = ORM::factory("photoannotation_notification")->where("user_id", "=", $user->id)->find();
if (!$notification_settings->loaded()) {
$notify = module::get_var("photoannotation", "notificationoptout", false);
$notification_settings = ORM::factory("photoannotation_notification");
$notification_settings->user_id = $user->id;
$notification_settings->newtag = $notify;
$notification_settings->comment = $notify;
$notification_settings->save();
}
$notification_settings = photoannotation::get_user_notification_settings($user);
$user_notification = $form->edit_user->group("edit_notification")->label("Tag notifications");
$user_notification->checkbox("photoannotation_newtag")->label(t("Notify me when a tag is added to a photo with me"))
->checked($notification_settings->newtag);
@ -234,6 +209,7 @@ class photoannotation_event_Core {
if (!module::get_var("photoannotation", "nonotifications", false)) {
$notification_settings = ORM::factory("photoannotation_notification")->where("user_id", "=", $user->id)->find();
if (!$notification_settings->loaded()) {
$notification_settings = ORM::factory("photoannotation_notification");
$notification_settings->user_id = $user->id;
}
$notification_settings->newtag = $form->edit_user->edit_notification->photoannotation_newtag->value;
@ -243,75 +219,21 @@ class photoannotation_event_Core {
}
static function comment_created($comment) {
//@todo: clean this up
$comment = ORM::factory("comment")->where("id", "=", "52")->find();
if (!module::get_var("photoannotation", "nonotifications", false)) {
$item_users = ORM::factory("items_user")->where("item_id", "=", $comment->item_id)->find_all();
if (count($item_users) > 0) {
foreach ($item_users as $item_user) {
$notification_settings = ORM::factory("photoannotation_notification")->where("user_id", "=", $item_user-user_id)->find();
if (!$notification_settings->loaded()) {
$notify = module::get_var("photoannotation", "notificationoptout", false);
$notification_settings = ORM::factory("photoannotation_notification");
$notification_settings->user_id = $item_user-user_id;
$notification_settings->newtag = $notify;
$notification_settings->comment = $notify;
$notification_settings->save();
}
if ($notification_settings->newtag) {
$user_recipient = ORM::factory("user")->where("id", "=", $item_user-user_id)->find();
if ($user_recipient->email != "") {
$recipient = $user_recipient->email;
$subject = t("Somebody has commented on a photo of you");
$item_notify = ORM::factory("item")->where("id", "=", $comment->item_id)->find();
$body = t("Please visit <a href=\"%url\">the gallery</a> to view the photo.", array("url" => $item_notify->resize_url(true)));
Sendmail::factory()
->to($recipient)
->subject($subject)
->header("Mime-Version", "1.0")
->header("Content-type", "text/html; charset=utf-8")
->message($body)
->send();
}
}
}
//Check if there are any user annotations on the photo and send notification if applicable
$item_users = ORM::factory("items_user")->where("item_id", "=", $comment->item_id)->find_all();
if (count($item_users) > 0) {
foreach ($item_users as $item_user) {
photoannotation::send_notifications($item_user->user_id, $comment->item_id, "newcomment");
}
}
}
static function comment_updated($comment) {
//@todo: clean this up
$comment = ORM::factory("comment")->where("id", "=", "52")->find();
if (!module::get_var("photoannotation", "nonotifications", false)) {
$item_users = ORM::factory("items_user")->where("item_id", "=", $comment->item_id)->find_all();
if (count($item_users) > 0) {
foreach ($item_users as $item_user) {
$notification_settings = ORM::factory("photoannotation_notification")->where("user_id", "=", $item_user-user_id)->find();
if (!$notification_settings->loaded()) {
$notify = module::get_var("photoannotation", "notificationoptout", false);
$notification_settings = ORM::factory("photoannotation_notification");
$notification_settings->user_id = $item_user-user_id;
$notification_settings->newtag = $notify;
$notification_settings->comment = $notify;
$notification_settings->save();
}
if ($notification_settings->newtag) {
$user_recipient = ORM::factory("user")->where("id", "=", $item_user-user_id)->find();
if ($user_recipient->email != "") {
$recipient = $user_recipient->email;
$subject = t("Somebody has updated a commented on a photo of you");
$item_notify = ORM::factory("item")->where("id", "=", $comment->item_id)->find();
$body = t("Please visit <a href=\"%url\">the gallery</a> to view the photo.", array("url" => $item_notify->resize_url(true)));
Sendmail::factory()
->to($recipient)
->subject($subject)
->header("Mime-Version", "1.0")
->header("Content-type", "text/html; charset=utf-8")
->message($body)
->send();
}
}
}
//Check if there are any user annotations on the photo and send notification if applicable
$item_users = ORM::factory("items_user")->where("item_id", "=", $comment->item_id)->find_all();
if (count($item_users) > 0) {
foreach ($item_users as $item_user) {
photoannotation::send_notifications($item_user->user_id, $comment->item_id, "updatecomment");
}
}
}

View File

@ -22,4 +22,9 @@
.bind('keyup', function(){
$(this).ColorPickerSetColor(this.value);
});
<? if (!module::is_active("comment")): ?>
$(document).ready(function(){
$("input[name='newcommentsubject'], input[name='updatedcommentsubject'], textarea[name='newcommentbody'], textarea[name='updatedcommentbody']").attr("disabled", true);
});
<? endif ?>
</script>