1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-08-13 19:44:16 +02:00

adding support for alias #47

This commit is contained in:
Mikael Roos
2015-01-15 23:29:18 +01:00
parent c35587c7e2
commit f87dc2967f
4 changed files with 109 additions and 28 deletions

View File

@@ -166,24 +166,27 @@ $img->setVerbose($verbose);
/**
* Allow or disallow remote download of images from other servers.
*
* Check if passwords are configured, used and match.
* Options decide themself if they require passwords to be used.
*/
$allowRemote = getConfig('remote_allow', false);
$remotePwd = getConfig('remote_password', false);
$pwdConfig = getConfig('password', false);
$pwd = get(array('password', 'pwd'), 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 ($pwdConfig) {
$passwordMatch = ($pwdConfig == $pwd);
}
/**
* Allow or disallow remote download of images from other servers.
* Passwords apply if used.
*
*/
$allowRemote = getConfig('remote_allow', false);
if ($allowRemote && $passwordMatch !== false) {
$pattern = getConfig('remote_pattern', null);
$img->setRemoteDownload($allowRemote, $pattern);
@@ -625,6 +628,33 @@ $postProcessing = getConfig('postprocessing', array(
/**
* alias - Save resulting image to another alias name.
* Password apply if defined.
*/
$alias = get('alias', null);
$aliasPath = getConfig('alias_path', null);
$aliasTarget = null;
if ($alias && $aliasPath) {
$aliasTarget = $aliasPath . $alias;
$useCache = false;
($passwordMatch !== false)
or errorPage("Alias used and password check failed.");
is_writable($aliasPath)
or errorPage("Directory for alias is not writable.");
preg_match($validFilename, $alias)
or errorPage('Filename for alias contains invalid characters.');
} else if ($alias) {
errorPage('Alias is not enabled in the config file.');
}
verbose("alias = $alias");
/**
* Display image if verbose mode
*/
@@ -716,4 +746,5 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
->postResize()
->setPostProcessingOptions($postProcessing)
->save()
->linkToCacheFile($aliasTarget)
->output();

View File

@@ -17,9 +17,42 @@ return array(
/**
* Paths, where are the images stored and where is the cache.
* End all paths with a slash.
*
* Default values:
* image_path: No default value
* cache_path: No default value
* alias_path: null
*/
'image_path' => __DIR__ . '/img/',
'cache_path' => __DIR__ . '/../cache/',
//'alias_path' => __DIR__ . '/img/alias/',
/**
* Use password to protect from missusage, send &pwd=... or &password=..
* with the request to match the password or set to false to disable.
* Passwords are only used together with the options for remote download
* and aliasing.
*
* Default values.
* password: false // as in do not use password
*/
//'password' => false, // "secret-password",
/**
* Allow or disallow downloading of remote files, images available on
* some remote server. Default is to disallow.
*
* Default values.
* remote_allow: false
* remote_pattern: null // use default values from CImage
*/
//'remote_allow' => true,
//'remote_pattern' => '#^https?://#',
@@ -45,23 +78,6 @@ return array(
/**
* Allow or disallow downloading of remote files, images available on
* some remote server. Default is to disallow.
* Use password to protect from missusage, send &pwd=... or &password=..
* with the request to match the password or set to false to disable.
*
* Default values.
* remote_allow: false
* remote_password: false // as in do not use password
* remote_pattern: null // use default values from CImage
*/
'remote_allow' => true,
//'remote_password' => false, // "secret-password",
//'remote_pattern' => '#^https?://#',
/**
* Set default timezone.
*