You are here

function _mee_extract_widget_embed_info in Scald: Media Management made easy 7

Extract information about atom embeds found in a DOMDocument.

Parameters

DOMDocument $dom: The DOMDocument.

Return value

array Information about atom embeds found in $dom. Each value is an array with the following key/value pairs:

  • node: the DOMNode containing the embed.
  • sid: the atom id.
  • align: the embed alignment (left, right, center, none).
  • context: the atom render context.
  • options: the atom render options.
  • caption: the embed caption.
2 calls to _mee_extract_widget_embed_info()
mee_filter_process in modules/fields/mee/mee.module
Process callback for the 'mee_scald_widgets' filter.
_mee_process_item_value in modules/fields/mee/mee.module
Extracts sids and copyright from $item. Updates $item if necessary.

File

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

Code

function _mee_extract_widget_embed_info($dom) {
  $embed_info = array();

  // Collect the DOM nodes and the corresponding embed data.
  $xpath = new DOMXPath($dom);
  $nodes = $xpath
    ->query("//div[@class='dnd-atom-wrapper']|//figure[@class='dnd-atom-wrapper']|//span[@class='dnd-atom-wrapper']");
  foreach ($nodes as $node) {
    $info = array(
      'node' => $node,
      'sid' => $node
        ->getAttribute('data-scald-sid'),
      'align' => $node
        ->getAttribute('data-scald-align'),
      'context' => $node
        ->getAttribute('data-scald-context'),
      'options' => urldecode($node
        ->getAttribute('data-scald-options')),
      'caption' => '',
    );

    // Extract the caption if present.
    $result = $xpath
      ->query("div[@class='dnd-caption-wrapper']|figcaption[@class='dnd-caption-wrapper']", $node);
    if ($result->length) {
      foreach ($result
        ->item(0)->childNodes as $child) {
        $info['caption'] .= $dom
          ->saveXML($child);
      }
    }
    $embed_info[] = $info;
  }
  return $embed_info;
}