/**
  * @dataProvider dataWithImages
  */
 public function testPositiveWithImages($input, $output)
 {
     WiseChatContainer::replace('services/user/WiseChatActions', new WiseChatActionsStub());
     WiseChatContainer::replace('services/WiseChatImagesService', new WiseChatImagesServiceStub());
     WiseChatContainer::replace('services/user/WiseChatAuthentication', new WiseChatAuthenticationStub());
     $linksPreFilter = new WiseChatLinksPreFilter();
     $this->assertEquals($output, $linksPreFilter->filter($input, true));
 }
 /**
  * WiseChatStatsShortcode constructor.
  */
 public function __construct()
 {
     $this->options = WiseChatOptions::getInstance();
     $this->service = WiseChatContainer::get('services/WiseChatService');
     $this->messagesService = WiseChatContainer::get('services/WiseChatMessagesService');
     $this->channelsDAO = WiseChatContainer::get('dao/WiseChatChannelsDAO');
     $this->renderer = WiseChatContainer::get('rendering/WiseChatRenderer');
 }
示例#3
0
 public function __construct()
 {
     WiseChatContainer::load('model/WiseChatMessage');
     WiseChatContainer::load('dao/criteria/WiseChatMessagesCriteria');
     $this->usersDAO = WiseChatContainer::get('dao/user/WiseChatUsersDAO');
     $this->channelsDAO = WiseChatContainer::get('dao/WiseChatChannelsDAO');
     $this->channelUsersDAO = WiseChatContainer::get('dao/WiseChatChannelUsersDAO');
     $this->table = WiseChatInstaller::getMessagesTable();
 }
示例#4
0
 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');
 }
示例#5
0
 public function __construct()
 {
     WiseChatContainer::load('model/WiseChatChannel');
     $this->options = WiseChatOptions::getInstance();
     $this->channelsDAO = WiseChatContainer::get('dao/WiseChatChannelsDAO');
     $this->usersDAO = WiseChatContainer::get('dao/user/WiseChatUsersDAO');
     $this->channelUsersDAO = WiseChatContainer::get('dao/WiseChatChannelUsersDAO');
     $this->userService = WiseChatContainer::get('services/user/WiseChatUserService');
     $this->authentication = WiseChatContainer::getLazy('services/user/WiseChatAuthentication');
     $this->authorization = WiseChatContainer::getLazy('services/user/WiseChatAuthorization');
 }
 /**
  * @param WiseChatChannel $channel
  * @param array $arguments
  */
 public function __construct($channel, $arguments)
 {
     $this->messagesDAO = WiseChatContainer::get('dao/WiseChatMessagesDAO');
     $this->bansDAO = WiseChatContainer::get('dao/WiseChatBansDAO');
     $this->usersDAO = WiseChatContainer::get('dao/user/WiseChatUsersDAO');
     $this->channelUsersDAO = WiseChatContainer::get('dao/WiseChatChannelUsersDAO');
     $this->authentication = WiseChatContainer::getLazy('services/user/WiseChatAuthentication');
     $this->bansService = WiseChatContainer::get('services/WiseChatBansService');
     $this->messagesService = WiseChatContainer::get('services/WiseChatMessagesService');
     $this->arguments = $arguments;
     $this->channel = $channel;
 }
 /**
  * Tokenizes command and returns command resolver.
  *
  * @param WiseChatChannel $channel Name of the channel
  * @param string $command The command
  *
  * @return WiseChatAbstractCommand
  */
 private function getCommandResolver($channel, $command)
 {
     try {
         $commandClassName = $this->getClassNameFromCommand($command);
         WiseChatContainer::load("commands/{$commandClassName}");
         $tokens = $this->getTokenizedCommand($command);
         array_shift($tokens);
         return new $commandClassName($channel, $tokens);
     } catch (Exception $e) {
         return null;
     }
 }
