diff --git a/_config.php b/_config.php index 0cbece5..93cca78 100644 --- a/_config.php +++ b/_config.php @@ -1,5 +1,21 @@ Fields()->dataFieldByName('Subsite'); if($grid) { - $grid->getConfig()->removeComponentsByType('GridFieldDetailForm'); + $grid->getConfig()->removeComponentsByType('SilverStripe\\Forms\\GridField\\GridFieldDetailForm'); $grid->getConfig()->addComponent(new GridFieldSubsiteDetailForm()); } diff --git a/code/SubsiteReportWrapper.php b/code/SubsiteReportWrapper.php index 2774cfc..104499d 100644 --- a/code/SubsiteReportWrapper.php +++ b/code/SubsiteReportWrapper.php @@ -1,10 +1,14 @@ renderWith('SubsiteList'); + return $this->renderWith('Includes/SubsiteList'); } } diff --git a/code/SubsitesVirtualPage.php b/code/SubsitesVirtualPage.php index c63fa13..72b5b0b 100644 --- a/code/SubsitesVirtualPage.php +++ b/code/SubsitesVirtualPage.php @@ -1,4 +1,17 @@ 'Text', 'CustomExtraMeta' => 'HTMLText' ); - + public function getCMSFields() { $fields = parent::getCMSFields(); - + $subsites = DataObject::get('Subsite'); if(!$subsites) { $subsites = new ArrayList(); }else { $subsites=ArrayList::create($subsites->toArray()); } - + $subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0))); $fields->addFieldToTab( 'Root.Main', DropdownField::create( - "CopyContentFromID_SubsiteID", - _t('SubsitesVirtualPage.SubsiteField',"Subsite"), + "CopyContentFromID_SubsiteID", + _t('SubsitesVirtualPage.SubsiteField',"Subsite"), $subsites->map('ID', 'Title') )->addExtraClass('subsitestreedropdownfield-chooser no-change-track'), 'CopyContentFromID' ); - + // Setup the linking to the original page. $pageSelectionField = new SubsitesTreeDropdownField( - "CopyContentFromID", - _t('VirtualPage.CHOOSE', "Choose a page to link to"), - "SiteTree", + "CopyContentFromID", + _t('VirtualPage.CHOOSE', "Choose a page to link to"), + "SilverStripe\\CMS\\Model\\SiteTree", "ID", "MenuTitle" ); - + if(Controller::has_curr() && Controller::curr()->getRequest()) { $subsiteID = Controller::curr()->getRequest()->requestVar('CopyContentFromID_SubsiteID'); $pageSelectionField->setSubsiteID($subsiteID); } $fields->replaceField('CopyContentFromID', $pageSelectionField); - + // Create links back to the original object in the CMS if($this->CopyContentFromID) { $editLink = "admin/pages/edit/show/$this->CopyContentFromID/?SubsiteID=" . $this->CopyContentFrom()->SubsiteID; $linkToContent = " - " . - _t('VirtualPage.EDITCONTENT', 'Click here to edit the content') . + " . + _t('VirtualPage.EDITCONTENT', 'Click here to edit the content') . ""; $fields->removeByName("VirtualPageContentLinkLabel"); $fields->addFieldToTab( - "Root.Main", + "Root.Main", $linkToContentLabelField = new LabelField('VirtualPageContentLinkLabel', $linkToContent), 'Title' ); $linkToContentLabelField->setAllowHTML(true); } - - + + $fields->addFieldToTab( - 'Root.Main', + 'Root.Main', TextField::create( - 'CustomMetaTitle', + 'CustomMetaTitle', $this->fieldLabel('CustomMetaTitle') - )->setDescription(_t('SubsitesVirtualPage.OverrideNote', 'Overrides inherited value from the source')), + )->setDescription(_t('SubsitesVirtualPage.OverrideNote', 'Overrides inherited value from the source')), 'MetaTitle' ); $fields->addFieldToTab( - 'Root.Main', + 'Root.Main', TextareaField::create( - 'CustomMetaKeywords', + 'CustomMetaKeywords', $this->fieldLabel('CustomMetaTitle') - )->setDescription(_t('SubsitesVirtualPage.OverrideNote')), + )->setDescription(_t('SubsitesVirtualPage.OverrideNote')), 'MetaKeywords' ); $fields->addFieldToTab( - 'Root.Main', + 'Root.Main', TextareaField::create( - 'CustomMetaDescription', + 'CustomMetaDescription', $this->fieldLabel('CustomMetaTitle') - )->setDescription(_t('SubsitesVirtualPage.OverrideNote')), + )->setDescription(_t('SubsitesVirtualPage.OverrideNote')), 'MetaDescription' ); $fields->addFieldToTab( - 'Root.Main', + 'Root.Main', TextField::create( - 'CustomExtraMeta', + 'CustomExtraMeta', $this->fieldLabel('CustomMetaTitle') - )->setDescription(_t('SubsitesVirtualPage.OverrideNote')), + )->setDescription(_t('SubsitesVirtualPage.OverrideNote')), 'ExtraMeta' ); - + return $fields; } @@ -113,73 +126,73 @@ class SubsitesVirtualPage extends VirtualPage { public function getCopyContentFromID_SubsiteID() { return ($this->CopyContentFromID) ? (int)$this->CopyContentFrom()->SubsiteID : (int)Session::get('SubsiteID'); } - + public function getVirtualFields() { $fields = parent::getVirtualFields(); foreach($fields as $k => $v) { if($v == 'SubsiteID') unset($fields[$k]); } - + foreach(self::$db as $field => $type) if (in_array($field, $fields)) unset($fields[array_search($field, $fields)]); return $fields; } - + public function syncLinkTracking() { $oldState = Subsite::$disable_subsite_filter; Subsite::$disable_subsite_filter = true; - if ($this->CopyContentFromID) $this->HasBrokenLink = DataObject::get_by_id('SiteTree', $this->CopyContentFromID) ? false : true; + if ($this->CopyContentFromID) $this->HasBrokenLink = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $this->CopyContentFromID) ? false : true; Subsite::$disable_subsite_filter = $oldState; } public function onBeforeWrite() { parent::onBeforeWrite(); - + if($this->CustomMetaTitle) $this->MetaTitle = $this->CustomMetaTitle; else { - $this->MetaTitle = $this->ContentSource()->MetaTitle ? $this->ContentSource()->MetaTitle : $this->MetaTitle; + $this->MetaTitle = $this->ContentSource()->MetaTitle ? $this->ContentSource()->MetaTitle : $this->MetaTitle; } if($this->CustomMetaKeywords) $this->MetaKeywords = $this->CustomMetaKeywords; else { - $this->MetaKeywords = $this->ContentSource()->MetaKeywords ? $this->ContentSource()->MetaKeywords : $this->MetaKeywords; + $this->MetaKeywords = $this->ContentSource()->MetaKeywords ? $this->ContentSource()->MetaKeywords : $this->MetaKeywords; } if($this->CustomMetaDescription) $this->MetaDescription = $this->CustomMetaDescription; else { - $this->MetaDescription = $this->ContentSource()->MetaDescription ? $this->ContentSource()->MetaDescription : $this->MetaDescription; + $this->MetaDescription = $this->ContentSource()->MetaDescription ? $this->ContentSource()->MetaDescription : $this->MetaDescription; } if($this->CustomExtraMeta) $this->ExtraMeta = $this->CustomExtraMeta; else { - $this->ExtraMeta = $this->ContentSource()->ExtraMeta ? $this->ContentSource()->ExtraMeta : $this->ExtraMeta; + $this->ExtraMeta = $this->ContentSource()->ExtraMeta ? $this->ContentSource()->ExtraMeta : $this->ExtraMeta; } } - + public function validURLSegment() { $isValid = parent::validURLSegment(); - + // Veto the validation rules if its false. In this case, some logic // needs to be duplicated from parent to find out the exact reason the validation failed. if(!$isValid) { $IDFilter = ($this->ID) ? "AND \"SiteTree\".\"ID\" <> $this->ID" : null; $parentFilter = null; - if(Config::inst()->get('SiteTree', 'nested_urls')) { + if(Config::inst()->get('SilverStripe\\CMS\\Model\\SiteTree', 'nested_urls')) { if($this->ParentID) { $parentFilter = " AND \"SiteTree\".\"ParentID\" = $this->ParentID"; } else { $parentFilter = ' AND "SiteTree"."ParentID" = 0'; } } - + $origDisableSubsiteFilter = Subsite::$disable_subsite_filter; Subsite::$disable_subsite_filter = true; $existingPage = DataObject::get_one( - 'SiteTree', + 'SilverStripe\\CMS\\Model\\SiteTree', "\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter", false // disable cache, it doesn't include subsite status in the key ); Subsite::$disable_subsite_filter = $origDisableSubsiteFilter; $existingPageInSubsite = DataObject::get_one( - 'SiteTree', + 'SilverStripe\\CMS\\Model\\SiteTree', "\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter", false // disable cache, it doesn't include subsite status in the key ); @@ -188,25 +201,7 @@ class SubsitesVirtualPage extends VirtualPage { // be more specific and allow same URLSegments in different subsites $isValid = !($existingPage && $existingPageInSubsite); } - + return $isValid; } } - -class SubsitesVirtualPage_Controller extends VirtualPage_Controller { - - public function reloadContent() { - $this->failover->copyFrom($this->failover->CopyContentFrom()); - $this->failover->write(); - return; - } - - public function init(){ - $origDisableSubsiteFilter = Subsite::$disable_subsite_filter; - Subsite::$disable_subsite_filter = true; - - parent::init(); - - Subsite::$disable_subsite_filter = $origDisableSubsiteFilter; - } -} diff --git a/code/extensions/CMSPageAddControllerExtension.php b/code/extensions/CMSPageAddControllerExtension.php index 8db4418..97f6309 100644 --- a/code/extensions/CMSPageAddControllerExtension.php +++ b/code/extensions/CMSPageAddControllerExtension.php @@ -1,4 +1,7 @@ 0'); - + // Migrate global-access data DB::query('UPDATE "Group" SET "AccessAllSubsites" = 1 WHERE "SubsiteID" = 0'); - + // Move the field out of the way so that this migration doesn't get executed again DB::get_schema()->renameField('Group', 'SubsiteID', '_obsolete_SubsiteID'); - + // No subsite access on anything means that we've just installed the subsites module. // Make all previous groups global-access groups - } else if(!DB::query('SELECT "Group"."ID" FROM "Group" + } else if(!DB::query('SELECT "Group"."ID" FROM "Group" LEFT JOIN "Group_Subsites" ON "Group_Subsites"."GroupID" = "Group"."ID" AND "Group_Subsites"."SubsiteID" > 0 WHERE "AccessAllSubsites" = 1 OR "Group_Subsites"."GroupID" IS NOT NULL ')->value()) { - + DB::query('UPDATE "Group" SET "AccessAllSubsites" = 1'); } } - + function updateCMSFields(FieldList $fields) { if($this->owner->canEdit() ){ // i18n tab @@ -58,11 +70,11 @@ class GroupSubsites extends DataExtension implements PermissionProvider { // Prevent XSS injection $subsiteMap = Convert::raw2xml($subsiteMap); - + // Interface is different if you have the rights to modify subsite group values on // all subsites if(isset($subsiteMap[0])) { - $fields->addFieldToTab("Root.Subsites", new OptionsetField("AccessAllSubsites", + $fields->addFieldToTab("Root.Subsites", new OptionsetField("AccessAllSubsites", _t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'), array( 1 => _t('GroupSubsites.ACCESSALL', "All subsites"), @@ -76,11 +88,11 @@ class GroupSubsites extends DataExtension implements PermissionProvider { } else { if (sizeof($subsiteMap) <= 1) { - $fields->addFieldToTab("Root.Subsites", new ReadonlyField("SubsitesHuman", + $fields->addFieldToTab("Root.Subsites", new ReadonlyField("SubsitesHuman", _t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'), reset($subsiteMap))); } else { - $fields->addFieldToTab("Root.Subsites", new CheckboxSetField("Subsites", + $fields->addFieldToTab("Root.Subsites", new CheckboxSetField("Subsites", _t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'), $subsiteMap)); } @@ -116,7 +128,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider { /*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID; else */$subsiteID = (int)Subsite::currentSubsiteID(); - + // Don't filter by Group_Subsites if we've already done that $hasGroupSubsites = false; foreach($query->getFrom() as $item) { @@ -125,10 +137,10 @@ class GroupSubsites extends DataExtension implements PermissionProvider { break; } } - + if(!$hasGroupSubsites) { if($subsiteID) { - $query->addLeftJoin("Group_Subsites", "\"Group_Subsites\".\"GroupID\" + $query->addLeftJoin("Group_Subsites", "\"Group_Subsites\".\"GroupID\" = \"Group\".\"ID\" AND \"Group_Subsites\".\"SubsiteID\" = $subsiteID"); $query->addWhere("(\"Group_Subsites\".\"SubsiteID\" IS NOT NULL OR \"Group\".\"AccessAllSubsites\" = 1)"); @@ -136,7 +148,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider { $query->addWhere("\"Group\".\"AccessAllSubsites\" = 1"); } } - + // WORKAROUND for databases that complain about an ORDER BY when the column wasn't selected (e.g. SQL Server) $select=$query->getSelect(); if(isset($select[0]) && !$select[0] == 'COUNT(*)') { @@ -152,7 +164,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider { $this->owner->AccessAllSubsites = 1; } } - + function onAfterWrite() { // New record test approximated by checking whether the ID has changed. // Note also that the after write test is only used when we're on a subsite @@ -166,7 +178,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider { // Find the sites that this group belongs to and the sites where we have appropriate perm. $accessibleSites = Subsite::accessible_sites('CMS_ACCESS_SecurityAdmin')->column('ID'); $linkedSites = $this->owner->Subsites()->column('ID'); - + // We are allowed to access this site if at we have CMS_ACCESS_SecurityAdmin permission on // at least one of the sites return (bool)array_intersect($accessibleSites, $linkedSites); diff --git a/code/extensions/LeftAndMainSubsites.php b/code/extensions/LeftAndMainSubsites.php index ae07712..840168f 100644 --- a/code/extensions/LeftAndMainSubsites.php +++ b/code/extensions/LeftAndMainSubsites.php @@ -1,4 +1,19 @@ duplicateToSubsite($subsite->ID, true); $response = $this->owner->getResponse(); diff --git a/code/extensions/SiteConfigSubsites.php b/code/extensions/SiteConfigSubsites.php index abc5474..f2d9979 100644 --- a/code/extensions/SiteConfigSubsites.php +++ b/code/extensions/SiteConfigSubsites.php @@ -1,5 +1,11 @@ 'Subsite', // The subsite that this page belongs to ); - + /** * Update any requests to limit the results to the current site */ diff --git a/code/extensions/SiteTreeSubsites.php b/code/extensions/SiteTreeSubsites.php index 9c3bab4..e99af73 100644 --- a/code/extensions/SiteTreeSubsites.php +++ b/code/extensions/SiteTreeSubsites.php @@ -1,5 +1,20 @@ 'SiteTree' // Stored separately, as the logic for URL rewriting is different + 'CrossSubsiteLinkTracking' => 'SilverStripe\\CMS\\Model\\SiteTree' // Stored separately, as the logic for URL rewriting is different ); private static $many_many_extraFields = array( @@ -21,14 +36,14 @@ class SiteTreeSubsites extends DataExtension { if($this->owner->SubsiteID == 0) return true; return false; } - + /** * Update any requests to limit the results to the current site */ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { if(Subsite::$disable_subsite_filter) return; if($dataQuery->getQueryParam('Subsite.filter') === false) return; - + // If you're querying by ID, ignore the sub-site - this is a bit ugly... // if(!$query->where || (strpos($query->where[0], ".\"ID\" = ") === false && strpos($query->where[0], ".`ID` = ") === false && strpos($query->where[0], ".ID = ") === false && strpos($query->where[0], "ID = ") !== 0)) { if($query->filtersOnID()) return; @@ -47,10 +62,10 @@ class SiteTreeSubsites extends DataExtension { break; } } - + function onBeforeWrite() { if(!$this->owner->ID && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID(); - + parent::onBeforeWrite(); } @@ -58,7 +73,7 @@ class SiteTreeSubsites extends DataExtension { $subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain"); $subsitesMap = array(); if($subsites && $subsites->Count()) { - $subsitesMap = $subsites->map('ID', 'Title'); + $subsitesMap = $subsites->map('ID', 'Title')->toArray(); unset($subsitesMap[$this->owner->SubsiteID]); } @@ -68,8 +83,8 @@ class SiteTreeSubsites extends DataExtension { $fields->addFieldToTab( 'Root.Main', new DropdownField( - "CopyToSubsiteID", - _t('SiteTreeSubsites.CopyToSubsite', "Copy page to subsite"), + "CopyToSubsiteID", + _t('SiteTreeSubsites.CopyToSubsite', "Copy page to subsite"), $subsitesMap, '' ) @@ -77,31 +92,30 @@ class SiteTreeSubsites extends DataExtension { $fields->addFieldToTab( 'Root.Main', $copyAction = new InlineFormAction( - "copytosubsite", + "copytosubsite", _t('SiteTreeSubsites.CopyAction', "Copy") ) ); - $copyAction->includeDefaultJS(false); } // replace readonly link prefix $subsite = $this->owner->Subsite(); - $nested_urls_enabled = Config::inst()->get('SiteTree', 'nested_urls'); + $nested_urls_enabled = Config::inst()->get('SilverStripe\\CMS\\Model\\SiteTree', 'nested_urls'); if($subsite && $subsite->ID) { $baseUrl = Director::protocol() . $subsite->domain() . '/'; $baseLink = Controller::join_links ( $baseUrl, ($nested_urls_enabled && $this->owner->ParentID ? $this->owner->Parent()->RelativeLink(true) : null) ); - + $urlsegment = $fields->dataFieldByName('URLSegment'); $urlsegment->setURLPrefix($baseLink); } } - + function alternateSiteConfig() { if(!$this->owner->SubsiteID) return false; - $sc = DataObject::get_one('SiteConfig', '"SubsiteID" = ' . $this->owner->SubsiteID); + $sc = DataObject::get_one('SilverStripe\\SiteConfig\\SiteConfig', '"SubsiteID" = ' . $this->owner->SubsiteID); if(!$sc) { $sc = new SiteConfig(); $sc->SubsiteID = $this->owner->SubsiteID; @@ -111,18 +125,18 @@ class SiteTreeSubsites extends DataExtension { } return $sc; } - + /** * Only allow editing of a page if the member satisfies one of the following conditions: * - Is in a group which has access to the subsite this page belongs to * - Is in a group with edit permissions on the "main site" - * + * * @return boolean */ function canEdit($member = null) { if(!$member) $member = Member::currentUser(); - + // Find the sites that this user has access to $goodSites = Subsite::accessible_sites('CMS_ACCESS_CMSMain',true,'all',$member)->column('ID'); @@ -140,25 +154,25 @@ class SiteTreeSubsites extends DataExtension { // Return true if they have access to this object's site if(!(in_array(0, $goodSites) || in_array($subsiteID, $goodSites))) return false; } - + /** * @return boolean */ function canDelete($member = null) { if(!$member && $member !== FALSE) $member = Member::currentUser(); - + return $this->canEdit($member); } - + /** * @return boolean */ function canAddChildren($member = null) { if(!$member && $member !== FALSE) $member = Member::currentUser(); - + return $this->canEdit($member); } - + /** * @return boolean */ @@ -252,7 +266,7 @@ class SiteTreeSubsites extends DataExtension { $subsite = Subsite::currentSubsite(); if($subsite && $subsite->Theme){ - Config::inst()->update('SSViewer', 'theme', Subsite::currentSubsite()->Theme); + Config::inst()->update('SilverStripe\\View\\SSViewer', 'theme', Subsite::currentSubsite()->Theme); } } @@ -293,22 +307,22 @@ class SiteTreeSubsites extends DataExtension { // Set LinkTracking appropriately $links = HTTP::getLinksIn($this->owner->Content); $linkedPages = array(); - + if($links) foreach($links as $link) { if(substr($link, 0, strlen('http://')) == 'http://') { $withoutHttp = substr($link, strlen('http://')); if(strpos($withoutHttp, '/') && strpos($withoutHttp, '/') < strlen($withoutHttp)) { $domain = substr($withoutHttp, 0, strpos($withoutHttp, '/')); $rest = substr($withoutHttp, strpos($withoutHttp, '/') + 1); - + $subsiteID = Subsite::getSubsiteIDForDomain($domain); if($subsiteID == 0) continue; // We have no idea what the domain for the main site is, so cant track links to it $origDisableSubsiteFilter = Subsite::$disable_subsite_filter; Subsite::disable_subsite_filter(true); - $candidatePage = DataObject::get_one("SiteTree", "\"URLSegment\" = '" . Convert::raw2sql(urldecode( $rest)) . "' AND \"SubsiteID\" = " . $subsiteID, false); + $candidatePage = DataObject::get_one("SilverStripe\\CMS\\Model\\SiteTree", "\"URLSegment\" = '" . Convert::raw2sql(urldecode( $rest)) . "' AND \"SubsiteID\" = " . $subsiteID, false); Subsite::disable_subsite_filter($origDisableSubsiteFilter); - + if($candidatePage) { $linkedPages[] = $candidatePage->ID; } else { @@ -317,17 +331,17 @@ class SiteTreeSubsites extends DataExtension { } } } - + $this->owner->CrossSubsiteLinkTracking()->setByIDList($linkedPages); } - + /** * Return a piece of text to keep DataObject cache keys appropriately specific */ function cacheKeyComponent() { return 'subsite-'.Subsite::currentSubsiteID(); } - + /** * @param Member * @return boolean|null diff --git a/code/extensions/SubsiteMenuExtension.php b/code/extensions/SubsiteMenuExtension.php index aab9af2..fd0d003 100644 --- a/code/extensions/SubsiteMenuExtension.php +++ b/code/extensions/SubsiteMenuExtension.php @@ -1,5 +1,7 @@ subsiteID; } - function tree(SS_HTTPRequest $request) { + function tree(HTTPRequest $request) { $oldSubsiteID = Session::get('SubsiteID'); Session::set('SubsiteID', $this->subsiteID); diff --git a/code/model/Subsite.php b/code/model/Subsite.php index ca77cca..62baa20 100644 --- a/code/model/Subsite.php +++ b/code/model/Subsite.php @@ -1,4 +1,31 @@ to the request. @@ -9,8 +36,8 @@ class Subsite extends DataObject { /** * @var $use_session_subsiteid Boolean Set to TRUE when using the CMS and FALSE - * when browsing the frontend of a website. - * + * when browsing the frontend of a website. + * * @todo Remove flag once the Subsite CMS works without session state, * similarly to the Translatable module. */ @@ -21,7 +48,7 @@ class Subsite extends DataObject { * to limit DataObject::get*() calls to a specific subsite. Useful for debugging. */ public static $disable_subsite_filter = false; - + /** * Allows you to force a specific subsite ID, or comma separated list of IDs. * Only works for reading. An object cannot be written to more than 1 subsite. @@ -33,10 +60,10 @@ class Subsite extends DataObject { * @var boolean */ public static $write_hostmap = true; - + /** * Memory cache of accessible sites - * + * * @array */ private static $_cache_accessible_sites = array(); @@ -54,7 +81,7 @@ class Subsite extends DataObject { * are listed. */ private static $allowed_themes = array(); - + /** * @var Boolean If set to TRUE, don't assume 'www.example.com' and 'example.com' are the same. * Doesn't affect wildcard matching, so '*.example.com' will match 'www.example.com' (but not 'example.com') @@ -78,13 +105,13 @@ class Subsite extends DataObject { /** * Set allowed themes - * + * * @param array $themes - Numeric array of all themes which are allowed to be selected for all subsites. */ public static function set_allowed_themes($themes) { self::$allowed_themes = $themes; } - + /** * Gets the subsite currently set in the session. * @@ -124,7 +151,7 @@ class Subsite extends DataObject { return (int)$id; } - + /** * Switch to another subsite through storing the subsite identifier in the current PHP session. * Only takes effect when {@link Subsite::$use_session_subsiteid} is set to TRUE. @@ -151,13 +178,13 @@ class Subsite extends DataObject { Permission::flush_permission_cache(); } - + /** * Get a matching subsite for the given host, or for the current HTTP_HOST. * Supports "fuzzy" matching of domains by placing an asterisk at the start of end of the string, * for example matching all subdomains on *.example.com with one subsite, * and all subdomains on *.example.org on another. - * + * * @param $host The host to find the subsite for. If not specified, $_SERVER['HTTP_HOST'] is used. * @return int Subsite ID */ @@ -176,7 +203,7 @@ class Subsite extends DataObject { $SQL_host = Convert::raw2sql($host); $matchingDomains = DataObject::get( - "SubsiteDomain", + "SubsiteDomain", "'$SQL_host' LIKE replace(\"SubsiteDomain\".\"Domain\",'*','%')", "\"IsPrimary\" DESC" )->innerJoin('Subsite', "\"Subsite\".\"ID\" = \"SubsiteDomain\".\"SubsiteID\" AND \"Subsite\".\"IsPublic\"=1"); @@ -210,7 +237,7 @@ class Subsite extends DataObject { } /** - * + * * @param string $className * @param string $filter * @param string $sort @@ -230,7 +257,7 @@ class Subsite extends DataObject { public static function disable_subsite_filter($disabled = true) { self::$disable_subsite_filter = $disabled; } - + /** * Flush caches on database reset */ @@ -238,7 +265,7 @@ class Subsite extends DataObject { self::$_cache_accessible_sites = array(); self::$_cache_subsite_for_domain = array(); } - + /** * Return all subsites, regardless of permissions (augmented with main site). * @@ -270,7 +297,7 @@ class Subsite extends DataObject { // Rationalise member arguments if(!$member) $member = Member::currentUser(); if(!$member) return new ArrayList(); - if(!is_object($member)) $member = DataObject::get_by_id('Member', $member); + if(!is_object($member)) $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); $subsites = new ArrayList(); @@ -308,12 +335,12 @@ class Subsite extends DataObject { // Rationalise member arguments if(!$member) $member = Member::currentUser(); if(!$member) return new ArrayList(); - if(!is_object($member)) $member = DataObject::get_by_id('Member', $member); + if(!is_object($member)) $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); - // Rationalise permCode argument + // Rationalise permCode argument if(is_array($permCode)) $SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'"; else $SQL_codes = "'" . Convert::raw2sql($permCode) . "'"; - + // Cache handling $cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle; if(isset(self::$_cache_accessible_sites[$cacheKey])) { @@ -352,19 +379,19 @@ class Subsite extends DataObject { if(!is_array($permCode)) $permCode = array($permCode); if(self::hasMainSitePermission($member, $permCode)) { $subsites=$subsites->toArray(); - + $mainSite = new Subsite(); $mainSite->Title = $mainSiteTitle; array_unshift($subsites, $mainSite); $subsites=ArrayList::create($subsites); } } - + self::$_cache_accessible_sites[$cacheKey] = $subsites; return $subsites; } - + /** * Write a host->domain map to subsites/host-map.php * @@ -375,22 +402,22 @@ class Subsite extends DataObject { */ public static function writeHostMap($file = null) { if (!self::$write_hostmap) return; - + if (!$file) $file = Director::baseFolder().'/subsites/host-map.php'; $hostmap = array(); - + $subsites = DataObject::get('Subsite'); - + if ($subsites) foreach($subsites as $subsite) { $domains = $subsite->Domains(); if ($domains) foreach($domains as $domain) { $domainStr = $domain->Domain; if(!self::$strict_subdomain_matching) $domainStr = preg_replace('/^www\./', '', $domainStr); - $hostmap[$domainStr] = $subsite->domain(); + $hostmap[$domainStr] = $subsite->domain(); } if ($subsite->DefaultSite) $hostmap['default'] = $subsite->domain(); } - + $data = "ID; - + // Count this user's groups which can access the main site $groupCount = DB::query(" SELECT COUNT(\"Permission\".\"ID\") @@ -453,7 +480,7 @@ class Subsite extends DataObject { // There has to be at least one that allows access. return ($groupCount + $roleCount > 0); } - + /** * * @var array @@ -468,7 +495,7 @@ class Subsite extends DataObject { // Used to hide unfinished/private subsites from public view. // If unset, will default to true 'IsPublic' => 'Boolean', - + // Comma-separated list of disallowed page types 'PageTypeBlacklist' => 'Text', ); @@ -480,13 +507,13 @@ class Subsite extends DataObject { private static $has_many = array( 'Domains' => 'SubsiteDomain', ); - + /** * * @var array */ private static $belongs_many_many = array( - "Groups" => "Group", + "Groups" => "SilverStripe\\Security\\Group", ); /** @@ -504,15 +531,15 @@ class Subsite extends DataObject { private static $searchable_fields = array( 'Title', 'Domains.Domain', - 'IsPublic', + 'IsPublic', ); - + /** * * @var string */ private static $default_sort = "\"Title\" ASC"; - + /** * @todo Possible security issue, don't grant edit permissions to everybody. * @return boolean @@ -523,30 +550,30 @@ class Subsite extends DataObject { /** * Show the configuration fields for each subsite - * + * * @return FieldList */ public function getCMSFields() { if($this->ID!=0) { $domainTable = new GridField( - "Domains", - _t('Subsite.DomainsListTitle',"Domains"), - $this->Domains(), + "Domains", + _t('Subsite.DomainsListTitle',"Domains"), + $this->Domains(), GridFieldConfig_RecordEditor::create(10) ); }else { $domainTable = new LiteralField( - 'Domains', + 'Domains', '
'._t('Subsite.DOMAINSAVEFIRST', 'You can only add domains after saving for the first time').'
' ); } - + $languageSelector = new DropdownField( - 'Language', + 'Language', $this->fieldLabel('Language'), i18n::get_common_locales() ); - + $pageTypeMap = array(); $pageTypes = SiteTree::page_type_classes(); foreach($pageTypes as $pageType) { @@ -559,11 +586,12 @@ class Subsite extends DataObject { new Tab( 'Configuration', _t('Subsite.TabTitleConfig', 'Configuration'), - new HeaderField($this->getClassName() . ' configuration', 2), + new HeaderField('ConfigurationHeader', $this->getClassName() . ' configuration', 2), new TextField('Title', $this->fieldLabel('Title'), $this->Title), - + new HeaderField( - _t('Subsite.DomainsHeadline',"Domains for this subsite") + 'DomainsHeader', + _t('Subsite.DomainsHeadline', "Domains for this subsite") ), $domainTable, $languageSelector, @@ -572,8 +600,8 @@ class Subsite extends DataObject { new CheckboxField('IsPublic', $this->fieldLabel('IsPublic'), $this->IsPublic), new DropdownField('Theme',$this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme), - - + + new LiteralField( 'PageTypeBlacklistToggle', sprintf( @@ -582,7 +610,7 @@ class Subsite extends DataObject { ) ), new CheckboxSetField( - 'PageTypeBlacklist', + 'PageTypeBlacklist', false, $pageTypeMap ) @@ -597,9 +625,9 @@ class Subsite extends DataObject { $this->extend('updateCMSFields', $fields); return $fields; } - + /** - * + * * @param boolean $includerelations * @return array */ @@ -617,10 +645,10 @@ class Subsite extends DataObject { return $labels; } - + /** * Return the themes that can be used with this subsite, as an array of themecode => description - * + * * @return array */ public function allowedThemes() { @@ -652,7 +680,7 @@ class Subsite extends DataObject { } /** - * + * * @return ValidationResult */ public function validate() { @@ -672,11 +700,11 @@ class Subsite extends DataObject { Subsite::writeHostMap(); parent::onAfterWrite(); } - + /** * Return the primary domain of this site. Tries to "normalize" the domain name, * by replacing potential wildcards. - * + * * @return string The full domain name of this subsite (without protocol prefix) */ public function domain() { @@ -692,18 +720,18 @@ class Subsite extends DataObject { $domain = preg_replace('/^\*\./',"subsite.", $domain); // *Only* removes "intermediate" subdomains, so 'subdomain.www.domain.com' becomes 'subdomain.domain.com' $domain = str_replace('.www.','.', $domain); - + return $domain; } - + // SubsiteID = 0 is often used to refer to the main site, just return $_SERVER['HTTP_HOST'] } else { return $_SERVER['HTTP_HOST']; } } - + /** - * + * * @return string - The full domain name of this subsite (without protocol prefix) */ public function getPrimaryDomain() { @@ -711,8 +739,8 @@ class Subsite extends DataObject { } /** - * - * @return string + * + * @return string */ public function absoluteBaseURL() { return "http://" . $this->domain() . Director::baseURL(); @@ -727,8 +755,8 @@ class Subsite extends DataObject { /** * Javascript admin action to duplicate this subsite - * - * @return string - javascript + * + * @return string - javascript */ public function adminDuplicate() { $newItem = $this->duplicate(); @@ -737,7 +765,7 @@ class Subsite extends DataObject { 'Created a copy of {title}', array('title' => Convert::raw2js($this->Title)) ); - + return <<