mozahidrana / timthumb

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

Compatible with WPMU #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
How could we get your script to work with WPMU ?

Original issue reported on code.google.com by jedbar...@gmail.com on 2 Mar 2009 at 1:04

GoogleCodeExporter commented 9 years ago
Looks like you have to further define the path down to the blog # on WordPress 
MU (#3
for me).

Manually changing the path to:

// get path to image on file system
$src = '/usr/local/share/wordpress-mu-1.5.1/wp-content/blogs.dir/3'

Original comment by magnusje...@gmail.com on 4 Mar 2009 at 9:55

GoogleCodeExporter commented 9 years ago
Hi - I am using timthumb just fine with WP mu, could you try using the latest 
version
and see if that works as I have made some changes to getting the image path 
that may
improve things for you

Original comment by BinaryMoon on 14 Mar 2009 at 9:04

GoogleCodeExporter commented 9 years ago
Hi all,
I've tried the latest version of timthumb on WPMu 2.7 + egamer Theme (from 
Elegant
Theme) and... it doesn't work.

any ideas ?

Original comment by hakevin....@gmail.com on 4 Jun 2009 at 3:34

GoogleCodeExporter commented 9 years ago
As it stands currently, Timthumb can be used with WPMU, though not as easily as
regular Wordpress. As I have it set up, I have to put the image URL as
http://domain.com/wp-content/blogs.dir/1/files/2009/01/sample-image.jpg as 
opposed to
just domain.com/files... This isn't a major issue, but is a bit annoying,
particularly when using it on additional blogs where the blog id isn't known.

That said, it'd be great if Timthumb could be tweaked to support the image URLs 
of
WPMU without having to add the blog id bit. Justin Tadlock's "Get the Image" 
plugin
can handle WPMU images well in that you don't have to add the blog ID, but I 
prefer
the way Timthumb handles the cropping as GTI compresses and distorts the images 
more
than I like. 

Ideally I'd like to see a combination of the features of GTI and its ability to 
use
WPMU's image URLs with the cropping of Timthumb.

Original comment by kriskark...@gmail.com on 30 Jun 2009 at 2:53

GoogleCodeExporter commented 9 years ago
dear all,

