mambax7 /
publisher
| 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 | |||
| 33 | require_once __DIR__ . '/header.php'; |
||
| 34 | |||
| 35 | $itemId = Request::getInt('itemid', 0, 'GET'); |
||
| 36 | $itemPageId = Request::getInt('page', -1, 'GET'); |
||
| 37 | |||
| 38 | if (0 == $itemId) { |
||
| 39 | // redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED); |
||
| 40 | } |
||
| 41 | |||
| 42 | $helper = Helper::getInstance(); |
||
| 43 | |||
| 44 | // Creating the item object for the selected item |
||
| 45 | /** @var Item $itemObj */ |
||
| 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); |
||
| 123 | $nextObj = $helper->getHandler('Item')->getNextPublished($itemObj); |
||
| 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); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 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'] = ' ' . _MD_PUBLISHER_ONECOMMENT . ' '; |
||
| 170 | } else { |
||
| 171 | $theItem['comments'] = ' ' . $comments . ' ' . _MD_PUBLISHER_COMMENTS . ' '; |
||
| 172 | } |
||
| 173 | } else { |
||
| 174 | $theItem['comments'] = ' ' . _MD_PUBLISHER_NO_COMMENTS . ' '; |
||
| 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'] . '&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))) { |
||
| 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['filename'] = $fileObj->filename(); |
||
| 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']) . '&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 . '&com_order=' . $com_order . '&com_mode=' . $com_mode . $link_extra, |
||
| 287 | // 'deletecomment_link' => PUBLISHER_URL . '/comment_delete.php?com_itemid=' . $com_itemid . '&com_order=' . $com_order . '&com_mode=' . $com_mode . $link_extra, |
||
| 288 | // 'replycomment_link' => PUBLISHER_URL . '/comment_reply.php?com_itemid=' . $com_itemid . '&com_order=' . $com_order . '&com_mode=' . $com_mode . $link_extra, |
||
| 289 | // ] |
||
| 290 | // ); |
||
| 291 | $xoopsTpl->_tpl_vars['commentsnav'] = str_replace( |
||
| 292 | "self.location.href='", |
||
| 293 | "self.location.href='" . PUBLISHER_URL . '/', |
||
| 294 | $xoopsTpl->_tpl_vars['commentsnav']??'' |
||
| 295 | ); |
||
| 296 | } |
||
| 297 | |||
| 298 | // Original AJAX rating |
||
| 299 | if ($helper->getConfig('perm_rating')) { |
||
| 300 | $xoopsTpl->assign('rating_enabled', true); |
||
| 301 | $item['ratingbar'] = Utility::ratingBar($itemId); |
||
| 302 | |||
| 303 | // $xoTheme->addScript(PUBLISHER_URL . '/assets/js/behavior.js'); |
||
| 304 | // $xoTheme->addScript(PUBLISHER_URL . '/assets/js/rating.js'); |
||
| 305 | //} |
||
| 306 | |||
| 307 | //=============== START VOTE RATING ====================================== |
||
| 308 | |||
| 309 | $start = Request::getInt('start', 0); |
||
| 310 | $limit = Request::getInt('limit', $helper->getConfig('userpager')); |
||
| 311 | $id = Request::getInt('itemid', 0, 'GET'); |
||
| 312 | |||
| 313 | // $ratingbars = (int)$helper->getConfig('ratingbars'); //from Preferences |
||
| 314 | |||
| 315 | $voteType = $itemObj->votetype(); |
||
| 316 | |||
| 317 | if ($voteType > 0) { |
||
| 318 | $GLOBALS['xoTheme']->addStylesheet(PUBLISHER_URL . '/assets/css/rating.css', null); |
||
| 319 | $GLOBALS['xoopsTpl']->assign('rating', $voteType); |
||
| 320 | $GLOBALS['xoopsTpl']->assign('rating_5stars', (Constants::RATING_5STARS === $voteType)); |
||
| 321 | $GLOBALS['xoopsTpl']->assign('rating_10stars', (Constants::RATING_10STARS === $voteType)); |
||
| 322 | $GLOBALS['xoopsTpl']->assign('rating_10num', (Constants::RATING_10NUM === $voteType)); |
||
| 323 | $GLOBALS['xoopsTpl']->assign('rating_likes', (Constants::RATING_LIKES === $voteType)); |
||
| 324 | $GLOBALS['xoopsTpl']->assign('rating_reaction', (Constants::RATING_REACTION === $voteType)); |
||
| 325 | $GLOBALS['xoopsTpl']->assign('itemid', 'itemid'); |
||
| 326 | $GLOBALS['xoopsTpl']->assign('blog_icon_url_16', PUBLISHER_URL . '/' . $modPathIcon16); |
||
| 327 | } |
||
| 328 | |||
| 329 | /** @var VoteHandler $voteHandler */ |
||
| 330 | $voteHandler = $helper->getHandler('Vote'); |
||
| 331 | |||
| 332 | $rating5 = $voteHandler->getItemRating5($itemObj, Constants::TABLE_ARTICLE); |
||
| 333 | $xoopsTpl->assign('rating', $rating5); |
||
| 334 | $item['rating'] = $rating5; |
||
| 335 | |||
| 336 | // $GLOBALS['xoopsTpl']->assign('article', $article); |
||
| 337 | // $xoopsTpl->assign('article', $article); |
||
| 338 | $xoopsTpl->assign('item2', $item); |
||
| 339 | // $xoopsTpl->assign('rating', $rating); |
||
| 340 | // unset($article); |
||
| 341 | // } |
||
| 342 | |||
| 343 | |||
| 344 | $GLOBALS['xoopsTpl']->assign('type', $helper->getConfig('table_type')); |
||
| 345 | $GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby')); |
||
| 346 | $GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col')); |
||
| 347 | } |
||
| 348 | |||
| 349 | //=================== END VOTE RATING ========================================= |
||
| 350 | |||
| 351 | //$xoopsTpl->assign('article', $article); |
||
| 352 | $xoopsTpl->assign('item', $item); |
||
| 353 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
| 354 |