function sharethis_node_view in ShareThis 7.2
Same name and namespace in other branches
- 8.2 sharethis.module \sharethis_node_view()
- 7 sharethis.module \sharethis_node_view()
Implements hook_node_view().
File
- ./
sharethis.module, line 69 - 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 the user is currently searching, or in the RSS feed.
switch ($view_mode) {
case 'search_result':
case 'search_index':
case 'rss':
return;
}
// First get all of the options for the sharethis widget from the database:
$data_options = sharethis_get_options_array();
// Get the full path to insert into the Share Buttons.
$mPath = url('node/' . $node->nid, array(
'absolute' => TRUE,
));
$mTitle = $node->title;
// Check where we want to display the ShareThis widget.
$location = variable_get('sharethis_location', array(
'content' => 'content',
));
if (in_array('content', $location, TRUE)) {
$enabled_types = $data_options['sharethis_node_types'];
if (isset($enabled_types[$node->type]) && $enabled_types[$node->type] === $node->type) {
$display_settings = field_extra_fields_get_display('node', $node->type, $view_mode);
if (isset($display_settings['sharethis']) && $display_settings['sharethis']['visible']) {
$node->content['sharethis'] = array(
// Wrap it in a div.
'#tag' => 'div',
'#type' => 'html_tag',
'#attributes' => array(
'class' => 'sharethis-buttons',
),
'#value' => theme('sharethis', array(
'data_options' => $data_options,
'm_path' => $mPath,
'm_title' => $mTitle,
)),
'#weight' => intval(variable_get('sharethis_weight', 10)),
);
// Include necessary js files.
sharethis_include_js();
}
}
}
if (in_array('links', $location, TRUE)) {
$enabled_view_modes = variable_get('sharethis_' . $node->type . '_options', array());
if (isset($enabled_view_modes[$view_mode]) && $enabled_view_modes[$view_mode]) {
$links['sharethis'] = array(
'html' => TRUE,
'title' => theme('sharethis', array(
'data_options' => $data_options,
'm_path' => $mPath,
'm_title' => $mTitle,
)),
'#attributes' => array(
'class' => array(
'sharethis-buttons',
),
),
);
$node->content['links']['sharethis'] = array(
'#theme' => 'links',
'#links' => $links,
'#attributes' => array(
'class' => array(
'links',
'inline',
),
),
// Wrap it in a div.
'#tag' => 'div',
'#type' => 'html_tag',
'#weight' => intval(variable_get('sharethis_weight', 10)),
);
// Include necessary js files.
sharethis_include_js();
}
}
}