2007-08-16 08:38:29 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Decorator designed to add subsites support to LeftAndMain
|
2008-11-24 04:22:01 +01:00
|
|
|
*
|
|
|
|
* @package subsites
|
2007-08-16 08:38:29 +02:00
|
|
|
*/
|
|
|
|
class LeftAndMainSubsites extends Extension {
|
2011-09-05 17:54:40 +02:00
|
|
|
|
2011-02-14 04:10:47 +01:00
|
|
|
function init() {
|
2007-08-16 08:38:29 +02:00
|
|
|
Requirements::css('subsites/css/LeftAndMain_Subsites.css');
|
|
|
|
Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js');
|
2008-12-02 04:50:06 +01:00
|
|
|
Requirements::javascript('subsites/javascript/VirtualPage_Subsites.js');
|
2007-08-16 08:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the title of the CMS tree
|
|
|
|
*/
|
|
|
|
function getCMSTreeTitle() {
|
|
|
|
$subsite = Subsite::currentSubSite();
|
2011-09-05 15:11:23 +02:00
|
|
|
return $subsite ? Convert::raw2xml($subsite->Title) : _t('LeftAndMain.SITECONTENTLEFT');
|
2007-08-16 08:38:29 +02:00
|
|
|
}
|
2010-03-01 22:40:43 +01:00
|
|
|
|
|
|
|
function updatePageOptions(&$fields) {
|
|
|
|
$fields->push(new HiddenField('SubsiteID', 'SubsiteID', Subsite::currentSubsiteID()));
|
|
|
|
}
|
2007-08-16 08:38:29 +02:00
|
|
|
|
|
|
|
public function Subsites() {
|
2010-03-01 22:32:37 +01:00
|
|
|
$accessPerm = 'CMS_ACCESS_'. $this->owner->class;
|
2008-12-04 22:36:06 +01:00
|
|
|
|
|
|
|
switch($this->owner->class) {
|
|
|
|
case "AssetAdmin":
|
2010-03-01 22:32:37 +01:00
|
|
|
$subsites = Subsite::accessible_sites($accessPerm, true, "Shared files & images");
|
|
|
|
break;
|
|
|
|
|
2008-12-04 22:36:06 +01:00
|
|
|
case "SecurityAdmin":
|
2010-03-01 22:32:37 +01:00
|
|
|
$subsites = Subsite::accessible_sites($accessPerm, true, "Groups accessing all sites");
|
2010-03-01 22:34:15 +01:00
|
|
|
if($subsites->find('ID',0)) {
|
|
|
|
$subsites->push(new ArrayData(array('Title' => 'All groups', 'ID' => -1)));
|
|
|
|
}
|
2010-03-01 22:16:58 +01:00
|
|
|
break;
|
2010-03-01 23:12:58 +01:00
|
|
|
|
2008-12-04 22:36:06 +01:00
|
|
|
case "CMSMain":
|
|
|
|
// If there's a default site then main site has no meaning
|
2010-03-01 23:12:58 +01:00
|
|
|
$showMainSite = !DataObject::get_one('Subsite',"\"DefaultSite\"=1 AND \"IsPublic\"=1");
|
2010-03-01 22:32:37 +01:00
|
|
|
$subsites = Subsite::accessible_sites($accessPerm, $showMainSite);
|
2008-12-04 22:36:06 +01:00
|
|
|
break;
|
2010-03-01 22:32:37 +01:00
|
|
|
|
2009-05-04 07:03:44 +02:00
|
|
|
default:
|
2010-03-01 22:32:37 +01:00
|
|
|
$subsites = Subsite::accessible_sites($accessPerm);
|
2009-05-04 07:03:44 +02:00
|
|
|
break;
|
2008-12-04 22:36:06 +01:00
|
|
|
}
|
|
|
|
|
2010-03-01 22:32:37 +01:00
|
|
|
return $subsites;
|
2007-08-16 08:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function SubsiteList() {
|
2010-03-01 22:34:33 +01:00
|
|
|
if ($this->owner->class == 'AssetAdmin') {
|
|
|
|
// See if the right decorator is there....
|
|
|
|
$file = new File();
|
|
|
|
if (!$file->hasExtension('FileSubsites')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-09 14:12:59 +02:00
|
|
|
// Don't show subsite list in reports section, it doesn't have
|
|
|
|
// any effect there - subsites are filtered through a custom dropdown there, see SubsiteReportWrapper
|
|
|
|
if($this->owner instanceof ReportAdmin) return false;
|
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
$list = $this->Subsites();
|
|
|
|
|
2010-04-06 05:15:44 +02:00
|
|
|
$currentSubsiteID = Subsite::currentSubsiteID();
|
2008-12-02 04:50:06 +01:00
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
if($list->Count() > 1) {
|
|
|
|
$output = '<select id="SubsitesSelect">';
|
|
|
|
|
|
|
|
foreach($list as $subsite) {
|
2008-12-02 04:50:06 +01:00
|
|
|
$selected = $subsite->ID == $currentSubsiteID ? ' selected="selected"' : '';
|
2007-08-16 08:38:29 +02:00
|
|
|
|
2011-09-05 15:11:23 +02:00
|
|
|
$output .= "\n<option value=\"{$subsite->ID}\"$selected>". Convert::raw2xml($subsite->Title) . "</option>";
|
2007-08-16 08:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '</select>';
|
|
|
|
|
2010-03-03 00:28:57 +01:00
|
|
|
Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js');
|
2007-08-16 08:38:29 +02:00
|
|
|
return $output;
|
2009-03-04 07:33:38 +01:00
|
|
|
} else if($list->Count() == 1) {
|
2007-08-16 08:38:29 +02:00
|
|
|
return $list->First()->Title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function CanAddSubsites() {
|
|
|
|
return Permission::check("ADMIN", "any", null, "all");
|
2007-08-31 02:29:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Alternative security checker for LeftAndMain.
|
|
|
|
* If security isn't found, then it will switch to a subsite where we do have access.
|
|
|
|
*/
|
|
|
|
public function alternateAccessCheck() {
|
|
|
|
$className = $this->owner->class;
|
2008-12-02 04:50:06 +01:00
|
|
|
|
2010-03-01 22:37:56 +01:00
|
|
|
// Switch to the subsite of the current page
|
|
|
|
if ($this->owner->class == 'CMSMain' && $currentPage = $this->owner->currentPage()) {
|
|
|
|
if (Subsite::currentSubsiteID() != $currentPage->SubsiteID) {
|
|
|
|
Subsite::changeSubsite($currentPage->SubsiteID);
|
2007-08-31 02:29:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-26 05:56:03 +02:00
|
|
|
// Switch to a subsite that this user can actually access.
|
|
|
|
$member = Member::currentUser();
|
|
|
|
if ($member && $member->isAdmin()) return true; //admin can access all subsites
|
|
|
|
|
2010-03-01 22:37:56 +01:00
|
|
|
$sites = Subsite::accessible_sites("CMS_ACCESS_{$this->owner->class}")->toDropdownMap();
|
|
|
|
if($sites && !isset($sites[Subsite::currentSubsiteID()])) {
|
|
|
|
$siteIDs = array_keys($sites);
|
|
|
|
Subsite::changeSubsite($siteIDs[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-01 22:39:19 +01:00
|
|
|
// Switch to a different top-level menu item
|
|
|
|
$menu = CMSMenu::get_menu_items();
|
|
|
|
foreach($menu as $candidate) {
|
|
|
|
if($candidate->controller != $this->owner->class) {
|
|
|
|
|
|
|
|
$sites = Subsite::accessible_sites("CMS_ACCESS_{$candidate->controller}")->toDropdownMap();
|
|
|
|
if($sites && !isset($sites[Subsite::currentSubsiteID()])) {
|
|
|
|
$siteIDs = array_keys($sites);
|
|
|
|
Subsite::changeSubsite($siteIDs[0]);
|
|
|
|
$cClass = $candidate->controller;
|
|
|
|
$cObj = new $cClass();
|
|
|
|
Director::redirect($cObj->Link());
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-01 22:37:56 +01:00
|
|
|
|
2010-03-01 22:39:19 +01:00
|
|
|
// If all of those fail, you really don't have access to the CMS
|
2007-08-31 02:29:25 +02:00
|
|
|
return null;
|
|
|
|
}
|
2007-10-11 06:50:49 +02:00
|
|
|
|
|
|
|
function augmentNewSiteTreeItem(&$item) {
|
2010-03-01 22:40:43 +01:00
|
|
|
$item->SubsiteID = isset($_POST['SubsiteID']) ? $_POST['SubsiteID'] : Subsite::currentSubsiteID();
|
2007-10-11 06:50:49 +02:00
|
|
|
}
|
2010-03-01 04:01:50 +01:00
|
|
|
|
|
|
|
function onAfterSave($record) {
|
2010-03-01 04:11:48 +01:00
|
|
|
if($record->hasMethod('NormalRelated') && ($record->NormalRelated() || $record->ReverseRelated())) {
|
2010-03-01 04:01:50 +01:00
|
|
|
FormResponse::status_message('Saved, please update related pages.', 'good');
|
|
|
|
}
|
|
|
|
}
|
2007-08-31 02:29:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
|
2009-05-04 07:03:44 +02:00
|
|
|
?>
|