/** * @see \wcf\system\event\IEventListener::execute() */ public function execute($eventObj, $className, $eventName) { if ($eventObj->menuItemController == 'cms\\page\\PagePage') { $eventObj->additionalFields['className'] = 'cms\\system\\menu\\page\\CMSPageMenuItemProvider'; $eventObj->additionalFields['packageID'] = PackageCache::getInstance()->getPackageID('de.codequake.cms'); } }
/** * Returns package object. * * @return \wcf\data\package\Package */ public function getPackage() { if ($this->package === null) { $this->package = PackageCache::getInstance()->getPackage($this->packageID); } return $this->package; }
/** * @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\data\DatabaseObject::__construct() */ public function __construct($id, $row = null, DatabaseObject $object = null) { if ($id !== null) { $sql = "SELECT\t\ttemplate.*, template_group.templateGroupFolderName,\n\t\t\t\t\t\tpackage.package\n\t\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_template_group template_group\n\t\t\t\tON\t\t(template_group.templateGroupID = template.templateGroupID)\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.templateID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($id)); $row = $statement->fetchArray(); if ($row !== false) { // get relative directory of the template the application // belongs to if ($row['application'] != 'wcf') { $application = ApplicationHandler::getInstance()->getApplication($row['application']); } else { $application = ApplicationHandler::getInstance()->getWCF(); } $row['packageDir'] = PackageCache::getInstance()->getPackage($application->packageID)->packageDir; } else { $row = array(); } } else { if ($object !== null) { $row = $object->data; } } $this->handleData($row); }
/** * @see \wcf\system\exporter\IExporter::getSupportedData() */ public function getSupportedData() { $supportedData = array('com.woltlab.wcf.user' => array('com.woltlab.wcf.user.group', 'com.woltlab.wcf.user.avatar', 'com.woltlab.wcf.user.option', 'com.woltlab.wcf.user.comment', 'com.woltlab.wcf.user.follower', 'com.woltlab.wcf.user.rank'), 'com.woltlab.wbb.board' => array('com.woltlab.wbb.acl', 'com.woltlab.wbb.attachment', 'com.woltlab.wbb.poll', 'com.woltlab.wbb.watchedThread', 'com.woltlab.wbb.like', 'com.woltlab.wcf.label'), 'com.woltlab.wcf.conversation' => array('com.woltlab.wcf.conversation.attachment', 'com.woltlab.wcf.conversation.label'), 'com.woltlab.blog.entry' => array('com.woltlab.blog.category', 'com.woltlab.blog.entry.attachment', 'com.woltlab.blog.entry.comment', 'com.woltlab.blog.entry.like'), 'com.woltlab.calendar.event' => array('com.woltlab.calendar.category', 'com.woltlab.calendar.event.attachment', 'com.woltlab.calendar.event.date.comment', 'com.woltlab.calendar.event.date.participation', 'com.woltlab.calendar.event.like'), 'com.woltlab.wcf.smiley' => array()); $gallery = PackageCache::getInstance()->getPackageByIdentifier('com.woltlab.gallery'); if ($gallery && Package::compareVersion('2.1.0 Alpha 1', $gallery->packageVersion) != 1) { $supportedData['com.woltlab.gallery.image'] = array('com.woltlab.gallery.category', 'com.woltlab.gallery.album', 'com.woltlab.gallery.image.comment', 'com.woltlab.gallery.image.like', 'com.woltlab.gallery.image.marker'); } return $supportedData; }
/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); foreach ($this->objects as $template) { if ($template->application != 'wcf') { $application = ApplicationHandler::getInstance()->getApplication($template->application); } else { $application = ApplicationHandler::getInstance()->getWCF(); } $package = PackageCache::getInstance()->getPackage($application->packageID); // set directory of the application package the template // belongs to $template->packageDir = $package->packageDir; } }
/** * Deletes the folder of this template group. */ public function deleteFolder() { if (file_exists(WCF_DIR . 'templates/' . $this->templateGroupFolderName)) { DirectoryUtil::getInstance(WCF_DIR . 'templates/' . $this->templateGroupFolderName)->removeAll(); } // check template group folders in other applications $sql = "SELECT\tDISTINCT application\n\t\t\tFROM\twcf" . WCF_N . "_template\n\t\t\tWHERE\ttemplateGroupID = ?\n\t\t\t\tAND application <> ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->templateGroupID, 'wcf')); while ($row = $statement->fetchArray()) { $application = ApplicationHandler::getInstance()->getApplication($row['application']); $package = PackageCache::getInstance()->getPackage($application->packageID); if (file_exists(WCF_DIR . $package->packageDir . 'templates/' . $this->templateGroupFolderName)) { DirectoryUtil::getInstance(WCF_DIR . $package->packageDir . 'templates/' . $this->templateGroupFolderName)->removeAll(); } } }
/** * @see \wcf\form\IForm::save() */ public function save() { \wcf\form\AbstractForm::save(); // save question message $this->questionMessage = 'wbb.post.butler.questionMessage' . $this->question->questionID; if (\wcf\system\language\I18nHandler::getInstance()->isPlainValue('questionMessage')) { \wcf\system\language\I18nHandler::getInstance()->remove($this->questionMessage, $this->questionID); $this->questionMessage = \wcf\system\language\I18nHandler::getInstance()->getValue('questionMessage'); } else { \wcf\system\language\I18nHandler::getInstance()->save('questionMessage', $this->questionMessage, 'wbb.post', \wcf\data\package\PackageCache::getInstance()->getPackageID('com.woltlab.wbb')); } $this->objectAction = new \wbb\data\post\butler\question\QuestionAction(array($this->question), 'update', array('data' => array_merge($this->additionalFields, array('questionTitle' => $this->questionTitle, 'questionMessage' => $this->questionMessage, 'prefixUserID' => $this->prefixUserID, 'prefixUsername' => $this->prefixUsername)))); $this->objectAction->executeAction(); // call saved event $this->saved(); // reload question object to update information $this->question = new \wbb\data\post\butler\question\Question($this->question->questionID); // show success \wcf\system\WCF::getTPL()->assign(array('success' => true)); }
/** * Returns the owner of this dashboard box. * * @return \wcf\data\package\Package */ public function getPackage() { return PackageCache::getInstance()->getPackage($this->packageID); }
/** * 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(); if (empty($_POST)) { I18nHandler::getInstance()->setOptions('title', PackageCache::getInstance()->getPackageID('info.codingcorner.ict'), $this->projectObj->title, 'ict.project.project\\d+'); I18nHandler::getInstance()->setOptions('subTitle', PackageCache::getInstance()->getPackageID('info.codingcorner.ict'), $this->projectObj->subTitle, 'ict.project.project\\d+.subTitle'); I18nHandler::getInstance()->setOptions('description', PackageCache::getInstance()->getPackageID('info.codingcorner.ict'), $this->projectObj->description, 'ict.project.project\\d+.description'); $this->title = $this->projectObj->title; $this->subTitle = $this->projectObj->subTitle; $this->description = $this->projectObj->description; $this->descriptionUseHtml = $this->projectObj->descriptionUseHtml; $this->position = $this->projectObj->position; $this->isInvisible = $this->projectObj->isInvisible; $this->isClosed = $this->projectObj->isClosed; $this->issuesPerPage = $this->projectObj->issuesPerPage; $this->commentsPerPage = $this->projectObj->commentsPerPage; $this->styleID = $this->projectObj->styleID; } }
/** * @see \wcf\form\IForm::save() */ public function save() { parent::save(); if (empty($this->application)) { $this->application = Package::getAbbreviation(PackageCache::getInstance()->getPackage($this->packageID)->package); } $this->objectAction = new TemplateAction(array(), 'create', array('data' => array_merge($this->additionalFields, array('application' => $this->application, 'templateName' => $this->tplName, 'packageID' => $this->packageID, 'templateGroupID' => $this->templateGroupID)), 'source' => $this->templateSource)); $this->objectAction->executeAction(); $this->saved(); // reset values $this->tplName = $this->templateSource = ''; $this->templateGroupID = 0; // show success WCF::getTPL()->assign(array('success' => true)); }
/** * 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); }
/** * Uninstalls the specified package. * $package may either be the packageID or the package identifier. * * @param mixed $package */ private function uninstall($package) { if (Package::isValidPackageName($package)) { $packageID = PackageCache::getInstance()->getPackageID($package); } else { $packageID = $package; } // UninstallPackageAction::prepare() $package = new Package($packageID); if (!$package->packageID || !$package->canUninstall()) { $this->error('invalidUninstallation'); } // get new process no $processNo = PackageInstallationQueue::getNewProcessNo(); // create queue $queue = PackageInstallationQueueEditor::create(array('processNo' => $processNo, 'userID' => CLIWCF::getUser()->userID, 'packageName' => $package->getName(), 'packageID' => $package->packageID, 'action' => 'uninstall')); // initialize uninstallation $installation = new PackageUninstallationDispatcher($queue); $installation->nodeBuilder->purgeNodes(); $installation->nodeBuilder->buildNodes(); CLIWCF::getTPL()->assign(array('queue' => $queue)); $queueID = $installation->nodeBuilder->getQueueByNode($queue->processNo, $installation->nodeBuilder->getNextNode()); $step = 'uninstall'; $node = $installation->nodeBuilder->getNextNode(); $currentAction = CLIWCF::getLanguage()->get('wcf.package.installation.step.uninstalling'); $progress = 0; // initialize progressbar $progressbar = new ProgressBar(new ConsoleProgressBar(array('width' => CLIWCF::getTerminal()->getWidth(), 'elements' => array(ConsoleProgressBar::ELEMENT_PERCENT, ConsoleProgressBar::ELEMENT_BAR, ConsoleProgressBar::ELEMENT_TEXT), 'textWidth' => min(floor(CLIWCF::getTerminal()->getWidth() / 2), 50)))); // InstallPackageAction::readParameters() $finished = false; while (!$finished) { $queue = new PackageInstallationQueue($queueID); $installation = new PackageUninstallationDispatcher($queue); switch ($step) { case 'uninstall': $_node = $installation->uninstall($node); if ($_node == '') { // remove node data $installation->nodeBuilder->purgeNodes(); // UninstallPackageAction::finalize() CacheHandler::getInstance()->flushAll(); // /UninstallPackageAction::finalize() // show success $currentAction = CLIWCF::getLanguage()->get('wcf.acp.package.uninstallation.step.success'); $progress = 100; $step = 'success'; $finished = true; continue; } // continue with next node $queueID = $installation->nodeBuilder->getQueueByNode($installation->queue->processNo, $installation->nodeBuilder->getNextNode($node)); $step = 'uninstall'; $progress = $installation->nodeBuilder->calculateProgress($node); $node = $_node; } $progressbar->update($progress, $currentAction); } $progressbar->getAdapter()->finish(); }
/** * @see \wcf\page\IPage::readData() */ public function readData() { parent::readData(); // get template groups $this->availableTemplateGroups = TemplateGroup::getSelectList(array(), 1); // get applications $applications = ApplicationHandler::getInstance()->getApplications(); $applications[] = ApplicationHandler::getInstance()->getWCF(); foreach ($applications as $application) { $package = PackageCache::getInstance()->getPackage($application->packageID); $this->availableApplications[ApplicationHandler::getInstance()->getAbbreviation($package->packageID)] = $package; // issues with the language cache would cause the uasort() below to throw a // misleading error message, calling it here just reveals the real error $package->getName(); } uasort($this->availableApplications, function ($a, $b) { return $a->getName() > $b->getName(); }); }
/** * Returns the package object based on the package archive's package identifier or null * if the package isn't already installed. * * @return \wcf\data\package\Package */ public function getPackage() { if ($this->package === null) { $this->package = PackageCache::getInstance()->getPackageByIdentifier($this->archive->getPackageInfo('name')); } return $this->package; }
/** * @see \wcf\form\IForm::save() */ public function save() { parent::save(); // save question $this->objectAction = new \wbb\data\post\butler\question\QuestionAction(array(), 'create', array('data' => array_merge($this->additionalFields, array('questionTitle' => $this->questionTitle, 'prefixUserID' => $this->prefixUserID, 'prefixUsername' => $this->prefixUsername, 'questionMessage' => $this->questionMessage)))); $returnValues = $this->objectAction->executeAction(); $question = $returnValues['returnValues']; // save question message if (!\wcf\system\language\I18nHandler::getInstance()->isPlainValue('questionMessage')) { \wcf\system\language\I18nHandler::getInstance()->save('questionMessage', 'wbb.post.butler.questionMessage' . $question->questionID, 'wbb.post', \wcf\data\package\PackageCache::getInstance()->getPackageID('com.woltlab.wbb')); // update message $questionEditor = new \wbb\data\post\butler\question\QuestionEditor($question); $questiionEditor->update(array('questionMessage' => 'wbb.post.butler.questionMessage' . $question->questionID)); } // call saved event $this->saved(); // reset values $this->questionTitle = ''; \wcf\system\language\I18nHandler::getInstance()->reset(); // show success \wcf\system\WCF::getTPL()->assign(array('success' => true)); }
/** * @see \wcf\form\IForm::save() */ public function save() { parent::save(); // save answer $this->objectAction = new \wbb\data\post\butler\answer\AnswerAction(array(), 'create', array('data' => array_merge($this->additionalFields, array('questionID' => $this->questionID, 'answerTitle' => $this->answerTitle, 'answerMessage' => $this->answerMessage, 'enableSmilies' => $this->enableSmilies ? 1 : 0, 'enableHtml' => $this->enableHtml ? 1 : 0, 'enableBBCodes' => $this->enableBBCodes ? 1 : 0)))); $returnValues = $this->objectAction->executeAction(); $answer = $returnValues['returnValues']; // save answer message if (!\wcf\system\language\I18nHandler::getInstance()->isPlainValue('answerMessage')) { \wcf\system\language\I18nHandler::getInstance()->save('answerMessage', 'wbb.post.butler.answerMessage' . $answer->answerID, 'wbb.post', \wcf\data\package\PackageCache::getInstance()->getPackageID('com.woltlab.wbb')); // update message $answerEditor = new \wbb\data\post\butler\answer\AnswerEditor($answer); $questiionEditor->update(array('answerMessage' => 'wbb.post.butler.answerMessage' . $answer->answerID)); } // call saved event $this->saved(); // reset values $this->answerTitle = ''; $this->enableSmilies = false; $this->enableHtml = false; $this->enableBBCodes = false; \wcf\system\language\I18nHandler::getInstance()->reset(); // show success \wcf\system\WCF::getTPL()->assign(array('success' => true)); }
/** * @see \wcf\page\IPage::readData() */ public function readData() { parent::readData(); $serverList = new PackageUpdateServerList(); $serverList->readObjects(); foreach ($serverList as $server) { if (preg_match('~https?://store.woltlab.com/(?P<wcfMajorRelease>[a-z]+)/~', $server->serverURL, $matches)) { $this->updateServers[$matches['wcfMajorRelease']] = $server; } } foreach ($this->products as $packageUpdateID => $product) { $wcfMajorRelease = $product['wcfMajorRelease']; if (!isset($this->productData[$wcfMajorRelease])) { $this->productData[$wcfMajorRelease] = array(); } $languageCode = WCF::getLanguage()->languageCode; $packageName = isset($product['packageName'][$languageCode]) ? $product['packageName'][$languageCode] : $product['packageName']['en']; $this->productData[$wcfMajorRelease][$packageUpdateID] = array('author' => $product['author'], 'authorURL' => $product['authorURL'], 'package' => $product['package'], 'packageName' => $packageName, 'pluginStoreURL' => $product['pluginStoreURL'], 'version' => array('available' => $product['lastVersion'], 'installed' => ''), 'status' => isset($this->updateServers[$wcfMajorRelease]) ? 'install' : 'unavailable'); $package = PackageCache::getInstance()->getPackageByIdentifier($product['package']); if ($package !== null) { $this->productData[$wcfMajorRelease][$packageUpdateID]['version']['installed'] = $package->packageVersion; if (Package::compareVersion($product['lastVersion'], $package->packageVersion, '>')) { $this->productData[$wcfMajorRelease][$packageUpdateID]['status'] = 'update'; } else { if (Package::compareVersion($product['lastVersion'], $package->packageVersion, '=')) { $this->productData[$wcfMajorRelease][$packageUpdateID]['status'] = 'upToDate'; } } } if (isset($this->updateServers[$wcfMajorRelease]) && $this->updateServers[$wcfMajorRelease]->lastUpdateTime == 0) { $this->productData[$wcfMajorRelease][$packageUpdateID]['status'] = 'requireUpdate'; } } }
/** * 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); } // register template path 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 self::$applicationObjects[$application->packageID] = call_user_func(array($className, 'getInstance')); $this->getTPL()->assign('__' . $abbreviation, self::$applicationObjects[$application->packageID]); } 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 self::$applicationObjects[$application->packageID]; }
/** * Updates an existing package. * * @param integer $packageID * @param string $version */ protected function updatePackage($packageID, $version) { // get package info $package = PackageCache::getInstance()->getPackage($packageID); // get current package version $packageVersion = $package->packageVersion; if (isset($this->virtualPackageVersions[$packageID])) { $packageVersion = $this->virtualPackageVersions[$packageID]; // check virtual package version if (Package::compareVersion($packageVersion, $version, '>=')) { // virtual package version is greater than requested version // skip package update return; } } // get highest version of the required major release if (preg_match('/(\\d+\\.\\d+\\.)/', $version, $match)) { $packageVersions = array(); $sql = "SELECT\tDISTINCT packageVersion\n\t\t\t\tFROM\twcf" . WCF_N . "_package_update_version\n\t\t\t\tWHERE\tpackageUpdateID IN (\n\t\t\t\t\t\tSELECT\tpackageUpdateID\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package_update\n\t\t\t\t\t\tWHERE\tpackage = ?\n\t\t\t\t\t)\n\t\t\t\t\tAND packageVersion LIKE ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($package->package, $match[1] . '%')); while ($row = $statement->fetchArray()) { $packageVersions[] = $row['packageVersion']; } if (count($packageVersions) > 1) { // sort by version number usort($packageVersions, array('wcf\\data\\package\\Package', 'compareVersion')); // get highest version $version = array_pop($packageVersions); } } // get all fromversion $fromversions = array(); $sql = "SELECT\t\tpuv.packageVersion, puf.fromversion\n\t\t\tFROM\t\twcf" . WCF_N . "_package_update_fromversion puf\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_update_version puv\n\t\t\tON\t\t(puv.packageUpdateVersionID = puf.packageUpdateVersionID)\n\t\t\tWHERE\t\tpuf.packageUpdateVersionID IN (\n\t\t\t\t\t\tSELECT\tpackageUpdateVersionID\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package_update_version\n\t\t\t\t\t\tWHERE\tpackageUpdateID IN (\n\t\t\t\t\t\t\tSELECT\tpackageUpdateID\n\t\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package_update\n\t\t\t\t\t\t\tWHERE\tpackage = ?\n\t\t\t\t\t\t)\n\t\t\t\t\t)"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($package->package)); while ($row = $statement->fetchArray()) { if (!isset($fromversions[$row['packageVersion']])) { $fromversions[$row['packageVersion']] = array(); } $fromversions[$row['packageVersion']][$row['fromversion']] = $row['fromversion']; } // sort by version number uksort($fromversions, array('wcf\\data\\package\\Package', 'compareVersion')); // find shortest update thread $updateThread = $this->findShortestUpdateThread($package->package, $fromversions, $packageVersion, $version); // process update thread foreach ($updateThread as $fromversion => $toVersion) { $packageUpdateVersions = PackageUpdateDispatcher::getInstance()->getPackageUpdateVersions($package->package, $toVersion); // resolve requirements $this->resolveRequirements($packageUpdateVersions[0]['packageUpdateVersionID']); // download package $download = $this->downloadPackage($package->package, $packageUpdateVersions); // add to stack $this->packageInstallationStack[] = array('packageName' => $package->getName(), 'fromversion' => $fromversion, 'toVersion' => $toVersion, 'package' => $package->package, 'packageID' => $packageID, 'archive' => $download, 'action' => 'update'); // update virtual versions $this->virtualPackageVersions[$packageID] = $toVersion; } }
private function saveI18nValue(DatabaseObject $object, $type, $columnName, $inContentData = false) { if (!I18nHandler::getInstance()->isPlainValue($columnName)) { I18nHandler::getInstance()->save($columnName, 'cms.' . $type . '.' . $columnName . $object->{$type . 'ID'}, 'cms.' . $type, PackageCache::getInstance()->getPackageID('de.codequake.cms')); $editorName = '\\cms\\data\\' . $type . '\\' . ucfirst($type) . 'Editor'; if ($object !== null) { $editor = new $editorName($object); if ($inContentData) { $tmpContentData = $object->contentData; if ($this->is_serialized($tmpContentData)) { $tmpContentData = unserialize($tmpContentData); $tmpContentData['text'] = 'cms.' . $type . '.' . $columnName . $object->{$type . 'ID'}; } else { if (is_array($tmpContentData)) { $tmpContentData['text'] = 'cms.' . $type . '.' . $columnName . $object->{$type . 'ID'}; } else { $tmpContentData = array(); $tmpContentData['text'] = 'cms.' . $type . '.' . $columnName . $object->{$type . 'ID'}; } } $tmpContentData = serialize($tmpContentData); $editor->update(array('contentData' => $tmpContentData)); } else { $editor->update(array($columnName => 'cms.' . $type . '.' . $columnName . $object->{$type . 'ID'})); } } } }
/** * Imports language variables. * * @param string $languageCategory * @param string $languageItem * @param array $languageItemValues * @param integer $packageID * @return array */ private function importLanguageVariable($languageCategory, $languageItem, array $languageItemValues) { $packageID = PackageCache::getInstance()->getPackageID('de.codequake.cms'); // get language category id $sql = "SELECT\tlanguageCategoryID\n\t\t\tFROM\twcf" . WCF_N . "_language_category\n\t\t\tWHERE\tlanguageCategory = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($languageCategory)); $row = $statement->fetchArray(); $languageCategoryID = $row['languageCategoryID']; $importableValues = array(); foreach ($languageItemValues as $languageCode => $value) { $language = LanguageFactory::getInstance()->getLanguageByCode($languageCode); if ($language === null) { continue; } $importableValues[$language->languageID] = $value; } $count = count($importableValues); if ($count > 1) { $sql = "INSERT INTO\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\t(languageID, languageItem, languageItemValue,\n\t\t\t\t\t\t\tlanguageItemOriginIsSystem, languageCategoryID,\n\t\t\t\t\t\t\tpackageID)\n\t\t\t\tVALUES\t\t(?, ?, ?, ?, ?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($importableValues as $languageID => $value) { $statement->execute(array($languageID, $languageItem, $value, 0, $languageCategoryID, $packageID)); } return $languageItem; } else { if ($count == 1) { return reset($importableValues); } } return false; }
/** * Returns a list of packages dependent from current package. * * @return array<wcf\data\package\Package> */ public function getDependentPackages() { if ($this->dependentPackages === null) { self::loadRequirements(); $this->dependentPackages = array(); foreach (self::$requirements as $packageID => $requiredPackageIDs) { if (in_array($this->packageID, $requiredPackageIDs)) { $this->dependentPackages[$packageID] = PackageCache::getInstance()->getPackage($packageID); } } } return $this->dependentPackages; }
/** * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::validateImport() */ protected function validateImport(array $data) { if ($data['bbcodeTag'] == 'all' || $data['bbcodeTag'] == 'none') { throw new SystemException("BBCodes can't be called 'all' or 'none'"); } // check if bbcode tag already exists $sqlData = $this->findExistingItem($data); $statement = WCF::getDB()->prepareStatement($sqlData['sql']); $statement->execute($sqlData['parameters']); $row = $statement->fetchArray(); if ($row && $row['packageID'] != $this->installation->getPackageID()) { $package = PackageCache::getInstance()->getPackage($row['packageID']); throw new SystemException("BBCode '" . $data['bbcodeTag'] . "' is already provided by '" . $package . "' ('" . $package->package . "')."); } }
/** * Saves a i18n values * * @param \ict\data\project\Project $project * @param string $columnName */ public function saveI18nValue(Project $project, $columnName) { if (!I18nHandler::getInstance()->isPlainValue($columnName)) { I18nHandler::getInstance()->save($columnName, 'ict.project.project' . $project->projectID . ($columnName == 'title' ? '' : '.' . $columnName), 'ict.project', PackageCache::getInstance()->getPackageID('info.codingcorner.ict')); // update description $projectEditor = new ProjectEditor($project); $projectEditor->update(array($columnName => 'ict.project.project' . $project->projectID . ($columnName == 'title' ? '' : '.' . $columnName))); } }
/** * @see \wcf\form\IForm::validate() */ public function validate() { parent::validate(); if (empty($this->domainName)) { throw new UserInputException('domainName'); } else { $regex = new Regex('^https?\\://'); $this->domainName = FileUtil::removeTrailingSlash($regex->replace($this->domainName, '')); $this->cookieDomain = FileUtil::removeTrailingSlash($regex->replace($this->cookieDomain, '')); // domain may not contain path components $regex = new Regex('[/#\\?&]'); if ($regex->match($this->domainName)) { throw new UserInputException('domainName', 'containsPath'); } else { if ($regex->match($this->cookieDomain)) { throw new UserInputException('cookieDomain', 'containsPath'); } } // strip port from cookie domain $regex = new Regex(':[0-9]+$'); $this->cookieDomain = $regex->replace($this->cookieDomain, ''); // check if cookie domain shares the same domain (may exclude subdomains) if (!StringUtil::endsWith($regex->replace($this->domainName, ''), $this->cookieDomain)) { throw new UserInputException('cookieDomain', 'notValid'); } } // add slashes $this->domainPath = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash($this->domainPath)); // search for other applications with the same domain and path $sql = "SELECT\tpackageID\n\t\t\tFROM\twcf" . WCF_N . "_application\n\t\t\tWHERE\tdomainName = ?\n\t\t\t\tAND domainPath = ?\n\t\t\t\tAND packageID <> ?"; $statement = WCF::getDB()->prepareStatement($sql, 1); $statement->execute(array($this->domainName, $this->domainPath, $this->application->packageID)); $row = $statement->fetchArray(); if ($row) { WCF::getTPL()->assign('conflictApplication', PackageCache::getInstance()->getPackage($row['packageID'])); throw new UserInputException('domainPath', 'conflict'); } }