From 9acd97791a069bd390a79d81bee98e3deb61c03e Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 28 Apr 2017 07:33:07 +1200 Subject: [PATCH] Update code formatting for the SS3 PHPCS ruleset, separate Page_Controller to new file --- .editorconfig | 2 +- index.php | 56 +++++++++++++++++---------------- install.php | 7 +++-- mysite/_config.php | 4 +-- mysite/code/Page.php | 39 ++++------------------- mysite/code/Page_Controller.php | 29 +++++++++++++++++ phpcs.xml.dist | 33 ++++++++++--------- 7 files changed, 88 insertions(+), 82 deletions(-) create mode 100644 mysite/code/Page_Controller.php diff --git a/.editorconfig b/.editorconfig index 34ecfa8..d3832ba 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,7 +8,7 @@ root = true charset = utf-8 end_of_line = lf indent_size = 4 -indent_style = tab +indent_style = space insert_final_newline = true trim_trailing_whitespace = true diff --git a/index.php b/index.php index f45eb36..1522b47 100644 --- a/index.php +++ b/index.php @@ -15,7 +15,7 @@ */ // This is the URL of the script that everything must be viewed with. -define('BASE_SCRIPT_URL','index.php/'); +define('BASE_SCRIPT_URL', 'index.php/'); $ruLen = strlen($_SERVER['REQUEST_URI']); $snLen = strlen($_SERVER['SCRIPT_NAME']); @@ -23,26 +23,28 @@ $snLen = strlen($_SERVER['SCRIPT_NAME']); $isIIS = (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false); // IIS will populate server variables using one of these two ways -if($isIIS) { - if($_SERVER['REQUEST_URI'] == $_SERVER['SCRIPT_NAME']) { - $url = ""; - } else if($ruLen > $snLen && substr($_SERVER['REQUEST_URI'],0,$snLen+1) == ($_SERVER['SCRIPT_NAME'] . '/')) { - $url = substr($_SERVER['REQUEST_URI'],$snLen+1); - $url = strtok($url, '?'); - } else { - $url = $_SERVER['REQUEST_URI']; - if($url[0] == '/') $url = substr($url,1); - $url = strtok($url, '?'); - } +if ($isIIS) { + if ($_SERVER['REQUEST_URI'] == $_SERVER['SCRIPT_NAME']) { + $url = ""; + } elseif ($ruLen > $snLen && substr($_SERVER['REQUEST_URI'], 0, $snLen + 1) == ($_SERVER['SCRIPT_NAME'] . '/')) { + $url = substr($_SERVER['REQUEST_URI'], $snLen+1); + $url = strtok($url, '?'); + } else { + $url = $_SERVER['REQUEST_URI']; + if ($url[0] == '/') { + $url = substr($url, 1); + } + $url = strtok($url, '?'); + } // Apache will populate the server variables this way } else { - if($ruLen > $snLen && substr($_SERVER['REQUEST_URI'],0,$snLen+1) == ($_SERVER['SCRIPT_NAME'] . '/')) { - $url = substr($_SERVER['REQUEST_URI'],$snLen+1); - $url = strtok($url, '?'); - } else { - $url = ""; - } + if ($ruLen > $snLen && substr($_SERVER['REQUEST_URI'], 0, $snLen+1) == ($_SERVER['SCRIPT_NAME'] . '/')) { + $url = substr($_SERVER['REQUEST_URI'], $snLen+1); + $url = strtok($url, '?'); + } else { + $url = ""; + } } $_GET['url'] = $_REQUEST['url'] = $url; @@ -53,14 +55,14 @@ $fileName = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . $url; * This code is a very simple wrapper for sending files * Very quickly pass through references to files */ -if($url && file_exists($fileName)) { - $fileURL = (dirname($_SERVER['SCRIPT_NAME'])=='/'?'':dirname($_SERVER['SCRIPT_NAME'])) . '/' . $url; - if(isset($_SERVER['QUERY_STRING'])) { - $fileURL .= '?' . $_SERVER['QUERY_STRING']; - } - header($_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently'); - header("Location: $fileURL"); - die(); +if ($url && file_exists($fileName)) { + $fileURL = (dirname($_SERVER['SCRIPT_NAME'])=='/'?'':dirname($_SERVER['SCRIPT_NAME'])) . '/' . $url; + if (isset($_SERVER['QUERY_STRING'])) { + $fileURL .= '?' . $_SERVER['QUERY_STRING']; + } + header($_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently'); + header("Location: $fileURL"); + die(); } -require_once('framework/main.php'); +require_once 'framework/main.php'; diff --git a/install.php b/install.php index dd22f83..921103d 100644 --- a/install.php +++ b/install.php @@ -9,5 +9,8 @@ ************************************************************************************ ************************************************************************************/ -if (!file_exists('framework') || !file_exists('framework/_config.php')) include "install-frameworkmissing.html"; -else include('./framework/dev/install/install.php'); +if (!file_exists('framework') || !file_exists('framework/_config.php')) { + include 'install-frameworkmissing.html'; +} else { + include './framework/dev/install/install.php'; +} diff --git a/mysite/_config.php b/mysite/_config.php index c577542..2ddd6a0 100644 --- a/mysite/_config.php +++ b/mysite/_config.php @@ -6,7 +6,7 @@ $project = 'mysite'; global $database; $database = ''; -require_once('conf/ConfigureFromEnv.php'); +require_once 'conf/ConfigureFromEnv.php'; // Set the site locale -i18n::set_locale('en_US'); \ No newline at end of file +i18n::set_locale('en_US'); diff --git a/mysite/code/Page.php b/mysite/code/Page.php index 594536e..140e2e4 100755 --- a/mysite/code/Page.php +++ b/mysite/code/Page.php @@ -1,37 +1,10 @@ - * array ( - * 'action', // anyone can access this action - * 'action' => true, // same as above - * 'action' => 'ADMIN', // you must have ADMIN permissions to access this action - * 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true - * ); - * - * - * @var array - */ - private static $allowed_actions = array ( - ); - - public function init() { - parent::init(); - // You can include any CSS or JS required by your project here. - // See: http://doc.silverstripe.org/framework/en/reference/requirements - } +class Page extends SiteTree +{ + private static $db = array( + ); + private static $has_one = array( + ); } diff --git a/mysite/code/Page_Controller.php b/mysite/code/Page_Controller.php new file mode 100644 index 0000000..f661c42 --- /dev/null +++ b/mysite/code/Page_Controller.php @@ -0,0 +1,29 @@ + + * array ( + * 'action', // anyone can access this action + * 'action' => true, // same as above + * 'action' => 'ADMIN', // you must have ADMIN permissions to access this action + * 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true + * ); + * + * + * @var array + */ + private static $allowed_actions = array( + ); + + public function init() + { + parent::init(); + // You can include any CSS or JS required by your project here. + // See: http://doc.silverstripe.org/framework/en/reference/requirements + } +} diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 7004b66..38151e4 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,25 +1,24 @@ - Coding standard for SilverStripe 3.x + Coding standard for SilverStripe 3.x - - */vendor/* - */thirdparty/* - ^index.php + + */vendor/* + */thirdparty/* - - - + + + - - - - + + + + - - + + - - - + + +