Simple Machines Community Forum

General Community => Scripting Help => Topic started by: aw06 on January 30, 2011, 10:18:27 PM

Title: Facebook like inside first post above the body
Post by: aw06 on January 30, 2011, 10:18:27 PM
Facebook LIKE Button HERE

I'd like to show a Facebook like button in the first post of every topic... basically where i have put in bold above..

I already have the code which i would like to call into my display.template ... Any Ideas ??? I'm trying but it's always breaking the template Need it for SMF 1.1.12

The Facebook Like code
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="button_count" show_faces="true" width="450"></fb:like>

My Display.Template
// Show the post itself, finally!

echo '

</td>

</tr></table>

<hr width="100%" size="0" style="border-top:1px solid #e1dfe1;" />

<div class="post"', $message['can_modify'] ? ' id="msg_' . $message['id'] . '"' : '', '>', $message['body'], '</div>', $message['can_modify'] ? '

<img src="' . $settings['images_url'] . '/icons/modify_inline.gif" alt="" align="right" id="modify_button_' . $message['id'] . '" style="cursor: pointer;" onclick="modify_msg(\'' . $message['id'] . '\', \'' . $context['session_id'] . '\')" />' : '' , '

</td>

</tr>';



// Now for the attachments, signature, ip logged, etc...


and how i am calling it in .. I have the FB Like code in a php file and i am trying to call it using the code below
//echo
if ($message['id'] == $context['first_message']) include 'fblike.php';
if ($message['id'] == $context['first_message']) echo '<BR>';
if ($message['id'] == $context['first_message']) echo '<BR>';


No matter what i try it breaks the layout or i get errors...
Title: Re: Facebook like inside first post above the body
Post by: Mick. on January 30, 2011, 10:49:37 PM
Here you go... use the facebook code
// Show the post itself, finally!
echo '
</td>
</tr></table>
<hr width="100%" size="1" class="hrcolor" />
<div class="post"', $message['can_modify'] ? ' id="msg_' . $message['id'] . '"' : '', '>', $message['body'], '</div>', $message['can_modify'] ? '
<img src="' . $settings['images_url'] . '/icons/modify_inline.gif" alt="" align="right" id="modify_button_' . $message['id'] . '" style="cursor: pointer; display: none;" onclick="modify_msg(\'' . $message['id'] . '\', \'' . $context['session_id'] . '\')" />' : '' , '
</td>
</tr>';



