function __construct() { $guid = getInput("guid"); $reply = getInput("reply"); if (!$reply) { new SystemMessage("Message body cannot be left empty."); forward(); } $message = getEntity($guid); $to = getLoggedInUserGuid() == $message->to ? $message->from : $message->to; $from = getLoggedInUserGuid(); $to_user = getEntity($to); $from_user = getEntity($from); $message_element = new Messageelement(); $message_element->message = $reply; $message_element->to = $to; $message_element->from = $from; $message_element->container_guid = $guid; $message_element->save(); $link = getSiteURL() . "messages"; notifyUser("message", $to, getLoggedInUserGuid(), $to); sendEmail(array("to" => array("name" => $to_user->full_name, "email" => $to_user->email), "from" => array("name" => getSiteName(), "email" => getSiteEmail()), "subject" => "You have a new message from " . getLoggedInUser()->full_name, "body" => "You have received a new message from " . getLoggedInUser()->full_name . "<br/><a href='{$link}'>Click here to view it.</a>", "html" => true)); new SystemMessage("Your message has been sent."); forward("messages/" . $message->guid); }
function __construct() { gateKeeper(); $to = getInput("to"); $from = getLoggedInUserGuid(); $subject = getInput("subject"); $message_body = getInput("message"); if (!$message_body) { new SystemMessage("Message body cannot be left blank."); forward(); } // Make sure recipient is a user $to_user = getEntity($to); classGateKeeper($to_user, "User"); // Make sure logged in user and to user are friends if (!FriendsPlugin::friends(getLoggedInUserGuid(), $to)) { forward(); } // Create a new message $message = new Message(); $message->to = $to; $message->from = $from; $message->subject = $subject; $message->save(); $message_element = new Messageelement(); $message_element->to = $to; $message_element->from = $from; $message_element->subject = $subject; $message_element->message = $message_body; $message_element->container_guid = $message->guid; $message_element->save(); $link = getSiteURL() . "messages"; $notify = $to_user->notify_when_message; if (!$notify) { $notify = "both"; } if ($notify == "both" || $notify == "site") { notifyUser("message", $to, $from, $to); } if ($notify == "both" || ($notify = "email")) { sendEmail(array("to" => array("name" => $to_user->full_name, "email" => $to_user->email), "from" => array("name" => getSiteName(), "email" => getSiteEmail()), "subject" => "You have a new message from " . getLoggedInUser()->full_name, "body" => "You have received a new message from " . getLoggedInUser()->full_name . "<br/><a href='{$link}'>Click here to view it.</a>", "html" => true)); } new SystemMessage("Your message has been sent."); forward(); }
function reply($params) { $guid = $params['message_guid']; $reply = $params['reply']; $message = getEntity($guid); $to = $params['to']; $from = $params['from']; $to = $from == $message->from ? $message->to : $message->from; $to_user = getEntity($to); $from_user = getEntity($from); $message_element = new Messageelement(); $message_element->message = $reply; $message_element->to = $to; $message_element->from = $from; $message_element->container_guid = $guid; $message_element->save(); $link = getSiteURL() . "messages"; notifyUser("message", $to, getLoggedInUserGuid(), $to); sendEmail(array("to" => array("name" => $to_user->full_name, "email" => $to_user->email), "from" => array("name" => getSiteName(), "email" => getSiteEmail()), "subject" => "You have a new message from " . getLoggedInUser()->full_name, "body" => "You have received a new message from " . getLoggedInUser()->full_name . "<br/><a href='{$link}'>Click here to view it.</a>", "html" => true)); return "success"; }