splittingred / phpThumbOf

A secure phpthumb output filter for MODx Revolution
http://rtfm.modx.com/display/addon/phpthumbof/
23 stars 17 forks source link

different sources for pulling server document root creates error #9

Closed lukemcd closed 13 years ago

lukemcd commented 13 years ago

I also had the issue that some users have noted with phpthumbof outputting an extended path that is incorrect. After looking into it the issue occurs in the phpthumbof snippet at line 94: CODE: $cacheUrl = $assetsUrl.'cache/'.str_replace($phpThumb->config_cache_directory,'',$cacheKey);

This line strips out the server document root path from the image path by comparing two variables that both have the server document root path: $phpThumb->config_cache_directory and $cacheKey. Both of these variables have the document root set from the variable $assetsPath, which gets the document root from a getOption call earlier in the script. Since both $phpThumb->config_cache_directory and $cacheKey get the server path from the same source they should match up. But at line 73 we have this: CODE: $phpThumb->setCacheDirectory();

I haven't looked into everything this does but one thing I discovered is that it resets the $phpThumb->config_cache_directory variable. It appears to use a PHP server global to get the real time server document root path. In most cases this is not a problem. But my installation of MODX is on a MediaTemple server where they recommend using an alias for the server document root path. Since the alias does not match the global for the document root it throws off the string replace function that is used to strip out the document root.

I have a solution which is not very elegant but is working for now. I made a duplicate of the $phpThumb->config_cache_directory. So line 70 becomes:

CODE: $phpThumb->setParameter('config_cache_directory',$assetsPath.'cache/'); $phpThumb->setParameter('config_cache_directory2',$assetsPath.'cache/');

Then line 94 is changed to this: CODE: $cacheUrl = $assetsUrl.'cache/'.str_replace($phpThumb->config_cache_directory2,'',$cacheKey);

phpthumbof has become a default add-on for my MODX Revo installations, hopefully an update to phpthumbof can be released that addresses this.