jonnsl/sliComments — Issue #37: Restricting Guests to just 1 vote on each comment
Author: iseo
Created: 2012-03-08 14:01:24+00:00
State: open

Looking at the code there seems to be a method of only allowing the Public/Guests to vote once on each comment - by recording the IP address.
How is this enabled?

I'm referring to models/commnets.php

// Guest already voted?
if (time() % 2) {
$query = $db->getQuery(true)
->delete('#__slicomments_ratings')
->where('user_id = 0')
->where('date < '. $yesterday);
$db->setQuery($query)->query();
}
$query = $db->getQuery(true)
->select('count(*)')
->from('#__slicomments_ratings')
->where('user_id = 0')
->where('ip = '. $db->quote($_SERVER['REMOTE_ADDR']))
->where('date > '. $yesterday)
->where('comment_id = '.(int) $comment_id);
$db->setQuery($query);
$voted = $db->loadResult();

if ($voted){
$this->setError(JText::_('COM_COMMENTS_ERROR_ALREADY_VOTED'));
return false;
}

$data = (object) array(
'user_id'	=> 0,
'vote'	=> (int) $vote,
'comment_id'=> (int) $comment_id,
'ip'	=> $_SERVER['REMOTE_ADDR'],
'date'	=> JFactory::getDate()->toMysql()
);
$stored = $db->insertObject('#__slicomments_ratings', $data);
}

if (!$stored){
if (JDEBUG) {
$this->setError(JText::sprintf('COM_COMMENTS_ERROR_COULD_NOT_STORE_VOTE_DEBUG', $db->getErrorMsg()));
} else {
$this->setError(JText::_('COM_COMMENTS_ERROR_COULD_NOT_STORE_VOTE'));
}
}