You are here

sharethis.install in ShareThis 7.2

Same filename and directory in other branches
  1. 8.2 sharethis.install
  2. 6 sharethis.install
  3. 7 sharethis.install

This file holds the install information for the ShareThis Module.

File

sharethis.install
View source
<?php

/**
 * @file
 * This file holds the install information for the ShareThis Module.
 */

/**
 * Implements hook_install().
 */
function sharethis_install() {
  variable_set('sharethis_publisherID', sharethis_create_publisher_key());
}

/**
 * Creates a publisher key for use with the ShareThis API.
 */
function sharethis_create_publisher_key() {
  $pubkey = "dr-";
  $pubkey .= dechex(mt_rand(0, 0xffff));
  $pubkey .= dechex(mt_rand(0, 0xffff)) . "-";
  $pubkey .= dechex(mt_rand(0, 0xffff)) . "-";
  $pubkey .= dechex(mt_rand(0, 0xffff)) . "-";
  $pubkey .= dechex(mt_rand(0, 0xffff)) . "-";
  $pubkey .= dechex(mt_rand(0, 0xffff));
  $pubkey .= dechex(mt_rand(0, 0xffff));
  $pubkey .= dechex(mt_rand(0, 0xffff));
  return $pubkey;
}

/**
 * Implements hook_uninstall().
 */
function sharethis_uninstall() {
  db_delete('variable')
    ->condition('name', db_like('sharethis_') . '%', 'LIKE')
    ->execute();
  cache_clear_all('variables', 'cache');
}

/**
 * Remove the custom ShareThis table.
 */
function sharethis_update_7001() {

  // Move from the st_table to the variables table.
  if (db_table_exists('st_table')) {

    // Select all options in the ShareThis table.
    $result = db_select('st_table', 's')
      ->fields('s', array(
      'st_option',
      'st_value',
    ))
      ->execute();
    while ($record = $result
      ->fetchAssoc()) {

      // Variable name switches. publisherID stays the same.
      switch ($record['st_option']) {
        case 'buttons':
          $record['st_option'] = 'button_option';
          break;
        case 'nodeType':
          $record['st_option'] = 'node_option';
          break;
        case 'services':
          $record['st_option'] = 'service_option';
          break;
        case 'viewMode':
          $record['st_option'] = 'teaser_option';
          break;
        case 'widget':
          $record['st_option'] = 'widget_option';
          break;
      }

      // Prefix the option with a "sharethis_" namespace.
      variable_set('sharethis_' . $record['st_option'], $record['st_value']);
    }

    // Now that our settings are in the variables table, safely drop the table.
    db_drop_table('st_table');

    // Return a success message.
    return t('Switched from the custom ShareThis table to the Variables table.');
  }
}

/**
 * Removes variables sharethis_override_* & sharethis_service_option.
 * @see https://www.drupal.org/node/2759221
 */
function sharethis_update_7002() {
  db_delete('variable')
    ->condition('name', db_like('sharethis_override_') . '%', 'LIKE')
    ->execute();
  $sharethis_service_option = variable_get("sharethis_service_option");
  $sharethis_service_option = str_replace('amp;', '', $sharethis_service_option);
  $sharethis_service_option = str_replace('&quot;', '"', $sharethis_service_option);
  variable_set("sharethis_service_option", $sharethis_service_option);
  cache_clear_all('variables', 'cache');
}

/**
 * Update the sharethis_location variable to an array.
 * @see https://www.drupal.org/node/2846151
 */
function sharethis_update_7003() {
  $location_places = variable_get('sharethis_location', array(
    'content' => 'content',
  ));
  if (!is_array($location_places)) {
    $location_places = array(
      'content' => $location_places,
    );
    variable_set('sharethis_location', $location_places);
  }
}

Functions

Namesort descending Description
sharethis_create_publisher_key Creates a publisher key for use with the ShareThis API.
sharethis_install Implements hook_install().
sharethis_uninstall Implements hook_uninstall().
sharethis_update_7001 Remove the custom ShareThis table.
sharethis_update_7002 Removes variables sharethis_override_* & sharethis_service_option.
sharethis_update_7003 Update the sharethis_location variable to an array.