/** * 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\page\IPage::readData() */ public function readData() { parent::readData(); // init cache data $this->cacheData = array('source' => get_class(CacheHandler::getInstance()->getCacheSource()), 'version' => '', 'size' => 0, 'files' => 0); switch ($this->cacheData['source']) { case 'wcf\\system\\cache\\source\\DiskCacheSource': // set version $this->cacheData['version'] = WCF_VERSION; $this->readCacheFiles('data', WCF_DIR . 'cache'); break; case 'wcf\\system\\cache\\source\\MemcachedCacheSource': // set version $this->cacheData['version'] = WCF_VERSION; break; } $this->readCacheFiles('language', FileUtil::unifyDirSeparator(WCF_DIR . 'language')); $this->readCacheFiles('template', FileUtil::unifyDirSeparator(WCF_DIR . 'templates/compiled'), new Regex('\\.meta\\.php$')); $this->readCacheFiles('template', FileUtil::unifyDirSeparator(WCF_DIR . 'acp/templates/compiled'), new Regex('\\.meta\\.php$')); $this->readCacheFiles('style', FileUtil::unifyDirSeparator(WCF_DIR . 'style'), null, 'css'); $this->readCacheFiles('style', FileUtil::unifyDirSeparator(WCF_DIR . 'acp/style'), new Regex('WCFSetup.css$'), 'css'); }
/** * Exports this style. * * @param boolean $templates * @param boolean $images * @param string $packageName */ public function export($templates = false, $images = false, $packageName = '') { // create style tar $styleTarName = FileUtil::getTemporaryFilename('style_', '.tgz'); $styleTar = new TarWriter($styleTarName, true); // append style preview image if ($this->image && @file_exists(WCF_DIR . 'images/' . $this->image)) { $styleTar->add(WCF_DIR . 'images/' . $this->image, '', FileUtil::addTrailingSlash(dirname(WCF_DIR . 'images/' . $this->image))); } // fetch style description $sql = "SELECT\t\tlanguage.languageCode, language_item.languageItemValue\n\t\t\tFROM\t\twcf" . WCF_N . "_language_item language_item\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_language language\n\t\t\tON\t\t(language.languageID = language_item.languageID)\n\t\t\tWHERE\t\tlanguage_item.languageItem = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->styleDescription)); $styleDescriptions = array(); while ($row = $statement->fetchArray()) { $styleDescriptions[$row['languageCode']] = $row['languageItemValue']; } // create style info file $xml = new XMLWriter(); $xml->beginDocument('style', 'http://www.woltlab.com', 'http://www.woltlab.com/XSD/maelstrom/style.xsd'); // general block $xml->startElement('general'); $xml->writeElement('stylename', $this->styleName); // style description foreach ($styleDescriptions as $languageCode => $value) { $xml->writeElement('description', $value, array('language' => $languageCode)); } $xml->writeElement('date', $this->styleDate); $xml->writeElement('version', $this->styleVersion); if ($this->image) { $xml->writeElement('image', $this->image); } if ($this->copyright) { $xml->writeElement('copyright', $this->copyright); } if ($this->license) { $xml->writeElement('license', $this->license); } $xml->endElement(); // author block $xml->startElement('author'); $xml->writeElement('authorname', $this->authorName); if ($this->authorURL) { $xml->writeElement('authorurl', $this->authorURL); } $xml->endElement(); // files block $xml->startElement('files'); $xml->writeElement('variables', 'variables.xml'); if ($templates) { $xml->writeElement('templates', 'templates.tar'); } if ($images) { $xml->writeElement('images', 'images.tar', array('path' => $this->imagePath)); } $xml->endElement(); // append style info file to style tar $styleTar->addString(self::INFO_FILE, $xml->endDocument()); unset($string); // create variable list $xml->beginDocument('variables', 'http://www.woltlab.com', 'http://www.woltlab.com/XSD/maelstrom/styleVariables.xsd'); // get variables $sql = "SELECT\t\tvariable.variableName, value.variableValue\n\t\t\tFROM\t\twcf" . WCF_N . "_style_variable_value value\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_style_variable variable\n\t\t\tON\t\t(variable.variableID = value.variableID)\n\t\t\tWHERE\t\tvalue.styleID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->styleID)); while ($row = $statement->fetchArray()) { $xml->writeElement('variable', $row['variableValue'], array('name' => $row['variableName'])); } // append variable list to style tar $styleTar->addString('variables.xml', $xml->endDocument()); unset($string); if ($templates && $this->templateGroupID) { $templateGroup = new TemplateGroup($this->templateGroupID); // create templates tar $templatesTarName = FileUtil::getTemporaryFilename('templates', '.tar'); $templatesTar = new TarWriter($templatesTarName); FileUtil::makeWritable($templatesTarName); // append templates to tar // get templates $sql = "SELECT\t\ttemplate.*, package.package\n\t\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\t\tON\t\t(package.packageID = template.packageID)\n\t\t\t\tWHERE\t\ttemplate.templateGroupID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->templateGroupID)); while ($row = $statement->fetchArray()) { $packageDir = 'com.woltlab.wcf'; $package = null; if ($row['application'] != 'wcf') { $application = ApplicationHandler::getInstance()->getApplication($row['application']); $package = PackageCache::getInstance()->getPackage($application->packageID); $packageDir = $package->package; } else { $application = ApplicationHandler::getInstance()->getWCF(); $package = PackageCache::getInstance()->getPackage($application->packageID); } $filename = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->packageDir . 'templates/' . $templateGroup->templateGroupFolderName)) . $row['templateName'] . '.tpl'; $templatesTar->add($filename, $packageDir, dirname($filename)); } // append templates tar to style tar $templatesTar->create(); $styleTar->add($templatesTarName, 'templates.tar', $templatesTarName); @unlink($templatesTarName); } if ($images && ($this->imagePath && $this->imagePath != 'images/')) { // create images tar $imagesTarName = FileUtil::getTemporaryFilename('images_', '.tar'); $imagesTar = new TarWriter($imagesTarName); FileUtil::makeWritable($imagesTarName); // append images to tar $path = FileUtil::addTrailingSlash(WCF_DIR . $this->imagePath); if (file_exists($path) && is_dir($path)) { $handle = opendir($path); $regEx = new Regex('\\.(jpg|jpeg|gif|png|svg)$', Regex::CASE_INSENSITIVE); while (($file = readdir($handle)) !== false) { if (is_file($path . $file) && $regEx->match($file)) { $imagesTar->add($path . $file, '', $path); } } } // append images tar to style tar $imagesTar->create(); $styleTar->add($imagesTarName, 'images.tar', $imagesTarName); @unlink($imagesTarName); } // output file content $styleTar->create(); // export as style package if (empty($packageName)) { readfile($styleTarName); } else { // export as package // create package tar $packageTarName = FileUtil::getTemporaryFilename('package_', '.tar.gz'); $packageTar = new TarWriter($packageTarName, true); // append style tar $styleTarName = FileUtil::unifyDirSeparator($styleTarName); $packageTar->add($styleTarName, '', FileUtil::addTrailingSlash(dirname($styleTarName))); // create package.xml $xml->beginDocument('package', 'http://www.woltlab.com', 'http://www.woltlab.com/XSD/maelstrom/package.xsd', array('name' => $packageName)); $xml->startElement('packageinformation'); $xml->writeElement('packagename', $this->styleName); // description foreach ($styleDescriptions as $languageCode => $value) { $xml->writeElement('packagedescription', $value, array('language' => $languageCode)); } $xml->writeElement('version', $this->styleVersion); $xml->writeElement('date', $this->styleDate); $xml->endElement(); $xml->startElement('authorinformation'); $xml->writeElement('author', $this->authorName); if ($this->authorURL) { $xml->writeElement('authorurl', $this->authorURL); } $xml->endElement(); $xml->startElement('requiredpackages'); $xml->writeElement('requiredpackage', 'com.woltlab.wcf', array('minversion' => PackageCache::getInstance()->getPackageByIdentifier('com.woltlab.wcf')->packageVersion)); $xml->endElement(); $xml->startElement('excludedpackages'); $xml->writeElement('excludedpackage', 'com.woltlab.wcf', array('version' => self::EXCLUDE_WCF_VERSION)); $xml->endElement(); $xml->startElement('instructions', array('type' => 'install')); $xml->writeElement('instruction', basename($styleTarName), array('type' => 'style')); $xml->endElement(); // append package info file to package tar $packageTar->addString(PackageArchive::INFO_FILE, $xml->endDocument()); $packageTar->create(); readfile($packageTarName); @unlink($packageTarName); } @unlink($styleTarName); }
/** * @see \wcf\form\IForm::validate() */ public function validate() { parent::validate(); if (empty($this->authorName)) { throw new UserInputException('authorName'); } // validate date if (empty($this->styleDate)) { throw new UserInputException('styleDate'); } else { try { DateUtil::validateDate($this->styleDate); } catch (SystemException $e) { throw new UserInputException('styleDate', 'notValid'); } } if (empty($this->styleName)) { throw new UserInputException('styleName'); } // validate version if (empty($this->styleVersion)) { throw new UserInputException('styleVersion'); } else { if (!Package::isValidVersion($this->styleVersion)) { throw new UserInputException('styleVersion', 'notValid'); } } // validate style description if (!I18nHandler::getInstance()->validateValue('styleDescription', true, true)) { throw new UserInputException('styleDescription'); } // validate template group id if ($this->templateGroupID) { if (!isset($this->availableTemplateGroups[$this->templateGroupID])) { throw new UserInputException('templateGroupID'); } } // ensure image path is below WCF_DIR/images/ if ($this->imagePath) { $relativePath = FileUtil::unifyDirSeparator(FileUtil::getRelativePath(WCF_DIR . 'images/', WCF_DIR . $this->imagePath)); if (strpos($relativePath, '../') !== false) { throw new UserInputException('imagePath', 'notValid'); } } if (!empty($this->variables['overrideLess'])) { $this->parseOverrides(); } }
/** * 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::isUTF8($REQUEST_URI)) { $REQUEST_URI = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $REQUEST_URI); } return mb_substr(FileUtil::unifyDirSeparator($REQUEST_URI), 0, 255); }
/** * Adds a file to the tar archive. * * @param string $filename * @param string $addDir * @param string $removeDir * @return boolean result */ protected function addFile($filename, $addDir, $removeDir) { $filename = FileUtil::unifyDirSeparator($filename); $storedFilename = $filename; if (!empty($removeDir)) { $storedFilename = StringUtil::replaceIgnoreCase($removeDir, '', $filename); } if (!empty($addDir)) { $storedFilename = $addDir . $storedFilename; } if (is_file($filename)) { // open file $file = new File($filename, 'rb'); // write header if (!$this->writeFileHeader($filename, $storedFilename)) { return false; } // write file content while (($buffer = $file->read(512)) != '') { $this->file->write(pack('a512', $buffer)); } // close file $file->close(); } else { // only directory header if (!$this->writeFileHeader($filename, $storedFilename)) { return false; } } return true; }
/** * Fills the list of available files, with DirectoryIterator object as value */ protected function scanFileObjects() { // value is cached if (!empty($this->fileObjects)) { return; } if ($this->recursive) { $it = new \RecursiveIteratorIterator($this->obj, \RecursiveIteratorIterator::CHILD_FIRST); foreach ($it as $filename => $obj) { // ignore . and .. if ($it->isDot()) { continue; } $this->fileObjects[FileUtil::unifyDirSeparator($filename)] = $obj; } } else { foreach ($this->obj as $obj) { // ignore . and .. if ($this->obj->isDot()) { continue; } $this->fileObjects[FileUtil::unifyDirSeparator($obj->getFilename())] = $obj; } } // add the directory itself $this->fileObjects[$this->directory] = new \SplFileInfo($this->directory); }
/** * Scans the given dir for installed files. * * @param string $dir */ protected function getInstalledFiles($dir) { if ($files = glob($dir . '*')) { foreach ($files as $file) { if (is_dir($file)) { $this->getInstalledFiles(FileUtil::addTrailingSlash($file)); } else { self::$installedFiles[] = FileUtil::unifyDirSeparator($file); } } } }
/** * 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); }
/** * @see \wcf\system\exception\IPrintableException::show() */ public function show() { // send status code @header('HTTP/1.1 503 Service Unavailable'); // show user-defined system-exception if (defined('SYSTEMEXCEPTION_FILE') && file_exists(SYSTEMEXCEPTION_FILE)) { require SYSTEMEXCEPTION_FILE; return; } $innerMessage = ''; try { if (is_object(WCF::getLanguage())) { $innerMessage = WCF::getLanguage()->get('wcf.global.error.exception', true); } } catch (\Exception $e) { } if (empty($innerMessage)) { $innerMessage = 'Please send the ID above to the site administrator.<br />The error message can be looked up at “ACP » Logs » Errors”.'; } // print report $e = $this->getPrevious() ?: $this; ?> <!DOCTYPE html> <html> <head> <title>Fatal error: <?php echo StringUtil::encodeHTML($this->_getMessage()); ?> </title> <meta charset="utf-8" /> <style> .systemException { font-family: 'Trebuchet MS', Arial, sans-serif !important; font-size: 80% !important; text-align: left !important; border: 1px solid #036; border-radius: 7px; background-color: #eee !important; overflow: auto !important; } .systemException h1 { font-size: 130% !important; font-weight: bold !important; line-height: 1.1 !important; text-decoration: none !important; text-shadow: 0 -1px 0 #003 !important; color: #fff !important; word-wrap: break-word !important; border-bottom: 1px solid #036; border-top-right-radius: 6px; border-top-left-radius: 6px; background-color: #369 !important; margin: 0 !important; padding: 5px 10px !important; } .systemException div { border-top: 1px solid #fff; border-bottom-right-radius: 6px; border-bottom-left-radius: 6px; padding: 0 10px !important; } .systemException h2 { font-size: 130% !important; font-weight: bold !important; color: #369 !important; text-shadow: 0 1px 0 #fff !important; margin: 5px 0 !important; } .systemException pre, .systemException p { text-shadow: none !important; color: #555 !important; margin: 0 !important; } .systemException pre { font-size: .85em !important; font-family: "Courier New" !important; text-overflow: ellipsis; padding-bottom: 1px; overflow: hidden !important; } .systemException pre:hover{ text-overflow: clip; overflow: auto !important; } </style> </head> <body> <div class="systemException"> <h1>Fatal error: <?php if (!$this->getExceptionID()) { ?> Unable to write log file, please make "<?php echo FileUtil::unifyDirSeparator(WCF_DIR); ?> log/" writable!<?php } else { echo StringUtil::encodeHTML($this->_getMessage()); } ?> </h1> <?php if (WCF::debugModeIsEnabled()) { ?> <div> <?php if ($this->getDescription()) { ?> <p><br /><?php echo $this->getDescription(); ?> </p><?php } ?> <h2>Information:</h2> <p> <b>id:</b> <code><?php echo $this->getExceptionID(); ?> </code><br> <b>error message:</b> <?php echo StringUtil::encodeHTML($this->_getMessage()); ?> <br> <b>error code:</b> <?php echo intval($e->getCode()); ?> <br> <?php echo $this->information; ?> <b>file:</b> <?php echo StringUtil::encodeHTML($e->getFile()); ?> (<?php echo $e->getLine(); ?> )<br> <b>php version:</b> <?php echo StringUtil::encodeHTML(phpversion()); ?> <br> <b>wcf version:</b> <?php echo WCF_VERSION; ?> <br> <b>date:</b> <?php echo gmdate('r'); ?> <br> <b>request:</b> <?php if (isset($_SERVER['REQUEST_URI'])) { echo StringUtil::encodeHTML($_SERVER['REQUEST_URI']); } ?> <br> <b>referer:</b> <?php if (isset($_SERVER['HTTP_REFERER'])) { echo StringUtil::encodeHTML($_SERVER['HTTP_REFERER']); } ?> <br> </p> <h2>Stacktrace:</h2> <pre><?php echo StringUtil::encodeHTML($this->__getTraceAsString()); ?> </pre> </div> <?php } else { ?> <div> <h2>Information:</h2> <p> <?php if (!$this->getExceptionID()) { ?> Unable to write log file, please make "<?php echo FileUtil::unifyDirSeparator(WCF_DIR); ?> log/" writable! <?php } else { ?> <b>ID:</b> <code><?php echo $this->getExceptionID(); ?> </code><br> <?php echo $innerMessage; ?> <?php } ?> </p> </div> <?php } ?> <?php echo $this->functions; ?> </div> </body> </html> <?php }
/** * Prompts for a text input for package directory (applies for applications only) * * @return \wcf\system\form\FormDocument */ protected function promptPackageDir() { if (!PackageInstallationFormManager::findForm($this->queue, 'packageDir')) { $container = new GroupFormElementContainer(); $packageDir = new TextInputFormElement($container); $packageDir->setName('packageDir'); $packageDir->setLabel(WCF::getLanguage()->get('wcf.acp.package.packageDir.input')); $defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator(dirname(WCF_DIR))); // check if there is already an application $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\tWHERE\tpackageDir = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array('../')); $row = $statement->fetchArray(); if ($row['count']) { // use abbreviation $defaultPath .= strtolower(Package::getAbbreviation($this->getPackage()->package)) . '/'; } $packageDir->setValue($defaultPath); $container->appendChild($packageDir); $document = new FormDocument('packageDir'); $document->appendContainer($container); PackageInstallationFormManager::registerForm($this->queue, $document); return $document; } else { $document = PackageInstallationFormManager::getForm($this->queue, 'packageDir'); $document->handleRequest(); $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(FileUtil::unifyDirSeparator($document->getValue('packageDir')))); if ($packageDir === '/') { $packageDir = ''; } if ($packageDir !== null) { // validate package dir if (file_exists($packageDir . 'global.php')) { $document->setError('packageDir', WCF::getLanguage()->get('wcf.acp.package.packageDir.notAvailable')); return $document; } // set package dir $packageEditor = new PackageEditor($this->getPackage()); $packageEditor->update(array('packageDir' => FileUtil::getRelativePath(WCF_DIR, $packageDir))); // determine domain path, in some environments (e.g. ISPConfig) the $_SERVER paths are // faked and differ from the real filesystem path if (PACKAGE_ID) { $wcfDomainPath = ApplicationHandler::getInstance()->getWCF()->domainPath; } else { $sql = "SELECT\tdomainPath\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_application\n\t\t\t\t\t\tWHERE\tpackageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(1)); $row = $statement->fetchArray(); $wcfDomainPath = $row['domainPath']; } $documentRoot = str_replace($wcfDomainPath, '', FileUtil::unifyDirSeparator(WCF_DIR)); $domainPath = str_replace($documentRoot, '', $packageDir); // update application path $application = new Application($this->getPackage()->packageID); $applicationEditor = new ApplicationEditor($application); $applicationEditor->update(array('domainPath' => $domainPath, 'cookiePath' => $domainPath)); // create directory and set permissions @mkdir($packageDir, 0777, true); FileUtil::makeWritable($packageDir); } return null; } }
/** * Removes files matching given pattern. * * @param string $pattern */ protected function removeFiles($pattern) { $directory = FileUtil::unifyDirSeparator(WCF_DIR . 'cache/'); $pattern = str_replace('*', '.*', str_replace('.', '\\.', $pattern)); $this->getDirectoryUtil()->executeCallback(new Callback(function ($filename) { if (!@touch($filename, 1)) { @unlink($filename); WCF::resetZendOpcache($filename); } }), new Regex('^' . $directory . $pattern . '$', Regex::CASE_INSENSITIVE)); }