Plugin hook suggestions for cpg1.5.x Plugin hook suggestions for cpg1.5.x
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Plugin hook suggestions for cpg1.5.x

Started by Joachim Müller, July 31, 2009, 08:02:26 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Joachim Müller

Although cpg1.5.x is in the feature freeze stage, which means that no more features can/will be added before the release, the dev team has decided that there will be an exception to this rule: plugin hooks can still be added.
We want to encourage plugin authors to request additional plugin hooks at this stage, with an alpha release being available to test things with.
So if you want to start porting a plugin written for cpg1.4.x to cpg1.5.x or if you have an idea for a new plugin for cpg1.5.x that you want to write, please go ahead and let us know in this thread what plugin hook you need.

@newbies/non-coders: this thread does not deal with plugin requests, so please do not ask for plugins to be written or ported for you here. This thread is for coders who already know what a plugin hook is. This thread only exists for coders to request additional plugin hooks.

If you actually want to request a new hook, just roughly explain what your plugin is suppossed to do and where exactly you want your hook to reside at (between line X and line Y in file Z). Please also state what the expected return value will be (if any).

Joachim

P.S. All unrelated replies to this thread will be deleted without further notice

Αndré

#1
May I add this plugin hook to include/mailer.inc.php?
   $sender_email = CPGPluginAPI::filter('cpg_mail_sender_email', $sender_email);

Explanation: I use a free hoster for my CPG. I figured out, that emails from the sender 'xyz@googlemail.com' will not be sent but a message is displayed, that the email has been sent successfully. If I change the sender address to '@gmail.com' everything works fine.

Maybe there are some limitations on other free hosters and someone else can use this hook.


Edit:
I just remembered, that it's also not possible to sent emails with more than one recipient on my webhost. So I'd need another hook to sent multiple emails with only 1 recipient or to sent emails sent to 'admin' only to 'gallery_admin_email'.


Additional plugin hooks can't hurt, right? 8)

Joe Carver

Plugin hook requests. Pages with user (guest level) input. Purpose - spam control, adding captcha or other methods to user's form submissions.

This is for three pages now not protected by captcha: Ecard + Report to Moderator + Login.
Example used here is ecard. I am not sure if I have the right line numbers or if the concept/request
is being communicated properly. In any case I didn't want to write a long post and will be happy to reply if needed.

Ecard example hook 1 validate submission - somewhere between lines 149 - 156 and similar to:
$error = CPGPluginAPI::filter('captcha_ecard_validate', $error);


Ecard example 2 display a captcha or alternative - at or below line 425 and similar to:
$subecard_print = CPGPluginAPI::filter('ecard_submit_print',$subecard_print);

The same concepts also for Report and Login: A hook to show a captcha on the form at or near the Submit button and a hook prior to where the submission is processed and data is written to db, etc..

This is not a direct request for the exact same Captcha hooks to be placed into Ecard, Report and Login as the ones now being used. However if that would be more compatible/consistent with the overall way 1.5 is to run then please consider it as a suggestion only.


Αndré

Quote from: Αndré on August 18, 2009, 01:43:03 PM
May I add this plugin hook to include/mailer.inc.php?
Added plugin hooks 'cpg_mail_to_email' & 'cpg_mail_sender_email' in r6545.

Joe Carver

Please, if it is possible and not too much trouble, could this hook be added?

File: index.php

Location: Directly below this: (around line 1122)
$elements = explode('/', $CONFIG['main_page_layout']);

Similar to:
$elements = CPGPluginAPI::filter('alt_page_layout', $elements);

Purpose: Plugin to allow differences in page layout (from home page) when visitor clicks on "Album list"

I hope that it is not too late for requests here. At the moment I have a rough working version of a plugin using that hook. It seems to function OK without interference elsewhere.

Thanks!

Joachim Müller


jayhunter

Hey,

I needed a hook to do an md5 dupe check on uploads. These get triggered right before the file is moved to it's final location.

For HTML upload in file db_input.php
Find line 619:
    $uploaded_pic = $dest_dir . $picture_name;


