public function FrxEditor::setBody in Forena Reports 7.4
Same name and namespace in other branches
- 7.3 FrxEditor.inc \FrxEditor::setBody()
Set the value of the body of the report Will parse and set the value of the body of the report using XML
Parameters
html $body:
File
- ./
FrxEditor.inc, line 207 - FrxEditor.inc Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd
Class
- FrxEditor
- @file FrxEditor.inc Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd
Code
public function setBody($body) {
$dom = $this->dom;
$nodes = $dom
->getElementsByTagName('body');
$cur_body = $nodes
->item(0);
// Make sure that we have a body tag.
if (strpos($body, '<body') === FALSE) {
$body = '<body>' . $body . '</body>';
}
// Attempt to parse the xml
$body_doc = new DOMDocument('1.0', 'UTF-8');
$body_xml = $this->doc_prefix . '<html xmlns:frx="' . $this->xmlns . '">' . $body . '</html>';
try {
$body_doc
->loadXML($body_xml);
$new_body = $dom
->importNode($body_doc
->getElementsByTagName('body')
->item(0), TRUE);
$parent = $cur_body->parentNode;
$parent
->replaceChild($new_body, $cur_body);
} catch (Exception $e) {
Frx::error('Malformed report body', '<pre>' . $e
->getMessage() . $e
->getTraceAsString() . '</pre>');
}
// If there are no frx attributes in the body then replace them with the old values.
$frx_nodes = $this->frxReport->rpt_xml
->xpath('body//*[@frx:*]');
if (!$frx_nodes) {
$this->frxReport
->save_attributes_by_id();
}
}