да в коде указана сортировка по убыванию, код верный, но такое ощущение что сортировка вообще не срабатывает. Добавил три сообщения подряд, два оказались в центре, одно в самом низу -
http://silon.su
по какому принципу идут сообщения, не ясно...
<?php
# Copyright © 2005 - 2008 SLAED
# Website: http://www.slaed.net
if (!defined("MODULE_FILE")) {
header("Location: ../../index.php");
exit;
}
get_lang($conf['name']);
include("config/config_news.php");
function menu($logo) {
global $conf, $confn;
$home = "<a href=\"index.php?name=".$conf['name']."\" title=\""._HOME."\">"._HOME."</a>";
$best = ($confn['newrate']) ? "<a href=\"index.php?name=".$conf['name']."&best=1\" title=\""._BEST."\">"._BEST."</a>" : "";
$pop = ($confn['newrate']) ? "<a href=\"index.php?name=".$conf['name']."&hits=1\" title=\""._POP."\">"._POP."</a>" : "";
$liste = "<a href=\"index.php?name=".$conf['name']."&op=liste\" title=\""._LIST."\">"._LIST."</a>";
$add = ((is_user() && $confn['add'] == 1) || (!is_user() && $confn['addquest'] == 1)) ? "<a href=\"index.php?name=".$conf['name']."&op=add\" title=\""._ADD."\">"._ADD."</a>" : "";
$navi = "[ <a href=\"index.php?name=".$conf['name']."\" title=\""._HOME."\">"._HOME."</a>";
$navi .= ($confn['newrate']) ? " | <a href=\"index.php?name=".$conf['name']."&best=1\" title=\""._BEST."\">"._BEST."</a> | <a href=\"index.php?name=".$conf['name']."&hits=1\" title=\""._POP."\">"._POP."</a>" : "";
$navi .= " | <a href=\"index.php?name=".$conf['name']."&op=liste\" title=\""._LIST."\">"._LIST."</a>";
$navi .= ((is_user() && $confn['add'] == 1) || (!is_user() && $confn['addquest'] == 1)) ? " | <a href=\"index.php?name=".$conf['name']."&op=add\" title=\""._ADD."\">"._ADD."</a>" : "";
$navi .= " ]";
search($logo, $conf['name'], $navi, $home, $best, $pop, $liste, $add);
}
function news() {
global $prefix, $db, $admin_file, $user, $conf, $confu, $confn, $home, $pagetitle;
$cwhere = catmids($conf['name'], "s.catid");
$newnum = user_news($user[3], $confn['newnum']);
$sbest = (isset($_GET['best'])) ? 1 : 0;
$shits = (isset($_GET['hits'])) ? 1 : 0;
$scat = (isset($_GET['cat'])) ? intval($_GET['cat']) : 0;
if ($sbest && $confn['newrate']) {
$caton = 0;
$field = "best=1&";
$order = "WHERE s.time <= now() AND s.status!='0' ".$cwhere." ORDER BY s.score DESC";
$ordernum = "time <= now() AND status!='0'";
$news_logo = ""._BEST."";
$pagetitle = "".$conf['defis']." "._NEWS." ".$conf['defis']." $news_logo";
} elseif ($shits && $confn['newrate']) {
$caton = 0;
$field = "hits=1&";
$order = "WHERE s.time <= now() AND s.status!='0' ".$cwhere." ORDER BY s.counter DESC";
$ordernum = "time <= now() AND status!='0'";
$news_logo = ""._POP."";
$pagetitle = "".$conf['defis']." "._NEWS." ".$conf['defis']." $news_logo";
} elseif ($scat) {
$caton = 1;
$field = "cat=$scat&";
list($cat_title, $cat_description) = $db->sql_fetchrow($db->sql_query("SELECT title, description FROM ".$prefix."_categories WHERE id='$scat'"));
$order = "WHERE s.catid='$scat' AND s.time <= now() AND s.status!='0' ".$cwhere." ORDER BY s.time DESC";
$ordernum = "catid='$scat' AND time <= now() AND status!='0'";
$pagetitle = "".$conf['defis']." "._NEWS." ".$conf['defis']." $cat_title";
} else {
$caton = 1;
$field = "";
$order = (!$home) ? "WHERE s.time <= now() AND s.status!='0' ".$cwhere." ORDER BY s.time DESC" : "WHERE s.ihome='0' AND s.time <= now() AND s.status!='0' ".$cwhere." ORDER BY s.time DESC";
$ordernum = (!$home) ? "time <= now() AND status!='0'" : "ihome='0' AND time <= now() AND status!='0'";
$news_logo = ""._NEWS."";
$pagetitle = "".$conf['defis']." $news_logo";
}
head();
if (!$home) {
if ($scat) {
menu($cat_title);
} else {
menu($news_logo);
}
if ($scat) templ("catlink", catlink($conf['name'], $scat, $confn['defis'], _NEWS));
if ($caton == 1) categories($conf['name'], $confn['newcol'], $confn['newsub'], $confn['newcatdesc'], $scat);
}
$num = isset($_GET['num']) ? intval($_GET['num']) : "1";
$offset = ($num-1) * $newnum;
$offset = intval($offset);
$result = $db->sql_query("SELECT s.sid, s.catid, s.name, s.title, UNIX_TIMESTAMP(s.time) as formatted, s.hometext, s.comments, s.counter, s.acomm, s.score, s.ratings, c.id, c.title, c.description, c.img, u.user_name FROM ".$prefix."_stories AS s LEFT JOIN ".$prefix."_categories AS c ON (s.catid=c.id) LEFT JOIN ".$prefix."_users AS u ON (s.uid=u.user_id) ".$order." LIMIT $offset, $newnum");
if ($db->sql_numrows($result) > 0) {
while (list($sid, $catid, $uname, $stitle, $formatted, $hometext, $comments, $counter, $acomm, $score, $ratings, $cid, $ctitle, $cdescription, $cimg, $user_name) = $db->sql_fetchrow($result)) {
$time = date(_DATESTRING, $formatted);
$title = "<a href=\"index.php?name=".$conf['name']."&op=view&id=$sid\" title=\"$stitle\">".$stitle."</a> ".new_graphic($formatted)."";
$read = "<a href=\"index.php?name=".$conf['name']."&op=view&id=$sid\" title=\"$stitle\">"._READMORE."</a>";
$post = ($user_name) ? " "._POSTEDBY.": ".user_info($user_name, 1)."" : (($uname) ? " "._POSTEDBY.": ".$uname."" : " "._POSTEDBY.": ".$confu['anonym']."");
$ndate = ($confn['newdate']) ? " "._DATE.": ".$time."" : "";
$reads = ($confn['newread']) ? " "._READS.": ".$counter."" : "";
if (!$acomm) {
if ($comments == 0) {
$comm = " <a href=\"index.php?name=".$conf['name']."&op=view&id=$sid#$sid\" title=\"$stitle\">"._COMMENTS."</a>";
} elseif ($comments == 1) {
$comm = " <a href=\"index.php?name=".$conf['name']."&op=view&id=$sid#$sid\" title=\"$stitle\">"._COMMENT.": $comments</a>";
} elseif ($comments > 1) {
$comm = " <a href=\"index.php?name=".$conf['name']."&op=view&id=$sid#$sid\" title=\"$stitle\">"._COMMENTS.": $comments</a>";
}
} else {
$comm = "";
}
$arating = " ".ajax_rating(0, $sid, $conf['name'], $ratings, $score, "");
$print = " ".ad_print("index.php?name=".$conf['name']."&op=printe&id=".$sid."");
$admin = (is_moder($conf['name'])) ? " ".add_menu($sid, "<a href=\"".$admin_file.".php?op=news_add&id=".$sid."\" title=\""._FULLEDIT."\">"._FULLEDIT."</a>||<a href=\"".$admin_file.".php?op=news_delete&id=".$sid."\" OnClick=\"return DelCheck(this, '"._DELETE." "$stitle"?');\" title=\""._ONDELETE."\">"._ONDELETE."</a>") : "";
$cdescription = ($cdescription) ? $cdescription : $ctitle;
$cimg = ($cimg) ? "<a href=\"index.php?name=".$conf['name']."&cat=$cid\"><img src=\"images/categories/".$cimg."\" border=\"0\" alt=\"$cdescription\" title=\"$cdescription\" align=\"right\" hspace=\"10\" vspace=\"10\"></a>" : "";
$link = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"75%\" align=\"left\"><b>".$read."</b>".$post."".$ndate."".$reads."".$comm."</td><td>".$arating."</td><td align=\"right\">".$print."".$admin."</td></tr></table>";
basic($cid, $cimg, $ctitle, $sid, $title, bb_decode($hometext, $conf['name']), $link, $read, $post, $ndate, $reads, $comm, $arating, $print, $admin);
}
num_article($conf['name'], $newnum, $field, "sid", "_stories", "catid", $ordernum);
}
foot();
}
function liste() {
global $prefix, $db, $pagetitle, $conf, $confu, $confn;
$cwhere = catmids($conf['name'], "s.catid");
$newlistnum = intval($confn['newlistnum']);
$let = (!preg_match("/[^a-zA-Zа-яА-Я0-9]/", $_GET['let'])) ? $_GET['let'] : "";
if ($let) {
$field = "op=liste&let=".urlencode($let)."&";
$pagetitle = "".$conf['defis']." "._NEWS." ".$conf['defis']." "._LIST." ".$conf['defis']." $let";
$order = "WHERE UPPER(s.title) LIKE '".$let."%' AND s.time <= now() AND s.status!='0'";
} else {
$field = "op=liste&";
$pagetitle = "".$conf['defis']." "._NEWS." ".$conf['defis']." "._LIST."";
$order = "WHERE s.time <= now() AND s.status!='0'";
}
$num = isset($_GET['num']) ? intval($_GET['num']) : "1";
$offset = ($num-1) * $newlistnum;
$offset = intval($offset);
$result = $db->sql_query("SELECT s.sid, s.catid, s.name, s.title, s.time, c.id, c.title, u.user_name FROM ".$prefix."_stories AS s LEFT JOIN ".$prefix."_categories AS c ON (s.catid=c.id) LEFT JOIN ".$prefix."_users AS u ON (s.uid=u.user_id) ".$order." ".$cwhere." ORDER BY time DESC LIMIT $offset, $newlistnum");
head();
menu(""._LIST."");
if ($db->sql_numrows($result) > 0) {
open();
if ($confn['newletter']) letter($conf['name']);
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"sort\" id=\"sort_id\"><tr>"
."<th>"._ID."</th><th>"._TITLE."</th><th>"._CATEGORY."</th><th>"._DATE."</th><th>"._POSTEDBY."</th></tr>";
while (list($sid, $catid, $uname, $stitle, $time, $cid, $ctitle, $user_name) = $db->sql_fetchrow($result)) {
$ctitle = (!$ctitle) ? ""._NO."" : "<a href=\"index.php?name=".$conf['name']."&cat=$cid\" title=\"".$ctitle."\">".cutstr($ctitle, 10)."</a>";
$post = ($user_name) ? user_info($user_name, 1) : (($uname) ? $uname : $confu['anonym']);
echo "<tr class=\"bgcolor1\">"
."<td align=\"center\">".$sid."</td>"
."<td><a href=\"index.php?name=".$conf['name']."&op=view&id=$sid\" title=\"".$stitle."\">".cutstr($stitle, 35)."</a></td>"
."<td align=\"center\">".$ctitle."</td>"
."<td align=\"center\">".format_time($time)."</td>"
."<td align=\"center\">".$post."</td></tr>";
}
echo "</table>";
close();
$ordernum = ($let) ? "UPPER(title) LIKE '".$let."%' AND time <= now() AND status!='0'" : "time <= now() AND status!='0'";
num_article($conf['name'], $newlistnum, $field, "sid", "_stories", "catid", $ordernum);
} else {
warning(_NO_INFO, "", "", 2);
}
foot();
}
function printe() {
global $prefix, $db, $pagetitle, $conf, $confn;
$id = intval($_GET['id']);
$cwhere = catmids($conf['name'], "catid");
$result = $db->sql_query("SELECT title, time, hometext, bodytext FROM ".$prefix."_stories WHERE sid='$id' AND time <= now() AND status!='0' ".$cwhere."");
if ($db->sql_numrows($result) == 1) {
$db->sql_query("UPDATE ".$prefix."_stories SET counter=counter+1 WHERE sid='$id'");
list($stitle, $date, $hometext, $bodytext) = $db->sql_fetchrow($result);
get_theme_inc();
$conf['defis'] = urldecode($conf['defis']);
$title = "$stitle ".$conf['defis']." "._NEWS." ".$conf['defis']." ".$conf['sitename']."";
$ptitle = "".format_time($date)." - ".$stitle."";
$text = ($bodytext) ? "".bb_decode($hometext, $conf['name'])."<br /><br />".bb_decode($bodytext, $conf['name'])."" : bb_decode($hometext, $conf['name']);
$url = ""._COMESFROM.": <a href=\"".$conf['homeurl']."\" title=\"".$conf['sitename']."\">".$conf['homeurl']."</a><br />"._THEURL.": <a href=\"".$conf['homeurl']."/index.php?name=".$conf['name']."&op=view&id=$id\" title=\"".$stitle."\">".$conf['homeurl']."/index.php?name=".$conf['name']."&op=view&id=$id</a>";
prints($title, $ptitle, str_replace("[pagebreak]", "", $text), $url);
} else {
header("Location: index.php?name=".$conf['name']."");
}
}
function view() {
global $prefix, $db, $admin_file, $conf, $confu, $confn, $pagetitle, $hometext, $bodytext;
$id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
$pag = (isset($_GET['pag'])) ? intval($_GET['pag']) : 0;
$word = (isset($_GET['word'])) ? text_filter($_GET['word']) : "";
$cwhere = catmids($conf['name'], "s.catid");
$result = $db->sql_query("SELECT s.catid, s.name, s.title, s.time, s.hometext, s.bodytext, s.field, s.comments, s.counter, s.acomm, s.score, s.ratings, s.associated, c.id, c.title, c.description, c.img, u.user_name FROM ".$prefix."_stories AS s LEFT JOIN ".$prefix."_categories AS c ON (s.catid=c.id) LEFT JOIN ".$prefix."_users AS u ON (s.uid=u.user_id) WHERE s.sid = '$id' AND s.time <= now() AND s.status!='0' ".$cwhere."");
if ($db->sql_numrows($result) == 1) {
$db->sql_query("UPDATE ".$prefix."_stories SET counter=counter+1 WHERE sid='$id'");
list($catid, $uname, $title, $time, $hometext, $bodytext, $field, $comments, $counter, $acomm, $score, $ratings, $associated, $cid, $ctitle, $cdescription, $cimg, $user_name) = $db->sql_fetchrow($result);
$pagetitle = (intval($catid)) ? "".$conf['defis']." "._NEWS." ".$conf['defis']." $ctitle ".$conf['defis']." $title" : "".$conf['defis']." "._NEWS." ".$conf['defis']." $title";
head();
menu(_NEWS);
if ($catid) templ("catlink", catlink($conf['name'], $catid, $confn['defis'], _NEWS));
$fields = fields_out($field, $conf['name']);
$fields = ($fields) ? "<br /><br />".$fields."" : "";
$text = (!$bodytext) ? "".$hometext."".$fields."" : "".$hometext."<br /><br />".$bodytext."".$fields."";
$conpag = explode("[pagebreak]", $text);
$pageno = count($conpag);
$pag = ($pag == "" || $pag < 1) ? 1 : $pag;
if ($pag > $pageno) $pag = $pageno;
$arrayelement = (int)$pag;
$arrayelement--;
$post = ($user_name) ? _POSTEDBY.": ".user_info($user_name, 1) : (($uname) ? _POSTEDBY.": ".$uname : _POSTEDBY.": ".$confu['anonym']);
$ndate = ($confn['newdate']) ? " "._DATE.": ".format_time($time) : "";
$reads = ($confn['newread']) ? " "._READS.": ".$counter."" : "";
$arating = " ".ajax_rating(1, $id, $conf['name'], $ratings, $score, "");
$print = " ".ad_print("index.php?name=".$conf['name']."&op=printe&id=".$id."");
$admin = (is_moder($conf['name'])) ? " ".add_menu($id, "<a href=\"".$admin_file.".php?op=news_add&id=".$id."\" title=\""._FULLEDIT."\">"._FULLEDIT."</a>||<a href=\"".$admin_file.".php?op=news_delete&id=".$id."\" OnClick=\"return DelCheck(this, '"._DELETE." "$title"?');\" title=\""._ONDELETE."\">"._ONDELETE."</a>") : "";
$cdescription = ($cdescription) ? $cdescription : $ctitle;
$cimg = ($cimg) ? "<a href=\"index.php?name=".$conf['name']."&cat=$cid\"><img src=\"images/categories/".$cimg."\" border=\"0\" alt=\"$cdescription\" title=\"$cdescription\" align=\"right\" hspace=\"10\" vspace=\"10\"></a>" : "";
$link = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"75%\" align=\"left\">".$post."".$ndate."".$reads."</td><td>".$arating."</td><td align=\"right\">".$print."".$admin."</td></tr></table>";
basic($cid, $cimg, $ctitle, $id, search_color($title, $word), search_color(bb_decode($conpag[$arrayelement], $conf['name']), $word), $link, "", $post, $ndate, $reads, "", $arating, $print, $admin);
num_pages($conf['name'], 1, $pageno, 1, "op=view&id=".$id."&");
if ($confn['newassoc']) {
if ($associated[strlen($associated)-1] == "-") $associated = substr($associated, 0, -1);
$asso = str_replace("-", ",", $associated);
$limit = intval($confn['newasocnum']);
$result = $db->sql_query("SELECT sid, title, time FROM ".$prefix."_stories WHERE catid IN (".$asso.") AND sid!='$id' AND time <= now() AND status!='0' ORDER BY time DESC LIMIT 0, ".$limit."");
if ($db->sql_numrows($result) > 0) {
open();
echo "<h2 style=\"margin: 0 0 5px 0;\">"._ASSTORY."</h2>"
."<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
while(list($s_sid, $title, $time) = $db->sql_fetchrow($result)) {
echo "<tr><td><a href=\"index.php?name=".$conf['name']."&op=view&id=$s_sid\" title=\"$title\"><img src=\"".img_find("all/news")."\" border=\"0\"></a></td><td>".format_time($time)." - <a href=\"index.php?name=".$conf['name']."&op=view&id=$s_sid\" title=\"$title\">$title</a></td></tr>";
}
echo "</table>";
close();
}
}
if (!$acomm) {
echo "<a name=\"$id\"></a>";
show_com($id);
}
foot();
} else {
header("Location: index.php?name=".$conf['name']."");
}
}
function add() {
global $prefix, $db, $user, $conf, $confn, $confu, $pagetitle, $stop;
$pagetitle = "".$conf['defis']." "._NEWS." ".$conf['defis']." "._ADD."";
if ((is_user() && $confn['add'] == 1) || (!is_user() && $confn['addquest'] == 1)) {
head();
menu(""._ADD."");
if ($stop) warning($stop, "", "", 1);
$subject = save_text($_POST['subject']);
$catid = intval($_POST['catid']);
$hometext = save_text($_POST['hometext']);
$bodytext = save_text($_POST['bodytext']);
$field = fields_save($_POST['field']);
$postname = text_filter(substr($_POST['postname'], 0, 25));
if ($hometext) preview($subject, $hometext, $bodytext, $field, $conf['name']);
warning(""._SUBMIT."", "", "", 2);
open();
echo "<form name=\"post\" action=\"index.php?name=".$conf['name']."\" method=\"post\">";
if (is_user()) {
echo "<div class=\"left\">"._YOURNAME.":</div><div class=\"center\">".text_filter(substr($user[1], 0, 25))."</div>";
} else {
$postname = ($postname) ? $postname : $confu['anonym'];
echo "<div class=\"left\">"._YOURNAME.":</div><div class=\"center\"><input type=\"text\" name=\"postname\" value=\"".$postname."\" size=\"65\" class=\"".$conf['style']."\"></div>";
}
echo "<div class=\"left\">"._TITLE.":</div><div class=\"center\"><input type=\"text\" name=\"subject\" value=\"".$subject."\" maxlength=\"80\" size=\"65\" class=\"".$conf['style']."\"></div>"
."<div class=\"left\">"._CATEGORY.":</div><div class=\"center\">".getcat($conf['name'], $catid, "catid", $conf['style'], "<option value=\"\">"._HOMECAT."</option>")."</div>"
."<div class=\"left\">"._TEXT.":</div><div class=\"center\">".textarea("1", "hometext", $hometext, $conf['name'], "5")."</div>"
."<div class=\"left\">"._ENDTEXT.":</div><div class=\"center\">".textarea("2", "bodytext", $bodytext, $conf['name'], "15")."</div>"
."".fields_in($field, $conf['name']).""
."".captcha_random().""
."<div class=\"button\"><select name=\"posttype\">"
."<option value=\"preview\">"._PREVIEW."</option>"
."<option value=\"save\">"._SEND."</option></select>"
."<input type=\"hidden\" name=\"op\" value=\"send\">"
." <input type=\"submit\" value=\""._OK."\" class=\"fbutton\"></div></form>";
close();
foot();
} else {
header("Location: index.php?name=".$conf['name']."");
}
}
function send() {
global $prefix, $db, $user, $conf, $confn, $stop;
if ((is_user() && $confn['add'] == 1) || (!is_user() && $confn['addquest'] == 1)) {
$postname = text_filter(substr($_POST['postname'], 0, 25));
$subject = save_text($_POST['subject']);
$hometext = save_text($_POST['hometext']);
$bodytext = save_text($_POST['bodytext']);
$field = fields_save($_POST['field']);
$catid = intval($_POST['catid']);
if (!$subject) $stop = ""._CERROR."";
if (!$hometext) $stop = ""._CERROR1."";
if (!$postname && !is_user()) $stop = ""._CERROR3."";
if (captcha_check()) $stop = ""._SECCODEINCOR."";
if (!$stop && $_POST['posttype'] == "save") {
$postid = (is_user()) ? intval($user[0]) : "";
$postname = (!is_user()) ? $postname : "";
$ip = getip();
$db->sql_query("INSERT INTO ".$prefix."_stories (sid, catid, uid, name, title, time, hometext, bodytext, field, comments, counter, ihome, acomm, score, ratings, associated, ip_sender, status) VALUES (NULL, '$catid', '$postid', '$postname', '$subject', now(), '$hometext', '$bodytext', '$field', '0', '0', '0', '0', '0', '0', '0', '$ip', '0')");
update_points(31);
head();
menu(""._ADD."");
warning(""._SUBTEXT."", "?name=".$conf['name']."", 10, 2);
foot();
} else {
add();
}
} else {
header("Location: index.php?name=".$conf['name']."");
}
}
switch($op) {
default:
news();
break;
case "liste":
liste();
break;
case "printe":
printe();
break;
case "view":
view();
break;
case "add":
add();
break;
case "send":
send();
break;
}
?>