2008-12-02 04:50:06 +01:00
< ? php
class SubsitesVirtualPage extends VirtualPage {
2010-03-01 04:00:29 +01:00
static $db = array (
'CustomMetaTitle' => 'Varchar(255)' ,
'CustomMetaKeywords' => 'Varchar(255)' ,
'CustomMetaDescription' => 'Text' ,
'CustomExtraMeta' => 'HTMLText'
);
2008-12-02 04:50:06 +01:00
function getCMSFields () {
$fields = parent :: getCMSFields ();
2010-03-01 22:26:35 +01:00
$subsites = DataObject :: get ( 'Subsite' );
2010-03-01 22:26:53 +01:00
if ( ! $subsites ) $subsites = new DataObjectSet ();
2010-03-01 22:26:35 +01:00
$subsites -> push ( new ArrayData ( array ( 'Title' => 'Main site' , 'ID' => 0 )));
2008-12-02 04:50:06 +01:00
2010-03-01 22:26:35 +01:00
$subsiteSelectionField = new DropdownField (
" CopyContentFromID_SubsiteID " ,
" Subsite " ,
$subsites -> toDropdownMap ( 'ID' , 'Title' ),
( $this -> CopyContentFromID ) ? $this -> CopyContentFrom () -> SubsiteID : Session :: get ( 'SubsiteID' )
);
$fields -> addFieldToTab (
'Root.Content.Main' ,
$subsiteSelectionField ,
'CopyContentFromID'
);
2008-12-02 04:50:06 +01:00
// Setup the linking to the original page.
$pageSelectionField = new SubsitesTreeDropdownField (
" CopyContentFromID " ,
_t ( 'VirtualPage.CHOOSE' , " Choose a page to link to " ),
2010-03-01 03:58:31 +01:00
" SiteTree " ,
" ID " ,
" MenuTitle "
2008-12-02 04:50:06 +01:00
);
2010-03-01 03:58:31 +01:00
2008-12-02 04:50:06 +01:00
$pageSelectionField -> setFilterFunction ( create_function ( '$item' , 'return $item->ClassName != "VirtualPage";' ));
2009-05-04 07:04:08 +02:00
if ( Controller :: curr () -> getRequest ()) {
2010-03-01 22:38:32 +01:00
$subsiteID = Controller :: curr () -> getRequest () -> getVar ( 'CopyContentFromID_SubsiteID' );
2009-07-30 04:11:02 +02:00
$pageSelectionField -> setSubsiteID ( $subsiteID );
2008-12-02 04:50:06 +01:00
}
$fields -> replaceField ( 'CopyContentFromID' , $pageSelectionField );
// Create links back to the original object in the CMS
if ( $this -> CopyContentFromID ) {
$editLink = " admin/show/ $this->CopyContentFromID /?SubsiteID= " . $this -> CopyContentFrom () -> SubsiteID ;
$linkToContent = "
< a class = \ " cmsEditlink \" href= \" $editLink\ " > " .
_t ( 'VirtualPage.EDITCONTENT' , 'Click here to edit the content' ) .
" </a> " ;
$fields -> removeByName ( " VirtualPageContentLinkLabel " );
$fields -> addFieldToTab (
" Root.Content.Main " ,
$linkToContentLabelField = new LabelField ( 'VirtualPageContentLinkLabel' , $linkToContent ),
'Title'
);
$linkToContentLabelField -> setAllowHTML ( true );
}
2010-03-01 22:26:13 +01:00
$fields -> addFieldToTab ( 'Root.Content.Metadata' , new TextField ( 'CustomMetaTitle' , 'Title (overrides inherited value from the source)' ), 'MetaTitle' );
$fields -> addFieldToTab ( 'Root.Content.Metadata' , new TextareaField ( 'CustomMetaKeywords' , 'Keywords (overrides inherited value from the source)' ), 'MetaKeywords' );
$fields -> addFieldToTab ( 'Root.Content.Metadata' , new TextareaField ( 'CustomMetaDescription' , 'Description (overrides inherited value from the source)' ), 'MetaDescription' );
$fields -> addFieldToTab ( 'Root.Content.Metadata' , new TextField ( 'CustomExtraMeta' , 'Custom Meta Tags (overrides inherited value from the source)' ), 'ExtraMeta' );
2010-03-01 04:00:29 +01:00
2008-12-02 04:50:06 +01:00
return $fields ;
}
function getVirtualFields () {
$fields = parent :: getVirtualFields ();
foreach ( $fields as $k => $v ) {
if ( $v == 'SubsiteID' ) unset ( $fields [ $k ]);
}
return $fields ;
}
2010-03-01 04:00:29 +01:00
2010-03-01 22:33:12 +01:00
function syncLinkTracking () {
$oldState = Subsite :: $disable_subsite_filter ;
Subsite :: $disable_subsite_filter = true ;
2010-03-01 22:40:36 +01:00
if ( $this -> CopyContentFromID ) $this -> HasBrokenLink = DataObject :: get_by_id ( 'SiteTree' , $this -> CopyContentFromID ) ? false : true ;
2010-03-01 22:33:12 +01:00
Subsite :: $disable_subsite_filter = $oldState ;
}
2010-03-01 04:00:29 +01:00
function onBeforeWrite () {
parent :: onBeforeWrite ();
if ( $this -> CustomMetaTitle ) $this -> MetaTitle = $this -> CustomMetaTitle ;
2010-03-01 22:33:46 +01:00
else {
$this -> MetaTitle = $this -> ContentSource () -> MetaTitle ? $this -> ContentSource () -> MetaTitle : $this -> MetaTitle ;
}
2010-03-01 04:00:29 +01:00
if ( $this -> CustomMetaKeywords ) $this -> MetaKeywords = $this -> CustomMetaKeywords ;
2010-03-01 22:33:46 +01:00
else {
$this -> MetaKeywords = $this -> ContentSource () -> MetaKeywords ? $this -> ContentSource () -> MetaKeywords : $this -> MetaKeywords ;
}
2010-03-01 04:00:29 +01:00
if ( $this -> CustomMetaDescription ) $this -> MetaDescription = $this -> CustomMetaDescription ;
2010-03-01 22:33:46 +01:00
else {
$this -> MetaDescription = $this -> ContentSource () -> MetaDescription ? $this -> ContentSource () -> MetaDescription : $this -> MetaDescription ;
}
2010-03-01 04:00:29 +01:00
if ( $this -> CustomExtraMeta ) $this -> ExtraMeta = $this -> CustomExtraMeta ;
2010-03-01 22:33:46 +01:00
else {
$this -> ExtraMeta = $this -> ContentSource () -> ExtraMeta ? $this -> ContentSource () -> ExtraMeta : $this -> ExtraMeta ;
}
2010-03-01 04:00:29 +01:00
}
2008-12-02 04:50:06 +01:00
}
class SubsitesVirtualPage_Controller extends VirtualPage_Controller {
function reloadContent () {
$this -> failover -> nextWriteDoesntCustomise ();
$this -> failover -> copyFrom ( $this -> failover -> CopyContentFrom ());
$this -> failover -> nextWriteDoesntCustomise ();
$this -> failover -> write ();
return ;
}
function init (){
Subsite :: $disable_subsite_filter = true ;
parent :: init ();
Subsite :: $disable_subsite_filter = false ;
}
}
2010-03-01 04:00:29 +01:00
?>