public function render() { //------------------------------------------------------------- // No Render? //------------------------------------------------------------- if ($this->get_data('no-render') || defined('POFW_SKIP_RENDER') && POFW_SKIP_RENDER) { return true; } //------------------------------------------------------------- // JavaScript / CSS Add-in Files //------------------------------------------------------------- if (!empty($this->js_files)) { $this->set_data('js_files', $this->js_files); } if (!empty($this->css_files)) { $this->set_data('css_files', $this->css_files); } //------------------------------------------------------------- // Escape Data (or not) //------------------------------------------------------------- if ($this->data_format == 'xml') { foreach ($this->data as $dkey => &$dval) { if (!isset($this->no_escape_elements[$dkey])) { $dval = xml_escape_array($dval); } } } //------------------------------------------------------------- // Create Data //------------------------------------------------------------- if ($this->data_format == 'xml') { $data = array2xml($this->root_node, $this->data); } else { if ($this->data_format == 'json') { $data = json_encode($this->data); } else { $data = $this->data; } } //------------------------------------------------------------- // Output //------------------------------------------------------------- if ($this->show_data_only) { if (is_array($data)) { print_array($data); } else { print $data; } return true; } else { $render_function = $this->get_data('render-function'); //---------------------------------------------------- // XML //---------------------------------------------------- if ($this->data_format == 'xml') { if ($render_function) { return $render_function($data, $this->template); } else { if (file_exists($this->template)) { return xml_transform($data, $this->template); } else { if (empty($this->template)) { print "No template file has been specified."; } else { print "Invalid template file specified."; } } } } else { if ($render_function) { return $render_function($data, $this->template); } else { print "No valid render function was specified."; } } } return false; }
function xml_escape_array($in_data) { if (is_array($in_data)) { foreach ($in_data as $key => $item) { $in_data[$key] = xml_escape_array($item); } return $in_data; } else { if ($in_data !== '' && !is_numeric($in_data)) { return '<![CDATA[' . strip_cdata_tags($in_data) . ']]>'; } else { if (is_numeric($in_data)) { return $in_data; } else { return false; } } } }