function IndexFormsMain()
{
    $forms = System::database()->Select('forms', GetWhereByAccess('view', "`active`='1'"));
    if (System::database()->NumRows() == 0) {
        GO(FORMS_UFU);
    }
    System::site()->AddTemplatedBox('', 'module/forms_list.html');
    System::site()->AddBlock('forms_list', true, true, 'form');
    foreach ($forms as $form) {
        $vars = array();
        $vars['link'] = Ufu('index.php?name=forms&formlink=' . SafeDB($form['link'], 255, str), 'forms:form');
        $vars['title'] = SafeDB($form['hname'], 255, str);
        System::site()->AddSubBlock('forms_list', true, $vars);
    }
}
<?php

/*
 * LinkorCMS 1.4
 * © 2012 LinkorCMS Development Group
 */
if (!defined('VALID_RUN')) {
    header("HTTP/1.1 404 Not Found");
    exit;
}
global $bottomMessages;
$msgs = System::database()->Select('messages', GetWhereByAccess('view', "`active`='1'"));
$disableMsg = false;
$bottomMessages = array();
function MessagesRender($msg)
{
    global $userAccess;
    $disableMsg = '';
    $total = TotalTime(time(), $msg['date'] + Day2Sec * $msg['expire']);
    if ($total === false) {
        if ($msg['expire'] != 0) {
            $disableMsg .= "and `id`='" . $msg['id'] . "'";
            return;
        }
    }
    if (VisibilityConditionsCheck($msg['showin'], $msg['showin_uri'])) {
        $adin = '';
        if ($userAccess == '1') {
            if ($msg['expire'] != '0') {
                $vt = 'Срок истекает через ' . $total['sdays'] . ($total['hours'] != 0 ? ' и ' . $total['shours'] : '');
            } else {
<?php

/*
 * LinkorCMS 1.4
 * © 2012 LinkorCMS Development Group
 */
if (!defined('VALID_RUN')) {
    header("HTTP/1.1 404 Not Found");
    exit;
}
global $search_results, $searchstr;
$objects = System::database()->Select('articles', GetWhereByAccess('view', "`active`='1'"));
foreach ($objects as $object) {
    $result = array();
    $result['mod'] = $plugin_info['mod_title'];
    // Имя модуля
    $result['coincidence'] = '';
    // Показывает где было совпадение
    $result['title'] = SafeDB($object['title'], 255, str);
    $result['public'] = TimeRender(SafeDB($object['public'], 11, int));
    // Дата публикации
    $result['link'] = Ufu('index.php?name=articles&op=read&art=' . SafeDB($object['id'], 11, int) . '&cat=' . SafeDB($object['cat_id'], 11, int), 'articles/{cat}/{art}/');
    $result['text'] = SafeDB($object['description'], 0, str);
    if (strlen($result['text']) > 255) {
        $result['text'] = substr($result['text'], 0, 255) . '&nbsp; ...';
    }
    if (SSearch($object['seo_keywords'], $searchstr) != false) {
        $result['coincidence'] = 'Ключевые слова статьи';
        $search_results[] = $result;
    } elseif (SSearch($object['seo_description'], $searchstr) != false) {
        $result['coincidence'] = 'Описание статьи';
function IndexPollsVoice()
{
    if (!isset($_GET['poll_id'])) {
        GoBack();
    }
    if (!isset($_POST['voice'])) {
        System::site()->AddTextBox('', '<p align="center">Вы не выбрали ни одного варианта ответа.</p>');
    } else {
        $pid = SafeEnv($_GET['poll_id'], 11, int);
        System::database()->Select('polls', GetWhereByAccess('view', "`id`='{$pid}' and `active`='1'"));
        if (System::database()->NumRows() == 0) {
            GoBack();
        }
        $poll = System::database()->FetchRow();
        $answers = unserialize($poll['answers']);
        $multianswers = SafeDB($poll['multianswers'], 1, int);
        $voice = SafeEnv($_POST['voice'], 11, int);
        if (!$multianswers) {
            $voice = $voice[0];
        }
        //Проверяем, учавствовал ли данный пользователь в этом опросе
        $ip = getip();
        if (System::user()->Auth) {
            $uid = System::user()->Get('u_id');
        } else {
            $uid = -1;
        }
        System::database()->Select('polls_voices', "`poll_id`='{$pid}' and (`user_ip`='{$ip}' or `user_id`='{$uid}')");
        if (System::database()->NumRows() == 0) {
            if (!$multianswers) {
                if (isset($answers[$voice])) {
                    $answers[$voice][2] = $answers[$voice][2] + 1;
                    $answers = serialize($answers);
                    System::database()->Update('polls', "answers='{$answers}'", "`id`='{$pid}'");
                } else {
                    GoBack();
                }
            } else {
                $c = count($voice);
                for ($i = 0; $i < $c; $i++) {
                    if (isset($answers[$voice[$i]])) {
                        $answers[$voice[$i]][2] = $answers[$voice[$i]][2] + 1;
                    } else {
                        GoBack();
                    }
                }
                $answers = serialize($answers);
                System::database()->Update('polls', "answers='{$answers}'", "`id`='{$pid}'");
            }
            $voice = serialize($voice);
            if (System::user()->Auth) {
                $user_id = System::user()->Get('u_id');
            } else {
                $user_id = 0;
            }
            System::database()->Insert('polls_voices', "'','{$pid}','" . getip() . "','{$voice}','{$user_id}'");
            System::user()->ChargePoints(System::config('points/polls_answer'));
            GoBack();
        } else {
            System::site()->AddTextBox('', '<p align="center">Извините, Вы уже принимали участие в этом опросе.</p>');
        }
    }
}
 /**
  * Выводит все блоки, зарегистрированные в базе данных
  */
 public function ViewBlocks()
 {
     global $site, $db, $user, $config, $userAccess, $userAuth;
     // для совместимости, НЕ УДАЛЯТЬ
     $blocks = System::database()->Select('blocks', GetWhereByAccess('view', "`enabled`='1'"), null, 'place');
     foreach ($blocks as $block) {
         $block_config = $block['config'];
         $area = SafeDB($block['position'], 1, str);
         $title = SafeDB($block['title'], 255, str);
         $enabled = SafeDB($block['enabled'], 1, int);
         $modified = SafeDB($block['modified'], 11, int);
         $cache = SafeDB($block['cache'], 0, str, false, false);
         $vars = array();
         $tempvars = array();
         $childs = array();
         if ($enabled && VisibilityConditionsCheck($block['showin'], $block['showin_uri'])) {
             include RealPath2(System::config('blocks_dir') . $block['type']) . '/index.php';
             // => $vars
             $this->AddUserBlock($area, $vars, $tempvars, $childs, SafeDB(RealPath2($block['template']), 255, str));
         }
     }
 }
<?php

/*
 * LinkorCMS 1.4
 * © 2012 LinkorCMS Development Group
 */
if (!defined('VALID_RUN')) {
    header("HTTP/1.1 404 Not Found");
    exit;
}
global $search_results, $searchstr;
$news_array = System::database()->Select('news', GetWhereByAccess('view', "`enabled`='1'"));
foreach ($news_array as $news) {
    $result = array();
    $result['mod'] = $plugin_info['mod_title'];
    // Имя модуля
    $result['coincidence'] = '';
    // Показывает где было совпадение
    $result['title'] = SafeDB($news['title'], 255, str);
    $result['public'] = TimeRender(SafeDB($news['date'], 11, int));
    // Дата публикации
    $result['link'] = Ufu('index.php?name=news&op=readfull&news=' . SafeDB($news['id'], 11, int) . '&topic=' . SafeDB($news['topic_id'], 11, int), 'news/{topic}/{news}/');
    $result['text'] = SafeDB($news['start_text'], 0, str);
    if ($news['auto_br'] == '1') {
        $result['text'] = SafeDB(nl2br($result['text']), 0, str, false, false);
    } else {
        $result['text'] = SafeDB($result['text'], 0, str, false, false);
    }
    if (strlen($result['text']) > 255) {
        $result['text'] = substr($result['text'], 0, 255) . '&nbsp; ...';
    }
    exit;
}
$vars['title'] = $title;
$bcache_name = 'news' . System::user()->AccessLevel();
if (!System::cache()->HasCache('block', $bcache_name)) {
    $block_config = unserialize($block_config);
    $topic = SafeDB($block_config['topic'], 11, int);
    // Тема новостей
    $max_news = SafeDB($block_config['count'], 11, int);
    // Количество новостей в блоке
    if ($topic != 0) {
        $where = "`enabled`='1' and `topic_id`='{$topic}'";
    } else {
        $where = "`enabled`='1'";
    }
    $newsdb = System::database()->Select('news', GetWhereByAccess('view', $where), $max_news, 'date', true);
    $news = array();
    foreach ($newsdb as $new) {
        $news[] = array('title' => SafeDB($new['title'], 255, str), 'text' => substr(SafeDB($new['start_text'], 0, str, true, false), 0, 255), 'date' => $new['date'], 'url' => Ufu('index.php?name=news&op=readfull&news=' . SafeDB($new['id'], 11, int) . '&topic=' . SafeDB($new['topic_id'], 11, int), 'news/{topic}/{news}/'));
    }
    System::cache()->Write('block', $bcache_name, $news);
} else {
    $news = System::cache()->Get('block', $bcache_name);
}
$count = count($news);
$en = !($count == 0);
$tempvars['content'] = 'block/content/news.html';
System::site()->AddBlock('no_news', !$en);
System::site()->AddBlock('block_news', $en);
System::site()->AddBlock('block_news_news', true, true, 'news');
foreach ($news as $new) {
<?php

/*
 * LinkorCMS 1.4
 * © 2012 LinkorCMS Development Group
 */
if (!defined('VALID_RUN')) {
    header("HTTP/1.1 404 Not Found");
    exit;
}
global $search_results, $searchstr;
$objects = System::database()->Select('gallery', GetWhereByAccess('view', "`show`='1'"));
foreach ($objects as $object) {
    $result = array();
    $result['mod'] = $plugin_info['mod_title'];
    // Имя модуля
    $result['coincidence'] = '';
    // Показывает где было совпадение
    $result['title'] = SafeDB($object['title'], 255, str);
    // Заголовок
    $result['public'] = TimeRender(SafeDB($object['public'], 11, int));
    // Дата публикации
    // Ссылка на просмотр обьекта
    $result['link'] = Ufu('index.php?name=gallery&op=view&img=' . SafeDB($object['id'], 11, int) . '&cat=' . SafeDB($object['cat_id'], 11, int), 'gallery/{cat}/{img}/');
    $result['text'] = SafeDB($object['description'], 0, str);
    if (strlen($result['text']) > 255) {
        $result['text'] = substr($result['text'], 0, 255) . '&nbsp; ...';
    }
    if (SSearch($object['title'], $searchstr) !== false) {
        $result['coincidence'] = 'Заголовок изображения';
        $search_results[] = $result;
function IndexGalleryAddVote()
{
    $ip = getip();
    $time = time() - 86400;
    //1 день
    $id = SafeEnv($_GET['img'], 11, int);
    $vote = SafeEnv($_POST['vote'], 1, int);
    System::database()->Delete('gallery_rating', "`time`<'{$time}'");
    System::site()->OtherMeta .= '<meta http-equiv="REFRESH" content="3; URL=' . HistoryGetUrl(1) . '">';
    System::database()->Select('gallery', GetWhereByAccess('view', "`id`='{$id}' and `show`='1'"));
    if (System::database()->NumRows() > 0) {
        $image = System::database()->FetchRow();
        if ($image['allow_votes'] == '1') {
            // оценки разрешены
            System::database()->Select('gallery_rating', "`ip`='{$ip}' and `imageid`='{$id}'");
            if (System::database()->NumRows() > 0) {
                System::site()->AddTextBox('', '<p align="center">Вы уже голосовали.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
            } else {
                if ($vote == 0) {
                    System::site()->AddTextBox('', '<p align="center">Вы не выбрали оценку.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
                } else {
                    System::user()->ChargePoints(System::config('points/gallery_rating'));
                    $time = time();
                    System::database()->Insert('gallery_rating', "'','{$id}','{$ip}','{$time}'");
                    $vote = SafeDB($image['sum_votes'], 11, int) + $vote;
                    $numvotes = SafeDB($image['num_votes'], 11, int) + 1;
                    System::database()->Update('gallery', "`num_votes`='{$numvotes}',`sum_votes`='{$vote}'", "`id`='{$id}'");
                    System::site()->AddTextBox('', '<p align="center">Спасибо за вашу оценку.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
                }
            }
        } else {
            // Оценка запрещена
            System::site()->AddTextBox('', '<p align="center">Извините, оценка этого изображения запрещена.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
        }
    } else {
        // Файл не существует
        System::site()->AddTextBox('', '<p align="center">Произошла ошибка. Изображение не найдено.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
    }
}
function IndexNewsReadFull()
{
    System::site()->AddTemplatedBox('', 'module/news_full.html');
    System::site()->AddBlock('news', true, true);
    if (isset($_GET['news'])) {
        $topics = IndexNewsGetTopics();
        $news_id = SafeEnv($_GET['news'], 11, int);
        $news = System::database()->SelectOne('news', GetWhereByAccess('view', "`id`='{$news_id}'"));
        if ($news && $news['enabled'] == '1') {
            // Новость включена
            System::site()->SetTitle(SafeDB($news['title'], 255, str));
            $topic_id = SafeDB($news['topic_id'], 11, int);
            $topic_title = SafeDB($topics[$topic_id]['title'], 255, str);
            System::site()->BreadCrumbAdd($topic_title, Ufu('index.php?name=news&topic=' . $topic_id, 'news/{topic}/'));
            System::site()->BreadCrumbAdd(SafeDB($news['title'], 255, str));
            //Модуль SEO
            System::site()->SeoTitle = SafeDB($news['seo_title'], 255, str);
            System::site()->SeoKeyWords = SafeDB($news['seo_keywords'], 255, str);
            System::site()->SeoDescription = SafeDB($news['seo_description'], 255, str);
            //
            IndexNewsAdd($news, $topic_title, true);
            System::database()->Update('news', "hit_counter='" . (SafeEnv($news['hit_counter'], 11, int) + 1) . "'", "`id`='" . $news_id . "'");
            // Выводим комментарии
            if (isset($_GET['page'])) {
                $page = SafeEnv($_GET['page'], 11, int);
            } else {
                $page = 0;
            }
            include_once System::config('inc_dir') . 'posts.class.php';
            $posts = new Posts('news_comments', $news['allow_comments'] == '1');
            $posts->EditPageUrl = "index.php?name=news&op=editpost&news={$news_id}";
            $posts->DeletePageUrl = "index.php?name=news&op=deletepost&news={$news_id}";
            $posts->PostFormAction = "index.php?name=news&op=addpost&news={$news_id}&topic={$topic_id}&page={$page}";
            $posts->NavigationUrl = Ufu("index.php?name=news&op=readfull&news={$news_id}&topic={$topic_id}", 'news/{topic}/{news}/page{page}/', true);
            $posts->NavigationAnchor = '#comments';
            $posts->RenderPosts($news_id, 'news_comments', 'comments_navigation', false, $page);
            $posts->RenderForm(false, 'news_comments_form');
        } else {
            System::site()->AddTextBox('Ошибка', '<p align="center">Эта новость не доступна в данный момент!<br><input type="button" value="Назад" onclick="history.back();"></p>');
        }
    } else {
        System::site()->AddTextBox('Ошибка', '<p align="center"><input type="button" value="Назад" onclick="history.back();"></p>');
    }
}
    exit;
}
$vars['title'] = $title;
$block_config = unserialize($block_config);
$bcache_name = 'random_images' . System::user()->AccessLevel();
if (!System::cache()->HasCache('block', $bcache_name)) {
    if (in_array(0, $block_config['cats'])) {
        $where = '';
    } else {
        $where = array();
        foreach ($block_config['cats'] as $cat) {
            $where[] = "`cat_id` = '" . SafeEnv($cat, 11, int) . "'";
        }
        $where = '(' . implode(' or ', $where) . ') and ';
    }
    $imagesdb = System::database()->Select('gallery', GetWhereByAccess('view', "{$where}`show`='1'"));
    $images = array();
    foreach ($imagesdb as $img) {
        $images[] = array('id' => SafeDB($img['id'], 11, int), 'cat_id' => SafeDB($img['cat_id'], 11, int), 'file' => SafeDB($img['file'], 255, str), 'title' => SafeDB($img['title'], 255, str));
    }
    System::cache()->Write('block', $bcache_name, $images);
} else {
    $images = System::cache()->Get('block', $bcache_name);
}
$count = count($images);
$en = !($count == 0);
$tempvars['content'] = 'block/content/random_images.html';
System::site()->AddBlock('no_images', !$en);
System::site()->AddBlock('random_images', $en, true, 'img');
if ($en) {
    for ($i = 0; $i < $block_config['count']; $i++) {
function IndexArticlesAddVote()
{
    $ip = getip();
    $time = time() - 86400;
    //1 день
    $article = SafeEnv($_GET['article'], 11, int);
    $vote = SafeEnv($_POST['vote'], 1, int);
    System::database()->Delete('articles_rating', "`time`<'{$time}'");
    System::site()->OtherMeta .= '<meta http-equiv="REFRESH" content="3; URL=' . HistoryGetUrl(1) . '">';
    System::database()->Select('articles', GetWhereByAccess('view', "`id`='{$article}' and `active`='1'"));
    if (System::database()->NumRows() > 0) {
        $dfile = System::database()->FetchRow();
        if ($dfile['allow_votes'] == '1') {
            // оценки разрешены
            System::database()->Select('articles_rating', "`ip`='{$ip}' and `downid`='{$article}'");
            if (System::database()->NumRows() > 0) {
                System::site()->AddTextBox('', '<p align="center">Вы уже голосовали за эту статью.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
            } else {
                if ($vote == 0) {
                    System::site()->AddTextBox('', '<p align="center">Вы не выбрали оценку.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
                } else {
                    System::user()->ChargePoints(System::config('points/article_rating'));
                    $time = time();
                    System::database()->Insert('articles_rating', "'','{$article}','{$ip}','{$time}'");
                    $numvotes = SafeDB($dfile['num_votes'], 11, int) + 1;
                    $vote = SafeDB($dfile['all_votes'], 11, int) + $vote;
                    System::database()->Update('articles', "num_votes='{$numvotes}',all_votes='{$vote}'", "`id`='{$article}'");
                    System::site()->AddTextBox('', '<p align="center">Спасибо за вашу оценку.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
                }
            }
        } else {
            System::site()->AddTextBox('', '<p align="center">Извините, оценка этой статьи запрещена.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
        }
    } else {
        System::site()->AddTextBox('', '<p align="center">Произошла ошибка. Статья не найдена.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
    }
}
                    }
                }
            }
        }
    }
}
// Кэширование
$bcache_name = 'menu' . System::user()->AccessLevel();
if (System::cache()->HasCache('block', $bcache_name)) {
    $block_menu_items = System::cache()->Get('block', $bcache_name);
    BlockMenuSelectItem($block_menu_items, $uri);
    $childs['block_menu_items'] = $block_menu_items;
    return;
}
// Выборка
$pages = System::database()->Select('pages', GetWhereByAccess('view', "`enabled`='1' and `showinmenu`='1'"), null, 'order');
$catsPid = array();
foreach ($pages as $page) {
    $catsPid[$page['parent']][] = $page;
}
if (!isset($catsPid[0])) {
    $catsPid[0] = array();
}
// Генерация меню
$items = Starkyt::CreateBlock(true, true, 'menu_item');
foreach ($catsPid[0] as $page) {
    $subitems = Starkyt::CreateBlock(true, true, 'menu_subitem');
    $link = '';
    if ($page['type'] == 'page') {
        $link = Ufu('index.php?name=pages&file=' . SafeDB($page['link'], 255, str), 'pages:page');
    } elseif ($page['type'] == 'link') {
function IndexDownloadsAddVote()
{
    $ip = getip();
    $time = time() - 86400;
    //1 день
    $file = SafeEnv($_GET['file'], 11, int);
    $vote = SafeEnv($_POST['vote'], 1, int);
    System::database()->Delete('downloads_rating', "`time`<'{$time}'");
    System::site()->OtherMeta .= '<meta http-equiv="REFRESH" content="3; URL=' . HistoryGetUrl(1) . '">';
    System::database()->Select('downloads', GetWhereByAccess('view', "`id`='{$file}' and `active`='1'"));
    if (System::database()->NumRows() > 0) {
        $dfile = System::database()->FetchRow();
        if ($dfile['allow_votes'] == '1') {
            // оценки разрешены
            System::database()->Select('downloads_rating', "`ip`='{$ip}' and `downid`='{$file}'");
            if (System::database()->NumRows() > 0) {
                System::site()->AddTextBox('', '<p align="center">Вы уже голосовали за этот файл.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
            } else {
                if ($vote == 0) {
                    System::site()->AddTextBox('', '<p align="center">Вы не выбрали оценку.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
                } else {
                    System::user()->ChargePoints(System::config('points/download_rating'));
                    $time = time();
                    System::database()->Insert('downloads_rating', "'','{$file}','{$ip}','{$time}'");
                    $vote = SafeDB($dfile['votes'], 11, int) + $vote;
                    $numvotes = SafeDB($dfile['votes_amount'], 11, int) + 1;
                    System::database()->Update('downloads', "votes_amount='{$numvotes}',votes='{$vote}'", "`id`='{$file}'");
                    System::site()->AddTextBox('', '<p align="center">Спасибо за вашу оценку.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
                }
            }
        } else {
            // Оценка запрещена
            System::site()->AddTextBox('', '<p align="center">Извините, оценка этого файла запрещена.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
        }
    } else {
        // Файл не существует
        System::site()->AddTextBox('', '<p align="center">Произошла ошибка. Файл, который вы пытаетесь оценить, не найден в нашем файловом архиве. Возможно он был удален.<br><br><a href="javascript:history.go(-1)">Назад</a></p>');
    }
}
<?php

/*
 * LinkorCMS 1.4
 * © 2012 LinkorCMS Development Group
 */
if (!defined('VALID_RUN')) {
    header("HTTP/1.1 404 Not Found");
    exit;
}
global $search_results, $searchstr;
$objects = System::database()->Select('pages', GetWhereByAccess('view', "`enabled`='1' and `type`='page'"));
foreach ($objects as $object) {
    $result = array();
    $result['mod'] = $plugin_info['mod_title'];
    // Имя модуля
    $result['coincidence'] = '';
    // Показывает где было совпадение
    $result['title'] = SafeDB($object['title'], 255, str);
    // Заголовок
    $result['public'] = TimeRender(SafeDB($object['modified'], 11, int));
    // Дата публикации
    // Ссылка на просмотр обьекта
    $result['link'] = Ufu('index.php?name=pages&file=' . SafeDB($object['link'], 255, str), 'pages/{file}.html');
    $result['text'] = SafeDB($object['text'], 0, str);
    if (strlen($result['text']) > 255) {
        $result['text'] = substr($result['text'], 0, 255) . '&nbsp; ...';
    }
    if (SSearch($object['seo_keywords'], $searchstr) !== false) {
        $result['coincidence'] = 'Ключевые слова страницы';
        $search_results[] = $result;