function IndexForumRestoreBasketTopic($topic_id = 0, $go_back = true)
{
    global $forum_lang;
    if (!System::user()->isAdmin()) {
        HackOff();
        return;
    }
    $topic = System::database()->Select('forum_topics', "`id`='{$topic_id}' and `delete`='1'");
    if (count($topic) > 0) {
        $topic = $topic[0];
        $forum_id = SafeEnv($topic['forum_id'], 11, int);
        // Восстанавливаем количество сообщений и тем для форума
        System::database()->Select('forums', "`id`='{$forum_id}'");
        if (System::database()->NumRows() == 0) {
            // Форум не найден
            System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_forum']);
            return;
        }
        $forum = System::database()->FetchRow();
        $forum_topics = SafeEnv($forum['topics'], 11, int) + 1;
        if ($forum_topics < 0) {
            $forum_topics = 0;
        }
        $forum_posts = SafeEnv($forum['posts'], 11, int) + SafeEnv($topic['posts'], 11, int);
        if ($forum_posts < 0) {
            $forum_posts = 0;
        }
        $forum_set = "`topics`='{$forum_topics}',`posts`='{$forum_posts}'";
        System::database()->Update('forums', $forum_set, "`id`='{$forum_id}'");
        // Восстанавливаем тему
        System::database()->Update('forum_topics', "`delete`='0'", "`id`='{$topic_id}'");
        // Удаляем метку в корзине
        System::database()->Delete('forum_basket_topics', "`obj_id`='{$topic_id}'");
        // Устанавливаем инф-ю о последнем сообщении для темы и форума
        ForumSetLastPost($topic_id);
        ForumSetLastTopic($forum_id);
        // Очищаем кэш форума
        ForumCacheClear();
        if ($go_back) {
            if (isset($_GET['back'])) {
                GoRefererUrl($_GET['back']);
            } else {
                GoBack();
            }
        }
    } else {
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_topic']);
        return;
    }
}
function IndexForumCloseTopic()
{
    if (!System::user()->isAdmin()) {
        HackOff();
        return;
    }
    if (CheckGet('topic')) {
        $topic_id = SafeEnv($_GET['topic'], 11, int);
    } else {
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_data']);
        return;
    }
    System::database()->Select('forum_topics', "`id`='{$topic_id}'");
    $topic = System::database()->FetchRow();
    $forum_id = SafeDB($topic['forum_id'], 11, int);
    System::database()->Update('forum_topics', "`close_topics`='1'", "`id`='{$topic_id}'");
    GO(Ufu('index.php?name=forum&op=showforum&forum=' . $forum_id, 'forum/{forum}/'));
}
function IndexPollsViewPoll($op)
{
    $id = SafeEnv($_GET['poll_id'], 11, int);
    System::database()->Select('polls', GetWhereByAccess('view', "`id`='{$id}' and `active`='1'"));
    if (System::database()->NumRows() == 0) {
        HackOff();
    }
    $poll = System::database()->FetchRow();
    $question = SafeDB($poll['question'], 255, str);
    System::site()->SetTitle($question);
    System::site()->BreadCrumbAdd($question);
    // Отвечал ли пользователь
    $ip = getip();
    if (System::user()->Auth) {
        $uid = System::user()->Get('u_id');
    } else {
        $uid = -1;
    }
    System::database()->Select('polls_voices', "`poll_id`='{$id}' and (`user_ip`='{$ip}' or `user_id`='{$uid}')");
    $viewresult = System::database()->NumRows() != 0;
    $viewresult = $viewresult || $op == 'viewresult' && (System::config('polls/show_results') == '1' || System::user()->isAdmin());
    $answers = unserialize($poll['answers']);
    $c = count($answers);
    $num_voices = 0;
    for ($i = 0; $i < $c; $i++) {
        $num_voices += SafeDB($answers[$i][2], 11, int);
    }
    if ($viewresult) {
        if ($num_voices != 0) {
            $per_c = 100 / $num_voices;
        } else {
            $per_c = 0;
        }
        System::site()->AddTemplatedBox('', 'module/poll_result.html');
        $vars = array('lresults_title' => 'Результаты опроса', 'lrvalue' => 'гол.');
        System::site()->AddBlock('poll_result_rows', true, true, 'pr');
        $c = count($answers);
        for ($i = 0; $i < $c; $i++) {
            if ($answers[$i][0] != '') {
                $title = SafeDB($answers[$i][0], 255, str);
                $color = SafeDB($answers[$i][1], 255, str);
                $value = round($per_c * $answers[$i][2]);
                $num_voices2 = SafeDB($answers[$i][2], 11, int);
                System::site()->AddSubBlock('poll_result_rows', true, array('answertext' => $title, 'value' => $value, 'num_voices' => $num_voices2, 'color' => $color));
            }
        }
    } else {
        System::site()->AddTemplatedBox('', 'module/poll.html');
        $vars = array();
        $vars['form_action'] = Ufu('index.php?name=polls&op=voice&poll_id=' . SafeDB($poll['id'], 11, int), 'polls/{poll_id}/voice/');
        System::site()->AddBlock('poll_variants', true, true, 'variant');
        for ($i = 0; $i < $c; $i++) {
            if ($answers[$i][0] != '') {
                $color = SafeDB($answers[$i][1], 255, str);
                $title = SafeDB($answers[$i][0], 255, str);
                if ($poll['multianswers'] == '1') {
                    $control = System::site()->Check('voice[]', $i);
                } else {
                    $control = System::site()->Radio('voice[]', $i);
                }
                System::site()->AddSubBlock('poll_variants', true, array('title' => $title, 'control' => $control, 'color' => $color));
            }
        }
        $vars['poll_showresults'] = System::config('polls/show_results') == '1' || System::user()->isAdmin();
        $vars['showresults_url'] = Ufu('index.php?name=polls&op=viewresult&poll_id=' . $id, 'polls/{poll_id}/results/');
        $vars['others_url'] = Ufu('index.php?name=polls', '{name}/');
    }
    $vars['title'] = $question;
    $vars['back_url'] = Ufu('index.php?name=polls', '{name}/');
    $vars['back_caption'] = 'Назад к списку';
    $vars['lnum_voices'] = 'Ответов';
    $vars['num_voices'] = $num_voices;
    $vars['lcomments'] = 'Комментариев';
    $vars['comments'] = SafeDB($poll['com_counter'], 11, int);
    System::site()->AddBlock('poll', true, false, '');
    System::site()->Blocks['poll']['vars'] = $vars;
    // Выводим комментарии
    if (isset($_GET['page'])) {
        $nav_page = SafeEnv($_GET['page'], 11, int);
    } else {
        $nav_page = 0;
    }
    $posts = new Posts('polls_comments', $poll['allow_comments'] == '1');
    $posts->PostFormAction = "index.php?name=polls&op=addpost&poll_id={$id}&page={$nav_page}";
    $posts->EditPageUrl = "index.php?name=polls&op=editpost&poll_id={$id}";
    $posts->DeletePageUrl = "index.php?name=polls&op=deletepost&poll_id={$id}";
    $posts->NavigationUrl = Ufu("index.php?name=polls&op=viewpoll&poll_id={$id}", 'polls/{poll_id}/page{page}/', true);
    $posts->RenderPosts($id, 'poll_comments', 'comments_navigation', false, $nav_page);
    $posts->RenderForm(false, 'poll_comments_form');
}
}
System::site()->SetTitle('Обратная связь');
if (isset($_GET['op'])) {
    $op = $_GET['op'];
} else {
    $op = 'main';
}
switch ($op) {
    case 'main':
        IndexFeedBackForm();
        break;
    case 'send':
        IndexFeedBackSend();
        break;
    default:
        HackOff();
}
function IndexFeedBackForm($errors = false)
{
    System::site()->AddTemplatedBox('Обратная связь', 'module/feedback.html');
    if (System::config('feedback/max_filesize') > intval(ini_get('upload_max_filesize'))) {
        $max_file_size = intval(ini_get('upload_max_filesize')) . 'Мб';
    } else {
        $max_file_size = System::config('feedback/max_filesize') . 'Мб';
    }
    System::site()->AddBlock('feedback', true, false, 'fb');
    $vars['url'] = Ufu('index.php?name=feedback&op=send', 'feedback/{op}/');
    if (!$errors) {
        $vars['top_text'] = System::config('feedback/top_text');
        $vars['bottom_text'] = System::config('feedback/bottom_text');
    } else {
function IndexForumDeletePost()
{
    global $forum_lang;
    if (!System::user()->isAdmin() || !CheckGet('topic', 'post', 'ok')) {
        HackOff();
        return;
    }
    if (isset($_GET['page']) && $_GET['page'] > 1) {
        $page = '&page=' . SafeDB($_GET['page'], 11, int);
        $page_ufu = '-{page}';
    } else {
        $page = '';
        $page_ufu = '';
    }
    // Подтверждение на удаление
    if (!isset($_GET['ok']) || !isset($_POST['text']) && System::config('forum/basket') || $_GET['ok'] == '0') {
        $text = '<br>' . $forum_lang['delete_post'] . '?';
        System::site()->AddTextBox($forum_lang['forum'], '<p align="center">' . $text . '</p>');
        System::site()->AddTemplatedBox('', 'module/forum_delete_post.html');
        System::site()->AddBlock('delete_form', true, false, 'form');
        $vars = array();
        $vars['basket'] = System::config('forum/basket');
        $vars['url'] = 'index.php?name=forum&op=deletepost&topic=' . SafeDB($_GET['topic'], 11, int) . '&post=' . SafeDB($_GET['post'], 11, int) . $page . '&ok=1';
        // Без UFU
        System::site()->Blocks['delete_form']['vars'] = $vars;
        return;
    }
    // Сообщение
    $post_id = SafeEnv($_GET['post'], 11, int);
    System::database()->Select('forum_posts', "`id`='{$post_id}'");
    if (System::database()->NumRows() == 0) {
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_post']);
        return;
    }
    $post = System::database()->FetchRow();
    if ($post['delete'] == '1') {
        // На удалении
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['post_basket']);
        return;
    }
    // Тема
    $topic_id = SafeEnv($_GET['topic'], 11, int);
    System::database()->Select('forum_topics', "`id`='{$topic_id}'");
    if (System::database()->NumRows() == 0) {
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_topic']);
        return;
    }
    $topic = System::database()->FetchRow();
    if ($topic['delete'] == '1') {
        // Тема на удалении
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['topic_basket']);
        return;
    }
    // Форум
    $forum_id = SafeEnv($topic['forum_id'], 11, int);
    System::database()->Select('forums', "`id`='{$forum_id}'");
    if (System::database()->NumRows() == 0) {
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_forum']);
        return;
    }
    $forum = System::database()->FetchRow();
    // Удаление поста
    if (System::config('forum/basket')) {
        // Удаляем сообщение в корзину
        $reason = '';
        if (isset($_POST['text'])) {
            $reason = SafeEnv($_POST['text'], 255, str);
        }
        Moderation_Do_Basket_Post($post_id, $reason);
    } else {
        ForumAdminDeletePost($post_id);
    }
    // Обновляем тему
    $topic_posts = (int) $topic['posts'] - 1;
    if ($topic_posts < 0) {
        $topic_posts = 0;
    }
    $topic_set = "`posts`='{$topic_posts}'";
    $topic_extra_set = false;
    // Удаляется последний пост в теме (нужно ли обновлять последний пост в форуме)
    if ($topic['last_post'] == $post['public'] && $topic['last_poster_id'] == $post['user_id']) {
        $topic_extra_set = true;
        $topic_set = ForumSetLastPost($topic_id, $topic_set, true);
    }
    System::database()->Update('forum_topics', $topic_set, "`id`='{$topic_id}'");
    // Обновляем форум
    $forum_posts = (int) $forum['posts'] - 1;
    if ($forum_posts < 0) {
        $forum_posts = 0;
    }
    $forum_set = "`posts`='{$forum_posts}'";
    if ($topic_extra_set) {
        // Только если удален последний пост в теме
        $forum_set = ForumSetLastTopic($forum_id, $forum_set, true);
    }
    System::database()->Update('forums', $forum_set, "`id`= '{$forum_id}'");
    // Очищаем кэш форума
    ForumCacheClear();
    GO(Ufu('index.php?name=forum&op=showtopic&topic=' . $topic_id . $page, 'forum/topic{topic}' . $page_ufu . '.html'));
}
function IndexForumDeleteTopic()
{
    global $forum_lang;
    if (!System::user()->isAdmin() || !CheckGet('topic', 'ok')) {
        HackOff();
        return;
    }
    $topic_id = SafeEnv($_GET['topic'], 11, int);
    // Подтверждение на удаление
    if (!isset($_GET['ok']) || !isset($_POST['text']) && System::config('forum/basket') || $_GET['ok'] == '0') {
        System::database()->Select('forum_topics', "`id`='" . SafeEnv($_GET['topic'], 11, int) . "'");
        $topic = System::database()->FetchRow();
        $text = $forum_lang['delete_topic'] . ' "' . SafeDB($topic['title'], 255, str) . '"?';
        System::site()->AddTextBox($forum_lang['forum'], '<p align="center">' . $text . '</p>');
        System::site()->AddTemplatedBox('', 'module/forum_delete_post.html');
        System::site()->AddBlock('delete_form', true, false, 'form');
        $vars = array();
        $vars['basket'] = System::config('forum/basket') == true;
        $vars['url'] = 'index.php?name=forum&op=deletetopic&topic=' . SafeEnv($_GET['topic'], 11, int) . '&ok=1';
        // Без UFU
        System::site()->Blocks['delete_form']['vars'] = $vars;
        return;
    }
    // Вытаскиваем тему
    System::database()->Select('forum_topics', "`id`='{$topic_id}'");
    if (System::database()->NumRows() == 0) {
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_topic']);
        return;
    }
    $topic = System::database()->FetchRow();
    if ($topic['delete'] == '1') {
        // Удалена в корзину
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['topic_basket']);
        return;
    }
    // Удаление
    if (System::config('forum/basket')) {
        // Удаляем тему в корзину
        $reason = '';
        if (isset($_POST['text'])) {
            $reason = SafeEnv($_POST['text'], 255, str);
        }
        Moderation_Do_Basket_Topic($topic_id, $reason);
    } else {
        ForumAdminDeleteTopic($topic_id);
    }
    // Форум (Изменяем счетчики количества тем и сообщений, устанавливаем информацию о последнем посте)
    $forum_id = SafeEnv($topic['forum_id'], 11, int);
    System::database()->Select('forums', "`id`='{$forum_id}'");
    if (System::database()->NumRows() == 0) {
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_forum']);
        return;
    }
    $forum = System::database()->FetchRow();
    // Значения счётчиков форума
    $forum_topics = (int) $forum['topics'] - 1;
    if ($forum_topics < 0) {
        $forum_topics = 0;
    }
    $forum_posts = (int) $forum['posts'] - (int) $topic['posts'];
    if ($forum_posts < 0) {
        $forum_posts = 0;
    }
    $forum_set = "`topics`='{$forum_topics}',`posts`='{$forum_posts}'";
    // Устанавливаем информацию о последнем посте в форуме
    if ($forum['last_id'] == $topic_id) {
        // Только если удалена тема с последним постом
        $forum_set = ForumSetLastTopic($forum_id, $forum_set, true);
    }
    System::database()->Update('forums', $forum_set, "`id`= '{$forum_id}'");
    // Очищаем кэш форума
    ForumCacheClear();
    GO(Ufu('index.php?name=forum&op=showforum&forum=' . $forum_id, 'forum/{forum}/'));
}
<?php

