dataRecord. Any unrecognised method calls, for example, Title()
* and Content(), will be passed along to the data record,
*
* Subclasses of ContentController are generally instantiated by ModelAsController; this will create
* a controller based on the URLSegment action variable, by looking in the SiteTree table.
*/
class ContentController extends Controller {
protected $dataRecord;
/**
* The ContentController will take the URLSegment parameter from the URL and use that to look
* up a SiteTree record.
*/
public function __construct($dataRecord) {
$this->dataRecord = $dataRecord;
$this->failover = $this->dataRecord;
parent::__construct();
}
public function Link($action = null) {
return Director::baseURL() . $this->RelativeLink($action);
}
public function RelativeLink($action = null) {
if($this->URLSegment){
if($action == "index") $action = "";
// '&' in a URL is apparently naughty
$action = preg_replace('/&/', '&', $action);
return $this->URLSegment . "/$action";
}else{
user_error("ContentController::RelativeLink() No URLSegment given on a '$this->class' object. Perhaps you should overload it?", E_USER_WARNING);
}
/** TODO : junk from CVS ?? **/
//if($action == "index") $action = "";
// '&' in a URL is apparently naughty
// $action = preg_replace('/&/', '&', $action);
//return $this->URLSegment . "/$action";
}
//----------------------------------------------------------------------------------//
// These flexible data methods remove the need for custom code to do simple stuff
/*
* Return the children of the given page.
* $parentRef can be a page number or a URLSegment
*/
public function ChildrenOf($parentRef) {
$SQL_parentRef = Convert::raw2sql($parentRef);
$parent = DataObject::get_one('SiteTree', "URLSegment = '$SQL_parentRef'");
if(!$parent && is_numeric($parentRef)) $parent = DataObject::get_by_id('SiteTree', $SQL_parentRef);
if($parent) {
return $parent->Children();
} else {
user_error("Error running <% control ChildrenOf($parentRef) %>: page '$parentRef' couldn't be found", E_USER_WARNING);
}
}
public function Page($url) {
$SQL_url = Convert::raw2sql($url);
return DataObject::get_one('SiteTree', "URLSegment = '$SQL_url'");
}
public function init() {
parent::init();
// If we've accessed the homepage as /home/, then we should redirect to /.
if($this->dataRecord && RootURLController::should_be_on_root($this->dataRecord) && !$this->urlParams['Action'] && !$_POST && !$_FILES) {
$getVars = $_GET;
unset($getVars['url']);
if($getVars) $url = "./?" . http_build_query($getVars);
else $url = "./";
Director::redirect($url);
die();
}
Versioned::choose_site_stage();
Director::set_site_mode('site');
// Check permissions
if($this->dataRecord && !$this->dataRecord->can('View')) Security::permissionFailure($this);
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
}
/**
* Get the project name
*
* @return string
*/
function project() {
global $project;
return $project;
}
/**
* Returns the associated database record
*/
public function data() {
return $this->dataRecord;
}
/*--------------------------------------------------------------------------------*/
/**
* Returns a fixed navigation menu of the given level.
*/
public function getMenu($level) {
if($level == 1) {
$result = DataObject::get("SiteTree", "ShowInMenus = 1 AND ParentID = 0");
} else {
$parent = $this->data();
$stack = array($parent);
while($parent = $parent->Parent)
array_unshift($stack, $parent);
if(isset($stack[$level-2]))
$result = $stack[$level-2]->Children();
}
$visible = array();
// Remove all entries the can not be viewed by the current user
// We might need to create a show in menu permission
if($result) {
foreach($result as $page) {
if($page->can('view')) {
$visible[] = $page;
}
}
}
return new DataObjectSet($visible);
}
/**
* Returns the page in the current page stack of the given level.
* Level(1) will return the main menu item that we're currently inside, etc.
*/
public function Level($level) {
$parent = $this->data();
$stack = array($parent);
while($parent = $parent->Parent) {
array_unshift($stack, $parent);
}
return isset($stack[$level-1]) ? $stack[$level-1] : null;
}
public function Menu($level) {
return $this->getMenu($level);
}
public function Section2() {
return $this->Level(2)->URLSegment;
}
/**
* Returns the default log-in form.
*/
public function LoginForm() {
return Object::create('LoginForm', $this, "LoginForm");
}
public function SilverStripeNavigator() {
$member = Member::currentUser();
if(Director::isDev() || ($member && $member->isCMSUser())) {
Requirements::css('sapphire/css/SilverStripeNavigator.css');
Requirements::javascript('jsparty/behaviour.js');
// Requirements::javascript('jsparty/prototype.js');
Requirements::customScript(<< This website is a simplistic version of a SilverStripe 2 site. To extend this, please take a look at our new tutorials.
You can start editing your site's content by opening the CMS.
Email: $username
Password: $password
For security reasons you should now delete the install files, unless you are planning to reinstall later. The web server also now only needs write access to the "assets" folder, you can remove write access from all other folders.
Unable to delete installation files. Please delete the files below manually: