示例#1
0
function get_votes($time)
{
    global $db, $events, $last_timestamp;
    $res = $db->get_results("select vote_id, unix_timestamp(vote_date) as timestamp, vote_value, vote_ip, vote_user_id, link_id, link_title, link_url, link_status, link_date, link_published_date, link_votes, link_author from " . table_votes . ", " . table_links . " where vote_date > from_unixtime({$time}) and link_id = vote_link_id and vote_user_id != link_author and link_status!='discard' and vote_type = 'links' order by vote_date desc limit 20");
    if (!$res) {
        return;
    }
    foreach ($res as $event) {
        if (substr($event->vote_ip, 0, 3) != '0.0') {
            $id = $event->vote_id;
            $uid = $event->vote_user_id;
            if ($uid > 0) {
                $user = $db->get_var("select user_login from " . table_users . " where user_id = {$uid}");
            } else {
                $user = preg_replace('/\\.[0-9]+$/', '', $event->vote_ip);
            }
            if ($event->vote_value >= 0) {
                $type = 'vote';
                $who = $user;
            } else {
                $type = 'problem';
                $who = get_negative_vote($event->vote_value);
            }
            $status = get_status($event->link_status);
            $key = $event->timestamp . ':votes:' . $id;
            $events[$key] = 'ts:"' . $event->timestamp . '", type:"' . $type . '", votes:"' . $event->link_votes . '", link:"' . $event->link_id . '", title:"' . addslashes($event->link_title) . '", who:"' . addslashes($who) . '", status:"' . $status . '", uid:"' . $uid . '"';
            //echo "($key)". $events[$key];
            if ($event->timestamp > $last_timestamp) {
                $last_timestamp = $event->timestamp;
            }
        }
    }
}
示例#2
0
function get_votes($dbtime)
{
    global $db, $events, $last_timestamp, $foo_link, $max_items, $current_user;
    $res = $db->get_results("select vote_id, unix_timestamp(vote_date) as timestamp, vote_value, INET_NTOA(vote_ip_int) as vote_ip, vote_user_id, link_id, link_title, link_uri, link_status, link_date, link_votes, link_anonymous, link_comments from votes, links, sub_statuses where sub_statuses.id = " . SitesMgr::my_id() . " and vote_type='links' and vote_date > {$dbtime} and link_id = sub_statuses.link and sub_statuses.link = vote_link_id and vote_user_id != link_author order by vote_date desc limit {$max_items}");
    if (!$res) {
        return;
    }
    foreach ($res as $event) {
        if ($current_user->user_id > 0) {
            if (!empty($_REQUEST['friends']) && $event->vote_user_id != $current_user->user_id) {
                // Check the user is a friend
                if (User::friend_exists($current_user->user_id, $event->vote_user_id) <= 0) {
                    continue;
                } elseif ($event->vote_value < 0) {
                    // If the vote is negative, verify also the other user has selected as friend to the current one
                    if (User::friend_exists($event->vote_user_id, $current_user->user_id) <= 0) {
                        continue;
                    }
                }
            } elseif (!empty($_REQUEST['admin']) && $current_user->admin) {
                $user_level = $db->get_var("select user_level from users where user_id={$event->vote_user_id}");
                if ($user_level != 'admin' && $user_level != 'god') {
                    continue;
                }
            }
        }
        if ($event->vote_value >= 0) {
            if ($_REQUEST['novote']) {
                continue;
            }
            if ($event->link_status == 'published' && $_REQUEST['nopubvotes']) {
                continue;
            }
        } else {
            if ($_REQUEST['noproblem']) {
                continue;
            }
        }
        $foo_link->id = $event->link_id;
        $foo_link->uri = $event->link_uri;
        $foo_link->get_relative_permalink();
        $uid = $event->vote_user_id;
        if ($event->vote_user_id > 0) {
            $res = $db->get_row("select user_login from users where user_id = {$event->vote_user_id}");
            $user = $res->user_login;
        } else {
            $user = preg_replace('/\\.[0-9]+$/', '', $event->vote_ip);
        }
        if ($event->vote_value >= 0) {
            $type = 'vote';
            $who = $user;
        } else {
            $type = 'problem';
            $who = get_negative_vote($event->vote_value);
            // Show user_login if she voted more than N negatives in one minute
            if ($current_user->user_id > 0 && $current_user->admin) {
                $negatives_last_minute = $db->get_var("select count(*) from votes where vote_type='links' and vote_user_id={$event->vote_user_id} and vote_date > date_sub(now(), interval 30 second) and vote_value < 0");
                if ($negatives_last_minute > 2) {
                    $who .= "<br>({$user})";
                }
            }
        }
        $json['status'] = get_status($event->link_status);
        $json['type'] = $type;
        $json['ts'] = $event->timestamp;
        $json['votes'] = $event->link_votes + $event->link_anonymous;
        $json['com'] = $event->link_comments;
        $json['link'] = $foo_link->get_relative_permalink();
        $json['title'] = $event->link_title;
        $json['who'] = $who;
        $json['uid'] = $event->vote_user_id;
        $json['id'] = $event->link_id;
        if ($event->vote_user_id > 0) {
            $json['icon'] = get_avatar_url($event->vote_user_id, -1, 20);
        }
        $key = $event->timestamp . ':votes:' . $event->vote_id;
        $events[$key] = $json;
        if ($event->timestamp > $last_timestamp) {
            $last_timestamp = $event->timestamp;
        }
    }
}
示例#3
0
function do_shaken()
{
    global $db, $rows, $user, $offset, $page_size, $globals;
    if ($globals['bot']) {
        return;
    }
    do_user_subheader(array(_('envíos propios') => get_user_uri($user->username, 'history'), _('votados') => get_user_uri($user->username, 'shaken'), _('favoritos') => get_user_uri($user->username, 'favorites'), _('votados por amigos') => get_user_uri($user->username, 'friends_shaken')), 1, 'rss?voted_by=' . $user->id, _('votadas en rss2'));
    $rows = -1;
    //$db->get_var("SELECT count(*) FROM votes WHERE vote_type='links' and vote_user_id=$user->id");
    $links = $db->get_results("SELECT vote_link_id as id, vote_value FROM votes WHERE vote_type='links' and vote_user_id={$user->id} ORDER BY vote_date DESC LIMIT {$offset},{$page_size}");
    if ($links) {
        foreach ($links as $linkdb) {
            $link = Link::from_db($linkdb->id);
            if ($link->author == $user->id) {
                continue;
            }
            echo '<div style="max-width: 60em">';
            $link->print_summary('short', 0, false);
            if ($linkdb->vote_value < 0) {
                echo '<div class="box" style="z-index:1;margin:0 0 -5x 0;background:#FF3333;position:relative;top:-5px;left:85px;width:8em;padding: 1px 1px 1px 1px;border-color:#f00;opacity:0.9;text-align:center;font-size:0.9em;color:#fff;text-shadow: 0 1px 0 #000">';
                echo get_negative_vote($linkdb->vote_value);
                echo "</div>\n";
            }
            echo "</div>\n";
        }
        echo '<br/><span style="color: #FF6400;"><strong>' . _('Nota') . '</strong>: ' . _('sólo se visualizan los votos de los últimos meses') . '</span><br />';
    }
}
示例#4
0
 function print_warn()
 {
     global $db, $globals;
     if ($this->status == 'abuse') {
         echo '<div class="warn"><strong>' . _('Aviso') . '</strong>: ';
         echo _('noticia descartada por violar las') . ' <a href="' . $globals['legal'] . '#tos">' . _('normas de uso') . '</a>';
         echo "</div>\n";
         return;
     }
     if (!$this->check_warn() || $this->is_discarded()) {
         return;
     }
     echo '<div class="warn"><strong>' . _('Aviso automático') . '</strong>: ';
     if ($this->status == 'published') {
         echo _('noticia errónea o controvertida, por favor lee los comentarios.');
     } elseif ($this->author == $current_user->user_id && $this->is_editable()) {
         echo _('Esta noticia tiene varios votos negativos.') . ' ' . _('Tu karma no será afectado si la descartas manualmente.');
     } else {
         // Only says "what" if most votes are "wrong" or "duplicated"
         $negatives = $db->get_row("select SQL_CACHE vote_value, count(vote_value) as count from votes where vote_type='links' and vote_link_id={$this->id} and vote_value < 0 group by vote_value order by count desc limit 1");
         if ($negatives->count > 2 && $negatives->count >= $this->negatives / 2 && ($negatives->vote_value == -6 || $negatives->vote_value == -8)) {
             echo _('Esta noticia podría ser') . ' <strong>' . get_negative_vote($negatives->vote_value) . '</strong>. ';
         } else {
             echo _('Esta noticia tiene varios votos negativos.');
         }
         if (!$this->voted && !$globals['link']) {
             echo ' <a href="' . $this->get_relative_permalink() . '">' . _('Asegúrate') . '</a> ' . _('antes de menear') . '.';
         }
     }
     echo "</div>\n";
 }
