Beispiel #1
0
 /**
  * Returns actions of the user and beginning from specified ID and (optionally) by user.
  * The result array is JSON ready. Some of the fields are hidden and command is decoded to array.
  *
  * @param integer $fromId Offset
  * @param WiseChatUser $user Actions directed to the specific user
  *
  * @return array
  */
 public function getJSONReadyActions($fromId, $user)
 {
     $actions = $this->actionsDAO->getBeginningFromIdAndByUser($fromId, $user !== null ? $user->getId() : null);
     $actionsCommands = array();
     foreach ($actions as $action) {
         $actionsCommands[] = array('id' => $action->getId(), 'command' => $action->getCommand());
     }
     return $actionsCommands;
 }
 /**
  * Publishes a message in the given channel of the chat and returns it.
  *
  * @param WiseChatUser $user Author of the message
  * @param WiseChatChannel $channel A channel to publish in
  * @param string $text Content of the message
  * @param boolean $isAdmin Indicates whether to mark the message as admin-owned
  *
  * @return WiseChatMessage|null
  * @throws Exception On validation error
  */
 public function addMessage($user, $channel, $text, $isAdmin = false)
 {
     $text = trim($text);
     $filteredMessage = $text;
     // basic validation:
     if ($user === null) {
         throw new Exception('User cannot be null');
     }
     if ($channel === null) {
         throw new Exception('Channel cannot be null');
     }
     if ($this->bansService->isIpAddressBanned($user->getIp())) {
         throw new Exception($this->options->getOption('message_error_3', 'You were banned from posting messages'));
     }
     // use bad words filtering:
     if ($this->options->isOptionEnabled('filter_bad_words')) {
         WiseChatContainer::load('rendering/filters/pre/WiseChatFilter');
         $badWordsFilterReplacement = $this->options->getOption('bad_words_replacement_text');
         $filteredMessage = WiseChatFilter::filter($filteredMessage, strlen($badWordsFilterReplacement) > 0 ? $badWordsFilterReplacement : null);
     }
     // auto-ban feature:
     if ($this->options->isOptionEnabled('enable_autoban') && $filteredMessage != $text) {
         $counter = $this->abuses->incrementAndGetAbusesCounter();
         $threshold = $this->options->getIntegerOption('autoban_threshold', 3);
         if ($counter >= $threshold && $threshold > 0) {
             $duration = $this->options->getIntegerOption('autoban_duration', 1440);
             $this->bansService->banIpAddress($user->getIp(), $this->bansService->getDurationFromString($duration . 'm'));
             $this->abuses->clearAbusesCounter();
         }
     }
     // flood prevention feature:
     if ($this->options->isOptionEnabled('enable_flood_control')) {
         $floodControlThreshold = $this->options->getIntegerOption('flood_control_threshold', 200);
         $floodControlTimeFrame = $this->options->getIntegerOption('flood_control_time_frame', 1);
         if ($floodControlThreshold > 0 && $floodControlTimeFrame > 0) {
             $messagesAmount = $this->messagesDAO->getNumberByCriteria(WiseChatMessagesCriteria::build()->setIp($user->getIp())->setMinimumTime(time() - $floodControlTimeFrame * 60));
             if ($messagesAmount > $floodControlThreshold) {
                 $duration = $this->options->getIntegerOption('flood_control_ban_duration', 1440);
                 $this->bansService->banIpAddress($user->getIp(), $this->bansService->getDurationFromString($duration . 'm'));
             }
         }
     }
     // go through the custom filters:
     $filterChain = WiseChatContainer::get('services/WiseChatFilterChain');
     $filteredMessage = $filterChain->filter($filteredMessage);
     // cut the message:
     $messageMaxLength = $this->options->getIntegerOption('message_max_length', 100);
     if ($messageMaxLength > 0) {
         $filteredMessage = substr($filteredMessage, 0, $messageMaxLength);
     }
     // convert images and links into proper shortcodes and download images (if enabled):
     /** @var WiseChatLinksPreFilter $linksPreFilter */
     $linksPreFilter = WiseChatContainer::get('rendering/filters/pre/WiseChatLinksPreFilter');
     $filteredMessage = $linksPreFilter->filter($filteredMessage, $this->options->isOptionEnabled('allow_post_images'), $this->options->isOptionEnabled('enable_youtube'));
     $message = new WiseChatMessage();
     $message->setTime(time());
     $message->setAdmin($isAdmin);
     $message->setUserName($user->getName());
     $message->setUserId($user->getId());
     $message->setText($filteredMessage);
     $message->setChannelName($channel->getName());
     $message->setIp($user->getIp());
     if ($user->getWordPressId() !== null) {
         $message->setWordPressUserId($user->getWordPressId());
     }
     $message = $this->messagesDAO->save($message);
     // mark attachments created by the links pre-filter:
     $createdAttachments = $linksPreFilter->getCreatedAttachments();
     if (count($createdAttachments) > 0) {
         $this->attachmentsService->markAttachmentsWithDetails($createdAttachments, $channel->getName(), $message->getId());
     }
     return $message;
 }
 /**
  * @param WiseChatUser $user
  */
 private function fillWithGeoDetails($user)
 {
     /** @var WiseChatGeoService $geoService */
     $geoService = WiseChatContainer::get('services/WiseChatGeoService');
     $geoDetails = $geoService->getGeoDetails($this->getRemoteAddress());
     if ($geoDetails !== null) {
         $geoDetailsArray = $geoDetails->toArray();
         foreach ($geoDetailsArray as $key => $value) {
             $user->setDataProperty($key, $value);
         }
     }
 }
Beispiel #4
0
 /**
  * Converts raw object into WiseChatUser object.
  *
  * @param stdClass $rawUserData
  *
  * @return WiseChatUser
  */
 private function populateUserData($rawUserData)
 {
     $user = new WiseChatUser();
     if (strlen($rawUserData->id) > 0) {
         $user->setId(intval($rawUserData->id));
     }
     if (strlen($rawUserData->wp_id) > 0) {
         $user->setWordPressId(intval($rawUserData->wp_id));
     }
     $user->setName($rawUserData->name);
     $user->setSessionId($rawUserData->session_id);
     $user->setIp($rawUserData->ip);
     $user->setData(json_decode($rawUserData->data, true));
     return $user;
 }