/**
  * Renders shortcode: [wise-chat-channel-stats]
  *
  * @param array $attributes
  * @return string
  */
 public function getRenderedChannelStatsShortcode($attributes)
 {
     if (!is_array($attributes)) {
         $attributes = array();
     }
     $attributes['channel'] = $this->service->getValidChatChannelName(array_key_exists('channel', $attributes) ? $attributes['channel'] : '');
     $channel = $this->channelsDAO->getByName($attributes['channel']);
     if ($channel !== null) {
         $this->options->replaceOptions($attributes);
         $this->messagesService->startUpMaintenance($channel);
         return $this->renderer->getRenderedChannelStats($channel);
     } else {
         return 'ERROR: channel does not exist';
     }
 }
Example #2
0
 /**
  * Returns rendered message content.
  *
  * @param WiseChatMessage $message
  *
  * @return string HTML source
  */
 private function getRenderedMessageContent($message)
 {
     $formattedMessage = htmlspecialchars($message->getText(), ENT_QUOTES, 'UTF-8');
     /** @var WiseChatLinksPostFilter $linksFilter */
     $linksFilter = WiseChatContainer::get('rendering/filters/post/WiseChatLinksPostFilter');
     $formattedMessage = $linksFilter->filter($formattedMessage, $this->options->isOptionEnabled('allow_post_links'));
     /** @var WiseChatAttachmentsPostFilter $attachmentsFilter */
     $attachmentsFilter = WiseChatContainer::get('rendering/filters/post/WiseChatAttachmentsPostFilter');
     $formattedMessage = $attachmentsFilter->filter($formattedMessage, $this->options->isOptionEnabled('enable_attachments_uploader'), $this->options->isOptionEnabled('allow_post_links'));
     /** @var WiseChatImagesPostFilter $imagesFilter */
     $imagesFilter = WiseChatContainer::get('rendering/filters/post/WiseChatImagesPostFilter');
     $formattedMessage = $imagesFilter->filter($formattedMessage, $this->options->isOptionEnabled('allow_post_images'), $this->options->isOptionEnabled('allow_post_links'));
     /** @var WiseChatYouTubePostFilter $youTubeFilter */
     $youTubeFilter = WiseChatContainer::get('rendering/filters/post/WiseChatYouTubePostFilter');
     $formattedMessage = $youTubeFilter->filter($formattedMessage, $this->options->isOptionEnabled('enable_youtube'), $this->options->isOptionEnabled('allow_post_links'), $this->options->getIntegerOption('youtube_width', 186), $this->options->getIntegerOption('youtube_height', 105));
     if ($this->options->isOptionEnabled('enable_twitter_hashtags')) {
         /** @var WiseChatHashtagsPostFilter $hashTagsFilter */
         $hashTagsFilter = WiseChatContainer::get('rendering/filters/post/WiseChatHashtagsPostFilter');
         $formattedMessage = $hashTagsFilter->filter($formattedMessage);
     }
     if ($this->options->isOptionEnabled('emoticons_enabled', true)) {
         /** @var WiseChatEmoticonsFilter $emoticonsFilter */
         $emoticonsFilter = WiseChatContainer::get('rendering/filters/post/WiseChatEmoticonsFilter');
         $formattedMessage = $emoticonsFilter->filter($formattedMessage);
     }
     if ($this->options->isOptionEnabled('multiline_support')) {
         $formattedMessage = str_replace("\n", '<br />', $formattedMessage);
     }
     return $formattedMessage;
 }
Example #3
0
 /**
  * @return string
  */
 private function getEndpointBase()
 {
     $endpointBase = get_site_url() . '/wp-admin/admin-ajax.php';
     if ($this->options->getEncodedOption('ajax_engine', null) === 'lightweight') {
         $endpointBase = get_site_url() . '/wp-content/plugins/wise-chat/src/endpoints/';
     }
     return $endpointBase;
 }
 public function __construct()
 {
     WiseChatContainer::load('model/WiseChatBan');
     $this->options = WiseChatOptions::getInstance();
     $this->bansDAO = WiseChatContainer::getLazy('dao/WiseChatBansDAO');
     $this->messagesDAO = WiseChatContainer::getLazy('dao/WiseChatMessagesDAO');
     $this->channelUsersDAO = WiseChatContainer::getLazy('dao/WiseChatChannelUsersDAO');
     $this->usersDAO = WiseChatContainer::getLazy('dao/user/WiseChatUsersDAO');
 }
 private function addUsersListWidthDefinition()
 {
     if ($this->options->isOptionNotEmpty('users_list_width')) {
         $width = $this->options->getIntegerOption('users_list_width');
         if ($width > 1 && $width < 99) {
             $this->addRawDefinition('.wcUsersList', 'width', $width . '%');
             $this->addRawDefinition('.wcMessages', 'width', 100 - $width - 1 . '%');
         }
     }
 }
