public function get($lastMessageId) { if (Fari_Filter::isInt($lastMessageId)) { // get is the freshest messages $newMessages = Messages::get($lastMessageId); // handle with JSON echo json_encode($newMessages); } }
/** * Set a cookie under our namespace. * * @param string $name Name of the cookie we want to save it under * @param string $value Value we want to set * @param int $expiry Expiry in seconds from now * @return boolean FALSE if cookie set unsuccesfuly */ public static function set($name, $value, $expiry) { // check we have data if (isset($name) && isset($value) && Fari_Filter::isInt($expiry)) { setcookie(self::COOKIE_STORAGE . $name, $value, time() + $expiry); } else { return FALSE; } }
/** * File upload * FIXME anyone can upload to another room! */ public function actionUpload() { $roomId = $this->request->getPost('roomId'); if (Fari_Filter::isInt($roomId)) { $file =& $this->request->getFile(); // save the file and get its code $this->file = new Upload($file, $roomId); $this->renderUpload($roomId); } }
/** * Delete the room */ public function actionDelete($roomId) { if ($this->request->isAjax()) { if (Fari_Filter::isInt($roomId)) { try { $this->settings->deleteRoom($roomId); } catch (RoomNotFoundException $e) { // } } } else { $this->renderTemplate('error404/javascript'); } }
public function sendInvitation() { // fetch the newly invited user $users = new Table('users'); $user = $users->findFirst('id DESC')->where(array('role' => 'invited')); // have we actually retrieved the user? if (!Fari_Filter::isInt($user->id)) { throw new UserNotFoundException(); } // form the email $this->mailer->addTo($user->email)->addFrom('*****@*****.**', 'Clubhouse'); $this->mailer->setSubject('You\'re invited to join Clubhouse'); $this->mailer->setBody("Hi {$user->first},\nYou're invited to join Clubhouse, our group chat system.\n\n" . "Click this link to get started:\n" . url('account/invitation/' . $user->invitation . '/', FALSE, TRUE) . "\n\nThanks"); //$this->mailer->send(); }
/** * Display transcripts listing */ public function actionIndex($page) { // set the default page number if (!isset($page)) { $page = 1; } // room tabs $this->bag->tabs = $this->user->inRooms(); try { // setup new transcripts object $transcripts = new TranscriptListing($this->user->getPermissionsDbString()); } catch (TranscriptEmptyException $e) { $this->renderAction('empty'); } // are we fetching a page number in a proper range? if (!Fari_Filter::isInt($page, array(1, ceil($transcripts->count / $this->pagination)))) { $this->renderTemplate('Error404/error404'); } // fetch transcript users, files and highlighted messages $this->renderAction('listing', array(&$transcripts, $page)); }
/** * Main point of entry for text parsing. * * @param int $months The number of months to display * @param string $date "n-Y" formatted date when to start calendar * @return string HTML formatted calendar ready to echo in the View */ public static function get($months, $date = NULL) { // determine today's date if (isset($date)) { // input date separated by '-' $date = explode('-', $date); // check and use passed month if (!empty($date[0]) && Fari_Filter::isInt($date[0], array(0, 12))) { $startMonth = $date[0]; } else { $startMonth = date('n'); } // check and use passed year if (!empty($date[1]) && Fari_Filter::isInt($date[1], array(1900, 2999))) { $startYear = $date[1]; } else { $startMonth = date('n'); } } else { $startMonth = date('n'); // 0 - 12 $startYear = date('Y'); // 1984 } $result = array(); // check that the number of months to display is a positive int, default to 4 $months = $months > 0 ? $months : 4; // get us x months for ($i = 0; $i < $months; $i++) { // we are changing the year if ($startMonth + $i > 12) { $startMonth = 0; $startYear++; } $result = self::_getMonth($startMonth + $i, $startYear, $result); } return $result; }
/** * Determine a type of the value. * @param <type> $value * @return <type> */ private function valueType($value) { // a file if (get_resource_type($value) == 'stream') { return PDO::PARAM_LOB; // a string or an integer } else { return Fari_Filter::isInt($value) ? PDO::PARAM_INT : PDO::PARAM_STR; } }
/** * Echo the SQL statement into the view * * @param string $statement SQL query string * @param array $values The values to insert, update * @param array/string $where The where clause * @return echo Query string into the view */ private static function _toString($statement, array $values = NULL, $where = NULL) { // traverse the values and where clause arrays if (is_array($where)) { $binder = 'set'; foreach (array($values, $where) as $array) { if (isset($array)) { // replace bound parametres with actual values $i = 0; foreach ($array as $value) { // determine value type of string or integer $value = Fari_Filter::isInt($value) ? "{$value}" : "'{$value}'"; // we have a variable binding key $statement = preg_replace("/:{$binder}{$i}/", $value, $statement); $i++; } } // a switch to keep track of which array are we traversing $binder = 'id'; } } // echo into the view die("<pre>{$statement}</pre>"); }
/** * Will set a valid page number requested for pagination and return number of pages in the query. * * @param int $requestedPage Page requested by user, can be invalid! * @param int $itemsTotal Number of items in the query result * @return int Pages total count */ private function setPageRequested($requestedPage, $itemsTotal) { // get the total number of pages we can display $pagesTotal = ceil($itemsTotal / $this->itemsPerPage); // set to first page if request invalid (not within the the min page, max page range) if (!Fari_Filter::isInt($requestedPage, array(1, $pagesTotal))) { $requestedPage = 1; } // set page requested $this->pageRequested = $requestedPage; return $pagesTotal; }
/** * Leave the room */ public function actionLeave($roomId) { if (Fari_Filter::isInt($roomId)) { // are we actually in the room? if ($this->user->inRoom($roomId)) { // remove us from participants $this->user->leaveRoom($roomId); // message about it $time = mktime(); $message = new MessageSpeak($roomId, $time); $message->leave($roomId, $time, $this->user->getShortName()); // the user might be a guest in which case show her a slightly different exit message if ($this->user->isGuest()) { $this->renderAction('bye'); } } } // redir either way $this->redirectTo('/'); }
/** * Message highlighting * * @uses Ajax */ public function actionHighlight($messageId) { if (Fari_Filter::isInt($messageId)) { $time = mktime(); $messages = new Message(); try { $result = $messages->switchHighlight($messageId); } catch (MessageNotFoundException $e) { // you mess with us... we mess with you $this->renderJson('bye'); } $this->renderJson($result); } else { $this->renderJson('bye'); } }
/** * Delete a user other than the owner * * @uses Ajax */ public function actionDelete($userId) { // is this Ajax? if ($this->request->isAjax()) { $adminUser = $this->user->getAdmin(); if (Fari_Filter::isInt($userId) && $userId != $adminUser['id']) { try { $this->accounts->deleteUser($userId); } catch (UserNotFoundException $e) { // } } } else { $this->renderTemplate('error404/javascript'); } }