Index: trunk/core/kernel/startup.php =================================================================== diff -u -r3210 -r3282 --- trunk/core/kernel/startup.php (.../startup.php) (revision 3210) +++ trunk/core/kernel/startup.php (.../startup.php) (revision 3282) @@ -76,6 +76,7 @@ k4_include_once(KERNEL_PATH.'/utility/event.php'); k4_include_once(KERNEL_PATH."/utility/factory.php"); k4_include_once(KERNEL_PATH."/languages/phrases_cache.php"); + if( !function_exists('adodb_mktime') ) k4_include_once(KERNEL_PATH.'/utility/adodb-time.inc.php'); // We should get rid of these includes: k4_include_once(KERNEL_PATH."/db/dblist.php"); Index: trunk/kernel/include/usersession.php =================================================================== diff -u -r2941 -r3282 --- trunk/kernel/include/usersession.php (.../usersession.php) (revision 2941) +++ trunk/kernel/include/usersession.php (.../usersession.php) (revision 3282) @@ -129,7 +129,7 @@ $this->Set("GroupList",$this->Get("GroupList")); $this->Set("Language",$this->Get("Language")); $this->Set("tz",$this->Get("tz")); - $this->Set("LastAccessed",date("U")); + $this->Set("LastAccessed",adodb_date("U")); $this->Update(); } } @@ -217,7 +217,7 @@ { global $objConfig; - //$this->Set("LastAccessed",date("U")); + //$this->Set("LastAccessed",adodb_date("U")); $this->Set("IpAddress",$_SERVER["REMOTE_ADDR"]); if(!isset($this->m_SessionKey)) { @@ -262,7 +262,7 @@ { global $objConfig; - $this->Set("LastAccessed", time()); + $this->Set("LastAccessed", adodb_mktime()); if(!is_numeric($this->Get("PortalUserId"))) { $this->Set("PortalUserId",0); @@ -525,10 +525,10 @@ $app->setVisitField('PortalUserId', $this->Get('PortalUserId') ); } - $this->Set('LastAccessed', date('U') ); + $this->Set('LastAccessed', adodb_date('U') ); $this_login = $this->GetPersistantVariable("ThisLogin"); $this->SetPersistantVariable("LastLogin", $this_login); - $this->SetPersistantVariable("ThisLogin", time()); + $this->SetPersistantVariable("ThisLogin", adodb_mktime()); $this->ResetSysPermCache(); $this->PermCache = array(); $this->Update(); @@ -552,7 +552,7 @@ $this->Set("PortalUserId", 0); // not logged-in $this->Set('LastAccessed',0); // session become expired $this->Set("GroupId", $objConfig->Get("User_GuestGroup")); - #$this->SetPersistantVariable("LastLogin", time()); + #$this->SetPersistantVariable("LastLogin", adodb_mktime()); if ($FrontEnd) $group_list = $objConfig->Get('User_GuestGroup').','.$objConfig->Get('User_LoggedInGroup'); $this->Set("GroupList", $group_list); @@ -751,7 +751,7 @@ { global $objConfig; - $cutoff = time()-$objConfig->Get("SessionTimeout"); + $cutoff = adodb_mktime()-$objConfig->Get("SessionTimeout"); $thiskey = $this->GetSessionKey(); $sql = "SELECT SessionKey from ".GetTablePrefix()."UserSession WHERE LastAccessed<$cutoff AND SessionKey != '$thiskey'"; $result = $this->adodbConnection->Execute($sql); @@ -1049,7 +1049,7 @@ function GetTotalSessions() { - # $time = time() - 900; + # $time = adodb_mktime() - 900; $sql = "SELECT count(*) as SesCount FROM ".GetTablePrefix()."UserSession"; $result = $this->adodbConnection->Execute($sql); if ($result === false) @@ -1177,7 +1177,7 @@ global $objConfig; $a = $this->Get("LastAccessed"); - $cutoff = time()-$objConfig->Get("SessionTimeout"); + $cutoff = adodb_mktime()-$objConfig->Get("SessionTimeout"); //echo $a." ".$cutoff."
"; //$ip = ($_SERVER['REMOTE_ADDR'] == $this->Get("IpAddress")); //echo $this->Get("IpAddress"); @@ -1192,8 +1192,7 @@ function UpdateAccessTime() { - $now = time(); - $this->Set("LastAccessed",$now); + $this->Set("LastAccessed", adodb_mktime() ); } function InSpamControl($ResourceId,$DataType=NULL) Index: trunk/kernel/include/adodb/adodb-time.inc.php =================================================================== diff -u -r535 -r3282 --- trunk/kernel/include/adodb/adodb-time.inc.php (.../adodb-time.inc.php) (revision 535) +++ trunk/kernel/include/adodb/adodb-time.inc.php (.../adodb-time.inc.php) (revision 3282) @@ -23,7 +23,9 @@ date() with adodb_date() gmdate() with adodb_gmdate() mktime() with adodb_mktime() - gmmktime() with adodb_gmmktime()45 + gmmktime() with adodb_gmmktime() + strftime() with adodb_strftime() + strftime() with adodb_gmstrftime() The parameters are identical, except that adodb_date() accepts a subset @@ -55,8 +57,8 @@ COPYRIGHT -(c) 2003 John Lim and released under BSD-style license except for code by jackbbs, -which includes adodb_mktime, adodb_get_gmt_different, adodb_is_leap_year +(c) 2003-2005 John Lim and released under BSD-style license except for code by +jackbbs, which includes adodb_mktime, adodb_get_gmt_diff, adodb_is_leap_year and originally found at http://www.php.net/manual/en/function.mktime.php ============================================================================= @@ -72,82 +74,155 @@ FUNCTION DESCRIPTIONS -FUNCTION adodb_getdate($date=false) +** FUNCTION adodb_getdate($date=false) Returns an array containing date information, as getdate(), but supports -dates greater than 1901 to 2038. +dates greater than 1901 to 2038. The local date/time format is derived from a +heuristic the first time adodb_getdate is called. + + +** FUNCTION adodb_date($fmt, $timestamp = false) - -FUNCTION adodb_date($fmt, $timestamp = false) - Convert a timestamp to a formatted local date. If $timestamp is not defined, the current timestamp is used. Unlike the function date(), it supports dates outside the 1901 to 2038 range. The format fields that adodb_date supports:
-a - "am" or "pm" 
-A - "AM" or "PM" 
-d - day of the month, 2 digits with leading zeros; i.e. "01" to "31" 
-D - day of the week, textual, 3 letters; e.g. "Fri" 
-F - month, textual, long; e.g. "January" 
-g - hour, 12-hour format without leading zeros; i.e. "1" to "12" 
-G - hour, 24-hour format without leading zeros; i.e. "0" to "23" 
-h - hour, 12-hour format; i.e. "01" to "12" 
-H - hour, 24-hour format; i.e. "00" to "23" 
-i - minutes; i.e. "00" to "59" 
-j - day of the month without leading zeros; i.e. "1" to "31" 
-l (lowercase 'L') - day of the week, textual, long; e.g. "Friday"  
-L - boolean for whether it is a leap year; i.e. "0" or "1" 
-m - month; i.e. "01" to "12" 
-M - month, textual, 3 letters; e.g. "Jan" 
-n - month without leading zeros; i.e. "1" to "12" 
-O - Difference to Greenwich time in hours; e.g. "+0200" 
-r - RFC 822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200" 
-s - seconds; i.e. "00" to "59" 
-S - English ordinal suffix for the day of the month, 2 characters; 
-   			i.e. "st", "nd", "rd" or "th" 
-t - number of days in the given month; i.e. "28" to "31"
-T - Timezone setting of this machine; e.g. "EST" or "MDT" 
-U - seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)  
-w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday) 
-Y - year, 4 digits; e.g. "1999" 
-y - year, 2 digits; e.g. "99" 
-z - day of the year; i.e. "0" to "365" 
-Z - timezone offset in seconds (i.e. "-43200" to "43200"). 
-   			The offset for timezones west of UTC is always negative, 
-			and for those east of UTC is always positive. 
+	a - "am" or "pm" 
+	A - "AM" or "PM" 
+	d - day of the month, 2 digits with leading zeros; i.e. "01" to "31" 
+	D - day of the week, textual, 3 letters; e.g. "Fri" 
+	F - month, textual, long; e.g. "January" 
+	g - hour, 12-hour format without leading zeros; i.e. "1" to "12" 
+	G - hour, 24-hour format without leading zeros; i.e. "0" to "23" 
+	h - hour, 12-hour format; i.e. "01" to "12" 
+	H - hour, 24-hour format; i.e. "00" to "23" 
+	i - minutes; i.e. "00" to "59" 
+	j - day of the month without leading zeros; i.e. "1" to "31" 
+	l (lowercase 'L') - day of the week, textual, long; e.g. "Friday"  
+	L - boolean for whether it is a leap year; i.e. "0" or "1" 
+	m - month; i.e. "01" to "12" 
+	M - month, textual, 3 letters; e.g. "Jan" 
+	n - month without leading zeros; i.e. "1" to "12" 
+	O - Difference to Greenwich time in hours; e.g. "+0200" 
+	Q - Quarter, as in 1, 2, 3, 4 
+	r - RFC 822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200" 
+	s - seconds; i.e. "00" to "59" 
+	S - English ordinal suffix for the day of the month, 2 characters; 
+	   			i.e. "st", "nd", "rd" or "th" 
+	t - number of days in the given month; i.e. "28" to "31"
+	T - Timezone setting of this machine; e.g. "EST" or "MDT" 
+	U - seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)  
+	w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday) 
+	Y - year, 4 digits; e.g. "1999" 
+	y - year, 2 digits; e.g. "99" 
+	z - day of the year; i.e. "0" to "365" 
+	Z - timezone offset in seconds (i.e. "-43200" to "43200"). 
+	   			The offset for timezones west of UTC is always negative, 
+				and for those east of UTC is always positive. 
 
Unsupported:
-B - Swatch Internet time 
-I (capital i) - "1" if Daylight Savings Time, "0" otherwise.
-W - ISO-8601 week number of year, weeks starting on Monday 
+	B - Swatch Internet time 
+	I (capital i) - "1" if Daylight Savings Time, "0" otherwise.
+	W - ISO-8601 week number of year, weeks starting on Monday 
 
 
-FUNCTION adodb_gmdate($fmt, $timestamp = false) +** FUNCTION adodb_date2($fmt, $isoDateString = false) +Same as adodb_date, but 2nd parameter accepts iso date, eg. + adodb_date2('d-M-Y H:i','2003-12-25 13:01:34'); + + +** FUNCTION adodb_gmdate($fmt, $timestamp = false) + Convert a timestamp to a formatted GMT date. If $timestamp is not defined, the current timestamp is used. Unlike the function date(), it supports dates outside the 1901 to 2038 range. -FUNCTION adodb_mktime($hr, $min, $sec, $month, $day, $year) +** FUNCTION adodb_mktime($hr, $min, $sec[, $month, $day, $year]) Converts a local date to a unix timestamp. Unlike the function mktime(), it supports -dates outside the 1901 to 2038 range. Differs from mktime() in that all parameters -are currently compulsory. +dates outside the 1901 to 2038 range. All parameters are optional. -FUNCTION adodb_gmmktime($hr, $min, $sec, $month, $day, $year) +** FUNCTION adodb_gmmktime($hr, $min, $sec [, $month, $day, $year]) + Converts a gmt date to a unix timestamp. Unlike the function gmmktime(), it supports dates outside the 1901 to 2038 range. Differs from gmmktime() in that all parameters are currently compulsory. +** FUNCTION adodb_gmstrftime($fmt, $timestamp = false) +Convert a timestamp to a formatted GMT date. + +** FUNCTION adodb_strftime($fmt, $timestamp = false) + +Convert a timestamp to a formatted local date. Internally converts $fmt into +adodb_date format, then echo result. + +For best results, you can define the local date format yourself. Define a global +variable $ADODB_DATE_LOCALE which is an array, 1st element is date format using +adodb_date syntax, and 2nd element is the time format, also in adodb_date syntax. + + eg. $ADODB_DATE_LOCALE = array('d/m/Y','H:i:s'); + + Supported format codes: + +
+	%a - abbreviated weekday name according to the current locale 
+	%A - full weekday name according to the current locale 
+	%b - abbreviated month name according to the current locale 
+	%B - full month name according to the current locale 
+	%c - preferred date and time representation for the current locale 
+	%d - day of the month as a decimal number (range 01 to 31) 
+	%D - same as %m/%d/%y 
+	%e - day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31') 
+	%h - same as %b
+	%H - hour as a decimal number using a 24-hour clock (range 00 to 23) 
+	%I - hour as a decimal number using a 12-hour clock (range 01 to 12) 
+	%m - month as a decimal number (range 01 to 12) 
+	%M - minute as a decimal number 
+	%n - newline character 
+	%p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale 
+	%r - time in a.m. and p.m. notation 
+	%R - time in 24 hour notation 
+	%S - second as a decimal number 
+	%t - tab character 
+	%T - current time, equal to %H:%M:%S 
+	%x - preferred date representation for the current locale without the time 
+	%X - preferred time representation for the current locale without the date 
+	%y - year as a decimal number without a century (range 00 to 99) 
+	%Y - year as a decimal number including the century 
+	%Z - time zone or name or abbreviation 
+	%% - a literal `%' character 
+
+ + Unsupported codes: +
+	%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99) 
+	%g - like %G, but without the century. 
+	%G - The 4-digit year corresponding to the ISO week number (see %V). 
+	     This has the same format and value as %Y, except that if the ISO week number belongs 
+		 to the previous or next year, that year is used instead. 
+	%j - day of the year as a decimal number (range 001 to 366) 
+	%u - weekday as a decimal number [1,7], with 1 representing Monday 
+	%U - week number of the current year as a decimal number, starting 
+	    with the first Sunday as the first day of the first week 
+	%V - The ISO 8601:1988 week number of the current year as a decimal number, 
+	     range 01 to 53, where week 1 is the first week that has at least 4 days in the 
+		 current year, and with Monday as the first day of the week. (Use %G or %g for 
+		 the year component that corresponds to the week number for the specified timestamp.) 
+	%w - day of the week as a decimal, Sunday being 0 
+	%W - week number of the current year as a decimal number, starting with the 
+	     first Monday as the first day of the first week 
+
+ ============================================================================= NOTES @@ -161,14 +236,81 @@ (page 428, xttotm.c _Ttotm() function). Plauger's algorithm will not work outside 32-bit signed range, so i decided not to implement it. -b. Iterate over a block of years (say 12) when searching for the -correct year. - -c. Implement daylight savings, which looks awfully complicated, see +b. Implement daylight savings, which looks awfully complicated, see http://webexhibits.org/daylightsaving/ CHANGELOG + +- 18 July 2005 0.21 +- In PHP 4.3.11, the 'r' format has changed. Leading 0 in day is added. Changed for compat. +- Added support for negative months in adodb_mktime(). + +- 24 Feb 2005 0.20 +Added limited strftime/gmstrftime support. x10 improvement in performance of adodb_date(). + +- 21 Dec 2004 0.17 +In adodb_getdate(), the timestamp was accidentally converted to gmt when $is_gmt is false. +Also adodb_mktime(0,0,0) did not work properly. Both fixed thx Mauro. + +- 17 Nov 2004 0.16 +Removed intval typecast in adodb_mktime() for secs, allowing: + adodb_mktime(0,0,0 + 2236672153,1,1,1934); +Suggested by Ryan. + +- 18 July 2004 0.15 +All params in adodb_mktime were formerly compulsory. Now only the hour, min, secs is compulsory. +This brings it more in line with mktime (still not identical). + +- 23 June 2004 0.14 + +Allow you to define your own daylights savings function, adodb_daylight_sv. +If the function is defined (somewhere in an include), then you can correct for daylights savings. + +In this example, we apply daylights savings in June or July, adding one hour. This is extremely +unrealistic as it does not take into account time-zone, geographic location, current year. + +function adodb_daylight_sv(&$arr, $is_gmt) +{ + if ($is_gmt) return; + $m = $arr['mon']; + if ($m == 6 || $m == 7) $arr['hours'] += 1; +} + +This is only called by adodb_date() and not by adodb_mktime(). + +The format of $arr is +Array ( + [seconds] => 0 + [minutes] => 0 + [hours] => 0 + [mday] => 1 # day of month, eg 1st day of the month + [mon] => 2 # month (eg. Feb) + [year] => 2102 + [yday] => 31 # days in current year + [leap] => # true if leap year + [ndays] => 28 # no of days in current month + ) + + +- 28 Apr 2004 0.13 +Fixed adodb_date to properly support $is_gmt. Thx to Dimitar Angelov. + +- 20 Mar 2004 0.12 +Fixed month calculation error in adodb_date. 2102-June-01 appeared as 2102-May-32. + +- 26 Oct 2003 0.11 +Because of daylight savings problems (some systems apply daylight savings to +January!!!), changed adodb_get_gmt_diff() to ignore daylight savings. + +- 9 Aug 2003 0.10 +Fixed bug with dates after 2038. +See http://phplens.com/lens/lensforum/msgs.php?id=6980 + +- 1 July 2003 0.09 +Added support for Q (Quarter). +Added adodb_date2(), which accepts ISO date in 2nd param + - 3 March 2003 0.08 Added support for 'S' adodb_date() format char. Added constant ADODB_ALLOW_NEGATIVE_TS if you want PHP to handle negative timestamps between 1901 to 1969. @@ -217,12 +359,11 @@ /* Version Number */ -define('ADODB_DATE_VERSION',0.08); +define('ADODB_DATE_VERSION',0.21); /* - We check for Windows as only +ve ints are accepted as dates on Windows. - - Apparently this problem happens also with Linux, RH 7.3 and later! + This code was originally for windows. But apparently this problem happens + also with Linux, RH 7.3 and later! glibc-2.2.5-34 and greater has been changed to return -1 for dates < 1970. This used to work. The problem exists with RedHat 7.3 and 8.0 @@ -235,30 +376,56 @@ if (!defined('ADODB_ALLOW_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS',1); -function adodb_date_test_date($y1,$m) +function adodb_date_test_date($y1,$m,$d=13) { - //print " $y1/$m "; - $t = adodb_mktime(0,0,0,$m,13,$y1); - if ("$y1-$m-13 00:00:00" != adodb_date('Y-n-d H:i:s',$t)) { - print "$y1 error
"; + $t = adodb_mktime(0,0,0,$m,$d,$y1); + $rez = adodb_date('Y-n-j H:i:s',$t); + if ("$y1-$m-$d 00:00:00" != $rez) { + print "$y1 error, expected=$y1-$m-$d 00:00:00, adodb=$rez
"; return false; } return true; } + +function adodb_date_test_strftime($fmt) +{ + $s1 = strftime($fmt); + $s2 = adodb_strftime($fmt); + + if ($s1 == $s2) return true; + + echo "error for $fmt, strftime=$s1, $adodb=$s2
"; + return false; +} + /** Test Suite */ function adodb_date_test() { error_reporting(E_ALL); - print "

Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION. "

"; - set_time_limit(0); + print "

Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION.' PHP='.PHP_VERSION."

"; + @set_time_limit(0); $fail = false; // This flag disables calling of PHP native functions, so we can properly test the code if (!defined('ADODB_TEST_DATES')) define('ADODB_TEST_DATES',1); + adodb_date_test_strftime('%Y %m %x %X'); + adodb_date_test_strftime("%A %d %B %Y"); + adodb_date_test_strftime("%H %M S"); + + $t = adodb_mktime(0,0,0); + if (!(adodb_date('Y-m-d') == date('Y-m-d'))) print 'Error in '.adodb_mktime(0,0,0).'
'; + + $t = adodb_mktime(0,0,0,6,1,2102); + if (!(adodb_date('Y-m-d',$t) == '2102-06-01')) print 'Error in '.adodb_date('Y-m-d',$t).'
'; + + $t = adodb_mktime(0,0,0,2,1,2102); + if (!(adodb_date('Y-m-d',$t) == '2102-02-01')) print 'Error in '.adodb_date('Y-m-d',$t).'
'; + + print "

Testing gregorian <=> julian conversion

"; $t = adodb_mktime(0,0,0,10,11,1492); //http://www.holidayorigins.com/html/columbus_day.html - Friday check @@ -367,7 +534,7 @@ // we generate a timestamp, convert it to a date, and convert it back to a timestamp // and check if the roundtrip broke the original timestamp value. print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: "; - + $cnt = 0; for ($max += $i; $i < $max; $i += $offset) { $ret = adodb_date('m,d,Y,H,i,s',$i); $arr = explode(',',$ret); @@ -382,8 +549,9 @@ $fail = true; break; } + $cnt += 1; } - + echo "Tested $cnt dates
"; if (!$fail) print "

Passed !

"; else print "

Failed :-(

"; } @@ -416,13 +584,13 @@ $year--; } - $day = ( floor((13 * $month - 1) / 5) + + $day = floor((13 * $month - 1) / 5) + $day + ($year % 100) + floor(($year % 100) / 4) + floor(($year / 100) / 4) - 2 * - floor($year / 100) + 77); + floor($year / 100) + 77 + $greg_correction; - return (($day - 7 * floor($day / 7))) + $greg_correction; + return $day - 7 * floor($day / 7); } @@ -444,6 +612,7 @@ return true; } + /** checks for leap year, returns true if it is. Has 2-digit year check */ @@ -479,20 +648,18 @@ return $y; } - /** get local time zone offset from GMT */ -function adodb_get_gmt_different() +function adodb_get_gmt_diff() { -static $DIFF; - if (isset($DIFF)) return $DIFF; +static $TZ; + if (isset($TZ)) return $TZ; - $DIFF = mktime(0,0,0,1,2,2000) - gmmktime(0,0,0,1,2,2000); - return $DIFF; + $TZ = mktime(0,0,0,1,2,1970,0) - gmmktime(0,0,0,1,2,1970,0); + return $TZ; } - /** Returns an array with date info. */ @@ -508,14 +675,36 @@ return _adodb_getdate($d); } +/* +// generate $YRS table for _adodb_getdate() +function adodb_date_gentable($out=true) +{ + + for ($i=1970; $i >= 1600; $i-=10) { + $s = adodb_gmmktime(0,0,0,1,1,$i); + echo "$i => $s,
"; + } +} +adodb_date_gentable(); + +for ($i=1970; $i > 1500; $i--) { + +echo "
$i "; + adodb_date_test_date($i,1,1); +} + +*/ + /** Low-level function that returns the getdate() array. We have a special $fast flag, which if set to true, will return fewer array values, and is much faster as it does not calculate dow, etc. */ function _adodb_getdate($origd=false,$fast=false,$is_gmt=false) { - $d = $origd - ($is_gmt ? 0 : adodb_get_gmt_different()); +static $YRS; + + $d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff()); $_day_power = 86400; $_hour_power = 3600; @@ -526,23 +715,103 @@ $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31); $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31); + $d366 = $_day_power * 366; + $d365 = $_day_power * 365; + if ($d < 0) { - $origd = $d; + + if (empty($YRS)) $YRS = array( + 1970 => 0, + 1960 => -315619200, + 1950 => -631152000, + 1940 => -946771200, + 1930 => -1262304000, + 1920 => -1577923200, + 1910 => -1893456000, + 1900 => -2208988800, + 1890 => -2524521600, + 1880 => -2840140800, + 1870 => -3155673600, + 1860 => -3471292800, + 1850 => -3786825600, + 1840 => -4102444800, + 1830 => -4417977600, + 1820 => -4733596800, + 1810 => -5049129600, + 1800 => -5364662400, + 1790 => -5680195200, + 1780 => -5995814400, + 1770 => -6311347200, + 1760 => -6626966400, + 1750 => -6942499200, + 1740 => -7258118400, + 1730 => -7573651200, + 1720 => -7889270400, + 1710 => -8204803200, + 1700 => -8520336000, + 1690 => -8835868800, + 1680 => -9151488000, + 1670 => -9467020800, + 1660 => -9782640000, + 1650 => -10098172800, + 1640 => -10413792000, + 1630 => -10729324800, + 1620 => -11044944000, + 1610 => -11360476800, + 1600 => -11676096000); + + if ($is_gmt) $origd = $d; // The valid range of a 32bit signed timestamp is typically from // Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT + // + + # old algorithm iterates through all years. new algorithm does it in + # 10 year blocks + + /* + # old algo for ($a = 1970 ; --$a >= 0;) { $lastd = $d; - if ($leaf = _adodb_is_leap_year($a)) { - $d += $_day_power * 366; - } else - $d += $_day_power * 365; + if ($leaf = _adodb_is_leap_year($a)) $d += $d366; + else $d += $d365; + if ($d >= 0) { $year = $a; break; } } + */ + $lastsecs = 0; + $lastyear = 1970; + foreach($YRS as $year => $secs) { + if ($d >= $secs) { + $a = $lastyear; + break; + } + $lastsecs = $secs; + $lastyear = $year; + } + + $d -= $lastsecs; + if (!isset($a)) $a = $lastyear; + + //echo ' yr=',$a,' ', $d,'.'; + + for (; --$a >= 0;) { + $lastd = $d; + + if ($leaf = _adodb_is_leap_year($a)) $d += $d366; + else $d += $d365; + + if ($d >= 0) { + $year = $a; + break; + } + } + /**/ + $secsInYear = 86400 * ($leaf ? 366 : 365) + $lastd; $d = $lastd; @@ -564,15 +833,12 @@ $hour = floor($d/$_hour_power); } else { - for ($a = 1970 ;; $a++) { $lastd = $d; - if ($leaf = _adodb_is_leap_year($a)) { - $d -= $_day_power * 366; - } else - $d -= $_day_power * 365; - if ($d <= 0) { + if ($leaf = _adodb_is_leap_year($a)) $d -= $d366; + else $d -= $d365; + if ($d < 0) { $year = $a; break; } @@ -583,7 +849,7 @@ for ($a = 1 ; $a <= 12; $a++) { $lastd = $d; $d -= $mtab[$a] * $_day_power; - if ($d <= 0) { + if ($d < 0) { $month = $a; $ndays = $mtab[$a]; break; @@ -635,22 +901,47 @@ return adodb_date($fmt,$d,true); } +// accepts unix timestamp and iso date format in $d +function adodb_date2($fmt, $d=false, $is_gmt=false) +{ + if ($d !== false) { + if (!preg_match( + "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ -]?(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|", + ($d), $rr)) return adodb_date($fmt,false,$is_gmt); + if ($rr[1] <= 100 && $rr[2]<= 1) return adodb_date($fmt,false,$is_gmt); + + // h-m-s-MM-DD-YY + if (!isset($rr[5])) $d = adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]); + else $d = @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]); + } + + return adodb_date($fmt,$d,$is_gmt); +} + + /** Return formatted date based on timestamp $d */ function adodb_date($fmt,$d=false,$is_gmt=false) { - if ($d === false) return date($fmt); +static $daylight; + + if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt); if (!defined('ADODB_TEST_DATES')) { if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer - return @date($fmt,$d); + return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d); + } } $_day_power = 86400; $arr = _adodb_getdate($d,true,$is_gmt); + + if (!isset($daylight)) $daylight = function_exists('adodb_daylight_sv'); + if ($daylight) adodb_daylight_sv($arr, $is_gmt); + $year = $arr['year']; $month = $arr['mon']; $day = $arr['mday']; @@ -672,22 +963,25 @@ case 'L': $dates .= $arr['leap'] ? '1' : '0'; break; case 'r': // Thu, 21 Dec 2000 16:01:07 +0200 + // 4.3.11 uses '04 Jun 2004' + // 4.3.8 uses ' 4 Jun 2004' $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))).', ' - . ($day<10?' '.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' '; + . ($day<10?'0'.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' '; if ($hour < 10) $dates .= '0'.$hour; else $dates .= $hour; if ($min < 10) $dates .= ':0'.$min; else $dates .= ':'.$min; if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs; - $gmt = adodb_get_gmt_different(); + $gmt = adodb_get_gmt_diff(); $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; case 'Y': $dates .= $year; break; case 'y': $dates .= substr($year,strlen($year)-2,2); break; // MONTH case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break; + case 'Q': $dates .= ($month+3)>>2; break; case 'n': $dates .= $month; break; case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break; case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break; @@ -702,16 +996,16 @@ case 'S': $d10 = $day % 10; if ($d10 == 1) $dates .= 'st'; - else if ($d10 == 2) $dates .= 'nd'; + else if ($d10 == 2 && $day != 12) $dates .= 'nd'; else if ($d10 == 3) $dates .= 'rd'; else $dates .= 'th'; break; // HOUR case 'Z': - $dates .= ($is_gmt) ? 0 : -adodb_get_gmt_different(); break; + $dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff(); break; case 'O': - $gmt = ($is_gmt) ? 0 : adodb_get_gmt_different(); + $gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff(); $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; case 'H': @@ -772,41 +1066,67 @@ Returns a timestamp given a GMT/UTC time. Note that $is_dst is not implemented and is ignored. */ -function adodb_gmmktime($hr,$min,$sec,$mon,$day,$year,$is_dst=false) +function adodb_gmmktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=false) { return adodb_mktime($hr,$min,$sec,$mon,$day,$year,$is_dst,true); } /** Return a timestamp given a local time. Originally by jackbbs. Note that $is_dst is not implemented and is ignored. + + Not a very fast algorithm - O(n) operation. Could be optimized to O(1). */ -function adodb_mktime($hr,$min,$sec,$mon,$day,$year,$is_dst=false,$is_gmt=false) +function adodb_mktime($hr = null, $min = null, $sec = null, $mon = null, $day = null, $year = null,$is_dst=false,$is_gmt=false) { + if( !isset($hr) ) $hr = adodb_date('H'); + if( !isset($min) ) $min = adodb_date('i'); + if( !isset($sec) ) $sec = adodb_date('s'); + if( !isset($mon) ) $mon = adodb_date('m'); + if( !isset($day) ) $day = adodb_date('d'); + if( !isset($year) ) $year = adodb_date('Y'); + if (!defined('ADODB_TEST_DATES')) { + + if ($mon === false || !isset($mon) ) { + return $is_gmt? @gmmktime($hr,$min,$sec): @mktime($hr,$min,$sec); + } + // for windows, we don't check 1970 because with timezone differences, // 1 Jan 1970 could generate negative timestamp, which is illegal - if (!defined('ADODB_NO_NEGATIVE_TS') || ($year >= 1971)) - if (1901 < $year && $year < 2038) - return @mktime($hr,$min,$sec,$mon,$day,$year); + if (1971 < $year && $year < 2038 + || !defined('ADODB_NO_NEGATIVE_TS') && (1901 < $year && $year < 2038) + ) { + return $is_gmt ? + @gmmktime($hr,$min,$sec,$mon,$day,$year): + @mktime($hr,$min,$sec,$mon,$day,$year); + } } - $gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_different(); - + $gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff(); + + /* + # disabled because some people place large values in $sec. + # however we need it for $mon because we use an array... $hr = intval($hr); $min = intval($min); $sec = intval($sec); + */ $mon = intval($mon); $day = intval($day); $year = intval($year); $year = adodb_year_digit_check($year); - + if ($mon > 12) { $y = floor($mon / 12); $year += $y; $mon -= $y*12; + } else if ($mon < 1) { + $y = ceil((1-$mon) / 12); + $year -= $y; + $mon += $y*12; } $_day_power = 86400; @@ -867,4 +1187,108 @@ return $ret; } -?> +function adodb_gmstrftime($fmt, $ts=false) +{ + return adodb_strftime($fmt,$ts,true); +} + +// hack - convert to adodb_date +function adodb_strftime($fmt, $ts=false,$is_gmt=false) +{ +global $ADODB_DATE_LOCALE; + + if (!defined('ADODB_TEST_DATES')) { + if ((abs($ts) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range + if (!defined('ADODB_NO_NEGATIVE_TS') || $ts >= 0) // if windows, must be +ve integer + return ($is_gmt)? @gmstrftime($fmt,$ts): @strftime($fmt,$ts); + + } + } + + if (empty($ADODB_DATE_LOCALE)) { + $tstr = strtoupper(gmstrftime('%c',31366800)); // 30 Dec 1970, 1 am + $sep = substr($tstr,2,1); + $hasAM = strrpos($tstr,'M') !== false; + + $ADODB_DATE_LOCALE = array(); + $ADODB_DATE_LOCALE[] = strncmp($tstr,'30',2) == 0 ? 'd'.$sep.'m'.$sep.'y' : 'm'.$sep.'d'.$sep.'y'; + $ADODB_DATE_LOCALE[] = ($hasAM) ? 'h:i:s a' : 'H:i:s'; + + } + $inpct = false; + $fmtdate = ''; + for ($i=0,$max = strlen($fmt); $i < $max; $i++) { + $ch = $fmt[$i]; + if ($ch == '%') { + if ($inpct) { + $fmtdate .= '%'; + $inpct = false; + } else + $inpct = true; + } else if ($inpct) { + + $inpct = false; + switch($ch) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'E': + case 'O': + /* ignore format modifiers */ + $inpct = true; + break; + + case 'a': $fmtdate .= 'D'; break; + case 'A': $fmtdate .= 'l'; break; + case 'h': + case 'b': $fmtdate .= 'M'; break; + case 'B': $fmtdate .= 'F'; break; + case 'c': $fmtdate .= $ADODB_DATE_LOCALE[0].$ADODB_DATE_LOCALE[1]; break; + case 'C': $fmtdate .= '\C?'; break; // century + case 'd': $fmtdate .= 'd'; break; + case 'D': $fmtdate .= 'm/d/y'; break; + case 'e': $fmtdate .= 'j'; break; + case 'g': $fmtdate .= '\g?'; break; //? + case 'G': $fmtdate .= '\G?'; break; //? + case 'H': $fmtdate .= 'H'; break; + case 'I': $fmtdate .= 'h'; break; + case 'j': $fmtdate .= '?z'; $parsej = true; break; // wrong as j=1-based, z=0-basd + case 'm': $fmtdate .= 'm'; break; + case 'M': $fmtdate .= 'i'; break; + case 'n': $fmtdate .= "\n"; break; + case 'p': $fmtdate .= 'a'; break; + case 'r': $fmtdate .= 'h:i:s a'; break; + case 'R': $fmtdate .= 'H:i:s'; break; + case 'S': $fmtdate .= 's'; break; + case 't': $fmtdate .= "\t"; break; + case 'T': $fmtdate .= 'H:i:s'; break; + case 'u': $fmtdate .= '?u'; $parseu = true; break; // wrong strftime=1-based, date=0-basde + case 'U': $fmtdate .= '?U'; $parseU = true; break;// wrong strftime=1-based, date=0-based + case 'x': $fmtdate .= $ADODB_DATE_LOCALE[0]; break; + case 'X': $fmtdate .= $ADODB_DATE_LOCALE[1]; break; + case 'w': $fmtdate .= '?w'; $parseu = true; break; // wrong strftime=1-based, date=0-basde + case 'W': $fmtdate .= '?W'; $parseU = true; break;// wrong strftime=1-based, date=0-based + case 'y': $fmtdate .= 'y'; break; + case 'Y': $fmtdate .= 'Y'; break; + case 'Z': $fmtdate .= 'T'; break; + } + } else if (('A' <= ($ch) && ($ch) <= 'Z' ) || ('a' <= ($ch) && ($ch) <= 'z' )) + $fmtdate .= "\\".$ch; + else + $fmtdate .= $ch; + } + //echo "fmt=",$fmtdate,"
"; + if ($ts === false) $ts = time(); + $ret = adodb_date($fmtdate, $ts, $is_gmt); + return $ret; +} + + +?> \ No newline at end of file Index: trunk/kernel/units/users/users_event_handler.php =================================================================== diff -u -r3270 -r3282 --- trunk/kernel/units/users/users_event_handler.php (.../users_event_handler.php) (revision 3270) +++ trunk/kernel/units/users/users_event_handler.php (.../users_event_handler.php) (revision 3282) @@ -575,8 +575,8 @@ $MinPwResetDelay = $this->Application->ConfigValue('Users_AllowReset'); $allow_reset = (strlen($PwResetConfirm) ? - mktime() > $PwRequestTime + $MinPwResetDelay : - mktime() > $PassResetTime + $MinPwResetDelay); + adodb_mktime() > $PwRequestTime + $MinPwResetDelay : + adodb_mktime() > $PassResetTime + $MinPwResetDelay); } if($found && $allow_reset) @@ -676,15 +676,15 @@ $exp_time = $user_object->GetDBField('PwRequestTime') + 3600; $user_object->SetDBField("PwResetConfirm", ''); $user_object->SetDBField("PwRequestTime", 0); - if ($exp_time > mktime()) + if ( $exp_time > adodb_mktime() ) { //$m_var_list_update['codevalidationresult'] = 'lu_resetpw_confirm_text'; $newpw = makepassword4(); $this->Application->StoreVar('password', $newpw); $user_object->SetDBField("Password",$newpw); - $user_object->SetDBField("PassResetTime", time()); + $user_object->SetDBField("PassResetTime", adodb_mktime()); $user_object->SetDBField("PwResetConfirm", ''); $user_object->SetDBField("PwRequestTime", 0); $user_object->Update(); @@ -750,7 +750,7 @@ function OnCheckExpiredMembership(&$event) { $sql = 'SELECT PortalUserId FROM '.TABLE_PREFIX.'UserGroup - WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.mktime(); + WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.adodb_mktime(); $user_ids = $this->Conn->GetCol($sql); if(is_array($user_ids) && count($user_ids) > 0) { @@ -761,10 +761,10 @@ } } $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup - WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.mktime(); + WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.adodb_mktime(); $this->Conn->Query($sql); - $pre_expiration = mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24; + $pre_expiration = adodb_mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24; $sql = 'SELECT PortalUserId, GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.$pre_expiration.' AND ExpirationReminderSent = 0'; Index: trunk/core/kernel/db/dbitem.php =================================================================== diff -u -r3210 -r3282 --- trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 3210) +++ trunk/core/kernel/db/dbitem.php (.../dbitem.php) (revision 3282) @@ -652,19 +652,21 @@ $fields_sql .= sprintf('`%s`, ',$field_name); //Adding field name to fields block of Insert statement //Adding field' value to Values block of Insert statement, escaping it with ADODB' qstr - if (is_null( $this->FieldValues[$field_name] )) { - if (isset($this->Fields[$field_name]['not_null']) && $this->Fields[$field_name]['not_null']) { - $values_sql .= $this->Conn->qstr($this->Fields[$field_name]['default']).', '; - } - else { - $values_sql .= 'NULL, '; - } - } - else - { - $values_sql .= sprintf('%s, ',$this->Conn->qstr($this->FieldValues[$field_name], 0)); - } - + if (is_null( $this->FieldValues[$field_name] )) + { + if (isset($this->Fields[$field_name]['not_null']) && $this->Fields[$field_name]['not_null']) + { + $values_sql .= $this->Conn->qstr($this->Fields[$field_name]['default']).', '; + } + else + { + $values_sql .= 'NULL, '; + } + } + else + { + $values_sql .= sprintf('%s, ',$this->Conn->qstr($this->FieldValues[$field_name], 0)); + } } //Cutting last commas and spaces $fields_sql = ereg_replace(", $", '', $fields_sql); Index: trunk/core/kernel/parser/template_parser.php =================================================================== diff -u -r2905 -r3282 --- trunk/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 2905) +++ trunk/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 3282) @@ -432,7 +432,7 @@ if (defined('SAFE_MODE') && SAFE_MODE) { if (!isset($conn)) $conn =& $this->Application->GetADODBConnection(); - $conn->Query('REPLACE INTO '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ('.$conn->qstr($fname).','.$conn->qstr($this->CompiledBuffer).','.mktime().')'); + $conn->Query('REPLACE INTO '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ('.$conn->qstr($fname).','.$conn->qstr($this->CompiledBuffer).','.adodb_mktime().')'); } else { $compiled = fopen($fname, 'w'); Index: trunk/themes/default/blocks/common/redirect.tpl =================================================================== diff -u --- trunk/themes/default/blocks/common/redirect.tpl (revision 0) +++ trunk/themes/default/blocks/common/redirect.tpl (revision 3282) @@ -0,0 +1,39 @@ + + + + + +

+
+ + "> + + + + + + + + + + + + + + + + + + + + + + + + + +



 





+
+ " class="button"> +
+
\ No newline at end of file Index: trunk/core/units/phrases/phrases_event_handler.php =================================================================== diff -u -r3145 -r3282 --- trunk/core/units/phrases/phrases_event_handler.php (.../phrases_event_handler.php) (revision 3145) +++ trunk/core/units/phrases/phrases_event_handler.php (.../phrases_event_handler.php) (revision 3282) @@ -69,8 +69,8 @@ if( $prev_translation != $object->GetDBField('Translation') ) { $ip_address = getenv('HTTP_X_FORWARDED_FOR') ? getenv('HTTP_X_FORWARDED_FOR') : getenv('REMOTE_ADDR'); - $object->SetDBField('LastChanged_date', time() ); - $object->SetDBField('LastChanged_time', time() ); + $object->SetDBField('LastChanged_date', adodb_mktime() ); + $object->SetDBField('LastChanged_time', adodb_mktime() ); $object->SetDBField('LastChangeIP', $ip_address); } Index: trunk/admin/users/adduser.php =================================================================== diff -u -r2882 -r3282 --- trunk/admin/users/adduser.php (.../adduser.php) (revision 2882) +++ trunk/admin/users/adduser.php (.../adduser.php) (revision 3282) @@ -38,7 +38,7 @@ if ( GetVar('new') == 1) { $c = new clsPortalUser(NULL); - $c->Set("CreatedOn", time()); + $c->Set("CreatedOn", adodb_mktime()); $c->Set("Status", 2); $en = 0; $action = "m_add_user"; Index: trunk/kernel/include/adodb/adodb.inc.php =================================================================== diff -u -r3216 -r3282 --- trunk/kernel/include/adodb/adodb.inc.php (.../adodb.inc.php) (revision 3216) +++ trunk/kernel/include/adodb/adodb.inc.php (.../adodb.inc.php) (revision 3282) @@ -2083,7 +2083,7 @@ //============================================================================================== // DATE AND TIME FUNCTIONS //============================================================================================== - include_once(ADODB_DIR.'/adodb-time.inc.php'); + if( !function_exists('adodb_mktime') ) include_once(ADODB_DIR.'/adodb-time.inc.php'); //============================================================================================== // CLASS ADORecordSet Index: trunk/core/units/languages/languages_event_handler.php =================================================================== diff -u -r3211 -r3282 --- trunk/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 3211) +++ trunk/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 3282) @@ -107,7 +107,7 @@ $phrases_live = $this->Application->getUnitOption('phrases','TableName'); $phrases_temp = kTempTablesHandler::GetTempName($phrases_live); $sql = 'INSERT INTO '.$phrases_temp.' - SELECT Phrase, Translation, PhraseType, 0-PhraseId, '.$lang_id.', '.time().', "", Module + SELECT Phrase, Translation, PhraseType, 0-PhraseId, '.$lang_id.', '.adodb_mktime().', "", Module FROM '.$phrases_live.' WHERE LanguageId='.$from_lang_id; $this->Conn->Query($sql); Index: trunk/core/units/stylesheets/stylesheets_item.php =================================================================== diff -u -r2604 -r3282 --- trunk/core/units/stylesheets/stylesheets_item.php (.../stylesheets_item.php) (revision 2604) +++ trunk/core/units/stylesheets/stylesheets_item.php (.../stylesheets_item.php) (revision 3282) @@ -21,7 +21,7 @@ $ret .= $this->GetDBField('AdvancedCSS'); - $compile_ts = time(); + $compile_ts = adodb_mktime(); $css_path = FULL_PATH.'/kernel/stylesheets/'; $css_file = $css_path.strtolower($this->GetDBField('Name')).'-'.$compile_ts.'.css'; Index: trunk/kernel/units/users/users_tag_processor.php =================================================================== diff -u -r3088 -r3282 --- trunk/kernel/units/users/users_tag_processor.php (.../users_tag_processor.php) (revision 3088) +++ trunk/kernel/units/users/users_tag_processor.php (.../users_tag_processor.php) (revision 3282) @@ -44,7 +44,7 @@ - $sql = 'UPDATE '.TABLE_PREFIX.'PortalUser SET PwResetConfirm="'.$code.'", PwRequestTime='.mktime().' WHERE PortalUserId='.$tmp_user_id; + $sql = 'UPDATE '.TABLE_PREFIX.'PortalUser SET PwResetConfirm="'.$code.'", PwRequestTime='.adodb_mktime().' WHERE PortalUserId='.$tmp_user_id; $this->Conn->Query($sql); @@ -94,7 +94,7 @@ if($user_object->Load(array('PwResetConfirm'=>$passed_key))) { $exp_time = $user_object->GetDBField('PwRequestTime') + 3600; - if ($exp_time > mktime()) + if ($exp_time > adodb_mktime()) { Index: trunk/admin/install/restore_select.php =================================================================== diff -u -r542 -r3282 --- trunk/admin/install/restore_select.php (.../restore_select.php) (revision 542) +++ trunk/admin/install/restore_select.php (.../restore_select.php) (revision 3282) @@ -58,7 +58,7 @@ $sel = ($value == $_REQUEST['backupdate']) ? ' checked' : ''; $options .= ""; $options .= ""; - $options .= '"; + $options .= '"; $count++; if($count>10) break; Index: trunk/kernel/include/item.php =================================================================== diff -u -r3268 -r3282 --- trunk/kernel/include/item.php (.../item.php) (revision 3268) +++ trunk/kernel/include/item.php (.../item.php) (revision 3282) @@ -82,7 +82,7 @@ $ip = $_SERVER["REMOTE_ADDR"]; if(!$CreatedOn) - $CreatedOn = mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); + $CreatedOn = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); $Status = 1; if($isPending) $Status = 2; @@ -544,7 +544,7 @@ { global $objConfig; - $expired=time()-86400*$objConfig->Get("Timeout_Rating"); + $expired = adodb_mktime() - 86400 * $objConfig->Get("Timeout_Rating"); $query="DELETE FROM ".GetTablePrefix()."ItemRating WHERE CreatedOn<$expired"; $this->adodbConnection->Execute($query); } @@ -1111,8 +1111,8 @@ function StripDisallowed($string) { - $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', - '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', + $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`', + '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~', '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ','); $string = str_replace($not_allowed, '_', $string); @@ -1156,8 +1156,16 @@ function GenerateFilename() { - if ( !$this->Get('AutomaticFilename') && $this->Get('Filename') ) return false; - $name = $this->StripDisallowed( $this->Get($this->TitleField) ); + if ( !$this->Get('AutomaticFilename') && $this->Get('Filename') ) + { + $name = $this->Get('Filename'); + } + else + { + $name = $this->Get($this->TitleField); + } + $name = $this->StripDisallowed($name); + if ( $name != $this->Get('Filename') ) $this->Set('Filename', $name); } Index: trunk/admin/config/addlang.php =================================================================== diff -u -r2853 -r3282 --- trunk/admin/config/addlang.php (.../addlang.php) (revision 2853) +++ trunk/admin/config/addlang.php (.../addlang.php) (revision 3282) @@ -190,15 +190,15 @@ > "> - Get("DateFormat"))) echo prompt_language("la_Text_example").":".date($c->Get("DateFormat")); ?> + Get("DateFormat"))) echo prompt_language("la_Text_example").":".adodb_date($c->Get("DateFormat")); ?> > "> - Get("TimeFormat"))) echo prompt_language("la_Text_example").":".date($c->Get("TimeFormat")); ?> + Get("TimeFormat"))) echo prompt_language("la_Text_example").":".adodb_date($c->Get("TimeFormat")); ?> Index: trunk/admin/install/upgrades/inportal_check_v1.1.4.php =================================================================== diff -u -r3077 -r3282 --- trunk/admin/install/upgrades/inportal_check_v1.1.4.php (.../inportal_check_v1.1.4.php) (revision 3077) +++ trunk/admin/install/upgrades/inportal_check_v1.1.4.php (.../inportal_check_v1.1.4.php) (revision 3282) @@ -83,7 +83,7 @@ $cat=$objCatList->GetItemByField('Name','Lost & Found'); if( !is_object($cat) ) { - $cat=&$objCatList->Add(0,'Lost & Found','Lost & Found Items',time(),0,0,2,2,2,0,'',''); + $cat=&$objCatList->Add(0,'Lost & Found','Lost & Found Items',adodb_mktime(),0,0,2,2,2,0,'',''); } $cat_id=$cat->UniqueId(); Index: trunk/core/units/visits/visits_event_handler.php =================================================================== diff -u -r2741 -r3282 --- trunk/core/units/visits/visits_event_handler.php (.../visits_event_handler.php) (revision 2741) +++ trunk/core/units/visits/visits_event_handler.php (.../visits_event_handler.php) (revision 3282) @@ -10,8 +10,8 @@ function OnRegisterVisit(&$event) { $object =& $event->getObject( Array('skip_autoload'=>true) ); - $object->SetDBField('VisitDate_date', time() ); - $object->SetDBField('VisitDate_time', time() ); + $object->SetDBField('VisitDate_date', adodb_mktime() ); + $object->SetDBField('VisitDate_time', adodb_mktime() ); $object->SetDBField('Referer', getArrayValue($_SERVER, 'HTTP_REFERER') ); $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR'] ); if( $object->Create() ) Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -r3163 -r3282 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 3163) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 3282) @@ -292,7 +292,7 @@ LIMIT '.$last_hot.', 1'; $res = $this->Conn->GetCol($sql); $hot_limit = (double)array_shift($res); - $this->Conn->Query('REPLACE INTO '.TABLE_PREFIX.'Cache VALUES ("'.$hot_limit_var.'", "'.$hot_limit.'", '.mktime().')'); + $this->Conn->Query('REPLACE INTO '.TABLE_PREFIX.'Cache VALUES ("'.$hot_limit_var.'", "'.$hot_limit.'", '.adodb_mktime().')'); return $hot_limit; } return 0; @@ -832,7 +832,7 @@ if( in_array($keywords[$field], Array('today', 'yesterday')) ) { $current_time = getdate(); - $day_begin = mktime(0, 0, 0, $current_time['mon'], $current_time['mday'], $current_time['year']); + $day_begin = adodb_mktime(0, 0, 0, $current_time['mon'], $current_time['mday'], $current_time['year']); $time_mapping = Array('today' => $day_begin, 'yesterday' => ($day_begin - 86400)); $min_time = $time_mapping[$keywords[$field]]; } @@ -842,7 +842,7 @@ 'last_3_months' => 7884000, 'last_6_months' => 15768000, 'last_year' => 31536000 ); - $min_time = mktime() - $time_mapping[$keywords[$field]]; + $min_time = adodb_mktime() - $time_mapping[$keywords[$field]]; } $condition = $field_name.' > '.$min_time; } Index: trunk/globals.php =================================================================== diff -u -r3216 -r3282 --- trunk/globals.php (.../globals.php) (revision 3216) +++ trunk/globals.php (.../globals.php) (revision 3282) @@ -1963,7 +1963,7 @@ if(!$condition) return false; global $objSession, $adminURL; - if( !headers_sent() ) set_cookie(SESSION_COOKIE_NAME, ' ', time() - 3600); + if( !headers_sent() ) set_cookie(SESSION_COOKIE_NAME, ' ', adodb_mktime() - 3600); $objSession->Logout(); if($pass_env) $redirect_params = 'env='.BuildEnv().'&'.$redirect_params; header('Location: '.$adminURL.'/index.php?'.$redirect_params); Index: trunk/kernel/units/users/users_config.php =================================================================== diff -u -r2820 -r3282 --- trunk/kernel/units/users/users_config.php (.../users_config.php) (revision 2820) +++ trunk/kernel/units/users/users_config.php (.../users_config.php) (revision 3282) @@ -65,7 +65,7 @@ 'FirstName' => Array('type' => 'string','default' => ''), 'LastName' => Array('type' => 'string','default' => ''), 'Email' => Array('type' => 'string', 'formatter'=>'kFormatter', 'regexp'=>'/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/', 'unique'=>Array('Email'), 'not_null' => '1', 'required'=>1, 'default' => '', 'error_msgs' => Array('invalid_format'=>'!la_invalid_email!', 'unique'=>'!lu_email_already_exist!') ), - 'CreatedOn' => Array('type'=>'int', 'formatter' => 'kDateFormatter', 'default'=>time(), 'not_null' => '1' ), + 'CreatedOn' => Array('type'=>'int', 'formatter' => 'kDateFormatter', 'default' => '#NOW#', 'not_null' => '1' ), 'Phone' => Array('type' => 'string','default' => ''), 'Street' => Array('type' => 'string','default' => ''), 'City' => Array('type' => 'string','default' => ''), @@ -88,7 +88,7 @@ 'not_null' => '1','default' => ''), 'ResourceId' => Array('type' => 'int','not_null' => '1','default' => '0'), 'Status' => Array('type' => 'int', 'formatter'=>'kOptionsFormatter', 'options'=>Array(1=>'la_Enabled', 0=>'la_Disabled', 2=>'la_Pending'), 'use_phrases'=>1, 'not_null' => '1','default' => 2), - 'Modified' => Array('type' => 'int', 'formatter'=>'kDateFormatter', 'not_null' => '1', 'default' => time() ), + 'Modified' => Array('type' => 'int', 'formatter'=>'kDateFormatter', 'not_null' => '1', 'default' => '#NOW#' ), 'dob' => Array('type'=>'int', 'formatter' => 'kDateFormatter', 'not_null' => '1', 'default' => '', 'required'=>1), 'tz' => Array('type' => 'int','default' => ''), 'ip' => Array('type' => 'string','default' => ''), Index: trunk/core/units/categories/categories_item.php =================================================================== diff -u -r2591 -r3282 --- trunk/core/units/categories/categories_item.php (.../categories_item.php) (revision 2591) +++ trunk/core/units/categories/categories_item.php (.../categories_item.php) (revision 3282) @@ -8,8 +8,8 @@ $this->SetDBField('ResourceId', $this->Application->NextResourceId()); $this->SetDBField('CreatedById', $this->Application->GetVar('u_id') ); - $this->SetDBField('CreatedOn_date', time() ); - $this->SetDBField('CreatedOn_time', time() ); + $this->SetDBField('CreatedOn_date', adodb_mktime() ); + $this->SetDBField('CreatedOn_time', adodb_mktime() ); $this->SetDBField('ParentId', $this->Application->GetVar('m_cat_id') ); $ret = parent::Create(); Index: trunk/core/kernel/db/db_event_handler.php =================================================================== diff -u -r3103 -r3282 --- trunk/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 3103) +++ trunk/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 3282) @@ -1231,8 +1231,8 @@ $dt_separator = getArrayValue( $object->GetFieldOptions($field_name), 'date_time_separator' ); if(!$dt_separator) $dt_separator = ' '; - $time = ($type == 'datefrom') ? mktime(0,0,0) : mktime(23,59,59); - $time = date( $lang_current->GetDBField('TimeFormat'), $time); + $time = ($type == 'datefrom') ? adodb_mktime(0,0,0) : adodb_mktime(23,59,59); + $time = adodb_date( $lang_current->GetDBField('TimeFormat'), $time); $full_value = $value.$dt_separator.$time; $formatter =& $this->Application->recallObject($formatter_class); Index: trunk/kernel/include/dates.php =================================================================== diff -u -r484 -r3282 --- trunk/kernel/include/dates.php (.../dates.php) (revision 484) +++ trunk/kernel/include/dates.php (.../dates.php) (revision 3282) @@ -105,7 +105,7 @@ if(strlen($date)) { $d = GetDateArray($date,$SourceFormat); - $ticks = adodb_mktime(date("H"),date("i"), date("s"),$d["month"],$d["day"],$d["year"]); + $ticks = adodb_mktime(adodb_date("H"), adodb_date("i"), adodb_date("s"), $d["month"], $d["day"], $d["year"]); } else $ticks = 0; Index: trunk/kernel/frontaction.php =================================================================== diff -u -r3201 -r3282 --- trunk/kernel/frontaction.php (.../frontaction.php) (revision 3201) +++ trunk/kernel/frontaction.php (.../frontaction.php) (revision 3282) @@ -37,7 +37,7 @@ $pw = $_POST["login_password"]; if(strlen($pw) < 31) $pw = md5($pw); $c .= $pw; - set_cookie('login', $c, time() + 2592000); + set_cookie('login', $c, adodb_mktime() + 2592000); } // set new destination template if passed @@ -96,13 +96,13 @@ $exp_time = $u->Get('PwRequestTime') + 3600; $u->Set("PwResetConfirm", ''); $u->Set("PwRequestTime", 0); - if ($exp_time > mktime()) + if ($exp_time > adodb_mktime()) { $m_var_list_update['codevalidationresult'] = 'lu_resetpw_confirm_text'; $newpw = makepassword(); SetVar('user_password', $newpw); $u->Set("Password",$newpw); - $u->Set("PassResetTime", time()); + $u->Set("PassResetTime", adodb_mktime()); $u->Set("PwResetConfirm", ''); $u->Set("PwRequestTime", 0); $u->Update(); @@ -149,8 +149,8 @@ $PassResetTime = $u->Get('PassResetTime'); $MinPwResetDelay = $u->Get('MinPwResetDelay'); $allow_reset = (strlen($PwResetConfirm) ? - mktime() > $PwRequestTime + $MinPwResetDelay : - mktime() > $PassResetTime + $MinPwResetDelay); + adodb_mktime() > $PwRequestTime + $MinPwResetDelay : + adodb_mktime() > $PassResetTime + $MinPwResetDelay); } if($found && $allow_reset) @@ -304,7 +304,7 @@ $u = new clsPortalUser(NULL); $u->Set("Email",$SubscribeAddress); $u->Set("ip",$_SERVER['REMOTE_ADDR']); - $u->Set("CreatedOn",date("U")); + $u->Set("CreatedOn",adodb_date("U")); $u->Set("Status",1); if(!$u->CheckBanned()) { @@ -740,7 +740,7 @@ } if($MissingCount==0) { - $CreatedOn = date("U"); + $CreatedOn = adodb_date("U"); $_POST=inp_striptags($_POST); $name = $_POST["name"]; $desc = $_POST["description"]; @@ -830,7 +830,7 @@ DeleteModuleTagCache('kernel'); break; case "m_suggest_email": - $cutoff = time()+(int)$objConfig->Get("Suggest_MinInterval"); + $cutoff = adodb_mktime()+(int)$objConfig->Get("Suggest_MinInterval"); $email = inp_striptags($_POST["suggest_email"]); if (strlen($email)) @@ -859,7 +859,7 @@ $Event->Item = null; $Event->SendToAddress($email); - $sql = "INSERT INTO ".GetTablePrefix()."SuggestMail (email,sent) VALUES ('".$email."','".time()."')"; + $sql = "INSERT INTO ".GetTablePrefix()."SuggestMail (email,sent) VALUES ('".$email."','".adodb_mktime()."')"; $rs = $adodbConnection->Execute($sql); $suggest_result=language("lu_suggest_success")." ".$email; Index: trunk/kernel/include/modules.php =================================================================== diff -u -r3200 -r3282 --- trunk/kernel/include/modules.php (.../modules.php) (revision 3200) +++ trunk/kernel/include/modules.php (.../modules.php) (revision 3282) @@ -7,7 +7,7 @@ $session_cookie_name = $ado->GetOne('SELECT VariableValue FROM '.$g_TablePrefix.'ConfigurationValues WHERE VariableName = "SessionCookieName"'); define('SESSION_COOKIE_NAME', $session_cookie_name); -set_cookie('cookies_on', '1', time() + 31104000); +set_cookie('cookies_on', '1', adodb_mktime() + 31104000); // if branches that uses if($mod_prefix) or like that will never be executed // due global variable $mod_prefix is never defined @@ -861,8 +861,8 @@ $var_list_update['t'] = 'index'; $var_list['t'] = ''; $var_list['sid'] = ''; - set_cookie('login', '', time() - 3600); - set_cookie(SESSION_COOKIE_NAME, '', time() - 3600); + set_cookie('login', '', adodb_mktime() - 3600); + set_cookie(SESSION_COOKIE_NAME, '', adodb_mktime() - 3600); } $CookieTest = isset($_COOKIE['cookies_on']) ? $_COOKIE['cookies_on'] : ''; Index: trunk/admin/category/addcategory.php =================================================================== diff -u -r3179 -r3282 --- trunk/admin/category/addcategory.php (.../addcategory.php) (revision 3179) +++ trunk/admin/category/addcategory.php (.../addcategory.php) (revision 3282) @@ -32,8 +32,8 @@ if ($_GET["new"] == 1) { $c = new clsCategory(NULL); - $c->Set("CreatedOn", time()); - $c->Set("EndOn", time()); + $c->Set("CreatedOn", adodb_mktime()); + $c->Set("EndOn", adodb_mktime()); $c->Set("ParentId",$objCatList->CurrentCategoryID()); $c->Set("NewItem",2); //auto $c->Set("Status",2); //pending @@ -235,7 +235,7 @@ - DBG: '.date('M d. Y H:i:s', $c->get('Modified') ); ?> + DBG: '.adodb_date('M d. Y H:i:s', $c->get('Modified') ); ?> Index: trunk/kernel/include/error.php =================================================================== diff -u -r2882 -r3282 --- trunk/kernel/include/error.php (.../error.php) (revision 2882) +++ trunk/kernel/include/error.php (.../error.php) (revision 3282) @@ -113,7 +113,7 @@ $fp = fopen($g_ErrorLog,"a"); if($fp) { - $datestamp = date("Y-m-d H:i:s"); + $datestamp = adodb_date("Y-m-d H:i:s"); fputs($fp,$datestamp."\t",$errorMessage." ".$errorField); fclose($fp); } Index: trunk/core/kernel/session/session.php =================================================================== diff -u -r3156 -r3282 --- trunk/core/kernel/session/session.php (.../session.php) (revision 3156) +++ trunk/core/kernel/session/session.php (.../session.php) (revision 3282) @@ -188,7 +188,7 @@ function GetExpiredSIDs() { - $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.$this->TimestampField.' > '.time(); + $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.$this->TimestampField.' > '.adodb_mktime(); return $this->Conn->GetCol($query); } @@ -392,7 +392,7 @@ setcookie( 'cookies_on', 1, - time()+31104000, //one year should be enough + adodb_mktime()+31104000, //one year should be enough $this->CookiePath, $this->CookieDomain, $this->CookieSecure @@ -432,7 +432,7 @@ $this->Expiration = $this->Storage->GetExpiration(); //If session has expired - if ($this->Expiration < time()) return false; + if ($this->Expiration < adodb_mktime()) return false; //Otherwise it's ok return true; @@ -534,7 +534,7 @@ function SetSession() { $this->GenerateSID(); - $this->Expiration = time() + $this->SessionTimeout; + $this->Expiration = adodb_mktime() + $this->SessionTimeout; switch ($this->Mode) { case smAUTO: if ($this->CookiesEnabled) { Index: trunk/admin/users/adduser_images.php =================================================================== diff -u -r2853 -r3282 --- trunk/admin/users/adduser_images.php (.../adduser_images.php) (revision 2853) +++ trunk/admin/users/adduser_images.php (.../adduser_images.php) (revision 3282) @@ -172,7 +172,7 @@ $sql .="concat(img.Name,ELT(img.DefaultImg+1,'','
(".admin_language("la_prompt_Primary").") ')) as FullName, "; $sql .="if(img.LocalImage=1 OR (img.SameImages=1 AND img.LocalThumb=1),'(".admin_language("la_Text_Local").") ',img.Url) as ShowURL, concat( '') AS Preview "; +$sql .="THEN concat('".$rootURL."',img.ThumbPath,'?".adodb_mktime()."') END , CASE WHEN (img.LocalImage=1) THEN concat('".$rootURL."',img.LocalPath,'?".adodb_mktime()."') ELSE img.ThumbUrl END), '\">') AS Preview "; $sql .="FROM ".$objImageList->SourceTable." as img WHERE img.ResourceId=".$c->Get("ResourceId"); Index: trunk/kernel/include/parseditem.php =================================================================== diff -u -r3155 -r3282 --- trunk/kernel/include/parseditem.php (.../parseditem.php) (revision 3155) +++ trunk/kernel/include/parseditem.php (.../parseditem.php) (revision 3282) @@ -2072,7 +2072,7 @@ if($attribs["_today"]) { - $today = mktime(0,0,0,date("m"),date("d"),date("Y")); + $today = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); $sql .= "AND ($t.CreatedOn>=$today) "; } //echo $sql."

