1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-09-01 11:42:33 +02:00

ready for merge #43

This commit is contained in:
Mikael Roos
2015-01-14 19:28:52 +01:00
parent f9704a4fbc
commit be98ae8979
4 changed files with 104 additions and 35 deletions

View File

@@ -70,6 +70,24 @@ function getDefined($key, $defined, $undefined)
/**
* Get value from config array or default if key is not set in config array.
*
* @param string $key the key in the config array.
* @param mixed $default value to be default if $key is not set in config.
*
* @return mixed value as $config[$key] or $default.
*/
function getConfig($key, $default)
{
global $config;
return isset($config[$key])
? $config[$key]
: $default;
}
/**
* Log when verbose mode, when used without argument it returns the result.
*
@@ -123,11 +141,23 @@ $verbose = getDefined(array('verbose', 'v'), true, false);
/**
* Get the source files.
*/
$autoloader = getConfig('autoloader', false);
$cimageClass = getConfig('cimage_class', false);
if ($autoloader) {
require $autoloader;
} else if ($cimageClass) {
require $cimageClass;
}
/**
* Create the class for the image.
*/
require $config['cimage_class'];
$img = new CImage();
$img->setVerbose($verbose);
@@ -137,12 +167,23 @@ $img->setVerbose($verbose);
* Allow or disallow remote download of images from other servers.
*
*/
$allowRemote = $config['remote_allow'];
$allowRemote = getConfig('remote_allow', false);
$remotePwd = getConfig('remote_password', false);
$pwd = get(array('password', 'pwd'), null);
if ($allowRemote) {
$pattern = isset($config['remote_pattern'])
? $config['remote_pattern']
: null;
// Check if passwords match, if configured to use passwords
$passwordMatch = null;
if ($remotePwd != false) {
if ($remotePwd == $pwd) {
$passwordMatch = true;
} else {
$passwordMatch = false;
errorPage('Trying to download remote image but missing password.');
}
}
if ($allowRemote && $passwordMatch !== false) {
$pattern = getConfig('remote_pattern', null);
$img->setRemoteDownload($allowRemote, $pattern);
}