Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Getting the url for the currently displayed image's thubnail  (Read 10151 times)

0 Members and 1 Guest are viewing this topic.

papukaija

  • Contributor
  • Coppermine frequent poster
  • ***
  • Country: 00
  • Offline Offline
  • Posts: 333
Getting the url for the currently displayed image's thubnail
« on: September 01, 2010, 10:27:52 pm »

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.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 to my gallery to demonstrate the issue.
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Getting the url for the currently displayed image's thubnail
« Reply #1 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);
}

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Getting the url for the currently displayed image's thubnail
« Reply #2 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

papukaija

  • Contributor
  • Coppermine frequent poster
  • ***
  • Country: 00
  • Offline Offline
  • Posts: 333
Re: Getting the url for the currently displayed image's thubnail
« Reply #3 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?
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Getting the url for the currently displayed image's thubnail
« Reply #4 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.

wbnp

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 37
Re: Getting the url for the currently displayed image's thubnail
« Reply #5 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.
Logged

wbnp

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 37
Re: Getting the url for the currently displayed image's thubnail
« Reply #6 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.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Getting the url for the currently displayed image's thubnail
« Reply #7 on: September 02, 2010, 09:03:11 am »

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

papukaija

  • Contributor
  • Coppermine frequent poster
  • ***
  • Country: 00
  • Offline Offline
  • Posts: 333
Re: Getting the url for the currently displayed image's thubnail
« Reply #8 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).
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Getting the url for the currently displayed image's thubnail
« Reply #9 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?
Logged

papukaija

  • Contributor
  • Coppermine frequent poster
  • ***
  • Country: 00
  • Offline Offline
  • Posts: 333
Re: Getting the url for the currently displayed image's thubnail
« Reply #10 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']>" / >
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Getting the url for the currently displayed image's thubnail
« Reply #11 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.

papukaija

  • Contributor
  • Coppermine frequent poster
  • ***
  • Country: 00
  • Offline Offline
  • Posts: 333
Re: Getting the url for the currently displayed image's thubnail
« Reply #12 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.
Logged
Pages: [1]   Go Up
 

Page created in 0.093 seconds with 20 queries.