/**
  * Creates a new MessageAttachmentListEditor object.
  * 
  * @param	array<integer>	$containerIDArray
  * @param	string		$containerType
  * @param	integer		$packageID
  * @param	integer		$maxFileSize
  * @param	string		$allowedExtensions
  * @param	integer		$maxUploads
  * @param	integer		$thumbnailWidth
  * @param	integer		$thumbnailHeight
  * @param	boolean		$addSourceInfo
  * @param	boolean		$useEmbedded
  */
 public function __construct($containerIDArray = array(), $containerType = 'post', $packageID = PACKAGE_ID, $maxFileSize = 2000000, $allowedExtensions = "gif\njpg\njpeg\npng\nbmp\nzip\ntxt", $maxUploads = 5, $thumbnailWidth = ATTACHMENT_THUMBNAIL_WIDTH, $thumbnailHeight = ATTACHMENT_THUMBNAIL_HEIGHT, $addSourceInfo = ATTACHMENT_THUMBNAIL_ADD_SOURCE_INFO, $useEmbedded = ATTACHMENT_THUMBNAIL_USE_EMBEDDED)
 {
     if (!is_array($containerIDArray)) {
         $containerIDArray = array($containerIDArray);
     }
     $this->thumbnailWidth = $thumbnailWidth;
     $this->thumbnailHeight = $thumbnailHeight;
     $this->addSourceInfo = $addSourceInfo;
     $this->useEmbedded = $useEmbedded;
     if (!count($containerIDArray)) {
         $this->getIDHash();
     }
     // call parent constructor
     parent::__construct($containerIDArray, $containerType, $this->idHash, $packageID);
     // read attachments
     $this->readObjects();
     $this->maxFileSize = $maxFileSize;
     $this->maxUploads = $maxUploads;
     $allowedExtensions = StringUtil::unifyNewlines($allowedExtensions);
     $allowedExtensions = implode("\n", array_unique(explode("\n", $allowedExtensions)));
     $this->allowedExtensions = '/^(' . StringUtil::replace("\n", "|", StringUtil::replace('\\*', '.*', preg_quote($allowedExtensions, '/'))) . ')$/i';
     $this->allowedExtensionsDesc = self::formatAllowedExtensions($allowedExtensions);
     $this->getAttachmentHashes();
     $this->assign();
 }
 /**
  * Creates a new MemcacheAdapter object.
  */
 private function __construct()
 {
     if (!class_exists('Memcache')) {
         throw new SystemException('memcache support is not enabled.');
     }
     // init memcache
     $this->memcache = new Memcache();
     // add servers
     $servers = explode("\n", StringUtil::unifyNewlines(CACHE_SOURCE_MEMCACHE_HOST));
     foreach ($servers as $server) {
         $server = StringUtil::trim($server);
         if (!empty($server)) {
             $host = $server;
             $port = 11211;
             // default memcache port
             // get port
             if (strpos($host, ':')) {
                 $parsedHost = explode(':', $host);
                 $host = $parsedHost[0];
                 $port = $parsedHost[1];
             }
             $this->memcache->addServer($host, $port, CACHE_SOURCE_MEMCACHE_USE_PCONNECT);
         }
     }
     // test connection
     $this->memcache->get('testing');
 }
 public function __construct()
 {
     if (MODULE_USER_EMAIL_BLACKLIST && BLOCKED_EMAIL_SUFFIXES != '') {
         $this->enabled = true;
         $blockedEmailSuffixex = explode("\n", preg_quote(StringUtil::unifyNewlines(StringUtil::trim(BLOCKED_EMAIL_SUFFIXES))));
         $blockedEmailSuffixex = array_filter($blockedEmailSuffixex);
         $this->mailSuffixRegex = '!^(.*' . implode('|.*', $blockedEmailSuffixex) . ')$!i';
     }
 }
 /**
  * Strips session links, html entities and \r\n from the given text.
  * 
  * @param	string		$text
  * @return	string
  */
 public static function stripCrap($text)
 {
     // strip session links
     $text = preg_replace('/(?<=\\?|&)s=[a-z0-9]{40}/', '', $text);
     // convert html entities (utf-8)
     $text = preg_replace_callback('/&#(3[2-9]|[4-9][0-9]|\\d{3,5});/', array('MessageUtil', 'stripCrapCallback'), $text);
     // remove \r\n
     $text = StringUtil::unifyNewlines($text);
     return $text;
 }
 /**
  * @see	SocketServerClient::onRead()
  */
 public function onRead()
 {
     $string = StringUtil::unifyNewlines($this->readBuffer);
     echo '#~->', strlen($string) > 500 ? substr($string, 0, 500) : $string;
     if (!$this->isValidString($string)) {
         return;
     }
     $lines = ArrayUtil::trim(explode("\n", $string));
     $this->handleRequest($lines);
     $this->read_buffer = '';
 }
 /**
  * Stores a given quote.
  *
  * @param	integer		$objectID
  * @param	string		$objectType
  * @param	string		$text
  * @param	string		$author
  * @param	string		$url
  * @param	integer		$parentID
  * @param	string		$quoteID
  * @return	string		quote id
  */
 public static function storeQuote($objectID, $objectType, $text, $author = '', $url = '', $parentID = 0, $quoteID = '')
 {
     self::loadStorage();
     if ($quoteID == '') {
         $quoteID = StringUtil::getRandomID();
     }
     self::$quoteStorage[$quoteID] = array('quoteID' => $quoteID, 'objectID' => $objectID, 'objectType' => $objectType, 'author' => $author, 'url' => $url, 'text' => StringUtil::unifyNewlines($text), 'parentID' => $parentID);
     if (!isset(self::$quoteCounts[$objectType . '-' . $objectID])) {
         self::$quoteCounts[$objectType . '-' . $objectID] = 0;
     }
     self::$quoteCounts[$objectType . '-' . $objectID]++;
     return $quoteID;
 }
