From: Marcel Werk Date: Thu, 14 Jul 2016 12:13:43 +0000 (+0200) Subject: Fixed redirect status codes X-Git-Tag: 3.0.0_Beta_1~1155 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b372ca966151915c149fb23f2a25e4680c7d1e0b;p=GitHub%2FWoltLab%2FWCF.git Fixed redirect status codes --- diff --git a/wcfsetup/install/files/lib/page/AbstractPage.class.php b/wcfsetup/install/files/lib/page/AbstractPage.class.php index 4eb1f0d31f..f6a2948479 100644 --- a/wcfsetup/install/files/lib/page/AbstractPage.class.php +++ b/wcfsetup/install/files/lib/page/AbstractPage.class.php @@ -255,8 +255,7 @@ abstract class AbstractPage implements IPage { // force a permanent redirect as recommended by Google // https://support.google.com/webmasters/answer/6033086?hl=en#a_note_about_redirects - @header('HTTP/1.0 301 Moved Permanently'); - HeaderUtil::redirect($redirectURL, false); + HeaderUtil::redirect($redirectURL, true, false); exit; } } diff --git a/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php index 8b60ba775a..3c34e482fd 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php @@ -1,5 +1,6 @@ getAttribute('name'); - if (!preg_match("/^[\w-\.]+$/", $data['name'])) { - $matches = []; - preg_match_all("/(\W)/", $data['name'], $matches); - throw new SystemException("The option '".$data['name']."' has at least one non-alphanumeric character (underscore is permitted): (".implode("), ( ", $matches[1]).")."); - } - + $this->validateOption($data); $this->saveOption($data, $data['categoryname']); } } @@ -275,6 +271,31 @@ abstract class AbstractOptionPackageInstallationPlugin extends AbstractXMLPackag */ abstract protected function saveOption($option, $categoryName, $existingOptionID = 0); + /** + * @inheritDoc + */ + protected function validateOption(array $data) { + if (!preg_match("/^[\w-\.]+$/", $data['name'])) { + $matches = []; + preg_match_all("/(\W)/", $data['name'], $matches); + throw new SystemException("The option '".$data['name']."' has at least one non-alphanumeric character (underscore is permitted): (".implode("), ( ", $matches[1]).")."); + } + + // check if option already exists + $sql = "SELECT * + FROM wcf".WCF_N."_".$this->tableName." + WHERE optionName = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([ + $data['name'] + ]); + $row = $statement->fetchArray(); + if ($row && $row['packageID'] != $this->installation->getPackageID()) { + $package = new Package($row['packageID']); + throw new SystemException($this->tableName . " '" . $data['name'] . "' is already provided by '" . $package . "' ('" . $package->package . "')."); + } + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index e3abf75b2d..f844698955 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -123,7 +123,7 @@ class RequestHandler extends SingletonFactory { $url .= '?' . $_SERVER['QUERY_STRING']; } - HeaderUtil::redirect($url, true); + HeaderUtil::redirect($url, true, false); exit; } } @@ -197,7 +197,7 @@ class RequestHandler extends SingletonFactory { } $redirectURL = LinkHandler::getInstance()->getLink($routeData['controller'], $routeData); - HeaderUtil::redirect($redirectURL, true); + HeaderUtil::redirect($redirectURL, true, false); exit; } @@ -220,7 +220,7 @@ class RequestHandler extends SingletonFactory { } else if (!empty($data['redirect'])) { // force a redirect - HeaderUtil::redirect($data['redirect'], true); + HeaderUtil::redirect($data['redirect'], true, false); } // copy route data diff --git a/wcfsetup/install/files/lib/util/HeaderUtil.class.php b/wcfsetup/install/files/lib/util/HeaderUtil.class.php index e576f7dff5..ab3c53c286 100644 --- a/wcfsetup/install/files/lib/util/HeaderUtil.class.php +++ b/wcfsetup/install/files/lib/util/HeaderUtil.class.php @@ -141,14 +141,18 @@ final class HeaderUtil { } /** - * Redirects the user agent. + * Redirects the user agent to given location. * * @param string $location * @param boolean $sendStatusCode + * @param boolean $temporaryRedirect */ - public static function redirect($location, $sendStatusCode = false) { - //if ($sendStatusCode) @header('HTTP/1.0 301 Moved Permanently'); - if ($sendStatusCode) @header('HTTP/1.1 307 Temporary Redirect'); + public static function redirect($location, $sendStatusCode = false, $temporaryRedirect = true) { + if ($sendStatusCode) { + if ($temporaryRedirect) @header('HTTP/1.1 307 Temporary Redirect'); + else @header('HTTP/1.0 301 Moved Permanently'); + } + header('Location: '.$location); }