2 |
function newsLoad($id, $cat, $limit = 1, $npar = 1) { |
function newsLoad($id, $cat, $limit = 1, $npar = 1) { |
3 |
global $dbh; |
global $dbh; |
4 |
$arts = array(); |
$arts = array(); |
5 |
$sql = "SELECT news_id, title, lead, title_pic, title_alt, title_pos, url, date FROM news WHERE (category = '$cat')"; |
$sql = "SELECT news_id, title, lead, title_pic, title_alt, title_pos, url, date, ord FROM news WHERE (category = '$cat')"; |
6 |
if ($id > 0) $sql .= " AND (news_id = $id)"; |
if ($id > 0) $sql .= " AND (news_id = $id)"; |
7 |
$sql .= " ORDER BY date DESC LIMIT $limit"; |
$sql .= " ORDER BY date DESC LIMIT $limit"; |
8 |
$sth = $dbh->prepare($sql); |
$sth = $dbh->prepare($sql); |
11 |
while ($row = $sth->fetchrow_array()) { |
while ($row = $sth->fetchrow_array()) { |
12 |
$art = array(); |
$art = array(); |
13 |
list($art["id"], $art["title"], $art["lead"], $art["pic_url"], |
list($art["id"], $art["title"], $art["lead"], $art["pic_url"], |
14 |
$art["pic_alt"], $art["pic_pos"], $art["more"], $date) = $row; |
$art["pic_alt"], $art["pic_pos"], $art["more"], |
15 |
|
$date, $ord) = $row; |
16 |
list($art["pic_w"], $art["pic_h"]) = PicSize($art["pic"]); |
list($art["pic_w"], $art["pic_h"]) = PicSize($art["pic"]); |
17 |
$text = array(); |
$text = array(); |
18 |
if (isset($art["id"])) { |
if (isset($art["id"])) { |
38 |
$sth2->finish(); |
$sth2->finish(); |
39 |
} |
} |
40 |
$art["text"] = $text; |
$art["text"] = $text; |
41 |
|
$art["order"] = $ord; |
42 |
$art["read"] = (count($art["text"]) > $npar) ? true : false; |
$art["read"] = (count($art["text"]) > $npar) ? true : false; |
43 |
$art["category"] = $cat; |
$art["category"] = $cat; |
44 |
$art["limit"] = $limit; |
$art["limit"] = $limit; |
46 |
array_push($arts, $art); |
array_push($arts, $art); |
47 |
} |
} |
48 |
$sth->finish(); |
$sth->finish(); |
49 |
|
$foo = true; |
50 |
|
while ($foo) { |
51 |
|
$foo = false; |
52 |
|
for ($i = 0; $i < count($arts); $i++) { |
53 |
|
if ($arts[$i]["order"] == 0) continue; |
54 |
|
$j = ($i + $arts[$i]["order"]); |
55 |
|
$j %= count($arts); |
56 |
|
$foo = true; |
57 |
|
$tmp = $arts[$j]; |
58 |
|
$arts[$j] = $arts[$i]; |
59 |
|
$arts[$i] = $tmp; |
60 |
|
$arts[$j]["order"] = 0; |
61 |
|
} |
62 |
|
} |
63 |
return $arts; |
return $arts; |
64 |
} |
} |
65 |
|
|