Your IP : 216.73.216.54


Current Path : /var/www/html/components/com_jvld/
Upload File :
Current File : /var/www/html/components/com_jvld/controller.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');

jimport('joomla.application.component.controller');

class JvldController extends JControllerLegacy
{
    public function display($cachable = false, $urlparams = array())
    {
    	$input = JFactory::getApplication()->input;

    	$view = $input->getCmd('view', '');
	    JvldLog::log("view: ".$view);

    	switch ($view)
    	{
    		case 'jvld':
		    case 'links':
    		case 'detail':
    		{
			    // Joomla conservative or progressive caching must be enabled for this to take effect. It must also be a guest user
			    if ((JvldCfg::getInstance()->get('en_cache')) && (JFactory::getUser()->get('id') == 0))
			    {
				    $cachable = true;
				    JvldLog::log("JV-LD view cache is enabled and it is a guest user");

				    $urlparams = array('cid' => 'INT', 'lid' => 'INT', 'limitstart' => 'UINT', 'limit' => 'UINT');

				    if ($view == 'detail')
				    {
				    	// update the number of views
					    $u_lalevels = JFactory::getUser()->getAuthorisedViewLevels();
					    $lid = $input->getInt('lid', 0);
					    $linkobj = new JvldLinkinfo($lid);
					    $catobj = new JvldCategoryinfo($linkobj->getPrimaryCategory());

					    if (
					    	($linkobj->isValid()) &&
						    ($linkobj->getInfo('link_status') == _JVLD_LINKSTATUS_ESTABLISHED) &&
						    (in_array($catobj->getInfo('access'), $u_lalevels)) &&
						    (in_array($linkobj->getInfo('access'), $u_lalevels)) &&
						    ((_JVLD_COUNT_VIEWS_FROM_SE) || (!JvldInit::isCrawler()))
					    )
					    {
						    JvldDb::update("update #__jvld_links set `num_views` = 1 + `num_views` where id = ".(int)$lid);
					    }
				    }
			    }
			    else
			    {
				    $cachable = false;
				    JvldLog::log("JV-LD view cache is disabled or user is logged in");
			    }
    			break;
    		}
    		default:
    		{
    			break;
    		}
    	}

    	return parent::display($cachable, $urlparams);
    }

    function validateUser()
    {
    	if (!JvldCfg::getInstance()->get('mylinks_en'))
    	{
    		JvldMsg::display(JText::_("COM_JVLD_ERR_INVALID_REQ"));
    		return 0;
    	}

    	if (!JFactory::getUser()->get('id'))
    	{
    		JvldMsg::display(JText::_("COM_JVLD_ERR_LOGIN"));
    		return 0;
    	}

    	return 1;
    }

    function xaddlink()
    {
    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Addlink');
		$model->process();

    	return;
    }

    function xcsponsor()
    {
    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Csponsor');
		$model->process();

    	return;
    }

    function xadvertise()
    {
    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Advertise');
    	$model->process();

    	return;
    }

    function xeditlink()
    {
		if (!$this->validateUser())
			return;

    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Editlink');
		$model->process();

    	return;
    }

    function xeditprofile()
    {
		if (!$this->validateUser())
			return;

    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Editprofile');
		$model->process();

    	return;
    }

    function xeditvideo()
    {
		if (!$this->validateUser())
			return;

    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Editvideo');
		$model->process();

    	return;
    }

	function xeditcoupon()
	{
		if (!$this->validateUser())
			return;

		JvldSecure::defendCSRF();

		$model = $this->getModel('Editcoupon');
		$model->process();

		return;
	}

    function xeditphoto()
    {
    	if (!$this->validateUser())
    		return;

    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Editphoto');
    	$model->process();

    	return;
    }

    function xeditfile()
    {
    	if (!$this->validateUser())
    		return;

    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Editfile');
    	$model->process();

    	return;
    }

    function xeditmyprofile()
    {
    	if (!$this->validateUser())
    		return;

    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Editmyprofile');
    	$model->process();

    	return;
    }

    function xaddbookmark()
    {
    	if (!JvldCfg::getInstance()->get('bookmark_en'))
    	{
    		JvldMsg::display(JText::_("COM_JVLD_FEATURED_DISABLED"));
    		return;
    	}

    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Addbookmark');
    	$model->process();

    	return;
    }

    function xrecommend()
    {
    	if (!JvldCfg::getInstance()->get('recawebsite_en'))
    	{
    		JvldMsg::display(JText::_("COM_JVLD_ERR_INVALID_REQ"));
    		return;
    	}

    	if (!JvldPostinit::isComponentActionAllowed('core.recommend'))
    	{
    		JvldMsg::display(JText::_('COM_JVLD_UNAUTHORIZED'));
    		return;
    	}

    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Recommend');
    	$model->process();

    	return;
    }

    function xsuggestcat()
    {
    	if (!JvldCfg::getInstance()->get('suggestcat_en'))
    	{
    		JvldMsg::display(JText::_("COM_JVLD_ERR_INVALID_REQ"));
    		return;
    	}

    	if (!JvldPostinit::isComponentActionAllowed('core.suggestcat'))
    	{
    		JvldMsg::display(JText::_('COM_JVLD_UNAUTHORIZED'));
    		return;
    	}

    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Suggestcat');
    	$model->process();

    	return;
    }

    function xtellafriend()
    {
    	if (!JvldCfg::getInstance()->get('tellafriend_en'))
    	{
    		JvldMsg::display(JText::_("COM_JVLD_ERR_INVALID_REQ"));
    		return;
    	}

    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Tellafriend');
    	$model->process();

    	return;
    }

