From 0f24e8322bee010e30ee4dfcfb922556262b984e Mon Sep 17 00:00:00 2001 From: Bryan Pedini Date: Thu, 17 Jan 2019 13:26:20 +0100 Subject: [PATCH] Improved speed and comprehensiveness Edited templates location, removed unnecessary CSS and JS files, moved the onePageApp style and scripts into respective files, modified variable names for better comprehension. TODO next: add comments to the code. --- css/hidden-scrollbar-GUI.css | 6 + index.php | 115 +- js/contact_me.js | 75 - js/contact_me.min.js | 7 - js/jqBootstrapValidation.js | 937 --- js/jqBootstrapValidation.min.js | 7 - js/onePageApp-sections-control.js | 38 + {tmpl => templates}/contact-form.phtml | 0 {tmpl => templates}/description.phtml | 0 {tmpl => templates}/home.phtml | 0 {tmpl => templates}/ideas.phtml | 0 {tmpl => templates}/projects.phtml | 0 vendor/bootstrap/js/bootstrap.bundle.js | 6818 ----------------- vendor/bootstrap/js/bootstrap.bundle.js.map | 1 - vendor/bootstrap/js/bootstrap.bundle.min.js | 7 - .../bootstrap/js/bootstrap.bundle.min.js.map | 1 - 16 files changed, 87 insertions(+), 7925 deletions(-) create mode 100644 css/hidden-scrollbar-GUI.css delete mode 100644 js/contact_me.js delete mode 100644 js/contact_me.min.js delete mode 100644 js/jqBootstrapValidation.js delete mode 100644 js/jqBootstrapValidation.min.js create mode 100644 js/onePageApp-sections-control.js rename {tmpl => templates}/contact-form.phtml (100%) rename {tmpl => templates}/description.phtml (100%) rename {tmpl => templates}/home.phtml (100%) rename {tmpl => templates}/ideas.phtml (100%) rename {tmpl => templates}/projects.phtml (100%) delete mode 100644 vendor/bootstrap/js/bootstrap.bundle.js delete mode 100644 vendor/bootstrap/js/bootstrap.bundle.js.map delete mode 100644 vendor/bootstrap/js/bootstrap.bundle.min.js delete mode 100644 vendor/bootstrap/js/bootstrap.bundle.min.js.map diff --git a/css/hidden-scrollbar-GUI.css b/css/hidden-scrollbar-GUI.css new file mode 100644 index 0000000..8898c09 --- /dev/null +++ b/css/hidden-scrollbar-GUI.css @@ -0,0 +1,6 @@ +html,body { + scrollbar-width: none; +} +::-webkit-scrollbar { + width: 0; +} \ No newline at end of file diff --git a/index.php b/index.php index d55bc1c..5470328 100644 --- a/index.php +++ b/index.php @@ -1,44 +1,60 @@ 'Previous', + $section_page_titles = [ + 0 => '', 1 => 'Home', 2 => 'About myself', 3 => 'What I\'ve done so far', 4 => 'Who I would like to be', - 5 => 'Contact me via webform' + 5 => 'Webform contact' ]; - if ( ! isset ( $_POST ['section'] ) || ! in_array ( $_POST ['section'], array_keys( $sections ) ) ) { - $section_title = 'Home'; + if ( ! isset ( $_POST ['section'] ) ) { + $requested_section_title = 'Home'; } else { - $section = $_POST ['section']; - if ( $section == 0 ) { + if ( ! in_array ( $_POST ['section'], array_keys( $section_page_titles ) ) ) { + $page_content_array = [ + 'status' => 400, + 'errorCode' => 'Bad Request', + 'errorText' => 'Requested section \'' . $_POST [ 'section' ] . '\' does not exist: do not attempt to compromise the website.', + ]; + $page_content_json = json_encode ( $page_content_array ); + header('Content-Type: application/json'); + echo $page_content_json; + exit; + } + $requested_section = $_POST ['section']; + if ( $requested_section == 0 ) { if ( isset ( $_SESSION [ 'section' ] ) ) { - $section = $_SESSION [ 'section' ]; + $requested_section = $_SESSION [ 'section' ]; } else { - $section = 1; + $requested_section = 1; } } - $_SESSION [ 'section' ] = $section; - $section_title = $sections [ $section ]; - $sections_content = [ - 1 => file_get_contents ( 'tmpl/home.phtml' ), - 2 => file_get_contents ( 'tmpl/description.phtml' ), - 3 => file_get_contents ( 'tmpl/projects.phtml' ), - 4 => file_get_contents ( 'tmpl/ideas.phtml' ), - 5 => file_get_contents ( 'tmpl/contact-form.phtml' ), + $_SESSION [ 'section' ] = $requested_section; + $requested_section_title = $section_page_titles [ $requested_section ]; + $section_templates = [ + 1 => file_get_contents ( 'templates/home.phtml' ), + 2 => file_get_contents ( 'templates/description.phtml' ), + 3 => file_get_contents ( 'templates/projects.phtml' ), + 4 => file_get_contents ( 'templates/ideas.phtml' ), + 5 => file_get_contents ( 'templates/contact-form.phtml' ), ]; - $arr_res = [ + $page_content_array = [ 'status' => 200, - 'pageTitle' => $section_title, - 'html' => $sections_content [ $section ] + 'pageTitle' => $requested_section_title, + 'html' => $section_templates [ $requested_section ] ]; - $res = json_encode($arr_res); + $page_content_json = json_encode($page_content_array); header('Content-Type: application/json'); - echo $res; + echo $page_content_json; exit; } ?> @@ -49,20 +65,13 @@ - <?=$section_title?> | Bryan Pedini + <?=$requested_section_title?> | Bryan Pedini - +