Example #6
0
 public static function getInstance()
 {
     if (self::$instance === null) {
         $instance = new WiseChatOptions();
         $instance->baseDir = plugin_dir_url(dirname(__FILE__));
         $instance->pluginBaseDir = dirname(dirname(__FILE__));
         self::$instance = $instance;
     }
     return self::$instance;
 }
Example #7
0
 private function verifyCheckSum()
 {
     $checksum = $this->getParam('checksum');
     if ($checksum !== null) {
         $decoded = unserialize(WiseChatCrypt::decrypt(base64_decode($checksum)));
         if (is_array($decoded)) {
             $this->options->replaceOptions($decoded);
         }
     }
 }
Example #8
0
 /**
  * Determines whether current user has given right.
  *
  * @param string $rightName
  *
  * @return boolean
  */
 public function hasCurrentWpUserRight($rightName)
 {
     $wpUser = $this->getCurrentWpUser();
     if ($wpUser !== null) {
         $targetRole = $this->options->getOption("permission_{$rightName}_role", 'administrator');
         if (is_array($wpUser->roles) && in_array($targetRole, $wpUser->roles) || current_user_can("wise_chat_{$rightName}")) {
             return true;
         }
     }
     return false;
 }
Example #9
0
 /**
  * Returns all filters
  *
  * @param boolean $htmlEscape
  *
  * @return array
  */
 public function getAll($htmlEscape = false)
 {
     $filters = $this->options->getOption('filters', array());
     if (!is_array($filters)) {
         return array();
     }
     $filtersOut = array();
     foreach ($filters as $key => $filter) {
         $type = $filter['type'];
         $replace = $filter['replace'];
         $with = $filter['with'];
         $label = $this->types[$type] . (in_array($type, array('text', 'regexp')) ? ': ' . $replace : '');
         if ($htmlEscape) {
             $replace = htmlentities($replace, ENT_QUOTES, 'UTF-8');
             $with = htmlentities($with, ENT_QUOTES, 'UTF-8');
             $label = htmlentities($label, ENT_QUOTES, 'UTF-8');
         }
         $filtersOut[] = array('id' => $key, 'replace' => $replace, 'with' => $with, 'label' => $label, 'type' => $type);
     }
     return $filtersOut;
 }
Example #10
0
 /**
  * Sets a new name for current user.
  *
  * @param string $userName A new username to set
  *
  * @return string New username
  * @throws Exception On validation error
  */
 public function changeUserName($userName)
 {
     if (!$this->options->isOptionEnabled('allow_change_user_name') || $this->usersDAO->getCurrentWpUser() !== null || !$this->authentication->isAuthenticated()) {
         throw new Exception('Unsupported operation');
     }
     $userName = $this->authentication->validateUserName($userName);
     $user = $this->authentication->getUser();
     // set new username and refresh it:
     $user->setName($userName);
     $this->usersDAO->save($user);
     $this->refreshNewUserName($user);
     $this->authentication->setOriginalUserName($userName);
     return $userName;
 }
 /**
  * Generates thumbnail image for given attachment and returns URL of the thumbnail.
  *
  * @param string $attachmentId
  *
  * @return null|string
  * @throws Exception
  */
 private function generateThumbnail($attachmentId)
 {
     $imagePath = get_attached_file($attachmentId);
     $imageThPath = preg_replace('/\\.([a-zA-Z]+)$/', '-th.$1', $imagePath);
     $image = wp_get_image_editor($imagePath);
     if (!is_wp_error($image)) {
         $image->resize($this->options->getIntegerOption('images_thumbnail_width_limit', 60), $this->options->getIntegerOption('images_thumbnail_height_limit', 60), true);
         $image->save($imageThPath);
     } else {
         $this->logError('Error creating thumbnail: ' . $image->get_error_message());
         throw new Exception('The thumbnail of the image could not be generated');
     }
     $imageUrl = wp_get_attachment_url($attachmentId);
     $imageThUrl = preg_replace('/\\.([a-zA-Z]+)$/', '-th.$1', $imageUrl);
     return $imageThUrl;
 }
 /**
  * @param string $userName
  *
  * @return WiseChatUser
  */
 private function createUserAndSave($userName)
 {
     WiseChatContainer::load('model/WiseChatUser');
     // construct username and user object:
     $user = new WiseChatUser();
     $user->setName($userName);
     $user->setSessionId($this->userSessionDAO->getSessionId());
     $user->setIp($this->getRemoteAddress());
     if ($this->options->isOptionEnabled('collect_user_stats', true)) {
         $this->fillWithGeoDetails($user);
     }
     // save user in DB and in the session:
     $this->usersDAO->save($user);
     $this->userSessionDAO->set(self::SESSION_KEY_USER_ID, $user->getId());
     return $user;
 }
Example #13
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;
 }
