<?php
namespace wcf\system;
use wcf\system\cache\CacheHandler;
+use wcf\system\request\RouteHandler;
use wcf\system\session\ACPSessionFactory;
use wcf\system\session\SessionHandler;
use wcf\system\template\ACPTemplateEngine;
parent::assignDefaultTemplateVariables();
// base tag is determined on runtime
- $phpSelf = $_SERVER['PHP_SELF'];
- if (isset($_SERVER['PATH_INFO'])) {
- // strip path info
- $phpSelf = str_replace($_SERVER['PATH_INFO'], '', $phpSelf);
- }
- if (($pos = strpos($phpSelf, 'index.php')) !== false) {
- // strip index.php
- $phpSelf = substr($phpSelf, 0, $pos);
- }
-
- // get protocol and domain name
- $protocol = 'http://';
- if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' || $_SERVER['SERVER_PORT'] == 443) {
- $protocol = 'https://';
- }
- $phpSelf = $protocol . $_SERVER['HTTP_HOST'] . $phpSelf;
+ $host = RouteHandler::getHost();
+ $path = RouteHandler::getPath();
self::getTPL()->assign(array(
- 'baseHref' => $phpSelf,
+ 'baseHref' => $host . $path,
'quickAccessPackages' => $this->getQuickAccessPackages(),
//'timezone' => util\DateUtil::getTimezone()
));
use wcf\system\form\container;
use wcf\system\form\element;
use wcf\system\request\LinkHandler;
+use wcf\system\request\RouteHandler;
use wcf\system\WCF;
use wcf\util\FileUtil;
use wcf\util\HeaderUtil;
$this->package = null;
if ($package->standalone) {
- $domainPath = '';
- if (isset($_SERVER['PHP_SELF'])) {
- $domainPath = $_SERVER['PHP_SELF'];
- if (strpos($domainPath, '.php') !== false) {
- $domainPath = preg_replace('~index\.php$~', '', $domainPath);
- }
- }
+ $host = RouteHandler::getHost();
+ $path = RouteHandler::getPath(array('acp'));
// insert as application
ApplicationEditor::create(array(
- 'domainName' => (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : '',
- 'domainPath' => $domainPath,
+ 'domainName' => $host,
+ 'domainPath' => $path,
'packageID' => $package->packageID
));
}
namespace wcf\system\request;
use wcf\system\event\EventHandler;
use wcf\system\SingletonFactory;
+use wcf\util\FileUtil;
/**
* Handles routes for HTTP requests.
* @category Community Framework
*/
class RouteHandler extends SingletonFactory {
+ /**
+ * current host and protocol
+ * @var string
+ */
+ protected static $host = '';
+
+ /**
+ * current absolute path
+ * @var string
+ */
+ protected static $path = '';
+
/**
* router filter for ACP
* @var boolean
throw new SystemException("Unable to build route, no available route is satisfied.");
}
+
+ /**
+ * Returns protocol and domain name.
+ *
+ * @return string
+ */
+ public static function getHost() {
+ if (empty(self::$host)) {
+ // get protocol and domain name
+ $protocol = 'http://';
+ if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' || $_SERVER['SERVER_PORT'] == 443) {
+ $protocol = 'https://';
+ }
+
+ self::$host = $protocol . $_SERVER['HTTP_HOST'];
+ }
+
+ return self::$host;
+ }
+
+ /**
+ * Returns absolute domain path.
+ *
+ * @param array $removeComponents
+ * @return string
+ */
+ public static function getPath(array $removeComponents = array()) {
+ if (empty(self::$path)) {
+ self::$path = FileUtil::addTrailingSlash(dirname($_SERVER['SCRIPT_NAME']));
+ }
+
+ if (!empty($removeComponents)) {
+ $path = explode('/', self::$path);
+ foreach ($path as $index => $component) {
+ if (empty($path[$index])) {
+ unset($path[$index]);
+ }
+
+ if (in_array($component, $removeComponents)) {
+ unset($path[$index]);
+ }
+ }
+
+ return implode('/', $path) . '/';
+ }
+
+ return self::$path;
+ }
}