--- inc/newsShow.php 2001/08/30 16:35:36 1.5 +++ inc/newsShow.php 2001/10/02 16:18:09 1.10 @@ -1,11 +1,42 @@ prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + while ($row = $sth->fetchrow_array()) { + $subs = get_sections($nid, $text, $row[0]); + list($w, $h) = PicSize($row[5]); + array_push($text, array( + "id" => $row[0], + "text" => $row[1], + "title" => $row[2], + "level" => $row[3], + "class" => $row[4], + "pic" => str_replace("+", "%20", urlencode($row[5])), + "alt" => $row[6], + "pos" => $row[7], + "hl" => $row[8], + "exp" => $row[9], + "subs" => $subs, + "w" => $w, + "h" => $h + )); + } + $sth->finish(); + } + function newsLoad($id, $cat = "", $limit = 0, $offset = 0, $npar = 1) { + global $dbh, $spec, $isMed; $arts = array(); if (!$offset) $offset = 0; - $sql = "SELECT news_id, title, lead, title_pic, title_alt, title_pos, url, date, ord FROM news WHERE (category = '$cat')"; - if ($id > 0) $sql .= " AND (news_id = $id)"; - $sql .= " ORDER BY date DESC"; + $sql = "SELECT DISTINCT news.news_id, title, lead, title_pic, title_alt, title_pos, url, url_title, d_orig, author_pic, author_alt, author_info, ord FROM news".(isset($cat)?", cat_news":"").($spec?", spec_news":"")." WHERE (".($isMed?"":"NOT ")."plivamed)"; + if ($id > 0) $sql .= " AND (news.news_id = $id)"; + if ($cat) $sql .= " AND ((category = '$cat') OR ((cat_news.cat_id = '$cat') AND (cat_news.news_id = news.news_id)))"; + if ($spec) $sql .= " AND (spec_news.news_id = news.news_id) AND (spec_news.spec_id = $spec)"; + $sql .= " ORDER BY d_orig DESC"; if ($limit) $sql .= " LIMIT $limit OFFSET $offset"; $sth = $dbh->prepare($sql); if (!$sth) error("Cannot prepare query: \"$sql\""); @@ -14,33 +45,16 @@ $art = array(); list($art["id"], $art["title"], $art["lead"], $art["pic_url"], $art["pic_alt"], $art["pic_pos"], $art["more"], - $date, $ord) = $row; + $art["more_title"], $art["date"], $art["au_pic"], + $art["au_alt"], $art["au_info"], $ord) = $row; + list($art["pic_w"], $art["pic_h"]) = PicSize($art["pic_url"]); + $art["more_new"] = strstr($art["more"], "://") ? true : false; + global $sysaupicdir; + list($art["au_w"], $art["au_h"]) = PicSize($art["au_pic"], $sysaupicdir); $art["pic_url"] = str_replace("+", "%20", urlencode($art["pic_url"])); - list($art["pic_w"], $art["pic_h"]) = PicSize($art["pic"]); - $text = array(); - if (isset($art["id"])) { - $sql = "SELECT paragraph_id, text, title, level, class, pic, alt, pos FROM paragraphs, par_levels WHERE (news_id = ".$art["id"].") AND (level = level_id)"; - $sth2 = $dbh->prepare($sql); - if (!$sth2) error("Cannot prepare query: \"$sql\""); - if (!$sth2->execute()) error("Cannot execute query: \"$sql\""); - while ($row = $sth2->fetchrow_array()) { - list($w, $h) = PicSize($row[5]); - array_push($text, array( - "id" => $row[0], - "text" => $row[1], - "title" => $row[2], - "level" => $row[3], - "class" => $row[4], - "pic" => str_replace("+", "%20", urlencode($row[5])), - "alt" => $row[6], - "pos" => $row[7], - "w" => $w, - "h" => $h - )); - } - $sth2->finish(); - } - $art["text"] = $text; + $art["au_pic"] = str_replace("+", "%20", urlencode($art["au_pic"])); + $art["text"] = array(); + if ($art["id"]) get_sections($art["id"], $art["text"]); $art["order"] = $ord; $art["read"] = (count($art["text"]) > $npar) ? true : false; $art["category"] = $cat; @@ -57,6 +71,8 @@ if ($arts[$i]["order"] == 0) continue; $j = ($i + $arts[$i]["order"]); $j %= count($arts); + if ($j < 0) $j += count($arts); + if ($i == $j) continue; $foo = true; $tmp = $arts[$j]; $arts[$j] = $arts[$i]; @@ -68,19 +84,37 @@ } function newsShow($art) { - global $fname, $syspicdir, $tpl; + global $fname, $tpl; $fname = "show.tpl"; - $tpl->assign("title", MyEscape($art["title"])); - $tpl->assign("lead", MyEscape($art["lead"])); - $tpl->assign("titlepic_url", MyEscape($art["pic_url"])); - $tpl->assign("titlepic_alt", MyEscape($art["pic_alt"])); + $tpl->assign("title", MyEscape(convert_html($art["title"]))); + $tpl->assign("lead", MyEscape(convert_html($art["lead"]), false)); + $tpl->assign("titlepic_url", MyEscape(convert_html($art["pic_url"]))); + $tpl->assign("titlepic_alt", MyEscape(convert_html($art["pic_alt"]))); $tpl->assign("titlepic_type", $art["pic_pos"]); - $tpl->assign("title_url", MyEscape($art["more"])); + $tpl->assign("title_url", MyEscape(convert_html($art["more"]))); + $tpl->assign("title_url_new", $art["more_new"]); + $tpl->assign("title_url_title", MyEscape(convert_html($art["more_title"]))); $tpl->assign("titlepic_width", $art["pic_w"]); $tpl->assign("titlepic_height", $art["pic_h"]); - for ($i = 0; $i < count($art["text"]); $i++) - $art["text"][$i]["text"] = ParseNewline(MyEscape($art["text"][$i]["text"]), true); + $tpl->assign("date", strftime("%d.%m.%Y.", strtotime($art["date"]))); + include_once("author.php"); + $tpl->assign("AUTHOR", GetAuthor($art["au_pic"], + $art["au_alt"], $art["au_info"], + $art["au_w"], $art["au_h"])); + for ($i = 0; $i < count($art["text"]); $i++) { + $art["text"][$i]["text"] = ParseNewline(convert_html( + MyEscape($art["text"][$i]["text"]), false), true); + $art["text"][$i]["hl"] = ParseNewline(convert_html( + MyEscape($art["text"][$i]["hl"]), false), true); + $art["text"][$i]["exp"] = ParseNewline(convert_html( + MyEscape($art["text"][$i]["exp"]), false), true); + if ($art["text"][$i]["hl"]) $art["text"][$i]["hl"] = GetHighlight($art["text"][$i]["hl"]); + if ($art["text"][$i]["level"]) $art["text"][$i]["level2"] = (($art["text"][$i]["level"] - 1) * 15) + 2; + } $tpl->assign("text", $art["text"]); $tpl->assign("cat", $art["category"]); + global $PATH; + if (is_array($PATH)) array_push($PATH, + MyUpper(MyEscape(convert_html($art["title"])))); } ?>