Example #14
0
 /**
  * Callback method for displaying list of checkboxes with a hint.
  *
  * @param array $args Array containing keys: id, name, hint, options
  *
  * @return null
  */
 public function checkboxesCallback($args)
 {
     $id = $args['id'];
     $hint = $args['hint'];
     $options = $args['options'];
     $defaults = $this->getDefaultValues();
     $defaultValue = array_key_exists($id, $defaults) ? $defaults[$id] : '';
     $values = $this->options->getOption($id, $defaultValue);
     $parentId = $this->getFieldParent($id);
     $html = '';
     foreach ($options as $key => $value) {
         $html .= sprintf('<label><input type="checkbox" value="%s" name="%s[%s][]" %s %s data-parent-field="%s" />%s</label>&nbsp;&nbsp; ', $key, WiseChatOptions::OPTIONS_NAME, $id, in_array($value, $values) ? 'checked="1"' : '', $parentId != null && !$this->options->isOptionEnabled($parentId, false) ? 'disabled="1"' : '', $parentId != null ? $parentId : '', $value);
     }
     printf($html);
     if (strlen($hint) > 0) {
         printf('<p class="description">%s</p>', $hint);
     }
 }
 /**
  * Prepares two input parameters for str_replace function.
  *
  * @return array
  */
 private function prepareReplacementArrays()
 {
     $searchArray = array();
     $replaceArray = array();
     $options = WiseChatOptions::getInstance();
     foreach (self::$emoticons as $emoticon) {
         $filePath = $options->getEmoticonsBaseURL() . '/' . $emoticon . '.png';
         $imgTag = sprintf("<img src='%s' alt='%s' class='wcEmoticon' />", $filePath, htmlspecialchars($emoticon, ENT_QUOTES, 'UTF-8'));
         $searchArray[] = htmlentities('<' . $emoticon . '>');
         $replaceArray[] = $imgTag;
         if (array_key_exists($emoticon, self::$aliases)) {
             foreach (self::$aliases[$emoticon] as $alias) {
                 $searchArray[] = $alias;
                 $replaceArray[] = $imgTag;
             }
         }
     }
     return array($searchArray, $replaceArray);
 }
 /**
  * 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);
         }
     }
 }
 /**
  * Returns information about the temporary file but only if it is an image file.
  *
  * @param string $fileName Name of the file
  *
  * @return null|array
  */
 private function getTempFileImageInfo($fileName)
 {
     if (file_exists($this->tempFileName)) {
         $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
         $allowedFormats = $this->getAllowedFormats();
         if (!in_array($extension, $allowedFormats)) {
             $this->logError('Unsupported file type: ' . $extension);
             return null;
         }
         $fileSize = filesize($this->tempFileName);
         if ($fileSize > $this->options->getIntegerOption('attachments_size_limit', 3145728)) {
             $this->logError('Attachment is to big: ' . $fileSize . ' bytes');
             return null;
         }
         $fileName = date('Ymd-His') . '-' . uniqid(rand()) . '.' . $extension;
         return $_FILES[self::UPLOAD_FILE_NAME] = array('name' => $fileName, 'type' => 'application/octet-stream', 'tmp_name' => $this->tempFileName, 'error' => 0, 'size' => $fileSize);
     }
     $this->logError('The file does not exist');
     return null;
 }
Example #18
0
 public static function uninstall()
 {
     if (!current_user_can('activate_plugins')) {
         return;
     }
     check_admin_referer('bulk-plugins');
     global $wpdb;
     // remove all messages and related images:
     /** @var WiseChatMessagesService $messagesService */
     $messagesService = WiseChatContainer::get('services/WiseChatMessagesService');
     $messagesService->deleteAll();
     $tableName = self::getMessagesTable();
     $sql = "DROP TABLE IF EXISTS {$tableName};";
     $wpdb->query($sql);
     $tableName = self::getBansTable();
     $sql = "DROP TABLE IF EXISTS {$tableName};";
     $wpdb->query($sql);
     $tableName = self::getActionsTable();
     $sql = "DROP TABLE IF EXISTS {$tableName};";
     $wpdb->query($sql);
     $tableName = self::getChannelUsersTable();
     $sql = "DROP TABLE IF EXISTS {$tableName};";
     $wpdb->query($sql);
     $tableName = self::getChannelsTable();
     $sql = "DROP TABLE IF EXISTS {$tableName};";
     $wpdb->query($sql);
     $tableName = self::getUsersTable();
     $sql = "DROP TABLE IF EXISTS {$tableName};";
     $wpdb->query($sql);
     WiseChatOptions::getInstance()->dropAllOptions();
 }
Example #19
0
 public function __construct()
 {
     WiseChatContainer::load('model/WiseChatAction');
     $this->options = WiseChatOptions::getInstance();
     $this->table = WiseChatInstaller::getActionsTable();
 }
Example #20
0
 public function __construct()
 {
     $this->options = WiseChatOptions::getInstance();
 }
Example #21
0
 public function __construct()
 {
     WiseChatContainer::load('model/WiseChatChannel');
     $this->options = WiseChatOptions::getInstance();
 }
Example #22
0
 private function getThemeProperty($property)
 {
     $theme = $this->options->getEncodedOption('theme', '');
     return self::$themesSettings[$theme][$property];
 }