1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-30 19:30:25 +02:00

Ability to use CDN files for libraries.

This commit is contained in:
Lóna Lore
2016-03-09 11:04:16 +01:00
parent 00f8dcdb16
commit 611dff4c06

View File

@@ -84,7 +84,7 @@ class e_library_manager
}
$libraryPath = e107::getParser()->replaceConstants($library['library_path']);
if($library['library_path'] === false || !file_exists($libraryPath))
if($library['library_path'] === false || (!file_exists($libraryPath) && substr($libraryPath, 0, 4) != 'http'))
{
$library['error'] = LAN_LIBRARY_MANAGER_09;
@@ -830,6 +830,7 @@ class e_library_manager
// Construct the full path to the library for later use.
$path = e107::getParser()->replaceConstants($library['library_path']);
$path = ($library['path'] !== '' ? $path . '/' . $library['path'] : $path);
$path = rtrim($path, '/');
// Count the number of loaded files for the return value.
$count = 0;
@@ -957,7 +958,6 @@ class e_library_manager
require_once $file_path;
}
/**
* Gets the version information from an arbitrary library.
*
@@ -988,7 +988,27 @@ class e_library_manager
$libraryPath = e107::getParser()->replaceConstants($library['library_path']);
$file = $libraryPath . '/' . $options['file'];
if(empty($options['file']) || !file_exists($file))
if(empty($options['file']))
{
return;
}
// If remote file (e.g. CDN URL)... we download file to temp, and get version number.
// The library will be cached with version number, so this only run once per library.
if(substr($file, 0, 4) == 'http')
{
$content = file_get_contents($file);
$tmpFile = tempnam(sys_get_temp_dir(), 'lib_');
if($tmpFile)
{
file_put_contents($tmpFile, $content);
$file = $tmpFile;
}
}
if(!file_exists($file))
{
return;
}
@@ -999,11 +1019,24 @@ class e_library_manager
if(preg_match($options['pattern'], $line, $version))
{
fclose($file);
// If downloaded file, we need to unlink it from temp.
if(isset($tmpFile) && file_exists($tmpFile))
{
unlink($tmpFile);
}
return $version[1];
}
$options['lines']--;
}
fclose($file);
// If downloaded file, we need to unlink it from temp.
if(isset($tmpFile) && file_exists($tmpFile))
{
unlink($tmpFile);
}
}
/**