After that add:
    // Give plugins a chance to error check
    $upload_plugin_error = CPGPluginAPI::filter('upload_html_pre_move');
    if ($upload_plugin_error) {
        cpg_die(ERROR, $upload_plugin_error, __FILE__, __LINE__);
    }




For SWF upload in file upload.php

Find around line 1015:
    // prevent moving the edit directory...
    if (is_dir($path_to_image)) {
        echo 'error|'.$lang_upload_php['failure'] . " - '$path_to_image'|0";
        exit;
    }


After that add:
    // Give plugins a chance to error check
    $upload_plugin_error = CPGPluginAPI::filter('upload_swf_pre_move');
    if ($upload_plugin_error) {
        echo 'error|'.$upload_plugin_error.'|0';
        exit;
    }


Works great for me ...

Cheers
Jayhunter

Αndré

Quote from: jayhunter on September 26, 2010, 03:46:30 PM
Hey,

I needed a hook to do an md5 dupe check on uploads. These get triggered right before the file is moved to it's final location.

For HTML upload in file db_input.php
Find line 619:
    $uploaded_pic = $dest_dir . $picture_name;


After that add:
    // Give plugins a chance to error check
    $upload_plugin_error = CPGPluginAPI::filter('upload_html_pre_move');
    if ($upload_plugin_error) {
        cpg_die(ERROR, $upload_plugin_error, __FILE__, __LINE__);
    }




For SWF upload in file upload.php

Find around line 1015:
    // prevent moving the edit directory...
    if (is_dir($path_to_image)) {
        echo 'error|'.$lang_upload_php['failure'] . " - '$path_to_image'|0";
        exit;
    }


After that add:
    // Give plugins a chance to error check
    $upload_plugin_error = CPGPluginAPI::filter('upload_swf_pre_move');
    if ($upload_plugin_error) {
        echo 'error|'.$upload_plugin_error.'|0';
        exit;
    }


Works great for me ...

Cheers
Jayhunter

Your hook suggestion is too specific imo. I suggest to add the following hooks.

Instead of adding
    // Give plugins a chance to error check
    $upload_plugin_error = CPGPluginAPI::filter('upload_html_pre_move');
    if ($upload_plugin_error) {
        cpg_die(ERROR, $upload_plugin_error, __FILE__, __LINE__);
    }

we should add
CPGPluginAPI::action('upload_html_pre_move');


And instead of adding
    // Give plugins a chance to error check
    $upload_plugin_error = CPGPluginAPI::filter('upload_swf_pre_move');
    if ($upload_plugin_error) {
        echo 'error|'.$upload_plugin_error.'|0';
        exit;
    }

we should add
CPGPluginAPI::action('upload_swf_pre_move');


You can check for errors directly in your plugin code and let Coppermine die etc.

jayhunter

Quote from: Αndré on September 27, 2010, 11:13:24 AM
Your hook suggestion is too specific imo.

You're right. Your suggestions are way cleaner. Wasn't thinking right. ;)

Αndré

Will add that hooks probably tomorrow after reviewing the code. Maybe there's also another (better) solution ;)

jayhunter

Quote from: Αndré on September 27, 2010, 06:15:47 PM
Will add that hooks probably tomorrow after reviewing the code. Maybe there's also another (better) solution ;)

Yeah. Actually, the upload handling in total is a bit unclean imho. Kind of massed up to have the SWF upload and HTML form output in one file but the HTML upload processing in another. A clean separation into an upstream upload plugin/method handler and the different proccesing methods would be nice.

Back to topic.

In picmgnt.inc.php line 36 or so
    $add_file_error = CPGPluginAPI::filter('add_file_start');
    if ($add_file_error) {
        return $add_file_error;
    }

might do the trick. But as i see it there is not much to work with at that point. For my purpose i'd need $work_image (or similar) to be global or to be passed with the filter.

An action hook wouldn't do me any good here, as I don't want to have to deal with further error handling (like unlinking files that have already been moved) only because my dupe check machted something. Also the different upload methodes need different output to die properly.

Well, maybe you come up with the ultimate idea. :)

Thanks very much.

Jayhunter

jayhunter

Hey there. Me again. :)

First I wanted to ask: Any news on the upload_pre_move or add_file_start hooks?

