Esempio n. 1
0
 function display($tpl = null)
 {
     JHTML::_('behavior.modal');
     $document = JFactory::getDocument();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $model = $this->getModel();
     $dispatcher = JDispatcher::getInstance();
     $config = JFactory::getConfig();
     $cat_id = JRequest::getVar('cid', 0, '', 'int');
     $uid = JRequest::getVar('uid', 0, '', 'int');
     $se = JRequest::getVar('se', 0, '', 'int');
     $reset = JRequest::getVar('reset', 0, '', 'int');
     $layout = JRequest::getVar('layout', '');
     $order = JRequest::getCmd('order', $par->get('items_ordering', 'date_e'));
     $ord_t = JRequest::getCmd('ord_t', $par->get('items_ordering_dir', 'desc'));
     $theme = $par->get('theme', 'default');
     if ($layout == 'favourites') {
         if ($user->id == '0') {
             $uri = JFactory::getURI();
             $app->redirect('index.php?option=com_users&view=login&return=' . base64_encode($uri), JText::_('COM_DJCLASSIFIEDS_PLEASE_LOGIN'));
         }
         JRequest::setVar('fav', '1');
     }
     if ($reset) {
         $items = $model->resetSearchFilters();
     }
     $catlist = '';
     if ($cat_id > 0) {
         $cats = DJClassifiedsCategory::getSubCatIemsCount($cat_id, 1, $par->get('subcats_ordering', 'ord'), $par->get('subcats_hide_empty', 0));
         $catlist = $cat_id;
         foreach ($cats as $c) {
             $catlist .= ',' . $c->id;
         }
     } else {
         $cats = DJClassifiedsCategory::getCatAllItemsCount(1, $par->get('subcats_ordering', 'ord'), $par->get('subcats_hide_empty', 0));
     }
     $subcats = '';
     $cat_images = '';
     foreach ($cats as $c) {
         if ($c->parent_id == $cat_id) {
             $subcats .= $c->id . ',';
         }
     }
     if ($subcats) {
         $subcats = substr($subcats, 0, -1);
         $cat_images = $model->getCatImages($subcats);
     }
     $items = $model->getItems($catlist);
     $countitems = $model->getCountItems($catlist);
     $menus = $app->getMenu('site');
     $m_active = $menus->getActive();
     $cat_menu_path = array();
     $cid_menu = 0;
     if ($m_active) {
         if (strstr($m_active->link, 'com_djclassifieds') && strstr($m_active->link, 'items')) {
             if (isset($m_active->query['cid'])) {
                 $cid_menu = $m_active->query['cid'];
                 if ($cid_menu > 0) {
                     $cat_menu_path = DJClassifiedsCategory::getParentPath(1, $cid_menu);
                 }
             }
         }
     }
     if ($uid > 0 || $se || $order != $par->get('items_ordering', 'date_e') || $ord_t != $par->get('items_ordering_dir', 'desc')) {
         $document->setMetaData('robots', 'NOINDEX, FOLLOW');
     }
     $warning18 = '';
     $cat_id = JRequest::getVar('cid', 0, '', 'int');
     $main_cat = '';
     if ($cat_id > 0) {
         $main_cat = $model->getMainCat($cat_id);
         if (!$main_cat) {
             DJClassifiedsTheme::djAccessRestriction('category');
         }
         if ($main_cat->metakey != '') {
             $document->setMetaData('keywords', $main_cat->metakey);
         } else {
             if ($m_active) {
                 if ($m_active->params->get('menu-meta_keywords')) {
                     $document->setMetaData('keywords', $m_active->params->get('menu-meta_keywords'));
                 }
             }
         }
         if ($main_cat->metadesc != '') {
             $document->setDescription($main_cat->metadesc);
         } else {
             if ($m_active) {
                 if ($m_active->params->get('menu-meta_description')) {
                     $document->setDescription($m_active->params->get('menu-meta_description'));
                 }
             }
         }
         $cat_path = array();
         $pathway = $app->getPathway();
         if ($main_cat->parent_id == 0) {
             if ($cid_menu != $cat_id) {
                 $pathway->addItem($main_cat->name);
             }
             $cat_path[] = $main_cat;
         } else {
             $cat_path = DJClassifiedsCategory::getParentPath(1, $main_cat->id);
             for ($c = count($cat_path); $c > 0; $c--) {
                 $to_b = 1;
                 if (count($cat_menu_path)) {
                     foreach ($cat_menu_path as $cm) {
                         if ($cm->id == $cat_path[$c - 1]->id) {
                             $to_b = 0;
                             break;
                         }
                     }
                 }
                 if ($to_b) {
                     $pathway->addItem($cat_path[$c - 1]->name, DJClassifiedsSEO::getCategoryRoute($cat_path[$c - 1]->id . ':' . $cat_path[$c - 1]->alias));
                 }
             }
         }
         $cat_theme = '';
         foreach ($cat_path as $cp) {
             if ($cp->theme) {
                 $cat_theme = $cp->theme;
             }
             if ($cp->restriction_18) {
                 $warning18 = 1;
             }
         }
         DJClassifiedsTheme::includeCSSfiles($cat_theme);
         if ($cat_theme) {
             $this->_addPath('template', JPATH_COMPONENT . '/themes/' . $cat_theme . '/views/items');
             $theme = $cat_theme;
         }
         $c_title = $document->getTitle();
         $cat_name = $main_cat->name;
         $seo_cat_path = '';
         $seo_title_separator = $par->get('seo_title_separator', ' - ');
         foreach ($cat_path as $cp) {
             if ($seo_cat_path) {
                 $seo_cat_path .= $seo_title_separator;
             }
             $seo_cat_path .= $cp->name;
         }
         $seo_title_from = array('|', '<default_title>', '<category_name>', '<category_path>');
         $seo_title_to = array($seo_title_separator, $c_title, $cat_name, $seo_cat_path);
         $seo_title = str_ireplace($seo_title_from, $seo_title_to, $par->get('seo_title_items', '<category_path>|<default_title>'));
         $document->setTitle($seo_title);
     } else {
         if ($se && isset($_GET['se_cats'])) {
             if (is_array($_GET['se_cats'])) {
                 $se_cat_id = end($_GET['se_cats']);
                 if ($se_cat_id == '' && count($_GET['se_cats']) > 2) {
                     $se_cat_id = $_GET['se_cats'][count($_GET['se_cats']) - 2];
                 }
             } else {
                 $se_cat_ids = explode(',', JRequest::getVar('se_cats'));
                 $se_cat_id = end($se_cat_ids);
             }
             $se_cat_id = (int) str_ireplace('p', '', $se_cat_id);
             if ($se_cat_id > 0) {
                 $main_cat = $model->getMainCat($se_cat_id);
             }
         }
     }
     $re = JRequest::getVar('re', 0, '', 'int');
     $reg_id = 0;
     if (isset($_GET['se_regs'])) {
         if (is_array($_GET['se_regs'])) {
             $reg_id = end($_GET['se_regs']);
             if ($reg_id == '' && count($_GET['se_regs']) > 2) {
                 $reg_id = $_GET['se_regs'][count($_GET['se_regs']) - 2];
             }
         } else {
             $reg_ids = explode(',', JRequest::getVar('se_regs'));
             $reg_id = end($reg_ids);
         }
         $reg_id = (int) $reg_id;
     }
     if ($reg_id) {
         $main_reg = $model->getMainRegions($reg_id);
     } else {
         $main_reg = '';
     }
     $se_results_link = JRoute::_(DJClassifiedsSEO::getCategoryRoute('0:all'));
     if ($config->get('sef')) {
         $se_results_link .= '?se=1&amp;re=1&amp;se_regs=';
     } else {
         $se_results_link .= '&se=1&re=1&se_regs=';
     }
     if ($uid > 0) {
         $u_name = $model->getUserName($uid);
         $this->assignRef('u_name', $u_name);
     }
     if ($par->get('show_types', '0')) {
         $types = $model->getTypes();
         $this->assignRef('types', $types);
     }
     $limit = JRequest::getVar('limit', $par->get('limit_djitem_show'), '', 'int');
     $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
     $pagination = new JPagination($countitems, $limitstart, $limit);
     //	$main_name = $model->makePathway($cat_list);
     if ($par->get('rss_feed', 1) == 1) {
         $link = '&format=feed&limitstart=';
         $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
         $document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
         $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
         $document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
     }
     if (!isset($_COOKIE["djcf_warning18"])) {
         $cats_all = DJClassifiedsCategory::getCategories();
         foreach ($items as $item) {
             if (isset($cats_all[$item->cat_id])) {
                 if ($cats_all[$item->cat_id]->restriction_18) {
                     $warning18 = 1;
                     break;
                 }
             }
         }
     }
     if ($warning18 && !isset($_COOKIE["djcf_warning18"])) {
         $warning18_link = '';
         if ($par->get('restriction_18_art_id', 0)) {
             require_once JPATH_SITE . '/components/com_content/helpers/route.php';
             $terms_article = $model->getTermsLink($par->get('restriction_18_art_id', 0));
             if ($terms_article) {
                 $slug = $terms_article->id . ':' . $terms_article->alias;
                 $cslug = $terms_article->catid . ':' . $terms_article->c_alias;
                 $warning18_link = ContentHelperRoute::getArticleRoute($slug, $cslug);
                 if ($par->get('restriction_18_art', 0) == 2) {
                     $warning18_link .= '&tmpl=component';
                 }
                 $warning18_link = JRoute::_($warning18_link);
             }
         }
         $this->assignRef('terms_link', $warning18_link);
         $this->assignRef('theme', $theme);
         parent::display('terms');
     } else {
         if ($cat_id > 0) {
             $correct_link = DJClassifiedsSEO::getCategoryRoute($main_cat->id . ':' . $main_cat->alias);
             $document->setMetaData('canonical', JRoute::_($correct_link));
         }
         /* plugins */
         if ($layout == 'blog') {
             $event_view = 'items.blog';
         } else {
             $event_view = 'items.table';
         }
         JPluginHelper::importPlugin('djclassifieds');
         foreach ($items as $item) {
             $results = $dispatcher->trigger('onPrepareItemDescription', array(&$item, &$par, 'items'));
             $item->event = new stdClass();
             $resultsAfterTitle = $dispatcher->trigger('onAfterDJClassifiedsDisplayTitle', array(&$item, &$par, $event_view));
             $item->event->afterDJClassifiedsDisplayTitle = trim(implode("\n", $resultsAfterTitle));
             $resultsBeforeContent = $dispatcher->trigger('onBeforeDJClassifiedsDisplayContent', array(&$item, &$par, $event_view));
             $item->event->beforeDJClassifiedsDisplayContent = trim(implode("\n", $resultsBeforeContent));
             $resultsAfterContent = $dispatcher->trigger('onAfterDJClassifiedsDisplayContent', array(&$item, &$par, $event_view));
             $item->event->afterDJClassifiedsDisplayContent = trim(implode("\n", $resultsAfterContent));
         }
         if (!$tpl && $layout != 'blog') {
             $itemid = JRequest::getVar('Itemid', '');
             $menu_tpl = -1;
             if ($itemid) {
                 $menu = $app->getMenu('site');
                 $menu_item = $menu->getItem($itemid);
                 if ($menu_item) {
                     $menu_tpl = $menu_item->params->get('table_type', '-1');
                 }
             }
             if ($menu_tpl != -1) {
                 if ($menu_tpl != 'classic') {
                     $tpl = $menu_tpl;
                 }
             } else {
                 if ($menu_tpl == -1 && $par->get('table_type', '')) {
                     $tpl = $par->get('table_type', '');
                 }
             }
         }
         $custom_fields = $model->getCustomFields();
         $this->assignRef('cats', $cats);
         $this->assignRef('cat_path', $cat_path);
         $this->assignRef('cat_images', $cat_images);
         $this->assignRef('items', $items);
         $this->assignRef('custom_fields', $custom_fields);
         $this->assignRef('countitems', $countitems);
         $this->assignRef('main_cat', $main_cat);
         $this->assignRef('main_reg', $main_reg);
         $this->assignRef('se_results_link', $se_results_link);
         $this->assignRef('pagination', $pagination);
         $this->assignRef('theme', $theme);
         parent::display('cat');
         parent::display($tpl);
     }
 }
