You are here

menu_minipanels.install in Menu Minipanels 6

Same filename and directory in other branches
  1. 7.2 menu_minipanels.install
  2. 7 menu_minipanels.install

Installation and update scripts for Menu_MiniPanels.

File

menu_minipanels.install
View source
<?php

/**
 * @file
 * Installation and update scripts for Menu_MiniPanels.
 */

/**
 * Implements hook_install().
 */
function menu_minipanels_install() {

  // Check the requirements.
  $requirements = menu_minipanels_requirements('runtime');

  // See if an error was returned.
  if (!empty($requirements['menu_minipanels']['severity']) && $requirements['menu_minipanels']['severity'] == REQUIREMENT_ERROR) {

    // Return the message.
    drupal_set_message($requirements['menu_minipanels']['description'], 'warning');
  }

  // Allow each menu to be menu_minipanel-ized, with some exceptions.
  _menu_minipanels_enable_menus();
}

/**
 * Implementation of hook_uninstall().
 */
function menu_minipanels_uninstall() {

  // Delete variables.
  variable_del('menu_minipanels_hover');
  variable_del('menu_minipanels_default_callbacks');
  variable_del('menu_minipanels_exclude_paths');
  foreach (menu_get_names() as $menu) {
    variable_del('menu_minipanels_' . $menu . '_enabled');
  }

  // Remove menu item settings.
  $results = db_query("SELECT menu_name, mlid, options FROM {menu_links} WHERE options LIKE ('%menu_minipanels%')");
  while ($menu = db_fetch_object($results)) {

    // The menu item's options are serialized.
    $options = unserialize($menu->options);
    unset($options['minipanel']);
    unset($options['menu_minipanels_hover']);

    // Update the menu item record.
    db_query("UPDATE menu_links SET options='%s' WHERE menu_name='%s' AND mlid=%d", serialize($options), $menu->menu_name, $menu->mlid);
  }
}

/**
 * Implementation of hook_requirements().
 */
function menu_minipanels_requirements($phase) {
  $t = get_t();
  $requirements = array();
  if ($phase == 'runtime') {
    $qtip_path = FALSE;
    $filename = 'jquery.qtip-1.0.0-rc3.min.js';
    $module_path = drupal_get_path('module', 'menu_minipanels');

    // An array of possible paths, in descending order of preference.
    $possible_paths = array(
      // Ideally should be stored here.
      'sites/all/libraries/qtip',
      // Legacy paths, including some possible incorrect ones, but the
      // performance hit should be negligible.
      $module_path . '/js/lib/qtip',
      $module_path . '/js/lib',
      $module_path . '/js/qtip',
      $module_path . '/js',
      $module_path . '/qtip',
      $module_path,
    );

    // Proper Libraries API support.
    if (function_exists('libraries_get_path')) {
      $lib_path = libraries_get_path('qtip');
      if (!empty($lib_path) && !in_array($lib_path, $possible_paths)) {
        array_unshift($possible_paths, $lib_path);
      }
    }

    // Check each of the paths.
    foreach ($possible_paths as $path) {

      // If the file exists, this is the one we'll use.
      if (file_exists($path . '/' . $filename)) {
        $qtip_path = $path . '/' . $filename;
        continue;
      }
    }

    // If the file was not found, leave a message for the user.
    if (empty($qtip_path)) {
      $requirements['menu_minipanels'] = array(
        'description' => $t('The module is enabled but the qTip library has not been downloaded. This module will not work without qTip! Please see README.txt in the menu_minipanels directory for instructions on how to download qTip, or use <a href="http://drupal.org/project/drush">Drush</a> to download it via the following command:<br /><pre>drush download-qtip</pre>'),
        'severity' => REQUIREMENT_ERROR,
        'title' => $t('Menu MiniPanels'),
        'value' => $t('qTip library not found'),
      );
    }
    else {
      $requirements['menu_minipanels'] = array(
        'severity' => REQUIREMENT_OK,
        'title' => $t('Menu MiniPanels'),
        'value' => $t('qTip library in use: <em>!path</em>.', array(
          '!path' => $qtip_path,
        )),
      );
      $cid = 'menu_minipanels_qtip_path';
      cache_set($cid, $qtip_path);
    }
  }
  return $requirements;
}

/**
 * Allow each menu to be menu_minipanel-ized, with some exceptions.
 */
function _menu_minipanels_enable_menus() {

  // Ignore the Navigation, Admin Menu and Devel menus, those have to be
  // manually enabled.
  $ignore_menus = array(
    'navigation',
    'admin_menu',
    'devel',
  );
  foreach ($ignore_menus as $menu) {
    variable_set('menu_minipanels_' . $menu . '_enabled', FALSE);
  }

  // Enable all of the custom menus that isn't already disabled.
  foreach (menu_get_names() as $menu) {
    if (!in_array($menu, $ignore_menus)) {
      variable_set('menu_minipanels_' . $menu . '_enabled', TRUE);
    }
  }
}

/**
 * Implementations of hook_update_N().
 */

/**
 * Placeholder.
 */
function menu_minipanels_update_6101() {

  // Do nothing.
  return array();
}

/**
 * Change the menu configurations to the new structure.
 */
function menu_minipanels_update_6102() {

  // Allow each menu to be menu_minipanel-ized, with some exceptions.
  _menu_minipanels_enable_menus();
  drupal_set_message(t('The menus have been converted to use the new Menu MiniPanels settings, though you should still check each menu to ensure that it is correctly enabled via each menu\'s edit page. You may also want to disable ones which are not necessary for a small performance improvement.'));
  return array();
}

/**
 * Change from the show_admin to the exclude_pages variable.
 */
function menu_minipanels_update_6103() {

  // Convert the existing show_admin variable.
  if (variable_get('menu_minipanels_show_admin', TRUE)) {
    variable_set('menu_minipanels_exclude_paths', "admin\nadmin/*");
  }
  else {
    variable_set('menu_minipanels_exclude_paths', '');
  }

  // Delete the existing show_admin variable.
  variable_del('menu_minipanels_show_admin');
  return array();
}

/**
 * Disable the menu for the Admin Menu and Devel modules.
 */
function menu_minipanels_update_6104() {
  variable_set('menu_minipanels_admin_menu_enabled', FALSE);
  variable_set('menu_minipanels_devel_enabled', FALSE);
  return array();
}

/**
 * Clear the theme cache so that the updated theme registry changes will take
 * effect.
 */
function menu_minipanels_update_6105() {
  cache_clear_all('theme_registry', 'cache', TRUE);
  return array();
}

Functions

Namesort descending Description
menu_minipanels_install Implements hook_install().
menu_minipanels_requirements Implementation of hook_requirements().
menu_minipanels_uninstall Implementation of hook_uninstall().
menu_minipanels_update_6101 Placeholder.
menu_minipanels_update_6102 Change the menu configurations to the new structure.
menu_minipanels_update_6103 Change from the show_admin to the exclude_pages variable.
menu_minipanels_update_6104 Disable the menu for the Admin Menu and Devel modules.
menu_minipanels_update_6105 Clear the theme cache so that the updated theme registry changes will take effect.
_menu_minipanels_enable_menus Allow each menu to be menu_minipanel-ized, with some exceptions.