示例#8
0
 public function __construct()
 {
     $this->options = WiseChatOptions::getInstance();
     $this->channelsDAO = WiseChatContainer::get('dao/WiseChatChannelsDAO');
     $this->bansDAO = WiseChatContainer::get('dao/WiseChatBansDAO');
     $this->usersDAO = WiseChatContainer::get('dao/user/WiseChatUsersDAO');
     $this->messagesDAO = WiseChatContainer::get('dao/WiseChatMessagesDAO');
     $this->filtersDAO = WiseChatContainer::get('dao/WiseChatFiltersDAO');
     $this->actions = WiseChatContainer::getLazy('services/user/WiseChatActions');
     $this->bansService = WiseChatContainer::get('services/WiseChatBansService');
     $this->messagesService = WiseChatContainer::get('services/WiseChatMessagesService');
 }
 /**
  * Detects URLs in the text and converts them into shortcodes indicating either regular links or images.
  *
  * @param string $text HTML-encoded string
  * @param boolean $detectAndDownloadImages Whether to check and download images
  * @param boolean $detectYouTubeVideos
  *
  * @return string
  */
 public function filter($text, $detectAndDownloadImages, $detectYouTubeVideos = false)
 {
     $this->replacementOffset = 0;
     $this->createdAttachments = array();
     if (preg_match_all(self::URL_REGEXP, $text, $matches)) {
         if (count($matches) == 0) {
             return $text;
         }
         foreach ($matches[0] as $detectedURL) {
             $shortCode = null;
             $regularLink = false;
             $ytMatches = array();
             if ($detectAndDownloadImages && preg_match(self::URL_IMAGE_REGEXP, $detectedURL)) {
                 $imageUrl = $detectedURL;
                 if (!preg_match(self::URL_PROTOCOLS_REGEXP, $detectedURL)) {
                     $imageUrl = "http://" . $detectedURL;
                 }
                 try {
                     $result = $this->imagesService->downloadImage($imageUrl);
                     $this->createdAttachments[] = $result['id'];
                     $shortCode = WiseChatShortcodeConstructor::getImageShortcode($result['id'], $result['image'], $result['image-th'], $detectedURL);
                 } catch (Exception $ex) {
                     $regularLink = true;
                     $actions = WiseChatContainer::get('services/user/WiseChatActions');
                     $authentication = WiseChatContainer::get('services/user/WiseChatAuthentication');
                     $actions->publishAction('showErrorMessage', array('message' => $ex->getMessage()), $authentication->getUser());
                 }
             } elseif ($detectYouTubeVideos && preg_match(self::URL_YOUTUBE_REGEXP, $detectedURL, $ytMatches)) {
                 $movieId = array_pop($ytMatches);
                 $shortCode = WiseChatShortcodeConstructor::getYouTubeShortcode($movieId, $detectedURL);
             } elseif ($detectYouTubeVideos && preg_match(self::URL_YOUTUBE_REGEXP_2, $detectedURL, $ytMatches)) {
                 $movieId = array_pop($ytMatches);
                 $shortCode = WiseChatShortcodeConstructor::getYouTubeShortcode($movieId, $detectedURL);
             } else {
                 $regularLink = true;
             }
             if ($regularLink) {
                 $shortCode = sprintf('[link src="%s"]', $detectedURL);
             }
             if ($shortCode !== null) {
                 $text = $this->strReplaceFirst($detectedURL, $shortCode, $text);
             }
         }
     }
     return $text;
 }
示例#10
0
 public function widget($args, $instance)
 {
     extract($args, EXTR_SKIP);
     echo $before_widget;
     $wiseChat = WiseChatContainer::get('WiseChat');
     $channel = $instance['channel'];
     $options = $instance['options'];
     $parsedOptions = shortcode_parse_atts($options);
     if (is_array($parsedOptions)) {
         $parsedOptions['channel'] = $channel;
         echo $wiseChat->getRenderedShortcode($parsedOptions);
     } else {
         echo $wiseChat->getRenderedChat($channel);
     }
     echo $after_widget;
     $wiseChat->registerResources();
 }
