28-11-2012_route.php

This routing script drives the Linuxfront v2 Logistics portal, loading requested assets or content pages through the proper template or direct include. It centralizes how JavaScript, static PHP files, pop-ups, CMS pages, and error pages are served.

⚙️ Configuration and Bootstrap

Before any routing occurs, the script boots up core settings:

  • Includes inc/config.php for:
    • Session start, environment flags
    • Directory constants: SITE_DIR, TEMPLATE_DIR, SITE_JS_DIR, TEMPLATE_JS_DIR
    • The $TEMPLATE mapping array
  • Prepares $currnt_file_name and $file_extension from the URL
<?php
include_once("inc/config.php");
// $currnt_file_name, $file_extension set in inc/template_vars.php

🛣️ Routing Flow

The main logic follows a clear, four-step pipeline:

  1. JavaScript Assets
    If the request ends in .js, attempt to include it directly from:

    • SITE_DIR . SITE_JS_DIR
    • Fallback: TEMPLATE_DIR . TEMPLATE_JS_DIR
    • On failure, output "No File Exist" and exit.
    if ($file_extension === 'js') {
        if (file_exists(SITE_DIR . SITE_JS_DIR . $currnt_file_name)) {
            include_once(SITE_DIR . SITE_JS_DIR . $currnt_file_name);
        } elseif (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;
    }
    
  2. Direct Site File Inclusion
    For non-JS files, if the file exists under SITE_DIR, include it outright and exit.

    if (file_exists(SITE_DIR . $currnt_file_name)) {
        include_once(SITE_DIR . $currnt_file_name);
        exit;
    }
    
  3. Template Registration Check
    If the requested page key is not present in the $TEMPLATE array, serve a 404 page.

    if (!isset($TEMPLATE[$currnt_file_name])) {
        include_once("404.php");
    }
    
  4. Template Selection
    For recognized pages, choose among:

    • Popup windows (five help/shipment pages)
    • CMS pages (policy and terms)
    • Default site template for all other pages

📦 Template Selection Details

Page Filename Included Template
nmfc_no_help.phpfreight_class_help.phpshippment_detail.phpchoose_address.phpchoose_product.php popup_template.php
privacy_policy.phpterms_and_conditions.phpnotification_of_infringement_dmca_policy.php cms.php (with $currentcmsPage set)
All other valid $TEMPLATE pages site_template.php

Example snippet handling pop-ups and CMS pages:

if ($currnt_file_name === 'nmfc_no_help.php'
 || $currnt_file_name === 'freight_class_help.php'
 || $currnt_file_name === 'shippment_detail.php'
 || $currnt_file_name === 'choose_address.php'
 || $currnt_file_name === 'choose_product.php'
) {
    include_once("popup_template.php");
}
elseif ($currnt_file_name === 'privacy_policy.php') {
    $currentcmsPage = 'privacy_policy';
    include_once("cms.php");
}
// … similar for terms_and_conditions & dmca policy …
else {
    include_once("site_template.php");
}

🛑 Error Handling

  • JavaScript missing: echoes "No File Exist".
  • Unknown PHP page: falls back to 404.php.
  • Ensures the user always sees a consistent error page style.

🧩 Dependencies & Context

  • inc/config.php: core constants and $TEMPLATE map
  • site_template.php: wraps content pages in full site layout
  • popup_template.php: minimal wrapper for modal/pop-up pages
  • cms.php: renders static CMS content from the database

This routing pattern ensures maintainable asset loading and consistent templating across the Linuxfront v2 Logistics portal.