示例#5
0
        die;
    }
    echo '<div class="voters-list">';
    foreach ($votes as $vote) {
        echo '<div class="item">';
        $vote_detail = get_date_time($vote->ts);
        // If current users is a god, show the first IP addresses
        if ($current_user->user_level == 'god') {
            $vote_detail .= ' (' . preg_replace('/\\.[0-9]+$/', '', $vote->ip) . ')';
        }
        if ($vote->vote_value > 0) {
            $vote_detail .= ' ' . _('valor') . ":&nbsp;{$vote->vote_value}";
            echo '<a href="' . get_user_uri($vote->user_login) . '" title="' . $vote->user_login . ': ' . $vote_detail . '">';
            echo '<img class="avatar" src="' . get_avatar_url($vote->vote_user_id, $vote->user_avatar, 20) . '" width="20" height="20" alt=""/>';
            echo $vote->user_login . '</a>';
        } else {
            if ($globals['show_negatives'] > 0 && $vote->ts > $globals['show_negatives']) {
                echo '<a href="' . get_user_uri($vote->user_login) . '" title="' . $vote->user_login . ': ' . $vote_detail . '">';
                echo '<img src="' . get_avatar_url($vote->vote_user_id, $vote->user_avatar, 20) . '" width="20" height="20" alt=""/></a>';
                echo '<span>' . get_negative_vote($vote->vote_value) . '</span>';
            } else {
                echo '<span>';
                echo '<img src="' . $globals['base_static'] . 'img/mnm/mnm-anonym-vote-01.png" width="20" height="20" alt="' . _('anónimo') . '" title="' . $vote_detail . '"/>';
                echo get_negative_vote($vote->vote_value) . '</span>';
            }
        }
        echo '</div>';
    }
    echo "</div>\n";
    do_contained_pages($globals['link_id'], $votes_users, $votes_page, $votes_page_size, 'meneos.php', 'voters', 'voters-container');
}
示例#6
0
function get_votes($dbtime, $link_id)
{
    global $db, $events, $last_timestamp, $max_items, $current_user;
    $res = $db->get_results("select vote_id, unix_timestamp(vote_date) as timestamp, vote_value, INET_NTOA(vote_ip_int) as vote_ip, vote_user_id, link_id, link_date, link_votes, link_anonymous, link_status, link_comments from votes, links where vote_type='links' and vote_link_id = {$link_id} and vote_date > {$dbtime} and link_id = vote_link_id order by vote_date desc limit {$max_items}");
    if (!$res) {
        return;
    }
    foreach ($res as $event) {
        $id = $event->vote_id;
        $uid = $event->vote_user_id;
        if ($uid > 0) {
            $res = $db->get_row("select user_login, user_avatar from users where user_id = {$uid}");
            $user = $res->user_login;
        } else {
            $user = preg_replace('/\\.[0-9]+$/', '', $event->vote_ip);
        }
        if ($event->vote_value >= 0) {
            $type = 'vote';
            $who = $user;
        } else {
            $type = 'problem';
            $who = get_negative_vote($event->vote_value);
        }
        $status = get_status($event->link_status);
        $key = $event->timestamp . ':votes:' . $id;
        $events[$key] = 'ts:"' . $event->timestamp . '",type:"' . $type . '",votes:"' . ($event->link_votes + $event->link_anonymous) . '", com:"' . $event->link_comments . '",who:"' . addslashes($who) . '",uid:"' . $uid . '",status:"' . $status . '"';
        if ($uid > 0) {
            $events[$key] .= ',icon:"' . get_avatar_url($uid, $res->user_avatar, 20) . '"';
        }
        if ($event->timestamp > $last_timestamp) {
            $last_timestamp = $event->timestamp;
        }
    }
}
示例#7
0
 function print_warn()
 {
     global $db;
     if ($this->status == 'queued' && $this->negatives > 3 && $this->negatives > $this->votes / 8) {
         echo '<div class="warn"><strong>' . _('Aviso automático') . '</strong>: ';
         // Only says "what" if most votes are "wrong" or "duplicated"
         $negatives = $db->get_row("select vote_value, count(vote_value) as count from votes where vote_type='links' and vote_link_id={$this->id} and vote_value < 0 group by vote_value order by count desc limit 1");
         if ($negatives->count > 2 && $negatives->count >= $this->negatives / 2 && ($negatives->vote_value == -6 || $negatives->vote_value == -8)) {
             echo _('Esta noticia podría ser <strong>') . get_negative_vote($negatives->vote_value) . '</strong>. ';
         } else {
             echo _('Esta noticia tiene varios votos negativos.');
         }
         if ($this->votes_enabled && !$this->voted) {
             echo ' <a href="' . $this->get_relative_permalink() . '/voters">' . _('Asegúrate') . '</a> ' . _('antes de menear') . '.';
         }
         echo "</div>\n";
     }
 }
