/** * TuiyoModelFriends::addFriend() * Adds a user as friend; * @param mixed $profileID * @param mixed $userID * @return */ public function addFriend($profileID, $userID = NULL) { $tble = TuiyoLoader::table("friends"); //Send and Email to the user with the activation code; TuiyoLoader::helper("parameter"); TuiyoLoader::library("mail.notify"); $notifyParams = TuiyoParameter::load("emails"); //user1 and user2 $user1 = !empty($userID) ? (int) $userID : TuiyoAPI::get("user")->id; $user2 = !empty($profileID) ? (int) $profileID : JError::raiseError(500, _('Invalid Profile ID')); //Verify that friend does not already exists! if (($rel = $this->isFriendOf($user1, $user2)) !== FALSE) { if ((int) $rel->thisUserID != (int) $user1 && (int) $rel->state < 1) { $rel->state = (int) $rel->state + 1; $rel->lastUpdated = date('Y-m-d H:i:s'); $rel->user1 = (int) $rel->thisUserID < (int) $rel->thatUserID ? (int) $rel->thisUserID : $rel->thatUserID; $rel->user2 = (int) $rel->thisUserID > (int) $rel->thatUserID ? (int) $rel->thisUserID : $rel->thatUserID; $relProfileLink = TUIYO_INDEX . '&view=profile&pid=' . $rel->user1; $relUser1Object = TuiyoAPI::get("user", (int) $rel->user1); $relUser2Object = TuiyoAPI::get("user", (int) $rel->user2); if (!$rel->store()) { JError::raiseError(500, $rel->getErrorMsg()); return false; } //echo $notifyEmail ; TuiyoNotify::_($rel->user2, sprintf(_("%s confirmed you as friend"), "@" . $relUser1Object->username), $relProfileLink, _("View profile")); //4b. Publish Activity Story; $uActivity = TuiyoAPI::get("activity", null); $uStoryLine = sprintf(_('%1s is now friends with %2s'), "@" . $relUser1Object->username, "@" . $relUser2Object->username); $uActivity->publishOneLineStory($relUser1Object, $uStoryLine, "friends"); $uStoryLine2 = sprintf(_('%1s is now friends with %2s'), "@" . $relUser2Object->username, "@" . $relUser1Object->username); $uActivity->publishOneLineStory($relUser2Object, $uStoryLine2, "friends"); return $rel->state; } return false; } else { $tble->load(null); $tble->type = "friends"; $tble->thisUserID = (int) $user1; $tble->thatUserID = (int) $user2; $tble->user1 = (int) $user1 < (int) $user2 ? (int) $user1 : $user2; $tble->user2 = (int) $user1 > (int) $user2 ? (int) $user1 : $user2; $tble->state = (int) 0; $tble->listID = 0; if (!$tble->store()) { JError::raiseError(500, $tble->getErrorMsg()); return $tble->state; } $relUser1Object = TuiyoAPI::get("user", (int) $tble->user1); $relUser2Object = TuiyoAPI::get("user", (int) $tble->user2); $relProfileLink = TUIYO_INDEX . '&view=profile&pid=' . $tble->user1; $tVars = array($relUser2Object->name, JURI::base(), $relUser1Object->name, ""); $tSearch = array("[thisuser]", "[link]", "[thatuser]", "[message]"); $emailTitle = str_replace($tSearch, $tVars, $notifyParams->get("connectionRequestEmailTitle", null)); $emailBody = str_replace($tSearch, $tVars, $notifyParams->get("connectionRequestEmailBody", null)); //echo $notifyEmail ; TuiyoNotify::_($tble->user1, sprintf(_("%s has requested to add you as friend"), "@" . $relUser2Object->username), $relProfileLink, _("View profile")); TuiyoNotify::sendMail($relUser1Object->email, $emailTitle, $emailBody); return $tble->state; } //We should not get to this point return false; }
/** * 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; }
/** * 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; }