示例#11
0
 /**
  * Returns geo details about the IP address.
  *
  * @param string $ipAddress
  *
  * @return WiseChatGeoDetails
  */
 public function getGeoDetails($ipAddress)
 {
     if (!function_exists('curl_init') || strlen($ipAddress) == 0 || $ipAddress == '127.0.0.1' || $ipAddress == '::1') {
         return null;
     }
     WiseChatContainer::load('model/WiseChatGeoDetails');
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_URL, 'http://www.geoplugin.net/json.gp?ip=' . urlencode($ipAddress));
     $data = curl_exec($curl);
     curl_close($curl);
     $rawData = json_decode($data);
     if ($rawData !== null && property_exists($rawData, 'geoplugin_status') && $rawData->geoplugin_status > 0) {
         $details = new WiseChatGeoDetails();
         if (property_exists($rawData, 'geoplugin_city')) {
             $details->setCity($rawData->geoplugin_city);
         }
         if (property_exists($rawData, 'geoplugin_regionCode')) {
             $details->setRegionCode($rawData->geoplugin_regionCode);
         }
         if (property_exists($rawData, 'geoplugin_countryCode')) {
             $details->setCountryCode($rawData->geoplugin_countryCode);
         }
         if (property_exists($rawData, 'geoplugin_countryName')) {
             $details->setCountry($rawData->geoplugin_countryName);
         }
         if (property_exists($rawData, 'geoplugin_continentCode')) {
             $details->setContinentCode($rawData->geoplugin_continentCode);
         }
         if (property_exists($rawData, 'geoplugin_latitude')) {
             $details->setLatitude($rawData->geoplugin_latitude);
         }
         if (property_exists($rawData, 'geoplugin_longitude')) {
             $details->setLongitude($rawData->geoplugin_longitude);
         }
         if (property_exists($rawData, 'geoplugin_regionName')) {
             $details->setRegion($rawData->geoplugin_regionName);
         }
         if (property_exists($rawData, 'geoplugin_currencyCode')) {
             $details->setCurrencyCode($rawData->geoplugin_currencyCode);
         }
         return $details;
     }
     return null;
 }
示例#12
0
 /**
  * Method loads all user-defined filters and applies them to the given text.
  *
  * @param string $text A text to filter
  * @return string
  */
 public function filter($text)
 {
     $filtersChain = WiseChatContainer::get('dao/WiseChatFiltersDAO')->getAll();
     foreach ($filtersChain as $filter) {
         $type = $filter['type'];
         $replace = $filter['replace'];
         $replaceWith = $filter['with'];
         if ($type == 'text') {
             $text = str_replace($replace, $replaceWith, $text);
         } else {
             $matches = array();
             $replace = '/' . $replace . '/i';
             if (preg_match_all($replace, $text, $matches)) {
                 foreach ($matches[0] as $value) {
                     $text = self::strReplaceFirst($value, $replaceWith, $text);
                 }
             }
         }
     }
     return $text;
 }
示例#13
0
 public function __construct()
 {
     $this->options = WiseChatOptions::getInstance();
     $this->usersDAO = WiseChatContainer::get('dao/user/WiseChatUsersDAO');
     $this->userSettingsDAO = WiseChatContainer::get('dao/user/WiseChatUserSettingsDAO');
     $this->channelUsersDAO = WiseChatContainer::get('dao/WiseChatChannelUsersDAO');
     $this->actionsDAO = WiseChatContainer::get('dao/WiseChatActionsDAO');
     $this->renderer = WiseChatContainer::get('rendering/WiseChatRenderer');
     $this->cssRenderer = WiseChatContainer::get('rendering/WiseChatCssRenderer');
     $this->bansService = WiseChatContainer::get('services/WiseChatBansService');
     $this->userService = WiseChatContainer::get('services/user/WiseChatUserService');
     $this->messagesService = WiseChatContainer::get('services/WiseChatMessagesService');
     $this->service = WiseChatContainer::get('services/WiseChatService');
     $this->attachmentsService = WiseChatContainer::get('services/WiseChatAttachmentsService');
     $this->authentication = WiseChatContainer::getLazy('services/user/WiseChatAuthentication');
     WiseChatContainer::load('WiseChatCrypt');
     WiseChatContainer::load('WiseChatThemes');
     WiseChatContainer::load('rendering/WiseChatTemplater');
     $this->userService->initMaintenance();
     $this->shortCodeOptions = array();
 }