示例#8
0
 function print_summary($type = 'full', $karma_best_comment = 0, $show_tags = true)
 {
     global $current_user, $current_user, $globals, $db;
     if (!$this->read) {
         return;
     }
     $this->is_votable();
     $this->get_current_sub_status_and_date();
     if (!empty($this->max_len) && $this->max_len > 0) {
         $this->truncate($this->max_len);
     }
     $this->content = $this->to_html($this->content);
     $this->show_tags = $show_tags;
     $this->relative_permalink = $this->get_relative_permalink();
     $this->permalink = $this->get_permalink(false, $this->relative_permalink);
     // To avoid double verification
     $this->show_shakebox = $type != 'preview' && $this->votes > 0;
     $this->has_warning = !(!$this->check_warn() || $this->is_discarded());
     $this->is_editable = $this->is_editable();
     $this->url_str = preg_replace('/^www\\./', '', parse_url($this->url, 1));
     $this->has_thumb();
     $this->map_editable = $this->geo && $this->is_map_editable();
     $this->can_vote_negative = !$this->voted && $this->votes_enabled && $this->negatives_allowed($globals['link_id'] > 0) && $type != 'short' && $type != 'preview';
     if ($this->status == 'abuse' || $this->has_warning) {
         $this->negative_text = FALSE;
         $negatives = $db->get_row("select SQL_CACHE vote_value, count(vote_value) as count from votes where vote_type='links' and vote_link_id={$this->id} and vote_value < 0 group by vote_value order by count desc limit 1");
         if ($negatives->count > 2 && $negatives->count >= $this->negatives / 2 && ($negatives->vote_value == -6 || $negatives->vote_value == -8)) {
             $this->negative_text = get_negative_vote($negatives->vote_value);
         }
     }
     if ($karma_best_comment > 0 && $this->comments > 0 && $this->comments < 50 && $globals['now'] - $this->date < 86400) {
         $this->best_comment = $db->get_row("select SQL_CACHE comment_id, comment_order, substr(comment_content, 1, 225) as content from comments where comment_link_id = {$this->id} and comment_karma > {$karma_best_comment} and comment_votes > 0 order by comment_karma desc limit 1");
     } else {
         $this->best_comment = FALSE;
     }
     if ($this->geo && $this->map_editable && $current_user->user_id == $this->author && $this->sent_date > $globals['now'] - 600 && !$this->latlng) {
         $this->add_geo = TRUE;
     } else {
         $this->add_geo = FALSE;
     }
     $this->get_box_class();
     if ($this->do_inline_friend_votes) {
         $this->friend_votes = $db->get_results("SELECT vote_user_id as user_id, vote_value, user_avatar, user_login, UNIX_TIMESTAMP(vote_date) as ts,inet_ntoa(vote_ip_int) as ip FROM votes, users, friends WHERE vote_type='links' and vote_link_id={$this->id} AND vote_user_id=friend_to AND vote_user_id > 0 AND user_id = vote_user_id AND friend_type = 'manual' AND friend_from = {$current_user->user_id} AND friend_value > 0 AND vote_value > 0 AND vote_user_id != {$this->author} ORDER BY vote_date DESC");
     }
     $vars = compact('type');
     $vars['self'] = $this;
     return Haanga::Load("link_summary.html", $vars);
 }
