XOOPS  2.6.0
ThumbsProvider.php
Go to the documentation of this file.
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 
15 use Xoops\Html\Img;
16 
28 {
30  protected $renderScript = 'modules/thumbs/include/thumbrender.php';
31 
38  public function getName()
39  {
40  return 'thumbs';
41  }
42 
48  public function getDescription()
49  {
50  return 'Thumbnail generation using stefangabos/zebra_image';
51  }
52 
53 
63  private function getThumbnailUrl($imgPath, $width, $height)
64  {
66  $helper = $xoops->getModuleHelper('thumbs');
67  $thumbPath = $helper->buildThumbPath($imgPath, $width, $height);
68 
69  $originalMtime = filemtime($xoops->path($imgPath));
70  $thumbMtime = filemtime($xoops->path($thumbPath));
71  if (false===$thumbMtime || $originalMtime>$thumbMtime) {
72  $params = array(
73  'img' => (string) $imgPath,
74  );
75  if ($height) {
76  $params['h'] = $height;
77  }
78  if ($width) {
79  $params['w'] = $width;
80  }
81  $url = $xoops->buildUrl($xoops->url($this->renderScript), $params);
82  } else {
83  $url = $xoops->url($thumbPath);
84  }
85 
86  return $url;
87  }
88 
99  public function getImgUrl(Response $response, $imgPath, $width = 0, $height = 0)
100  {
101  $response->setValue($this->getThumbnailUrl($imgPath, $width, $height));
102  }
103 
115  public function getImgTag(
117  $imgPath,
118  $width = 0,
119  $height = 0,
120  $attributes = array()
121  ) {
123 
124  $imgTag = new Img(array('src' => $url));
125  $imgTag->setAttributes($attributes);
126  $response->setValue($imgTag->render());
127  }
128 }
getImgTag(Response $response, $imgPath, $width=0, $height=0, $attributes=array())
static getInstance()
Definition: Xoops.php:160
getImgUrl(Response $response, $imgPath, $width=0, $height=0)
$imgPath
Definition: thumbrender.php:27
getThumbnailUrl($imgPath, $width, $height)
$xoops
Definition: admin.php:25
$thumbPath
Definition: thumbrender.php:37
$height
$helper
$url
Definition: register.php:72
$width
if($xoops->isUser()&&$isAdmin) $response
Definition: userinfo.php:83