Файл: index.php
Строк: 86
<?php
define('BLOG',TRUE);
include('core/init.php');
include( MODULES_PATH . 'auth.php' );
# Кеширование категорий блога
$categories = get_vars('categories');
if (!$categories) {
$db->query("UPDATE ?_category SET `count` = (SELECT COUNT(`id`) FROM ?_data
WHERE ?_category.`id` = ?_data.`cid`);");
$categories = array();
$cats = $db->select("SELECT * FROM ?_category");
foreach( $cats as $cat ) {
$categories[$cat['id']] = array($cat['title'], $cat['text'], (int) $cat['count']);
}
set_vars('categories',$categories);
}
# Кеширование статических страниц
$static_pages = get_vars('static_pages');
if (!$static_pages || !is_array($static_pages)) {
$rows = $db->select( "SELECT `name`,`title` FROM ?_pages WHERE `active` = '1' ORDER BY `views` DESC, `id` DESC;" );
$static_pages = array();
if (!empty($rows)) {
foreach( $rows as $row ) {
$static_pages[$row['name']] = $row['title'];
}
}
set_vars('static_pages', $static_pages);
}
if ( !empty($mod) && file_exists( MODULES_PATH . $mod . '.php' ) ) {
include( MODULES_PATH . $mod . '.php' );
}
else if (!empty($mod) && array_key_exists($mod,$static_pages)) {
include( MODULES_PATH . 'static.php' );
}
else {
define('IS_INDEX',TRUE);
# Кеширование статических страниц для главной
$static_index = get_vars('static_index');
if (!$static_index || !is_array($static_index)) {
$rows = $db->select( "SELECT `name`,`title` FROM ?_pages WHERE `active` = '1' AND `is_index` = '1' ORDER BY `views` DESC, `id` DESC;" );
$static_index = array();
if (!empty($rows)) {
foreach( $rows as $row ) {
$static_index[$row['name']] = $row['title'];
}
}
set_vars('static_index', $static_index);
}
$onpage = !empty($config['post_num']) ? (int) $config['post_num'] : 10;
if ($page > 1) $from = ($page - 1) * $onpage; else $from = 0;
if ($is_admin) {
$rows = $db->selectPage( $total, "SELECT *,
(SELECT `name` FROM ?_comments WHERE ?_comments.`post` = ?_data.`id` ORDER BY ?_comments.`id` DESC LIMIT 1) AS `author`
FROM ?_data ORDER BY `date` DESC
LIMIT ?d, ?d", $from, $onpage );
}
else {
$rows = $db->selectPage( $total, "SELECT *,
(SELECT `name` FROM ?_comments WHERE ?_comments.`post` = ?_data.`id` ORDER BY ?_comments.`id` DESC LIMIT 1) AS `author`
FROM ?_data WHERE `active` = '1' ORDER BY `date` DESC
LIMIT ?d, ?d", $from, $onpage );
}
# Кеширование всего статей
$count_posts = get_vars('counts_posts', 7200);
if ( !$count_posts ) {
$count_posts = $total;
set_vars('counts_posts', array($total));
}
else {
$count_posts = (int) $count_posts[0];
}
show_header('Сборник Страшных историй на ' . $config['site_name'], $config['site_keys'], $config['site_desc']);
if ( !empty($rows) && $total > 0 ) {
foreach( $rows as $row ) {
$idk = intval($row['id']);
echo '<div class="downlist2"><div class="title"><a href="' . gen_uri('post', $idk) . '"><b>' . $row['title'] . '</b></a></div>';
if ($row['active'] == 0 && $is_admin) echo '[<span class="blink">Не опубликовано</span>]<br />';
if (!defined('EMPTY_LINKS')) {
echo '<div>' . format_text($row['text'],0,$config['substr_text'],'UTF-8') . '...<br />';
echo '<a href="' . gen_uri('post', $idk) . '">Читать далее »</a> | ';
echo' <a href="' . gen_uri('comments', $idk) . '">Комментарии</a> (' . intval($row['comm']) . ') ';
echo '<span class="author"><small> ' . $row['author'] . ' </small></span></div></div>';
}
else echo '</div>';
}
echo show_pages('index','','p');
}
else {
echo '<div class="downlist2">Записей еще нет!</div>';
}
echo '<div class="downlist2">';
if ($is_admin) {
echo'<img src="' . ICONS . 'site.png" alt=""/> <a href="' . ADMIN_DIR . '?a=add_post">Добавить статью</a><br />
<img src="' . ICONS . 'site.png" alt=""/> <a href="' . ADMIN_DIR . '">Панель Управления</a><br />';
}
///if ($config['allow_rss'] == 1)
///echo '<img src="' . ICONS . 'site.png" alt=""/> <a href="/' . gen_uri('rss','','','xml') . '">RSS</a><br />';
if ($config['open_stat'] == 1 || $is_admin) {
///echo '<img src="' . ICONS . 'site.png" alt=""/> <a href="/' . gen_uri('stat') . '">Статистика блога</a><br />';
}
foreach($static_index as $key => $val) {
echo '<img src="' . ICONS . 'site.png" alt=""/> <a href="/' . gen_uri($key) . '">' . $val . '</a><br />';
}
echo '</div>';
}
show_footer();
?>