示例#14
0
 /**
  * Endpoint that prepares an image for further upload: 
  * - basic checks
  * - resizing
  * - fixing orientation
  *
  * @notice GIFs are returned unchanged because of the lack of proper resizing abilities
  *
  * @return null
  */
 public function prepareImageEndpoint()
 {
     $this->verifyCheckSum();
     try {
         $this->checkChatOpen();
         $this->checkUserAuthentication();
         $this->checkUserAuthorization();
         $this->checkUserWriteAuthorization();
         $this->checkPostParams(array('data'));
         $data = $this->getPostParam('data');
         $imagesService = WiseChatContainer::get('services/WiseChatImagesService');
         $decodedImageData = $imagesService->decodePrefixedBase64ImageData($data);
         if ($decodedImageData['mimeType'] == 'image/gif') {
             echo $data;
         } else {
             $preparedImageData = $imagesService->getPreparedImage($decodedImageData['data']);
             echo $imagesService->encodeBase64WithPrefix($preparedImageData, $decodedImageData['mimeType']);
         }
     } catch (WiseChatUnauthorizedAccessException $exception) {
         echo json_encode(array('error' => $exception->getMessage()));
         $this->sendUnauthorizedStatus();
     } catch (Exception $exception) {
         echo json_encode(array('error' => $exception->getMessage()));
         $this->sendBadRequestStatus();
     }
     die;
 }
示例#15
0
<?php

WiseChatContainer::load('WiseChatThemes');
/**
 * Wise Chat admin appearance settings tab class.
 *
 * @author Marcin Ławrowski <*****@*****.**>
 */
