From 80a8e9033ecd3d4fdcab292c1f745f82fc634094 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Tue, 1 May 2018 12:59:53 +0100 Subject: [PATCH 1/3] Move navigator casting to static --- code/Controllers/ContentController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/Controllers/ContentController.php b/code/Controllers/ContentController.php index 187748b8..fe24d315 100644 --- a/code/Controllers/ContentController.php +++ b/code/Controllers/ContentController.php @@ -58,6 +58,10 @@ class ContentController extends Controller 'LoginForm' ); + private static $casting = array( + 'SilverStripeNavigator' => 'HTMLFragment', + ); + /** * The ContentController will take the URLSegment parameter from the URL and use that to look * up a SiteTree record. From ed17eb2bd805a991fdd0f09d3f82af30bc59d375 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Tue, 1 May 2018 13:00:11 +0100 Subject: [PATCH 2/3] Revert "FIX Correct SilverStripeNavigator correctly in templates" This reverts commit cf5a0984addf308d2cb10df9b67386be2a080f18. --- code/Controllers/ContentController.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/code/Controllers/ContentController.php b/code/Controllers/ContentController.php index fe24d315..43a6ed63 100644 --- a/code/Controllers/ContentController.php +++ b/code/Controllers/ContentController.php @@ -355,7 +355,7 @@ class ContentController extends Controller } $viewPageIn = _t('SilverStripe\\CMS\\Controllers\\ContentController.VIEWPAGEIN', 'View Page in:'); - $navigator = <<
@@ -370,7 +370,6 @@ class ContentController extends Controller
$message HTML; - return DBField::create_field('HTMLFragment', $navigator); // On live sites we should still see the archived message } else { @@ -379,9 +378,9 @@ HTML; /** @var DBDatetime $dateObj */ $dateObj = DBField::create_field('Datetime', $date); // $dateObj->setVal($date); - return DBField::create_field('HTMLFragment', "
" . + return "
" . _t('SilverStripe\\CMS\\Controllers\\ContentController.ARCHIVEDSITEFROM', 'Archived site from') . - "
" . $dateObj->Nice() . "
"); + "
" . $dateObj->Nice() . "
"; } } return null; From a393de8d8d80220cf1fb13423f1932d6740715f1 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 2 May 2018 11:54:59 +0100 Subject: [PATCH 3/3] Updating code style --- code/Controllers/ContentController.php | 76 +++++++++++++------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/code/Controllers/ContentController.php b/code/Controllers/ContentController.php index 43a6ed63..503946c6 100644 --- a/code/Controllers/ContentController.php +++ b/code/Controllers/ContentController.php @@ -50,17 +50,19 @@ class ContentController extends Controller protected $dataRecord; - private static $extensions = array('SilverStripe\\CMS\\Controllers\\OldPageRedirector'); + private static $extensions = [ + 'SilverStripe\\CMS\\Controllers\\OldPageRedirector', + ]; - private static $allowed_actions = array( + private static $allowed_actions = [ 'successfullyinstalled', 'deleteinstallfiles', // secured through custom code - 'LoginForm' - ); + 'LoginForm', + ]; - private static $casting = array( + private static $casting = [ 'SilverStripeNavigator' => 'HTMLFragment', - ); + ]; /** * The ContentController will take the URLSegment parameter from the URL and use that to look @@ -137,7 +139,7 @@ class ContentController extends Controller // If we've accessed the homepage as /home/, then we should redirect to /. if ($this->dataRecord instanceof SiteTree && RootURLController::should_be_on_root($this->dataRecord) - && (!isset($this->urlParams['Action']) || !$this->urlParams['Action'] ) + && (!isset($this->urlParams['Action']) || !$this->urlParams['Action']) && !$_POST && !$_FILES && !$this->redirectedTo() ) { $getVars = $_GET; @@ -180,7 +182,7 @@ class ContentController extends Controller public function handleRequest(HTTPRequest $request) { /** @var SiteTree $child */ - $child = null; + $child = null; $action = $request->param('Action'); // If nested URLs are enabled, and there is no action handler for the current request then attempt to pass @@ -192,10 +194,10 @@ class ContentController extends Controller Translatable::disable_locale_filter(); } // look for a page with this URLSegment - $child = SiteTree::get()->filter(array( + $child = SiteTree::get()->filter([ 'ParentID' => $this->ID, - 'URLSegment' => rawurlencode($action) - ))->first(); + 'URLSegment' => rawurlencode($action), + ])->first(); if (class_exists('Translatable')) { Translatable::enable_locale_filter(); } @@ -273,13 +275,13 @@ class ContentController extends Controller public function getMenu($level = 1) { if ($level == 1) { - $result = SiteTree::get()->filter(array( + $result = SiteTree::get()->filter([ "ShowInMenus" => 1, - "ParentID" => 0 - )); + "ParentID" => 0, + ]); } else { $parent = $this->data(); - $stack = array($parent); + $stack = [$parent]; if ($parent) { while (($parent = $parent->Parent()) && $parent->exists()) { @@ -287,12 +289,12 @@ class ContentController extends Controller } } - if (isset($stack[$level-2])) { - $result = $stack[$level-2]->Children(); + if (isset($stack[$level - 2])) { + $result = $stack[$level - 2]->Children(); } } - $visible = array(); + $visible = []; // Remove all entries the can not be viewed by the current user // We might need to create a show in menu permission @@ -344,13 +346,13 @@ class ContentController extends Controller if ($member) { $firstname = Convert::raw2xml($member->FirstName); $surname = Convert::raw2xml($member->Surname); - $logInMessage = _t('SilverStripe\\CMS\\Controllers\\ContentController.LOGGEDINAS', 'Logged in as') ." {$firstname} {$surname} - ". _t('SilverStripe\\CMS\\Controllers\\ContentController.LOGOUT', 'Log out'). ""; + $logInMessage = _t('SilverStripe\\CMS\\Controllers\\ContentController.LOGGEDINAS', 'Logged in as') . " {$firstname} {$surname} - " . _t('SilverStripe\\CMS\\Controllers\\ContentController.LOGOUT', 'Log out') . ""; } else { $logInMessage = sprintf( '%s - %s', _t('SilverStripe\\CMS\\Controllers\\ContentController.NOTLOGGEDIN', 'Not logged in'), Security::config()->login_url, - _t('SilverStripe\\CMS\\Controllers\\ContentController.LOGIN', 'Login') ."" + _t('SilverStripe\\CMS\\Controllers\\ContentController.LOGIN', 'Login') . "" ); } $viewPageIn = _t('SilverStripe\\CMS\\Controllers\\ContentController.VIEWPAGEIN', 'View Page in:'); @@ -371,7 +373,7 @@ class ContentController extends Controller $message HTML; - // On live sites we should still see the archived message + // On live sites we should still see the archived message } else { if ($date = Versioned::current_archived_date()) { Requirements::css('silverstripe/cms: client/dist/styles/SilverStripeNavigator.css'); @@ -483,19 +485,19 @@ HTML; } global $project; - $data = new ArrayData(array( + $data = new ArrayData([ 'Project' => Convert::raw2xml($project), 'Username' => Convert::raw2xml($this->getRequest()->getSession()->get('username')), 'Password' => Convert::raw2xml($this->getRequest()->getSession()->get('password')), - )); + ]); - return array( - "Title" => _t("SilverStripe\\CMS\\Controllers\\ContentController.INSTALL_SUCCESS", "Installation Successful!"), + return [ + "Title" => _t("SilverStripe\\CMS\\Controllers\\ContentController.INSTALL_SUCCESS", "Installation Successful!"), "Content" => $data->renderWith([ 'type' => 'Includes', - 'Install_successfullyinstalled' + 'Install_successfullyinstalled', ]), - ); + ]; } public function deleteinstallfiles() @@ -510,12 +512,12 @@ HTML; // We can't delete index.php as it might be necessary for URL routing without mod_rewrite. // There's no safe way to detect usage of mod_rewrite across webservers, // so we have to assume the file is required. - $installfiles = array( + $installfiles = [ 'install.php', 'config-form.css', 'config-form.html', - 'index.html' - ); + 'index.html', + ]; $unsuccessful = new ArrayList(); foreach ($installfiles as $installfile) { @@ -524,23 +526,23 @@ HTML; } if (file_exists(BASE_PATH . '/' . $installfile)) { - $unsuccessful->push(new ArrayData(array('File' => $installfile))); + $unsuccessful->push(new ArrayData(['File' => $installfile])); } } - $data = new ArrayData(array( + $data = new ArrayData([ 'Username' => Convert::raw2xml($this->getRequest()->getSession()->get('username')), 'Password' => Convert::raw2xml($this->getRequest()->getSession()->get('password')), - 'UnsuccessfulFiles' => $unsuccessful - )); + 'UnsuccessfulFiles' => $unsuccessful, + ]); $content->setValue($data->renderWith([ 'type' => 'Includes', - 'Install_deleteinstallfiles' + 'Install_deleteinstallfiles', ])); - return array( + return [ "Title" => $title, "Content" => $content, - ); + ]; } }