Skip to content

Commit 9115b1d

Browse files
authored
Merge pull request #10 from dconco/dev
Update configuration and file handling with Template
2 parents 4f7ac6f + dffa41d commit 9115b1d

File tree

12 files changed

+266
-37
lines changed

12 files changed

+266
-37
lines changed

.env

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
APP_NAME='PhpSlides'
2-
APP_VERSION='1.0.0'
3-
APP_SERVER='localhost'
1+
APP_NAME = 'PhpSlides'
2+
APP_VERSION = '1.0.0'
3+
APP_SERVER = 'localhost'
44

55
## DATABASE INFO
6-
DB_USER='root'
7-
DB_PASS='root'
8-
DB_HOST='localhost'
9-
DB_BASE='php_slides'
6+
DB_USER = 'root'
7+
DB_PASS = 'root'
8+
DB_HOST = 'localhost'
9+
DB_BASE = 'php_slides'
10+
11+
## Default host page
12+
ORIGIN = '//localhost'
13+
ORIGIN_ROOT = '//localhost/projects/php_slides'

App/Controller/RouteController.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,24 @@ protected static function config_file(): array|bool
4848
* |
4949
* -----------------------------------------------------------
5050
*/
51-
protected static function get_included_file($filename)
51+
public static function get_included_file($filename)
5252
{
5353
if (is_file($filename))
5454
{
55+
$file_contents = file_get_contents($filename);
56+
57+
$root = strtolower(Route::$root_dir . '/');
58+
$root = str_replace('c:\\', 'c:\\\\', $root);
59+
60+
$find = '/routes/route.php';
61+
$self = $_SERVER['PHP_SELF'];
62+
$view = substr_replace($self, '/', strrpos($self, $find), strlen($find));
63+
64+
$file_contents = str_replace('::root::view/', $view, $file_contents);
65+
$file_contents = str_replace('::root/', $root, $file_contents);
66+
5567
ob_start();
56-
include $filename;
68+
eval('?>' . $file_contents);
5769
$output = ob_get_contents();
5870
ob_end_clean();
5971

App/PhpSlides.php

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ final class Route extends Controller
4646
*/
4747
public static bool $log;
4848

49+
public static string $root_dir;
50+
4951

5052
/**
5153
* ------------------------------------------------------
@@ -61,11 +63,65 @@ public static function file_type(string $filename): bool|string
6163
{
6264
if (is_file($filename))
6365
{
66+
if (!extension_loaded('fileinfo'))
67+
{
68+
throw new Exception('Fileinfo extension is not enabled. Please enable it in your php.ini configuration.');
69+
}
70+
6471
$file_info = finfo_open(FILEINFO_MIME_TYPE);
65-
$file_type = mime_content_type($filename);
72+
$file_type = finfo_file($file_info, $filename);
6673
finfo_close($file_info);
6774

68-
return $file_type;
75+
$file_ext = explode('.', $filename);
76+
$file_ext = strtolower(end($file_ext));
77+
78+
if ($file_type === 'text/plain' || $file_type === 'application/octet-stream')
79+
{
80+
switch ($file_ext)
81+
{
82+
case 'css':
83+
return 'text/css';
84+
case 'csv':
85+
return 'text/csv';
86+
case 'htm':
87+
return 'text/htm';
88+
case 'html':
89+
return 'text/html';
90+
case 'js':
91+
return 'application/javascript';
92+
case 'pdf':
93+
return 'application/pdf';
94+
case 'doc':
95+
return 'application/msword';
96+
case 'docx':
97+
return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
98+
case 'xls':
99+
return 'application/vnd.ms-excel';
100+
case 'xlsx':
101+
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
102+
case 'json':
103+
return 'application/json';
104+
case 'md':
105+
return 'text/markdown';
106+
case 'ppt':
107+
return 'application/mspowerpoint';
108+
case 'pptx':
109+
return 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
110+
case 'swf':
111+
return 'application/x-shockwave-flash';
112+
case 'ai':
113+
return 'application/postscript';
114+
case 'odt':
115+
return 'application/vnd.oasis.opendocument.text';
116+
117+
default:
118+
return $file_type;
119+
}
120+
}
121+
else
122+
{
123+
return $file_type;
124+
}
69125
}
70126
else
71127
{
@@ -98,11 +154,15 @@ public static function config(bool $request_log = true)
98154
try
99155
{
100156
self::$log = $request_log;
157+
self::$root_dir = dirname(__DIR__);
101158

102159
$dir = dirname(__DIR__);
103160
$req = preg_replace("/(^\/)|(\/$)/", "", $_REQUEST["uri"]);
104161
$url = explode('/', $req);
105162

163+
$req_ext = explode('.', end($url));
164+
$req_ext = strtolower(end($req_ext));
165+
106166
$file = self::get_included_file($dir . '/public/' . $req);
107167
$file_type = $file ? self::file_type($dir . '/public/' . $req) : null;
108168

@@ -119,10 +179,6 @@ public static function config(bool $request_log = true)
119179
if (!empty($config_file) && $file_type != null)
120180
{
121181
$config = $config_file['public'];
122-
123-
// checks if the all URL / match the key in json
124-
$req_ext = explode('.', end($url));
125-
$req_ext = strtolower(end($req_ext));
126182
$accept = true;
127183

128184
// loop over the requested URL folders

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Use ***PhpSlides*** in creating of Very based secured Router, Api & database, created inbuilt template database which accepts - `MySql` & `Sqlite` database 🔥✨ can also setup other database.
66

7-
It has by default SQL injections, it prevents project from XXS attacks 🔐.
7+
It has by default in preventing SQL injections, it prevents project from XXS attacks & CSRF 🔐.
88

99
It's a good practice for a beginner in Php to start with ***PhpSlides***
1010

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dconco/php_slides",
3-
"description": "PhpSlides let you create a secured Routing in php and secured API, which contains SQL injections, and prevent from XSS attack.",
3+
"description": "PhpSlides let you create a secured Routing in php and secured API, which prevents SQL injections, and from XSS attack & CSRF.",
44
"homepage": "https://github.com/dconco/php_slides",
55
"version": "1.0.0",
66
"type": "project",

public/.gitignore

Whitespace-only changes.

public/styles/App.css

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,106 @@
1-
.s {
2-
color: blue;
1+
body {
2+
margin: 0;
3+
display: flex;
4+
height: 100svh;
5+
flex-flow: column;
6+
background: #bb9fe5;
7+
}
8+
9+
@keyframes ZoomIn {
10+
from {
11+
transform: scale(0, 0);
12+
}
13+
75% {
14+
transform: scale(1.2, 1.2);
15+
}
16+
to {
17+
transform: scale(1, 1);
18+
}
19+
}
20+
21+
.container {
22+
width: 70%;
23+
height: 70%;
24+
margin: auto;
25+
padding: 20px;
26+
display: flex;
27+
flex-flow: column;
28+
overflow-y: auto;
29+
overflow-x: hidden;
30+
border-radius: 15px;
31+
background: #6432c9;
32+
align-items: center;
33+
justify-content: space-between;
34+
box-shadow: 0px 0px 8px 10px #a176f8;
35+
animation: ZoomIn 0.8s ease-in-out forwards;
36+
}
37+
38+
.container::-webkit-scrollbar {
39+
width: 8px;
40+
border-radius: 5px;
41+
background: #bb9fe5;
42+
}
43+
44+
.container::-webkit-scrollbar-thumb {
45+
border-radius: 5px;
46+
background: #783fe9;
47+
}
48+
49+
.logo {
50+
width: 45%;
51+
}
52+
53+
.logo img {
54+
width: 100%;
55+
}
56+
57+
button.btn {
58+
border: none;
59+
margin: 0 auto;
60+
color: wheat;
61+
cursor: pointer;
62+
font-weight: bold;
63+
border-radius: 5px;
64+
text-transform: uppercase;
65+
transition: all 0.2s ease-in-out;
66+
padding: 10px 40px 10px 40px;
67+
box-shadow: 0 0 8px #a176f8;
68+
background: linear-gradient(50deg, darkblue, blue);
69+
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
70+
}
71+
72+
button.btn:hover {
73+
background: #783fe9;
74+
animation: ButtonAnim 0.5s ease-in-out forwards;
75+
}
76+
77+
@keyframes ButtonAnim {
78+
0% {
79+
transform: scale(1.3, 1.3);
80+
}
81+
100% {
82+
transform: scale(1, 1);
83+
}
84+
}
85+
86+
button.btn:active {
87+
background: #a176f8;
88+
}
89+
90+
h3.text {
91+
margin: auto;
92+
color: wheat;
93+
text-align: center;
94+
font-size: 50px;
95+
font-weight: 700;
96+
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
97+
}
98+
99+
.description {
100+
margin: auto;
101+
color: wheat;
102+
font-size: 15px;
103+
text-align: center;
104+
font-weight: 400;
105+
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
3106
}

routes/route.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* --------------------------------------------------------------------
2323
*/
2424

25-
Route::view('/dashboard', '::dashboard');
25+
Route::view('/dashboard', '::Dashboard');
2626
Route::redirect('/', '/dashboard');
2727

28-
Route::any('*', view::render('::errors::404'));
28+
Route::any('*', view::render('::Errors::404'));

views/.gitignore

Whitespace-only changes.

views/components/Header.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<meta http-equiv="content-type" content="text/html, charset=utf-8" />
2+
<meta name="viewport" content="width=device-width, initial-scale=1" />
3+
<meta name="title" content="PhpSlides | PHP Framework" />
4+
5+
<link rel="apple-touch-icon" href="::root::view/assets/logo-squared.png" sizes="1000x1000" />
6+
<link rel="shortcut icon" href="::root::view/assets/logo-squared.png" type="image/png" />
7+
<link rel="icon" href="::root::view/assets/logo-squared.png" type="image/png" />
8+
9+
<!-- CSS Links -->
10+
<link rel="stylesheet" type="text/css" href="::root::view/styles/App.css">

views/dashboard.view.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
1+
<!--
2+
| For an HTML page to render, php tag should not start the page, it'll render it as an PHP page
3+
| Instead write the <!doctype html> tag which declears HTML 5 then the <html> tag before writing any PHP codes,
4+
| then it'll evaluate the PHP codes in the HTML.
5+
| You can write PHP codes anywhere in the file but never start HTML page with PHP codes.
6+
-->
7+
18
<!DOCTYPE html>
2-
<html>
9+
<html lang="en">
10+
11+
<!-- PHP code start -->
12+
<?php
13+
14+
?>
15+
<!-- // End PHP code -->
316

417
<head>
5-
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
18+
<meta http-equiv="content-type" content="text/html, charset=utf-8" />
619
<meta name="viewport" content="width=device-width, initial-scale=1" />
7-
<title>Index Page</title>
20+
<meta name="title" content="PhpSlides | PHP Framework" />
21+
<title>Dashboard | PhpSlides</title>
22+
23+
<link rel="apple-touch-icon" href="::root::view/assets/logo-squared.png" sizes="1000x1000" />
24+
<link rel="shortcut icon" href="::root::view/assets/logo-squared.png" type="image/png" />
25+
<link rel="icon" href="::root::view/assets/logo-squared.png" type="image/png" />
26+
27+
<link rel="stylesheet" type="text/css" href="::root::view/styles/App.css">
828
</head>
929

1030
<body>
11-
<h1>Index Page</h1>
31+
<div class=" container">
32+
<div class="logo">
33+
<img src="::root::view/assets/svg/logo-no-background.svg" alt="PhpSlides Logo">
34+
</div>
35+
36+
<div class="description">
37+
<p>PhpSlides let you create a secured Routing in php and secured API, which prevents SQL injections, and from XSS attack & CSRF.</p>
38+
</div>
1239

13-
<a href="./login">Login</a>
14-
<br />
15-
<a href="./signup">Signup</a>
40+
<a href="./any"><button class="btn">Navigate To Not Found Page</button></a>
41+
</div>
1642
</body>
1743

1844
</html>

views/errors/404.view.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1+
<!--
2+
| For an HTML page to render, php tag should not start the page, it'll render it as an PHP page
3+
| Instead write the <!doctype html> tag which declears HTML 5 then the <html> tag before writing any PHP codes,
4+
| then it'll evaluate the PHP codes in the HTML.
5+
| You can write PHP codes anywhere in the file but never start HTML page with PHP codes.
6+
-->
7+
18
<!DOCTYPE html>
2-
<html>
3-
<head>
4-
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
5-
<meta name="viewport" content="width=device-width; initial-scale=1" />
6-
<title>404 | Page not Found</title>
7-
</head>
8-
<body>
9-
<h1>404 | Page not Found</h1>
10-
</body>
9+
<html lang="en">
10+
11+
<head>
12+
<?php
13+
use PhpSlides\Controller\RouteController;
14+
15+
// includes the Header.php file
16+
echo RouteController::get_included_file("::root/views/components/Header.php");
17+
?>
18+
19+
<title>404 | Page Not Found</title>
20+
</head>
21+
22+
<body>
23+
<div class="container">
24+
<h3 class="text">404 | Page Not Found</h3>
25+
<a href="::root::view/"><button class="btn">Navigate Back To Dashboard</button></a>
26+
</div>
27+
</body>
28+
1129
</html>

0 commit comments

Comments
 (0)