You are here

function _juicebox_get_lib_options in Juicebox HTML5 Responsive Image Galleries 7

Helper to get all Juicebox library conf options from the display settings.

This is used in preparation for generating XML output. Some Juicebox XML configuration options are set via a GUI and others are set as manual strings. This function merges all of these values into one array.

Parameters

array $settings: An associative array containing all the settings for a Juicebox gallery.

Return value

array An associative array of Juicebox XML configuration options.

2 calls to _juicebox_get_lib_options()
juicebox_build_gallery_data_from_entity_field in ./juicebox.module
Generate data for a Juicebox gallery from an entity image field.
juicebox_build_gallery_data_from_view in ./juicebox.module
Generate data for a Juicebox gallery from a view object.

File

./juicebox.module, line 532
Provides Drupal integration with the Juicebox library.

Code

function _juicebox_get_lib_options($settings) {
  $custom_options = array();

  // Get the string options set via the GUI.
  foreach (array(
    'jlib_galleryWidth',
    'jlib_galleryHeight',
    'jlib_backgroundColor',
    'jlib_textColor',
    'jlib_thumbFrameColor',
  ) as $name) {
    if (!empty($settings[$name])) {
      $name_real = str_replace('jlib_', '', $name);
      $custom_options[drupal_strtolower($name_real)] = trim(check_plain($settings[$name]));
    }
  }

  // Get the bool options set via the GUI.
  foreach (array(
    'jlib_showOpenButton',
    'jlib_showExpandButton',
    'jlib_showThumbsButton',
    'jlib_useThumbDots',
    'jlib_useFullscreenExpand',
  ) as $name) {
    $name_real = str_replace('jlib_', '', $name);
    $custom_options[drupal_strtolower($name_real)] = $settings[$name] ? 'TRUE' : 'FALSE';
  }

  // Merge-in the manually assigned options making sure they take priority
  // over any conflicting GUI options.
  $manual_options = explode("\n", $settings['manual_config']);
  foreach ($manual_options as $option) {
    $option = trim($option);
    if (!empty($option)) {

      // Each manual option has only been validated (on input) to be in the form
      // optionName="optionValue". Now we need split and sanitize the values.
      $matches = array();
      preg_match('/^([A-Za-z0-9]+?)="([^"]+?)"$/u', $option, $matches);
      list($full_match, $name, $value) = $matches;
      $name = drupal_strtolower($name);

      // See if the manual option is also a GUI option. If so, remove the GUI
      // option.
      $match = array_search($name, $custom_options);
      if ($match) {
        unset($custom_options[$match]);
      }
      $custom_options[$name] = check_plain($value);
    }
  }
  return $custom_options;
}