示例#7
0
 /**
  * Compresses css code.
  * 
  * @param	string		$string
  * @return	string
  */
 public static function compressCSS($string)
 {
     $string = StringUtil::unifyNewlines($string);
     // remove comments
     $string = preg_replace('!/\\*.*?\\*/\\r?\\n?!s', '', $string);
     // remove tabs
     $string = preg_replace('!\\t+!', '', $string);
     // remove line breaks
     $string = preg_replace('!(?<=\\{|;) *\\n!', '', $string);
     $string = preg_replace('! *\\n(?=})!', '', $string);
     // remove empty lines
     $string = preg_replace('~\\n{2,}~s', "\n", $string);
     return StringUtil::trim($string);
 }
 /**
  * Returns an excerpt of the message.
  * 
  * @return	string
  */
 public function getExcerpt()
 {
     // pre-format
     $message = StringUtil::trim(StringUtil::unifyNewlines($this->message));
     // find 1st paragraph
     $excerpt = preg_replace('/^(.*?)\\n\\n.*/s', '$1', $message);
     if (StringUtil::length($excerpt) != StringUtil::length($message)) {
         $this->data['hasMoreText'] = 1;
     }
     // format
     require_once WCF_DIR . 'lib/data/message/bbcode/MessageParser.class.php';
     MessageParser::getInstance()->setOutputType('text/html');
     require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
     AttachmentBBCode::setMessageID($this->contestID);
     return MessageParser::getInstance()->parse($excerpt, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes);
 }
 /**
  * Reads the given parameters.
  */
 public function readParams()
 {
     $pollOptionsText = '';
     $this->data['votesNotChangeable'] = $this->data['sortByResult'] = 0;
     if (isset($_POST['pollQuestion'])) {
         $this->data['question'] = StringUtil::trim($_POST['pollQuestion']);
     }
     if (isset($_POST['pollOptions'])) {
         $pollOptionsText = StringUtil::unifyNewlines(StringUtil::trim($_POST['pollOptions']));
     }
     if (isset($_POST['choiceCount'])) {
         $this->data['choiceCount'] = intval($_POST['choiceCount']);
     }
     if (isset($_POST['votesNotChangeable'])) {
         $this->data['votesNotChangeable'] = intval($_POST['votesNotChangeable']);
     }
     if (isset($_POST['sortByResult'])) {
         $this->data['sortByResult'] = intval($_POST['sortByResult']);
     }
     if ($this->canStartPublicPoll) {
         $this->data['isPublic'] = 0;
         if (isset($_POST['isPublic'])) {
             $this->data['isPublic'] = intval($_POST['isPublic']);
         }
     }
     // end time
     if (isset($_POST['endTimeDay'])) {
         $this->endTimeDay = intval($_POST['endTimeDay']);
     }
     if (isset($_POST['endTimeMonth'])) {
         $this->endTimeMonth = intval($_POST['endTimeMonth']);
     }
     if (isset($_POST['endTimeYear'])) {
         $this->endTimeYear = intval($_POST['endTimeYear']);
     }
     if (isset($_POST['endTimeHour'])) {
         $this->endTimeHour = intval($_POST['endTimeHour']);
     }
     if (isset($_POST['endTimeMinutes'])) {
         $this->endTimeMinutes = intval($_POST['endTimeMinutes']);
     }
     $this->pollOptionsArray = array_unique(ArrayUtil::trim(explode("\n", $pollOptionsText)));
     $this->assign();
 }
