/** * TuiyoLoader::library() * * @param mixed $libraryDotPath * @param mixed $parameters * @return */ public function library($libraryDotPath, $parameters = null) { /** * Load the files */ TuiyoLoader::import($libraryDotPath, 'library'); //check is loaded if (!array_key_exists($libraryDotPath, self::$_loaded)) { JError::raiseError(TUIYO_NOT_FOUND, "Request Library Class Not Found"); } $library = ucfirst(TUIYO_LIB) . ucfirst(self::$_loaded[$libraryDotPath]); if (in_array($library, self::$_stored["libraries"])) { $object = self::$_stored["libraries"][$library]; if (is_object($object)) { return $object; } else { unset(self::$_stored["libraries"][$library]); TuiyoLoader::library($libraryDotPath, $parameters); } } //instanciate the class $instance =& call_user_func(array($library, 'getInstance'), $parameters); if (!is_object($instance)) { die; JError::raiseError(TUIYO_NOT_ACCEPTABLE, "Libary Class is not an object"); //$libary is not an object } self::$_stored["libraries"][$library] =& $instance; return $instance; }
/** * 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; }
/** * TuiyoAPI::import() * @param mixed $classScope * @return void */ public function get($classScope, $parameters = null, $instance = true) { if ($instance) { if (in_array($classScope, self::$_instances)) { return self::$_instances[$classScope]; } } //create a new one! $classScope = strtolower($classScope); $classDotScope = array_key_exists($classScope, self::$_apiMap) ? self::$_apiMap[$classScope] : $classScope; //import $APIClass = TuiyoLoader::library($classDotScope, $parameters); //return the object if (is_object($APIClass)) { self::$_instances[$classScope] = $APIClass; return $APIClass; } }