1 <?php // $Id: imagecache.php 8071 2011-05-18 14:56:14Z vargenau $
3 * Copyright (C) 2002 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 along
18 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Gets an image from the cache and prints it to the browser.
24 * This file belongs to WikiPluginCached.
25 * @author Johannes Große
29 include_once 'lib/config.php';
30 require_once(dirname(__FILE__)."/stdlib.php");
31 require_once 'lib/Request.php';
32 if (ENABLE_USER_NEW) require_once("lib/WikiUserNew.php");
33 else require_once("lib/WikiUser.php");
34 require_once 'lib/WikiDB.php';
36 require_once 'lib/WikiPluginCached.php';
38 // -----------------------------------------------------------------------
40 function deducePagename ($request) {
41 if ($request->getArg('pagename'))
42 return $request->getArg('pagename');
45 $pathinfo = $request->get('PATH_INFO');
46 $tail = substr($pathinfo, strlen(PATH_INFO_PREFIX));
47 if ($tail != '' and $pathinfo == PATH_INFO_PREFIX . $tail) {
51 elseif ($this->isPost()) {
52 global $HTTP_GET_VARS;
53 if (isset($HTTP_GET_VARS['pagename'])) {
54 return $HTTP_GET_VARS['pagename'];
58 $query_string = $request->get('QUERY_STRING');
59 if (preg_match('/^[^&=]+$/', $query_string))
60 return urldecode($query_string);
65 function deduceUsername() {
66 global $request, $HTTP_SERVER_VARS, $HTTP_ENV_VARS;
67 if (!empty($request->args['auth']) and !empty($request->args['auth']['userid']))
68 return $request->args['auth']['userid'];
69 if (!empty($HTTP_SERVER_VARS['PHP_AUTH_USER']))
70 return $HTTP_SERVER_VARS['PHP_AUTH_USER'];
71 if (!empty($HTTP_ENV_VARS['REMOTE_USER']))
72 return $HTTP_ENV_VARS['REMOTE_USER'];
74 if ($user = $request->getSessionVar('wiki_user')) {
75 $request->_user = $user;
76 $request->_user->_authhow = 'session';
77 return ENABLE_USER_NEW ? $user->UserName() : $request->_user;
79 if ($userid = $request->getCookieVar(getCookieName())) {
80 if (!empty($userid) and substr($userid,0,2) != 's:') {
81 $request->_user->authhow = 'cookie';
89 * Initializes PhpWiki and calls the plugin specified in the url to
90 * produce an image. Furthermore, allow the usage of Apache's
91 * ErrorDocument mechanism in order to make this file only called when
92 * image could not be found in the cache.
93 * (see doc/README.phpwiki-cache for further information).
95 function mainImageCache() {
96 $request = new Request;
98 $request->setArg('pagename', deducePagename($request));
99 $pagename = $request->getArg('pagename');
100 $request->_dbi = WikiDB::open($GLOBALS['DBParams']);
101 if (ENABLE_USER_NEW) {
102 $request->_user = new _AnonUser();
103 $request->_prefs =& $request->_user->_prefs;
105 $request->_user = new WikiUser($request);
106 $request->_prefs = new UserPreferences();
109 // Enable the output of most of the warning messages.
110 // The warnings will screw up zip files and setpref though.
111 // They will also screw up my images... But I think
112 // we should keep them.
113 global $ErrorManager;
114 $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
116 $id = $request->getArg('id');
117 $args = $request->getArg('args');
118 $request->setArg('action', 'imagecache');
119 $cache = new WikiPluginCached;
122 // this indicates a direct call (script wasn't called as
123 // 404 ErrorDocument)
125 // deduce image id or image args (plugincall) from
128 $uri = $request->get('REDIRECT_URL');
129 $query = $request->get('REDIRECT_QUERY_STRING');
130 $uri .= $query ? '?'.$query : '';
133 $uri = $request->get('REQUEST_URI');
136 $cache->printError( 'png',
137 'Could not deduce image identifier or creation'
138 . ' parameters. (Neither REQUEST nor REDIRECT'
142 //$cacheparams = $GLOBALS['CacheParams'];
143 if (!preg_match(':^(.*/)?'.PLUGIN_CACHED_FILENAME_PREFIX.'([^\?/]+)\.img(\?args=([^\?&]*))?$:', $uri, $matches)) {
144 $cache->printError('png', "I do not understand this URL: $uri");
148 $request->setArg('id', $matches[2]);
151 $request->setArg('args', rawurldecode($matches[4]));
153 $request->setStatus(200); // No, we do _not_ have an Error 404 :->
156 $cache->fetchImageFromCache($request->_dbi, $request, 'png');
167 // c-hanging-comment-ender-p: nil
168 // indent-tabs-mode: nil