replace with:
// Show the post itself, finally!
echo '
</td>
</tr></table>
<hr width="100%" size="1" class="hrcolor" />
<div class="post"', $message['can_modify'] ? ' id="msg_' . $message['id'] . '"' : '', '>YOU FACEBOOK CODE GOES IN HERE<br>', $message['body'], '</div>', $message['can_modify'] ? '
<img src="' . $settings['images_url'] . '/icons/modify_inline.gif" alt="" align="right" id="modify_button_' . $message['id'] . '" style="cursor: pointer; display: none;" onclick="modify_msg(\'' . $message['id'] . '\', \'' . $context['session_id'] . '\')" />' : '' , '
</td>
</tr>';
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 30, 2011, 11:47:50 PM
OK, almost got it ... it works ... but it puts the button in  every post ... i just need it in the first post .. not all the replies
Title: Re: Facebook like inside first post above the body
Post by: Matthew K. on January 31, 2011, 12:21:26 AM
Do you want to put it on the right side of [This] (http://prntscr.com/1hyu5) cat_bar?
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 12:32:09 AM
Quote from: Labradoodle-360 on January 31, 2011, 12:21:26 AM
Do you want to put it on the right side of [This] (http://prntscr.com/1hyu5) cat_bar?

Naw, would love it right above the message in the first post only :)
Title: Re: Facebook like inside first post above the body
Post by: Mick. on January 31, 2011, 06:29:06 AM
Quote from: aw06 on January 30, 2011, 11:47:50 PM
OK, almost got it ... it works ... but it puts the button in  every post ... i just need it in the first post .. not all the replies
I figured that. i was waiting for your reply last night but i fell asleep. lol

try this...


// Show the post itself, finally!
echo '
</td>
</tr></table>
<hr width="100%" size="1" class="hrcolor" />
<div class="post"', $message['can_modify'] ? ' id="msg_' . $message['id'] . '"' : '', '>';if ($message['id'] == $context['topic_first_message']) echo' <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
                  <fb:like href=', $scripturl, '?topic=', $context['current_topic'], 'layout="standard" width="450" show_faces="true" action="like" colorscheme="light" /></fb:like><br>', $message['body'], '</div>', $message['can_modify'] ? '
<img src="' . $settings['images_url'] . '/icons/modify_inline.gif" alt="" align="right" id="modify_button_' . $message['id'] . '" style="cursor: pointer; display: none;" onclick="modify_msg(\'' . $message['id'] . '\', \'' . $context['session_id'] . '\')" />' : '' , '
</td>
</tr>';


Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 06:47:03 AM
Works as well .. but now no body is shown in the replies  :-[
Title: Re: Facebook like inside first post above the body
Post by: All Colours Sam on January 31, 2011, 11:14:03 AM
heres another way of doing it:

on your Sources/Display.php  find:

   // Do the censor thang.


and above add:


$facebook_share = 'YOU FACEBOOK CODE GOES IN HERE<br />';

if ($counter == 0)
$message['body'] = ($facebook_share.$message['body']);



by the way this code is from share this topic mod:  http://custom.simplemachines.org/mods/index.php?mod=2111

that mod has the option to show the facebook button only in thefirst message.
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 11:43:09 AM
Not following ...   ::) Can you explain abit more

Blue Devil your FB Like mod looks solid .. is it for 2.0 only ???
Title: Re: Facebook like inside first post above the body
Post by: All Colours Sam on January 31, 2011, 11:49:10 AM
the Display.php  is located in your Sources  folder,  go to that folder with your ftp program, download the file, open the file with your code editor  anf fine this line:

// Do the censor thang.

once you had found that line,   above that line  add the following code:

$facebook_share = 'YOU FACEBOOK CODE GOES IN HERE<br />';
if ($counter == 0)
$message['body'] = ($facebook_share.$message['body']);



and replace YOU FACEBOOK CODE GOES IN HERE   with your actual facebook code, thats all you need to do,  the code will handle the rest.

$counter == 0    makes sure the facebook button only appear in the first message of every topic.


you can do that or you can install the mod wich pretty much take care of all of that plus more options to customize and you got the twitter, buzz and digg buttons as well :)
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 12:05:14 PM
Ok kool , will give it a go  :)
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 12:27:01 PM
OK, seems to be working, but i'm having a problem where if you are logged out of facebook, it does not show the likes ..  :-[
Title: Re: Facebook like inside first post above the body
Post by: Matthew K. on January 31, 2011, 12:33:44 PM
That is probably a problem with Facebook's API then.
Title: Re: Facebook like inside first post above the body
Post by: Mick. on January 31, 2011, 12:37:23 PM
I'm at work now. Tonight I'll help you with for 1.1.12

My facebook mod shows the likes logged in or not.
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 12:42:02 PM
Quote from: Labradoodle-360 on January 31, 2011, 12:33:44 PM
That is probably a problem with Facebook's API then.

I was wondering.. but when i check other sites and on my blog it's ok ...

Quote from: Mick G. on January 31, 2011, 12:37:23 PM
I'm at work now. Tonight I'll help you with for 1.1.12

My facebook mod shows the likes logged in or not.

OK kool ... thank much :)
Title: Re: Facebook like inside first post above the body
Post by: All Colours Sam on January 31, 2011, 12:52:52 PM
whats the code yu're using to show the like button?


edit, its on the first message,   that code needs some edits on your index.template  to  fully  work properly, along with creating a facebook app,  it is better to use the iframe option:

somthing like this:

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fexample.com%2Fpage%2Fto%2Flike&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>

Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 12:57:22 PM
Quote from: Miss All Sunday on January 31, 2011, 12:52:52 PM
whats the code yu're using to show the like button?

