Added page function + needed files & debug

This commit is contained in:
2026-04-30 01:14:13 +01:00
parent 2115a94a1f
commit 29c112c8d5
6 changed files with 116 additions and 6 deletions

View File

@@ -1,4 +1,6 @@
<?php
// CHECKING ERROR ENV AND PRINT RESULT
function error_env($option){
global $env;
if (empty($env)){
@@ -16,7 +18,106 @@
}else{
echo "ERROR: Wrong attribute in declared in the function!";
die;
}
}
function php_pages($option=null, $domain_shows=null){
// Required files or shows error if debug has been set to on.
if ($option == "error"){
$required_pages=[
PAGES_FOLD . "404.php",
PAGES_FOLD . "home.php"
];
$missing_pages=[];
foreach($required_pages as $required){
if (! file_exists($required)){
array_push($missing_pages, $required);
}
}
if (! empty($missing_pages)){
if (DEBUG){
echo "<h1>ERROR: Missing Required Pages:</h1>";
echo "<ul>";
foreach ($missing_pages as $pagepath){
echo "<li>Required file '" . $pagepath . "' is missing!</li>";
}
echo "</ul>";
}
die("Required pages are missing!.");
}
}
if (isset($_GET["page"])){
// ---- OPTIONS IF PAGE HAS BEEN DECLARED ----
$pagecheck=$_GET["page"];
if (empty($pagecheck)){
$page="home";
}elseif(file_exists(PAGES_FOLD . $pagecheck . ".php")){
$page=$pagecheck;
}else{
$page="404";
}
// title for pages
if ( $domain_shows == "show" ){
$page_title=DOMAIN . " | " . ucfirst($page);
}else{
$page_title= ucfirst($page);
}
// return call
switch($option){
case "return_page":
return $page;
break;
case "return_title":
return $page_title;
break;
case "page":
echo $page;
break;
case "title":
echo $page_title;
break;
default:
echo $page;
}
}else{
// ---- OPTIONS IF PAGE HAS NOT BEEN DECLARED ----
$page = "home";
// title for pages
if ( $domain_shows == "show" ){
$page_title=DOMAIN . " | " . ucfirst($page);
}else{
$page_title= ucfirst($page);
}
// return call
switch($option){
case "return_page":
return $page;
break;
case "return_title":
return $page_title;
break;
case "page":
echo $page;
break;
case "title":
echo $page_title;
break;
default:
echo $page;
}
}
}
}
?>

View File

@@ -1,5 +1,6 @@
<?php
$env="";
include("config/functions_init.php");
$env="generic";
switch($env){
/*------ DON'T TOUCH THIS PART ------ */
@@ -13,7 +14,7 @@
break;
/* ----------------------------------- */
default:
include("config/functions_init.php");
// Showing error page by default.
include("pages/env-error.php");
die;

View File

@@ -1,4 +1,7 @@
<?php
// -- GENERAL SETTING --
$debug="on";
// --- DB SETTINGS ---
$db_needed="no";
$db_debug="yes";
@@ -7,9 +10,14 @@ $db_name="database-name";
$db_user="database-user";
$db_pass="database-user-password";
//-------------------------------------------------------------------------------------
// --- DON'T CHANGE ALL THE CODE BELOW!!! ---
//-------------------------------------------------------------------------------------
// --- GENERAL SECTION CONFIGURATION
if ($debug == "on"){ define("DEBUG",true);} else { define("DEBUG", false); }
// --- DON'T CHANGE ALL THE CODE BELOW ---
// --- DB SECTION CONFIGURATION
if ($db_needed == "yes"){
define("DB_HOST", $db_host);
define("DB_USER", $db_user);
@@ -17,6 +25,5 @@ if ($db_needed == "yes"){
define("DB_NAME", $db_name);
define("DB_DEBUG", $db_debug);
require_once(CONFIG_FOLD . "db.php");
}
?>

View File

@@ -1,5 +1,6 @@
<?php
include("./config/init.php");
php_pages("error");
include(ROOT_DIR . "/templates/header.php");
include("./pages/home.php");
include("./templates/footer.php");

View File

View File

@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php include(INCLUDES_FOLD . "head_links.php"); ?>
<title>Document</title>
<title><?php php_pages("title", "show"); ?></title>
</head>
<body>
<header>