<?php

/**
 * @file
 * Enable and uninstall functions for the Google Plus One module.
 */

/**
 * Implements hook_enable().
 */
function google_plusone_enable() {
  $node_types = variable_get('google_plusone_node_types', array());
  if (empty($node_types)) {
    drupal_set_message(t('To finish enabling Google +1 button in your nodes, visit the <a href="@settings">settings</a> page. And remember to check the <a href="@perm">permissions</a> to view the button.', array('@settings' => url('admin/config/services/google-plusone'), '@perm' => url('admin/people/permissions', array('fragment' => 'module-google_plusone')))));
  }
}

/**
 * Implements hook_uninstall().
 */
function google_plusone_uninstall() {
  variable_del('google_plusone_node_types');
  variable_del('google_plusone_node_location');
  variable_del('google_plusone_weight');
  variable_del('google_plusone_block_settings');
  variable_del('google_plusone_button_settings');
  variable_del('google_plusone_advanced_settings');
}

/**
 * 'count' parameter has been deprecated in favor of 'annotation' in the Google +1 API
 * Updating variables according to the new API.
 */
function google_plusone_update_7001() {
  // Updating settings of the G+ button for the node
  $button_settings = variable_get('google_plusone_button_settings', 0);
  if (isset($button_settings['count'])) {
    $button_settings['annotation'] = $button_settings['count'] ? 'none' : 'bubble';
    $button_settings['width'] = '250';
    unset($button_settings['count']);
    variable_set('google_plusone_button_settings', $button_settings);
  }
  // Same for the block settings
  $block_settings = variable_get('google_plusone_block_settings', 0);
  if (isset($block_settings['count'])) {
    $block_settings['annotation'] = $button_settings['count'] ? 'none' : 'bubble';
    $block_settings['width'] = '250';
    if (empty($block_settings['url'])) {
      $block_settings['url'] = '<front>';
    }
    unset($block_settings['count']);
    variable_set('google_plusone_block_settings', $block_settings);
  }
}