From b8146916c1138311ea819c78544e10a98084c598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 6 Apr 2024 16:00:41 +0200 Subject: [PATCH] keep non-composer autoloading relying on include_path set in plugins --- program/lib/Roundcube/bootstrap.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/program/lib/Roundcube/bootstrap.php b/program/lib/Roundcube/bootstrap.php index 950256f566b..b2c0c15125f 100644 --- a/program/lib/Roundcube/bootstrap.php +++ b/program/lib/Roundcube/bootstrap.php @@ -92,6 +92,9 @@ mb_internal_encoding(RCUBE_CHARSET); mb_regex_encoding(RCUBE_CHARSET); +// Register legacy autoloader for plugins +spl_autoload_register('rcube_legacy_autoload'); + // set PEAR error handling (will also load the PEAR main class) if (class_exists('PEAR')) { // @phpstan-ignore-next-line @@ -390,3 +393,25 @@ function version_parse($version) $version ); } + +/** + * Legacy autoloader for plugins not using or not installed using composer. + * + * @param string $classname Class name + * + * @return bool True when the class file has been found + */ +function rcube_legacy_autoload(string $classname): bool +{ + // Translate PHP namespaces into directories, + // i.e. 'Sabre\Reader' -> 'Sabre/Reader.php' + $classname = str_replace('\\', '/', $classname); + + if ($fp = @fopen("{$classname}.php", 'r', true)) { + fclose($fp); + include_once "{$classname}.php"; + return true; + } + + return false; +}