class WiseChatAppearanceTab extends WiseChatAbstractTab
{
    public function getFields()
    {
        return array(array('_section', 'Chat Window Appearance'), array('theme', 'Theme', 'selectCallback', 'string', '', WiseChatThemes::getAllThemes()), array('background_color_chat', 'Background Color', 'colorFieldCallback', 'string', ''), array('text_color_chat', 'Font Color', 'colorFieldCallback', 'string', ''), array('text_size_chat', 'Font Size', 'selectCallback', 'string', '', WiseChatAppearanceTab::getFontSizes()), array('chat_width', 'Width', 'stringFieldCallback', 'string', 'Allowed values: a number with or without an unit (px or %), default: 100%'), array('chat_height', 'Height', 'stringFieldCallback', 'string', 'Allowed values: a number with or without an unit (px or %), default: 200px'), array('_section', 'Messages List Appearance'), array('messages_limit', 'Messages Limit', 'stringFieldCallback', 'integer', 'Maximum number of messages loaded on start-up'), array('messages_order', 'Messages Order', 'selectCallback', 'string', 'Sorting order of the messages', WiseChatAppearanceTab::getSortingOrder()), array('_section', 'Message Appearance'), array('background_color', 'Background Color', 'colorFieldCallback', 'string', ''), array('text_color', 'Font Color', 'colorFieldCallback', 'string', ''), array('text_color_user', 'Username Font Color', 'colorFieldCallback', 'string', 'Font color of username text in messages sent by a non-logged in user'), array('text_color_logged_user', 'Username Font Color<br />(logged in user)', 'colorFieldCallback', 'string', 'Font color of username text in messages sent by a logged in user'), array('text_size', 'Font Size', 'selectCallback', 'string', '', WiseChatAppearanceTab::getFontSizes()), array('messages_time_mode', 'Message Time Mode', 'selectCallback', 'string', 'Format of the date and time displayed next to each message', WiseChatAppearanceTab::getTimeModes()), array('link_wp_user_name', 'Username Display Mode', 'selectCallback', 'string', '
			    Controls how username is displayed in each message:<br />
			    <strong>- Plain text:</strong> username is displayed as a plain text.<br />
                <strong>- Link to the page:</strong> username is displayed as a link. By default the link directs to the author\'s page. Only messages sent by WordPress users are taken into account. If you would like to link every user name provide a template for the link (see the option below).<br />
                <strong>- Link for @mentioning the user:</strong> username is displayed as a link that inserts <strong>"@UserName: "******"Collect User Statistics" option in General tab
                '), array('show_users_city_and_country', 'Show City And Country', 'booleanFieldCallback', 'boolean', '
                Shows city and country code next to each user on the list. City and country are obtained from IP address and this may not be successful sometimes.<br />
                <strong>Notice:</strong> In order to show cities and countries enable "Collect User Statistics" option in General tab
                '), array('users_list_width', 'Users List Width', 'stringFieldCallback', 'integer', 'Percentage width of the list of users. Empty field sets default value of 29%.'), array('background_color_users_list', 'Background Color', 'colorFieldCallback', 'string', 'Background color of the users list'), array('text_color_users_list', 'Font Color', 'colorFieldCallback', 'string', 'Font color of the texts inside the users list'), array('text_size_users_list', 'Font Size', 'selectCallback', 'string', 'Font size', WiseChatAppearanceTab::getFontSizes()), array('_section', 'Advanced Customization'), array('custom_styles', 'Custom CSS Styles', 'multilineFieldCallback', 'multilinestring', 'Custom CSS styles for the chat, valid CSS syntax is required.'));
    }
    public function getDefaultValues()
示例#16
0
 public function __construct()
 {
     WiseChatContainer::load('model/WiseChatChannel');
     $this->options = WiseChatOptions::getInstance();
 }
示例#17
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();
 }
示例#18
0
 public function __construct()
 {
     WiseChatContainer::load('model/WiseChatAction');
     $this->options = WiseChatOptions::getInstance();
     $this->table = WiseChatInstaller::getActionsTable();
 }
示例#19
0
 /**
  * Returns an instance of the requested tab object.
  *
  * @param string $tabKey A key from $this->tabs array
  *
  * @return WiseChatAbstractTab
  */
 private function getTabObject($tabKey)
 {
     $tabKey = ucfirst(str_replace('wise-chat-', '', $tabKey));
     $classPathAndName = "admin/WiseChat{$tabKey}Tab";
     return WiseChatContainer::get($classPathAndName);
 }
示例#20
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));
     }
 }
示例#21
0
<?php

