/** * TuiyoNotify::_() * * @param mixed $userIdTo * @param mixed $title * @param mixed $actionLink * @param mixed $actionTitle * @param string $application * @param mixed $template * @param mixed $templateVars * @return void */ public function _($userIdTo, $title, $actionLink, $actionTitle, $application = 'system', $template = NULL, $templateVars = NULL) { global $mainframe; TuiyoLoader::helper("parameter"); //1. Check App can send Mail //2. Load the user message is being sent to $document = TuiyoApi::get("document"); $userFrom = TuiyoApi::get("user", null); $user = TuiyoApi::get("user", (int) $userIdTo); $notifyTable = TuiyoLoader::table("notifications", true); $notifyParams = TuiyoParameter::load("emails"); if ($userIdTo < 1) { $document->enqueMessage(_("Could not notify the user due to a UserID({$userIdTo}) error"), "error"); return false; } //3. Add Notification Title to database; $notifyTable->title = $title; $notifyTable->userid = $userIdTo; $notifyTable->link = $actionLink; $notifyTable->linktitle = $actionTitle; $notifyTable->application = $application; $notifyTable->status = 0; $notifyTable->type = $template; $notifyTable->template = json_encode($templateVars); if (!$notifyTable->store()) { $document->enqueMessage(sprintf(_("Could not notify the user due to the following error: %s"), $notifyTable->getError()), "error"); return false; } if (!empty($template)) { $eTitle = $notifyParams->get($template . "Title"); $eBody = $notifyParams->get($template . "Body"); $subject = html_entity_decode($eTitle, ENT_QUOTES); $message = html_entity_decode($eBody, ENT_QUOTES); TuiyoNotify::sendMail($user->joomla->get('email'), $subject, $message); } }
/** * TuiyoModelTimeline::setStatusComment() * @param mixed $userID * @param mixed $postData * @param mixed $options * @return void */ public function setStatusComment($userID, $postData, $options = array()) { $commenter = TuiyoApi::get("user", null); $table = TuiyoLoader::table("timeline"); $table->load(null); //print_R($postData); $statusText = strval($postData['commentbody']); //get out all mentions in the update string preg_match_all('#@([\\d\\w]+)#', $statusText, $mentions); preg_match_all('/#([\\d\\w]+)/', $statusText, $hashTags); $table->tags = sizeof($hashTags[1]) > 0 ? json_encode($hashTags[1]) : null; $table->mentions = sizeof($mentions[1]) > 0 ? json_encode($mentions[1]) : null; $table->userID = (int) $userID; $table->template = null; $table->datetime = date('Y-m-d H:i:s'); $table->data = $statusText; $table->type = "comment"; $table->source = isset($postData['source']) ? $postData['source'] : "web"; $table->source = strval($table->source); $table->inreplyto = isset($postData['inreplyto']) ? (int) $postData['inreplyto'] : JError::raiseError(403, _("Invalid activity ID")); if (!$table->store()) { trigger_error($table->getError(), E_USER_ERROR); return false; } //Send Notifications to All users participating in this discussion TuiyoLoader::library("mail.notify"); $getParticipants = $table->getAllCommenters($table->inreplyto); $firstAuthors = array(); //Notify Authors foreach ($getParticipants["author"] as $author) { $firstAuthors[] = $author; if ($userID != $author) { $userTo = TuiyoAPI::get("user", $author); $actionLink = JRoute::_(TUIYO_INDEX . "&view=profile&do=viewStatus&user={$userTo->username}&id={$table->inreplyto}"); $emailTitle = sprintf(_("%s commented on your wall post"), "@" . $commenter->username); $emailBody = ""; //str_replace( $tSearch , $tVars , $notifyParams->get( "connectionRequestEmailBody" , null ) ); //echo $notifyEmail ; TuiyoNotify::_($userTo->id, $emailTitle, $actionLink, _("View Status")); TuiyoNotify::sendMail($userTo->email, $emailTitle, $emailBody); } } //Notify Participants foreach ($getParticipants["participant"] as $tookpart) { if ($userID != $tookpart) { $firstauthor = TuiyoAPI::get("user", (int) $firstAuthors[0]); $userTo = TuiyoAPI::get("user", $tookpart); $actionLink = JRoute::_(TUIYO_INDEX . "&view=profile&do=viewStatus&user={$firstauthor->username}&id={$table->inreplyto}"); $emailTitle = sprintf(_("%s commented on %2s wall post"), "@" . $commenter->username, "@" . $firstauthor->username); $emailBody = ""; //str_replace( $tSearch , $tVars , $notifyParams->get( "connectionRequestEmailBody" , null ) ); //echo $notifyEmail ; TuiyoNotify::_($userTo->id, $emailTitle, $actionLink, _("View Status")); TuiyoNotify::sendMail($userTo->email, $emailTitle, $emailBody); } } return $table; }
/** * TuiyoModelFriends::addInvite() * Generates an Invite * @param mixed $inviter * @param mixed $invitee * @return */ public function addInvite($inviter, $invitee, $message = NULL) { $iTable = TuiyoLoader::table("invites", TRUE); $iNotify = TuiyoLoader::library("mail.notify", true); if (empty($invitee->email) || !isset($invitee->email) || $iTable->hasExistingAccount($invitee->email)) { return false; } $iTable->load(NULL); $iData = array("userid" => $inviter->id, "email" => $invitee->email, "state" => 0, "name" => !empty($invitee->name) ? $invitee->name : $invitee->email, "code" => $iTable->generateCode()); if (!$iTable->bind($iData)) { JError::raiseError(TUIYO_SERVER_ERROR, $iTable->getError()); return false; } //We can Now save the table if (!$iTable->store($iData)) { return false; } //Send and Email to the user with the activation code; TuiyoLoader::helper("parameter"); TuiyoLoader::library("mail.notify"); $notifyParams = TuiyoParameter::load("emails"); $tVars = array($invitee->name, JURI::base(), $inviter->username, $message); $tSearch = array("[name]", "[link]", "[username]", "[message]"); $emailTitle = str_replace($tSearch, $tVars, $notifyParams->get("inviteEmailTitle", null)); $emailBody = str_replace($tSearch, $tVars, $notifyParams->get("inviteEmailBody", null)); //echo $notifyEmail ; TuiyoNotify::sendMail($invitee->email, $emailTitle, $emailBody); return true; }
/** * TuiyoModelMessages::addMessage() * Adds a message to the user table; * @param mixed $userID * @param mixed $postData * @param integer $status * @return boolean true if successful */ public function addMessage($thisUserID, $post, $status = 0) { $pmsTable = TuiyoLoader::table('messages', true); $uTable = TuiyoLoader::table('users', true); $document = TuiyoAPI::get('document'); //1. Get Users ID $recipients = $post["sendTo"]; $subject = strip_tags(trim($post["messageSubject"])); $message = strip_tags(trim($post["newMessageText"])); $datetime = date('Y-m-d H:i:s'); $status = !empty($status) ? (int) $status : 0; //NO Empty Messages $message = !empty($message) ? $message : "{tuiyo:undefined-messages}"; //Get the recipients //$recipients = explode( "," , $sendTo ); $count = sizeof($recipients); $failed = array(); //print_R($recipients); //die; //2. Send the Message to Every User foreach ($recipients as $i => $thatUserID) { $thatUserID = (int) $thatUserID; $mTable = clone $pmsTable; //Get the UserID from the userTable //$thatUserID = $uTable->getUserID( trim( (string)$recipient ) ); //Check we have a valid ID and no empty message; if (empty($thatUserID) || (int) $thatUserID < 1 || !$uTable->userProfileExists((int) $thisUserID)) { $failed[] = $thatUserID; $document->enqueMessage(sprintf(_("Invalid user with ID: %s"), $thatUserID), "error"); continue; //return false; } $mTable->load(null); $mTable->user_id_from = (int) $thisUserID; $mTable->user_id_to = (int) $thatUserID; $mTable->subject = !empty($subject) ? $subject : "{tuiyo:undefined-subject}"; $mTable->date_time = $datetime; $mTable->message = $message; $mTable->state = $status; $mTable->folder_id = 10; //die; if (!$mTable->store()) { //Oops something bad happened JError::raiseError(TUIYO_SERVER_ERROR, $table->getError()); return false; } //destroy $mTable if ((int) $mTable->user_id_to === (int) $mTable->user_id_from) { $document->enqueMessage(_("Messages to self do not show in inbox but in sent folder"), "notice"); } //Notify Recepient TuiyoLoader::library("mail.notify"); if ((int) $mTable->user_id_to > 0 && (int) $mTable->user_id_to != $mTable->user_id_from) { $userTo = TuiyoAPI::get("user", $mTable->user_id_to); $userFrom = TuiyoAPI::get("user", $mTable->user_id_from); $actionLink = JRoute::_(TUIYO_INDEX . "&view=messages"); $emailTitle = sprintf(_("%s sent you a new private message"), "@" . $userFrom->username); $emailBody = ""; //str_replace( $tSearch , $tVars , $notifyParams->get( "connectionRequestEmailBody" , null ) ); //echo $notifyEmail ; TuiyoNotify::_($userTo->id, $emailTitle, $actionLink, _("View Messages")); } $mTable->message_id = null; unset($mTable); } //Retur true return true; }