Example #1
0
 /**
  * Destroy user session
  */
 public function actionLogout()
 {
     try {
         // we might not be signed in actually
         $this->user = new User();
     } catch (UserNotAuthenticatedException $e) {
         $this->flashSuccess = 'You are already logged out';
     }
     // as we are logging out, leave us from all rooms
     if ($this->user != NULL) {
         $inRooms = $this->user->inRooms();
         if (!empty($inRooms)) {
             $time = mktime();
             foreach ($inRooms as $room) {
                 // message about it
                 $message = new MessageSpeak($room, $time);
                 $message->leave($room, $time, $this->user->getShortName());
             }
             // remove us from participants
             $room = new Room();
             $room->removeParticipant($this->user->getId());
         }
         $this->flashSuccess = 'You have been logged out';
         $this->user->signOut();
     }
     $this->bag->token = Fari_FormToken::create();
     $this->renderAction('login');
 }
Example #2
0
 /**
  * Delete the transcript.
  */
 public function delete($date, $shortName)
 {
     // transcript users are not needed anymore
     $this->db->delete('transcript_users', array('transcript' => $this->details['key']));
     // files
     $files = $this->db->selectRow('files', 'group_concat(code) as codes', array('transcript' => $this->details['key']));
     $this->db->delete('files', array('transcript' => $this->details['key']));
     // thumbnails aka silly quoting
     $codes = explode(',', $files['codes']);
     foreach ($codes as &$code) {
         $code = "'{$code}'";
     }
     $codes = implode(', ', $codes);
     $this->db->delete('thumbs', "code IN ({$codes})");
     // finaly ourselves
     $this->db->delete('room_transcripts', array('key' => $this->details['key']));
     // reset the last activity for the room so a new transcript can be created
     $this->db->update('rooms', array('activity' => 0), array('id' => $this->details['room']));
     // delete all messages for the day
     $this->db->delete('messages', array('room' => $this->details['room'], 'date' => $this->details['date']));
     // has this happened today?
     if ($date == SystemTime::timestampToDate()) {
         $message = new MessageSpeak($this->details['room'], mktime());
         $message->transcript($this->details['room'], $shortName, $date);
     }
 }
 /**
  * Send a message from a room
  *
  * @uses Ajax
  */
 public function actionSpeak($roomId)
 {
     $text = Fari_Escape::text(Fari_Decode::javascript($this->request->getRawPost('text')));
     if (!empty($text)) {
         $time = mktime();
         // a text message
         $message = new MessageSpeak($roomId, $time);
         $message->text($roomId, $time, $this->user->getShortName(), $this->user->getId(), $text);
         // the message might be saved under wrong room id, but activity updater will kick us...
         try {
             $this->room->updateUserActivity($roomId, $time, $this->user->getId());
         } catch (UserNotFoundException $e) {
             $this->renderJson('bye');
         }
     }
 }
Example #4
0
 function __construct($time = NULL)
 {
     if (!isset($time)) {
         $time = mktime();
     }
     $this->db = Fari_Db::getConnection();
     parent::__construct($this->db);
     $cutoff = $time - 60 * 10;
     // check if user has a timestamp older than 5 minutes in a room
     $leave = $this->db->select('room_users JOIN users ON room_users.user=users.id', 'user, room, short', "timestamp < {$cutoff}");
     if (!empty($leave)) {
         $message = new MessageSpeak();
         foreach ($leave as $user) {
             // leaving message
             $message->leave($user['room'], $time, $user['short']);
         }
         // clear them out from the room
         $this->db->delete('room_users', "timestamp < {$cutoff}");
     }
 }
