You are here

protected function JuiceboxGalleryDrupal::setGalleryOptions in Juicebox HTML5 Responsive Image Galleries 7.2

Utility to extract Juicebox options from the common Drupal display settings, and add them to the gallery.

Some common Juicebox configuration options are set via a GUI and others are set as manual strings. This method fetches all of these values from drupal settings data and merges them into the gallery. Note that this only accounts for common settings.

1 call to JuiceboxGalleryDrupal::setGalleryOptions()
JuiceboxGalleryDrupal::runCommonBuild in includes/JuiceboxGalleryDrupal.inc
Common post-build tasks that should take place whenever a gallery of any type/source is built.

File

includes/JuiceboxGalleryDrupal.inc, line 338
Class to extend a JuiceboxGalleryDecorator object with Drupal-specific logic and structures.

Class

JuiceboxGalleryDrupal
Class to extend a JuiceboxGalleryDecorator object with Drupal-specific logic and structures.

Code

protected function setGalleryOptions() {
  $settings = $this->settings;

  // Get the string options set via the GUI.
  foreach (array(
    'jlib_galleryWidth',
    'jlib_galleryHeight',
    'jlib_backgroundColor',
    'jlib_textColor',
    'jlib_thumbFrameColor',
  ) as $name) {
    if (isset($settings[$name])) {
      $name_real = str_replace('jlib_', '', $name);
      $this
        ->addOption(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) {
    if (isset($settings[$name])) {
      $name_real = str_replace('jlib_', '', $name);
      $this
        ->addOption(drupal_strtolower($name_real), !empty($settings[$name]) ? 'TRUE' : 'FALSE');
    }
  }

  // Merge-in the manually assigned options making sure they take priority
  // over any conflicting GUI options.
  if (!empty($settings['manual_config'])) {
    $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);
        $this
          ->addOption(drupal_strtolower($name), check_plain($value));
      }
    }
  }
}