1 |
<?php |
<?php |
2 |
function newsLoad($id, $cat, $limit = 1, $offset = 0, $npar = 1) { |
function get_sections($nid, &$text, $par = 0) { |
3 |
global $dbh; |
global $dbh; |
4 |
|
if (!isset($nid)) return array(); |
5 |
|
if (!$par) $par = "NULL"; |
6 |
|
$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 |
|
$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 |
|
list($w2, $h2) = PicSize($row[10]); |
14 |
|
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 |
|
"full" => $row[10], |
26 |
|
"fw" => $w2, |
27 |
|
"fh" => $h2, |
28 |
|
"subs" => $subs, |
29 |
|
"w" => $w, |
30 |
|
"h" => $h |
31 |
|
)); |
32 |
|
} |
33 |
|
$sth->finish(); |
34 |
|
} |
35 |
|
function newsLoad($id, $ct = "", $limit = 0, $offset = 0, $npar = 1) { |
36 |
|
global $dbh, $spec, $isMed, $isEdit; |
37 |
$arts = array(); |
$arts = array(); |
38 |
if (!$offset) $offset = 0; |
if (!$offset) $offset = 0; |
39 |
$sql = "SELECT news_id, title, lead, title_pic, title_alt, title_pos, url, date, ord FROM news WHERE (category = '$cat')"; |
if (!$spec && $isMed) $spec = 0; |
40 |
if ($id > 0) $sql .= " AND (news_id = $id)"; |
$conds = array(); |
41 |
$sql .= " ORDER BY date DESC"; |
if (!$isEdit) array_push($conds, "(prikazi)"); |
42 |
if ($limit) $sql .= " LIMIT $limit OFFSET $offset"; |
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, exclusive 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 |
|
if ($limit && !$isEdit) $sql .= " LIMIT $limit"; |
52 |
|
if ($offset) $sql .= " OFFSET $offset"; |
53 |
$sth = $dbh->prepare($sql); |
$sth = $dbh->prepare($sql); |
54 |
if (!$sth) error("Cannot prepare query: \"$sql\""); |
if (!$sth) error("Cannot prepare query: \"$sql\""); |
55 |
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
57 |
$art = array(); |
$art = array(); |
58 |
list($art["id"], $art["title"], $art["lead"], $art["pic_url"], |
list($art["id"], $art["title"], $art["lead"], $art["pic_url"], |
59 |
$art["pic_alt"], $art["pic_pos"], $art["more"], |
$art["pic_alt"], $art["pic_pos"], $art["more"], |
60 |
$date, $ord) = $row; |
$art["more_title"], $art["date"], $art["au_pic"], |
61 |
list($art["pic_w"], $art["pic_h"]) = PicSize($art["pic"]); |
$art["au_alt"], $art["au_info"], $art["au_name"], |
62 |
$text = array(); |
$art["au_cv"], $ord, $art["show"], $art["ex"]) = $row; |
63 |
if (isset($art["id"])) { |
$art["show"] = ($art["show"][0] == "f" || $art["show"][0] == "F") ? false : true; |
64 |
$sql = "SELECT paragraph_id, text, title, level, class, pic, alt, pos FROM paragraphs, par_levels WHERE (news_id = ".$art["id"].") AND (level = level_id)"; |
$art["ex"] = ($art["ex"][0] == "f" || $art["ex"][0] == "F") ? false : true; |
65 |
$sth2 = $dbh->prepare($sql); |
list($art["pic_w"], $art["pic_h"]) = PicSize($art["pic_url"]); |
66 |
if (!$sth2) error("Cannot prepare query: \"$sql\""); |
$art["more_new"] = strstr($art["more"], "://") ? true : false; |
67 |
if (!$sth2->execute()) error("Cannot execute query: \"$sql\""); |
global $sysaupicdir; |
68 |
while ($row = $sth2->fetchrow_array()) { |
list($art["au_w"], $art["au_h"]) = PicSize($art["au_pic"], $sysaupicdir); |
69 |
list($w, $h) = PicSize($row[5]); |
$art["pic_url"] = str_replace("+", "%20", urlencode($art["pic_url"])); |
70 |
array_push($text, array( |
$art["au_pic"] = str_replace("+", "%20", urlencode($art["au_pic"])); |
71 |
"id" => $row[0], |
$art["text"] = array(); |
72 |
"text" => $row[1], |
if ($art["id"]) get_sections($art["id"], $art["text"]); |
|
"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; |
|
73 |
$art["order"] = $ord; |
$art["order"] = $ord; |
74 |
$art["read"] = (count($art["text"]) > $npar) ? true : false; |
$sql = "SELECT rel_id FROM related WHERE (news_id = ".$art["id"].")"; |
75 |
$art["category"] = $cat; |
$sth2 = $dbh->prepare($sql); |
76 |
|
if (!$sth2) error("Cannot prepare query: \"$sql\""); |
77 |
|
if (!$sth2->execute()) error("Cannot execute query: \"$sql\""); |
78 |
|
$row = $sth2->fetchrow_array(); |
79 |
|
$sth2->finish(); |
80 |
|
$art["related"] = $row ? true : false; |
81 |
|
$art["read"] = (count($art["text"]) > $npar || $art["more"] || $art["related"]) ? GetRead($art["id"], $ct) : ""; |
82 |
|
$art["category"] = $ct; |
83 |
$art["limit"] = $limit; |
$art["limit"] = $limit; |
84 |
$art["offset"] = $offset; |
$art["offset"] = $offset; |
85 |
$art["npar"] = $npar; |
$art["npar"] = $npar; |
93 |
if ($arts[$i]["order"] == 0) continue; |
if ($arts[$i]["order"] == 0) continue; |
94 |
$j = ($i + $arts[$i]["order"]); |
$j = ($i + $arts[$i]["order"]); |
95 |
$j %= count($arts); |
$j %= count($arts); |
96 |
|
if ($j < 0) $j += count($arts); |
97 |
|
if ($i == $j) continue; |
98 |
$foo = true; |
$foo = true; |
99 |
$tmp = $arts[$j]; |
$tmp = $arts[$j]; |
100 |
$arts[$j] = $arts[$i]; |
$arts[$j] = $arts[$i]; |
106 |
} |
} |
107 |
|
|
108 |
function newsShow($art) { |
function newsShow($art) { |
109 |
global $fname, $syspicdir, $tpl; |
global $fname, $tpl, $acat, $acat2, $dbh; |
110 |
$fname = "show.tpl"; |
$fname = "show.tpl"; |
111 |
$tpl->assign("title", MyEscape($art["title"])); |
$tpl->assign("title", MyEscape(convert_html($art["title"]))); |
112 |
$tpl->assign("lead", MyEscape($art["lead"])); |
$tpl->assign("lead", ParseNewline(MyEscape(convert_html($art["lead"]), false), false)); |
113 |
$tpl->assign("titlepic_url", MyEscape($art["pic_url"])); |
$tpl->assign("titlepic_url", MyEscape(convert_html($art["pic_url"]))); |
114 |
$tpl->assign("titlepic_alt", MyEscape($art["pic_alt"])); |
$tpl->assign("titlepic_alt", MyEscape(convert_html($art["pic_alt"]))); |
115 |
$tpl->assign("titlepic_type", $art["pic_pos"]); |
$tpl->assign("titlepic_type", $art["pic_pos"]); |
116 |
$tpl->assign("title_url", MyEscape($art["more"])); |
$tpl->assign("title_url", MyEscape(convert_html($art["more"]))); |
117 |
|
$tpl->assign("title_url_new", $art["more_new"]); |
118 |
|
$tpl->assign("title_url_title", MyEscape(convert_html($art["more_title"]))); |
119 |
$tpl->assign("titlepic_width", $art["pic_w"]); |
$tpl->assign("titlepic_width", $art["pic_w"]); |
120 |
$tpl->assign("titlepic_height", $art["pic_h"]); |
$tpl->assign("titlepic_height", $art["pic_h"]); |
121 |
for ($i = 0; $i < count($art["text"]); $i++) |
$tpl->assign("date", $art["date"] ? strftime("%d.%m.%Y.", strtotime($art["date"])) : ""); |
122 |
$art["text"][$i]["text"] = ParseNewline(MyEscape($art["text"][$i]["text"])); |
$tpl->assign("AUTHOR", GetAuthor($art["au_pic"], $art["au_alt"], |
123 |
|
$art["au_info"], $art["au_w"], $art["au_h"], $art["au_cv"])); |
124 |
|
$tpl->assign("exclusive", $art["ex"]); |
125 |
|
$some_title = false; |
126 |
|
for ($i = 0; $i < count($art["text"]); $i++) { |
127 |
|
if ($art["text"][$i]["title"]) $some_title = true; |
128 |
|
if ($art["text"][$i]["text"]) { |
129 |
|
$art["text"][$i]["text"] = ParseNewline(MyEscape( |
130 |
|
convert_html($art["text"][$i]["text"]), false), true); |
131 |
|
} |
132 |
|
if ($art["text"][$i]["exp"]) { |
133 |
|
$art["text"][$i]["exp"] = ParseNewline(MyEscape( |
134 |
|
convert_html($art["text"][$i]["exp"]), false), true); |
135 |
|
} |
136 |
|
if ($art["text"][$i]["hl"]) { |
137 |
|
$art["text"][$i]["hl"] = GetHighlight(ParseNewline( |
138 |
|
MyEscape($art["text"][$i]["hl"], false), false)); |
139 |
|
} |
140 |
|
if ($art["text"][$i]["level"]) $art["text"][$i]["level2"] = (($art["text"][$i]["level"] - 1) * 15) + 2; |
141 |
|
} |
142 |
$tpl->assign("text", $art["text"]); |
$tpl->assign("text", $art["text"]); |
143 |
$tpl->assign("cat", $art["category"]); |
$tpl->assign("cat", $art["category"]); |
144 |
|
$tpl->assign("acat", $acat); |
145 |
|
$tpl->assign("acat2", $acat2); |
146 |
|
$tpl->assign("pgfs", count($art["text"])); |
147 |
|
$tpl->assign("some_title", $some_title); |
148 |
|
if ($art["id"]) { |
149 |
|
$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"; |
150 |
|
$sth = $dbh->prepare($sql); |
151 |
|
if (!$sth) error("Cannot prepare query: \"$sql\""); |
152 |
|
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
153 |
|
$related = array(); |
154 |
|
while ($row = $sth->fetchrow_array()) { |
155 |
|
list($id, $cat, $title, $lead, $pic, $alt) = $row; |
156 |
|
if ($pic) list($w, $h) = PicSize($pic); |
157 |
|
array_push($related, array( |
158 |
|
"id" => $id, |
159 |
|
"title" => MyEscape($title), |
160 |
|
"lead" => ParseNewline(MyEscape($lead), false), |
161 |
|
"pic" => MyEscape($pic), "w" => $w, "h" => $h, |
162 |
|
"alt" => MyEscape($alt), |
163 |
|
"read" => GetRead($id, $cat) |
164 |
|
)); |
165 |
|
} |
166 |
|
$sth->finish(); |
167 |
|
$tpl->assign("related", $related); |
168 |
|
} |
169 |
|
global $PATH; |
170 |
|
if (is_array($PATH)) array_push($PATH, |
171 |
|
MyUpper(MyEscape(convert_html($art["title"])))); |
172 |
} |
} |
173 |
?> |
?> |