<?php

/**
 * @file
 * Install, update and uninstall functions for the Superfish module.
 */

/**
 * Implements hook_uninstall().
 */
function superfish_uninstall() {
  db_delete('variable')->condition('name', '%%superfish%%', 'LIKE')->execute();
  db_delete('block')->condition('module', 'superfish')->execute();
}

/**
 * Implements hook_enable().
 */
function superfish_enable() {
  drupal_set_message(check_plain('To use Superfish go to the administer blocks page and enable a Superfish block.'));
}


/**
 * Implements hook_requirements().
 */
function superfish_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    // Ensure translations do not break at install time
    $t = get_t();
    $requirements['superfish']['title'] = $t('Superfish library');
    if (module_exists('libraries') && function_exists('libraries_get_libraries')) {
      $library = libraries_get_libraries();
      $superfish_installed = (isset($library['superfish'])) ? TRUE : FALSE;
    }
    elseif (file_exists('sites/all/libraries/superfish/superfish.js') || file_exists('profiles/' . drupal_get_profile() . '/libraries/superfish/superfish.js')) {
      $superfish_installed = TRUE;
    }
    else {
      $superfish_installed = FALSE;
    }
    if ($superfish_installed) {
      $requirements['superfish']['value'] = $t('Installed');
      $requirements['superfish']['severity'] = REQUIREMENT_OK;
    }
    else {
      $requirements['superfish']['value'] = $t('Not installed');
      $requirements['superfish']['severity'] = REQUIREMENT_ERROR;
      $requirements['superfish']['description'] = $t('Please download the Superfish library from !link.', array('!link' => l('http://drupal.org/project/superfish', 'http://drupal.org/project/superfish')));
    }
  }
  return $requirements;
}

/**
 * Implements hook_update_N().
 */
function superfish_update_7100() {
}