Check if a user has voted for this entry

@param   integer  $user_id  Optinal user ID to set as voter
@param   string   $ip       IP Address
@return  integer
6908
public function ballot($user_id = 0, $ip = null)
	{
		if (User::isGuest())
		{
			$vote = new Vote();
			$vote->set('item_type', 'comment');
			$vote->set('item_id', $this->get('id'));
			$vote->set('created_by', $user_id);
			$vote->set('ip', $ip);

			return $vote;
		}

		$user = $user_id ? User::getInstance($user_id) : User::getInstance();
		$ip   = $ip ?: Request::ip();

		// See if a person from this IP has already voted in the last week
		$votes = $this->votes();

		if ($user->get('id'))
		{
			$votes->whereEquals('created_by', $user->get('id'));
		}
		elseif ($ip)
		{
			$votes->whereEquals('ip', $ip);
		}

		$vote = $votes
			->ordered()
			->limit(1)
			->row();

		if (!$vote || !$vote->get('id'))
		{
			$vote = new Vote();
			$vote->set('item_type', 'comment');
			$vote->set('item_id', $this->get('id'));
			$vote->set('created_by', $user_id);
			if ($ip)
			{
				$vote->set('ip', $ip);
			}
		}

		return $vote;
	}
734183
public function getUserToken($userId, $ip, $userAgent = null)
    {
        $query = $this->getUserTokenQuery($userId, $ip, $userAgent);

        return $this->findOneWith($query);
    }
1084760
public static function checkIP($UserIP = false)
    {
        // Check if IP present
        if ($UserIP === false)
        {
            if (\Environment::get('ip'))
            {
                if (strpos(\Environment::get('ip'), ',') !== false) //first IP
                {
                    $UserIP =  trim(substr(\Environment::get('ip'), 0, strpos(\Environment::get('ip'), ',')));
                }
                else
                {
                    $UserIP = trim(\Environment::get('ip'));
                }
            }
            else
            {
                return false; // No IP, no search.
            }
            //Test for private IPs
            if ( true === static::checkPrivateIP($UserIP) &&
                false === empty($_SERVER['HTTP_X_FORWARDED_FOR'])
            )
            {
                //second try
                $HTTPXFF = $_SERVER['HTTP_X_FORWARDED_FOR'];
                $_SERVER['HTTP_X_FORWARDED_FOR'] = '';
            
                $UserIP = \Environment::get('ip');
                if (strpos($UserIP, ',') !== false) //first IP
                {
                    $UserIP = trim( substr($UserIP, 0, strpos($UserIP, ',') ) );
                }
                $_SERVER['HTTP_X_FORWARDED_FOR'] = $HTTPXFF;
            }
        }
        // IPv4 or IPv6 ?
        switch (static::getIpVersion($UserIP))
        {
        	case "IPv4":
        	    if ( static::checkBotIPv4($UserIP, static::getBotIpv4List()) === true) { return true; }
        	    break;
        	case "IPv6":
        	    if ( static::checkBotIPv6($UserIP, static::getBotIpv6List()) === true) { return true; }
        	    break;
        	default:
        	    return false;
        	    break;
        }
        return false;
    }
1235755
def can_vote_in_poll(self, poll, user):
        
        # First we have to check if the poll is curently open
        if poll.duration:
            poll_dtend = poll.created + dt.timedelta(days=poll.duration)
            if poll_dtend < now():
                return False

        # Is this user allowed to vote in polls in the current forum?
        can_vote = (
            self._perform_basic_permission_check(poll.topic.forum, user, 'can_vote_in_polls') and
            not poll.topic.is_locked
        )

        # Retrieve the user votes for the considered poll
        user_votes = TopicPollVote.objects.filter(poll_option__poll=poll)
        if user.is_anonymous:
            forum_key = get_anonymous_user_forum_key(user)
            if forum_key:
                user_votes = user_votes.filter(anonymous_key=forum_key)
            else:
                # If the forum key of the anonymous user cannot be retrieved, the user should not be
                # allowed to vote in the considered poll.
                user_votes = user_votes.none()
                can_vote = False
        else:
            user_votes = user_votes.filter(voter=user)

        # If the user has already voted, they can vote again if the vote changes are allowed
        if user_votes.exists() and can_vote:
            can_vote = poll.user_changes

        return can_vote
