From 7292e7d9c735ff6021bd2ae843ac87410d751a4e Mon Sep 17 00:00:00 2001 From: rurban Date: Sat, 19 Jun 2004 10:06:38 +0000 Subject: [PATCH] Moved lib/plugincache-config.php to config/*.ini use PLUGIN_CACHED_* constants instead of global $CacheParams git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@3728 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/IniConfig.php | 28 ++++++- lib/WikiPluginCached.php | 79 +++++++++++-------- lib/imagecache.php | 6 +- lib/plugin/Ploticus.php | 17 ++-- lib/plugin/TexToPng.php | 13 +++- lib/plugin/VisualWiki.php | 17 ++-- lib/plugincache-config.php | 154 ------------------------------------- 7 files changed, 102 insertions(+), 212 deletions(-) delete mode 100644 lib/plugincache-config.php diff --git a/lib/IniConfig.php b/lib/IniConfig.php index c4ac61435..dc4c7ecc0 100644 --- a/lib/IniConfig.php +++ b/lib/IniConfig.php @@ -1,5 +1,5 @@ plugin/VisualWiki.php * * @author Johannes Große - * @version 0.8 + * @version 1.0 */ class WikiPluginCached extends WikiPlugin { @@ -68,36 +69,36 @@ class WikiPluginCached extends WikiPlugin */ function genUrl($cache,$argarray) { global $request; - $cacheparams = $GLOBALS['CacheParams']; + //$cacheparams = $GLOBALS['CacheParams']; $plugincall = serialize( array( 'pluginname' => $this->getName(), 'arguments' => $argarray ) ); $id = $cache->generateId( $plugincall ); - $url = $cacheparams['cacheurl']; // FIXME: SERVER_URL ? + $url = DATA_PATH . '/getimg.php?'; if (($lastchar = substr($url,-1)) == '/') { $url = substr($url, 0, -1); } - if (strlen($plugincall)>$cacheparams['maxarglen']) { + if (strlen($plugincall) > PLUGIN_CACHED_MAXARGLEN) { // we can't send the data as URL so we just send the id - if (!$request->getSessionVar('imagecache'.$id)) { $request->setSessionVar('imagecache'.$id, $plugincall); } $plugincall = false; // not needed anymore } - if ($lastchar=='?') { + if ($lastchar == '?') { // this indicates that a direct call of the image creation // script is wished ($url is assumed to link to the script) $url .= "id=$id" . ($plugincall ? '&args='.rawurlencode($plugincall) : ''); } else { - // we are supposed to use the indirect 404 ErrorDocument method + // Not yet supported. + // We are supposed to use the indirect 404 ErrorDocument method // ($url is assumed to be the url of the image in // cache_dir and the image creation script is referred to in the // ErrorDocument 404 directive.) - $url .= '/' . $cacheparams['filename_prefix'] . $id . '.img' + $url .= '/' . PLUGIN_CACHED_FILENAME_PREFIX . $id . '.img' . ($plugincall ? '?args='.rawurlencode($plugincall) : ''); } if ($request->getArg("start_debug")) @@ -126,7 +127,7 @@ class WikiPluginCached extends WikiPlugin */ function run($dbi, $argstr, &$request, $basepage) { $cache = WikiPluginCached::newCache(); - $cacheparams = $GLOBALS['CacheParams']; + //$cacheparams = $GLOBALS['CacheParams']; $sortedargs = $this->getArgs($argstr, $request); if (is_array($sortedargs) ) @@ -154,7 +155,7 @@ class WikiPluginCached extends WikiPlugin } break; case PLUGIN_CACHED_IMG_INLINE: - if ($cacheparams['usecache']&&(!$content || !$content['image'])) { + if (PLUGIN_CACHED_USECACHE && (!$content || !$content['image'])) { $do_save = WikiPluginCached::produceImage($content, $this, $dbi, $sortedargs, $request, 'html'); $content['html'] = $do_save?$this->embedImg($url, $dbi, $sortedargs, $request) : false; } @@ -252,8 +253,8 @@ class WikiPluginCached extends WikiPlugin * @param request Request ??? * @return string 'png', 'jpeg' or 'gif' */ - function getImageType($dbi,$argarray,$request) { - if (in_array($argarray['imgtype'], $GLOBAL['CacheParams']['imgtypes'])) + function getImageType(&$dbi, $argarray, &$request) { + if (in_array($argarray['imgtype'], preg_split('/\s*:\s*/', PLUGIN_CACHED_IMGTYPES))) return $argarray['imgtype']; else return 'png'; @@ -383,16 +384,21 @@ class WikiPluginCached extends WikiPlugin function newCache() { static $staticcache; - $cacheparams = $GLOBALS['CacheParams']; - if (!is_object($staticcache)) { - /* $pearFinder = new PearFileFinder; - $pearFinder->includeOnce('Cache.php');*/ - - $staticcache = new Cache($cacheparams['database'],$cacheparams); - $staticcache->gc_maxlifetime = $cacheparams['maxlifetime']; + if (!class_exists('Cache')) { + $pearFinder = new PearFileFinder; + $pearFinder->includeOnce('Cache.php'); + } + $cacheparams = array(); + foreach (explode(':','database:cache_dir:filename_prefix:highwater:lowwater' + .':maxlifetime:maxarglen:usecache:force_syncmap') as $key) { + $cacheparams[$key] = constant('PLUGIN_CACHED_'.strtoupper($key)); + } + $cacheparams['imgtypes'] = preg_split('/\s*:\s*/', PLUGIN_CACHED_IMGTYPES); + $staticcache = new Cache(PLUGIN_CACHED_DATABASE, $cacheparams); + $staticcache->gc_maxlifetime = PLUGIN_CACHED_MAXLIFETIME; - if (!$cacheparams['usecache']) { + if (! PLUGIN_CACHED_USECACHE ) { $staticcache->setCaching(false); } } @@ -476,7 +482,7 @@ class WikiPluginCached extends WikiPlugin * @return void */ function writeHeader($doctype) { - $IMAGEHEADER = array( + static $IMAGEHEADER = array( 'gif' => 'Content-type: image/gif', 'png' => 'Content-type: image/png', 'jpeg' => 'Content-type: image/jpeg', @@ -486,9 +492,9 @@ class WikiPluginCached extends WikiPlugin 'gd2' => 'Content-type: image/gd2', 'wbmp' => 'Content-type: image/vnd.wap.wbmp', // wireless bitmaps for PDA's and such. 'html' => 'Content-type: text/html' ); - // Todo: swf + // Todo: swf, pdf Header($IMAGEHEADER[$doctype]); - } // writeHeader + } /** @@ -615,8 +621,8 @@ class WikiPluginCached extends WikiPlugin } // image handle -> image data - $cacheparams = $GLOBALS['CacheParams']; - $tmpfile = tempnam($cacheparams['cache_dir'],$cacheparams['filename_prefix']); + //$cacheparams = $GLOBALS['CacheParams']; + $tmpfile = $this->tempnam(); WikiPluginCached::writeImage($content['imagetype'], $imagehandle, $tmpfile); ImageDestroy($imagehandle); if (file_exists($tmpfile)) { @@ -630,6 +636,10 @@ class WikiPluginCached extends WikiPlugin return false; } // produceImage + function tempnam($prefix = false) { + return tempnam(isWindows() ? str_replace('/', "\\", PLUGIN_CACHED_CACHE_DIR) : PLUGIN_CACHED_CACHE_DIR, + $prefix ? $prefix : PLUGIN_CACHED_FILENAME_PREFIX); + } /** * Main function for obtaining images from cache or generating on-the-fly @@ -666,14 +676,15 @@ class WikiPluginCached extends WikiPlugin // cache empty, but image maps have to be created _inline_ // so ask user to reload wiki page instead - $cacheparams = $GLOBALS['CacheParams']; - if (($plugin->getPluginType() == PLUGIN_CACHED_MAP) && $cacheparams['force_syncmap']) { - $errortext = gettext('Image map expired. Reload wiki page to recreate its html part.'); + //$cacheparams = $GLOBALS['CacheParams']; + if (($plugin->getPluginType() == PLUGIN_CACHED_MAP) && PLUGIN_CACHED_FORCE_SYNCMAP) { + $errortext = _("Image map expired. Reload wiki page to recreate its html part."); WikiPluginCached::printError($errorformat, $errortext); } - if (!WikiPluginCached::produceImage($content, $plugin, $dbi, $argarray, $request, $errorformat) ) return false; + if (!WikiPluginCached::produceImage($content, $plugin, $dbi, $argarray, + $request, $errorformat) ) return false; $expire = $plugin->getExpire($dbi,$argarray,$request); diff --git a/lib/imagecache.php b/lib/imagecache.php index 36fb7d0e9..930ecca89 100644 --- a/lib/imagecache.php +++ b/lib/imagecache.php @@ -1,4 +1,4 @@ -defaultArguments(); - $other_imgtypes = $GLOBALS['CacheParams']['imgtypes']; - unset ($other_imgtypes[$def['imgtype']]); + //$other_imgtypes = $GLOBALS['PLUGIN_CACHED_IMGTYPES']; + //unset ($other_imgtypes[$def['imgtype']]); $helparr = array( ' ' = "' . $def['device'] . "(default)|" . join('|',$GLOBALS['CacheParams']['imgtypes']).'"', + 'device' => ' = "' . $def['device'] . "(default)|" . join('|',$GLOBALS['PLUGIN_CACHED_IMGTYPES']).'"', 'alt' => ' = "alternate text"', '-csmap' => ' bool: clickable map?', 'help' => ' bool: displays this screen', @@ -223,8 +223,8 @@ extends WikiPluginCached $source =& $this->source; if (!empty($source)) { $html = HTML(); - $cacheparams = $GLOBALS['CacheParams']; - $tempfiles = tempnam($cacheparams['cache_dir'], 'Ploticus'); + //$cacheparams = $GLOBALS['CacheParams']; + $tempfiles = $this->tempnam('Ploticus'); $gif = $argarray['device']; $args = " -stdin -$gif -o $tempfiles.$gif"; if (!empty($argarray['-csmap'])) { @@ -255,6 +255,9 @@ extends WikiPluginCached }; // $Log: not supported by cvs2svn $ +// Revision 1.3 2004/06/03 09:40:57 rurban +// WikiPluginCache improvements +// // Revision 1.2 2004/06/02 19:37:07 rurban // extended description // diff --git a/lib/plugin/TexToPng.php b/lib/plugin/TexToPng.php index 864bc83f8..70f3a7fe4 100644 --- a/lib/plugin/TexToPng.php +++ b/lib/plugin/TexToPng.php @@ -1,5 +1,5 @@ tempnam('TexToPng'); $img = 0; // $size = 0; // procuce options for pstoimg @@ -303,6 +303,11 @@ class WikiPlugin_TexToPng extends WikiPluginCached } // WikiPlugin_TexToPng // $Log: not supported by cvs2svn $ +// Revision 1.4 2003/01/18 22:08:01 carstenklapp +// Code cleanup: +// Reformatting & tabs to spaces; +// Added copyleft, getVersion, getDescription, rcs_id. +// // For emacs users // Local Variables: diff --git a/lib/plugin/VisualWiki.php b/lib/plugin/VisualWiki.php index 6832cdc1a..1315a1955 100644 --- a/lib/plugin/VisualWiki.php +++ b/lib/plugin/VisualWiki.php @@ -1,5 +1,5 @@ defaultarguments(); - $other_imgtypes = $GLOBALS['CacheParams']['imgtypes']; + $other_imgtypes = $GLOBALS['PLUGIN_CACHED_IMGTYPES']; unset ($other_imgtypes[$def['imgtype']]); $helparr = array( 'getName() . - ' img' => ' = "' . $def['imgtype'] . "(default)|" . join('|',$GLOBALS['CacheParams']['imgtypes']).'"', + ' img' => ' = "' . $def['imgtype'] . "(default)|" . join('|',$GLOBALS['PLUGIN_CACHED_IMGTYPES']).'"', 'width' => ' = "width in inches"', 'height' => ' = "height in inches"', 'fontname' => ' = "font family"', @@ -609,8 +609,8 @@ extends WikiPluginCached */ function invokeDot($argarray) { global $dotbin; - $cacheparams = $GLOBALS['CacheParams']; - $tempfiles = tempnam($cacheparams['cache_dir'], 'VisualWiki'); + //$cacheparams = $GLOBALS['CacheParams']; + $tempfiles = $this->tempnam('VisualWiki'); $gif = $argarray['imgtype']; $ImageCreateFromFunc = "ImageCreateFrom$gif"; $ok = $tempfiles @@ -732,6 +732,9 @@ function interpolate($a, $b, $pos) { } // $Log: not supported by cvs2svn $ +// Revision 1.9 2004/06/03 09:40:57 rurban +// WikiPluginCache improvements +// // Revision 1.8 2004/01/26 09:18:00 rurban // * changed stored pref representation as before. // the array of objects is 1) bigger and 2) diff --git a/lib/plugincache-config.php b/lib/plugincache-config.php deleted file mode 100644 index 317ecdcc4..000000000 --- a/lib/plugincache-config.php +++ /dev/null @@ -1,154 +0,0 @@ -include "lib/main.php"; - * (to be found at the end of the file) by - * include "lib/imagecache.php"; . - * Make sure that there is a trailing - * question mark in 'cache_url'. - * @param 'maxarglen' int number of characters allowed to be send as - * parameters in the url before using sessions - * vars instead. - * @param 'usecache' boolean switches the use of the cache on (true) - * or off (false). If you want to avoid the - * usage of a cache but need WikiPlugin~s - * that nevertheless rely on a cache you might set - * 'usecache' to false. You still need to set - * 'cache_dir' appropriately to allow image creation - * and you should set 'force_syncmap' to false. - * @param 'force_syncmap' boolean Will prevent image creation for an image - * map 'on demand'. It is a good idea to set this - * to 'true' because it will also prevent the - * html part not to fit to the image of the map. - * If you don't use a cache, you have to set it - * to 'false', maps will not work otherwise but - * strange effects may happen if the output of - * an image map producing WikiPlugin is not - * completely determined by its parameters. - * (As it is the case for a graphical site map.) - */ -$CacheParams = array - ( - // db settings (database='file' is the fastest) - 'database' => 'file', - // the webserver must have write access to this dir! - 'cache_dir' => '/tmp/cache/', - 'filename_prefix' => 'phpwiki', - - // When highwater is exceeded, a garbage collection will start. - // It will collect garbage till lowwater is reached. - 'highwater' => 4 * Megabyte, - 'lowwater' => 3 * Megabyte, - - // If an image has not been used for maxlifetime remove it from - // the cache. - // (Since there is also the highwater/lowwater mechanism - // and an image usually requires only 1kb you don't have to - // make it very small, I think.) - 'maxlifetime' => 30 * Day, - - // name of the imagecache start up file - // This file should have been created by hand by copying - // phpwiki/index.php and substituting - // include "lib/main.php"; - // by - // include "lib/imagecache.php"; - // - //'cacheurl' => '../imagecache/', - 'cacheurl' => DATA_PATH . '/getimg.php?', - - // usually send plugin arguments as URL, but when they become - // longer than maxarglen store them in session variables - // setting it to 3000 worked fine for me, 30000 completely - // crashed my linux, 1000 should be safe. - 'maxarglen' => 1000, - - // actually use the cache - // (should be always true unless you are debugging) - 'usecache' => true, - - // This will prevent image creation for an image - // map 'on demand'. It is a good idea to set this - // to 'true' because it will also prevent the - // html part not to fit to the image of the map. - // If you don't use a cache, you have to set it - // to 'false', maps will not work otherwise. - 'force_syncmap' => true, - - // if ImageTypes() does not exist (PHP < 4.0.2) allow the - // following image formats (IMG_PNG | IMG_GIF | IMG_JPG | IMG_WBMP) - // in principal all image types which are compiled into php: - // libgd, libpng, libjpeg, libungif, libtiff, libgd2, ... - 'imgtypes' => array('png','gif','gd','gd2','jpeg','wbmp','xbm','xpm') - // Todo: swf, pdf, ... -); - -if (!file_exists($CacheParams['cache_dir']) and substr(PHP_OS,0,3) == 'WIN') { - if (isset($GLOBALS['HTTP_ENV_VARS']['TEMP'])) - $CacheParams['cache_dir'] = $GLOBALS['HTTP_ENV_VARS']['TEMP'] . "\\cache\\"; - else - $CacheParams['cache_dir'] = "\\TEMP\\cache\\"; -} -?> -- 2.45.0