protected function _rooms() { $roomHandler = new Dura_Model_RoomHandler(); $roomModels = $roomHandler->loadAll(); $rooms = array(); $lang = Dura::user()->getLanguage(); $rooms[$lang] = array(); $roomExpire = time() - DURA_CHAT_ROOM_EXPIRE; $activeUser = 0; foreach ($roomModels as $id => $roomModel) { $room = $roomModel->asArray(); if ($room['update'] < $roomExpire) { $roomHandler->delete($id); continue; } $room['creater'] = ''; foreach ($room['users'] as $user) { if ($user['id'] == $room['host']) { $room['creater'] = $user['name']; } } $room['id'] = $id; $room['total'] = count($room['users']); $room['url'] = Dura::url('room'); $lang = $room['language']; $rooms[$lang][] = $room; $activeUser += $room['total']; } unset($roomHandler, $roomModels, $roomModel, $room); $this->output['rooms'] = $rooms; $this->output['active_user'] = $activeUser; }
protected function _createRoom() { $userName = Dura::user()->getName(); $userId = Dura::user()->getId(); $userIcon = Dura::user()->getIcon(); $roomHandler = new Dura_Model_RoomHandler(); $roomModel = $roomHandler->create(); $roomModel->name = $this->input['name']; $roomModel->update = time(); $roomModel->limit = $this->input['limit']; $roomModel->host = $userId; $roomModel->language = $this->input['language']; $users = $roomModel->addChild('users'); $users->addChild('name', $userName); $users->addChild('id', $userId); $users->addChild('icon', $userIcon); $users->addChild('update', time()); if (Dura::$language != $this->input['language']) { $langFile = DURA_TRUST_PATH . '/language/' . $this->input['language'] . '.php'; Dura::$catalog = (require $langFile); } $talk = $roomModel->addChild('talks'); $talk->addChild('id', md5(microtime() . mt_rand())); $talk->addChild('uid', 0); $talk->addChild('name', $userName); $talk->addChild('message', "{1} logged in."); $talk->addChild('icon', ''); $talk->addChild('time', time()); $id = md5(microtime() . mt_rand()); if (!$roomHandler->save($id, $roomModel)) { throw new Exception(t("Data Error: Room creating failed.")); } Dura_Class_RoomSession::create($id); Dura::redirect('room'); }
* */ if (file_exists('setting.php')) { require 'setting.php'; } else { require 'setting.dist.php'; } require 'dura.php'; Dura::setup(); if (!isset($_SESSION['room']['id'])) { // Session not exists. header('Content-Type: application/xml; charset=UTF-8'); die('<?xml version="1.0" encoding="UTF-8"?><room><error>1</error></room>'); } $id = $_SESSION['room']['id']; $roomHandler = new Dura_Model_RoomHandler(); $roomModel = $roomHandler->load($id); if (!$roomModel) { // Room not found. header('Content-Type: application/xml; charset=UTF-8'); die('<?xml version="1.0" encoding="UTF-8"?><room><error>2</error></room>'); } $file = $roomHandler->getFilePath($id); $content = md5(file_get_contents($file)); session_write_close(); if (!isset($_GET['fast'])) { for ($i = 0; $i < DURA_SLEEP_LOOP; $i++) { if ($content != md5(file_get_contents($file))) { break; } sleep(DURA_SLEEP_TIME);