forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 plugins => Topic started by: papukaija on September 01, 2010, 10:27:52 pm

Title: Getting the url for the currently displayed image's thubnail
Post by: papukaija on September 01, 2010, 10:27:52 pm
I am trying to provide a bugfix for my Facebook sharer (http://forum.coppermine-gallery.net/index.php/topic,65740.0.html) 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.php
Code: [Select]
global $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
Code: [Select]
<link rel="image_src" href="albums//" / >
as output.

I also tried
Code: [Select]
get_pic_url($CURRENT_PIC_DATA['filename'], 'thumb'); for $thumb_url but in that case I just get
Code: [Select]
<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 (http://mcguardians.byethost14.com/displayimage.php?pid=1#top_display_media) to my gallery to demonstrate the issue.
Title: Re: Getting the url for the currently displayed image's thubnail
Post by: Stramm on September 01, 2010, 10:34:36 pm
first add the necessary filter
Code: [Select]
$thisplugin->add_filter('file_data','some_function_name_you_like');
then the function
Code: [Select]
function some_function_name_you_like($data){
    print_r($data);
}

Title: Re: Getting the url for the currently displayed image's thubnail
Post by: Stramm on September 01, 2010, 10:38:13 pm
Code: [Select]
$fullsize_url = get_pic_url(data);  //here we grab the url to the fullsized pic
$thumb_url = get_pic_url(data, 'thumb'); //thumb url
Title: Re: Getting the url for the currently displayed image's thubnail
Post by: papukaija on September 01, 2010, 11:05:03 pm
Thanks for your very fast help. Unfortunately,
Code: [Select]
$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.

first add the necessary filter
Code: [Select]
$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:
Code: [Select]
$thisplugin->add_filter('page_meta','fb_head');
Could this be the reason for the wrong url given by the code you gave?
Title: Re: Getting the url for the currently displayed image's thubnail
Post by: 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.
Title: Re: Getting the url for the currently displayed image's thubnail
Post by: 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.
Title: Re: Getting the url for the currently displayed image's thubnail
Post by: wbnp on September 02, 2010, 05:00:42 am
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.
Title: Re: Getting the url for the currently displayed image's thubnail
Post by: Αndré on September 02, 2010, 09:03:11 am
I suggest to move that thread to the cpg1.5.x plugin board.
Title: Re: Getting the url for the currently displayed image's thubnail
Post by: papukaija on September 02, 2010, 11:18:30 pm
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']>" / >

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.

Oh I forgot to add that you don't even have to use the thumbnail
At least it will save your server's bandwidth.

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).
Title: Re: Getting the url for the currently displayed image's thubnail
Post by: Α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?
Title: Re: Getting the url for the currently displayed image's thubnail
Post by: papukaija on September 03, 2010, 01:05:07 pm
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
Code: [Select]
$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:

Code: [Select]
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']>" / >
Title: Re: Getting the url for the currently displayed image's thubnail
Post by: Stramm on September 03, 2010, 09:09:46 pm
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.
Title: Re: Getting the url for the currently displayed image's thubnail
Post by: papukaija on September 05, 2010, 12:33:55 pm
I finally found a solution to this. A simple mysql query to find the thumbnail's url is
Code: [Select]
SELECT filepath, filename FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = $pid. Thanks for your help.