| Current Path : /var/www/html/components/com_jvld/models/ |
| Current File : /var/www/html/components/com_jvld/models/jvld.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.model');
class JvldModelJvld extends JModelLegacy
{
var $pop;
public function __construct(array $config = array())
{
$this->pop = JFactory::getApplication()->input->getInt('pop', 0);
parent::__construct($config);
}
function validateRefId()
{
$cfg = JvldCfg::getInstance();
$user = JFactory::getUser();
$input = JFactory::getApplication()->input;
if (!$user->get('id'))
{
JvldMsg::display(JText::_("COM_JVLD_ERR_LOGIN"));
return;
}
$refid = $input->getString('refid', '');
$pemail = $input->getString('pemail', '');
$itype = $input->getString('itemtype', '');
if (($refid == '') || ($pemail == '') || ($itype == ''))
{
JvldMsg::display(JText::_("COM_JVLD_ERR_INSUFFINFO"), _JVLD_NEXT_PAGE_GO_BACK);
return;
}
$row = JvldDb::getRow("select * from #__jvld_revenue where refid = '".JvldSecure::defendSQL($refid)."' and payer_email = '".JvldSecure::defendSQL($pemail)."' and service_name = '".JvldSecure::defendSQL($itype)."'");
if (!$row)
{
JvldMsg::display(JText::_("COM_JVLD_MYPURCHASES_NOMATCH"), _JVLD_NEXT_PAGE_GO_BACK);
return;
}
if (!$row->uid)
{
$custom = JvldInit::buildCustomArray($row->custom);
if (!$custom['uid'])
{
$custom['uid'] = $user->get('id');
JvldDb::update("update #__jvld_revenue set uid = '".(int)$user->get('id')."', custom = '".JvldSecure::defendSQL(JvldInit::buildCustomString($custom))."' where id = ".(int)$row->id);
}
JvldMsg::display(JText::_("COM_JVLD_MYPURCHASES_MATCHED_OK"), _JVLD_NEXT_PAGE_GO_TO_URL, JvldPostinit::getRoute('mypurchases'));
return;
}
else
{
if ($row->uid == $user->get('id'))
{
JvldMsg::display(JText::_("COM_JVLD_MYPURCHASES_MATCHED_ALREADY_INLIST"), _JVLD_NEXT_PAGE_GO_BACK);
return;
}
else
{
JvldMsg::display(JText::_("COM_JVLD_UNAUTHORIZED"));
return;
}
}
}
function deleteBookmark()
{
try
{
$bid = JFactory::getApplication()->input->getInt('bid', 0);
if (!$bid)
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
$cfg = JvldCfg::getInstance();
if (!$cfg->get('bookmark_en'))
throw new Exception(JText::_("COM_JVLD_FEATURED_DISABLED"));
$user = JFactory::getUser();
if (!$user->get('id'))
throw new Exception(JText::_("COM_JVLD_ERR_LOGIN"));
JvldDb::update("delete from `#__jvld_bookmarks` where `id` = '".(int)$bid."' and `bby` = '".(int)$user->get('id')."'");
JvldMsg::display(JText::_("COM_JVLD_DELBMARK_DONE"), _JVLD_NEXT_PAGE_CLOSE_WINDOW, '', 1);
return;
}
catch (Exception $ex)
{
JvldMsg::display($ex->getMessage(), _JVLD_NEXT_PAGE_GO_BACK, '', 1);
return;
}
}
function actionByEmail()
{
$emstr = JFactory::getApplication()->input->getString('emstr', '');
$aprrej = JFactory::getApplication()->input->getInt('aprrej', '-1');
$cfg = JvldCfg::getInstance();
try
{
if (($emstr == '') || ($aprrej == -1))
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
if (!$cfg->get('link_apprem'))
throw new Exception(JText::_("COM_JVLD_FEATURED_DISABLED"));
// Get link info for this emstr
$obj = JvldDb::getRow("select id from #__jvld_links where emstr = '".JvldSecure::defendSQL($emstr)."'");
if (!$obj)
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
$link = new JvldLinkinfo($obj->id);
if ($link->getInfo('link_status') != _JVLD_LINKSTATUS_WPENDING)
throw new Exception(JText::_("COM_JVLD_EMAPR_IMPROPER_STATE"));
if ($aprrej == 1)
{
// approved
$link->updateStatus(_JVLD_LINKSTATUS_ESTABLISHED);
JvldLog::log(__METHOD__." link status updated to active");
$partner_linkloc_url = JvldUtil::getPartnerLinkAtHome($link->getPrimaryCategory());
$partner_detail_url = JvldInit::getSEFUrlForXternal(JvldPostinit::getRoute('detailpageurl', $link->getInfo('id')));
$em = new JvldEmail('NP_LINK_APPROVAL');
$em->setTag('{PARTNER-URL}', JvldPostinit::getLinkUrlorTitleForDisplay($link->getInfo('partner_url'), $link->getInfo('partner_title')));
$em->setTag('{PARTNER-LINKLOC-AT-HOME}', $partner_linkloc_url);
$em->setTag('{PARTNER-DETAILPAGE-HOME}', $partner_detail_url);
$em->send($link->getInfo('partner_email'));
JvldLog::log(__METHOD__." email sent to partner");
$msg = JText::_("COM_JVLD_EMAPPR_APPROVAL_DONE");
// Event handler
JvldInit::triggerPlugins('OnLinkPublish', array($link->getInfo('id')));
JvldLog::log(__METHOD__." onlinkpublish events triggered");
}
else if ($aprrej == 0)
{
// reject reason
$reason = $cfg->get('link_reject_reason');
// rejected
$link->updateStatus(_JVLD_LINKSTATUS_PPENDING, $reason);
JvldLog::log(__METHOD__." link status updated to partner pending");
if ($reason != '')
{
$em = new JvldEmail('NP_LINK_REJECTION');
$em->setTag('{PARTNER-URL}', JvldPostinit::getLinkUrlorTitleForDisplay($link->getInfo('partner_url'), $link->getInfo('partner_title')));
$em->setTag('{REJECT-REASON}', strip_tags($reason));
$em->setTag('{MY-LISTINGS-URL}', JvldInit::getSEFUrlForXternal(JvldPostinit::getRoute('mylinks')));
$em->setTag('{CLAIMLINK-URL}', JvldInit::getSEFUrlForXternal(JvldPostinit::getRoute('claimlink', $link->getInfo('id'))));
$em->send($link->getInfo('partner_email'));
JvldLog::log(__METHOD__." email sent to partner");
}
$msg = JText::_("COM_JVLD_EMAPPR_REJECTION_DONE");
}
else if ($aprrej == 9)
{
// Change status
$link->updateStatus(_JVLD_LINKSTATUS_RECYCLED);
JvldLog::log(__METHOD__." link status updated to recycled");
$msg = JText::_("COM_JVLD_EMAPPR_DELETION_DONE");
}
else
{
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
}
JvldMsg::display($msg);
return;
}
catch (Exception $ex)
{
JvldMsg::display($ex->getMessage());
return;
}
}
function executeCronJobs()
{
try
{
$taskmgr = new JvldTaskManager();
$taskmgr->execute();
}
catch (Exception $ex)
{
JvldLog::log(__FUNCTION__.': '.$ex->getMessage());
}
}
function redirectLink()
{
try
{
$cfg = JvldCfg::getInstance();
if (!$cfg->get('hitstracking_en'))
throw new Exception(JText::_("COM_JVLD_FEATURED_DISABLED"));
$lid = JFactory::getApplication()->input->getInt('lid', 0);
if (!$lid)
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
$link = JvldDb::getRow("select partner_url, alias_url, out_hits from #__jvld_links where id = '".(int)$lid."'");
if (!$link)
throw new Exception(JText::_("COM_JVLD_ERR_DB"));
$out_hits = 1 + $link->out_hits;
JvldDb::update("update #__jvld_links set out_hits = '".(int)$out_hits."' where id = '".(int)$lid."'");
$url = JvldUtil::getVisitUrl($link->partner_url, $link->alias_url);
if ($url == '')
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
JvldInit::redirectUrl($url);
}
catch (Exception $ex)
{
JvldMsg::display($ex->getMessage(), _JVLD_NEXT_PAGE_GO_BACK);
return;
}
}
function redirectToXchangeUrl()
{
try
{
$cfg = JvldCfg::getInstance();
if (!$cfg->get('lecs_en'))
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
$lid = JFactory::getApplication()->input->getInt('lid', 0);
if (!$lid)
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
$link = JvldDb::getRow("select lecs_accept_invites, lecs_xglink_url, lecs_hits, partner_url from #__jvld_links where id = '".(int)$lid."'");
if (!$link)
throw new Exception(JText::_("COM_JVLD_ERR_DB"));
if (($link->partner_url == '') || (!$link->lecs_accept_invites) || ($link->lecs_xglink_url == ''))
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
$lecs_hits = 1 + $link->lecs_hits;
JvldDb::update("update #__jvld_links set lecs_hits = '".(int)$lecs_hits."' where id = '".(int)$lid."'");
JvldInit::redirectUrl($link->lecs_xglink_url);
}
catch (Exception $ex)
{
JvldMsg::display($ex->getMessage(), _JVLD_NEXT_PAGE_GO_BACK);
return;
}
}
function executePaidService()
{
$cfg = JvldCfg::getInstance();
$user = JFactory::getUser();
try
{
// get the variables
$sname = \Joomla\String\StringHelper::strtoupper(JFactory::getApplication()->input->getString('s', ''));
$token = JFactory::getApplication()->input->getString('t', '');
if (($token == '') || ($sname == ''))
{
JvldMsg::display(JText::_("COM_JVLD_ERR_INSUFFINFO"));
return;
}
/**
* User login status need not be checked
* In any case, just get the revenue record associated with the service name and refid. The plan code and id are required to generate the outgoing redirect url
* If the revenue record is already associated with a lid, then show an error message. This is to prevent reusing the same incoming url for adding multiple links
*/
// get revenue record associated with the service and refid
$row = JvldDb::getRow("select * from #__jvld_revenue where refid = '".JvldSecure::defendSQL($token)."' and service_name = '".JvldSecure::defendSQL($sname)."'");
if (!$row)
{
JvldMsg::display(JText::_("COM_JVLD_ERR_INVALID_REQ"));
return;
}
// get custom values
$custom = JvldInit::buildCustomArray($row->custom);
/**
* lid in revenue record is a generic param. It stores:
* link id (set as 0 during ipn processing and set to actual link id during link add completion) for one-way link,
* link id for set featured link (set during ipn processing),
* cat id for category sponsor (set during ipn processing),
* adspecid (set during ipn processing)
*/
switch ($sname)
{
case _JVLD_PAIDSVC_KEY_LISTING:
{
if ($row->lid)
{
JvldMsg::display(JText::_("COM_JVLD_ALREADY_USED"));
return;
}
JvldInit::redirectUrl(JvldPostinit::getRoute('addlink', '0&owpaid_id='.(int)$row->id.'&next=1&oway_plan='.htmlspecialchars($custom["plancode"])));
break;
}
case _JVLD_PAIDSVC_KEY_CSPONSOR:
{
JvldInit::redirectUrl(JvldPostinit::getRoute('sponsorcat', $row->lid.'&submode=2&revid='.$row->id));
break;
}
case _JVLD_PAIDSVC_KEY_ADVERTISING:
{
JvldInit::redirectUrl(JvldPostinit::getRoute('advertise', $row->lid.'&submode=2&revid='.$row->id));
break;
}
default:
{
JvldMsg::display();
return;
}
}
}
catch (Exception $ex)
{
JvldMsg::display($ex->getMessage(), _JVLD_NEXT_PAGE_GO_BACK);
return;
}
}
function resubmitListing()
{
try
{
$cfg = JvldCfg::getInstance();
$lid = JFactory::getApplication()->input->getInt('lid', 0);
if (!$lid)
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
$linkobj = new JvldLinkinfo($lid);
if (!$linkobj)
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
if ($linkobj->getInfo('link_status') != _JVLD_LINKSTATUS_PPENDING)
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
if (!JvldPostinit::isListingOwner($linkobj->getInfo('uid')))
throw new Exception(JText::_("COM_JVLD_UNAUTHORIZED"));
$linkplan = new JvldLinkPlan();
$linkplan->setPlanCode($linkobj->getInfo('oway_plan'));
// update status
JvldDb::update("update #__jvld_links set link_status = "._JVLD_LINKSTATUS_WPENDING.", last_submitted_on = '".JvldDate::getDateTimeInUTCInMySqlFormat()."', num_submits = num_submits + 1 where id = ".(int)$lid);
// notify admin
$partner_linkloc_url = JvldUtil::getPartnerLinkAtHome($linkobj->getPrimaryCategory());
$partner_detail_url = JvldInit::getSEFUrlForXternal(JvldPostinit::getRoute('detailpageurl', $lid));
$purl = JvldPostinit::getLinkUrlorTitleForDisplay($linkobj->getInfo('partner_url'), $linkobj->getInfo('partner_title'));
$pemail = $linkobj->getInfo('partner_email');
$email_approval_msg = "";
if ($cfg->get('link_apprem'))
{
$apnowstr = JvldPostinit::generateKey(32);
JvldDb::update("update `#__jvld_links` set `emstr` = '".JvldSecure::defendSQL($apnowstr)."' where `id` = '".(int)$lid."'");
$approve_url = JvldInit::getSEFUrlForXternal(JvldPostinit::getRoute('emailappr', $apnowstr, 0));
$reject_url = JvldInit::getSEFUrlForXternal(JvldPostinit::getRoute('emailrejt', $apnowstr, 0));
$delete_url = JvldInit::getSEFUrlForXternal(JvldPostinit::getRoute('emaildel', $apnowstr, 0));
$email_approval_msg = JText::sprintf("COM_JVLD_EMAIL_EMAIL_ACTION_TXT", $approve_url, $reject_url, $delete_url);
}
$em = new JvldEmail('FNA_RESUBMIT_REQUEST');
$em->setTag('{PARTNER-EMAIL}', $pemail);
$em->setTag('{PARTNER-URL}', $purl);
$em->setTag('{PARTNER-LINKLOC-AT-HOME}', $partner_linkloc_url);
$em->setTag('{PARTNER-DETAILPAGE-HOME}', $partner_detail_url);
$em->setTag('{LISTING-PLAN}', $linkplan->getName());
$em->setTag('{EMAIL-APPROVE-ACTION}', $email_approval_msg);
$em->send($cfg->get('site_email'));
// notify admin by sms
if ($cfg->get('admin_sms_notify_link_added'))
{
JvldPostinit::sendSMStoAdmin(JText::sprintf("COM_JVLD_ADDLINK_SMS_2", JvldPostinit::getLinkUrlorTitleForDisplay($linkobj->getInfo('partner_url'), $linkobj->getInfo('partner_title')), $cfg->get('site_url')));
}
JvldMsg::display(JText::_("COM_JVLD_RESUBMIT_OK"), _JVLD_NEXT_PAGE_CLOSE_WINDOW);
return;
}
catch (Exception $ex)
{
JvldMsg::display($ex->getMessage(), _JVLD_NEXT_PAGE_CLOSE_WINDOW);
return;
}
}
}