/**
  * 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;
 }
Example #2
0
 /**
  * Sets the target url, by default appends appropriate session id.
  * May be left empty to disable url functionality.
  * 
  * @param	string		$url
  * @param	boolean		$appendSession
  */
 public function setURL($url, $appendSession = false)
 {
     // append session id
     if ($appendSession) {
         if (StringUtil::indexOf($url, '?') === false) {
             $url .= SID_ARG_1ST;
         } else {
             $url .= SID_ARG_2ND_NOT_ENCODED;
         }
     }
     $this->url = $url;
 }
	/**
	 * @see	\Exception::__construct()
	 */
	public function __construct($fieldName, $errorMessage = 'empty', array $variables = array()) {
		$this->errorMessage = $errorMessage;
		if (StringUtil::indexOf($this->errorMessage, '.') === false) {
			$this->errorMessage = WCF::getLanguage()->get('wcf.global.form.error.'.$this->errorMessage);
		}
		else {
			$this->errorMessage = WCF::getLanguage()->getDynamicVariable($this->errorMessage, $variables);
		}
		
		$this->fieldName = $fieldName;
		$this->message = WCF::getLanguage()->getDynamicVariable('wcf.ajax.error.invalidParameter', array('fieldName' => $this->fieldName));
	}
Example #4
0
 /**
  * Parses a possible range of values including a step value.
  * 
  * @param	string		$value
  * @return	array
  */
 protected static function getRanges($value)
 {
     // this is a single value
     if (StringUtil::indexOf($value, '-') === false) {
         return array($value);
     }
     $step = 1;
     if (StringUtil::indexOf($value, '/') !== false) {
         $data = explode('/', $value);
         $step = $data[1];
         $value = $data[0];
     }
     $data = explode('-', $value);
     return self::calculateRange($data[0], $data[1], $step);
 }
Example #5
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);
	}
Example #6
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 #7
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 {
         HeaderUtil::redirect('index.php' . SID_ARG_1ST);
     }
     exit;
 }
Example #8
0
 /**
  * Handles request input variables.
  */
 public function handleRequest()
 {
     $variables = array();
     foreach ($_REQUEST as $key => $value) {
         if (StringUtil::indexOf($key, $this->getName() . '_') !== false) {
             $key = StringUtil::replace($this->getName() . '_', '', $key);
             $variables[$key] = $value;
         }
     }
     if (!empty($variables)) {
         foreach ($this->containers as $container) {
             $container->handleRequest($variables);
         }
     }
 }
Example #9
0
	/**
	 * 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		templateName, templateID, templateGroupID, packageID
			FROM		wcf".WCF_N."_template
					".($replace !== null ? "WHERE templateGroupID <> 0" : "");
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute();
		while ($row = $statement->fetchArray()) {
			if (!isset($availableTemplateIDs[$row['templateName'].'-'.$row['templateGroupID']]) || PACKAGE_ID == $row['packageID']) {
				$availableTemplateIDs[$row['templateName'].'-'.$row['templateGroupID']] = $row['templateID'];
			}
		}
		
		// get templates
		if (empty($availableTemplateIDs)) return $results;
		
		$conditions = new PreparedStatementConditionBuilder();
		$conditions->add("template.templateID IN (?)", array($availableTemplateIDs));
		if ($templateIDs !== null) $conditions->add("template.templateID ".($invertTemplates ? "NOT " : "")." IN (?)", array($templateIDs));
		
		$sql = "SELECT		template.*, group.templateGroupFolderName, package.packageDir
			FROM		wcf".WCF_N."_template template
			LEFT JOIN	wcf".WCF_N."_template_group group
			ON		(group.templateGroupID = template.templateGroupID)
			LEFT JOIN	wcf".WCF_N."_package package
			ON		(package.packageID = template.packageID)
			".$conditions."
			ORDER BY	templateName ASC";
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute($conditions->getParameters());
		unset($availableTemplateIDs);
		while ($row = $statement->fetchArray()) {
			$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;
	}
Example #10
0
	/**
	 * Checks the version number of the installed package against the "fromversion"
	 * number of the update.
	 * 
	 * The "fromversion" number may contain wildcards (asterisks) which means
	 * that the update covers the whole range of release numbers where the asterisk
	 * wildcards digits from 0 to 9.
	 * For example, if "fromversion" is "1.1.*" and this package updates to
	 * version 1.2.0, all releases from 1.1.0 to  1.1.9 may be updated using
	 * this package.
	 * 
	 * @param	string		$currentVersion
	 * @param	string		$fromVersion
	 * @return	boolean
	 */
	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;
	}
