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 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 | */ |
|||||||||||
17 | ||||||||||||
18 | include __DIR__ . '/header.php'; |
|||||||||||
19 | require_once XOOPS_ROOT_PATH . '/modules/extgallery/class/publicPerm.php'; |
|||||||||||
20 | ||||||||||||
21 | $GLOBALS['xoopsOption']['template_main'] = 'extgallery_public-photo.tpl'; |
|||||||||||
22 | include XOOPS_ROOT_PATH . '/header.php'; |
|||||||||||
23 | ||||||||||||
24 | View Code Duplication | if (!isset($_GET['photoId'])) { |
||||||||||
25 | $photoId = 0; |
|||||||||||
26 | } else { |
|||||||||||
27 | $photoId = (int)$_GET['photoId']; |
|||||||||||
28 | } |
|||||||||||
29 | /** @var ExtgalleryPublicCatHandler $catHandler */ |
|||||||||||
30 | $catHandler = xoops_getModuleHandler('publiccat', 'extgallery'); |
|||||||||||
31 | /** @var ExtgalleryPublicPhotoHandler $photoHandler */ |
|||||||||||
32 | $photoHandler = xoops_getModuleHandler('publicphoto', 'extgallery'); |
|||||||||||
33 | /** @var ExtgalleryPublicRatingHandler $ratingHandler */ |
|||||||||||
34 | $ratingHandler = xoops_getModuleHandler('publicrating', 'extgallery'); |
|||||||||||
35 | $permHandler = ExtgalleryPublicPermHandler::getInstance(); |
|||||||||||
36 | ||||||||||||
37 | $photoObj = $photoHandler->getPhoto($photoId); |
|||||||||||
38 | ||||||||||||
39 | // Check is the photo exist |
|||||||||||
40 | if (!$photoObj) { |
|||||||||||
41 | redirect_header('index.php', 3, _NOPERM); |
|||||||||||
42 | } |
|||||||||||
43 | ||||||||||||
44 | $photo = $photoHandler->objectToArray($photoObj, ['cat_id', 'uid']); |
|||||||||||
45 | ||||||||||||
46 | // Check the category access permission |
|||||||||||
47 | $permHandler = ExtgalleryPublicPermHandler::getInstance(); |
|||||||||||
48 | View Code Duplication | if (!$permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_access', $photo['cat']['cat_id'])) { |
||||||||||
49 | redirect_header('index.php', 3, _NOPERM); |
|||||||||||
50 | } |
|||||||||||
51 | ||||||||||||
52 | // Don't update counter if user come from rating page |
|||||||||||
53 | View Code Duplication | if (isset($_SERVER['HTTP_REFERER']) && basename($_SERVER['HTTP_REFERER']) != 'public-rating.php?photoId=' . $photoId) { |
||||||||||
54 | $photoHandler->updateHits($photoId); |
|||||||||||
55 | } |
|||||||||||
56 | ||||||||||||
57 | // Plugin traitement |
|||||||||||
58 | $plugin = xoops_getModuleHandler('plugin', 'extgallery'); |
|||||||||||
59 | $params = ['catId' => $photo['cat']['cat_id'], 'photoId' => $photo['photo_id'], 'link' => []]; |
|||||||||||
60 | $plugin->triggerEvent('photoAlbumLink', $params); |
|||||||||||
61 | $photo['link'] = $params['link']; |
|||||||||||
62 | ||||||||||||
63 | $photo['photo_date'] = formatTimestamp($photo['photo_date'], _MEDIUMDATESTRING); |
|||||||||||
64 | $xoopsTpl->assign('photo', $photo); |
|||||||||||
65 | ||||||||||||
66 | $cat = $catHandler->objectToArray($catHandler->getCat($photo['cat']['cat_id'])); |
|||||||||||
67 | $xoopsTpl->assign('cat', $cat); |
|||||||||||
68 | ||||||||||||
69 | $catPath = $catHandler->objectToArray($catHandler->getPath($photo['cat']['cat_id'], true)); |
|||||||||||
70 | $xoopsTpl->assign('catPath', $catPath); |
|||||||||||
71 | ||||||||||||
72 | $photosIds = $photoHandler->getPhotoAlbumId($photoObj->getVar('cat_id')); |
|||||||||||
73 | ||||||||||||
74 | $nbPhoto = count($photosIds); |
|||||||||||
75 | $currentPhotoPlace = array_search($photoId, $photosIds); |
|||||||||||
76 | ||||||||||||
77 | View Code Duplication | if ($nbPhoto == 1) { |
||||||||||
78 | $prev = 0; |
|||||||||||
79 | $next = 0; |
|||||||||||
80 | } elseif ($currentPhotoPlace == 0) { |
|||||||||||
81 | $prev = 0; |
|||||||||||
82 | $next = $photosIds[$currentPhotoPlace + 1]; |
|||||||||||
83 | } elseif (($currentPhotoPlace + 1) == $nbPhoto) { |
|||||||||||
84 | $prev = $photosIds[$currentPhotoPlace - 1]; |
|||||||||||
85 | $next = 0; |
|||||||||||
86 | } else { |
|||||||||||
87 | $prev = $photosIds[$currentPhotoPlace - 1]; |
|||||||||||
88 | $next = $photosIds[$currentPhotoPlace + 1]; |
|||||||||||
89 | } |
|||||||||||
90 | $xoopsTpl->assign('prevId', $prev); |
|||||||||||
91 | $xoopsTpl->assign('nextId', $next); |
|||||||||||
92 | $xoopsTpl->assign('currentPhoto', $currentPhotoPlace + 1); |
|||||||||||
93 | $xoopsTpl->assign('totalPhoto', $nbPhoto); |
|||||||||||
94 | ||||||||||||
95 | //DNPROSSI - changed photo_desc to photo_title |
|||||||||||
96 | $xoopsTpl->assign('xoops_pagetitle', $photo['photo_title'] . ' - ' . $cat['cat_name']); |
|||||||||||
97 | $xoTheme->addMeta('meta', 'description', $photo['photo_title'] . ' - ' . $cat['cat_desc']); |
|||||||||||
98 | ||||||||||||
99 | $rel = 'alternate'; |
|||||||||||
100 | $attributes['rel'] = $rel; |
|||||||||||
101 | $attributes['type'] = 'application/rss+xml'; |
|||||||||||
102 | $attributes['title'] = _MD_EXTGALLERY_RSS; |
|||||||||||
103 | $attributes['href'] = XOOPS_URL . '/modules/extgallery/public-rss.php'; |
|||||||||||
104 | $xoTheme->addMeta('link', $rel, $attributes); |
|||||||||||
105 | $xoTheme->addStylesheet('modules/extgallery/assets/css/style.css'); |
|||||||||||
106 | ||||||||||||
107 | $xoopsTpl->assign('rating', $ratingHandler->getRate($photoId)); |
|||||||||||
108 | ||||||||||||
109 | $lang = [ |
|||||||||||
110 | 'preview' => _MD_EXTGALLERY_PREVIEW, |
|||||||||||
111 | 'next' => _MD_EXTGALLERY_NEXT, |
|||||||||||
112 | 'of' => _MD_EXTGALLERY_OF, |
|||||||||||
113 | 'voteFor' => _MD_EXTGALLERY_VOTE_FOR_THIS_PHOTO, |
|||||||||||
114 | 'photoInfo' => _MD_EXTGALLERY_PHOTO_INFORMATION, |
|||||||||||
115 | 'resolution' => _MD_EXTGALLERY_RESOLUTION, |
|||||||||||
116 | 'pixels' => _MD_EXTGALLERY_PIXELS, |
|||||||||||
117 | 'view' => _MD_EXTGALLERY_VIEW, |
|||||||||||
118 | 'hits' => _MD_EXTGALLERY_HITS, |
|||||||||||
119 | 'fileSize' => _MD_EXTGALLERY_FILE_SIZE, |
|||||||||||
120 | 'added' => _MD_EXTGALLERY_ADDED, |
|||||||||||
121 | 'score' => _MD_EXTGALLERY_SCORE, |
|||||||||||
122 | 'votes' => _MD_EXTGALLERY_VOTES, |
|||||||||||
123 | 'downloadOrig' => _MD_EXTGALLERY_DOWNLOAD_ORIG, |
|||||||||||
124 | 'donwloads' => _MD_EXTGALLERY_DOWNLOADS, |
|||||||||||
125 | 'sendEcard' => _MD_EXTGALLERY_SEND_ECARD, |
|||||||||||
126 | 'sends' => _MD_EXTGALLERY_SENDS, |
|||||||||||
127 | 'submitter' => _MD_EXTGALLERY_SUBMITTER, |
|||||||||||
128 | 'allPhotoBy' => _MD_EXTGALLERY_ALL_PHOTO_BY |
|||||||||||
129 | ]; |
|||||||||||
130 | $xoopsTpl->assign('lang', $lang); |
|||||||||||
131 | ||||||||||||
132 | View Code Duplication | if ($xoopsModuleConfig['enable_rating']) { |
||||||||||
133 | $xoopsTpl->assign('canRate', $permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_rate', $cat['cat_id'])); |
|||||||||||
134 | } else { |
|||||||||||
135 | $xoopsTpl->assign('canRate', false); |
|||||||||||
136 | //DNPROSSI - added preferences option - enable_rating |
|||||||||||
137 | $xoopsTpl->assign('enable_rating', $xoopsModuleConfig['enable_rating']); |
|||||||||||
138 | } |
|||||||||||
139 | ||||||||||||
140 | //DNPROSSI - added preferences option |
|||||||||||
141 | // enable_info, enable_resolution, enable_download, enable_date |
|||||||||||
142 | // enable_ecards, enable_submitter_lnk, enable_photo_hits |
|||||||||||
143 | View Code Duplication | if ($xoopsModuleConfig['info_view'] === 'photo' || $xoopsModuleConfig['info_view'] === 'both') { |
||||||||||
0 ignored issues
–
show
|
||||||||||||
144 | if ($xoopsModuleConfig['pubusr_info_view'] === 'public' || $xoopsModuleConfig['pubusr_info_view'] === 'both') { |
|||||||||||
145 | if ($xoopsModuleConfig['enable_info'] == 0) { |
|||||||||||
146 | $enable_info = $xoopsModuleConfig['enable_info']; |
|||||||||||
147 | } else { |
|||||||||||
148 | $enable_info = 1; |
|||||||||||
149 | } |
|||||||||||
150 | } else { |
|||||||||||
151 | $enable_info = 1; |
|||||||||||
152 | } |
|||||||||||
153 | } else { |
|||||||||||
154 | $enable_info = 1; |
|||||||||||
155 | } |
|||||||||||
156 | ||||||||||||
157 | $xoopsTpl->assign('enable_info', $enable_info); |
|||||||||||
158 | $xoopsTpl->assign('enable_resolution', $xoopsModuleConfig['enable_resolution']); |
|||||||||||
159 | $xoopsTpl->assign('enable_download', $xoopsModuleConfig['enable_download']); |
|||||||||||
160 | $xoopsTpl->assign('enable_date', $xoopsModuleConfig['enable_date']); |
|||||||||||
161 | $xoopsTpl->assign('enable_ecards', $xoopsModuleConfig['enable_ecards']); |
|||||||||||
162 | $xoopsTpl->assign('enable_submitter_lnk', $xoopsModuleConfig['enable_submitter_lnk']); |
|||||||||||
163 | $xoopsTpl->assign('enable_photo_hits', $xoopsModuleConfig['enable_photo_hits']); |
|||||||||||
164 | $xoopsTpl->assign('show_social_book', $xoopsModuleConfig['show_social_book']); |
|||||||||||
165 | ||||||||||||
166 | $xoopsTpl->assign('enableExtra', $xoopsModuleConfig['display_extra_field']); |
|||||||||||
167 | $xoopsTpl->assign('canSendEcard', $permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_ecard', $cat['cat_id'])); |
|||||||||||
168 | $xoopsTpl->assign('canDownload', $permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_download', $cat['cat_id'])); |
|||||||||||
169 | ||||||||||||
170 | $xoopsTpl->assign('extgalleryName', $xoopsModule->getVar('name')); |
|||||||||||
171 | $xoopsTpl->assign('disp_ph_title', $xoopsModuleConfig['disp_ph_title']); |
|||||||||||
172 | $xoopsTpl->assign('display_type', $xoopsModuleConfig['display_type']); |
|||||||||||
173 | $xoopsTpl->assign('show_rss', $xoopsModuleConfig['show_rss']); |
|||||||||||
174 | ||||||||||||
175 | // For xoops tag |
|||||||||||
176 | View Code Duplication | if (($xoopsModuleConfig['usetag'] == 1) and is_dir('../tag')) { |
||||||||||
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
177 | require_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php'; |
|||||||||||
178 | $xoopsTpl->assign('tagbar', tagBar($photo['photo_id'], $catid = 0)); |
|||||||||||
179 | $xoopsTpl->assign('tags', true); |
|||||||||||
180 | } else { |
|||||||||||
181 | $xoopsTpl->assign('tags', false); |
|||||||||||
182 | } |
|||||||||||
183 | ||||||||||||
184 | include XOOPS_ROOT_PATH . '/include/comment_view.php'; |
|||||||||||
185 | include XOOPS_ROOT_PATH . '/footer.php'; |
|||||||||||
186 |
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.