You are here

function sharethis_block_contents in ShareThis 7.2

Same name and namespace in other branches
  1. 7 sharethis_block/sharethis_block.module \sharethis_block_contents()

Implements of sharethis_block_contents().

Return value

string Returns cached contentfor block

1 call to sharethis_block_contents()
sharethis_block_view in ./sharethis.module
Implements hook_block_view().

File

./sharethis.module, line 452
A module that adds one of the ShareThis widget to your website.

Code

function sharethis_block_contents() {
  $location = variable_get('sharethis_location', array(
    'content' => 'content',
  ));
  if (in_array('block', $location, TRUE)) {

    // Output the embedded JavaScript.
    sharethis_include_js();
    $cache_name = 'sharethis:sharethis_block:' . current_path();
    $cache = cache_get($cache_name, 'cache_block');

    // Is the tab html cached already?
    if (!empty($cache) && isset($cache->data) && !empty($cache->data)) {

      // It is cached. Return the cached content.
      return $cache->data;
    }
    else {

      // Get all of the options for the sharethis widget from the database.
      $data_options = sharethis_get_options_array();
      $path = isset($_GET['q']) ? $_GET['q'] : '<front>';
      if ($path == variable_get('site_frontpage')) {
        $path = "<front>";
      }
      $mPath = url($path, array(
        'absolute' => TRUE,
      ));
      $mTitle = decode_entities(drupal_get_title());
      $content = theme('sharethis', array(
        'data_options' => $data_options,
        'm_path' => $mPath,
        'm_title' => $mTitle,
      ));

      // Cache the content temporarily.
      cache_set($cache_name, $content, 'cache_block', CACHE_TEMPORARY);
      return $content;
    }
  }
}