Passed
Branch master (160f79)
by Michael
02:51
created

item.php (3 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
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
9
 This program is distributed in the hope that it will be useful,
10
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 */
13
14
/**
15
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
16
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 * @author          The SmartFactory <www.smartfactory.ca>
20
 */
21
22
use Xmf\Request;
23
use XoopsModules\Publisher\{Category,
24
    Constants,
25
    Helper,
26
    Item,
27
    Metagen,
28
    Utility
29
};
30
31
/** @var Category $categoryObj */
32
/** @var Item $itemObj */
33
34
require_once __DIR__ . '/header.php';
35
36
$itemId     = Request::getInt('itemid', 0, 'GET');
37
$itemPageId = Request::getInt('page', -1, 'GET');
38
39
if (0 == $itemId) {
40
    redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED);
41
}
42
43
$helper = Helper::getInstance();
44
45
// Creating the item object for the selected item
46
$itemObj = $helper->getHandler('Item')->get($itemId);
47
48
// if the selected item was not found, exit
49
if (null !== $itemObj) {
50
    redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED);
51
}
52
53
$GLOBALS['xoopsOption']['template_main'] = 'publisher_item.tpl';
54
require_once $GLOBALS['xoops']->path('header.php');
55
56
//$xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js');
57
//$xoTheme->addScript(PUBLISHER_URL . '/assets/js/jquery.popeye-2.1.js');
58
//$xoTheme->addScript(PUBLISHER_URL . '/assets/js/publisher.js');
59
//
60
//$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/jquery.popeye.css');
61
//$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/jquery.popeye.style.css');
62
$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/publisher.css');
63
$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/rating.css');
64
65
require_once PUBLISHER_ROOT_PATH . '/footer.php';
66
67
// Creating the category object that holds the selected item
68
$categoryObj = $helper->getHandler('Category')->get($itemObj->categoryid());
69
70
// Check user permissions to access that category of the selected item
71
if (!$itemObj->accessGranted()) {
72
    redirect_header('<script>javascript:history.go(-1)</script>', 1, _NOPERM);
73
}
74
$com_replytitle = $itemObj->getTitle();
75
76
// Update the read counter of the selected item
77
if (!$GLOBALS['xoopsUser']
78
    || ($GLOBALS['xoopsUser'] && !$GLOBALS['xoopsUser']->isAdmin($helper->getModule()->mid()))
79
    || ($GLOBALS['xoopsUser']->isAdmin($helper->getModule()->mid()) && 1 == $helper->getConfig('item_admin_hits'))) {
80
    $itemObj->updateCounter();
81
}
82
83
// creating the Item objects that belong to the selected category
84
switch ($helper->getConfig('format_order_by')) {
85
    case 'title':
86
        $sort  = 'title';
87
        $order = 'ASC';
88
        break;
89
    case 'date':
90
        $sort  = 'datesub';
91
        $order = 'DESC';
92
        break;
93
    case 'counter':
94
        $sort  = 'counter';
95
        $order = 'DESC';
96
        break;
97
    case 'rating':
98
        $sort  = 'rating';
99
        $order = 'DESC';
100
        break;
101
    case 'votes':
102
        $sort  = 'votes';
103
        $order = 'DESC';
104
        break;
105
    case 'comments':
106
        $sort  = 'comments';
107
        $order = 'DESC';
108
        break;
109
    default:
110
        $sort  = 'weight';
111
        $order = 'ASC';
112
        break;
113
}
114
115
if ('previous_next' === $helper->getConfig('item_other_items_type')) {
116
    // Retrieving the next and previous object
117
    $previousItemLink = '';
118
    $previousItemUrl  = '';
119
    $nextItemLink     = '';
120
    $nextItemUrl      = '';
121
122
    $previousObj = $helper->getHandler('Item')->getPreviousPublished($itemObj);
0 ignored issues
show
$itemObj of type void is incompatible with the type XoopsModules\Publisher\Item expected by parameter $obj of XoopsModules\Publisher\I...:getPreviousPublished(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

122
    $previousObj = $helper->getHandler('Item')->getPreviousPublished(/** @scrutinizer ignore-type */ $itemObj);
Loading history...
123
    $nextObj     = $helper->getHandler('Item')->getNextPublished($itemObj);
0 ignored issues
show
$itemObj of type void is incompatible with the type XoopsModules\Publisher\Item expected by parameter $obj of XoopsModules\Publisher\I...ler::getNextPublished(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

123
    $nextObj     = $helper->getHandler('Item')->getNextPublished(/** @scrutinizer ignore-type */ $itemObj);
Loading history...
124
    if (is_object($previousObj)) {
125
        $previousItemLink = $previousObj->getItemLink();
126
        $previousItemUrl  = $previousObj->getItemUrl();
127
    }
128
129
    if (is_object($nextObj)) {
130
        $nextItemLink = $nextObj->getItemLink();
131
        $nextItemUrl  = $nextObj->getItemUrl();
132
    }
133
    unset($previousObj, $nextObj);
134
    $xoopsTpl->assign('previousItemLink', $previousItemLink);
135
    $xoopsTpl->assign('nextItemLink', $nextItemLink);
136
    $xoopsTpl->assign('previousItemUrl', $previousItemUrl);
137
    $xoopsTpl->assign('nextItemUrl', $nextItemUrl);
138
}
139
140
//CAREFUL!! with many items this will exhaust memory
141
if ('all' === $helper->getConfig('item_other_items_type')) {
142
    $itemsObj = $helper->getHandler('Item')->getAllPublished(0, 0, $categoryObj->categoryId, $sort, $order, '', true, true);
143
    $items    = [];
144
    foreach ($itemsObj[''] as $theItemObj) {
145
        $theItem              = [];
146
        $theItem['body']      = $theItemObj->getBody();
147
        $theItem['title']     = $theItemObj->getTitle();
148
        $theItem['titlelink'] = $theItemObj->getItemLink();
149
        $theItem['itemid']    = $theItemObj->itemid();
150
        $theItem['itemurl']   = $theItemObj->getItemUrl();
151
        $theItem['datesub']   = $theItemObj->getDatesub();
152
        $theItem['counter']   = $theItemObj->counter();
153
        $theItem['who']       = $theItemObj->getWho();
154
        $theItem['category']  = $theItemObj->getCategoryLink();
155
        $theItem['more']      = '<a href="' . $theItemObj->getItemUrl() . '">' . _MD_PUBLISHER_READMORE . '</a>';
156
157
        $summary = $theItemObj->getSummary(300);
158
        if (!$summary) {
159
            $summary = $theItemObj->getBody(300);
160
        }
161
        $theItem['summary'] = $summary;
162
163
        $theItem['cancomment'] = $theItemObj->cancomment();
164
        $comments              = $theItemObj->comments();
165
        if ($comments > 0) {
166
            //shows 1 comment instead of 1 comm. if comments ==1
167
            //langugage file modified accordingly
168
            if (1 == $comments) {
169
                $theItem['comments'] = '&nbsp;' . _MD_PUBLISHER_ONECOMMENT . '&nbsp;';
170
            } else {
171
                $theItem['comments'] = '&nbsp;' . $comments . '&nbsp;' . _MD_PUBLISHER_COMMENTS . '&nbsp;';
172
            }
173
        } else {
174
            $theItem['comments'] = '&nbsp;' . _MD_PUBLISHER_NO_COMMENTS . '&nbsp;';
175
        }
176
177
        $mainImage = $theItemObj->getMainImage();
178
        // check to see if GD function exist       
179
        $theItem['item_image'] = $mainImage['image_path'];
180
        if (!empty($mainImage['image_path']) && function_exists('imagecreatetruecolor')) {
181
            $theItem['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path'] . '&amp;w=100';
182
            $theItem['image_path'] = $mainImage['image_path'];
183
        }
184
185
        if ($theItemObj->itemId() == $itemObj->itemId()) {
186
            $theItem['titlelink'] = $theItemObj->getItemLink();
187
        }
188
        $items[] = $theItem;
189
        unset($theItem);
190
    }
191
    unset($itemsObj);
192
    $xoopsTpl->assign('items', $items);
193
    unset($items);
194
}
195
196
// Populating the smarty variables with information related to the selected item
197
$item = $itemObj->toArraySimple($itemPageId);
198
$xoopsTpl->assign('show_subtitle', $helper->getConfig('item_disp_subtitle'));
199
200
if ($itemObj->pagescount() > 0) {
201
    if (-1 == $itemPageId) {
202
        $itemPageId = 0;
203
    }
204
    require_once $GLOBALS['xoops']->path('class/pagenav.php');
205
    //    $pagenav = new \XoopsPageNav($itemObj->pagescount(), 1, $itemPageId, 'page', 'itemid=' . $itemObj->itemId());
206
207
    $pagenav = new \XoopsPageNav($itemObj->pagescount(), 1, $itemPageId, 'page', 'itemid=' . $itemObj->itemid()); //SMEDrieben changed ->itemId to ->itemid
208
209
    $xoopsTpl->assign('pagenav', $pagenav->renderNav());
210
}
211
212
// Creating the files object associated with this item
213
$file         = [];
214
$files        = [];
215
$embededFiles = [];
216
$filesObj     = $itemObj->getFiles();
217
218
// check if user has permission to modify files
219
$hasFilePermissions = true;
220
if (!(Utility::userIsAdmin() || Utility::userIsModerator($itemObj))) {
0 ignored issues
show
$itemObj of type void is incompatible with the type XoopsObject expected by parameter $itemObj of XoopsModules\Publisher\Utility::userIsModerator(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

220
if (!(Utility::userIsAdmin() || Utility::userIsModerator(/** @scrutinizer ignore-type */ $itemObj))) {
Loading history...
221
    $hasFilePermissions = false;
222
}
223
if (null !== $filesObj) {
224
    foreach ($filesObj as $fileObj) {
225
        $file        = [];
226
        $file['mod'] = false;
227
        if ($hasFilePermissions || (is_object($GLOBALS['xoopsUser']) && $fileObj->getVar('uid') == $GLOBALS['xoopsUser']->getVar('uid'))) {
228
            $file['mod'] = true;
229
        }
230
231
        if ('application/x-shockwave-flash' === $fileObj->mimetype()) {
232
            $file['content'] = $fileObj->displayFlash();
233
            if (mb_strpos($item['maintext'], '[flash-' . $fileObj->getVar('fileid') . ']')) {
234
                $item['maintext'] = str_replace('[flash-' . $fileObj->getVar('fileid') . ']', $file['content'], $item['maintext']);
235
            } else {
236
                $embededFiles[] = $file;
237
            }
238
        } else {
239
            $file['fileid']      = $fileObj->fileid();
240
            $file['name']        = $fileObj->name();
241
            $file['description'] = $fileObj->description();
242
            $file['name']        = $fileObj->name();
243
            $file['type']        = $fileObj->mimetype();
244
            $file['datesub']     = $fileObj->getDatesub();
245
            $file['hits']        = $fileObj->counter();
246
            $files[]             = $file;
247
        }
248
    }
249
}
250
251
$item['files']         = $files;
252
$item['embeded_files'] = $embededFiles;
253
unset($file, $embededFiles, $filesObj, $fileObj);
254
255
// Language constants
256
$xoopsTpl->assign('mail_link', 'mailto:?subject=' . sprintf(_CO_PUBLISHER_INTITEM, $GLOBALS['xoopsConfig']['sitename']) . '&amp;body=' . sprintf(_CO_PUBLISHER_INTITEMFOUND, $GLOBALS['xoopsConfig']['sitename']) . ': ' . $itemObj->getItemUrl());
257
$xoopsTpl->assign('itemid', $itemObj->itemId());
258
$xoopsTpl->assign('sectionname', $helper->getModule()->getVar('name'));
259
$xoopsTpl->assign('module_dirname', $helper->getDirname());
260
$xoopsTpl->assign('module_home', Utility::moduleHome($helper->getConfig('format_linked_path')));
261
$xoopsTpl->assign('categoryPath', '<li>' . $item['categoryPath'] . '</li><li> ' . $item['title'] . '</li>');
262
$xoopsTpl->assign('commentatarticlelevel', $helper->getConfig('perm_com_art_level'));
263
$xoopsTpl->assign('com_rule', $helper->getConfig('com_rule'));
264
$xoopsTpl->assign('other_items', $helper->getConfig('item_other_items_type'));
265
$xoopsTpl->assign('itemfooter', $myts->displayTarea($helper->getConfig('item_footer'), 1));
266
$xoopsTpl->assign('perm_author_items', $helper->getConfig('perm_author_items'));
267
268
// tags support
269
if (xoops_isActiveModule('tag')) {
270
    require_once $GLOBALS['xoops']->path('modules/tag/include/tagbar.php');
271
    $xoopsTpl->assign('tagbar', tagBar($itemId, $catId = 0));
272
}
273
274
/**
275
 * Generating meta information for this page
276
 */
277
$publisherMetagen = new Metagen($itemObj->getVar('title'), $itemObj->getVar('meta_keywords', 'n'), $itemObj->getVar('meta_description', 'n'), $itemObj->getCategoryPath());
278
$publisherMetagen->createMetaTags();
279
280
// Include the comments if the selected ITEM supports comments
281
if ((0 != $helper->getConfig('com_rule')) && ((1 == $itemObj->cancomment()) || !$helper->getConfig('perm_com_art_level'))) {
282
    require_once $GLOBALS['xoops']->path('include/comment_view.php');
283
    // Problem with url_rewrite and posting comments :
284
    $xoopsTpl->assign(
285
        [
286
            'editcomment_link'   => PUBLISHER_URL . '/comment_edit.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . $link_extra,
287
            'deletecomment_link' => PUBLISHER_URL . '/comment_delete.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . $link_extra,
288
            'replycomment_link'  => PUBLISHER_URL . '/comment_reply.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . $link_extra,
289
        ]
290
    );
291
    $xoopsTpl->_tpl_vars['commentsnav'] = str_replace("self.location.href='", "self.location.href='" . PUBLISHER_URL . '/', $xoopsTpl->_tpl_vars['commentsnav']);
292
}
293
294
// Original AJAX rating
295
if ($helper->getConfig('perm_rating')) {
296
    $xoopsTpl->assign('rating_enabled', true);
297
    $item['ratingbar'] = Utility::ratingBar($itemId);
298
    $xoTheme->addScript(PUBLISHER_URL . '/assets/js/behavior.js');
299
    $xoTheme->addScript(PUBLISHER_URL . '/assets/js/rating.js');
300
    //}
301
302
    //=============== START VOTE RATING ======================================
303
304
    $start = Request::getInt('start', 0);
305
    $limit = Request::getInt('limit', $helper->getConfig('userpager'));
306
    $id    = Request::getInt('itemid', 0, 'GET');
307
308
    $ratingbars = (int)$helper->getConfig('ratingbars');
309
    if ($ratingbars > 0) {
310
        $GLOBALS['xoTheme']->addStylesheet(PUBLISHER_URL . '/assets/css/rating.css', null);
311
        $GLOBALS['xoopsTpl']->assign('rating', $ratingbars);
312
        $GLOBALS['xoopsTpl']->assign('rating_5stars', (Constants::RATING_5STARS === $ratingbars));
313
        $GLOBALS['xoopsTpl']->assign('rating_10stars', (Constants::RATING_10STARS === $ratingbars));
314
        $GLOBALS['xoopsTpl']->assign('rating_10num', (Constants::RATING_10NUM === $ratingbars));
315
        $GLOBALS['xoopsTpl']->assign('rating_likes', (Constants::RATING_LIKES === $ratingbars));
316
        $GLOBALS['xoopsTpl']->assign('rating_reaction', (Constants::RATING_REACTION === $ratingbars));
317
        $GLOBALS['xoopsTpl']->assign('itemid', 'itemid');
318
        $GLOBALS['xoopsTpl']->assign('blog_icon_url_16', PUBLISHER_URL . '/' . $modPathIcon16);
319
    }
320
    $crArticle = new \CriteriaCompo();
321
    if ($id > 0) {
322
        $crArticle->add(new \Criteria('itemid', $id));
323
    }
324
325
    /** @var ItemHandler $itemHandler */
326
    /** @var VoteHandler $voteHandler */
327
    $itemHandler = $helper->getHandler('Item');
328
    $voteHandler = $helper->getHandler('Vote');
329
330
    $articleCount = $itemHandler->getCount($crArticle);
331
    $GLOBALS['xoopsTpl']->assign('articleCount', $articleCount);
332
    $crArticle->setStart($start);
333
    $crArticle->setLimit($limit);
334
    $articleAll = $itemHandler->getAll($crArticle);
335
    if ($articleCount > 0) {
336
        $article = [];
337
        // Get All Article
338
        foreach (\array_keys($articleAll) as $i) {
339
            $article[$i]           = $articleAll[$i]->toArraySimple();
340
            $keywords[$i]          = $articleAll[$i]->getVar('title');
341
            $rating                = $voteHandler->getItemRating($articleAll[$i]->getVar('itemid'), Constants::TABLE_ARTICLE);
342
            $article[$i]['rating'] = $rating;
343
344
            $item['rating'] = $rating;
345
        }
346
        //    $GLOBALS['xoopsTpl']->assign('article', $article);
347
        $xoopsTpl->assign('article', $article);
348
        $xoopsTpl->assign('item2', $item);
349
        $xoopsTpl->assign('rating', $rating);
350
        unset($article);
351
    }
352
353
    // Display Navigation
354
    if ($articleCount > $limit) {
355
        include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
356
        $pagenav = new \XoopsPageNav($articleCount, $limit, $start, 'start', 'op=list&limit=' . $limit);
357
        $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
358
    }
359
    $GLOBALS['xoopsTpl']->assign('type', $helper->getConfig('table_type'));
360
    $GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby'));
361
    $GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col'));
362
}
363
364
//=================== END VOTE RATING =========================================
365
366
//$xoopsTpl->assign('article', $article);
367
$xoopsTpl->assign('item', $item);
368
require_once XOOPS_ROOT_PATH . '/footer.php';
369