News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Needing help with I think is a hook

Started by Texan78, July 29, 2012, 12:25:48 PM

Previous topic - Next topic

Texan78

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

themegenius

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

SA™

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
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Texan78

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.

Texan78

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.

Texan78

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;
}

SA™

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
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Texan78

#7
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.

SA™

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]
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Texan78

#9
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

SA™

yeah it should be show_facebook_login
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Texan78

#11
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

SA™

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
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Texan78

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));




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.





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!

SA™

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
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Texan78

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!


SA™

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;
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Texan78

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


SA™

sry i ment replace global $fb_hook_object; with global $fb_hook_object, $context, $scripturl;
http://samods.github.io/SAChatBar/

Xbox Live: smokerthecheese 360 or xbone
My Work
Piano Movers / Delivery service
QuoteMy allies are dead.
I'm 'bout to be too.
Zombies are chasing me.
F*** it, I'm screwed -___-

Texan78

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!

Advertisement: