Skip to content

Commit

Permalink
[5.0] Allow Joomla be served from a public* folder (joomla#40509)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Dimitris Grammatikogiannis <[email protected]>
Co-authored-by: Harald Leithner <[email protected]>
  • Loading branch information
dgrammatiko and HLeithner authored Jun 26, 2023
1 parent aa5b197 commit 12a1274
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 28 deletions.
8 changes: 6 additions & 2 deletions administrator/includes/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
require_once JPATH_BASE . '/includes/defines.php';
}

if (!defined('JPATH_PUBLIC')) {
define('JPATH_PUBLIC', JPATH_ROOT);
}

// Check for presence of vendor dependencies not included in the git repository
if (!file_exists(JPATH_LIBRARIES . '/vendor/autoload.php') || !is_dir(JPATH_ROOT . '/media/vendor')) {
echo file_get_contents(JPATH_ROOT . '/templates/system/build_incomplete.html');
if (!file_exists(JPATH_LIBRARIES . '/vendor/autoload.php') || !is_dir(JPATH_PUBLIC . '/media/vendor')) {
echo file_get_contents(JPATH_BASE . '/templates/system/build_incomplete.html');

exit;
}
Expand Down
1 change: 1 addition & 0 deletions administrator/includes/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// Defines
define('JPATH_ROOT', implode(DIRECTORY_SEPARATOR, $parts));
define('JPATH_SITE', JPATH_ROOT);
define('JPATH_PUBLIC', JPATH_ROOT);
define('JPATH_CONFIGURATION', JPATH_ROOT);
define('JPATH_ADMINISTRATOR', JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator');
define('JPATH_LIBRARIES', JPATH_ROOT . DIRECTORY_SEPARATOR . 'libraries');
Expand Down
6 changes: 5 additions & 1 deletion administrator/includes/framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
|| (file_exists(JPATH_INSTALLATION . '/index.php') && (false === (new Version())->isInDevelopmentState()))
) {
if (file_exists(JPATH_INSTALLATION . '/index.php')) {
header('Location: ../installation/index.php');
if (JPATH_ROOT === JPATH_PUBLIC) {
header('Location: ../installation/index.php');
} else {
echo 'Installation from a public folder is not supported, revert your Server configuration to point at the Joomla\'s root folder to continue.';
}

exit();
} else {
Expand Down
2 changes: 1 addition & 1 deletion administrator/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
str_replace(
'{{phpversion}}',
JOOMLA_MINIMUM_PHP,
file_get_contents(dirname(__FILE__) . '/../templates/system/incompatible.html')
file_get_contents(dirname(dirname(__FILE__)) . '/includes/incompatible.html')
)
);
}
Expand Down
4 changes: 4 additions & 0 deletions api/includes/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
require_once JPATH_BASE . '/includes/defines.php';
}

if (!defined('JPATH_PUBLIC')) {
define('JPATH_PUBLIC', JPATH_ROOT);
}

require_once JPATH_BASE . '/includes/framework.php';

// Set profiler start time and memory usage and mark afterLoad in the profiler.
Expand Down
1 change: 1 addition & 0 deletions api/includes/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// Defines.
define('JPATH_ROOT', implode(DIRECTORY_SEPARATOR, $parts));
define('JPATH_SITE', JPATH_ROOT);
define('JPATH_PUBLIC', JPATH_ROOT);
define('JPATH_CONFIGURATION', JPATH_ROOT);
define('JPATH_ADMINISTRATOR', JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator');
define('JPATH_LIBRARIES', JPATH_ROOT . DIRECTORY_SEPARATOR . 'libraries');
Expand Down
12 changes: 5 additions & 7 deletions build/build-modules-js/error-pages.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,12 @@ module.exports.createErrorPages = async (options) => {
await mkdir(dirname(`${RootPath}${options.settings.errorPages[name].destFile}`), { recursive: true, mode: 0o755 });
}

await writeFile(
`${RootPath}${options.settings.errorPages[name].destFile}`,
template,
{ encoding: 'utf8', mode: 0o644 },
);
options.settings.errorPages[name].destFile.forEach(async (folder) => {
await writeFile(`${RootPath}${folder}`, template, { encoding: 'utf8', mode: 0o644 });

// eslint-disable-next-line no-console
console.error(`✅ Created the file: ${options.settings.errorPages[name].destFile}`);
// eslint-disable-next-line no-console
console.error(`✅ Created the file: ${folder}`);
});
};

