// 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;
}
}
<?php
namespace wcf\system\package\plugin;
+use wcf\data\package\Package;
use wcf\system\exception\SystemException;
use wcf\system\WCF;
$data['name'] = $element->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']);
}
}
*/
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
*/
$url .= '?' . $_SERVER['QUERY_STRING'];
}
- HeaderUtil::redirect($url, true);
+ HeaderUtil::redirect($url, true, false);
exit;
}
}
}
$redirectURL = LinkHandler::getInstance()->getLink($routeData['controller'], $routeData);
- HeaderUtil::redirect($redirectURL, true);
+ HeaderUtil::redirect($redirectURL, true, false);
exit;
}
}
else if (!empty($data['redirect'])) {
// force a redirect
- HeaderUtil::redirect($data['redirect'], true);
+ HeaderUtil::redirect($data['redirect'], true, false);
}
// copy route data
}
/**
- * 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);
}