mambax7 /
extgallery
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * ExtGallery Class Manager |
||
| 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 | */ |
||
| 17 | |||
| 18 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
||
| 19 | |||
| 20 | require_once __DIR__ . '/photoHandler.php'; |
||
| 21 | require_once __DIR__ . '/publicPerm.php'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Class ExtgalleryPublicPhoto |
||
| 25 | */ |
||
| 26 | class ExtgalleryPublicPhoto extends ExtgalleryPhoto |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * ExtgalleryPublicPhoto constructor. |
||
| 30 | */ |
||
| 31 | public function __construct() |
||
| 32 | { |
||
| 33 | parent::__construct(); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Class ExtgalleryPublicPhotoHandler |
||
| 39 | */ |
||
| 40 | class ExtgalleryPublicPhotoHandler extends ExtgalleryPhotoHandler |
||
| 41 | { |
||
| 42 | /** |
||
| 43 | * ExtgalleryPublicPhotoHandler constructor. |
||
| 44 | * @param XoopsDatabase $db |
||
| 45 | */ |
||
| 46 | public function __construct(XoopsDatabase $db) |
||
| 47 | { |
||
| 48 | parent::__construct($db, 'public'); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param $photo |
||
| 53 | */ |
||
| 54 | public function deleteFile(XoopsObject $photo = null) |
||
| 55 | { |
||
| 56 | View Code Duplication | if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name'))) { |
|
| 57 | unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name')); |
||
| 58 | } |
||
| 59 | |||
| 60 | View Code Duplication | if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $photo->getVar('photo_name'))) { |
|
| 61 | unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $photo->getVar('photo_name')); |
||
| 62 | } |
||
| 63 | |||
| 64 | View Code Duplication | if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/large/large_' . $photo->getVar('photo_name'))) { |
|
| 65 | unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/large/large_' . $photo->getVar('photo_name')); |
||
| 66 | } |
||
| 67 | |||
| 68 | View Code Duplication | if ('' != $photo->getVar('photo_orig_name') |
|
|
0 ignored issues
–
show
|
|||
| 69 | && file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/original/' . $photo->getVar('photo_orig_name'))) { |
||
| 70 | unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/original/' . $photo->getVar('photo_orig_name')); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @return array|int|string |
||
| 76 | */ |
||
| 77 | public function getAllSize() |
||
| 78 | { |
||
| 79 | return $this->getSum(null, 'photo_size'); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return string |
||
| 84 | */ |
||
| 85 | public function _getUploadPhotoPath() |
||
| 86 | { |
||
| 87 | return XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/'; |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @param $userId |
||
| 92 | * @param $start |
||
| 93 | * @param $sortby |
||
| 94 | * @param $orderby |
||
| 95 | * |
||
| 96 | * @return array |
||
| 97 | */ |
||
| 98 | public function getUserAlbumPhotoPage($userId, $start, $sortby, $orderby) |
||
| 99 | { |
||
| 100 | $catHandler = xoops_getModuleHandler('publiccat', 'extgallery'); |
||
| 101 | |||
| 102 | $criteria = new CriteriaCompo(); |
||
| 103 | $criteria->add($catHandler->getCatRestrictCriteria()); |
||
| 104 | $criteria->add(new Criteria('photo_approved', 1)); |
||
| 105 | $criteria->add(new Criteria('uid', $userId)); |
||
| 106 | $criteria->setSort($sortby); |
||
| 107 | $criteria->setOrder($orderby); |
||
| 108 | $criteria->setStart($start); |
||
| 109 | $criteria->setLimit($GLOBALS['xoopsModuleConfig']['nb_column'] * $GLOBALS['xoopsModuleConfig']['nb_line']); |
||
| 110 | |||
| 111 | return $this->getObjects($criteria); |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @param $userId |
||
| 116 | * @param $photoDate |
||
| 117 | * |
||
| 118 | * @return array |
||
| 119 | */ |
||
| 120 | View Code Duplication | public function getUserAlbumPrevPhoto($userId, $photoDate) |
|
| 121 | { |
||
| 122 | $catHandler = xoops_getModuleHandler('publiccat', 'extgallery'); |
||
| 123 | |||
| 124 | $criteria = new CriteriaCompo(); |
||
| 125 | $criteria->add($catHandler->getCatRestrictCriteria()); |
||
| 126 | $criteria->add(new Criteria('photo_approved', 1)); |
||
| 127 | $criteria->add(new Criteria('uid', $userId)); |
||
| 128 | $criteria->add(new Criteria('photo_date', $photoDate, '>')); |
||
| 129 | $criteria->setSort('photo_date'); |
||
| 130 | $criteria->setOrder('ASC'); |
||
| 131 | $criteria->setLimit(1); |
||
| 132 | |||
| 133 | return $this->getObjects($criteria); |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @param $userId |
||
| 138 | * @param $photoDate |
||
| 139 | * |
||
| 140 | * @return array |
||
| 141 | */ |
||
| 142 | View Code Duplication | public function getUserAlbumNextPhoto($userId, $photoDate) |
|
| 143 | { |
||
| 144 | $catHandler = xoops_getModuleHandler('publiccat', 'extgallery'); |
||
| 145 | |||
| 146 | $criteria = new CriteriaCompo(); |
||
| 147 | $criteria->add($catHandler->getCatRestrictCriteria()); |
||
| 148 | $criteria->add(new Criteria('photo_approved', 1)); |
||
| 149 | $criteria->add(new Criteria('uid', $userId)); |
||
| 150 | $criteria->add(new Criteria('photo_date', $photoDate, '<')); |
||
| 151 | $criteria->setSort('photo_date'); |
||
| 152 | $criteria->setOrder('DESC'); |
||
| 153 | $criteria->setLimit(1); |
||
| 154 | |||
| 155 | return $this->getObjects($criteria); |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param $userId |
||
| 160 | * @param $photoDate |
||
| 161 | * |
||
| 162 | * @return int |
||
| 163 | */ |
||
| 164 | View Code Duplication | public function getUserAlbumCurrentPhotoPlace($userId, $photoDate) |
|
| 165 | { |
||
| 166 | $catHandler = xoops_getModuleHandler('publiccat', 'extgallery'); |
||
| 167 | |||
| 168 | $criteria = new CriteriaCompo(); |
||
| 169 | $criteria->add($catHandler->getCatRestrictCriteria()); |
||
| 170 | $criteria->add(new Criteria('photo_approved', 1)); |
||
| 171 | $criteria->add(new Criteria('uid', $userId)); |
||
| 172 | $criteria->add(new Criteria('photo_date', $photoDate, '>=')); |
||
| 173 | $criteria->setSort('photo_date'); |
||
| 174 | $criteria->setOrder('ASC'); |
||
| 175 | |||
| 176 | return $this->getCount($criteria); |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @param $userId |
||
| 181 | * |
||
| 182 | * @return int |
||
| 183 | */ |
||
| 184 | public function getUserAlbumCount($userId) |
||
| 185 | { |
||
| 186 | $catHandler = xoops_getModuleHandler('publiccat', 'extgallery'); |
||
| 187 | |||
| 188 | $criteria = new CriteriaCompo(); |
||
| 189 | $criteria->add($catHandler->getCatRestrictCriteria()); |
||
| 190 | $criteria->add(new Criteria('photo_approved', 1)); |
||
| 191 | $criteria->add(new Criteria('uid', $userId)); |
||
| 192 | |||
| 193 | return $this->getCount($criteria); |
||
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @param $userId |
||
| 198 | * |
||
| 199 | * @return array |
||
| 200 | */ |
||
| 201 | View Code Duplication | public function getUserPhotoAlbumId($userId) |
|
| 202 | { |
||
| 203 | $criteria = new CriteriaCompo(); |
||
| 204 | $criteria->add(new Criteria('uid', $userId)); |
||
| 205 | $criteria->add(new Criteria('photo_approved', 1)); |
||
| 206 | |||
| 207 | $sql = 'SELECT photo_id FROM ' . $this->db->prefix('extgallery_publicphoto') . ' ' . $criteria->renderWhere() . ' ORDER BY photo_date, photo_id DESC;'; |
||
| 208 | |||
| 209 | $result = $this->db->query($sql); |
||
| 210 | $ret = []; |
||
| 211 | while (false !== ($myrow = $this->db->fetchArray($result))) { |
||
| 212 | $ret[] = $myrow['photo_id']; |
||
| 213 | } |
||
| 214 | |||
| 215 | return $ret; |
||
| 216 | } |
||
| 217 | } |
||
| 218 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.