1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-09-01 03:41:43 +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();