forked from XoopsModules25x/adslight
-
Notifications
You must be signed in to change notification settings - Fork 1
/
view_photos.php
209 lines (174 loc) · 7.16 KB
/
view_photos.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php declare(strict_types=1);
/*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* @copyright XOOPS Project (https://xoops.org)
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
* @author XOOPS Development Team
* @author Pascal Le Boustouller: original author ([email protected])
* @author Luc Bizet (www.frxoops.org)
* @author jlm69 (www.jlmzone.com)
* @author mamba (www.xoops.org)
*/
use Xmf\Request;
use XoopsModules\Adslight\{
Pictures,
PicturesHandler,
Utility
};
/** @var Helper $helper */
require_once __DIR__ . '/header.php';
/**
* Xoops header
*/
require_once \dirname(__DIR__, 2) . '/mainfile.php';
$GLOBALS['xoopsOption']['template_main'] = 'adslight_view_photos.tpl';
require_once XOOPS_ROOT_PATH . '/header.php';
global $xoopsModule, $xoopsDB, $xoopsConfig, $xoTheme;
/**
* Module classes
*/
$lid = Request::getInt('lid', 0, 'GET');
if (empty($lid)) {
//mb TODO $helper->redirect('index.php');
}
// Is a member looking ?
if ($GLOBALS['xoopsUser'] instanceof \XoopsUser) {
// If no $_GET['uid'] then redirect to own
if (Request::hasVar('uid', 'GET')) {
$uid = Request::getInt('uid', 0, 'GET');
} else {
$helper->redirect('index.php');
}
/**
* Is the user the owner of the album ?
*/
$isOwner = $GLOBALS['xoopsUser']->getVar('uid') === $uid;
$moduleId = $xoopsModule->getVar('mid');
$groups = &$GLOBALS['xoopsUser']->getGroups();
/** @var \XoopsGroupPermHandler $grouppermHandler */
$grouppermHandler = xoops_getHandler('groupperm');
$perm_itemid = Request::getInt('item_id', 0, 'POST');
//If no access
if ($grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $moduleId)) {
$permit = '1';
} else {
$permit = '0';
}
/**
* If it is an anonym
*/
} elseif (Request::hasVar('uid', 'GET')) { // user is anon
$uid = Request::getInt('uid', 0, 'GET');
} else {
$helper->redirect('index.php');
$isOwner = false;
}
/**
* Filter for search pictures in database
*/
$criteria_lid = new \Criteria('lid', $lid);
$criteria_uid = new \Criteria('uid', $uid);
// Creating a factory of pictures
$picturesHandler = $helper->getHandler('Pictures');
/**
* Fetch pictures from the factory
*/
$pictures_object_array = $picturesHandler->getObjects($criteria_lid, $criteria_uid);
// How many pictures are on the user album
$pictures_number = $picturesHandler->getCount($criteria_lid);
// Are there pictures in the album?
if (0 === $pictures_number) {
$GLOBALS['xoopsTpl']->assign('lang_nopicyet', _ADSLIGHT_NOTHINGYET);
} else {
// no pictures in the album
/**
* Let's populate an array with the data from the pictures
*/
$i = 0;
foreach ($pictures_object_array as $picture) {
$picturesArray[$i]['url'] = $picture->getVar('url', 's');
$picturesArray[$i]['desc'] = $picture->getVar('title', 's');
$picturesArray[$i]['cod_img'] = $picture->getVar('cod_img', 's');
$picturesArray[$i]['lid'] = $picture->getVar('lid', 's');
$GLOBALS['xoopsTpl']->assign('pics_array', $picturesArray);
++$i;
}
}
/**
* Show the form if it is the owner and he can still upload pictures
*/
if (!empty($GLOBALS['xoopsUser'])) {
if ($isOwner
&& $helper->getConfig('adslight_nb_pict') > $pictures_number) {
$maxfilebytes = $helper->getConfig('adslight_maxfilesize');
$picturesHandler->renderFormSubmit($uid, $lid, $maxfilebytes, $xoopsTpl);
}
}
/**
* Let's get the user name of the owner of the album
*/
$owner = new \XoopsUser();
$identifier = $owner::getUnameFromId($uid);
/**
* Adding to the module js and css of the lightbox and new ones
*/
Utility::loadLightbox(); // JJDai
// if (1 == $helper->getConfig('adslight_lightbox')) {
// $header_lightbox = '<script type="text/javascript" src="lightbox/js/prototype.js"></script>
// <script type="text/javascript" src="lightbox/js/scriptaculous.js?load=effects"></script>
// <script type="text/javascript" src="lightbox/js/lightbox.js"></script>
// <link rel="stylesheet" href="include/adslight.css" type="text/css" media="screen" >
// <link rel="stylesheet" href="lightbox/css/lightbox.css" type="text/css" media="screen" >';
// } else {
// $header_lightbox = '<link rel="stylesheet" href="assets/css/galery.css" type="text/css" media="screen" >';
//}
/**
* Assigning smarty variables
*/
$sql = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $lid . " AND valid='Yes'";
$result = $xoopsDB->query($sql);
if (!$xoopsDB->isResultSet($result)) {
\trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
}
while ([$title] = $xoopsDB->fetchRow($result)) {
$GLOBALS['xoopsTpl']->assign('lang_gtitle', "<a href='viewads.php?lid=" . $lid . "'>" . $title . '</a>');
$GLOBALS['xoopsTpl']->assign('lang_showcase', _ADSLIGHT_SHOWCASE);
}
$maxPicturesNumber = $helper->getConfig('adslight_not_premium');
if ($permit) {
$maxPicturesNumber = $helper->getConfig('adslight_nb_pict');
}
$GLOBALS['xoopsTpl']->assign('current_nb_pict', $pictures_number);
$GLOBALS['xoopsTpl']->assign('max_nb_pict', $maxPicturesNumber);
$GLOBALS['xoopsTpl']->assign('lang_not_premium', sprintf(_ADSLIGHT_BMCANHAVE, $helper->getConfig('adslight_not_premium')));
$GLOBALS['xoopsTpl']->assign('lang_no_prem_nb', sprintf(_ADSLIGHT_PREMYOUHAVE, $pictures_number));
$upgrade = '<a href="premium.php"><strong> ' . _ADSLIGHT_UPGRADE_NOW . '</strong></a>';
$GLOBALS['xoopsTpl']->assign('lang_upgrade_now', $upgrade);
$GLOBALS['xoopsTpl']->assign('lang_max_nb_pict', sprintf(_ADSLIGHT_YOUCANHAVE, $helper->getConfig('adslight_nb_pict')));
$GLOBALS['xoopsTpl']->assign('lang_nb_pict', sprintf(_ADSLIGHT_YOUHAVE, $pictures_number));
$GLOBALS['xoopsTpl']->assign('lang_albumtitle', sprintf(_ADSLIGHT_ALBUMTITLE, '<a href=' . XOOPS_URL . '/userinfo.php?uid=' . addslashes((string)$uid) . '>' . $identifier . '</a>'));
$GLOBALS['xoopsTpl']->assign('path_uploads', $helper->getConfig('adslight_link_upload'));
$GLOBALS['xoopsTpl']->assign('xoops_pagetitle', $xoopsModule->getVar('name') . ' - ' . $identifier . "'s album");
$GLOBALS['xoopsTpl']->assign('nome_modulo', $xoopsModule->getVar('name'));
$GLOBALS['xoopsTpl']->assign('lang_delete', _ADSLIGHT_DELETE);
$GLOBALS['xoopsTpl']->assign('lang_editdesc', _ADSLIGHT_EDITDESC);
$GLOBALS['xoopsTpl']->assign('isOwner', $isOwner);
$GLOBALS['xoopsTpl']->assign('permit', $permit);
//$GLOBALS['xoopsTpl']->assign('xoops_module_header', $header_lightbox);
$GLOBALS['xoopsTpl']->assign('xoopsSecurity', $GLOBALS['xoopsSecurity']->getTokenHTML());
/**
* Adding the comment system
*/
require_once XOOPS_ROOT_PATH . '/include/comment_view.php';
/**
* Closing the page
*/
require_once XOOPS_ROOT_PATH . '/footer.php';