Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: Texan78 on July 29, 2012, 12:25:48 PM

Title: Needing help with I think is a hook
Post by: Texan78 on July 29, 2012, 12:25:48 PM
Hello,

I have the SA Twitter and SA Facebook mod installed and works great. I just have some minor cosmetic edits I would like to make and I am not sure how since the code is not actually in the theme templates so I am not sure how to edit it. I believe these are done with hooks?

One thing I am trying to do is move the Facebook and Twitter login buttons side by side below the login boxes. See the first screenshot for example.

Second thing on the topics page I want to move the twitter button inline next to the facebook buttons so they are inline as well. See the second screenshot for example.

I believe these are done with hooks but I am not sure how to edit them. If it was just a normal template code edits it wouldn't be a problem, but it's not.

So if anyone could offer some assistance on how to make this happen with this that would be great.

-Thanks
Title: Re: Needing help with I think is a hook
Post by: themegenius on July 29, 2012, 05:44:54 PM
i think it might be in the .css file of your current theme. if your using google chrome you can right click either facebook or the twitter button and select "Inspect Element" that might give you sum tips
Title: Re: Needing help with I think is a hook
Post by: SA™ on July 29, 2012, 05:57:01 PM
the code for them in in the facebookhooks.php and twitterhooks.php

for the login buttons it is
function ob_twitter
and
public static function ob_facebook

for the share buttons it is
function template_facebook_above
and
function template_twitter_above
Title: Re: Needing help with I think is a hook
Post by: Texan78 on July 29, 2012, 05:57:05 PM
If that was true and it was in my CSS shouldn't there still be a ID or Class in the template to reference? There is no reference to the code anywhere in the template related to those buttons.
Title: Re: Needing help with I think is a hook
Post by: Texan78 on July 29, 2012, 05:58:23 PM
Quote from: SA™ on July 29, 2012, 05:57:01 PM
the code for them in in the facebookhooks.php and twitterhooks.php

for the login buttons it is
function ob_twitter
and
public static function ob_facebook

for the share buttons it is
function template_facebook_above
and
function template_twitter_above

Thanks SA, I will take a look and see what I can do about repositioning them.
Title: Re: Needing help with I think is a hook
Post by: Texan78 on July 29, 2012, 06:05:42 PM
Ok I found the code for the Twitter login, but how do I change where it is positioned? Do I just put it into the template?

function ob_twitter(&$buffer){
    global $txt, $context,$settings, $modSettings, $url;
   
if(empty($modSettings['tw_app_enabled']) || isset($_REQUEST['xml']))
   return $buffer;

if (!$context['user']['is_logged']){
   
$twitterObjUnAuth = new EpiTwitter($modSettings['tw_app_id'], $modSettings['tw_app_key']);
        try {
    $url = $twitterObjUnAuth->getAuthenticateUrl();
    }
catch (Exception $e) {
            $url = '';
        }

    $txt['guestnew'] = sprintf($txt['welcome_guest'], $txt['guest_title']);

    $buffer = preg_replace('~(' . preg_quote($txt['forgot_your_password']. '</a></p>') . ')~', ''. $txt['forgot_your_password']. '</a></p><div align="center"><a href="'.$url.'"><img src="http://si0.twimg.com/images/dev/buttons/sign-in-with-twitter-l.png" alt="'.$txt['twittsign'].'"/></a></div>', $buffer);
    $buffer = preg_replace('~(' . preg_quote('<div class="info">'. $txt['guestnew']. '</div>') . ')~', '<a href="'.$url.'"><img src="'.$modSettings['tw_app_log_img'].'" alt="'.$txt['twittsign'].'"/></a><br /><div class="info">'. $txt['guestnew']. '</div>', $buffer);
    $buffer = preg_replace('~(' . preg_quote('<dt><strong><label for="smf_autov_username">'. $txt['username']. ':</label></strong></dt>') . ')~', '<dt>'.$txt['twittregister'].'</dt><dd><a href="'.$url.'"><img src="http://si0.twimg.com/images/dev/buttons/sign-in-with-twitter-l.png" alt="'.$txt['twittsign'].'"/></a></dd><dt><strong><label for="smf_autov_username">'. $txt['username']. ':</label></strong></dt>', $buffer);
}

return $buffer;
}
Title: Re: Needing help with I think is a hook
Post by: SA™ on July 30, 2012, 02:04:18 PM
well this is where the code will be injected to
$txt['forgot_your_password']. '</a></p> in other word it looks for that code then injects the button

so you could actualy just comment out
$buffer = preg_replace('~(' . preg_quote($txt['forgot_your_password']. '</a></p>') . ')~', ''. $txt['forgot_your_password']. '</a></p><div align="center"><a href="'.$url.'"><img src="http://si0.twimg.com/images/dev/buttons/sign-in-with-twitter-l.png" alt="'.$txt['twittsign'].'"/></a></div>', $buffer);

