You are here

function juicebox_render_gallery_xml in Juicebox HTML5 Responsive Image Galleries 7

Render the final XML for a Juicebox gallery.

This function is a bit like drupal_render() in that it takes an associative array as input and returns final markup. Actaully, this function's $data input could probably be made to work with drupal_render(), but as we are producing structured XML here (and not HTML), using a custom function instead seems more prudent and flexible.

Parameters

array $data: An associative array containing all the content variables that will be used in the Juicebox XML.

Return value

string Fully renderd XML data for a Juicebox gallery.

1 call to juicebox_render_gallery_xml()
juicebox_page_xml in ./juicebox.module
Menu callback: generate Juicebox XML.

File

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

Code

function juicebox_render_gallery_xml($data) {

  // We use DOMDocument instead of a SimpleXMLElement to build the XML as it's
  // much more flexible (CDATA is supported, etc.).
  $dom = new DOMDocument('1.0', 'UTF-8');
  $dom->formatOutput = TRUE;
  $juicebox = $dom
    ->appendChild($dom
    ->createElement('juicebox'));
  foreach ($data['jlib_options'] as $option => $value) {
    $juicebox
      ->setAttribute($option, $value);
  }
  foreach ($data['images'] as $image) {
    $juicebox_image = $juicebox
      ->appendChild($dom
      ->createElement('image'));
    $juicebox_image
      ->setAttribute('imageURL', $image['image_src']);
    $juicebox_image
      ->setAttribute('thumbURL', $image['thumb_src']);
    $juicebox_image
      ->setAttribute('linkURL', $image['image_link_src']);
    $juicebox_image
      ->setAttribute('linkTarget', $image['linkurl_target']);
    $juicebox_image_title = $juicebox_image
      ->appendChild($dom
      ->createElement('title'));
    $juicebox_image_title
      ->appendChild($dom
      ->createCDATASection($image['title']));
    $juicebox_image_caption = $juicebox_image
      ->appendChild($dom
      ->createElement('caption'));
    $juicebox_image_caption
      ->appendChild($dom
      ->createCDATASection($image['caption']));
  }
  return $dom
    ->saveXML();
}