Example #1
0
 /**
  * @see	\wcf\system\bbcode\IBBCode::getParsedTag()
  */
 public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser)
 {
     if ($parser->getOutputType() == 'text/html') {
         $quoteLink = !empty($openingTag['attributes'][1]) ? $openingTag['attributes'][1] : '';
         $externalQuoteLink = !empty($openingTag['attributes'][1]) ? !ApplicationHandler::getInstance()->isInternalURL($openingTag['attributes'][1]) : false;
         if (!$externalQuoteLink) {
             $quoteLink = preg_replace('~^https?://~', RouteHandler::getProtocol(), $quoteLink);
         }
         $quoteAuthor = !empty($openingTag['attributes'][0]) ? $openingTag['attributes'][0] : '';
         $quoteAuthorObject = null;
         if ($quoteAuthor && !$externalQuoteLink) {
             $quoteAuthorLC = mb_strtolower(StringUtil::decodeHTML($quoteAuthor));
             foreach (MessageEmbeddedObjectManager::getInstance()->getObjects('com.woltlab.wcf.quote') as $user) {
                 if (mb_strtolower($user->username) == $quoteAuthorLC) {
                     $quoteAuthorObject = $user;
                     break;
                 }
             }
         }
         WCF::getTPL()->assign(array('content' => $content, 'quoteLink' => $quoteLink, 'quoteAuthor' => $quoteAuthor, 'quoteAuthorObject' => $quoteAuthorObject, 'isExternalQuoteLink' => $externalQuoteLink));
         return WCF::getTPL()->fetch('quoteBBCodeTag');
     } else {
         if ($parser->getOutputType() == 'text/simplified-html') {
             return WCF::getLanguage()->getDynamicVariable('wcf.bbcode.quote.text', array('content' => $content, 'cite' => !empty($openingTag['attributes'][0]) ? $openingTag['attributes'][0] : '')) . "\n";
         }
     }
 }
Example #2
0
 /**
  * @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);
 }
Example #3
0
 /**
  * @see \wcf\system\SingletonFactory::init()
  */
 protected function init()
 {
     $application = ApplicationHandler::getInstance()->getPrimaryApplication();
     $cacheName = 'sitemap-' . $application->packageID;
     CacheHandler::getInstance()->addResource($cacheName, WCF_DIR . 'cache/cache.' . $cacheName . '.php', 'wcf\\system\\cache\\builder\\SitemapCacheBuilder');
     $this->cache = CacheHandler::getInstance()->get($cacheName);
 }
Example #4
0
	/**
	 * Does the user authentication.
	 */
	protected function initAuth() {
		// this is a work-around since neither RequestHandler
		// nor RouteHandler are populated right now
		$pathInfo = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : '';
		if (empty($pathInfo) || !preg_match('~^/(ACPCaptcha|Login|Logout)/~', $pathInfo)) {
			if (WCF::getUser()->userID == 0) {
				// build redirect path
				$application = ApplicationHandler::getInstance()->getActiveApplication();
				$path = $application->getPageURL() . 'acp/index.php/Login/' . SID_ARG_1ST;
				
				HeaderUtil::redirect($path);
				exit;
			}
			else {
				// work-around for AJAX-requests within ACP
				if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
					try {
						WCF::getSession()->checkPermissions(array('admin.general.canUseAcp'));
					}
					catch (PermissionDeniedException $e) {
						throw new AJAXException(self::getLanguage()->get('wcf.ajax.error.permissionDenied'), AJAXException::INSUFFICIENT_PERMISSIONS, $e->getTraceAsString());
					}
				}
				else {
					WCF::getSession()->checkPermissions(array('admin.general.canUseAcp'));
				}
			}
		}
	}
 /**
  * @see	\wcf\system\template\TemplateEngine::getCompiledFilename()
  */
 public function getCompiledFilename($templateName, $application)
 {
     $abbreviation = 'wcf';
     if (PACKAGE_ID) {
         $abbreviation = ApplicationHandler::getInstance()->getActiveApplication()->getAbbreviation();
     }
     return $this->compileDir . $this->templateGroupID . '_' . $abbreviation . '_' . $this->languageID . '_' . $templateName . '.php';
 }
