forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 plugins => Topic started by: jeepguy_1980 on April 09, 2009, 05:58:02 am

Title: file_data hook
Post by: jeepguy_1980 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?.
Title: Re: file_data hook
Post by: Joachim Müller 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.
Title: Re: file_data hook
Post by: jeepguy_1980 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.
Title: Re: file_data hook
Post by: Joachim Müller 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.
Title: Re: file_data hook
Post by: jeepguy_1980 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.