Skip to content

Instantly share code, notes, and snippets.

@orta
Created February 9, 2010 16:24
Show Gist options
  • Save orta/299367 to your computer and use it in GitHub Desktop.
Save orta/299367 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: AdMangler for bbPress
Plugin URI: http://www.webternals.com/products/admangler/
Description: Display ad space on your bbpress powered site with AdMangler.
Version: 0.1
Author: Webternals, LLC - Allen Sanford
Author URI: http://www.webternals.com/
*/
// Ben Maslen - ben@fabspider.com - February 9, 2010
class AdMangler
{
function AdMangler()
{
global $bbdb;
$prefix = "wp_1_";
$this->adsTable = $prefix . "AdMangler_ads";
$this->settingsTable = $prefix . "AdMangler_settings";
$this->usersTable = $prefix . "AdMangler_users";
} // End function AdMangler
function FormatAd($type,$code)
{
switch($type)
{
case 'html':
$code = $code;
}
return $code;
} //End function FormatAd
function GetAdById($id, $return)
{
global $bbdb;
$sql = "SELECT * FROM $this->adsTable WHERE id=".intval($id);
$row = $bbdb->get_row($sql);
$str = $this->FormatAd($row->type, $row->code);
if ($return) return $str; else echo $str;
} // End function GetAdById
function GetAds($width=468, $height=60, $return=true)
{
global $bbdb;
if (!is_array($this->banners[$width."x".$height]))
$this->banners[$width."x".$height] = array();
if (empty($this->banners[$width."x".$height]))
{
$sql = "SELECT type,code FROM $this->adsTable WHERE width=$width and height=$height and active and approved and NOT base ORDER BY RAND()";
$results = $bbdb->get_results($sql);
if ($results)
$this->banners[$width."x".$height] = $results;
$sql = "SELECT type,code FROM $this->adsTable WHERE width=$width and height=$height and active and approved and base ORDER BY RAND()";
$results = $bbdb->get_results($sql);
if ($results)
{
$this->banners[$width."x".$height] = array_merge($this->banners[$width."x".$height], $results);
}
}
$str = "";
$banner = array_shift($this->banners[$width."x".$height]);
array_push($this->banners[$width."x".$height], $banner);
$str = $this->FormatAd($banner->type, $banner->code);
if ($return) return $str; else echo $str;
} // End function GetAds
} // End class AdMangler
$adMangler = new AdMangler();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment