All right, I have the same issue as BIGSHOT. Doing some custom work for a client, we needed to add a few buttons (and yes, a share link to, say,
ShareThis) at the bottom of the image displayed under
displayimage.php.
The first version, who took about 30 seconds to write, was... just adding a few lines in
displayimage.php, at the end of the
html_picture_menu() function. Very easy to do
To add a link for ShareThis, for instance, all you need to do is to add, just before
return $picmenu:
$fullimagelink = "http://" . $_SERVER['SERVER_NAME'] . "/albums/pix/" . $CURRENT_PIC_DATA['filename'];
// note that the "pix" bit in the URL will depend on where your images are actually stored
$picmenu .= "<script type=\"text/javascript\" src=\"http://w.sharethis.com/button/sharethis.js#publisher=XXXX&type=website\"></script>";
// XXXX is your ShareThis publisher ID; you should of course register first with ShareThis to get it
But of course this means that with every Coppermine upgrade this file will be overwritten and you have to remember to change it.
Plugins to the rescue! Or... probably not? I know I'm spoiled with WordPress plugins, which can change so many things that you lose the trees in the forest. Coppermine seems to have a very "light" approach to plugins, and this mostly means that there are not enough hooks... and most of them seem to be active on 1.5 either (which hasn't been released yet and I'm not a beta-tester anyway).
So, for now, I've just added a brand new hook on
displayimage.php, just before
return $picmenu:
/**
* Add hook for picmenu
*/
$picmenu = CPGPluginAPI::filter('picmenu',$picmenu);
return $picmenu;
}
I wish that this would be one of the standard hooks.
Then I can create a very basic plugin:
~/plugins/addlinktophoto/configuration.php<?php
/**************************************************
Coppermine Plugin - Add Links to photo
*************************************************
Copyright (c) 2009 Gwyneth Llewelyn for Beta Technologies
*************************************************
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
***************************************************/
$name='Add Links to photo';
$description='Add Links to photo 0.9';
$author='Gwyneth Llewelyn';
$version='0.9';
?>
~/plugins/addlinktophoto/codebase.php<?php
/**************************************************
Coppermine Plugin - Add Links to photo
*************************************************
Copyright (c) 2009 Gwyneth Llewelyn for Beta Technologies
*************************************************
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
***************************************************/
if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
$thisplugin->add_filter('picmenu','add_links_photo');
function add_links_photo($html)
{
global $CURRENT_PIC_DATA;
$fullimagelink = "http://" . $_SERVER['SERVER_NAME'] . "/albums/pix/" . $CURRENT_PIC_DATA['filename'];
// change "pix" to reflect the place where your images are uploaded to
// Added by Gwyneth Llewelyn (20090808)
$html .= "<script type=\"text/javascript\" src=\"http://w.sharethis.com/button/sharethis.js#publisher=XXXX&type=website\"></script>\n";
// XXXX is your ShareThis publisher ID; you should of course register first with ShareThis to get it
return $html;
}
?>
As an exercise to the reader, this should actually have a configuration mode, where you could configure the following:
- actual directory where the images are uploaded in your installation
- if you use ShareThis, just a place to type your Publisher ID
- or a more generic thing where the user can add whatever HTML/JS they wish and it appears as a new button/link
In practice, of course, since this hook also required a change of displayimage.php, when Coppermine gets updated, this hook will disappear, making the plugin worthless. The point was having the plugin as part of the code that does NOT get overwritten by an upgrade... so, well, it helped me to learn how plugins are written for Coppermine, but is as little helpful as changing the code directly in
displayimage.php ...
If the core developers are willing to make this new hook a permanent feature, I'd be more than glad to create a new fully-fledged plugin that actually works
(Note that the only alternative to use the
current hooks is to parse the
whole HTML and add and remove bits of HTML to place your buttons/links there... which is painfully slow and a waste of time, when one extra simple hook would do everything with just a line of code!
)