mirror of
https://github.com/mosbth/cimage.git
synced 2025-07-25 18:51:19 +02:00
adding support for alias #47
This commit is contained in:
31
CImage.php
31
CImage.php
@@ -2134,6 +2134,37 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a hard link, as an alias, to the cached file.
|
||||||
|
*
|
||||||
|
* @param string $alias where to store the link.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function linkToCacheFile($alias)
|
||||||
|
{
|
||||||
|
if ($alias === null) {
|
||||||
|
$this->log("Ignore creating alias.");
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_readable($alias)) {
|
||||||
|
unlink($alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = link($this->cacheFileName, $alias);
|
||||||
|
|
||||||
|
if ($res) {
|
||||||
|
$this->log("Created an alias to the cachefile: $alias");
|
||||||
|
} else {
|
||||||
|
$this->log("Failed to create the alias: $alias");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output image to browser using caching.
|
* Output image to browser using caching.
|
||||||
*
|
*
|
||||||
|
@@ -280,6 +280,8 @@ Revision history
|
|||||||
|
|
||||||
v0.6.x (latest)
|
v0.6.x (latest)
|
||||||
|
|
||||||
|
* Support for option `password, pwd` to protect usage of `alias` and remote download.
|
||||||
|
* Added support for option `alias` that creates a link to a cached version of the image #47.
|
||||||
* Create cache directory for remote download if it does not exists.
|
* Create cache directory for remote download if it does not exists.
|
||||||
* Cleaned up `img_config.php` and introduced default values for almost all options #72.
|
* Cleaned up `img_config.php` and introduced default values for almost all options #72.
|
||||||
|
|
||||||
@@ -287,6 +289,7 @@ v0.6.x (latest)
|
|||||||
v0.6.2 (2015-01-14)
|
v0.6.2 (2015-01-14)
|
||||||
|
|
||||||
* Added support for download of remote images #43.
|
* Added support for download of remote images #43.
|
||||||
|
* Added autoloader.
|
||||||
|
|
||||||
|
|
||||||
v0.6.1 (2015-01-08)
|
v0.6.1 (2015-01-08)
|
||||||
|
@@ -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);
|
$pwdConfig = getConfig('password', false);
|
||||||
$remotePwd = getConfig('remote_password', false);
|
|
||||||
$pwd = get(array('password', 'pwd'), null);
|
$pwd = get(array('password', 'pwd'), null);
|
||||||
|
|
||||||
// Check if passwords match, if configured to use passwords
|
// Check if passwords match, if configured to use passwords
|
||||||
$passwordMatch = null;
|
$passwordMatch = null;
|
||||||
if ($remotePwd != false) {
|
if ($pwdConfig) {
|
||||||
if ($remotePwd == $pwd) {
|
$passwordMatch = ($pwdConfig == $pwd);
|
||||||
$passwordMatch = true;
|
|
||||||
} else {
|
|
||||||
$passwordMatch = false;
|
|
||||||
errorPage('Trying to download remote image but missing password.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow or disallow remote download of images from other servers.
|
||||||
|
* Passwords apply if used.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$allowRemote = getConfig('remote_allow', false);
|
||||||
|
|
||||||
if ($allowRemote && $passwordMatch !== false) {
|
if ($allowRemote && $passwordMatch !== false) {
|
||||||
$pattern = getConfig('remote_pattern', null);
|
$pattern = getConfig('remote_pattern', null);
|
||||||
$img->setRemoteDownload($allowRemote, $pattern);
|
$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
|
* Display image if verbose mode
|
||||||
*/
|
*/
|
||||||
@@ -716,4 +746,5 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
|
|||||||
->postResize()
|
->postResize()
|
||||||
->setPostProcessingOptions($postProcessing)
|
->setPostProcessingOptions($postProcessing)
|
||||||
->save()
|
->save()
|
||||||
|
->linkToCacheFile($aliasTarget)
|
||||||
->output();
|
->output();
|
||||||
|
@@ -17,9 +17,42 @@ return array(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Paths, where are the images stored and where is the cache.
|
* 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/',
|
'image_path' => __DIR__ . '/img/',
|
||||||
'cache_path' => __DIR__ . '/../cache/',
|
'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.
|
* Set default timezone.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user