cvs: php4 /pear/Cache Container.php Output.php /pear/Cache/Container db.php file.php phplib.php
| From: | Christian Stocker | Date: | Thu, 08 Mar 2001 11:57:16 +0000 |
| Subject: | cvs: php4 /pear/Cache Container.php Output.php /pear/Cache/Container db.php file.php phplib.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-4445@lists.php.net to get a copy of this message | ||
chregu Thu Mar 8 03:57:16 2001 EDT
Modified files:
/php4/pear/Cache Container.php Output.php
/php4/pear/Cache/Container db.php file.php phplib.php
Log:
Introduced getExpiresAbsolute($expire) function, which translates
relative/human readable/unixtime expire-times in unixtime-format.
Index: php4/pear/Cache/Container.php
diff -u php4/pear/Cache/Container.php:1.6 php4/pear/Cache/Container.php:1.7
--- php4/pear/Cache/Container.php:1.6 Tue Mar 6 07:27:30 2001
+++ php4/pear/Cache/Container.php Thu Mar 8 03:57:15 2001
@@ -14,9 +14,10 @@
// +----------------------------------------------------------------------+
// | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> |
// | Sebastian Bergmann <sb@sebastian-bergmann.de> |
+// | Christian Stocker <chregu@nomad.ch> |
// +----------------------------------------------------------------------+
//
-// $Id: Container.php,v 1.6 2001/03/06 15:27:30 sbergmann Exp $
+// $Id: Container.php,v 1.7 2001/03/08 11:57:15 chregu Exp $
/**
* Common base class of all cache storage container.
@@ -36,7 +37,7 @@
* not recommended!
*
* @author Ulf Wendel <ulf.wendel@phpdoc.de>
-* @version $Id: Container.php,v 1.6 2001/03/06 15:27:30 sbergmann Exp $
+* @version $Id: Container.php,v 1.7 2001/03/08 11:57:15 chregu Exp $
* @package Cache
* @access public
* @abstract
@@ -372,5 +373,47 @@
else
return unserialize($data);
} // end func decode
+
+ /**
+ * Translates human readable/relative times in unixtime
+ *
+ * @var mixed can be in the following formats:
+ * human readable : yyyymmddhhmm[ss]] eg: 20010308095100
+ * relative in seconds (1) : +xx eg: +10
+ * relative in seconds (2) : x < 946681200 eg: 10
+ * absolute unixtime : x < 2147483648 eg: 2147483648
+ * see comments in code for details
+ */
+
+ function getExpiresAbsolute($expires)
+
+ {
+ if (!$expires)
+ return 0;
+ //for api-compatibility, one has not to provide a "+",
+ // if integer is < 946681200 (= Jan 01 2000 00:00:00)
+ if ('+' == $expires[0] || $expires < 946681200)
+ {
+ return(time() + $expires);
+ }
+ //if integer is < 100000000000 (= in 3140 years),
+ // it must be an absolut unixtime
+ // (since the "human readable" definition asks for a higher number)
+ elseif ($expires < 100000000000)
+ {
+ return $expires;
+ }
+ // else it's "human readable";
+ else
+ {
+ $year = substr($expires, 0, 4);
+ $month = substr($expires, 4, 2);
+ $day = substr($expires, 6, 2);
+ $hour = substr($expires, 8, 2);
+ $minute = substr($expires, 10, 2);
+ $second = substr($expires, 12, 2);
+ return mktime($hour, $minute, $second, $month, $day, $year);
+ }
+ }
}
?>
Index: php4/pear/Cache/Output.php
diff -u php4/pear/Cache/Output.php:1.9 php4/pear/Cache/Output.php:1.10
--- php4/pear/Cache/Output.php:1.9 Tue Mar 6 07:27:30 2001
+++ php4/pear/Cache/Output.php Thu Mar 8 03:57:15 2001
@@ -17,7 +17,7 @@
// | Vinai Kopp <kopp@netzarbeiter.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Output.php,v 1.9 2001/03/06 15:27:30 sbergmann Exp $
+// $Id: Output.php,v 1.10 2001/03/08 11:57:15 chregu Exp $
require_once 'Cache.php';
@@ -129,11 +129,11 @@
/*
* Stores the content of the output buffer into the cache and returns the content.
*
- * @param integer lifetime of the cached data in seconds - 0 for endless
+ * @param mixed lifetime of the cached data in seconds - 0 for endless. More formats
available. see Container::getExpiresAbsolute()
* @param string additional userdefined data
* @return string cached output
* @access public
- * @see endPrint(), endGet()
+ * @see endPrint(), endGet(), Container::getExpiresAbsolute()
*/
function end($expire = 0, $userdata = "") {
$content = ob_get_contents();
Index: php4/pear/Cache/Container/db.php
diff -u php4/pear/Cache/Container/db.php:1.7 php4/pear/Cache/Container/db.php:1.8
--- php4/pear/Cache/Container/db.php:1.7 Tue Mar 6 07:27:30 2001
+++ php4/pear/Cache/Container/db.php Thu Mar 8 03:57:16 2001
@@ -17,7 +17,7 @@
// | Chuck Hagenbuch <chuck@horde.org> |
// +----------------------------------------------------------------------+
//
-// $Id: db.php,v 1.7 2001/03/06 15:27:30 sbergmann Exp $
+// $Id: db.php,v 1.8 2001/03/08 11:57:16 chregu Exp $
require_once 'DB.php';
require_once 'Cache/Container.php';
@@ -52,7 +52,7 @@
* )
*
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
-* @version $Id: db.php,v 1.7 2001/03/06 15:27:30 sbergmann Exp $
+* @version $Id: db.php,v 1.8 2001/03/08 11:57:16 chregu Exp $
* @package Cache
*/
class Cache_Container_db extends Cache_Container {
@@ -131,7 +131,7 @@
$this->cache_table,
addslashes($userdata),
addslashes($this->encode($data)),
- ($expires) ? $expires + time() : 0,
+ $this->getExpiresAbsolute($expires) ,
addslashes($id),
addslashes($group)
);
Index: php4/pear/Cache/Container/file.php
diff -u php4/pear/Cache/Container/file.php:1.6 php4/pear/Cache/Container/file.php:1.7
--- php4/pear/Cache/Container/file.php:1.6 Tue Mar 6 07:27:30 2001
+++ php4/pear/Cache/Container/file.php Thu Mar 8 03:57:16 2001
@@ -16,7 +16,7 @@
// | Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: file.php,v 1.6 2001/03/06 15:27:30 sbergmann Exp $
+// $Id: file.php,v 1.7 2001/03/08 11:57:16 chregu Exp $
require_once 'Cache/Container.php';
@@ -24,7 +24,7 @@
* Stores cache contents in a file.
*
* @author Ulf Wendel <ulf.wendel@phpdoc.de>
-* @version $Id: file.php,v 1.6 2001/03/06 15:27:30 sbergmann Exp $
+* @version $Id: file.php,v 1.7 2001/03/08 11:57:16 chregu Exp $
*/
class Cache_Container_file extends Cache_Container {
@@ -107,7 +107,7 @@
// 1st line: expiration date
// 2nd line: user data
// 3rd+ lines: cache data
- $expires = ($expires) ? $expires + time() : 0;
+ $expires = $this->getExpiresAbsolute($expires);
fwrite($fh, $expires . "\n");
fwrite($fh, $userdata . "\n");
fwrite($fh, $this->encode($cachedata));
Index: php4/pear/Cache/Container/phplib.php
diff -u php4/pear/Cache/Container/phplib.php:1.8 php4/pear/Cache/Container/phplib.php:1.9
--- php4/pear/Cache/Container/phplib.php:1.8 Tue Mar 6 07:27:30 2001
+++ php4/pear/Cache/Container/phplib.php Thu Mar 8 03:57:16 2001
@@ -16,7 +16,7 @@
// | Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: phplib.php,v 1.8 2001/03/06 15:27:30 sbergmann Exp $
+// $Id: phplib.php,v 1.9 2001/03/08 11:57:16 chregu Exp $
require_once 'Cache/Container.php';
@@ -51,7 +51,7 @@
*
*
* @author Ulf Wendel <ulf.wendel@phpdoc.de>, Sebastian Bergmann
<sb@sebastian-bergmann.de>
-* @version $Id: phplib.php,v 1.8 2001/03/06 15:27:30 sbergmann Exp $
+* @version $Id: phplib.php,v 1.9 2001/03/08 11:57:16 chregu Exp $
* @package Cache
* @see save()
*/
@@ -161,7 +161,7 @@
$query = sprintf("REPLACE INTO %s (cachedata, expires, id, cachegroup) VALUES
('%s', %d, '%s', '%s')",
$this->cache_table,
addslashes($this->encode($data)),
- ($expires) ? $expires + time() : 0,
+ $this->getExpiresAbsolute($expires) ,
$id,
$group
);