<?php


/*
=======================
Dcms-Blog
Автор модификации: Dark_AKC
-----------------------------------------
Контакты
http://darkwm.ru
=======================
*/


echo "<table style='width:100%; height:30px' cellspacing='0' cellpadding='0'><tr>";

echo "<td class='title' style='width:35%;border-right:1px solid #a0a0a0'><a href='/plugins/blog/dir.php'><center>Категории</a></center></td>";
echo '<td class="title"><a href="?sort=t"><center>Новые</a></center></td>';
echo '<td class="title" style="width:35%;border-left:1px solid #a0a0a0"><a href="?sort=c"><center>Популярные</a></center></td>';

echo '</tr></table>';

$usearch=NULL;
if (isset($_SESSION['usearch']))$usearch=$_SESSION['usearch'];
if (isset($_POST['usearch']))$usearch=$_POST['usearch'];

if ($usearch==NULL)
unset($_SESSION['usearch']);
else
$_SESSION['usearch']=$usearch;
$usearch=preg_replace("#( ){1,}#","",$usearch);

$order='order by `time` desc';
echo "<form class='mess' method='post' action='/plugins/blog/search.php?go'><center>";
$usearch=stripcslashes(htmlspecialchars($usearch));
echo "<input type=\"text\" name=\"usearch\" maxlength=\"16\" value=\"$usearch\" style='width:70%' placeholder='Введите название блога'/>\n";
echo "<input type=\"submit\" value=\"Искать\" />";
echo "</center></form>\n";


if (isset($_GET['go'])){
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `blog` where `name` like '%".mysql_real_escape_string($usearch)."%'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_query("SELECT * FROM `blog` WHERE `name` like '%".mysql_real_escape_string($usearch)."%' $order LIMIT $start, $set[p_str]");

if ($k_post==0){
echo "<div class='mess'>\n";
echo "Нет записей\n";
echo "</div>\n";
}
$num=0;
while ($post = mysql_fetch_assoc($q)){


echo "<img src='/style/icons/dnev.png' alt='*'> ";

echo "<a href='/plugins/blog/list.php?id=$post[id]'>" . htmlspecialchars($post['name']) . "</a> \n";

echo " <span style='time'>(".vremja($post['time']).")</span>\n";

$k_n= mysql_result(mysql_query("SELECT COUNT(*) FROM `blog` WHERE `id` = $post[id] AND `time` > '".$ftime."'",$db), 0);
if ($k_n!=0)echo " <img src='/style/icons/new.gif' alt='*'>";
}


if ($k_page>1)str('?go&amp;',$k_page,$page); // Вывод страниц

}




//////////////////////////////////////////////////////
//echo '<div class="mess">';




if (isset($_GET['sort']) && $_GET['sort'] =='t')$order='order by `time` desc';
elseif (isset($_GET['sort']) && $_GET['sort'] =='c') $order='order by `count` desc';
else $order='order by `time` desc';



$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `blog` "),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

$q=mysql_query("SELECT * FROM `blog` WHERE `mod` = '1'  $order LIMIT $start, $set[p_str]");
echo "<table class='post'>\n";
if ($k_post==0)
{
echo "  <div class='mess'>\n";
echo "Нет записей\n";
echo "  </div>\n";
}


while ($post = mysql_fetch_assoc($q)){
$k_n= mysql_result(mysql_query("SELECT COUNT(*) FROM `blog` WHERE `id` = $post[id] AND `time` > '$ftime'",$db), 0);
$likes = mysql_result(mysql_query("SELECT COUNT(*) FROM `blog_like` WHERE `like` = '1' AND `id_notes` = '".$post['id']."' LIMIT 1"),0);
$dir = mysql_fetch_assoc(mysql_query("SELECT * FROM `blog_dir` WHERE `id` = '".$post['id_dir']."' "));
$avtor = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = '".$post['id_user']."'"));

echo "<div class='blog_name'><img src='/style/icons/dnev.png' alt='*'> ";
echo '<a href="/plugins/blog/list.php?id='.$post['id'].'">'.htmlspecialchars($post['name']).'</a></div>';

if($post['block'] == 1){
echo '<div class="err">Статья заблокирована</div>';
echo '<div class="mess">';
}else{
echo '<div class="mess">';
echo rez_text(htmlspecialchars($post['msg']))." <a href='/plugins/blog/list.php?id=$post[id]'>Читать далее...</a><br /><br>"; 
}

echo "(".vremja($post['time']).")<br>";
echo 'Автор: ';
echo group($post['id_user']).' <a href="/id'.$post['id_user'].'">'.$avtor['nick'].'</a> '.online($post['id_user']);
echo medal($post['id_user']);
echo '<br>Раздел:<a href="/plugins/blog/dir.php?id='.$post['id_dir'].'"> '.$dir['name'].'</a>';
echo '<span style="float:right"><img src="/style/icons/bbl5.png" alt="*"/> '.mysql_result(mysql_query("SELECT COUNT(*) FROM `blog_komm` WHERE `id_notes` = '$post[id]'"),0).' <img src="/style/icons/eye.png"/> '.$post['count'].' <img src="/style/icons/like.gif" alt="*" /> '.$likes.'</span></div>';

}


if (isset($_GET['sort'])) $dop="sort=$_GET[sort]&amp;";
else $dop='';
if ($k_page>1)str('?'.$dop.'',$k_page,$page); // Вывод страниц

///////////////////////////////////////////////////

echo '</div>';


?>