View source
<?php
function sharethis_help($path, $arg) {
switch ($path) {
case 'admin/settings/service_links/sharethis':
return '<p>' . t('The following are configuration options for the <a href="@sharethis">ShareThis</a> web service. You can add the ShareThis button to nodes and links in the <a href="@services">services tab</a>.', array(
'@sharethis' => 'http://sharethis.com',
'@services' => url('admin/settings/service_links/services'),
)) . '</p>';
}
}
function sharethis_menu() {
$items['admin/settings/service_links/sharethis'] = array(
'title' => 'ShareThis',
'description' => 'Configuration options for the ShareThis web service.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'sharethis_admin_settings',
),
'access arguments' => array(
'administer service links',
),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'sharethis.admin.inc',
);
return $items;
}
function sharethis_service_links() {
$links['sharethis'] = array(
'name' => 'ShareThis',
'description' => t('ShareThis makes sharing easy!'),
'link' => 'http://sharethis.com/post?url=<encoded-url>&title=<encoded-title>',
'icon' => drupal_get_path('module', 'sharethis') . '/images/' . variable_get('sharethis_icon', 'sharethis.png'),
'javascript' => drupal_get_path('module', 'sharethis') . '/sharethis.js',
'callback' => 'sharethis_service_links_callback',
);
$chicklets = array(
'email' => array(
'name' => 'Email',
'description' => t('Send this post to a friend via Email.'),
),
'twitter' => array(
'name' => 'Twitter',
'description' => t('Share this post on Twitter.'),
),
);
foreach ($chicklets as $name => $chicklet) {
$links['sharethis-' . $name] = array(
'name' => $chicklet['name'],
'description' => $chicklet['description'],
'link' => 'http://sharethis.com/post?url=<encoded-url>&title=<encoded-title>',
'icon' => drupal_get_path('module', 'sharethis') . "/images/{$name}.gif",
'attributes' => array(
'class' => $name,
),
'javascript' => drupal_get_path('module', 'sharethis') . '/sharethis.js',
'callback' => 'sharethis_service_links_callback',
);
}
return $links;
}
function sharethis_service_links_callback($service, $context) {
static $added = FALSE;
if ($added == FALSE) {
$added = TRUE;
$code = variable_get('sharethis_code', '');
if (empty($code)) {
$code = 'http://w.sharethis.com/button/sharethis.js#publisher=00000000-0000-0000-0000-000000000000&type=website';
}
else {
$code = str_replace(array(
'<script type="text/javascript" src="',
'"></script>',
), array(
'',
'',
), $code);
}
drupal_set_html_head('<script type="text/javascript" src="' . $code . '&button=false"></script>');
}
$settings = array(
$service['attributes']['id'] => array(
'title' => $context['title'],
'url' => $context['url'],
'chicklet' => isset($service['attributes']['class']) ? $service['attributes']['class'] : FALSE,
),
);
drupal_add_js(array(
'sharethis' => $settings,
), 'setting');
}