--- inc/newsShow.php 2001/08/03 09:12:42 1.1.1.1 +++ inc/newsShow.php 2001/10/30 16:11:28 1.20 @@ -1,66 +1,174 @@ 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]); + list($w2, $h2) = PicSize($row[10]); + 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], + "full" => $row[10], + "fw" => $w2, + "fh" => $h2, + "subs" => $subs, + "w" => $w, + "h" => $h + )); + } + $sth->finish(); + } + function newsLoad($id, $ct = "", $limit = 0, $offset = 0, $npar = 1) { + global $dbh, $spec, $isMed, $isEdit; $arts = array(); - $sql = "SELECT news_id, title, lead, title_pic, title_alt, title_pos, url, date FROM news WHERE (category = '$cat')"; - if ($id > 0) $sql .= " AND (news_id = $id)"; - $sql .= " ORDER BY date DESC LIMIT $limit"; + if (!$offset) $offset = 0; + 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); if (!$sth) error("Cannot prepare query: \"$sql\""); if (!$sth->execute()) error("Cannot execute query: \"$sql\""); while ($row = $sth->fetchrow_array()) { $art = array(); list($art["id"], $art["title"], $art["lead"], $art["pic_url"], - $art["pic_alt"], $art["pic_pos"], $art["more"], $date) = $row; - list($art["pic_w"], $art["pic_h"]) = PicSize($art["pic"]); - $text = array(); - if ($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" => $row[5], - "alt" => $row[6], - "pos" => $row[7], - "w" => $w, - "h" => $h - )); - } - $sth2->finish(); - } - $art["text"] = $text; - $art["read"] = (count($text) > $npar) ? true : false; - $art["category"] = $cat; + $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"], + $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; + list($art["au_w"], $art["au_h"]) = PicSize($art["au_pic"], $sysaupicdir); + $art["pic_url"] = str_replace("+", "%20", urlencode($art["pic_url"])); + $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; + $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; $art["npar"] = $npar; array_push($arts, $art); } $sth->finish(); + $foo = true; + while ($foo) { + $foo = false; + for ($i = 0; $i < count($arts); $i++) { + 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]; + $arts[$i] = $tmp; + $arts[$j]["order"] = 0; + } + } return $arts; } function newsShow($art) { - global $fname, $syspicdir, $tpl; + global $fname, $tpl, $acat, $acat2, $dbh; $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", ParseNewline(MyEscape(convert_html($art["lead"]), false), 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"])); + $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"], $art["au_cv"])); + $tpl->assign("exclusive", $art["ex"]); + $some_title = false; + for ($i = 0; $i < count($art["text"]); $i++) { + 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("id", $art["id"]); $tpl->assign("text", $art["text"]); $tpl->assign("cat", $art["category"]); + $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"])))); } ?>