You are here

function _jquery_ui_filter_dialog_prepare_replacer in jQuery UI filter 7

Same name and namespace in other branches
  1. 6 dialog/jquery_ui_filter_dialog.module \_jquery_ui_filter_dialog_prepare_replacer()

Jquery UI filter dialog prepare replacer.

1 string reference to '_jquery_ui_filter_dialog_prepare_replacer'
_jquery_ui_filter_dialog_prepare_callback in dialog/jquery_ui_filter_dialog.module
Jquery UI filter dialog prepare callback.

File

dialog/jquery_ui_filter_dialog.module, line 121
Opens links inside a jQuery UI dialog widget.

Code

function _jquery_ui_filter_dialog_prepare_replacer($matches) {
  $attributes = _jquery_ui_filter_parse_tag_attributes($matches[0]);

  // Look for json in rel attribute.
  if (empty($attributes['rel'])) {
    return $matches[0];
  }

  // Parse the JSON insures that no one can inject JavaScript into the site.
  $json = json_decode(str_replace("'", '"', $attributes['rel']));
  if (!$json) {
    return $matches[0];
  }

  // Since filter_xss() removes {} (ie Netscape 4 JS entities) we are going to
  // escape (urlencode) the json string.
  // - Once HTML 5 is support we can use the data attribute.
  //   http://ejohn.org/blog/html-5-data-attributes/
  // - Allow filter_xss_admin() to accept HTML5 tags
  //   http://drupal.org/node/732992
  $attributes['rel'] = urlencode(json_encode($json));
  return '<a' . drupal_attributes($attributes) . '>';
}