##############################################################
## MOD Title: Inline Banner Ad
## MOD Author: geocator < geocator@gmail.com > (Brian) http://www.geocator.us (CH Adaptation by DavidIQ)
## MOD Description: Allows placement of banner ads inline with posts. Contains a variety of options to control display behavior
## MOD Version: 1.0.3
##
## Installation Level: Moderate
## Installation Time: 14 minutes
## Files To Edit: includes/class_posts.php
##                templates/subSilver/overall_header.tpl
##                templates/subSilver/viewtopic_body.tpl
##                templates/ptifo/ptifo.css
##                templates/ptifo/viewtopic_body.tpl
## Included Files: (admin_inline_ad.php, inline_ad_config_body.tpl, admin_inline_ad_code.php, inline_ad_code_body.tpl, inline_ad_code_edit.tpl)
## Generator: MOD Studio 3.0 Alpha 1 [mod functions 0.2.1677.25348]
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/
##############################################################
## Author Notes:
##############################################################
## MOD History:
##
##   2008-05-02 (Mod reviewed by Haynes)
##      -fixed some bugs
##      -added an installer
##      -moved towards the CH plugin system
##
##   2007-04-17 - CH Version (David IQ)
##
##      - Made changes to edits to allow for CH Compatibility
##
##   2005-07-13 - Version 1.0.3
##
##      - Various Optimizations
##      - Added srand() for php compatibility
##
##   2005-06-18 - Version 1.0.2
##
##      - Exclude Forums Fix
##      - Various code clean-ups
##
##   2005-06-15 - Version 1.0.1
##
##      - Minor changes for MOD Validation
##
##   2005-06-05 - Version 1.0.0
##
##      - MOD DB Release
##      - Fixed admin styling bug
##
##   2005-05-01 - Version 0.2.0
##
##      - Added psedo random rotation
##      - Added new display mode/style
##      - Added post threshold to disable ads for a user
##      - Heavy code rework for performance and cleanliness
##      - DB Schema Cahnges
##
##   2005-03-15 - Version 0.0.5
##
##      - Added ability to exclude specific groups from ad display
##
##   2005-02-27 - Version 0.0.4
##
##      - Added ability to configure what forums ad is displayed in
##      - Added ability to configure who ad is displayed to
##      - Added ability to configure placement of ad in topic
##
##   2004-10-16 - Version 0.0.3
##
##      - Now has own table and admin page
##
##   2004-10-14 - Version 0.0.2
##
##      - Changed to admin panel, now works for any ad code
##
##   2004-10-14 - Version 0.0.1
##
##      - First Beta release.
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
#
#-----[ COPY ]------------------------------------------
#
copy root/*.* to /*.*
#
#-----[ OPEN ]------------------------------------------
#
includes/inc_plugins.php
#
#-----[ FIND ]------------------------------------------
#
?>
#
#-----[ BEFORE, ADD ]------------------------------------------
#
$plug_ins['mod_inline_banner_ad_CH'] = array('layer' => 'includes/inline_ad/class_inline_banner_ad');
#
#-----[ OPEN ]------------------------------------------
#
includes/class_posts.php
#
#-----[ FIND ]------------------------------------------
#
            $this->display_a_post($row, $color);
#
#-----[ REPLACE WITH ]------------------------------------------
#
            $this->display_a_post($row, $color, $i++);
#
#-----[ FIND ]------------------------------------------
#
   function display_a_post(&$row, $color, $tpl_switch='')
   {
      global $config, $user, $forums, $template, $theme;
#
#-----[ REPLACE WITH ]------------------------------------------
#
   function display_a_post(&$row, $color, $i, $tpl_switch='')
   {
      global $config, $user, $forums, $template, $theme, $db;
#
#-----[ FIND ]------------------------------------------
#
      // parse message
      $this->parse_message($row);
#
#-----[ AFTER, ADD ]------------------------------------------
#
		$inline_ad_code = '';
		$display_ad = ($i == $config->data['ad_after_post'] - 1) || (($config->data['ad_every_post'] != 0) && ($i + 1) % $config->data['ad_every_post'] == 0);
		//This if statement should keep server processing down a bit
		if ($display_ad)
		{
			$display_ad = ($config->data['ad_who'] == ALL) || ($config->data['ad_who'] == ANONYMOUS && $user->data['user_id'] == ANONYMOUS) || ($config->data['ad_who'] == USER && $user->data['user_id'] != ANONYMOUS);
			$ad_no_forums = explode(",", $config->data['ad_no_forums']);
			for ($a=0; $a < count($ad_no_forums); $a++){
				if ($row['forum_id'] == $ad_no_forums[$a]){
					$display_ad = false;
					break;
				}
			}
			if ($config->data['ad_no_groups'] != '')
			{
				$ad_no_groups = explode(",", $config->data['ad_no_groups']);
				$sql = "SELECT 1
               FROM " . USER_GROUP_TABLE . "
               WHERE user_id=" . $user->data['user_id'] . " AND (";
				for ($a=0; $a < count($ad_no_groups); $a++){
					if ($a!=0)
					{
					$sql .= " OR group_id=" . $ad_no_groups[$a];
					}
					else 
					{
						$sql .= " group_id=" . $ad_no_groups[$a];
					}
				}
				$sql .= ")";
				
				if ( !($result = $db->sql_query($sql)) )
				{
					message_die(GENERAL_ERROR, 'Could not query ad information', '', __LINE__, __FILE__, $sql);
				}
				if ($adrow = $db->sql_fetchrow($result)){

					$display_ad = false;
				}
			}
			if (($config->data['ad_post_threshold'] != '') &&($user->data['user_posts'] >= $config->data['ad_post_threshold']))
			{
				$display_ad = false;
			}
		}
		//check once more, for server performance

		if ($display_ad== true)
		{
			$sql = "SELECT a.ad_code
            FROM " . ADS_TABLE . " a";
			if ( !($result = $db->sql_query($sql)) )
			{
				message_die(GENERAL_ERROR, 'Could not query ad information', '', __LINE__, __FILE__, $sql);
			}
			$adRow = array();
			$adRow = $db->sql_fetchrowset($result);
			srand((double)microtime()*1000000);
			$adindex = rand(1, $db->sql_numrows($result)) - 1;
			$db->sql_freeresult($result);
			$inline_ad_code = $adRow[$adindex]['ad_code'];
		}
#
#-----[ FIND ]------------------------------------------
#
         'ROW_COLOR' => $color ? '#' . $theme['td_color1'] : '#' . $theme['td_color2'],
         'ROW_CLASS' => $color ? $theme['td_class1'] : $theme['td_class2'],
#
#-----[ AFTER, ADD ]------------------------------------------
#
         'L_SPONSOR' => $lang['Sponsor'],
         'INLINE_AD' => $inline_ad_code,
#
#-----[ FIND ]------------------------------------------
#
      $template->assign_block_vars($tpl_switch, $tpl_vars);
      $template->set_switch($tpl_switch . '.light', $color);
#
#-----[ AFTER, ADD ]------------------------------------------
#
   if ($display_ad){
      if (!$config->data['ad_old_style'] && $display_ad)
      {
         $template->assign_block_vars('postrow.switch_ad',array());
      }
      else
      {
         $template->assign_block_vars('postrow.switch_ad_style2',array());
      }
   }
#
#-----[ OPEN ]------------------------------------------
#
includes/class_search.php
#
#-----[ FIND ]------------------------------------------
#
            $this->display_a_post($row, $color);
#
#-----[ REPLACE WITH ]------------------------------------------
#
            $this->display_a_post($row, $color, $i++);
#
#-----[ FIND ]------------------------------------------
#
function display_a_post(&$row, $color)
#
#-----[ REPLACE WITH ]------------------------------------------
#
function display_a_post(&$row, $color, $i)
#
#-----[ FIND ]------------------------------------------
#
parent::display_a_post($row, $color, 'searchresults');
#
#-----[ REPLACE WITH ]------------------------------------------
#
parent::display_a_post($row, $color, $i, 'searchresults');
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/overall_header.tpl
#
#-----[ FIND ]------------------------------------------
#
.helpline { background-color: {T_TR_COLOR2}; border-style: none; }
#
#-----[ AFTER, ADD ]------------------------------------------
#
td.inlineadtitle {
   background-color: {T_TR_COLOR3}; border: {T_TH_COLOR3}; border-style: solid; border-width: 1px;
}
td.inlinead {
   background-color: {T_TR_COLOR3}; border: {T_TH_COLOR3}; border-style: solid; border-width: 1px; text-align: center;
}
#
#-----[ OPEN ]------------------------------------------
#
templates/ptifo/ptifo.css
#
#-----[ FIND ]------------------------------------------
#
hr {
   height: 0px;
   border: solid #D0CAEA 0px;
   border-bottom-width: 1px;
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
td.inlineadtitle {
   background-color: {T_TR_COLOR3}; border: {T_TH_COLOR3}; border-style: solid; border-width: 1px;
}
td.inlinead {
   background-color: {T_TR_COLOR3}; border: {T_TH_COLOR3}; border-style: solid; border-width: 1px; text-align: center;
}
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/viewtopic_body.tpl
#
#-----[ FIND ]------------------------------------------
#
<!-- END postrow -->
#
#-----[ BEFORE, ADD ]------------------------------------------
#
   <!-- BEGIN switch_ad -->
   <tr>
      <td width="150" align="left" valign="top" class="inlineadtitle"><span class="name"><b>{postrow.L_SPONSOR}</b></span><br /</td>
      <td class="inlinead" width="100%" height="28" valign="top">
         {postrow.INLINE_AD}
      </td>
   </tr>
   <tr>
      <td class="spaceRow" colspan="2" height="1"><img src="templates/subSilver/images/spacer.gif" alt="" width="1" height="1" /></td>
   </tr>
   <!-- END switch_ad -->
   <!-- BEGIN switch_ad_style2 -->
   <tr>
      <td colspan=2 class="inlinead">
         {postrow.INLINE_AD}
      </td>
   </tr>
   <!-- END switch_ad_style2 -->
#
#-----[ OPEN ]------------------------------------------
#
templates/ptifo/viewtopic_body.tpl
#
#-----[ FIND ]------------------------------------------
#
<!-- END postrow -->
#
#-----[ REPLACE WITH ]------------------------------------------
#
</form>
<!-- BEGIN switch_ad -->
<tr>
   <td width="150" align="left" valign="top" class="inlineadtitle" colspan="3"><span class="name"><b>{postrow.L_SPONSOR}</b></span><br />
   </td>
   <td class="inlinead" width="100%" height="28" valign="top" colspan="2">
      {postrow.INLINE_AD}
   </td>
</tr>
<tr>
   <td class="spaceRow" colspan="5" height="1"><img src="{I_SPACER}" alt="" width="1" height="1" /></td>
</tr>
<!-- END switch_ad -->
<!-- BEGIN switch_ad_style2 -->
<tr>
   <td colspan="5" class="inlinead">
      {postrow.INLINE_AD}
   </td>
</tr>
<!-- END switch_ad_style2 -->
<!-- END postrow -->
<form method="post" name="post" action="{S_POST_DAYS_ACTION}">
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
