silverstripe-framework/core/control/RootURLController.php
Ingo Schommer 7ad7f8dcf2 ENHANCEMENT Adjusted SearchForm, Debug, ErrorPage, SiteTree to using locales instead of lang codes
API CHANGE Changed Translatable datamodel to use locales ("en_US") instead of lang values ("en).
API CHANGE Changed Translatable::$default_lang to $default_locale, Translatable::$reading_lang to $reading_locale
API CHANGE Using "locale" instead of "lang" in Translatable::choose_site_lang() to auto-detect language from cookies or GET parameters
API CHANGE Deprecated Translatable::is_default_lang(), set_default_lang(), get_default_lang(), current_lang(), set_reading_lang(), get_reading_lang(), get_by_lang(), get_one_by_lang()
API CHANGE Removed Translatable::get_original() - with the new "translation groups" concept there no longer is an original for a translation
BUGFIX Updated MigrateTranslatableTask to new Locale based datamodel

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@73468 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-03-20 08:47:06 +00:00

94 lines
2.6 KiB
PHP
Executable File

<?php
/**
* This controller handles what happens when you visit the root URL.
*
* @package sapphire
* @subpackage control
*/
class RootURLController extends Controller {
/**
* @var boolean $is_at_root
*/
protected static $is_at_root = false;
/**
* @var string $default_homepage_urlsegment Defines which URLSegment value on a {@link SiteTree} object
* is regarded as the correct "homepage" if the requested URI doesn't contain
* an explicit segment. E.g. http://mysite.com should show http://mysite.com/home.
*/
protected static $default_homepage_urlsegment = 'home';
public function init() {
Director::set_site_mode('site');
parent::init();
}
public function handleRequest($request) {
self::$is_at_root = true;
$this->pushCurrent();
$this->init();
// If the basic database hasn't been created, then build it.
if(!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new HTTPResponse();
$this->redirect("dev/build?returnURL=");
return $this->response;
}
$controller = new ModelAsController();
$request = new HTTPRequest("GET", self::get_homepage_urlsegment().'/', $request->getVars(), $request->postVars());
$request->match('$URLSegment//$Action', true);
$result = $controller->handleRequest($request);
$this->popCurrent();
return $result;
}
/**
* Return the URL segment for the current HTTP_HOST value
*
* @return string
*/
static function get_homepage_urlsegment() {
$urlSegment = '';
// @todo Temporarily restricted to MySQL database while testing db abstraction
if(DB::getConn() instanceof MySQLDatabase) {
$host = $_SERVER['HTTP_HOST'];
$host = str_replace('www.','',$host);
$SQL_host = str_replace('.','\\.',Convert::raw2sql($host));
$homePageOBJ = DataObject::get_one("SiteTree", "HomepageForDomain REGEXP '(,|^) *$SQL_host *(,|\$)'");
} else {
$homePageOBJ = null;
}
if($homePageOBJ) {
$urlSegment = $homePageOBJ->URLSegment;
} elseif(Translatable::is_enabled()) {
$urlSegment = Translatable::get_homepage_urlsegment_by_language(Translatable::current_locale());
}
return ($urlSegment) ? $urlSegment : self::get_default_homepage_urlsegment();
}
/**
* Returns true if we're currently on the root page and should be redirecting to the root
* Doesn't take into account actions, post vars, or get vars
*/
static function should_be_on_root(SiteTree $currentPage) {
if(!self::$is_at_root) return self::get_homepage_urlsegment() == $currentPage->URLSegment;
else return false;
}
/**
* @return string
*/
static function get_default_homepage_urlsegment() {
return self::$default_homepage_urlsegment;
}
}
?>