Object.keys(options.settings.errorPages).forEach((name) => processPages.push(processPage(name)));
Expand Down
8 changes: 4 additions & 4 deletions build/build-modules-js/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,31 +798,31 @@
"text": "It looks like you are trying to run Joomla! from our git repository. To do so requires you complete a couple of extra steps first.",
"link": "J4.x:Setting_Up_Your_Local_Environment",
"linkText": "More Details",
"destFile": "/templates/system/build_incomplete.html"
"destFile": ["/templates/system/build_incomplete.html"]
},
"unsupported": {
"title": "Joomla: unsupported PHP version",
"header": "Sorry, your PHP version is not supported",
"text": "Your host needs to use PHP version {{phpversion}} or newer to run this version of Joomla!",
"link": "J4.x:Unsupported_PHP_Version",
"linkText": "Help me resolve this",
"destFile": "/templates/system/incompatible.html"
"destFile": ["/templates/system/incompatible.html", "/includes/incompatible.html"]
},
"noxml": {
"title": "Joomla: Missing PHP-XML library",
"header": "Sorry, your PHP is missing a vital library",
"text": "Your host needs to use PHP with support for the XML library to run this version of Joomla!",
"link": "J4.x:Missing_XML_Library",
"linkText": "Help me resolve this",
"destFile": "/media/system/html/noxml.html"
"destFile": ["/media/system/html/noxml.html"]
},
"fatal": {
"title": "An Error Occurred: {{statusText}}",
"header": "Sorry, there was a problem we could not recover from.",
"text": "The server returned a \"{{statusCode_statusText}}\"",
"link": "J4.x:FatalError",
"linkText": "Help me resolve this",
"destFile": "/templates/system/fatal-error.html"
"destFile": ["/templates/system/fatal-error.html"]
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions cli/joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
exit;
}

if (!defined('JPATH_PUBLIC')) {
define('JPATH_PUBLIC', JPATH_ROOT);
}

// Check if installed
if (
!file_exists(JPATH_CONFIGURATION . '/configuration.php')
Expand Down
8 changes: 6 additions & 2 deletions includes/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
require_once JPATH_BASE . '/includes/defines.php';
}

if (!defined('JPATH_PUBLIC')) {
define('JPATH_PUBLIC', JPATH_ROOT);
}

// Check for presence of vendor dependencies not included in the git repository
if (!file_exists(JPATH_LIBRARIES . '/vendor/autoload.php') || !is_dir(JPATH_ROOT . '/media/vendor')) {
echo file_get_contents(JPATH_ROOT . '/templates/system/build_incomplete.html');
if (!file_exists(JPATH_LIBRARIES . '/vendor/autoload.php') || !is_dir(JPATH_PUBLIC . '/media/vendor')) {
echo file_get_contents(JPATH_BASE . '/templates/system/build_incomplete.html');

exit;
}
Expand Down
1 change: 1 addition & 0 deletions includes/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
define('JPATH_ROOT', implode(DIRECTORY_SEPARATOR, $parts));
define('JPATH_SITE', JPATH_ROOT);
define('JPATH_CONFIGURATION', JPATH_ROOT);
define('JPATH_PUBLIC', JPATH_ROOT);
define('JPATH_ADMINISTRATOR', JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator');
define('JPATH_LIBRARIES', JPATH_ROOT . DIRECTORY_SEPARATOR . 'libraries');
define('JPATH_PLUGINS', JPATH_ROOT . DIRECTORY_SEPARATOR . 'plugins');
Expand Down
6 changes: 5 additions & 1 deletion includes/framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
|| (file_exists(JPATH_INSTALLATION . '/index.php') && (false === (new Version())->isInDevelopmentState()))
) {
if (file_exists(JPATH_INSTALLATION . '/index.php')) {
header('Location: ' . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], 'index.php')) . 'installation/index.php');
if (JPATH_ROOT === JPATH_PUBLIC) {
header('Location: ' . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], 'index.php')) . 'installation/index.php');
} else {
echo 'Installation from a public folder is not supported, revert your Server configuration to point at the Joomla\'s root folder to continue.';
}

