manishjaingit / timthumb

Automatically exported from code.google.com/p/timthumb
0 stars 0 forks source link

Rewrite timthumb->getLocalImagePath($src) using a brain #464

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

I don't even know where to start with this one... What is 
getLocalImagePath($src) suppose to be doing, and why isn't it using 
get_option('upload_path')?  The entire function can be replaced with the 
following code.  As an added bonus this function will actually find the upload 
location EVERY TIME!

$src_uri = str_replace(get_option('fileupload_url'), '', get_option('siteurl') 
. $src);
                return realpath(ABSPATH . get_option('upload_path') . '/' . $src_uri);

You need to include the needed WP files:

if ( !defined('ABSPATH') ) {
        /** Set up WordPress environment */
        require_once('../../../wp-load.php');
}
require_once("../../../wp-includes/functions.php");

Original issue reported on code.google.com by a...@1stleg.com on 10 Sep 2013 at 6:46

GoogleCodeExporter commented 9 years ago
After reviewing the code and the site, I doubt this is a valid bug.  It appears 
that several themes that have ended up on our wordpress installation have 
botched patching the function in question in several different ways.  The only 
halfway decent solution I can think of would be defining some variable to 
override the document root path or appending some prefix to the LocalImagePath 
returned by the function in question.  Ill keep digging around and see if I 
cant get a patch together to help stop the insanity.

Original comment by a...@1stleg.com on 11 Sep 2013 at 10:32

GoogleCodeExporter commented 9 years ago
Ok this is even easier than I thought... Please document 
LOCAL_FILE_BASE_DIRECTORY at the top with the rest of the configuration options 
;)

Original comment by a...@1stleg.com on 11 Sep 2013 at 10:45

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Here is a very small file that should be used to configure this script to work 
with wordpress instead of patching.  This should work for most installs, just 
place the timthumb-config.php file in the same location as the timthumb.php 
file.

[root@titan avenue]# cat timthumb-config.php 
<?php

if ( !defined('ABSPATH') ) {
        /** Set up WordPress environment */
        require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php');
}

define ('LOCAL_FILE_BASE_DIRECTORY', realpath(ABSPATH . 
get_option('upload_path') . '/..'));
define ('FILE_CACHE_DIRECTORY', LOCAL_FILE_BASE_DIRECTORY . '/cache');

Original comment by a...@1stleg.com on 11 Sep 2013 at 11:27

GoogleCodeExporter commented 9 years ago
Hi - TimThumb is not part of WordPress. It does not know WordPress exists and 
does not use any of WordPresses functions. As such it can not make use of 
WordPress functionality. If you want to add features to timthumb-config you can 
(that's why it's there) but this is not something that will be added to the 
TimThumb core.

That said I shall add a note to the top of timthumb about 
LOCAL_FILE_BASE_DIRECTORY :)

Original comment by BinaryMoon on 27 Sep 2013 at 8:57