示例#1
0
function VoteTopic($topic_id, $user_id, $mod, $vote)
{
    global $session;
    session_start();
    $objResponse = new xajaxResponse();
    if (!get_uid(false)) {
        return $objResponse;
    }
    if (get_uid(false) != $user_id) {
        return $objResponse;
    }
    if (!commune_carma::isAllowedVote()) {
        return $objResponse;
    }
    // !!! Вообще, везде бы, где ajax, проверку такую делать.
    $topic = commune::GetTopMessageByAnyOther($topic_id, $user_id, $mod);
    $uStatus = commune::GetUserCommuneRel($topic['commune_id'], $user_id);
    if ((!$uStatus || !$uStatus['is_accepted']) && (!$uStatus['is_author'] && $topic['user_id'] != $user_id) || $uStatus['is_deleted'] || $uStatus['is_banned'] || is_banned($user_id)) {
        $objResponse->script("lockRating{$topic_id}=0;");
        return $objResponse;
    } else {
        if ($topic && !$topic['is_blocked']) {
            $v = commune::TopicVote($topic_id, $user_id, intval($vote));
            //        $rating = intval($prev_rating) + $v;
            //$rating = commune::GetTopicRating($topic_id);
            $html = __commPrntTopicRating(commune::GetTopMessageByAnyOther($topic_id, $user_id, commune::MOD_COMM_MODERATOR), $mod, $user_id);
            $objResponse->assign('topicRate_' . $topic_id, 'innerHTML', $html);
            $objResponse->script("if(window.lockRating{$topic_id}) lockRating{$topic_id}=0;");
        }
    }
    return $objResponse;
}
示例#2
0
 /**
  * Голосование в комментах
  *
  * @param <type> $uid       ид пользователя
  * @param <type> $id        ид комментария
  * @param <type> $dir       голос +1/-1
  */
 public function RateComment($uid, $id, $dir)
 {
     if (!$uid) {
         return false;
     }
     $res = commune::TopicVote($id, $uid, $dir);
     return $res;
 }