2009-09-18 22:20:40 +00:00
< ? php
/*
2013-02-28 17:48:18 +01:00
* e107 website system
*
* Copyright ( C ) 2008 - 2013 e107 Inc ( e107 . org )
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Banner shortcode
*
2009-09-18 22:20:40 +00:00
*/
2009-12-28 21:36:13 +00:00
/**
* e107 Banner management plugin
*
* Handles the display and sequencing of banners on web pages , including counting impressions
*
* @ package e107_plugins
* @ subpackage banner
*/
2015-02-07 22:20:31 -08:00
class banner_shortcodes extends e_shortcode
{
function sc_banner ( $parm = '' )
2009-09-18 22:20:40 +00:00
{
2015-02-07 22:20:31 -08:00
2009-09-18 22:20:40 +00:00
$e107 = e107 :: getInstance ();
2013-02-28 17:48:18 +01:00
$sql = e107 :: getDb ();
2013-03-24 18:59:18 +01:00
$tp = e107 :: getParser ();
2009-09-18 22:20:40 +00:00
$ret = '' ;
$text = '' ;
mt_srand (( double ) microtime () * 1000000 );
$seed = mt_rand ( 1 , 2000000000 );
$time = time ();
2013-03-24 18:59:18 +01:00
$query = " (banner_startdate=0 OR banner_startdate <= { $time } ) AND (banner_enddate=0 OR banner_enddate > { $time } ) AND (banner_impurchased=0 OR banner_impressions<=banner_impurchased) " . ( $parm ? " AND banner_campaign=' " . $tp -> toDB ( $parm ) . " ' " : '' ) . "
2009-09-18 22:20:40 +00:00
AND banner_active IN ( " .USERCLASS_LIST. " )
ORDER BY RAND ( $seed ) LIMIT 1 " ;
2013-12-30 04:16:01 -08:00
if ( $sql -> select ( 'banner' , 'banner_id, banner_image, banner_clickurl' , $query ))
2009-09-18 22:20:40 +00:00
{
2013-12-30 04:16:01 -08:00
$row = $sql -> fetch ();
2015-02-07 22:20:31 -08:00
return $this -> renderBanner ( $row );
2013-12-30 04:16:01 -08:00
2015-02-07 22:20:31 -08:00
}
else
{
return ' ' ;
}
}
// Also used by banner_menu.php
public function renderBanner ( $row )
{
$sql = e107 :: getDb ( 'banner' );
$tp = e107 :: getParser ();
if ( ! $row [ 'banner_image' ])
{
return " <a href=' " . e_HTTP . 'banner.php?' . $row [ 'banner_id' ] . " ' rel='external'>no image assigned to this banner</a> " ;
}
$fileext1 = substr ( strrchr ( $row [ 'banner_image' ], '.' ), 1 );
$sql -> update ( 'banner' , 'banner_impressions=banner_impressions+1 WHERE banner_id=' . ( int ) $row [ 'banner_id' ]);
switch ( $fileext1 )
2009-09-18 22:20:40 +00:00
{
case 'swf' :
return "
< object classid = \ " clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 \" codebase= \" http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 \" width= \" 468 \" height= \" 60 \" > \n
< param name = \ " movie \" value= \" " . e_IMAGE_ABS . " banners/ " . $row [ 'banner_image' ] . " \" > \n
< param name = \ " quality \" value= \" high \" > \n
< param name = \ " SCALE \" value= \" noborder \" > \n
< embed src = \ " " . e_IMAGE_ABS . " banners/ " . $row [ 'banner_image' ] . " \" width= \" 468 \" height= \" 60 \" scale= \" noborder \" quality= \" high \" pluginspage= \" http://www.macromedia.com/go/getflashplayer \" type= \" application/x-shockwave-flash \" ></embed>
</ object >
" ;
2015-02-07 22:20:31 -08:00
break ;
2009-09-18 22:20:40 +00:00
case 'html' :
case 'js' :
case 'php' : // Code - may 'echo' text, or may return it as a value
$file_data = file_get_contents ( e_IMAGE . 'banners/' . $row [ 'banner_image' ]);
return $file_data ;
2015-02-07 22:20:31 -08:00
break ;
2009-09-18 22:20:40 +00:00
default :
2013-12-30 04:16:01 -08:00
2015-02-07 22:20:31 -08:00
$src = ( $row [ 'banner_image' ][ 0 ] == '{' ) ? $tp -> thumbUrl ( $row [ 'banner_image' ]) : e_IMAGE_ABS . 'banners/' . $row [ 'banner_image' ];
2013-12-30 04:16:01 -08:00
2014-02-11 07:47:44 -08:00
$ban_ret = " <img class='e-banner img-responsive' src=' " . $src . " ' alt=' " . $row [ 'banner_clickurl' ] . " ' style='border:0' /> " ;
2015-02-07 22:20:31 -08:00
break ;
2009-09-18 22:20:40 +00:00
}
2015-02-07 22:20:31 -08:00
return " <a href=' " . e_HTTP . 'banner.php?' . $row [ 'banner_id' ] . " ' rel='external'> " . $ban_ret . '</a>' ;
2009-09-18 22:20:40 +00:00
}
2015-02-07 22:20:31 -08:00
2009-09-18 22:20:40 +00:00
}
?>