1 <?php rcs_id('$Id: imagecache.php,v 1.7 2004-06-03 09:40:57 rurban Exp $');
3 Copyright (C) 2002 Johannes Große (Johannes Große)
5 This file is 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_once("lib/config.php");
29 require_once(dirname(__FILE__)."/stdlib.php");
30 require_once('lib/Request.php');
31 if (ENABLE_USER_NEW) require_once("lib/WikiUserNew.php");
32 else require_once("lib/WikiUser.php");
33 require_once('lib/WikiDB.php');
35 require_once "lib/WikiPluginCached.php";
37 // -----------------------------------------------------------------------
39 function deducePagename ($request) {
40 if ($request->getArg('pagename'))
41 return $request->getArg('pagename');
44 $pathinfo = $request->get('PATH_INFO');
45 $tail = substr($pathinfo, strlen(PATH_INFO_PREFIX));
46 if ($tail != '' and $pathinfo == PATH_INFO_PREFIX . $tail) {
50 elseif ($this->isPost()) {
51 global $HTTP_GET_VARS;
52 if (isset($HTTP_GET_VARS['pagename'])) {
53 return $HTTP_GET_VARS['pagename'];
57 $query_string = $request->get('QUERY_STRING');
58 if (preg_match('/^[^&=]+$/', $query_string))
59 return urldecode($query_string);
64 function deduceUsername() {
65 global $request, $HTTP_SERVER_VARS, $HTTP_ENV_VARS;
66 if (!empty($request->args['auth']) and !empty($request->args['auth']['userid']))
67 return $request->args['auth']['userid'];
68 if (!empty($HTTP_SERVER_VARS['PHP_AUTH_USER']))
69 return $HTTP_SERVER_VARS['PHP_AUTH_USER'];
70 if (!empty($HTTP_ENV_VARS['REMOTE_USER']))
71 return $HTTP_ENV_VARS['REMOTE_USER'];
73 if ($user = $request->getSessionVar('wiki_user')) {
74 $request->_user = $user;
75 $request->_user->_authhow = 'session';
76 return ENABLE_USER_NEW ? $user->UserName() : $request->_user;
78 if ($userid = $request->getCookieVar('WIKI_ID')) {
79 if (!empty($userid) and substr($userid,0,2) != 's:') {
80 $request->_user->authhow = 'cookie';
88 * Initializes PhpWiki and calls the plugin specified in the url to
89 * produce an image. Furthermore, allow the usage of Apache's
90 * ErrorDocument mechanism in order to make this file only called when
91 * image could not be found in the cache.
92 * (see doc/README.phpwiki-cache for further information).
94 function mainImageCache() {
95 $request = new Request;
97 $request->setArg('pagename', deducePagename($request));
98 $pagename = $request->getArg('pagename');
99 $request->_dbi = WikiDB::open($GLOBALS['DBParams']);
100 if (ENABLE_USER_NEW) {
101 $request->_user = new _AnonUser();
102 $request->_prefs =& $request->_user->_prefs;
104 $request->_user = new WikiUser($request);
105 $request->_prefs = new UserPreferences();
108 // Enable the output of most of the warning messages.
109 // The warnings will screw up zip files and setpref though.
110 // They will also screw up my images... But I think
111 // we should keep them.
112 global $ErrorManager;
113 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
115 $id = $request->getArg('id');
116 $args = $request->getArg('args');
117 $request->setArg('action', 'imagecache');
120 // this indicates a direct call (script wasn't called as
121 // 404 ErrorDocument)
123 // deduce image id or image args (plugincall) from
126 $uri = $request->get('REDIRECT_URL');
127 $query = $request->get('REDIRECT_QUERY_STRING');
128 $uri .= $query ? '?'.$query : '';
131 $uri = $request->get('REQUEST_URI');
134 WikiPluginCached::printError( 'png',
135 'Could not deduce image identifier or creation'
136 . ' parameters. (Neither REQUEST nor REDIRECT'
140 $cacheparams = $GLOBALS['CacheParams'];
141 if (!preg_match(':^(.*/)?'.$cacheparams['filename_prefix'].'([^\?/]+)\.img(\?args=([^\?&]*))?$:', $uri, $matches)) {
142 WikiPluginCached::printError('png', "I do not understand this URL: $uri");
146 $request->setArg('id',$matches[2]);
148 $request->setArg('args',rawurldecode($matches[4]));
150 $request->setStatus(200); // No, we do _not_ have an Error 404 :->
153 WikiPluginCached::fetchImageFromCache($request->_dbi,$request,'png');
164 // c-hanging-comment-ender-p: nil
165 // indent-tabs-mode: nil