Navigation
This commit is contained in:
parent
e0e1097b49
commit
c28756c6fa
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
function get_protocol() :string {
|
||||
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
|
||||
return "https://";
|
||||
else
|
||||
return "http://";
|
||||
}
|
||||
|
||||
/* Pass either 'http://' or 'https://' asc parameter*/
|
||||
|
||||
function base_url(string $protocol = 'http://') {
|
||||
// Append the host(domain name, ip) to the URL.
|
||||
$url = $protocol . $_SERVER['HTTP_HOST'];
|
||||
return $url . '/';
|
||||
}
|
||||
|
||||
function parent_url(string $protocol = 'http://') : string {
|
||||
// Append the host(domain name, ip) to the URL.
|
||||
$url = $protocol . $_SERVER['HTTP_HOST'];
|
||||
// Append the requested resource location to the URL
|
||||
$url .= $_SERVER['REQUEST_URI'];
|
||||
// If URL is already the base
|
||||
if (base_url($protocol) === $url)
|
||||
return $url;
|
||||
return dirname($url);
|
||||
}
|
||||
|
40
index.php
40
index.php
|
@ -3,7 +3,9 @@
|
|||
<?php
|
||||
|
||||
include 'include/header.php';
|
||||
include 'include/utils.php';
|
||||
|
||||
/* Functions */
|
||||
function link_from_file(string $filename, string $name = null, string $css_class = null ) : string {
|
||||
// Check if css_class is null
|
||||
$css_class = $css_class ? " class=\"$css_class\"" : '';
|
||||
|
@ -31,29 +33,21 @@ function filter_files_dir($files_array, string $path) : array {
|
|||
return $ret_array;
|
||||
}
|
||||
|
||||
|
||||
// HTML Head
|
||||
echo($header);
|
||||
echo("\n");
|
||||
|
||||
?>
|
||||
<body>
|
||||
<h1>Magatzem de Dusk</h1>
|
||||
<?php
|
||||
|
||||
// Debug
|
||||
//var_dump($_SERVER);
|
||||
// Debug
|
||||
|
||||
// Debug
|
||||
//var_dump($files_in_folder);
|
||||
// Debug
|
||||
|
||||
/* Misc. Variables */
|
||||
$not_found_error = '<h1>File not found, error 404</h1>';
|
||||
|
||||
$basedir = 'content';
|
||||
$request_uri = $_SERVER['REQUEST_URI'];
|
||||
|
||||
$path = $basedir . $request_uri;
|
||||
/**/
|
||||
|
||||
// Check if URI is correct
|
||||
if(!is_dir($path)) {
|
||||
echo($not_found_error);
|
||||
die();
|
||||
|
@ -62,6 +56,14 @@ if(!is_dir($path)) {
|
|||
$files_in_folder = scandir($path);
|
||||
$resource_array = filter_files_dir($files_in_folder, $path);
|
||||
|
||||
/* Debug */
|
||||
/* var_dump($_SERVER);
|
||||
* var_dump($files_in_folder); */
|
||||
|
||||
?>
|
||||
<body>
|
||||
<h1>Magatzem de Dusk</h1>
|
||||
<?php
|
||||
// Show folder links
|
||||
{
|
||||
if(!empty($resource_array['dir'])) {
|
||||
|
@ -92,6 +94,18 @@ echo("\n");
|
|||
|
||||
echo("\n");
|
||||
|
||||
$base_url = base_url();
|
||||
$parent_url = parent_url();
|
||||
|
||||
//Navigation
|
||||
echo <<<NAV
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href={$base_url}>Inici</a></li>
|
||||
<li><a href={$parent_url}>Arrere</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
NAV;
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue