2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage control
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class RootURLController extends Controller {
|
2009-02-22 22:30:41 +01:00
|
|
|
|
|
|
|
/**
|
2009-10-11 02:07:17 +02:00
|
|
|
* @var bool
|
2009-02-22 22:30:41 +01:00
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
protected static $is_at_root = false;
|
2008-08-09 05:29:30 +02:00
|
|
|
|
2009-02-22 22:30:41 +01:00
|
|
|
/**
|
2009-10-11 02:07:17 +02:00
|
|
|
* @var string
|
2009-02-22 22:30:41 +01:00
|
|
|
*/
|
2009-10-11 02:07:17 +02:00
|
|
|
protected static $default_homepage_link = 'home';
|
2009-02-22 22:30:41 +01:00
|
|
|
|
2009-10-11 02:07:22 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected static $cached_homepage_link;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2009-10-11 02:07:17 +02:00
|
|
|
* Get the full form (e.g. /home/) relative link to the home page for the current HTTP_HOST value. Note that the
|
|
|
|
* link is trimmed of leading and trailing slashes before returning to ensure consistency.
|
|
|
|
*
|
2009-02-22 22:30:41 +01:00
|
|
|
* @return string
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2009-10-11 02:07:17 +02:00
|
|
|
public static function get_homepage_link() {
|
2009-10-11 02:07:22 +02:00
|
|
|
if(!self::$cached_homepage_link) {
|
|
|
|
$host = str_replace('www.', null, $_SERVER['HTTP_HOST']);
|
|
|
|
$SQL_host = Convert::raw2sql($host);
|
|
|
|
|
2010-12-01 21:36:38 +01:00
|
|
|
$query = new SQLQuery (array('"ID"', '"HomepageForDomain"'), '"SiteTree"', "(\"HomepageForDomain\" LIKE '%$SQL_host%')", "\"Sort\"", null, null);
|
|
|
|
singleton("SiteTree")->getExtensionInstance('Versioned')->augmentSQL($query);
|
|
|
|
$candidates = $query->execute()->map();
|
|
|
|
|
|
|
|
if($candidates) foreach($candidates as $id => $domainString) {
|
|
|
|
if(preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $domainString)) {
|
|
|
|
self::$cached_homepage_link = trim(DataObject::get_by_id('SiteTree', $id)->RelativeLink(true), '/');
|
|
|
|
break;
|
2009-10-11 02:07:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!self::$cached_homepage_link) {
|
|
|
|
if (
|
|
|
|
Object::has_extension('SiteTree', 'Translatable')
|
|
|
|
&& $link = Translatable::get_homepage_link_by_locale(Translatable::get_current_locale())
|
|
|
|
) {
|
|
|
|
self::$cached_homepage_link = $link;
|
|
|
|
} else {
|
|
|
|
self::$cached_homepage_link = self::get_default_homepage_link();
|
|
|
|
}
|
2009-06-16 05:15:01 +02:00
|
|
|
}
|
2008-11-24 00:21:29 +01:00
|
|
|
}
|
2009-04-01 18:35:32 +02:00
|
|
|
|
2009-10-11 02:07:22 +02:00
|
|
|
return self::$cached_homepage_link;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-10-11 02:07:17 +02:00
|
|
|
* Gets the link that denotes the homepage if there is not one explicitly defined for this HTTP_HOST value.
|
2009-04-28 01:08:39 +02:00
|
|
|
*
|
2009-10-11 02:07:17 +02:00
|
|
|
* @return string
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2009-10-11 02:07:17 +02:00
|
|
|
public static function get_default_homepage_link() {
|
|
|
|
return self::$default_homepage_link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns TRUE if a request to a certain page should be redirected to the site root (i.e. if the page acts as the
|
|
|
|
* home page).
|
|
|
|
*
|
|
|
|
* @param SiteTree $page
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function should_be_on_root(SiteTree $page) {
|
|
|
|
if(!self::$is_at_root && self::get_homepage_link() == trim($page->RelativeLink(true), '/')) {
|
|
|
|
return !(
|
|
|
|
$page->hasExtension('Translatable') && $page->Locale && $page->Locale != Translatable::default_locale()
|
|
|
|
);
|
|
|
|
}
|
2009-08-05 07:30:04 +02:00
|
|
|
|
2009-10-11 02:07:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-11 02:07:22 +02:00
|
|
|
/**
|
|
|
|
* Resets the cached homepage link value - useful for testing.
|
|
|
|
*/
|
|
|
|
public static function reset() {
|
|
|
|
self::$cached_homepage_link = null;
|
|
|
|
}
|
|
|
|
|
2009-02-22 22:30:41 +01:00
|
|
|
/**
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* @param SS_HTTPRequest $request
|
|
|
|
* @return SS_HTTPResponse
|
2009-02-22 22:30:41 +01:00
|
|
|
*/
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
public function handleRequest(SS_HTTPRequest $request) {
|
2009-10-11 02:07:17 +02:00
|
|
|
self::$is_at_root = true;
|
|
|
|
|
|
|
|
$this->pushCurrent();
|
|
|
|
$this->init();
|
|
|
|
|
|
|
|
if(!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$this->response = new SS_HTTPResponse();
|
2009-11-27 02:26:13 +01:00
|
|
|
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
|
2009-10-11 02:07:17 +02:00
|
|
|
return $this->response;
|
|
|
|
}
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$request = new SS_HTTPRequest (
|
2009-10-11 02:07:17 +02:00
|
|
|
$request->httpMethod(), self::get_homepage_link() . '/', $request->getVars(), $request->postVars()
|
|
|
|
);
|
|
|
|
$request->match('$URLSegment//$Action', true);
|
|
|
|
|
|
|
|
$controller = new ModelAsController();
|
|
|
|
$result = $controller->handleRequest($request);
|
|
|
|
|
|
|
|
$this->popCurrent();
|
|
|
|
return $result;
|
2009-02-22 22:30:41 +01:00
|
|
|
}
|
2009-10-11 02:07:17 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|