1062466
static function isUserIPInList( $ipList )
    {
        $ipAddress = eZSys::clientIP();
        if ( $ipAddress )
        {
            $result = false;
            foreach( $ipList as $itemToMatch )
            {
                if ( preg_match("/^(([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+))(\/([0-9]+)$|$)/", $itemToMatch, $matches ) )
                {
                    if ( $matches[6] )
                    {
                        if ( eZDebug::isIPInNet( $ipAddress, $matches[1], $matches[7] ) )
                        {
                            $result = true;
                            break;
                        }
                    }
                    else
                    {
                        if ( $matches[1] == $ipAddress )
                        {
                            $result = true;
                            break;
                        }
                    }
                }
            }
        }
        else
        {
            $result = (
                in_array( 'commandline', $ipList ) &&
                ( php_sapi_name() == 'cli' )
            );
        }
        return $result;
    }
645131
public function user_has(string $id_option, string $id_user): bool
  {
    return (bool)$this->_retrieve_ids($id_option, $id_user);
  }
342158
public function userLikedComment($ip, $useragent)
    {
        $count = BaseManager::build('FelixOnline\Core\Comment', 'comment_like')
            ->filter("ip = '%s'", array($ip))
            ->filter("user_agent = '%s'", array($useragent))
            ->filter("comment = %i", array($this->getId()))
            ->filter("binlike = 1")
            ->count();

        return (boolean) $count;
    }
683407
protected function checkIps($requestedIp, $ips)
    {
        $ips = (array) $ips;

        $valid = false;
        $i = 0;

        while ($i<count($ips) && !$valid) {
            $valid = IpUtils::checkIp($requestedIp, $ips[$i]);
            $i++;
        }

        return $valid;
    }
50636
public function getIp2Decimal($ip = null)
    {
        $ip = $ip ?: $this->getIp();

        if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            return false;
        }

        $ipEntryData = explode('.', $ip);

        return ((int)$ipEntryData[3]) + ($ipEntryData[2] * 256) + ($ipEntryData[1] * 256 * 256) + ($ipEntryData[0] * 256 * 256 * 256);
    }
297925
public static function ipCidrsCheck($p_ip, $p_cidrs)
    {
        foreach ($p_cidrs as $name => $range) {
            if (self::ipCidrCheck($p_ip, $range)) {
                return true;
            }
        }
        
        return false;
    }
427153
public function switch_to_user( $user_id ) {
		$user_id = $this->getUserIdFromLogin( $user_id );

		PHPUnit_Framework_Assert::assertNotEmpty( $user_id );

		$this->visitPath( sprintf( 'wp-admin/user-edit.php?user_id=%d', $user_id ) );
		$this->getSession()->getPage()->clickLink( "Switch\xc2\xa0To" );
	}
378737
public function isAllowed ($ip, $priority = 'deny,allow')
	{
		
		// Convert IP to decimal
		
		$ipDec = (float)sprintf ("%u", ip2long ($ip));
		
		// Check
		
		foreach (explode (',', $priority) as $type)
		{
			
			switch ($type)
			{
				
				// Check if the IP is allowed
				
				case 'allow':
					
					foreach ($this->allowIPs as $name => $range)
					{
						if ($this->isInside ($ipDec, $name, $range))
						{
							return TRUE;
						}
					}
					
					break;
				
				// Check if IP is denied
					
				case 'deny':
					
					foreach ($this->denyIPs as $name => $range)
					{
						if ($this->isInside ($ipDec, $name, $range))
						{
							return FALSE;
						}
					}
					
					break;
				
			}
			
		}
		
		// Not allowed by default
		
		return FALSE;
		
	}