Example #6
0
 /**
  * @see wcf\system\menu\ITreeMenuItem::getLink()
  */
 public function getLink()
 {
     $abbreviation = ApplicationHandler::getInstance()->getAbbreviation($this->packageID);
     $parameters = array();
     if ($abbreviation) {
         $parameters['application'] = $abbreviation;
     }
     return LinkHandler::getInstance()->getLink(null, $parameters, $this->menuItemLink);
 }
 /**
  * @see	\wcf\system\event\IEventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     // thx to SoftCreatR http://www.woltlab.com/forum/index.php/Thread/224017-Request-Handler/?postID=1332856#post1332856
     $application = ApplicationHandler::getInstance()->getActiveApplication();
     if (PACKAGE_ID != 1 && $application != null) {
         $route = new Route('cmsPageRoute');
         $route->setSchema('/{alias}/', 'Page');
         $route->setParameterOption('alias', null, PageUtil::ALIAS_PATTERN_STACK);
         $eventObj->addRoute($route);
     }
 }
Example #8
0
 /**
  * @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;
     }
 }
	/**
	 * Uninstalls node components and returns next node.
	 * 
	 * @param	string		$node
	 * @return	string
	 */
	public function uninstall($node) {
		$nodes = $this->nodeBuilder->getNodeData($node);
		
		// invoke node-specific actions
		foreach ($nodes as $data) {
			$nodeData = unserialize($data['nodeData']);
			
			switch ($data['nodeType']) {
				case 'package':
					$this->uninstallPackage($nodeData);
				break;
				
				case 'pip':
					$this->executePIP($nodeData);
				break;
			}
		}
		
		// mark node as completed
		$this->nodeBuilder->completeNode($node);
		$node = $this->nodeBuilder->getNextNode($node);
		
		// perform post-uninstall actions
		if ($node == '') {
			// update options.inc.php if uninstallation is completed
			OptionEditor::resetCache();
			
			// clear cache
			CacheHandler::getInstance()->flushAll();
			
			// reset language cache
			LanguageFactory::getInstance()->clearCache();
			LanguageFactory::getInstance()->deleteLanguageCache();
			
			// reset stylesheets
			StyleHandler::resetStylesheets();
			
			// rebuild application paths
			ApplicationHandler::rebuild();
		}
		
		if ($this->requireRestructureVersionTables) {
			$this->restructureVersionTables();
		}		
		
		// return next node
		return $node;
	}
 /**
  * @see	\wcf\system\SingletonFactory::init()
  */
 protected function init()
 {
     $this->packageID = ApplicationHandler::getInstance()->getPrimaryApplication()->packageID;
     // load stored quotes from session
     $messageQuotes = WCF::getSession()->getVar('__messageQuotes' . $this->packageID);
     if (is_array($messageQuotes)) {
         $this->quotes = isset($messageQuotes['quotes']) ? $messageQuotes['quotes'] : array();
         $this->quoteData = isset($messageQuotes['quoteData']) ? $messageQuotes['quoteData'] : array();
         $this->removeQuoteIDs = isset($messageQuotes['removeQuoteIDs']) ? $messageQuotes['removeQuoteIDs'] : array();
     }
     // load object types
     $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.message.quote');
     foreach ($objectTypes as $objectType) {
         $this->objectTypes[$objectType->objectType] = $objectType;
     }
 }
Example #11
0
 /**
  * Does the user authentication.
  */
 protected function initAuth()
 {
     // this is a work-around since neither RequestHandler
     // nor RouteHandler are populated right now
     $pathInfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
     if (empty($pathInfo) || !preg_match('~^/(ACPCaptcha|Login|Logout)/~', $pathInfo)) {
         if (WCF::getUser()->userID == 0) {
             // build redirect path
             $application = ApplicationHandler::getInstance()->getActiveApplication();
             $path = $application->domainName . $application->domainPath . 'acp/index.php/Login/' . SID_ARG_1ST;
             util\HeaderUtil::redirect($path, false);
             exit;
         } else {
             WCF::getSession()->checkPermissions(array('admin.general.canUseAcp'));
         }
     }
 }
 /**
  * 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();
         }
     }
 }
Example #13
0
	/**
	 * @see	wcf\system\SingletonFactory::init()
	 */
	protected final function init() {
		if (empty($this->abbreviation) || $this->abbreviation == 'wcf') {
			throw new SystemException("Unable to determine application, abbreviation is missing");
		}
		
		$application = ApplicationHandler::getInstance()->getApplication($this->abbreviation);
		if ($application === null) {
			throw new SystemException("Unable to determine application, abbreviation is unknown");
		}
		
		$this->packageID = $application->packageID;
		
		// check if current application is active (directly invoked, not dependent)
		if ($application->packageID == ApplicationHandler::getInstance()->getActiveApplication()->packageID) {
			$this->isActiveApplication = true;
		}
	}
Example #14
0
 /**
  * Does the user authentication.
  */
 protected function initAuth()
 {
     // this is a work-around since neither RequestHandler
     // nor RouteHandler are populated right now
     $pathInfo = RouteHandler::getPathInfo();
     if (empty($pathInfo) || !preg_match('~^/?(acp-?captcha|login|logout)/~i', $pathInfo)) {
         if (WCF::getUser()->userID == 0) {
             // work-around for AJAX-requests within ACP
             if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
                 throw new AJAXException(WCF::getLanguage()->get('wcf.ajax.error.sessionExpired'), AJAXException::SESSION_EXPIRED, '');
             }
             // build redirect path
             $application = ApplicationHandler::getInstance()->getActiveApplication();
             if ($application === null) {
                 throw new SystemException("You have aborted the installation, therefore this installation is unusable. You are required to reinstall the software.");
             }
             // fallback for unknown host (rescue mode)
             if ($application->domainName != $_SERVER['HTTP_HOST']) {
                 $pageURL = RouteHandler::getProtocol() . $_SERVER['HTTP_HOST'] . RouteHandler::getPath(array('acp'));
             } else {
                 $pageURL = $application->getPageURL();
             }
             // drop session id
             $redirectURI = preg_replace('~[&\\?]s=[a-f0-9]{40}(&|$)~', '', WCF::getSession()->requestURI);
             $path = $pageURL . 'acp/index.php?login/' . SID_ARG_2ND_NOT_ENCODED . '&url=' . rawurlencode(RouteHandler::getProtocol() . $_SERVER['HTTP_HOST'] . $redirectURI);
             HeaderUtil::redirect($path);
             exit;
         } else {
             // work-around for AJAX-requests within ACP
             if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
                 try {
                     WCF::getSession()->checkPermissions(array('admin.general.canUseAcp'));
                 } catch (PermissionDeniedException $e) {
                     throw new AJAXException(self::getLanguage()->get('wcf.ajax.error.permissionDenied'), AJAXException::INSUFFICIENT_PERMISSIONS, $e->getTraceAsString());
                 }
             } else {
                 WCF::getSession()->checkPermissions(array('admin.general.canUseAcp'));
             }
             // force debug mode if in ACP and authenticated
             self::$overrideDebugMode = true;
         }
     }
 }
Example #15
0
 /**
  * Returns an array used to build a page selection. If $application is given,
  * only pages who belong to the application with the given abbreviation
  * are returned.
  * 
  * @param	string		$application
  * @return	array<string>
  */
 public function getSelection($application = null)
 {
     $objectTypes = $this->objectTypes;
     // filter by application
     if ($application !== null) {
         // validate application
         if ($application != 'wcf' && ApplicationHandler::getInstance()->getApplication($application) === null) {
             throw new SystemException("Unknown application with abbreviation '" . $application . "'");
         }
         foreach ($objectTypes as $objectTypeName => $objectType) {
             $classNamePieces = explode('\\', $objectType->className);
             if ($classNamePieces[0] != $application) {
                 unset($objectTypes[$objectTypeName]);
             }
         }
     }
     // filter by options
     foreach ($objectTypes as $objectTypeName => $objectType) {
         if ($objectType->options) {
             $options = explode(',', strtoupper($objectType->options));
             foreach ($options as $option) {
                 if (!defined($option) || !constant($option)) {
                     unset($objectTypes[$objectTypeName]);
                     break;
                 }
             }
         }
     }
     $selection = array();
     foreach ($objectTypes as $objectType) {
         $categoryName = WCF::getLanguage()->get('wcf.page.category.' . $objectType->categoryname);
         if (!isset($selection[$categoryName])) {
             $selection[$categoryName] = array();
         }
         $selection[$categoryName][$objectType->objectTypeID] = WCF::getLanguage()->get('wcf.page.' . $objectType->objectType);
     }
     ksort($selection);
     foreach ($selection as &$subSelection) {
         asort($subSelection);
     }
     return $selection;
 }
