You are here

flexslider.install in Flex Slider 7

Same filename and directory in other branches
  1. 8.2 flexslider.install
  2. 7.2 flexslider.install

Installation actions for Flex Slider

File

flexslider.install
View source
<?php

/**
 * @file
 * Installation actions for Flex Slider
 */

/**
 * Implements hook_schema().
 */
function flexslider_schema() {
  $schema = array();
  $schema['flexslider_optionset'] = array(
    'description' => 'Store option sets for flexslider instances.',
    'export' => array(
      'key' => 'name',
      'identifier' => 'preset',
      'default hook' => 'flexslider_default_presets',
      'api' => array(
        'owner' => 'flexslider',
        'api' => 'flexslider_default_preset',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'name' => array(
        'description' => 'The machine-readable option set name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'title' => array(
        'description' => 'The human-readable title for this option set.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'theme' => array(
        'description' => 'The flexslider theme.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => 'classic',
      ),
      'imagestyle_normal' => array(
        'description' => 'The image style for normal images.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => 'flexslider_full',
      ),
      'options' => array(
        'description' => 'The options array.',
        'type' => 'blob',
        'size' => 'big',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'name',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 *
 * Adds a 'default' option set for fresh installs.
 */
function flexslider_install() {

  /*
    $optionset = array(
      'name' => 'default',
      'title' => 'Default',
      'options' => array(
        'height' => 300,
        'width' => 450,
      ),
    );

    flexslider_optionset_save($optionset, TRUE);
  */
}

/**
 * Implements hook_uninstall().
 */
function flexslider_uninstall() {
  variable_del('flexslider_debug');
}

/**
 * Implements hook_requirements().
 */
function flexslider_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time
  $t = get_t();

  // Check to see if the flexslider library is available
  if ($phase == 'runtime') {
    $requirements['flexslider'] = array(
      'title' => $t('Flex Slider'),
      // @todo have the version automatically detected
      'description' => $t('Version 1.8 installed'),
      'severity' => REQUIREMENT_OK,
    );
    _flexslider_requirements_library_installed($requirements);
  }
  return $requirements;
}

/**
 * Implements hook_update_N().
 *
 * Remove/Update table fields to better suit Flex Slider
 */
function flexslider_update_7001(&$sandbox) {
  $field_new = array(
    'description' => 'The image style for normal images.',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => 'flexslider_full',
  );

  // Change the default image style
  db_change_field('flexslider_optionset', 'imagestyle_normal', $field_new, array());

  // Drop the unused table column
  db_drop_field('flexslider_optionset', 'imagestyle_thumb');
}

/**
 * Implements hook_update_N().
 *
 * Enables the Image module since it is now explicitly listed as a
 * dependency.
 */
function flexslider_update_7002(&$sandbox) {
  module_enable(array(
    'image',
  ));
}

/**
 * Check if the library is available
 *
 * @param array $requirements
 *  Requirements definition
 */
function _flexslider_requirements_library_installed(&$requirements) {
  $t = get_t();
  $path = libraries_get_path('flexslider');
  $installed = file_exists($path . '/jquery.flexslider-min.js') && file_exists($path . '/jquery.flexslider.js');

  // Check the results of the test
  if (!$installed) {
    $requirements['flexslider']['description'] = $t('Flex Slider library not found. Please consult the README.txt for installation instructions.');
    $requirements['flexslider']['severity'] = REQUIREMENT_ERROR;
    $requirements['flexslider']['value'] = $t('Flex Slider library not found.');
    return;
  }
  $js = file_exists($path . '/jquery.flexslider-min.js') ? fopen($path . '/jquery.flexslider-min.js', 'r') : fopen($path . '/jquery.flexslider.js', 'r');
  $header = fread($js, 64);
  $matches = array();
  if (preg_match("/ v([0-9]+)\\.([0-9]+)/", $header, $matches)) {
    if (!($matches[1] == 1 and $matches[2] >= 8)) {
      $requirements['flexslider']['description'] = $t('Flex Slider must be version 1.8 or higher, but lower than version 2.0.  Please consult the README.txt for installation instructions.');
      $requirements['flexslider']['severity'] = REQUIREMENT_WARNING;
      $requirements['flexslider']['value'] = $t('Incorrect version detected.');
      return;
    }
    else {
      $requirements['flexslider']['description'] = $t('Version %version installed', array(
        '%version' => $matches[1] . "." . $matches[2],
      ));
      $requirements['flexslider']['value'] = $t('Flex Slider library installed.');
      return;
    }
  }
  else {
    $requirements['flexslider']['description'] = $t('Flex Slider version could not be determined.  Please consult the README.txt for installation instructions.');
    $requirements['flexslider']['severity'] = REQUIREMENT_WARNING;
    $requirements['flexslider']['value'] = $t('Unable to detect version.');
  }
}