Ejemplo n.º 1
0
function afficheVotes($nb_votes, $num_article)
{
    global $blog_settings, $core;
    # On met un s a vote si il le faut
    $vote = "vote";
    if ($nb_votes > 1) {
        $vote = "votes";
    }
    # Score du vote en fonction du system
    $score = $nb_votes;
    if ($blog_settings->get('planet_votes_system') != "yes-no" && $score < 0) {
        $score = 0;
    }
    # Bouton de vote
    $text = '';
    if (checkVote($core->con, getIP(), $num_article)) {
        # Si le visiteur a deja vote
        $text .= '<span id="vote' . $num_article . '" class="avote">' . $score . ' ' . $vote . '.
				<span id="imgoui" title="' . T_('Vote yes') . '"></span>
				<span id="imgnon" title="' . T_('Vote no') . '"></span>';
        $text .= '</span>';
    } else {
        # Si il n'a jamais vote, on construit le token
        $ip = getIP();
        $token = md5($ip . $num_article);
        # On affiche le bouton de vote
        $text .= '<span id="vote' . $num_article . '" class="vote">' . $score . ' ' . $vote . '
				<a href="#blackhole" title="' . T_('This post seems pertinent to you') . '" id="aoui' . $num_article . '"
				onclick="javascript:vote(' . "'{$num_article}','{$token}', 'positif'" . ');" >
				<span id="imgoui" title="' . T_('Vote yes') . '"></span></a>';
        # En fonciton du systeme de vote
        if ($blog_settings->get('planet_votes_system') == "yes-no") {
            $text .= '<a href="#blackhole" title="' . T_('This post seems not pertinent to you') . '" id="anon' . $num_article . '"
				onclick="javascript:vote(' . "'{$num_article}','{$token}', 'negatif'" . ');" >
				<span id="imgnon" title="' . T_('Vote no') . '"></span></a>';
        } else {
            $text .= '<a href="#blackhole" title="' . T_('This post should not be here') . '" id="anon' . $num_article . '"
				onclick="if(confirm(\'' . T_('Are you sure this post should not be on this planet and should be removed?') . '\')) ' . "{ vote('{$num_article}','{$token}', 'negatif');}" . ' " >
				<span id="imgnon" title="' . T_('Vote no') . '"></span></a>';
        }
        $text .= "</span>";
    }
    return $text;
}
Ejemplo n.º 2
0
 /**
  * Allow the user to vote.
  * It is called to register a vote in a poll.
  * Must be called with a topic and option specified.
  * Requires the poll_vote permission.
  * Upon successful completion of action will direct user back to topic.
  * Accessed via ?action=poll;sa=vote.
  *
  * @uses Post language file.
  */
 public function action_vote()
 {
     global $topic, $user_info, $modSettings;
     require_once SUBSDIR . '/Poll.subs.php';
     // Make sure you can vote.
     isAllowedTo('poll_vote');
     loadLanguage('Post');
     // Check if they have already voted, or voting is locked.
     $row = checkVote($topic);
     if (empty($row)) {
         fatal_lang_error('poll_error', false);
     }
     // If this is a guest can they vote?
     if ($user_info['is_guest']) {
         // Guest voting disabled?
         if (!$row['guest_vote']) {
             fatal_lang_error('guest_vote_disabled');
         } elseif (!empty($_COOKIE['guest_poll_vote']) && preg_match('~^[0-9,;]+$~', $_COOKIE['guest_poll_vote']) && strpos($_COOKIE['guest_poll_vote'], ';' . $row['id_poll'] . ',') !== false) {
             // ;id,timestamp,[vote,vote...]; etc
             $guestinfo = explode(';', $_COOKIE['guest_poll_vote']);
             // Find the poll we're after.
             foreach ($guestinfo as $i => $guestvoted) {
                 $guestvoted = explode(',', $guestvoted);
                 if ($guestvoted[0] == $row['id_poll']) {
                     break;
                 }
             }
             // Has the poll been reset since guest voted?
             if (isset($guestvoted[1]) && $row['reset_poll'] > $guestvoted[1]) {
                 // Remove the poll info from the cookie to allow guest to vote again
                 unset($guestinfo[$i]);
                 if (!empty($guestinfo)) {
                     $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
                 } else {
                     unset($_COOKIE['guest_poll_vote']);
                 }
             } else {
                 fatal_lang_error('poll_error', false);
             }
             unset($guestinfo, $guestvoted, $i);
         }
     }
     // Is voting locked or has it expired?
     if (!empty($row['voting_locked']) || !empty($row['expire_time']) && time() > $row['expire_time']) {
         fatal_lang_error('poll_error', false);
     }
     // If they have already voted and aren't allowed to change their vote - hence they are outta here!
     if (!$user_info['is_guest'] && $row['selected'] != -1 && empty($row['change_vote'])) {
         fatal_lang_error('poll_error', false);
     } elseif (!empty($row['change_vote']) && !$user_info['is_guest'] && empty($_POST['options'])) {
         checkSession('request');
         // Find out what they voted for before.
         $pollOptions = determineVote($user_info['id'], $row['id_poll']);
         // Just skip it if they had voted for nothing before.
         if (!empty($pollOptions)) {
             // Update the poll totals.
             decreaseVoteCounter($row['id_poll'], $pollOptions);
             // Delete off the log.
             removeVote($user_info['id'], $row['id_poll']);
         }
         // Redirect back to the topic so the user can vote again!
         if (empty($_POST['options'])) {
             redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
         }
     }
     checkSession('request');
     // Make sure the option(s) are valid.
     if (empty($_POST['options'])) {
         fatal_lang_error('didnt_select_vote', false);
     }
     // Too many options checked!
     if (count($_REQUEST['options']) > $row['max_votes']) {
         fatal_lang_error('poll_too_many_votes', false, array($row['max_votes']));
     }
     $pollOptions = array();
     $inserts = array();
     foreach ($_REQUEST['options'] as $id) {
         $id = (int) $id;
         $pollOptions[] = $id;
         $inserts[] = array($row['id_poll'], $user_info['id'], $id);
     }
     // Add their vote to the tally.
     addVote($inserts);
     increaseVoteCounter($row['id_poll'], $pollOptions);
     // If it's a guest don't let them vote again.
     if ($user_info['is_guest'] && count($pollOptions) > 0) {
         // Time is stored in case the poll is reset later, plus what they voted for.
         $_COOKIE['guest_poll_vote'] = empty($_COOKIE['guest_poll_vote']) ? '' : $_COOKIE['guest_poll_vote'];
         // ;id,timestamp,[vote,vote...]; etc
         $_COOKIE['guest_poll_vote'] .= ';' . $row['id_poll'] . ',' . time() . ',' . (count($pollOptions) > 1 ? implode(',', $pollOptions) : $pollOptions[0]);
         // Increase num guest voters count by 1
         increaseGuestVote($row['id_poll']);
         require_once SUBSDIR . '/Auth.subs.php';
         $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
         elk_setcookie('guest_poll_vote', $_COOKIE['guest_poll_vote'], time() + 2500000, $cookie_url[1], $cookie_url[0], false, false);
     }
     // Maybe let a social networking mod log this, or something?
     call_integration_hook('integrate_poll_vote', array(&$row['id_poll'], &$pollOptions));
     // Return to the post...
     redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
 }
