silverstripe-framework/core/model/RedirectorPage.php
Normann Lou 26b8f7dffe switch externals to trunk.
Inform-merge: from the changeset:
r32477: Merge 2.0-inform from trunk previously
r32478: Merge 2.0-inform from trunk previously
r32481: merge 2.0infom with lastes chunk 
r32483: merge 2.0infom with lastes chunk 
r33526: Final styling of all forms and combined communication form add/alter javascript for height adjustment of First / Second block 
r33580: styling for combined form communication in myinfom pages 
r33706: styling of combined form (communication) in Email 
r33881: made compatible to $extraClass 
r33885: added defaultVal
r33887: fixed typo 
r34728: modified SmallFieldHolder?()
r34729: added "validationError"-class 
r34914: WIP3866: Factfinder: Hide "self emplyed" block 
r34964: Change current plan upto TraumaInsurance? 
r35038: disabled friggin field focus 
r35230: #1032 Fixed hash-link insertion 
r35887: conditionally setting parameters in sourceID() - to avoid empty overrides
r35892: Saving value in SQL-compatible format (YYYY-MM-DD instead of DD/MM/YYYY), with fallback for non-sql values (just passed through without conversion) 
r35928: Removed "create a" from PageType?-dropdown, sorting alphabetically, falling back to $singular_name
r35990: branched off for membertablefield
r35994: fix for membertablefield
r36024: added array-condition needed for DMYDateField 
r36083: fix bug for compositeField -> dropDatalessField
r36394: removed debug code 
r36826: change wrong indent format 
r36828: WIP 4262: Logging out of My Inform goes to blank page
r36858: Fixed error caused in r12472 while merging to Session-class
r37132: Merged partial changesets from branches/2.0-nzct, only adding childID to detailform when not in add-mode 
r40815: add an unsubscribe record when a member subscribe a newslettertype 
r41113: fix the bug described in http://support.silverstripe.com/info/ticket/31: CRM not showing search results
r43226: fixed search (partial merge from trunk) 
r43268: merged createNewPassword() from trunk, was referencing a non-existinent global function randomString()


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@45473 467b73ca-7a2a-4603-9d3b-597d59a354a9
2007-11-23 01:10:19 +00:00

114 lines
3.1 KiB
PHP
Executable File

<?php
/**
* A redirector page redirects when the page is visited.
*/
class RedirectorPage extends Page {
static $add_action = "Redirector to another page";
static $icon = array("cms/images/treeicons/page-shortcut","file");
static $db = array(
"RedirectionType" => "Enum('Internal,External','Internal')",
"ExternalURL" => "Varchar(255)",
);
static $has_one = array(
"LinkTo" => "SiteTree",
);
static $many_many = array(
);
/**
* Returns this page if the redirect is external, otherwise
* returns the target page.
* @return SiteTree
*/
function ContentSource() {
if($this->RedirectionType == 'Internal') {
return $this->LinkTo();
} else {
return $this;
}
}
function Link() {
if($this->RedirectionType == 'External') {
return $this->ExternalURL;
} else {
$linkTo = $this->LinkToID ? DataObject::get_by_id("SiteTree", $this->LinkToID) : null;
if($linkTo) {
return $linkTo->Link();
}
}
}
function getCMSFields() {
Requirements::javascript("sapphire/javascript/RedirectorPage.js");
$fields = new FieldSet(
new TabSet("Root",
$tabContent = new Tab("Content",
new TextField("Title", _t('SiteTree.PAGETITLE')),
new TextField("MenuTitle", _t('SiteTree.MENUTITLE')),
new FieldGroup(_t('SiteTree.URL'),
new LabelField("http://www.yoursite.com/"),
new TextField("URLSegment",""),
new LabelField("/")
),
new HeaderField(_t('RedirectorPage.HEADER', "This page will redirect users to another page")),
new OptionsetField(
"RedirectionType",
_t('RedirectorPage.REDIRECTTO', "Redirect to"),
array(
"Internal" => _t('RedirectorPage.REDIRECTTOPAGE', "A page on your website"),
"External" => _t('RedirectorPage.REDIRECTTOEXTERNAL', "Another website"),
),
"Internal"
),
new TreeDropdownField(
"LinkToID",
_t('RedirectorPage.YOURPAGE', "Page on your website"),
"SiteTree"
),
new TextField("ExternalURL", _t('RedirectorPage.OTHERURL', "Other website URL")),
new TextareaField("MetaDescription", _t('SiteTree.METADESC'))
),
$tabBehaviour = new Tab("Behaviour",
new DropdownField("ClassName", _t('SiteTree.PAGETYPE'), $this->getClassDropdown()),
new CheckboxField("ShowInMenus", _t('SiteTree.SHOWINMENUS')),
new CheckboxField("ShowInSearch", _t('SiteTree.SHOWINSEARCH'))
)
)
);
$tabContent->setTitle(_t('SiteTree.TABCONTENT'));
$tabBehaviour->setTitle(_t('SiteTree.TABBEHAVIOUR'));
return $fields;
}
}
class RedirectorPage_Controller extends Page_Controller {
function init() {
if($this->RedirectionType == 'External') {
if($this->ExternalURL) {
Director::redirect($this->ExternalURL);
} else {
echo "<p>" .
_t('RedirectorPage.HASBEENSETUP', 'A redirector page has been set up without anywhere to redirect to.') .
"</p>";
}
} else {
$linkTo = DataObject::get_by_id("SiteTree", $this->LinkToID);
if($linkTo) {
Director::redirect($linkTo->Link());
} else {
echo "<p>" . _t('RedirectorPage.HASBEENSETUP') . "</p>";
}
}
parent::init();
}
}
?>