Example #16
0
 /**
  * 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);
 }
Example #17
0
	/**
	 * Returns class name for option type.
	 * 
	 * @param	string		$optionType
	 * @return	string
	 */
	protected function getClassName($optionType) {
		$optionType = StringUtil::firstCharToUpperCase($optionType);
		
		// attempt to validate against WCF first
		$isValid = false;
		$className = 'wcf\system\option\\'.$optionType.'OptionType';
		if (class_exists($className)) {
			$isValid = true;
		}
		else {
			if ($this->abbreviations === null) {
				$this->abbreviations = array();
				
				$applications = ApplicationHandler::getInstance()->getApplications();
				foreach ($applications as $application) {
					$this->abbreviations[] = ApplicationHandler::getInstance()->getAbbreviation($application->packageID);
				}
			}
			
			foreach ($this->abbreviations as $abbreviation) {
				$className = $abbreviation.'\system\option\\'.$optionType.'OptionType';
				if (class_exists($className)) {
					$isValid = true;
					break;
				}
			}
		}
		
		// validate class
		if (!$isValid) {
			return null;
		}
		
		if (!ClassUtil::isInstanceOf($className, 'wcf\system\option\IOptionType')) {
			throw new SystemException("'".$className."' does not implement 'wcf\system\option\IOptionType'");
		}
		
		return $className;
	}
Example #18
0
 /**
  * Returns the abbreviation of the application.
  * 
  * @return	string
  */
 public function getAbbreviation()
 {
     return ApplicationHandler::getInstance()->getAbbreviation($this->packageID);
 }
 /**
  * @see	\wcf\page\IPage::assignVariables()
  */
 public function assignVariables()
 {
     parent::assignVariables();
     WCF::getTPL()->assign(array('query' => $this->searchData['query'], 'objects' => $this->messages, 'searchData' => $this->searchData, 'searchID' => $this->searchID, 'highlight' => $this->highlight, 'sortField' => $this->searchData['sortField'], 'sortOrder' => $this->searchData['sortOrder'], 'alterable' => !empty($this->searchData['alterable']) ? 1 : 0, 'objectTypes' => SearchEngine::getInstance()->getAvailableObjectTypes(), 'resultListTemplateName' => $this->resultListTemplateName, 'resultListApplication' => $this->resultListApplication, 'application' => ApplicationHandler::getInstance()->getAbbreviation(ApplicationHandler::getInstance()->getActiveApplication()->packageID)));
 }
Example #20
0
 /**
  * Returns the favicon URL or a base64 encoded image.
  * 
  * @return	string
  */
 public function getFavicon()
 {
     $activeApplication = ApplicationHandler::getInstance()->getActiveApplication();
     $primaryApplication = ApplicationHandler::getInstance()->getPrimaryApplication();
     if ($activeApplication->domainName != $primaryApplication->domainName) {
         if (file_exists(WCF_DIR . 'images/favicon.ico')) {
             $favicon = file_get_contents(WCF_DIR . 'images/favicon.ico');
             return 'data:image/x-icon;base64,' . base64_encode($favicon);
         }
     }
     return self::getPath() . 'images/favicon.ico';
 }
Example #21
0
 /**
  * Generates an anchor tag from given URL.
  * 
  * @param	string		$url
  * @param	string		$title
  * @param	boolean		$encodeTitle
  * @return	string		anchor tag
  */
 public static function getAnchorTag($url, $title = '', $encodeTitle = true)
 {
     $url = self::trim($url);
     $external = true;
     if (ApplicationHandler::getInstance()->isInternalURL($url)) {
         $external = false;
         $url = preg_replace('~^https?://~', RouteHandler::getProtocol(), $url);
     }
     // cut visible url
     if (empty($title)) {
         // use URL and remove protocol and www subdomain
         $title = preg_replace('~^(?:https?|ftps?)://(?:www\\.)?~i', '', $url);
         if (mb_strlen($title) > 60) {
             $title = mb_substr($title, 0, 30) . self::HELLIP . mb_substr($title, -25);
         }
         if (!$encodeTitle) {
             $title = self::encodeHTML($title);
         }
     }
     return '<a href="' . self::encodeHTML($url) . '"' . ($external ? ' class="externalURL"' . (EXTERNAL_LINK_REL_NOFOLLOW ? ' rel="nofollow"' : '') . (EXTERNAL_LINK_TARGET_BLANK ? ' target="_blank"' : '') : '') . '>' . ($encodeTitle ? self::encodeHTML($title) : $title) . '</a>';
 }
