Esempio n. 1
0
 /**
  * Returns array of SQL WHERE conditions based on given criteria.
  *
  * @param WiseChatMessagesCriteria $criteria
  *
  * @return array
  */
 private function getSQLConditionsByCriteria($criteria)
 {
     $conditions = array();
     if ($criteria->getChannelName() !== null) {
         $channelName = addslashes($criteria->getChannelName());
         $conditions[] = "channel = '{$channelName}'";
     }
     if ($criteria->getUserId() !== null) {
         $conditions[] = "chat_user_id = " . intval($criteria->getUserId());
     }
     if ($criteria->getOffsetId() !== null) {
         $conditions[] = "id > " . intval($criteria->getOffsetId());
     }
     if (!$criteria->isIncludeAdminMessages()) {
         $conditions[] = "admin = 0";
     }
     if ($criteria->getMaximumTime() !== null) {
         $conditions[] = "time < " . intval($criteria->getMaximumTime());
     }
     if ($criteria->getMinimumTime() !== null) {
         $conditions[] = "time >= " . intval($criteria->getMinimumTime());
     }
     if ($criteria->getIp() !== null) {
         $ip = addslashes($criteria->getIp());
         $conditions[] = "ip = '{$ip}'";
     }
     if (count($conditions) == 0) {
         $conditions[] = '1 = 1';
     }
     return $conditions;
 }
Esempio n. 2
0
 /**
  * Refreshes username after setting a new one.
  *
  * @param WiseChatUser $user
  *
  * @return null
  */
 private function refreshNewUserName($user)
 {
     WiseChatContainer::load('dao/criteria/WiseChatMessagesCriteria');
     $this->refreshUserName($user);
     $this->messagesDAO->updateUserNameByCriteria($user->getName(), WiseChatMessagesCriteria::build()->setUserId($user->getId()));
     /** @var WiseChatRenderer $renderer */
     $renderer = WiseChatContainer::get('rendering/WiseChatRenderer');
     $criteria = new WiseChatMessagesCriteria();
     $criteria->setUserId($user->getId());
     $messages = $this->messagesDAO->getAllByCriteria($criteria);
     if (count($messages) > 0) {
         $messagesIds = array();
         $renderedUserName = null;
         foreach ($messages as $message) {
             $messagesIds[] = $message->getId();
             if ($renderedUserName === null) {
                 $renderedUserName = $renderer->getRenderedUserName($message);
             }
         }
         $this->actions->publishAction('replaceUserNameInMessages', array('renderedUserName' => $renderedUserName, 'messagesIds' => $messagesIds));
     }
 }
 /**
  * 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);
         }
     }
 }