mambax7 /
extgallery
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * ExtGallery User area |
||
| 4 | * |
||
| 5 | * You may not change or alter any portion of this comment or credits |
||
| 6 | * of supporting developers from this source code or any supporting source code |
||
| 7 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 8 | * This program is distributed in the hope that it will be useful, |
||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 11 | * |
||
| 12 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 13 | * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
||
| 14 | * @author Zoullou (http://www.zoullou.net) |
||
| 15 | * @package ExtGallery |
||
| 16 | * @version $Id: hook-photo.php 8088 2011-11-06 09:38:12Z beckmi $ |
||
| 17 | */ |
||
| 18 | |||
| 19 | |||
| 20 | use XoopsModules\Extgallery; |
||
| 21 | |||
| 22 | include __DIR__ . '/header.php'; |
||
| 23 | require_once XOOPS_ROOT_PATH . '/modules/extgallery/class/publicPerm.php'; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 24 | |||
| 25 | if (!isset($_GET['id'])) { |
||
| 26 | $photoId = 0; |
||
| 27 | } else { |
||
| 28 | $photoId = (int)$_GET['id']; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** @var Extgallery\PublicPhotoHandler $photoHandler */ |
||
| 32 | /** @var Extgallery\Photo $photo */ |
||
| 33 | $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto'); |
||
| 34 | $photoHandler->updateHits($photoId); |
||
| 35 | $photo = $photoHandler->get($photoId); |
||
| 36 | |||
| 37 | switch (strtolower(strrchr($photo->getVar('photo_name'), '.'))) { |
||
| 38 | case '.png': |
||
| 39 | $type = 'image/png'; |
||
| 40 | break; |
||
| 41 | case '.gif': |
||
| 42 | $type = 'image/gif'; |
||
| 43 | break; |
||
| 44 | case '.jpg': |
||
| 45 | $type = 'image/jpeg'; |
||
| 46 | break; |
||
| 47 | default: |
||
| 48 | $type = 'application/octet-stream'; |
||
| 49 | break; |
||
| 50 | } |
||
| 51 | |||
| 52 | $permHandler = Extgallery\PublicPermHandler::getInstance(); |
||
| 53 | |||
| 54 | // If require image don't exist |
||
| 55 | if (0 == $photo->getVar('cat_id')) { |
||
| 56 | header('Content-type: image/jpeg'); |
||
| 57 | readfile(XOOPS_ROOT_PATH . '/modules/extgallery/assets/images/dont-exist.jpg'); |
||
| 58 | |||
| 59 | // If user is allowed to view this picture |
||
| 60 | } elseif ($permHandler->isAllowed($xoopsUser, 'public_access', $photo->getVar('cat_id'))) { |
||
| 61 | $photo = $photoHandler->objectToArray($photo); |
||
| 62 | header('Content-type: ' . $type . ''); |
||
| 63 | readfile(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $photo['photo_name']); |
||
| 64 | |||
| 65 | // If user isn't allowed to view this picture |
||
| 66 | } else { |
||
| 67 | header('Content-type: image/jpeg'); |
||
| 68 | readfile(XOOPS_ROOT_PATH . '/modules/extgallery/assets/images/not-allowed.jpg'); |
||
| 69 | } |
||
| 70 |