Getting the url for the currently displayed image's thubnail Getting the url for the currently displayed image's thubnail
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Getting the url for the currently displayed image's thubnail

Started by papukaija, September 01, 2010, 10:27:52 PM

Previous topic - Next topic

0 Members and 4 Guests are viewing this topic.

papukaija

I am trying to provide a bugfix for my Facebook sharer plugin. The bugfix needs the relative url (from cpg root) to the thumbnail of the currently displayed image by displayimage.php. If I use the following code in codebase.phpglobal $CONFIG, $CURRENT_PIC_DATA;

$thumb_url = $CONFIG['fullpath'].$CURRENT_PIC_DATA['filepath'].'/'.$CURRENT_PIC_DATA['filename'];
$header = '<link rel="image_src" href="'.$thumb_url.'" / >';

... I get <link rel="image_src" href="albums//" / >
as output.

I also tried get_pic_url($CURRENT_PIC_DATA['filename'], 'thumb'); for $thumb_url but in that case I just get <link rel="image_src" href="" / >


What is the best and correct way to find out this url? If needed, I can attach the codebase.php or the current testing version of my plugin to this topic. Here's a link to my gallery to demonstrate the issue.

Stramm

first add the necessary filter
$thisplugin->add_filter('file_data','some_function_name_you_like');

then the function
function some_function_name_you_like($data){
    print_r($data);
}



Stramm

$fullsize_url = get_pic_url(data);  //here we grab the url to the fullsized pic
$thumb_url = get_pic_url(data, 'thumb'); //thumb url

papukaija

Thanks for your very fast help. Unfortunately, $thumb_url = get_pic_url($data, 'thumb'); //thumb url gives
Quote<link rel="image_src" href="images/thumbs/thumb_nopic.png" / >
I checked that the tested image has both thumb_ and normal_ files.

Quote from: Stramm on September 01, 2010, 10:34:36 PM
first add the necessary filter
$thisplugin->add_filter('file_data','some_function_name_you_like');
Sorry, I didn't mention about this but I already have one function similar to this. Since the url needs to go the the header part of the document, I used: $thisplugin->add_filter('page_meta','fb_head');
Could this be the reason for the wrong url given by the code you gave?

Stramm

add the plugin filter I gave you (if needed in addition to other filters, that doesn't matter). But you need that one for the file_data hook to get the pic data.

wbnp

If it makes a difference the absolute URL will work with Facebook as well as the relative URL.

wbnp

Oh I forgot to add that you don't even have to use the thumbnail if it makes it easier, you can use the image itself as Facebook re-sizes them.

Αndré

I suggest to move that thread to the cpg1.5.x plugin board.

papukaija

Quote from: Stramm on September 02, 2010, 12:14:08 AM
add the plugin filter I gave you (if needed in addition to other filters, that doesn't matter). But you need that one for the file_data hook to get the pic data.
The problem is that the file_data hook doesn't modify the <header>, so I need another hook for that; page_meta. And I can't get second function (loaded by page_meta hook) to use the $thumb_url from the first function (for file_data hook).

I attached the current codebase.php (as you can see from that code, I can't get the get_pic_url function to work) because I think it's easier to understand  my explanation with it. With the attached code, the <header> gets this additional line:
Quote<link rel="image_src" href="<just the value of $CONFIG['ecards_more_pic_target']>" / >

Quote from: wbnp on September 02, 2010, 03:19:23 AM
If it makes a difference the absolute URL will work with Facebook as well as the relative URL.
My mistake. Actually it has to be absolute as FB dowloads (or just hotlinks) the image from your server to its server.

Quote from: wbnp on September 02, 2010, 05:00:42 AM
Oh I forgot to add that you don't even have to use the thumbnail
At least it will save your server's bandwidth.

Quote from: Αndré on September 02, 2010, 09:03:11 AM
I suggest to move that thread to the cpg1.5.x plugin board.
No problems. I just thought that this sub-board is better for coding issues (even if it's related to plugins).

Αndré

I hadn't looked thoroughly at your issue, but wouldn't it be easier to get the needed information by querying the database?

papukaija

Quote from: Αndré on September 03, 2010, 08:20:08 AM
I hadn't looked thoroughly at your issue, but wouldn't it be easier to get the needed information by querying the database?
No, I don't think so. I'm now able to get the url for the thubnail with $thumb_url = str_replace('normal', 'thumb', $CURRENT_PIC_DATA['url']); but that code is run inside a function which is called by the file_data hook. The new problem is that this hook does not modify <header> of the html code. Therefore I have created a second function (called by page_meta hook) with the following code:

function fb_head($data)
{
    global $CONFIG, $thumb_url;

    $header = '<link rel="image_src" href="'.$CONFIG['ecards_more_pic_target'].$thumb_url.'" / >';

    return $header;
}


...which returns
Quote<link rel="image_src" href="<just the value of $CONFIG['ecards_more_pic_target']>" / >

Stramm

if you need the URL in the meta then it's probably the best to grab the _GET var pid (using inspekt). If the pid key doesn't exist, then you most probably aren't on displayimage! With the pid you can query the pictures table for all the data you need (as Αndré told you).

The file_data hook is able to modify all data related to the intermediate image before it's going through the html creating process. But it can't modify the header, footer or meta. Even the image nav it's out of its scope.

papukaija

I finally found a solution to this. A simple mysql query to find the thumbnail's url is SELECT filepath, filename FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = $pid. Thanks for your help.