* * @param string $str HTML code */ public function add_footer($str) { $this->footer .= "\n" . $str; } /** * Process template and write to stdOut * * @param string $output HTML output */ protected function _write($output = '') { $output = trim($output); if (empty($output)) { $output = html::doctype('html5') . "\n" . $this->default_template; $is_empty = true; } $merge_script_files = function($output, $script) { return $output . html::script($script); }; $merge_scripts = function($output, $script) { return $output . html::script([], $script); }; // put docready commands into page footer if (!empty($this->scripts['docready'])) { $this->add_script("\$(function() {\n" . $this->scripts['docready'] . "\n});", 'foot'); } $page_header = ''; $page_footer = ''; $meta = ''; // declare page language if (!empty($_SESSION['language'])) { $lang = substr($_SESSION['language'], 0, 2); $output = preg_replace('/header('Content-Language: ' . $lang); } } // include meta tag with charset if (!empty($this->charset)) { if (!headers_sent()) { $this->header('Content-Type: text/html; charset=' . $this->charset); } $meta .= html::tag('meta', [ 'http-equiv' => 'content-type', 'content' => "text/html; charset={$this->charset}", 'nl' => true ]); } // include page title (after charset specification) $meta .= '
\n"; $output = preg_replace('/(
]*>)\n*/i', "\\1\n{$meta}", $output, 1, $count); if (!$count) { $page_header .= $meta; } // include scripts into header/footer if (!empty($this->script_files['head'])) { $page_header .= array_reduce((array) $this->script_files['head'], $merge_script_files); } $head = $this->scripts['head_top'] ?? ''; $head .= $this->scripts['head'] ?? ''; $page_header .= array_reduce((array) $head, $merge_scripts); $page_header .= $this->header . "\n"; if (!empty($this->script_files['head_bottom'])) { $page_header .= array_reduce((array) $this->script_files['head_bottom'], $merge_script_files); } if (!empty($this->script_files['foot'])) { $page_footer .= array_reduce((array) $this->script_files['foot'], $merge_script_files); } $page_footer .= $this->footer . "\n"; if (!empty($this->scripts['foot'])) { $page_footer .= array_reduce((array) $this->scripts['foot'], $merge_scripts); } // find page header if ($hpos = stripos($output, '')) { $page_header .= "\n"; } else { if (!is_numeric($hpos)) { $hpos = stripos($output, '
')) || ($fpos = strripos($output, '