Passed
Branch master (d2b70f)
by Michael
12:26
created
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
use XoopsModules\Publisher\Constants;
25
use XoopsModules\Publisher\Helper;
26
use XoopsModules\Publisher\Item;
27
use XoopsModules\Publisher\Jsonld;
0 ignored issues
show
The type XoopsModules\Publisher\Jsonld was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use XoopsModules\Publisher\Metagen;
29
use XoopsModules\Publisher\Utility;
30
31
/** @var Category $categoryObj */
32
require_once __DIR__ . '/header.php';
33
34
$itemId     = Request::getInt('itemid', 0, 'GET');
35
$itemPageId = Request::getInt('page', -1, 'GET');
36
37
if (0 == $itemId) {
38
    //    redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED);
39
}
40
41
$helper = Helper::getInstance();
42
43
// Creating the item object for the selected item
44
/** @var Item $itemObj */
45
$itemObj = $helper->getHandler('Item')->get($itemId);
46
47
// if the selected item was not found, exit
48
if (null === $itemObj) {
49
    //    redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED);
50
}
51
52
$GLOBALS['xoopsOption']['template_main'] = 'publisher_item.tpl';
53
require_once $GLOBALS['xoops']->path('header.php');
54
55
//$xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js');
56
//$xoTheme->addScript(PUBLISHER_URL . '/assets/js/jquery.popeye-2.1.js');
57
//$xoTheme->addScript(PUBLISHER_URL . '/assets/js/publisher.js');
58
//
59
//$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/jquery.popeye.css');
60
//$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/jquery.popeye.style.css');
61
$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/publisher.css');
62
$xoTheme->addStylesheet(PUBLISHER_URL . '/assets/css/rating.css');
63
64
require_once PUBLISHER_ROOT_PATH . '/footer.php';
65
66
// Creating the category object that holds the selected item
67
$categoryObj = $helper->getHandler('Category')->get($itemObj->categoryid());
68
69
// Check user permissions to access that category of the selected item
70
if (!$itemObj->accessGranted()) {
71
    redirect_header('<script>javascript:history.go(-1)</script>', 1, _NOPERM);
72
}
73
$com_replytitle = $itemObj->getTitle();
74
75
// Update the read counter of the selected item
76
if (!$GLOBALS['xoopsUser']
77
    || ($GLOBALS['xoopsUser'] && !$GLOBALS['xoopsUser']->isAdmin($helper->getModule()->mid()))
78
    || ($GLOBALS['xoopsUser']->isAdmin($helper->getModule()->mid()) && 1 == $helper->getConfig('item_admin_hits'))) {
79
    $itemObj->updateCounter();
80
}
81
82
// creating the Item objects that belong to the selected category
83
switch ($helper->getConfig('format_order_by')) {
84
    case 'title':
85
        $sort  = 'title';
86
        $order = 'ASC';
87
        break;
88
    case 'date':
89
        $sort  = 'datesub';
90
        $order = 'DESC';
91
        break;
92
    case 'counter':
93
        $sort  = 'counter';
94
        $order = 'DESC';
95
        break;
96
    case 'rating':
97
        $sort  = 'rating';
98
        $order = 'DESC';
99
        break;
100
    case 'votes':
101
        $sort  = 'votes';
102
        $order = 'DESC';
103
        break;
104
    case 'comments':
105
        $sort  = 'comments';
106
        $order = 'DESC';
107
        break;
108
    default:
109
        $sort  = 'weight';
110
        $order = 'ASC';
111
        break;
112
}
113
114
if ('previous_next' === $helper->getConfig('item_other_items_type')) {
115
    // Retrieving the next and previous object
116
    $previousItemLink = '';
117
    $previousItemUrl  = '';
118
    $nextItemLink     = '';
119
    $nextItemUrl      = '';
120
121
    $previousObj = $helper->getHandler('Item')->getPreviousPublished($itemObj);
122
    $nextObj     = $helper->getHandler('Item')->getNextPublished($itemObj);
123
    if (is_object($previousObj)) {
124
        $previousItemLink = $previousObj->getItemLink();
125
        $previousItemUrl  = $previousObj->getItemUrl();
126
    }
127
128
    if (is_object($nextObj)) {
129
        $nextItemLink = $nextObj->getItemLink();
130
        $nextItemUrl  = $nextObj->getItemUrl();
131
    }
132
    unset($previousObj, $nextObj);
133
    $xoopsTpl->assign('previousItemLink', $previousItemLink);
134
    $xoopsTpl->assign('nextItemLink', $nextItemLink);
135
    $xoopsTpl->assign('previousItemUrl', $previousItemUrl);
136
    $xoopsTpl->assign('nextItemUrl', $nextItemUrl);
137
}
138
139
//CAREFUL!! with many items this will exhaust memory
140
if ('all' === $helper->getConfig('item_other_items_type')) {
141
    $itemsObj = $helper->getHandler('Item')->getAllPublished(0, 0, $categoryObj->categoryid, $sort, $order, '', true, true);
142
    $items    = [];
143
    foreach ($itemsObj[''] as $theItemObj) {
144
        $theItem              = [];
145
        $theItem['body']      = $theItemObj->getBody();
146
        $theItem['title']     = $theItemObj->getTitle();
147
        $theItem['titlelink'] = $theItemObj->getItemLink();
148
        $theItem['itemid']    = $theItemObj->itemid();
149
        $theItem['itemurl']   = $theItemObj->getItemUrl();
150
        $theItem['datesub']   = $theItemObj->getDatesub();
151
        $theItem['counter']   = $theItemObj->counter();
152
        $theItem['who']       = $theItemObj->getWho();
153
        $theItem['category']  = $theItemObj->getCategoryLink();
154
        $theItem['more']      = '<a href="' . $theItemObj->getItemUrl() . '">' . _MD_PUBLISHER_READMORE . '</a>';
155
156
        $summary = $theItemObj->getSummary(300);
157
        if (!$summary) {
158
            $summary = $theItemObj->getBody(300);
159
        }
160
        $theItem['summary'] = $summary;
161
162
        $theItem['cancomment'] = $theItemObj->cancomment();
163
        $comments              = $theItemObj->comments();
164
        if ($comments > 0) {
165
            //shows 1 comment instead of 1 comm. if comments ==1
166
            //langugage file modified accordingly
167
            if (1 == $comments) {
168
                $theItem['comments'] = '&nbsp;' . _MD_PUBLISHER_ONECOMMENT . '&nbsp;';
169
            } else {
170
                $theItem['comments'] = '&nbsp;' . $comments . '&nbsp;' . _MD_PUBLISHER_COMMENTS . '&nbsp;';
171
            }
172
        } else {
173
            $theItem['comments'] = '&nbsp;' . _MD_PUBLISHER_NO_COMMENTS . '&nbsp;';
174
        }
175
176
        $mainImage = $theItemObj->getMainImage();
177
        // check to see if GD function exist
178
        $theItem['item_image'] = $mainImage['image_path'];
179
        if (!empty($mainImage['image_path']) && function_exists('imagecreatetruecolor')) {
180
            $theItem['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path'] . '&amp;w=100';
181
            $theItem['image_path'] = $mainImage['image_path'];
182
        }
183
184
        if ($theItemObj->itemid == $itemObj->itemid()) {
185
            $theItem['titlelink'] = $theItemObj->getItemLink();
186
        }
187
        $items[] = $theItem;
188
        unset($theItem);
189
    }
190
    unset($itemsObj);
191
    $xoopsTpl->assign('items', $items);
192
    unset($items);
193
}
194
195
// Populating the smarty variables with information related to the selected item
196
$item = $itemObj->toArraySimple($itemPageId);
197
$xoopsTpl->assign('show_subtitle', $helper->getConfig('item_disp_subtitle'));
198
199
if ($itemObj->pagescount() > 0) {
200
    if (-1 == $itemPageId) {
201
        $itemPageId = 0;
202
    }
203
    require_once $GLOBALS['xoops']->path('class/pagenav.php');
204
    //    $pagenav = new \XoopsPageNav($itemObj->pagescount(), 1, $itemPageId, 'page', 'itemid=' . $itemObj->itemid());
205
206
    $pagenav = new \XoopsPageNav($itemObj->pagescount(), 1, $itemPageId, 'page', 'itemid=' . $itemObj->itemid()); //SMEDrieben changed ->itemId to ->itemid
207
208
    $xoopsTpl->assign('pagenav', $pagenav->renderNav());
209
}
210
211
// Creating the files object associated with this item
212
$file         = [];
213
$files        = [];
214
$embededFiles = [];
215
$filesObj     = $itemObj->getFiles();
216
217
// check if user has permission to modify files
218
$hasFilePermissions = true;
219
if (!(Utility::userIsAdmin() || Utility::userIsModerator($itemObj))) {
220
    $hasFilePermissions = false;
221
}
222
if (null !== $filesObj) {
223
    foreach ($filesObj as $fileObj) {
224
        $file        = [];
225
        $file['mod'] = false;
226
        if ($hasFilePermissions || (is_object($GLOBALS['xoopsUser']) && $fileObj->getVar('uid') == $GLOBALS['xoopsUser']->getVar('uid'))) {
227
            $file['mod'] = true;
228
        }
229
230
        if ('application/x-shockwave-flash' === $fileObj->mimetype()) {
231
            $file['content'] = $fileObj->displayFlash();
232
            if (mb_strpos($item['maintext'], '[flash-' . $fileObj->getVar('fileid') . ']')) {
233
                $item['maintext'] = str_replace('[flash-' . $fileObj->getVar('fileid') . ']', $file['content'], $item['maintext']);
234
            } else {
235
                $embededFiles[] = $file;
236
            }
237
        } else {
238
            $file['fileid']      = $fileObj->fileid();
239
            $file['name']        = $fileObj->name();
240
            $file['description'] = $fileObj->description();
241
            $file['filename']    = $fileObj->filename();
242
            $file['type']        = $fileObj->mimetype();
243
            $file['datesub']     = $fileObj->getDatesub();
244
            $file['hits']        = $fileObj->counter();
245
            $files[]             = $file;
246
        }
247
    }
248
}
249
250
$item['files']         = $files;
251
$item['embeded_files'] = $embededFiles;
252
unset($file, $embededFiles, $filesObj, $fileObj);
253
254
// Language constants
255
$xoopsTpl->assign('mail_link', 'mailto:?subject=' . sprintf(_CO_PUBLISHER_INTITEM, $GLOBALS['xoopsConfig']['sitename']) . '&amp;body=' . sprintf(_CO_PUBLISHER_INTITEMFOUND, $GLOBALS['xoopsConfig']['sitename']) . ': ' . $itemObj->getItemUrl());
256
$xoopsTpl->assign('itemid', $itemObj->itemid());
257
$xoopsTpl->assign('sectionname', $helper->getModule()->getVar('name'));
258
$xoopsTpl->assign('module_dirname', $helper->getDirname());
259
$xoopsTpl->assign('module_home', Utility::moduleHome($helper->getConfig('format_linked_path')));
260
$xoopsTpl->assign('categoryPath', '<li>' . $item['categoryPath'] . '</li><li> ' . $item['title'] . '</li>');
261
$xoopsTpl->assign('commentatarticlelevel', $helper->getConfig('perm_com_art_level'));
262
$xoopsTpl->assign('com_rule', $helper->getConfig('com_rule'));
263
$xoopsTpl->assign('other_items', $helper->getConfig('item_other_items_type'));
264
$xoopsTpl->assign('itemfooter', $myts->displayTarea($helper->getConfig('item_footer'), 1));
265
$xoopsTpl->assign('perm_author_items', $helper->getConfig('perm_author_items'));
266
267
// tags support
268
if (xoops_isActiveModule('tag')) {
269
    require_once $GLOBALS['xoops']->path('modules/tag/include/tagbar.php');
270
    $xoopsTpl->assign('tagbar', tagBar($itemId, $catId = 0));
271
}
272
273
/**
274
 * Generating meta information for this page
275
 */
