-
Notifications
You must be signed in to change notification settings - Fork 5
/
singlefile.php
348 lines (312 loc) · 15.5 KB
/
singlefile.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php
/*
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.
*/
/**
* Wfdownloads module
*
* @copyright XOOPS Project (https://xoops.org)
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
* @package wfdownload
* @since 3.23
* @author Xoops Development Team
*/
use Xmf\Request;
use XoopsModules\Wfdownloads\{
Common,
Helper,
Utility,
ObjectTree
};
/** @var Helper $helper */
/** @var Utility $utility */
$currentFile = basename(__FILE__);
require_once __DIR__ . '/header.php';
/** @var \XoopsGroupPermHandler $grouppermHandler */
$grouppermHandler = xoops_getHandler('groupperm');
$lid = Request::getInt('lid', 0);
$downloadObj = $helper->getHandler('Download')->get($lid);
if (null === $downloadObj) {
redirect_header('index.php', 3, _CO_WFDOWNLOADS_ERROR_NODOWNLOAD);
}
$cid = Request::getInt('cid', $downloadObj->getVar('cid'));
$categoryObj = $helper->getHandler('Category')->get($cid);
if (null === $categoryObj) {
redirect_header('index.php', 3, _CO_WFDOWNLOADS_ERROR_NOCATEGORY);
}
// Check permissions
$userGroups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS];
if (!$grouppermHandler->checkRight('WFDownCatPerm', $cid, $userGroups, $helper->getModule()->mid())) {
if (in_array(XOOPS_GROUP_ANONYMOUS, $userGroups)) {
redirect_header(XOOPS_URL . '/user.php', 3, _MD_WFDOWNLOADS_NEEDLOGINVIEW);
} else {
redirect_header('index.php', 3, _NOPERM);
}
}
// Get download
if ($downloadObj->isNew()) {
redirect_header('index.php', 1, _MD_WFDOWNLOADS_NODOWNLOAD);
}
// If Download not published, expired or taken offline - redirect
if (0 == $downloadObj->getVar('published') || $downloadObj->getVar('published') > time()
|| true === $downloadObj->getVar('offline')
|| (0 != $downloadObj->getVar('expired')
&& $downloadObj->getVar('expired') < time())
|| _WFDOWNLOADS_STATUS_WAITING == $downloadObj->getVar('status')) {
redirect_header('index.php', 3, _MD_WFDOWNLOADS_NODOWNLOAD);
}
// Load Template
$GLOBALS['xoopsOption']['template_main'] = "{$helper->getModule()->dirname()}_singlefile.tpl";
require_once XOOPS_ROOT_PATH . '/header.php';
$xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js');
$xoTheme->addScript(WFDOWNLOADS_URL . '/assets/js/magnific/jquery.magnific-popup.min.js');
$xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/js/magnific/magnific-popup.css');
$xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/css/module.css');
$xoopsTpl->assign('wfdownloads_url', WFDOWNLOADS_URL . '/');
//assign title of the download to Page title
if ($helper->getConfig('shortTitles')) {
$xoopsTpl->assign('xoops_pagetitle', $downloadObj->getVar('title'));
} else {
$xoopsTpl->assign('xoops_pagetitle', $downloadObj->getVar('title') . ' | ' . $helper->getModule()->name());
}
// Making the category image and title available in the template
if (('' != $categoryObj->getVar('imgurl'))
&& is_file(XOOPS_ROOT_PATH . '/' . $helper->getConfig('catimage') . '/' . $categoryObj->getVar('imgurl'))) {
if ($helper->getConfig('usethumbs') && function_exists('gd_info')) {
$imgurl = Utility::createThumb(
$categoryObj->getVar('imgurl'),
$helper->getConfig('catimage'),
'thumbs',
$helper->getConfig('cat_imgwidth'),
$helper->getConfig('cat_imgheight'),
$helper->getConfig('imagequality'),
$helper->getConfig('updatethumbs'),
$helper->getConfig('keepaspect')
);
} else {
$imgurl = XOOPS_URL . '/' . $helper->getConfig('catimage') . '/' . $categoryObj->getVar('imgurl');
}
} else {
$imgurl = XOOPS_URL . '/' . $helper->getConfig('catimage') . '/blank.png';
}
$xoopsTpl->assign('category_title', $categoryObj->getVar('title'));
$xoopsTpl->assign('category_image', $imgurl);
// Retreiving the top parent category
$categoriesTopParentByCid = $helper->getHandler('Category')->getAllSubcatsTopParentCid();
$topCategoryObj = $helper->getHandler('Category')->get($categoriesTopParentByCid[$cid]);
$xoopsTpl->assign('topcategory_title', $topCategoryObj->getVar('title'));
$xoopsTpl->assign('topcategory_image', $topCategoryObj->getVar('imgurl'));
$xoopsTpl->assign('topcategory_cid', $topCategoryObj->getVar('cid'));
// Formulize module support (2006/03/06, 2006/03/08) jpc - start
$formulize_idreq = $downloadObj->getVar('formulize_idreq');
if (Utility::checkModule('formulize') && $formulize_idreq) {
$xoopsTpl->assign('custom_form', true);
require_once XOOPS_ROOT_PATH . '/modules/formulize/include/extract.php';
// get the form id and id_req of the user's entry
$formulizeModule = $moduleHandler->getByDirname('formulize');
$formulizeConfig = $configHandler->getConfigsByCat(0, $formulizeModule->mid());
$formulize_fid = $categoryObj->getVar('formulize_fid');
if ($formulize_fid) {
// get Formulize form description
$sql = 'SELECT desc_form';
$sql .= " FROM {$GLOBALS['xoopsDB']->prefix('formulize_id')}";
$sql .= " WHERE id_form = '{$formulize_fid}'";
$formulize_formQuery = $GLOBALS['xoopsDB']->query($sql);
if (false !== ($formulize_form_array = $GLOBALS['xoopsDB']->fetchArray($formulize_formQuery))) {
$desc_form = $formulize_form_array['desc_form'];
// query the form for its data
$data = getData('', $formulize_fid, $formulize_idreq); // is a Formulize function
// include only elements that are visible to the user's groups in the DB query below
$userGroups = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS];
$start = 1;
foreach ($userGroups as $thisgroup) {
if ($start) {
$userGroups_query = "ele_display LIKE '%,{$thisgroup},%'";
$start = 0;
} else {
$userGroups_query .= " OR ele_display LIKE '%,{$thisgroup},%'";
}
}
// collect the element id numbers for use in a DB query, and apply the groups filter to each
$start = 1;
foreach ($data[0][$desc_form][$formulize_idreq] as $ele_id => $values) {
if ($start) {
$ele_id_query = "(ele_id='{$ele_id}' AND (ele_display=1 OR ({$userGroups_query})))";
$start = 0;
} else {
$ele_id_query .= " OR (ele_id='{$ele_id}' AND (ele_display=1 OR ({$userGroups_query})))";
}
}
// get the captions for the elements that are visible to the user's groups
$sql = 'SELECT ele_caption, ele_id, ele_display';
$sql .= " FROM {$GLOBALS['xoopsDB']->prefix('formulize')}";
$sql .= " WHERE ({$ele_id_query}) AND ele_type <> 'ib' AND ele_type <> 'sep' AND ele_type <> 'areamodif'";
$sql .= ' ORDER BY ele_order';
$captionQuery = $GLOBALS['xoopsDB']->query($sql);
// collect the captions and their values into an array for passing to the template
$formulize_fields = [];
$i = 0;
while (false !== ($caption_array = $GLOBALS['xoopsDB']->fetchArray($captionQuery))) {
$formulize_fields[$i]['caption'] = $caption_array['ele_caption'];
if (count($data[0][$desc_form][$formulize_idreq][$caption_array['ele_id']]) > 1) {
$formulize_fields[$i]['values'][] = implode(', ', $data[0][$desc_form][$formulize_idreq][$caption_array['ele_id']]);
} else {
$formulize_fields[$i]['values'][] = $data[0][$desc_form][$formulize_idreq][$caption_array['ele_id']][0];
}
++$i;
}
$xoopsTpl->assign('formulize_download', $formulize_fields); // this definition is not removed for backward compatibility issues
$xoopsTpl->assign('custom_fields', $formulize_fields);
}
}
} else {
$xoopsTpl->assign('custom_form', false);
}
// Formulize module support (2006/03/06, 2006/03/08) jpc - end
$use_mirrors = $helper->getConfig('enable_mirrors');
$add_mirror = false;
if (!is_object($GLOBALS['xoopsUser']) && true === $use_mirrors
&& (_WFDOWNLOADS_ANONPOST_MIRROR == $helper->getConfig('anonpost')
|| _WFDOWNLOADS_ANONPOST_BOTH == $helper->getConfig('anonpost'))
&& (_WFDOWNLOADS_SUBMISSIONS_MIRROR == $helper->getConfig('submissions')
|| _WFDOWNLOADS_SUBMISSIONS_BOTH == $helper->getConfig('submissions'))) {
$add_mirror = true;
} elseif (is_object($GLOBALS['xoopsUser']) && true === $use_mirrors
&& (_WFDOWNLOADS_SUBMISSIONS_MIRROR == $helper->getConfig('submissions')
|| _WFDOWNLOADS_SUBMISSIONS_BOTH == $helper->getConfig('submissions')
|| Utility::userIsAdmin())) {
$add_mirror = true;
}
// Get download information
$downloadInfo = $downloadObj->getDownloadInfo();
$xoopsTpl->assign('categoryPath', $downloadInfo['path'] . ' > ' . $downloadInfo['title']); // this definition is not removed for backward compatibility issues
$xoopsTpl->assign('lang_dltimes', sprintf(_MD_WFDOWNLOADS_DLTIMES, $downloadInfo['hits']));
$xoopsTpl->assign('lang_subdate', $downloadInfo['is_updated']);
$xoopsTpl->assign('file_url', $downloadInfo['file_url']); // this definition is not removed for backward compatibility issues
$xoopsTpl->append('file', $downloadInfo);
$xoopsTpl->assign('show_screenshot', false);
if (1 == $helper->getConfig('screenshot')) {
$xoopsTpl->assign('shots_dir', $helper->getConfig('screenshots'));
$xoopsTpl->assign('shotwidth', $helper->getConfig('shotwidth'));
$xoopsTpl->assign('shotheight', $helper->getConfig('shotheight'));
$xoopsTpl->assign('show_screenshot', true);
}
// Breadcrumb
require_once XOOPS_ROOT_PATH . '/class/tree.php';
$categoryObjsTree = new ObjectTree($helper->getHandler('Category')->getObjects(), 'cid', 'pid');
$breadcrumb = new Common\Breadcrumb();
$breadcrumb->addLink($helper->getModule()->getVar('name'), WFDOWNLOADS_URL);
foreach (array_reverse($categoryObjsTree->getAllParent($cid)) as $parentCategory) {
$breadcrumb->addLink($parentCategory->getVar('title'), 'viewcat.php?cid=' . $parentCategory->getVar('cid'));
}
$breadcrumb->addLink($categoryObj->getVar('title'), 'viewcat.php?cid=' . $categoryObj->getVar('cid'));
$breadcrumb->addLink($downloadInfo['title'], '');
$xoopsTpl->assign('wfdownloads_breadcrumb', $breadcrumb->render());
// Show other author downloads
$downloadByUserCriteria = new CriteriaCompo(new Criteria('submitter', $downloadObj->getVar('submitter')));
$downloadByUserCriteria->add(new Criteria('lid', $lid, '!='));
$downloadByUserCriteria->setLimit(20);
$downloadByUserCriteria->setSort('published');
$downloadByUserCriteria->setOrder('DESC');
$downloadByUserObjs = $helper->getHandler('Download')->getActiveDownloads($downloadByUserCriteria);
foreach ($downloadByUserObjs as $downloadByUserObj) {
$downloadByUser['title'] = $downloadByUserObj->getVar('title');
$downloadByUser['lid'] = (int)$downloadByUserObj->getVar('lid');
$downloadByUser['cid'] = (int)$downloadByUserObj->getVar('cid');
$downloadByUser['published'] = formatTimestamp($downloadByUserObj->getVar('published'), $helper->getConfig('dateformat'));
$xoopsTpl->append('down_uid', $downloadByUser); // this definition is not removed for backward compatibility issues
$xoopsTpl->append('downloads_by_user', $downloadByUser);
}
$cid = (int)$downloadObj->getVar('cid');
$lid = (int)$downloadObj->getVar('lid');
// User reviews
$criteria = new CriteriaCompo(new Criteria('lid', $lid));
$criteria->add(new Criteria('submit', 1));
$reviewCount = $helper->getHandler('Review')->getCount($criteria);
if ($reviewCount > 0) {
$user_reviews = "op=list&cid={$cid}&lid={$lid}\">" . _MD_WFDOWNLOADS_USERREVIEWS;
} else {
$user_reviews = "cid={$cid}&lid={$lid}\">" . _MD_WFDOWNLOADS_NOUSERREVIEWS;
}
$xoopsTpl->assign('lang_user_reviews', $GLOBALS['xoopsConfig']['sitename'] . ' ' . _MD_WFDOWNLOADS_USERREVIEWSTITLE);
$xoopsTpl->assign('lang_UserReviews', sprintf($user_reviews, $downloadObj->getVar('title')));
$xoopsTpl->assign('review_amount', $reviewCount);
// User mirrors
$downloadInfo['add_mirror'] = $add_mirror;
$criteria = new CriteriaCompo(new Criteria('lid', $lid));
$criteria->add(new Criteria('submit', 1));
$mirrorCount = $helper->getHandler('Mirror')->getCount($criteria);
if ($mirrorCount > 0) {
$user_mirrors = "op=list&cid={$cid}&lid={$lid}\">" . _MD_WFDOWNLOADS_USERMIRRORS;
} else {
$user_mirrors = "cid={$cid}&lid={$lid}\">" . _MD_WFDOWNLOADS_NOUSERMIRRORS;
}
$xoopsTpl->assign('lang_user_mirrors', $GLOBALS['xoopsConfig']['sitename'] . ' ' . _MD_WFDOWNLOADS_USERMIRRORSTITLE);
$xoopsTpl->assign('lang_UserMirrors', sprintf($user_mirrors, $downloadObj->getVar('title')));
$xoopsTpl->assign('mirror_amount', $mirrorCount);
$xoopsTpl->assign('use_mirrors', $helper->getConfig('enable_mirrors'));
$xoopsTpl->assign('use_ratings', $helper->getConfig('enable_ratings'));
$xoopsTpl->assign('use_reviews', $helper->getConfig('enable_reviews'));
$xoopsTpl->assign('use_brokenreports', $helper->getConfig('enable_brokenreports'));
$xoopsTpl->assign('use_rss', $helper->getConfig('enablerss'));
// Copyright
if (1 === $helper->getConfig('copyright')) {
$xoopsTpl->assign('lang_copyright', $downloadObj->getVar('title') . ' © ' . _MD_WFDOWNLOADS_COPYRIGHT . ' ' . formatTimestamp(time(), 'Y'));
}
$xoopsTpl->assign('down', $downloadInfo); // this definition is not removed for backward compatibility issues
$xoopsTpl->assign('download', $downloadInfo);
require_once XOOPS_ROOT_PATH . '/include/comment_view.php';
$xoopsTpl->assign('com_rule', $helper->getConfig('com_rule'));
$xoopsTpl->assign('module_home', Utility::moduleHome(true));
require_once __DIR__ . '/footer.php';
?>
<script type="text/javascript">
$('.magnific_zoom').magnificPopup({
type: 'image',
image: {
cursor: 'mfp-zoom-out-cur',
titleSrc: "title",
verticalFit: true,
tError: 'The image could not be loaded.' // Error message
},
gallery: {
enabled: true
},
iframe: {
patterns: {
youtube: {
index: 'youtube.com/',
id: 'v=',
src: '//www.youtube.com/embed/%id%?autoplay=1'
}, vimeo: {
index: 'vimeo.com/',
id: '/',
src: '//player.vimeo.com/video/%id%?autoplay=1'
}, gmaps: {
index: '//maps.google.',
src: '%id%&output=embed'
}
}
},
preloader: true,
showCloseBtn: true,
closeBtnInside: false,
closeOnContentClick: true,
closeOnBgClick: true,
enableEscapeKey: true,
modal: false,
alignTop: false,
mainClass: 'mfp-img-mobile mfp-fade',
zoom: {
enabled: true,
duration: 300,
easing: 'ease-in-out'
},
removalDelay: 200
});
</script>