/[health_html]/inc/newsShow.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /inc/newsShow.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (hide annotations)
Tue Oct 23 16:13:59 2001 UTC (22 years, 6 months ago) by ravilov
Branch: MAIN
Changes since 1.16: +54 -17 lines
Added an author's CV. Added a secondary main article. Added the Related fields to news editor, and also fixed some bugs in it. Other bugfixes and improvements.

1 ravilov 1.1 <?php
2 ravilov 1.8 function get_sections($nid, &$text, $par = 0) {
3     global $dbh;
4     if (!isset($nid)) return array();
5     if (!$par) $par = "NULL";
6 ravilov 1.15 $sql = "SELECT paragraph_id, text, title, level, class, pic, alt, pos, hl, pic_title, full_pic FROM paragraphs, par_levels WHERE (news_id = $nid) AND (level = level_id) AND (parent = $par)";
7 ravilov 1.8 $sth = $dbh->prepare($sql);
8     if (!$sth) error("Cannot prepare query: \"$sql\"");
9     if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
10     while ($row = $sth->fetchrow_array()) {
11     $subs = get_sections($nid, $text, $row[0]);
12     list($w, $h) = PicSize($row[5]);
13 ravilov 1.15 list($w2, $h2) = PicSize($row[10]);
14 ravilov 1.8 array_push($text, array(
15     "id" => $row[0],
16     "text" => $row[1],
17     "title" => $row[2],
18     "level" => $row[3],
19     "class" => $row[4],
20     "pic" => str_replace("+", "%20", urlencode($row[5])),
21     "alt" => $row[6],
22     "pos" => $row[7],
23     "hl" => $row[8],
24     "exp" => $row[9],
25 ravilov 1.15 "full" => $row[10],
26     "fw" => $w2,
27     "fh" => $h2,
28 ravilov 1.8 "subs" => $subs,
29     "w" => $w,
30     "h" => $h
31     ));
32     }
33     $sth->finish();
34     }
35 ravilov 1.11 function newsLoad($id, $ct = "", $limit = 0, $offset = 0, $npar = 1) {
36 ravilov 1.12 global $dbh, $spec, $isMed, $isEdit;
37 ravilov 1.1 $arts = array();
38 ravilov 1.4 if (!$offset) $offset = 0;
39 ravilov 1.16 if (!$spec && $isMed) $spec = 0;
40 ravilov 1.17 $conds = array();
41     if (!$isEdit) array_push($conds, "(prikazi)");
42     if (!$id || $id < 0) array_push($conds, $isMed ? "(plivamed)" : "(NOT plivamed)");
43     if ($id > 0) array_push($conds, "(news.news_id = $id)");
44     if ($ct) array_push($conds, "((category = '$ct') OR ((cat_news.cat_id = '$ct') AND (cat_news.news_id = news.news_id)))");
45     if (isset($spec) && (!$id || $id < 0)) array_push($conds, "((spec_news.news_id = news.news_id) AND (spec_news.spec_id = $spec))");
46     # if ($limit && $isEdit) array_push($conds, "");
47     $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 FROM news".(isset($ct)?", cat_news":"").((isset($spec)&&(!$id||$id<0))?", spec_news":"");
48     $conds = implode(" AND ", $conds);
49     if ($conds) $sql .= " WHERE ".$conds;
50     $sql .= " ORDER BY d_orig DESC, title";
51 ravilov 1.13 if ($limit && !$isEdit) $sql .= " LIMIT $limit";
52     if ($offset) $sql .= " OFFSET $offset";
53 ravilov 1.1 $sth = $dbh->prepare($sql);
54     if (!$sth) error("Cannot prepare query: \"$sql\"");
55     if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
56     while ($row = $sth->fetchrow_array()) {
57     $art = array();
58     list($art["id"], $art["title"], $art["lead"], $art["pic_url"],
59 ravilov 1.3 $art["pic_alt"], $art["pic_pos"], $art["more"],
60 ravilov 1.10 $art["more_title"], $art["date"], $art["au_pic"],
61 ravilov 1.11 $art["au_alt"], $art["au_info"], $art["au_name"],
62 ravilov 1.16 $art["au_cv"], $ord, $art["show"]) = $row;
63 ravilov 1.12 $art["show"] = ($art["show"][0] == "f" || $art["show"][0] == "F") ? false : true;
64 ravilov 1.8 list($art["pic_w"], $art["pic_h"]) = PicSize($art["pic_url"]);
65 ravilov 1.7 $art["more_new"] = strstr($art["more"], "://") ? true : false;
66     global $sysaupicdir;
67     list($art["au_w"], $art["au_h"]) = PicSize($art["au_pic"], $sysaupicdir);
68 ravilov 1.5 $art["pic_url"] = str_replace("+", "%20", urlencode($art["pic_url"]));
69 ravilov 1.7 $art["au_pic"] = str_replace("+", "%20", urlencode($art["au_pic"]));
70 ravilov 1.8 $art["text"] = array();
71     if ($art["id"]) get_sections($art["id"], $art["text"]);
72 ravilov 1.3 $art["order"] = $ord;
73 ravilov 1.16 $art["read"] = (count($art["text"]) > $npar || $art["more"]) ? GetRead($art["id"], $ct) : "";
74 ravilov 1.11 $art["category"] = $ct;
75 ravilov 1.1 $art["limit"] = $limit;
76 ravilov 1.4 $art["offset"] = $offset;
77 ravilov 1.1 $art["npar"] = $npar;
78 ravilov 1.17 $sql = "SELECT rel_id FROM related WHERE (news_id = ".$art["id"].") LIMIT 1";
79     $sth2 = $dbh->prepare($sql);
80     if (!$sth2) error("Cannot prepare query: \"$sql\"");
81     if (!$sth2->execute()) error("Cannot execute query: \"$sql\"");
82     $row = $sth2->fetchrow_array();
83     $sth2->finish();
84     $art["related"] = $row ? true : false;
85 ravilov 1.1 array_push($arts, $art);
86     }
87     $sth->finish();
88 ravilov 1.3 $foo = true;
89     while ($foo) {
90     $foo = false;
91     for ($i = 0; $i < count($arts); $i++) {
92     if ($arts[$i]["order"] == 0) continue;
93     $j = ($i + $arts[$i]["order"]);
94     $j %= count($arts);
95 ravilov 1.7 if ($j < 0) $j += count($arts);
96     if ($i == $j) continue;
97 ravilov 1.3 $foo = true;
98     $tmp = $arts[$j];
99     $arts[$j] = $arts[$i];
100     $arts[$i] = $tmp;
101     $arts[$j]["order"] = 0;
102     }
103     }
104 ravilov 1.1 return $arts;
105     }
106    
107     function newsShow($art) {
108 ravilov 1.17 global $fname, $tpl, $acat, $acat2, $dbh;
109 ravilov 1.1 $fname = "show.tpl";
110 ravilov 1.7 $tpl->assign("title", MyEscape(convert_html($art["title"])));
111 ravilov 1.14 $tpl->assign("lead", ParseNewline(MyEscape(convert_html($art["lead"]), false), false));
112 ravilov 1.7 $tpl->assign("titlepic_url", MyEscape(convert_html($art["pic_url"])));
113     $tpl->assign("titlepic_alt", MyEscape(convert_html($art["pic_alt"])));
114 ravilov 1.1 $tpl->assign("titlepic_type", $art["pic_pos"]);
115 ravilov 1.7 $tpl->assign("title_url", MyEscape(convert_html($art["more"])));
116     $tpl->assign("title_url_new", $art["more_new"]);
117     $tpl->assign("title_url_title", MyEscape(convert_html($art["more_title"])));
118 ravilov 1.1 $tpl->assign("titlepic_width", $art["pic_w"]);
119     $tpl->assign("titlepic_height", $art["pic_h"]);
120 ravilov 1.11 $tpl->assign("date", $art["date"] ? strftime("%d.%m.%Y.", strtotime($art["date"])) : "");
121 ravilov 1.17 $tpl->assign("AUTHOR", GetAuthor($art["au_pic"], $art["au_alt"],
122     $art["au_info"], $art["au_w"], $art["au_h"], $art["au_cv"]));
123 ravilov 1.7 for ($i = 0; $i < count($art["text"]); $i++) {
124 ravilov 1.17 if ($art["text"][$i]["text"]) {
125     $art["text"][$i]["text"] = ParseNewline(MyEscape(
126     convert_html($art["text"][$i]["text"]), false), true);
127     }
128     if ($art["text"][$i]["exp"]) {
129     $art["text"][$i]["exp"] = ParseNewline(MyEscape(
130     convert_html($art["text"][$i]["exp"]), false), true);
131     }
132     if ($art["text"][$i]["hl"]) {
133     $art["text"][$i]["hl"] = GetHighlight(ParseNewline(
134     MyEscape($art["text"][$i]["hl"], false), false));
135     }
136 ravilov 1.10 if ($art["text"][$i]["level"]) $art["text"][$i]["level2"] = (($art["text"][$i]["level"] - 1) * 15) + 2;
137 ravilov 1.7 }
138 ravilov 1.1 $tpl->assign("text", $art["text"]);
139     $tpl->assign("cat", $art["category"]);
140 ravilov 1.11 $tpl->assign("acat", $acat);
141     $tpl->assign("acat2", $acat2);
142 ravilov 1.13 $tpl->assign("pgfs", count($art["text"]));
143 ravilov 1.17 if ($art["id"]) {
144     $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";
145     $sth = $dbh->prepare($sql);
146     if (!$sth) error("Cannot prepare query: \"$sql\"");
147     if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
148     $related = array();
149     while ($row = $sth->fetchrow_array()) {
150     list($id, $cat, $title, $lead, $pic, $alt) = $row;
151     if ($pic) list($w, $h) = PicSize($pic);
152     array_push($related, array(
153     "id" => $id,
154     "title" => MyEscape($title),
155     "lead" => ParseNewline(MyEscape($lead), false),
156     "pic" => MyEscape($pic), "w" => $w, "h" => $h,
157     "alt" => MyEscape($alt),
158     "read" => GetRead($id, $cat)
159     ));
160     }
161     $sth->finish();
162     $tpl->assign("related", $related);
163     }
164 ravilov 1.8 global $PATH;
165     if (is_array($PATH)) array_push($PATH,
166     MyUpper(MyEscape(convert_html($art["title"]))));
167 ravilov 1.1 }
168     ?>

  ViewVC Help
Powered by ViewVC 1.1.26