forked from binjuhor/html-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.php
46 lines (41 loc) · 1.1 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
function asset($file, $show = true)
{
$file_url = "resources/assets/{$file}";
if (!$show) {
return $file_url;
}
echo $file_url;
return '';
}
function getVar($key, $default = null)
{
$env = file_get_contents('.env');
$env = explode("\n", $env);
foreach ($env as $line) {
if (strpos($line, $key) !== false) {
return explode('=', $line)[1];
}
}
return $default;
}
function getPage()
{
$env = getVar('ENV', 'development');
if($env === 'development') { return isset($_REQUEST['f']) ? $_REQUEST['f'] : 'index'; }
if(isset($_REQUEST['f'])) { return $_REQUEST['f'] === '' ? 'index' : $_REQUEST['f'];}
$file = basename($_SERVER['REQUEST_URI']);
$page = pathinfo($file, PATHINFO_FILENAME);
return $page === '' ? 'index' : $page;
}
function route($part = '')
{
$env = getVar('ENV', 'development');
if($env === 'development' && ($part === 'index' || $part === '')) { return getVar('APP_URL'); }
if($env === 'development') { return getVar('APP_URL').'/?f='.$part; }
return $part !== '' ? $part.'.html' : 'index.html';
}
function active($part = '')
{
return getPage() === $part ? 'active' : '';
}