You are here

function _juicebox_filter_markup in Juicebox HTML5 Responsive Image Galleries 7

Filter markup for valid display in a Juicebox gallery.

Some markup that validates fine via common Drupal text format filters will not be syntactically valid once rendered within Juicebox. This is because Juicebox will wrap titles and captions in block-level tags, like <p>, making any block-level elements they contain invalid. This filter accommodates for this and is meant to be applied AFTER any Drupal text formats.

Parameters

string $markup: The markup to be filtered after it has been processed by Drupal's text format rules.

Return value

string Valid filtered markup ready for display in a Juicebox gallery.

2 calls to _juicebox_filter_markup()
juicebox_build_gallery_data_from_entity_field in ./juicebox.module
Generate data for a Juicebox gallery from an entity image field.
juicebox_build_gallery_data_from_view in ./juicebox.module
Generate data for a Juicebox gallery from a view object.

File

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

Code

function _juicebox_filter_markup($markup) {

  // Set inline elements that are safe in a Juicebox gallery. References:
  // http://www.htmlhelp.com/reference/html40/inline.html
  // https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/HTML5_element_list
  $valid_elements = "<a><abbr><acronym><b><basefont><bdi><bdo><big><br><cite><code><data><del><dfn><em><font><i><img><ins><kbd><label><mark><q><rp><rt><ruby><s><samp><small><span><strike><strong><sub><sup><time><tt><u><var><wbr>";
  $markup = strip_tags($markup, $valid_elements);

  // Also remove newlines to keep the output concise.
  $markup = str_replace(array(
    "\r",
    "\n",
  ), '', $markup);
  return $markup;
}