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 |
|
|
$sql = "SELECT paragraph_id, text, title, level, class, pic, alt, pos, hl, pic_title 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 |
|
|
array_push($text, array( |
14 |
|
|
"id" => $row[0], |
15 |
|
|
"text" => $row[1], |
16 |
|
|
"title" => $row[2], |
17 |
|
|
"level" => $row[3], |
18 |
|
|
"class" => $row[4], |
19 |
|
|
"pic" => str_replace("+", "%20", urlencode($row[5])), |
20 |
|
|
"alt" => $row[6], |
21 |
|
|
"pos" => $row[7], |
22 |
|
|
"hl" => $row[8], |
23 |
|
|
"exp" => $row[9], |
24 |
|
|
"subs" => $subs, |
25 |
|
|
"w" => $w, |
26 |
|
|
"h" => $h |
27 |
|
|
)); |
28 |
|
|
} |
29 |
|
|
$sth->finish(); |
30 |
|
|
} |
31 |
ravilov |
1.11 |
function newsLoad($id, $ct = "", $limit = 0, $offset = 0, $npar = 1) { |
32 |
ravilov |
1.12 |
global $dbh, $spec, $isMed, $isEdit; |
33 |
ravilov |
1.1 |
$arts = array(); |
34 |
ravilov |
1.4 |
if (!$offset) $offset = 0; |
35 |
ravilov |
1.12 |
$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)"); |
36 |
ravilov |
1.8 |
if ($id > 0) $sql .= " AND (news.news_id = $id)"; |
37 |
ravilov |
1.11 |
if ($ct) $sql .= " AND ((category = '$ct') OR ((cat_news.cat_id = '$ct') AND (cat_news.news_id = news.news_id)))"; |
38 |
ravilov |
1.7 |
if ($spec) $sql .= " AND (spec_news.news_id = news.news_id) AND (spec_news.spec_id = $spec)"; |
39 |
ravilov |
1.13 |
if ($limit && $isEdit) $sql .= ""; |
40 |
ravilov |
1.9 |
$sql .= " ORDER BY d_orig DESC"; |
41 |
ravilov |
1.13 |
if ($limit && !$isEdit) $sql .= " LIMIT $limit"; |
42 |
|
|
if ($offset) $sql .= " OFFSET $offset"; |
43 |
ravilov |
1.1 |
$sth = $dbh->prepare($sql); |
44 |
|
|
if (!$sth) error("Cannot prepare query: \"$sql\""); |
45 |
|
|
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
46 |
|
|
while ($row = $sth->fetchrow_array()) { |
47 |
|
|
$art = array(); |
48 |
|
|
list($art["id"], $art["title"], $art["lead"], $art["pic_url"], |
49 |
ravilov |
1.3 |
$art["pic_alt"], $art["pic_pos"], $art["more"], |
50 |
ravilov |
1.10 |
$art["more_title"], $art["date"], $art["au_pic"], |
51 |
ravilov |
1.11 |
$art["au_alt"], $art["au_info"], $art["au_name"], |
52 |
ravilov |
1.12 |
$ord, $art["show"]) = $row; |
53 |
|
|
$art["show"] = ($art["show"][0] == "f" || $art["show"][0] == "F") ? false : true; |
54 |
ravilov |
1.8 |
list($art["pic_w"], $art["pic_h"]) = PicSize($art["pic_url"]); |
55 |
ravilov |
1.7 |
$art["more_new"] = strstr($art["more"], "://") ? true : false; |
56 |
|
|
global $sysaupicdir; |
57 |
|
|
list($art["au_w"], $art["au_h"]) = PicSize($art["au_pic"], $sysaupicdir); |
58 |
ravilov |
1.5 |
$art["pic_url"] = str_replace("+", "%20", urlencode($art["pic_url"])); |
59 |
ravilov |
1.7 |
$art["au_pic"] = str_replace("+", "%20", urlencode($art["au_pic"])); |
60 |
ravilov |
1.8 |
$art["text"] = array(); |
61 |
|
|
if ($art["id"]) get_sections($art["id"], $art["text"]); |
62 |
ravilov |
1.3 |
$art["order"] = $ord; |
63 |
ravilov |
1.11 |
$art["read"] = (count($art["text"]) > $npar) ? GetRead($art["id"], $ct) : ""; |
64 |
|
|
$art["category"] = $ct; |
65 |
ravilov |
1.1 |
$art["limit"] = $limit; |
66 |
ravilov |
1.4 |
$art["offset"] = $offset; |
67 |
ravilov |
1.1 |
$art["npar"] = $npar; |
68 |
|
|
array_push($arts, $art); |
69 |
|
|
} |
70 |
|
|
$sth->finish(); |
71 |
ravilov |
1.3 |
$foo = true; |
72 |
|
|
while ($foo) { |
73 |
|
|
$foo = false; |
74 |
|
|
for ($i = 0; $i < count($arts); $i++) { |
75 |
|
|
if ($arts[$i]["order"] == 0) continue; |
76 |
|
|
$j = ($i + $arts[$i]["order"]); |
77 |
|
|
$j %= count($arts); |
78 |
ravilov |
1.7 |
if ($j < 0) $j += count($arts); |
79 |
|
|
if ($i == $j) continue; |
80 |
ravilov |
1.3 |
$foo = true; |
81 |
|
|
$tmp = $arts[$j]; |
82 |
|
|
$arts[$j] = $arts[$i]; |
83 |
|
|
$arts[$i] = $tmp; |
84 |
|
|
$arts[$j]["order"] = 0; |
85 |
|
|
} |
86 |
|
|
} |
87 |
ravilov |
1.1 |
return $arts; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
function newsShow($art) { |
91 |
ravilov |
1.11 |
global $fname, $tpl, $acat, $acat2; |
92 |
ravilov |
1.1 |
$fname = "show.tpl"; |
93 |
ravilov |
1.7 |
$tpl->assign("title", MyEscape(convert_html($art["title"]))); |
94 |
ravilov |
1.14 |
$tpl->assign("lead", ParseNewline(MyEscape(convert_html($art["lead"]), false), false)); |
95 |
ravilov |
1.7 |
$tpl->assign("titlepic_url", MyEscape(convert_html($art["pic_url"]))); |
96 |
|
|
$tpl->assign("titlepic_alt", MyEscape(convert_html($art["pic_alt"]))); |
97 |
ravilov |
1.1 |
$tpl->assign("titlepic_type", $art["pic_pos"]); |
98 |
ravilov |
1.7 |
$tpl->assign("title_url", MyEscape(convert_html($art["more"]))); |
99 |
|
|
$tpl->assign("title_url_new", $art["more_new"]); |
100 |
|
|
$tpl->assign("title_url_title", MyEscape(convert_html($art["more_title"]))); |
101 |
ravilov |
1.1 |
$tpl->assign("titlepic_width", $art["pic_w"]); |
102 |
|
|
$tpl->assign("titlepic_height", $art["pic_h"]); |
103 |
ravilov |
1.11 |
$tpl->assign("date", $art["date"] ? strftime("%d.%m.%Y.", strtotime($art["date"])) : ""); |
104 |
ravilov |
1.7 |
$tpl->assign("AUTHOR", GetAuthor($art["au_pic"], |
105 |
|
|
$art["au_alt"], $art["au_info"], |
106 |
|
|
$art["au_w"], $art["au_h"])); |
107 |
|
|
for ($i = 0; $i < count($art["text"]); $i++) { |
108 |
|
|
$art["text"][$i]["text"] = ParseNewline(convert_html( |
109 |
ravilov |
1.14 |
MyEscape($art["text"][$i]["text"], false)), true); |
110 |
ravilov |
1.7 |
$art["text"][$i]["hl"] = ParseNewline(convert_html( |
111 |
ravilov |
1.14 |
MyEscape($art["text"][$i]["hl"], false)), true); |
112 |
ravilov |
1.8 |
$art["text"][$i]["exp"] = ParseNewline(convert_html( |
113 |
ravilov |
1.14 |
MyEscape($art["text"][$i]["exp"], false)), true); |
114 |
ravilov |
1.8 |
if ($art["text"][$i]["hl"]) $art["text"][$i]["hl"] = GetHighlight($art["text"][$i]["hl"]); |
115 |
ravilov |
1.10 |
if ($art["text"][$i]["level"]) $art["text"][$i]["level2"] = (($art["text"][$i]["level"] - 1) * 15) + 2; |
116 |
ravilov |
1.7 |
} |
117 |
ravilov |
1.1 |
$tpl->assign("text", $art["text"]); |
118 |
|
|
$tpl->assign("cat", $art["category"]); |
119 |
ravilov |
1.11 |
$tpl->assign("acat", $acat); |
120 |
|
|
$tpl->assign("acat2", $acat2); |
121 |
ravilov |
1.13 |
$tpl->assign("pgfs", count($art["text"])); |
122 |
ravilov |
1.8 |
global $PATH; |
123 |
|
|
if (is_array($PATH)) array_push($PATH, |
124 |
|
|
MyUpper(MyEscape(convert_html($art["title"])))); |
125 |
ravilov |
1.1 |
} |
126 |
|
|
?> |