1 <?php rcs_id('$Id: imagecache.php,v 1.2 2002-08-18 12:34:14 rurban Exp $');
3 Copyright (C) 2002 Johannes Große (Johannes Große)
5 This file is (not yet) part of PhpWiki.
7 PhpWiki is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 PhpWiki is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with PhpWiki; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Gets an image from the cache and prints it to the browser.
23 * This file belongs to WikiPluginCached.
24 * @author Johannes Große
28 include "lib/config.php";
29 include "lib/stdlib.php";
30 //include "lib/logger.php";
31 require_once('lib/Request.php');
32 require_once("lib/WikiUser.php");
33 require_once('lib/WikiDB.php');
35 require_once "lib/WikiPluginCached.php";
37 // -----------------------------------------------------------------------
39 // FIXME: do I need this? What the hell does it?
41 function deduce_pagename ($request) {
42 if ($request->getArg('pagename'))
43 return $request->getArg('pagename');
46 $pathinfo = $request->get('PATH_INFO');
47 if (ereg('^' . PATH_INFO_PREFIX . '(..*)$', $pathinfo, $m))
51 $query_string = $request->get('QUERY_STRING');
52 if (preg_match('/^[^&=]+$/', $query_string))
53 return urldecode($query_string);
55 return gettext("HomePage");
59 * Initializes PhpWiki and calls the plugin specified in the url to
60 * produce an image. Furthermore, allow the usage of Apache's
61 * ErrorDocument mechanism in order to make this file only called when
62 * image could not be found in the cache.
63 * (see doc/README.phpwiki-cache for further information).
65 function mainImageCache() {
66 $request = new Request;
67 //$request->setArg('pagename', deduce_pagename($request));
68 //$pagename = $request->getArg('pagename');
70 // assume that every user may use the cache
71 global $user; // FIXME: necessary ?
72 $user = new WikiUser($request, 'ANON_OK');
74 $dbi = WikiDB::open($GLOBALS['DBParams']);
76 // Enable the output of most of the warning messages.
77 // The warnings will screw up zip files and setpref though.
78 // They will also screw up my images... But I think
79 // we should keep them.
81 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
83 $id = $request->getArg('id');
84 $args = $request->getArg('args');
85 $request->setArg('action', 'imagecache');
88 // this indicates a direct call (script wasn't called as
91 // deduce image id or image args (plugincall) from
94 $uri = $request->get('REDIRECT_URL');
95 $query = $request->get('REDIRECT_QUERY_STRING');
96 $uri .= $query ? '?'.$query : '';
99 $uri = $request->get('REQUEST_URI');
102 WikiPluginCached::printError( 'png',
103 'Could not deduce image identifier or creation'
104 . ' parameters. (Neither REQUEST nor REDIRECT'
108 $cacheparams = $GLOBALS['CacheParams'];
109 if (!preg_match(':^(.*/)?'.$cacheparams['filename_prefix'].'([^\?/]+)\.img(\?args=([^\?&]*))?$:', $uri, $matches)) {
110 WikiPluginCached::printError('png', "I do not understand this URL: $uri");
114 $request->setArg('id',$matches[2]);
116 $request->setArg('args',rawurldecode($matches[4]));
118 $request->setStatus(200); // No, we do _not_ have an Error 404 :->
121 WikiPluginCached::fetchImageFromCache($dbi,$request,'png');
132 // c-hanging-comment-ender-p: nil
133 // indent-tabs-mode: nil