/** * Returns the extension of the original file name. * * @return string */ public function getFileExtension() { if (($position = StringUtil::lastIndexOf($this->getFilename(), '.')) !== false) { return StringUtil::toLowerCase(StringUtil::substring($this->getFilename(), $position + 1)); } return ''; }
/** * Prepares JSON-encoded values for disabling or enabling dependent options. * * @param wcf\data\option\Option $option * @return array */ protected function parseEnableOptions(Option $option) { $disableOptions = $enableOptions = ''; if (!empty($option->enableOptions)) { $options = $option->parseMultipleEnableOptions(); foreach ($options as $key => $optionData) { $tmp = explode(',', $optionData); foreach ($optionData as $item) { if ($item{0} == '!') { if (!empty($disableOptions)) $disableOptions .= ','; $disableOptions .= "{ value: '".$key."', option: '".StringUtil::substring($item, 1)."' }"; } else { if (!empty($enableOptions)) $enableOptions .= ','; $enableOptions .= "{ value: '".$key."', option: '".$item."' }"; } } } } return array( 'disableOptions' => $disableOptions, 'enableOptions' => $enableOptions ); }
/** * @see wcf\system\template\IModifierTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { // default values $length = 80; $etc = '...'; $breakWords = false; // get values $string = $tagArgs[0]; if (isset($tagArgs[1])) { $length = intval($tagArgs[1]); } if (isset($tagArgs[2])) { $etc = $tagArgs[2]; } if (isset($tagArgs[3])) { $breakWords = $tagArgs[3]; } // execute plugin if ($length == 0) { return ''; } if (StringUtil::length($string) > $length) { $length -= StringUtil::length($etc); if (!$breakWords) { $string = preg_replace('/\\s+?(\\S+)?$/', '', StringUtil::substring($string, 0, $length + 1)); } return StringUtil::substring($string, 0, $length) . $etc; } else { return $string; } }
/** * Inserts the page number into the link. * * @param string $link * @param integer $pageNo * @return string final link */ protected static function insertPageNumber($link, $pageNo) { $startPos = StringUtil::indexOf($link, '%d'); if ($startPos !== null) { $link = StringUtil::substring($link, 0, $startPos) . $pageNo . StringUtil::substring($link, $startPos + 2); } return $link; }
/** * Creates a new ActiveStyle object. * * @param Style $object */ public function __construct(Style $object) { parent::__construct($object); // calculate page logo path if (!empty($this->object->data['variables']['page.logo.image']) && !FileUtil::isURL($this->object->data['variables']['page.logo.image']) && StringUtil::substring($this->object->data['variables']['page.logo.image'], 0, 1) !== '/') { $this->object->data['variables']['page.logo.image'] = RELATIVE_WCF_DIR . $this->object->data['variables']['page.logo.image']; } // load icon cache $cacheName = 'icon-' . PACKAGE_ID . '-' . $this->styleID; CacheHandler::getInstance()->addResource($cacheName, WCF_DIR . 'cache/cache.' . $cacheName . '.php', 'wcf\\system\\cache\\builder\\IconCacheBuilder'); $this->iconCache = CacheHandler::getInstance()->get($cacheName); }
/** * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() */ public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { $compiler->pushTag('implode'); if (!isset($tagArgs['from'])) { throw new SystemException($compiler->formatSyntaxError("missing 'from' argument in implode tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); } if (!isset($tagArgs['item'])) { throw new SystemException($compiler->formatSyntaxError("missing 'item' argument in implode tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); } $hash = StringUtil::getRandomID(); $glue = isset($tagArgs['glue']) ? $tagArgs['glue'] : "', '"; $this->tagStack[] = array('hash' => $hash, 'glue' => $glue); $phpCode = "<?php\n"; $phpCode .= "\$_length" . $hash . " = count(" . $tagArgs['from'] . ");\n"; $phpCode .= "\$_i" . $hash . " = 0;\n"; $phpCode .= "foreach (" . $tagArgs['from'] . " as " . (isset($tagArgs['key']) ? (StringUtil::substring($tagArgs['key'], 0, 1) != '$' ? "\$this->v[" . $tagArgs['key'] . "]" : $tagArgs['key']) . " => " : '') . (StringUtil::substring($tagArgs['item'], 0, 1) != '$' ? "\$this->v[" . $tagArgs['item'] . "]" : $tagArgs['item']) . ") { ?>"; return $phpCode; }
/** * Returns a list of options by object type id. * * @param integer $objectTypeID * @param string $categoryName * @return wcf\data\acl\option\ACLOptionList */ public function getOptions($objectTypeID, $categoryName = '') { $optionList = new ACLOptionList(); if (!empty($categoryName)) { if (StringUtil::endsWith($categoryName, '.*')) { $categoryName = StringUtil::substring($categoryName, 0, -1) . '%'; $optionList->getConditionBuilder()->add("acl_option.categoryName LIKE ?", array($categoryName)); } else { $optionList->getConditionBuilder()->add("acl_option.categoryName = ?", array($categoryName)); } } $optionList->getConditionBuilder()->add("acl_option.objectTypeID = ?", array($objectTypeID)); $optionList->readObjects(); return $optionList; }
/** * Returns the request uri of the active request. * * @return string */ public static function getRequestURI() { $REQUEST_URI = ''; $appendQueryString = true; if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], '.php') !== false) { $REQUEST_URI = $_SERVER['ORIG_PATH_INFO']; } else if (!empty($_SERVER['ORIG_SCRIPT_NAME'])) { $REQUEST_URI = $_SERVER['ORIG_SCRIPT_NAME']; } else if (!empty($_SERVER['SCRIPT_NAME']) && (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO']))) { $REQUEST_URI = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']; } else if (isset($_SERVER['REQUEST_URI']) && !empty($_SERVER['REQUEST_URI'])) { $REQUEST_URI = $_SERVER['REQUEST_URI']; $appendQueryString = false; } else if (!empty($_SERVER['PHP_SELF'])) { $REQUEST_URI = $_SERVER['PHP_SELF']; } else if (!empty($_SERVER['PATH_INFO'])) { $REQUEST_URI = $_SERVER['PATH_INFO']; } if ($appendQueryString && !empty($_SERVER['QUERY_STRING'])) { $REQUEST_URI .= '?'.$_SERVER['QUERY_STRING']; } // fix encoding if (!StringUtil::isASCII($REQUEST_URI) && !StringUtil::isUTF8($REQUEST_URI)) { $REQUEST_URI = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $REQUEST_URI); } return StringUtil::substring(FileUtil::unifyDirSeperator($REQUEST_URI), 0, 255); }
/** * Imports a style. * * @param string $filename * @param integer $packageID * @param StyleEditor $style * @return StyleEditor */ public static function import($filename, $packageID = PACKAGE_ID, StyleEditor $style = null) { // open file $tar = new Tar($filename); // get style data $data = self::readStyleData($tar); $styleData = array( 'styleName' => $data['name'], 'variables' => $data['variables'], 'styleVersion' => $data['version'], 'styleDate' => $data['date'], 'copyright' => $data['copyright'], 'license' => $data['license'], 'authorName' => $data['authorName'], 'authorURL' => $data['authorURL'] ); // create template group $templateGroupID = 0; if (!empty($data['templates'])) { $templateGroupName = $originalTemplateGroupName = $data['name']; $templateGroupFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templateGroupName); if (empty($templateGroupFolderName)) $templateGroupFolderName = 'generic'.StringUtil::substring(StringUtil::getRandomID(), 0, 8); $originalTemplateGroupFolderName = $templateGroupFolderName; // get unique template pack name $i = 1; while (true) { $sql = "SELECT COUNT(*) AS count FROM wcf".WCF_N."_template_group WHERE templateGroupName = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($templateGroupName)); $row = $statement->fetchArray(); if (!$row['count']) break; $templateGroupName = $originalTemplateGroupName . '_' . $i; $i++; } // get unique folder name $i = 1; while (true) { $sql = "SELECT COUNT(*) AS count FROM wcf".WCF_N."_template_group WHERE templateGroupFolderName = ? AND parentTemplatePackID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array( FileUtil::addTrailingSlash($templateGroupFolderName), 0 )); $row = $statement->fetchArray(); if (!$row['count']) break; $templateGroupFolderName = $originalTemplateGroupFolderName . '_' . $i; $i++; } $templateGroup = TemplateGroupEditor::create(array( 'templateGroupName' => $templateGroupName, 'templateGroupFolderName' => FileUtil::addTrailingSlash($templateGroupFolderName) )); $styleData['templateGroupID'] = $templateGroup->templateGroupID; } // import preview image if (!empty($data['image'])) { $fileExtension = StringUtil::substring($data['image'], StringUtil::lastIndexOf($data['image'], '.')); $index = $tar->getIndexByFilename($data['image']); if ($index !== false) { $filename = WCF_DIR.'images/stylePreview-'.$style->styleID.'.'.$fileExtension; $tar->extract($index, $filename); @chmod($filename, 0777); if (file_exists($filename)) { $styleData['image'] = $filename; } } } // import images if (!empty($data['images']) && $data['imagesPath'] != 'images/') { // create images folder if necessary $imagesLocation = self::getFileLocation($data['imagesPath']); $styleData['imagePath'] = FileUtil::getRelativePath(WCF_DIR, $imagesLocation); $index = $tar->getIndexByFilename($data['images']); if ($index !== false) { // extract images tar $destination = FileUtil::getTemporaryFilename('images_'); $tar->extract($index, $destination); // open images tar $imagesTar = new Tar($destination); $contentList = $imagesTar->getContentList(); foreach ($contentList as $key => $val) { if ($val['type'] == 'file') { $imagesTar->extract($key, $imagesLocation.basename($val['filename'])); @chmod($imagesLocation.basename($val['filename']), 0666); } } // delete tmp file $imagesTar->close(); @unlink($destination); } } // import templates if (!empty($data['templates'])) { $index = $tar->getIndexByFilename($data['templates']); if ($index !== false) { // extract templates tar $destination = FileUtil::getTemporaryFilename('templates_'); $tar->extract($index, $destination); // open templates tar and group templates by package $templatesTar = new Tar($destination); $contentList = $templatesTar->getContentList(); $packageToTemplates = array(); foreach ($contentList as $val) { if ($val['type'] == 'file') { $folders = explode('/', $val['filename']); $packageName = array_shift($folders); if (!isset($packageToTemplates[$packageName])) { $packageToTemplates[$packageName] = array(); } $packageToTemplates[$packageName][] = array('index' => $val['index'], 'filename' => implode('/', $folders)); } } // copy templates foreach ($packageToTemplates as $package => $templates) { // try to find package $sql = "SELECT * FROM wcf".WCF_N."_package WHERE package = ? AND isApplication = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array( $package, 1 )); while ($row = $statement->fetchArray()) { // get template path $templatesDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$row['packageDir']).'templates/'.$templateGroupFolderName); // create template path if (!file_exists($templatesDir)) { @mkdir($templatesDir, 0777); @chmod($templatesDir, 0777); } // copy templates foreach ($templates as $template) { $templatesTar->extract($template['index'], $templatesDir.$template['filename']); TemplateEditor::create(array( 'packageID' => $row['packageID'], 'templateName' => StringUtil::replace('.tpl', '', $template['filename']), 'templateGroupID' => $templateGroupID )); } } } // delete tmp file $templatesTar->close(); @unlink($destination); } } $tar->close(); // save style if ($style !== null) { $style->update($styleData); } else { $styleData['packageID'] = $packageID; $style = new StyleEditor(self::create($styleData)); } // handle descriptions if (!empty($data['description'])) { self::saveLocalizedDescriptions($style, $data['description']); } if ($data['default']) { $style->setAsDefault(); } return $style; }
/** * Returns html entities of all characters in the given string. * * @param string $string * @return string */ public static function encodeAllChars($string) { $result = ''; for ($i = 0, $j = StringUtil::length($string); $i < $j; $i++) { $char = StringUtil::substring($string, $i, 1); $result .= '&#' . StringUtil::getCharValue($char) . ';'; } return $result; }
/** * Creates a new DatabaseObjectList object. */ public function __construct() { // set class name if (empty($this->className)) { $className = get_called_class(); if (StringUtil::substring($className, -4) == 'List') { $this->className = StringUtil::substring($className, 0, -4); } } $this->conditionBuilder = new PreparedStatementConditionBuilder(); }
/** * Initialize a new DatabaseObject-related action. * * @param array<mixed> $objects * @param string $action * @param array $parameters */ public function __construct(array $objects, $action, array $parameters = array()) { // set class name if (empty($this->className)) { $className = get_called_class(); if (StringUtil::substring($className, -6) == 'Action') { $this->className = StringUtil::substring($className, 0, -6).'Editor'; } } $indexName = call_user_func(array($this->className, 'getDatabaseTableIndexName')); $baseClass = call_user_func(array($this->className, 'getBaseClass')); foreach ($objects as $object) { if (is_object($object)) { if ($object instanceof $this->className) { $this->objects[] = $object; } else if ($object instanceof $baseClass) { $this->objects[] = new $this->className($object); } else { throw new SystemException('invalid value of parameter objects given'); } $this->objectIDs[] = $object->$indexName; } else { $this->objectIDs[] = $object; } } $this->action = $action; $this->parameters = $parameters; // fire event action EventHandler::getInstance()->fireAction($this, 'initializeAction'); }
/** * Converts shorthand byte values into an integer representing bytes. * * @param string $value * @return integer * @see http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes */ protected static function convertShorthandByteValue($value) { // convert into bytes $lastCharacter = StringUtil::substring($value, -1); switch ($lastCharacter) { // gigabytes case 'g': return (int)$value * 1073741824; break; // megabytes case 'm': return (int)$value * 1048576; break; // kilobytes case 'k': return (int)$value * 1024; break; default: return $value; break; } }
/** * Compiles an output tag and returns the compiled PHP code. * * @param string $tag * @return string */ protected function compileOutputTag($tag) { $encodeHTML = false; $formatNumeric = false; if ($tag[0] == '@') { $tag = StringUtil::substring($tag, 1); } else if ($tag[0] == '#') { $tag = StringUtil::substring($tag, 1); $formatNumeric = true; } else { $encodeHTML = true; } $parsedTag = $this->compileVariableTag($tag); // the @ operator at the beginning of an output avoids // the default call of StringUtil::encodeHTML() if ($encodeHTML) { $parsedTag = 'wcf\util\StringUtil::encodeHTML('.$parsedTag.')'; } // the # operator at the beginning of an output instructs // the complier to call the StringUtil::formatNumeric() method else if ($formatNumeric) { $parsedTag = 'wcf\util\StringUtil::formatNumeric('.$parsedTag.')'; } return '<?php echo '.$parsedTag.'; ?>'; }
/** * Determines schema for given document. */ protected function getSchema() { // determine schema by looking for xsi:schemaLocation $this->schema = $this->document->documentElement->getAttributeNS($this->document->documentElement->lookupNamespaceURI('xsi'), 'schemaLocation'); // no valid schema found or it's lacking a valid namespace if (strpos($this->schema, ' ') === false) { throw new SystemException("XML document '".$this->path."' does not provide a valid schema."); } // build file path upon namespace and filename $tmp = explode(' ', $this->schema); $this->schema = WCF_DIR.'xsd/'.StringUtil::substring(sha1($tmp[0]), 0, 8) . '_' . basename($tmp[1]); if (!file_exists($this->schema) || !is_readable($this->schema)) { throw new SystemException("Could not read XML schema definition located at '".$this->schema."'."); } }
/** * Returns a short SHA1-hash. * * @return string */ protected function getToken() { return StringUtil::substring(StringUtil::getRandomID(), 0, 8); }
/** * Copies a style. * * @return array<string> */ public function copy() { // get unique style name $sql = "SELECT styleName FROM wcf".WCF_N."_style WHERE styleName LIKE ? AND styleID <> ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array( $this->styleEditor->styleName.'%', $this->styleEditor->styleID )); $numbers = array(); $regEx = new Regex('\((\d+)\)$'); while ($row = $statement->fetchArray()) { $styleName = $row['styleName']; if ($regEx->match($styleName)) { $matches = $regEx->getMatches(); // check if name matches the pattern 'styleName (x)' if ($styleName == $this->styleEditor->styleName . ' ('.$matches[1].')') { $numbers[] = $matches[1]; } } } $number = (count($numbers)) ? max($numbers) + 1 : 2; $styleName = $this->styleEditor->styleName . ' ('.$number.')'; // create the new style $newStyle = StyleEditor::create(array( 'packageID' => PACKAGE_ID, 'styleName' => $styleName, 'templateGroupID' => $this->styleEditor->templateGroupID, 'isDisabled' => 1, // newly created styles are disabled by default 'styleDescription' => $this->styleEditor->styleDescription, 'styleVersion' => $this->styleEditor->styleVersion, 'styleDate' => $this->styleEditor->styleDate, 'copyright' => $this->styleEditor->copyright, 'license' => $this->styleEditor->license, 'authorName' => $this->styleEditor->authorName, 'authorURL' => $this->styleEditor->authorURL, 'imagePath' => $this->styleEditor->imagePath )); // copy style variables $sql = "INSERT INTO wcf".WCF_N."_style_variable_value (styleID, variableID, variableValue) SELECT ".$newStyle->styleID." AS styleID, value.variableID, value.variableValue FROM wcf".WCF_N."_style_variable_value value WHERE value.styleID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->styleEditor->styleID)); // copy preview image if ($this->styleEditor->image) { // get extension $fileExtension = StringUtil::substring($this->styleEditor->image, StringUtil::lastIndexOf($this->styleEditor->image, '.')); // copy existing preview image if (@copy(WCF_DIR.'images/'.$this->styleEditor->image, WCF_DIR.'images/stylePreview-'.$newStyle->styleID.$fileExtension)) { // bypass StyleEditor::update() to avoid scaling of already fitting image $sql = "UPDATE wcf".WCF_N."_style SET image = ? WHERE styleID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array( 'stylePreview-'.$newStyle->styleID.$fileExtension, $newStyle->styleID )); } } return array( 'redirectURL' => LinkHandler::getInstance()->getLink('StyleEdit', array('id' => $newStyle->styleID)) ); }
/** * Parses enableOptions. * * @param string $optionData * @return array */ public static function parseEnableOptions($optionData) { $disableOptions = $enableOptions = ''; if (!empty($optionData)) { $options = explode(',', $optionData); foreach ($options as $item) { if ($item{0} == '!') { if (!empty($disableOptions)) $disableOptions .= ','; $disableOptions .= "'".StringUtil::substring($item, 1)."' "; } else { if (!empty($enableOptions)) $enableOptions .= ','; $enableOptions .= "'".$item."' "; } } } return array( 'disableOptions' => $disableOptions, 'enableOptions' => $enableOptions ); }
/** * Imports a style. * * @param string $filename * @param integer $packageID * @param StyleEditor $style * @return StyleEditor */ public static function import($filename, $packageID = PACKAGE_ID, StyleEditor $style = null) { // open file $tar = new Tar($filename); // get style data $data = self::readStyleData($tar); // get image locations $iconsLocation = FileUtil::addTrailingSlash($data['variables']['global.icons.location']); $imagesLocation = $data['variables']['global.images.location']; // create template group $templateGroupID = 0; if (!empty($data['templates'])) { $templateGroupName = $data['name']; $templateGroupFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templateGroupName); if (empty($templateGroupFolderName)) { $templateGroupFolderName = 'generic' . StringUtil::substring(StringUtil::getRandomID(), 0, 8); } $originalTemplatePackFolderName = $templateGroupFolderName; // get unique template pack name $i = 1; do { $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_template_group\n\t\t\t\t\tWHERE\ttemplateGroupName = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($templateGroupName)); $row = $statement->fetchArray(); if (!$row['count']) { break; } $templateGroupName = $originalTemplatePackName . '_' . $i; //TODO: undefined variable $i++; } while (true); // get unique folder name $i = 1; do { $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_template_group\n\t\t\t\t\tWHERE\ttemplateGroupFolderName = ?\n\t\t\t\t\t\tAND parentTemplatePackID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(FileUtil::addTrailingSlash($templateGroupFolderName), 0)); $row = $statement->fetchArray(); if (!$row['count']) { break; } $templateGroupFolderName = $originalTemplatePackFolderName . '_' . $i; $i++; } while (true); $templateGroup = TemplateGroupEditor::create(array('templateGroupName' => $templateGroupName, 'templateGroupFolderName' => FileUtil::addTrailingSlash($templateGroupFolderName))); $templateGroupID = $templateGroup->templateGroupID; } // save style $styleData = array('styleName' => $data['name'], 'variables' => $data['variables'], 'templateGroupID' => $templateGroupID, 'styleDescription' => $data['description'], 'styleVersion' => $data['version'], 'styleDate' => $data['date'], 'image' => ($data['image'] ? 'images/' : '') . $data['image'], 'copyright' => $data['copyright'], 'license' => $data['license'], 'authorName' => $data['authorName'], 'authorURL' => $data['authorURL']); if ($style !== null) { $style->update($styleData); } else { $styleData['packageID'] = $packageID; $style = self::create($styleData); } // import preview image if (!empty($data['image'])) { $i = $tar->getIndexByFilename($data['image']); if ($i !== false) { $tar->extract($i, WCF_DIR . 'images/' . $data['image']); @chmod(WCF_DIR . 'images/' . $data['image'], 0777); } } // import images if (!empty($data['images'])) { // create images folder if necessary if (!file_exists(WCF_DIR . $imagesLocation)) { @mkdir(WCF_DIR . $data['variables']['global.images.location'], 0777); @chmod(WCF_DIR . $data['variables']['global.images.location'], 0777); } $i = $tar->getIndexByFilename($data['images']); if ($i !== false) { // extract images tar $destination = FileUtil::getTemporaryFilename('images_'); $tar->extract($i, $destination); // open images tar $imagesTar = new Tar($destination); $contentList = $imagesTar->getContentList(); foreach ($contentList as $key => $val) { if ($val['type'] == 'file') { $imagesTar->extract($key, WCF_DIR . $imagesLocation . basename($val['filename'])); @chmod(WCF_DIR . $imagesLocation . basename($val['filename']), 0666); } } // delete tmp file $imagesTar->close(); @unlink($destination); } } // import icons if (!empty($data['icons']) && $iconsLocation != 'icon/') { $i = $tar->getIndexByFilename($data['icons']); if ($i !== false) { // extract icons tar $destination = FileUtil::getTemporaryFilename('icons_'); $tar->extract($i, $destination); // open icons tar and group icons by package $iconsTar = new Tar($destination); $contentList = $iconsTar->getContentList(); $packageToIcons = array(); foreach ($contentList as $val) { if ($val['type'] == 'file') { $folders = explode('/', $val['filename']); $packageName = array_shift($folders); if (!isset($packageToIcons[$packageName])) { $packageToIcons[$packageName] = array(); } $packageToIcons[$packageName][] = array('index' => $val['index'], 'filename' => implode('/', $folders)); } } // copy icons foreach ($packageToIcons as $package => $icons) { // try to find package $sql = "SELECT\t*\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackage = ?\n\t\t\t\t\t\t\tAND isApplication = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($package, 1)); while ($row = $statement->fetchArray()) { // get icon path $iconDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . $iconsLocation; // create icon path if (!file_exists($iconDir)) { @mkdir($iconDir, 0777); @chmod($iconDir, 0777); } // copy icons foreach ($icons as $icon) { $iconsTar->extract($icon['index'], $iconDir . $icon['filename']); } } } // delete tmp file $iconsTar->close(); @unlink($destination); } } // import templates if (!empty($data['templates'])) { $i = $tar->getIndexByFilename($data['templates']); if ($i !== false) { // extract templates tar $destination = FileUtil::getTemporaryFilename('templates_'); $tar->extract($i, $destination); // open templates tar and group templates by package $templatesTar = new Tar($destination); $contentList = $templatesTar->getContentList(); $packageToTemplates = array(); foreach ($contentList as $val) { if ($val['type'] == 'file') { $folders = explode('/', $val['filename']); $packageName = array_shift($folders); if (!isset($packageToTemplates[$packageName])) { $packageToTemplates[$packageName] = array(); } $packageToTemplates[$packageName][] = array('index' => $val['index'], 'filename' => implode('/', $folders)); } } // copy templates foreach ($packageToTemplates as $package => $templates) { // try to find package $sql = "SELECT\t*\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackage = ?\n\t\t\t\t\t\t\tAND isApplication = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($package, 1)); while ($row = $statement->fetchArray()) { // get icon path $templatesDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . 'templates/' . $templateGroupFolderName); // create template path if (!file_exists($templatesDir)) { @mkdir($templatesDir, 0777); @chmod($templatesDir, 0777); } // copy templates foreach ($templates as $template) { $templatesTar->extract($template['index'], $templatesDir . $template['filename']); TemplateEditor::create(array('packageID' => $row['packageID'], 'templateName' => StringUtil::replace('.tpl', '', $template['filename']), 'templateGroupID' => $templateGroupID)); } } } // delete tmp file $templatesTar->close(); @unlink($destination); } } $tar->close(); return $style; }
/** * Calculates all values matching possible expressions. * * @param string $fieldName * @param string $fieldValue * @return array */ protected static function calculateValue($fieldName, $fieldValue) { $values = array(); // examinate first char $char = StringUtil::substring($fieldValue, 0, 1); // could be a single value, range or list if (is_numeric($char)) { $items = self::getListItems($fieldValue); foreach ($items as $item) { $values = array_merge($values, self::getRanges($item)); } } else { if ($char == '*') { $step = 1; if (StringUtil::indexOf($fieldValue, '/') !== false) { $rangeData = explode('/', $fieldValue); $step = $rangeData[1]; } $values = self::calculateRange(self::$ranges[$fieldName][0], self::$ranges[$fieldName][1], $step); } } sort($values, SORT_NUMERIC); return $values; }
/** * Returns a blowfish salt, e.g. $2a$07$usesomesillystringforsalt$ * * @param string $salt * @return string */ protected static function getSalt($salt) { $salt = StringUtil::substring($salt, 0, 22); return '$' . self::BCRYPT_TYPE . '$' . self::BCRYPT_COST . '$' . $salt; }
/** * Creates a new DatabaseObjectList object. */ public function __construct() { // set class name if (empty($this->className)) { $className = get_called_class(); if (StringUtil::substring($className, -4) == 'List') { $this->className = StringUtil::substring($className, 0, -4); } } if (!empty($this->decoratorClassName)) { // validate decorator class name if (!ClassUtil::isInstanceOf($this->decoratorClassName, 'wcf\data\DatabaseObjectDecorator')) { throw new SystemException("'".$this->decoratorClassName."' should extend 'wcf\data\DatabaseObjectDecorator'"); } $objectClassName = $this->objectClassName ?: $this->className; $baseClassName = call_user_func(array($this->decoratorClassName, 'getBaseClass')); if ($objectClassName != $baseClassName && !ClassUtil::isInstanceOf($baseClassName, $objectClassName)) { throw new SystemException("'".$this->decoratorClassName."' can't decorate objects of class '".$objectClassName."'"); } } $this->conditionBuilder = new PreparedStatementConditionBuilder(); }
/** * @see \wcf\system\event\listener\IParameterizedEventListener::execute() */ public function execute($eventObj, $className, $eventName, array &$parameters) { if (MODULE_JCOINS == 0 || MODULE_LIKE == 0) { return; } switch ($eventObj->getActionName()) { case 'like': case 'dislike': break; default: return; } $returnValues = $eventObj->getReturnValues(); $returnValues = $returnValues['returnValues']; $objectID = $eventObj->getParameters(); $like = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.like.likeableObject', $objectID['data']['objectType'])->getProcessor()->getObjectByID($objectID['data']['objectID']); // the object-user-id is unknown if (!$like->userID) { return; } $addtionalData = array('username' => \wcf\system\WCF::getUser()->username); if ($like->getObjectID() != 0) { $addtionalData['title'] = $like->getTitle(); } // because a title which is to long is uncool (profile-comments) if (isset($addtionalData['title']) && StringUtil::length($addtionalData['title']) > 30) { $addtionalData['title'] = StringUtil::substring($addtionalData['title'], 0, 26); $addtionalData['title'] .= '...'; } switch ($returnValues['oldValue']) { case Like::LIKE: if (JCOINS_RECEIVECOINS_LIKE != 0) { $this->statementAction = new UserJcoinsStatementAction(array(), 'create', array('data' => array('userID' => $like->userID, 'reason' => 'wcf.jcoins.statement.like.revoke', 'sum' => JCOINS_RECEIVECOINS_LIKE * -1, 'link' => $like->getURL(), 'additionalData' => $addtionalData), 'changeBalance' => 1)); $this->statementAction->validateAction(); $this->statementAction->executeAction(); } break; case Like::DISLIKE: if (JCOINS_RECEIVECOINS_DISLIKE != 0) { $this->statementAction = new UserJcoinsStatementAction(array(), 'create', array('data' => array('userID' => $like->userID, 'reason' => 'wcf.jcoins.statement.dislike.revoke', 'sum' => JCOINS_RECEIVECOINS_DISLIKE * -1, 'link' => $like->getURL(), 'additionalData' => $addtionalData), 'changeBalance' => 1)); $this->statementAction->validateAction(); $this->statementAction->executeAction(); } break; } switch ($returnValues['newValue']) { case Like::LIKE: if (JCOINS_RECEIVECOINS_LIKE != 0) { $this->statementAction = new UserJcoinsStatementAction(array(), 'create', array('data' => array('userID' => $like->userID, 'reason' => 'wcf.jcoins.statement.like.recive', 'sum' => JCOINS_RECEIVECOINS_LIKE, 'link' => $like->getURL(), 'additionalData' => $addtionalData), 'changeBalance' => 1)); $this->statementAction->validateAction(); $this->statementAction->executeAction(); } break; case Like::DISLIKE: if (JCOINS_RECEIVECOINS_DISLIKE != 0) { $this->statementAction = new UserJcoinsStatementAction(array(), 'create', array('data' => array('userID' => $like->userID, 'reason' => 'wcf.jcoins.statement.dislike.recive', 'sum' => JCOINS_RECEIVECOINS_DISLIKE, 'link' => $like->getURL(), 'additionalData' => $addtionalData), 'changeBalance' => 1)); $this->statementAction->validateAction(); $this->statementAction->executeAction(); } break; } }