コード例 #1
0
function RateComment($sname, $item, $dir)
{
    session_start();
    $objResponse = new xajaxResponse();
    $uid = get_uid(false);
    if (!$uid) {
        return $objResponse;
    }
    $obj = null;
    switch (strtolower($sname)) {
        case 'commune':
            if (!commune_carma::isAllowedVote()) {
                return $objResponse;
            }
            require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/comments/CommentsCommune.php';
            $comments = new CommentsCommune($item);
            $data = $comments->getData($item);
            if ($data['author'] == $uid) {
                return $objResponse;
            }
            // За свой коммент голосовать нельзя
            break;
        default:
            return $objResponse;
    }
    $result = $comments->RateComment($uid, $item, $dir);
    $jsfunct = 'RateCommentCallback';
    if ($comments->is_new_template) {
        $jsfunct = 'RateCommentCallbackNew';
    }
    $objResponse->call($jsfunct, $item, $dir);
    return $objResponse;
}
コード例 #2
0
ファイル: commune.server.php プロジェクト: kapai69/fl-ru-damp
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;
}
コード例 #3
0
ファイル: index.php プロジェクト: kapai69/fl-ru-damp
 }
 if ($top['close_comments'] == 't') {
     $params['no_comments'] = true;
     $params['readonly'] = 1;
 }
 if ($is_user_member) {
     $params['readonly_alert'] = 'Комментирование закрыто.';
 }
 $params['is_permission'] = commune::setAccessComments($user_mod);
 if (!$params['is_permission'] && $is_top_author) {
     $params['is_permission'] = 4;
 }
 if (commune::isBannedCommune($user_mod) || $top['deleted_id']) {
     $params['readonly'] = 1;
 }
 if (!commune_carma::isAllowedVote()) {
     $params['deny_vote'] = true;
 }
 if (__paramInit('string', 'cmtask', 'cmtask') == 'delete' || __paramInit('string', 'cmtask', 'cmtask') == 'restore') {
     if ($_GET['token'] != $_SESSION['rand']) {
         header('Location: /404.php');
         exit;
     }
 }
 $comments = new CommentsCommune($top['id'], $top['last_viewed_time'], $params);
 $comments->tpl_path = $_SERVER['DOCUMENT_ROOT'] . '/classes/comments/';
 $comments_html = $comments->render();
 $js_file_utf8[] = '/scripts/ckedit/ckeditor.js';
 $js_file[] = '/scripts/commune_card.js';
 // если собираемся редактировать пост
 if (__paramInit('string', 'taction') === 'edit') {
コード例 #4
0
ファイル: commune.php プロジェクト: Nikitian/fl-ru-damp
 /**
 * Голосование
 *
 * @param integer $commune_id ИД сообщества
 * @param integer $user_id    Ид пользователя
 * @param integer $rating       Голос
 * @return  Возвращает: -1, если голос ПРОТИВ был принят; 1, если голос ЗА был принят;
    				0, если голос не принят или ошибка.
  			Принят -- то есть, пошел в расчет, рейтинг изменился.
 */
 function TopicVote($topic_id, $user_id, $rating)
 {
     global $DB;
     $vB = (int) self::GetUserTopicVote($topic_id, $user_id);
     if ($vB == 0) {
         $rating = $rating > 0 ? 1 : -1;
     } elseif ($vB < 0 && $rating > 0) {
         $rating = 0;
     } elseif ($vB > 0 && $rating < 0) {
         $rating = 0;
     } elseif ($vB == $rating) {
         return 0;
     } elseif ($vB < 0 && $rating < 0) {
         return 0;
     } elseif ($vB > 0 && $rating > 0) {
         return 0;
     }
     $sql = "UPDATE commune_users_messages SET rating = ?i\n            WHERE message_id = ?i\n                AND user_id = ?i;";
     $res = $DB->query($sql, $rating, $topic_id, $user_id);
     if (!pg_affected_rows($res)) {
         $insert_table = self::getTableName('commune_users_messages', self::getCommuneIDByMessageID($topic_id));
         $sql = "INSERT INTO {$insert_table} (message_id, user_id, rating)\n                VALUES (?i, ?i, ?i)";
         $res = $DB->query($sql, $topic_id, $user_id, $rating);
     }
     $rate = self::GetTopicRating($topic_id);
     $actionRate = commune_carma::actionByRate($rate, commune_carma::getScale('post'));
     if ($actionRate == 'banned') {
         $themes = current(commune::getCommunePostByIds(array($topic_id)));
         if (!commune_carma::isImmunity($themes['user_id'], array(), $topic_id) && $themes['id'] > 0) {
             commune::BlockedTopic($themes['theme_id'], $topic_id, 'block');
         }
     }
     //    $vB = (int)self::GetUserTopicVote($topic_id, $user_id);
     $vA = (int) self::GetUserTopicVote($topic_id, $user_id);
     return ($vA > $vB) - ($vA < $vB);
 }