Esempio n. 2
0
 function display($tpl = null)
 {
     $model = $this->getModel();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $document = JFactory::getDocument();
     $app = JFactory::getApplication();
     $dispatcher = JDispatcher::getInstance();
     $theme = $par->get('theme', 'default');
     $user = JFactory::getUser();
     $item = $model->getItem();
     if ($item->user_id != $user->id) {
         $groups_acl = ',' . implode(',', $user->getAuthorisedViewLevels()) . ',';
         if (!strstr($groups_acl, ',' . $item->c_access_view . ',') || !$item) {
             DJClassifiedsTheme::djAccessRestriction('category');
         } else {
             if ($item->access_view == 0) {
                 if (!strstr($groups_acl, ',' . $item->c_access_item_view . ',')) {
                     DJClassifiedsTheme::djAccessRestriction();
                 }
             } else {
                 if (!strstr($groups_acl, ',' . $item->access_view . ',')) {
                     DJClassifiedsTheme::djAccessRestriction();
                 }
             }
         }
     }
     $item_images = DJClassifiedsImage::getAdsImages($item->id);
     $category = $model->getCategory($item->cat_id);
     $fields = $model->getFields($item->cat_id);
     $fields_contact = $model->geContactFields();
     $item_payments = $model->getItemPayment($item->id);
     $item_options = $model->getItemOptions($item->id);
     $bids = $model->getBids($item->id, $par->get('bids_displayed', 5));
     if ($item->user_id != 0) {
         $user_items_c = $model->getUserItemsCount($item->user_id);
         $this->assignRef('user_items_c', $user_items_c);
     }
     $menus = $app->getMenu('site');
     $m_active = $menus->getActive();
     $cat_menu_path = array();
     $cid_menu = 0;
     if ($m_active) {
         if (strstr($m_active->link, 'com_djclassifieds') && strstr($m_active->link, 'items')) {
             $cid_menu = $m_active->query['cid'];
             if ($cid_menu > 0) {
                 $cat_menu_path = DJClassifiedsCategory::getParentPath(1, $cid_menu);
             }
         }
     }
     $warning18 = '';
     $main_cat_id = $item->cat_id;
     $pathway = $app->getPathway();
     $cat_path = array();
     $cat_theme = '';
     if ($category->id != 0) {
         $cat_path = DJClassifiedsCategory::getParentPath(1, $category->id);
         $main_cat_id = $cat_path[count($cat_path) - 1]->id;
         for ($c = count($cat_path); $c > 0; $c--) {
             $to_b = 1;
             if (count($cat_menu_path)) {
                 foreach ($cat_menu_path as $cm) {
                     if ($cm->id == $cat_path[$c - 1]->id) {
                         $to_b = 0;
                         break;
                     }
                 }
             }
             if ($to_b) {
                 $pathway->addItem($cat_path[$c - 1]->name, DJClassifiedsSEO::getCategoryRoute($cat_path[$c - 1]->id . ':' . $cat_path[$c - 1]->alias));
             }
         }
         foreach ($cat_path as $cp) {
             if ($cp->theme) {
                 $cat_theme = $cp->theme;
             }
             if ($cp->restriction_18) {
                 $warning18 = 1;
             }
         }
     }
     DJClassifiedsTheme::includeCSSfiles($cat_theme);
     if ($cat_theme) {
         $this->_addPath('template', JPATH_COMPONENT . '/themes/' . $cat_theme . '/views/item');
         $theme = $cat_theme;
     }
     $regions = $model->getRegions();
     $country = '';
     $city = '';
     $region_name = '';
     if ($item->region_id != 0 && $par->get('show_regions', '1')) {
         $address = '';
         $rid = $item->region_id;
         if ($rid != 0) {
             while ($rid != 0) {
                 foreach ($regions as $li) {
                     if ($li->id == $rid) {
                         $rid = $li->parent_id;
                         $address .= $li->name . ', ';
                         if ($li->country) {
                             $country = $li->name;
                         }
                         if ($li->city) {
                             $city = $li->name;
                         }
                         if (!$region_name) {
                             $region_name = $li->name;
                         }
                         break;
                     }
                 }
                 if ($rid == $item->region_id) {
                     break;
                 }
             }
         }
         $address = substr($address, 0, -2);
     }
     $profile = '';
     if ($item->user_id) {
         $profile = $model->getProfile($item->user_id);
     }
     $custom_ask_seller = $model->getCustomAskSellerFields();
     if ($item->metakey != '') {
         $document->setMetaData('keywords', $item->metakey);
     } else {
         if ($category->metakey != '') {
             $document->setMetaData('keywords', $category->metakey);
         } else {
             if ($m_active) {
                 if ($m_active->params->get('menu-meta_description')) {
                     $document->setMetaData('keywords', $m_active->params->get('menu-meta_description'));
                 }
             }
         }
     }
     if ($item->metadesc != '') {
         $document->setDescription($item->metadesc);
     } else {
         if ($par->get('seo_item_metadesc', '0') == 0) {
             $document->setDescription($item->intro_desc);
         } else {
             if ($category->metadesc != '') {
                 $document->setDescription($category->metadesc);
             } else {
                 if ($m_active) {
                     if ($m_active->params->get('menu-meta_keywords')) {
                         $document->setDescription($m_active->params->get('menu-meta_keywords'));
                     }
                 }
             }
         }
     }
     $c_title = $document->getTitle();
     $cat_name = $category->name;
     $item_name = $item->name;
     $seo_cat_path = '';
     $seo_title_separator = $par->get('seo_title_separator', ' - ');
     foreach ($cat_path as $cp) {
         if ($seo_cat_path) {
             $seo_cat_path .= $seo_title_separator;
         }
         $seo_cat_path .= $cp->name;
     }
     $seo_title_from = array('|', '<default_title>', '<category_name>', '<category_path>', '<item_name>', '<region_name>');
     $seo_title_to = array($seo_title_separator, $c_title, $cat_name, $seo_cat_path, $item_name, $region_name);
     $seo_title = str_ireplace($seo_title_from, $seo_title_to, $par->get('seo_title_item', '<item_name>|<category_name>|<default_title>'));
     $document->setTitle($seo_title);
     $document->setMetaData('og:title', $item->name);
     $document->setMetaData('og:description', $item->intro_desc);
     if ($item_images) {
         $document->setMetaData('og:image', JURI::base() . $item_images[0]->thumb_b);
     }
     if ($par->get('comments', '0') == 1 && $par->get('fb_comments_admin', '') != '') {
         $document->addCustomTag('<meta property="fb:admins" content="' . $par->get('fb_comments_admin', '') . '" />');
     }
     $anch = $par->get('showitem_jump', 0) ? '#dj-classifieds' : '';
     $correct_link = JRoute::_(DJClassifiedsSEO::getItemRoute($item->id . ':' . $item->alias, $item->cat_id . ':' . $item->c_alias)) . $anch;
     $document->setMetaData('canonical', $correct_link);
     /* plugins */
     if ($category) {
         $item->c_alias = $category->alias;
     }
     $results = $dispatcher->trigger('onPrepareItemDescription', array(&$item, &$par, 'item'));
     $item->event = new stdClass();
     $resultsAfterTitle = $dispatcher->trigger('onAfterDJClassifiedsDisplayTitle', array(&$item, &$par, 'item'));
     $item->event->afterDJClassifiedsDisplayTitle = trim(implode("\n", $resultsAfterTitle));
     $resultsBeforeContent = $dispatcher->trigger('onBeforeDJClassifiedsDisplayContent', array(&$item, &$par, 'item'));
     $item->event->beforeDJClassifiedsDisplayContent = trim(implode("\n", $resultsBeforeContent));
     $resultsAfterContent = $dispatcher->trigger('onAfterDJClassifiedsDisplayContent', array(&$item, &$par, 'item'));
     $item->event->afterDJClassifiedsDisplayContent = trim(implode("\n", $resultsAfterContent));
     $resultsAfterAuthorProfile = $dispatcher->trigger('onAfterDJClassifiedsDisplayAdvertAuthor', array(&$item, &$par, 'item'));
     $item->event->onAfterDJClassifiedsDisplayAdvertAuthor = trim(implode("\n", $resultsAfterAuthorProfile));
     $pathway->addItem($item->name);
     $this->assignRef('item', $item);
     $this->assignRef('item_images', $item_images);
     $this->assignRef('item_options', $item_options);
     $this->assignRef('fields', $fields);
     $this->assignRef('fields_contact', $fields_contact);
     $this->assignRef('country', $country);
     $this->assignRef('city', $city);
     $this->assignRef('address', $address);
     $this->assignRef('main_cat_id', $main_cat_id);
     $this->assignRef('item_payments', $item_payments);
     $this->assignRef('category', $category);
     $this->assignRef('profile', $profile);
     $this->assignRef('theme', $theme);
     $this->assignRef('bids', $bids);
     $this->assignRef('custom_ask_seller', $custom_ask_seller);
     if ($warning18 && !isset($_COOKIE["djcf_warning18"])) {
         $warning18_link = '';
         if ($par->get('restriction_18_art_id', 0)) {
             require_once JPATH_SITE . '/components/com_content/helpers/route.php';
             $terms_article = $model->getTermsLink($par->get('restriction_18_art_id', 0));
             if ($terms_article) {
                 $slug = $terms_article->id . ':' . $terms_article->alias;
                 $cslug = $terms_article->catid . ':' . $terms_article->c_alias;
                 $warning18_link = ContentHelperRoute::getArticleRoute($slug, $cslug);
                 if ($par->get('restriction_18_art', 0) == 2) {
                     $warning18_link .= '&tmpl=component';
                 }
                 $warning18_link = JRoute::_($warning18_link);
             }
         }
         $this->assignRef('terms_link', $warning18_link);
         parent::display('terms');
     } else {
         parent::display($tpl);
     }
 }