function __construct() { // create SQLite database parent::__construct(); // files $this->createTable('files', array('id' => 'INTEGER PRIMARY KEY', 'mime' => 'TEXT', 'data' => 'DATA', 'code' => 'TEXT', 'date' => 'TEXT', 'room' => 'NUMERIC', 'transcript' => 'NUMERIC', 'filename' => 'TEXT', 'type' => 'TEXT')); // image thumbnails $this->createTable('thumbs', array('data' => 'DATA', 'code' => 'TEXT')); // messages $this->createTable('messages', array('id' => 'INTEGER PRIMARY KEY', 'date' => 'TEXT', 'room' => 'NUMERIC', 'userId' => 'NUMERIC', 'text' => 'TEXT', 'type' => 'TEXT', 'user' => 'NUMERIC', 'transcript' => 'NUMERIC', 'highlight' => 'NUMERIC', 'locked' => 'NUMERIC')); // room transcripts $this->createTable('room_transcripts', array('key' => 'INTEGER PRIMARY KEY', 'deleted' => 'NUMERIC', 'niceDate' => 'TEXT', 'date' => 'TEXT', 'room' => 'NUMERIC')); // room users $this->createTable('room_users', array('timestamp' => 'NUMERIC', 'room' => 'NUMERIC', 'user' => 'NUMERIC')); // rooms $this->createTable('rooms', array('id' => 'INTEGER PRIMARY KEY', 'deleted' => 'TEXT', 'activity' => 'NUMERIC', 'timestamp' => 'NUMERIC', 'description' => 'TEXT', 'guest' => 'TEXT', 'locked' => 'TEXT', 'name' => 'TEXT')); // transcript users $this->createTable('transcript_users', array('date' => 'TEXT', 'room' => 'NUMERIC', 'user' => 'NUMERIC')); // user permissions $this->createTable('user_permissions', array('room' => 'NUMERIC', 'user' => 'NUMERIC')); // users $this->createTable('users', array('id' => 'INTEGER PRIMARY KEY', 'role' => 'TEXT', 'long' => 'TEXT', 'short' => 'TEXT', 'email' => 'TEXT', 'invitation' => 'TEXT', 'name' => 'TEXT', 'password' => 'TEXT', 'surname' => 'TEXT', 'username' => 'TEXT')); $db = Fari_Db::getConnection(); $db->insert('users', array('role' => 'admin', 'name' => 'Radek', 'surname' => 'Stepan', 'long' => 'Radek Stepan', 'short' => 'Radek S.', 'password' => 'd033e22ae348aeb5660fc2140aec35850c4da997', 'username' => 'admin')); }
public function __construct($file, $roomId) { // get file $this->name = Fari_Escape::file($file['name'], TRUE); $this->mime = $file['type']; // db instance $db = Fari_Db::getConnection(); $type = explode('/', $this->mime); $type = count($type) > 1 ? $type[1] : $type[0]; // set generic filetype for files we don't have icons for :) if (!in_array($type, $this->fileTypes)) { $type = 'generic'; } $stream = fopen($file['tmp_name'], 'rb'); $code = $this->randomCode($db); $date = SystemTime::timestampToDate(); // let's associate the file with a transcript (there better be a transcript...) $transcript = $db->selectRow('room_transcripts', 'key', array('date' => $date, 'room' => $roomId)); // insert the file $db->query("INSERT INTO files (mime, data, code, room, filename, type, date, transcript)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?)", array($this->mime, $stream, $this->code = $code, $roomId, $this->name, $this->type = $type, $date, $transcript['key'])); fclose($stream); // create a thumbnail if required $thumbnail = new UploadThumbnail($file); if ($thumbnail->isCreated()) { // yes we do have one $this->thumbnail = TRUE; $thumb = fopen($thumbnail->getPath(), 'rb'); // insert the thumbnail $db->query("INSERT INTO thumbs (data, code) VALUES (?, ?)", array($thumb, $this->code)); fclose($thumb); //$thumbnail->destroy(); } }
/** * Constructor, creating a timestamp type message (whenever any action happens) * * Make sure that activity column has a number in it! * * @param integer $roomId Id of the room (optional) * @param integer $time UNIX timestamp (optional) * @param integer $hide Set to one if you don't want a message to appear in transcript but room is not locked yet * @return void */ function __construct($roomId = null, $time = null, $hide = 0) { // call parent constructor to set db connection $this->db = Fari_Db::getConnection(); parent::__construct($this->db); // we don't want to timestamp a room as active if a user is leaving for example... if (isset($roomId)) { $this->roomId = $roomId; $this->timestampRoom($time, $hide); } }
function __construct($roomPermissionsString) { // setup db connection $this->db = Fari_Db::getConnection(); // fetch the count of all the transcripts, calculate in PHP $this->all = $this->db->select('room_transcripts' . ' JOIN rooms' . ' ON room_transcripts.room=rooms.id', 'room_transcripts.key, rooms.id, rooms.name, room_transcripts.niceDate, room_transcripts.date', "room_transcripts.deleted=0 AND rooms.id IN ({$roomPermissionsString})", 'room_transcripts.key DESC'); // count of all items if (($this->count = count($this->all)) == 0) { throw new TranscriptEmptyException(); } }
function __construct($date, $roomId) { // setup db connection $this->db = Fari_Db::getConnection(); $this->details = $this->db->selectRow('room_transcripts JOIN rooms ON rooms.id=room_transcripts.room', 'room_transcripts.key, niceDate, name, room, date', array('date' => $date, 'room_transcripts.deleted' => 0, 'room' => $roomId)); // nothing found, throw an exception if (!is_array($this->details)) { throw new TranscriptNotFoundException(); } // get users $this->users = $this->getUsers($date, $roomId); // get messages $this->messages = $this->getMessages($date, $roomId); // get files $this->files = $this->getFiles($date, $roomId); // next transcript $this->next = $this->next($roomId); // previous transcript $this->previous = $this->previous($roomId); }
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}"); } }
/** * Create object for authenticated user */ function __construct($roles = NULL) { $this->db = Fari_Db::getConnection(); parent::__construct(); // no entry, we are not logged in, fail the constructor if (!$this->isAuthenticated()) { throw new UserNotAuthenticatedException(); } // fetch the database entry for us $dbUser = $this->db->selectRow('users', 'id, role, name, surname, short, long, invitation', array('username' => $this->getCredentials())); // user has been inactivated, throw them away if ($dbUser['role'] == 'inactive') { throw new UserNotAuthenticatedException(); } // ORM much? effectively map db entry into an identity Fari_Bag object $this->identity = new Fari_Bag(); foreach ($dbUser as $key => $value) { $this->identity->{$key} = $value; } // get an array of room permissions for us $q = $this->db->select('user_permissions', 'room', array('user' => $dbUser['id']), 'room ASC'); foreach ($q as $room) { array_push($this->permissions, $room['room']); } // which rooms are we in? $q = $this->db->select('room_users JOIN rooms ON room_users.room=rooms.id', 'rooms.id, name', array('user' => $dbUser['id']), 'room ASC'); foreach ($q as $room) { $this->inRoom[$room['name']] = $room['id']; } // optionally check the roles if (isset($roles)) { if (!$this->isAuthorized(&$roles, $dbUser['role'])) { throw new UserNotAuthorizedException(); } } }
/** * Get instance of database connection. */ public function __construct() { $this->db = Fari_Db::getConnection(); }
/** * Get code and name from the form and create a new user for us (generate username) */ public function actionCreate() { $name = Fari_Decode::accents($this->request->getPost('name')); $code = $this->request->getPost('code'); if (!empty($name)) { $name = explode(' ', $name); // do we have a 'long' name? if (count($name) > 1) { $short = $name[0] . ' ' . substr(end($name), 0, 1) . '.'; $long = implode(' ', $name); $surname = end($name); $name = $name[0]; } else { $short = $long = $name = $name[0]; $surname = ''; } // generate a username $username = Fari_Escape::slug($long) . Fari_Tools::randomCode(10); $db = Fari_Db::getConnection(); // insert the user in a guest role $userId = $db->insert('users', array('short' => $short, 'long' => $long, 'name' => $name, 'surname' => $surname, 'role' => 'guest', 'username' => $username)); // log them in automatically Fari_AuthenticatorSimple::forceAuthenticate($username); // give them permissions to enter this room $room = $db->selectRow('rooms', 'id', array('guest' => $code)); if (!empty($room)) { $db->insert('user_permissions', array('room' => $room['id'], 'user' => $userId)); } } // redirect to the room, if we've ailed will be asked for guest's name again $this->redirectTo('/g/' . $code); }