Request Lifecycle and Routing
Relevant source files
The following files were used as context for generating this wiki page:The application employs a straightforward, multi-file, server-side routing model augmented by client-side JavaScript for navigation. Each primary URL path corresponds to a specific PHP file that acts as a controller for that request. The system handles page rendering, internationalization (i18n), and layout composition for each request.
Server-Side Request Handling
The core of the routing system is a collection of PHP files in the root directory and subdirectories (e.g., iite/, departments/, inside/). When a user navigates to a URL like / or /login.php, the web server executes the corresponding PHP file (index.php or login.php).
This diagram illustrates the general flow of a server-side request.
Sources: index.php:2-22, iite/overview.php:2-21
1. Initialization and Language Handling
Every request-handling PHP script begins by starting a session and checking for a lang query parameter.
- Session Start:
session_start()is called to persist user data, primarily the selected language. - Language Detection: The script checks if
$_GET['lang']is set. If it is, the value is stored in$_SESSION['lang'], and the browser is redirected to the same URL without the query parameter to provide a cleaner URL. - Language Fallback: If no language is set in the session or the URL, it defaults to
'it'(Italian).
Sources: index.php:2-11, login.php:2-11, iite/overview.php:2-9
2. Page Identification and Content Loading
After establishing the language, the script identifies the page content to be rendered.
- Page Key: A
$pagevariable is determined, usually from the$_GET['page']parameter. If not present, a default value specific to the entry point is used (e.g.,'index'forindex.php,'iite_overview'foriite/overview.php). - Translations: The script loads an array of page titles from
apps/pages.phpand uses the$pagekey and current$langto set the HTML<title>. - Content Buffering: The core page content is generated by including a
.phtmltemplate file (e.g.,themes/apps/index.phtml). The output of this include is captured into the$output_pagevariable using an output buffer (ob_start()/ob_get_clean()).
Sources: index.php:13-20, iite/overview.php:13-19, apps/pages.php
3. Layout and Response Rendering
The final step is to embed the buffered page content into a master layout file.
- Master Layout: The script includes
themes/components/statics/layout.phtml, which serves as the main HTML skeleton. - Content Injection: Inside
layout.phtml, the$output_pagevariable is echoed, injecting the specific page's content into the main structure. - Special Layout Logic: Some pages require layout variations. For example,
login.phpsets a$hideNavbar = trueflag to instructlayout.phtmlto omit the navigation bar.
Sources: login.php:21-28, index.php:21-22, iite/overview.php:20-21
Client-Side Navigation
Client-side JavaScript in apps/js/iite_components.js enhances navigation by handling clicks on menu items and other links, redirecting the user to the appropriate server-side PHP script.
Navigation Link Handling
Elements with a data-page attribute are designated as navigation triggers. A click event listener is attached to each of these elements.
The following table maps the data-page attribute values to their target URLs.
data-page Value | Target URL |
|---|---|
iite | http://localhost |
insideiite | /inside/overview.php |
research | # (no-op) |
departments | /departments/overview.php |
news | # (no-op) |
inside | # (no-op) |
This logic is implemented with a forEach loop over all [data-page] elements.
// Source: apps/js/iite_components.js:5-21
const pages = document.querySelectorAll('[data-page]');
pages.forEach(page => {
page.addEventListener('click', () => {
if (page.dataset.page === 'iite') {
location.href = "http://localhost";
} else if (page.dataset.page === 'insideiite') {
location.href = "/inside/overview.php";
} else if (page.dataset.page === 'departments') {
location.href = "/departments/overview.php";
}
// ... other cases
});
});
Sources: apps/js/iite_components.js:5-21
Dynamic UI Changes
The client-side script also adjusts the UI based on the current URL path (window.location.pathname).
- Logo Color: The color of the IITE logo (
#iitelogo) is changed to black on specific pages to ensure visibility against a white background. - Navbar Visibility: As a client-side fallback, the navbar is hidden on pages like
/login.phpto prevent a "flash" of the navbar before the server-side logic removes it.
This sequence diagram shows the interaction between a user click, client-side JS, and the server.
Internationalization (i18n)
Internationalization is a key feature of the request lifecycle, driven by a shared translation function and JSON data.
Translation Function t()
Most page controllers define a global function t($key) which is responsible for retrieving translated strings.
- It accesses a global
$translationsvariable, which is loaded fromapps/pages.php(for titles) orapps/translations.json(for other UI text). - It looks for the requested
$keyin the translations array. - It attempts to return the string for the current language (
$lang). - If the string for the current language is not found, it falls back to a default (usually English,
'en'). - It can replace
\ncharacters with<br>tags for HTML rendering.
Sources: iite/overview.php:15-18, index.php:15-18
Translation Data
apps/pages.php: Contains an associative array mapping page keys (e.g.,iite_overview) to their translated titles.apps/translations.json: A comprehensive JSON file containing translations for all other UI elements, from navigation links to body text, keyed by identifiers likehero_quoteornavbar_primary_iite.
Sources: apps/pages.php, apps/translations.json