Example #22
0
	/**
	 * @see	wcf\form\IForm::save()
	 */
	public function save() {
		parent::save();
		
		// change user
		WCF::getSession()->changeUser($this->user);
		$this->saved();
		
		if (!empty($this->url)) {
			// append session
			if (StringUtil::indexOf($this->url, '?') !== false) $this->url .= SID_ARG_2ND_NOT_ENCODED;
			else $this->url .= SID_ARG_1ST;
			HeaderUtil::redirect($this->url);
		}
		else {
			$application = ApplicationHandler::getInstance()->getActiveApplication();
			$path = $application->getPageURL() . 'acp/' . SID_ARG_1ST;
			HeaderUtil::redirect($path);
		}
		exit;
	}
Example #23
0
 /**
  * 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;
 }
Example #24
0
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     // get additional data
     $additionalData = array();
     foreach (SearchEngine::getInstance()->getAvailableObjectTypes() as $objectTypeName => $objectType) {
         if (($data = $objectType->getAdditionalData()) !== null) {
             $additionalData[$objectTypeName] = $data;
         }
     }
     // save result in database
     $this->searchData = array('packageID' => PACKAGE_ID, 'query' => $this->query, 'results' => $this->results, 'additionalData' => $additionalData, 'sortField' => $this->sortField, 'sortOrder' => $this->sortOrder, 'nameExactly' => $this->nameExactly, 'subjectOnly' => $this->subjectOnly, 'startDate' => $this->startDate, 'endDate' => $this->endDate, 'username' => $this->username, 'userID' => $this->userID, 'selectedObjectTypes' => $this->selectedObjectTypes, 'alterable' => !$this->userID ? 1 : 0);
     if ($this->modifySearchID) {
         $this->objectAction = new SearchAction(array($this->modifySearchID), 'update', array('data' => array('searchData' => serialize($this->searchData), 'searchTime' => TIME_NOW, 'searchType' => 'messages', 'searchHash' => $this->searchHash)));
         $this->objectAction->executeAction();
     } else {
         $this->objectAction = new SearchAction(array(), 'create', array('data' => array('userID' => WCF::getUser()->userID ?: null, 'searchData' => serialize($this->searchData), 'searchTime' => TIME_NOW, 'searchType' => 'messages', 'searchHash' => $this->searchHash)));
         $resultValues = $this->objectAction->executeAction();
         $this->searchID = $resultValues['returnValues']->searchID;
     }
     // save keyword
     if (!empty($this->query)) {
         SearchKeywordManager::getInstance()->add($this->query);
     }
     $this->saved();
     // get application
     $application = 'wcf';
     if (count($this->selectedObjectTypes) == 1) {
         $objectType = SearchEngine::getInstance()->getObjectType(reset($this->selectedObjectTypes));
         if ($tmp = ApplicationHandler::getInstance()->getAbbreviation($objectType->packageID)) {
             $application = $tmp;
         }
     }
     // forward to result page
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('SearchResult', array('id' => $this->searchID, 'application' => $application), 'highlight=' . urlencode($this->query)));
     exit;
 }
Example #25
0
 /**
  * Returns a relative link.
  * 
  * @param	string		$controller
  * @param	array		$parameters
  * @param	string		$url
  * @return	string
  */
 public function getLink($controller = null, array $parameters = array(), $url = '')
 {
     $abbreviation = 'wcf';
     $anchor = '';
     $isACP = $originIsACP = RequestHandler::getInstance()->isACPRequest();
     $forceWCF = $isRaw = false;
     $appendSession = $encodeTitle = true;
     // enforce a certain level of sanitation and protection for links embedded in emails
     if (isset($parameters['isEmail']) && (bool) $parameters['isEmail']) {
         $parameters['forceFrontend'] = true;
         $parameters['appendSession'] = false;
         unset($parameters['isEmail']);
     }
     if (isset($parameters['application'])) {
         $abbreviation = $parameters['application'];
     }
     if (isset($parameters['isRaw'])) {
         $isRaw = $parameters['isRaw'];
         unset($parameters['isRaw']);
     }
     if (isset($parameters['appendSession'])) {
         $appendSession = $parameters['appendSession'];
         unset($parameters['appendSession']);
     }
     if (isset($parameters['isACP'])) {
         $isACP = (bool) $parameters['isACP'];
         unset($parameters['isACP']);
         // drop session id if link leads to ACP from frontend or vice versa
         if ($originIsACP != $isACP) {
             $appendSession = false;
         }
     }
     if (isset($parameters['forceFrontend'])) {
         if ($parameters['forceFrontend'] && $isACP) {
             $isACP = false;
             $appendSession = false;
         }
         unset($parameters['forceFrontend']);
     }
     if (isset($parameters['forceWCF'])) {
         if ($parameters['forceWCF'] && $isACP) {
             $forceWCF = true;
         }
         unset($parameters['forceWCF']);
     }
     if (isset($parameters['encodeTitle'])) {
         $encodeTitle = $parameters['encodeTitle'];
         unset($parameters['encodeTitle']);
     }
     // remove anchor before parsing
     if (($pos = strpos($url, '#')) !== false) {
         $anchor = substr($url, $pos);
         $url = substr($url, 0, $pos);
     }
     // build route
     if ($controller === null) {
         if ($isACP) {
             $controller = 'Index';
         } else {
             return PageMenu::getInstance()->getLandingPage()->getProcessor()->getLink();
         }
     }
     // handle object
     if (isset($parameters['object'])) {
         if (!$parameters['object'] instanceof IRouteController && $parameters['object'] instanceof DatabaseObjectDecorator && $parameters['object']->getDecoratedObject() instanceof IRouteController) {
             $parameters['object'] = $parameters['object']->getDecoratedObject();
         }
         if ($parameters['object'] instanceof IRouteController) {
             $parameters['id'] = $parameters['object']->getObjectID();
             $parameters['title'] = $parameters['object']->getTitle();
         }
     }
     unset($parameters['object']);
     if (isset($parameters['title'])) {
         // component replacement
         if (!empty($this->titleSearch)) {
             $parameters['title'] = str_replace($this->titleSearch, $this->titleReplace, $parameters['title']);
         }
         // remove illegal characters
         $parameters['title'] = trim($this->titleRegex->replace($parameters['title'], '-'), '-');
         // trim to 80 characters
         $parameters['title'] = rtrim(mb_substr($parameters['title'], 0, 80), '-');
         if (!URL_LEGACY_MODE) {
             $parameters['title'] = mb_strtolower($parameters['title']);
         }
         // encode title
         if ($encodeTitle) {
             $parameters['title'] = rawurlencode($parameters['title']);
         }
     }
     $parameters['controller'] = $controller;
     $routeURL = RouteHandler::getInstance()->buildRoute($parameters, $isACP);
     if (!$isRaw && !empty($url)) {
         $routeURL .= strpos($routeURL, '?') === false ? '?' : '&';
     }
     // encode certain characters
     if (!empty($url)) {
         $url = str_replace(array('[', ']'), array('%5B', '%5D'), $url);
     }
     $url = $routeURL . $url;
     // append session id
     if ($appendSession) {
         $url .= strpos($url, '?') === false ? SID_ARG_1ST : SID_ARG_2ND_NOT_ENCODED;
     }
     // handle applications
     if (!PACKAGE_ID) {
         $url = RouteHandler::getHost() . RouteHandler::getPath(array('acp')) . ($isACP ? 'acp/' : '') . $url;
     } else {
         if (RequestHandler::getInstance()->inRescueMode()) {
             $pageURL = RouteHandler::getHost() . str_replace('//', '/', RouteHandler::getPath(array('acp')));
         } else {
             // try to resolve abbreviation
             $application = null;
             if ($abbreviation != 'wcf') {
                 $application = ApplicationHandler::getInstance()->getApplication($abbreviation);
             }
             // fallback to primary application if abbreviation is 'wcf' or unknown
             if ($forceWCF) {
                 $application = ApplicationHandler::getInstance()->getWCF();
             } else {
                 if ($application === null) {
                     $application = ApplicationHandler::getInstance()->getPrimaryApplication();
                 }
             }
             $pageURL = $application->getPageURL();
         }
         $url = $pageURL . ($isACP ? 'acp/' : '') . $url;
     }
     // append previously removed anchor
     $url .= $anchor;
     return $url;
 }
