]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/imagecache.php
Disable profiling output when DEBUG is defined but false.
[SourceForge/phpwiki.git] / lib / imagecache.php
1 <?php rcs_id('$Id: imagecache.php,v 1.2 2002-08-18 12:34:14 rurban Exp $');
2 /*
3  Copyright (C) 2002 Johannes Große (Johannes Gro&szlig;e)
4
5  This file is (not yet) part of PhpWiki.
6
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.
11
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.
16
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
20  */ 
21 /**
22  * Gets an image from the cache and prints it to the browser.
23  * This file belongs to WikiPluginCached.
24  * @author  Johannes Große
25  * @version 0.8
26  */
27
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');
34
35 require_once "lib/WikiPluginCached.php";
36
37 // -----------------------------------------------------------------------
38
39 // FIXME: do I need this? What the hell does it? 
40
41 function deduce_pagename ($request) {
42     if ($request->getArg('pagename'))
43         return $request->getArg('pagename');
44
45     if (USE_PATH_INFO) {
46         $pathinfo = $request->get('PATH_INFO');
47         if (ereg('^' . PATH_INFO_PREFIX . '(..*)$', $pathinfo, $m))
48             return $m[1];
49     }
50
51     $query_string = $request->get('QUERY_STRING');
52     if (preg_match('/^[^&=]+$/', $query_string))
53         return urldecode($query_string);
54     
55     return gettext("HomePage");
56 }
57
58 /**
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).
64  */
65 function mainImageCache() {
66     $request = new Request;   
67     //$request->setArg('pagename', deduce_pagename($request));
68     //$pagename = $request->getArg('pagename');
69
70     // assume that every user may use the cache    
71     global $user; // FIXME: necessary ?
72     $user = new WikiUser($request, 'ANON_OK'); 
73
74     $dbi = WikiDB::open($GLOBALS['DBParams']);
75     
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.
80     global $ErrorManager;
81     $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
82
83     $id = $request->getArg('id');
84     $args = $request->getArg('args');
85     $request->setArg('action', 'imagecache');
86
87     if ($id) {
88         // this indicates a direct call (script wasn't called as
89         // 404 ErrorDocument)
90     } else {
91         // deduce image id or image args (plugincall) from
92         // refering URL
93
94         $uri = $request->get('REDIRECT_URL');
95         $query = $request->get('REDIRECT_QUERY_STRING');
96         $uri .= $query ? '?'.$query : '';        
97
98         if (!$uri) {
99             $uri = $request->get('REQUEST_URI');
100         }
101         if (!uri) {
102             WikiPluginCached::printError( 'png', 
103                 'Could not deduce image identifier or creation'
104                 . ' parameters. (Neither REQUEST nor REDIRECT'
105                 . ' obtained.)' ); 
106             return;
107         }    
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");
111             return;
112         }        
113         
114         $request->setArg('id',$matches[2]);
115         if ($matches[4]) {
116            $request->setArg('args',rawurldecode($matches[4]));
117         }
118         $request->setStatus(200); // No, we do _not_ have an Error 404 :->
119     } 
120
121     WikiPluginCached::fetchImageFromCache($dbi,$request,'png');
122 }
123
124
125 mainImageCache();
126
127
128 // Local Variables:
129 // mode: php
130 // tab-width: 8
131 // c-basic-offset: 4
132 // c-hanging-comment-ender-p: nil
133 // indent-tabs-mode: nil
134 // End:   
135 ?>