Secondly I got a new hook suggestion. I use it in conjunction with add_file_data_success and after_delete_file to keep a keyword cache up-to-date. Would love to see this one added.

In editpics.php find line 367
            cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET $update WHERE pid = $pid");

After that add:
            // Plugin filter to be called after a file update is committed
            CPGPluginAPI::filter('after_edit_file', $pid);


And in edit_one_pic.php find line 165
    $query = "UPDATE {$CONFIG['TABLE_PICTURES']} SET $update WHERE pid='$pid' LIMIT 1";

    cpg_db_query($query);

After that also add:
    // Plugin filter to be called after a file update is committed
    CPGPluginAPI::filter('after_edit_file', $pid);


Cheers
Jayhunter

Gallery @ http://htbackdrops.com

Αndré

Hello jayhunter. I finally found some time to have a look at this topic again.

Regarding your dupe check:
- Hook 'upload_html_pre_move': if your plugin uses cpg_die(); everything should be okay. The file resides in the temp directory and will be deleted automatically  I think.
- Hook 'upload_swf_pre_move': I currently don't know if Coppermine has a garbage collection for the edit folder, but I think it hasn't. So you'll have to unlink that file within your plugin before you return your error message.
- Hook 'add_file_start': I also think that hook isn't the best solution for your purpose because of the different output to die properly.


Regarding your keyword cache:
- Hooks 'after_edit_file': as you don't want to filter anything but you just want to perform something (without modifying the passed values) I suggest to use an action hook. It's been a while I had a look at the plugin API, but I afaik the only difference between filter and action hooks is the name (= they work the same way, can return something or do anything else).

jayhunter

Hey André.

Thanks for your response.

I actually already use simple action hooks for 'upload_swf_pre_move' and 'upload_html_pre_move'.
And I don't perform any file unlinking. upload.php and db_input.php don't do it either at that point. That would just have been necessary with the 'add_file_start' hook as the files already would have been moved to their final location here.

An action for 'after_edit_file' is okay for me too. I used filter here .. well, because I copied it from 'before_delete_file' or 'after_delete_file', which should be action hooks, too. Atleast by your definition. :)

Cheers
Jayhunter

Αndré

I'll add the discussed hooks (except add_file_start) soon, probably tomorrow.

Αndré


programista

I think that there should be a hook for displaying additional content in some special case pages or pages that show up in response to post, like information message after registering but when only admin can activate account - it would simplify making additional register futures like account activation only after payment.

Short example - user registers, only admin can activate account, user gets a message of this, the line 632 in register.php i responsible for this:

msg_box($lang_register_php['information'], $lang_register_php['thank_you_admin_activation'], $lang_common['continue'], 'index.php');

Now i would like to not change anything in register.php but i would like to display some additional markup with payment options to activate account, instead of only showing a msg_box, it should also give access to registered user data in case i would like to generate payment markup from that data.

In simple scenario this would work with an iframe that generates output based on user name or email sent as query string to that iframe script and showing the return html instead of that message.
As for now i need to change the register.php code, because there are no other way.

Αndré

What's your actual hook suggestion? We already have some hooks for the registration process (register_form_create, register_form_submit,    register_user_activation) and you can always use the page_html hook to modify every page.

1aB

It would be cool if the appearance of the album information in the "alblist" (index.php, function list_albums) could be customized by a plugin, to e.g. add a small button (social_sharing plugin)

Not sure if the hook should be best inside function list_albums (then probably just before calling theme_display_album_list)
- in the hook the plugin would have to go through all the $alb_list allbum datastructure at once, and could add to all albums' titles or descriptions or whatever it finds in the data structure.

or in function theme_display_album_list (then probably just before calling template_eval($album_cell, $params) )
- the plugin could adjust the $params and would be called individually for each album in a hook like this
- would it be a disadvantage for a plugin to use a hook which is "themed" and might not be called by all possible themes?

paperlife

unsure if this is a revival, or will even be viewed, but i searched, and have ideas...but don't know code **yet))

upon upload, have uploader remember last location of last image (this is useful in single item upload) as many pics are 3 or more levels deep, and there seems to be a time limit on selection

remove time limit on selecting images to upload