You are here

superfish.install in Superfish 6

Same filename and directory in other branches
  1. 8 superfish.install
  2. 7 superfish.install

Install, update and uninstall functions for the Superfish module.

File

superfish.install
View source
<?php

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

/**
 * Implements hook_uninstall().
 */
function superfish_uninstall() {
  db_query("DELETE FROM {variable} WHERE name like '%%superfish%%'", $name);
  db_query("DELETE FROM {blocks} WHERE module = 'superfish'", $name);
}

/**
 * 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();

    // Ensure the Superfish library is present.
    $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')) {
      $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'),
      ));
    }

    // Check the uploaded Superfish library version.
    if (superfish_library_version() != '1.2-beta2') {
      $requirements['superfish']['value'] = $t('Not supported');
      $requirements['superfish']['severity'] = REQUIREMENT_ERROR;
      $requirements['superfish']['description'] = $t('The Superfish library requires an update. You can find the update instructions on !link.', array(
        '!link' => l('http://drupal.org/project/superfish', 'http://drupal.org/project/superfish'),
      ));
    }
  }
  return $requirements;
}

/**
 * A function to check the Superfish library version.
 */
function superfish_library_version() {

  // Ensure the Libraries API module is installed and working.
  if (module_exists('libraries') && function_exists('libraries_get_path') && libraries_get_path('superfish') != '') {
    $directory = libraries_get_path('superfish');
  }
  else {
    $directory = 'sites/all/libraries/superfish';
  }

  // Get the library version.
  if (file_exists($directory . '/VERSION')) {
    $version = file_get_contents($directory . '/VERSION');

    // Removing blank lines and white spaces.
    $version = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", trim($version));
    if (!empty($version)) {
      return $version;
    }
    else {
      return '';
    }
  }
  else {
    return '';
  }
}

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

Functions

Namesort descending Description
superfish_enable Implements hook_enable().
superfish_library_version A function to check the Superfish library version.
superfish_requirements Implements hook_requirements().
superfish_uninstall Implements hook_uninstall().
superfish_update_6100 Implements hook_update_N().