Skip to content

Instantly share code, notes, and snippets.

@a-fro
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-fro/0c5f07dc3d0f9de772f4 to your computer and use it in GitHub Desktop.
Save a-fro/0c5f07dc3d0f9de772f4 to your computer and use it in GitHub Desktop.
<?php
/**
* Implements hook_node_view().
*/
function tweet_this_node_view($node, $view_mode, $langcode) {
if ($view_mode == "full" && $node->type == "article") {
_tweet_this_generate_button($node);
}
}
function _tweet_this_generate_button(&$node) {
$href = _tweet_this_prepare_url_string($node);
$node->content['tweet_this']['#markup'] = "<button href='$href'>Tweet This!</button>";
$node->content['tweet_this']['#weight'] = 15;
}
/**
* Uses node values to generate the appropriate intent url
*/
function _tweet_this_prepare_url_string($node) {
$twitter_url = 'https://twitter.com/intent/tweet?';
$twitter_url .= 'text=' . urlencode($node->title),
$twitter_url .= '&hashtags=' . $node->field_category[LANGUAGE_NONE][0]['taxonomy_term']->name;
$twitter_url .= '&url=' . url(current_path(), array('absolute' => TRUE));
return $twitter_url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment