Example #1
0
 public function display($tpl = null)
 {
     $this->item = $this->get('Item');
     if (!JUDirectoryFrontHelperPermission::canViewListing($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_JUDIRECTORY_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['judir_recently_viewed_listings'])) {
         $recently_viewed_listing_array = explode(',', $_COOKIE['judir_recently_viewed_listings']);
         $recently_viewed_listing_array = array_unique($recently_viewed_listing_array);
         $key = array_search($this->item->id, $recently_viewed_listing_array);
         if ($key !== false) {
             unset($recently_viewed_listing_array[$key]);
         } else {
             if ($limitStart == 0) {
                 $this->model->updateHits($this->item->id);
             }
         }
         $maxListings = $this->params->get('max_recently_viewed_listings', 12);
         if (count($recently_viewed_listing_array) >= $maxListings) {
             $recently_viewed_listing_array = array_slice($recently_viewed_listing_array, 0, $maxListings - 1);
         }
         array_unshift($recently_viewed_listing_array, $this->item->id);
         $recently_viewed_listing_array = implode(',', $recently_viewed_listing_array);
         setcookie('judir_recently_viewed_listings', $recently_viewed_listing_array, time() + 3600 * 24 * 15, $cookie_path, $cookie_domain);
     } else {
         if ($limitStart == 0) {
             $this->model->updateHits($this->item->id);
         }
         setcookie('judir_recently_viewed_listings', $this->item->id, time() + 3600 * 24 * 15, $cookie_path, $cookie_domain);
     }
     $topLevelCats = JUDirectoryHelper::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 (JUDIRPROVERSION && $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_judirectory.listing';
     $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('onBeforeDisplayJUDIRComment', array($context, &$this->item, &$this->item->params, $limitStart));
     $this->item->event->beforeDisplayJUDIRComment = trim(implode("\n", $results));
     $results = $dispatcher->trigger('onAfterDisplayJUDIRComment', array($context, &$this->item, &$this->item->params, $limitStart));
     $this->item->event->afterDisplayJUDIRComment = trim(implode("\n", $results));
     $this->_prepareData();
     $this->_prepareDocument();
     $this->_setBreadcrumb();
     parent::display($tpl);
 }