Get XOOPS XOOPS FAQ Forums News Themes Modules
News World of XOOPS Developers Hacks Modules Themes Archive Submit News

XOOPS vs. Herko Coomans

Make a donation

Please select an amount to donate


Do you want your username revealed with your donation?
Yes - List me as a Generous Donor
No - List my donation as from an Anonymous Donor


Search

Local Support Sites

Cumulus Tag Cloud

admin Arabic banner block Christmas comments cumulus DayDawn dhsoft e-Commerce E-Learning Google GUI hacks instant-zero jQuery module news Nordic Olédrion oxygen PageRank security SEO simple-XOOPS sport tag Theme wiki xoops

New Users

Registering user

# 96568

dvsshoescom

Welcome to XOOPS!

Archives

XOOPS Code hosted on SourceForge

Revolution Xoops Banner System!

Posted by slyss on 2009/11/11 3:20:00 (1744 reads) | Posted on Hacks
I have finally created 2 functions to place your BANNERS everywhere you want and to choose which BANNER to show!!!
Is very very simple. You have 3 options to place your BANNERS in blocks:

1. No banners preference: view random banner
2. Banner preference: view specific banner
3. Client preference: view specific client banner

LET'S DO THIS:

Please, go to your root_directory/include/ and open the file functions.php
Go to the end of the file functions.php and before the tag ?> insert this code:


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 ) {
$numrows $numrows-1;
mt_srand((double)microtime()*1000000);
$bannum mt_rand(0$numrows);
} else {
$bannum 0;
}
if ( 
$numrows ) {
$bresult $db->query("SELECT * FROM ".$db->prefix("banner")." WHERE bid = "$banner_id1$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$datetime());
$db->queryF($sql);
$db->queryF(sprintf("DELETE FROM %s WHERE bid = %u"$db->prefix("banner"), $bid));
}
if (
$htmlbanner){
$bannerobject $htmlcode;
}else{
$bannerobject '<div align="center"><a href="'.XOOPS_URL.'/banners.php?op=click&bid='.$bid.'" target="_blank">';
if (
stristr($imageurl'.swf')) {
$bannerobject $bannerobject
.'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60">'
.'<param name="movie" value="'.$imageurl.'"></param>'
.'<param name="quality" value="high"></param>'
.'<embed src="'.$imageurl.'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">'
.'</embed>'
.'</object>';
} else {
$bannerobject $bannerobject.'<img src="'.$imageurl.'" alt="" />';
}

$bannerobject $bannerobject.'</a></div>';
}
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 ) {
$numrows $numrows-1;
mt_srand((double)microtime()*1000000);
$bannum mt_rand(0$numrows);
} else {
$bannum 0;
}
if ( 
$numrows ) {
$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$datetime());
$db->queryF($sql);
$db->queryF(sprintf("DELETE FROM %s WHERE bid = %u"$db->prefix("banner"), $bid));
}
if (
$htmlbanner){
$bannerobject $htmlcode;
}else{
$bannerobject '<div align="center"><a href="'.XOOPS_URL.'/banners.php?op=click&bid='.$bid.'" target="_blank">';
if (
stristr($imageurl'.swf')) {
$bannerobject $bannerobject
.'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60">'
.'<param name="movie" value="'.$imageurl.'"></param>'
.'<param name="quality" value="high"></param>'
.'<embed src="'.$imageurl.'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">'
.'</embed>'
.'</object>';
} else {
$bannerobject $bannerobject.'<img src="'.$imageurl.'" alt="" />';
}

$bannerobject $bannerobject.'</a></div>';
}
return 
$bannerobject;
}
}


then SAVE and CLOSE.

Now there are 3 simple ways to create your BANNERS BLOCKS:

CASE 1:

Place your BANNERS in your blocks (no limit for number of blocks) anywhere you want! BANNERS will be shown randomly!

Add a new custom Xoops block PHP and insert this code:

echo xoops_getbanner(); 


CASE 2:

Place your BANNERS in your blocks (no limit for number of blocks) anywhere you want! BANNERS will be shown by ID_BANNER and so, e.g., you can select a specific BANNER in a specific block!

Add a new custom Xoops block PHP and insert this code:

echo getbanner_from_id_banner(ID_BANNER); 


where ID_BANNER = ID of BANNER to SHOW (you can see this ID on your BANNERS admin page --> Banner ID on Current Active Banners)

CASE 3:

Place your BANNERS in your blocks (no limit for number of blocks) anywhere you want! BANNERS will be shown by ID_CLIENT and so, e.g., if a client has 10 banners, your BANNERS will be view random only from this 10 BANNERS!

Add a new custom Xoops block PHP and insert this code:

echo getbanner_from_id_client(ID_CLIENT); 


where ID_CLIENT = ID of CLIENT of BANNERS to SHOW (you can see this ID on your BANNERS admin page --> Banner ID on Advertising Clients)

THAT'S ALL!


Tags: hacks   banner  
Printer Friendly Page Send this Story to a Friend Create a PDF from the article


Bookmark this article at these sites

                   

The comments are owned by the poster. We aren't responsible for their content.

Thanks a million !

Any chance to get it in next Xoops core ? A very useful feature, not only to show ads.
Posted: 2009/11/11 4:18 • Updated: 2009/11/11 4:18
Nice hack. Very cool indeed.
Posted: 2009/11/11 5:09 • Updated: 2009/11/11 5:09
nice...excellent

xoops banner system should be improve

by including slyss hack and the rwbanner module to core
Posted: 2009/11/11 5:18 • Updated: 2009/11/11 5:18
Nice

but delete this lines
.'<embed src="'.$imageurl.'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">' 
.'</embed>' 

Posted: 2009/11/11 7:51 • Updated: 2009/11/11 7:51
kris_fr said:
Quote:
but delete this lines

Why?

.
Posted: 2009/11/11 8:12 • Updated: 2009/11/11 8:13
why not ? any problems?

thanks a lot guys

happy if my hack is appreciated...
Posted: 2009/11/11 9:35 • Updated: 2009/11/11 9:35
Great and easy, thanks slyss.

There must be an easy way to add hacks without having to modify core files...
Posted: 2009/11/11 11:00 • Updated: 2009/11/11 11:00
very useful banner hack, thank you slyss.
Posted: 2009/11/12 5:48 • Updated: 2009/11/12 5:48
Very cool! Nice work! :)
Posted: 2009/11/13 7:17 • Updated: 2009/11/13 7:17
@ sailjapan and Slyss : see this old article for "embed" tag

Also this post in adobe forum
Posted: 2009/11/24 10:02 • Updated: 2009/11/24 10:08
Is it possible to add this code in the theme.html for the header banner?
Posted: 2010/1/27 12:45 • Updated: 2010/1/27 12:45