Quote<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="button_count" show_faces="false" width="550" action="like" font="verdana"></fb:like>
Title: Re: Facebook like inside first post above the body
Post by: All Colours Sam on January 31, 2011, 12:58:01 PM
yes I did realize while I was posting, I edited my previous message, note that you need to tell facebook the url you want to share.
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 01:01:56 PM
Quote from: Miss All Sunday on January 31, 2011, 12:52:52 PM
whats the code yu're using to show the like button?


edit, its on the first message,   that code needs some edits on your index.template  to  fully  work properly, along with creating a facebook app,  it is better to use the iframe option:

somthing like this:

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fexample.com%2Fpage%2Fto%2Flike&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>

When i use the iframe code it cannot like each indevidual page,... it just defaults to liking the main domain... and that is shown where ever the like button is...

I created an app .. but i don't see anywhere in the code to put the app ID
Title: Re: Facebook like inside first post above the body
Post by: All Colours Sam on January 31, 2011, 01:07:40 PM
to be able to like an individual topic you need this variable:

$scripturl . '?topic=' . $topic . '.msg' . $message['ID_MSG'] . '#msg' . $message['ID_MSG']

the full code will look like this:

$facebook_url = $scripturl . '?topic=' . $topic . '.msg' . $message['ID_MSG'] . '#msg' . $message['ID_MSG'];
$facebook_share = '<iframe src="http://www.facebook.com/plugins/like.php?href=',$facebook_url,'&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe><br />';
if ($counter == 0)
$message['body'] = ($facebook_share.$message['body']);

 
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 01:23:36 PM
Quote from: Miss All Sunday on January 31, 2011, 01:07:40 PM
to be able to like an individual topic you need this variable:

$scripturl . '?topic=' . $topic . '.msg' . $message['ID_MSG'] . '#msg' . $message['ID_MSG']

the full code will look like this:

$facebook_url = $scripturl . '?topic=' . $topic . '.msg' . $message['ID_MSG'] . '#msg' . $message['ID_MSG'];
$facebook_share = '<iframe src="http://www.facebook.com/plugins/like.php?href=',$facebook_url,'&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe><br />';
if ($counter == 0)
$message['body'] = ($facebook_share.$message['body']);

 

Error  :-[

Parse error: syntax error, unexpected ','
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 01:41:31 PM
Ok, i tested the code on a regular page ... when click it gives the error...


The page at http://&#039;,$facebook_url,&#039;/ could not be reached.
Title: Re: Facebook like inside first post above the body
Post by: All Colours Sam on January 31, 2011, 03:09:55 PM
can you attach your Sources/Display.php file?
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 06:17:14 PM
Quote from: Miss All Sunday on January 31, 2011, 03:09:55 PM
can you attach your Sources/Display.php file?

see attached ...
Title: Re: Facebook like inside first post above the body
Post by: All Colours Sam on January 31, 2011, 06:28:00 PM
try this one, always made a backup before you modify a file.
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 06:42:13 PM
Quote from: Miss All Sunday on January 31, 2011, 06:28:00 PM
try this one, always made a backup before you modify a file.

Hmmm, that seems to be working  :) Will monitor it for a few minutes and report back ...

Possible to have it come after that message body ??? kinda got used to it in that location :P

Also how do i set the text back to verdana ??

Im adding it like

like&amp;font=verdana&amp;colorscheme=light

But it doesn't seem to be changing
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 06:59:45 PM
Hmmm .. this code not taking any changes  :-\ trying to turn off faces and no luck either ???

Even when i delete to show faces bit of code it still shows
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 07:32:20 PM
OK, Blue devil ... been testing on your site .. seems you are getting an error .. when i click like facebook gives the error..

QuoteYou failed to provide a valid list of administators. You need to supply the administors using either a "fb:app_id" meta tag, or using a "fb:admins" meta tag to specify a comma-delimited list of Facebook users.

And it didn't push the feed to my profile
Title: Re: Facebook like inside first post above the body
Post by: Mick. on January 31, 2011, 08:00:32 PM
Quote from: aw06 on January 31, 2011, 07:32:20 PM
OK, Blue devil ... been testing on your site .. seems you are getting an error .. when i click like facebook gives the error..

