2009-07-23 16:43:03 +00:00
< ? php
/*
2009-11-17 10:46:35 +00:00
* e107 website system
*
2013-02-28 17:48:18 +01:00
* Copyright ( C ) 2008 - 2013 e107 Inc ( e107 . org )
2009-11-17 10:46:35 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
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
2009-11-17 10:46:35 +00:00
*/
2009-07-23 16:43:03 +00:00
if ( ! defined ( 'e107_INIT' )) { exit ; }
2009-11-19 22:02:19 +00:00
2015-01-29 14:09:47 -08:00
if ( file_exists ( THEME . 'templates/banner/banner_template.php' )) // v2.x location.
{
require_once ( THEME . 'templates/banner/banner_template.php' );
}
elseif ( file_exists ( THEME . 'banner_template.php' )) // v1.x location.
2009-07-23 16:43:03 +00:00
{
2009-12-28 21:36:13 +00:00
require_once ( THEME . 'banner_template.php' );
2009-11-19 22:02:19 +00:00
}
else
2009-07-23 16:43:03 +00:00
{
2013-05-09 23:51:34 -07:00
require_once ( e_PLUGIN . 'banner/banner_template.php' );
2009-07-23 16:43:03 +00:00
}
2013-05-09 23:51:34 -07:00
2009-12-28 21:36:13 +00:00
$menu_pref = e107 :: getConfig ( 'menu' ) -> getPref ( '' );
2009-07-23 16:43:03 +00:00
2015-02-07 22:20:31 -08:00
if ( defset ( 'BOOTSTRAP' ))
2009-07-23 16:43:03 +00:00
{
2015-02-07 22:20:31 -08:00
$BANNER_MENU_START = $BANNER_TEMPLATE [ 'menu' ][ 'start' ];
$BANNER_MENU_ITEM = $BANNER_TEMPLATE [ 'menu' ][ 'item' ];
$BANNER_MENU_END = $BANNER_TEMPLATE [ 'menu' ][ 'end' ];
2009-07-23 16:43:03 +00:00
}
else
{
2015-02-07 22:20:31 -08:00
$BANNER_MENU_ITEM = $BANNER_MENU ;
}
/*
2009-11-19 22:02:19 +00:00
if ( isset ( $menu_pref [ 'banner_campaign' ]) && $menu_pref [ 'banner_campaign' ])
2009-07-23 16:43:03 +00:00
{
2010-06-01 21:55:14 +00:00
$parms = array ();
2009-11-19 22:02:19 +00:00
if ( strstr ( $menu_pref [ 'banner_campaign' ], " | " ))
{
2009-12-28 21:36:13 +00:00
$campaignlist = explode ( '|' , $menu_pref [ 'banner_campaign' ]);
2009-11-19 22:02:19 +00:00
$amount = ( $menu_pref [ 'banner_amount' ] < 1 ? '1' : $menu_pref [ 'banner_amount' ]);
$amount = ( $amount > count ( $campaignlist ) ? count ( $campaignlist ) : $amount );
2010-06-01 21:55:14 +00:00
$keys = array_rand ( $campaignlist , $amount ); // If one entry, returns a single value
if ( ! is_array ( $keys ))
{
$keys = array ( $keys );
}
2009-11-19 22:02:19 +00:00
foreach ( $keys as $k => $v )
{
$parms [] = $campaignlist [ $v ];
}
}
else
{
$parms [] = $menu_pref [ 'banner_campaign' ];
}
2013-06-17 16:03:33 -07:00
2015-02-07 22:20:31 -08:00
$txt = e107 :: getParser () -> parseTemplate ( $BANNER_MENU_START , true );
$sc = e107 :: getScBatch ( 'banner' );
2015-01-29 14:09:47 -08:00
2013-06-17 16:03:33 -07:00
foreach ( $parms as $parm )
{
2015-02-07 22:20:31 -08:00
$p = array ( 'banner_campaign' => $parm );
$sc -> setVars ( $p );
$txt .= e107 :: getParser () -> parseTemplate ( $BANNER_MENU_ITEM , true , $sc );
// $txt .= e107::getParser()->parseTemplate("{BANNER=".$parm."}",true);
2013-06-17 16:03:33 -07:00
}
2015-01-29 14:09:47 -08:00
2015-02-07 22:20:31 -08:00
$txt .= e107 :: getParser () -> parseTemplate ( $BANNER_MENU_END , true );
2009-07-23 16:43:03 +00:00
}
2010-02-10 21:53:56 +00:00
2015-02-07 22:20:31 -08:00
*/
2013-06-17 16:03:33 -07:00
2009-07-23 16:43:03 +00:00
2015-02-07 22:20:31 -08:00
if ( ! empty ( $menu_pref [ 'banner_campaign' ]) && ! empty ( $menu_pref [ 'banner_amount' ]))
2009-07-23 16:43:03 +00:00
{
2015-02-07 22:20:31 -08:00
$sc = e107 :: getScBatch ( 'banner' );
$ret = array ();
$head = e107 :: getParser () -> parseTemplate ( $BANNER_MENU_START , true );
mt_srand (( double ) microtime () * 1000000 );
$seed = mt_rand ( 1 , 2000000000 );
$time = time ();
$tmp = explode ( " | " , $menu_pref [ 'banner_campaign' ]);
foreach ( $tmp as $v )
{
$filter [] = " banner_campaign= \" " . $v . " \" " ;
}
$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) " ;
$query .= ( count ( $filter )) ? " AND ( " . implode ( " OR " , $filter ) . " ) " : " " ;
$query .= ( $parm ? " AND banner_campaign=' " . $tp -> toDB ( $parm ) . " ' " : '' );
$query .= " AND banner_active IN ( " . USERCLASS_LIST . " ) ORDER BY RAND( $seed ) LIMIT " . intval ( $menu_pref [ 'banner_amount' ]);
if ( $data = $sql -> retrieve ( 'banner' , 'banner_id, banner_image, banner_clickurl,banner_campaign' , $query , true ))
{
foreach ( $data as $k => $row )
{
$var = array ( 'BANNER' => $sc -> renderBanner ( $row ));
$cat = $row [ 'banner_campaign' ];
$ret [ $cat ][] = $tp -> simpleParse ( $BANNER_MENU_ITEM , $var );
}
}
$foot = e107 :: getParser () -> parseTemplate ( $BANNER_MENU_END , true );
switch ( $menu_pref [ 'banner_rendertype' ])
{
2009-07-23 16:43:03 +00:00
2015-02-07 22:20:31 -08:00
case 0 : // All banners - no render or caption.
$text = " " ;
foreach ( $ret as $cat )
{
foreach ( $cat as $val )
{
$text .= $head . $val . $foot ;
}
}
echo $text ;
break ;
case 1 : // One menu for each campaign.
$text = " " ;
foreach ( $ret as $cat )
{
$text = " " ;
foreach ( $cat as $val )
{
$text .= $head . $val . $foot ;
}
$ns -> tablerender ( $menu_pref [ 'banner_caption' ], $text , 'banner-menu' );
}
break ;
case 3 : // one rendered menu per banner
foreach ( $ret as $cat )
{
foreach ( $cat as $val )
{
$ns -> tablerender ( $menu_pref [ 'banner_caption' ], $head . $val . $foot , 'banner-menu' );
}
}
break ;
case 2 : // all campaigns/banners single menu.
default :
$text = " " ;
foreach ( $ret as $cat )
{
foreach ( $cat as $val )
{
$text .= $head . $val . $foot ;
}
}
$ns -> tablerender ( $menu_pref [ 'banner_caption' ], $text , 'banner-menu' );
break ;
}
2009-11-19 22:02:19 +00:00
2015-02-07 22:20:31 -08:00
}
2009-07-23 16:43:03 +00:00
?>