Allowing any user to post photo / link to their social networking site! Allowing any user to post photo / link to their social networking site!
 

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

Allowing any user to post photo / link to their social networking site!

Started by BIGSHOT, July 13, 2009, 03:24:26 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

BIGSHOT

Ive had a good search first and havnt found anything..

There are lots of websites like blogs for instance, where there is a page of information, or say a youtube video, with the options of 'Sharing' and you can choose to post to your Facebook, Digg, Myspace, Twitter etc. I cant write php at all but isnt there an easy way to get one of those boxes with all the sharing options so that when clubbers come to my site they can just share/post to their social networking site from mine?

Sorry gau gau in advance lol, I dont want to get into trouble for asking!  ;D

Thanks a lot everyone, Coppermine is amazing!


Joachim Müller

Such a mod/hack/plugin has not been contributed yet. You'd have to look into the APIs provided by the social networking sites and use that. Slightly different tools (coppermine running as facebook app for example) do exist though.
There can not be a swiss army tool for content syndication - since all those community sites have different APIs, you'll have to adopt the needed form of representing the data for the services you catter for. There are mods/plugins as well that just display the URL or bbcode of each embedded image for easy copy'n paste, so basically it depends on what you want to see accomplished.

Gwyneth Llewelyn

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&amp;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&amp;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! :) )

Nibbler

That's already covered by the existing hooks. The picmenu goes into $CURRENT_PIC_DATA['menu'] which then gets sent to the file_data filter. You can edit it there.


$CURRENT_PIC_DATA['menu'] = html_picture_menu();
...
$CURRENT_PIC_DATA = CPGPluginAPI::filter('file_data',$CURRENT_PIC_DATA);


Also, you can form the URL to the image using config settings like this:


$fullimagelink = $CONFIG['site_url'] . $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'];


Thanks for posting your code.

jeepguy_1980


Gwyneth Llewelyn

@Nibbler, thanks for the explanation! I guess these hooks are way harder to figure out than I thought (and searching on the forums is not easy, either!). I'm pretty sure that what is needed are good use cases for each hook, I would have never understood from the following description:

Quotefilters $pic_row when get_pic_url is called... usually this is called before any html is created so you can use this to change a lot of data

... that what this actually means is that you can change several variables (namely, $CURRENT_PIC_DATA) to add buttons, menu links, Javascript etc. to each picture as it gets displayed. And yes, I was looking for a hook on... displayimage.php, I wasn't expecting this hook to be in themes, so I've skipped that hook entirely...

You're right, no further hooks are necessary then! And jeepguy_1980, thanks so much for the example provided — although I'm just modifying the menu and not the whole html, the mod you've provided allowed me to figure out what I was actually supposed to do inside that hook!

(Now to tackle the next issue — figuring out how to apply a theme template to an external file, called from a new menu button, so that it looks perfectly integrated into the theme, and allows additional functionality, while still respecting the theme. I'm sure it'll be a nice challenge!)

For BIGSHOT's example, using ShareThis:

codebase.php

<?php
/**************************************************
  Coppermine Plugin - Add Links to include ShareThis

  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('file_data','add_links_photo');

function 
add_links_photo($CURRENT_PIC_DATA)
{
$CURRENT_PIC_DATA['menu'] .= "\n<script type=\"text/javascript\" src=\"http://w.sharethis.com/button/sharethis.js#publisher=XXX&amp;type=website\"></script>\n";

return $CURRENT_PIC_DATA;
}
?>



For ShareThis the full image link is actually not necessary, ShareThis just uses the current URL (and not the picture itself).