示例#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
/**
 * Блокировка/разблокировка топика администратором free-lance.ru
 * 
 * @param  int    $commune_id  ID сообщества
 * @param  int    $topic_id    ID топика
 * @param  int    $topic_id    ID сообщения
 * @param  string $reason      Причина
 * @param  int    $reason_id   ID причины, если она выбрана из списка (таблица admin_reasons, где act_id = 15)
 * @param  string $reason_name Краткое описание причины действия (из селекта) для лога админских действий
 * @return object xajaxResponse
 */
function BlockedCommuneTheme($commune_id = 0, $topic_id = 0, $msg_id = 0, $reason, $reason_id = null, $reason_name = '')
{
    global $DB;
    session_start();
    $objResponse = new xajaxResponse();
    $commune_id = intval($commune_id);
    $topic_id = intval($topic_id);
    $msg_id = intval($msg_id);
    if (hasPermissions('communes')) {
        require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/commune.php';
        if (is_string($reason) && $reason != '') {
            if (hasPermissions('communes')) {
                $count = $DB->val('SELECT COUNT(*) FROM commune_themes WHERE id = ?', $topic_id);
                if ($count) {
                    $commune = new commune();
                    $topic = commune::GetTopMessageByAnyOther($msg_id, $_SESSION['uid'], commune::MOD_ADMIN);
                    // лог админских действий
                    $sObjName = $topic['title'];
                    $sObjLink = '/commune/?id=' . $commune_id . '&site=Topic&post=' . $msg_id;
                    $reason_id = $reason_id ? $reason_id : null;
                    $reason = str_replace('%USERNAME%', $topic['user_uname'] . ' ' . $topic['user_usurname'], $reason);
                    $reason = change_q($reason, FALSE, 0, TRUE);
                    if ($topic['is_blocked_s'] == 't') {
                        $commune->unblockedCommuneTheme($topic_id);
                        // пишем лог админских действий
                        admin_log::addLog(admin_log::OBJ_CODE_COMM, 16, $topic['user_id'], $topic_id, $sObjName, $sObjLink, 0, '', $reason_id, $reason);
                        $objResponse->assign("theme-reason-{$topic_id}", 'innerHTML', ' ');
                        $objResponse->assign("theme-button-{$topic_id}", 'innerHTML', '<a href="javascript:void(0)" onclick="banned.blockedCommuneTheme(' . $commune_id . ',' . $topic_id . ',' . $msg_id . ')" class="lnk-red">Заблокировать</a>');
                    } else {
                        $commune->blockedCommuneTheme($topic, $reason, $reason_id, $_SESSION['uid']);
                        // пишем лог админских действий
                        admin_log::addLog(admin_log::OBJ_CODE_COMM, 15, $topic['user_id'], $topic_id, $sObjName, $sObjLink, 0, '', $reason_id, $reason, $topic_id);
                        $reason = reformat($reason, 24, 0, 0, 1, 24);
                        $html = BlockedCommuneThemeHTML($reason);
                        $objResponse->assign("theme-reason-{$topic_id}", 'innerHTML', $html);
                        $objResponse->assign("theme-button-{$topic_id}", 'innerHTML', '<a href="javascript:void(0)" onclick="banned.unblockedCommuneTheme(' . $commune_id . ',' . $topic_id . ',' . $msg_id . ')" class="lnk-red">Разблокировать</a>');
                    }
                } else {
                    $objResponse->alert('Несуществующее сообщение в сообществе');
                }
            }
        }
    }
    return $objResponse;
}
示例#3
0
 /**
  * Сообщества. Утверждение/удаление записи
  * 
  * @param  string $stream_id идентификатор потока
  * @param  int $user_id идентификатор модератора
  * @param  int $from_id идентификатор пользователя
  * @param  int $rec_id идентификатор записи
  * @param  int $rec_type тип записи 
  * @param  int $action действие: 1 - утверждено, 2 - удалено
  * @param  string $is_sent было ли отправлено уведомление
  * @param  string $reason причина удаления
  * @return bool true - успех, false - провал
  */
 function resolveCommunity($stream_id = '', $user_id = 0, $from_id = 0, $rec_id = 0, $rec_type = 0, $action = 1, $is_sent = '', $reason = '')
 {
     $bRet = false;
     $sQuery = 'UPDATE moderation SET moder_num = ?i, status = ?i WHERE rec_id = ?i AND rec_type = ?i AND stream_id = ? RETURNING rec_id';
     $sRecId = $GLOBALS['DB']->val($sQuery, $this->nResolveCnt, $action, $rec_id, self::MODER_COMMUNITY, $stream_id);
     if ($sRecId) {
         $bRet = true;
         if ($rec_type == 1) {
             // топик
             $GLOBALS['DB']->update('commune_messages', array('moderator_status' => $user_id, 'mod_access' => 1), 'id = ?i', $rec_id);
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/commune.php';
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/admin_log.php';
             $commune = new commune();
             $topic = commune::GetTopMessageByAnyOther($rec_id, $user_id, commune::MOD_ADMIN);
             $sObjName = $topic['title'];
             $sObjLink = getFriendlyURL('commune', $rec_id);
             if ($action == 1 && $topic['is_blocked_s'] == 't') {
                 //утверждаем
                 $commune->unblockedCommuneTheme($topic['theme_id']);
                 admin_log::addLog(admin_log::OBJ_CODE_COMM, 16, $from_id, $topic['theme_id'], $sObjName, $sObjLink, 0, '', 0, '');
             } elseif ($action == 2 && $topic['is_blocked_s'] != 't') {
                 $commune->blockedCommuneTheme($topic, $reason, 0, $user_id, true);
                 admin_log::addLog(admin_log::OBJ_CODE_COMM, 15, $from_id, $topic['theme_id'], $sObjName, $sObjLink, 0, '', 0, $reason, $topic['theme_id']);
             }
         } else {
             // комментарий
             $aData = array('moderator_status' => $user_id, 'mod_access' => 1);
             if ($action == 1 && $is_sent == 'f') {
                 // отправка уведомления о новом сообщении
                 /*require_once( $_SERVER['DOCUMENT_ROOT'] . '/classes/pmail.php' );
                 
                                     $pmail = new pmail;
                                     $pmail->CommuneNewComment( $rec_id );*/
                 $aData['is_sent'] = true;
                 // устанавливаем флаг отправки
             }
             $aRow = $GLOBALS['DB']->row('SELECT theme_id, deleted_id FROM commune_messages WHERE id = ?i', $rec_id);
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/comments/CommentsCommune.php';
             $comments = new CommentsCommune($aRow['theme_id']);
             if ($action == 1 && $aRow['deleted_id'] && $aRow['deleted_id'] != $from_id) {
                 $comments->restore($rec_id);
             } elseif ($action == 2 && $aRow['deleted_id'] != $from_id) {
                 $comments->delete($rec_id, $from_id, true);
                 $aData['deleted_reason'] = $reason;
             }
             $GLOBALS['DB']->update('commune_messages', $aData, 'id = ?i', $rec_id);
         }
     }
     return $bRet;
 }
