diff --git a/_config.php b/_config.php index e9a0c55..b8ed4f2 100644 --- a/_config.php +++ b/_config.php @@ -11,6 +11,7 @@ new SiteTree(); Object::add_extension('ContentController', 'ControllerSubsites'); Object::add_extension('LeftAndMain', 'LeftAndMainSubsites'); Object::add_extension('LeftAndMain', 'ControllerSubsites'); + Object::add_extension('Group', 'GroupSubsites'); Object::add_extension('File', 'FileSubsites'); ?> diff --git a/code/SiteTreeSubsites.php b/code/SiteTreeSubsites.php index 4c07f2d..5b4994a 100644 --- a/code/SiteTreeSubsites.php +++ b/code/SiteTreeSubsites.php @@ -128,6 +128,8 @@ class SiteTreeSubsites extends DataObjectDecorator { static function contentcontrollerInit($controller) { // Need to set the SubsiteID to null incase we've been in the CMS Session::set('SubsiteID', null); + $subsite = Subsite::currentSubsite(); + if($subsite && $subsite->Theme) SSViewer::set_theme(Subsite::currentSubsite()->Theme); } /** diff --git a/code/Subsite.php b/code/Subsite.php index 6e0a472..24adad6 100644 --- a/code/Subsite.php +++ b/code/Subsite.php @@ -52,6 +52,24 @@ class Subsite extends DataObject implements PermissionProvider { self::$allowed_themes = $themes; } + /** + * Return the themes that can be used with this subsite, as an array of themecode => description + */ + function allowedThemes() { + if($themes = $this->stat('allowed_themes')) { + return ArrayLib::valuekey($themes); + } else { + $themes = array(); + foreach(scandir('../themes/') as $theme) { + if($theme[0] == '.') continue; + $theme = strtok($theme,'_'); + $themes[$theme] = $theme; + } + ksort($themes); + return $themes; + } + } + /** * Return the base domain for this set of subsites. * You can set this by setting Subsite::$Base_domain, otherwise it defaults to HTTP_HOST @@ -96,7 +114,7 @@ class Subsite extends DataObject implements PermissionProvider { new CheckboxField('DefaultSite', 'Use this subsite as the default site', $this->DefaultSite), new CheckboxField('IsPublic', 'Can access this subsite publicly?', $this->IsPublic), - new DropdownField('Theme','Theme', ArrayLib::valuekey($this->stat('allowed_themes')), $this->Theme) + new DropdownField('Theme','Theme', $this->allowedThemes(), $this->Theme) ) ), new HiddenField('ID', '', $this->ID), diff --git a/code/SubsiteAdmin.php b/code/SubsiteAdmin.php index d9a24f7..7c30b47 100644 --- a/code/SubsiteAdmin.php +++ b/code/SubsiteAdmin.php @@ -62,10 +62,9 @@ class SubsiteAdmin extends GenericDataAdmin { function AddSubsiteForm() { $templates = $this->getIntranetTemplates(); + $templateArray = array('' => "(No template)"); if($templates) { - $templateArray = $templates->map('ID', 'Title'); - } else { - $templateArray = array(); + $templateArray = $templateArray + $templates->map('ID', 'Title'); } return new Form($this, 'AddSubsiteForm', new FieldSet( @@ -104,19 +103,32 @@ class SubsiteAdmin extends GenericDataAdmin { } */ - $template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']); + if(isset($data['TemplateID']) && $data['TemplateID']) { + $template = DataObject::get_by_id('Subsite_Template', $data['TemplateID']); + } else { + $template = null; + } // Create intranet from existing template switch($data['Type']) { case 'template': - $intranet = $template->duplicate(); + if($template) $intranet = $template->duplicate(); + else $intranet = new Subsite_Template(); + $intranet->Title = $data['Name']; $intranet->write(); break; - default: case 'subsite': - $intranet = $template->createInstance($data['Name'], $data['Subdomain']); + default: + if($template) $intranet = $template->createInstance($data['Name'], $data['Subdomain']); + else { + $intranet = new Subsite(); + $intranet->Title = $data['Name']; + $intranet->Subdomain = $data['Subdomain']; + $intranet->write(); + } + break; } diff --git a/templates/Includes/CMSTopMenu_alternative.ss b/templates/Includes/CMSTopMenu_alternative.ss new file mode 100644 index 0000000..791704e --- /dev/null +++ b/templates/Includes/CMSTopMenu_alternative.ss @@ -0,0 +1,11 @@ + +
+
+ $SubsiteList + $ApplicationLogoText +
+