升级:革命性的Xoops横幅系统!
发布者: slyss于 2009/11/11 8:20:00 16951 次阅读我终于创建了两个函数,可以将您的横幅放置在任何您想放置的位置,并选择要显示的哪个横幅!!
非常简单。您有三种选项来在块中放置横幅
1. 没有横幅偏好:查看随机横幅
2. 横幅偏好:查看特定横幅
3. 客户端偏好:查看特定客户端横幅
让我们开始吧
请,前往您的根目录/include/,并打开文件functions.php
前往文件functions.php的末尾,在?>标签之前插入以下代码
function getbanner_from_id_banner($banner_id)
{
###### Hack by www.stefanosilvestrini.com ######
global $xoopsConfig;
$db =& Database::getInstance();
$bresult = $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner")." WHERE bid = ". $banner_id);
list ($numrows) = $db->fetchRow($bresult);
if ( $numrows > 1 ) {
$numrows = $numrows-1;
mt_srand((double)microtime()*1000000);
$bannum = mt_rand(0, $numrows);
} else {
$bannum = 0;
}
if ( $numrows > 0 ) {
$bresult = $db->query("SELECT * FROM ".$db->prefix("banner")." WHERE bid = ". $banner_id, 1, $bannum);
list ($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($bresult);
if ($xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) {
// EMPTY
} else {
$db->queryF(sprintf("UPDATE %s SET impmade = impmade+1 WHERE bid = %u", $db->prefix("banner"), $bid));
}
/* Check if this impression is the last one and print the banner */
if ( $imptotal == $impmade ) {
$newid = $db->genId($db->prefix("bannerfinish")."_bid_seq");
$sql = sprintf("INSERT INTO %s (bid, cid, impressions, clicks, datestart, dateend) VALUES (%u, %u, %u, %u, %u, %u)", $db->prefix("bannerfinish"), $newid, $cid, $impmade, $clicks, $date, time());
$db->queryF($sql);
$db->queryF(sprintf("DELETE FROM %s WHERE bid = %u", $db->prefix("banner"), $bid));
}
if ($htmlbanner){
$bannerobject = $htmlcode;
}else{
$bannerobject = '
';
}
return $bannerobject;
}
}
function getbanner_from_id_client($client_id)
{
###### Hack by www.stefanosilvestrini.com ######
global $xoopsConfig;
$db =& Database::getInstance();
$bresult = $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner")." WHERE cid = ". $client_id);
list ($numrows) = $db->fetchRow($bresult);
if ( $numrows > 1 ) {
$numrows = $numrows-1;
mt_srand((double)microtime()*1000000);
$bannum = mt_rand(0, $numrows);
} else {
$bannum = 0;
}
if ( $numrows > 0 ) {
$bresult = $db->query("SELECT * FROM ".$db->prefix("banner")." WHERE cid = ". $client_id ." ORDER BY rand()", 1, $bannum);
list ($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($bresult);
if ($xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) {
// EMPTY
} else {
$db->queryF(sprintf("UPDATE %s SET impmade = impmade+1 WHERE bid = %u", $db->prefix("banner"), $bid));
}
/* Check if this impression is the last one and print the banner */
if ( $imptotal == $impmade ) {
$newid = $db->genId($db->prefix("bannerfinish")."_bid_seq");
$sql = sprintf("INSERT INTO %s (bid, cid, impressions, clicks, datestart, dateend) VALUES (%u, %u, %u, %u, %u, %u)", $db->prefix("bannerfinish"), $newid, $cid, $impmade, $clicks, $date, time());
$db->queryF($sql);
$db->queryF(sprintf("DELETE FROM %s WHERE bid = %u", $db->prefix("banner"), $bid));
}
if ($htmlbanner){
$bannerobject = $htmlcode;
}else{
$bannerobject = '