You are here

protected function JuiceboxGallery::processAttributes in Juicebox HTML5 Responsive Image Galleries 7.2

Process an attribute list for valid use in a Juicebox gallery.

For legacy support we can allow a variety of attribute name inputs, including underscore-separated and dash-separated values. Because the Juicebox library expects attribute names in camelCase we use this method to make a best-effort conversion (e.g., convert image_url to imageURL). Note that this process does NOT do any sanitization and can only correctly convert certain input names.

Parameters

array $attributes: An associative array of name => value pairs for juicebox XML attributes to be converted.

Return value

array The converted array of attributes.

3 calls to JuiceboxGallery::processAttributes()
JuiceboxGallery::addImage in includes/JuiceboxGallery.inc
Add a new image to the gallery.
JuiceboxGallery::getImages in includes/JuiceboxGallery.inc
Getter method for the gallery images.
JuiceboxGallery::getOptions in includes/JuiceboxGallery.inc
Getter method for the gallery options.

File

includes/JuiceboxGallery.inc, line 303
A php-only set of methods to create the script and markup components of a Juicebox gallery.

Class

JuiceboxGallery
Class to generate the script and markup for a Juicebox gallery.

Code

protected function processAttributes($attributes) {
  $filtered = array();
  foreach ($attributes as $name => $value) {

    // First make some adjustments for legacy support. We used to use some
    // specialized keys that are no longer valid, but still want to support
    // them as input. These values are special and cannot be handled alone by
    // the word-separator processing logic below.
    $name_mappings = array(
      'image_url_small' => 'smallImageURL',
      'image_url_large' => 'largeImageURL',
    );
    if (array_key_exists($name, $name_mappings)) {
      $name = $name_mappings[$name];
    }

    // Check that the name is in a format expected by the XML such that any
    // word-separators (like "-" and "_") are dropped. Also, the Juicebox
    // library uses camelCase for attributes so we do our best to deliver
    // that. Note that for image attributes proper camelCase appears to be
    // REQUIRED, but for gallery attributes all-lowercase values will work in
    // addition to camelCase.
    $parts = preg_split('/(_|-)/', $name);
    $i = 0;
    foreach ($parts as &$word) {
      if ($i) {

        // Don't alter the first word.
        $word = ucfirst($word);

        // For some reason the library requires that some attributes
        // containing a "url" string capitalize the "url" part.
        $word = $word == 'Url' ? 'URL' : $word;
      }
      $i++;
    }
    $name = implode('', $parts);
    $filtered[$name] = $value;
  }
  return $filtered;
}