mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
2ef72b374c
Replaced deprecated DataObjectDecorator with DataExtension Fixed hard crashes in the cms Updated to support new LeftAndMain template structure Made the subsites model admin functional Moved the LeftAndMain_Menu template up a directory so it overrides the core Fixed some errors caused by changes to the framework Re-organized the code folder Fixed permission issue causing to default to first subsite regardless if it is the default or not Fixed crashes on the subsite virtual page when creating/editing Removed toDropdownMap() calls replacing with map() Fixed the URLSegment field on subsites Fixed error when detecting subsite for a domain Improved styles on the subsite dropdown Updated LeftAndMain_Subsites.js to work with jQuery entwine Started porting the SubsitesTreeDropdownField.js to use jQuery entwine and work with the new TreeDropdownField.js Fixed issue causing crash when viewing a page who is linked to by a subsite virtual page Removed unused methods on SubsitesTreeDropdownField.js Re-added classes that were moved Fixed hard crash after saving caused by the many_many definition on SiteTreeSubsites Replaced deprecated DataObjectSet creation with ArrayList Compatibility fixes with SS 3.0 beta 2 Fixed crash in cms caused by no parameter being passed to the SubsiteReportWrapper constructor Proper fix for report wrapper Removed table list field in favor of a basic grid field Fixed updateCMSFields() for file subsites Migrated translations to yml Fixed issue causing the current page to not get cleared when changing subsites in the cms Fixed virtual page icon Fixed language files issue
148 lines
4.7 KiB
PHP
148 lines
4.7 KiB
PHP
<?php
|
|
/**
|
|
* Decorator designed to add subsites support to LeftAndMain
|
|
*
|
|
* @package subsites
|
|
*/
|
|
class LeftAndMainSubsites extends Extension {
|
|
|
|
function init() {
|
|
Requirements::css('subsites/css/LeftAndMain_Subsites.css');
|
|
Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js');
|
|
Requirements::javascript('subsites/javascript/VirtualPage_Subsites.js');
|
|
|
|
if(isset($_REQUEST['SubsiteID'])) {
|
|
// Clear current page when subsite changes (or is set for the first time)
|
|
if(!Session::get('SubsiteID') || $_REQUEST['SubsiteID'] != Session::get('SubsiteID')) {
|
|
Session::clear("{$this->owner->class}.currentPage");
|
|
}
|
|
|
|
// Update current subsite in session
|
|
Subsite::changeSubsite($_REQUEST['SubsiteID']);
|
|
|
|
//Redirect to clear the current page
|
|
$this->owner->redirect('admin/pages');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Set the title of the CMS tree
|
|
*/
|
|
function getCMSTreeTitle() {
|
|
$subsite = Subsite::currentSubSite();
|
|
return $subsite ? Convert::raw2xml($subsite->Title) : _t('LeftAndMain.SITECONTENTLEFT');
|
|
}
|
|
|
|
function updatePageOptions(&$fields) {
|
|
$fields->push(new HiddenField('SubsiteID', 'SubsiteID', Subsite::currentSubsiteID()));
|
|
}
|
|
|
|
public function Subsites() {
|
|
return Subsite::accessible_sites('ADMIN');
|
|
}
|
|
|
|
public function SubsiteList() {
|
|
$list = $this->Subsites();
|
|
|
|
$currentSubsiteID = Subsite::currentSubsiteID();
|
|
|
|
if($list->Count() > 1) {
|
|
$output = '<select id="SubsitesSelect">';
|
|
|
|
foreach($list as $subsite) {
|
|
$selected = $subsite->ID == $currentSubsiteID ? ' selected="selected"' : '';
|
|
|
|
$output .= "\n<option value=\"{$subsite->ID}\"$selected>". Convert::raw2xml($subsite->Title) . "</option>";
|
|
}
|
|
|
|
$output .= '</select>';
|
|
|
|
Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js');
|
|
return $output;
|
|
} else if($list->Count() == 1) {
|
|
if($list->First()->DefaultSite==false) {
|
|
$output = '<select id="SubsitesSelect">';
|
|
$output .= "\n<option value=\"0\">". _t('LeftAndMainSubsites.DEFAULT_SITE', '_Default Site') . "</option>";
|
|
foreach($list as $subsite) {
|
|
$selected = $subsite->ID == $currentSubsiteID ? ' selected="selected"' : '';
|
|
|
|
$output .= "\n<option value=\"{$subsite->ID}\"$selected>". Convert::raw2xml($subsite->Title) . "</option>";
|
|
}
|
|
|
|
$output .= '</select>';
|
|
|
|
Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js');
|
|
return $output;
|
|
}else {
|
|
return '<span>'.$list->First()->Title.'</span>';
|
|
}
|
|
}
|
|
}
|
|
|
|
public function CanAddSubsites() {
|
|
return Permission::check("ADMIN", "any", null, "all");
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
// Switch to a subsite that this user can actually access.
|
|
$member = Member::currentUser();
|
|
if ($member && Permission::check('ADMIN')) {
|
|
return true; //admin can access all subsites
|
|
}
|
|
|
|
$sites = Subsite::accessible_sites("CMS_ACCESS_{$this->owner->class}")->map('ID', 'Title')->toArray();
|
|
if($sites && !isset($sites[Subsite::currentSubsiteID()])) {
|
|
$siteIDs = array_keys($sites);
|
|
Subsite::changeSubsite($siteIDs[0]);
|
|
return true;
|
|
}
|
|
|
|
// 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}")->map('ID', 'Title')->toArray();
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
// If all of those fail, you really don't have access to the CMS
|
|
return null;
|
|
}
|
|
|
|
function augmentNewSiteTreeItem(&$item) {
|
|
$item->SubsiteID = isset($_POST['SubsiteID']) ? $_POST['SubsiteID'] : Subsite::currentSubsiteID();
|
|
}
|
|
|
|
function onAfterSave($record) {
|
|
if($record->hasMethod('NormalRelated') && ($record->NormalRelated() || $record->ReverseRelated())) {
|
|
FormResponse::status_message('Saved, please update related pages.', 'good');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
?>
|