/** * Saves file, fetched from $_FILES to specified upload path. * * @global ilObjUser $ilUser */ public function uploadFile() { global $ilCtrl; if (!ilChatroom::checkUserPermissions('read', $this->gui->ref_id)) { $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID); $ilCtrl->redirectByClass("ilrepositorygui", ""); } $upload_path = $this->getUploadPath(); $this->checkUploadPath($upload_path); /** * @todo: filename must be unique. */ $file = $_FILES['file_to_upload']['tmp_name']; $filename = $_FILES['file_to_upload']['name']; $type = $_FILES['file_to_upload']['type']; $target = $upload_path . $filename; if (ilUtil::moveUploadedFile($file, $filename, $target)) { global $ilUser; require_once 'Modules/Chatroom/classes/class.ilChatroom.php'; require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php'; $room = ilChatroom::byObjectId($this->gui->object->getId()); $chat_user = new ilChatroomUser($ilUser, $room); $user_id = $chat_user->getUserId(); if (!$room) { throw new Exception('unkown room'); } else { if (!$room->isSubscribed($chat_user->getUserId())) { throw new Exception('not subscribed'); } } $room->saveFileUploadToDb($user_id, $filename, $type); $this->displayLinkToUploadedFile($room, $chat_user); } }
/** * Prepares and posts message fetched from $_REQUEST['message'] * to recipients fetched from $_REQUEST['recipient'] * and adds an entry to history if successful. * * @global ilObjUser $ilUser * @param string $method */ public function executeDefault($method) { global $ilUser, $ilCtrl; require_once 'Modules/Chatroom/classes/class.ilChatroom.php'; require_once 'Modules/Chatroom/classes/class.ilChatroomUser.php'; if (!ilChatroom::checkUserPermissions('read', $this->gui->ref_id)) { $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", ROOT_FOLDER_ID); $ilCtrl->redirectByClass("ilrepositorygui", ""); } $room = ilChatroom::byObjectId($this->gui->object->getId()); $chat_user = new ilChatroomUser($ilUser, $room); $user_id = $chat_user->getUserId(); if (!$room) { throw new Exception('unkown room'); } else { if (!$room->isSubscribed($chat_user->getUserId())) { throw new Exception('not subscribed'); } else { if (isset($_REQUEST['sub']) && !$room->userIsInPrivateRoom($_REQUEST['sub'], $chat_user->getUserId())) { $response = json_encode(array('success' => false, 'reason' => 'not subscribed to private room')); echo json_encode($response); exit; } } } $scope = $room->getRoomId(); $params = array(); if ($recipient = $_REQUEST['recipient']) { $params['recipients'] = join(',', array_unique(array($user_id, $recipient))); $params['recipient_names'] = implode(',', array($chat_user->getUsername(), $_REQUEST['recipient_name'])); $params['public'] = isset($_REQUEST['public']) ? (int) $_REQUEST['public'] : 0; } else { $params['public'] = 1; } if ($_REQUEST['sub']) { $params['sub'] = (int) $_REQUEST['sub']; } $messageObject = $this->buildMessage(ilUtil::stripSlashes($_REQUEST['message']), $params, $chat_user); $message = json_encode($messageObject); $params = array_merge($params, array('message' => $message)); //print_r($params);exit; $query = http_build_query($params); $connector = $this->gui->getConnector(); $response = $connector->post($scope, $query); $responseObject = json_decode($response); if ($responseObject->success == true) { $room->addHistoryEntry($messageObject, $recipient, $publicMessage); } echo $response; exit; }
/** * @param int $invited_id */ private function inviteById($invited_id) { /** * @var $ilUser ilObjUser * @var $ilCtrl ilCtrl */ global $ilUser, $ilCtrl; if (!ilChatroom::checkUserPermissions('read', $this->gui->ref_id)) { $ilCtrl->setParameterByClass('ilrepositorygui', 'ref_id', ROOT_FOLDER_ID); $ilCtrl->redirectByClass('ilrepositorygui', ''); } $room = ilChatroom::byObjectId($this->gui->object->getId()); $chat_user = new ilChatroomUser($ilUser, $room); $user_id = $chat_user->getUserId(); if (!$room) { $response = json_encode(array('success' => false, 'reason' => 'unkown room')); echo json_encode($response); exit; } else { if ($_REQUEST['sub'] && !$room->isOwnerOfPrivateRoom($user_id, $_REQUEST['sub'])) { $response = json_encode(array('success' => false, 'reason' => 'not owner of private room')); echo json_encode($response); exit; } } $connector = $this->gui->getConnector(); $result = $connector->inviteToPrivateRoom($room, $_REQUEST['sub'], $ilUser, $invited_id); $room->sendInvitationNotification($this->gui, $chat_user, $invited_id, (int) $_REQUEST['sub']); echo json_encode($result); exit; }
public function executeDefault($method) { global $tpl, $ilUser, $ilCtrl, $lng, $ilAccess; $room = ilChatroom::byObjectId($this->gui->object->getId()); $chat_user = new ilChatroomUser($ilUser, $room); $result = new stdClass(); $result->users = $room->getConnectedUsers(); $result->private_rooms = $room->getActivePrivateRooms($ilUser->getId()); $result->userinfo = array('moderator' => $ilAccess->checkAccess('moderate', '', $_GET['ref_id']), 'userid' => $chat_user->getUserId()); $smileys = array(); include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php'; $smileys_array = ilChatroomSmilies::_getSmilies(); foreach ($smileys_array as $smiley_array) { foreach ($smiley_array as $key => $value) { if ($key == 'smiley_keywords') { $new_keys = explode("\n", $value); } if ($key == 'smiley_fullpath') { $new_val = $value; } } foreach ($new_keys as $new_key) { $smileys[$new_key] = $new_val; } } $result->smileys = $smileys; echo json_encode($result); exit; }
/** * Prepares and returns $userInfo using given $user object. * * @param ilChatroomUser $user * @return stdClass */ public function getPersonalInformation(ilChatroomUser $user) { $userInfo = new stdClass(); $userInfo->username = $user->getUsername(); $userInfo->id = $user->getUserId(); return $userInfo; }
/** * Prepares and displays history period form by day. * * @global ilLanguage $lng * @global ilCtrl2 $ilCtrl * @global ilObjUser $ilUser */ public function byDay($export = false) { global $lng, $ilCtrl, $ilUser, $tpl; $room = ilChatroom::byObjectId($this->gui->object->getId()); $tpl->addJavaScript('./Services/Form/js/date_duration.js'); $scope = $room->getRoomId(); $chat_user = new ilChatroomUser($ilUser, $room); $formFactory = new ilChatroomFormFactory(); $durationForm = $formFactory->getPeriodForm(); $durationForm->setTitle($lng->txt('history_byday_title')); $durationForm->addCommandButton('history-byDayExport', $lng->txt('export')); $durationForm->addCommandButton('history-byDay', $lng->txt('show')); $durationForm->setFormAction($ilCtrl->getFormAction($this->gui), 'history-byDay'); if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') { $durationForm->checkInput(); $period = $durationForm->getItemByPostVar('timeperiod'); $messages = $room->getHistory($from = $period->getStart(), $to = $period->getEnd(), $chat_user->getUserId(), isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0); } else { $from = new ilDateTime(time() - 60 * 60, IL_CAL_UNIX); $to = new ilDateTime(time(), IL_CAL_UNIX); $period = $durationForm->getItemByPostVar('timeperiod'); $period->setStart($from); $period->setEnd($to); $messages = $room->getHistory($from, $to, $chat_user->getUserId(), isset($_REQUEST['scope']) ? $_REQUEST['scope'] : 0); } $psessions = $room->getPrivateRoomSessions($from, $to, $chat_user->getUserId(), $scope); $this->showMessages($messages, $durationForm, $export, $psessions, $from, $to); }
public function addPrivateRoom($title, ilChatroomUser $owner, $settings) { global $ilDB; $nextId = $ilDB->nextId('chatroom_prooms'); $ilDB->insert(self::$privateRoomsTable, array('proom_id' => array('integer', $nextId), 'parent_id' => array('integer', $this->roomId), 'title' => array('text', $title), 'owner' => array('integer', $owner->getUserId()), 'created' => array('integer', time()), 'is_public' => array('integer', $settings['public']))); return $nextId; }
/** * @param ilChatroom $room * @param string $title * @param ilChatroomUser $owner * @return mixed */ public function createPrivateRoom(ilChatroom $room, $title, ilChatroomUser $owner) { $settings = array('public' => false); $params['user'] = $owner->getUserId(); $params['id'] = $room->addPrivateRoom($title, $owner, $settings); $query = http_build_query($params); $response = $this->sendCreatePrivateRoom($room->getRoomId(), $query); $responseObject = json_decode($response); $return = $responseObject; if ($responseObject->success == true) { $message = json_encode(array('type' => 'private_room_created', 'timestamp' => date('c'), 'public' => 0, 'title' => $title, 'id' => $responseObject->id, 'proom_id' => $responseObject->id, 'owner' => $owner->getUserId())); $result = $this->sendMessage($room->getRoomId(), $message, array('public' => 0, 'recipients' => $owner->getUserId())); $params = array(); $params['user'] = $owner->getUserId(); $params['sub'] = $responseObject->id; $query = http_build_query($params); $response = $this->enterPrivateRoom($room->getRoomId(), $query); $room->subscribeUserToPrivateRoom($params['sub'], $params['user']); $message = json_encode(array('type' => 'private_room_entered', 'user' => $owner->getUserId(), 'timestamp' => date('c'), 'sub' => $responseObject->id)); $this->sendMessage($room->getRoomId(), $message); } return $responseObject; }
/** * Instantiates stdClass, sets $data->user, $data->message, $data->public * and $data->recipients using given $chat_user, $messageString and * $params and returns $data. * * @param string $messageString * @param array $params * @param ilChatroomUser $chat_user * @return stdClass */ private function buildMessage($messageString, $params, ilChatroomUser $chat_user) { $data = new stdClass(); $data->user = $chat_user->getUserId(); //$this->gui->object->getPersonalInformation( $chat_user ); $data->title = $params['title']; $data->timestamp = date('c'); $data->type = 'private_room_created'; return $data; }
/** * Chatroom and Chatuser get prepared before $this->showRoom method * is called. If custom usernames are allowed, $this->showNameSelection * method is called if user isn't already registered in the Chatroom. * @param string $method */ public function executeDefault($method) { /** * @var $ilUser ilObjUser * @var $lng ilLanguage * @var $ilCtrl ilCtrl */ global $ilUser, $lng, $ilCtrl; include_once 'Modules/Chatroom/classes/class.ilChatroom.php'; ilChatroom::checkUserPermissions('read', $this->gui->ref_id); $this->gui->switchToVisibleMode(); $this->setupTemplate(); $chatSettings = new ilSetting('chatroom'); if (!$chatSettings->get('chat_enabled')) { $ilCtrl->redirect($this->gui, 'settings-general'); exit; } $room = ilChatroom::byObjectId($this->gui->object->getId()); if (!$room->getSetting('allow_anonymous') && $ilUser->isAnonymous()) { $this->cancelJoin($lng->txt('anonymous_not_allowed')); return; } $chat_user = new ilChatroomUser($ilUser, $room); if ($room->getSetting('allow_custom_usernames')) { if ($room->isSubscribed($chat_user->getUserId())) { $chat_user->setUsername($chat_user->getUsername()); $this->showRoom($room, $chat_user); } else { $this->showNameSelection($chat_user); } } else { $chat_user->setUsername($ilUser->getLogin()); $this->showRoom($room, $chat_user); } }