-
Notifications
You must be signed in to change notification settings - Fork 25
/
item.php
354 lines (302 loc) · 14.2 KB
/
item.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
349
350
351
352
353
354
<?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 The XUUPS Project http://sourceforge.net/projects/xuups/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @since 1.0
* @author trabis <[email protected]>
* @author The SmartFactory <www.smartfactory.ca>
*/
use Xmf\Request;
use XoopsModules\Publisher\{
Category,
Constants,
Helper,
Item,
Metagen,
Utility
};
/** @var Category $categoryObj */
require_once __DIR__ . '/header.php';
$itemId = Request::getInt('itemid', 0, 'GET');
$itemPageId = Request::getInt('page', -1, 'GET');
if (0 == $itemId) {
// redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED);
}
$helper = Helper::getInstance();
// Creating the item object for the selected item
/** @var Item $itemObj */
$itemObj = $helper->getHandler('Item')->get($itemId);
// if the selected item was not found, exit
if (null === $itemObj) {
// redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED);
}
$GLOBALS['xoopsOption']['template_main'] = 'publisher_item.tpl';
require_once $GLOBALS['xoops']->path('header.php');
//$xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js');
//$xoTheme->addScript(PUBLISHER_URL . '/assets/js/jquery.popeye-2.1.js');
//$xoTheme->addScript(PUBLISHER_URL . '/assets/js/publisher.js');
//
//$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/jquery.popeye.css');
//$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/jquery.popeye.style.css');
$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/publisher.css');
$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/rating.css');
require_once PUBLISHER_ROOT_PATH . '/footer.php';
// Creating the category object that holds the selected item
$categoryObj = $helper->getHandler('Category')->get($itemObj->categoryid());
// Check user permissions to access that category of the selected item
if (!$itemObj->accessGranted()) {
redirect_header('<script>javascript:history.go(-1)</script>', 1, _NOPERM);
}
$com_replytitle = $itemObj->getTitle();
// Update the read counter of the selected item
if (!$GLOBALS['xoopsUser']
|| ($GLOBALS['xoopsUser'] && !$GLOBALS['xoopsUser']->isAdmin($helper->getModule()->mid()))
|| ($GLOBALS['xoopsUser']->isAdmin($helper->getModule()->mid()) && 1 == $helper->getConfig('item_admin_hits'))) {
$itemObj->updateCounter();
}
// creating the Item objects that belong to the selected category
switch ($helper->getConfig('format_order_by')) {
case 'title':
$sort = 'title';
$order = 'ASC';
break;
case 'date':
$sort = 'datesub';
$order = 'DESC';
break;
case 'counter':
$sort = 'counter';
$order = 'DESC';
break;
case 'rating':
$sort = 'rating';
$order = 'DESC';
break;
case 'votes':
$sort = 'votes';
$order = 'DESC';
break;
case 'comments':
$sort = 'comments';
$order = 'DESC';
break;
default:
$sort = 'weight';
$order = 'ASC';
break;
}
if ('previous_next' === $helper->getConfig('item_other_items_type')) {
// Retrieving the next and previous object
$previousItemLink = '';
$previousItemUrl = '';
$nextItemLink = '';
$nextItemUrl = '';
$previousObj = $helper->getHandler('Item')->getPreviousPublished($itemObj);
$nextObj = $helper->getHandler('Item')->getNextPublished($itemObj);
if (is_object($previousObj)) {
$previousItemLink = $previousObj->getItemLink();
$previousItemUrl = $previousObj->getItemUrl();
}
if (is_object($nextObj)) {
$nextItemLink = $nextObj->getItemLink();
$nextItemUrl = $nextObj->getItemUrl();
}
unset($previousObj, $nextObj);
$xoopsTpl->assign('previousItemLink', $previousItemLink);
$xoopsTpl->assign('nextItemLink', $nextItemLink);
$xoopsTpl->assign('previousItemUrl', $previousItemUrl);
$xoopsTpl->assign('nextItemUrl', $nextItemUrl);
}
//CAREFUL!! with many items this will exhaust memory
if ('all' === $helper->getConfig('item_other_items_type')) {
$itemsObj = $helper->getHandler('Item')->getAllPublished(0, 0, $categoryObj->categoryid, $sort, $order, '', true, true);
$items = [];
foreach ($itemsObj[''] as $theItemObj) {
$theItem = [];
$theItem['body'] = $theItemObj->getBody();
$theItem['title'] = $theItemObj->getTitle();
$theItem['titlelink'] = $theItemObj->getItemLink();
$theItem['itemid'] = $theItemObj->itemid();
$theItem['itemurl'] = $theItemObj->getItemUrl();
$theItem['datesub'] = $theItemObj->getDatesub();
$theItem['counter'] = $theItemObj->counter();
$theItem['who'] = $theItemObj->getWho();
$theItem['category'] = $theItemObj->getCategoryLink();
$theItem['more'] = '<a href="' . $theItemObj->getItemUrl() . '">' . _MD_PUBLISHER_READMORE . '</a>';
$summary = $theItemObj->getSummary(300);
if (!$summary) {
$summary = $theItemObj->getBody(300);
}
$theItem['summary'] = $summary;
$theItem['cancomment'] = $theItemObj->cancomment();
$comments = $theItemObj->comments();
if ($comments > 0) {
//shows 1 comment instead of 1 comm. if comments ==1
//langugage file modified accordingly
if (1 == $comments) {
$theItem['comments'] = ' ' . _MD_PUBLISHER_ONECOMMENT . ' ';
} else {
$theItem['comments'] = ' ' . $comments . ' ' . _MD_PUBLISHER_COMMENTS . ' ';
}
} else {
$theItem['comments'] = ' ' . _MD_PUBLISHER_NO_COMMENTS . ' ';
}
$mainImage = $theItemObj->getMainImage();
// check to see if GD function exist
$theItem['item_image'] = $mainImage['image_path'];
if (!empty($mainImage['image_path']) && function_exists('imagecreatetruecolor')) {
$theItem['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path'] . '&w=100';
$theItem['image_path'] = $mainImage['image_path'];
}
if ($theItemObj->itemid == $itemObj->itemid()) {
$theItem['titlelink'] = $theItemObj->getItemLink();
}
$items[] = $theItem;
unset($theItem);
}
unset($itemsObj);
$xoopsTpl->assign('items', $items);
unset($items);
}
// Populating the smarty variables with information related to the selected item
$item = $itemObj->toArraySimple($itemPageId);
$xoopsTpl->assign('show_subtitle', $helper->getConfig('item_disp_subtitle'));
if ($itemObj->pagescount() > 0) {
if (-1 == $itemPageId) {
$itemPageId = 0;
}
require_once $GLOBALS['xoops']->path('class/pagenav.php');
// $pagenav = new \XoopsPageNav($itemObj->pagescount(), 1, $itemPageId, 'page', 'itemid=' . $itemObj->itemid());
$pagenav = new \XoopsPageNav($itemObj->pagescount(), 1, $itemPageId, 'page', 'itemid=' . $itemObj->itemid()); //SMEDrieben changed ->itemId to ->itemid
$xoopsTpl->assign('pagenav', $pagenav->renderNav());
}
// Creating the files object associated with this item
$file = [];
$files = [];
$embededFiles = [];
$filesObj = $itemObj->getFiles();
// check if user has permission to modify files
$hasFilePermissions = true;
if (!(Utility::userIsAdmin() || Utility::userIsModerator($itemObj))) {
$hasFilePermissions = false;
}
if (null !== $filesObj) {
foreach ($filesObj as $fileObj) {
$file = [];
$file['mod'] = false;
if ($hasFilePermissions || (is_object($GLOBALS['xoopsUser']) && $fileObj->getVar('uid') == $GLOBALS['xoopsUser']->getVar('uid'))) {
$file['mod'] = true;
}
if ('application/x-shockwave-flash' === $fileObj->mimetype()) {
$file['content'] = $fileObj->displayFlash();
if (mb_strpos($item['maintext'], '[flash-' . $fileObj->getVar('fileid') . ']')) {
$item['maintext'] = str_replace('[flash-' . $fileObj->getVar('fileid') . ']', $file['content'], $item['maintext']);
} else {
$embededFiles[] = $file;
}
} else {
$file['fileid'] = $fileObj->fileid();
$file['name'] = $fileObj->name();
$file['description'] = $fileObj->description();
$file['filename'] = $fileObj->filename();
$file['type'] = $fileObj->mimetype();
$file['datesub'] = $fileObj->getDatesub();
$file['hits'] = $fileObj->counter();
$files[] = $file;
}
}
}
$item['files'] = $files;
$item['embeded_files'] = $embededFiles;
unset($file, $embededFiles, $filesObj, $fileObj);
// Language constants
$xoopsTpl->assign('mail_link', 'mailto:?subject=' . sprintf(_CO_PUBLISHER_INTITEM, $GLOBALS['xoopsConfig']['sitename']) . '&body=' . sprintf(_CO_PUBLISHER_INTITEMFOUND, $GLOBALS['xoopsConfig']['sitename']) . ': ' . $itemObj->getItemUrl());
$xoopsTpl->assign('itemid', $itemObj->itemid());
$xoopsTpl->assign('sectionname', $helper->getModule()->getVar('name'));
$xoopsTpl->assign('module_dirname', $helper->getDirname());
$xoopsTpl->assign('module_home', Utility::moduleHome($helper->getConfig('format_linked_path')));
$xoopsTpl->assign('categoryPath', '<li>' . $item['categoryPath'] . '</li><li> ' . $item['title'] . '</li>');
$xoopsTpl->assign('commentatarticlelevel', $helper->getConfig('perm_com_art_level'));
$xoopsTpl->assign('com_rule', $helper->getConfig('com_rule'));
$xoopsTpl->assign('other_items', $helper->getConfig('item_other_items_type'));
$xoopsTpl->assign('itemfooter', $myts->displayTarea($helper->getConfig('item_footer'), 1));
$xoopsTpl->assign('perm_author_items', $helper->getConfig('perm_author_items'));
// tags support
if (xoops_isActiveModule('tag')) {
require_once $GLOBALS['xoops']->path('modules/tag/include/tagbar.php');
$xoopsTpl->assign('tagbar', tagBar($itemId, $catId = 0));
}
/**
* Generating meta information for this page
*/
$publisherMetagen = new Metagen($itemObj->getVar('title'), $itemObj->getVar('meta_keywords', 'n'), $itemObj->getVar('meta_description', 'n'), $itemObj->getCategoryPath());
$publisherMetagen->createMetaTags();
// Include the comments if the selected ITEM supports comments
if ((0 != $helper->getConfig('com_rule')) && ((1 == $itemObj->cancomment()) || !$helper->getConfig('perm_com_art_level'))) {
require_once $GLOBALS['xoops']->path('include/comment_view.php');
// Problem with url_rewrite and posting comments :
// $xoopsTpl->assign(
// [
// 'editcomment_link' => PUBLISHER_URL . '/comment_edit.php?com_itemid=' . $com_itemid . '&com_order=' . $com_order . '&com_mode=' . $com_mode . $link_extra,
// 'deletecomment_link' => PUBLISHER_URL . '/comment_delete.php?com_itemid=' . $com_itemid . '&com_order=' . $com_order . '&com_mode=' . $com_mode . $link_extra,
// 'replycomment_link' => PUBLISHER_URL . '/comment_reply.php?com_itemid=' . $com_itemid . '&com_order=' . $com_order . '&com_mode=' . $com_mode . $link_extra,
// ]
// );
$xoopsTpl->_tpl_vars['commentsnav'] = str_replace(
"self.location.href='",
"self.location.href='" . PUBLISHER_URL . '/',
$xoopsTpl->_tpl_vars['commentsnav']??''
);
}
// Original AJAX rating
if ($helper->getConfig('perm_rating')) {
$xoopsTpl->assign('rating_enabled', true);
$item['ratingbar'] = Utility::ratingBar($itemId);
// $xoTheme->addScript(PUBLISHER_URL . '/assets/js/behavior.js');
// $xoTheme->addScript(PUBLISHER_URL . '/assets/js/rating.js');
//}
//=============== START VOTE RATING ======================================
$start = Request::getInt('start', 0);
$limit = Request::getInt('limit', $helper->getConfig('userpager'));
$id = Request::getInt('itemid', 0, 'GET');
// $ratingbars = (int)$helper->getConfig('ratingbars'); //from Preferences
$voteType = $itemObj->votetype();
if ($voteType > 0) {
$GLOBALS['xoTheme']->addStylesheet(PUBLISHER_URL . '/assets/css/rating.css', null);
$GLOBALS['xoopsTpl']->assign('rating', $voteType);
$GLOBALS['xoopsTpl']->assign('rating_5stars', (Constants::RATING_5STARS === $voteType));
$GLOBALS['xoopsTpl']->assign('rating_10stars', (Constants::RATING_10STARS === $voteType));
$GLOBALS['xoopsTpl']->assign('rating_10num', (Constants::RATING_10NUM === $voteType));
$GLOBALS['xoopsTpl']->assign('rating_likes', (Constants::RATING_LIKES === $voteType));
$GLOBALS['xoopsTpl']->assign('rating_reaction', (Constants::RATING_REACTION === $voteType));
$GLOBALS['xoopsTpl']->assign('itemid', 'itemid');
$GLOBALS['xoopsTpl']->assign('blog_icon_url_16', PUBLISHER_URL . '/' . $modPathIcon16);
}
/** @var VoteHandler $voteHandler */
$voteHandler = $helper->getHandler('Vote');
$rating5 = $voteHandler->getItemRating5($itemObj, Constants::TABLE_ARTICLE);
$xoopsTpl->assign('rating', $rating5);
$item['rating'] = $rating5;
// $GLOBALS['xoopsTpl']->assign('article', $article);
// $xoopsTpl->assign('article', $article);
$xoopsTpl->assign('item2', $item);
// $xoopsTpl->assign('rating', $rating);
// unset($article);
// }
$GLOBALS['xoopsTpl']->assign('type', $helper->getConfig('table_type'));
$GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby'));
$GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col'));
}
//=================== END VOTE RATING =========================================
//$xoopsTpl->assign('article', $article);
$xoopsTpl->assign('item', $item);
require_once XOOPS_ROOT_PATH . '/footer.php';