]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/imagecache.php
added SubPages support: see SUBPAGE_SEPERATOR in index.php
[SourceForge/phpwiki.git] / lib / imagecache.php
1 <?php // -*-php-*-
2 // +---------------------------------------------------------------------+
3 // | imagecache.php                                                      |
4 // +---------------------------------------------------------------------+
5 // | Copyright (C) 2002 Johannes Große (Johannes Gro&szlig;e)            |
6 // | You may copy this code freely under the conditions of the GPL       |
7 // +---------------------------------------------------------------------+
8
9 /**
10  * Gets an image from the cache and prints it to the browser.
11  * This file belongs to WikiPluginCached.
12  * @author  Johannes Große
13  * @version 0.8
14  */
15
16 include "lib/config.php";
17 include "lib/stdlib.php";
18 //include "lib/logger.php";
19 require_once('lib/Request.php');
20 require_once("lib/WikiUser.php");
21 require_once('lib/WikiDB.php');
22
23 require_once "lib/WikiPluginCached.php";
24
25 // -----------------------------------------------------------------------
26
27 // FIXME: do I need this? What the hell does it? 
28
29 function deduce_pagename ($request) {
30     if ($request->getArg('pagename'))
31         return $request->getArg('pagename');
32
33     if (USE_PATH_INFO) {
34         $pathinfo = $request->get('PATH_INFO');
35         if (ereg('^' . PATH_INFO_PREFIX . '(..*)$', $pathinfo, $m))
36             return $m[1];
37     }
38
39     $query_string = $request->get('QUERY_STRING');
40     if (preg_match('/^[^&=]+$/', $query_string))
41         return urldecode($query_string);
42     
43     return gettext("HomePage");
44 }
45
46 /**
47  * Initializes PhpWiki and calls the plugin specified in the url to
48  * produce an image. Furthermore, allow the usage of Apache's
49  * ErrorDocument mechanism in order to make this file only called when 
50  * image could not be found in the cache.
51  * (see PHPWIKI-CACHE.README for further information).
52  */
53 function mainImageCache() {
54     $request = new Request;   
55     //$request->setArg('pagename', deduce_pagename($request));
56     //$pagename = $request->getArg('pagename');
57
58     // assume that every user may use the cache    
59     global $user; // FIXME: necessary ?
60     $user = new WikiUser($request, 'ANON_OK'); 
61
62     $dbi = WikiDB::open($GLOBALS['DBParams']);
63     
64     // Enable the output of most of the warning messages.
65     // The warnings will screw up zip files and setpref though.
66     // They will also screw up my images... But I think 
67     // we should keep them.
68     global $ErrorManager;
69     $ErrorManager->setPostponedErrorMask(E_NOTICE|E_USER_NOTICE);
70
71     $id = $request->getArg('id');
72     $args = $request->getArg('args');
73     $request->setArg('action', 'imagecache');
74
75     if ($id) {
76         // this indicates a direct call (script wasn't called as
77         // 404 ErrorDocument)
78     } else {
79         // deduce image id or image args (plugincall) from
80         // refering URL
81
82         $uri = $request->get('REDIRECT_URL');
83         $query = $request->get('REDIRECT_QUERY_STRING');
84         $uri .= $query ? '?'.$query : '';        
85
86         if (!$uri) {
87             $uri = $request->get('REQUEST_URI');
88         }
89         if (!uri) {
90             WikiPluginCached::printError( 'png', 
91                 'Could not deduce image identifier or creation'
92                 . ' parameters. (Neither REQUEST nor REDIRECT'
93                 . ' obtained.)' ); 
94             return;
95         }    
96         $cacheparams = $GLOBALS['CacheParams'];
97         if (!preg_match(':^(.*/)?'.$cacheparams['filename_prefix'].'([^\?/]+)\.img(\?args=([^\?&]*))?$:', $uri, $matches)) {
98             WikiPluginCached::printError('png', "I do not understand this URL: $uri");
99             return;
100         }        
101         
102         $request->setArg('id',$matches[2]);
103         if ($matches[4]) {
104            $request->setArg('args',rawurldecode($matches[4]));
105         }
106         $request->setStatus(200); // No, we do _not_ have an Error 404 :->
107     } 
108
109     WikiPluginCached::fetchImageFromCache($dbi,$request,'png');
110 }
111
112
113 mainImageCache();
114
115
116 // Local Variables:
117 // mode: php
118 // tab-width: 8
119 // c-basic-offset: 4
120 // c-hanging-comment-ender-p: nil
121 // indent-tabs-mode: nil
122 // End:   
123 ?>