1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: use Xoops\Module\Helper\HelperAbstract;
13:
14: /**
15: * Module helper for thumbs modue
16: *
17: * @category Xoops\Module\Helper
18: * @package Thumbs
19: * @author Richard Griffith <richard@geekwright.com>
20: * @copyright 2014 XOOPS Project (http://xoops.org)
21: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22: * @link http://xoops.org
23: */
24: class Thumbs extends HelperAbstract
25: {
26: /**
27: * init
28: *
29: * @return void
30: */
31: public function init()
32: {
33: $this->_dirname = 'thumbs';
34: }
35:
36: /**
37: * buildThumbPath
38: *
39: * @param string $imgPath xoops virtual path to image to be thumbed
40: * @param integer $width maximum width of thumbnail in pixels, 0 to use default
41: * @param integer $height maximum height of thumbnail in pixels, 0 to use default
42: *
43: * @return string xoops virtual path for the thumbnail
44: */
45: public function buildThumbPath($imgPath, $width, $height)
46: {
47: //$xoops = \Xoops::getInstance();
48: if ($width==0 && $height==0) {
49: $width = $this->getConfig('thumbs_width');
50: $height = $this->getConfig('thumbs_height');
51: }
52: $sizeDir = sprintf('/%01dx%01d/', $width, $height);
53: $pathParts = pathinfo($imgPath);
54: if ($pathParts['dirname'] === '.') {
55: $pathParts['dirname'] = '';
56: }
57: $thumbPath = 'assets/thumbs/' . $pathParts['dirname'].$sizeDir.$pathParts['basename'];
58:
59: return $thumbPath;
60: }
61: }
62: