<?php
#########################################################
# GiveMeEnergy Projects #
# Engine by []==ThoRĀ® for More Interactive #
# Contact: #
# hide@address.com #
# More Interactive - www.more.it #
# #
# See More Projects WebSite for updates & patches #
# http://projects.moreinteractive.net/ #
# #
#########################################################
/*
$Revision: 1.4 $
*/
define(_CALC_YEAR,60 * 60 * 24 * 365);
define(_CALC_MONTH,60 * 60 * 24 * 7 * ((365/7)/12)); // (365 days in 1 year / number of days in a week) / number of month in a year
define(_CALC_DAYS,60 * 60 * 24);
define(_CALC_HOURS,60 * 60);
define(_CALC_MINUTES,60);
define(_CALC_SECONDS,1);
class countDown {
var $endY = "1976"; // default end date is my birthday (oh, it will shows my real age!!)
var $endM = "9";
var $endD = "21";
var $endH = "0"; // it's not accurate while using time
var $endMn = "0";
var $endS = "0";
// LANGUAGES
var $yearsT = "year(s)";
var $daysT = "day(s)";
var $monthsT = "month(s)";
var $hoursT = "hour(s)";
var $minutesT = "minute(s)";
var $secondsT = "second(s)";
// Set language for the texts
// @public
function setLangTxt($yearsT="year(s)",$monthsT="month(s)",$daysT="day(s)",$hoursT="hour(s)",$minutesT="minute(s)",$secondsT="second(s)") {
$this->yearsT = $yearsT;
$this->monthsT = $monthsT;
$this->daysT = $daysT;
$this->hoursT = $hoursT;
$this->minutesT = $minutesT;
$this->secondsT = $secondsT;
}
// Set the ending date
// @public
function setEnd($endYear,$endMonth,$endDay,$endHours=0,$endMinutes=0,$endSeconds=0) {
$this->endY = (isset($endYear) && $endYear != "") ? $endYear : date("Y");
$this->endM = (isset($endMonth) && $endMonth != "") ? $endMonth : date("m");
$this->endD = (isset($endDay) && $endDay != "") ? $endDay : date("Y");
$this->endH = (isset($endHours) && $endHours != "") ? $endHours : 0;
$this->endMn = (isset($endMinutes) && $endMinutes != "") ? $endMinutes : 0;
$this->endS = (isset($endSeconds) && $endSeconds != "") ? $endSeconds : 0;
}
// Useful function to get human readable date format
// @private
Function GetDateFormat($data,$dFormat="Y-M-D",$format="%e %B %Y") {
// Format a Data by given format (default= Day MonthName Year)
// dFormat is how the data is given: possible value are: Y-M-D, D-M-Y
$Alldata = Split("-",$data);
$Year = (StrtoLower($dFormat) == "y-m-d" || $dFormat == "") ? $Alldata[0] : $Alldata[2];
$Month = $Alldata[1];
$Day = (StrtoLower($dFormat) == "y-m-d" || $dFormat == "") ? $Alldata[2] : $Alldata[0];
$h = date("H");
$m = date("i");
$s = date("s");
$DataFinish = strftime($format, mktime($h,$m,$s,$Month,$Day,$Year));
return $DataFinish;
}
// Show the Count Down
// @public
// #return the string
// $appendMsgStart01 is the text before the DateCountdown when isn't passed
// $appendMsgStart02 is the text after the DateCountdown when isn't passed
// $appendMsgEnd01 is the text before the DateCountdown when is passed
// $appendMsgEnd02 is the text after the DateCountdown when is passed
//
// $appendMsgStart01 COUNTDOWN $appendMsgStart02 => Still COUNTDOWN for the event
function showCountDown($appendMsgStart01="",$appendMsgStart02="",$appendMsgEnd01="",$appendMsgEnd02="",$display=1) {
// every element is the month, and the value is the days in that month
$monthArray = Array(
1=>31, // January
2=>28, // February
3=>31, // March
4=>30, // April
5=>31, // May
6=>30, // June
7=>31, // July
8=>31, // August
9=>30, // September
10=>31, // October
11=>30, // November
12=>31); // December
$numMonth = Count($monthArray); // I know how many months there are in a year... :o)
// Human readable format
$endDate = $this->GetDateFormat($this->endY."-".$this->endM."-".$this->endD);
$theMkTime = abs(mktime($this->endH,$this->endMn,$this->endS,$this->endM,$this->endD,$this->endY) - time());
$year_until = floor( $theMkTime / _CALC_YEAR ); //
$months_until = floor( $theMkTime / _CALC_MONTH ); //
$days_until = floor( $theMkTime / _CALC_DAYS ); //
$hours_until = floor( $theMkTime / _CALC_HOURS ); //
$minutes_until = floor( $theMkTime / _CALC_MINUTES ); //
$seconds_until = floor( $theMkTime / _CALC_SECONDS ); //
$hour_offset = $hours_until;
$minute_offset = $minutes_until;
$realYear = abs($year_until);
$realMonth = abs($months_until);
$realDays = abs($days_until);
//$year_until = ($year_until < 0) ? 0 : $year_until;
//$months_until = floor($dateDiff/60/60/24/7/4);
//$days_until = $days_until + 1;
$hours_until -= $days_until * 24;
$minutes_until -= $hour_offset * 60;
$seconds_until -= $minute_offset * 60;
$before_since = (int)((mktime ($this->endH,$this->endMn,$this->endS,$this->endM,$this->endD,$this->endY) - time())/1);
$factor = ($before_since < 0) ? -1 : 1;
// CALCUALATION PRECISION
// SubStract 12 months from months for every year passed/to come
$toSub = $realYear * 12;
$realMonth = $realMonth - $toSub;
// SubStract $months_until days from days for every month passed/to come
$startingArray = $this->endM;
for ($i=0;$i<abs($months_until);$i++) {
$realDays = $realDays - $monthArray[$startingArray];
$startingArray++;
$startingArray = ($startingArray > $numMonth) ? 1 : $startingArray;
}
if (abs($hours_until) >= 24) {
$hours_until = abs($hours_until) - 24;
}
if ($hours_until < 0) {
$hours_until = $hours_until + 24;
}
// DISPLAY ONLY NECESSARY
$yearTXT = (abs($realYear) <= 0) ? "" : "".abs($realYear)." ".$this->yearsT.", ";
$monthTXT = (abs($realMonth) <= 0) ? "" : "".abs($realMonth)." ".$this->monthsT.", ";
$dayTXT = (abs($realDays) <= 0) ? "" : "".abs($realDays)." ".$this->daysT.", ";
$hoursTXT = (abs($hours_until) <= 0) ? "" : "".abs($hours_until)." ".$this->hoursT.", ";
$minTXT = (abs($minutes_until) <= 0) ? "" : "".abs($minutes_until)." ".$this->minutesT.", ";
$secTXT = (abs($seconds_until) <= 0) ? "" : "".abs($seconds_until)." ".$this->secondsT.", ";
If ($factor != -1) {
$msg = "".$appendMsgStart01."
".$yearTXT."
".$monthTXT."
".$dayTXT."
".$hoursTXT."
".$minTXT."
".$secTXT."
".$appendMsgStart02." ";
} else {
$msg = "".$appendMsgEnd01."
".$yearTXT."
".$monthTXT."
".$dayTXT."
".$hoursTXT."
".$minTXT."
".$secTXT."
".$appendMsgEnd02." ";
}
return $msg;
}
}
?>