/*
 * LinkorCMS 1.4
 * © 2012 LinkorCMS Development Group
 */
if (!defined('VALID_RUN')) {
    header("HTTP/1.1 404 Not Found");
    exit;
}
if (!isset($_GET['p'])) {
    HackOff(true, false);
    echo "<b>Ошибка</b>: Функция отключена или не поддерживается.";
    exit;
} else {
    $PluginName = SafeEnv($_GET['p'], 40, str);
}
//Проверяем доступен ли данный плагин
System::database()->Select('plugins', "`type`='" . PLUG_CALLEE . "' and `name`='{$PluginName}'");
$valid_plugin = System::database()->NumRows() == 1;
$mod = System::database()->FetchRow();
define('PLUG_DIR', System::config('plug_dir') . $PluginName . '/');
define('PLUG_FILE', PLUG_DIR . 'index.php');
if ($valid_plugin && file_exists(PLUG_FILE)) {
    include_once PLUG_DIR . 'info.php';
    include_once PLUG_FILE;
} else {
    HackOff(true, false);
    echo "<b>Ошибка</b>: Функция отключена или не поддерживается.";
}
function IndexForumSavePost()
{
    global $forum_lang;
    if (!System::user()->Auth) {
        System::site()->AddTextBox($forum_lang['forum'], '<p align="center">' . $forum_lang['error_auth'] . '</p>');
        return;
    }
    if (!CheckGet('post') || !CheckPost('text')) {
        HackOff();
        return;
    }
    if (isset($_GET['page'])) {
        $page = '&page=' . SafeEnv($_GET['page'], 11, int);
        $page_ufu = '-{page}';
    } else {
        $page = '';
        $page_ufu = '';
    }
    // Берём пост, проверяем на существование и удаление в корзину
    $post_id = SafeEnv($_GET['post'], 11, int);
    System::database()->Select('forum_posts', "`id`='{$post_id}'");
    if (System::database()->NumRows() == 0) {
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_post']);
        return;
    }
    $post = System::database()->FetchRow();
    if ($post['delete'] == '1') {
        // Удалён в корзину
        System::site()->AddTextBox($forum_lang['post_basket'], '<p align="center">' . $forum_lang['post_basket_no_edit'] . '.<br><input type="button" value="' . $forum_lang['back'] . '"onclick="history.back();"></p>');
        return;
    }
    // Берём тему
    $topic_id = SafeEnv($post['object'], 11, int);
    System::database()->Select('forum_topics', "`id`='" . $topic_id . "'");
    if (System::database()->NumRows() == 0) {
        System::site()->AddTextBox($forum_lang['error'], $forum_lang['error_no_topic']);
        return;
    }
    $topic = System::database()->FetchRow();
    if ($topic['delete'] == '1') {
        // Тема удалена в корзину
        System::site()->AddTextBox($forum_lang['topic_basket_current_post'], '<p align="center">' . $forum_lang['topic_basket_post'] . '.<br><input type="button" value="' . $forum_lang['back'] . '"onclick="history.back();"></p>');
        return;
    }
    // Пользователи могут редактировать только свои сообщения.
    // Админы могут редактировать все сообщения.
    if (System::user()->Get('u_id') == $post['user_id'] || System::user()->isAdmin()) {
        // Меняем текст сообщения
        $post_text = SafeEnv($_POST['text'], 100000, str);
        // Добавляем метку об изменении сообщения
        $post_text .= "\n\n" . '[i]-- Изменено "' . System::user()->Name() . '": ' . TimeRender(time(), true, false) . ' --[/i]';
        System::database()->Update('forum_posts', "`message`='{$post_text}'", "`id`='{$post_id}'");
        // Меняем заголовок темы
        if (isset($_POST['title'])) {
            $topic_title = SafeEnv($_POST['title'], 255, str);
            System::database()->Update('forum_topics', "`title`='{$topic_title}'", "`id`='{$topic_id}'");
        }
        // Очищаем кэш форума
        ForumCacheClear();
        GO(Ufu('index.php?name=forum&op=showtopic&topic=' . $topic_id . $page . '#' . $post_id, 'forum/topic{topic}' . $page_ufu . '.html'));
    } else {
        System::site()->AddTextBox($forum_lang['forum'], '<p align="center">' . $forum_lang['no_right_comment_edit'] . '</p>');
        return;
    }
}