Skip to content

Instantly share code, notes, and snippets.

@dubrod
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubrod/10181283 to your computer and use it in GitHub Desktop.
Save dubrod/10181283 to your computer and use it in GitHub Desktop.
Zap Banner Engine
<?php
//BOOSTRAP FILE CODE
//ZAP Banner Engine
include_once('zap.banner.engine.php');
$ZAP_banner_engine = new ZAP_banner_engine;
$banner_html = $ZAP_banner_engine->get_unseen();
?>
<?php
# Banner Engine - zap.banner.engine.php
# Version 1.0
# Impression Counter
# Click Counter
# Support for 1 location - who has more than 1 banner per page??
# still using zap : http://www.shayanderson.com/projects/zap.htm
# April 08 2014 - Year of our Lord
# include this in boostrap
class ZAP_banner_engine{
function get_unseen(){
//GRAB THE MOST UNSEEN BANNER
//obviously there might be multiple with 0, they will all eventually get their turn
$unseen_records = z::select('* FROM banners WHERE active = 1 ORDER BY impressions LIMIT 1');
$unseen_banner = $unseen_records->records[0];
$banner_file = $unseen_banner->file_name; //skyscraper.gif
$banner_id = $unseen_banner->banner_id;
$banner_dir = "banners/"; //where do you keep banners?
$click_counter = "zap.banner.engine.php?zap_clicker="; //passthrough page to count the click
//update the impression count
z::update('banners SET impressions = impressions+1 WHERE banner_id = {$1}', $banner_id);
return '<a href="/'.$click_counter.$banner_id.'"><img src="/'.$banner_dir.''.$banner_file.'" class="sidebar-banner"></a>';
}
}
if(isset($_GET["zap_clicker"])){
require_once 'lib/Zap/zap.bootstrap.php';
$clicked_id = $_GET["zap_clicker"];
//update the click count
z::update('banners SET clicks = clicks+1 WHERE banner_id = {$1}', $clicked_id);
//send it on its way
$zap_out = z::select('link FROM banners WHERE banner_id = {$1}', $clicked_id);
header('Location: '.$zap_out->records[0]->link.'');
}
?>
//HTML FILE
<?=$banner_html;?>
--
-- Table structure for table `banners`
--
CREATE TABLE `banners` (
`banner_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`vendor_id` int(11) NOT NULL,
`file_name` varchar(255) NOT NULL,
`link` varchar(255) NOT NULL,
`clicks` int(11) NOT NULL,
`impressions` int(100) NOT NULL,
`active` int(11) NOT NULL,
PRIMARY KEY (`banner_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment