2009-09-18 22:20:40 +00:00
< ? php
/*
2013-02-28 17:48:18 +01:00
* e107 website system
*
2016-12-02 10:33:29 +00:00
* Copyright ( C ) 2008 - 2016 e107 Inc ( e107 . org )
2013-02-28 17:48:18 +01:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Banner shortcode
*
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
*/
2021-01-14 11:32:02 -08:00
2015-02-07 22:20:31 -08:00
class banner_shortcodes extends e_shortcode
{
2016-04-19 09:13:35 +01:00
// $parm now can be array, old campaign $parm still allowed....
2021-01-14 11:32:02 -08:00
function sc_banner ( $parm = '' )
2009-09-18 22:20:40 +00:00
{
2021-01-14 14:46:49 -08:00
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
$time = time ();
2021-01-14 11:32:02 -08:00
$campaign = ( isset ( $parm [ 'campaign' ]) ? $parm [ 'campaign' ] : $parm );
$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) " . ( $campaign ? " AND banner_campaign=' " . $tp -> toDB ( $campaign ) . " ' " : '' ) . "
AND banner_active IN ( " . USERCLASS_LIST . " ) " ;
2016-03-11 23:12:19 -08:00
if ( $tags = e107 :: getRegistry ( 'core/form/related' ))
{
2021-01-14 11:32:02 -08:00
$tags_regexp = " '(^|,)( " . str_replace ( " , " , " | " , $tags ) . " )(,| $ )' " ;
$query .= " AND banner_keywords REGEXP " . $tags_regexp ;
2016-03-11 23:12:19 -08:00
}
2021-01-14 11:32:02 -08:00
2021-09-04 15:06:19 +02:00
$query .= " ORDER BY RAND() LIMIT 1 " ;
2021-01-14 11:32:02 -08:00
2016-01-12 03:22:06 -08:00
if ( $sql -> select ( 'banner' , 'banner_id, banner_image, banner_clickurl, banner_description' , $query ))
2009-09-18 22:20:40 +00:00
{
2013-12-30 04:16:01 -08:00
$row = $sql -> fetch ();
2021-01-14 11:32:02 -08:00
2016-04-17 16:19:46 +01:00
return $this -> renderBanner ( $row , $parm );
2015-02-07 22:20:31 -08:00
}
else
{
return ' ' ;
}
}
// Also used by banner_menu.php
2019-05-20 14:53:43 -07:00
public function renderBanner ( $row , $parm = null )
2015-02-07 22:20:31 -08:00
{
2021-01-14 11:32:02 -08:00
2015-02-07 22:20:31 -08:00
$sql = e107 :: getDb ( 'banner' );
$tp = e107 :: getParser ();
if ( ! $row [ 'banner_image' ])
{
2021-01-14 11:32:02 -08:00
return " <a href=' " . e_HTTP . 'banner.php?' . $row [ 'banner_id' ] . " ' rel='external'> " . BANNERLAN_39 . " </a> " ;
2015-02-07 22:20:31 -08:00
}
2021-01-14 11:32:02 -08:00
2015-02-07 22:20:31 -08:00
$fileext1 = substr ( strrchr ( $row [ 'banner_image' ], '.' ), 1 );
2021-01-14 11:32:02 -08:00
$sql -> update ( 'banner' , 'banner_impressions=banner_impressions+1 WHERE banner_id=' . ( int ) $row [ 'banner_id' ]);
switch ( $fileext1 )
{
case 'swf' :
return "
2009-09-18 22:20:40 +00:00
< 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
2021-01-14 11:32:02 -08:00
< param name = \ " movie \" value= \" " . e_IMAGE_ABS . " banners/ " . $row [ 'banner_image' ] . " \" > \n
2009-09-18 22:20:40 +00:00
< param name = \ " quality \" value= \" high \" > \n
< param name = \ " SCALE \" value= \" noborder \" > \n
2021-01-14 11:32:02 -08:00
< 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>
2009-09-18 22:20:40 +00:00
</ object >
" ;
2015-02-07 22:20:31 -08:00
break ;
2021-01-14 11:32:02 -08: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 ;
2016-12-19 13:49:18 -08:00
2021-01-14 11:32:02 -08:00
default :
$class = empty ( $parm [ 'class' ]) ? " e-banner img-responsive img-fluid " : $parm [ 'class' ];
$ban_ret = $tp -> toImage ( $row [ 'banner_image' ], array ( 'class' => $class , 'alt' => basename ( $row [ 'banner_image' ]), 'legacy' => '{e_IMAGE}banners' ));
2016-03-11 10:27:40 -08:00
2015-02-07 22:20:31 -08:00
break ;
2021-01-14 11:32:02 -08:00
}
$start = " <a class='e-tip' href=' " . e_HTTP . 'banner.php?' . $row [ 'banner_id' ] . " ' rel='external' title= \" " . $tp -> toAttribute ( varset ( $row [ 'banner_tooltip' ], '' )) . " \" > " ;
$end = '</a>' ;
$text = $start . $ban_ret . $end ;
if ( ! empty ( $row [ 'banner_description' ]))
{
$text .= " <div class='e-banner-description'> " . $start . $tp -> toHTML ( $row [ 'banner_description' ], true ) . $end . " </div> " ;
}
return $text ;
2009-09-18 22:20:40 +00:00
}
}
2016-04-22 09:03:21 -07:00