Current File : /home/pacjaorg/public_html/kmm/components/com_djclassifieds/komento_plugin.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');
require_once(JPATH_ROOT.'/administrator/components/com_djclassifieds/lib/djseo.php');
class KomentoComDjclassifieds extends KomentoExtension
{
public $_item;
public $_map = array(
'id' => 'id',
'title' => 'name',
'hits' => 'hits',
'created_by' => 'user_id',
'catid' => 'cat_id',
'state' => 'published'
);
private $_currentTrigger = '';
public function __construct( $component )
{
//$this->addFile( JPATH_ROOT .'administrator'. DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_djclassifieds' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR .'djseo.php' );
parent::__construct( $component );
}
public function load( $cid )
{
static $instances = array();
if( !isset( $instances[$cid] ) )
{
$db = Komento::getDBO();
$query = 'SELECT a.*, c.alias AS category_alias'
. ' FROM ' . $db->nameQuote( '#__djcf_items' ) . ' AS a'
. ' LEFT JOIN ' . $db->nameQuote( '#__djcf_categories') . ' AS c ON c.id = a.cat_id'
. ' WHERE a.id' . '=' . $db->quote($cid);
$db->setQuery( $query );
if( !$this->_item = $db->loadObject() )
{
return $this->onLoadArticleError( $cid );
}
$instances[$cid] = $this->_item;
}
$this->_item = $instances[$cid];
return $this;
}
public function getContentIds( $categories = '' )
{
$db = Komento::getDBO();
$query = '';
if( empty( $categories ) )
{
$query = 'SELECT `id` FROM ' . $db->nameQuote( '#__djcf_items' ) . ' ORDER BY `id`';
}
else
{
if( is_array( $categories ) )
{
$categories = implode( ',', $categories );
}
$query = 'SELECT DISTINCT `id` FROM ' . $db->nameQuote( '#__djcf_items' ) . ' WHERE `cat_id` IN (' . $categories . ') ORDER BY `id`';
}
$db->setQuery( $query );
return $db->loadResultArray();
}
public function getCategories()
{
$db = Komento::getDBO();
$query = 'SELECT a.id, a.name AS title, a.parent_id, a.name, a.parent_id as parent'
. ' FROM `#__djcf_categories` AS a'
. ' WHERE a.published = 1'
. ' ORDER BY a.ordering';
$db->setQuery( $query );
$categories = $db->loadObjectList();
$children = array();
foreach ($categories as $row)
{
$pt = $row->parent_id;
$list = @$children[$pt] ? $children[$pt] : array();
$list[] = $row;
$children[$pt] = $list;
}
$categories = JHTML::_('menu.treerecurse', 0, '', array(), $children, 9999, 0, 0);
return $categories;
}
public function isListingView()
{
return false;
}
public function isEntryView()
{
return ( $this->_currentTrigger == 'onDJClassifiedsItem' ) ? true : false;
}
public function onExecute( &$article, $html, $view, $options = array() )
{
if( $options['trigger'] == 'onDJClassifiedsItem' )
{
$model = Komento::getModel( 'comments' );
$count = $model->getCount( $this->component, $this->getContentId() );
$article->numOfComments = $count;
return $html;
}
}
public function getEventTrigger()
{
return array( 'onDJClassifiedsItem');
}
public function getContext()
{
return array( 'com_djclassifieds.item');
}
public function getAuthorName()
{
return $this->_item->author ? $this->_item->author : null;
}
/*
public function getCommentAnchorId()
{
return '';
}*/
public function onBeforeLoad( $eventTrigger, $context, &$article, &$params, &$page, &$options )
{
if( !$params instanceof JRegistry )
{
return false;
}
$this->_currentTrigger = $eventTrigger;
return true;
}
public function onParameterDisabled( $eventTrigger, $context, &$article, &$params, &$page, &$options )
{
$params->set( 'comments', 0 );
return false;
}
public function getContentPermalink()
{
$link = DJClassifiedsSEO::getItemRoute($this->_item->id.':'.urlencode($this->_item->alias), $this->_item->cat_id.':'.urlencode($this->_item->category_alias));
if( JFactory::getApplication()->isClient('site') ){
$link = urldecode(JRoute::_($link,false));
}
$link = $this->prepareLink( $link );
return $link;
}
public function getComponentName() {
return 'DJ-Classifieds';
}
public function getComponentIcon() {
return JURI::root(true).'/'.DJClassifiedsTheme::getImgAssetPath('djcf_icon.png').'';
}
}