function sharethis_node_view in ShareThis 7
Same name and namespace in other branches
- 8.2 sharethis.module \sharethis_node_view()
- 7.2 sharethis.module \sharethis_node_view()
Implements hook_node_view.
Inserts ShareThis widget code onto each node view. TODO: Want to add the option somewhere to select nodes.
Parameters
node : The node that is being acted upon
view_mode : The type of view (teaser, full, etc)
langcode: Information about the language
File
- ./
sharethis.module, line 272 - A module that adds one of the ShareThis widget to your website.
Code
function sharethis_node_view($node, $view_mode, $langcode) {
// Don't display if searched
if ($view_mode == 'search_result' || $view_mode == 'search_index') {
return;
}
// First get all of the options for the sharethis widget from the database:
$data_options = get_options_array();
// This looks to see if the path variable has been posted by some rewrite module.
// This is not super efficient, O(N), but N is often less than 20.
$is_path = FALSE;
foreach ($node as $k => $v) {
if ($k == "path") {
$is_path = TRUE;
}
}
// This will choose the path to use.
if ($is_path) {
$path_module = $node->path;
}
else {
$path_module = "/node/" . $node->nid;
}
// Pathauto integration !
if (module_exists('pathauto')) {
$path_module = '/';
$path_module .= drupal_lookup_path('alias', "node/" . $node->nid);
}
global $base_url;
// Get the full path to insert into the Share Buttons.
$mPath = $base_url . $path_module;
$mTitle = $node->title;
// Only display the ShareThis buttons if this node fits all the requirements
if (strpos($data_options['nodeType'], $node->type) !== FALSE) {
// Make sure this is the right type of node.
if ($data_options['viewMode'] == "1" && $view_mode == "teaser") {
// If "don't show for teaser" is enabled, and this is a teaser, don't do anything
// Do nothing.
}
else {
// This puts the buttons on the node and adds the necessary scripts.
// You can change the weight to change whether the buttons are near the top or bottom of the node.
// Default is at the bottom:
$node->content['my_additional_field'] = array(
'#markup' => get_button_HTML($data_options, $mPath, $mTitle),
'#weight' => 10,
);
}
}
}