public function display($tpl = null) { $this->item = $this->get('Item'); if (!JUDownloadFrontHelperPermission::canViewDocument($this->item->id)) { $user = JFactory::getUser(); if ($user->id) { return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); } else { $uri = JUri::getInstance(); $loginUrl = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($uri), false); $app = JFactory::getApplication(); $app->redirect($loginUrl, JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_ACCESS_THIS_PAGE'), 'warning'); return false; } } $app = JFactory::getApplication(); $this->user = JFactory::getUser(); $this->print = $app->input->getBool('print', false); $this->model = $this->getModel(); $this->state = $this->get('State'); $this->params = $this->state->get('params'); if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $limitStart = $app->input->getUint('limitstart', 0); $config = JFactory::getConfig(); $cookie_domain = $config->get('cookie_domain', ''); $cookie_path = $config->get('cookie_path', '/'); if (isset($_COOKIE['judl_recently_viewed_documents'])) { $recently_viewed_doc_array = explode(',', $_COOKIE['judl_recently_viewed_documents']); $recently_viewed_doc_array = array_unique($recently_viewed_doc_array); $key = array_search($this->item->id, $recently_viewed_doc_array); if ($key !== false) { unset($recently_viewed_doc_array[$key]); } else { if ($limitStart == 0) { $this->model->updateHits($this->item->id); } } $maxDocuments = $this->params->get('max_recently_viewed_documents', 12); if (count($recently_viewed_doc_array) >= $maxDocuments) { $recently_viewed_doc_array = array_slice($recently_viewed_doc_array, 0, $maxDocuments - 1); } array_unshift($recently_viewed_doc_array, $this->item->id); $recently_viewed_doc_array = implode(',', $recently_viewed_doc_array); setcookie('judl_recently_viewed_documents', $recently_viewed_doc_array, time() + (3600 * 24 * 15), $cookie_path, $cookie_domain); } else { if ($limitStart == 0) { $this->model->updateHits($this->item->id); } setcookie('judl_recently_viewed_documents', $this->item->id, time() + (3600 * 24 * 15), $cookie_path, $cookie_domain); } $topLevelCats = JUDownloadHelper::getCatsByLevel(1, $this->item->cat_id); if ($topLevelCats) { $this->tl_catid = $topLevelCats[0]->id; } $this->pageclass_sfx = htmlspecialchars($this->item->params->get('pageclass_sfx')); $this->item->class_sfx = htmlspecialchars($this->item->class_sfx); $this->collection_popup = false; if (JUDLPROVERSION && $this->user->id > 0) { $this->collection_popup = true; $this->collections = $this->model->getCollectionPopup($this->item->id); } $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $this->item->event = new stdClass(); $context = 'com_judownload.document'; $results = $dispatcher->trigger('onContentAfterTitle', array($context, &$this->item, &$this->item->params, $limitStart)); $this->item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array($context, &$this->item, &$this->item->params, $limitStart)); $this->item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array($context, &$this->item, &$this->item->params, $limitStart)); $this->item->event->afterDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onBeforeDisplayJUDLComment', array($context, &$this->item, &$this->item->params, $limitStart)); $this->item->event->beforeDisplayJUDLComment = trim(implode("\n", $results)); $results = $dispatcher->trigger('onAfterDisplayJUDLComment', array($context, &$this->item, &$this->item->params, $limitStart)); $this->item->event->afterDisplayJUDLComment = trim(implode("\n", $results)); $this->_prepareData(); $this->_prepareDocument(); $this->_setBreadcrumb(); parent::display($tpl); }