\n"; @@ -2091,7 +2091,7 @@ $t = $this->SourceTable; if( getArrayValue($attribs,'_today') ) { - $today = mktime(0,0,0,date("m"),date("d"),date("Y")); + $today = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); $where = "($t.CreatedOn>=$today)"; } @@ -2285,7 +2285,7 @@ $cattable = GetTablePrefix()."CategoryItems"; $CategoryTable = GetTablePrefix()."Category"; $ptable = GetTablePrefix()."PermCache"; - $today = mktime(0,0,0,date("m"),date("d"),date("Y")); + $today = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); $where = "PortalUserId=".$objSession->Get("PortalUserId")." AND $ltable.Status=1"; $where .= " AND $favtable.Modified >= $today AND ItemTypeId=".$this->ItemType; @@ -2410,7 +2410,7 @@ $where = "PortalUserId=".$objSession->Get("PortalUserId")." AND $ltable.Status=1"; if($attribs["_today"]) { - $today = mktime(0,0,0,date("m"),date("d"),date("Y")); + $today = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); $where .= " AND $favtable.Modified >= $today AND ItemTypeId=".$this->ItemType; } $p = $this->BasePermission.".VIEW"; @@ -2480,7 +2480,7 @@ } if(getArrayValue($attribs,'_today')) { - $today = mktime(0,0,0,date("m"),date("d"),date("Y")); + $today = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); $where .= " AND ($TableName.CreatedOn>=$today)"; } $CategoryTable = GetTablePrefix()."Category"; @@ -2536,7 +2536,7 @@ $where = " ".$TableName.".Status>-1 AND ".$TableName.".CreatedById=".$objSession->Get("PortalUserId"); if(getArrayValue($attribs,'_today')) { - $today = mktime(0,0,0,date("m"),date("d"),date("Y")); + $today = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); $where .= " AND ($TableName.CreatedOn>=$today)"; } $CategoryTable = GetTablePrefix()."Category"; @@ -2592,7 +2592,7 @@ $TableName = $this->SourceTable; if(getArrayValue($attribs,'_today')) { - $cutoff = mktime(0,0,0,date("m"),date("d"),date("Y")); + $cutoff = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); } else { @@ -2701,7 +2701,7 @@ } if($attribs["_today"]) { - $today = mktime(0,0,0,date("m"),date("d"),date("Y")); + $today = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); $where .= " AND ($TableName.CreatedOn>=$today)"; } $CategoryTable = GetTablePrefix()."Category"; @@ -2774,7 +2774,7 @@ if($attribs["_today"]) { - $today = mktime(0,0,0,date("m"),date("d"),date("Y")); + $today = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); $where .= " AND ($TableName.CreatedOn>=$today)"; } $CategoryTable = GetTablePrefix()."Category"; Index: trunk/core/units/users/users_event_handler.php =================================================================== diff -u -r3270 -r3282 --- trunk/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 3270) +++ trunk/core/units/users/users_event_handler.php (.../users_event_handler.php) (revision 3282) @@ -575,8 +575,8 @@ $MinPwResetDelay = $this->Application->ConfigValue('Users_AllowReset'); $allow_reset = (strlen($PwResetConfirm) ? - mktime() > $PwRequestTime + $MinPwResetDelay : - mktime() > $PassResetTime + $MinPwResetDelay); + adodb_mktime() > $PwRequestTime + $MinPwResetDelay : + adodb_mktime() > $PassResetTime + $MinPwResetDelay); } if($found && $allow_reset) @@ -676,15 +676,15 @@ $exp_time = $user_object->GetDBField('PwRequestTime') + 3600; $user_object->SetDBField("PwResetConfirm", ''); $user_object->SetDBField("PwRequestTime", 0); - if ($exp_time > mktime()) + if ( $exp_time > adodb_mktime() ) { //$m_var_list_update['codevalidationresult'] = 'lu_resetpw_confirm_text'; $newpw = makepassword4(); $this->Application->StoreVar('password', $newpw); $user_object->SetDBField("Password",$newpw); - $user_object->SetDBField("PassResetTime", time()); + $user_object->SetDBField("PassResetTime", adodb_mktime()); $user_object->SetDBField("PwResetConfirm", ''); $user_object->SetDBField("PwRequestTime", 0); $user_object->Update(); @@ -750,7 +750,7 @@ function OnCheckExpiredMembership(&$event) { $sql = 'SELECT PortalUserId FROM '.TABLE_PREFIX.'UserGroup - WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.mktime(); + WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.adodb_mktime(); $user_ids = $this->Conn->GetCol($sql); if(is_array($user_ids) && count($user_ids) > 0) { @@ -761,10 +761,10 @@ } } $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup - WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.mktime(); + WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.adodb_mktime(); $this->Conn->Query($sql); - $pre_expiration = mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24; + $pre_expiration = adodb_mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24; $sql = 'SELECT PortalUserId, GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE MembershipExpires IS NOT NULL AND MembershipExpires < '.$pre_expiration.' AND ExpirationReminderSent = 0'; Index: trunk/kernel/include/itemreview.php =================================================================== diff -u -r3124 -r3282 --- trunk/kernel/include/itemreview.php (.../itemreview.php) (revision 3124) +++ trunk/kernel/include/itemreview.php (.../itemreview.php) (revision 3282) @@ -456,7 +456,7 @@ $sql = 'SELECT COUNT(*) FROM '.$this->SourceTable.' WHERE ItemId = '.$this->itemID.' AND Status = 1'; if($TodayOnly) { - $today = mktime(0,0,0,date('m'),date('d'),date('Y')); + $today = adodb_mktime(0,0,0,adodb_date('m'),adodb_date('d'),adodb_date('Y')); $sql .= ' AND CreatedOn >= '.$today; } return (int)$this->adodbConnection->GetOne($sql); Index: trunk/core/units/users/users_tag_processor.php =================================================================== diff -u -r3088 -r3282 --- trunk/core/units/users/users_tag_processor.php (.../users_tag_processor.php) (revision 3088) +++ trunk/core/units/users/users_tag_processor.php (.../users_tag_processor.php) (revision 3282) @@ -44,7 +44,7 @@ - $sql = 'UPDATE '.TABLE_PREFIX.'PortalUser SET PwResetConfirm="'.$code.'", PwRequestTime='.mktime().' WHERE PortalUserId='.$tmp_user_id; + $sql = 'UPDATE '.TABLE_PREFIX.'PortalUser SET PwResetConfirm="'.$code.'", PwRequestTime='.adodb_mktime().' WHERE PortalUserId='.$tmp_user_id; $this->Conn->Query($sql); @@ -94,7 +94,7 @@ if($user_object->Load(array('PwResetConfirm'=>$passed_key))) { $exp_time = $user_object->GetDBField('PwRequestTime') + 3600; - if ($exp_time > mktime()) + if ($exp_time > adodb_mktime()) { Index: trunk/admin/category/addcategory_images.php =================================================================== diff -u -r2853 -r3282 --- trunk/admin/category/addcategory_images.php (.../addcategory_images.php) (revision 2853) +++ trunk/admin/category/addcategory_images.php (.../addcategory_images.php) (revision 3282) @@ -170,7 +170,7 @@ $sql .="concat(img.Name,ELT(img.DefaultImg+1,'','
(".admin_language("la_prompt_Primary").") ')) as FullName, "; $sql .="if(img.LocalImage=1,'(".admin_language("la_Text_Local").") ',img.Url) as ShowURL, concat( '') AS Preview "; +$sql .="THEN concat('".$rootURL."',img.ThumbPath,'?".adodb_mktime()."') END , img.ThumbUrl), '\">') AS Preview "; $sql .="FROM ".$objImageList->SourceTable." as img WHERE img.ResourceId=".$c->Get("ResourceId"); Index: trunk/admin/backup/backup1.php =================================================================== diff -u -r2853 -r3282 --- trunk/admin/backup/backup1.php (.../backup1.php) (revision 2853) +++ trunk/admin/backup/backup1.php (.../backup1.php) (revision 3282) @@ -34,7 +34,7 @@ $objSession->SetVariable("backup_start",0); $objSession->SetVariable("backup_tnumber","start"); -$date=time(); +$date = adodb_mktime(); $filepath=$objConfig->Get("Backup_Path"); $filename="dump".$date.".txt"; Index: trunk/kernel/include/advsearch.php =================================================================== diff -u -r1566 -r3282 --- trunk/kernel/include/advsearch.php (.../advsearch.php) (revision 1566) +++ trunk/kernel/include/advsearch.php (.../advsearch.php) (revision 3282) @@ -173,7 +173,7 @@ $Value == 1 ? $not = '' : $not = 'NOT '; $where_clause = $FieldConfig->GetWhereClause($Verb, $Value); $where_clause .= ' OR ('.AddTablePrefix($TableName).'.NewItem=2 AND '. - $not.'('.mktime().'-'.AddTablePrefix($TableName). + $not.'('.adodb_mktime().'-'.AddTablePrefix($TableName). '.CreatedOn<'.$NewTime.'))'; break; default: Index: trunk/admin/install/upgrades/inportal_check_v1.0.10.php =================================================================== diff -u -r1393 -r3282 --- trunk/admin/install/upgrades/inportal_check_v1.0.10.php (.../inportal_check_v1.0.10.php) (revision 1393) +++ trunk/admin/install/upgrades/inportal_check_v1.0.10.php (.../inportal_check_v1.0.10.php) (revision 3282) @@ -83,7 +83,7 @@ $cat=$objCatList->GetItemByField('Name','Lost & Found'); if( !is_object($cat) ) { - $cat=&$objCatList->Add(0,'Lost & Found','Lost & Found Items',time(),0,0,2,2,2,0,'',''); + $cat=&$objCatList->Add(0,'Lost & Found','Lost & Found Items',adodb_mktime(),0,0,2,2,2,0,'',''); } $cat_id=$cat->UniqueId(); Index: trunk/core/units/users/users_config.php =================================================================== diff -u -r2820 -r3282 --- trunk/core/units/users/users_config.php (.../users_config.php) (revision 2820) +++ trunk/core/units/users/users_config.php (.../users_config.php) (revision 3282) @@ -65,7 +65,7 @@ 'FirstName' => Array('type' => 'string','default' => ''), 'LastName' => Array('type' => 'string','default' => ''), 'Email' => Array('type' => 'string', 'formatter'=>'kFormatter', 'regexp'=>'/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/', 'unique'=>Array('Email'), 'not_null' => '1', 'required'=>1, 'default' => '', 'error_msgs' => Array('invalid_format'=>'!la_invalid_email!', 'unique'=>'!lu_email_already_exist!') ), - 'CreatedOn' => Array('type'=>'int', 'formatter' => 'kDateFormatter', 'default'=>time(), 'not_null' => '1' ), + 'CreatedOn' => Array('type'=>'int', 'formatter' => 'kDateFormatter', 'default' => '#NOW#', 'not_null' => '1' ), 'Phone' => Array('type' => 'string','default' => ''), 'Street' => Array('type' => 'string','default' => ''), 'City' => Array('type' => 'string','default' => ''), @@ -88,7 +88,7 @@ 'not_null' => '1','default' => ''), 'ResourceId' => Array('type' => 'int','not_null' => '1','default' => '0'), 'Status' => Array('type' => 'int', 'formatter'=>'kOptionsFormatter', 'options'=>Array(1=>'la_Enabled', 0=>'la_Disabled', 2=>'la_Pending'), 'use_phrases'=>1, 'not_null' => '1','default' => 2), - 'Modified' => Array('type' => 'int', 'formatter'=>'kDateFormatter', 'not_null' => '1', 'default' => time() ), + 'Modified' => Array('type' => 'int', 'formatter'=>'kDateFormatter', 'not_null' => '1', 'default' => '#NOW#' ), 'dob' => Array('type'=>'int', 'formatter' => 'kDateFormatter', 'not_null' => '1', 'default' => '', 'required'=>1), 'tz' => Array('type' => 'int','default' => ''), 'ip' => Array('type' => 'string','default' => ''), Index: trunk/kernel/include/portaluser.php =================================================================== diff -u -r3124 -r3282 --- trunk/kernel/include/portaluser.php (.../portaluser.php) (revision 3124) +++ trunk/kernel/include/portaluser.php (.../portaluser.php) (revision 3282) @@ -119,7 +119,7 @@ global $objGroups; $Description = $this->Get("FirstName")." ".$this->Get("LastName"); - $CreatedOn=time(); + $CreatedOn = adodb_mktime(); $n = "_".$this->Get("Login"); $g = $objGroups->Add_Group($n, $Description, $CreatedOn, 1, 0); $g->Set("Personal",1); Index: trunk/admin/install/upgrades/inportal_check_v1.0.12.php =================================================================== diff -u -r1444 -r3282 --- trunk/admin/install/upgrades/inportal_check_v1.0.12.php (.../inportal_check_v1.0.12.php) (revision 1444) +++ trunk/admin/install/upgrades/inportal_check_v1.0.12.php (.../inportal_check_v1.0.12.php) (revision 3282) @@ -83,7 +83,7 @@ $cat=$objCatList->GetItemByField('Name','Lost & Found'); if( !is_object($cat) ) { - $cat=&$objCatList->Add(0,'Lost & Found','Lost & Found Items',time(),0,0,2,2,2,0,'',''); + $cat=&$objCatList->Add(0,'Lost & Found','Lost & Found Items',adodb_mktime(),0,0,2,2,2,0,'',''); } $cat_id=$cat->UniqueId(); Index: trunk/kernel/units/general/cat_dbitem.php =================================================================== diff -u -r3268 -r3282 --- trunk/kernel/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 3268) +++ trunk/kernel/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 3282) @@ -19,7 +19,7 @@ $this->checkFilename(); $this->SetDBField('ResourceId', $this->Application->NextResourceId()); - $this->SetDBField('Modified', mktime()); + $this->SetDBField('Modified', adodb_mktime() ); $this->SetDBField('CreatedById', $this->Application->GetVar('u_id')); $this->generateFilename(); @@ -44,7 +44,7 @@ { $this->checkFilename(); $this->VirtualFields['ResourceId'] = true; - $this->SetDBField('Modified', mktime()); + $this->SetDBField('Modified', adodb_mktime() ); $this->SetDBField('ModifiedById', $this->Application->GetVar('u_id')); $this->generateFilename(); @@ -201,8 +201,8 @@ */ function stripDisallowed($string) { - $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', - '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', + $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`', + '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~', '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ','); $string = str_replace($not_allowed, '_', $string); Index: trunk/kernel/units/general/inp_ses_storage.php =================================================================== diff -u -r3031 -r3282 --- trunk/kernel/units/general/inp_ses_storage.php (.../inp_ses_storage.php) (revision 3031) +++ trunk/kernel/units/general/inp_ses_storage.php (.../inp_ses_storage.php) (revision 3282) @@ -76,7 +76,7 @@ function GetExpiredSIDs() { - $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.time().' - '.$this->TimestampField.' > '.$this->SessionTimeout; + $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.adodb_mktime().' - '.$this->TimestampField.' > '.$this->SessionTimeout; $ret = $this->Conn->GetCol($query); if($ret) $this->DeleteEditTables(); return $ret; Index: trunk/kernel/units/languages/import_xml.php =================================================================== diff -u -r3145 -r3282 --- trunk/kernel/units/languages/import_xml.php (.../import_xml.php) (revision 3145) +++ trunk/kernel/units/languages/import_xml.php (.../import_xml.php) (revision 3282) @@ -193,7 +193,7 @@ 'Phrase' => $attributes['LABEL'], 'PhraseType' => $attributes['TYPE'], 'Module' => $phrase_module, - 'LastChanged' => time(), + 'LastChanged' => adodb_mktime(), 'LastChangeIP' => $this->ip_address, 'Translation' => ''); break; Index: trunk/kernel/include/parse.php =================================================================== diff -u -r3201 -r3282 --- trunk/kernel/include/parse.php (.../parse.php) (revision 3201) +++ trunk/kernel/include/parse.php (.../parse.php) (revision 3282) @@ -501,8 +501,8 @@ $exp = isset($CurrentTheme->ParseCacheDate[$id]) ? $CurrentTheme->ParseCacheDate[$id] : false; if($exp) { - //echo "$template Cache expires: ".date("m-d-Y h:m s",$exp)."
\n"; - if( $exp > time() ) + //echo "$template Cache expires: ".adodb_date("m-d-Y h:m s",$exp)."
\n"; + if( $exp > adodb_mktime() ) { /* look for a cache file */ $t = new clsTemplate($template); @@ -531,7 +531,7 @@ { //echo "Writing Template ".$objTemplate->name."
\n"; $interval = $CurrentTheme->ParseCacheTimeout[$TemplateId]; - $CurrentTheme->UpdateFileCacheData($TemplateId,time()+$interval); + $CurrentTheme->UpdateFileCacheData($TemplateId,adodb_mktime()+$interval); $dir = $CurrentTheme->ThemeDirectory()."/_cache/"; $objTemplate->WriteFile($dir); } Index: trunk/kernel/include/cachecount.php =================================================================== diff -u -r1248 -r3282 --- trunk/kernel/include/cachecount.php (.../cachecount.php) (revision 1248) +++ trunk/kernel/include/cachecount.php (.../cachecount.php) (revision 3282) @@ -135,7 +135,7 @@ if(is_object($i)) { $d = $i->Get("LastUpdate"); - $el = date("U") - $d; + $el = adodb_date("U") - $d; if($el > $Timeout) { $val = ""; @@ -157,7 +157,7 @@ if($rs && !$rs->EOF) { $d = $rs->fields["LastUpdate"]; - $el = $date("U") - $d; + $el = adodb_date("U") - $d; if($el < $Timeout) { $val = (int)$rs->fields["Value"]; @@ -178,7 +178,7 @@ if(is_object($c)) { $c->Set("Value",$Value); - $c->Set("LastUpdate",Date("U")); + $c->Set("LastUpdate",adodb_date("U")); $c->Update(); } else @@ -189,7 +189,7 @@ $c->Set("ExtraId",$ExtraId); $c->Set("Value",$Value); $c->Set("TodayOnly",$Today); - $c->Set("LastUpdate",Date("U")); + $c->Set("LastUpdate",adodb_date("U")); $c->Create(); } } Index: trunk/core/kernel/event_manager.php =================================================================== diff -u -r2600 -r3282 --- trunk/core/kernel/event_manager.php (.../event_manager.php) (revision 2600) +++ trunk/core/kernel/event_manager.php (.../event_manager.php) (revision 3282) @@ -344,7 +344,7 @@ foreach($events_source as $short_name => $event_data) { $event_last_run = getArrayValue($event_last_runs, $short_name); - if($event_last_run && $event_last_run > mktime() - $event_data['RunInterval']) + if($event_last_run && $event_last_run > adodb_mktime() - $event_data['RunInterval']) { continue; } @@ -353,12 +353,12 @@ $event = new kEvent($event_data['EventName']); $event->redirect = false; $this->Application->HandleEvent($event); - $event_last_runs[$short_name] = mktime(); + $event_last_runs[$short_name] = adodb_mktime(); } } $sql = 'REPLACE INTO '.TABLE_PREFIX.'Cache (VarName,Data,Cached) VALUES (%s,%s,%s)'; - $this->Conn->Query( sprintf($sql, $this->Conn->qstr('RegularEventRuns'), $this->Conn->qstr(serialize($event_last_runs)), mktime() ) ); + $this->Conn->Query( sprintf($sql, $this->Conn->qstr('RegularEventRuns'), $this->Conn->qstr(serialize($event_last_runs)), adodb_mktime() ) ); } } Index: trunk/core/kernel/application.php =================================================================== diff -u -r3229 -r3282 --- trunk/core/kernel/application.php (.../application.php) (revision 3229) +++ trunk/core/kernel/application.php (.../application.php) (revision 3282) @@ -168,7 +168,7 @@ if( $this->isDebugMode() && dbg_ConstOn('DBG_PROFILE_MEMORY') ) { - $GLOBALS['debugger']->appendMemoryUsage('Application before Init:'); + $this->Debugger->appendMemoryUsage('Application before Init:'); } if( !$this->isDebugMode() && !constOn('DBG_ZEND_PRESENT') ) @@ -212,8 +212,7 @@ $this->Phrases->Init('phrases'); $this->VerifyThemeId(); } - - if( $this->GetVar('m_cat_id') === false ) $this->SetVar('m_cat_id', 0); + if( !$this->RecallVar('UserGroups') ) { $session =& $this->recallObject('Session'); @@ -228,13 +227,14 @@ $this->SetVar('lang.current_id', $this->GetVar('m_lang') ); $this->SetVar('theme.current_id', $this->GetVar('m_theme') ); + if( $this->GetVar('m_cat_id') === false ) $this->SetVar('m_cat_id', 0); $language =& $this->recallObject( 'lang.current', null, Array('live_table' => true) ); $this->ValidateLogin(); // TODO: write that method if( $this->isDebugMode() ) { - $GLOBALS['debugger']->profileFinish('kernel4_startup'); + $this->Debugger->profileFinish('kernel4_startup'); } $this->InitDone = true; @@ -553,7 +553,7 @@ /*if (constOn('EXPERIMENTAL_PRE_PARSE')) { $data = serialize($this->PreParsedCache); - $this->DB->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("blocks_cache", '.$this->DB->qstr($data).', '.time().')'); + $this->DB->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("blocks_cache", '.$this->DB->qstr($data).', '.adodb_mktime().')'); }*/ } @@ -1062,9 +1062,10 @@ { if($js_redirect) { - $this->InitParser(); - $block_params = Array('name' => 'redirect', 'redirect_to_js' => addslashes($a_location), 'redirect_to' => $a_location ); - echo $this->ParseBlock($block_params); + $this->SetVar('t', 'redirect'); + $this->SetVar('redirect_to_js', addslashes($a_location) ); + $this->SetVar('redirect_to', $a_location); + return true; } else { @@ -1078,7 +1079,7 @@ } } } - + $session =& $this->recallObject('Session'); $session->SaveData(); $this->SaveBlocksCache(); @@ -1443,7 +1444,7 @@ if( constOn('SILENT_LOG') ) { $fp = fopen(FULL_PATH.'/silent_log.txt','a'); - $time = date('d/m/Y H:i:s'); + $time = adodb_date('d/m/Y H:i:s'); fwrite($fp, '['.$time.'] #'.$errno.': '.strip_tags($errstr).' in ['.$errfile.'] on line '.$errline."\n"); fclose($fp); } Index: trunk/kernel/include/syscache.php =================================================================== diff -u -r1089 -r3282 --- trunk/kernel/include/syscache.php (.../syscache.php) (revision 1089) +++ trunk/kernel/include/syscache.php (.../syscache.php) (revision 3282) @@ -241,7 +241,7 @@ function PurgeExpired() { - $sql = "DELETE FROM ".$this->SourceTable." WHERE Expire>0 AND Expire <".date("U"); + $sql = "DELETE FROM ".$this->SourceTable." WHERE Expire>0 AND Expire <".adodb_date("U"); $this->adodbConnection->Execute($sql); } Index: trunk/core/units/general/cat_dbitem.php =================================================================== diff -u -r3268 -r3282 --- trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 3268) +++ trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 3282) @@ -19,7 +19,7 @@ $this->checkFilename(); $this->SetDBField('ResourceId', $this->Application->NextResourceId()); - $this->SetDBField('Modified', mktime()); + $this->SetDBField('Modified', adodb_mktime() ); $this->SetDBField('CreatedById', $this->Application->GetVar('u_id')); $this->generateFilename(); @@ -44,7 +44,7 @@ { $this->checkFilename(); $this->VirtualFields['ResourceId'] = true; - $this->SetDBField('Modified', mktime()); + $this->SetDBField('Modified', adodb_mktime() ); $this->SetDBField('ModifiedById', $this->Application->GetVar('u_id')); $this->generateFilename(); @@ -201,8 +201,8 @@ */ function stripDisallowed($string) { - $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', - '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', + $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`', + '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~', '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ','); $string = str_replace($not_allowed, '_', $string); Index: trunk/kernel/parser.php =================================================================== diff -u -r3236 -r3282 --- trunk/kernel/parser.php (.../parser.php) (revision 3236) +++ trunk/kernel/parser.php (.../parser.php) (revision 3282) @@ -2289,7 +2289,7 @@ $conn = &GetADODBConnection(); $code = md5(GenerateCode()); - $sql = 'UPDATE '.GetTablePrefix().'PortalUser SET PwResetConfirm="'.$code.'", PwRequestTime='.mktime().' WHERE PortalUserId='.$tmp_user_id; + $sql = 'UPDATE '.GetTablePrefix().'PortalUser SET PwResetConfirm="'.$code.'", PwRequestTime='.adodb_mktime().' WHERE PortalUserId='.$tmp_user_id; $query = "&user_key=".$code."&Action=m_resetpw"; @@ -3332,7 +3332,7 @@ $ret =0; $ado = &GetADODBConnection(); - $today = mktime(0,0,0,date("m"),date("d"),date("Y")); + $today = adodb_mktime(0, 0, 0, adodb_date("m"), adodb_date("d"), adodb_date("Y")); $sql = "SELECT count(*) as c FROM ".GetTablePrefix()."Favorites WHERE ItemTypeId=6 and PortalUserId=".$objSession->Get("PortalUserId")." AND Modified>$today"; $rs = $ado->Execute($sql); if($rs && !$rs->EOF) @@ -3448,7 +3448,7 @@ $OwnCount = (int)($attribs['_owncount']); if ($LastActive && !is_null($LastActive)) - $sql_add = " AND LastAccessed>".(time()-$LastActive); + $sql_add = " AND LastAccessed>".(adodb_mktime()-$LastActive); if (!$OwnCount || is_null($OwnCount)) $sql_add.= " AND SessionKey!='".$objSession->GetSessionKey()."'"; Index: trunk/kernel/include/language.php =================================================================== diff -u -r3124 -r3282 --- trunk/kernel/include/language.php (.../language.php) (revision 3124) +++ trunk/kernel/include/language.php (.../language.php) (revision 3282) @@ -648,7 +648,7 @@ $t_length = strlen($rs->fields['PhraseList']) ? 1 : 0; $this->TemplateDate = $rs->fields["CacheDate"]; - if(date("U") < $this->TemplateDate + $timeout || !$t_length) + if(adodb_date("U") < $this->TemplateDate + $timeout || !$t_length) { $this->TemplateCache = Array(); $this->TemplateDate=0; @@ -688,13 +688,13 @@ $value = implode(",",$this->TemplateCache); if($this->TemplateDate==0) { - $sql = "UPDATE ".GetTablePrefix()."PhraseCache SET PhraseList='$value',CacheDate=".date("U"); + $sql = "UPDATE ".GetTablePrefix()."PhraseCache SET PhraseList='$value',CacheDate=".adodb_date("U"); $sql .=" WHERE Template='".$this->TemplateName."' AND ThemeId=".$this->ThemeId; } else { $sql = "INSERT IGNORE INTO ".GetTablePrefix()."PhraseCache (Template,PhraseList,CacheDate,ThemeId) VALUES ('"; - $sql .= $this->TemplateName."','$value',".date("U").",".$this->ThemeId.")"; + $sql .= $this->TemplateName."','$value',".adodb_date("U").",".$this->ThemeId.")"; } $this->adodbConnection->Execute($sql); } Index: trunk/core/kernel/utility/unit_config_reader.php =================================================================== diff -u -r3216 -r3282 --- trunk/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 3216) +++ trunk/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 3282) @@ -213,7 +213,7 @@ if (defined('CACHE_CONFIGS_FILES')) { $conn =& $this->Application->GetADODBConnection(); $data = $conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "config_files"'); - if ($data && $data['Cached'] > (time() - 3600) ) { + if ($data && $data['Cached'] > (adodb_mktime() - 3600) ) { $this->configFiles = unserialize($data['Data']); $files_cached = $data['Cached']; } @@ -228,7 +228,7 @@ if (defined('CACHE_CONFIGS_DATA') && CACHE_CONFIGS_DATA) { $conn =& $this->Application->GetADODBConnection(); $data = $conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "config_data"'); - if ($data && $data['Cached'] > (time() - 3600) ) { + if ($data && $data['Cached'] > (adodb_mktime() - 3600) ) { $this->configData = unserialize($data['Data']); $data_cached = $data['Cached']; } @@ -248,7 +248,7 @@ $this->includeConfigFiles(); } - /*// && (time() - $cached) > 600) - to skip checking files modified dates + /*// && (adodb_mktime() - $cached) > 600) - to skip checking files modified dates if ( !defined('CACHE_CONFIGS') ) { $fh=opendir($folderPath); while(($sub_folder=readdir($fh))) @@ -262,13 +262,13 @@ }*/ if (defined('CACHE_CONFIGS_DATA') && $data_cached == 0) { - $conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_data", '.$conn->qstr(serialize($this->configData)).', '.time().')'); + $conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_data", '.$conn->qstr(serialize($this->configData)).', '.adodb_mktime().')'); } $this->ParseConfigs(); if (defined('CACHE_CONFIGS_FILES') && $files_cached == 0) { - $conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_files", '.$conn->qstr(serialize($this->configFiles)).', '.time().')'); + $conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_files", '.$conn->qstr(serialize($this->configFiles)).', '.adodb_mktime().')'); } unset($this->configFiles); Index: trunk/core/kernel/utility/formatters.php =================================================================== diff -u -r3097 -r3282 --- trunk/core/kernel/utility/formatters.php (.../formatters.php) (revision 3097) +++ trunk/core/kernel/utility/formatters.php (.../formatters.php) (revision 3282) @@ -297,7 +297,7 @@ // when we have only date field on form, we need time hidden field always empty, don't ask me why! if ( $object->GetDBField($sub_fields['date']) != '' && $object->GetDBField($sub_fields['time']) == '' ) { $empty_time = getArrayValue($options,'empty_time'); - if($empty_time === false) $empty_time = mktime(0,0,0); + if($empty_time === false) $empty_time = adodb_mktime(0,0,0); $object->SetDBField($sub_fields['time'], $empty_time); } $object->SetField($field, $object->GetField($sub_fields['date']).$options['date_time_separator'].$object->GetField($sub_fields['time'])); @@ -320,7 +320,7 @@ $options = $object->GetFieldOptions($field_name); if ( isset($format) ) $options['format'] = $format; - return date($options['format'], $value); + return adodb_date($options['format'], $value); } function HumanFormat($format) @@ -410,7 +410,7 @@ $format = $options['format']; if($dt_separator) $format = trim($format, $dt_separator); - $object->FieldErrors[$field_name]['params'] = Array( $this->HumanFormat($format), date($format) ); + $object->FieldErrors[$field_name]['params'] = Array( $this->HumanFormat($format), adodb_date($format) ); $object->FieldErrors[$field_name]['value'] = $value; $hour = 0; @@ -534,12 +534,12 @@ return $value; } // echo "day: $day, month: $month, year: $year, hour: $hour, minute: $minute
"; - return (mktime($hour, $minute, $second, $month, $day, $year)); + return adodb_mktime($hour, $minute, $second, $month, $day, $year); } function GetSample($field, &$options, &$object) { - return $this->Format( time(), $field, $object); + return $this->Format( adodb_mktime(), $field, $object); } } Index: trunk/core/units/general/inp_ses_storage.php =================================================================== diff -u -r3031 -r3282 --- trunk/core/units/general/inp_ses_storage.php (.../inp_ses_storage.php) (revision 3031) +++ trunk/core/units/general/inp_ses_storage.php (.../inp_ses_storage.php) (revision 3282) @@ -76,7 +76,7 @@ function GetExpiredSIDs() { - $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.time().' - '.$this->TimestampField.' > '.$this->SessionTimeout; + $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.adodb_mktime().' - '.$this->TimestampField.' > '.$this->SessionTimeout; $ret = $this->Conn->GetCol($query); if($ret) $this->DeleteEditTables(); return $ret; Index: trunk/kernel/include/statitem.php =================================================================== diff -u -r13 -r3282 --- trunk/kernel/include/statitem.php (.../statitem.php) (revision 13) +++ trunk/kernel/include/statitem.php (.../statitem.php) (revision 3282) @@ -107,7 +107,7 @@ break; default: // simple-default postformatting - $value = date($this->PostFormatting, $value); + $value = adodb_date($this->PostFormatting, $value); break; } $this->PostFormatting = false; Index: trunk/core/units/languages/import_xml.php =================================================================== diff -u -r3145 -r3282 --- trunk/core/units/languages/import_xml.php (.../import_xml.php) (revision 3145) +++ trunk/core/units/languages/import_xml.php (.../import_xml.php) (revision 3282) @@ -193,7 +193,7 @@ 'Phrase' => $attributes['LABEL'], 'PhraseType' => $attributes['TYPE'], 'Module' => $phrase_module, - 'LastChanged' => time(), + 'LastChanged' => adodb_mktime(), 'LastChangeIP' => $this->ip_address, 'Translation' => ''); break; Index: trunk/kernel/units/phrases/phrases_event_handler.php =================================================================== diff -u -r3145 -r3282 --- trunk/kernel/units/phrases/phrases_event_handler.php (.../phrases_event_handler.php) (revision 3145) +++ trunk/kernel/units/phrases/phrases_event_handler.php (.../phrases_event_handler.php) (revision 3282) @@ -69,8 +69,8 @@ if( $prev_translation != $object->GetDBField('Translation') ) { $ip_address = getenv('HTTP_X_FORWARDED_FOR') ? getenv('HTTP_X_FORWARDED_FOR') : getenv('REMOTE_ADDR'); - $object->SetDBField('LastChanged_date', time() ); - $object->SetDBField('LastChanged_time', time() ); + $object->SetDBField('LastChanged_date', adodb_mktime() ); + $object->SetDBField('LastChanged_time', adodb_mktime() ); $object->SetDBField('LastChangeIP', $ip_address); } Index: trunk/kernel/include/emailmessage.php =================================================================== diff -u -r3145 -r3282 --- trunk/kernel/include/emailmessage.php (.../emailmessage.php) (revision 3145) +++ trunk/kernel/include/emailmessage.php (.../emailmessage.php) (revision 3282) @@ -191,7 +191,7 @@ $objEmailQueue->SendMail($FromAddr,$FromName,$to_addr,$To,$subject,$body,"",$charset, $this->Get("Event"),NULL,$this->headers); } - /*$time = time(); + /*$time = adodb_mktime(); $sql = "INSERT INTO ".GetTablePrefix()."EmailLog VALUES ('', '$FromName', '$To', '$subject', $time, '')"; $conn->Execute($sql); */ @@ -251,7 +251,7 @@ $objEmailQueue->SendMail($FromAddr,$FromName,$to_addr,$To,$subject,$body,"",$charset, $this->Get("Event"),NULL,$this->headers); } - /*$time = time(); + /*$time = adodb_mktime(); $sql = "INSERT INTO ".GetTablePrefix()."EmailLog VALUES ('', '$FromName', '$To ($to_addr)', '$subject', $time, '')"; $conn->Execute($sql); */ @@ -298,7 +298,7 @@ $objEmailQueue->SendMail($FromAddr,$FromName,$to_addr,$To,$subject,$body,"",$charset, $this->Get("Event"),NULL,$this->headers); } - /* $time = time(); + /* $time = adodb_mktime(); $sql = "INSERT INTO ".GetTablePrefix()."EmailLog VALUES ('', '$FromName', '$To ($to_addr)', '$subject', $time, '')"; $conn->Execute($sql); @@ -723,14 +723,14 @@ $this->MessagesSent++; - $time = time(); + $time = adodb_mktime(); $conn = &GetADODBConnection(); /* $sql = "INSERT INTO ".GetTablePrefix()."EmailLog VALUES ('', '".htmlspecialchars($From)."', '".htmlspecialchars($To)."', '$Subject', $time, '')"; $conn->Execute($sql);*/ /* ensure headers are using \r\n instead of \n */ - $headers = "Date: ".date("r")."\n".$headers; + $headers = "Date: ".adodb_date("r")."\n".$headers; $headers = "Return-Path: ".$objConfig->Get("Smtp_AdminMailFrom")."\n".$headers; $headers = str_replace("\n\n","\r\n\r\n",$headers); @@ -884,7 +884,7 @@ $headers .= "MIME-Version: 1.0\r\n"; $conn = &GetADODBConnection(); - $time = time(); + $time = adodb_mktime(); $sendTo = $ToName; Index: trunk/kernel/units/languages/languages_event_handler.php =================================================================== diff -u -r3211 -r3282 --- trunk/kernel/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 3211) +++ trunk/kernel/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 3282) @@ -107,7 +107,7 @@ $phrases_live = $this->Application->getUnitOption('phrases','TableName'); $phrases_temp = kTempTablesHandler::GetTempName($phrases_live); $sql = 'INSERT INTO '.$phrases_temp.' - SELECT Phrase, Translation, PhraseType, 0-PhraseId, '.$lang_id.', '.time().', "", Module + SELECT Phrase, Translation, PhraseType, 0-PhraseId, '.$lang_id.', '.adodb_mktime().', "", Module FROM '.$phrases_live.' WHERE LanguageId='.$from_lang_id; $this->Conn->Query($sql); Index: trunk/core/kernel/languages/phrases_cache.php =================================================================== diff -u -r3162 -r3282 --- trunk/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 3162) +++ trunk/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 3282) @@ -69,7 +69,7 @@ VALUES (%s, %s, %s)", TABLE_PREFIX.'PhraseCache', $this->Conn->Qstr(join(',', $this->Ids)), - mktime(), + adodb_mktime(), $this->Conn->Qstr(md5($this->Application->GetVar('t')))); $this->Conn->Query($query); } Index: trunk/themes/default/redirect.tpl =================================================================== diff -u --- trunk/themes/default/redirect.tpl (revision 0) +++ trunk/themes/default/redirect.tpl (revision 3282) @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +

+ + + + + + + + + + + +

+ + + + + + +

  + + + + + + + +
" width="18" height="12" alt="" />
   
+
+ +
+ + + +

+
+ + + Index: trunk/kernel/include/favorites.php =================================================================== diff -u -r13 -r3282 --- trunk/kernel/include/favorites.php (.../favorites.php) (revision 13) +++ trunk/kernel/include/favorites.php (.../favorites.php) (revision 3282) @@ -78,7 +78,7 @@ { $f = new clsFavorite; $f->Set(array("PortalUserId","ResourceId","ItemTypeId","Modified"), - array($PortalUserId,$ResourceId,$ItemType,date("U"))); + array($PortalUserId,$ResourceId,$ItemType,adodb_date("U"))); $f->Create(); return $f; } Index: trunk/kernel/action.php =================================================================== diff -u -r3237 -r3282 --- trunk/kernel/action.php (.../action.php) (revision 3237) +++ trunk/kernel/action.php (.../action.php) (revision 3282) @@ -767,7 +767,7 @@ $CreatedOn = DateTimestamp($_POST["cat_date"],GetDateFormat()); } else - $CreatedOn = time(); + $CreatedOn = adodb_mktime(); $html = (int)$_POST["html_enable"]; $cat_pick = $_POST["cat_pick"]; Index: trunk/kernel/units/stylesheets/stylesheets_item.php =================================================================== diff -u -r2604 -r3282 --- trunk/kernel/units/stylesheets/stylesheets_item.php (.../stylesheets_item.php) (revision 2604) +++ trunk/kernel/units/stylesheets/stylesheets_item.php (.../stylesheets_item.php) (revision 3282) @@ -21,7 +21,7 @@ $ret .= $this->GetDBField('AdvancedCSS'); - $compile_ts = time(); + $compile_ts = adodb_mktime(); $css_path = FULL_PATH.'/kernel/stylesheets/'; $css_file = $css_path.strtolower($this->GetDBField('Name')).'-'.$compile_ts.'.css'; Index: trunk/kernel/units/general/cat_event_handler.php =================================================================== diff -u -r3163 -r3282 --- trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 3163) +++ trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 3282) @@ -292,7 +292,7 @@ LIMIT '.$last_hot.', 1'; $res = $this->Conn->GetCol($sql); $hot_limit = (double)array_shift($res); - $this->Conn->Query('REPLACE INTO '.TABLE_PREFIX.'Cache VALUES ("'.$hot_limit_var.'", "'.$hot_limit.'", '.mktime().')'); + $this->Conn->Query('REPLACE INTO '.TABLE_PREFIX.'Cache VALUES ("'.$hot_limit_var.'", "'.$hot_limit.'", '.adodb_mktime().')'); return $hot_limit; } return 0; @@ -832,7 +832,7 @@ if( in_array($keywords[$field], Array('today', 'yesterday')) ) { $current_time = getdate(); - $day_begin = mktime(0, 0, 0, $current_time['mon'], $current_time['mday'], $current_time['year']); + $day_begin = adodb_mktime(0, 0, 0, $current_time['mon'], $current_time['mday'], $current_time['year']); $time_mapping = Array('today' => $day_begin, 'yesterday' => ($day_begin - 86400)); $min_time = $time_mapping[$keywords[$field]]; } @@ -842,7 +842,7 @@ 'last_3_months' => 7884000, 'last_6_months' => 15768000, 'last_year' => 31536000 ); - $min_time = mktime() - $time_mapping[$keywords[$field]]; + $min_time = adodb_mktime() - $time_mapping[$keywords[$field]]; } $condition = $field_name.' > '.$min_time; } Index: trunk/kernel/units/visits/visits_event_handler.php =================================================================== diff -u -r2741 -r3282 --- trunk/kernel/units/visits/visits_event_handler.php (.../visits_event_handler.php) (revision 2741) +++ trunk/kernel/units/visits/visits_event_handler.php (.../visits_event_handler.php) (revision 3282) @@ -10,8 +10,8 @@ function OnRegisterVisit(&$event) { $object =& $event->getObject( Array('skip_autoload'=>true) ); - $object->SetDBField('VisitDate_date', time() ); - $object->SetDBField('VisitDate_time', time() ); + $object->SetDBField('VisitDate_date', adodb_mktime() ); + $object->SetDBField('VisitDate_time', adodb_mktime() ); $object->SetDBField('Referer', getArrayValue($_SERVER, 'HTTP_REFERER') ); $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR'] ); if( $object->Create() ) Index: trunk/core/kernel/utility/adodb-time.inc.php =================================================================== diff -u --- trunk/core/kernel/utility/adodb-time.inc.php (revision 0) +++ trunk/core/kernel/utility/adodb-time.inc.php (revision 3282) @@ -0,0 +1,1294 @@ + 4 digit year conversion. The maximum is billions of years in the +future, but this is a theoretical limit as the computation of that year +would take too long with the current implementation of adodb_mktime(). + +This library replaces native functions as follows: + +
	