Example #5
0
 /**
  * Display the room from a guest's perspective
  */
 public function actionIndex($guestCode)
 {
     try {
         // get the room
         $room = $this->room->getGuestRoom($guestCode = Fari_Escape::text($guestCode));
         // is user authenticated?
         $this->guestUser = new User();
         // is user authorized?
         $this->guestUser->canEnter($room['id']);
         // the room does not exist
     } catch (RoomNotFoundException $e) {
         $this->renderTemplate('room/invalid');
         // we haven't signed in
     } catch (UserNotAuthenticatedException $e) {
         $this->bag->code = $guestCode;
         // show a form to enter a name for the new guest
         $this->renderTemplate('account/guest');
         // we cannot enter this room
     } catch (UserNotAuthorizedException $e) {
         $this->renderTemplate('room/permissions');
     }
     // we are already in
     $time = mktime();
     // is the user already in the room?
     if (!$this->guestUser->inRoom($room['id'])) {
         // not in the room... is it locked?
         if ($room['locked']) {
             $system = new System();
             $this->renderTemplate('room/locked');
         } else {
             // enter them into the room
             $this->guestUser->enterRoom($room['id'], $time);
             // say that the user has entered
             $message = new MessageSpeak();
             $message->enter($room['id'], $time, $this->guestUser->getShortName());
         }
     }
     // all other fails captured...
     // show a 'guest' view
     $this->renderTemplate('room/guest', $room['id']);
 }
Example #6
0
 public function renderUpload($roomId)
 {
     // message about it
     $time = mktime();
     $message = new MessageSpeak($roomId, $time);
     $text = '<a class="file ' . $this->file->type . '"></a><a class="blue" href="' . WWW_DIR . '/file/get/' . $this->file->code . '"/>' . $this->file->name . '</a>';
     // live preview image thumbnail
     if ($this->file->thumbnail === TRUE) {
         $text .= '<div class="image"><img src="' . WWW_DIR . '/file/thumb/' . $this->file->code . '" alt="thumb" /></div>';
     } else {
         switch ($this->file->mime) {
             case 'image/jpeg':
             case 'image/jpg':
             case 'image/png':
             case 'image/gif':
                 $text .= '<div class="image"><img src="' . WWW_DIR . '/file/get/' . $this->file->code . '" alt="image" /></div>';
         }
     }
     $message->text($roomId, $time, $this->user->getShortName(), $this->user->getId(), $text);
     die($this->file->name);
 }
Example #7
0
 function kickGuests($roomId, $time)
 {
     $leaving = $this->db->select('user_permissions JOIN users ON user_permissions.user = users.id', 'id, short', array('role' => 'guest', 'room' => $roomId));
     if (!empty($leaving)) {
         $message = new MessageSpeak();
         foreach ($leaving as $kick) {
             // you should be leaving...
             $this->db->delete('user_permissions', array('user' => $kick['id'], 'room' => $roomId));
             // you are leaving...
             $message->leave($roomId, $time, $kick['short']);
             // you are actually leaving...
             $this->db->delete('room_users', array('user' => $kick['id'], 'room' => $roomId));
         }
     }
 }
Example #8
0
 /**
  * Set a new topic or clear it
  *
  * @uses Ajax
  */
 public function actionTopic($roomId)
 {
     $this->filterRoomId($roomId);
     try {
         // are we allowed to enter?
         $this->user->canEnter($roomId);
         $topic = $this->request->getPost('topic');
         $room = new Room();
         $room->topic($roomId, $topic = $this->request->getPost('topic'));
         // message about it
         $time = mktime();
         $message = new MessageSpeak($roomId, $time);
         $message->topic($roomId, $this->user->getShortName(), $topic);
         $this->renderJson($topic);
     } catch (UserNotAuthorizedException $e) {
         $this->renderJson('bye');
     }
 }
Example #9
0
 private function leaveRoom($userId)
 {
     $result = $this->db->selectRow('room_users JOIN users on room_users.user = users.id', 'room, short', array('user' => $userId));
     if (!empty($result)) {
         $time = mktime();
         $message = new MessageSpeak($result['room'], $time);
         $message->leave($result['room'], $time, $result['short']);
         // delete in one big swoop
         $this->db->delete('room_users', array('user' => $userId));
     }
 }