Last active
August 29, 2015 14:19
-
-
Save a-fro/0c5f07dc3d0f9de772f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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