'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', ), 'imagestyle_thumbnail' => array( 'description' => 'The image style for thumbnail images.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'flexslider_thumbnail', ), '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() { // Do nothing for now } /** * Implements hook_uninstall(). */ function flexslider_uninstall() { variable_del('flexslider_debug'); variable_del('flexslider_version'); } /** * 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('FlexSlider'), // @todo have the version automatically detected 'description' => $t('Version 2.0 installed'), 'severity' => REQUIREMENT_OK, ); _flexslider_requirements_library_installed($requirements); } return $requirements; } /** * Implements hook_update_N(). * * Remove/Update table fields to better suit FlexSlider */ 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')); } /** * Implements hook_update_N(). * * Migrate settings from FlexSlider v1 to v2 */ function flexslider_update_7200(&$sandbox) { $t = get_t(); $optionsets = flexslider_optionset_load_all(); foreach ($optionsets as $optionset) { // Map old options to new keys/values $optionset->options['animationSpeed'] = $optionset->options['animationDuration']; $optionset->options['direction'] = $optionset->options['slidedirection']; $optionset->options['keyboard'] = $optionset->options['keyboardnav']; $optionset->options['startAt'] = $optionset->options['slidetostart']; $optionset->options['start'] = $optionset->options['startCallback']; $optionset->options['before'] = $optionset->options['beforeCallback']; $optionset->options['after'] = $optionset->options['afterCallback']; $optionset->options['end'] = $optionset->options['endCallback']; // Delete any options which no longer exist unset($optionset->options['animationDuration']); unset($optionset->options['slidedirection']); unset($optionset->options['keyboardnav']); unset($optionset->options['startCallback']); unset($optionset->options['beforeCallback']); unset($optionset->options['afterCallback']); unset($optionset->options['endCallback']); unset($optionset->options['controlsContainer']); // This value changed in the new version. We have to reset it to the default value // Merge in defaults for new options $optionset->options += _flexslider_optionset_defaults(); // Save the updated optionset flexslider_optionset_save($optionset); } drupal_set_message($t('Optionsets migrated. However it is recommended to go validate all your settings manually. Especially if you have callback functions defined. They may reference functions which no longer exist.'), 'warning'); } function flexslider_update_7201(&$sandbox) { $field_new = array( 'description' => 'The image style for thumbnail images.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'flexslider_thumbnail', ); // Change the default image style db_add_field('flexslider_optionset', 'imagestyle_thumbnail', $field_new, array()); } /** * 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('FlexSlider library not found. Please consult the README.txt for installation instructions.'); $requirements['flexslider']['severity'] = REQUIREMENT_ERROR; $requirements['flexslider']['value'] = $t('FlexSlider 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] == 2 and $matches[2] >= 0)) { $requirements['flexslider']['description'] = $t('FlexSlider must be version 2.0 or higher, but lower than version 3.0. Please consult the README.txt for installation instructions.'); $requirements['flexslider']['severity'] = REQUIREMENT_WARNING; $requirements['flexslider']['value'] = $t('Incorrect version detected.'); return; } else { $version = $matches[1] . "." . $matches[2]; variable_set('flexslider_version', $version); $requirements['flexslider']['description'] = $t('Version %version installed', array( '%version' => $version)); $requirements['flexslider']['value'] = $t('FlexSlider library installed.'); return; } } else { $requirements['flexslider']['description'] = $t('FlexSlider 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.'); } } // @todo add hook_update_N function to migrate old option set data to new values