示例#4
0
 /**
  * Удаление сообщение.
  *
  * @param integer $message_id     Ид сообщения
  * @param integer $user_id        Кто удаляет
  * @param integer $user_mod       Права удаляющего
  * @param string  &$deleted_time  Время удаления комментария 
  * @return integer 1 если удаление прошл успешно, иначе 0
  */
 function DeleteMessage($message_id, $user_id, $user_mod = 0, &$deleted_time)
 {
     global $DB;
     $message = commune::GetTopMessageByAnyOther($message_id, $_SESSION['uid'], $user_mod);
     if (get_uid(false)) {
         $comm = commune::getCommuneIDByMessageID($message_id);
         $status = commune::GetUserCommuneRel($comm, get_uid(false));
     }
     if ($message['user_id'] != get_uid(false) && !hasPermissions('communes') && !($status['is_moderator'] == 1 || $status['is_admin'] == 1 || $status['is_author'] == 1)) {
         return 0;
         // Чужой топик удалять нельзя если ты не админ сайта
     }
     if (!$message['parent_id']) {
         $uid = get_uid(false);
         $deleted_time = date('Y-m-d H:i:s');
         //modified_id обновляю исключительно ради получения имени удалившего модератора, т к в запросе итак предостаточно джоинов. Если спама об редактировании не начнет приходить, то думаю можно оставить
         $sql = "UPDATE commune_messages SET deleted_id = {$uid}, modified_id = {$uid}, deleted_time = '{$deleted_time}' WHERE id = ?i RETURNING theme_id, parent_id";
         if ($res = $DB->query($sql, $message_id)) {
             if (pg_affected_rows($res)) {
                 // Пересчитать позиции
                 list($theme_id, $parent_id) = pg_fetch_row($res);
                 if (!$parent_id && $theme_id) {
                     $sql = "SELECT re_pos_commune_themes(?i, (SELECT pos FROM commune_themes WHERE id = ?i), NULL);";
                     $DB->query($sql, $message['commune_id'], $theme_id);
                 }
                 // уведомление об удалении, если удаляет админ
                 if ($message['user_id'] != $user_id) {
                     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/messages.php';
                     $commune = self::GetCommune($message['commune_id'], get_uid(0));
                     $member = self::getMember($message['commune_id'], get_uid(0), self::MEMBER_ADMIN | self::MEMBER_MODERATOR);
                     if ($commune['author_uid'] == get_uid(0)) {
                         $deleter = 'admin';
                     } elseif ($member) {
                         $deleter = 'moder';
                     } else {
                         $deleter = 'site-moder';
                     }
                     messages::SendDeletedCommuneTheme($message, $deleter);
                 }
                 require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/user_content.php';
                 $DB->query('DELETE FROM moderation WHERE rec_id = ?i AND rec_type = ?i', $message_id, user_content::MODER_COMMUNITY);
                 return 1;
             } else {
             }
             // Не удалилось. Значит будем делать UPDATE.
         } else {
             return 0;
         }
     }
     $sql = "UPDATE commune_messages\n               SET deleted_time = LOCALTIMESTAMP,\n                   deleted_id = ?i,\n                   modified_id = ?i\n            WHERE id = ?i RETURNING *";
     if ($res = $DB->query($sql, $user_id, $user_id, $message['id'])) {
         return -1;
     }
     return 0;
 }