Files
legacy_rock/pub.php

154 lines
4.8 KiB
PHP

<?
header("Preved: Krosavcheg!");
$forum_version = 'SMF 1.0.6';
// Get everything started up...
define('SMF', 1);
@set_magic_quotes_runtime(0);
//error_reporting(E_ALL);
$time_start = microtime();
// Load the settings...
require_once('forum/Settings.php');
// Just in case something happens to Settings.php, let's try to at least load an error screen.
//if (!isset($sourcedir))
$sourcedir = 'forum/Sources';
// And important includes.
//require_once($sourcedir . '/QueryString.php');
require_once($sourcedir . '/Subs.php');
//require_once($sourcedir . '/Errors.php');
//require_once($sourcedir . '/Load.php');
//require_once($sourcedir . '/Security.php');
require_once("tpl.php");
// If $maintenance is set specifically to 2, then we're upgrading or something.
if ($maintenance == 2)
db_fatal_error();
// Connect to the MySQL database.
if (empty($db_persist))
$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
else
$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
// Show an error if the connection couldn't be made.
if (!$db_connection || !@mysql_select_db($db_name, $db_connection))
db_fatal_error();
db_query("SET NAMES 'utf8'", __FILE__, __LINE__);
if(!empty($_GET['id'])){
$id=intval($_GET['id']);
$r=db_query("SELECT title, body, ID_MSG, ID_TOPIC, id_category FROM publications INNER JOIN smf_messages ON publications.id_post=smf_messages.ID_MSG WHERE id=$id ORDER BY timestamp DESC limit 1", __FILE__, __LINE__);
if(mysql_num_rows($r)==0) {
e404();
}
$post=mysql_fetch_assoc($r);
// if special - redirect to forum
if ($post['id_category'] == 9) {
header("Location: http://forum.rock.ru/index.php?topic={$post['ID_TOPIC']}.msg{$post['ID_MSG']}#msg{$post['ID_MSG']}");
}
$context['title']=$post['title'];
parsecode($post['body']);
head();
$body = $post['body'];
#die $r['id_category'];
if (! in_array ($post['id_category'], array (3, 4))) {
$body .= "<div align=\"right\"><a href=\"http://forum.rock.ru/index.php?topic={$post['ID_TOPIC']}.msg{$post['ID_MSG']}#msg{$post['ID_MSG']}\">Обсудить на форуме</a></div>";
}
block($post['title'],$body, true);
foot();
} elseif(!empty($_GET['cat'])) {
if (isset($_GET['page'])) {
$page = intval($_GET['page']);
} else {
$page = 1;
}
if ($page > 0) $page -= 1;
$start = $page * 10;
$cat=intval($_GET['cat']);
$r=db_query("SELECT name, urlname, reverse FROM categories WHERE id=$cat", __FILE__, __LINE__);
if(mysql_num_rows($r)==0) {
e404();
}
list($category, $url, $reverse)=mysql_fetch_row($r);
$context['title']=$category;
if($reverse == 1) {
$order = "ASC";
} else {
$order = "DESC";
}
$r=db_query("SELECT id, title, ID_MSG, ID_TOPIC, ID_MEMBER, posterName, brief, timestamp FROM publications INNER JOIN smf_messages ON publications.id_post=smf_messages.ID_MSG WHERE id_category=$cat ORDER BY timestamp $order LIMIT $start, 10", __FILE__, __LINE__);
if(mysql_num_rows($r)==0) {
e404();
}
list($total_rows) = mysql_fetch_row(
mysql_query("SELECT COUNT(*) FROM publications INNER JOIN smf_messages ON publications.id_post=smf_messages.ID_MSG WHERE id_category=$cat")
);
$total_pages = ceil($total_rows/10);
$txt="";
while($post=mysql_fetch_assoc($r)) {
parsecode($post['brief']);
$txt.='<div style="clear: both;"><p><h2><a href="/'.$url.'/'.$post['id'].'.html">'.$post['title'].'</a></h2> добавил <a href="http://forum.rock.ru/index.php?action=profile;u='.$post['ID_MEMBER'].'">'.$post['posterName'].'</a> '.date("d.m.Y H:i", $post['timestamp']).'</p>
<p>'.$post['brief'].'</p></div>';
}
$txt .= pager($page+1, $total_pages, $url);
head();
block($category,$txt);
foot();
} else {
e404();
}
function pager($page, $page_count, $url){
if($page_count<2) return;
$output = '<div style="clear:both; font-size: large; text-align: center;">';
$limit = $page_count;
//echo '<div align="center" style="display: inline;">';
if(!empty($page)){
$limit = $page+5;
if($limit>=$page_count) $limit = $page_count;
$i = $page-5;
if($page <= 6) $limit = 11;
if($page >= $page_count-5) $i = $page_count - 11;
if($page_count <= 10) $limit = $page_count;
}else{
$page = $limit;
if($page >= $page_count-6) $limit = $page_count - 11;
}
/*if($show_label){
?>Pages (<?=$page_count?> total):<br><?
}*/
if($page != 1){
$page_back = $page - 1;
$output .= '<a href="/'.$url.'/'.$page_back.'" title="Previous page">&lt;&lt;</a>&nbsp;';
}
if($i<1) $i=1;
do{
if($i > $page_count) break;
if($page == $i){
$output .= "<b>$i</b>&nbsp;";
}else{
$output .= '<a href="/'.$url.'/'.$i.'">'.$i.'</a>&nbsp;';
}
}while(++$i < $limit+1);
echo " ";
if($page != $page_count){
$page_go = $page + 1;
$output .= '<a href="/'.$url.'/'.$page_go.'" title="Next page">&gt;&gt;</a>';
}
$output .= '</div>';
return $output;
}