WiseChatContainer::load('rendering/filters/pre/WiseChatFilter');
class WiseChatFilterTest extends PHPUnit_Framework_TestCase
{
    private static $mbExtension = 'mbstring';
    /**
     * @dataProvider data
     */
    public function testPositive($input, $output)
    {
        WiseChatFilter::$words = array('balls');
        if (!extension_loaded(self::$mbExtension)) {
            $this->assertEquals($output, WiseChatFilter::filter($input));
        }
    }
    /**
     * @dataProvider dataNegative
     */
    public function testNegative($input, $output)
    {
        WiseChatFilter::$words = array('balls');
        if (!extension_loaded(self::$mbExtension)) {
            $this->assertEquals($output, WiseChatFilter::filter($input));
        }
    }
    /**
     * @dataProvider dataUnicode
     */
    public function testPositiveUnicode($input, $output)
    {
示例#22
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;
 }
示例#23
0
 /**
  * Returns information about the image stored in the temporary file.
  * If the file is not an image an exception is thrown.
  *
  * @param boolean $safeResize
  *
  * @return array
  * @throws \Exception
  */
 private function getTempFileImageInfo($safeResize)
 {
     $fileInfo = file_exists($this->tempFileName) ? getimagesize($this->tempFileName) : null;
     if (is_array($fileInfo)) {
         $mimeType = $fileInfo['mime'];
         if (!array_key_exists($mimeType, $this->supportedExtensions)) {
             $this->logError('Unsupported mime type: ' . $mimeType);
             throw new Exception($this->options->getEncodedOption('message_error_7', 'Unsupported type of file'));
         }
         $fileName = date('Ymd-His') . '-' . uniqid(rand()) . '.' . $this->supportedExtensions[$mimeType];
         if ($safeResize) {
             $imageEditor = WiseChatContainer::get('services/WiseChatImageEditor');
             $imageEditor->load($this->tempFileName);
             $imageEditor->resize($this->options->getIntegerOption('images_width_limit', 1000), $this->options->getIntegerOption('images_height_limit', 1000));
             $imageEditor->build();
         }
         return $_FILES[self::UPLOAD_FILE_NAME] = array('name' => $fileName, 'type' => $mimeType, 'tmp_name' => $this->tempFileName, 'error' => 0, 'size' => filesize($this->tempFileName));
     }
     $this->logError('The file is not an image');
     throw new Exception($this->options->getEncodedOption('message_error_7', 'Unsupported type of file'));
 }
示例#24
0
<?php

WiseChatContainer::load('rendering/WiseChatTemplater');
class WiseChatTemplaterTest extends PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider data
     */
    public function testTemplater($template, $data, $output)
    {
        $templater = new WiseChatTemplater('');
        $templater->setTemplate($template);
        $actualOutput = $templater->render($data);
        $this->assertEquals($output, $actualOutput);
    }
    public function data()
    {
        return array(array("", array(), ""), array("{{ x }}", array('x' => 't1'), "t1"), array("{{ x }} a {{ y }}", array('x' => 't1', 'y' => 't2'), "t1 a t2"), array("{{x }} a {{    y \t}}", array('x' => 't1', 'y' => 't2'), "t1 a t2"), array("{{ x }} a {{ y }} b {{ x }}", array('x' => 't1', 'y' => 't2'), "t1 a t2 b t1"), array("{% if x %} c1 {% endif x %}", array('x' => true), "c1"), array("{% if x %} c1 {% endif x %}", array('x' => '1'), "c1"), array("{% if x %} c1 {% endif x %}", array('x' => ''), ""), array("{% if !x %} c1 {% endif x %}", array('x' => '1'), ""), array("{% if !x %} c1 {% endif x %}", array('x' => ''), "c1"), array("{% if x %} c1 {% endif x %}", array('x' => 12), "c1"), array("{% if x %} c1 {% endif x %}", array('x' => 0), ""), array("{% if !x %} c1 {% endif x %}", array('x' => 12), ""), array("{% if !x %} c1 {% endif x %}", array('x' => 0), "c1"), array("{% if x %} c1 {% endif x %}", array('x' => 12.43), "c1"), array("{% if x %} c1 {% endif x %}", array('x' => 0.0), ""), array("{% if !x %} c1 {% endif x %}", array('x' => 12.53), ""), array("{% if !x %} c1 {% endif x %}", array('x' => 0.0), "c1"), array("{% if x %} c1 {% endif x %}", array('x' => array(1, 2)), "c1"), array("{% if x %} c1 {% endif x %}", array('x' => array()), ""), array("{% if !x %} c1 {% endif x %}", array('x' => array(1, 2)), ""), array("{% if !x %} c1 {% endif x %}", array('x' => array()), "c1"), array("{% if !x %} c1 {% endif x %}", array('x' => null), "c1"), array("{%if    x%}c1{%endif x%}", array('x' => true), "c1"), array("{% if x %} c1 {% endif x %}", array('x' => false), ""), array("{% if x %} c1 {% endif x %} a {% if x %} c2 {% endif x %}", array('x' => true), "c1 a c2"), array("{% if x %} c1 {% endif x %} a {%if y%} c2 {%endif y%}", array('x' => true, 'y' => true), "c1 a c2"), array("{% if x %} c1 {% endif x %} a {%if y%} c2 {%endif y%} b {% if x %} c3 {% endif x %}", array('x' => true, 'y' => true), "c1 a c2 b c3"), array("{% if x %} c1 {%if y%} a {%endif y%} c2 {% endif x %} {%if y%} c3 {%endif y%}", array('x' => true, 'y' => true), "c1 a c2 c3"), array("{% if x %} c1\nc2\n\n{% endif x %}", array('x' => true), "c1\nc2"), array("1 {% if x %} a {{y}} {%if x %} b {% endif x %} c {% if z %} d {% endif z %} e {% endif x %} f", array('x' => true, 'y' => 'v', 'z' => false), "1 a v b c  e f"), array("{% if !x %} c1 {% endif x %}", array('x' => false), "c1"), array("{% if !x %} c1 {% endif x %} c2{%if x %} c3 {% endif x %}", array('x' => false), "c1 c2"), array("{% if !x %} c1{%if x %} c3 {% endif x %} {% endif x %} c2{%if x %} c3 {% endif x %}", array('x' => false), "c1 c2"), array("{% variable v %} c {% endvariable v %} {{v}}", array(), " c"), array("{%variable v%} c {%    endvariable v%} {{v}}", array(), " c"), array("{% variable v %} c1 {% if x %} c2 {% endif x %} {% endvariable v %} {{v}}", array('x' => true), " c1 c2"));
    }
}
 /**
  * @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);
         }
     }
 }
示例#26
0
 /**
  * WiseChatActions constructor.
  */
 public function __construct()
 {
     $this->actionsDAO = WiseChatContainer::get('dao/WiseChatActionsDAO');
 }
