| Current Path : /var/www/html/components/com_jvld/ |
| Current File : /var/www/html/components/com_jvld/komento_plugin.php |
<?php
/**
* @version $Id$
* @package JV-LinkDirectory
* @subpackage com_jvld
* @copyright Copyright 2008-2013 JV-Extensions. All rights reserved
* @license GNU General Public License version 3 or later
* @author JV-Extensions
* @link http://www.jv-extensions.com
*/
// No direct access
defined('_JEXEC') or die('Restricted access');
require_once(JPATH_ROOT.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_komento'.DIRECTORY_SEPARATOR.'komento_plugins'.DIRECTORY_SEPARATOR.'abstract.php');
class KomentoComJvld extends KomentoExtension
{
// This property (object) stores all the required properties by Komento. (Refer to "load" method in Class methods)
public $_item;
/*
* This property (array) stores all the key mappings of the required item properties to map from Komento's default key to your component's custom key.
* List of required properties are listed below
*/
public $_map = array(
'id' => 'id',
'title' => 'partner_title',
'hits' => 'num_views',
'created_by' => 'uid',
'catid' => 'cid',
'permalink' => 'permalink'
);
/**
* If your component need to load extra files, do it here by calling $this->addFile( 'your_file' ).
*
* @param unknown $component
*/
public function __construct($component)
{
// Load all required files by component
//$this->addFile( 'COM_SAMPLE_DEPENDENCIES' );
parent::__construct($component);
}
/**
* This method should load the article's main property. Required properties by Komento consists of 6 items:
* Article Id
* Article Title
* Article Category Id
* Article Permalink
* Article Hits
* Article Author
* The article's property can have it's own key. All you need to do is just map it back with the _map properties.
*
* @param unknown $cid
*
* @return KomentoComJvld
*/
public function load($cid)
{
static $instances = array();
if (!$cid)
{
return false;
}
if (!isset($instances[$cid]))
{
$row = JvldDb::getRow("select L.id as id, L.partner_title as partner_title, L.num_views as num_views, L.uid as uid, CL.cid as cid from #__jvld_links as L, #__jvld_catlinks as CL where L.id = CL.lid and CL.isprimary = 1 and L.link_status = " . _JVLD_LINKSTATUS_ESTABLISHED . " and L.id = " . (int) $cid);
if (!$row)
{
return $this->onLoadArticleError($cid);
}
$link = JvldPostinit::getRoute('detailpageurl', $cid, 0);
$row->permalink = $this->prepareLink($link);
$this->_item = $row;
$instances[$cid] = $this->_item;
}
$this->_item = $instances[$cid];
return $this;
}
/**
* This method should load all the article ids filtered by category ids
*
* @param string $categories
*
* @return Ambigous <multitype:, mixed, NULL, multitype:unknown mixed >|multitype:
*/
public function getContentIds($categories = '')
{
if (empty($categories))
{
// without category filters
// return all valid article ids
return JvldDb::getRows("select id from #__jvld_links order by id");
}
else
{
if (is_array($categories))
{
$categories = implode(',', \Joomla\Utilities\ArrayHelper::toInteger($categories));
}
// with category filters
// return article ids in that category
return JvldDb::getRows("select distinct L.id from #__jvld_links as L, #__jvld_catlinks as CL where L.id = CL.lid and CL.cid in (" . $categories . ") order by id");
}
}
/**
* This method should load all the category ids of the component
* @return Ambigous <multitype:, mixed, NULL, multitype:unknown mixed >
*/
public function getCategories()
{
$items = JvldDb::getRows("select id, title, level from #__categories where extension = 'com_jvld' and published = 1 order by lft");
foreach ($items as $item)
{
$repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0;
$item->title = str_repeat('. ', 3 * $repeat) . ' |_ ' . $item->title;
}
return $items;
}
/**
* This method lets Komento know if this is the front page or category layout. Useful when you just want Komento to output the comment / hit count.
* @return boolean
*/
public function isListingView()
{
return false;
}
/**
* This method lets Komento know if this is the page that the comment form should be displayed on.
* @return boolean
*/
public function isEntryView()
{
return JFactory::getApplication()->input->getCmd('view') == 'detail';
}
public function getContext()
{
return false;
}
/**
* This method is the main method that appends Komento on the article.
*
* @param unknown $article
* @param unknown $html
* @param unknown $view
* @param unknown $options
*
* @return unknown
*/
public function onExecute(&$article, $html, $view, $options = array())
{
// $html is the html content generated by Komento
$model = Komento::getModel('comments');
$cnt = $model->getCount($this->component, $this->getContentId());
$article->numOfComments = $cnt;
return $html;
}
public function getComponentIcon()
{
return '../media/com_jvld/assets/images/com_jvld.png';
}
public function getComponentName()
{
return 'JV-LinkDirectory';
}
public function onAfterSaveComment($comment)
{
if ($comment->component != 'com_jvld')
{
return;
}
JvldLog::log("Komento onaftersavecomment: <pre>" . print_r($comment, true) . "</pre>");
JvldLog::log("Komento: onAfterSaveComment");
$this->onAfterPublishComment($comment);
}
public function onAfterDeleteComment($comment)
{
if ($comment->component != 'com_jvld')
{
return;
}
JvldLog::log("Komento: onAfterDeleteComment");
$this->onAfterUnpublishComment($comment);
}
public function onAfterPublishComment($comment)
{
if ($comment->component != 'com_jvld')
{
return;
}
JvldLog::log("Komento: onAfterPublishComment");
$robj = JvldRatings::getInstance('komento');
$robj->addVote($comment->cid, $comment->ratings / 2, true);
}
public function onAfterUnpublishComment($comment)
{
if ($comment->component != 'com_jvld')
{
return;
}
JvldLog::log("Komento: onAfterUnpublishComment");
$robj = JvldRatings::getInstance('komento');
$robj->removeVote($comment->cid, $comment->ratings / 2);
}
}