Your IP : 216.73.216.54


Current Path : /var/www/html/plugins/jvextensions/jvldalphauserpoints/
Upload File :
Current File : /var/www/html/plugins/jvextensions/jvldalphauserpoints/jvldalphauserpoints.php

<?php
/**
* @version		$Id$
* @package		JV-LinkDirectory
* @subpackage	com_jvld
* @copyright	Copyright 2015 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');

class plgJvextensionsJvldalphauserpoints extends JPlugin
{
	private $cfg = null;
	private $process = 0;

    function __construct(&$subject, $params)
    {
        parent::__construct($subject, $params);

        if (!defined('_JVLD_INSTALLED'))
        	return;

        JvldPostinit::loadLanguageFile();

        if (!JFile::exists(JPATH_ROOT.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_alphauserpoints'.DIRECTORY_SEPARATOR.'helper.php'))
        	return;

       	require_once(JPATH_ROOT.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_alphauserpoints'.DIRECTORY_SEPARATOR.'helper.php');

        $this->cfg = JvldCfg::getInstance();
        $this->process = 1;
    }

    public function OnLinkPublish($lid)
    {
        if (!$this->process)
        	return;

        try
        {
        	JvldLog::log("Alpha Userpoints Plugin: OnLinkPublish Started: ".print_r($lid, true));

			$link = JvldDb::getRow("select uid from #__jvld_links where id = ".(int)$lid);
        	if (!$link)
        		throw new Exception('Invalid link');

        	if ($this->cfg->get('aup_addlink_reward'))
        		$this->assignPoints('plgaup_jvld_link_add', $link->uid);
        }
        catch (Exception $ex)
        {
        	JvldLog::log("Error in OnLinkPublish: ".$ex->getMessage());
        }

        return;
    }

    public function OnNewLinkReviewPublish($revid)
    {
        if (!$this->process)
        	return;

        try
        {
        	JvldLog::log("Alpha Userpoints Plugin: OnNewLinkReviewPublish Started: ".print_r($revid, true));

            $revobj = JvldDb::getRow("select * from #__jvld_linkreviews where id = '".(int)$revid."'");
            if (!$revobj)
            	throw new Exception('Invalid review id');

            $link = JvldPostinit::getLinkInformation((int)$revobj->lid);
            if (!$link)
            	throw new Exception('Invalid link');

            if ($this->cfg->get('aup_addrev_reward'))
            	$this->assignPoints('plgaup_jvld_review_add', $revobj->revbyid);
        }
    	catch (Exception $ex)
        {
        	JvldLog::log("Error in OnNewLinkReviewPublish: ".$ex->getMessage());
        }

        return;
    }

    public function OnNewSiteRecommend($url, $reason)
    {
        if (!$this->process)
        	return;

        try
        {
        	JvldLog::log("Alpha Userpoints Plugin: OnNewSiteRecommend Started: ".print_r($url, true)."<>".print_r($reason, true));

            if ($this->cfg->get('aup_recsite_reward'))
            	$this->assignPoints('plgaup_jvld_recommend_site');
        }
    	catch (Exception $ex)
        {
        	JvldLog::log("Error in OnNewSiteRecommend: ".$ex->getMessage());
        }

        return;
    }

    public function OnAddBookmark($lid)
    {
        if (!$this->process)
        	return;

        try
        {
        	JvldLog::log("Alpha Userpoints Plugin: OnAddBookmark Started: ".print_r($lid, true));

        	$link = JvldPostinit::getLinkInformation((int)$lid);
        	if (!$link)
        		throw new Exception('Invalid link');

            $target = ($link->uid) ? $link->uid : 0;

            if ($this->cfg->get('aup_addbmark_reward'))
            	$this->assignPoints('plgaup_jvld_bookmark_add', $target);
        }
		catch (Exception $ex)
        {
        	JvldLog::log("Error in OnAddBookmark: ".$ex->getMessage());
        }

        return;
    }

    public function OnRatingLink($lid, $rating)
    {
    	if (!$this->process)
    		return;

    	try
    	{
    		JvldLog::log("Alpha Userpoints Plugin: OnRatingLink Started: ".print_r($lid, true));

    		$link = JvldPostinit::getLinkInformation((int)$lid);
    		if (!$link)
    			throw new Exception('Invalid link');

    		if ($this->cfg->get('aup_ratelink_reward'))
    			$this->assignPoints('plgaup_jvld_link_rate');
    	}
        catch (Exception $ex)
        {
        	JvldLog::log("Error in OnRatingLink: ".$ex->getMessage());
        }

    	return;
    }

    public function OnCategorySuggest($catname, $catdesc)
    {
    	if (!$this->process)
    		return;

    	try
    	{
    		JvldLog::log("Alpha Userpoints Plugin: OnCategorySuggest Started: ".print_r($catname, true));

    		if ($this->cfg->get('aup_sugcat_reward'))
    			$this->assignPoints('plgaup_jvld_category_suggest');
    	}
    	catch (Exception $ex)
    	{
    		JvldLog::log("Error in OnCategorySuggest: ".$ex->getMessage());
    	}

    	return;
    }

    public function OnLikeLink($lid)
    {
    	if (!$this->process)
    		return;

    	try
    	{
    		JvldLog::log("Alpha Userpoints Plugin: OnLikeLink Started: ".print_r($lid, true));

    		$link = JvldPostinit::getLinkInformation((int)$lid);
    		if (!$link)
    			throw new Exception('Invalid link');

    		if ($this->cfg->get('aup_likelink_reward'))
    			$this->assignPoints('plgaup_jvld_link_like');
    	}
    	catch (Exception $ex)
    	{
    		JvldLog::log("Error in OnLikeLink: ".$ex->getMessage());
    	}

    	return;
    }

    public function OnReportBrokenLink($lid)
    {
    	if (!$this->process)
    		return;

    	try
    	{
    		JvldLog::log("Alpha Userpoints Plugin: OnReportBrokenLink Started: ".print_r($lid, true));

    		$link = JvldPostinit::getLinkInformation((int)$lid);
    		if (!$link)
    			throw new Exception('Invalid link');

    		if ($this->cfg->get('aup_rblink_reward'))
    			$this->assignPoints('plgaup_jvld_link_report_broken');
    	}
    	catch (Exception $ex)
    	{
    		JvldLog::log("Error in OnReportBrokenLink: ".$ex->getMessage());
    	}

    	return;
    }

    public function OnNewLinkProfile($lid, $id)
    {
    	if (!$this->process)
    		return;

    	try
    	{
    		JvldLog::log("Alpha Userpoints Plugin: OnNewLinkProfile Started: ".print_r($lid, true));

    		$link = JvldPostinit::getLinkInformation((int)$lid);
    		if (!$link)
    			throw new Exception('Invalid link');

    		if ($this->cfg->get('aup_addprof_reward'))
    			$this->assignPoints('plgaup_jvld_profile_add');
    	}
    	catch (Exception $ex)
    	{
    		JvldLog::log("Error in OnNewLinkProfile: ".$ex->getMessage());
    	}

    	return;
    }

    public function OnNewPhotoUpload($lid, $imgurl, $imgtitle)
    {
    	if (!$this->process)
    		return;

    	try
    	{
    		JvldLog::log("Alpha Userpoints Plugin: OnNewPhotoUpload Started: ".print_r($lid, true));

    		$link = JvldPostinit::getLinkInformation((int)$lid);
    		if (!$link)
    			throw new Exception('Invalid link');

    		if ($this->cfg->get('aup_addphoto_reward'))
    			$this->assignPoints('plgaup_jvld_photo_add');
    	}
    	catch (Exception $ex)
    	{
    		JvldLog::log("Error in OnNewPhotoUpload: ".$ex->getMessage());
    	}

    	return;
    }

    public function OnNewVideoUpload($lid, $id)
    {
    	if (!$this->process)
    		return;

    	try
    	{
    		JvldLog::log("Alpha Userpoints Plugin: OnNewVideoUpload Started: ".print_r($lid, true));

    		$link = JvldPostinit::getLinkInformation((int)$lid);
    		if (!$link)
    			throw new Exception('Invalid link');

    		if ($this->cfg->get('aup_addvideo_reward'))
    			$this->assignPoints('plgaup_jvld_video_add');
    	}
    	catch (Exception $ex)
    	{
    		JvldLog::log("Error in OnNewVideoUpload: ".$ex->getMessage());
    	}

    	return;
    }

	public function OnNewCouponUpload($lid, $id)
	{
		if (!$this->process)
			return;

		try
		{
			JvldLog::log("Alpha Userpoints Plugin: OnNewCouponUpload Started: ".print_r($lid, true));

			$link = JvldPostinit::getLinkInformation((int)$lid);
			if (!$link)
				throw new Exception('Invalid link');

			if ($this->cfg->get('aup_addcoupon_reward'))
				$this->assignPoints('plgaup_jvld_coupon_add');
		}
		catch (Exception $ex)
		{
			JvldLog::log("Error in OnNewCouponUpload: ".$ex->getMessage());
		}

		return;
	}

    public function OnCategorySponsor($cid)
    {
    	if (!$this->process)
    		return;

    	try
    	{
    		JvldLog::log("Alpha Userpoints Plugin: OnCategorySponsor Started: ".print_r($cid, true));

    		if ($this->cfg->get('aup_catsponsor_reward'))
    			$this->assignPoints('plgaup_jvld_category_sponsor');
    	}
    	catch (Exception $ex)
    	{
    		JvldLog::log("Error in OnCategorySponsor: ".$ex->getMessage());
    	}

    	return;
    }

    public function OnSetFeaturedLink($lid)
    {
    	if (!$this->process)
    		return;

    	try
    	{
    		JvldLog::log("Alpha Userpoints Plugin: OnSetFeaturedLink Started: ".print_r($lid, true));

    		$link = JvldPostinit::getLinkInformation((int)$lid);
    		if (!$link)
    			throw new Exception('Invalid link');

    		if ($this->cfg->get('aup_setf_reward'))
    			$this->assignPoints('plgaup_jvld_link_set_featured');
    	}
    	catch (Exception $ex)
    	{
    		JvldLog::log("Error in OnLinkSetFeatured: ".$ex->getMessage());
    	}

    	return;
    }

	public function OnPinLink($lid)
	{
		if (!$this->process)
			return;

		try
		{
			JvldLog::log("Alpha Userpoints Plugin: OnPinLink Started: ".print_r($lid, true));

			$link = JvldPostinit::getLinkInformation((int)$lid);
			if (!$link)
				throw new Exception('Invalid link');

			if ($this->cfg->get('aup_pinl_reward'))
				$this->assignPoints('plgaup_jvld_link_pin');
		}
		catch (Exception $ex)
		{
			JvldLog::log("Error in OnPinLink: ".$ex->getMessage());
		}

		return;
	}

    public function OnLecsAcceptInvite($lid)
    {
        return;
    }

    public function OnNewFileUpload($fid)
    {
        if (!$this->process)
        	return;

        try
        {
        	JvldLog::log("Alpha Userpoints Plugin: OnNewFileUpload Started: ".print_r($fid, true));

            $file = JvldDb::getRow("select * from #__jvld_files where id = '".(int)$fid."'");
            if (!$file)
            	throw new Exception('Invalid file id');

            $link = JvldPostinit::getLinkInformation((int)$file->lid);
            if (!$link)
            	throw new Exception('Invalid link');

            if ($this->cfg->get('aup_addfile_reward'))
            	$this->assignPoints('plgaup_jvld_link_file_add');
        }
    	catch (Exception $ex)
        {
        	JvldLog::log("Error in OnNewFileUpload: ".$ex->getMessage());
        }

        return;
    }

    private function assignPoints($function, $target=0)
    {
    	if (!$target)
    		AlphaUserPointsHelper::newpoints($function); // currently logged in user
    	else
    		AlphaUserPointsHelper::newpoints($function, AlphaUserPointsHelper::getAnyUserReferreID($target));

    	JvldLog::log("Alpha Userpoints Plugin: Points added");
    }
}