Exemplo n.º 1
0
 /**
  * Marks the current user as authorized for given channel.
  *
  * @param WiseChatChannel $channel
  *
  * @return null
  */
 public function markAuthorizedForChannel($channel)
 {
     $grants = $this->userSessionDAO->get(self::SESSION_KEY_USER_CHANNEL_AUTHORIZATION);
     if (!is_array($grants)) {
         $grants = array();
     }
     $grants[$channel->getId()] = true;
     $this->userSessionDAO->set(self::SESSION_KEY_USER_CHANNEL_AUTHORIZATION, $grants);
 }
Exemplo n.º 2
0
 /**
  * Bans an user by message ID.
  *
  * @param integer $messageId
  * @param WiseChatChannel $channel
  * @param string $durationString
  *
  * @throws Exception If the message or user was not found
  */
 public function banByMessageId($messageId, $channel, $durationString = '1d')
 {
     $message = $this->messagesDAO->get($messageId);
     if ($message === null) {
         throw new Exception('Message was not found');
     }
     $channelUser = $this->channelUsersDAO->getByUserIdAndChannelId($message->getUserId(), $channel->getId());
     if ($channelUser !== null) {
         $user = $this->usersDAO->get($message->getUserId());
         if ($user !== null) {
             $duration = $this->getDurationFromString($durationString);
             $this->banIpAddress($user->getIp(), $duration);
             return;
         }
     }
     throw new Exception('User was not found in this channel');
 }
Exemplo n.º 3
0
 /**
  * Determines if the number of channels that current user participates has been reached.
  *
  * @param WiseChatChannel $channel
  *
  * @return boolean
  */
 public function isChatChannelsLimitReached($channel)
 {
     $limit = $this->options->getIntegerOption('channels_limit', 0);
     if ($limit > 0) {
         $this->userService->refreshChannelUsersData();
         $amountOfChannels = $this->channelUsersDAO->getAmountOfActiveBySessionId(session_id());
         $user = $this->authentication->getUser();
         if ($user === null || $channel === null || $this->channelUsersDAO->getActiveByUserIdAndChannelId($user->getId(), $channel->getId()) === null) {
             $amountOfChannels++;
         }
         if ($amountOfChannels > $limit) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * Converts raw object into WiseChatChannel object.
  *
  * @param stdClass $rawChannelData
  *
  * @return WiseChatChannel
  */
 private function populateChannelData($rawChannelData)
 {
     $channel = new WiseChatChannel();
     if ($rawChannelData->id > 0) {
         $channel->setId(intval($rawChannelData->id));
     }
     $channel->setName($rawChannelData->name);
     $channel->setPassword($rawChannelData->password);
     return $channel;
 }
Exemplo n.º 5
0
 /**
  * Marks presence of the current user in the given channel.
  *
  * @param WiseChatChannel $channel
  *
  * @return null
  */
 private function markPresenceInChannel($channel)
 {
     $user = $this->authentication->getUser();
     if ($user !== null) {
         $channelUser = $this->channelUsersDAO->getByUserIdAndChannelId($user->getId(), $channel->getId());
         if ($channelUser === null) {
             $channelUser = new WiseChatChannelUser();
             $channelUser->setActive(true);
             $channelUser->setLastActivityTime(time());
             $channelUser->setUserId($user->getId());
             $channelUser->setChannelId($channel->getId());
             $this->channelUsersDAO->save($channelUser);
         } else {
             $channelUser->setActive(true);
             $channelUser->setLastActivityTime(time());
             $this->channelUsersDAO->save($channelUser);
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Returns rendered channel statistics.
  *
  * @param WiseChatChannel $channel
  *
  * @return string HTML source
  */
 public function getRenderedChannelStats($channel)
 {
     if ($channel === null) {
         return 'ERROR: channel does not exist';
     }
     $variables = array('channel' => $channel->getName(), 'messages' => $this->messagesService->getNumberByChannelName($channel->getName()), 'users' => $this->channelUsersDAO->getAmountOfUsersInChannel($channel->getId()));
     return $this->getTemplatedString($variables, $this->options->getOption('template', 'ERROR: TEMPLATE NOT SPECIFIED'));
 }
Exemplo n.º 7
0
 /**
  * @param WiseChatChannel $channel
  * @throws WiseChatUnauthorizedAccessException
  */
 private function checkChannelAuthorization($channel)
 {
     if ($channel !== null && strlen($channel->getPassword()) > 0 && !$this->authorization->isUserAuthorizedForChannel($channel)) {
         throw new WiseChatUnauthorizedAccessException('Not authorized in this channel');
     }
 }
Exemplo n.º 8
0
 /**
  * Deletes old messages according to the plugin's settings.
  * Images connected to the messages (WordPress Media Library attachments) are also deleted.
  *
  * @param WiseChatChannel $channel
  *
  * @throws Exception
  */
 private function deleteOldMessages($channel)
 {
     $minutesThreshold = $this->options->getIntegerOption('auto_clean_after', 0);
     if ($minutesThreshold > 0) {
         $criteria = new WiseChatMessagesCriteria();
         $criteria->setChannelName($channel->getName());
         $criteria->setIncludeAdminMessages(true);
         $criteria->setMaximumTime(time() - $minutesThreshold * 60);
         $messages = $this->messagesDAO->getAllByCriteria($criteria);
         $messagesIds = array();
         foreach ($messages as $message) {
             $messagesIds[] = $message->getId();
         }
         if (count($messagesIds) > 0) {
             $this->attachmentsService->deleteAttachmentsByMessageIds($messagesIds);
             $this->actions->publishAction('deleteMessages', array('ids' => $messagesIds));
             $this->messagesDAO->deleteAllByCriteria($criteria);
         }
     }
 }