Code:
<?php
/**
* @package Joomla.Plugin
* @subpackage System.SpendPoints_ToRead
* @copyright Copyright (C) 2010 - 2016 Nordmograph.com/extensions. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
class PlgSystemSpendpoints_Toread extends JPlugin
{
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
$this->loadLanguage();
}
public function onBeforeRender()
{
if (JFactory::getApplication()->isAdmin())
return true;
$pointsys = $this->params->get('pointsys','aup');
$contentsys = $this->params->get('contentsys','com_content');
$excludecatids = $this->params->get('excludecatids');
$onlycatids = $this->params->get('onlycatids');
$banned_cats = explode(',',$excludecatids);
$prefered_cats = explode(',',$onlycatids);
$jusergroups = $this->params->get('jusergroups');
$pointsperpage = $this->params->get('pointsperpage','1');
$nopoints_url = $this->params->get('nopoints_url','index.php');
$app = JFactory::getApplication();
$jinput = $app->input;
$option = $jinput->getCmd('option');
$view = $jinput->getCmd('view');
$id_index = 'id';
if($contentsys =='com_content')
$view_index= 'article';
elseif($contentsys =='com_easyblog')
$view_index= 'entry';
elseif($contentsys =='com_k2')
$view_index= 'item';
$id = $jinput->getInt( $id_index );
if($option != $contentsys || $view != $view_index || $id=='')
return true;
$db = JFactory::getDBO();
$q = "SELECT title, catid, created_by FROM #__k2_items
WHERE id='".$id."' ";
$db->setQuery($q);
$article = $db->loadObject();
if($excludecatids!='' && in_array( $article->catid , $banned_cats) )
return true;
if($onlycatids!='' && !in_array( $article->catid , $prefered_cats) )
return true;
PlgSystemSpendpoints_Toread::RewardAuthor(
$pointsperpage,
$contentsys,
$view,
$id_index,
$id,
$article->title,
$article->created_by);
}
static function RewardAuthor($pointsperpage,$contentsys,$view,$id_index,$id,$article_title, $author)
{
$app = JFactory::getApplication();
$user = JFactory::getUser();
$uri = JFactory::getURI();
$contenturl = $uri->toString();
$api_AUP = JPATH_SITE.'/components/com_altauserpoints/helper.php';
if ( file_exists($api_AUP))
{
require_once $api_AUP;
AltaUserPointsHelper::newpoints(
'plgaup_spendpoints_toread' ,
AltaUserPointsHelper::getAnyUserReferreID( $author ),
'' , //$contentsys.'-'.$id
sprintf( JText::_('PLG_SPTR_READPAGEID'), $contenturl, $article_title) ,
$pointsperpage
);
}
}
}