Skip to content

Commit b24d310

Browse files
markrandallderickr
authored andcommitted
Create the public/ directory, and move all the files.
- Update the includes - Swap out docroot to use a function
1 parent 1d4f635 commit b24d310

3,038 files changed

Lines changed: 1198 additions & 1088 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.docker/dev/Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Development Docker
2+
#
3+
# Provides the main runtime engine as well as tooling for running
4+
# during development
5+
#
6+
# NOTES:
7+
# - Does not copy and files in as it is expected to be handled via a mount
8+
9+
FROM php:8.4-cli
10+
11+
# Codebase doesn't have production flag so we negate it instead with
12+
# the DEVELOPMENT flag
13+
ENV DEVELOPMENT=1
14+
15+
#
16+
# install additional development tooling
17+
#
18+
RUN apt update \
19+
&& apt-get install -y --no-install-recommends git unzip \
20+
&& rm -rf /var/lib/apt/lists/*
21+
22+
#
23+
# Composer is required for dev dependencies
24+
#
25+
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
26+
&& php -r "if (hash_file('sha384', 'composer-setup.php') === 'c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }" \
27+
&& php composer-setup.php \
28+
&& php -r "unlink('composer-setup.php');" \
29+
&& mv composer.phar /usr/local/bin/composer
30+
31+
#
32+
# node.js - used for socket.dev and other front-end tooling
33+
#
34+
RUN apt-get update && apt-get install -y curl gnupg ca-certificates \
35+
&& mkdir -p /etc/apt/keyrings \
36+
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
37+
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
38+
&& apt-get update && apt-get install -y nodejs \
39+
&& rm -rf /var/lib/apt/lists/*
40+
41+
#
42+
# Global dependencies and tools brought in via npm
43+
#
44+
RUN npm install -g socket
45+
46+
WORKDIR /app/public

.docker/prod/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# "Production" Docker
2+
#
3+
# Provides the main runtime for PHP when deploying to a "Production"
4+
# or "Testing" environment that needs a full container using
5+
# the inbuilt server (not recommended).
6+
7+
FROM php:8.4-cli
8+
9+
# All of the files from the source location are copied into
10+
# the /app folder
11+
RUN mkdir /app
12+
WORKDIR /app/public
13+
COPY . /app

include/do-download.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
we would like to know about (PHP binary or source).
77
*/
88

