0
0

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.
This commit is contained in:
Bryan Pedini
2019-01-17 13:26:20 +01:00
parent b31908029a
commit 0f24e8322b
16 changed files with 87 additions and 7925 deletions

115
index.php
View File

@@ -1,44 +1,60 @@
<?php
session_set_cookie_params ( 1*24*60*60, "/" );
$session_timeout_days = 1;
$session_timeout_hours = 0;
$session_timeout_minutes = 0;
$session_timeout_seconds = 0;
$session_timeout = ($session_timeout_days*86400)+($session_timeout_hours*3600)+($session_timeout_minutes*60)+$session_timeout_seconds;
session_set_cookie_params ( $session_timeout, "/" );
session_start ();
$sections = [
0 => '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 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title id="page-title"><?=$section_title?> | Bryan Pedini</title>
<title id="page-title"><?=$requested_section_title?> | Bryan Pedini</title>
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<link href="css/clean-blog.min.css" rel="stylesheet">
<style>
html,body {
scrollbar-width: none;
}
::-webkit-scrollbar {
width: 0;
}
</style>
<link href="css/hidden-scrollbar-GUI.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light fixed-top" id="mainNav">
@@ -97,46 +106,8 @@
</div>
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="js/clean-blog.min.js"></script>
<script>
var $ = jQuery;
function getPageContent (section) {
$.ajax({
url: 'index.php',
method: 'POST',
datatype: 'JSON',
data: {
section: section,
},
success: function (data) {
if ( data.status == 200 ) {
$('#page-title').html(data.pageTitle + " | Bryan Pedini");
$('#user-content').html(data.html);
}
else {
console.log(data.status + ": " + data.errorText);
}
},
error: function (jqXHR, exception) {
console.log(jqXHR.status + ": " + jqXHR.responseText + " | - | " + exception);
},
});
}
$(function() {
$('#navbar-home').on('click', function (clickEvent) { getPageContent (1) } );
$('#navbar-description').on('click', function (clickEvent) { getPageContent (2) });
$('#navbar-work').on('click', function (clickEvent) { getPageContent (3) });
$('#navbar-ideas').on('click', function (clickEvent) { getPageContent (4) });
$('#navbar-contact-form').on('click', function (clickEvent) { getPageContent (5) });
$('#navbar-contact-email').on('click', function (clickEvent) { window.location.href = "mailto:bryanpedini@bryanpedini.it"; });
$('ul.nav li.dropdown').hover(function() {
$(this).find('.dropdown-menu').stop(true, true).fadeIn(500);
}, function() {
$(this).find('.dropdown-menu').stop(true, true).fadeOut(500);
});
getPageContent(0);
});
</script>
<script src="js/onePageApp-sections-control.js"></script>
</body>
</html>