Example #11
0
 /**
  * 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.templateGroupID, template.packageID\n\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tON\t\t(package_dependency.dependency = template.packageID)\n\t\t\tWHERE \t\tpackage_dependency.packageID = ?\n\t\t\t\t\t" . ($replace !== null ? "AND template.templateGroupID <> 0" : "") . "\n\t\t\tORDER BY\tpackage_dependency.priority ASC";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array(PACKAGE_ID));
     while ($row = $statement->fetchArray()) {
         if (!isset($availableTemplateIDs[$row['templateName'] . '-' . $row['templateGroupID']]) || PACKAGE_ID == $row['packageID']) {
             $availableTemplateIDs[$row['templateName'] . '-' . $row['templateGroupID']] = $row['templateID'];
         }
     }
     // get templates
     if (!count($availableTemplateIDs)) {
         return $results;
     }
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("template.templateID IN (?)", array($availableTemplateIDs));
     if ($templateIDs !== null) {
         $conditions->add("template.templateID " . ($invertTemplates ? "NOT " : "") . " IN (?)", array($templateIDs));
     }
     $sql = "SELECT\t\ttemplate.*, group.templateGroupFolderName, package.packageDir\n\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_template_group group\n\t\t\tON\t\t(group.templateGroupID = template.templateGroupID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = template.packageID)\n\t\t\t" . $conditions . "\n\t\t\tORDER BY\ttemplateName ASC";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     unset($availableTemplateIDs);
     while ($row = $statement->fetchArray()) {
         $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;
 }
Example #12
0
 /**
  * Gets the package name of the first 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 . 'install/packages/' . $packageFile);
                     $archive->openArchive();
                     self::$setupPackageName = $archive->getLocalizedPackageInfo('packageName');
                     $archive->getTar()->close();
                     break;
                 } catch (SystemException $e) {
                 }
             }
         }
     }
     $tar->close();
     // assign package name
     WCF::getTPL()->assign(array('setupPackageName' => self::$setupPackageName));
 }
Example #13
0
	/**
	 * Returns a list of the enable options.
	 * 
	 * @return	array
	 */
	public function parseMultipleEnableOptions() {
		$result = array();
		if (!empty($this->enableOptions)) {
			$options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($this->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;
	}
Example #14
0
	/**
	 * Returns the URI of the current page.
	 *
	 * @return	string
	 */
	public static function getRequestURI() {
		// resolve path and query components
		$scriptName = $_SERVER['SCRIPT_NAME'];
		if (empty($_SERVER['PATH_INFO'])) {
			// bug fix if URL omits script name and path
			$scriptName = substr($scriptName, 0, strrpos($scriptName, '/'));
		}
		
		$path = str_replace('/index.php', '', str_replace($scriptName, '', $_SERVER['REQUEST_URI']));
		if (!StringUtil::isASCII($path) && !StringUtil::isUTF8($path)) {
			$path = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $path);
		}
		$path = FileUtil::removeLeadingSlash($path);
		$baseHref = self::getTPL()->get('baseHref');
		
		if (!empty($path) && StringUtil::indexOf($path, '?') !== 0) {
			$baseHref .= 'index.php/';
		}
		
		return $baseHref . $path;
	}
	/**
	 * 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;
	}
Example #16
0
 /**
  * Starts the extracting of the files.
  */
 protected function install()
 {
     $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.', $errors);
     }
     $this->logFiles($files);
     // close tar
     $tar->close();
 }