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 {
|
2008-02-26 00:02:02 +01:00
|
|
|
static $allowed_actions = array(
|
|
|
|
'changesubsite',
|
|
|
|
);
|
|
|
|
|
2009-11-30 02:44:38 +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');
|
2010-03-01 22:25:58 +01:00
|
|
|
|
|
|
|
if ($currentPage = $this->owner->currentPage()) {
|
|
|
|
if (Subsite::currentSubsiteID() != $currentPage->SubsiteID) {
|
|
|
|
Subsite::changeSubsite($currentPage->SubsiteID);
|
|
|
|
}
|
|
|
|
}
|
2007-08-16 08:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the title of the CMS tree
|
|
|
|
*/
|
|
|
|
function getCMSTreeTitle() {
|
|
|
|
$subsite = Subsite::currentSubSite();
|
2010-01-26 21:45:05 +01:00
|
|
|
return $subsite ? $subsite->Title : null;
|
2007-08-16 08:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function changesubsite() {
|
2009-05-06 04:41:16 +02:00
|
|
|
$id = $_REQUEST['SubsiteID'];
|
2007-08-16 08:38:29 +02:00
|
|
|
|
|
|
|
Subsite::changeSubsite($id);
|
|
|
|
|
2010-03-01 22:16:58 +01:00
|
|
|
if ($id == '-1') Cookie::set('noSubsiteFilter', 'true', 1);
|
|
|
|
else Cookie::set('noSubsiteFilter', 'false', 1);
|
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
if(Director::is_ajax()) {
|
|
|
|
$tree = $this->owner->SiteTreeAsUL();
|
|
|
|
$tree = ereg_replace('^[ \t\r\n]*<ul[^>]*>','', $tree);
|
|
|
|
$tree = ereg_replace('</ul[^>]*>[ \t\r\n]*$','', $tree);
|
|
|
|
return $tree;
|
|
|
|
} else
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Subsites() {
|
|
|
|
$siteList = new DataObjectSet();
|
2007-08-31 02:29:25 +02:00
|
|
|
$subsites = Subsite::accessible_sites('CMS_ACCESS_' . $this->owner->class);
|
|
|
|
|
2009-11-02 04:00:18 +01:00
|
|
|
if(defined('DB::USE_ANSI_SQL'))
|
|
|
|
$q="\"";
|
|
|
|
else $q='`';
|
2008-12-04 22:36:06 +01:00
|
|
|
|
|
|
|
$mainSiteTitle = null;
|
|
|
|
switch($this->owner->class) {
|
|
|
|
case "AssetAdmin":
|
|
|
|
$mainSiteTitle = "Shared files & images"; break;
|
|
|
|
case "SecurityAdmin":
|
2010-03-01 22:16:58 +01:00
|
|
|
$mainSiteTitle = "Groups accessing all sites";
|
|
|
|
$siteList->push(new ArrayData(array('Title' => 'All groups', 'ID' => -1)));
|
|
|
|
break;
|
2008-12-04 22:36:06 +01:00
|
|
|
case "CMSMain":
|
|
|
|
// If there's a default site then main site has no meaning
|
2009-11-02 04:00:18 +01:00
|
|
|
if(!DataObject::get_one('Subsite', "{$q}DefaultSite{$q} = 1 AND {$q}IsPublic{$q} = 1")) {
|
2008-12-04 22:36:06 +01:00
|
|
|
$mainSiteTitle = "Main site";
|
|
|
|
}
|
|
|
|
break;
|
2009-05-04 07:03:44 +02:00
|
|
|
default:
|
|
|
|
$mainSiteTitle = "Main site";
|
|
|
|
break;
|
2008-12-04 22:36:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if($mainSiteTitle && Subsite::hasMainSitePermission(Member::currentUser(), array('CMS_ACCESS_' . $this->owner->class, 'ADMIN')))
|
|
|
|
$siteList->push(new ArrayData(array('Title' => $mainSiteTitle, 'ID' => 0)));
|
2007-08-16 08:38:29 +02:00
|
|
|
|
|
|
|
if($subsites)
|
2008-02-26 00:02:02 +01:00
|
|
|
$siteList->merge($subsites);
|
2007-08-16 08:38:29 +02:00
|
|
|
|
|
|
|
return $siteList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function SubsiteList() {
|
|
|
|
$list = $this->Subsites();
|
|
|
|
|
2008-12-04 22:36:06 +01:00
|
|
|
if(Controller::curr()->hasMethod('getRequest')) $requestSubsiteID = Controller::curr()->getRequest()->getVar('SubsiteID');
|
|
|
|
else $requestSubsiteID = isset($_REQUEST['SubsiteID']) ? $_REQUEST['SubsiteID'] : null;
|
|
|
|
|
2008-12-02 04:50:06 +01:00
|
|
|
$currentSubsiteID = ($requestSubsiteID) ? $requestSubsiteID : Session::get('SubsiteID');
|
|
|
|
|
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
|
|
|
|
|
|
|
$output .= "\n<option value=\"{$subsite->ID}\"$selected>{$subsite->Title}</option>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '</select>';
|
|
|
|
|
|
|
|
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
|
|
|
|
2007-08-31 02:29:25 +02:00
|
|
|
if($result = Permission::check("CMS_ACCESS_$className")) {
|
|
|
|
return $result;
|
|
|
|
} else {
|
|
|
|
$otherSites = Subsite::accessible_sites("CMS_ACCESS_$className");
|
|
|
|
if($otherSites && $otherSites->TotalItems() > 0) {
|
|
|
|
$otherSites->First()->activate();
|
|
|
|
return Permission::check("CMS_ACCESS_$className");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2007-10-11 06:50:49 +02:00
|
|
|
|
|
|
|
function augmentNewSiteTreeItem(&$item) {
|
|
|
|
$item->SubsiteID = Subsite::currentSubsiteID();
|
|
|
|
}
|
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
|
|
|
?>
|