/** * @see wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { parent::install(); // get installation path of package $sql = "SELECT packageDir FROM wcf".WCF_N."_package WHERE packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->installation->getPackageID())); $packageDir = $statement->fetchArray(); $packageDir = $packageDir['packageDir']; // get relative path of script $path = FileUtil::getRealPath(WCF_DIR.$packageDir); // reset WCF cache CacheHandler::getInstance()->flushAll(); // run script $this->run($path.$this->instruction['value']); // delete script if (@unlink($path.$this->instruction['value'])) { // delete file log entry $sql = "DELETE FROM wcf".WCF_N."_package_installation_file_log WHERE packageID = ? AND filename = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array( $this->installation->getPackageID(), $this->instruction['value'] )); } }
/** * @see \wcf\system\option\IOptionType::getData() */ public function getData(Option $option, $newValue) { $this->createUploadHandler($option); if ($this->uploadHandlers[$option->optionName] === null) { return ''; } $files = $this->uploadHandlers[$option->optionName]->getFiles(); $file = reset($files); // check if file has been uploaded if (!$file->getFilename()) { // if checkbox is checked, remove file if ($newValue) { @unlink($option->optionValue); return ''; } // use old value return $option->optionValue; } else { if ($option->optionValue) { // delete old file first @unlink($option->optionValue); } } // determine location the file will be stored at $package = PackageCache::getInstance()->getPackage($option->packageID); $fileLocation = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->packageDir)) . $option->filelocation . '.' . $file->getFileExtension(); // save file move_uploaded_file($file->getLocation(), $fileLocation); // return file location as the value to store in the database return $fileLocation; }
/** * @see \wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { parent::install(); $abbreviation = 'wcf'; $path = ''; if (isset($this->instruction['attributes']['application'])) { $abbreviation = $this->instruction['attributes']['application']; } else { if ($this->installation->getPackage()->isApplication) { $path = FileUtil::getRealPath(WCF_DIR . $this->installation->getPackage()->packageDir); } } if (empty($path)) { $dirConstant = strtoupper($abbreviation) . '_DIR'; if (!defined($dirConstant)) { throw new SystemException("Cannot execute script-PIP, abbreviation '" . $abbreviation . "' is unknown"); } $path = constant($dirConstant); } // reset WCF cache CacheHandler::getInstance()->flushAll(); // run script $this->run($path . $this->instruction['value']); // delete script if (@unlink($path . $this->instruction['value'])) { // delete file log entry $sql = "DELETE FROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\tWHERE\t\tpackageID = ?\n\t\t\t\t\t\tAND filename = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->installation->getPackageID(), $this->instruction['value'])); } }
/** * @see wcf\system\package\plugin\IPackageInstallationPlugin::uninstall() */ public function uninstall() { // create ACP-templates list $templates = array(); // get ACP-templates from log $sql = "SELECT * FROM wcf".WCF_N."_acp_template WHERE packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->installation->getPackageID())); while ($row = $statement->fetchArray()) { // store acp template with suffix (_$packageID) $templates[] = 'acp/templates/'.$row['templateName'].'.tpl'; } if (!empty($templates)) { // delete template files $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$this->installation->getPackage()->packageDir)); $deleteEmptyDirectories = $this->installation->getPackage()->isApplication; $this->installation->deleteFiles($packageDir, $templates, false, $deleteEmptyDirectories); // delete log entries parent::uninstall(); } }
/** * @see wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { parent::install(); // get package installation dir $dir = $this->installation->getPackage()->packageDir; if (empty($dir)) { if ($this->installation->getPackage()->isApplication == 1 && $this->installation->getPackage()->package != 'com.woltlab.wcf' && $this->installation->getAction() == 'install') { // application // prompt package dir $dir = $this->promptPackageDir(); } // save package dir if (!empty($dir)) { $package = new Package($this->installation->getPackageID()); $packageEditor = new PackageEditor($package); $packageEditor->update(array('packageDir' => $dir)); $this->installation->getPackage()->packageDir = $dir; } } // absolute path to package dir $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$dir)); // extract files.tar to temp folder $sourceFile = $this->installation->getArchive()->extractTar($this->instruction['value'], 'files_'); // create file handler $fileHandler = new FilesFileHandler($this->installation); // extract content of files.tar $fileInstaller = $this->installation->extractFiles($packageDir, $sourceFile, $fileHandler); // if this a an application, write config.inc.php for this package if ($this->installation->getPackage()->isApplication == 1 && $this->installation->getPackage()->package != 'com.woltlab.wcf' && $this->installation->getAction() == 'install') { // touch file $fileInstaller->touchFile(PackageInstallationDispatcher::CONFIG_FILE); // create file Package::writeConfigFile($this->installation->getPackageID()); // log file $sql = "INSERT INTO wcf".WCF_N."_package_installation_file_log (packageID, filename) VALUES (?, 'config.inc.php')"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->installation->getPackageID())); } // delete temporary sourceArchive @unlink($sourceFile); // update acp style file StyleUtil::updateStyleFile(); }
/** * Deletes the folders of this template group. */ public function deleteFolders() { // default template dir $folders = array(WCF_DIR . 'templates/' . $this->templateGroupFolderName); // get package dirs $sql = "SELECT\tpackageDir\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\tWHERE\tpackageDir <> ''"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); while ($row = $statement->fetchArray()) { $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); DirectoryUtil::getInstance($packageDir . 'templates/' . $this->templateGroupFolderName)->deleteAll(); } }
/** * Returns the directory of the application with the given abbrevation. * * @param string $abbreviation * @return string */ public static function getDirectory($abbreviation) { if (static::$directories === null) { static::$directories = array(); // read application directories $packageList = new PackageList(); $packageList->getConditionBuilder()->add('package.isApplication = ?', array(1)); $packageList->readObjects(); foreach ($packageList as $package) { $abbr = Package::getAbbreviation($package->package); static::$directories[$abbr] = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->packageDir)); } } if (!isset(static::$directories[$abbreviation])) { throw new SystemException("Unknown application '" . $abbreviation . "'"); } return static::$directories[$abbreviation]; }
/** * Uninstalls the templates of this package. */ public function uninstall() { // create templates list $templates = array(); // get templates from log $sql = "SELECT\ttemplateName\n\t\t\tFROM\twcf" . WCF_N . "_template\n\t\t\tWHERE \tpackageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->installation->getPackageID())); while ($row = $statement->fetchArray()) { $templates[] = 'templates/' . $row['templateName'] . '.tpl'; } if (count($templates) > 0) { // delete template files $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $this->installation->getPackage()->packageDir)); $deleteEmptyDirectories = $this->installation->getPackage()->isApplication; $this->installation->deleteFiles($packageDir, $templates, false, $deleteEmptyDirectories); // delete log entries parent::uninstall(); } }
/** * @see wcf\action\IAction::execute() */ public function execute() { parent::execute(); // delete language cache and compiled templates as well LanguageFactory::getInstance()->deleteLanguageCache(); $conditions = new PreparedStatementConditionBuilder(); $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $conditions->add("isApplication = ?", array(1)); // get package dirs $sql = "SELECT\tpackageDir\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); while ($row = $statement->fetchArray()) { $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); try { CacheHandler::getInstance()->clear($packageDir . 'cache', '*.php'); } catch (SystemException $e) { } } $this->executed(); HeaderUtil::redirect(LinkHandler::getInstance()->getLink('CacheList')); exit; }
/** * @see wcf\data\IEditableCachedObject::resetCache() */ public static function resetCache() { // reset cache CacheHandler::getInstance()->clear(WCF_DIR . 'cache', 'cache.option-*.php'); // reset options.inc.php files $sql = "SELECT\tpackage, packageID, packageDir\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\tWHERE\tisApplication = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(1)); while ($row = $statement->fetchArray()) { if ($row['package'] == 'com.woltlab.wcf') { $packageDir = WCF_DIR; } else { $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); } $filename = FileUtil::addTrailingSlash($packageDir) . self::FILENAME; if (file_exists($filename)) { if (!@touch($filename, 1)) { if (!@unlink($filename)) { self::rebuildFile($filename, $row['packageID']); } } } } }
/** * 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); }
/** * 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; } }
/** * Loads an application on runtime, do not use this outside the package installation. * * @param integer $packageID */ public static function loadRuntimeApplication($packageID) { $package = new Package($packageID); $application = new Application($packageID); $abbreviation = Package::getAbbreviation($package->package); $packageDir = FileUtil::getRealPath(WCF_DIR . $package->packageDir); self::$autoloadDirectories[$abbreviation] = $packageDir . 'lib/'; self::$applications[$abbreviation] = $application; self::getTPL()->addApplication($abbreviation, $packageDir . 'acp/templates/'); }
/** * Exports gallery images. */ public function exportGalleryImages($offset, $limit) { $sourceVersion21 = version_compare($this->getPackageVersion('com.woltlab.gallery'), '2.1.0 Alpha 1', '>='); $destVersion21 = version_compare(\gallery\system\GALLERYCore::getInstance()->getPackage()->packageVersion, '2.1.0 Alpha 1', '>='); // build path to gallery image directories $sql = "SELECT\tpackageDir\n\t\t\tFROM\twcf" . $this->dbNo . "_package\n\t\t\tWHERE\tpackage = ?"; $statement = $this->database->prepareStatement($sql, 1); $statement->execute(array('com.woltlab.gallery')); $packageDir = $statement->fetchColumn(); $imageFilePath = FileUtil::getRealPath($this->fileSystemPath . '/' . $packageDir); // fetch image data $sql = "SELECT\t\t*\n\t\t\tFROM\t\tgallery" . $this->dbNo . "_image\n\t\t\tWHERE\t\timageID BETWEEN ? AND ?\n\t\t\tORDER BY\timageID"; $statement = $this->database->prepareStatement($sql); $statement->execute(array($offset + 1, $offset + $limit)); $imageIDs = $images = array(); while ($row = $statement->fetchArray()) { $imageIDs[] = $row['imageID']; $images[$row['imageID']] = array('tmpHash' => $row['tmpHash'], 'userID' => $row['userID'], 'username' => $row['username'], 'albumID' => $row['albumID'], 'title' => $row['title'], 'description' => $row['description'], 'filename' => $row['filename'], 'fileExtension' => $row['fileExtension'], 'fileHash' => $row['fileHash'], 'filesize' => $row['filesize'], 'comments' => $row['comments'], 'views' => $row['views'], 'comments' => $row['comments'], 'cumulativeLikes' => $row['cumulativeLikes'], 'uploadTime' => $row['uploadTime'], 'creationTime' => $row['creationTime'], 'width' => $row['width'], 'creationTime' => $row['creationTime'], 'height' => $row['height'], 'orientation' => $row['orientation'], 'camera' => $row['camera'], 'location' => $row['location'], 'latitude' => $row['latitude'], 'longitude' => $row['longitude'], 'thumbnailX' => $row['thumbnailX'], 'thumbnailY' => $row['thumbnailY'], 'thumbnailHeight' => $row['thumbnailHeight'], 'thumbnailWidth' => $row['thumbnailWidth'], 'tinyThumbnailSize' => $row['tinyThumbnailSize'], 'smallThumbnailSize' => $row['smallThumbnailSize'], 'mediumThumbnailSize' => $row['mediumThumbnailSize'], 'largeThumbnailSize' => $row['largeThumbnailSize'], 'ipAddress' => $row['ipAddress'], 'enableComments' => $row['enableComments'], 'isDisabled' => $row['isDisabled'], 'isDeleted' => $row['isDeleted'], 'deleteTime' => $row['deleteTime'], 'exifData' => $row['exifData']); if ($sourceVersion21 && $destVersion21) { $images[$row['imageID']] = array_merge($images[$row['imageID']], array('enableSmilies' => $row['enableSmilies'], 'enableHtml' => $row['enableHtml'], 'enableBBCodes' => $row['enableBBCodes'], 'rawExifData' => $row['rawExifData'], 'hasEmbeddedObjects' => $row['hasEmbeddedObjects'], 'hasMarkers' => $row['hasMarkers'], 'showOrder' => $row['showOrder'], 'hasOriginalWatermark' => $row['hasOriginalWatermark'])); } } if (empty($imageIDs)) { return; } // fetch tags $tags = $this->getTags('com.woltlab.gallery.image', $imageIDs); // fetch categories $categories = array(); $conditionBuilder = new PreparedStatementConditionBuilder(); $conditionBuilder->add('imageID IN (?)', array($imageIDs)); $sql = "SELECT\t\t*\n\t\t\tFROM\t\tgallery" . $this->dbNo . "_image_to_category\n\t\t\t" . $conditionBuilder; $statement = $this->database->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); while ($row = $statement->fetchArray()) { if (!isset($categories[$row['imageID']])) { $categories[$row['imageID']] = array(); } $categories[$row['imageID']][] = $row['categoryID']; } foreach ($images as $imageID => $imageData) { $additionalData = array('fileLocation' => $imageFilePath . '/userImages/' . substr($imageData['fileHash'], 0, 2) . '/' . $imageID . '-' . $imageData['fileHash'] . '.' . $imageData['fileExtension']); if (isset($categories[$imageID])) { $additionalData['categories'] = $categories[$imageID]; } if (isset($tags[$imageID])) { $additionalData['tags'] = $tags[$imageID]; } ImportHandler::getInstance()->getImporter('com.woltlab.gallery.image')->import($imageID, $imageData, $additionalData); } }
/** * Loads an application. * * @param wcf\data\application\Application $application * @param boolean $isDependentApplication */ protected function loadApplication(Application $application, $isDependentApplication = false) { $package = PackageCache::getInstance()->getPackage($application->packageID); $abbreviation = ApplicationHandler::getInstance()->getAbbreviation($application->packageID); $packageDir = util\FileUtil::getRealPath(WCF_DIR . $package->packageDir); self::$autoloadDirectories[$abbreviation] = $packageDir . 'lib/'; $className = $abbreviation . '\\system\\' . strtoupper($abbreviation) . 'Core'; if (class_exists($className) && util\ClassUtil::isInstanceOf($className, 'wcf\\system\\application\\IApplication')) { // include config file $configPath = $packageDir . PackageInstallationDispatcher::CONFIG_FILE; if (file_exists($configPath)) { require_once $configPath; } else { throw new exception\SystemException('Unable to load configuration for ' . $package->package); } // start application if not within ACP if (!class_exists('wcf\\system\\WCFACP', false)) { call_user_func(array($className, 'getInstance')); } } else { unset(self::$autoloadDirectories[$abbreviation]); throw new exception\SystemException("Unable to run '" . $package->package . "', '" . $className . "' is missing or does not implement 'wcf\\system\\application\\IApplication'."); } // load options $this->loadOptions($packageDir . 'options.inc.php', $application->packageID); // register template path in ACP if (class_exists('wcf\\system\\WCFACP', false)) { $this->getTPL()->addTemplatePath($application->packageID, $packageDir . 'acp/templates/'); } else { if (!$isDependentApplication) { // assign base tag $this->getTPL()->assign('baseHref', $application->domainName . $application->domainPath); } } // register application self::$applications[$abbreviation] = $application; }
/** * @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); $_this = $this; $readFileCache = function ($cacheDir, Regex $ignore = null) use($_this) { $_this->caches[$cacheDir] = array(); // get files in cache directory try { $directoryUtil = DirectoryUtil::getInstance($cacheDir); } catch (SystemException $e) { return; } $files = $directoryUtil->getFileObjects(SORT_ASC, new Regex('\\.php$')); // get additional file information if (is_array($files)) { foreach ($files as $file) { if ($ignore !== null) { if ($ignore->match($file)) { continue; } } $_this->caches[$cacheDir][] = array('filename' => $file->getBasename(), 'filesize' => $file->getSize(), 'mtime' => $file->getMtime(), 'perm' => substr(sprintf('%o', $file->getPerms()), -3), 'writable' => $file->isWritable()); $_this->cacheData['files']++; $_this->cacheData['size'] += $file->getSize(); } } }; // filesystem cache if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\DiskCacheSource') { // set version $this->cacheData['version'] = WCF_VERSION; $conditions = new PreparedStatementConditionBuilder(); $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $conditions->add("isApplication = ?", array(1)); // get package dirs $sql = "SELECT\tpackageDir\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); while ($row = $statement->fetchArray()) { $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); $readFileCache($packageDir . 'cache'); } } else { if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\MemcacheCacheSource') { // get version $this->cacheData['version'] = MemcacheAdapter::getInstance()->getMemcache()->getVersion(); // get stats $stats = MemcacheAdapter::getInstance()->getMemcache()->getStats(); $this->cacheData['files'] = $stats['curr_items']; $this->cacheData['size'] = $stats['bytes']; } else { if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\ApcCacheSource') { // set version $this->cacheData['version'] = phpversion('apc'); $conditions = new PreparedStatementConditionBuilder(); $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $conditions->add("isApplication = ?", array(1)); // get package dirs $sql = "SELECT\tpackageDir, packageName, instanceNo\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $packageNames = array(); while ($row = $statement->fetchArray()) { $packagePath = FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . 'cache/'; $packageNames[$packagePath] = $row['packageName'] . ' #' . $row['instanceNo']; } $apcinfo = apc_cache_info('user'); $cacheList = $apcinfo['cache_list']; foreach ($cacheList as $cache) { $cachePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(dirname($cache['info']))); if (isset($packageNames[$cachePath])) { // Use the packageName + the instance number, because pathes could confuse the administrator. // He could think this is a file cache. If instanceName would be unique, we could use it instead. $packageName = $packageNames[$cachePath]; if (!isset($this->caches[$packageName])) { $this->caches[$packageName] = array(); } // get additional cache information $this->caches[$packageName][] = array('filename' => basename($cache['info'], '.php'), 'filesize' => $cache['mem_size'], 'mtime' => $cache['mtime']); $this->cacheData['files']++; $this->cacheData['size'] += $cache['mem_size']; } } } else { if ($this->cacheData['source'] == 'wcf\\system\\cache\\source\\NoCacheSource') { $this->cacheData['version'] = WCF_VERSION; $this->cacheData['files'] = $this->cacheData['size'] = 0; } } } } $readFileCache(WCF_DIR . 'language'); $readFileCache(WCF_DIR . 'templates/compiled', new Regex('\\.meta\\.php$')); $readFileCache(WCF_DIR . 'acp/templates/compiled', new Regex('\\.meta\\.php$')); }
/** * Returns the path to this template. * * @return string */ public function getPath() { $path = FileUtil::getRealPath(WCF_DIR . $this->packageDir) . 'templates/' . $this->templateGroupFolderName . $this->templateName . '.tpl'; return $path; }
/** * Clears resources after successful installation. */ protected function finalize() { // clear cache $sql = "SELECT\tpackageDir\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\tWHERE\tisApplication = 1"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); while ($row = $statement->fetchArray()) { $cacheDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir'] . 'cache/'); CacheHandler::getInstance()->clear($cacheDir, '*.php'); } }
/** * @see wcf\system\cache\source\ICacheSource::flush() */ public function flush() { $sql = "SELECT\t\tpackage.packageDir\n\t\t\tFROM\t\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = package_dependency.dependency)\n\t\t\tWHERE\t\tpackage_dependency.packageID = ?\n\t\t\t\t\tAND isApplication = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(PACKAGE_ID, 1)); while ($row = $statement->fetchArray()) { $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); $cacheDir = $packageDir . 'cache'; DirectoryUtil::getInstance($cacheDir)->removePattern(new Regex('.*\\.php$')); } }
/** * @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; // get package dirs $sql = "SELECT packageDir FROM wcf".WCF_N."_package WHERE isApplication = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(1)); while ($row = $statement->fetchArray()) { $packageDir = FileUtil::getRealPath(WCF_DIR.$row['packageDir']); $this->readCacheFiles('data', $packageDir.'cache'); } break; case 'wcf\system\cache\source\MemcachedCacheSource': // set version $this->cacheData['version'] = WCF_VERSION; // get package dirs $sql = "SELECT packageDir FROM wcf".WCF_N."_package WHERE isApplication = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(1)); while ($row = $statement->fetchArray()) { $packageDir = FileUtil::getRealPath(WCF_DIR.$row['packageDir']); $this->readCacheFiles('data', $packageDir.'cache'); } break; case 'wcf\system\cache\source\ApcCacheSource': // set version $this->cacheData['version'] = phpversion('apc'); // get package dirs $sql = "SELECT packageDir, packageName FROM wcf".WCF_N."_package WHERE isApplication = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(1)); $packageNames = array(); while ($row = $statement->fetchArray()) { $packagePath = FileUtil::getRealPath(WCF_DIR.$row['packageDir']).'cache/'; $packageNames[$packagePath] = $row['packageName']; } $apcinfo = apc_cache_info('user'); $cacheList = $apcinfo['cache_list']; foreach ($cacheList as $cache) { $cachePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(dirname($cache['info']))); if (isset($packageNames[$cachePath])) { // Use the packageName + the instance number, because pathes could confuse the administrator. // He could think this is a file cache. If instanceName would be unique, we could use it instead. $packageName = $packageNames[$cachePath]; if (!isset($this->caches['data'])) { $this->caches['data'] = array(); } if (!isset($this->caches['data'][$packageName])) { $this->caches['data'][$packageName] = array(); } // get additional cache information $this->caches['data'][$packageName][] = array( 'filename' => basename($cache['info'], '.php'), 'filesize' => $cache['mem_size'], 'mtime' => $cache['mtime'], ); $this->cacheData['files']++; $this->cacheData['size'] += $cache['mem_size']; } } break; case 'wcf\system\cache\source\NoCacheSource': $this->cacheData['version'] = WCF_VERSION; $this->cacheData['files'] = $this->cacheData['size'] = 0; break; } $this->readCacheFiles('language', FileUtil::unifyDirSeperator(WCF_DIR.'language')); $this->readCacheFiles('template', FileUtil::unifyDirSeperator(WCF_DIR.'templates/compiled'), new Regex('\.meta\.php$')); $this->readCacheFiles('template', FileUtil::unifyDirSeperator(WCF_DIR.'acp/templates/compiled'), new Regex('\.meta\.php$')); $this->readCacheFiles('style', FileUtil::unifyDirSeperator(WCF_DIR.'style'), null, 'css'); $this->readCacheFiles('style', FileUtil::unifyDirSeperator(WCF_DIR.'acp/style'), new Regex('WCFSetup.css$'), 'css'); }
/** * Loads an application. * * @param wcf\data\application\Application $application * @param boolean $isDependentApplication * @return wcf\system\application\IApplication */ protected function loadApplication(Application $application, $isDependentApplication = false) { $applicationObject = null; $package = PackageCache::getInstance()->getPackage($application->packageID); // package cache might be outdated if ($package === null) { $package = new Package($application->packageID); // package cache is outdated, discard cache if ($package->packageID) { PackageEditor::resetCache(); } else { // package id is invalid throw new SystemException("application identified by package id '".$application->packageID."' is unknown"); } } $abbreviation = ApplicationHandler::getInstance()->getAbbreviation($application->packageID); $packageDir = FileUtil::getRealPath(WCF_DIR.$package->packageDir); self::$autoloadDirectories[$abbreviation] = $packageDir . 'lib/'; $className = $abbreviation.'\system\\'.strtoupper($abbreviation).'Core'; if (class_exists($className) && ClassUtil::isInstanceOf($className, 'wcf\system\application\IApplication')) { // include config file $configPath = $packageDir . PackageInstallationDispatcher::CONFIG_FILE; if (file_exists($configPath)) { require_once($configPath); } else { throw new SystemException('Unable to load configuration for '.$package->package); } // start application if not within ACP if (!class_exists('wcf\system\WCFACP', false)) { // add template path and abbreviation $this->getTPL()->addApplication($abbreviation, $packageDir . 'templates/'); // init application and assign it as template variable $applicationObject = call_user_func(array($className, 'getInstance')); $this->getTPL()->assign('__'.$abbreviation, $applicationObject); } } else { unset(self::$autoloadDirectories[$abbreviation]); throw new SystemException("Unable to run '".$package->package."', '".$className."' is missing or does not implement 'wcf\system\application\IApplication'."); } // register template path in ACP if (class_exists('wcf\system\WCFACP', false)) { $this->getTPL()->addApplication($abbreviation, $packageDir . 'acp/templates/'); } else if (!$isDependentApplication) { // assign base tag $this->getTPL()->assign('baseHref', $application->getPageURL()); } // register application self::$applications[$abbreviation] = $application; return $applicationObject; }
/** * Exports this style. * * @param boolean $templates * @param boolean $images * @param boolean $icons */ public function export($templates = false, $images = false, $icons = false) { // create style tar $styleTarName = FileUtil::getTemporaryFilename('style_', '.tgz'); $styleTar = new TarWriter($styleTarName, true); // append style preview image if ($this->image && @file_exists(WCF_DIR . $this->image)) { $styleTar->add(WCF_DIR . $this->image, '', FileUtil::addTrailingSlash(dirname(WCF_DIR . $this->image))); } // create style info file $string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<!DOCTYPE style SYSTEM \"http://www.woltlab.com/DTDs/SXF/style.dtd\">\n<style>\n"; // general block $string .= "\t<general>\n"; $string .= "\t\t<stylename><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleName) : $this->styleName) . "]]></stylename>\n"; // style name if ($this->styleDescription) { $string .= "\t\t<description><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleDescription) : $this->styleDescription) . "]]></description>\n"; } // style description if ($this->styleVersion) { $string .= "\t\t<version><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleVersion) : $this->styleVersion) . "]]></version>\n"; } // style version if ($this->styleDate) { $string .= "\t\t<date><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->styleDate) : $this->styleDate) . "]]></date>\n"; } // style date if ($this->image) { $string .= "\t\t<image><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', basename($this->image)) : basename($this->image)) . "]]></image>\n"; } // style preview image if ($this->copyright) { $string .= "\t\t<copyright><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->copyright) : $this->copyright) . "]]></copyright>\n"; } // copyright if ($this->license) { $string .= "\t\t<license><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->license) : $this->license) . "]]></license>\n"; } // license $string .= "\t</general>\n"; // author block $string .= "\t<author>\n"; if ($this->authorName) { $string .= "\t\t<authorname><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->authorName) : $this->authorName) . "]]></authorname>\n"; } // author name if ($this->authorURL) { $string .= "\t\t<authorurl><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $this->authorURL) : $this->authorURL) . "]]></authorurl>\n"; } // author URL $string .= "\t</author>\n"; // files block $string .= "\t<files>\n"; $string .= "\t\t<variables>variables.xml</variables>\n"; // variables if ($templates && $this->templateGroupID) { $string .= "\t\t<templates>templates.tar</templates>\n"; } // templates if ($images) { $string .= "\t\t<images>images.tar</images>\n"; } // images if ($icons) { $string .= "\t\t<icons>icons.tar</icons>\n"; } // icons $string .= "\t</files>\n"; $string .= "</style>"; // append style info file to style tar $styleTar->addString(self::INFO_FILE, $string); unset($string); // create variable list $string = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<!DOCTYPE variables SYSTEM \"http://www.woltlab.com/DTDs/SXF/variables.dtd\">\n<variables>\n"; // get variables $variables = $this->getVariables(); $exportImages = array(); foreach ($variables as $name => $value) { // search images if ($images && $value) { if (preg_match_all('~([^/\\s\\$]+\\.(?:gif|jpg|jpeg|png))~i', $value, $matches)) { $exportImages = array_merge($exportImages, $matches[1]); } } $string .= "\t<variable name=\"" . StringUtil::encodeHTML($name) . "\"><![CDATA[" . StringUtil::escapeCDATA(CHARSET != 'UTF-8' ? StringUtil::convertEncoding(CHARSET, 'UTF-8', $value) : $value) . "]]></variable>\n"; } $string .= "</variables>"; // append variable list to style tar $styleTar->addString('variables.xml', $string); unset($string); if ($templates && $this->templateGroupID) { $templateGroup = new TemplateGroup($this->templateGroupID); // create templates tar $templatesTarName = FileUtil::getTemporaryFilename('templates', '.tar'); $templatesTar = new TarWriter($templatesTarName); @chmod($templatesTarName, 0777); // append templates to tar // get templates $sql = "SELECT\t\ttemplate.*, package.package, package.packageDir,\n\t\t\t\t\t\tparent_package.package AS parentPackage, parent_package.packageDir AS parentPackageDir\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\tLEFT JOIN\twcf" . WCF_N . "_package parent_package\n\t\t\t\tON\t\t(parent_package.packageID = package.parentPackageID)\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'; if (!empty($row['parentPackageDir'])) { $packageDir = $row['parentPackage']; } else { if (!empty($row['packageDir'])) { $packageDir = $row['package']; } } $filename = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $row['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) { // create images tar $imagesTarName = FileUtil::getTemporaryFilename('images_', '.tar'); $imagesTar = new TarWriter($imagesTarName); @chmod($imagesTarName, 0777); // cache rtl versions foreach ($exportImages as $exportImage) { if (strpos($exportImage, '-ltr')) { $exportImages[] = str_replace('-ltr', '-rtl', $exportImage); } } // append images to tar $path = WCF_DIR . $variables['global.images.location']; if (file_exists($path) && is_dir($path)) { $handle = opendir($path); while (($file = readdir($handle)) !== false) { if (is_file($path . $file) && in_array($file, $exportImages)) { $imagesTar->add($path . $file, '', $path); } } } // append images tar to style tar $imagesTar->create(); $styleTar->add($imagesTarName, 'images.tar', $imagesTarName); @unlink($imagesTarName); } // export icons $iconsLocation = FileUtil::addTrailingSlash($variables['global.icons.location']); if ($icons && $iconsLocation != 'icon/') { // create icons tar $iconsTarName = FileUtil::getTemporaryFilename('icons_', '.tar'); $iconsTar = new TarWriter($iconsTarName); @chmod($iconsTar, 0777); // get package dirs $sql = "SELECT\tpackage, packageDir\n\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\tWHERE\tisApplication = 1\n\t\t\t\t\tAND (packageDir <> '' OR package = 'com.woltlab.wcf')"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); while ($row = $statement->fetchArray()) { $iconsDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . $iconsLocation; $packageIcons = array(); if (file_exists($iconsDir)) { $icons = glob($iconsDir . '*.png'); if (is_array($icons)) { foreach ($icons as $icon) { $packageIcons[] = $icon; } } } if (count($packageIcons)) { $iconsTar->add($packageIcons, $row['package'] . '/', $iconsDir); } } $iconsTar->create(); $styleTar->add($iconsTarName, 'icons.tar', $iconsTarName); @unlink($iconsTarName); } // output file content $styleTar->create(); readfile($styleTarName); @unlink($styleTarName); }
/** * Writes the config.inc.php for an application. * * @param integer $packageID */ public static function writeConfigFile($packageID) { $package = new Package($packageID); $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$package->packageDir)); $file = new File($packageDir.PackageInstallationDispatcher::CONFIG_FILE); $file->write("<?php\n"); $prefix = strtoupper(self::getAbbreviation($package->package)); $file->write("// ".$package->package." (packageID ".$package->packageID.")\n"); $file->write("if (!defined('".$prefix."_DIR')) define('".$prefix."_DIR', dirname(__FILE__).'/');\n"); $file->write("if (!defined('RELATIVE_".$prefix."_DIR')) define('RELATIVE_".$prefix."_DIR', '');\n"); $file->write("\n"); // write general information $file->write("// general info\n"); $file->write("if (!defined('RELATIVE_WCF_DIR')) define('RELATIVE_WCF_DIR', RELATIVE_".$prefix."_DIR.'".FileUtil::getRelativePath($packageDir, WCF_DIR)."');\n"); $file->write("if (!defined('PACKAGE_ID')) define('PACKAGE_ID', ".$packageID.");\n"); $file->write("if (!defined('PACKAGE_NAME')) define('PACKAGE_NAME', '".str_replace("'", "\'", $package->getName())."');\n"); $file->write("if (!defined('PACKAGE_VERSION')) define('PACKAGE_VERSION', '".$package->packageVersion."');\n"); // write end $file->close(); }
/** * @see wcf\system\cache\ICacheBuilder::getData() */ public function getData(array $cacheResource) { list($cache, $packageID, $styleID) = explode('-', $cacheResource['cache']); $data = array(); // get active package $activePackage = new Package($packageID); $activePackageDir = FileUtil::getRealPath(WCF_DIR . $activePackage->packageDir); // get package dirs $packageDirs = array(); $conditionBuilder = new PreparedStatementConditionBuilder(); $conditionBuilder->add("dependency.packageID IN (?) AND package.packageDir <> ''", array(PackageDependencyHandler::getInstance()->getDependencies())); $sql = "SELECT\t\tDISTINCT package.packageDir, dependency.priority\n\t\t\tFROM\t\twcf" . WCF_N . "_package_dependency dependency\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = dependency.dependency)\n\t\t\t" . $conditionBuilder->__toString() . "\n\t\t\tORDER BY\tdependency.priority DESC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); while ($row = $statement->fetchArray()) { $packageDirs[] = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); } $packageDirs[] = FileUtil::unifyDirSeperator(WCF_DIR); // get style icon path $iconDirs = array(); $sql = "SELECT\tvariableValue\n\t\t\tFROM\twcf" . WCF_N . "_style_variable\n\t\t\tWHERE\tstyleID = ?\n\t\t\t\tAND variableName = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($styleID, 'global.icons.location')); $row = $statement->fetchArray(); if (!empty($row['variableValue'])) { $iconDirs[] = FileUtil::addTrailingSlash($row['variableValue']); } if (!in_array('icon/', $iconDirs)) { $iconDirs[] = 'icon/'; } // get icons foreach ($packageDirs as $packageDir) { $relativePackageDir = $activePackageDir != $packageDir ? FileUtil::getRelativePath($activePackageDir, $packageDir) : ''; foreach ($iconDirs as $iconDir) { $path = FileUtil::addTrailingSlash($packageDir . $iconDir); // get png icons $icons = self::getIconFiles($path, 'png'); foreach ($icons as $icon) { $icon = str_replace($path, '', $icon); if (preg_match('/^(.*)(S|M|L)\\.png$/', $icon, $match)) { if (!isset($data[$match[1]][$match[2]])) { $data[$match[1]][$match[2]] = $relativePackageDir . $iconDir . $icon; } } } // get svg icons $icons = self::getIconFiles($path, 'svg'); foreach ($icons as $icon) { $icon = str_replace($path, '', $icon); if (preg_match('/^(.*)\\.svg$/', $icon, $match)) { if (!isset($data[$match[1]]['S'])) { $data[$match[1]]['S'] = $relativePackageDir . $iconDir . $icon; } if (!isset($data[$match[1]]['M'])) { $data[$match[1]]['M'] = $relativePackageDir . $iconDir . $icon; } if (!isset($data[$match[1]]['L'])) { $data[$match[1]]['L'] = $relativePackageDir . $iconDir . $icon; } } } } } return $data; }