You are here

function RendererBase::addFragment in Forena Reports 8

Append a textual XHTML fragment to the dom. We do not use the DOMDocumentFragment optioin because they don't properly import namespaces. .

Parameters

DOMNode $node: Node of DOM to add element too.

string $xml_string: String containing an XML fragment to add

string $ctl_name:

File

src/FrxPlugin/Renderer/RendererBase.php, line 638
FrxRenderer.php Base class for FrxAPI custom Renderer @author davidmetzler

Class

RendererBase
Crosstab Renderer

Namespace

Drupal\forena\FrxPlugin\Renderer

Code

function addFragment(DOMNode $node, $xml_string, $ctl_name = 'Header') {
  if (is_array($xml_string) && isset($xml_string['value'])) {
    $xml_string = $xml_string['value'];
  }
  if ($xml_string && !is_array($xml_string)) {
    $temp_dom = FrxAPI::tempDOM();
    $body_xml = '<?xml version="1.0" encoding="UTF-8"?>
         <!DOCTYPE root [
         <!ENTITY nbsp "&#160;">
         ]><html xmlns:frx="' . $this->xmlns . '"><body>' . $xml_string . '</body></html>';
    try {
      $temp_dom
        ->loadXML($body_xml);
    } catch (\Exception $e) {
      $this
        ->error('Malformed report body', '<pre>' . $e
        ->getMessage() . $e
        ->getTraceAsString() . '</pre>');
    }
    $body = $temp_dom
      ->getElementsByTagName('body')
      ->item(0);
    foreach ($body->childNodes as $sub) {
      $new_node = $this->report->dom
        ->importNode($sub, TRUE);
      $node
        ->appendChild($new_node);
    }
    if ($node->nodeType == XML_ELEMENT_NODE) {
      $xmlnode = simplexml_import_dom($node);
      $frx_nodes = $xmlnode
        ->xpath('//*[@frx:*]');
      if (!$frx_nodes) {
        $this
          ->frxReportsave_attributes_by_id();
      }
    }
  }
}