550254
public function actionEditpoll($cid = null, $fid = null, $tid = null, $pid = null)
    {
        $poll = Poll::find()->joinWith('thread')->where([
            Poll::tableName() . '.id' => $pid,
            Poll::tableName() . '.thread_id' => $tid,
            Thread::tableName() . '.category_id' => $cid,
            Thread::tableName() . '.forum_id' => $fid,
        ])->limit(1)->one();
        if (empty($poll)) {
            $this->error(Yii::t('podium/flash', 'Sorry! We can not find the poll you are looking for.'));
            return $this->redirect(['forum/index']);
        }

        if ($poll->thread->locked == 1 && !User::can(Rbac::PERM_UPDATE_THREAD, ['item' => $poll->thread])) {
            $this->info(Yii::t('podium/flash', 'This thread is locked.'));
            return $this->redirect(['forum/thread',
                'cid' => $poll->thread->forum->category->id,
                'fid' => $poll->thread->forum->id,
                'id' => $poll->thread->id,
                'slug' => $poll->thread->slug
            ]);
        }
        if ($poll->author_id != User::loggedId() && !User::can(Rbac::PERM_UPDATE_THREAD, ['item' => $poll->thread])) {
            $this->error(Yii::t('podium/flash', 'Sorry! You do not have the required permission to perform this action.'));
            return $this->redirect(['forum/thread',
                'cid' => $poll->thread->forum->category->id,
                'fid' => $poll->thread->forum->id,
                'id' => $poll->thread->id,
                'slug' => $poll->thread->slug
            ]);
        }
        if ($poll->votesCount) {
            $this->error(Yii::t('podium/flash', 'Sorry! Someone has already voted and this poll can no longer be edited.'));
            return $this->redirect(['forum/thread',
                'cid' => $poll->thread->forum->category->id,
                'fid' => $poll->thread->forum->id,
                'id' => $poll->thread->id,
                'slug' => $poll->thread->slug
            ]);
        }

        foreach ($poll->answers as $answer) {
            $poll->editAnswers[] = $answer->answer;
        }

        $postData = Yii::$app->request->post();
        if ($poll->load($postData)) {
            if ($poll->validate()) {
                if ($poll->podiumEdit()) {
                    $this->success(Yii::t('podium/flash', 'Poll has been updated.'));
                    return $this->redirect(['forum/thread',
                        'cid' => $poll->thread->forum->category->id,
                        'fid' => $poll->thread->forum->id,
                        'id' => $poll->thread->id,
                        'slug' => $poll->thread->slug
                    ]);
                }
                $this->error(Yii::t('podium/flash', 'Sorry! There was an error while updating the post. Contact administrator about this problem.'));
            }
        }
        return $this->render('editpoll', ['model' => $poll]);
    }
1364614
public function verifyIp($ip) {
        $data = $this->ip();
        return $data === false || in_array($ip, $data);
    }
1256198
public static function isValid(string $ip = null)
    {
        if (is_null($ip)) {
            $ip = self::get();
        }

        return filter_var($ip, FILTER_VALIDATE_IP) == $ip;
    }
181238
public function getByUser($product_id, $user_id)
    {
        $result = null;
        $this->hook->attach('rating.get.user.before', $product_id, $user_id, $result, $this);

        if (isset($result)) {
            return $result;
        }

        $user_ids = (array) $user_id;
        $conditions = array_merge($user_ids, array($product_id));
        $placeholders = rtrim(str_repeat('?,', count($user_ids)), ',');

        $sql = "SELECT * FROM rating_user WHERE user_id IN($placeholders) AND product_id=?";

        $result = $this->db->fetchAll($sql, $conditions, array('index' => 'user_id'));

        if (!is_array($user_id) && isset($result[$user_id])) {
            $result = $result[$user_id];
        }

        $this->hook->attach('rating.get.user.after', $product_id, $user_id, $result, $this);
        return $result;
    }
1275416
public function setClientUser($client_id, $user_id)
    {
        if ($this->getClientUser($client_id, $user_id)) {
            return true;
        } else {
            $created_at = date('Y-m-d H:i:s');
            $sql        = 'INSERT INTO %s (client_id, user_id, created_at) VALUES (:client_id, :user_id, :created_at)';
            $sql        = sprintf($sql, $this->config['client_user_table']);

            $params = array_map('trim', compact('client_id', 'user_id', 'created_at'));

            return $this->db->prepare($sql)->execute($params);
        }
    }