| Current Path : /var/www/html/components/com_jvld/helpers/ |
| Current File : /var/www/html/components/com_jvld/helpers/class.likes.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');
class JvldLinkLikes
{
private $lid = 0;
private $uid = 0;
function __construct($lid, $uid)
{
$this->lid = $lid;
$this->uid = $uid;
}
function doesUserLikeListing()
{
if ($this->uid)
{
// user is logged in
$r = JvldDb::getRow("select * from #__jvld_likes where lid = '".(int)$this->lid."' and uid = '".(int)$this->uid."'");
if ($r)
{
// user likes this listing
return true;
}
else
{
// user does not like this listing
return false;
}
}
else
{
// guest user
$r = JvldDb::getRow("select * from #__jvld_likes where lid = '".(int)$this->lid."' and ip = '".JvldSecure::defendSQL(JvldFrameworkHelper::getIpAddress())."'");
if ($r)
{
// guest likes this listing
return true;
}
else
{
// guest does not like this listing
return false;
}
}
}
public function likeListing()
{
$cfg = JvldCfg::getInstance();
switch ($cfg->get('like_en'))
{
case 0:
{
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
}
case 1: // logged in user can only like
{
if (!$this->uid)
throw new Exception(JText::_("COM_JVLD_LOGIN_FIRST"));
break;
}
case 2: // any user can like
{
break;
}
}
JvldDb::update("insert into `#__jvld_likes` (lid, uid, ip, tstamp) values('".(int)$this->lid."', '".(int)$this->uid."', '".JvldSecure::defendSQL(JvldFrameworkHelper::getIpAddress())."', '".JvldSecure::defendSQL(JvldDate::getDateTimeInUTCInMySqlFormat())."')");
}
public function unLikeListing()
{
$cfg = JvldCfg::getInstance();
switch ($cfg->get('like_en'))
{
case 0:
{
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
}
case 1: // logged in user can only unlike
{
if (!$this->uid)
throw new Exception(JText::_("COM_JVLD_LOGIN_FIRST"));
break;
}
case 2: // any user can unlike
{
break;
}
}
if ($this->uid)
JvldDb::update("delete from #__jvld_likes where lid = '".(int)$this->lid."' and uid = '".(int)$this->uid."'");
else
JvldDb::update("delete from #__jvld_likes where lid = '".(int)$this->lid."' and uid = '".(int)$this->uid."' and ip = '".JvldSecure::defendSQL(JvldFrameworkHelper::getIpAddress())."'");
}
}