2022-01-26 23:25:24 +00:00
|
|
|
<!DOCTYPE html>
|
2022-01-27 14:10:00 +00:00
|
|
|
<html>
|
2022-01-26 23:25:24 +00:00
|
|
|
<?php
|
|
|
|
|
2022-01-27 14:10:00 +00:00
|
|
|
include 'include/header.php';
|
2022-01-27 15:31:53 +00:00
|
|
|
include 'include/utils.php';
|
2022-01-27 14:10:00 +00:00
|
|
|
|
2022-01-27 15:31:53 +00:00
|
|
|
/* Functions */
|
2022-01-26 23:25:24 +00:00
|
|
|
function link_from_file(string $filename, string $name = null, string $css_class = null ) : string {
|
|
|
|
// Check if css_class is null
|
2022-01-27 14:10:00 +00:00
|
|
|
$css_class = $css_class ? " class=\"$css_class\"" : '';
|
2022-01-26 23:25:24 +00:00
|
|
|
// Check if name is null
|
|
|
|
$name = $name ?: basename($filename);
|
2022-01-27 14:10:00 +00:00
|
|
|
return sprintf('<a href=%s%s>%s</a>', $filename, $css_class, $name);
|
2022-01-26 23:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function filter_files_dir($files_array, string $path) : array {
|
|
|
|
$ret_array = ['dir' => [], 'file' => []];
|
|
|
|
foreach($files_array as $file) {
|
2022-01-27 14:10:00 +00:00
|
|
|
// Hidden Files are not shown
|
|
|
|
if(substr($file, 0, 1) == '.') {
|
|
|
|
continue;
|
|
|
|
}
|
2022-01-26 23:25:24 +00:00
|
|
|
if(is_dir($path . $file)) {
|
|
|
|
// Append dir to array
|
|
|
|
$ret_array['dir'][] = $file;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Append file to array
|
|
|
|
$ret_array['file'][] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret_array;
|
|
|
|
}
|
|
|
|
|
2022-01-27 15:31:53 +00:00
|
|
|
|
|
|
|
// HTML Head
|
2022-01-27 14:10:00 +00:00
|
|
|
echo($header);
|
|
|
|
echo("\n");
|
|
|
|
|
2022-01-27 15:31:53 +00:00
|
|
|
/* Misc. Variables */
|
2022-01-26 23:30:51 +00:00
|
|
|
$not_found_error = '<h1>File not found, error 404</h1>';
|
|
|
|
|
|
|
|
$basedir = 'content';
|
|
|
|
$request_uri = $_SERVER['REQUEST_URI'];
|
|
|
|
|
|
|
|
$path = $basedir . $request_uri;
|
2022-01-27 15:31:53 +00:00
|
|
|
/**/
|
2022-01-26 23:30:51 +00:00
|
|
|
|
2022-01-27 15:31:53 +00:00
|
|
|
// Check if URI is correct
|
2022-01-26 23:40:40 +00:00
|
|
|
if(!is_dir($path)) {
|
|
|
|
echo($not_found_error);
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
$files_in_folder = scandir($path);
|
2022-01-26 23:25:24 +00:00
|
|
|
$resource_array = filter_files_dir($files_in_folder, $path);
|
|
|
|
|
2022-01-27 15:31:53 +00:00
|
|
|
/* Debug */
|
|
|
|
/* var_dump($_SERVER);
|
|
|
|
* var_dump($files_in_folder); */
|
|
|
|
|
|
|
|
?>
|
|
|
|
<body>
|
|
|
|
<h1>Magatzem de Dusk</h1>
|
|
|
|
<?php
|
2022-01-26 23:25:24 +00:00
|
|
|
// Show folder links
|
|
|
|
{
|
2022-01-27 14:10:00 +00:00
|
|
|
if(!empty($resource_array['dir'])) {
|
|
|
|
echo('<h2>Directoris</h2>');
|
|
|
|
}
|
|
|
|
echo('<ul>');
|
2022-01-26 23:25:24 +00:00
|
|
|
foreach($resource_array['dir'] as $dir) {
|
2022-01-27 14:10:00 +00:00
|
|
|
echo('<li>' . link_from_file($request_uri . $dir, null, "dir_link") . '</li>');
|
2022-01-26 23:25:24 +00:00
|
|
|
echo('<br/>');
|
|
|
|
}
|
2022-01-27 14:10:00 +00:00
|
|
|
echo('</ul>');
|
2022-01-26 23:25:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 14:10:00 +00:00
|
|
|
echo("\n");
|
|
|
|
|
2022-01-26 23:25:24 +00:00
|
|
|
//Show file links
|
|
|
|
{
|
2022-01-27 14:10:00 +00:00
|
|
|
if(!empty($resource_array['file'])) {
|
|
|
|
echo('<h2>Fitxers</h2>');
|
|
|
|
}
|
|
|
|
echo('<ul>');
|
2022-01-26 23:25:24 +00:00
|
|
|
foreach($resource_array['file'] as $file) {
|
2022-01-27 14:10:00 +00:00
|
|
|
echo('<li>' . link_from_file($request_uri . $file, null, 'file_link') . '</li>');
|
2022-01-26 23:25:24 +00:00
|
|
|
echo('<br/>');
|
|
|
|
}
|
2022-01-27 14:10:00 +00:00
|
|
|
echo('</ul>');
|
2022-01-26 23:25:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 14:10:00 +00:00
|
|
|
echo("\n");
|
2022-01-26 23:25:24 +00:00
|
|
|
|
2022-01-27 15:31:53 +00:00
|
|
|
$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;
|
2022-01-27 14:10:00 +00:00
|
|
|
?>
|
2022-01-26 23:25:24 +00:00
|
|
|
</body>
|
|
|
|
</html>
|