🎨 Site Template (site_template.php)
This template serves as the universal wrapper for all page views in the LinuxFront v2 Logistics portal. It standardizes HTML structure, meta tags, headers, footers, and optional debugging tools. Through a series of includes and conditionals, it dynamically injects page‐specific partials based on the requested template name.
Template Composition Flow
- Load configuration and template variables
- Optionally include a top template partial
- Render the HTML head with meta tags and assets
- Select and include the header (home, inner, or subheader)
- Inject the main content partial
- Select and include the footer (home or custom)
- Optionally render the profiler for benchmarks and query logs
flowchart TD
A[Start: include config] --> B{Top template exists?}
B -- Yes --> C[Include top template]
B -- No --> D[Skip]
C --> E[Render HEAD meta & assets]
D --> E
E --> F{Header view ignored?}
F -- No --> G[Include header-home/subheader]
F -- Yes --> H[Include subheader]
G --> I[Include content partial]
H --> I
I --> J{Footer view ignored?}
J -- No --> K[Include footer-home/header-home]
J -- Yes --> L[Include headercor]
K --> M{PROFILER enabled?}
L --> M
M -- Yes --> N[Render profiler 🛠️]
M -- No --> O[End]
N --> O
Dependencies & Interactions
This file interacts with several components:
- inc/config.php
Sets up constants, session, template mappings, asset lists, and flags. - TEMPLATE_DIR & $current_template_name
Determine paths for template partials. - inc/template_meta.php
Renders<title>, meta tags, CSS & JS includes. - inc/panels/meta.php
Adds additional meta elements. - inc/panels/header-home.php / subheader.php
Main navigation headers. - TEMPLATE_DIR …_content.php
Page-specific content injection. - inc/panels/footer-home.php / headercor.php
Standard or alternate footers. - Profiler
Optional debugging overlay printing execution times and SQL query logs.
Key Variables
| Variable | Type | Description |
|---|---|---|
$current_template_name |
string | Path fragment identifying which template partials to include. |
$header_view_ignore |
bool | When true, bypasses the standard header and footer flow. |
$exclude_banner |
array | Templates excluded from displaying the small banner. |
$currnt_template |
string | Base name of the current PHP file (without extension). |
PROFILER |
constant | Flag enabling runtime benchmarks and SQL query logging. |
$GLOBALS['BENCHMARKS'] |
array | Collected named timers for performance profiling. |
$GLOBALS['QueryLog'] |
array | Captured SQL statements and their execution durations. |
Header Inclusion Logic
Based on session state and template name, the header partial is selected:
// Determine which header to include
if (!$header_view_ignore) {
if (isset($_SESSION) && $_SESSION['Customer_email'] != '') {
// Authenticated, special home page layouts
if (in_array($current_template_name, [
'my_shipments_v3/my_shipments_v3',
'my_shipments_v4/my_shipments_v4',
'my_shipments_v5/my_shipments_v5',
'shipments_map/shipments_map'
])) {
include_once("inc/panels/header-home.php");
} else {
if ($current_template_name != 'fetching_rates_v2/fetching_rates_v2')
include_once("inc/panels/header-home.php");
}
} else {
include_once("inc/panels/header-home.php");
}
} else {
include_once("inc/panels/subheader.php");
}
Content Rendering
The main content is dynamically loaded from the active template directory:
<div id="content-wrap">
<!-- Optional small banner omitted for certain templates -->
<?php if (!in_array($currnt_template, $exclude_banner)) /* include banner */ ?>
<!-- Inject page-specific content -->
<?php include_once(TEMPLATE_DIR . $current_template_name . "_content.php"); ?>
</div>
Footer Selection
Footer logic mirrors the header flow, with an alternate headercor for ignored views:
if (!$header_view_ignore) {
// Similar template-based selection for footer-home.php
if (in_array($current_template_name, [
'my_shipments_v3/my_shipments_v3',
'my_shipments_v4/my_shipments_v4',
'shipments_map/shipments_map'
])) {
include_once("inc/panels/footer-home.php");
} else {
if ($current_template_name != 'fetching_rates_v2/fetching_rates_v2')
include_once("inc/panels/footer-home.php");
}
} elseif ($header_view_ignore) {
include_once("headercor.php");
}
Profiling & Debugging Section 🛠️
When PROFILER is enabled, execution time and database queries are displayed:
<?php if (PROFILER) {
$pageLoadingEndTime = microtime(true);
$GLOBALS['BENCHMARKS']['total_execution_time'] =
$pageLoadingEndTime - $pageLoadingStartTime;
?>
<div class="profiler">
<!-- Benchmark table -->
<?php if (!empty($GLOBALS['BENCHMARKS'])): ?>
<fieldset class="benchmarks_profiler">
<legend style="color:#990000;">BENCHMARKS</legend>
<table>
<?php foreach ($GLOBALS['BENCHMARKS'] as $key => $value): ?>
<tr>
<td><?= ucwords(strtolower(str_replace('_',' ',$key))) ?></td>
<td><?= $value ?></td>
</tr>
<?php endforeach; ?>
</table>
</fieldset>
<?php endif; ?>
<!-- Query log table -->
<?php if (!empty($GLOBALS['QueryLog'])):
$times = $GLOBALS['QueryLog']['TimeTaken'];
natsort($times);
$times = array_reverse($times, true);
?>
<fieldset class="query_profiler">
<legend style="color:#0000FF;">
DATABASE: <?= DB_NAME ?> QUERIES:
<?= count($GLOBALS['QueryLog']['Query']) ?>
(<?= array_sum($GLOBALS['QueryLog']['TimeTaken']) ?>)
</legend>
<table>
<?php foreach ($times as $idx => $t): ?>
<tr>
<td><?= $t ?></td>
<td><?= $GLOBALS['QueryLog']['Query'][$idx] ?></td>
</tr>
<?php endforeach; ?>
</table>
</fieldset>
<?php endif; ?>
</div>
<?php } ?>
By centralizing layout concerns in site_template.php, the application ensures consistent branding, responsive asset loading, and optional diagnostics across all pages. This modular approach separates page logic (in content partials) from the overall site frame.