exit;
} else {
Expand Down
38 changes: 38 additions & 0 deletions includes/incompatible.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
str_replace(
'{{phpversion}}',
JOOMLA_MINIMUM_PHP,
file_get_contents(dirname(__FILE__) . '/templates/system/incompatible.html')
file_get_contents(dirname(__FILE__) . '/includes/incompatible.html')
)
);
}
Expand Down
1 change: 1 addition & 0 deletions installation/includes/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// Defines
define('JPATH_ROOT', implode(DIRECTORY_SEPARATOR, $parts));
define('JPATH_SITE', JPATH_ROOT);
define('JPATH_PUBLIC', JPATH_ROOT);
define('JPATH_CONFIGURATION', JPATH_ROOT);
define('JPATH_ADMINISTRATOR', JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator');
define('JPATH_LIBRARIES', JPATH_ROOT . DIRECTORY_SEPARATOR . 'libraries');
Expand Down
18 changes: 9 additions & 9 deletions libraries/src/HTML/HTMLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ protected static function includeRelativeFiles($folder, $file, $relative, $detec

if ($template->inheritable || !empty($template->parent)) {
$client = $app->isClient('administrator') === true ? 'administrator' : 'site';
$templaPath = JPATH_ROOT . "/media/templates/$client";
$templaPath = JPATH_PUBLIC . "/media/templates/$client";
}

// For each potential files
Expand Down Expand Up @@ -441,7 +441,7 @@ protected static function includeRelativeFiles($folder, $file, $relative, $detec
list($element, $file) = explode('/', $file, 2);

// Try to deal with plugins group in the media folder
$found = static::addFileToBuffer(JPATH_ROOT . "/media/$extension/$element/$folder/$file", $ext, $debugMode);
$found = static::addFileToBuffer(JPATH_PUBLIC . "/media/$extension/$element/$folder/$file", $ext, $debugMode);

if (!empty($found)) {
$includes[] = $found;
Expand All @@ -450,7 +450,7 @@ protected static function includeRelativeFiles($folder, $file, $relative, $detec
}

// Try to deal with classical file in a media subfolder called element
$found = static::addFileToBuffer(JPATH_ROOT . "/media/$extension/$folder/$element/$file", $ext, $debugMode);
$found = static::addFileToBuffer(JPATH_PUBLIC . "/media/$extension/$folder/$element/$file", $ext, $debugMode);

if (!empty($found)) {
$includes[] = $found;
Expand All @@ -477,7 +477,7 @@ protected static function includeRelativeFiles($folder, $file, $relative, $detec
}
} else {
// Try to deal with system files in the media folder
$found = static::addFileToBuffer(JPATH_ROOT . "/media/system/$folder/$element/$file", $ext, $debugMode);
$found = static::addFileToBuffer(JPATH_PUBLIC . "/media/system/$folder/$element/$file", $ext, $debugMode);

if (!empty($found)) {
$includes[] = $found;
Expand All @@ -487,7 +487,7 @@ protected static function includeRelativeFiles($folder, $file, $relative, $detec
}
} else {
// Try to deal with files in the extension's media folder
$found = static::addFileToBuffer(JPATH_ROOT . "/media/$extension/$folder/$file", $ext, $debugMode);
$found = static::addFileToBuffer(JPATH_PUBLIC . "/media/$extension/$folder/$file", $ext, $debugMode);

if (!empty($found)) {
$includes[] = $found;
Expand Down Expand Up @@ -524,7 +524,7 @@ protected static function includeRelativeFiles($folder, $file, $relative, $detec
}

// Try to deal with system files in the media folder
$found = static::addFileToBuffer(JPATH_ROOT . "/media/system/$folder/$file", $ext, $debugMode);
$found = static::addFileToBuffer(JPATH_PUBLIC . "/media/system/$folder/$file", $ext, $debugMode);

if (!empty($found)) {
$includes[] = $found;
Expand All @@ -534,7 +534,7 @@ protected static function includeRelativeFiles($folder, $file, $relative, $detec
}
} else {
// Try to deal with system files in the media folder
$found = static::addFileToBuffer(JPATH_ROOT . "/media/system/$folder/$file", $ext, $debugMode);
$found = static::addFileToBuffer(JPATH_PUBLIC . "/media/system/$folder/$file", $ext, $debugMode);

if (!empty($found)) {
$includes[] = $found;
Expand All @@ -558,7 +558,7 @@ protected static function includeRelativeFiles($folder, $file, $relative, $detec
* This MD5SUM file must represent the signature of the folder content
*/
foreach ($files as $file) {
$path = JPATH_ROOT . "/$file";
$path = JPATH_PUBLIC . '/' . $file;

$found = static::addFileToBuffer($path, $ext, $debugMode);

Expand Down Expand Up @@ -1209,7 +1209,7 @@ protected static function addFileToBuffer($path = '', $ext = '', $debugMode = fa
*/
protected static function convertToRelativePath($path)
{
$relativeFilePath = Uri::root(true) . str_replace(JPATH_ROOT, '', $path);
$relativeFilePath = Uri::root(true) . str_replace(JPATH_PUBLIC, '', $path);

// On windows devices we need to replace "\" with "/" otherwise some browsers will not load the asset
return str_replace(DIRECTORY_SEPARATOR, '/', $relativeFilePath);
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
define('JPATH_ROOT', JPATH_BASE);
}

if (!defined('JPATH_PUBLIC')) {
define('JPATH_PUBLIC', JPATH_ROOT);
}

/**
* @deprecated 4.4.0 will be removed in 6.0
**/
Expand Down

0 comments on commit 12a1274

Please sign in to comment.