示例#27
0
 /**
  * WiseChatAbuses constructor.
  */
 public function __construct()
 {
     $this->userSessionDAO = WiseChatContainer::getLazy('dao/user/WiseChatUserSessionDAO');
 }
<?php

WiseChatContainer::load('rendering/filters/post/WiseChatImagesPostFilter');
class WiseChatImagesPostFilterTest extends PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider data
     */
    public function testPositiveImages($input, $output)
    {
        $input = str_replace('"', '&quot;', $input);
        $postFilter = new WiseChatImagesPostFilter();
        $this->assertEquals($output, $postFilter->filter($input, true));
    }
    public function data()
    {
        return array(array('[img id="1" src="http://www.poznan.pl/sdsd.jpg" src-th="http://www.poznan.pl/sdsd-th.jpg" src-org="ORG"]', '<a href="http://www.poznan.pl/sdsd.jpg" target="_blank" data-lightbox="wise_chat" rel="lightbox[wise_chat]"><img src="http://www.poznan.pl/sdsd-th.jpg" class="wcImage" /></a>'), array('H: [img id="1" src="http://www.poznan.pl/sdsd.jpg?aaa=%20ss" src-th="http://www.poznan.pl/sdsd-th.jpg?bbb=%20ss" src-org="ORG"]', 'H: <a href="http://www.poznan.pl/sdsd.jpg?aaa=%20ss" target="_blank" data-lightbox="wise_chat" rel="lightbox[wise_chat]"><img src="http://www.poznan.pl/sdsd-th.jpg?bbb=%20ss" class="wcImage" /></a>'), array('H: [img id="1" src="http://www.poznan.pl/sdsd.jpg?aaa=%20ss" src-th="http://www.poznan.pl/sdsd-th.jpg?bbb=%20ss" src-org="ORG"] x [img id="1" src="http://www.poznan.pl/www.jpg?aaa=%20ss" src-th="http://www.poznan.pl/www-th.jpg?bbb=%20ss" src-org="ORG"]', 'H: <a href="http://www.poznan.pl/sdsd.jpg?aaa=%20ss" target="_blank" data-lightbox="wise_chat" rel="lightbox[wise_chat]"><img src="http://www.poznan.pl/sdsd-th.jpg?bbb=%20ss" class="wcImage" /></a> x <a href="http://www.poznan.pl/www.jpg?aaa=%20ss" target="_blank" data-lightbox="wise_chat" rel="lightbox[wise_chat]"><img src="http://www.poznan.pl/www-th.jpg?bbb=%20ss" class="wcImage" /></a>'));
    }
    /**
     * @dataProvider dataNoImagesButLinks
     */
    public function testPositiveNoImagesButLinks($input, $output)
    {
        $input = str_replace('"', '&quot;', $input);
        $postFilter = new WiseChatImagesPostFilter();
        $this->assertEquals($output, $postFilter->filter($input, false, true));
    }
    public function dataNoImagesButLinks()
    {
        return array(array('[img id="1" src="http://www.poznan.pl/sdsd.jpg" src-th="http://www.poznan.pl/sdsd-th.jpg" src-org="www.wroc.pl/org.jpg"]', '<a href="http://www.wroc.pl/org.jpg" target="_blank" rel="nofollow">www.wroc.pl/org.jpg</a>'), array('[img id="1" src="http://www.poznan.pl/sdsd.jpg" src-th="http://www.poznan.pl/sdsd-th.jpg" src-org="http://www.wroc.pl/org.jpg"]', '<a href="http://www.wroc.pl/org.jpg" target="_blank" rel="nofollow">http://www.wroc.pl/org.jpg</a>'), array('H: [img id="1" src="http://www.poznan.pl/sdsd.jpg" src-th="http://www.poznan.pl/sdsd-th.jpg" src-org="www.wroc.pl/org.jpg?q=pozna%C5%84+%22:)%22"]', 'H: <a href="http://www.wroc.pl/org.jpg?q=pozna%C5%84+%22:)%22" target="_blank" rel="nofollow">www.wroc.pl/org.jpg?q=poznań &quot;:)&quot;</a>'));
    }
