Skip to content

Instantly share code, notes, and snippets.

@bangpound
Created April 14, 2011 21:55
Show Gist options
  • Save bangpound/920653 to your computer and use it in GitHub Desktop.
Save bangpound/920653 to your computer and use it in GitHub Desktop.
exposes share links using social media APIs.
<?php
function XXX_node_view($node, $view_mode, $langcode) {
if ($view_mode == 'full' && in_array($node->type, array('blog', 'release', 'report', 'review', 'story'))) {
// http://dev.twitter.com/pages/tweet_button
$links['twitter'] = array(
'title' => t('Tweet'),
'href' => 'http://twitter.com/share',
'attributes' => array(
'class' => 'twitter-share-button',
),
'query' => array(
'url' => url($node->uri['path'], array('absolute' => TRUE)),
'via' => 'XXX',
'text' => $node->title,
'counturl' => url($node->uri['path'], array('absolute' => TRUE, 'alias' => TRUE)),
),
);
$script = <<<EOT
window.fbAsyncInit = function() {
FB.init({appId: 'XXX', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
EOT;
drupal_add_js($script, array('type' => 'inline', 'scope' => 'footer'));
$links['facebook'] = array(
'title' => '<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="button_count" show_faces="false" width="90" action="recommend" font="verdana"></fb:like>',
'html' => TRUE,
'query' => array(
'url' => url($node->uri['path'], array('absolute' => TRUE)),
'via' => 'intifada',
'text' => $node->title,
'counturl' => url($node->uri['path'], array('absolute' => TRUE, 'alias' => TRUE)),
),
);
$node->content['links']['sharing'] = array(
'#theme' => 'links__node__sharing',
'#links' => $links,
'#attributes' => array('class' => array('links', 'inline')),
);
$node->content['links']['#attached']['js']['http://platform.twitter.com/widgets.js'] = array(
'type' => 'external',
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment