示例#1
0
 /**
  * TuiyoTableMessages::getMessageList()
  * Get All the messages in the Table 
  * and group according to state
  * @param mixed $userID
  * @param mixed $state
  * @return array
  */
 public function getMessageList($userID, array $state)
 {
     $dbo = $this->_db;
     $query = "SELECT m.*, f.name as user_from_name, f.username as user_from_username," . "t.name as user_to_name, t.username as user_to_username, '' as user_from_avatar" . "\nFROM #__messages m" . "\nRIGHT JOIN #__users as f ON m.user_id_from=f.id" . "\nRIGHT JOIN #__users as t ON m.user_id_to=t.id" . "\nWHERE m.user_id_to=" . $dbo->Quote((int) $userID) . "\nOR m.user_id_from=" . $dbo->Quote((int) $userID);
     $dbo->setQuery($query);
     $rows = $dbo->loadObjectList();
     $list = array("inbox" => array(), "sent" => array(), "drafts" => array(), "trash" => array());
     //Sort The messages;
     foreach ((array) $rows as $message) {
         //How many words--crude!!;
         $message->word_count = count(explode(" ", trim($message->message)));
         $message->date_time = TuiyoTimer::diff(strtotime($message->date_time));
         $message->user_to_avatar = TuiyoUser::getUserAvatar($message->user_id_to, "thumb35");
         $message->user_from_avatar = TuiyoUser::getUserAvatar($message->user_id_from, "thumb35");
         $folder = $this->getMessageFolderFromCode($message->folder_id, $message->user_id_from);
         $list[$folder][] = $message;
         //If we sent the messsage, add to sent;
         //if($message->user_id_to <> (int)$userID ):
         //				//Draft
         //				if($message->message_id < 1 ):
         //					$list["drafts"][] = $message;
         //					continue;
         //				endif;
         //				//Trash Sender
         //				if($message->foder_id >= 60 ):
         //					$list["trash"][] = $message;
         //					continue;
         //				endif;
         //				//Sent
         //				$list["sent"][] = $message;
         //				continue;
         //			else:
         //				//Trash Recipient
         //				$sFid = (string)$message->folder_id ;
         //				if(intval($sFid[strlen($sFid)-1]) === 6):
         //					$list["trash"][] = $message;
         //					continue;
         //				endif;
         //				//If we are recieving the message
         //
         //				$list["inbox"][] = $message;
         //				continue;
         //			endif;
     }
     //print_R( $rows );
     return $list;
 }
示例#2
0
 /**
  * TuiyoTableGroups::getGroupMembers()
  * Gets all Members from widthing a group
  * @param mixed $groupID
  * @param integer $limitstart
  * @param mixed $limit
  * @return void
  */
 private function getGroupMembers($groupID, $creatorID, $limitstart = 0, $limit = NULL)
 {
     $dbo = $this->_db;
     $dbo->setQuery("SELECT m.* FROM #__tuiyo_groups_members AS m " . "\nWHERE m.groupID =" . $dbo->quote((int) $groupID), $limitstart, $limit);
     $rows = $dbo->loadObjectList();
     $members = array();
     //user
     $user = JFactory::getUser(NULL);
     // );
     $this->isMember = 0;
     $this->creator = NULL;
     foreach ((array) $rows as $member) {
         $mUser = TuiyoAPI::get("user", $member->userID);
         $member->data = array("userID" => $mUser->id, "avatar" => TuiyoUser::getUserAvatar($mUser->id), "username" => $mUser->username, "name" => $mUser->name, "email" => $mUser->email);
         $member->isAdmin = $mUser->id != $creatorID ? 0 : 1;
         //Indicators
         if ($creatorID === $mUser->id) {
             $this->creator = $member->data;
         }
         if ($mUser->id === $user->id) {
             $this->isMember = 1;
             $this->gMemberID = $member->memberID;
         }
         $members[] = $member;
         unset($mUser);
     }
     return $members;
 }
