file_data hook file_data hook
 

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]

Main Menu

file_data hook

Started by jeepguy_1980, April 09, 2009, 05:58:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jeepguy_1980

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:

$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:

$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?.

Joachim Müller

#1
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: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.

jeepguy_1980

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.

Quote from: Joachim Müller on April 09, 2009, 08:18:41 AM
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.

Joachim Müller

Quote from: jeepguy_1980 on April 09, 2009, 06:36:33 PM
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:
<?php
function my_function($foo) {
   echo 
$foo;
}

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

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

jeepguy_1980

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.