Exemplo n.º 1
0
 /**
  * @see	\wcf\action\IAction::execute();
  */
 public function execute()
 {
     parent::execute();
     // header
     @header('Content-type: text/xml');
     // file name
     @header('Content-disposition: attachment; filename="options.xml"');
     // no cache headers
     @header('Pragma: no-cache');
     @header('Expires: 0');
     // content
     echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<options>\n";
     $options = Option::getOptions();
     foreach ($options as $option) {
         if ($option->hidden) {
             continue;
         }
         // ignore hidden options
         echo "\t<option>\n";
         echo "\t\t<name><![CDATA[" . StringUtil::escapeCDATA($option->optionName) . "]]></name>\n";
         echo "\t\t<value><![CDATA[" . StringUtil::escapeCDATA($option->optionValue) . "]]></value>\n";
         echo "\t</option>\n";
     }
     echo '</options>';
     $this->executed();
     exit;
 }
Exemplo n.º 2
0
	/**
	 * @see	wcf\form\IForm::save()
	 */
	public function save() {
		parent::save();
		
		// build conditions
		$this->conditions = new PreparedStatementConditionBuilder();
		
		// static fields
		if (!empty($this->username)) {
			$this->conditions->add("user.username LIKE ?", array('%'.addcslashes($this->username, '_%').'%'));
		}
		if (!empty($this->email)) {
			$this->conditions->add("user.email LIKE ?", array('%'.addcslashes($this->email, '_%').'%'));
		}
		if (!empty($this->groupIDArray)) {
			$this->conditions->add("user.userID ".($this->invertGroupIDs == 1 ? 'NOT ' : '')."IN (SELECT userID FROM wcf".WCF_N."_user_to_group WHERE groupID IN (?))", array($this->groupIDArray));
		}
		if (!empty($this->languageIDArray)) {
			$this->conditions->add("user.languageID IN (?)", array($this->languageIDArray));
		}
		
		// dynamic fields
		foreach ($this->activeOptions as $name => $option) {
			$value = isset($this->values[$option['optionName']]) ? $this->values[$option['optionName']] : null;
			$this->getTypeObject($option['optionType'])->getCondition($this->conditions, $option, $value);
		}
		
		// call buildConditions event
		EventHandler::getInstance()->fireAction($this, 'buildConditions');
		
		// execute action
		switch ($this->action) {
			case 'sendMail':
				WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
				// get user ids
				$userIDArray = array();
				$sql = "SELECT		user.userID
					FROM		wcf".WCF_N."_user
					LEFT JOIN	wcf".WCF_N."_user_option_value option_value
					ON		(option_value.userID = user.userID)".
					$this->conditions;
				$statement = WCF::getDB()->prepareStatement($sql);
				$statement->execute($this->conditions->getParameters());
				while ($row = $statement->fetchArray()) {
					$userIDArray[] = $row['userID'];
					$this->affectedUsers++;
				}
				
				// save config in session
				$userMailData = WCF::getSession()->getVar('userMailData');
				if ($userMailData === null) $userMailData = array();
				$mailID = count($userMailData);
				$userMailData[$mailID] = array(
					'action' => '',
					'userIDs' => implode(',', $userIDArray),
					'groupIDs' => '',
					'subject' => $this->subject,
					'text' => $this->text,
					'from' => $this->from,
					'enableHTML' => $this->enableHTML
				);
				WCF::getSession()->register('userMailData', $userMailData);
				$this->saved();
				
				$url = LinkHandler::getInstance()->getLink('UserMail', array('id' => $mailID));
				
				// show worker template
				WCF::getTPL()->assign(array(
					'pageTitle' => WCF::getLanguage()->get('wcf.acp.user.sendMail'),
					'url' => $url
				));
				WCF::getTPL()->display('worker');
				exit;
			break;
			
			case 'exportMailAddress':
				WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
				// send content type
				header('Content-Type: text/'.$this->fileType.'; charset=UTF-8');
				header('Content-Disposition: attachment; filename="export.'.$this->fileType.'"');
				
				if ($this->fileType == 'xml') {
					echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
				}
				
				// count users
				$sql = "SELECT		COUNT(*) AS count
					FROM		wcf".WCF_N."_user user
					LEFT JOIN	wcf".WCF_N."_user_option_value option_value
					ON		(option_value.userID = user.userID)
					".$this->conditions;
				$statement = WCF::getDB()->prepareStatement($sql);
				$statement->execute($this->conditions->getParameters());
				$count = $statement->fetchArray();
				
				// get users
				$sql = "SELECT		user.email
					FROM		wcf".WCF_N."_user user
					LEFT JOIN	wcf".WCF_N."_user_option_value option_value
					ON		(option_value.userID = user.userID)
					".$this->conditions."
					ORDER BY	user.email";
				$statement = WCF::getDB()->prepareStatement($sql);
				$statement->execute($this->conditions->getParameters());
				
				$i = 0;
				while ($row = $statement->fetchArray()) {
					if ($this->fileType == 'xml') echo "<address><![CDATA[".StringUtil::escapeCDATA($row['email'])."]]></address>\n";
					else echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : '');
					$i++;
					$this->affectedUsers++;
				}
				
				if ($this->fileType == 'xml') {
					echo "</addresses>";
				}
				$this->saved();
				exit;
			break;
			
			case 'assignToGroup':
				WCF::getSession()->checkPermissions(array('admin.user.canEditUser'));
				
				$userIDArray = $this->fetchUsers(function($userID, array $userData) {
					$user = new UserEditor(new User(null, $userData));
					$user->addToGroups($this->assignToGroupIDArray, false, false);
				});
				
				UserStorageHandler::getInstance()->reset($userIDArray, 'groupIDs', 1);
			break;
			
			case 'delete':
				WCF::getSession()->checkPermissions(array('admin.user.canDeleteUser'));
				
				$userIDArray = $this->fetchUsers();
				
				UserEditor::deleteUsers($userIDArray);
			break;
		}
		$this->saved();
		
		WCF::getTPL()->assign('affectedUsers', $this->affectedUsers);
	}
