--- inc/newsShow.php 2001/10/12 13:13:38 1.15 +++ inc/newsShow.php 2001/10/27 16:54:50 1.19 @@ -36,12 +36,18 @@ global $dbh, $spec, $isMed, $isEdit; $arts = array(); if (!$offset) $offset = 0; - $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, author_name, ord, prikazi FROM news".(isset($ct)?", cat_news":"").($spec?", spec_news":"")." WHERE (".($isMed?"":"NOT ")."plivamed)".($isEdit?"":" AND (prikazi)"); - if ($id > 0) $sql .= " AND (news.news_id = $id)"; - if ($ct) $sql .= " AND ((category = '$ct') OR ((cat_news.cat_id = '$ct') 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)"; - if ($limit && $isEdit) $sql .= ""; - $sql .= " ORDER BY d_orig DESC"; + if (!$spec && $isMed) $spec = 0; + $conds = array(); + if (!$isEdit) array_push($conds, "(prikazi)"); + if (!$id || $id < 0) array_push($conds, $isMed ? "(plivamed)" : "(NOT plivamed)"); + if ($id > 0) array_push($conds, "(news.news_id = $id)"); + if ($ct) array_push($conds, "((category = '$ct') OR ((cat_news.cat_id = '$ct') AND (cat_news.news_id = news.news_id)))"); + if (isset($spec) && (!$id || $id < 0)) array_push($conds, "((spec_news.news_id = news.news_id) AND (spec_news.spec_id = $spec))"); + # if ($limit && $isEdit) array_push($conds, ""); + $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, author_name, autor_cv, ord, prikazi, exclusive FROM news".(isset($ct)?", cat_news":"").((isset($spec)&&(!$id||$id<0))?", spec_news":""); + $conds = implode(" AND ", $conds); + if ($conds) $sql .= " WHERE ".$conds; + $sql .= " ORDER BY d_orig DESC, title"; if ($limit && !$isEdit) $sql .= " LIMIT $limit"; if ($offset) $sql .= " OFFSET $offset"; $sth = $dbh->prepare($sql); @@ -53,8 +59,9 @@ $art["pic_alt"], $art["pic_pos"], $art["more"], $art["more_title"], $art["date"], $art["au_pic"], $art["au_alt"], $art["au_info"], $art["au_name"], - $ord, $art["show"]) = $row; + $art["au_cv"], $ord, $art["show"], $art["ex"]) = $row; $art["show"] = ($art["show"][0] == "f" || $art["show"][0] == "F") ? false : true; + $art["ex"] = ($art["ex"][0] == "f" || $art["ex"][0] == "F") ? false : true; list($art["pic_w"], $art["pic_h"]) = PicSize($art["pic_url"]); $art["more_new"] = strstr($art["more"], "://") ? true : false; global $sysaupicdir; @@ -64,7 +71,14 @@ $art["text"] = array(); if ($art["id"]) get_sections($art["id"], $art["text"]); $art["order"] = $ord; - $art["read"] = (count($art["text"]) > $npar) ? GetRead($art["id"], $ct) : ""; + $sql = "SELECT rel_id FROM related WHERE (news_id = ".$art["id"].")"; + $sth2 = $dbh->prepare($sql); + if (!$sth2) error("Cannot prepare query: \"$sql\""); + if (!$sth2->execute()) error("Cannot execute query: \"$sql\""); + $row = $sth2->fetchrow_array(); + $sth2->finish(); + $art["related"] = $row ? true : false; + $art["read"] = (count($art["text"]) > $npar || $art["more"] || $art["related"]) ? GetRead($art["id"], $ct) : ""; $art["category"] = $ct; $art["limit"] = $limit; $art["offset"] = $offset; @@ -92,7 +106,7 @@ } function newsShow($art) { - global $fname, $tpl, $acat, $acat2; + global $fname, $tpl, $acat, $acat2, $dbh; $fname = "show.tpl"; $tpl->assign("title", MyEscape(convert_html($art["title"]))); $tpl->assign("lead", ParseNewline(MyEscape(convert_html($art["lead"]), false), false)); @@ -105,17 +119,24 @@ $tpl->assign("titlepic_width", $art["pic_w"]); $tpl->assign("titlepic_height", $art["pic_h"]); $tpl->assign("date", $art["date"] ? strftime("%d.%m.%Y.", strtotime($art["date"])) : ""); - $tpl->assign("AUTHOR", GetAuthor($art["au_pic"], - $art["au_alt"], $art["au_info"], - $art["au_w"], $art["au_h"])); + $tpl->assign("AUTHOR", GetAuthor($art["au_pic"], $art["au_alt"], + $art["au_info"], $art["au_w"], $art["au_h"], $art["au_cv"])); + $tpl->assign("exclusive", $art["ex"]); + $some_title = false; 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]["title"]) $some_title = true; + if ($art["text"][$i]["text"]) { + $art["text"][$i]["text"] = ParseNewline(MyEscape( + convert_html($art["text"][$i]["text"]), false), true); + } + if ($art["text"][$i]["exp"]) { + $art["text"][$i]["exp"] = ParseNewline(MyEscape( + convert_html($art["text"][$i]["exp"]), false), true); + } + if ($art["text"][$i]["hl"]) { + $art["text"][$i]["hl"] = GetHighlight(ParseNewline( + MyEscape($art["text"][$i]["hl"], false), false)); + } if ($art["text"][$i]["level"]) $art["text"][$i]["level2"] = (($art["text"][$i]["level"] - 1) * 15) + 2; } $tpl->assign("text", $art["text"]); @@ -123,6 +144,28 @@ $tpl->assign("acat", $acat); $tpl->assign("acat2", $acat2); $tpl->assign("pgfs", count($art["text"])); + $tpl->assign("some_title", $some_title); + if ($art["id"]) { + $sql = "SELECT news.news_id, news.category, news.title, news.lead, news.title_pic, news.title_alt FROM news, related WHERE (news.news_id = related.rel_id) AND (related.news_id = ".$art["id"].") AND (prikazi) ORDER BY d_orig DESC"; + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + $related = array(); + while ($row = $sth->fetchrow_array()) { + list($id, $cat, $title, $lead, $pic, $alt) = $row; + if ($pic) list($w, $h) = PicSize($pic); + array_push($related, array( + "id" => $id, + "title" => MyEscape($title), + "lead" => ParseNewline(MyEscape($lead), false), + "pic" => MyEscape($pic), "w" => $w, "h" => $h, + "alt" => MyEscape($alt), + "read" => GetRead($id, $cat) + )); + } + $sth->finish(); + $tpl->assign("related", $related); + } global $PATH; if (is_array($PATH)) array_push($PATH, MyUpper(MyEscape(convert_html($art["title"]))));