17.01.2006, 22:19
Вот это лучше используйте!
function blocks($side) {
global $storynum, $prefix, $multilingual, $currentlang, $db, $admin, $user;
static $barr;
if ($multilingual == 1) {
$querylang = "AND (blanguage='$currentlang' OR blanguage='')";
} else {
$querylang = "";
}
if (strtolower($side[0]) == "l") {
$pos = "l";
} elseif (strtolower($side[0]) == "r") {
$pos = "r";
} elseif (strtolower($side[0]) == "c") {
$pos = "c";
} elseif (strtolower($side[0]) == "d") {
$pos = "d";
}
$side = $pos;
if (!isset($barr)) {
$sql = "SELECT bid, bkey, title, content, url, blockfile, view, expire, action, subscription, bposition FROM ".$prefix."_blocks WHERE active='1' $querylang ORDER BY weight ASC";
$result = $db->sql_query($sql);
while(list($bid, $bkey, $title, $content, $url, $blockfile, $view, $expire, $action, $subscription, $bposition) = $db->sql_fetchrow($result)) {
$bid = intval($bid);
$view = intval($view);
$barr[]= array($bid, $bkey, $title, $content, $url, $blockfile, $view, $expire, $action, $subscription, $bposition);
}
}
for ($i=0; $i<sizeof($barr); $i++){
list ($bid, $bkey, $title, $content, $url, $blockfile, $view, $expire, $action, $subscription, $bposition)=$barr[$i];
if ($bposition==$side){
$now = time();
$sub = intval($subscription);
if ($sub == 0 OR ($sub == 1 AND !paid())) {
if ($expire != 0 AND $expire <= $now) {
if ($action == "d") {
$db->sql_query("UPDATE ".$prefix."_blocks SET active='0', expire='0' WHERE bid='$bid'");
return;
} elseif ($action == "r") {
$db->sql_query("DELETE FROM ".$prefix."_blocks WHERE bid='$bid'");
return;
}
}
if ($bkey == "admin") {
adminblock();
} elseif ($bkey == "userbox") {
userblock();
} elseif ($bkey == "") {
if ($view == 0) {
render_blocks($side, $blockfile, $title, $content, $bid, $url);
} elseif ($view == 1 AND is_user($user) || is_admin($admin)) {
render_blocks($side, $blockfile, $title, $content, $bid, $url);
} elseif ($view == 2 AND is_admin($admin)) {
render_blocks($side, $blockfile, $title, $content, $bid, $url);
} elseif ($view == 3 AND !is_user($user) || is_admin($admin)) {
render_blocks($side, $blockfile, $title, $content, $bid, $url);
}
}
}
}
}
$db->sql_freeresult($result);
}
|