[klutz]Patch to allow caching of Klutz images
Jon Knepher
jbk at wild-e.com
Mon Dec 16 21:37:23 PST 2002
My users like the comics so much, they should cache the images!
I don't know if adding a parameter to Horde::selfURL() is better than using
Horde::url($_SERVER['PHP_SELF']). I think adding the parameter is better,
hoping for more cachable pages later... Should the option for caching the
images be a config option? I have it hard-coded to always send it as cachable.
If you think otherwise, I'll rewrite the patch to fit the horde opinion. :)
Thanks
Jon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-keys
Size: 967 bytes
Desc: PGP Public Key
Url : http://lists.horde.org/archives/klutz/attachments/20021216/77a9c5ed/attachment.bin
-------------- next part --------------
Index: klutz/comics.php
===================================================================
RCS file: /repository/klutz/comics.php,v
retrieving revision 1.28
diff -u -b -B -r1.28 comics.php
--- klutz/comics.php 16 Oct 2002 04:37:15 -0000 1.28
+++ klutz/comics.php 17 Dec 2002 05:05:39 -0000
@@ -65,6 +65,10 @@
$image = $storage->retrieveImage($index, $date);
if (is_object($image)) {
+ header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $date) . ' GMT');
+ header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 172800) . ' GMT');
+ header('Cache-Control: public, max-age=172800');
+ header('Pragma:');
header("Content-type: " . $image->type);
print $image->data;
} elseif (is_string($image) && substr($image, 0, 4) == 'http') {
@@ -144,7 +148,7 @@
$author = $klutz->getProperty($index, 'author');
if ($storage->imageExists($index, $date)) {
$size = $storage->imageSize($index, $date);
- $url = Horde::selfURL();
+ $url = Horde::selfURL(false, false);
$url = Horde::addParameter($url, 'actionID=' . KLUTZ_DISPLAY_IMAGE);
$url = Horde::addParameter($url, "date=$date");
$url = Horde::addParameter($url, "index=$index");
@@ -174,7 +178,7 @@
foreach ($storage->listDates($date) as $date) {
if ($storage->imageExists($index, $date)) {
$size = $storage->imageSize($index, $date);
- $url = Horde::selfURL();
+ $url = Horde::selfURL(false, false);
$url = Horde::addParameter($url, 'actionID=' . KLUTZ_DISPLAY_IMAGE);
$url = Horde::addParameter($url, "date=$date");
$url = Horde::addParameter($url, "index=$index");
Index: klutz/config/comics.php.dist
===================================================================
RCS file: /repository/klutz/config/comics.php.dist,v
retrieving revision 1.18
diff -u -b -B -r1.18 comics.php.dist
--- klutz/config/comics.php.dist 22 Nov 2002 15:33:50 -0000 1.18
+++ klutz/config/comics.php.dist 17 Dec 2002 05:05:39 -0000
@@ -684,5 +684,15 @@
'method' => 'direct',
'url' =>'http://www.slagoon.com/dailies/SL{%y}.{%m}.{%d}.gif',
'enabled' => true
+ ),
+
+ 'ohmygods' => array(
+ 'name' => 'Oh My Gods!',
+ 'author' => 'Shivian',
+ 'method' => 'direct',
+ 'homepage' => 'http://ohmygods.timerift.net/',
+ 'url' => 'http://ohmygods.timerift.net/strips/{%Y}/{%m}/{%d}.gif',
+ 'enabled' => true
)
+
);
Index: lib/Horde.php
===================================================================
RCS file: /repository/horde/lib/Horde.php,v
retrieving revision 1.219
diff -u -b -B -r1.219 Horde.php
--- lib/Horde.php 13 Dec 2002 14:02:44 -0000 1.219
+++ lib/Horde.php 17 Dec 2002 05:05:53 -0000
@@ -535,9 +535,13 @@
* @param optional boolean $query_string Include any QUERY_STRING?
* Defaults to no.
*
+ * @param optional boolean $nocache If the broswer requires it,
+ * should we include a nocache
+ * query. Defaults to yes.
+ *
* @return string The requested URI.
*/
- function selfURL($query_string = false)
+ function selfURL($query_string = false, $nocache = true)
{
global $browser;
if (is_null($browser)) {
@@ -555,7 +559,7 @@
/* We may need to set a dummy parameter 'nocache' since some browsers
do not always honor the 'no-cache' header. */
- if ($browser->hasQuirk('cache_same_url')) {
+ if ($nocache && $browser->hasQuirk('cache_same_url')) {
return Horde::addParameter($url, 'nocache=' . uniqid(rand()));
} else {
return $url;
More information about the klutz
mailing list