Example #26
0
 /**
  * Checks page access for possible mandatory redirects.
  * 
  * @param	string		$application
  * @param	array		$routeData
  */
 protected function handleDefaultController($application, array &$routeData)
 {
     if (!RouteHandler::getInstance()->isDefaultController()) {
         return;
     }
     $landingPage = PageMenu::getInstance()->getLandingPage();
     if ($landingPage === null) {
         return;
     }
     if (empty($routeData['controller'])) {
         $routeData['isImplicitController'] = true;
     }
     // resolve implicit application abbreviation for landing page controller
     $landingPageApplication = $landingPage->getApplication();
     $primaryApplication = ApplicationHandler::getInstance()->getPrimaryApplication();
     $primaryApplicationAbbr = ApplicationHandler::getInstance()->getAbbreviation($primaryApplication->packageID);
     if ($landingPageApplication == 'wcf') {
         $landingPageApplication = $primaryApplicationAbbr;
     }
     // check if currently invoked application matches the landing page
     if ($landingPageApplication == $application) {
         $routeData['controller'] = $landingPage->getController();
         if (!URL_LEGACY_MODE) {
             $routeData['controller'] = self::getTokenizedController($routeData['controller']);
         }
         // use alias if defined to prevent incorrect recognition
         $alias = $this->getAliasByController($routeData['controller']);
         if ($alias !== null) {
             $routeData['controller'] = $alias;
         }
         return;
     }
     // redirect if this is the primary application
     if ($application === $primaryApplicationAbbr) {
         HeaderUtil::redirect($landingPage->getLink());
         exit;
     }
     // set default controller
     $applicationObj = WCF::getApplicationObject(ApplicationHandler::getInstance()->getApplication($application));
     $routeData['controller'] = preg_replace('~^.*?\\\\([^\\\\]+)(?:Action|Form|Page)$~', '\\1', $applicationObj->getPrimaryController());
     if (!URL_LEGACY_MODE) {
         $routeData['controller'] = self::getTokenizedController($routeData['controller']);
     }
 }
 /**
  * Returns a list of application abbreviations.
  * 
  * @param	string		$suffix
  * @return	array<string>
  */
 public function getAbbreviations($suffix = '')
 {
     if (empty($this->abbreviations)) {
         // append the 'WCF' pseudo application
         $this->abbreviations[] = 'wcf';
         // get running application
         $this->abbreviations[] = ApplicationHandler::getInstance()->getAbbreviation(ApplicationHandler::getInstance()->getActiveApplication()->packageID);
         // get dependent applications
         foreach (ApplicationHandler::getInstance()->getDependentApplications() as $application) {
             $this->abbreviations[] = ApplicationHandler::getInstance()->getAbbreviation($application->packageID);
         }
     }
     if (!empty($suffix)) {
         $abbreviations = array();
         foreach ($this->abbreviations as $abbreviation) {
             $abbreviations[] = $abbreviation . $suffix;
         }
         return $abbreviations;
     }
     return $this->abbreviations;
 }
