Completed
Pull Request — master (#14)
by
unknown
03:22
created

public-photo.php (1 issue)

Labels
Severity
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
use Xmf\Request;
19
use XoopsModules\Extgallery;
20
21
include __DIR__ . '/header.php';
22
23
$GLOBALS['xoopsOption']['template_main'] = 'extgallery_public-photo.tpl';
24
include XOOPS_ROOT_PATH . '/header.php';
25
26
/** @var Extgallery\Helper $helper */
27
$helper = Extgallery\Helper::getInstance();
28
29
if (!isset($_GET['photoId'])) {
30
    $photoId = 0;
31
} else {
32
    $photoId = \Xmf\Request::getInt('photoId', 0, 'GET');
33
}
34
/** @var Extgallery\PublicCategoryHandler $catHandler */
35
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
36
/** @var Extgallery\PublicPhotoHandler $photoHandler */
37
$photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
38
/** @var Extgallery\PublicRatingHandler $ratingHandler */
39
$ratingHandler = Extgallery\Helper::getInstance()->getHandler('PublicRating');
40
$permHandler   = Extgallery\PublicPermHandler::getInstance();
41
42
$photoObj = $photoHandler->getPhoto($photoId);
43
44
// Check is the photo exist
45
if (!$photoObj) {
46
    redirect_header('index.php', 3, _NOPERM);
47
}
48
49
$photo = $photoHandler->objectToArray($photoObj, ['cat_id', 'uid']);
50
51
// Check the category access permission
52
$permHandler = Extgallery\PublicPermHandler::getInstance();
53
if (!$permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_access', $photo['cat']['cat_id'])) {
54
    redirect_header('index.php', 3, _NOPERM);
55
}
56
57
// Don't update counter if user come from rating page
58
if (null !== (Request::getString('HTTP_REFERER', '', 'SERVER')) && basename(Request::getString('HTTP_REFERER', '', 'SERVER')) != 'public-rating.php?photoId=' . $photoId) {
59
    $photoHandler->updateHits($photoId);
60
}
61
62
// Plugin traitement
63
$plugin = Extgallery\Helper::getInstance()->getHandler('Plugin');
64
$params = ['catId' => $photo['cat']['cat_id'], 'photoId' => $photo['photo_id'], 'link' => []];
65
$plugin->triggerEvent('photoAlbumLink', $params);
0 ignored issues
show
The method triggerEvent() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsNotificationHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
$plugin->/** @scrutinizer ignore-call */ 
66
         triggerEvent('photoAlbumLink', $params);
Loading history...
66
$photo['link'] = $params['link'];
67
68
$photo['photo_date'] = formatTimestamp($photo['photo_date'], _MEDIUMDATESTRING);
69
$xoopsTpl->assign('photo', $photo);
70
71
$cat = $catHandler->objectToArray($catHandler->getCat($photo['cat']['cat_id']));
72
$xoopsTpl->assign('cat', $cat);
73
74
$catPath = $catHandler->objectToArray($catHandler->getPath($photo['cat']['cat_id'], true));
75
$xoopsTpl->assign('catPath', $catPath);
76
77
$photosIds = $photoHandler->getPhotoAlbumId($photoObj->getVar('cat_id'));
78
79
$nbPhoto           = count($photosIds);
80
$currentPhotoPlace = array_search($photoId, $photosIds);
81
82
if (1 == $nbPhoto) {
83
    $prev = 0;
84
    $next = 0;
85
} elseif (0 == $currentPhotoPlace) {
86
    $prev = 0;
87
    $next = $photosIds[$currentPhotoPlace + 1];
88
} elseif (($currentPhotoPlace + 1) == $nbPhoto) {
89
    $prev = $photosIds[$currentPhotoPlace - 1];
90
    $next = 0;
91
} else {
92
    $prev = $photosIds[$currentPhotoPlace - 1];
93
    $next = $photosIds[$currentPhotoPlace + 1];
94
}
95
$xoopsTpl->assign('prevId', $prev);
96
$xoopsTpl->assign('nextId', $next);
97
$xoopsTpl->assign('currentPhoto', $currentPhotoPlace + 1);
98
$xoopsTpl->assign('totalPhoto', $nbPhoto);
99
100
//DNPROSSI - changed photo_desc to photo_title
101
$xoopsTpl->assign('xoops_pagetitle', $photo['photo_title'] . ' - ' . $cat['cat_name']);
102
$xoTheme->addMeta('meta', 'description', $photo['photo_title'] . ' - ' . $cat['cat_desc']);
103
104
$rel                 = 'alternate';
105
$attributes['rel']   = $rel;
106
$attributes['type']  = 'application/rss+xml';
107
$attributes['title'] = _MD_EXTGALLERY_RSS;
108
$attributes['href']  = XOOPS_URL . '/modules/extgallery/public-rss.php';
109
$xoTheme->addMeta('link', $rel, $attributes);
110
$xoTheme->addStylesheet('modules/extgallery/assets/css/style.css');
111
112
$xoopsTpl->assign('rating', $ratingHandler->getRate($photoId));
113
114
$lang = [
115
    'preview'      => _MD_EXTGALLERY_PREVIEW,
116
    'next'         => _MD_EXTGALLERY_NEXT,
117
    'of'           => _MD_EXTGALLERY_OF,
118
    'voteFor'      => _MD_EXTGALLERY_VOTE_FOR_THIS_PHOTO,
119
    'photoInfo'    => _MD_EXTGALLERY_PHOTO_INFORMATION,
120
    'resolution'   => _MD_EXTGALLERY_RESOLUTION,
121
    'pixels'       => _MD_EXTGALLERY_PIXELS,
122
    'view'         => _MD_EXTGALLERY_VIEW,
123
    'hits'         => _MD_EXTGALLERY_HITS,
124
    'fileSize'     => _MD_EXTGALLERY_FILE_SIZE,
125
    'added'        => _MD_EXTGALLERY_ADDED,
126
    'score'        => _MD_EXTGALLERY_SCORE,
127
    'votes'        => _MD_EXTGALLERY_VOTES,
128
    'downloadOrig' => _MD_EXTGALLERY_DOWNLOAD_ORIG,
129
    'donwloads'    => _MD_EXTGALLERY_DOWNLOADS,
130
    'sendEcard'    => _MD_EXTGALLERY_SEND_ECARD,
131
    'sends'        => _MD_EXTGALLERY_SENDS,
132
    'submitter'    => _MD_EXTGALLERY_SUBMITTER,
133
    'allPhotoBy'   => _MD_EXTGALLERY_ALL_PHOTO_BY
134
];
135
$xoopsTpl->assign('lang', $lang);
136
137
if ($helper->getConfig('enable_rating')) {
138
    $xoopsTpl->assign('canRate', $permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_rate', $cat['cat_id']));
139
} else {
140
    $xoopsTpl->assign('canRate', false);
141
    //DNPROSSI - added preferences option - enable_rating
142
    $xoopsTpl->assign('enable_rating', $helper->getConfig('enable_rating'));
143
}
144
145
//DNPROSSI - added preferences option
146
//  enable_info, enable_resolution, enable_download, enable_date
147
//  enable_ecards, enable_submitter_lnk, enable_photo_hits
148
if ('photo' === $helper->getConfig('info_view') || 'both' === $helper->getConfig('info_view')) {
149
    if ('public' === $helper->getConfig('pubusr_info_view') || 'both' === $helper->getConfig('pubusr_info_view')) {
150
        if (0 == $helper->getConfig('enable_info')) {
151
            $enable_info = $helper->getConfig('enable_info');
152
        } else {
153
            $enable_info = 1;
154
        }
155
    } else {
156
        $enable_info = 1;
157
    }
158
} else {
159
    $enable_info = 1;
160
}
161
162
$xoopsTpl->assign('enable_info', $enable_info);
163
$xoopsTpl->assign('enable_resolution', $helper->getConfig('enable_resolution'));
164
$xoopsTpl->assign('enable_download', $helper->getConfig('enable_download'));
165
$xoopsTpl->assign('enable_date', $helper->getConfig('enable_date'));
166
$xoopsTpl->assign('enable_ecards', $helper->getConfig('enable_ecards'));
167
$xoopsTpl->assign('enable_submitter_lnk', $helper->getConfig('enable_submitter_lnk'));
168
$xoopsTpl->assign('enable_photo_hits', $helper->getConfig('enable_photo_hits'));
169
$xoopsTpl->assign('show_social_book', $helper->getConfig('show_social_book'));
170
171
$xoopsTpl->assign('enableExtra', $helper->getConfig('display_extra_field'));
172
$xoopsTpl->assign('canSendEcard', $permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_ecard', $cat['cat_id']));
173
$xoopsTpl->assign('canDownload', $permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_download', $cat['cat_id']));
174
175
$xoopsTpl->assign('extgalleryName', $xoopsModule->getVar('name'));
176
$xoopsTpl->assign('disp_ph_title', $helper->getConfig('disp_ph_title'));
177
$xoopsTpl->assign('display_type', $helper->getConfig('display_type'));
178
$xoopsTpl->assign('show_rss', $helper->getConfig('show_rss'));
179
180
// For xoops tag
181
if ((1 == $helper->getConfig('usetag')) && is_dir('../tag')) {
182
    require_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php';
183
    $xoopsTpl->assign('tagbar', tagBar($photo['photo_id'], $catid = 0));
184
    $xoopsTpl->assign('tags', true);
185
} else {
186
    $xoopsTpl->assign('tags', false);
187
}
188
189
include XOOPS_ROOT_PATH . '/include/comment_view.php';
190
include XOOPS_ROOT_PATH . '/footer.php';
191