示例#10
0
 /**
  * Returns a list of the enable options.
  * 
  * @param 	string		$enableOptions
  * @return	array
  */
 public static function parseMultipleEnableOptions($enableOptions)
 {
     $result = array();
     if (!empty($enableOptions)) {
         $options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($enableOptions)));
         $key = -1;
         foreach ($options as $option) {
             if (StringUtil::indexOf($option, ':') !== false) {
                 $optionData = explode(':', $option);
                 $key = array_shift($optionData);
                 $value = implode(':', $optionData);
             } else {
                 $key++;
                 $value = $option;
             }
             $result[$key] = $value;
         }
     }
     return $result;
 }
 /**
  * Creates a new PackageUpdateAuthForm object.
  * 
  * @param	PackageUpdateAuthorizationRequiredException	$exception
  */
 public function __construct($exception = null)
 {
     $this->exception = $exception;
     if ($this->exception !== null) {
         $this->packageUpdateServerID = $this->exception->getPackageUpdateServerID();
         $this->url = $this->exception->getURL();
         $this->header = $this->exception->getResponseHeader();
         // get message
         $this->message = $this->exception->getResponseContent();
         // find out response charset
         if (preg_match('/charset=([a-z0-9\\-]+)/i', $this->header, $match)) {
             $charset = strtoupper($match[1]);
             if ($charset != CHARSET) {
                 $this->message = @StringUtil::convertEncoding($charset, CHARSET, $this->message);
             }
         }
         // format message
         $this->message = nl2br(preg_replace("/\n{3,}/", "\n\n", StringUtil::unifyNewlines(StringUtil::trim(strip_tags($this->message)))));
     }
     parent::__construct();
 }
 /**
  * @see Action::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     // get object id
     if (isset($_REQUEST['objectID'])) {
         $this->objectID = intval($_REQUEST['objectID']);
     }
     // get quote(s)
     if (isset($_REQUEST['text'])) {
         $this->text = $_REQUEST['text'];
     }
     if (is_array($this->text)) {
         $this->text = ArrayUtil::unifyNewlines(ArrayUtil::trim($this->text));
         if (CHARSET != 'UTF-8') {
             $this->text = ArrayUtil::convertEncoding('UTF-8', CHARSET, $this->text);
         }
     } else {
         $this->text = StringUtil::unifyNewlines(StringUtil::trim($this->text));
         if (CHARSET != 'UTF-8') {
             $this->text = StringUtil::convertEncoding('UTF-8', CHARSET, $this->text);
         }
     }
 }
 /**
  * Returns censored words from a text. 
  * 
  * @param	string		$text
  * @return	mixed		$matches / false
  */
 public static function test($text)
 {
     // reset matches
     self::$matches = array();
     // get words which should be censored
     $censoredWords = explode("\n", StringUtil::unifyNewlines(StringUtil::toLowerCase(CENSORED_WORDS)));
     // format censored words
     $censoredWords = ArrayUtil::trim($censoredWords);
     // string to lower case
     $text = StringUtil::toLowerCase($text);
     // ignore bbcode tags
     $text = preg_replace('~\\[/?[a-z]+[^\\]]*\\]~i', '', $text);
     // split the text in single words
     self::$words = preg_split("!" . self::$delimiters . "+!", $text, -1, PREG_SPLIT_NO_EMPTY);
     // check each word if it censored.
     for ($i = 0, $count = count(self::$words); $i < $count; $i++) {
         $word = self::$words[$i];
         foreach ($censoredWords as $censoredWord) {
             // check for direct matches ("badword" == "badword")
             if ($censoredWord == $word) {
                 // store censored word
                 if (isset(self::$matches[$word])) {
                     self::$matches[$word]++;
                 } else {
                     self::$matches[$word] = 1;
                 }
                 continue 2;
             } else {
                 if (StringUtil::indexOf($censoredWord, '*') !== false) {
                     $censoredWord = StringUtil::replace('\\*', '.*', preg_quote($censoredWord));
                     if (preg_match('!^' . $censoredWord . '$!', $word)) {
                         // store censored word
                         if (isset(self::$matches[$word])) {
                             self::$matches[$word]++;
                         } else {
                             self::$matches[$word] = 1;
                         }
                         continue 2;
                     }
                 } else {
                     if (StringUtil::indexOf($censoredWord, '~') !== false) {
                         $censoredWord = StringUtil::replace('~', '', $censoredWord);
                         if (($position = StringUtil::indexOf($censoredWord, $word)) !== false) {
                             if ($position > 0) {
                                 // look behind
                                 if (!self::lookBehind($i - 1, StringUtil::substring($censoredWord, 0, $position))) {
                                     continue;
                                 }
                             }
                             if ($position + StringUtil::length($word) < StringUtil::length($censoredWord)) {
                                 // look ahead
                                 if ($newIndex = self::lookAhead($i + 1, StringUtil::substring($censoredWord, $position + StringUtil::length($word)))) {
                                     $i = $newIndex;
                                 } else {
                                     continue;
                                 }
                             }
                             // store censored word
                             if (isset(self::$matches[$censoredWord])) {
                                 self::$matches[$censoredWord]++;
                             } else {
                                 self::$matches[$censoredWord] = 1;
                             }
                             continue 2;
                         }
                     }
                 }
             }
         }
     }
     // at least one censored word was found
     if (count(self::$matches) > 0) {
         return self::$matches;
     } else {
         return false;
     }
 }
 /**
  * Gets the page URLs.
  * 
  * @return	array
  */
 protected static function getPageURLs()
 {
     $urlString = '';
     if (defined('PAGE_URL')) {
         $urlString .= PAGE_URL;
     }
     if (defined('PAGE_URLS')) {
         $urlString .= "\n" . PAGE_URLS;
     }
     $urlString = StringUtil::unifyNewlines($urlString);
     self::$pageURLs = ArrayUtil::trim(explode("\n", $urlString));
 }