and then just put this
show_twitter_login()
where you want the button in you themes index.template.php
Title: Re: Needing help with I think is a hook
Post by: Texan78 on July 30, 2012, 10:42:58 PM
Thanks SA, I commented out the line you suggested. It didn't hide the button. I had to comment out the line below to hide the button. Which is this line....

//$buffer = preg_replace('~(' . preg_quote('<div class="info">'. $txt['guestnew']. '</div>') . ')~', '<a href="'.$url.'"><img src="'.$modSettings['tw_app_log_img'].'" alt="'.$txt['twittsign'].'"/></a><br /><div class="info">'. $txt['guestnew']. '</div>', $buffer);

Is that ok? I mean it worked, but not sure if that will cause issues in other places.

I then placed show_twitter_login() in my index template and that works perfect. I tried show_facebook_login() and show_fb_login() to get the facebook button to show and nether of them worked. Is there a different way to do it for Facebook?

One thing I also noticed is when you log in the sign in with twitter button doesn't disappear like it does now.


Sorted that one issue out by doing this. So it only shows for users not logged in. It works, is that ok is there a better way?

// Twitter and Facebook login for guest or user not logged in.
if ($context['user']['is_guest'])
{
          show_twitter_login(); echo '&nbsp;';
}


Thank you for all your help, making huge progress on getting this last issue knocked out so I can launch my boards. I can't thank you enough.
Title: Re: Needing help with I think is a hook
Post by: SA™ on July 31, 2012, 11:56:36 AM
in facebook admin there is hook page the code you need isin there for the facebook one

if(class_exists('SAFacebookhooks'))
    $fb_hook_object->call_facebook_hook('show_facebook_login',array(true));
[/code]
Title: Re: Needing help with I think is a hook
Post by: Texan78 on July 31, 2012, 02:18:10 PM
I saw that code in the Admin panel for FB and copied it on put it where I need it. The twitter button shows no problem, but the FB doesn't show. I did notice in one of the FB files in the array it says show_twitter_login. Shouldn't that say Facebook instead?

Here is what I have in my template

// Show Twitter and Facebook login for guest if not logged in
if ($context['user']['is_guest'])
{
          show_twitter_login(); global $fb_hook_object;
if(class_exists('SAFacebookhooks'))
    $fb_hook_object->call_facebook_hook('show_facebook_login',array(true));
}


Here is the array before the call for the login button. Notice it says twitter, should that say facebook?

