summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-03-11 22:32:18 +0100
committerandi <andi@splitbrain.org>2005-03-11 22:32:18 +0100
commitaf7d064b727d27d3aaa61e6dd3523d58a5c4015d (patch)
treeeb4a3c8e2b1322030b74d3591c9d53473bf7bf08
parent820fa24b2cc7cd677f9e392f5834e69bc3e46dc5 (diff)
downloadrpg-af7d064b727d27d3aaa61e6dd3523d58a5c4015d.tar.gz
rpg-af7d064b727d27d3aaa61e6dd3523d58a5c4015d.tar.bz2
better image parameter handling
darcs-hash:20050311213218-9977f-a2a5fd11dbac275d26b58f26fa3b2031c2b6028c.gz
-rw-r--r--inc/format.php27
1 files changed, 17 insertions, 10 deletions
diff --git a/inc/format.php b/inc/format.php
index 9c418e9ad..0d8106fa2 100644
--- a/inc/format.php
+++ b/inc/format.php
@@ -338,10 +338,15 @@ function format_link_media($link){
}
$link['name'] = trim($link['name']);
- //split into src and parameters
- list($src,$param) = split('\?',$link['name'],2);
+ //split into src and parameters (using the very last questionmark)
+ $pos = strrpos($link['name'], '?');
+ if($pos !== false){
+ $src = substr($link['name'],0,$pos);
+ $param = substr($link['name'],$pos+1);
+ }
+
//parse width and height
- if(preg_match('#(\d*)(x(\d*))?#i',$param,$size)){
+ if(preg_match('#(\d+)(x(\d+))?#i',$param,$size)){
if($size[1]) $w = $size[1];
if($size[3]) $h = $size[3];
}
@@ -359,11 +364,12 @@ function format_link_media($link){
}
}
- //check for nocache param
- $nocache = preg_match('/nocache/i',$param);
+ //check for nocache/recache param
+ preg_match('/(nocache|recache)/i',$param,$cachemode);
+
//do image caching, resizing and src rewriting
$cache = $src;
- $isimg = img_cache($cache,$src,$w,$h,$nocache);
+ $isimg = img_cache($cache,$src,$w,$h,$cachemode[1]);
//set link to src if none given
if(!$link['url']){
@@ -435,9 +441,9 @@ function format_rss($url){
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function img_cache(&$csrc,&$src,&$w,&$h,$nocache){
+function img_cache(&$csrc,&$src,&$w,&$h,$cachemode){
global $conf;
-
+
//container for various paths
$f['full']['web'] = $src;
$f['resz']['web'] = $src;
@@ -466,9 +472,10 @@ function img_cache(&$csrc,&$src,&$w,&$h,$nocache){
}
//download external images if allowed
- if($isurl && $isimg && !$nocache){
+ if($isurl && $isimg && $cachemode != 'nocache'){
$cache = $conf['mediadir']."/.cache/$md5.$ext";
- if (@file_exists($cache) || download($src,$cache)){
+ if ( ($cachemode == 'recache' && download($src,$cache)) ||
+ @file_exists($cache) || download($src,$cache)){
$f['full']['web'] = $conf['mediaweb']."/.cache/$md5.$ext";
$f['resz']['web'] = $conf['mediaweb']."/.cache/$md5.$ext";
$f['full']['fs'] = $conf['mediadir']."/.cache/$md5.$ext";