sorry to bother you... would you please explain how to you manage to change the 
path
(when saying "Manually changing the path to..." or "I have to put the image URL 
as..."

many thanks for your kind help

Original comment by mduse...@gmail.com on 10 Aug 2009 at 3:15

GoogleCodeExporter commented 9 years ago
@kriskarkoski, I have the same question as mduserre.

@BinaryMoon, I'm using the latest version of both timthumb and wpmu and still 
having 
this error, too. Also, the image I am trying to create thumbnail is an offsite 
image.

Original comment by supersaw...@gmail.com on 19 Aug 2009 at 1:00

GoogleCodeExporter commented 9 years ago
Here's the code from my theme:

    <?php
    //Check if custom field key "Image" has a value
    $values = get_post_custom_values("Image");
    if (isset($values[0])) {
    ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img
src="http://mmafrenzy.com/wp-content/themes/mmafrenzy/scripts/timthumb.php?src=<
?php
$values = get_post_custom_values("Image"); echo $values[0];
?>&w=120&h=120&zc=1&q=100"
alt="<?php the_title(); ?>" class="right" width="120px" height="120px"  /></a>
        <?php } ?>

Then, in the "Image" custom field I specify an image URL like this, swapping 
out /1/
for the blog's ID.

http://mmafrenzy.com/wp-content/blogs.dir/1/files/2009/04/strikeforce-shamrock-v
s-diaz-00008.jpg

Original comment by kriskark...@gmail.com on 19 Aug 2009 at 2:45

GoogleCodeExporter commented 9 years ago
@mduserre & @supersawsaw08

I used the fix from @magnusjepson. He is a WooThemes designer (I use WooThemes) 
and
it works pretty well.  Plus you only need to change the code in the thumb.php, 
rather
than in the other theme files. 

Unfortunately, with this approach, no other subdomain or subfolder blogs can 
use the
them, since the resizer will point to the image file for the specific blog 
number in
the code i.e. "/1/"

Hope that makes sense. 

Original comment by Mmcom...@gmail.com on 19 Aug 2009 at 3:26

GoogleCodeExporter commented 9 years ago
Here is a modified version of the code that I thought would work but it just 
isn't working for me, it may work 
for you it ads in the blog id for you.

 <?php
    //Check if custom field key "Image" has a value
    global $blog_id;

    $values = get_post_custom_values("preview");
    if (isset($values[0])) {
    ?>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img
src="<?php bloginfo('stylesheet_directory'); 
?>/timthumb.php?src=wp-content/blogs.dir/<?php echo 
$blog_id; ?>/<?php
$values = get_post_custom_values("preview"); echo $values[0];
?>&w=360&h=180&zc=1&q=100"
alt="<?php the_title(); ?>" class="right" width="360px" height="180px"  /></a>
        <?php } ?>

Original comment by joseff...@gmail.com on 8 Sep 2009 at 4:08

GoogleCodeExporter commented 9 years ago
/*
CAT - Oct 2009

The problem I identified is this:        
TimThumb.php expects a real URL the file in $src, but WPMU creates virtual URL 
paths
to resources. So $src gets:
"http://site.dom/wpmu/blog-name/files/2009/10/03032008.jpg" instead of a URL 
with the
real file system path:
"http://site.dom/wp-content/blogs.dir/2/files/2009/10/03032008.jpg" (where blog 
named
'blog-name' is number '2').

My solution is to modify the variable $src containing the URL, in function
cleanSource(). This will work for all the blogs on this WPMU install.
*/

require '../../../wp-blog-header.php'; // conversion functions in
wp-includes/wpmu-functions.php

////////in function clearSource() after those 2 lines of code:
        $src = preg_replace("/\.\.+\//", "", $src);

        //print_r($_SERVER);

        // WPMU fix - CAT (2 new lines)
        $blog_name = preg_replace('/^.*\/(\w+)\/files.*$/', '${1}', $src);     
//this extracts the blog name from the URL (done separately since can't use
backreferences in function args in replacement string below!! :( )
        $src = preg_replace('/^.*\/(\w+)\/files/',
'/wp-content/blogs.dir/'.get_id_from_blogname($blog_name).'/files', $src);     
//
this modifies the URL from virtual to real path, using an existing WPMU 
function 

That's it. Now all the virtual paths created in WPMU are automatically 
transformed in
a real one pointing to the actual image file.

Original comment by really...@gmail.com on 12 Oct 2009 at 11:04

GoogleCodeExporter commented 9 years ago
This solution doesn't work for me.. :(
I added lines on the top of my timthumb.php:

require '../../../wp-blog-header.php'; // conversion functions in
wp-includes/wpmu-functions.php

And here is my function cleanSource($src):

function cleanSource($src) {

    // remove slash from start of string
    if(strpos($src, "/") == 0) {
        $src = substr($src, -(strlen($src) - 1));
    }

    // remove http/ https/ ftp
    $src = preg_replace("/^((ht|f)tp(s|):\/\/)/i", "", $src);
    // remove domain name from the source url
    $host = $_SERVER["HTTP_HOST"];
    $src = str_replace($host, "", $src);
    $host = str_replace("www.", "", $host);
    $src = str_replace($host, "", $src);

    // don't allow users the ability to use '../' 
    // in order to gain access to files below document root

    // src should be specified relative to document root like:
    // src=images/img.jpg or src=/images/img.jpg
    // not like:
    // src=../images/img.jpg
    $src = preg_replace("/\.\.+\//", "", $src);

$blog_name = preg_replace('/^.*\/(\w+)\/files.*$/', '${1}', $src);
$src = preg_replace('/^.*\/(\w+)\/files/',
'/wp-content/blogs.dir/'.get_id_from_blogname($blog_name).'/files', $src);
    // get path to image on file system
    $src = get_document_root($src) . '/' . $src;    

    return $src;

}

Original comment by ndr...@gmail.com on 13 Oct 2009 at 10:14

GoogleCodeExporter commented 9 years ago
quick & dirty fix:

// add the following 2 lines at the beginning of timthumb.php

define( 'SHORTINIT', true );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );

// add the following line "just" before the function call to 
get_document_root(), e.g.
$src = str_replace( array( $_SERVER['DOCUMENT_ROOT'], "/files/") , array("", 
"") ,
BLOGUPLOADDIR  ) . $src;  // Add this line

$src = get_document_root($src) . '/' . $src;    

Original comment by ryanchan...@gmail.com on 7 Dec 2009 at 3:37

GoogleCodeExporter commented 9 years ago
This is not an issue with TimThumb. The problem is with the image file path, the
theme needs to be changed to use the correct path. There's info on how to do 
this here:

http://www.binarymoon.co.uk/2009/10/timthumb-wordpress-mu/

Original comment by BinaryMoon on 31 Dec 2009 at 5:19