function get_votes($time) {
	global $db, $events, $last_timestamp;
	$res = $db->get_results("select vote_id, unix_timestamp(vote_date) as timestamp, vote_value, vote_ip, vote_user_id, link_id, link_title, link_url, link_status, link_date, link_published_date, link_votes, link_author from votes, links where vote_type='links' and vote_date > from_unixtime($time) and link_id = vote_link_id and vote_user_id != link_author order by vote_date desc limit 20");
	if (!$res) return;
	foreach ($res as $event) {
		if ($event->vote_value >= 0 && !empty($_GET['novote'])) continue;
		if ($event->vote_value < 0 && !empty($_GET['noproblem'])) continue;
		$id=$event->vote_id;
		$uid = $event->vote_user_id;
		if($uid > 0) {
			$res = $db->get_row("select user_login, user_email from users where user_id = $uid");
			$user = $res->user_login;
			$md5 = md5($res->user_email);
		} else {
			$user= preg_replace('/\.[0-9]+$/', '', $event->vote_ip);
		}
		if ($event->vote_value >= 0) {
			$type = 'vote';
			$who = $user;
		} else { 
			$type = 'problem';
			$who = get_negative_vote($event->vote_value);
		}
		$status =  get_status($event->link_status);
		$key = $event->timestamp . ':votes:'.$id;
		$events[$key] = 'ts:"'.$event->timestamp.'", type:"'.$type.'", votes:"'.$event->link_votes.'", link:"'.$event->link_id.'", title:"'.addslashes($event->link_title).'", who:"'.addslashes($who).'", status:"'.$status.'", uid:"'.$uid.'", md5:"'.$md5.'"';
		//echo "($key)". $events[$key];
		if($event->timestamp > $last_timestamp) $last_timestamp = $event->timestamp;
	}
}
示例#10
0
function get_votes($time)
{
    global $db, $events, $last_timestamp, $foo_link, $max_items, $current_user;
    if (!empty($_GET['nopubvotes'])) {
        $pvotes = "and link_status != 'published'";
    } else {
        $pvotes = '';
    }
    $res = $db->get_results("select vote_id, unix_timestamp(vote_date) as timestamp, vote_value, vote_ip, vote_user_id, link_id, link_title, link_uri, link_status, link_date, link_published_date, link_votes, link_comments, link_author from votes, links where vote_type='links' and vote_date > from_unixtime({$time}) and link_id = vote_link_id {$pvotes} and vote_user_id != link_author order by vote_date desc limit {$max_items}");
    if (!$res) {
        return;
    }
    foreach ($res as $event) {
        if ($event->vote_value >= 0 && !empty($_GET['novote'])) {
            continue;
        }
        if ($event->vote_value < 0 && !empty($_GET['noproblem'])) {
            continue;
        }
        $foo_link->id = $event->link_id;
        $foo_link->uri = $event->link_uri;
        $link = $foo_link->get_relative_permalink();
        $id = $event->vote_id;
        $uid = $event->vote_user_id;
        if ($uid > 0) {
            $res = $db->get_row("select user_login, user_email from users where user_id = {$uid}");
            $user = $res->user_login;
            $md5 = md5($res->user_email);
        } else {
            $user = preg_replace('/\\.[0-9]+$/', '', $event->vote_ip);
        }
        if ($event->vote_value >= 0) {
            $type = 'vote';
            $who = $user;
        } else {
            $type = 'problem';
            $who = get_negative_vote($event->vote_value);
            // Show user_login if she voted more than N negatives in one minute
            if ($current_user->user_id > 0 && ($current_user->user_level == 'admin' || $current_user->user_level == 'god')) {
                $negatives_last_minute = $db->get_var("select count(*) from votes where vote_type='links' and vote_user_id={$uid} and vote_date > date_sub(now(), interval 1 minute) and vote_value < 0");
                if ($negatives_last_minute > 2) {
                    $who .= "<br>({$user})";
                }
            }
        }
        $status = get_status($event->link_status);
        $key = $event->timestamp . ':votes:' . $id;
        $events[$key] = 'ts:"' . $event->timestamp . '",type:"' . $type . '",votes:"' . $event->link_votes . '", com:"' . $event->link_comments . '",link:"' . $link . '",title:"' . addslashes($event->link_title) . '",who:"' . addslashes($who) . '",status:"' . $status . '",uid:"' . $uid . '",md5:"' . $md5 . '"';
        //echo "($key)". $events[$key];
        if ($event->timestamp > $last_timestamp) {
            $last_timestamp = $event->timestamp;
        }
    }
}
示例#11
0
 function print_shake_box()
 {
     global $current_user, $anonnymous_vote, $site_key, $globals;
     switch ($this->status) {
         case 'queued':
             // another color box for not-published
             $box_class = 'mnm-queued';
             break;
         case 'abuse':
             // another color box for discarded
         // another color box for discarded
         case 'autodiscard':
             // another color box for discarded
         // another color box for discarded
         case 'discard':
             // another color box for discarded
             $box_class = 'mnm-discarded';
             break;
         case 'published':
             // default for published
         // default for published
         default:
             $box_class = 'mnm-published';
             break;
     }
     echo '<div class="news-shakeit">';
     echo '<div class="' . $box_class . '">';
     echo '<a id="a-votes-' . $this->id . '" href="' . $this->get_relative_permalink() . '">' . ($this->votes + $this->anonymous) . '</a></div>';
     echo '<div class="menealo" id="a-va-' . $this->id . '">';
     if ($this->votes_enabled == false) {
         echo '<span>' . _('cerrado') . '</span>';
     } elseif (!$this->voted) {
         echo '<a href="javascript:menealo(' . "{$current_user->user_id},{$this->id}" . ')" id="a-shake-' . $this->id . '">' . _('menéalo') . '</a>';
     } else {
         if ($this->voted > 0) {
             $mess = _('¡chachi!');
             $sty = '';
         } else {
             $mess = get_negative_vote($this->voted);
             $sty = 'class="negative"';
         }
         echo '<span id="a-shake-' . $this->id . '" ' . $sty . '>' . $mess . '</span>';
     }
     echo '</div>' . "\n";
     echo '</div>' . "\n";
 }