9+
use phpweb\ProjectGlobals;
10+
911
function get_actual_download_file($file)
1012
{
1113
// Could be a normal download or a manual download file
@@ -14,7 +16,7 @@ function get_actual_download_file($file)
1416
// Find out what is the exact file requested
1517
$found = false;
1618
foreach ($possible_files as $name => $log) {
17-
if (@file_exists($_SERVER['DOCUMENT_ROOT'] . '/distributions/' . $name)) {
19+
if (@file_exists(ProjectGlobals::getPublicRoot() . '/distributions/' . $name)) {
1820
$found = $name;
1921
break;
2022
}

include/errors.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
use phpweb\I18n\Languages;
9+
use phpweb\ProjectGlobals;
910

1011
// A 'good looking' 404 error message page
1112
function error_404(): void
@@ -578,7 +579,7 @@ function is_known_snippet(string $term): ?string {
578579
*/
579580
function get_legacy_manual_urls(string $uri): array
580581
{
581-
$filename = $_SERVER["DOCUMENT_ROOT"] . "/manual/legacyurls.json";
582+
$filename = ProjectGlobals::getPublicRoot() . "/manual/legacyurls.json";
582583
$pages_ids = json_decode(file_get_contents($filename), true);
583584
$page_id = preg_replace_callback('/^manual\/[a-z_A-Z]+\/(.*?)(\.php)?$/', function (array $matches): string {
584585
if (count($matches) < 2) {

include/get-download.inc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22
// Try to make this page non-cached
3+
use phpweb\ProjectGlobals;
4+
35
header_nocache();
46

57
// No file to download
@@ -18,7 +20,7 @@ $site_config = [
1820
// Find out what is the exact file requested
1921
$file = false;
2022
foreach ($possible_files as $name) {
21-
if (@file_exists($_SERVER['DOCUMENT_ROOT'] . '/distributions/' . $name)) {
23+
if (@file_exists(ProjectGlobals::getPublicRoot() . '/distributions/' . $name)) {
2224
$file = $name;
2325
break;
2426
}
@@ -41,7 +43,7 @@ if ($file === false) {
4143
EOT;
4244
} else {
4345
// Set local file name
44-
$local_file = $_SERVER['DOCUMENT_ROOT'] . '/distributions/' . $file;
46+
$local_file = ProjectGlobals::getPublicRoot() . '/distributions/' . $file;
4547
// Try to get filesize to display
4648
$size = @filesize($local_file);
4749
}

include/header.inc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
use phpweb\ProjectGlobals;
4+
25
$css_files = [
36
'/fonts/Fira/fira.css',
47
'/fonts/Font-Awesome/css/fontello.css',
@@ -39,7 +42,7 @@ if ($config["cache"]) {
3942
if (is_numeric($config["cache"])) {
4043
$timestamp = $config["cache"];
4144
} else {
42-
$timestamp = filemtime($_SERVER["DOCUMENT_ROOT"] . "/" . $_SERVER["BASE_PAGE"]);
45+
$timestamp = filemtime(ProjectGlobals::getPublicRoot() . "/" . $_SERVER["BASE_PAGE"]);
4346
}
4447
$tsstring = gmdate("D, d M Y H:i:s ", $timestamp) . "GMT";
4548

include/layout.inc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use phpweb\I18n\Languages;
44
use phpweb\Navigation\NavItem;
55
use phpweb\News\NewsHandler;
6+
use phpweb\ProjectGlobals;
67

78
$_SERVER['STATIC_ROOT'] = $MYSITE;
89
$_SERVER['MYSITE'] = $MYSITE;
@@ -95,7 +96,7 @@ function make_image($file, $alt = false, $align = false, $extras = false,
9596
$webdir = $_SERVER['MYSITE'] . ($dir[0] == '/' ? '' : '/') . $dir;
9697

9798
// Get width and height values if possible
98-
if ($addsize && ($size = @getimagesize($_SERVER['DOCUMENT_ROOT'] . "$dir/$file"))) {
99+
if ($addsize && ($size = @getimagesize(ProjectGlobals::getPublicRoot() . "$dir/$file"))) {
99100
$sizeparams = ' ' . trim($size[3]);
100101
} else {
101102
$sizeparams = '';
@@ -565,12 +566,12 @@ function get_news_changes()
565566
}
566567

567568
function doc_toc($lang): void {
568-
$file = __DIR__ . "/../manual/$lang/toc/index.inc";
569+
$file = ProjectGlobals::getPublicRoot() . "/manual/$lang/toc/index.inc";
569570
if (!file_exists($file)) {
570571
$lang = "en"; // Fallback on English if the translation doesn't exist
571-
$file = __DIR__ . "/../manual/en/toc/index.inc";
572+
$file = ProjectGlobals::getPublicRoot() . "/manual/en/toc/index.inc";
572573
}
573-
require __DIR__ . "/../manual/$lang/toc/index.inc";
574+
require ProjectGlobals::getPublicRoot() . "/manual/$lang/toc/index.inc";
574575

575576
echo "<dl>\n";
576577
doc_toc_list($lang, $TOC, "getting-started");
@@ -612,7 +613,7 @@ function doc_toc($lang): void {
612613

613614
}
614615
function doc_toc_list($lang, $index, $file): void {
615-
include __DIR__ . "/../manual/$lang/toc/$file.inc";
616+
include ProjectGlobals::getPublicRoot() . "/manual/$lang/toc/$file.inc";
616617

617618
doc_toc_title($lang, $index, $file);
618619
foreach ($TOC as $entry) {

include/manual-lookup.inc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

33
// We need this for error reporting
4+
use phpweb\ProjectGlobals;
5+
46
include_once __DIR__ . '/errors.inc';
57

68
// Try to find some variations of keyword with $prefix in the $lang manual
@@ -14,35 +16,35 @@ function tryprefix($lang, $keyword, $prefix)
1416

1517
// Try the keyword with the prefix
1618
$try = "/manual/{$lang}/{$prefix}{$keyword}.php";
17-
if (@file_exists($_SERVER['DOCUMENT_ROOT'] . $try)) { return $try; }
19+
if (@file_exists(ProjectGlobals::getPublicRoot() . $try)) { return $try; }
1820

1921
// Drop out spaces, and try that keyword (if different)
2022
$nosp = str_replace(" ", "", $keyword);
2123
if ($nosp != $keyword) {
2224
$try = "/manual/{$lang}/{$prefix}{$nosp}.php";
23-
if (@file_exists($_SERVER['DOCUMENT_ROOT'] . $try)) { return $try; }
25+
if (@file_exists(ProjectGlobals::getPublicRoot() . $try)) { return $try; }
2426
}
2527

2628
// Replace spaces with hyphens, and try that (if different)
2729
$dasp = str_replace(" ", "-", $keyword);
2830
if ($dasp != $keyword) {
2931
$try = "/manual/{$lang}/{$prefix}{$dasp}.php";
30-
if (@file_exists($_SERVER['DOCUMENT_ROOT'] . $try)) { return $try; }
32+
if (@file_exists(ProjectGlobals::getPublicRoot() . $try)) { return $try; }
3133
}
3234

3335
// Remove hyphens (and underscores), and try that (if different)
3436
$noul = str_replace("-", "", $keyword);
3537
if ($noul != $keyword) {
3638
$try = "/manual/{$lang}/{$prefix}{$noul}.php";
37-
if (@file_exists($_SERVER['DOCUMENT_ROOT'] . $try)) { return $try; }
39+
if (@file_exists(ProjectGlobals::getPublicRoot() . $try)) { return $try; }
3840
}
3941

4042
// urldecode() (%5C == \) Replace namespace sperators, and try that (if different)
4143
$keyword = urldecode($keyword);
4244
$noul = str_replace("\\", "-", $keyword);
4345
if ($noul != $keyword) {
4446
$try = "/manual/{$lang}/{$prefix}{$noul}.php";
45-
if (@file_exists($_SERVER['DOCUMENT_ROOT'] . $try)) { return $try; }
47+
if (@file_exists(ProjectGlobals::getPublicRoot() . $try)) { return $try; }
4648
}
4749

4850
// Replace first - with a dot and try that (for mysqli_ type entries)
@@ -53,7 +55,7 @@ function tryprefix($lang, $keyword, $prefix)
5355
$keyword[$pos] = '.';
5456

5557
$try = "/manual/{$lang}/{$prefix}{$keyword}.php";
56-
if (@file_exists($_SERVER['DOCUMENT_ROOT'] . $try)) { return $try; }
58+
if (@file_exists(ProjectGlobals::getPublicRoot() . $try)) { return $try; }
5759
}
5860
}
5961

@@ -108,9 +110,9 @@ function find_manual_page($lang, $keyword)
108110
$dbh = false;
109111
if (class_exists('PDO')) {
110112
if (in_array('sqlite', PDO::getAvailableDrivers(), true)) {
111-
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/backend/manual-lookup.sqlite')) {
113+
if (file_exists(ProjectGlobals::getPublicRoot() . '/backend/manual-lookup.sqlite')) {
112114
try {
113-
$dbh = new PDO( 'sqlite:' . $_SERVER['DOCUMENT_ROOT'] . '/backend/manual-lookup.sqlite', '', '', [PDO::ATTR_PERSISTENT => true, PDO::ATTR_EMULATE_PREPARES => true] );
115+
$dbh = new PDO( 'sqlite:' . ProjectGlobals::getPublicRoot() . '/backend/manual-lookup.sqlite', '', '', [PDO::ATTR_PERSISTENT => true, PDO::ATTR_EMULATE_PREPARES => true] );
114116
} catch (PDOException $e) {
115117
return find_manual_page_slow($lang, $keyword);
116118
}
@@ -204,7 +206,7 @@ function find_manual_page($lang, $keyword)
204206
// But does the file really exist?
205207
// @todo consider redirecting here, instead of including content within the 404
206208
// @todo considering the file path is generated from the manual build, we can probably remove this file_exists() check
207-
if (file_exists($_SERVER["DOCUMENT_ROOT"] . $r[0])) {
209+
if (file_exists(ProjectGlobals::getPublicRoot() . $r[0])) {
208210
return $r[0];
209211
}
210212
}

include/shared-manual.inc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $PGI = []; $SIDEBAR_DATA = '';
2323
// =============================================================================
2424

2525
use phpweb\I18n\Languages;
26+
use phpweb\ProjectGlobals;
2627
use phpweb\UserNotes\Sorter;
2728
use phpweb\UserNotes\UserNote;
2829

@@ -35,7 +36,7 @@ function manual_notes($notes):void {
3536
global $LANG;
3637

3738
// Get needed values
38-
list($filename) = $GLOBALS['PGI']['this'];
39+
[$filename] = $GLOBALS['PGI']['this'];
3940

4041
// Drop file extension from the name
4142
if (substr($filename, -4) == '.php') {
@@ -96,7 +97,7 @@ END_USERNOTE_HEADER;
9697
function manual_notes_load(string $id): array
9798
{
9899
$hash = substr(md5($id), 0, 16);
99-
$notes_file = $_SERVER['DOCUMENT_ROOT'] . "/backend/notes/" .
100+
$notes_file = ProjectGlobals::getPublicRoot() . "/backend/notes/" .
100101
substr($hash, 0, 2) . "/$hash";
101102

102103
// Open the note file for reading and get the data (12KB)
@@ -140,7 +141,7 @@ function manual_note_display(UserNote $note, $voteOption = true): void
140141

141142
// Vote User Notes Div
142143
if ($voteOption) {
143-
list($redir_filename) = $GLOBALS['PGI']['this'];
144+
[$redir_filename] = $GLOBALS['PGI']['this'];
144145
if (substr($redir_filename, -4) == '.php') {
145146
$redir_filename = substr($redir_filename, 0, -4);
146147
}
@@ -286,9 +287,9 @@ function manual_setup($setup): void {
286287
$_SERVER['BASE_HREF'] = $MYSITE . $_SERVER['BASE_PAGE'];
287288

288289
$timestamps = [
289-
filemtime($_SERVER["DOCUMENT_ROOT"] . "/" . $_SERVER["BASE_PAGE"]),
290-
filemtime($_SERVER["DOCUMENT_ROOT"] . "/include/prepend.inc"),
291-
filemtime($_SERVER["DOCUMENT_ROOT"] . "/styles/theme-base.css"),
290+
filemtime(ProjectGlobals::getPublicRoot() . "/" . $_SERVER["BASE_PAGE"]),
291+
filemtime(ProjectGlobals::getProjectRoot() . "/include/prepend.inc"),
292+
filemtime(ProjectGlobals::getPublicRoot() . "/styles/theme-base.css"),
292293
];
293294

294295
// Load user note for this page

manual/index.php

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)