public function buildStream($user, $offset = 0) { $network = array(); // prepare an array require_once 'relation.php'; // use the relationships model to get relationships $relation = new RelationsGet($this->registry); $network = $relation->getNetwork($user); //$subscribers = $relation->getSubscribers( $user ); //$network = array_merge($network, $subscribers); // Add a zero element; so if network is empty the IN part of the query won't fail if (count($network) == 0) { $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.", 25"; $sql = "SELECT t.type_reference, t.type_name, s.*, UNIX_TIMESTAMP(s.posted) as timestamp, p.username as poster_user, p.name as poster_name, r.name as profile_name, i.image, v.video_id, l.URL, s.ID FROM status_types t, profile p, profile r, statuses s LEFT JOIN statuses_images i ON s.ID=i.id LEFT JOIN statuses_videos v ON s.ID=v.id LEFT JOIN statuses_links l ON s.ID=l.id WHERE t.ID=s.type AND p.user_id=s.poster AND (r.user_id=s.profile OR s.profile=0) 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 //echo $sql; while ($row = $this->registry->getObject('db')->getRows()) { if (!in_array($row['ID'], $this->IDs)) { $row['friendly_time'] = $this->generateFriendlyTime($row['timestamp']); $this->IDs[] = $row['ID']; $this->stream[] = $row; } } //var_dump($this->IDs);var_dump($this->stream); } else { //$this->registry->errorPage('No more Streams', 'No more streams were found at this offset'); $this->noMoreStreams = true; } }
public function addStatus($user) { $loggedInUser = $this->registry->getObject('authenticate')->getUser()->getUserID(); if ($loggedInUser == $user) { require_once 'status.php'; if (isset($_POST['status_type']) && $_POST['status_type'] != 'update') { if ($_POST['status_type'] == 'image') { require_once 'imagestatus.php'; $status = new Imagestatus($this->registry, 0, $this->username); $status->processImage('image_file'); } elseif ($_POST['status_type'] == 'video') { require_once 'videostatus.php'; $status = new Videostatus($this->registry, 0, $this->username); $status->setVideoIdFromURL($_POST['video_url']); } elseif ($_POST['status_type'] == 'link') { require_once '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); if (isset($_POST['status'])) { $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_status_update_confirm.php'); } else { require_once 'relation.php'; $relationships = new RelationsGet($this->registry); $connections = $relationships->getNetwork($user, false); if (in_array($loggedInUser, $connections)) { require_once 'status.php'; if (isset($_POST['status_type']) && $_POST['status_type'] != 'update') { if ($_POST['status_type'] == 'image') { require_once 'imagestatus.php'; $status = new Imagestatus($this->registry, 0, $this->username); $status->processImage('image_file'); } elseif ($_POST['status_type'] == 'video') { require_once 'videostatus.php'; $status = new Videostatus($this->registry, 0, $this->username); $status->setVideoIdFromURL($_POST['video_url']); } elseif ($_POST['status_type'] == 'link') { require_once '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_status_post_confirm.php'); } else { // error message display $this->registry->getObject('template')->addTemplateBit('status_update_message', 'profile_status_error.php'); } } }