You are here

sharethis.module in ShareThis 6.2

File

sharethis.module
View source
<?php

/**
 * Implementation of hook_help().
 */
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>';
  }
}

/**
 * Implementation of hook_menu().
 */
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;
}

/**
 * Implementation of hook_service_links().
 *
 * See the Service Links module.
 */
function sharethis_service_links() {

  // The main ShareThis button.
  $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',
  );

  // Construct the individual chicklets.
  $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;
}

/**
 * Callback function from Service 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&amp;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 . '&amp;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');
}

Functions

Namesort descending Description
sharethis_help Implementation of hook_help().
sharethis_menu Implementation of hook_menu().
sharethis_service_links Implementation of hook_service_links().
sharethis_service_links_callback Callback function from Service Links.