Ejemplo n.º 3
0
*
***** END LICENSE BLOCK *****/
# Inclusion des fonctions
require_once dirname(__FILE__) . '/../inc/prepend.php';
if ($core->auth->sessionExists() && isset($_POST) && isset($_POST['num_article']) && is_numeric(trim($_POST['num_article'])) && isset($_POST['token']) && isset($_POST['type'])) {
    # On recuepre la valeur du post
    $num_article = trim($_POST['num_article']);
    $token = trim($_POST['token']);
    $type = trim($_POST['type']);
    $value = $type == "positif" ? 1 : -1;
    # On recupere l'adresse ip
    $ip = getIP();
    # On reconstruit le token
    $hash = md5($ip . $num_article);
    # On met a jour le score si l'ip n'a pas vote et si le token est bon
    if (!checkVote($core->con, $ip, $num_article)) {
        $user_id = $core->auth->userID();
        # Verification du numero de l'article
        $sql = "SELECT post_score from " . $core->prefix . "post WHERE post_id = {$num_article}";
        $rs = $core->con->select($sql);
        $nb_art = $rs->count();
        $post_current_score = $rs->f('post_score');
        #Verification s'il a deja vote
        $sql = "SELECT COUNT(*) as nb from " . $core->prefix . "votes WHERE post_id = {$num_article} AND vote_ip = '{$ip}' AND user_id='" . $user_id . "'";
        $rs = $core->con->select($sql);
        $nb_vote = $rs->f('nb');
        if ($nb_art > 0 && $nb_vote == 0) {
            # Ajout de l'ip a la liste
            # FIXME : we have to handle the vote with a user logged in !!! Instead of admin.rand()
            $cur = $core->con->openCursor($core->prefix . 'votes');
            $cur->post_id = $num_article;