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; }
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; }
} 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') {
/** * Вывод рейтингов * * @param array $topic Данные по комментарию * @param integer $mod Битовая маска прав пользователя * @param integer $user_id ИД пользователя * @return string */ function __commPrntTopicRating($topic, $mod, $user_id = NULL) { // var_dump($topic); if (!$user_id) { $user_id = get_uid(false); } // if($rating===NULL) // $rating = (int)$topic['vote'] ? (int)$topic['vote'] : 0; // if($user_id){ $vote = $topic['user_vote']; // } $rating = $topic['rating']; // echo $rating.'<br/>'; $p_onClick = ''; $m_onClick = ''; $p_href = ''; $m_href = ''; $p_alt = ''; $m_alt = ''; $onclick = ''; $ponclick = ''; $monclick = ''; // var_dump($user_id.' > '.$topic['user_id']); $uStatus = commune::GetUserCommuneRel($topic['commune_id'], $user_id); // можно ли голосовать //$allow_vote = $user_id && $user_id != $topic['user_id']; // можно ли голосовать за топик // var_dump($uStatus); //if( ((!$uStatus || !$uStatus['is_accepted']) && (!$uStatus['is_author'] && $topic['user_id'] != $user_id )) if ($uStatus && ($uStatus['is_accepted'] || $uStatus['is_author']) && $topic['is_blocked_c'] != 't' && $topic['user_id'] != $user_id && !$uStatus['is_deleted'] && !$uStatus['is_banned'] && !is_banned($user_id) && !$topic['deleted_id'] && commune_carma::isAllowedVote()) { $allow_vote = true; } else { $allow_vote = false; } if (!$allow_vote) { $ponclick = ' href=""'; $monclick = ' href=""'; } else { $ponclick = $vote <= 0 ? "if(!lockRating{$topic['id']}) xajax_VoteTopic({$topic['id']}, {$user_id}, {$mod}, 1); lockRating{$topic['id']} = 1;" : false; $monclick = $vote >= 0 ? "if(!lockRating{$topic['id']}) xajax_VoteTopic({$topic['id']}, {$user_id}, {$mod}, -1); lockRating{$topic['id']} = 1; " : false; } if ($ponclick) { // $p_onClick = " onclick=\"try { if(!lockRating{$topic['id']}) {$ponclick}, 1); lockRating{$topic['id']}=1; } catch(e) { }\""; $p_href = " href='javascript:void(0)'"; $p_onClick = " onclick=\"{$ponclick}\""; $p_alt = " alt='+'"; } if ($monclick) { // $m_onClick = " onclick=\"try { if(!lockRating{$topic['id']}) {$monclick}, -1); lockRating{$topic['id']}=1; } catch(e) { }\""; $m_href = " href='javascript:void(0)'"; $m_onClick = " onclick=\"{$monclick}\""; $m_alt = " alt='-'"; } if ($topic['user_is_team'] != 't') { ob_start(); ?> <script>var lockRating<?php echo $topic['id']; ?> =0;</script> <?php $classname = $rating < 0 ? '_color_red' : ($rating >= 1 ? '_color_green' : ''); ?> <div class="b-voting b-voting_float_right"> <?php if ($allow_vote && $vote <= 0) { ?> <a class="b-button b-button_poll_plus normal_behavior b-button_active b-voiting__right" <?php echo $p_href . $alt . $p_onClick; ?> ></a> <?php } else { ?> <a class="b-button b-button_poll_plus normal_behavior b-button_poll_nopointer b-voiting__right"></a> <?php } ?> <?php if ($allow_vote && $vote >= 0) { ?> <a class="b-button b-button_poll_minus normal_behavior b-button_active b-voiting__left" <?php echo $p_href . $alt . $m_onClick; ?> ></a> <?php } else { ?> <a class="b-button b-button_poll_minus normal_behavior b-button_poll_nopointer b-voiting__left"></a> <?php } ?> <span class="b-voting__mid b-voting__mid<?php echo $classname; ?> " id="idCommRatingValue_<?php echo $comm['id']; ?> "> <?php echo ($rating > 0 ? '+' : ($rating < 0 ? '−' : '')) . abs(intval($rating)); ?> </span> </div> <?php $str = ob_get_contents(); ob_end_clean(); } return $str; }