276
$publisherMetagen = new Metagen($itemObj->getVar('title'), $itemObj->getVar('meta_keywords', 'n'), $itemObj->getVar('meta_description', 'n'), $itemObj->getCategoryPath());
277
$publisherMetagen->createMetaTags();
278
279
280
// generate JSON-LD and add to page
281
if ($helper->getConfig('generate_jsonld')) {
282
    $jsonld = Jsonld::getItem($itemObj, $categoryObj);
283
    echo $jsonld;
284
}
285
286
// Include the comments if the selected ITEM supports comments
287
if ((0 != $helper->getConfig('com_rule')) && ((1 == $itemObj->cancomment()) || !$helper->getConfig('perm_com_art_level'))) {
288
    require_once $GLOBALS['xoops']->path('include/comment_view.php');
289
    // Problem with url_rewrite and posting comments :
290
    //    $xoopsTpl->assign(
291
    //        [
292
    //            'editcomment_link'   => PUBLISHER_URL . '/comment_edit.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . $link_extra,
293
    //            'deletecomment_link' => PUBLISHER_URL . '/comment_delete.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . $link_extra,
294
    //            'replycomment_link'  => PUBLISHER_URL . '/comment_reply.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . $link_extra,
295
    //        ]
296
    //    );
297
    $xoopsTpl->_tpl_vars['commentsnav'] = str_replace(
298
        "self.location.href='",
299
        "self.location.href='" . PUBLISHER_URL . '/',
300
        $xoopsTpl->_tpl_vars['commentsnav'] ?? ''
301
    );
302
}
303
304
// Original AJAX rating
305
if ($helper->getConfig('perm_rating')) {
306
    $xoopsTpl->assign('rating_enabled', true);
307
    $item['ratingbar'] = Utility::ratingBar($itemId);
308
309
    //    $xoTheme->addScript(PUBLISHER_URL . '/assets/js/behavior.js');
310
    //    $xoTheme->addScript(PUBLISHER_URL . '/assets/js/rating.js');
311
    //}
312
313
    //=============== START VOTE RATING ======================================
314
315
    $start = Request::getInt('start', 0);
316
    $limit = Request::getInt('limit', $helper->getConfig('userpager'));
317
    $id    = Request::getInt('itemid', 0, 'GET');
318
319
    //    $ratingbars = (int)$helper->getConfig('ratingbars'); //from Preferences
320
321
    $voteType = $itemObj->votetype();
322
323
    if ($voteType > 0) {
324
        $GLOBALS['xoTheme']->addStylesheet(PUBLISHER_URL . '/assets/css/rating.css', null);
325
        $GLOBALS['xoopsTpl']->assign('rating', $voteType);
326
        $GLOBALS['xoopsTpl']->assign('rating_5stars', (Constants::RATING_5STARS === $voteType));
327
        $GLOBALS['xoopsTpl']->assign('rating_10stars', (Constants::RATING_10STARS === $voteType));
328
        $GLOBALS['xoopsTpl']->assign('rating_10num', (Constants::RATING_10NUM === $voteType));
329
        $GLOBALS['xoopsTpl']->assign('rating_likes', (Constants::RATING_LIKES === $voteType));
330
        $GLOBALS['xoopsTpl']->assign('rating_reaction', (Constants::RATING_REACTION === $voteType));
331
        $GLOBALS['xoopsTpl']->assign('itemid', 'itemid');
332
        $GLOBALS['xoopsTpl']->assign('blog_icon_url_16', PUBLISHER_URL . '/' . $modPathIcon16);
333
    }
334
335
    /** @var VoteHandler $voteHandler */
336
    $voteHandler = $helper->getHandler('Vote');
337
338
    $rating5 = $voteHandler->getItemRating5($itemObj, Constants::TABLE_ARTICLE);
339
    $xoopsTpl->assign('rating', $rating5);
340
    $item['rating'] = $rating5;
341
342
    //    $GLOBALS['xoopsTpl']->assign('article', $article);
343
    //        $xoopsTpl->assign('article', $article);
344
    $xoopsTpl->assign('item2', $item);
345
    //        $xoopsTpl->assign('rating', $rating);
346
    //        unset($article);
347
    //    }
348
349
    $GLOBALS['xoopsTpl']->assign('type', $helper->getConfig('table_type'));
350
    $GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby'));
351
    $GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col'));
352
}
353
354
//=================== END VOTE RATING =========================================
355
356
//$xoopsTpl->assign('article', $article);
357
$xoopsTpl->assign('item', $item);
358
require_once XOOPS_ROOT_PATH . '/footer.php';
359