route1.php
Dynamic request router for the LinuxFront Logistics application.
It inspects the requested file name and extension, then delegates to the appropriate handler: static JavaScript, site files, 404 page, popup templates, CMS pages, or the main site template.
Overview
This front-controller handles all incoming requests. It:
- Loads global configuration and template mappings.
- Parses the requested path into file name and extension.
- Routes
.jsassets to the correct directory. - Includes site files if they exist.
- Falls back to 404 if unmapped.
- Renders pages via
site_template.php,popup_template.php, orcms.phpbased on context .
Configuration Constants
Defined in inc/config.php, these constants determine directory paths and URL bases:
| Constant | Description |
|---|---|
| TEMPLATE_DIR | Root path to the template files (e.g. /var/www/tech-portals/fawv2-tech-templates/) |
| SITE_DIR | Root path to site-specific PHP files (e.g. /var/www/tech-portals/linuxfront-v2-logistics/) |
| TEMPLATE_JS_DIR | Relative path under TEMPLATE_DIR for JS assets (inc/scripts/) |
| SITE_JS_DIR | Relative path under SITE_DIR for JS assets (js/) |
| SITE_PATH | Base URL for site links (set from $_SERVER['SERVER_NAME']) |
| PROFILER | Toggle for performance tracing |
URL Parsing & Variables
Global setup in inc/template_vars.php populates:
$file_pathfrom$_SERVER['REQUEST_URI']or alternates.$currnt_file_name(basename of path).$currnt_template(filename without extension).$file_extension(e.g.php,js).$TEMPLATEarray mapping PHP pages to sub-template directories .
// Example extraction
$file_path_arr = explode("?", $file_path);
$path_parts = pathinfo($file_path_arr[0]);
$currnt_file_name = $path_parts["basename"];
$file_extension = $path_parts["extension"];
Routing Logic
<?php
include_once("inc/config.php");
if ($file_extension == 'js') {
// Serve JS from site or template directory
if (file_exists(SITE_DIR . SITE_JS_DIR . $currnt_file_name))
include_once(SITE_DIR . SITE_JS_DIR . $currnt_file_name);
else if (file_exists(TEMPLATE_DIR . TEMPLATE_JS_DIR . $currnt_file_name))
include_once(TEMPLATE_DIR . TEMPLATE_JS_DIR . $currnt_file_name);
else
echo "No File Exist";
exit;
}
// Serve site file if it exists
if (file_exists(SITE_DIR . $currnt_file_name)) {
include_once(SITE_DIR . $currnt_file_name);
exit;
}
// Unmapped pages → 404
if (!isset($TEMPLATE[$currnt_file_name])) {
include_once("404.php");
} else {
// Mapped pages → template renderer
// ...
}
?>
Conditional Template Inclusions
Once $TEMPLATE[$currnt_file_name] exists, routing falls into three rendering modes:
1. Popup Templates
For lightweight dialogs (e.g. address/product chooser), uses popup_template.php.
if (in_array($currnt_file_name, ['choose_address.php','choose_product.php'])) {
include_once("popup_template.php");
}
2. CMS Pages
Static content pages use cms.php. The script sets
$currentcmsPage to one of:
privacy_policyterms_and_conditionsnotification_of_infringement_dmca_policy
else if ($currnt_file_name == 'privacy_policy.php') {
$currentcmsPage = 'privacy_policy';
include_once("cms.php");
}
3. Default Site Template
All other mapped pages render within the main layout via site_template.php:
else {
include_once("site_template.php");
}
Flowchart of Request Routing
flowchart TD
A[Request Received] --> B[Include inc/config.php]
B --> C{Extension == 'js'?}
C -- Yes --> D[Check JS dirs & include<br/>or echo "No File Exist"]
D --> Z[Exit]
C -- No --> E{SITE_DIR file exists?}
E -- Yes --> F[Include SITE_DIR/$currnt_file_name]
F --> Z
E -- No --> G{Mapped in $TEMPLATE?}
G -- No --> H[Include 404.php]
G -- Yes --> I{Popup Page?}
I -- Yes --> J[Include popup_template.php]
I -- No --> K{CMS Page?}
K -- Yes --> L[Set $currentcmsPage; include cms.php]
K -- No --> M[Include site_template.php]
H & J & L & M --> Z[Exit]
Key Responsibilities
- Asset Distribution: Dynamically loads JavaScript files from either site or template directories.
- File Inclusion: Prioritizes site overrides; falls back to template or 404.
- Template Routing: Leverages
$TEMPLATEmapping for consistent page layouts. - CMS Integration: Bridges static content stored in database with front-end template.
Embrace this file as the central routing engine, enabling modular page and asset management across the logistics portal.