You are here

function juicebox_style_plugin::render in Juicebox HTML5 Responsive Image Galleries 7

Render the view page display.

This is where the Juicebox embed code is built for the view.

Overrides views_plugin_style::render

File

plugins/juicebox_style_plugin.inc, line 180
Contains the Juicebox views style plugin.

Class

juicebox_style_plugin
Style plugin to render each item in a views list.

Code

function render() {
  $view = $this->view;

  // Generate a unique ID that can be used to identify this gallery and view
  // source details.
  $xml_id = 'view/' . $view->name . '/' . $view->current_display;
  foreach ($view->args as $arg) {
    $xml_id .= '/' . $arg;
  }
  $xml_path = 'juicebox/xml/' . $xml_id;

  // If we are previewing the view in the admin interface all the necessary
  // <script> elements in our embed markup seem to get stripped. This means
  // that the preview cannot render and so there is no point in loading the
  // Juicebox lib (doing so can actually cause display problems).
  if (strpos(current_path(), 'admin/structure/views') !== 0) {

    // Load the juicebox library, this will include the appropriate js in the
    // page header, etc.
    libraries_load('juicebox');
  }
  else {

    // Post a notice to admins so that they don't think things are broken
    // when the preview does not produce anything useful.
    drupal_set_message(t("Due to javascript requirements Juicebox galleries cannot be viewed as a live preview. Please save your view and visit the full page URL for this display to preview this gallery."), 'warning');
  }

  // Initialize the "settings" values before working with them. This is
  // required for legacy support.
  $view->style_plugin->options = _juicebox_init_display_settings($view->style_plugin->options);

  // Calculate the data that will ultimately be used to render the gallery
  // XML. We won't officially generate the XML until the Juicebox javascript
  // requests it, but we will still need the related data within parts of the
  // embed code.
  $view->juicebox_gallery_data = juicebox_build_gallery_data_from_view($view, $xml_path);

  // Get a checksum for the gallery data. This can be useful for invalidating
  // any old caches of this data. Note json_encode() is faster than
  // serialize().
  $gallery_checksum = md5(json_encode($view->juicebox_gallery_data));

  // Construct the query parameters that should be added to the XML path. Be
  // sure to retain any currently active query parameters.
  $query = array_merge(array(
    'checksum' => $gallery_checksum,
  ), drupal_get_query_parameters());

  // Set template variables for embed markup.
  $variables['gallery_id'] = preg_replace('/[^0-9a-zA-Z-]/', '_', str_replace('/', '-', $xml_id));
  $variables['gallery_xml_path'] = url($xml_path, array(
    'query' => $query,
  ));
  $variables['settings'] = $view->style_plugin->options;
  $variables['data'] = $view->juicebox_gallery_data;
  return theme('juicebox_embed_markup', $variables);
}