示例#3
0
 public function addVote()
 {
     // Check for request forgeries
     JRequest::checkToken("request") or jexit('Invalid Token');
     $auth = TuiyoAPI::get('authentication');
     //Must be loggedIN
     $auth->requireAuthentication('post');
     $user = TuiyoAPI::get('user');
     $storyID = JRequest::getInt("sid", NULL, "post");
     $storyVT = JRequest::getInt("svt", 1, "post");
     //+1 for Like -1 for dislike
     $userID = $user->id;
     $model =& $this->getModel("timeline");
     $view =& $this->getView("profile", "json");
     if (empty($storyID) || empty($storyVT)) {
         JError::raiseError(TUIYO_SERVER_ERROR, 'Invalid story ID or story Vote Type');
         return false;
     }
     if (!$model->storeVote($userID, $storyID, $storyVT)) {
         JError::raiseError(TUIYO_SERVER_ERROR, 'Could not save the vote');
         return false;
     }
     //After Add Timeline Vote
     $GLOBALS["events"]->trigger("onAddTimelineVote", $this);
     return $view->encode(array("code" => TUIYO_OK, "userID" => $user->id, "userPic" => TuiyoUser::getUserAvatar($user->id, "thumb35")));
 }
示例#4
0
 /**
  * TuiyoModelTimeline::getReplies()
  * Response should contatin
  * $object->datetime, $object->username
  * $object->id,  	  $object->userid
  * $object->bodytext, $object->source
  * $object->userpic,  $object->candelete (bool)
  * $object->cancomment,
  * @param mixed $storyID
  * @return void
  */
 public function getComments($storyID)
 {
     $user = TuiyoAPI::get("user", null);
     $table = TuiyoLoader::table("timeline");
     $comments = array();
     //1. Get the timelien data from DB
     $replies = $table->loadTimeline(null, null, (int) $storyID, null, 0, null);
     //2. Standardize
     foreach ($replies as $comment) {
         $comment->datetime = TuiyoTimer::diff(strtotime($comment->datetime));
         $comment->id = (int) $comment->id;
         $comment->bodytext = strval($comment->bodytext);
         //No HTML unless defined in template
         $comment->userpic = TuiyoUser::getUserAvatar($comment->userid, "thumb35");
         $comment->source = empty($comment->source) ? "web" : $comment->source;
         //Story Permissions
         $comment->candelete = (int) $comment->userid != (int) $user->id ? false : true;
         $comment->cancomment = !$user->joomla->get('guest') ? true : false;
         //Add to the stories array;
         $comments[] = $comment;
     }
     return (array) $comments;
 }
示例#5
0
 /**
  * TuiyoModelFriends::removeFriend()
  * Removes a friend from your friend lists
  * @param mixed $profileID
  * @param mixed $userID
  * @return
  */
 public function removeFriend($profileID, $userID = NULL)
 {
     $tble = TuiyoLoader::table("friends");
     //user1 and user2
     $user1 = !empty($userID) ? (int) $userID : TuiyoAPI::get("user")->id;
     $user2 = !empty($profileID) ? (int) $profileID : JError::raiseError(500, _('Invalid Profile ID'));
     $user2P = TuiyoUser::getInstance($user2);
     if (($rel = $this->isFriendOf($user1, $user2)) !== FALSE) {
         if (!$rel->delete()) {
             JError::raiseError(500, $rel->getErrorMsg());
             return false;
         }
         return sprintf(_("%s has been removed from your friends list"), $user2P->name);
     }
     JError::raiseError(500, sprintf(_("There was a problem removing %s from your friends list"), $user2P->name));
 }
示例#6
0
 public function TuiyoSession($handler = 'DB')
 {
     parent::TuiyoUser();
     self::setHandler($handler);
 }
示例#7
0
 public function finishBuild()
 {
     global $mainframe;
     $userData = TuiyoAPI::get("user");
     $profile = TuiyoUser::getUserFromRequest();
     $document = JFactory::getDocument();
     $template = JFilterInput::clean($mainframe->getTemplate(), 'cmd');
     $userStyle = TUIYO_STYLES . DS . $userData->id . DS . $template . ".ini";
     if (file_exists($userStyle) && is_file($userStyle) && is_readable($userStyle)) {
         $content = file_get_contents($userStyle);
         $params = new JParameter($content);
         $session = JSession::getInstance('none', array());
         $session->set("TUIYO_STYLE", $params);
     }
     //User Avatar
     $mainframe->addMetaTag("thumb70", $userData->getUserAvatar()->thumb70);
     $mainframe->addMetaTag("thumb35", $userData->getUserAvatar()->thumb35);
 }