Example #28
0
	/**
	 * Alias to php setcookie() function.
	 */
	public static function setCookie($name, $value = '', $expire = 0) {
		$application = ApplicationHandler::getInstance()->getActiveApplication();
		$addDomain = (StringUtil::indexOf($application->cookieDomain, '.') === false || StringUtil::endsWith($application->cookieDomain, '.lan') || StringUtil::endsWith($application->cookieDomain, '.local')) ? false : true;
		
		@header('Set-Cookie: '.rawurlencode(COOKIE_PREFIX.$name).'='.rawurlencode($value).($expire ? '; expires='.gmdate('D, d-M-Y H:i:s', $expire).' GMT; max-age='.($expire - TIME_NOW) : '').'; path='.$application->cookiePath.($addDomain ? '; domain='.$application->cookieDomain : '').(RouteHandler::secureConnection() ? '; secure' : '').'; HttpOnly', false);
	}
	/**
	 * Installs node components and returns next node.
	 * 
	 * @param	string		$node
	 * @return	wcf\system\package\PackageInstallationStep
	 */
	public function install($node) {
		$nodes = $this->nodeBuilder->getNodeData($node);
		
		// invoke node-specific actions
		foreach ($nodes as $data) {
			$nodeData = unserialize($data['nodeData']);
			
			switch ($data['nodeType']) {
				case 'package':
					$step = $this->installPackage($nodeData);
				break;
				
				case 'pip':
					$step = $this->executePIP($nodeData);
				break;
				
				case 'optionalPackages':
					$step = $this->selectOptionalPackages($node, $nodeData);
				break;
				
				default:
					die("Unknown node type: '".$data['nodeType']."'");
				break;
			}
			
			if ($step->splitNode()) {
				$this->nodeBuilder->cloneNode($node, $data['sequenceNo']);
				break;
			}
		}
		
		// mark node as completed
		$this->nodeBuilder->completeNode($node);
		
		// assign next node
		$node = $this->nodeBuilder->getNextNode($node);
		$step->setNode($node);
		
		// perform post-install/update actions
		if ($node == '') {
			// update options.inc.php
			OptionEditor::resetCache();
			
			if ($this->action == 'install') {
				// save localized package infos
				$this->saveLocalizedPackageInfos();
				
				// remove all cache files after WCFSetup
				if (!PACKAGE_ID) {
					CacheHandler::getInstance()->flushAll();
				}
				
				// rebuild application paths
				ApplicationHandler::rebuild();
				ApplicationEditor::setup();
			}
			
			// remove template listener cache
			TemplateListenerCacheBuilder::getInstance()->reset();
			TemplateListenerCodeCacheBuilder::getInstance()->reset();
				
			// reset language cache
			LanguageFactory::getInstance()->clearCache();
			LanguageFactory::getInstance()->deleteLanguageCache();
			
			// reset stylesheets
			StyleHandler::resetStylesheets();
		}	
		
		if ($this->requireRestructureVersionTables) {
			$this->restructureVersionTables();
		}			
		
		return $step;
	}