    function xcontactowner()
    {
	    if (!JvldCfg::getInstance()->get('clowner_en'))
	    {
    		JvldMsg::display(JText::_("COM_JVLD_ERR_INVALID_REQ"));
    		return;
    	}

    	JvldSecure::defendCSRF();

    	$model = $this->getModel('Contact');
    	$model->process();

    	return;
    }

    function xreportbrokenlink()
    {
    	if (!JvldCfg::getInstance()->get('report_broken_link'))
    	{
	    	JvldMsg::display(JText::_("COM_JVLD_ERR_INVALID_REQ"));
    		return;
    	}

    	if ((JvldCfg::getInstance()->get('report_broken_link') == 1) && (!JFactory::getUser()->get('id')))
   		{
   			JvldMsg::display(JText::_("COM_JVLD_ERR_LOGIN"));
   			return;
   		}

    	JvldSecure::defendCSRF();

        $model = $this->getModel('Reportbrokenlink');
        $model->process();

        return;
	}

	function delbookmark()
	{
		$model = $this->getModel();
		$model->deleteBookmark();

		return;
	}

	function validatepurchase()
	{
		$model = $this->getModel();
		$model->validateRefId();
	}

	function delprofile()
	{
		if (!$this->validateUser())
			return;

		$model = $this->getModel('Profiles');
		$model->deleteProfile();

		return;
	}

	function downloadfile()
	{
		$id = JFactory::getApplication()->input->getInt('id', 0);
		if (!$id)
			return;

		JvldFileManager::downloadFile($id);
		return;
	}

	function delvideo()
	{
		if (!$this->validateUser())
			return;

		$model = $this->getModel('Videos');
		$model->deleteVideo();

		return;
	}

	function delcoupon()
	{
		if (!$this->validateUser())
			return;

		$model = $this->getModel('Coupons');
		$model->deleteCoupon();

		return;
	}

	function delphoto()
	{
		if (!$this->validateUser())
			return;

		$model = $this->getModel('Photos');
		$model->deletePhoto();

		return;
	}

	function delfile()
	{
		if (!$this->validateUser())
			return;

		$model = $this->getModel('Files');
		$model->deleteFile();

		return;
	}

	function dellink()
	{
		if (!$this->validateUser())
			return;

		$model = $this->getModel('Links');
		$model->deleteLink();

		return;
	}

	function quicknav()
	{
		$op = "";
		$query = JFactory::getApplication()->input->getString('query');

		if ($query == "")
		{
			echo "";
			return;
		}

		// Get the list of category names, description with urls that has this query string in the category name in it
		$u_alevels = implode(',', JFactory::getUser()->getAuthorisedViewLevels());
		$rows = JvldDb::getRows("select id, title, path from #__categories where extension = 'com_jvld' and access in (".$u_alevels.") and title like '%".JvldSecure::defendSQL($query, 1)."%'");
		if (count($rows))
		{
			foreach ($rows as $row)
			{
				$url = JvldPostinit::getRoute('catpageurl', $row->id);
				$op .= $row->title."|".$url."|".JvldUtil::getCategoryPath($row->path)."~";
			}
		}
		else
		{
			$op .= JText::_("COM_JVLD_CATQUICKNAV_NOMATCH")."|javascript:void(0)|".JText::_("COM_JVLD_CATQUICKNAV_TRY_ANOTHER")."~";
		}

		echo $op;
	}

	function registerhit()
	{
		$id = JFactory::getApplication()->input->getInt('id', 0);
		if (!$id)
			return;

		$link = JvldDb::getRow("select out_hits, http_status, partner_url from #__jvld_links where id = ".(int)$id);
		if (!$link)
			return;

		$out_hits = 1 + $link->out_hits;
		JvldDb::update("update #__jvld_links set out_hits = '".(int)$out_hits."' where id = ".(int)$id);

		// send email to admin if it is broken link
		$cfg = JvldCfg::getInstance();
		if ($cfg->get('broken_link_notify_admin_of_visit') && JvldBrokenLinkChecker::isBrokenLink($link->http_status))
		{
			$catobj = new JvldCategoryinfo(JvldUtil::getLinkCategories($id, 'P'));
			$catname = $catobj->getInfo('title');

			$em = new JvldEmail('FNA_BROKEN_LINK_VISITED');
			$em->setTag('{PARTNER-URL}', $link->partner_url);
			$em->setTag('{PRIMARY-CATEGORY}', $catname);
			$em->setTag('{LID}', $id);
			$em->setTag('{VISITOR-IP}', JvldFrameworkHelper::getIpAddress());
			$em->send($cfg->get('site_email'));
		}

		return;
	}

	function emappr()
	{
		if (!JvldPostinit::isListingApproverOrAdmin())
		{
			JvldMsg::display(JText::_("COM_JVLD_UNAUTHORIZED").". ".JText::_("COM_JVLD_ERR_LOGIN"));
			return;
		}

		$emstr = JFactory::getApplication()->input->getString('emstr', '');
		$aprrej = JFactory::getApplication()->input->getInt('aprrej', '-1');

		if (($emstr == '') || ($aprrej == -1))
		{
			JvldMsg::display(JText::_("COM_JVLD_ERR_INVALID_REQ"));
			return;
		}

		$model = $this->getModel();
		$model->actionByEmail();

		return;
	}

	function cron()
	{
		$model = $this->getModel();
		$model->executeCronJobs();
		return;
	}

	function visit()
	{
		$model = $this->getModel();
		$model->redirectLink();

		return;
	}

	function lecs()
	{
	    $model = $this->getModel();
	    $model->redirectToXchangeUrl();

	    return;
	}

	function execsvc()
	{
	    $model = $this->getModel();
	    $model->executePaidService();

	    return;
	}

	function resubmit()
	{
		$model = $this->getModel();
		$model->resubmitListing();

		return;
	}
}