QuoteYou failed to provide a valid list of administators. You need to supply the administors using either a "fb:app_id" meta tag, or using a "fb:admins" meta tag to specify a comma-delimited list of Facebook users.

And it didn't push the feed to my profile

Ugh.  Facebook making changes again.  I need to look into it.  Thanx for seeing that,
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 08:06:12 PM
Yeah, the api really seems to be the problem ...

What i'm seeing is that the api see each url as different even if it's on the same page...

So if i click like on
http://www.simplemachines.org/community/index.php?action=post;topic=419777.20

Then look at it logged in or out of facebook it will show..... but if i use url say on the same page
http://www.simplemachines.org/community/index.php?action=post;topic=419777.20;last_msg=2935385

It will not show the likes .. you have to look back at the
http://www.simplemachines.org/community/index.php?action=post;topic=419777.20

Kinda crappy on facebook's end
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 08:10:10 PM
So far now .. I'm pulling it directly into display.template... and showing it below post...

<td valign="bottom" class="smalltext" id="modified_', $message['id'], '">';

if ($message['id'] == $context['topic_first_message']) echo '<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="standard" show_faces="false" width="450" action="like" font="verdana"></fb:like>';

// Show "�� Last Edit: Time by Person ��" if this post was edited.
if ($settings['show_modify'] && !empty($message['modified']['name']))


See more
http://shopinja.com/forum/index.php?board=15.0

Once we can get it to show likes on pages and not so much the url then will be good to go..
I'm going to try it with Miss All Sunday's code and see if it works any better, but with her code changing some of the values does not work.
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 08:15:23 PM
<td valign="bottom" class="smalltext" id="modified_', $message['id'], '">';

if ($message['id'] == $context['topic_first_message']) echo '<iframe src="http://www.facebook.com/plugins/like.php?href='.$facebook_url.'&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>';

// Show "�� Last Edit: Time by Person ��" if this post was edited.
if ($settings['show_modify'] && !empty($message['modified']['name']))


OK that never work ... in smf error log
8: Undefined variable: facebook_url

Facebook Error
QuoteYou must specify a URL as part of this widget or API.
Title: Re: Facebook like inside first post above the body
Post by: aw06 on January 31, 2011, 08:33:18 PM
OK, more testing .. the one on Miss All Sunday's site works perfectly ... it shows the correct likes be in your logged in or out.. and no matter the reply you view it still shows the likes...

Only problem i want to turn off faces and change the font to verdana but it's not letting me  :-\  maybe Miss All Sunday's can tell me how to move it below the message body where it will take up less space...
Title: Re: Facebook like inside first post above the body
Post by: aw06 on February 01, 2011, 12:22:38 AM
Well now magically the code i was using stop working...

Quote from: aw06 on January 31, 2011, 08:10:10 PM
So far now .. I'm pulling it directly into display.template... and showing it below post...

<td valign="bottom" class="smalltext" id="modified_', $message['id'], '">';

if ($message['id'] == $context['topic_first_message']) echo '<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="standard" show_faces="false" width="450" action="like" font="verdana"></fb:like>';

// Show "�� Last Edit: Time by Person ��" if this post was edited.
if ($settings['show_modify'] && !empty($message['modified']['name']))

The code basically just stopped showing the button ....  :o
Title: Re: Facebook like inside first post above the body
Post by: aw06 on February 01, 2011, 12:28:37 AM
Quote from: Miss All Sunday on January 31, 2011, 06:28:00 PM
try this one, always made a backup before you modify a file.

Using this code now .... like button is working correctly now ... but why can't i turn off faces and change the font ???  :-\
Title: Re: Facebook like inside first post above the body
Post by: All Colours Sam on February 02, 2011, 01:19:16 PM
tha is up completly related to facebook, if facebook ignores its own code, theres nothing you can do.

Title: Re: Facebook like inside first post above the body
Post by: aw06 on February 02, 2011, 01:29:45 PM
Quote from: Miss All Sunday on February 02, 2011, 01:19:16 PM
tha is up completly related to facebook, if facebook ignores its own code, theres nothing you can do.

yeah i realize ... i just made the height smaller to hide the faces.. all seems good to go now ..
Thanks again..