You are here

public function JuiceboxGallery::renderXml in Juicebox HTML5 Responsive Image Galleries 7.2

Render the XML for a Juicebox gallery once images and options have been added.

Parameters

string $script_wrap_id: If a value is passed the XML will be wrapped inside <script> tags with this id. If no value is passed, no <script> wrapper will be used and the raw XML will be returned. This is useful if the XML will be embedded inside normal HTML.

Return value

string Structured Juicebox XML describing a gallery. Note that no header data is set or returned here.

Overrides JuiceboxGalleryInterface::renderXml

File

includes/JuiceboxGallery.inc, line 204
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

public function renderXml($embed_wrap_id = NULL) {

  // 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'));

  // Get filtered attributes.
  $gallery_attributes = $this
    ->getOptions(TRUE);
  foreach ($gallery_attributes as $attribute => $value) {
    $juicebox
      ->setAttribute($attribute, $value);
  }

  // Get filtered image data.
  $gallery_images = $this
    ->getImages(TRUE);
  foreach ($gallery_images as $image) {
    $juicebox_image = $juicebox
      ->appendChild($dom
      ->createElement('image'));
    foreach ($image['src_data'] as $attribute => $value) {
      $juicebox_image
        ->setAttribute($attribute, $value);
    }
    $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']));
  }
  $prefix = $suffix = '';
  if ($embed_wrap_id) {
    $prefix = '<script id="' . $embed_wrap_id . '" type="text/xml">';
    $suffix = '</script>';
  }
  return $prefix . $dom
    ->saveXML() . $suffix;
}