1
jmc286642
Multiple <{$xoops_banner}>?
  • 2005/1/18 4:03

  • jmc286642

  • Just popping in

  • Posts: 1

  • Since: 2005/1/18


Is there a way to declare multiple <{$xoops_banner}> elements in theme.html and have XOOPS bring up two different banners? Perhaps with some creative Smarty loops?

Example markup:

<td>
  <{
$xoops_banner}>
  <
br/>
  <{
$xoops_banner}>
</
td>

Declaring <{$xoops_banner}> twice as in the example above merely causes XOOPS to bring up two instances of the same banner ad.

2
Mithrandir
Re: Multiple ?

As you have discovered, a Smarty variable points to the same value no matter how many times you place it in your theme.

You will have to edit the xoops_getbanner() function in include/functions.php to return an array of banners which you will then be able to use with <{$xoops_banner.0}>, <{$xoops_banner.1}> etc. depending on how you build the array in the function.

3
Liawlius
Solution
  • 2005/4/29 18:48

  • Liawlius

  • Just popping in

  • Posts: 4

  • Since: 2005/4/29


I solved this problem like this:

function xoops_getbanner()
{
    global 
$xoopsConfig;
    
$db =& Database::getInstance();
    
$bresult = $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner"));
    list (
$numrows) = $db->fetchRow($bresult);
    while (
$numrows <> 0) {
    
$numrows = $numrows - 1;
    
$bannum = $numrows;
        
$bresult = $db->query("SELECT * FROM ".$db->prefix("banner"), 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 = '<div><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 name=quality value=high>'
                    
.'<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>';
        }
     
$banner_ret = $banner_ret.'<br>'.$bannerobject;
    
}
        return 
$banner_ret;

}

Now this function repeats banner adding routine until no more banners left. If you can suggest better solution dont be shy

4
Liawlius
Re: Multiple ?
  • 2005/4/29 18:49

  • Liawlius

  • Just popping in

  • Posts: 4

  • Since: 2005/4/29


My solution:

function xoops_getbanner()
{
    global 
$xoopsConfig;
    
$db =& Database::getInstance();
    
$bresult = $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner"));
    list (
$numrows) = $db->fetchRow($bresult);
    while (
$numrows <> 0) {
    
$numrows = $numrows - 1;
    
$bannum = $numrows;
        
$bresult = $db->query("SELECT * FROM ".$db->prefix("banner"), 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 = '<div><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 name=quality value=high>'
                    
.'<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>';
        }
     
$banner_ret = $banner_ret.'<br>'.$bannerobject;
    
}
        return 
$banner_ret;

}

Its loop whitch repeats banner adding routine untill no more banner left to add.

----
I edited this post and the previous one to use the [ code ] tag - Dave_L

5
Anonymous
Re: Multiple <{$xoops_banner}>?
  • 2005/5/10 20:09

  • Anonymous

  • Posts: 0

  • Since: 0


Hi,

Is possible now to use more than banner in many blocks, example : <{$xoops_banner1}>,<{$xoops_banner2}>, .. etc ?