<?php
##########################
# Obanner
# -------VER 1.0.1------
##########################
# name : Obanner
# description : with this class , you can add alot & alot of banners with specific period .. after this period the class will show the default banner .
# author : saanina (abdulrahman muhammad) (K.S.A)
# email : hide@address.com
# price : 0.0$
###########################
# todo : advanced version for those who love alot of features .
###########################
# send to me your changes in this class for more improvement and sharing
# the information !
###########################
# last edit : 21/7/29H = ../7/08C
#example ..
#//configuration
#$banner = new banner('defulat.gif','http://default.com');
#//ads .. alot of them you can add ..
#print $banner->add_banner('bnr1.gif','http://bnr1.com','1-1-2008');
#print $banner->add_banner('bnr2.gif','http://bnr2.com','1-1-2009');
####
class banner
{
//
// vars
//
var $default_banner = '';
var $default_link = '';
var $default_lang = array (
'time_left' => 'time left',
);
#
# the default banner
# img_src : default banner img link
#link : default img link
#@banner class
#
function banner ($img_src = false, $link = false, $lang = false)
{
//default things
if($img_src !== false) $this->default_banner = $img_src;
if($link !== false) $this->default_link = $link ;
if($lang !== false && is_array($lang)) $this->default_lang = $lang;
}
#
# add_banner
# img_src : banner link
# link : banner link
# date_end : the date the banner will be off
# @banner class
#
function add_banner ($img_src, $link, $date_end)
{
// get ime left
$time_left = $this->time_left($date_end);
//if still there time in the banner , lets show it , or show default one if time left
$banner_lnik = ($time_left > 0) ? $link : $this->default_link;
//same as above but this with img
$banner_img = ($time_left > 0) ? $img_src : $this->default_banner;
//lets return the data without print , why ? cuz "print" inside classes and function may make the page dispaly not ok ..
return '<a href="' . $banner_lnik . '"><img src="' . $banner_img . '" alt="'. $this->default_lang['time_left'] .':' . $time_left . '" style="border:0px" /></a>';
}
#
# time_left
# date : future date [ day-month-year]
# @banner class
#
function time_left ($date)
{
//lets check for sign in the date , cuz its important
if(strpos($date , '/') === false && strpos($date , '-') === false)
{
return false;
}
//split the date by two method
$t = split('[-,/]', $date);
//convert the date format to unix format [ why ? cuz computer doesnt understand , its fool machine ]
$t1 = mktime(0,0,0,$t[1], $t[0], $t[2]);
// may be u want ask me , time() will help ! , i will say : yes , but it have hours and minuts !!!
$t2 = mktime(0,0,0,date('m'), date('d'), date('Y'));
// future date - now / day calculating
$totaldays = ($t1 - $t2) / (60 * 60 * 24);
//return the day left
return $totaldays;
}
}#end of class
?>