コード例 #1
0
ファイル: shoutbox.php プロジェクト: radekstepan/zenchat
 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);
     }
 }
コード例 #2
0
ファイル: Cookie.php プロジェクト: radekstepan/PumpedBlog
 /**
  * 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;
     }
 }
コード例 #3
0
 /**
  * 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);
     }
 }
コード例 #4
0
 /**
  * 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');
     }
 }
コード例 #5
0
ファイル: Mailer.php プロジェクト: radekstepan/Clubhouse
 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();
 }
コード例 #6
0
 /**
  * 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));
 }
コード例 #7
0
 /**
  * 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;
 }
コード例 #8
0
 /**
  * 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;
     }
 }
コード例 #9
0
ファイル: Db.php プロジェクト: radekstepan/Knowledgebase
 /**
  * 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>");
 }
コード例 #10
0
 /**
  * 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;
 }
コード例 #11
0
 /**
  * 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('/');
 }
コード例 #12
0
 /**
  * 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');
     }
 }
コード例 #13
0
 /**
  * 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');
     }
 }