Exemplo n.º 3
0
 /**
  * Writes an element directly.
  * 
  * @param	string		$element
  * @param	string		$cdata
  * @param	array<string>	$attributes
  */
 public function writeElement($element, $cdata, array $attributes = array())
 {
     $this->startElement($element);
     // write attributes
     if (!empty($attributes)) {
         $this->writeAttributes($attributes);
     }
     // content
     $this->xml->writeCData(StringUtil::escapeCDATA($cdata));
     $this->endElement();
 }
 /**
  * @see wcf\system\template\IModifierTemplatePlugin::execute()
  */
 public function execute($tagArgs, TemplateEngine $tplObj)
 {
     return StringUtil::escapeCDATA($tagArgs[0]);
 }
Exemplo n.º 5
0
 /**
  * Exports this language.
  */
 public function export($packageIDArray = array(), $exportCustomValues = false)
 {
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("language_item.languageID = ?", array($this->languageID));
     // bom
     echo "";
     // header
     echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<language xmlns=\"http://www.woltlab.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.woltlab.com http://www.woltlab.com/XSD/maelstrom/language.xsd\" languagecode=\"" . $this->languageCode . "\" languagename=\"" . $this->languageName . "\" countrycode=\"" . $this->countryCode . "\">\n";
     // get items
     $items = array();
     if (!empty($packageIDArray)) {
         $conditions->add("language_item.packageID IN (?)", array($packageIDArray));
     }
     $sql = "SELECT\t\tlanguageItem, " . ($exportCustomValues ? "CASE WHEN languageUseCustomValue > 0 THEN languageCustomItemValue ELSE languageItemValue END AS languageItemValue" : "languageItemValue") . ", languageCategory\n\t\t\tFROM\t\twcf" . WCF_N . "_language_item language_item\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_language_category language_category\n\t\t\tON\t\t(language_category.languageCategoryID = language_item.languageCategoryID)\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     while ($row = $statement->fetchArray()) {
         $items[$row['languageCategory']][$row['languageItem']] = $row['languageItemValue'];
     }
     // sort categories
     ksort($items);
     foreach ($items as $category => $categoryItems) {
         // sort items
         ksort($categoryItems);
         // category header
         echo "\t<category name=\"" . $category . "\">\n";
         // items
         foreach ($categoryItems as $item => $value) {
             echo "\t\t<item name=\"" . $item . "\"><![CDATA[" . StringUtil::escapeCDATA($value) . "]]></item>\n";
         }
         // category footer
         echo "\t</category>\n";
     }
     // footer
     echo "</language>";
 }
 /**
  * @see wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     // send content type
     header('Content-Type: text/' . $this->fileType . '; charset=UTF-8');
     header('Content-Disposition: attachment; filename="export.' . $this->fileType . '"');
     if ($this->fileType == 'xml') {
         echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
     }
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("userID IN (?)", array($this->userIDs));
     // count users
     $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_user\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $count = $statement->fetchArray();
     // get users
     $sql = "SELECT\t\temail\n\t\t\tFROM\t\twcf" . WCF_N . "_user\n\t\t\t" . $conditions . "\n\t\t\tORDER BY\temail";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $i = 0;
     while ($row = $statement->fetchArray()) {
         if ($this->fileType == 'xml') {
             echo "<address><![CDATA[" . StringUtil::escapeCDATA($row['email']) . "]]></address>\n";
         } else {
             echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : '');
         }
         $i++;
     }
     if ($this->fileType == 'xml') {
         echo "</addresses>";
     }
     $this->saved();
     // remove items
     ClipboardHandler::getInstance()->removeItems($this->typeID);
     exit;
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     // build conditions
     $this->conditions = new PreparedStatementConditionBuilder();
     // deny self delete
     if ($this->action == 'delete') {
         $this->conditions->add("user_table.userID <> ?", array(WCF::getUser()->userID));
     }
     // static fields
     if (!empty($this->username)) {
         $this->conditions->add("user_table.username LIKE ?", array('%' . addcslashes($this->username, '_%') . '%'));
     }
     if (!empty($this->email)) {
         $this->conditions->add("user_table.email LIKE ?", array('%' . addcslashes($this->email, '_%') . '%'));
     }
     if (!empty($this->groupIDs)) {
         $this->conditions->add("user_table.userID " . ($this->invertGroupIDs == 1 ? 'NOT ' : '') . "IN (SELECT userID FROM wcf" . WCF_N . "_user_to_group WHERE groupID IN (?))", array($this->groupIDs));
     }
     if (!empty($this->languageIDs)) {
         $this->conditions->add("user_table.languageID IN (?)", array($this->languageIDs));
     }
     // registration date
     if ($startDate = @strtotime($this->registrationDateStart)) {
         $this->conditions->add('user_table.registrationDate >= ?', array($startDate));
     }
     if ($endDate = @strtotime($this->registrationDateEnd)) {
         $this->conditions->add('user_table.registrationDate <= ?', array($endDate));
     }
     if ($this->banned) {
         $this->conditions->add('user_table.banned = ?', array(1));
     }
     if ($this->notBanned) {
         $this->conditions->add('user_table.banned = ?', array(0));
     }
     // last activity time
     if ($startDate = @strtotime($this->lastActivityTimeStart)) {
         $this->conditions->add('user_table.lastActivityTime >= ?', array($startDate));
     }
     if ($endDate = @strtotime($this->lastActivityTimeEnd)) {
         $this->conditions->add('user_table.lastActivityTime <= ?', array($endDate));
     }
     if ($this->enabled) {
         $this->conditions->add('user_table.activationCode = ?', array(0));
     }
     if ($this->disabled) {
         $this->conditions->add('user_table.activationCode <> ?', array(0));
     }
     // dynamic fields
     foreach ($this->activeOptions as $name => $option) {
         $value = isset($this->values[$option['optionName']]) ? $this->values[$option['optionName']] : null;
         $this->getTypeObject($option['optionType'])->getCondition($this->conditions, $option, $value);
     }
     // call buildConditions event
     EventHandler::getInstance()->fireAction($this, 'buildConditions');
     // execute action
     switch ($this->action) {
         case 'sendMail':
             WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
             // get user ids
             $userIDs = array();
             $sql = "SELECT\t\tuser_table.userID\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)" . $this->conditions;
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($this->conditions->getParameters());
             while ($row = $statement->fetchArray()) {
                 $userIDs[] = $row['userID'];
                 $this->affectedUsers++;
             }
             if (!empty($userIDs)) {
                 // save config in session
                 $userMailData = WCF::getSession()->getVar('userMailData');
                 if ($userMailData === null) {
                     $userMailData = array();
                 }
                 $mailID = count($userMailData);
                 $userMailData[$mailID] = array('action' => '', 'userIDs' => $userIDs, 'groupIDs' => '', 'subject' => $this->subject, 'text' => $this->text, 'from' => $this->from, 'enableHTML' => $this->enableHTML);
                 WCF::getSession()->register('userMailData', $userMailData);
                 WCF::getTPL()->assign('mailID', $mailID);
             }
             break;
         case 'exportMailAddress':
             WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
             // send content type
             header('Content-Type: text/' . $this->fileType . '; charset=UTF-8');
             header('Content-Disposition: attachment; filename="export.' . $this->fileType . '"');
             if ($this->fileType == 'xml') {
                 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
             }
             // count users
             $sql = "SELECT\t\tCOUNT(*) AS count\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t\t\t" . $this->conditions;
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($this->conditions->getParameters());
             $count = $statement->fetchArray();
             // get users
             $sql = "SELECT\t\tuser_table.email\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t\t\t" . $this->conditions . "\n\t\t\t\t\tORDER BY\tuser_table.email";
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($this->conditions->getParameters());
             $i = 0;
             while ($row = $statement->fetchArray()) {
                 if ($this->fileType == 'xml') {
                     echo "<address><![CDATA[" . StringUtil::escapeCDATA($row['email']) . "]]></address>\n";
                 } else {
                     echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : '');
                 }
                 $i++;
                 $this->affectedUsers++;
             }
             if ($this->fileType == 'xml') {
                 echo "</addresses>";
             }
             $this->saved();
             exit;
             break;
         case 'assignToGroup':
             WCF::getSession()->checkPermissions(array('admin.user.canEditUser'));
             $_this = $this;
             $userIDs = $this->fetchUsers(function ($userID, array $userData) use($_this) {
                 $user = new UserEditor(new User(null, $userData));
                 $user->addToGroups($_this->assignToGroupIDs, false, false);
             });
             if (!empty($userIDs)) {
                 UserStorageHandler::getInstance()->reset($userIDs, 'groupIDs', 1);
             }
             break;
         case 'delete':
             WCF::getSession()->checkPermissions(array('admin.user.canDeleteUser'));
             $userIDs = $this->fetchUsers();
             if (!empty($userIDs)) {
                 $userAction = new UserAction($userIDs, 'delete');
                 $userAction->executeAction();
             }
             break;
     }
     $this->saved();
     WCF::getTPL()->assign('affectedUsers', $this->affectedUsers);
 }
Exemplo n.º 8
0
 /**
  * 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);
 }