示例#15
0
 /**
  * Converts dos to unix newlines.
  *
  * @param 	array 		$array
  * @return 	array 		$array
  */
 public static function unifyNewlines($array)
 {
     if (!is_array($array)) {
         return StringUtil::unifyNewlines($array);
     } else {
         foreach ($array as $key => $val) {
             $array[$key] = self::unifyNewlines($val);
         }
         return $array;
     }
 }
示例#16
0
 /**	
  * Returns an array with the prefixes of this board.
  * 
  * @return	array
  */
 public function getPrefixes()
 {
     if (!$this->hasPrefixes()) {
         return array();
     }
     // get prefixes
     $prefixes = '';
     if (($this->prefixMode == self::PREFIX_MODE_GLOBAL || $this->prefixMode == self::PREFIX_MODE_COMBINATION) && THREAD_DEFAULT_PREFIXES) {
         $prefixes = THREAD_DEFAULT_PREFIXES;
     }
     if (($this->prefixMode == self::PREFIX_MODE_BOARD || $this->prefixMode == self::PREFIX_MODE_COMBINATION) && $this->prefixes) {
         if (!empty($prefixes)) {
             $prefixes .= "\n";
         }
         $prefixes .= $this->prefixes;
     }
     return explode("\n", StringUtil::unifyNewlines($prefixes));
 }
 /**
  * Gets the page URLs.
  * 
  * @return	array
  */
 public static function getPageURLs()
 {
     $urlString = '';
     if (defined('PAGE_URL')) {
         $urlString .= PAGE_URL;
     }
     if (defined('PAGE_URLS')) {
         $urlString .= "\n" . PAGE_URLS;
     }
     $urlString = StringUtil::unifyNewlines($urlString);
     return ArrayUtil::trim(explode("\n", $urlString));
 }
 /**
  * Returns a list of allowed avatar file extensions.
  * 
  * @return	array<string>
  */
 public static function getAllowedFileExtensions()
 {
     if (self::$allowedFileExtensions === null) {
         self::$allowedFileExtensions = array();
         self::$allowedFileExtensions = array_unique(explode("\n", StringUtil::unifyNewlines(WCF::getUser()->getPermission('user.profile.avatar.allowedFileExtensions'))));
         self::$allowedFileExtensions = array_diff(self::$allowedFileExtensions, self::$illegalFileExtensions);
     }
     return self::$allowedFileExtensions;
 }