Facebook Like button, how to create one for Gallery 2: fixes thumbnail not appearing in facebook

battledingo
battledingo's picture

Joined: 2006-08-25
Posts: 39
Posted: Mon, 2012-10-01 13:27

Create a facebook like button for gallery 2

Hi

Here is how to make a facebook like button for Gallery 2 Module. I didn't do any coding just read multiple forums & got help from the legend Mr.Flori Dave. Thanks Flori Dave for your help and knowledge.

1. Add the like button:

In photo.tpl which is found at /public_html/gallery/themes/(your theme name here)/templates/

(It is safer to add a folder local to the templates folder & copy photo.tpl to it. Now edit the file from the local folder)

Somewhere around halfway down your photo.tpl file, find:

Quote:
{else}
{g->text text="There is nothing to view for this item."}
{/if}
</div>

Now pop this in below it:

Quote:
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.YOUR_SITE_URL.com{g->url arg1="view=core.ShowItem" arg2="itemId=`$theme.item.id`"} &amp;layout=standard&amp;show_faces=true&amp;layout=standard&amp;width=500&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=lucida+grande&amp;height=35&amp;appId=your_facebook_app_id" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:35px;" allowTransparency="true"></iframe>

Be sure to change

to whatever your site is, I didn't add my gallery url to the end and it works. My gallery directory is "gallery", don't know if this code would work if your gallery is located under another name...

Also change

Quote:
your_facebook_app_id.

To get a facebook app id see the troubleshooting notes below. It is easy to do.

You now have a like button, however there will be no thumbnail on your facebook page.

2. Add the code for the facebook page so the thumbnail appears:

In theme.tpl which is found at /public_html/gallery/themes/(your theme name here)/templates/

(It is safer to add a folder local to the templates folder & copy theme.tpl to it. Now edit the file from the local folder)

Place this code between the <head> and </head> tags, don't forget to change the "http://www.your_website_here" and register a facbook app id to get the app number (see below) :

Quote:
<meta property="og:title" content="{ $theme.item.title }" />
<meta property="og:type" content="article" />
<meta property="og:image" content='http://www.your_website_here{g->url arg1="view=core.DownloadItem"}&g2_itemId={"`$theme.item.id`"}' />
<meta property="og:url" content='http://www.your_website_here{g->url arg1="view=core.ShowItem" arg2="itemId=`$theme.item.id`"}' />
<meta property="og:site_name" content="change this to your website name" />
<meta property="og:description" content="This site is awesome!" />
<meta property="fb:app_id" content="YOUR_APP_ID" />

3. Now make the thumbnail image appear by adding the following code in modules/core/DownloadItem.inc

Under this row:

Quote:
$fileName = GalleryUtilities::getRequestVariables('fileName');

I just change the mailicous-url-checker from...

Quote:
if (!empty($fileName) && $fileName != $pseudoFileName) {

to...

Quote:
if (!empty($fileName) && $fileName != $pseudoFileName && urldecode($fileName) != $pseudoFileName) {

You now should have a working like button for gallery 2.

Here are my sources:

1. Adding the like button: http://gallery.menalto.com/node/95707 (credits to cozbaldwin)
I modified the code slightly taken from the facebook like button code generator (http://developers.facebook.com/docs/reference/plugins/like/).

2. Adding the meta properties:

http://stackoverflow.com/questions/10689677/facebook-like-button-tag-missing-error-how-do-i-fix-it
http://gallery.menalto.com/node/95707 (credits to varun7pathak)

3. Help facebook recognise the url links (credits to Tornevall):

http://gallery.menalto.com/node/96164#comment-359843


Troubleshooting:

If you can't see the thumbnail image on facebook delete your browser cache or try another browser when you press the like button.

To create a app id number:

1.Login to Facebook

2. Go to Facebook Developers Application page https://developers.facebook.com/apps

3. From all those unsuccessful trials, choose one app that you set up for a target before

4. Within the description, you will find APP ID

This debugger is your best friend:

http://developers.facebook.com/tools/debug

(Copy & paste your URL containing the like button into the address bar and fix any error messages by editing the theme.tpl file (found in section 2.)

Learn how to code the metadata: http://ogp.me/

:) happy coding

 
mckeown2
mckeown2's picture

Joined: 2012-10-01
Posts: 1
Posted: Mon, 2012-10-08 09:25

Thanks for your time and effort and in putting this together battledingo. Been trying to put this in place for a while. I've just cracked it with your steps.

You've really helped me out!!

mckeown2
Noise Cancelling Headphones Review

 
battledingo
battledingo's picture

Joined: 2006-08-25
Posts: 39
Posted: Mon, 2012-10-01 17:47

No worries, glad to help you out.