/**
  * Checks the condition.
  *
  * @param	PMRuleCondition		$condition
  * @param	string			$string
  * @return	boolean
  */
 protected function checkCondition(PMRuleCondition $condition, $string)
 {
     $value = StringUtil::toLowerCase($condition->ruleConditionValue);
     $string = StringUtil::toLowerCase($string);
     switch ($condition->ruleCondition) {
         case 'contains':
             if (StringUtil::indexOf($string, $value) !== false) {
                 return true;
             }
             break;
         case 'dontContains':
             if (StringUtil::indexOf($string, $value) === false) {
                 return true;
             }
             break;
         case 'beginsWith':
             if (StringUtil::indexOf($string, $value) === 0) {
                 return true;
             }
             break;
         case 'endsWith':
             if (StringUtil::substring($string, -1 * StringUtil::length($value)) == $value) {
                 return true;
             }
             break;
         case 'isEqualTo':
             if ($value == $string) {
                 return true;
             }
             break;
     }
     return false;
 }
 /**
  * @see Page::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     // get available letters
     $defaultLetters = WCF::getLanguage()->get('wcf.user.membersList.letters');
     if (!empty($defaultLetters) && $defaultLetters != 'wcf.user.membersList.letters') {
         self::$defaultLetters = $defaultLetters;
     }
     // get user options
     $this->userOptions = new UserOptions('medium');
     // letter
     if (isset($_REQUEST['letter']) && StringUtil::length($_REQUEST['letter']) == 1 && StringUtil::indexOf(self::$defaultLetters, $_REQUEST['letter']) !== false) {
         $this->letter = $_REQUEST['letter'];
     }
     // active fields
     $this->activeFields = explode(',', MEMBERS_LIST_COLUMNS);
     if (MODULE_AVATAR != 1 && ($key = array_search('avatar', $this->activeFields)) !== false) {
         unset($this->activeFields[$key]);
     }
     // search id
     if (isset($_REQUEST['searchID'])) {
         $this->searchID = intval($_REQUEST['searchID']);
         if ($this->searchID != 0) {
             $this->getSearchResult();
         }
     }
 }
 /**
  * Inserts the page number into the link.
  * 
  * @param 	string		$link
  * @param 	integer		$pageNo
  * @return	string		final link
  */
 protected static function insertPageNumber($link, $pageNo)
 {
     $startPos = StringUtil::indexOf($link, '%d');
     if ($startPos !== null) {
         $link = StringUtil::substring($link, 0, $startPos) . $pageNo . StringUtil::substring($link, $startPos + 2);
     }
     return $link;
 }
 /**
  * @see BBCode::getParsedTag()
  */
 public function getParsedTag($openingTag, $content, $closingTag, BBCodeParser $parser)
 {
     if (StringUtil::indexOf($content, '[*]') !== false) {
         // get list elements
         $listElements = preg_split('/\\[\\*\\]/', StringUtil::trim($content), -1, PREG_SPLIT_NO_EMPTY);
         // remove empty elements
         foreach ($listElements as $key => $val) {
             $listElements[$key] = StringUtil::trim($val);
             if (empty($listElements[$key]) || $listElements[$key] == '<br />') {
                 unset($listElements[$key]);
             }
         }
         if (count($listElements) > 0) {
             // get list style type
             $listType = 'disc';
             if (isset($openingTag['attributes'][0])) {
                 $listType = $openingTag['attributes'][0];
             }
             $listType = strtolower($listType);
             // replace old types
             if ($listType == '1') {
                 $listType = 'decimal';
             }
             if ($listType == 'a') {
                 $listType = 'lower-latin';
             }
             if ($parser->getOutputType() == 'text/html') {
                 // build list html
                 $listHTML = 'ol';
                 if ($listType == 'none' || $listType == 'circle' || $listType == 'square' || $listType == 'disc') {
                     $listHTML = 'ul';
                 }
                 return '<' . $listHTML . ' style="list-style-type: ' . $listType . '"><li>' . implode('</li><li>', $listElements) . '</li></' . $listHTML . '>';
             } else {
                 if ($parser->getOutputType() == 'text/plain') {
                     $result = '';
                     $i = 1;
                     foreach ($listElements as $listElement) {
                         switch ($listType) {
                             case 'decimal':
                                 $result .= $i . '. ';
                                 break;
                             default:
                                 $result .= '- ';
                         }
                         $result .= $listElement . "\n";
                         $i++;
                     }
                     return $result;
                 }
             }
         }
     }
     // no valid list
     // return bbcode as text
     return $openingTag['source'] . $content . $closingTag['source'];
 }
