Created
February 9, 2010 16:24
-
-
Save orta/299367 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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