From 315621892d2f6bec914fba8a03ea996973d25209 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 19 Jun 2018 13:47:15 +1200 Subject: [PATCH 1/4] FIX Double escaping subsites title in CMS menu --- src/Extensions/LeftAndMainSubsites.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Extensions/LeftAndMainSubsites.php b/src/Extensions/LeftAndMainSubsites.php index c3a57af..760623f 100644 --- a/src/Extensions/LeftAndMainSubsites.php +++ b/src/Extensions/LeftAndMainSubsites.php @@ -160,7 +160,7 @@ class LeftAndMainSubsites extends LeftAndMainExtension $output->push(ArrayData::create([ 'CurrentState' => $currentState, 'ID' => $subsite->ID, - 'Title' => Convert::raw2xml($subsite->Title) + 'Title' => $subsite->Title, ])); } From dc9d6de62dbea4d14d7b8e3b7d6b7ca01d7674e9 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 19 Jun 2018 15:43:09 +1200 Subject: [PATCH 2/4] FIX Do no provide input for canEdit or canPublish if no subsites exist --- src/Extensions/SiteTreeSubsites.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Extensions/SiteTreeSubsites.php b/src/Extensions/SiteTreeSubsites.php index e36bea5..de5fc2b 100644 --- a/src/Extensions/SiteTreeSubsites.php +++ b/src/Extensions/SiteTreeSubsites.php @@ -273,8 +273,10 @@ class SiteTreeSubsites extends DataExtension * - 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" * - * @param null $member - * @return bool + * If there are no subsites configured yet, this logic is skipped. + * + * @param Member|null $member + * @return bool|null */ public function canEdit($member = null) { @@ -282,6 +284,11 @@ class SiteTreeSubsites extends DataExtension $member = Security::getCurrentUser(); } + // Do not provide any input if there are no subsites configured + if (!Subsite::get()->count()) { + return null; + } + // Find the sites that this user has access to $goodSites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', true, 'all', $member)->column('ID'); @@ -329,8 +336,8 @@ class SiteTreeSubsites extends DataExtension } /** - * @param null $member - * @return bool + * @param Member|null $member + * @return bool|null */ public function canPublish($member = null) { From 153db12d42c2a67f1d74e128bc0a1ca127ef455c Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 20 Jun 2018 09:27:04 +1200 Subject: [PATCH 3/4] Switch count for exists() check for readability --- src/Extensions/SiteTreeSubsites.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Extensions/SiteTreeSubsites.php b/src/Extensions/SiteTreeSubsites.php index de5fc2b..8a7aef1 100644 --- a/src/Extensions/SiteTreeSubsites.php +++ b/src/Extensions/SiteTreeSubsites.php @@ -285,7 +285,7 @@ class SiteTreeSubsites extends DataExtension } // Do not provide any input if there are no subsites configured - if (!Subsite::get()->count()) { + if (!Subsite::get()->exists()) { return null; } From 5370bc8af68646634396a9d13202b39b6c3719b2 Mon Sep 17 00:00:00 2001 From: Dylan Wagstaff Date: Wed, 4 Jul 2018 14:43:01 +1200 Subject: [PATCH 4/4] FIX apply SubsiteID getVar to CMS Preview fetches A preview link must be loaded on the same domain the CMS is loaded through, which was previously causing issues when a page (identified via URLSegment) did not exist on the subsite domain. By _always_ prepending the identifier to the preview link, this should never happen. --- docs/en/technical.md | 2 +- javascript/LeftAndMain_Subsites.js | 2 +- src/Extensions/SiteTreeSubsites.php | 28 +++++++++++++++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/docs/en/technical.md b/docs/en/technical.md index cb705f1..27bfbe4 100644 --- a/docs/en/technical.md +++ b/docs/en/technical.md @@ -28,5 +28,5 @@ This method is called when a pages are being copied between the main site or ano ### alternateAbsoluteLink This method modifies the absolute link to contain the valid subsite domain -### alternatePreviewLink +### updatePreviewLink This method modifies the preview link for the CMS. diff --git a/javascript/LeftAndMain_Subsites.js b/javascript/LeftAndMain_Subsites.js index b1541ba..8dd2b24 100644 --- a/javascript/LeftAndMain_Subsites.js +++ b/javascript/LeftAndMain_Subsites.js @@ -101,7 +101,7 @@ /** * Update links and forms with GET/POST SubsiteID param, so we remaing on the current subsite. - * The initial link for the iframe comes from SiteTreeSubsites::alternatePreviewLink. + * The initial link for the iframe comes from SiteTreeSubsites::updatePreviewLink. * * This is done so we can use the CMS domain for displaying previews so we prevent single-origin * violations and SSL cert problems that come up when iframing content from a different URL. diff --git a/src/Extensions/SiteTreeSubsites.php b/src/Extensions/SiteTreeSubsites.php index 8a7aef1..488fef6 100644 --- a/src/Extensions/SiteTreeSubsites.php +++ b/src/Extensions/SiteTreeSubsites.php @@ -382,17 +382,31 @@ class SiteTreeSubsites extends DataExtension /** * Use the CMS domain for iframed CMS previews to prevent single-origin violations - * and SSL cert problems. - * @param null $action + * and SSL cert problems. Always set SubsiteID to avoid errors because a page doesn't + * exist on the CMS domain. + * + * @param string &$link + * @param string|null $action + * @return string + */ + public function updatePreviewLink(&$link, $action = null) + { + $url = Director::absoluteURL($this->owner->Link($action)); + $link = HTTP::setGetVar('SubsiteID', $this->owner->SubsiteID, $url); + return $link; + } + + /** + * This function is marked as deprecated for removal in 5.0.0 in silverstripe/cms + * so now simply passes execution to where the functionality exists for backwards compatiblity. + * + * @param string|null $action * @return string */ public function alternatePreviewLink($action = null) { - $url = Director::absoluteURL($this->owner->Link()); - if ($this->owner->SubsiteID) { - $url = HTTP::setGetVar('SubsiteID', $this->owner->SubsiteID, $url); - } - return $url; + $link = ''; + return $this->updatePreviewLink($link, $action); } /**