/** * Returns all aliases for this smiley. * * @return array<string> */ public function getAliases() { if (!$this->aliases) { return array(); } return explode("\n", StringUtil::unifyNewlines($this->aliases)); }
/** * Cleans up newlines and converts input to lower-case. * * @param string $newValue * @return string */ protected function cleanup($newValue) { $newValue = StringUtil::unifyNewlines($newValue); $newValue = trim($newValue); $newValue = preg_replace('~\\n+~', "\n", $newValue); $newValue = mb_strtolower($newValue); return $newValue; }
/** * Creates a new instance of memcached. */ public function __construct() { if (!class_exists('Memcached')) { throw new SystemException('memcached support is not enabled.'); } // init memcached $this->memcached = new \Memcached(); // add servers $tmp = explode("\n", StringUtil::unifyNewlines(CACHE_SOURCE_MEMCACHED_HOST)); $servers = array(); $defaultWeight = floor(100 / count($tmp)); $regex = new Regex('^\[([a-z0-9\:\.]+)\](?::([0-9]{1,5}))?(?::([0-9]{1,3}))?$', Regex::CASE_INSENSITIVE); foreach ($tmp as $server) { $server = StringUtil::trim($server); if (!empty($server)) { $host = $server; $port = 11211; // default memcached port $weight = $defaultWeight; // check for IPv6 if ($regex->match($host)) { $matches = $regex->getMatches(); $host = $matches[1]; if (isset($matches[2])) { $port = $matches[2]; } if (isset($matches[3])) { $weight = $matches[3]; } } else { // IPv4, try to get port and weight if (strpos($host, ':')) { $parsedHost = explode(':', $host); $host = $parsedHost[0]; $port = $parsedHost[1]; if (isset($parsedHost[2])) { $weight = $parsedHost[2]; } } } $servers[] = array($host, $port, $weight); } } $this->memcached->addServers($servers); // test connection $this->memcached->get('testing'); // set variable prefix to prevent collision $this->prefix = substr(sha1(WCF_DIR), 0, 8) . '_'; }
/** * Checks whether this question matches the given message. * * @param string $message * @return boolean */ public function matches($message) { $lines = explode("\n", \wcf\util\StringUtil::unifyNewlines($this->questionMessage)); foreach ($lines as $line) { if (\wcf\system\Regex::compile($line)->match($message)) { return true; } } return false; }
/** * 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); }
/** * @see \wcf\system\SingletonFactory::init() */ protected function init() { $this->titleRegex = new Regex('[\\x0-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7F]+'); if (defined('URL_TITLE_COMPONENT_REPLACEMENT') && URL_TITLE_COMPONENT_REPLACEMENT) { $replacements = explode("\n", StringUtil::unifyNewlines(StringUtil::trim(URL_TITLE_COMPONENT_REPLACEMENT))); foreach ($replacements as $replacement) { if (strpos($replacement, '=') === false) { continue; } $components = explode('=', $replacement); $this->titleSearch[] = $components[0]; $this->titleReplace[] = $components[1]; } } }
/** * Returns the html for this provider. * * @param string $url * @return string */ public function getOutput($url) { $lines = explode("\n", StringUtil::unifyNewlines($this->regex)); foreach ($lines as $line) { $regex = new Regex($line); if (!$regex->match($url)) { continue; } $output = $this->html; foreach ($regex->getMatches() as $name => $value) { $output = str_replace('{$' . $name . '}', $value, $output); } return $output; } return ''; }
/** * @see \wcf\system\option\IOptionType::compare() */ public function compare($value1, $value2) { $value1 = explode("\n", StringUtil::unifyNewlines($value1)); $value2 = explode("\n", StringUtil::unifyNewlines($value2)); // check if value1 contains more elements than value2 $diff = array_diff($value1, $value2); if (!empty($diff)) { return 1; } // check if value1 contains less elements than value2 $diff = array_diff($value2, $value1); if (!empty($diff)) { return -1; } // both lists are equal return 0; }
/** * Returns true if the given user input is an answer to this question. * * @param string $answer * @return boolean */ public function isAnswer($answer) { $answers = explode("\n", StringUtil::unifyNewlines(WCF::getLanguage()->get($this->answers))); foreach ($answers as $__answer) { if (mb_substr($__answer, 0, 1) == '~' && mb_substr($__answer, -1, 1) == '~') { if (Regex::compile(mb_substr($__answer, 1, mb_strlen($__answer) - 2))->match($answer)) { return true; } continue; } else { if ($__answer == $answer) { return true; } } } return false; }
/** * 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, security tokens and access tokens $text = Regex::compile('(?<=\\?|&)([st]=[a-f0-9]{40}|at=\\d+-[a-f0-9]{40})')->replace($text, ''); // convert html entities (utf-8) $text = Regex::compile('&#(3[2-9]|[4-9][0-9]|\\d{3,5});')->replace($text, new Callback(function ($matches) { return StringUtil::getCharacter(intval($matches[1])); })); // unify new lines $text = StringUtil::unifyNewlines($text); // remove 4 byte utf-8 characters as MySQL < 5.5 does not support them // see http://stackoverflow.com/a/16902461/782822 $text = preg_replace('/[\\xF0-\\xF7].../s', '', $text); // remove control characters $text = preg_replace('~[\\x00-\\x08\\x0B-\\x1F\\x7F]~', '', $text); return $text; }
/** * @see \wcf\form\IForm::validate() */ public function validate() { parent::validate(); // validate fields if (empty($this->title)) { throw new UserInputException('title'); } if (empty($this->regex)) { throw new UserInputException('regex'); } if (empty($this->html)) { throw new UserInputException('html'); } $lines = explode("\n", StringUtil::unifyNewlines($this->regex)); foreach ($lines as $line) { if (!Regex::compile($line)->isValid()) { throw new UserInputException('regex', 'notValid'); } } }
/** * @see \wcf\system\SingletonFactory::init() */ protected function init() { // get words which should be censored $censoredWords = explode("\n", StringUtil::unifyNewlines(mb_strtolower(CENSORED_WORDS))); // format censored words for ($i = 0, $length = count($censoredWords); $i < $length; $i++) { $censoredWord = StringUtil::trim($censoredWords[$i]); if (empty($censoredWord)) { continue; } $displayedCensoredWord = str_replace(array('~', '*'), '', $censoredWord); // check if censored word contains at least one delimiter if (preg_match('!' . $this->delimiters . '+!', $displayedCensoredWord)) { // remove delimiters $censoredWord = preg_replace('!' . $this->delimiters . '!', '', $censoredWord); // enforce partial matching $censoredWord = '~' . $censoredWord; } $this->censoredWords[$displayedCensoredWord] = $censoredWord; } }
/** * Compiles LESS stylesheets. * * @param \wcf\data\style\Style $style */ public function compile(Style $style) { // read stylesheets by dependency order $conditions = new PreparedStatementConditionBuilder(); $conditions->add("filename REGEXP ?", array('style/([a-zA-Z0-9\\_\\-\\.]+)\\.less')); $sql = "SELECT\t\tfilename, application\n\t\t\tFROM\t\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t" . $conditions . "\n\t\t\tORDER BY\tpackageID"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $files = array(); while ($row = $statement->fetchArray()) { $files[] = Application::getDirectory($row['application']) . $row['filename']; } // get style variables $variables = $style->getVariables(); $individualLess = ''; if (isset($variables['individualLess'])) { $individualLess = $variables['individualLess']; unset($variables['individualLess']); } // add style image path $imagePath = '../images/'; if ($style->imagePath) { $imagePath = FileUtil::getRelativePath(WCF_DIR . 'style/', WCF_DIR . $style->imagePath); $imagePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator($imagePath)); } $variables['style_image_path'] = "'{$imagePath}'"; // apply overrides if (isset($variables['overrideLess'])) { $lines = explode("\n", StringUtil::unifyNewlines($variables['overrideLess'])); foreach ($lines as $line) { if (preg_match('~^@([a-zA-Z]+): ?([@a-zA-Z0-9 ,\\.\\(\\)\\%\\#-]+);$~', $line, $matches)) { $variables[$matches[1]] = $matches[2]; } } unset($variables['overrideLess']); } $this->compileStylesheet(WCF_DIR . 'style/style-' . $style->styleID, $files, $variables, $individualLess, new Callback(function ($content) use($style) { return "/* stylesheet for '" . $style->styleName . "', generated on " . gmdate('r') . " -- DO NOT EDIT */\n\n" . $content; })); }
/** * @see \wcf\system\importer\IImporter::import() */ public function import($oldID, array $data, array $additionalData = array()) { // copy smiley $data['smileyPath'] = 'images/smilies/' . basename($additionalData['fileLocation']); if (!@copy($additionalData['fileLocation'], WCF_DIR . $data['smileyPath'])) { return 0; } // check smileycode if (isset($this->knownCodes[mb_strtolower($data['smileyCode'])])) { return $this->knownCodes[mb_strtolower($data['smileyCode'])]; } $data['packageID'] = 1; if (!isset($data['aliases'])) { $data['aliases'] = ''; } // check aliases $aliases = array(); if (!empty($data['aliases'])) { $aliases = explode("\n", StringUtil::unifyNewlines($data['aliases'])); foreach ($aliases as $key => $alias) { if (isset($this->knownCodes[mb_strtolower($alias)])) { unset($aliases[$key]); } } $data['aliases'] = implode("\n", $aliases); } // get category id if (!empty($data['categoryID'])) { $data['categoryID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.smiley.category', $data['categoryID']); } // save smiley $smiley = SmileyEditor::create($data); // add smileyCode + aliases to knownCodes $this->knownCodes[mb_strtolower($data['smileyCode'])] = $smiley->smileyID; foreach ($aliases as $alias) { $this->knownCodes[mb_strtolower($alias)] = $smiley->smileyID; } return $smiley->smileyID; }
public function assignVariables() { parent::assignVariables(); if (WCF::getSession()->getPermission('user.cms.news.canStartPoll') && MODULE_POLL) { PollManager::getInstance()->assignVariables(); } if ($this->imageID && $this->imageID != 0) { $this->image = FileCache::getInstance()->getFile($this->imageID); } WCF::getTPL()->assign(array('categoryList' => $this->categoryList, 'categoryIDs' => $this->categoryIDs, 'imageID' => $this->imageID, 'image' => $this->image, 'teaser' => $this->teaser, 'time' => $this->time, 'action' => $this->action, 'tags' => $this->tags, 'allowedFileExtensions' => explode("\n", StringUtil::unifyNewlines(WCF::getSession()->getPermission('user.cms.news.allowedAttachmentExtensions'))))); }
/** * Returns a list of the enable options. * * @return array */ public function parseMultipleEnableOptions() { $result = array(); if (!empty($this->enableOptions)) { $options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($this->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; }
/** * Validates LESS-variable overrides. * * If an override is invalid, unknown or matches a variable covered by * the style editor itself, it will be silently discarded. */ protected function parseOverrides() { // get available variables $sql = "SELECT\tvariableName\n\t\t\tFROM\twcf" . WCF_N . "_style_variable"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); $variables = array(); while ($row = $statement->fetchArray()) { $variables[] = $row['variableName']; } $lines = explode("\n", StringUtil::unifyNewlines($this->variables['overrideLess'])); $regEx = new Regex('^@([a-zA-Z]+): ?([@a-zA-Z0-9 ,\\.\\(\\)\\%\\#-]+);$'); $errors = array(); foreach ($lines as $index => &$line) { $line = StringUtil::trim($line); // ignore empty lines if (empty($line)) { unset($lines[$index]); continue; } if ($regEx->match($line)) { $matches = $regEx->getMatches(); // cannot override variables covered by style editor if (in_array($matches[1], $this->colors) || in_array($matches[1], $this->globals) || in_array($matches[1], $this->specialVariables)) { $errors[] = array('error' => 'predefined', 'text' => $matches[1]); } else { if (!in_array($matches[1], $variables)) { // unknown style variable $errors[] = array('error' => 'unknown', 'text' => $matches[1]); } else { $this->variables[$matches[1]] = $matches[2]; } } } else { // not valid $errors[] = array('error' => 'notValid', 'text' => $line); } } $this->variables['overrideLess'] = implode("\n", $lines); if (!empty($errors)) { throw new UserInputException('overrideLess', $errors); } }
/** * @see \wcf\form\IForm::validate() */ public function validate() { parent::validate(); // validate fields if (empty($this->questionTitle)) { throw new \wcf\system\exception\UserInputException('questionTitle'); } if (!\wcf\system\language\I18nHandler::getInstance()->validateValue('questionMessage', false, true)) { throw new \wcf\system\exception\UserInputException('questionMessage'); } $lines = explode("\n", \wcf\util\StringUtil::unifyNewlines($this->questionMessage)); foreach ($lines as $line) { if (!\wcf\system\Regex::compile($line)->isValid()) { throw new \wcf\system\exception\UserInputException('questionMessage', 'notValid'); } } // end foreach-loop }
/** * @see \wcf\system\option\user\group\IUserGroupOptionType::merge() */ public function merge($defaultValue, $groupValue) { if ($this->bbCodes === null) { $this->loadBBCodeSelection(); } if ($defaultValue == 'all') { $defaultValue = $this->bbCodes; } else { if (empty($defaultValue) || $defaultValue == 'none') { $defaultValue = array(); } else { $defaultValue = explode(',', StringUtil::unifyNewlines($defaultValue)); } } if ($groupValue == 'all') { $groupValue = $this->bbCodes; } else { if (empty($groupValue) || $groupValue == 'none') { $groupValue = array(); } else { $groupValue = explode(',', StringUtil::unifyNewlines($groupValue)); } } $newValue = array_unique(array_merge($defaultValue, $groupValue)); sort($newValue); return implode(',', $newValue); }
private static function fixMessage($string) { $string = str_replace("\n", "<br />\n", StringUtil::unifyNewlines($string)); return $string; }
/** * @see \wcf\page\IPage::assignVariables() */ public function assignVariables() { parent::assignVariables(); WCF::getTPL()->assign(array('categoryList' => $this->categoryList, 'categoryIDs' => $this->categoryIDs, 'fileSubject' => $this->fileSubject, 'tags' => $this->tags, 'action' => 'add', 'teaser' => $this->teaser, 'uploadID' => $this->uploadID, 'fileUpload' => $this->fileUpload, 'website' => $this->website, 'allowedFileExtensions' => explode("\n", StringUtil::unifyNewlines(WCF::getSession()->getPermission('user.filebase.allowedFileExtensions'))))); }
/** * Compiles LESS stylesheets. * * @param \cms\data\stylesheet\Stylesheet $stylesheet * @param integer $styleID */ public function compile(Stylesheet $stylesheet, $styleID = null) { $styles = StyleHandler::getInstance()->getStyles(); // compile stylesheet for all installed styles if ($styleID === null) { foreach ($styles as $style) { $this->compile($stylesheet, $style->styleID); } return; } $style = $styles[$styleID]; // get style variables $variables = $style->getVariables(); if (isset($variables['individualLess'])) { unset($variables['individualLess']); } // add style image path $imagePath = '../images/'; if ($style->imagePath) { $imagePath = FileUtil::getRelativePath(WCF_DIR . 'style/', WCF_DIR . $style->imagePath); $imagePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator($imagePath)); } $variables['style_image_path'] = "'{$imagePath}'"; // apply overrides if (isset($variables['overrideLess'])) { $lines = explode("\n", StringUtil::unifyNewlines($variables['overrideLess'])); foreach ($lines as $line) { if (preg_match('~^@([a-zA-Z]+): ?([@a-zA-Z0-9 ,\\.\\(\\)\\%\\#-]+);$~', $line, $matches)) { $variables[$matches[1]] = $matches[2]; } } unset($variables['overrideLess']); } // add options as LESS variables foreach (Option::getOptions() as $constantName => $option) { if (in_array($option->optionType, array('boolean', 'integer'))) { $variables['wcf_option_' . mb_strtolower($constantName)] = '~"' . $option->optionValue . '"'; } } // compile $this->compiler->setVariables($variables); $content = "/* stylesheet for '" . $stylesheet->getTitle() . "', generated on " . gmdate('r') . " -- DO NOT EDIT */\n\n"; $content .= $this->compiler->compile($stylesheet->less); // compress stylesheet $lines = explode("\n", $content); $content = $lines[0] . "\n" . $lines[1] . "\n"; for ($i = 2, $length = count($lines); $i < $length; $i++) { $line = trim($lines[$i]); $content .= $line; switch (substr($line, -1)) { case ',': $content .= ' '; break; case '}': $content .= "\n"; break; } if (substr($line, 0, 6) == '@media') { $content .= "\n"; } } // write stylesheet $filename = $stylesheet->getLocation($styleID); file_put_contents($filename, $content); FileUtil::makeWritable($filename); // write rtl stylesheet $content = StyleUtil::convertCSSToRTL($content); $filename = $stylesheet->getLocation($styleID, true); file_put_contents($filename, $content); FileUtil::makeWritable($filename); }
/** * Returns an array with the list of all available workers. * * @return array */ public function generateList() { $directory = DirectoryUtil::getInstance(WCF_DIR . 'lib/system/worker/'); $workerList = $directory->getFiles(SORT_ASC, new Regex('Worker\\.class\\.php$')); $table = array(array('Class', 'Description')); foreach ($workerList as $worker) { $class = 'wcf\\system\\worker\\' . basename($worker, '.class.php'); if (!class_exists($class) && !interface_exists($class)) { Log::info('Invalid worker file: ', $worker); continue; } $reflection = new \ReflectionClass($class); if (!$reflection->isInstantiable()) { continue; } if (!ClassUtil::isInstanceOf($class, 'wcf\\system\\worker\\IWorker')) { Log::info('Invalid worker file: ', $worker); continue; } $docComment = explode("\n", StringUtil::unifyNewlines($reflection->getDocComment())); foreach ($docComment as $commentLine) { if (Regex::compile('[a-z]', Regex::CASE_INSENSITIVE)->match($commentLine)) { $comment = Regex::compile('^[^a-z]+', Regex::CASE_INSENSITIVE)->replace($commentLine, ''); break; } } $table[] = array(basename($worker, '.class.php'), $comment); } return $table; }
/** * @see \wcf\system\option\user\group\IUserGroupOptionType::merge() */ public function merge($defaultValue, $groupValue) { $defaultValue = empty($defaultValue) ? array() : explode(',', StringUtil::unifyNewlines($defaultValue)); $groupValue = empty($groupValue) ? array() : explode(',', StringUtil::unifyNewlines($groupValue)); return implode(',', array_unique(array_merge($defaultValue, $groupValue))); }
/** * @see \wcf\page\IPage::assignVariables() */ public function assignVariables() { parent::assignVariables(); WCF::getTPL()->assign(array('action' => 'add', 'uploadID' => $this->uploadID, 'fileUpload' => $this->fileUpload, 'entryID' => $this->entryID, 'entry' => $this->entry, 'allowedFileExtensions' => explode("\n", StringUtil::unifyNewlines(WCF::getSession()->getPermission('user.filebase.allowedFileExtensions'))))); }
/** * Creates a new PackageUpdateAuthForm object. * * @param PackageUpdateAuthorizationRequiredException $exception */ public function __construct(PackageUpdateAuthorizationRequiredException $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 != 'UTF-8') { $this->message = @StringUtil::convertEncoding($charset, 'UTF-8', $this->message); } } // format message $this->message = nl2br(preg_replace("/\n{3,}/", "\n\n", StringUtil::unifyNewlines(StringUtil::trim(strip_tags($this->message))))); } parent::__construct(); }
/** * Converts dos to unix newlines. * * @param array $array * @return 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; } }
/** * Exports labels. */ public function exportLabels($offset, $limit) { $prefixMap = array(); // get global prefixes $globalPrefixes = ''; $sql = "SELECT\toptionValue\n\t\t\tFROM\twcf" . $this->dbNo . "_option\n\t\t\tWHERE\toptionName = ?"; $statement = $this->database->prepareStatement($sql); $statement->execute(array('thread_default_prefixes')); $row = $statement->fetchArray(); if ($row !== false) { $globalPrefixes = $row['optionValue']; } // get boards if (substr($this->getPackageVersion('com.woltlab.wcf'), 0, 3) == '1.1') { $sql = "SELECT\t\tboardID, prefixes, prefixMode\n\t\t\t\tFROM\t\twbb" . $this->dbNo . "_" . $this->instanceNo . "_board\n\t\t\t\tWHERE\t\tprefixMode > ?"; $statement = $this->database->prepareStatement($sql); $statement->execute(array(0)); } else { $sql = "SELECT\t\tboardID, prefixes, 2 AS prefixMode\n\t\t\t\tFROM\t\twbb" . $this->dbNo . "_" . $this->instanceNo . "_board\n\t\t\t\tWHERE\t\tprefixes <> ?"; $statement = $this->database->prepareStatement($sql); $statement->execute(array('')); } while ($row = $statement->fetchArray()) { $prefixes = ''; switch ($row['prefixMode']) { case 1: $prefixes = $globalPrefixes; break; case 2: $prefixes = $row['prefixes']; break; case 3: $prefixes = $globalPrefixes . "\n" . $row['prefixes']; break; } $prefixes = StringUtil::trim(StringUtil::unifyNewlines($prefixes)); if ($prefixes) { $key = StringUtil::getHash($prefixes); if (!isset($prefixMap[$key])) { $prefixMap[$key] = array('prefixes' => $prefixes, 'boardIDs' => array()); } $boardID = ImportHandler::getInstance()->getNewID('com.woltlab.wbb.board', $row['boardID']); if ($boardID) { $prefixMap[$key]['boardIDs'][] = $boardID; } } } // save prefixes if (!empty($prefixMap)) { $i = 1; $objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.label.objectType', 'com.woltlab.wbb.board'); foreach ($prefixMap as $key => $data) { // import label group ImportHandler::getInstance()->getImporter('com.woltlab.wcf.label.group')->import($key, array('groupName' => 'labelgroup' . $i), array('objects' => array($objectType->objectTypeID => $data['boardIDs']))); // import labels $labels = explode("\n", $data['prefixes']); foreach ($labels as $label) { ImportHandler::getInstance()->getImporter('com.woltlab.wcf.label')->import($key . '-' . $label, array('groupID' => $key, 'label' => mb_substr($label, 0, 80))); } $i++; } } }
/** * Assigns element values to template. Using request data once reading * initial database data is explicitly disallowed. * * @param boolean $useRequestData */ public function assignVariables($useRequestData = true) { $elementValues = array(); $elementValuesI18n = array(); foreach ($this->elementIDs as $elementID) { $value = ''; $i18nValues = array(); // use POST values instead of querying database if ($useRequestData) { if ($this->isPlainValue($elementID)) { $value = $this->getValue($elementID); } else { if ($this->hasI18nValues($elementID)) { $i18nValues = $this->i18nValues[$elementID]; // encoding the entries for javascript foreach ($i18nValues as $languageID => $value) { $i18nValues[$languageID] = StringUtil::encodeJS(StringUtil::unifyNewlines($value)); } } else { $i18nValues = array(); } } } else { $isI18n = Regex::compile('^' . $this->elementOptions[$elementID]['pattern'] . '$')->match($this->elementOptions[$elementID]['value']); if (!$isI18n) { // check if it's a regular language variable $isI18n = Regex::compile('^([a-zA-Z0-9-_]+\\.)+[a-zA-Z0-9-_]+$')->match($this->elementOptions[$elementID]['value']); } if ($isI18n) { // use i18n values from language items $sql = "SELECT\tlanguageID, languageItemValue\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\tWHERE\tlanguageItem = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->elementOptions[$elementID]['value'])); while ($row = $statement->fetchArray()) { $languageItemValue = StringUtil::unifyNewlines($row['languageItemValue']); $i18nValues[$row['languageID']] = StringUtil::encodeJS($languageItemValue); if ($row['languageID'] == LanguageFactory::getInstance()->getDefaultLanguageID()) { $value = $languageItemValue; } } // item appeared to be a language item but either is not or does not exist if (empty($i18nValues) && empty($value)) { $value = $this->elementOptions[$elementID]['value']; } } else { // use data provided by setOptions() $value = $this->elementOptions[$elementID]['value']; } } $elementValues[$elementID] = $value; $elementValuesI18n[$elementID] = $i18nValues; } WCF::getTPL()->assign(array('availableLanguages' => $this->availableLanguages, 'i18nPlainValues' => $elementValues, 'i18nValues' => $elementValuesI18n)); }
/** * @see \wcf\system\image\adapter\IImageAdapter::drawTextRelative() */ public function drawTextRelative($text, $position, $margin, $offsetX, $offsetY, $font, $size, $opacity = 1) { // split text into multiple lines $lines = explode("\n", StringUtil::unifyNewlines($text)); // calc text width, height and first line height $box = imagettfbbox($size, 0, $font, $text); $firstLineBox = imagettfbbox($size, 0, $font, $lines[0]); $textWidth = abs($box[0] - $box[2]); $textHeight = abs($box[7] - $box[1]); $firstLineHeight = abs($firstLineBox[7] - $firstLineBox[1]); // calculate x coordinate $x = 0; switch ($position) { case 'topLeft': case 'middleLeft': case 'bottomLeft': $x = $margin; break; case 'topCenter': case 'middleCenter': case 'bottomCenter': $x = floor(($this->getWidth() - $textWidth) / 2); break; case 'topRight': case 'middleRight': case 'bottomRight': $x = $this->getWidth() - $textWidth - $margin; break; } // calculate y coordinate $y = 0; switch ($position) { case 'topLeft': case 'topCenter': case 'topRight': $y = $margin + $firstLineHeight; break; case 'middleLeft': case 'middleCenter': case 'middleRight': $y = floor(($this->getHeight() - $textHeight) / 2) + $firstLineHeight; break; case 'bottomLeft': case 'bottomCenter': case 'bottomRight': $y = $this->getHeight() - $textHeight + $firstLineHeight - $margin; break; } $this->drawText($text, $x + $offsetX, $y + $offsetY, $font, $size, $opacity); }