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(); } }
/** * 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); } }
/** * Say that a topic has been set/cleared * * @param integer $roomId Id of the room * @param string $shortName Short version of the user's name * @param string $topic Topic that has been set * @return void */ public function topic($roomId, $shortName, $topic) { $text = empty($topic) ? 'cleared the topic ' : "changed the room's topic to <em>{$topic}</em>"; $this->db->insert('messages', array('room' => $roomId, 'user' => $shortName, 'type' => 'topic', 'text' => $text, 'date' => SystemTime::timestampToDate(), 'locked' => $this->lockedRoom)); }