public static function call_facebook_hook($hook, $parameters = array()){
   
    $results = array();

    $functions = array(
        'show_facebook_friendpile',
    'show_facebook_comments',
    'show_facebook_like_button',
    'show_facebook_send',
    'show_facebook_live',
    'show_facebook_activity',
    'show_facebook_recomendation',
    'show_facebook_likebox',
    'show_twitter_login()',

    );


Again, thank you for all your help
Title: Re: Needing help with I think is a hook
Post by: SA™ on July 31, 2012, 03:01:48 PM
yeah it should be show_facebook_login
Title: Re: Needing help with I think is a hook
Post by: Texan78 on July 31, 2012, 06:56:45 PM
I had changed it and tried it with the change but it didn't work. So I uploaded a recent and fresh copy of the facebookhooks.php and now it works great.

So now I am trying to put those buttons in the display template inline together. I used to the social hooks from facebook admin to create the new buttons. Now where I am stuck at is what do I put for the URL so it Likes that page it is on. Also what do I need to comment out in the hooks.php page so I don't have doubles. Same for the twitter page, and what code do I call for the tweet button to show. I can't find it.

Quoteglobal $fb_hook_object;
if(class_exists('SAFacebookhooks'))
    $fb_hook_object->call_facebook_hook('show_facebook_like_button',array('URL','like','true','button_count','light','true',true));
-Thanks
Title: Re: Needing help with I think is a hook
Post by: SA™ on July 31, 2012, 09:12:07 PM
for the url
$turl = ''.$scripturl .'?topic='.$context['current_topic'].'.0';

then use $turl

just disable the like button in the admin to remove it there is no real need to remove or comment here

foor the twitter you can use this
echo'<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="'.$context['data_via'].'">'.$txt['twti'].'</a>
       <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>';


just change '.$context['data_via'].' to you twitter username and again just disble it in admin to remove it
Title: Re: Needing help with I think is a hook
Post by: Texan78 on August 02, 2012, 02:23:00 PM
Quote from: SA™ on July 31, 2012, 09:12:07 PM
for the url
$turl = ''.$scripturl .'?topic='.$context['current_topic'].'.0';

then use $turl

Ok sorry, I am have a brain fart at the moment. Where do I insert that code? I have tried it in the FacebookHooks.php and display.template.php where the code is for the button. Then used the $turl  in the hook to display the button but it doesn't work. It shows in Facebook as shown below. FYI, image and name was removed for privacy, but it does show.

global $fb_hook_object;
if(class_exists('SAFacebookhooks'))
    $fb_hook_object->call_facebook_hook('show_facebook_like_button',array('$turl','like','true','button_count','light','true',true));


(http://www.mesquiteweather.net/weatherconnection/images/FB_WC_Like.png)

Is there anyways I can adjust the padding on the left and right of the FB buttons? As you can see it leaves a gap on both sides. Bigger on the right as you can see. I don't mind putting it on ether side as long as I can adjust the padding so they look more uniform.

(http://www.mesquiteweather.net/weatherconnection/images/tweet_left.png)

(http://www.mesquiteweather.net/weatherconnection/images/tweet_right.png)

Quote from: SA™ on July 31, 2012, 09:12:07 PMjust disable the like button in the admin to remove it there is no real need to remove or comment here

Duh, don't know why I didn't think of that...LoL I was trying to do it the hard way and comment out the code. Makes sense, when I commented out the FB code it wouldn't show at all. I disabled them in the Admin panel and it works great as you can see from the screen shots with the exception of the small padding issue.

-Thanks!
Title: Re: Needing help with I think is a hook
Post by: SA™ on August 03, 2012, 04:22:29 PM
add
$turl = ''.$scripturl .'?topic='.$context['current_topic'].'.0';
befor
$fb_hook_object->call_facebook_hook('show_facebook_like_button',array('$turl','like','true','button_count','light','true',true));

it is this part in facebookhooks.php that causes the gap
<div id="fb-root"></div> i did find an anser for this a while back but i cant rember now your have to google around for a bit
Title: Re: Needing help with I think is a hook
Post by: Texan78 on August 06, 2012, 02:39:43 AM
It should be like below correct? If so, I am still getting the same results. Is there something else I am not doing that is causing it to output incorrectly that I may be missing?

global $fb_hook_object;
if(class_exists('SAFacebookhooks'))
    $turl = ''.$scripturl .'?topic='.$context['current_topic'].'.0';
    $fb_hook_object->call_facebook_hook('show_facebook_like_button',array('$turl','like','true','button_count','light','true',true));


-Thanks!

Title: Re: Needing help with I think is a hook
Post by: SA™ on August 07, 2012, 01:03:43 PM
yup that right but do you get any errors in you error logs ?

maybebe $context and $scripturl or not globaled?

global $fb_hook_object, $context, $scripturl;
Title: Re: Needing help with I think is a hook
Post by: Texan78 on August 07, 2012, 05:52:52 PM
Quote from: SA™ on August 07, 2012, 01:03:43 PM
yup that right but do you get any errors in you error logs ?

maybebe $context and $scripturl or not globaled?

global $fb_hook_object, $context, $scripturl;

No, I am not getting any errors related to this.

What are you referring to by "maybebe $context and $scripturl or not globaled?"

global $fb_hook_object, $context, $scripturl;

-Thanks

Title: Re: Needing help with I think is a hook
Post by: SA™ on August 07, 2012, 11:05:00 PM
sry i ment replace global $fb_hook_object; with global $fb_hook_object, $context, $scripturl;
Title: Re: Needing help with I think is a hook
Post by: Texan78 on August 08, 2012, 10:07:49 AM
Tried the suggestion with no luck. What's strange is it works fine when the mod is placing the button. Just doesn't work when use the hook to place it. Any other suggestions maybe?

Here's what I tried

global $fb_hook_object, $context, $scripturl;
          if(class_exists('SAFacebookhooks'))
               $turl = ''.$scripturl .'?topic='.$context['current_topic'].'.0';
               $fb_hook_object->call_facebook_hook('show_facebook_like_button',array('$turl','like','true','button_count','light','true',true));


-Thanks!
Title: Re: Needing help with I think is a hook
Post by: SA™ on August 08, 2012, 11:40:47 AM
hmmm you got a link where i can see the liek button on your site the one in your profile is givving me server erros
Title: Re: Needing help with I think is a hook
Post by: Texan78 on August 08, 2012, 12:36:13 PM
Sorry about that SA, I changed domains yesterday and didn't update my profile to reflect the new url. Try it now, it should work.

-Thanks
Title: Re: Needing help with I think is a hook
Post by: SA™ on August 08, 2012, 01:48:21 PM
my bad i think '$turl' shuold just be $turl fixed code below

$fb_hook_object->call_facebook_hook('show_facebook_like_button',array($turl,'like','true','button_count','light','true',true));
Title: Re: Needing help with I think is a hook
Post by: Texan78 on August 08, 2012, 02:01:05 PM
BAAAAM! That did the trick! Believe everything if fully functional. Thank you so much for your time and patients SA. I really appreciate it.

-Thanks Again!
Title: Re: Needing help with I think is a hook
Post by: SA™ on August 08, 2012, 02:03:47 PM
np  :D