+	getdate()  with  adodb_getdate()
+	date()     with  adodb_date() 
+	gmdate()   with  adodb_gmdate()
+	mktime()   with  adodb_mktime()
+	gmmktime() with  adodb_gmmktime()
+	strftime() with  adodb_strftime()
+	strftime() with  adodb_gmstrftime()
+
+ +The parameters are identical, except that adodb_date() accepts a subset +of date()'s field formats. Mktime() will convert from local time to GMT, +and date() will convert from GMT to local time, but daylight savings is +not handled currently. + +This library is independant of the rest of ADOdb, and can be used +as standalone code. + +PERFORMANCE + +For high speed, this library uses the native date functions where +possible, and only switches to PHP code when the dates fall outside +the 32-bit signed integer range. + +GREGORIAN CORRECTION + +Pope Gregory shortened October of A.D. 1582 by ten days. Thursday, +October 4, 1582 (Julian) was followed immediately by Friday, October 15, +1582 (Gregorian). + +Since 0.06, we handle this correctly, so: + +adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582) + == 24 * 3600 (1 day) + +============================================================================= + +COPYRIGHT + +(c) 2003-2005 John Lim and released under BSD-style license except for code by +jackbbs, which includes adodb_mktime, adodb_get_gmt_diff, adodb_is_leap_year +and originally found at http://www.php.net/manual/en/function.mktime.php + +============================================================================= + +BUG REPORTS + +These should be posted to the ADOdb forums at + + http://phplens.com/lens/lensforum/topics.php?id=4 + +============================================================================= + +FUNCTION DESCRIPTIONS + + +** FUNCTION adodb_getdate($date=false) + +Returns an array containing date information, as getdate(), but supports +dates greater than 1901 to 2038. The local date/time format is derived from a +heuristic the first time adodb_getdate is called. + + +** FUNCTION adodb_date($fmt, $timestamp = false) + +Convert a timestamp to a formatted local date. If $timestamp is not defined, the +current timestamp is used. Unlike the function date(), it supports dates +outside the 1901 to 2038 range. + +The format fields that adodb_date supports: + +
+	a - "am" or "pm" 
+	A - "AM" or "PM" 
+	d - day of the month, 2 digits with leading zeros; i.e. "01" to "31" 
+	D - day of the week, textual, 3 letters; e.g. "Fri" 
+	F - month, textual, long; e.g. "January" 
+	g - hour, 12-hour format without leading zeros; i.e. "1" to "12" 
+	G - hour, 24-hour format without leading zeros; i.e. "0" to "23" 
+	h - hour, 12-hour format; i.e. "01" to "12" 
+	H - hour, 24-hour format; i.e. "00" to "23" 
+	i - minutes; i.e. "00" to "59" 
+	j - day of the month without leading zeros; i.e. "1" to "31" 
+	l (lowercase 'L') - day of the week, textual, long; e.g. "Friday"  
+	L - boolean for whether it is a leap year; i.e. "0" or "1" 
+	m - month; i.e. "01" to "12" 
+	M - month, textual, 3 letters; e.g. "Jan" 
+	n - month without leading zeros; i.e. "1" to "12" 
+	O - Difference to Greenwich time in hours; e.g. "+0200" 
+	Q - Quarter, as in 1, 2, 3, 4 
+	r - RFC 822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200" 
+	s - seconds; i.e. "00" to "59" 
+	S - English ordinal suffix for the day of the month, 2 characters; 
+	   			i.e. "st", "nd", "rd" or "th" 
+	t - number of days in the given month; i.e. "28" to "31"
+	T - Timezone setting of this machine; e.g. "EST" or "MDT" 
+	U - seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)  
+	w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday) 
+	Y - year, 4 digits; e.g. "1999" 
+	y - year, 2 digits; e.g. "99" 
+	z - day of the year; i.e. "0" to "365" 
+	Z - timezone offset in seconds (i.e. "-43200" to "43200"). 
+	   			The offset for timezones west of UTC is always negative, 
+				and for those east of UTC is always positive. 
+
+ +Unsupported: +
+	B - Swatch Internet time 
+	I (capital i) - "1" if Daylight Savings Time, "0" otherwise.
+	W - ISO-8601 week number of year, weeks starting on Monday 
+
+
+ + +** FUNCTION adodb_date2($fmt, $isoDateString = false) +Same as adodb_date, but 2nd parameter accepts iso date, eg. + + adodb_date2('d-M-Y H:i','2003-12-25 13:01:34'); + + +** FUNCTION adodb_gmdate($fmt, $timestamp = false) + +Convert a timestamp to a formatted GMT date. If $timestamp is not defined, the +current timestamp is used. Unlike the function date(), it supports dates +outside the 1901 to 2038 range. + + +** FUNCTION adodb_mktime($hr, $min, $sec[, $month, $day, $year]) + +Converts a local date to a unix timestamp. Unlike the function mktime(), it supports +dates outside the 1901 to 2038 range. All parameters are optional. + + +** FUNCTION adodb_gmmktime($hr, $min, $sec [, $month, $day, $year]) + +Converts a gmt date to a unix timestamp. Unlike the function gmmktime(), it supports +dates outside the 1901 to 2038 range. Differs from gmmktime() in that all parameters +are currently compulsory. + +** FUNCTION adodb_gmstrftime($fmt, $timestamp = false) +Convert a timestamp to a formatted GMT date. + +** FUNCTION adodb_strftime($fmt, $timestamp = false) + +Convert a timestamp to a formatted local date. Internally converts $fmt into +adodb_date format, then echo result. + +For best results, you can define the local date format yourself. Define a global +variable $ADODB_DATE_LOCALE which is an array, 1st element is date format using +adodb_date syntax, and 2nd element is the time format, also in adodb_date syntax. + + eg. $ADODB_DATE_LOCALE = array('d/m/Y','H:i:s'); + + Supported format codes: + +
+	%a - abbreviated weekday name according to the current locale 
+	%A - full weekday name according to the current locale 
+	%b - abbreviated month name according to the current locale 
+	%B - full month name according to the current locale 
+	%c - preferred date and time representation for the current locale 
+	%d - day of the month as a decimal number (range 01 to 31) 
+	%D - same as %m/%d/%y 
+	%e - day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31') 
+	%h - same as %b
+	%H - hour as a decimal number using a 24-hour clock (range 00 to 23) 
+	%I - hour as a decimal number using a 12-hour clock (range 01 to 12) 
+	%m - month as a decimal number (range 01 to 12) 
+	%M - minute as a decimal number 
+	%n - newline character 
+	%p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale 
+	%r - time in a.m. and p.m. notation 
+	%R - time in 24 hour notation 
+	%S - second as a decimal number 
+	%t - tab character 
+	%T - current time, equal to %H:%M:%S 
+	%x - preferred date representation for the current locale without the time 
+	%X - preferred time representation for the current locale without the date 
+	%y - year as a decimal number without a century (range 00 to 99) 
+	%Y - year as a decimal number including the century 
+	%Z - time zone or name or abbreviation 
+	%% - a literal `%' character 
+
+ + Unsupported codes: +
+	%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99) 
+	%g - like %G, but without the century. 
+	%G - The 4-digit year corresponding to the ISO week number (see %V). 
+	     This has the same format and value as %Y, except that if the ISO week number belongs 
+		 to the previous or next year, that year is used instead. 
+	%j - day of the year as a decimal number (range 001 to 366) 
+	%u - weekday as a decimal number [1,7], with 1 representing Monday 
+	%U - week number of the current year as a decimal number, starting 
+	    with the first Sunday as the first day of the first week 
+	%V - The ISO 8601:1988 week number of the current year as a decimal number, 
+	     range 01 to 53, where week 1 is the first week that has at least 4 days in the 
+		 current year, and with Monday as the first day of the week. (Use %G or %g for 
+		 the year component that corresponds to the week number for the specified timestamp.) 
+	%w - day of the week as a decimal, Sunday being 0 
+	%W - week number of the current year as a decimal number, starting with the 
+	     first Monday as the first day of the first week 
+
+ +============================================================================= + +NOTES + +Useful url for generating test timestamps: + http://www.4webhelp.net/us/timestamp.php + +Possible future optimizations include + +a. Using an algorithm similar to Plauger's in "The Standard C Library" +(page 428, xttotm.c _Ttotm() function). Plauger's algorithm will not +work outside 32-bit signed range, so i decided not to implement it. + +b. Implement daylight savings, which looks awfully complicated, see + http://webexhibits.org/daylightsaving/ + + +CHANGELOG + +- 18 July 2005 0.21 +- In PHP 4.3.11, the 'r' format has changed. Leading 0 in day is added. Changed for compat. +- Added support for negative months in adodb_mktime(). + +- 24 Feb 2005 0.20 +Added limited strftime/gmstrftime support. x10 improvement in performance of adodb_date(). + +- 21 Dec 2004 0.17 +In adodb_getdate(), the timestamp was accidentally converted to gmt when $is_gmt is false. +Also adodb_mktime(0,0,0) did not work properly. Both fixed thx Mauro. + +- 17 Nov 2004 0.16 +Removed intval typecast in adodb_mktime() for secs, allowing: + adodb_mktime(0,0,0 + 2236672153,1,1,1934); +Suggested by Ryan. + +- 18 July 2004 0.15 +All params in adodb_mktime were formerly compulsory. Now only the hour, min, secs is compulsory. +This brings it more in line with mktime (still not identical). + +- 23 June 2004 0.14 + +Allow you to define your own daylights savings function, adodb_daylight_sv. +If the function is defined (somewhere in an include), then you can correct for daylights savings. + +In this example, we apply daylights savings in June or July, adding one hour. This is extremely +unrealistic as it does not take into account time-zone, geographic location, current year. + +function adodb_daylight_sv(&$arr, $is_gmt) +{ + if ($is_gmt) return; + $m = $arr['mon']; + if ($m == 6 || $m == 7) $arr['hours'] += 1; +} + +This is only called by adodb_date() and not by adodb_mktime(). + +The format of $arr is +Array ( + [seconds] => 0 + [minutes] => 0 + [hours] => 0 + [mday] => 1 # day of month, eg 1st day of the month + [mon] => 2 # month (eg. Feb) + [year] => 2102 + [yday] => 31 # days in current year + [leap] => # true if leap year + [ndays] => 28 # no of days in current month + ) + + +- 28 Apr 2004 0.13 +Fixed adodb_date to properly support $is_gmt. Thx to Dimitar Angelov. + +- 20 Mar 2004 0.12 +Fixed month calculation error in adodb_date. 2102-June-01 appeared as 2102-May-32. + +- 26 Oct 2003 0.11 +Because of daylight savings problems (some systems apply daylight savings to +January!!!), changed adodb_get_gmt_diff() to ignore daylight savings. + +- 9 Aug 2003 0.10 +Fixed bug with dates after 2038. +See http://phplens.com/lens/lensforum/msgs.php?id=6980 + +- 1 July 2003 0.09 +Added support for Q (Quarter). +Added adodb_date2(), which accepts ISO date in 2nd param + +- 3 March 2003 0.08 +Added support for 'S' adodb_date() format char. Added constant ADODB_ALLOW_NEGATIVE_TS +if you want PHP to handle negative timestamps between 1901 to 1969. + +- 27 Feb 2003 0.07 +All negative numbers handled by adodb now because of RH 7.3+ problems. +See http://bugs.php.net/bug.php?id=20048&edit=2 + +- 4 Feb 2003 0.06 +Fixed a typo, 1852 changed to 1582! This means that pre-1852 dates +are now correctly handled. + +- 29 Jan 2003 0.05 + +Leap year checking differs under Julian calendar (pre 1582). Also +leap year code optimized by checking for most common case first. + +We also handle month overflow correctly in mktime (eg month set to 13). + +Day overflow for less than one month's days is supported. + +- 28 Jan 2003 0.04 + +Gregorian correction handled. In PHP5, we might throw an error if +mktime uses invalid dates around 5-14 Oct 1582. Released with ADOdb 3.10. +Added limbo 5-14 Oct 1582 check, when we set to 15 Oct 1582. + +- 27 Jan 2003 0.03 + +Fixed some more month problems due to gmt issues. Added constant ADODB_DATE_VERSION. +Fixed calculation of days since start of year for <1970. + +- 27 Jan 2003 0.02 + +Changed _adodb_getdate() to inline leap year checking for better performance. +Fixed problem with time-zones west of GMT +0000. + +- 24 Jan 2003 0.01 + +First implementation. +*/ + + +/* Initialization */ + +/* + Version Number +*/ +define('ADODB_DATE_VERSION',0.21); + +/* + This code was originally for windows. But apparently this problem happens + also with Linux, RH 7.3 and later! + + glibc-2.2.5-34 and greater has been changed to return -1 for dates < + 1970. This used to work. The problem exists with RedHat 7.3 and 8.0 + echo (mktime(0, 0, 0, 1, 1, 1960)); // prints -1 + + References: + http://bugs.php.net/bug.php?id=20048&edit=2 + http://lists.debian.org/debian-glibc/2002/debian-glibc-200205/msg00010.html +*/ + +if (!defined('ADODB_ALLOW_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS',1); + +function adodb_date_test_date($y1,$m,$d=13) +{ + $t = adodb_mktime(0,0,0,$m,$d,$y1); + $rez = adodb_date('Y-n-j H:i:s',$t); + if ("$y1-$m-$d 00:00:00" != $rez) { + print "$y1 error, expected=$y1-$m-$d 00:00:00, adodb=$rez
"; + return false; + } + return true; +} + +function adodb_date_test_strftime($fmt) +{ + $s1 = strftime($fmt); + $s2 = adodb_strftime($fmt); + + if ($s1 == $s2) return true; + + echo "error for $fmt, strftime=$s1, $adodb=$s2
"; + return false; +} + +/** + Test Suite +*/ +function adodb_date_test() +{ + + error_reporting(E_ALL); + print "

Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION.' PHP='.PHP_VERSION."

"; + @set_time_limit(0); + $fail = false; + + // This flag disables calling of PHP native functions, so we can properly test the code + if (!defined('ADODB_TEST_DATES')) define('ADODB_TEST_DATES',1); + + adodb_date_test_strftime('%Y %m %x %X'); + adodb_date_test_strftime("%A %d %B %Y"); + adodb_date_test_strftime("%H %M S"); + + $t = adodb_mktime(0,0,0); + if (!(adodb_date('Y-m-d') == date('Y-m-d'))) print 'Error in '.adodb_mktime(0,0,0).'
'; + + $t = adodb_mktime(0,0,0,6,1,2102); + if (!(adodb_date('Y-m-d',$t) == '2102-06-01')) print 'Error in '.adodb_date('Y-m-d',$t).'
'; + + $t = adodb_mktime(0,0,0,2,1,2102); + if (!(adodb_date('Y-m-d',$t) == '2102-02-01')) print 'Error in '.adodb_date('Y-m-d',$t).'
'; + + + print "

Testing gregorian <=> julian conversion

"; + $t = adodb_mktime(0,0,0,10,11,1492); + //http://www.holidayorigins.com/html/columbus_day.html - Friday check + if (!(adodb_date('D Y-m-d',$t) == 'Fri 1492-10-11')) print 'Error in Columbus landing
'; + + $t = adodb_mktime(0,0,0,2,29,1500); + if (!(adodb_date('Y-m-d',$t) == '1500-02-29')) print 'Error in julian leap years
'; + + $t = adodb_mktime(0,0,0,2,29,1700); + if (!(adodb_date('Y-m-d',$t) == '1700-03-01')) print 'Error in gregorian leap years
'; + + print adodb_mktime(0,0,0,10,4,1582).' '; + print adodb_mktime(0,0,0,10,15,1582); + $diff = (adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582)); + if ($diff != 3600*24) print " Error in gregorian correction = ".($diff/3600/24)." days
"; + + print " 15 Oct 1582, Fri=".(adodb_dow(1582,10,15) == 5 ? 'Fri' : 'Error')."
"; + print " 4 Oct 1582, Thu=".(adodb_dow(1582,10,4) == 4 ? 'Thu' : 'Error')."
"; + + print "

Testing overflow

"; + + $t = adodb_mktime(0,0,0,3,33,1965); + if (!(adodb_date('Y-m-d',$t) == '1965-04-02')) print 'Error in day overflow 1
'; + $t = adodb_mktime(0,0,0,4,33,1971); + if (!(adodb_date('Y-m-d',$t) == '1971-05-03')) print 'Error in day overflow 2
'; + $t = adodb_mktime(0,0,0,1,60,1965); + if (!(adodb_date('Y-m-d',$t) == '1965-03-01')) print 'Error in day overflow 3 '.adodb_date('Y-m-d',$t).'
'; + $t = adodb_mktime(0,0,0,12,32,1965); + if (!(adodb_date('Y-m-d',$t) == '1966-01-01')) print 'Error in day overflow 4 '.adodb_date('Y-m-d',$t).'
'; + $t = adodb_mktime(0,0,0,12,63,1965); + if (!(adodb_date('Y-m-d',$t) == '1966-02-01')) print 'Error in day overflow 5 '.adodb_date('Y-m-d',$t).'
'; + $t = adodb_mktime(0,0,0,13,3,1965); + if (!(adodb_date('Y-m-d',$t) == '1966-01-03')) print 'Error in mth overflow 1
'; + + print "Testing 2-digit => 4-digit year conversion

"; + if (adodb_year_digit_check(00) != 2000) print "Err 2-digit 2000
"; + if (adodb_year_digit_check(10) != 2010) print "Err 2-digit 2010
"; + if (adodb_year_digit_check(20) != 2020) print "Err 2-digit 2020
"; + if (adodb_year_digit_check(30) != 2030) print "Err 2-digit 2030
"; + if (adodb_year_digit_check(40) != 1940) print "Err 2-digit 1940
"; + if (adodb_year_digit_check(50) != 1950) print "Err 2-digit 1950
"; + if (adodb_year_digit_check(90) != 1990) print "Err 2-digit 1990
"; + + // Test string formating + print "

Testing date formating

"; + $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C822 r s t U w y Y z Z 2003'; + $s1 = date($fmt,0); + $s2 = adodb_date($fmt,0); + if ($s1 != $s2) { + print " date() 0 failed
$s1
$s2
"; + } + flush(); + for ($i=100; --$i > 0; ) { + + $ts = 3600.0*((rand()%60000)+(rand()%60000))+(rand()%60000); + $s1 = date($fmt,$ts); + $s2 = adodb_date($fmt,$ts); + //print "$s1
$s2

"; + $pos = strcmp($s1,$s2); + + if (($s1) != ($s2)) { + for ($j=0,$k=strlen($s1); $j < $k; $j++) { + if ($s1[$j] != $s2[$j]) { + print substr($s1,$j).' '; + break; + } + } + print "Error date(): $ts

 
+  \"$s1\" (date len=".strlen($s1).")
+  \"$s2\" (adodb_date len=".strlen($s2).")

"; + $fail = true; + } + + $a1 = getdate($ts); + $a2 = adodb_getdate($ts); + $rez = array_diff($a1,$a2); + if (sizeof($rez)>0) { + print "Error getdate() $ts
"; + print_r($a1); + print "
"; + print_r($a2); + print "

"; + $fail = true; + } + } + + // Test generation of dates outside 1901-2038 + print "

Testing random dates between 100 and 4000

"; + adodb_date_test_date(100,1); + for ($i=100; --$i >= 0;) { + $y1 = 100+rand(0,1970-100); + $m = rand(1,12); + adodb_date_test_date($y1,$m); + + $y1 = 3000-rand(0,3000-1970); + adodb_date_test_date($y1,$m); + } + print '

'; + $start = 1960+rand(0,10); + $yrs = 12; + $i = 365.25*86400*($start-1970); + $offset = 36000+rand(10000,60000); + $max = 365*$yrs*86400; + $lastyear = 0; + + // we generate a timestamp, convert it to a date, and convert it back to a timestamp + // and check if the roundtrip broke the original timestamp value. + print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: "; + $cnt = 0; + for ($max += $i; $i < $max; $i += $offset) { + $ret = adodb_date('m,d,Y,H,i,s',$i); + $arr = explode(',',$ret); + if ($lastyear != $arr[2]) { + $lastyear = $arr[2]; + print " $lastyear "; + flush(); + } + $newi = adodb_mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]); + if ($i != $newi) { + print "Error at $i, adodb_mktime returned $newi ($ret)"; + $fail = true; + break; + } + $cnt += 1; + } + echo "Tested $cnt dates
"; + if (!$fail) print "

Passed !

"; + else print "

Failed :-(

"; +} + +/** + Returns day of week, 0 = Sunday,... 6=Saturday. + Algorithm from PEAR::Date_Calc +*/ +function adodb_dow($year, $month, $day) +{ +/* +Pope Gregory removed 10 days - October 5 to October 14 - from the year 1582 and +proclaimed that from that time onwards 3 days would be dropped from the calendar +every 400 years. + +Thursday, October 4, 1582 (Julian) was followed immediately by Friday, October 15, 1582 (Gregorian). +*/ + if ($year <= 1582) { + if ($year < 1582 || + ($year == 1582 && ($month < 10 || ($month == 10 && $day < 15)))) $greg_correction = 3; + else + $greg_correction = 0; + } else + $greg_correction = 0; + + if($month > 2) + $month -= 2; + else { + $month += 10; + $year--; + } + + $day = floor((13 * $month - 1) / 5) + + $day + ($year % 100) + + floor(($year % 100) / 4) + + floor(($year / 100) / 4) - 2 * + floor($year / 100) + 77 + $greg_correction; + + return $day - 7 * floor($day / 7); +} + + +/** + Checks for leap year, returns true if it is. No 2-digit year check. Also + handles julian calendar correctly. +*/ +function _adodb_is_leap_year($year) +{ + if ($year % 4 != 0) return false; + + if ($year % 400 == 0) { + return true; + // if gregorian calendar (>1582), century not-divisible by 400 is not leap + } else if ($year > 1582 && $year % 100 == 0 ) { + return false; + } + + return true; +} + + +/** + checks for leap year, returns true if it is. Has 2-digit year check +*/ +function adodb_is_leap_year($year) +{ + return _adodb_is_leap_year(adodb_year_digit_check($year)); +} + +/** + Fix 2-digit years. Works for any century. + Assumes that if 2-digit is more than 30 years in future, then previous century. +*/ +function adodb_year_digit_check($y) +{ + if ($y < 100) { + + $yr = (integer) date("Y"); + $century = (integer) ($yr /100); + + if ($yr%100 > 50) { + $c1 = $century + 1; + $c0 = $century; + } else { + $c1 = $century; + $c0 = $century - 1; + } + $c1 *= 100; + // if 2-digit year is less than 30 years in future, set it to this century + // otherwise if more than 30 years in future, then we set 2-digit year to the prev century. + if (($y + $c1) < $yr+30) $y = $y + $c1; + else $y = $y + $c0*100; + } + return $y; +} + +/** + get local time zone offset from GMT +*/ +function adodb_get_gmt_diff() +{ +static $TZ; + if (isset($TZ)) return $TZ; + + $TZ = mktime(0,0,0,1,2,1970,0) - gmmktime(0,0,0,1,2,1970,0); + return $TZ; +} + +/** + Returns an array with date info. +*/ +function adodb_getdate($d=false,$fast=false) +{ + if ($d === false) return getdate(); + if (!defined('ADODB_TEST_DATES')) { + if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range + if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer + return @getdate($d); + } + } + return _adodb_getdate($d); +} + +/* +// generate $YRS table for _adodb_getdate() +function adodb_date_gentable($out=true) +{ + + for ($i=1970; $i >= 1600; $i-=10) { + $s = adodb_gmmktime(0,0,0,1,1,$i); + echo "$i => $s,
"; + } +} +adodb_date_gentable(); + +for ($i=1970; $i > 1500; $i--) { + +echo "
$i "; + adodb_date_test_date($i,1,1); +} + +*/ + +/** + Low-level function that returns the getdate() array. We have a special + $fast flag, which if set to true, will return fewer array values, + and is much faster as it does not calculate dow, etc. +*/ +function _adodb_getdate($origd=false,$fast=false,$is_gmt=false) +{ +static $YRS; + + $d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff()); + + $_day_power = 86400; + $_hour_power = 3600; + $_min_power = 60; + + if ($d < -12219321600) $d -= 86400*10; // if 15 Oct 1582 or earlier, gregorian correction + + $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31); + $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31); + + $d366 = $_day_power * 366; + $d365 = $_day_power * 365; + + if ($d < 0) { + + if (empty($YRS)) $YRS = array( + 1970 => 0, + 1960 => -315619200, + 1950 => -631152000, + 1940 => -946771200, + 1930 => -1262304000, + 1920 => -1577923200, + 1910 => -1893456000, + 1900 => -2208988800, + 1890 => -2524521600, + 1880 => -2840140800, + 1870 => -3155673600, + 1860 => -3471292800, + 1850 => -3786825600, + 1840 => -4102444800, + 1830 => -4417977600, + 1820 => -4733596800, + 1810 => -5049129600, + 1800 => -5364662400, + 1790 => -5680195200, + 1780 => -5995814400, + 1770 => -6311347200, + 1760 => -6626966400, + 1750 => -6942499200, + 1740 => -7258118400, + 1730 => -7573651200, + 1720 => -7889270400, + 1710 => -8204803200, + 1700 => -8520336000, + 1690 => -8835868800, + 1680 => -9151488000, + 1670 => -9467020800, + 1660 => -9782640000, + 1650 => -10098172800, + 1640 => -10413792000, + 1630 => -10729324800, + 1620 => -11044944000, + 1610 => -11360476800, + 1600 => -11676096000); + + if ($is_gmt) $origd = $d; + // The valid range of a 32bit signed timestamp is typically from + // Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT + // + + # old algorithm iterates through all years. new algorithm does it in + # 10 year blocks + + /* + # old algo + for ($a = 1970 ; --$a >= 0;) { + $lastd = $d; + + if ($leaf = _adodb_is_leap_year($a)) $d += $d366; + else $d += $d365; + + if ($d >= 0) { + $year = $a; + break; + } + } + */ + + $lastsecs = 0; + $lastyear = 1970; + foreach($YRS as $year => $secs) { + if ($d >= $secs) { + $a = $lastyear; + break; + } + $lastsecs = $secs; + $lastyear = $year; + } + + $d -= $lastsecs; + if (!isset($a)) $a = $lastyear; + + //echo ' yr=',$a,' ', $d,'.'; + + for (; --$a >= 0;) { + $lastd = $d; + + if ($leaf = _adodb_is_leap_year($a)) $d += $d366; + else $d += $d365; + + if ($d >= 0) { + $year = $a; + break; + } + } + /**/ + + $secsInYear = 86400 * ($leaf ? 366 : 365) + $lastd; + + $d = $lastd; + $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal; + for ($a = 13 ; --$a > 0;) { + $lastd = $d; + $d += $mtab[$a] * $_day_power; + if ($d >= 0) { + $month = $a; + $ndays = $mtab[$a]; + break; + } + } + + $d = $lastd; + $day = $ndays + ceil(($d+1) / ($_day_power)); + + $d += ($ndays - $day+1)* $_day_power; + $hour = floor($d/$_hour_power); + + } else { + for ($a = 1970 ;; $a++) { + $lastd = $d; + + if ($leaf = _adodb_is_leap_year($a)) $d -= $d366; + else $d -= $d365; + if ($d < 0) { + $year = $a; + break; + } + } + $secsInYear = $lastd; + $d = $lastd; + $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal; + for ($a = 1 ; $a <= 12; $a++) { + $lastd = $d; + $d -= $mtab[$a] * $_day_power; + if ($d < 0) { + $month = $a; + $ndays = $mtab[$a]; + break; + } + } + $d = $lastd; + $day = ceil(($d+1) / $_day_power); + $d = $d - ($day-1) * $_day_power; + $hour = floor($d /$_hour_power); + } + + $d -= $hour * $_hour_power; + $min = floor($d/$_min_power); + $secs = $d - $min * $_min_power; + if ($fast) { + return array( + 'seconds' => $secs, + 'minutes' => $min, + 'hours' => $hour, + 'mday' => $day, + 'mon' => $month, + 'year' => $year, + 'yday' => floor($secsInYear/$_day_power), + 'leap' => $leaf, + 'ndays' => $ndays + ); + } + + + $dow = adodb_dow($year,$month,$day); + + return array( + 'seconds' => $secs, + 'minutes' => $min, + 'hours' => $hour, + 'mday' => $day, + 'wday' => $dow, + 'mon' => $month, + 'year' => $year, + 'yday' => floor($secsInYear/$_day_power), + 'weekday' => gmdate('l',$_day_power*(3+$dow)), + 'month' => gmdate('F',mktime(0,0,0,$month,2,1971)), + 0 => $origd + ); +} + +function adodb_gmdate($fmt,$d=false) +{ + return adodb_date($fmt,$d,true); +} + +// accepts unix timestamp and iso date format in $d +function adodb_date2($fmt, $d=false, $is_gmt=false) +{ + if ($d !== false) { + if (!preg_match( + "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ -]?(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|", + ($d), $rr)) return adodb_date($fmt,false,$is_gmt); + + if ($rr[1] <= 100 && $rr[2]<= 1) return adodb_date($fmt,false,$is_gmt); + + // h-m-s-MM-DD-YY + if (!isset($rr[5])) $d = adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]); + else $d = @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]); + } + + return adodb_date($fmt,$d,$is_gmt); +} + + +/** + Return formatted date based on timestamp $d +*/ +function adodb_date($fmt,$d=false,$is_gmt=false) +{ +static $daylight; + + if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt); + if (!defined('ADODB_TEST_DATES')) { + if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range + if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer + return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d); + + } + } + $_day_power = 86400; + + $arr = _adodb_getdate($d,true,$is_gmt); + + if (!isset($daylight)) $daylight = function_exists('adodb_daylight_sv'); + if ($daylight) adodb_daylight_sv($arr, $is_gmt); + + $year = $arr['year']; + $month = $arr['mon']; + $day = $arr['mday']; + $hour = $arr['hours']; + $min = $arr['minutes']; + $secs = $arr['seconds']; + + $max = strlen($fmt); + $dates = ''; + + /* + at this point, we have the following integer vars to manipulate: + $year, $month, $day, $hour, $min, $secs + */ + for ($i=0; $i < $max; $i++) { + switch($fmt[$i]) { + case 'T': $dates .= date('T');break; + // YEAR + case 'L': $dates .= $arr['leap'] ? '1' : '0'; break; + case 'r': // Thu, 21 Dec 2000 16:01:07 +0200 + + // 4.3.11 uses '04 Jun 2004' + // 4.3.8 uses ' 4 Jun 2004' + $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))).', ' + . ($day<10?'0'.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' '; + + if ($hour < 10) $dates .= '0'.$hour; else $dates .= $hour; + + if ($min < 10) $dates .= ':0'.$min; else $dates .= ':'.$min; + + if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs; + + $gmt = adodb_get_gmt_diff(); + $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; + + case 'Y': $dates .= $year; break; + case 'y': $dates .= substr($year,strlen($year)-2,2); break; + // MONTH + case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break; + case 'Q': $dates .= ($month+3)>>2; break; + case 'n': $dates .= $month; break; + case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break; + case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break; + // DAY + case 't': $dates .= $arr['ndays']; break; + case 'z': $dates .= $arr['yday']; break; + case 'w': $dates .= adodb_dow($year,$month,$day); break; + case 'l': $dates .= gmdate('l',$_day_power*(3+adodb_dow($year,$month,$day))); break; + case 'D': $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))); break; + case 'j': $dates .= $day; break; + case 'd': if ($day<10) $dates .= '0'.$day; else $dates .= $day; break; + case 'S': + $d10 = $day % 10; + if ($d10 == 1) $dates .= 'st'; + else if ($d10 == 2 && $day != 12) $dates .= 'nd'; + else if ($d10 == 3) $dates .= 'rd'; + else $dates .= 'th'; + break; + + // HOUR + case 'Z': + $dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff(); break; + case 'O': + $gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff(); + $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; + + case 'H': + if ($hour < 10) $dates .= '0'.$hour; + else $dates .= $hour; + break; + case 'h': + if ($hour > 12) $hh = $hour - 12; + else { + if ($hour == 0) $hh = '12'; + else $hh = $hour; + } + + if ($hh < 10) $dates .= '0'.$hh; + else $dates .= $hh; + break; + + case 'G': + $dates .= $hour; + break; + + case 'g': + if ($hour > 12) $hh = $hour - 12; + else { + if ($hour == 0) $hh = '12'; + else $hh = $hour; + } + $dates .= $hh; + break; + // MINUTES + case 'i': if ($min < 10) $dates .= '0'.$min; else $dates .= $min; break; + // SECONDS + case 'U': $dates .= $d; break; + case 's': if ($secs < 10) $dates .= '0'.$secs; else $dates .= $secs; break; + // AM/PM + // Note 00:00 to 11:59 is AM, while 12:00 to 23:59 is PM + case 'a': + if ($hour>=12) $dates .= 'pm'; + else $dates .= 'am'; + break; + case 'A': + if ($hour>=12) $dates .= 'PM'; + else $dates .= 'AM'; + break; + default: + $dates .= $fmt[$i]; break; + // ESCAPE + case "\\": + $i++; + if ($i < $max) $dates .= $fmt[$i]; + break; + } + } + return $dates; +} + +/** + Returns a timestamp given a GMT/UTC time. + Note that $is_dst is not implemented and is ignored. +*/ +function adodb_gmmktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=false) +{ + return adodb_mktime($hr,$min,$sec,$mon,$day,$year,$is_dst,true); +} + +/** + Return a timestamp given a local time. Originally by jackbbs. + Note that $is_dst is not implemented and is ignored. + + Not a very fast algorithm - O(n) operation. Could be optimized to O(1). +*/ +function adodb_mktime($hr = null, $min = null, $sec = null, $mon = null, $day = null, $year = null,$is_dst=false,$is_gmt=false) +{ + if( !isset($hr) ) $hr = adodb_date('H'); + if( !isset($min) ) $min = adodb_date('i'); + if( !isset($sec) ) $sec = adodb_date('s'); + if( !isset($mon) ) $mon = adodb_date('m'); + if( !isset($day) ) $day = adodb_date('d'); + if( !isset($year) ) $year = adodb_date('Y'); + + if (!defined('ADODB_TEST_DATES')) { + + if ($mon === false || !isset($mon) ) { + return $is_gmt? @gmmktime($hr,$min,$sec): @mktime($hr,$min,$sec); + } + + // for windows, we don't check 1970 because with timezone differences, + // 1 Jan 1970 could generate negative timestamp, which is illegal + if (1971 < $year && $year < 2038 + || !defined('ADODB_NO_NEGATIVE_TS') && (1901 < $year && $year < 2038) + ) { + return $is_gmt ? + @gmmktime($hr,$min,$sec,$mon,$day,$year): + @mktime($hr,$min,$sec,$mon,$day,$year); + } + } + + $gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff(); + + /* + # disabled because some people place large values in $sec. + # however we need it for $mon because we use an array... + $hr = intval($hr); + $min = intval($min); + $sec = intval($sec); + */ + $mon = intval($mon); + $day = intval($day); + $year = intval($year); + + + $year = adodb_year_digit_check($year); + + if ($mon > 12) { + $y = floor($mon / 12); + $year += $y; + $mon -= $y*12; + } else if ($mon < 1) { + $y = ceil((1-$mon) / 12); + $year -= $y; + $mon += $y*12; + } + + $_day_power = 86400; + $_hour_power = 3600; + $_min_power = 60; + + $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31); + $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31); + + $_total_date = 0; + if ($year >= 1970) { + for ($a = 1970 ; $a <= $year; $a++) { + $leaf = _adodb_is_leap_year($a); + if ($leaf == true) { + $loop_table = $_month_table_leaf; + $_add_date = 366; + } else { + $loop_table = $_month_table_normal; + $_add_date = 365; + } + if ($a < $year) { + $_total_date += $_add_date; + } else { + for($b=1;$b<$mon;$b++) { + $_total_date += $loop_table[$b]; + } + } + } + $_total_date +=$day-1; + $ret = $_total_date * $_day_power + $hr * $_hour_power + $min * $_min_power + $sec + $gmt_different; + + } else { + for ($a = 1969 ; $a >= $year; $a--) { + $leaf = _adodb_is_leap_year($a); + if ($leaf == true) { + $loop_table = $_month_table_leaf; + $_add_date = 366; + } else { + $loop_table = $_month_table_normal; + $_add_date = 365; + } + if ($a > $year) { $_total_date += $_add_date; + } else { + for($b=12;$b>$mon;$b--) { + $_total_date += $loop_table[$b]; + } + } + } + $_total_date += $loop_table[$mon] - $day; + + $_day_time = $hr * $_hour_power + $min * $_min_power + $sec; + $_day_time = $_day_power - $_day_time; + $ret = -( $_total_date * $_day_power + $_day_time - $gmt_different); + if ($ret < -12220185600) $ret += 10*86400; // if earlier than 5 Oct 1582 - gregorian correction + else if ($ret < -12219321600) $ret = -12219321600; // if in limbo, reset to 15 Oct 1582. + } + //print " dmy=$day/$mon/$year $hr:$min:$sec => " .$ret; + return $ret; +} + +function adodb_gmstrftime($fmt, $ts=false) +{ + return adodb_strftime($fmt,$ts,true); +} + +// hack - convert to adodb_date +function adodb_strftime($fmt, $ts=false,$is_gmt=false) +{ +global $ADODB_DATE_LOCALE; + + if (!defined('ADODB_TEST_DATES')) { + if ((abs($ts) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range + if (!defined('ADODB_NO_NEGATIVE_TS') || $ts >= 0) // if windows, must be +ve integer + return ($is_gmt)? @gmstrftime($fmt,$ts): @strftime($fmt,$ts); + + } + } + + if (empty($ADODB_DATE_LOCALE)) { + $tstr = strtoupper(gmstrftime('%c',31366800)); // 30 Dec 1970, 1 am + $sep = substr($tstr,2,1); + $hasAM = strrpos($tstr,'M') !== false; + + $ADODB_DATE_LOCALE = array(); + $ADODB_DATE_LOCALE[] = strncmp($tstr,'30',2) == 0 ? 'd'.$sep.'m'.$sep.'y' : 'm'.$sep.'d'.$sep.'y'; + $ADODB_DATE_LOCALE[] = ($hasAM) ? 'h:i:s a' : 'H:i:s'; + + } + $inpct = false; + $fmtdate = ''; + for ($i=0,$max = strlen($fmt); $i < $max; $i++) { + $ch = $fmt[$i]; + if ($ch == '%') { + if ($inpct) { + $fmtdate .= '%'; + $inpct = false; + } else + $inpct = true; + } else if ($inpct) { + + $inpct = false; + switch($ch) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'E': + case 'O': + /* ignore format modifiers */ + $inpct = true; + break; + + case 'a': $fmtdate .= 'D'; break; + case 'A': $fmtdate .= 'l'; break; + case 'h': + case 'b': $fmtdate .= 'M'; break; + case 'B': $fmtdate .= 'F'; break; + case 'c': $fmtdate .= $ADODB_DATE_LOCALE[0].$ADODB_DATE_LOCALE[1]; break; + case 'C': $fmtdate .= '\C?'; break; // century + case 'd': $fmtdate .= 'd'; break; + case 'D': $fmtdate .= 'm/d/y'; break; + case 'e': $fmtdate .= 'j'; break; + case 'g': $fmtdate .= '\g?'; break; //? + case 'G': $fmtdate .= '\G?'; break; //? + case 'H': $fmtdate .= 'H'; break; + case 'I': $fmtdate .= 'h'; break; + case 'j': $fmtdate .= '?z'; $parsej = true; break; // wrong as j=1-based, z=0-basd + case 'm': $fmtdate .= 'm'; break; + case 'M': $fmtdate .= 'i'; break; + case 'n': $fmtdate .= "\n"; break; + case 'p': $fmtdate .= 'a'; break; + case 'r': $fmtdate .= 'h:i:s a'; break; + case 'R': $fmtdate .= 'H:i:s'; break; + case 'S': $fmtdate .= 's'; break; + case 't': $fmtdate .= "\t"; break; + case 'T': $fmtdate .= 'H:i:s'; break; + case 'u': $fmtdate .= '?u'; $parseu = true; break; // wrong strftime=1-based, date=0-basde + case 'U': $fmtdate .= '?U'; $parseU = true; break;// wrong strftime=1-based, date=0-based + case 'x': $fmtdate .= $ADODB_DATE_LOCALE[0]; break; + case 'X': $fmtdate .= $ADODB_DATE_LOCALE[1]; break; + case 'w': $fmtdate .= '?w'; $parseu = true; break; // wrong strftime=1-based, date=0-basde + case 'W': $fmtdate .= '?W'; $parseU = true; break;// wrong strftime=1-based, date=0-based + case 'y': $fmtdate .= 'y'; break; + case 'Y': $fmtdate .= 'Y'; break; + case 'Z': $fmtdate .= 'T'; break; + } + } else if (('A' <= ($ch) && ($ch) <= 'Z' ) || ('a' <= ($ch) && ($ch) <= 'z' )) + $fmtdate .= "\\".$ch; + else + $fmtdate .= $ch; + } + //echo "fmt=",$fmtdate,"
"; + if ($ts === false) $ts = time(); + $ret = adodb_date($fmtdate, $ts, $is_gmt); + return $ret; +} + + +?> \ No newline at end of file Index: trunk/admin/users/addgroup.php =================================================================== diff -u -r2853 -r3282 --- trunk/admin/users/addgroup.php (.../addgroup.php) (revision 2853) +++ trunk/admin/users/addgroup.php (.../addgroup.php) (revision 3282) @@ -38,8 +38,8 @@ if ($_GET["new"] == 1) { $c = new clsPortalGroup(NULL); - $c->Set("CreatedOn", time()); - $c->Set("EndOn", time()); + $c->Set("CreatedOn", adodb_mktime()); + $c->Set("EndOn", adodb_mktime()); $en = 0; $action = "m_add_group"; $objGroups->CreateEmptyEditTable("GroupId"); Index: trunk/admin/backup/restore2.php =================================================================== diff -u -r2853 -r3282 --- trunk/admin/backup/restore2.php (.../restore2.php) (revision 2853) +++ trunk/admin/backup/restore2.php (.../restore2.php) (revision 3282) @@ -135,7 +135,7 @@ $onClick = "swap('moveright', 'toolbar/tool_next.gif');"; echo ""; - echo date("F j, Y, g:i a",$value).""; + echo adodb_date("F j, Y, g:i a",$value).""; } ?> Index: trunk/admin/index.php =================================================================== diff -u -r3021 -r3282 --- trunk/admin/index.php (.../index.php) (revision 3021) +++ trunk/admin/index.php (.../index.php) (revision 3282) @@ -100,7 +100,7 @@ if (!admin_login() || GetVar('logout') || GetVar('expired') ) { - if( !headers_sent() ) set_cookie(SESSION_COOKIE_NAME, '', time() - 3600); + if( !headers_sent() ) set_cookie(SESSION_COOKIE_NAME, '', adodb_mktime() - 3600); $objSession->Logout(); require_once($pathtoroot.$admin.'/login.php'); } Index: trunk/admin/users/banuser.php =================================================================== diff -u -r2853 -r3282 --- trunk/admin/users/banuser.php (.../banuser.php) (revision 2853) +++ trunk/admin/users/banuser.php (.../banuser.php) (revision 3282) @@ -36,7 +36,7 @@ if ($_GET["new"] == 1) { $c = new clsPortalUser(NULL); - $c->Set("CreatedOn", time()); + $c->Set("CreatedOn", adodb_mktime()); $c->Set("Status", 2); $en = 0; $action = "m_ban_user"; Index: trunk/kernel/startup.php =================================================================== diff -u -r3216 -r3282 --- trunk/kernel/startup.php (.../startup.php) (revision 3216) +++ trunk/kernel/startup.php (.../startup.php) (revision 3282) @@ -90,7 +90,7 @@ LogEntry("Initalizing System..\n"); /* for 64 bit timestamps */ -require_once(FULL_PATH.'/kernel/include/adodb/adodb-time.inc.php'); +if( !function_exists('adodb_mktime') ) require_once(FULL_PATH.'/kernel/include/adodb/adodb-time.inc.php'); require_once(FULL_PATH.'/kernel/include/dates.php'); /* create the global error object */ Index: trunk/kernel/units/categories/categories_item.php =================================================================== diff -u -r2591 -r3282 --- trunk/kernel/units/categories/categories_item.php (.../categories_item.php) (revision 2591) +++ trunk/kernel/units/categories/categories_item.php (.../categories_item.php) (revision 3282) @@ -8,8 +8,8 @@ $this->SetDBField('ResourceId', $this->Application->NextResourceId()); $this->SetDBField('CreatedById', $this->Application->GetVar('u_id') ); - $this->SetDBField('CreatedOn_date', time() ); - $this->SetDBField('CreatedOn_time', time() ); + $this->SetDBField('CreatedOn_date', adodb_mktime() ); + $this->SetDBField('CreatedOn_time', adodb_mktime() ); $this->SetDBField('ParentId', $this->Application->GetVar('m_cat_id') ); $ret = parent::Create(); Index: trunk/kernel/include/category.php =================================================================== diff -u -r3268 -r3282 --- trunk/kernel/include/category.php (.../category.php) (revision 3268) +++ trunk/kernel/include/category.php (.../category.php) (revision 3282) @@ -40,8 +40,8 @@ function StripDisallowed($string) { - $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', - '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', + $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`', + '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~', '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ','); $string = str_replace($not_allowed, '_', $string); @@ -87,8 +87,16 @@ function GenerateFilename() { - if ( !$this->Get('AutomaticFilename') && $this->Get('Filename') ) return false; - $name = $this->StripDisallowed( $this->Get('Name') ); + if ( !$this->Get('AutomaticFilename') && $this->Get('Filename') ) + { + $name = $this->Get('Filename'); + } + else + { + $name = $this->Get('Name'); + } + $name = $this->StripDisallowed($name); + if ( $name != $this->Get('Filename') ) $this->Set('Filename', $name); } @@ -157,7 +165,7 @@ function Create() { - if( (int)$this->Get('CreatedOn') == 0 ) $this->Set('CreatedOn', date('U') ); + if( (int)$this->Get('CreatedOn') == 0 ) $this->Set('CreatedOn', adodb_date('U') ); parent::Create(); $this->GenerateFilename(); @@ -1572,7 +1580,7 @@ } if( getArrayValue($attribs,'_today') ) { - $today = mktime(0,0,0,date("m"),date("d"),date("Y")); + $today = adodb_mktime(0,0,0,adodb_date("m"),adodb_date("d"),adodb_date("Y")); $TodayWhere = "(CreatedOn>=$today)"; } else Index: trunk/core/kernel/utility/email.php =================================================================== diff -u -r3216 -r3282 --- trunk/core/kernel/utility/email.php (.../email.php) (revision 3216) +++ trunk/core/kernel/utility/email.php (.../email.php) (revision 3282) @@ -30,8 +30,8 @@ var $EmailBoundary; function kEmailMessage(){ - //$this->TextBoundary = uniqid(time()); - $this->EmailBoundary = uniqid(time()); + //$this->TextBoundary = uniqid(adodb_mktime()); + $this->EmailBoundary = uniqid(adodb_mktime()); $this->LineFeed = "\n"; $this->Charset='ISO-8859-1'; $this->TransferEncoding='8bit'; Index: trunk/core/kernel/processors/main_processor.php =================================================================== diff -u -r3226 -r3282 --- trunk/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 3226) +++ trunk/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 3282) @@ -337,7 +337,8 @@ unset($params['template']); $env = $this->Application->BuildEnv($t, $params, 'm', null, false); $o = ''; - if (defined('MOD_REWRITE') && MOD_REWRITE) { + if ( $this->Application->RewriteURLs() ) + { $session =& $this->Application->recallObject('Session'); if ($session->NeedQueryString()) { $o .= "\n"; Index: trunk/core/kernel/kbase.php =================================================================== diff -u -r2711 -r3282 --- trunk/core/kernel/kbase.php (.../kbase.php) (revision 2711) +++ trunk/core/kernel/kbase.php (.../kbase.php) (revision 3282) @@ -349,7 +349,7 @@ { if( getArrayValue($options, 'default') === '#NOW#') { - $this->Fields[$field]['default'] = mktime(); + $this->Fields[$field]['default'] = adodb_mktime(); } } }