示例#29
0
function wise_chat_endpoint_prepare_image()
{
    $wiseChatEndpoints = WiseChatContainer::get('endpoints/WiseChatEndpoints');
    $wiseChatEndpoints->prepareImageEndpoint();
}
示例#30
0
require_once ABSPATH . WPINC . '/rewrite.php';
require_once ABSPATH . WPINC . '/author-template.php';
requireIfExists('class-wp-rewrite.php');
requireIfExists('rest-api.php');
require_once ABSPATH . WPINC . '/rewrite.php';
require_once ABSPATH . WPINC . '/kses.php';
require_once ABSPATH . WPINC . '/revision.php';
require_once ABSPATH . WPINC . '/capabilities.php';
requireIfExists('class-wp-roles.php');
requireIfExists('class-wp-role.php');
require_once ABSPATH . WPINC . '/pluggable.php';
require_once ABSPATH . WPINC . '/pluggable-deprecated.php';
requireIfExists('class-wp-user.php');
requireIfExists('class-wp-user-query.php');
$GLOBALS['wp_rewrite'] = new WP_Rewrite();
// NOTICE: hack for warning in plugin_basename() function:
$wp_plugin_paths = array();
wp_plugin_directory_constants();
wp_cookie_constants();
// removing images downloaded by the chat:
$wiseChatImagesService = WiseChatContainer::get('services/WiseChatImagesService');
add_action('delete_attachment', array($wiseChatImagesService, 'removeRelatedImages'));
$actionsMap = array('wise_chat_messages_endpoint' => 'messagesEndpoint', 'wise_chat_message_endpoint' => 'messageEndpoint', 'wise_chat_delete_message_endpoint' => 'messageDeleteEndpoint', 'wise_chat_user_ban_endpoint' => 'userBanEndpoint', 'wise_chat_maintenance_endpoint' => 'maintenanceEndpoint', 'wise_chat_settings_endpoint' => 'settingsEndpoint', 'wise_chat_prepare_image_endpoint' => 'prepareImageEndpoint');
$wiseChatEndpoints = WiseChatContainer::get('endpoints/WiseChatEndpoints');
$action = $_REQUEST['action'];
if (array_key_exists($action, $actionsMap)) {
    $method = $actionsMap[$action];
    $wiseChatEndpoints->{$method}();
} else {
    header('HTTP/1.0 400 Bad Request');
}