Include PHP libraries from system if not packaged and they are installed.

Thanks to:
    "Bhuvan Krishna" <bhuvan@swecha.net>
    "Sunil Mohan" <sunil@medhas.org>
This commit is contained in:
Mikael Nordfeldth 2015-09-03 17:52:04 +02:00
parent c77bce12e5
commit 84a65c7189
1 changed files with 10 additions and 1 deletions

View File

@ -137,9 +137,18 @@ spl_autoload_register('GNUsocial_class_autoload');
* and is available here: http://www.php-fig.org/psr/psr-0/
*/
spl_autoload_register(function($class){
$file = INSTALLDIR.'/extlib/'.preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php';
$class_path = preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php';
$file = INSTALLDIR.'/extlib/'.$class_path;
if (file_exists($file)) {
require_once $file;
return;
}
# Try if the system has this external library
$file = '/usr/share/php/'.$class_path;
if (file_exists($file)) {
require_once $file;
return;
}
});