2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* This controller handles what happens when you visit the root URL.
|
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage control
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class RootURLController extends Controller {
|
|
|
|
protected static $is_at_root = false;
|
2008-08-09 05:29:30 +02:00
|
|
|
|
|
|
|
public function handleRequest($request) {
|
2007-07-19 12:40:28 +02:00
|
|
|
self::$is_at_root = true;
|
2007-08-17 05:09:46 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
$controller = new ModelAsController();
|
2008-09-16 17:53:05 +02:00
|
|
|
$controller->pushCurrent();
|
2007-08-18 01:11:43 +02:00
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
$request = new HTTPRequest("GET", self::get_homepage_urlsegment().'/', $request->getVars(), $request->postVars());
|
|
|
|
$request->match('$URLSegment//$Action');
|
|
|
|
|
2008-09-19 07:54:07 +02:00
|
|
|
$result = $controller->handleRequest($request);
|
|
|
|
$controller->popCurrent();
|
|
|
|
return $result;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-08-09 05:29:30 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Return the URL segment for the current HTTP_HOST value
|
|
|
|
*/
|
|
|
|
static function get_homepage_urlsegment() {
|
|
|
|
$host = $_SERVER['HTTP_HOST'];
|
|
|
|
$host = str_replace('www.','',$host);
|
2008-03-19 21:38:41 +01:00
|
|
|
$SQL_host = str_replace('.','\\.',Convert::raw2sql($host));
|
|
|
|
$homePageOBJ = DataObject::get_one("SiteTree", "HomepageForDomain REGEXP '(,|^) *$SQL_host *(,|\$)'");
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
if($homePageOBJ) {
|
|
|
|
return $homePageOBJ->URLSegment;
|
|
|
|
} else {
|
|
|
|
return 'home';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|