示例#8
0
 /**
  * Method to display the users profile
  * Profile ID must be specified, or else redirected to own profile
  * @access	public
  */
 public function view($tpl = null)
 {
     //1. Requirements
     $thisuser = $GLOBALS['API']->get('user');
     $redirect = JRoute::_(TUIYO_INDEX . "&amp;view=welcome");
     $thatuser = TuiyoUser::getUserFromRequest();
     $thatuser = !is_object($thatuser) ? $thisuser : $thatuser;
     $profileID = $thatuser->id;
     $view = $this->getView('profile', "html");
     $fModel = $this->getModel('friends');
     $pModel = $this->getModel('profile');
     //3. Check Privacy Settings;
     $uPrivacy =& $GLOBALS['API']->get('privacy');
     $tPrivacy = array("canViewProfile" => $uPrivacy->canViewProfile($thatuser->id, $thisuser->id), "canViewProfileEx" => $uPrivacy->canViewExtendedProfile($thatuser->id, $thisuser->id), "canViewProfileSb" => $uPrivacy->canViewProfileInformation($thatuser->id, $thisuser->id), "canViewProfileFrs" => $uPrivacy->canViewProfileFriends($thatuser->id, $thisuser->id), "canRateProfile" => $uPrivacy->canRateUser($thatuser->id, $thisuser->id), "canAddAsFriend" => $uPrivacy->canAddAsFriends($thatuser->id, $thisuser->id));
     //If guest profile?
     if ($thatuser->joomla->get('guest')) {
         $this->setRedirect($redirect);
         $this->redirect();
     }
     //4. Load Extended Profile,
     $uFriends = $fModel->getFriendLists($thatuser->id, $thisuser->id, 1);
     //Bread crumbs and Page Title
     $GLOBALS['mainframe']->addMetaTag("pid", $thatuser->id);
     //Assign Variables
     $view->assignRef("friends", $uFriends);
     $view->assignRef("privacy", $tPrivacy);
     $view->assignRef("thisuser", $thisuser);
     $view->assignRef("thatuser", $thatuser);
     $view->assignRef("controller", $this);
     $pModel->incrementViews($thatuser->id, +1);
     //onProfileView
     $GLOBALS["events"]->trigger("onProfileView", $this);
     $view->display($tpl, $thatuser->id, $tPrivacy);
 }
示例#9
0
 /**
  * TuiyoUser::getInstance()
  * 
  * Gets an instance of the user object
  * 
  * @param mixed $userid
  * @param bool $ifNotExist
  * @return
  */
 public function getInstance($userid = null, $ifNotExist = TRUE)
 {
     /** Creates new instance if none already exists ***/
     static $instance = array();
     if (isset($instance['uid:' . $userid]) && $ifNotExist && !empty($userid)) {
         if (is_object($instance['uid:' . $userid])) {
             return $instance['uid:' . $userid];
         } else {
             unset($instance['uid:' . $userid]);
             TuiyoUser::getInstance($userid, $ifNotExist);
         }
     } else {
         $object = new TuiyoUser($userid);
         if (!empty($userid)) {
             $instance['uid:' . $userid] = $object;
         }
     }
     return $object;
 }
示例#10
0
 /**
  * TuiyoModelResources::getAllMembers()
  * Gets a lists of all members
  * @param mixed $filterOptions
  * @return void
  */
 public function getAllMembers($filterOptions = array())
 {
     $userAPI =& TuiyoAPI::get("user", null);
     $usersTable =& TuiyoLoader::table("users", true);
     $friendsModel =& TuiyoLoader::model("friends", true);
     $limit = $this->getState('limit');
     $limitstart = $this->getState('limitstart');
     $usersList =& $usersTable->getAllUsers(TRUE, FALSE, $limitstart, $limit);
     //1b. Paginate?
     jimport('joomla.html.pagination');
     $dbo = $usersTable->_db;
     $this->_total = $dbo->loadResult();
     $pageNav = new JPagination($this->_total, $limitstart, $limit);
     $this->pageNav = $pageNav->getPagesLinks();
     //Set the total count
     $this->setState('total', $this->_total);
     $this->setState('pagination', $this->pageNav);
     //Its important that this be called after pagination is processed!
     $myFriendsIds = (array) $friendsModel->generateIDs($userAPI->id);
     //add Avatar object
     foreach ((array) $usersList as $user) {
         $user->isUserFriend = !in_array($user->id, $myFriendsIds) && $user->id != $userAPI->id ? FALSE : TRUE;
         $user->avatar =& TuiyoUser::getUserAvatar($user->id);
     }
     return $usersList;
 }