Completed
Push — master ( 72613d...069c91 )
by Michael
02:16
created

public-userphoto.php (1 issue)

Upgrade to new PHP Analysis Engine

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-userphoto.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 ExtgalleryCatHandler $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
$photo['photo_date'] = date(_MEDIUMDATESTRING, $photo['photo_date']);
58
$xoopsTpl->assign('photo', $photo);
59
60
$photosIds = $photoHandler->getUserPhotoAlbumId($photoObj->getVar('uid'));
61
62
$nbPhoto           = count($photosIds);
63
$currentPhotoPlace = array_search($photoId, $photosIds);
64
65 View Code Duplication
if (1 == $nbPhoto) {
66
    $prev = 0;
67
    $next = 0;
68
} elseif (0 == $currentPhotoPlace) {
69
    $prev = 0;
70
    $next = $photosIds[$currentPhotoPlace + 1];
71
} elseif (($currentPhotoPlace + 1) == $nbPhoto) {
72
    $prev = $photosIds[$currentPhotoPlace - 1];
73
    $next = 0;
74
} else {
75
    $prev = $photosIds[$currentPhotoPlace - 1];
76
    $next = $photosIds[$currentPhotoPlace + 1];
77
}
78
$xoopsTpl->assign('prevId', $prev);
79
$xoopsTpl->assign('nextId', $next);
80
$xoopsTpl->assign('currentPhoto', $currentPhotoPlace + 1);
81
$xoopsTpl->assign('totalPhoto', $nbPhoto);
82
83
$albumName = $photo['user']['uname'] . _MD_EXTGALLERY_USERS_SUB_PHOTO_ALBUM;
84
$xoopsTpl->assign('xoops_pagetitle', $photo['photo_title'] . ' - ' . $albumName);
85
$xoTheme->addMeta('meta', 'description', $photo['photo_title'] . ' - ' . $albumName);
86
87
$rel                 = 'alternate';
88
$attributes['rel']   = $rel;
89
$attributes['type']  = 'application/rss+xml';
90
$attributes['title'] = _MD_EXTGALLERY_RSS;
91
$attributes['href']  = XOOPS_URL . '/modules/extgallery/public-rss.php';
92
$xoTheme->addMeta('link', $rel, $attributes);
93
$xoTheme->addStylesheet('modules/extgallery/assets/css/style.css');
94
95
$xoopsTpl->assign('rating', $ratingHandler->getRate($photoId));
96
97
$lang = [
98
    'preview'      => _MD_EXTGALLERY_PREVIEW,
99
    'next'         => _MD_EXTGALLERY_NEXT,
100
    'of'           => _MD_EXTGALLERY_OF,
101
    'voteFor'      => _MD_EXTGALLERY_VOTE_FOR_THIS_PHOTO,
102
    'photoInfo'    => _MD_EXTGALLERY_PHOTO_INFORMATION,
103
    'resolution'   => _MD_EXTGALLERY_RESOLUTION,
104
    'pixels'       => _MD_EXTGALLERY_PIXELS,
105
    'view'         => _MD_EXTGALLERY_VIEW,
106
    'hits'         => _MD_EXTGALLERY_HITS,
107
    'fileSize'     => _MD_EXTGALLERY_FILE_SIZE,
108
    'added'        => _MD_EXTGALLERY_ADDED,
109
    'score'        => _MD_EXTGALLERY_SCORE,
110
    'votes'        => _MD_EXTGALLERY_VOTES,
111
    'downloadOrig' => _MD_EXTGALLERY_DOWNLOAD_ORIG,
112
    'donwloads'    => _MD_EXTGALLERY_DOWNLOADS,
113
    'sendEcard'    => _MD_EXTGALLERY_SEND_ECARD,
114
    'sends'        => _MD_EXTGALLERY_SENDS,
115
    'submitter'    => _MD_EXTGALLERY_SUBMITTER,
116
    'allPhotoBy'   => _MD_EXTGALLERY_ALL_PHOTO_BY,
117
    'albumName'    => $albumName
118
];
119
$xoopsTpl->assign('lang', $lang);
120
121 View Code Duplication
if ($xoopsModuleConfig['enable_rating']) {
122
    $xoopsTpl->assign('canRate', $permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_rate', $cat['cat_id']));
123
} else {
124
    $xoopsTpl->assign('canRate', false);
125
    //DNPROSSI - added preferences option - enable_rating
126
    $xoopsTpl->assign('enable_rating', $xoopsModuleConfig['enable_rating']);
127
}
128
129
//DNPROSSI - added preferences option
130
//  enable_info, enable_resolution, enable_download, enable_date
131
//  enable_ecards, enable_submitter_lnk, enable_photo_hits
132 View Code Duplication
if ('photo' === $xoopsModuleConfig['info_view'] || 'both' === $xoopsModuleConfig['info_view']) {
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.

Loading history...
133
    if ('user' === $xoopsModuleConfig['pubusr_info_view'] || 'both' === $xoopsModuleConfig['pubusr_info_view']) {
134
        if (0 == $xoopsModuleConfig['enable_info']) {
135
            $enable_info = $xoopsModuleConfig['enable_info'];
136
        } else {
137
            $enable_info = 1;
138
        }
139
    } else {
140
        $enable_info = 1;
141
    }
142
} else {
143
    $enable_info = 1;
144
}
145
146
$xoopsTpl->assign('enable_info', $enable_info);
147
$xoopsTpl->assign('enable_resolution', $xoopsModuleConfig['enable_resolution']);
148
$xoopsTpl->assign('enable_download', $xoopsModuleConfig['enable_download']);
149
$xoopsTpl->assign('enable_date', $xoopsModuleConfig['enable_date']);
150
$xoopsTpl->assign('enable_ecards', $xoopsModuleConfig['enable_ecards']);
151
$xoopsTpl->assign('enable_submitter_lnk', $xoopsModuleConfig['enable_submitter_lnk']);
152
$xoopsTpl->assign('enable_photo_hits', $xoopsModuleConfig['enable_photo_hits']);
153
154
$xoopsTpl->assign('enableExtra', $xoopsModuleConfig['display_extra_field']);
155
$xoopsTpl->assign('canSendEcard', $permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_ecard', $photo['cat']['cat_id']));
156
$xoopsTpl->assign('canDownload', $permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_download', $photo['cat']['cat_id']));
157
158
$xoopsTpl->assign('extgalleryName', $xoopsModule->getVar('name'));
159
$xoopsTpl->assign('disp_ph_title', $xoopsModuleConfig['disp_ph_title']);
160
$xoopsTpl->assign('show_rss', $xoopsModuleConfig['show_rss']);
161
162
// For xoops tag
163
if ((1 == $xoopsModuleConfig['usetag']) && is_dir('../tag')) {
164
    require_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php';
165
    $xoopsTpl->assign('tagbar', tagBar($photo['photo_id'], $catid = 0));
166
    $xoopsTpl->assign('tags', true);
167
} else {
168
    $xoopsTpl->assign('tags', false);
169
}
170
171
include XOOPS_ROOT_PATH . '/include/comment_view.php';
172
include XOOPS_ROOT_PATH . '/footer.php';
173