Example #30
0
 /**
  * Returns a relative link.
  * 
  * @param	string		$controller
  * @param 	array		$parameters
  * @param 	string		$url
  * @return	string
  */
 public function getLink($controller = null, array $parameters = array(), $url = '')
 {
     $abbreviation = 'wcf';
     $anchor = '';
     $isRaw = false;
     if (isset($parameters['application'])) {
         $abbreviation = $parameters['application'];
         unset($parameters['application']);
     }
     if (isset($parameters['isRaw'])) {
         $isRaw = $parameters['isRaw'];
         unset($parameters['isRaw']);
     }
     // remove anchor before parsing
     if (($pos = strpos($url, '#')) !== false) {
         $anchor = substr($url, $pos);
         $url = substr($url, 0, $pos);
     }
     // build route
     if ($controller !== null) {
         // handle object
         if (isset($parameters['object'])) {
             if (!$parameters['object'] instanceof \wcf\system\request\IRouteController && $parameters['object'] instanceof \wcf\data\DatabaseObjectDecorator && $parameters['object']->getDecoratedObject() instanceof \wcf\system\request\IRouteController) {
                 $parameters['object'] = $parameters['object']->getDecoratedObject();
             }
             if ($parameters['object'] instanceof \wcf\system\request\IRouteController) {
                 $parameters['id'] = $parameters['object']->getID();
                 $parameters['title'] = $parameters['object']->getTitle();
             }
             unset($parameters['object']);
         }
         if (isset($parameters['title'])) {
             // remove illegal characters
             $parameters['title'] = trim(preg_replace('/[\\x0-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7F]+/', '-', $parameters['title']), '-');
         }
         $parameters['controller'] = $controller;
         $routeURL = RouteHandler::getInstance()->buildRoute($parameters);
         if (!$isRaw && !empty($url)) {
             $routeURL .= strpos($routeURL, '?') === false ? '?' : '&';
         }
         $url = $routeURL . $url;
     }
     // append session id
     $url .= strpos($url, '?') === false ? SID_ARG_1ST : SID_ARG_2ND_NOT_ENCODED;
     // handle application groups
     $applicationGroup = ApplicationHandler::getInstance()->getActiveGroup();
     if ($applicationGroup !== null) {
         // try to resolve abbreviation
         $application = null;
         if ($abbreviation != 'wcf') {
             $application = ApplicationHandler::getInstance()->getApplication($abbreviation);
         }
         // fallback to primary application if abbreviation is 'wcf' or unknown
         if ($application === null) {
             $application = ApplicationHandler::getInstance()->getPrimaryApplication();
         }
         $url = $application->domainName . $application->domainPath . (RequestHandler::getInstance()->isACPRequest() ? 'acp/' : '') . $url;
     }
     // append previously removed anchor
     $url .= $anchor;
     return $url;
 }