function theme_sharethis in ShareThis 7.2
Same name and namespace in other branches
- 5 sharethis.module \theme_sharethis()
- 6 sharethis.module \theme_sharethis()
Theme function for ShareThis code based on settings.
5 theme calls to theme_sharethis()
- sharethis_block_contents in ./
sharethis.module - Implements of sharethis_block_contents().
- sharethis_comment_view in ./
sharethis.module - Implements hook_comment_view().
- sharethis_handler_field_link::renderSharethisLink in views/
sharethis_handler_field_link.inc - Renders sharethis link.
- sharethis_node_view in ./
sharethis.module - Implements hook_node_view().
- sharethis_sharethis_content_type_render in plugins/
content_types/ sharethis/ sharethis.inc - Sharethis content type render function.
File
- ./
sharethis.module, line 264 - A module that adds one of the ShareThis widget to your website.
Code
function theme_sharethis($variables) {
$data_options = $variables['data_options'];
$m_path = $variables['m_path'];
$m_title = $variables['m_title'];
// Inject the extra services.
foreach ($data_options['option_extras'] as $service) {
$data_options['services'] .= ',"' . $service . '"';
}
foreach (variable_get('sharethis_option_extras_fbsub', array()) as $service) {
$data_options['services'] .= ',"' . $service . '"';
}
foreach (variable_get('sharethis_option_extras_pinterestfollow', array()) as $service) {
$data_options['services'] .= ',"' . $service . '"';
}
foreach (variable_get('sharethis_option_extras_twitterfollow', array()) as $service) {
$data_options['services'] .= ',"' . $service . '"';
}
foreach (variable_get('sharethis_option_extras_youtube', array()) as $service) {
$data_options['services'] .= ',"' . $service . '"';
}
foreach (variable_get('sharethis_option_extras_foursquaresave', array()) as $service) {
$data_options['services'] .= ',"' . $service . '"';
}
foreach (variable_get('sharethis_option_extras_foursquarefollow', array()) as $service) {
$data_options['services'] .= ',"' . $service . '"';
}
// The share buttons are simply spans of the form
// class='st_SERVICE_BUTTONTYPE' -- "st" stands for ShareThis.
$type = drupal_substr($data_options['buttons'], 4);
$type = $type == "_" ? "" : check_plain($type);
$service_array = explode(",", $data_options['services']);
$st_spans = "";
foreach ($service_array as $service_full) {
// Strip the quotes from the element in the array for javascript.
$service = explode(":", $service_full);
// Service names are expected to be parsed by Name:machine_name.
// If only one element in the array is given, it's an invalid service.
if (count($service) < 2) {
continue;
}
// Find the service code name.
$serviceCodeName = drupal_substr($service[1], 0, -1);
// Switch the title on a per-service basis if required.
$title = $m_title;
switch ($serviceCodeName) {
case 'twitter':
// Append Prefix.
$title = !empty($data_options['twitter_prefix']) ? $data_options['twitter_prefix'] . ' ' . $title : $title;
// Append Suffix.
$title = !empty($data_options['twitter_suffix']) ? $title . ' ' . $data_options['twitter_suffix'] : $title;
break;
}
// Sanitize the service code for display.
$display = check_plain($serviceCodeName);
// Add attributes to the variables array so they can be overridden and
// put together the default span attributes.
$attributes['st_url'] = $m_path;
$attributes['st_title'] = rawurlencode($title);
$attributes['class'] = 'st_' . $display . $type;
$variables['attributes'] = $attributes;
if ($serviceCodeName == 'twitter') {
if (isset($data_options['twitter_handle'])) {
$attributes['st_via'] = $data_options['twitter_handle'];
$attributes['st_username'] = $data_options['twitter_recommends'];
}
}
switch ($serviceCodeName) {
case 'fbsub':
$attributes['st_username'] = variable_get('sharethis_option_extras_fbsub_field', '');
break;
case 'pinterestfollow':
$attributes['st_username'] = variable_get('sharethis_option_extras_pinterestfollow_field', '');
break;
case 'twitterfollow':
$attributes['st_username'] = variable_get('sharethis_option_extras_twitterfollow_field', '');
break;
case 'youtube':
$attributes['st_username'] = variable_get('sharethis_option_extras_youtube_field', '');
break;
case 'foursquarefollow':
$attributes['st_username'] = variable_get('sharethis_option_extras_foursquarefollow_field', '');
$attributes['st_followId'] = variable_get('sharethis_option_extras_foursquarefollow_field2', '');
break;
}
// Only show the display text if the type is set.
if (!empty($type)) {
$attributes['displayText'] = check_plain($display);
}
// Render the span tag.
$st_spans .= theme('html_tag', array(
'element' => array(
'#tag' => 'span',
'#attributes' => $attributes,
'#value' => '',
),
));
}
// Output the embedded JavaScript.
// sharethis_include_js();
return '<div class="sharethis-wrapper">' . $st_spans . '</div>';
}