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: file_data hook  (Read 5580 times)

0 Members and 1 Guest are viewing this topic.

jeepguy_1980

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 94
    • Loop Family Forum & Gallery
file_data hook
« on: April 09, 2009, 05:58:02 am »

I trying to learn some PHP and contribute to Coppermine at the same time.  I am working on converting an existing mod (LightBoxJS) into a plugin, as a stepping stone to a mod that I wish to create.  The mod changes the function theme_display_image which has a hookpoint file_data.  The hookpoint line is as follows:

Code: [Select]
$CURRENT_PIC_DATA = CPGPluginAPI::filter('file_data',$CURRENT_PIC_DATA);
Does this mean that the hookpoint filters out the $CURRENT_PIC_DATA variable? If so, I should theoretically be able to copy everything in the theme_display_image function before the hookpoint and paste it into my my new function using:

Code: [Select]
$thisplugin->add_filter('file_data','LightBox_theme_html_picture');
However, when I copy the entire function to my LightBox_theme_html_picture function all I get is a little white box where my intermediate picture should be.  Does this mean that the filter function in the hookpoint completely prevents me from accessing the $CURRENT_PIC_DATA variable, including the 'pid' attribute?.
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: file_data hook
« Reply #1 on: April 09, 2009, 08:18:41 am »

The function that you failed to post is a filter, that's the important bit you failed to understand. Using the plugin hook you refered to, you're able to manipulate the array $CURRENT_PIC_DATA
However, you don't seem to know what actually resides in that array. To understand it, change your function temporarily to do this:
Code: [Select]
function LightBox_theme_html_picture($pic_data_array) {
    print_r($pic_data_array);
    die;
}
The output you get should give you an idea what actually resides in that array. You better ask yourself: do I really want to manipulate that data? Probably not, the data inside that array is fine. What you probably want to accomplish is something else, so you'll need to find another plugin hook to use.
« Last Edit: April 10, 2009, 10:46:32 am by Joachim Müller »
Logged

jeepguy_1980

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 94
    • Loop Family Forum & Gallery
Re: file_data hook
« Reply #2 on: April 09, 2009, 06:36:33 pm »

Thank you for the quick and helpful reply. I guess I have more to think about than I first thought.

What I don't understand is how $pic_data_array relates to $CURRENT_PIC_DATA.  I can't find that variable in any function.

You better ask yourself: do I really want to manipulate that data? Probably not, the data inside that array is fine. What you probably want to accomplish is something else, so you'll need to find another plugin hook to use.
Running the function as you suggested did bring up some useful information. I do think that I do want to to manipulate this data.  More specifically, I believe it's the $CURRENT_PIC_DATA['html'] that I want to manipulate.  I'm going to play around with this a little and see where I get.
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: file_data hook
« Reply #3 on: April 10, 2009, 10:51:39 am »

What I don't understand is how $pic_data_array relates to $CURRENT_PIC_DATA
The plugin hook feeds $CURRENT_PIC_DATA to your custom function. Inside the function, I named the variable $pic_data_array, but I could have named it $foobar as well. You better read up how functions work in PHP:
Code: [Select]
<?php
function my_function($foo) {
   echo 
$foo;
}

$bla 'Hello world';
my_function($bla);
?>
This example will output
Quote
Hello world
Observe the variable names!

However, it's beyond the scope of this board to teach you PHP basics.
Logged

jeepguy_1980

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 94
    • Loop Family Forum & Gallery
Re: file_data hook
« Reply #4 on: April 11, 2009, 06:10:05 am »

Thanks. Got the plugin working.  I've sent it to Sawey first, to make sure he's ok with me releasing it as a plugin.
Logged
Pages: [1]   Go Up
 

Page created in 0.022 seconds with 20 queries.