示例#12
0
    $votes_page = 1;
} else {
    $votes_page = intval($_GET['p']);
}
$votes_page_size = 20;
$votes_offset = ($votes_page - 1) * $votes_page_size;
$votes_users = $db->get_var("SELECT count(*) FROM votes WHERE vote_type='links' and vote_link_id=" . $globals['link_id'] . " AND vote_user_id!=0 AND vote_value > 0");
$votes_anon = $db->get_var("SELECT count(*) FROM votes WHERE vote_type='links' and vote_link_id=" . $globals['link_id'] . " AND vote_user_id=0 AND vote_value > 0");
echo '<div class="news-details">';
echo _('votos usuarios') . ': ' . $votes_users . ',&nbsp;&nbsp;';
echo _('votos anónimos') . ': ' . $votes_anon;
$negatives = $db->get_results("select vote_value, count(vote_value) as count from votes where vote_type='links' and vote_link_id=" . $globals['link_id'] . " and vote_value < 0 group by vote_value order by count desc");
if ($negatives) {
    foreach ($negatives as $negative) {
        echo ',&nbsp; ';
        echo get_negative_vote($negative->vote_value) . ':&nbsp;' . $negative->count;
    }
}
echo '</div>';
if ($no_show_voters) {
    // don't show voters if the user votes the link
    echo '<br /><br />&#187;&nbsp;' . '<a href="javascript:get_votes(\'meneos.php\',\'voters\',\'voters-container\',1,' . $globals['link_id'] . ')" title="' . _('quiénes han votado') . '">' . _('ver quiénes han votado') . '</a>';
} else {
    //echo '<script type="text/javascript">var update_voters=true;</script>';
    $votes = $db->get_results("SELECT vote_user_id, user_avatar, user_login, date_format(vote_date,'%d/%m %T') as date FROM votes, users WHERE vote_type='links' and vote_link_id=" . $globals['link_id'] . " AND vote_user_id > 0 AND vote_value > 0 AND user_id = vote_user_id ORDER BY vote_date ASC LIMIT {$votes_offset},{$votes_page_size}");
    if (!$votes) {
        die;
    }
    echo '<div class="voters-list">';
    foreach ($votes as $vote) {
        echo '<div class="item">';
示例#13
0
function get_votes($dbtime)
{
    global $db, $globals, $events, $last_timestamp, $max_items, $current_user;
    if ($globals['subs']) {
        $filter = 'and sub_statuses.id in (' . $globals['subs'] . ')';
    } else {
        $filter = '';
    }
    $res = $db->get_results("select vote_link_id, vote_id, unix_timestamp(vote_date) as timestamp, vote_value, INET_NTOA(vote_ip_int) as vote_ip, vote_user_id, user_login, user_level from votes LEFT JOIN users on (user_id = vote_user_id), sub_statuses where vote_type='links' and vote_date > {$dbtime} and sub_statuses.link = vote_link_id {$filter} order by vote_date desc limit {$max_items}");
    if (!$res) {
        return;
    }
    foreach ($res as $event) {
        $link = Link::from_db($event->vote_link_id, null, false);
        if (!$link) {
            continue;
        }
        if ($current_user->user_id > 0) {
            if (!empty($_REQUEST['friends']) && $event->vote_user_id != $current_user->user_id) {
                // Check the user is a friend
                if (User::friend_exists($current_user->user_id, $event->vote_user_id) <= 0) {
                    continue;
                } elseif ($event->vote_value < 0) {
                    // If the vote is negative, verify also the other user has selected as friend to the current one
                    if (User::friend_exists($event->vote_user_id, $current_user->user_id) <= 0) {
                        continue;
                    }
                }
            } elseif (!empty($_REQUEST['admin']) && $current_user->admin) {
                if ($event->user_level != 'admin' && $event->user_level != 'god') {
                    continue;
                }
            }
        }
        if ($event->vote_value >= 0) {
            if ($_REQUEST['novote']) {
                continue;
            }
            if ($link->get_a_status() == 'published' && $_REQUEST['nopubvotes']) {
                continue;
            }
        } else {
            if ($_REQUEST['noproblem']) {
                continue;
            }
        }
        $uid = $event->vote_user_id;
        if ($event->vote_user_id > 0) {
            $user = $event->user_login;
        } else {
            $user = preg_replace('/(\\.[0-9]+|){2}$|(:[0-9a-f]*){4}$/i', '', $event->vote_ip) . '&hellip;';
        }
        if ($event->vote_value >= 0) {
            $type = 'vote';
            $who = $user;
        } else {
            $type = 'problem';
            $who = get_negative_vote($event->vote_value);
            // Show user_login if she voted more than N negatives in one minute
            if ($current_user->user_id > 0 && $current_user->admin) {
                $negatives_last_minute = $db->get_var("select count(*) from votes where vote_type='links' and vote_user_id={$event->vote_user_id} and vote_date > date_sub(now(), interval 30 second) and vote_value < 0");
                if ($negatives_last_minute > 2) {
                    $who .= "<br>({$user})";
                }
            }
        }
        $json['status'] = get_status($link->get_a_status());
        $json['sub_name'] = $link->sub_name;
        $json['type'] = $type;
        $json['ts'] = $event->timestamp;
        $json['votes'] = $link->total_votes;
        $json['com'] = $link->comments;
        $json['link'] = $link->get_relative_permalink();
        $json['title'] = $link->title;
        $json['who'] = $who;
        $json['uid'] = $event->vote_user_id;
        $json['id'] = $link->id;
        if ($event->vote_user_id > 0) {
            $json['icon'] = get_avatar_url($event->vote_user_id, -1, 20);
        }
        $key = $event->timestamp . ':votes:' . $event->vote_id;
        $events[$key] = $json;
        if ($event->timestamp > $last_timestamp) {
            $last_timestamp = $event->timestamp;
        }
    }
}
示例#14
0
	function print_problem_form() {
		global $current_user, $db, $anon_karma, $anonnymous_vote, $globals, $site_key;
		require_once(mnminclude.'votes.php');

		$vote = new Vote;
		$vote->link=$this->id;
		$vote->type='links';
		$vote->user=$current_user->user_id;
		if(/*!$current_user->user_id > 0 || */ (!$anonnymous_vote && $current_user->user_id == 0 ) || $this->voted) {
			// don't show it for now
			return;
			$status='disabled="disabled"';
		}
		//echo '<span class="tool-right">';
		echo '<form class="tool" action="" id="problem-'.$this->id.'">';
		echo '<select '.$status.' name="ratings"  onchange="';
		echo 'report_problem(this.form,'."$current_user->user_id, $this->id, "."'".md5($site_key.$current_user->user_id.$this->randkey.$globals['user_ip'])."'".')';
		echo '">';
		echo '<option value="0" selected="selected">¿problema?</option>';
		for ($pvalue = -1; $pvalue > -7; $pvalue--) {
			echo '<option value="'.$pvalue.'">'.get_negative_vote($pvalue).'</option>';
		}
		echo '</select>';
//		echo '<input type="hidden" name="return" value="" disabled />';
		echo '</form>';
	}