2009-07-23 16:43:03 +00:00
< ? php
/*
2009-11-17 10:46:35 +00:00
* e107 website system
*
2016-12-02 10:33:29 +00:00
* Copyright ( C ) 2008 - 2016 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 ; }
2016-02-13 11:54:24 -08:00
e107 :: lan ( 'banner' );
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.
{
2016-01-12 15:44:54 -08:00
require ( THEME . 'templates/banner/banner_template.php' ); // don't use require_once as we might use this menu in more than 1 location.
2015-01-29 14:09:47 -08:00
}
elseif ( file_exists ( THEME . 'banner_template.php' )) // v1.x location.
2009-07-23 16:43:03 +00:00
{
2016-01-12 15:44:54 -08:00
require ( THEME . 'banner_template.php' );
2009-11-19 22:02:19 +00:00
}
else
2009-07-23 16:43:03 +00:00
{
2016-01-12 15:44:54 -08:00
require ( e_PLUGIN . 'banner/banner_template.php' );
2009-07-23 16:43:03 +00:00
}
2013-05-09 23:51:34 -07:00
2016-02-13 11:54:24 -08:00
2016-01-12 15:44:54 -08:00
$menu_pref = e107 :: getConfig ( 'menu' ) -> getPref ( '' ); // legacy preference lookup.
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 ;
}
2015-04-04 16:24:10 -07:00
if ( ! empty ( $parm ))
{
2016-02-08 13:54:44 -08:00
if ( is_string ( $parm )) // unserailize the v2.x e_menu.php preferences.
2009-11-19 22:02:19 +00:00
{
2016-01-12 15:44:54 -08:00
parse_str ( $parm , $parms ); // if it fails, use legacy method. (query string format)
2009-11-19 22:02:19 +00:00
}
2016-02-08 13:54:44 -08:00
elseif ( is_array ( $parm )) // prefs array so overwrite the legacy preference values.
2009-11-19 22:02:19 +00:00
{
2016-02-08 13:54:44 -08:00
if ( isset ( $parm [ 'banner_caption' ][ e_LANGUAGE ]))
{
$parm [ 'banner_caption' ] = $parm [ 'banner_caption' ][ e_LANGUAGE ];
}
$menu_pref = $parm ;
2016-01-12 15:44:54 -08:00
$menu_pref [ 'banner_campaign' ] = implode ( " | " , $menu_pref [ 'banner_campaign' ]);
unset ( $parm );
2009-11-19 22:02:19 +00:00
}
2016-01-12 15:44:54 -08:00
}
2015-01-29 14:09:47 -08:00
2016-03-12 00:15:29 -08:00
2010-02-10 21:53:56 +00:00
2016-01-12 15:44:54 -08:00
// print_a($menu_pref);
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 );
2016-03-12 00:15:29 -08:00
if ( ! empty ( $menu_pref [ 'banner_width' ]))
{
e107 :: getParser () -> thumbWidth ( $menu_pref [ 'banner_width' ]);
}
2015-02-07 22:20:31 -08:00
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 ) . " ) " : " " ;
2016-03-13 00:16:08 -08:00
// $query .= ($parm ? " AND banner_campaign='".$tp->toDB($parm)."'" : '');
2016-03-11 23:12:19 -08:00
2016-03-14 03:03:56 -07:00
$query .= " AND banner_active IN ( " . USERCLASS_LIST . " ) " ;
$query .= " ORDER BY " ;
$ord = array ();
2016-03-11 23:12:19 -08:00
if ( $tags = e107 :: getRegistry ( 'core/form/related' ))
{
$tags_regexp = " '(^|,)( " . str_replace ( " , " , " | " , $tags ) . " )(,| $ )' " ;
2016-03-14 03:03:56 -07:00
$ord [] = " banner_keywords REGEXP " . $tags_regexp . " DESC " ;
2016-03-11 23:12:19 -08:00
}
2016-03-14 03:03:56 -07:00
$ord [] = " RAND( $seed ) ASC " ;
$query .= implode ( ', ' , $ord );
$query .= " LIMIT " . intval ( $menu_pref [ 'banner_amount' ]);
2015-02-07 22:20:31 -08:00
2016-01-12 03:22:06 -08:00
if ( $data = $sql -> retrieve ( 'banner' , 'banner_id, banner_image, banner_clickurl,banner_campaign, banner_description' , $query , true ))
2015-02-07 22:20:31 -08:00
{
foreach ( $data as $k => $row )
{
$var = array ( 'BANNER' => $sc -> renderBanner ( $row ));
$cat = $row [ 'banner_campaign' ];
$ret [ $cat ][] = $tp -> simpleParse ( $BANNER_MENU_ITEM , $var );
}
}
2016-03-13 22:24:28 -07:00
elseif ( e_DEBUG == true && getperms ( '0' ))
2016-01-12 15:44:54 -08:00
{
echo " no banner data " ;
2016-01-12 17:11:06 -08:00
print_a ( $menu_pref );
print_a ( $query );
2016-01-12 15:44:54 -08:00
}
2015-02-07 22:20:31 -08:00
$foot = e107 :: getParser () -> parseTemplate ( $BANNER_MENU_END , true );
2016-01-12 15:44:54 -08:00
2015-02-07 22:20:31 -08:00
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
?>