forked from XoopsModules25x/publisher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item.php
262 lines (222 loc) · 10.3 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
<?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.
*/
/**
* @copyright The XUUPS Project http://sourceforge.net/projects/xuups/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @package Publisher
* @subpackage Action
* @since 1.0
* @author trabis <[email protected]>
* @author The SmartFactory <www.smartfactory.ca>
*/
use Xmf\Request;
use XoopsModules\Publisher;
require_once __DIR__ . '/header.php';
$itemId = Request::getInt('itemid', 0, 'GET');
$itemPageId = Request::getInt('page', -1, 'GET');
if (0 == $itemId) {
redirect_header('javascript:history.go(-1)', 1, _MD_PUBLISHER_NOITEMSELECTED);
}
/** @var Publisher\Helper $helper */
$helper = Publisher\Helper::getInstance();
// Creating the item object for the selected item
$itemObj = $helper->getHandler('Item')->get($itemId);
// if the selected item was not found, exit
if (!$itemObj) {
redirect_header('javascript:history.go(-1)', 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');
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('javascript:history.go(-1)', 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['titlelink'] = $theItemObj->getItemLink();
$theItem['datesub'] = $theItemObj->getDatesub();
$theItem['counter'] = $theItemObj->counter();
if ($theItemObj->itemId() == $itemObj->itemId()) {
$theItem['titlelink'] = $theItemObj->getTitle();
}
$items[] = $theItem;
unset($theItem);
}
unset($itemsObj, $theItemObj);
$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 (!(Publisher\Utility::userIsAdmin() || Publisher\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['name'] = $fileObj->name();
$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', Publisher\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 Publisher\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']);
}
// Include support for AJAX rating
if ($helper->getConfig('perm_rating')) {
$xoopsTpl->assign('rating_enabled', true);
$item['ratingbar'] = Publisher\Utility::ratingBar($itemId);
$xoTheme->addScript(PUBLISHER_URL . '/assets/js/behavior.js');
$xoTheme->addScript(PUBLISHER_URL . '/assets/js/rating.js');
}
$xoopsTpl->assign('item', $item);
require_once XOOPS_ROOT_PATH . '/footer.php';