You are here

function mee_filter_process in Scald: Media Management made easy 7

Process callback for the 'mee_scald_widgets' filter.

This expends the embed marker into the themed "atom embed" markup. The atom itself is not rendered yet, since that is not cacheable. Instead, a placeholder SAS code is left, that will be replaced in mee_field_attach_view_alter().

Parameters

string $text: The text to process.

Return value

string The processed text.

2 calls to mee_filter_process()
mee_field_attach_view_alter in modules/fields/mee/mee.module
Implements hook_field_attach_view_alter.
mee_panels_pane_content_alter in modules/fields/mee/mee.module
Implements hook_panels_pane_content_alter().
1 string reference to 'mee_filter_process'
mee_filter_info in modules/fields/mee/mee.module
Implements hook_filter_info().

File

modules/fields/mee/mee.module, line 910
Defines a special textarea, with drag and drop media driven by Scald and dnd.module.

Code

function mee_filter_process($text) {

  // Work on the string as a DOM structure.
  $dom = filter_dom_load($text);

  // Collect the DOM nodes and the corresponding embed data.
  if ($embed_info = _mee_extract_widget_embed_info($dom)) {

    // Collect the corresponding atom ids and load them upfront to benefit from
    // multiple-loading.
    $sids = array();
    foreach ($embed_info as $info) {
      $sids[] = $info['sid'];
    }
    $atoms = scald_atom_load_multiple(array_unique($sids));

    // Replace each DOM node with the themed embed.
    foreach ($embed_info as $info) {
      $html = '';
      if (isset($atoms[$info['sid']])) {
        $html = theme('mee_widget_embed', array(
          'atom' => $atoms[$info['sid']],
          'context' => $info['context'],
          'options' => $info['options'],
          'align' => $info['align'],
          'caption' => $info['caption'],
          // Only store a SAS code in the filter cache, that will get replaced
          // with the HTML for the rendered atom in
          // mee_field_attach_view_alter().
          'content' => '[scald=' . $info['sid'] . ':' . $info['context'] . ($info['options'] ? ' ' . $info['options'] : '') . ']',
        ));
      }
      $node = $info['node'];
      $fragment = $dom
        ->createDocumentFragment();
      $fragment
        ->appendXML($html);
      $node->parentNode
        ->replaceChild($fragment, $node);
    }
    $text = filter_dom_serialize($dom);
  }
  return $text;
}