/**
  * Returns list of allowed attachment formats. 
  *
  * @return array
  */
 public function getAllowedFormats()
 {
     $validFormats = array();
     if ($this->options->isOptionEnabled('enable_attachments_uploader')) {
         $formats = $this->options->getEncodedOption('attachments_file_formats');
         $formatsSplited = preg_split('/,/', $formats);
         if (is_array($formatsSplited)) {
             foreach ($formatsSplited as $format) {
                 $proposedFormat = strtolower(trim($format));
                 if (!in_array($proposedFormat, $this->securityExcludedFormats)) {
                     $validFormats[] = $proposedFormat;
                 }
             }
         }
     }
     return $validFormats;
 }
예제 #2
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;
 }
예제 #3
0
 /**
  * Returns all messages from the given channel and (optionally) beginning from the given offset.
  * Limit, order and admin messages inclusion are taken from the plugin's options.
  *
  * @param string $channelName Name of the channel
  * @param integer $fromId Begin from specific message ID
  *
  * @return WiseChatMessage[]
  */
 public function getAllByChannelNameAndOffset($channelName, $fromId = null)
 {
     $orderMode = $this->options->getEncodedOption('messages_order', '');
     $criteria = new WiseChatMessagesCriteria();
     $criteria->setChannelName($channelName);
     $criteria->setOffsetId($fromId);
     $criteria->setIncludeAdminMessages($this->usersDAO->isWpUserAdminLogged());
     $criteria->setLimit($this->options->getIntegerOption('messages_limit', 100));
     $criteria->setOrderMode($orderMode == WiseChatMessagesCriteria::ORDER_DESCENDING ? $orderMode : WiseChatMessagesCriteria::ORDER_ASCENDING);
     return $this->messagesDAO->getAllByCriteria($criteria);
 }
예제 #4
0
 /**
  * Callback method for displaying select field with a hint. If the property is not defined the default value is used.
  *
  * @param array $args Array containing keys: id, name, hint, options
  *
  * @return null
  */
 public function selectCallback($args)
 {
     $id = $args['id'];
     $hint = $args['hint'];
     $options = $args['options'];
     $defaults = $this->getDefaultValues();
     $defaultValue = array_key_exists($id, $defaults) ? $defaults[$id] : '';
     $value = $this->options->getEncodedOption($id, $defaultValue);
     $parentId = $this->getFieldParent($id);
     $optionsHtml = '';
     foreach ($options as $name => $label) {
         $optionsHtml .= sprintf("<option value='%s'%s>%s</option>", $name, $name == $value ? ' selected="1"' : '', $label);
     }
     printf('<select id="%s" name="' . WiseChatOptions::OPTIONS_NAME . '[%s]" %s data-parent-field="%s">%s</select>', $id, $id, $parentId != null && !$this->options->isOptionEnabled($parentId, false) ? ' disabled="1" ' : '', $parentId != null ? $parentId : '', $optionsHtml);
     if (strlen($hint) > 0) {
         printf('<p class="description">%s</p>', $hint);
     }
 }
예제 #5
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'));
 }
예제 #6
0
 private function getThemeProperty($property)
 {
     $theme = $this->options->getEncodedOption('theme', '');
     return self::$themesSettings[$theme][$property];
 }
예제 #7
0
 /**
  * Returns the form which allows to enter username.
  *
  * @param string|null $errorMessage
  *
  * @return string HTML source
  * @throws Exception
  */
 public function getRenderedUserNameForm($errorMessage = null)
 {
     $this->templater->setTemplateFile(WiseChatThemes::getInstance()->getUserNameFormTemplate());
     $data = array('themeStyles' => $this->options->getBaseDir() . WiseChatThemes::getInstance()->getCss(), 'windowTitle' => $this->options->getEncodedOption('window_title', ''), 'errorMessage' => $errorMessage, 'messageLogin' => $this->options->getEncodedOption('message_login', 'Log in'), 'messageEnterUserName' => $this->options->getEncodedOption('message_enter_user_name', 'Enter your username'));
     return $this->templater->render($data);
 }
예제 #8
0
 /**
  * @throws Exception
  */
 private function checkChatOpen()
 {
     if (!$this->service->isChatOpen()) {
         throw new Exception($this->options->getEncodedOption('message_error_5', 'The chat is closed now'));
     }
 }