Beispiel #5
0
	/**
	 * Reinserts strings that have been replaced by unique hash values.
	 *
	 * @param	string		$string
	 * @param	string		$type
	 * @return	string
	 */
	public static function reinsertStrings($string, $type = 'default') {
		if (isset(self::$stringStack[$type])) {
			foreach (self::$stringStack[$type] as $hash => $value) {
				if (StringUtil::indexOf($string, $hash) !== false) {
					$string = StringUtil::replace($hash, $value, $string);
					unset(self::$stringStack[$type][$hash]);
				}
			}
		}
		
		return $string;
	}
 /**
  * Starts the extracting of the files.
  */
 protected function install()
 {
     $this->checkTargetDir();
     $this->createTargetDir();
     // open source archive
     $tar = new Tar($this->source);
     // distinct directories and files
     $directories = array();
     $files = array();
     foreach ($tar->getContentList() as $index => $file) {
         if (empty($this->folder) || StringUtil::indexOf($file['filename'], $this->folder) === 0) {
             if (!empty($this->folder)) {
                 $file['filename'] = StringUtil::replace($this->folder, '', $file['filename']);
             }
             // remove leading slash
             $file['filename'] = FileUtil::removeLeadingSlash($file['filename']);
             if ($file['type'] == 'folder') {
                 // remove trailing slash
                 $directories[] = FileUtil::removeTrailingSlash($file['filename']);
             } else {
                 $files[$index] = $file['filename'];
             }
         }
     }
     $this->checkFiles($files);
     // now create the directories
     $errors = array();
     foreach ($directories as $dir) {
         try {
             $this->createDir($dir);
         } catch (SystemException $e) {
             $errors[] = array('file' => $dir, 'code' => $e->getCode(), 'message' => $e->getMessage());
         }
     }
     // now untar all files
     foreach ($files as $index => $file) {
         try {
             $this->createFile($file, $index, $tar);
         } catch (SystemException $e) {
             $errors[] = array('file' => $file, 'code' => $e->getCode(), 'message' => $e->getMessage());
         }
     }
     if (count($errors) > 0) {
         throw new SystemException('error(s) during the installation of the files.', 11111, $errors);
     }
     $this->logFiles($files);
     // close tar
     $tar->close();
 }
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     if (!empty($this->filename)) {
         // import style
         $this->style = StyleEditor::import($this->filename, PACKAGE_ID, $this->destinationStyle !== null && $this->destinationStyle->styleID ? $this->destinationStyle : null);
     } else {
         // import destination
         if ($this->destinationStyle !== null && !$this->destinationStyle->styleID) {
             throw new UserInputException('destinationStyleID');
         }
         // upload style
         if ($this->styleUpload && $this->styleUpload['error'] != 4) {
             if ($this->styleUpload['error'] != 0) {
                 throw new UserInputException('styleUpload', 'uploadFailed');
             }
             $this->newFilename = $this->styleUpload['tmp_name'];
             try {
                 $this->styleData = StyleEditor::getStyleData($this->styleUpload['tmp_name']);
             } catch (SystemException $e) {
                 throw new UserInputException('styleUpload', 'invalid');
             }
             // copy file
             $newFilename = FileUtil::getTemporaryFilename('style_');
             if (@move_uploaded_file($this->styleUpload['tmp_name'], $newFilename)) {
                 $this->newFilename = $newFilename;
             }
         } else {
             if ($this->styleURL != 'http://') {
                 if (StringUtil::indexOf($this->styleURL, 'http://') !== 0) {
                     throw new UserInputException('styleURL', 'downloadFailed');
                 }
                 try {
                     $this->newFilename = FileUtil::downloadFileFromHttp($this->styleURL, 'style');
                 } catch (SystemException $e) {
                     throw new UserInputException('styleURL', 'downloadFailed');
                 }
                 try {
                     $this->styleData = StyleEditor::getStyleData($this->newFilename);
                 } catch (SystemException $e) {
                     throw new UserInputException('styleURL', 'invalid');
                 }
             } else {
                 throw new UserInputException('styleUpload');
             }
         }
     }
 }
    /**
     * Adds the url and email bbcode tags in a text automatically.
     */
    public static function parse($text)
    {
        self::$text = $text;
        // cache codes
        self::$text = self::cacheCodes(self::$text);
        // call event
        EventHandler::fireAction('URLParser', 'shouldParse');
        // define pattern
        $urlPattern = '~(?<!\\B|"|\'|=|/|\\]|,|\\?)
			(?:						# hostname
				(?:ftp|https?)://' . self::$illegalChars . '(?:\\.' . self::$illegalChars . ')*
				|
				www\\.(?:' . self::$illegalChars . '\\.)+
				(?:[a-z]{2,4}(?=\\b))
			)

			(?::\\d+)?					# port

			(?:
				/
				[^!.,?;"\'<>()\\[\\]{}\\s]*
				(?:
					[!.,?;(){}]+ [^!.,?;"\'<>()\\[\\]{}\\s]+
				)*
			)?
			~ix';
        $emailPattern = '~(?<!\\B|"|\'|=|/|\\]|,|:)
			(?:)
			\\w+(?:[\\.\\-]\\w+)*
			@
			(?:' . self::$illegalChars . '\\.)+		# hostname
			(?:[a-z]{2,4}(?=\\b))
			(?!"|\'|\\[|\\-|\\.[a-z])
			~ix';
        // add url tags
        self::$text = preg_replace($urlPattern, '[url]\\0[/url]', self::$text);
        if (StringUtil::indexOf(self::$text, '@') !== false) {
            self::$text = preg_replace($emailPattern, '[email]\\0[/email]', self::$text);
        }
        // call event
        EventHandler::fireAction('URLParser', 'didParse');
        if (count(self::$cachedCodes) > 0) {
            // insert cached codes
            self::$text = self::insertCachedCodes(self::$text);
        }
        return self::$text;
    }
Beispiel #9
0
 /**
  * Returns a list of the enable options.
  * 
  * @param 	string		$enableOptions
  * @return	array
  */
 public static function parseMultipleEnableOptions($enableOptions)
 {
     $result = array();
     if (!empty($enableOptions)) {
         $options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($enableOptions)));
         $key = -1;
         foreach ($options as $option) {
             if (StringUtil::indexOf($option, ':') !== false) {
                 $optionData = explode(':', $option);
                 $key = array_shift($optionData);
                 $value = implode(':', $optionData);
             } else {
                 $key++;
                 $value = $option;
             }
             $result[$key] = $value;
         }
     }
     return $result;
 }
 protected static function getResult($optionData, $value)
 {
     $options = OptionUtil::parseSelectOptions($optionData['selectOptions']);
     // multiselect
     if (StringUtil::indexOf($value, "\n") !== false) {
         $values = explode("\n", $value);
         $result = array();
         foreach ($values as $value) {
             if (isset($options[$value])) {
                 $result[] = $options[$value];
             }
         }
         return $result;
     } else {
         if (!empty($value) && isset($options[$value])) {
             return $options[$value];
         }
         return null;
     }
 }
	/**
	 * @see EventListener::execute()
	 */
	public function execute($eventObj, $className, $eventName) {
		if (!MODULE_ROUTER) return;
		
		// get base
		$segments = explode('/', FileUtil::addTrailingSlash(PAGE_URL), 4);
		if (!empty($segments[3])) $this->base .= $segments[3];
		
		// load routes
		WCF::getCache()->addResource(
			'routes-'.PACKAGE_ID,
			WCF_DIR.'cache/cache.routes-'.PACKAGE_ID.'.php',
			WCF_DIR.'lib/system/cache/CacheBuilderRoutes.class.php'
		);
		$this->routes = WCF::getCache()->get('routes-'.PACKAGE_ID);
		
		// get request
		$request = $_SERVER['REQUEST_URI'];
		$_ = explode($this->base, $request, 2);
		$request = $_[count($_)-1];
		
		if (StringUtil::indexOf($request, 'index.php') === 0)
			return false;
		
		// get route which suits best for the request
		if (!$route = $this->getRouteByRequest($request))
			throw new SystemException('No route');
		
		// set variables
		foreach ($route[0][1] as $isset) {
			if (!isset($route[0][2][$isset]) && isset($route[1][$isset])) {
				$_GET[$isset] = $route[1][$isset];
				$_REQUEST[$isset] = $route[1][$isset];
			}
		}
		
		// set predefined variables
		foreach ($route[0][2] as $key => $value) {
			$_GET[$key] = $value;
			$_REQUEST[$key] = $value;
		}
	}
 /**
  * @see EventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     if (MODULE_AVATAR == 1) {
         if ($eventName == 'readFormParameters') {
             if (isset($_POST['avatarID'])) {
                 $this->avatarID = intval($_POST['avatarID']);
             }
             if (isset($_POST['disableAvatar'])) {
                 $this->disableAvatar = intval($_POST['disableAvatar']);
             }
             if (isset($_POST['disableAvatarReason'])) {
                 $this->disableAvatarReason = $_POST['disableAvatarReason'];
             }
             if (isset($_POST['useAvatar'])) {
                 $this->useAvatar = intval($_POST['useAvatar']);
             }
             if (isset($_POST['avatarURL'])) {
                 $this->avatarURL = StringUtil::trim($_POST['avatarURL']);
             }
             if (isset($_FILES['avatarUpload'])) {
                 $this->avatarUpload = $_FILES['avatarUpload'];
             }
             if (MODULE_GRAVATAR == 1 && isset($_POST['gravatar'])) {
                 $this->gravatar = StringUtil::trim($_POST['gravatar']);
             }
         } else {
             if ($eventName == 'validate') {
                 try {
                     if ($this->useAvatar == 1) {
                         if (empty($this->gravatar)) {
                             // upload or download avatar
                             if ($this->avatarUpload && $this->avatarUpload['error'] != 4) {
                                 if ($this->avatarUpload['error'] != 0) {
                                     throw new UserInputException('avatarUpload', 'uploadFailed');
                                 }
                                 $this->avatarID = AvatarEditor::create($this->avatarUpload['tmp_name'], $this->avatarUpload['name'], 'avatarUpload', $eventObj->userID);
                             } else {
                                 if ($this->avatarURL != 'http://') {
                                     if (StringUtil::indexOf($this->avatarURL, 'http://') !== 0) {
                                         throw new UserInputException('avatarURL', 'downloadFailed');
                                     }
                                     try {
                                         $tmpName = FileUtil::downloadFileFromHttp($this->avatarURL, 'avatar');
                                     } catch (SystemException $e) {
                                         throw new UserInputException('avatarURL', 'downloadFailed');
                                     }
                                     $this->avatarID = AvatarEditor::create($tmpName, $this->avatarURL, 'avatarURL', $eventObj->userID);
                                 } else {
                                     $this->avatarID = $eventObj->user->avatarID;
                                 }
                             }
                         }
                     } else {
                         if ($this->useAvatar == 2) {
                             // use a default avatar
                             $avatar = new AvatarEditor($this->avatarID);
                             if (!$avatar->avatarID || $avatar->userID || $avatar->groupID && !in_array($avatar->groupID, $eventObj->user->getGroupIDs()) || $avatar->neededPoints > $eventObj->user->activityPoints) {
                                 throw new UserInputException('availableAvatars', 'invalid');
                             }
                         } else {
                             $this->avatarID = 0;
                         }
                     }
                 } catch (UserInputException $e) {
                     $eventObj->errorType[$e->getField()] = $e->getType();
                 }
             } else {
                 if ($eventName == 'save') {
                     // delete old avatar if necessary
                     if ($eventObj->user->avatarID) {
                         $currentAvatar = new AvatarEditor($eventObj->user->avatarID);
                         if ($currentAvatar->userID && $this->avatarID != $currentAvatar->avatarID) {
                             $currentAvatar->delete();
                         }
                     }
                     // update user
                     $eventObj->additionalFields['avatarID'] = $this->avatarID;
                     $eventObj->additionalFields['disableAvatar'] = $this->disableAvatar;
                     $eventObj->additionalFields['disableAvatarReason'] = $this->disableAvatarReason;
                     $eventObj->additionalFields['gravatar'] = $this->gravatar;
                 } else {
                     if ($eventName == 'show') {
                         // get default values
                         if (!count($_POST)) {
                             $this->avatarID = $eventObj->user->avatarID;
                             $this->disableAvatar = $eventObj->user->disableAvatar;
                             $this->disableAvatarReason = $eventObj->user->disableAvatarReason;
                             $this->gravatar = $eventObj->user->gravatar;
                         }
                         $currentAvatar = null;
                         if ($this->avatarID) {
                             $currentAvatar = new AvatarEditor($this->avatarID);
                             $this->useAvatar = $currentAvatar->userID ? 1 : 2;
                         } else {
                             if ($this->gravatar) {
                                 require_once WCF_DIR . 'lib/data/user/avatar/Gravatar.class.php';
                                 $currentAvatar = new Gravatar($this->gravatar);
                                 $this->useAvatar = 1;
                             }
                         }
                         $availableAvatarCategories = $this->getAvailableAvatars(implode(',', $eventObj->user->getGroupIDs()), intval($eventObj->user->activityPoints));
                         $avatarCount = 0;
                         foreach ($availableAvatarCategories as $availableAvatarCategory) {
                             $avatarCount += count($availableAvatarCategory['avatars']);
                         }
                         WCF::getTPL()->assign(array('avatarID' => $this->avatarID, 'disableAvatar' => $this->disableAvatar, 'disableAvatarReason' => $this->disableAvatarReason, 'avatarURL' => $this->avatarURL, 'currentAvatar' => $currentAvatar, 'avatarCategories' => $availableAvatarCategories, 'items' => $avatarCount, 'useAvatar' => $this->useAvatar, 'gravatar' => $this->gravatar));
                         WCF::getTPL()->append(array('additionalTabs' => '<li id="avatar"><a onclick="tabMenu.showSubTabMenu(\'avatar\');"><span>' . WCF::getLanguage()->get('wcf.user.avatar') . '</span></a></li>', 'additionalTabContents' => WCF::getTPL()->fetch('userEditAvatar')));
                     }
                 }
             }
         }
     }
 }
    /**
     * Parses urls.
     * 
     * @param	string		$text
     * @return	string		text
     */
    public static function parseURLs($text)
    {
        // define pattern
        $urlPattern = '~(?<!\\B|"|\'|=|/|\\]|,|\\?)
			(?:						# hostname
				(?:ftp|https?)://' . self::$illegalChars . '(?:\\.' . self::$illegalChars . ')*
				|
				www\\.(?:' . self::$illegalChars . '\\.)+
				(?:[a-z]{2,4}(?=\\b))
			)

			(?::\\d+)?					# port

			(?:
				/
				[^!.,?;"\'<>()\\[\\]{}\\s]*
				(?:
					[!.,?;(){}]+ [^!.,?;"\'<>()\\[\\]{}\\s]+
				)*
			)?
			~ix';
        $emailPattern = '~(?<!\\B|"|\'|=|/|\\]|,|:)
			(?:)
			\\w+(?:[\\.\\-]\\w+)*
			@
			(?:' . self::$illegalChars . '\\.)+		# hostname
			(?:[a-z]{2,4}(?=\\b))
			(?!"|\'|\\[|\\-)
			~ix';
        // parse urls
        $text = preg_replace_callback($urlPattern, array('self', 'parseURLsCallback'), $text);
        // parse emails
        if (StringUtil::indexOf($text, '@') !== false) {
            $text = preg_replace($emailPattern, '<a href="mailto:\\0">\\0</a>', $text);
        }
        return $text;
    }
Beispiel #14
0
 public static function checkFromversion($currentVersion, $fromversion)
 {
     if (StringUtil::indexOf($fromversion, '*') !== false) {
         // from version with wildcard
         // use regular expression
         $fromversion = StringUtil::replace('\\*', '.*', preg_quote($fromversion, '!'));
         if (preg_match('!^' . $fromversion . '$!i', $currentVersion)) {
             return true;
         }
     } else {
         if (self::compareVersion($currentVersion, $fromversion, '=')) {
             return true;
         }
     }
     return false;
 }
 /**
  * @see Form::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 {
         HeaderUtil::redirect('index.php?packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED);
     }
     exit;
 }
 /**
  * Replaces all php tags.
  * 
  * @param	string		$string
  * @return	string
  */
 public function replacePHPTags($string)
 {
     if (StringUtil::indexOf($string, '<?') !== false) {
         $string = StringUtil::replace('<?php', '@@PHP_START_TAG@@', $string);
         $string = StringUtil::replace('<?', '@@PHP_SHORT_START_TAG@@', $string);
         $string = StringUtil::replace('?>', '@@PHP_END_TAG@@', $string);
         $string = StringUtil::replace('@@PHP_END_TAG@@', "<?php echo '?>'; ?>\n", $string);
         $string = StringUtil::replace('@@PHP_SHORT_START_TAG@@', "<?php echo '<?'; ?>\n", $string);
         $string = StringUtil::replace('@@PHP_START_TAG@@', "<?php echo '<?php'; ?>\n", $string);
     }
     return $string;
 }
 /**
  * Gets the package name of the first standalone application in WCFSetup.tar.gz.
  */
 protected static function getPackageName()
 {
     // get package name
     $tar = new Tar(SETUP_FILE);
     foreach ($tar->getContentList() as $file) {
         if ($file['type'] != 'folder' && StringUtil::indexOf($file['filename'], 'install/packages/') === 0) {
             $packageFile = basename($file['filename']);
             $packageName = preg_replace('!\\.(tar\\.gz|tgz|tar)$!', '', $packageFile);
             if ($packageName != 'com.woltlab.wcf') {
                 try {
                     $archive = new PackageArchive(TMP_DIR . TMP_FILE_PREFIX . $packageFile);
                     $archive->openArchive();
                     self::$setupPackageName = $archive->getPackageInfo('packageName');
                     $archive->getTar()->close();
                     break;
                 } catch (SystemException $e) {
                 }
             }
         }
     }
     $tar->close();
     // assign package name
     WCF::getTPL()->assign('setupPackageName', self::$setupPackageName);
 }
 protected function getFormVariables()
 {
     $formVariables = $this->defaultVariables;
     $styleVariables = $this->style->getVariables();
     foreach ($styleVariables as $name => $value) {
         $formVariables[$name] = $value;
     }
     // split unit from size
     foreach ($this->sizeVariables as $name) {
         if (!empty($styleVariables[$name]) && preg_match('/(%|em|pt|px)$/', $styleVariables[$name], $match)) {
             $formVariables[$name . '.unit'] = $match[1];
             $formVariables[$name] = StringUtil::substring($styleVariables[$name], 0, strlen($match[1]) * -1);
         }
     }
     // split/create values
     // page.header.background.image.alignment
     if ($styleVariables['page.header.background.image.alignment']) {
         $split = explode(' ', $styleVariables['page.header.background.image.alignment']);
         if (count($split) == 2) {
             $formVariables['page.header.background.image.alignment.horizontal'] = $split[0];
             $formVariables['page.header.background.image.alignment.vertical'] = $split[1];
         }
     }
     // page.header.background.image.repeat
     if ($styleVariables['page.header.background.image.repeat'] == 'repeat' || $styleVariables['page.header.background.image.repeat'] == 'repeat-x') {
         $formVariables['page.header.background.image.repeat.horizontal'] = 1;
     }
     if ($styleVariables['page.header.background.image.repeat'] == 'repeat' || $styleVariables['page.header.background.image.repeat'] == 'repeat-y') {
         $formVariables['page.header.background.image.repeat.vertical'] = 1;
     }
     // page.background.image.attachment
     if ($styleVariables['page.background.image.attachment'] == 'fixed') {
         $formVariables['page.background.image.fixed'] = 1;
     }
     // page.background.image.alignment
     if ($styleVariables['page.background.image.alignment']) {
         $split = explode(' ', $styleVariables['page.background.image.alignment']);
         if (count($split) == 2) {
             $formVariables['page.background.image.alignment.horizontal'] = $split[0];
             $formVariables['page.background.image.alignment.vertical'] = $split[1];
         }
     }
     // page.background.image.repeat
     if ($styleVariables['page.background.image.repeat'] == 'repeat' || $styleVariables['page.background.image.repeat'] == 'repeat-x') {
         $formVariables['page.background.image.repeat.horizontal'] = 1;
     }
     if ($styleVariables['page.background.image.repeat'] == 'repeat' || $styleVariables['page.background.image.repeat'] == 'repeat-y') {
         $formVariables['page.background.image.repeat.vertical'] = 1;
     }
     // page.width*
     if ($styleVariables['page.width.min'] || $styleVariables['page.width.max']) {
         $formVariables['page.width.mode'] = 'dynamic';
     } else {
         $formVariables['page.width.mode'] = 'static';
     }
     // global.title.hide / buttons.small.caption.hide / buttons.large.caption.hide / menu.main.caption.hide
     $formVariables['global.title.show'] = empty($styleVariables['global.title.hide']);
     $formVariables['buttons.small.caption.show'] = empty($styleVariables['buttons.small.caption.hide']);
     $formVariables['buttons.large.caption.show'] = empty($styleVariables['buttons.large.caption.hide']);
     $formVariables['menu.main.caption.show'] = empty($styleVariables['menu.main.caption.hide']);
     // additional css
     if (!empty($styleVariables['user.additional.style.input1.use'])) {
         $formVariables['user.additional.style.input1'] = $styleVariables['user.additional.style.input1.use'];
         $formVariables['user.additional.style.input1.use'] = 1;
     } else {
         $formVariables['user.additional.style.input1.use'] = 0;
     }
     if (!empty($styleVariables['user.additional.style.input2.use'])) {
         $formVariables['user.additional.style.input2'] = $styleVariables['user.additional.style.input2.use'];
         $formVariables['user.additional.style.input2.use'] = 1;
     } else {
         $formVariables['user.additional.style.input2.use'] = 0;
     }
     // IE fixes
     if (!empty($styleVariables['user.MSIEFixes.IE6.use'])) {
         $formVariables['user.MSIEFixes.IE6'] = $styleVariables['user.MSIEFixes.IE6.use'];
         $formVariables['user.MSIEFixes.IE6.use'] = 1;
     } else {
         $formVariables['user.MSIEFixes.IE6.use'] = 0;
     }
     if (!empty($styleVariables['user.MSIEFixes.IE7.use'])) {
         $formVariables['user.MSIEFixes.IE7'] = $styleVariables['user.MSIEFixes.IE7.use'];
         $formVariables['user.MSIEFixes.IE7.use'] = 1;
     } else {
         $formVariables['user.MSIEFixes.IE7.use'] = 0;
     }
     if (!empty($styleVariables['user.MSIEFixes.IE8.use'])) {
         $formVariables['user.MSIEFixes.IE8'] = $styleVariables['user.MSIEFixes.IE8.use'];
         $formVariables['user.MSIEFixes.IE8.use'] = 1;
     } else {
         $formVariables['user.MSIEFixes.IE8.use'] = 0;
     }
     // font styles
     // global.title.font.style
     if ($styleVariables['global.title.font.weight'] == 'bold' && $styleVariables['global.title.font.style'] == 'italic') {
         $formVariables['global.title.font.style'] = 'bold italic';
     } else {
         if ($styleVariables['global.title.font.weight'] == 'bold') {
             $formVariables['global.title.font.style'] = 'bold';
         }
     }
     // page.title.font.style
     if ($styleVariables['page.title.font.weight'] == 'bold' && $styleVariables['page.title.font.style'] == 'italic') {
         $formVariables['page.title.font.style'] = 'bold italic';
     } else {
         if ($styleVariables['page.title.font.weight'] == 'bold') {
             $formVariables['page.title.font.style'] = 'bold';
         }
     }
     // menu.main.bar.show
     if (!isset($styleVariables['menu.main.bar.hide']) || $styleVariables['menu.main.bar.hide'] != 'transparent') {
         $formVariables['menu.main.bar.hide'] = 0;
     } else {
         $formVariables['menu.main.bar.hide'] = 1;
     }
     if (!isset($styleVariables['menu.main.bar.divider.show']) || $styleVariables['menu.main.bar.divider.show'] != '0') {
         $formVariables['menu.main.bar.divider.show'] = 1;
     } else {
         $formVariables['menu.main.bar.divider.show'] = 0;
     }
     // main menu alignment
     switch ($styleVariables['menu.main.position']) {
         case 'text-align:center;margin:0 auto':
             $formVariables['menu.main.position'] = 'center';
             break;
         case 'text-align:right;margin:0 0 0 auto':
             $formVariables['menu.main.position'] = 'right';
             break;
         default:
             $formVariables['menu.main.position'] = 'left';
     }
     // use variables
     foreach ($this->useVariables as $name => $variables) {
         foreach ($variables as $variable) {
             if ($formVariables[$variable]) {
                 $formVariables[$name] = 1;
                 break;
             }
         }
     }
     // format images
     foreach ($this->images as $image) {
         if (!empty($formVariables[$image])) {
             $isBackgroundImage = strstr($image, 'background') ? true : false;
             // remove url()
             if ($isBackgroundImage) {
                 $formVariables[$image] = preg_replace('/^url\\("?(.*?)"?\\)$/', '\\1', $formVariables[$image]);
             }
             // format path
             if (StringUtil::indexOf($formVariables[$image], ($isBackgroundImage ? '../' : '') . $formVariables['global.images.location']) === 0) {
                 $formVariables[$image] = StringUtil::substring($formVariables[$image], StringUtil::length(($isBackgroundImage ? '../' : '') . $formVariables['global.images.location']));
             }
         }
     }
     return $formVariables;
 }
 /**
  * Gets the redirect url.
  */
 protected function checkURL()
 {
     if (empty($this->url) || StringUtil::indexOf($this->url, 'index.php?form=UserLogin') !== false || StringUtil::indexOf($this->url, 'index.php?page=Register') !== false) {
         $this->url = 'index.php' . SID_ARG_1ST;
     } else {
         if (SID_ARG_1ST != '' && !preg_match('/(?:&|\\?)s=[a-z0-9]{40}/', $this->url)) {
             if (StringUtil::indexOf($this->url, '?') !== false) {
                 $this->url .= SID_ARG_2ND_NOT_ENCODED;
             } else {
                 $this->url .= SID_ARG_1ST;
             }
         }
     }
 }
 /**
  * Process configured dates with plaintext names, dashed ranges and slashed intervals.
  * 
  * @param	array		$cronjobsCache
  */
 protected function processConfiguredDates($cronjobsCache = array())
 {
     // get arrays containing the configured dates from our database (or, respectively, the cache).
     $this->cronjobsDataRaw['startMinute'] = explode(',', $cronjobsCache['startMinute']);
     $this->cronjobsDataRaw['startHour'] = explode(',', $cronjobsCache['startHour']);
     $this->cronjobsDataRaw['startDom'] = explode(',', $cronjobsCache['startDom']);
     $this->cronjobsDataRaw['startMonth'] = explode(',', $cronjobsCache['startMonth']);
     $this->cronjobsDataRaw['startDow'] = explode(',', $cronjobsCache['startDow']);
     // process plaintext month and day of week values.
     foreach ($this->cronjobsDataRaw as $element => $datesRaw) {
         foreach ($datesRaw as $position => $dateRaw) {
             switch ($element) {
                 // months.
                 case 'startMonth':
                     $datesPlain = array('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec');
                     break;
                     // days of week.
                 // days of week.
                 case 'startDow':
                     // for us, the week begins on sunday because date() wants us to think that way.
                     $datesPlain = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
                     break;
                     // nothing to do for the others.
                 // nothing to do for the others.
                 default:
                     break;
             }
             // if $dateRaw is a time range expressed with a dash, a special handling is needed.
             if (StringUtil::indexOf($dateRaw, '-')) {
                 // dismantle the range into an array.
                 $range = explode('-', $dateRaw);
                 // investigate the new array.
                 foreach ($range as $key => $value) {
                     $slashPos = StringUtil::indexOf($value, '/');
                     if (StringUtil::length($value) == 3 && $slashPos === false) {
                         // this is a plaintext name, so convert this into a number.
                         $datePlain = StringUtil::toLowerCase($value);
                         $dateNum = array_search($datePlain, $datesPlain);
                         // put the converted value back to the array.
                         if ($dateNum !== false) {
                             $range[$key] = $dateNum;
                         }
                     } else {
                         if ($slashPos !== false) {
                             // this value additionally contains a slashed interval,
                             // so once again part this value.
                             $interval = explode('/', $value);
                             if (StringUtil::length($interval['0']) == 3) {
                                 // this is a plaintext name, so convert this into a number.
                                 $datePlain = StringUtil::toLowerCase($interval['0']);
                                 $dateNum = array_search($datePlain, $datesPlain);
                                 if ($dateNum !== false) {
                                     $range[$key] = $dateNum;
                                 }
                             } else {
                                 $range[$key] = $interval['0'];
                             }
                             $range[$key + 1] = $interval['1'];
                         }
                     }
                 }
                 // reassemble array.
                 foreach ($range as $key => $digit) {
                     $range[$key] = intval($digit);
                 }
                 $newPos = array_search($dateRaw, $this->cronjobsDataRaw[$element]);
                 $this->cronjobsDataRaw[$element][$newPos] = $range;
                 $this->getDashedRange($element, $newPos);
             } else {
                 // this is no range.
                 $slashPos = StringUtil::indexOf($dateRaw, '/');
                 if (StringUtil::length($dateRaw) == 3 && $slashPos === false) {
                     // this is a plaintext name, so convert this into a number.
                     $datePlain = StringUtil::toLowerCase($dateRaw);
                     $dateNum = array_search($datePlain, $datesPlain);
                     // put the converted value back to the original array.
                     if ($dateNum !== false) {
                         $this->cronjobsDataRaw[$element][$position] = $dateNum;
                     }
                 } else {
                     if ($slashPos !== false) {
                         // this value additionally contains a slashed interval,
                         // so once again part this value.
                         $interval = explode('/', $dateRaw);
                         // put parted value back to array.
                         unset($this->cronjobsDataRaw[$element][$position]);
                         $this->cronjobsDataRaw[$element][$position][] = $interval['0'];
                         $this->cronjobsDataRaw[$element][$position][] = $interval['1'];
                         // break down slashed interval.
                         $this->getSlashedInterval($element, $position);
                     }
                 }
             }
         }
     }
 }
 /**
  * Searches in templates.
  * 
  * @param	string		$search		search query
  * @param	string		$replace
  * @param	array		$templateIDs
  * @param	boolean		$invertTemplates
  * @param	boolean		$useRegex
  * @param	boolean		$caseSensitive
  * @param	boolean		$invertSearch
  * @return	array		results 
  */
 public static function search($search, $replace = null, $templateIDs = null, $invertTemplates = 0, $useRegex = 0, $caseSensitive = 0, $invertSearch = 0)
 {
     // get available template ids
     $results = array();
     $availableTemplateIDs = array();
     $sql = "SELECT\t\ttemplate.templateName, template.templateID, template.templatePackID, template.packageID\n\t\t\tFROM\t\twcf" . WCF_N . "_template template,\n\t\t\t\t\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tWHERE \t\ttemplate.packageID = package_dependency.dependency\n\t\t\t\t\tAND package_dependency.packageID = " . PACKAGE_ID . "\n\t\t\t\t\t" . ($replace !== null ? "AND template.templatePackID <> 0" : "") . "\n\t\t\tORDER BY\tpackage_dependency.priority";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if (!isset($availableTemplateIDs[$row['templateName'] . '-' . $row['templatePackID']]) || PACKAGE_ID == $row['packageID']) {
             $availableTemplateIDs[$row['templateName'] . '-' . $row['templatePackID']] = $row['templateID'];
         }
     }
     // get templates
     if (!count($availableTemplateIDs)) {
         return $results;
     }
     $sql = "SELECT\t\ttemplate.*, pack.templatePackFolderName, package.packageDir\n\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_template_pack pack\n\t\t\tON\t\t(pack.templatePackID = template.templatePackID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = template.packageID)\n\t\t\tWHERE\t\ttemplate.templateID IN (" . implode(',', $availableTemplateIDs) . ")\n\t\t\t\t\t" . ($templateIDs != null ? "AND template.templateID " . ($invertTemplates ? "NOT " : "") . "IN (" . implode(',', $templateIDs) . ")" : "") . "\n\t\t\tORDER BY\ttemplateName";
     $result = WCF::getDB()->sendQuery($sql);
     unset($availableTemplateIDs);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $template = new TemplateEditor(null, $row);
         if ($replace === null) {
             // search
             if ($useRegex) {
                 $matches = intval(preg_match('/' . $search . '/s' . (!$caseSensitive ? 'i' : ''), $template->getSource())) !== 0;
             } else {
                 if ($caseSensitive) {
                     $matches = StringUtil::indexOf($template->getSource(), $search) !== false;
                 } else {
                     $matches = StringUtil::indexOfIgnoreCase($template->getSource(), $search) !== false;
                 }
             }
             if ($matches && !$invertSearch || !$matches && $invertSearch) {
                 $results[] = $row;
             }
         } else {
             // search and replace
             $matches = 0;
             if ($useRegex) {
                 $newSource = preg_replace('/' . $search . '/s' . (!$caseSensitive ? 'i' : ''), $replace, $template->getSource(), -1, $matches);
             } else {
                 if ($caseSensitive) {
                     $newSource = StringUtil::replace($search, $replace, $template->getSource(), $matches);
                 } else {
                     $newSource = StringUtil::replaceIgnoreCase($search, $replace, $template->getSource(), $matches);
                 }
             }
             if ($matches > 0) {
                 $template->setSource($newSource);
                 $row['matches'] = $matches;
                 $results[] = $row;
             }
         }
     }
     return $results;
 }
 protected function replaceWcfNumber($wcfNumber)
 {
     $wcfTables = WCF::getDB()->getTableNames();
     /* Test missing tables
        $wcfTables[] = 'wcf1_test_table1';
        $wcfTables[] = 'wcf1_test_table2';
        $wcfTables[] = 'wcf1_test_table3';
        */
     foreach ($wcfTables as $key => $table) {
         if (StringUtil::indexOf($table, 'wcf' . WCF_N . '_') === false) {
             unset($wcfTables[$key]);
         } else {
             $wcfTables[$key] = StringUtil::replace('wcf' . WCF_N . '_', 'wcf' . $wcfNumber . '_', $table);
         }
     }
     return $wcfTables;
 }
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     if ($this->avatarID) {
         if ($this->avatarID == -1) {
             if (empty($this->gravatar)) {
                 // check permission
                 WCF::getUser()->checkPermission('user.profile.avatar.canUploadAvatar');
                 // upload or download avatar
                 if ($this->avatarUpload && $this->avatarUpload['error'] != 4) {
                     if ($this->avatarUpload['error'] != 0) {
                         throw new UserInputException('avatarUpload', 'uploadFailed');
                     }
                     $this->avatarID = AvatarEditor::create($this->avatarUpload['tmp_name'], $this->avatarUpload['name'], 'avatarUpload', WCF::getUser()->userID);
                 } else {
                     if ($this->avatarURL != 'http://') {
                         if (StringUtil::indexOf($this->avatarURL, 'http://') !== 0) {
                             throw new UserInputException('avatarURL', 'downloadFailed');
                         }
                         try {
                             $tmpName = FileUtil::downloadFileFromHttp($this->avatarURL, 'avatar');
                         } catch (SystemException $e) {
                             throw new UserInputException('avatarURL', 'downloadFailed');
                         }
                         $this->avatarID = AvatarEditor::create($tmpName, $this->avatarURL, 'avatarURL', WCF::getUser()->userID);
                     } else {
                         throw new UserInputException('avatarUpload');
                     }
                 }
             } else {
                 $this->avatarID = 0;
             }
         } else {
             // check permission
             WCF::getUser()->checkPermission('user.profile.avatar.canUseDefaultAvatar');
             // use a default avatar
             $avatar = new AvatarEditor($this->avatarID);
             if (!$avatar->avatarID || $avatar->userID || $avatar->groupID && !in_array($avatar->groupID, WCF::getUser()->getGroupIDs()) || $avatar->neededPoints > WCF::getUser()->activityPoints) {
                 throw new UserInputException('availableAvatars', 'invalid');
             }
             // check category permissions
             if ($avatar->avatarCategoryID) {
                 $category = new AvatarCategory($avatar->avatarCategoryID);
                 if ($category->groupID && !in_array($category->groupID, WCF::getUser()->getGroupIDs()) || $category->neededPoints > WCF::getUser()->activityPoints) {
                     throw new UserInputException('availableAvatars', 'invalid');
                 }
             }
         }
     }
 }
 /**
  * Looks ahead in the word list.
  * 
  * @param	integer		$index
  * @param	string		$search
  * @return	mixed
  */
 protected static function lookAhead($index, $search)
 {
     if (isset(self::$words[$index])) {
         if (StringUtil::indexOf(self::$words[$index], $search) === 0) {
             return $index;
         } else {
             if (StringUtil::indexOf($search, self::$words[$index]) === 0) {
                 return self::lookAhead($index + 1, StringUtil::substring($search, StringUtil::length(self::$words[$index])));
             }
         }
     }
     return false;
 }