Current File : /home/pacjaorg/public_html/km/components/com_djclassifieds/views/items/view.html.php |
<?php
/**
* @package DJ-Classifieds
* @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
* @license http://www.gnu.org/licenses GNU/GPL
* @author url: http://dj-extensions.com
* @author email contact@dj-extensions.com
*/
defined ('_JEXEC') or die('Restricted access');
class DJClassifiedsViewItems extends JViewLegacy
{
private static $_viewname = 'items';
public function __construct($config = array())
{
parent::__construct($config);
$par = JFactory::getApplication()->getParams('com_djclassifieds');
$this->_addPath('template', JPATH_ROOT.'/components/com_djclassifieds/themes/'.$par->get('theme','default').'/views/'.self::$_viewname);
}
function display($tpl = null)
{
$app = JFactory::getApplication();
$document = JFactory::getDocument();
$user = JFactory::getUser();
$par = $app->getParams('com_djclassifieds');
$model = $this->getModel();
$menus = $app->getMenu('site');
$m_active = $menus->getActive();
$uid = $app->input->getInt('uid', 0);
$se = $app->input->getInt('se', 0);
$reset = $app->input->getInt('reset', 0); // backward compatibility
$layout = $app->input->getVar('layout');
$theme = $par->get('theme','default');
$warning18 = false;
$main_cat = null;
$cat_theme = '';
$c_title = $document->getTitle();
$cat_name = '';
$cat_seo_title = '';
$seo_cat_path = '';
$seo_title_separator = $par->get('seo_title_separator', ' - ');
$cat_path = array();
$cat_menu_path = array();
$cid_menu = 0;
$subcats = '';
$cat_images = null;
$catlist = '';
$main_reg = null;
$reg_name = '';
$reg_seo_title = '';
$seo_reg_path = '';
$reg_path = array();
$reg_menu_path = array();
$reg_menu = 0;
if($par->get('table_type', '') == '-1'){ // backward compatibility
$par->set('table_type', JComponentHelper::getParams('com_djclassifieds')->get('table_type', ''));
}
if($par->get('404_cat_redirect','0')==1){
if($app->input->get('cid','')=='' && $app->input->get('rid','')=='' && $app->input->get('se','')=='' && $app->input->get('uid','')=='' && $app->input->get('type','')=='' && $layout!='favourites'){
throw new Exception(JText::_('COM_DJCLASSIFIEDS_CATEGORY_NOT_AVAILABLE'), 404);
}
}
if($m_active && $layout=='' && $m_active->query['option']=='com_djclassifieds' && $m_active->query['view']=='items' && isset($m_active->query['layout']) && $m_active->query['layout']=='blog'){
$this->setLayout('blog');
$layout = 'blog';
}
if($layout=='favourites'){
if(!$user->id){
DJClassifiedsSEO::redirectLogIn();
}
$layout = '';
if($par->get('list_type','table')=='blog'){
$this->setLayout('blog');
$layout = 'blog';
}
$app->input->set('fav','1');
}
if($reset){ // backward compatibility
$model->resetSearchFilters();
}
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){
$cat_menu_path = DJClassifiedsCategory::getParentPath(1,$cid_menu);
}
}
if(isset($m_active->query['rid'])){
$rid_menu = $m_active->query['rid'];
if($rid_menu){
$reg_menu_path = DJClassifiedsRegion::getParentPath($rid_menu,1);
}
}
}
if($m_active->getParams()->get('menu-meta_keywords')){
$document->setMetaData('keywords',$m_active->getParams()->get('menu-meta_keywords'));
}
if($m_active->getParams()->get('menu-meta_description')){
$document->setDescription($m_active->getParams()->get('menu-meta_description'));
}
}
// removing [none] sort opt
DJClassifiedsTheme::removeNoneParamOpt('blog_sorting_fields', $par);
DJClassifiedsTheme::removeNoneParamOpt('table_smart_sorting_fields', $par);
/* categories */
$cat_id = DJClassifiedsTheme::getIdFromTree($app->input->getVar('se_cats'));
if(!$cat_id){
$cat_id = $app->input->getInt('cid', 0);
}
if($cat_id){
$main_cat = $model->getCategory($cat_id);
if(!$main_cat){
DJClassifiedsAccess::restrictionRedirect('category');
}
$pathway = $app->getPathway();
if($main_cat->parent_id == 0){
if($cid_menu != $cat_id){
$pathway->addItem(JText::_($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;
foreach($cat_menu_path as $cm){
if($cm->id == $cat_path[$c-1]->id){
$to_b = 0;
break;
}
}
if($to_b){
$pathway->addItem(JText::_($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 = true;
}
}
if($cat_theme){
$this->_addPath('template', JPATH_COMPONENT. '/themes/'.$cat_theme.'/views/items');
$theme = $cat_theme;
}
$cat_name = JText::_($main_cat->name);
$cat_seo_title = $main_cat->metatitle;
foreach($cat_path as $cp){
if($seo_cat_path){
$seo_cat_path .= $seo_title_separator;
}
$seo_cat_path .= JText::_($cp->name);
}
}
if($cat_id){
$cats = DJClassifiedsCategory::getSubCatItemsCount($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));
}
foreach($cats as $c){
if($c->parent_id==$cat_id){
$subcats .= $c->id.',';
}
}
if($cat_id || $subcats){
$cat_ids = array_filter(explode(',', $subcats));
if($cat_id){
$cat_ids[] = $cat_id;
}
$cat_images = DJClassifiedsImage::getCatImages(implode(',',$cat_ids));
}
if($main_cat){
$app->input->cookie->set('djcf_lastcat',$main_cat->id,0,'/');
}
/* regions */
$reg_id = DJClassifiedsTheme::getIdFromTree($app->input->getVar('se_regs'));
if(!$reg_id){
$reg_id = $app->input->getInt('rid');
}
if($reg_id){
$main_reg = $model->getRegion($reg_id);
$pathway = $app->getPathway();
if($main_reg->parent_id == 0){
if($reg_menu != $reg_id){
$pathway->addItem(JText::_($main_reg->name));
}
$reg_path[] = $main_reg;
}else{
$reg_path = DJClassifiedsRegion::getParentPath($main_reg->id,1);
for($r=count($reg_path);$r>0;$r--){
$to_b = 1;
foreach($reg_menu_path as $rm){
if($rm->id == $reg_path[$r-1]->id){
$to_b = 0;
break;
}
}
if($to_b){
$pathway->addItem(JText::_($reg_path[$r-1]->name), DJClassifiedsSEO::getRegionRoute($reg_path[$r-1]->id.':'.$reg_path[$r-1]->alias));
}
}
}
$reg_name = JText::_($main_reg->name);
$reg_seo_title = $main_reg->metatitle;
foreach($reg_path as $rp){
if($seo_reg_path){
$seo_reg_path .= $seo_title_separator;
}
$seo_reg_path .= JText::_($rp->name);
}
}
/* linked field */
$this->main_field = $app->input->getInt('fid') ? $model->getField($app->input->getInt('fid')) : null;
if($this->main_field){
$f_val = $app->input->getVar('se_'.$this->main_field->id);
$f_par = new JRegistry();
$f_par->loadString($this->main_field->params);
$values_to_labels = $f_par->get('values_to_labels','-1') != '-1' ? $f_par->get('values_to_labels','-1') : $par->get('cf_values_to_labels','0');
$this->main_field->val = $values_to_labels ? DJClassifiedsTheme::getFieldValueToLabel($f_val) : $f_val;
}
/* document prepare */
if($main_cat && $main_cat->metakey){
$document->setMetaData('keywords',$main_cat->metakey);
}elseif($main_reg && $main_reg->metakey){
$document->setMetaData('keywords',$main_reg->metakey);
}
if($main_cat && $main_cat->metadesc){
$document->setDescription($main_cat->metadesc);
}elseif($main_reg && $main_reg->metadesc){
$document->setDescription($main_reg->metadesc);
}
if($uid || $se || $app->input->getCmd('order', '') || $app->input->getCmd('ord_t', '')){
$document->setMetaData('robots','NOINDEX, FOLLOW');
}else if($main_cat && $main_cat->metarobots){
$document->setMetaData('robots',$main_cat->metarobots);
}else if($main_reg && $main_reg->metarobots){
$document->setMetaData('robots',$main_reg->metarobots);
}else if($m_active && $m_active->getParams()->get('seo_items_metarobots')){
$document->setMetaData('robots',$m_active->getParams()->get('seo_items_metarobots'));
}else if($par->get('seo_items_metarobots','')){
$document->setMetaData('robots',$par->get('seo_items_metarobots',''));
}
if($m_active && $page_title = $m_active->getParams()->get('page_title','')){
$active_cid = !empty($m_active->query['cid']) ? $m_active->query['cid'] : '0';
$active_rid = !empty($m_active->query['rid']) ? $m_active->query['rid'] : '0';
if($active_cid == $app->input->getInt('cid', '0') && $active_rid == $app->input->getInt('rid', '0')){
$document->setTitle($page_title);
}
}
$seo_title_from = array('|','<default_title>','<category_name>','<category_path>','<region_name>','<region_path>','<category_seo_title>','<region_seo_title>');
$seo_title_to = array($seo_title_separator,$c_title,$cat_name,$seo_cat_path,$reg_name,$seo_reg_path,$cat_seo_title,$reg_seo_title);
$seo_title = str_ireplace($seo_title_from, $seo_title_to, $par->get('seo_title_items', '<category_path>|<default_title>'));
$seo_title = trim($seo_title, $seo_title_separator);
if($seo_title){
$document->setTitle($seo_title);
}
if($par->get('seo_canonical_tags','1')){
$uri = JUri::getInstance();
$uri_vars = $uri->getQuery(true);
unset($uri_vars['order']);
unset($uri_vars['ord_t']);
if(!empty($main_cat)){
$canonical = DJClassifiedsSEO::getCategoryRoute($main_cat->id.':'.$main_cat->alias, true);
}elseif(!empty($main_reg)){
$canonical = DJClassifiedsSEO::getRegionRoute($main_reg->id.':'.$main_reg->alias, true);
}else{
$canonical = JRoute::_('index.php'); // DJClassifiedsSEO::getCategoryRoute('0:all');
}
if(!empty($uri_vars)){
$canonical .= '&'.$uri->buildQuery($uri_vars);
}
$canonical = JRoute::_($canonical, true, (JUri::getInstance()->isSSL() ? 1 : -1));
$this->document->addHeadLink($canonical, 'canonical');
}
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',false), 'alternate', 'rel', $attribs);
$attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
$document->addHeadLink(JRoute::_($link.'&type=atom',false), 'alternate', 'rel', $attribs);
}
DJClassifiedsTheme::includeCSSfiles($cat_theme);
if($uid){
$this->u_name = $model->getAuthorName($uid, $par);
}
$this->cats = $cats;
$this->cat_path = $cat_path;
$this->cat_images = $cat_images;
$this->main_cat = $main_cat;
$this->main_reg = $main_reg;
$this->dispatcher = new DJClassifiedsDispatcher(); // backward compatibility
$this->theme = $theme;
$this->par = $par;
$this->countitems = '';
$this->is_main_cat = ($main_cat && $main_cat->id == $cid_menu) || $app->input->getInt('cid') == 0 ? true : false;
$this->anch = $par->get('showitem_jump',0) ? '#dj-classifieds' : '';
$this->cat_anch = $par->get('category_jump',0) ? '#dj-classifieds' : '';
DJClassifiedsSEO::setSiteNameInPageTitle();
$this->page_heading = DJClassifiedsSEO::getPageHeading($par);
/* load with ajax */
if($par->get('items_ajax_load','0') == '1' && !$app->input->get('ajaxload')){
parent::display('cat');
$this->setLayout('ajaxload');
parent::display($tpl);
return;
}
/* items processing */
$items = $model->getItems($catlist);
$countitems = $model->getCountItems();
$limit = $app->input->getVar('limit', $par->get('limit_djitem_show','7'));
$limitstart = $app->input->getVar('limitstart');
$pagination = new JPagination($countitems, $limitstart, $limit);
/* document prepare part 2 */
$this->first_page = true;
if($pagination->total > 0 && $pagination->total > $pagination->limit){
$pages_total = ceil($pagination->total / $pagination->limit);
$page_no = ceil(($pagination->limitstart + 1) / $pagination->limit);
$previous_page = ($page_no > 1) ? (($page_no - 2) * $pagination->limit) : false;
$next_page = ($page_no < $pages_total) ? ($page_no * $pagination->limit) : false;
if($previous_page !== false){
$document->addHeadLink(str_replace("?start=0", "", JRoute::_('&limitstart='.(int)$previous_page)), 'prev', 'rel');
if($document->getTitle()){
$document->setTitle($document->getTitle().$seo_title_separator.JText::sprintf('COM_DJCLASSIFIEDS_META_ITEMS_PAGE_N', $page_no));
}
if($document->getDescription()){
$document->setDescription($document->getDescription().$seo_title_separator.JText::sprintf('COM_DJCLASSIFIEDS_META_ITEMS_PAGE_N', $page_no));
}
$this->first_page = false;
}
if($next_page !== false){
$document->addHeadLink(JRoute::_('&limitstart='.(int)$next_page), 'next', 'rel');
}
}
if($par->get('seo_empty_cats_noindex','1') && !$countitems){
$document->setMetaData('robots','NOINDEX, NOFOLLOW');
}
if($par->get('show_types','0')){ // view backward compatibility
$this->types = DJClassifiedsType::getTypes();
}
/* plugins */
if(JPluginHelper::isEnabled('system', 'wbamp') && plgSystemWbamp::isAmpPage()){
$event_view = 'items.amp';
}else if($warning18 && !isset($_COOKIE["djcf_warning18"])){
$event_view = 'items.terms';
}else if($layout=='blog'){
$event_view = 'items.blog';
}else{
$event_view = 'items.table';
}
$app->triggerEvent('onPrepareDJClassifiedsItems', array(&$par, &$items, &$countitems));
foreach($items as $item){
$temp_par = clone $par;
$app->triggerEvent('onDJClassifiedsPrepareItem', array(&$item, &$temp_par, 'items'));
$item->auction = $item->auction && $temp_par->get('auctions') ? '1' : '0';
$item->buynow = $item->buynow && $temp_par->get('buynow') ? '1' : '0';
$item->type_id = $item->type_id && $temp_par->get('show_types') ? $item->type_id : '0';
$app->triggerEvent('onPrepareItemDescription', array(&$item, &$par, 'items'));
$item->event = new stdClass();
$item->event->afterDJClassifiedsDisplayTitle = trim(implode("\n", $app->triggerEvent('onAfterDJClassifiedsDisplayTitle', array (&$item, &$par, $event_view))));
$item->event->beforeDJClassifiedsDisplayContent = trim(implode("\n", $app->triggerEvent('onBeforeDJClassifiedsDisplayContent', array (&$item, &$par, $event_view))));
$item->event->afterDJClassifiedsDisplayContent = trim(implode("\n", $app->triggerEvent('onAfterDJClassifiedsDisplayContent', array (&$item, &$par, $event_view))));
$item->event->DJClassifiedsDisplayCategory = trim(implode("\n", $app->triggerEvent('onDJClassifiedsDisplayCategory', array (&$item, &$par, $event_view))));
$item->event->DJClassifiedsDisplayRegion = trim(implode("\n", $app->triggerEvent('onDJClassifiedsDisplayRegion', array (&$item, &$par, $event_view))));
if($item->c_restr_18){
$warning18 = true;
}
}
$this->items = $items;
$this->countitems = $countitems;
$this->pagination = $pagination;
$this->custom_fields = $model->getListCustomFields(); // view backward compatibility
$this->sort_fields = DJClassifiedsField::getSortFields($cat_id);
if(JPluginHelper::isEnabled('system', 'wbamp') && plgSystemWbamp::isAmpPage()){
$this->setLayout('amp');
parent::display($tpl);
}elseif($warning18 && !isset($_COOKIE["djcf_warning18"])){
$this->terms_link = $par->get('restriction_18_art_id', 0) ? $model->getTermsLink($par->get('restriction_18_art_id',0), $par->get('restriction_18_art',0)==2) : '';
parent::display('terms');
}else{
if(!$tpl && $layout!='blog'){
$itemid = $app->input->getVar('Itemid');
$menu_tpl = -1;
if($itemid){
$menu = $app->getMenu('site');
$menu_item = $menu->getItem($itemid);
if($menu_item){
$menu_tpl = $menu_item->getParams()->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','');
}
}
$jview = $this;
$app->triggerEvent('onDJClassifiedsAfterPrepareItemsList', array(&$tpl, &$jview));
if(JPluginHelper::isEnabled('system', 'djclassifiedsyt')){
ob_start();
parent::display('cat');
$output = ob_get_contents();
ob_end_clean();
echo $output;
if(strpos($output, ' Builder #template-') !== false){
return;
}
}else{
parent::display('cat');
}
parent::display($tpl);
}
}
}