Skip to content

Commit e132703

Browse files
committed
Up phpthumb to 1.3.3
1 parent 91e3699 commit e132703

2 files changed

Lines changed: 23 additions & 25 deletions

File tree

assets/snippets/phpthumb/snippet.phpthumb.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* PHPThumb creates thumbnails and altered images on the fly and caches them
66
*
77
* @category snippet
8-
* @version 1.3.2
8+
* @version 1.3.3
99
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
1010
* @internal @properties
1111
* @internal @modx_category Content
@@ -16,61 +16,57 @@
1616
* @link noimage.png here [+site_url+]assets/snippets/phpthumb/noimage.png
1717
* @author Bumkaka
1818
* @author Many contributors since then
19-
* @lastupdate 30/10/2018
19+
* @lastupdate 26/11/2018
2020
*/
21-
if (!defined('MODX_BASE_PATH')) {
21+
if (! defined('MODX_BASE_PATH')) {
2222
die('What are you doing? Get out of here!');
2323
}
2424

2525
$newFolderAccessMode = $modx->getConfig('new_folder_permissions');
2626
$newFolderAccessMode = empty($new) ? 0777 : octdec($newFolderAccessMode);
2727

28-
$cacheFolder = isset($cacheFolder) ? $cacheFolder : $modx->getCacheFolder() . "images";
28+
$cacheFolder = isset($cacheFolder) ? $cacheFolder : $modx->getCacheFolder() . 'images';
29+
$phpThumbPath = isset($phpThumbPath) ? $phpThumbPath : 'assets/snippets/phpthumb/';
30+
2931
/**
3032
* @see: https://github.com/kalessil/phpinspectionsea/blob/master/docs/probable-bugs.md#mkdir-race-condition
3133
*/
3234
$path = MODX_BASE_PATH . $cacheFolder;
33-
if (!file_exists($path) && mkdir($path) && is_dir($path)) {
34-
chmod(MODX_BASE_PATH . $cacheFolder, $newFolderAccessMode);
35+
if (! file_exists($path) && mkdir($path) && is_dir($path)) {
36+
chmod($path, $newFolderAccessMode);
3537
}
3638

37-
$tmpFolder = $modx->getCacheFolder() . 'tmp';
3839
if (!empty($input)) {
3940
$input = rawurldecode($input);
4041
}
4142

42-
if (empty($input) || !file_exists(MODX_BASE_PATH . $input)) {
43-
$input = isset($noImage) ? $noImage : 'assets/snippets/phpthumb/noimage.png';
43+
if (empty($input) || ! file_exists(MODX_BASE_PATH . $input)) {
44+
$input = isset($noImage) ? $noImage : $phpThumbPath . 'noimage.png';
4445
}
4546

4647
/**
4748
* allow read in phpthumb cache folder
4849
*/
49-
if (!file_exists(MODX_BASE_PATH . $cacheFolder . '/.htaccess') &&
50+
if (! file_exists(MODX_BASE_PATH . $cacheFolder . '/.htaccess') &&
5051
$cacheFolder !== $modx->getCacheFolder() &&
5152
strpos($cacheFolder, $modx->getCacheFolder()) === 0
5253
) {
5354
file_put_contents(MODX_BASE_PATH . $cacheFolder . '/.htaccess', "order deny,allow\nallow from all\n");
5455
}
5556

56-
$path = MODX_BASE_PATH . $tmpFolder;
57-
if (!file_exists($path) && mkdir($path) && is_dir($path)) {
58-
chmod($path, $newFolderAccessMode);
59-
}
60-
6157
$path_parts = pathinfo($input);
62-
$tmpImagesFolder = str_replace('assets/images', '',$path_parts['dirname']);
58+
$tmpImagesFolder = str_replace('assets/images', '', $path_parts['dirname']);
6359
$tmpImagesFolder = explode('/', $tmpImagesFolder);
6460
$ext = strtolower($path_parts['extension']);
6561
$options = 'f=' . (in_array($ext, array('png', 'gif', 'jpeg')) ? $ext : 'jpg&q=85') . '&' .
6662
strtr($options, array(',' => '&', '_' => '=', '{' => '[', '}' => ']'));
6763

6864
parse_str($options, $params);
6965
foreach ($tmpImagesFolder as $folder) {
70-
if (!empty($folder)) {
66+
if (! empty($folder)) {
7167
$cacheFolder .= '/' . $folder;
7268
$path = MODX_BASE_PATH . $cacheFolder;
73-
if (!file_exists($path) && mkdir($path) && is_dir($path)) {
69+
if (! file_exists($path) && mkdir($path) && is_dir($path)) {
7470
chmod($path, $newFolderAccessMode);
7571
}
7672
}
@@ -79,16 +75,18 @@
7975
$fNamePref = rtrim($cacheFolder, '/') . '/';
8076
$fName = $path_parts['filename'];
8177
$fNameSuf = '-' .
82-
$params['w'] .'x' . $params['h'] . '-' .
78+
(isset($params['w']) ? $params['w'] : '') .'x' . (isset($params['h']) ? $params['h'] : '') . '-' .
8379
substr(md5(serialize($params) . filemtime(MODX_BASE_PATH . $input)), 0, 3) .
8480
'.' . $params['f'];
8581

8682
$outputFilename = MODX_BASE_PATH . $fNamePref . $fName . $fNameSuf;
87-
if (!file_exists($outputFilename)) {
88-
require_once MODX_BASE_PATH . 'assets/snippets/phpthumb/phpthumb.class.php';
83+
if (! file_exists($outputFilename)) {
84+
if (! class_exists('phpthumb')) {
85+
require_once MODX_BASE_PATH . $phpThumbPath . '/phpthumb.class.php';
86+
}
8987
$phpThumb = new phpthumb();
90-
$phpThumb->config_cache_directory = MODX_BASE_PATH . $tmpFolder;
91-
$phpThumb->config_temp_directory = $tmpFolder;
88+
$phpThumb->config_cache_directory = MODX_BASE_PATH . $modx->getCacheFolder();
89+
$phpThumb->config_temp_directory = $modx->getCacheFolder();
9290
$phpThumb->config_document_root = MODX_BASE_PATH;
9391
$phpThumb->setSourceFilename(MODX_BASE_PATH . $input);
9492
foreach ($params as $key => $value) {
@@ -101,4 +99,4 @@
10199
}
102100
}
103101

104-
return $fNamePref . rawurlencode($fName) . $fNameSuf;
102+
return $fNamePref . rawurlencode($fName) . $fNameSuf;

install/assets/snippets/phpthumb.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* PHPThumb creates thumbnails and altered images on the fly and caches them
66
*
77
* @category snippet
8-
* @version 1.3.2
8+
* @version 1.3.3
99
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
1010
* @internal @properties
1111
* @internal @modx_category Content

0 commit comments

Comments
 (0)