/** * Compose a new message, and process new message submissions * @parm int $reply message ID this message is in reply to [optional] only used to pre-populate subject and recipient * @return void */ private function newMessage($reply = 0) { $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'messages/create.tpl.php', 'footer.tpl.php'); require_once FRAMEWORK_PATH . 'models/relationships.php'; $relationships = new Relationships($this->registry); if (isset($_POST) && count($_POST) > 0) { $network = $relationships->getNetwork($this->registry->getObject('authenticate')->getUser()->getUserID()); $recipient = intval($_POST['recipient']); if (in_array($recipient, $network)) { // this additional check may not be something we require for private messages? require_once FRAMEWORK_PATH . 'models/message.php'; $message = new Message($this->registry, 0); $message->setSender($this->registry->getObject('authenticate')->getUser()->getUserID()); $message->setRecipient($recipient); $message->setSubject($this->registry->getObject('db')->sanitizeData($_POST['subject'])); $message->setMessage($this->registry->getObject('db')->sanitizeData($_POST['message'])); $message->save(); // email notification to the recipient perhaps?? // confirm, and redirect $url = $this->registry->getObject('url')->buildURL(array('messages'), '', false); $this->registry->redirectUser($url, 'Message sent', 'The message has been sent'); } else { $this->registry->errorPage('Invalid recipient', 'Sorry, you can only send messages to your recipients'); } } else { $cache = $relationships->getByUser($this->registry->getObject('authenticate')->getUser()->getUserID()); $this->registry->getObject('template')->getPage()->addTag('recipients', array('SQL', $cache)); if ($reply > 0) { require_once FRAMEWORK_PATH . 'models/message.php'; $message = new Message($this->registry, $reply); if ($message->getRecipient() == $this->registry->getObject('authenticate')->getUser()->getUserID()) { $this->registry->getObject('template')->getPage()->addAdditionalParsingData('recipients', 'ID', $message->getSender(), 'opt', "selected='selected'"); $this->registry->getObject('template')->getPage()->addTag('subject', 'Re: ' . $message->getSubject()); } else { $this->registry->getObject('template')->getPage()->addTag('subject', ''); } } else { $this->registry->getObject('template')->getPage()->addTag('subject', ''); } } }
/** * Build a users stream * @param int $user the user whose network we want to stream * @param int $offset - useful if we add in an AJAX based "view more statuses" feature * @return void */ public function buildStream($user, $offset = 0) { // prepare an array $network = array(); // use the relationships model to get relationships require_once FRAMEWORK_PATH . 'models/relationships.php'; $relationships = new Relationships($this->registry); $network = $relationships->getNetwork($user); // Add a zero element; so if network is empty the IN part of the query won't fail $network[] = 0; $network = implode(',', $network); // query the statuses table $sql = "SELECT t.type_reference, t.type_name, s.*, UNIX_TIMESTAMP(s.posted) as timestamp, p.name as poster_name, r.name as profile_name FROM statuses s, status_types t, profile p, profile r WHERE t.ID=s.type AND p.user_id=s.poster AND r.user_id=s.profile AND ( p.user_id={$user} OR r.user_id={$user} OR ( p.user_id IN ({$network}) AND r.user_id IN ({$network}) ) ) ORDER BY s.ID DESC LIMIT {$offset}, 20"; $this->registry->getObject('db')->executeQuery($sql); if ($this->registry->getObject('db')->numRows() > 0) { $this->empty = false; // iterate through the statuses, adding the ID to the IDs array, making the time friendly, and saving the stream while ($row = $this->registry->getObject('db')->getRows()) { $row['friendly_time'] = $this->generateFriendlyTime($row['timestamp']); $this->IDs[] = $row['ID']; $this->stream[] = $row; } } }
/** * Process a new status submission / profile message * @param int $user the profile the message is being posted on * @return void */ private function addStatus($user) { $loggedInUser = $this->registry->getObject('authenticate')->getUser()->getUserID(); if ($loggedInUser == $user) { require_once FRAMEWORK_PATH . 'models/status.php'; if (isset($_POST['status_type']) && $_POST['status_type'] != 'update') { if ($_POST['status_type'] == 'image') { require_once FRAMEWORK_PATH . 'models/imagestatus.php'; $status = new Imagestatus($this->registry, 0); $status->processImage('image_file'); } elseif ($_POST['status_type'] == 'video') { require_once FRAMEWORK_PATH . 'models/videostatus.php'; $status = new Videostatus($this->registry, 0); $status->setVideoIdFromURL($_POST['video_url']); } elseif ($_POST['status_type'] == 'link') { require_once FRAMEWORK_PATH . 'models/linkstatus.php'; $status = new Linkstatus($this->registry, 0); $status->setURL($this->registry->getObject('db')->sanitizeData($_POST['link_url'])); $status->setDescription($this->registry->getObject('db')->sanitizeData($_POST['link_description'])); } } else { $status = new Status($this->registry, 0); } //$status = new Status( $this->registry, 0 ); $status->setProfile($user); $status->setPoster($loggedInUser); $status->setStatus($this->registry->getObject('db')->sanitizeData($_POST['status'])); $status->generateType(); $status->save(); // success message display $this->registry->getObject('template')->addTemplateBit('status_update_message', 'profile/statuses/update_confirm.tpl.php'); } else { require_once FRAMEWORK_PATH . 'models/relationships.php'; $relationships = new Relationships($this->registry); $connections = $relationships->getNetwork($user, false); if (in_array($loggedInUser, $connections)) { require_once FRAMEWORK_PATH . 'models/status.php'; if (isset($_POST['status_type']) && $_POST['status_type'] != 'update') { if ($_POST['status_type'] == 'image') { require_once FRAMEWORK_PATH . 'models/imagestatus.php'; $status = new Imagestatus($this->registry, 0); $status->processImage('image_file'); } elseif ($_POST['status_type'] == 'video') { require_once FRAMEWORK_PATH . 'models/videostatus.php'; $status = new Videostatus($this->registry, 0); $status->setVideoIdFromURL($_POST['video_url']); } elseif ($_POST['status_type'] == 'link') { require_once FRAMEWORK_PATH . 'models/linkstatus.php'; $status = new Linkstatus($this->registry, 0); $status->setURL($this->registry->getObject('db')->sanitizeData($_POST['link_url'])); $status->setDescription($this->registry->getObject('db')->sanitizeData($_POST['link_description'])); } } else { $status = new Status($this->registry, 0); } $status->setProfile($user); $status->setPoster($loggedInUser); $status->setStatus($this->registry->getObject('db')->sanitizeData($_POST['status'])); $status->generateType(); $status->save(); // success message display $this->registry->getObject('template')->addTemplateBit('status_update_message', 'profile/statuses/post_confirm.tpl.php'); } else { // error message display $this->registry->getObject('template')->addTemplateBit('status_update_message', 'profile/statuses/error.tpl.php'); } } }