public function compile() { $doc_impl = new DOMImplementation(); $implType = $doc_impl->createDocumentType($this->m_doctype['type'], $this->m_doctype['name'], $this->m_doctype['doctype']); $doc = null; if ($implType) { $doc = $doc_impl->createDocument(null, $this->m_doctype['type'], $implType); } else { return; } $doc->encoding = $this->getEncoding(); parent::setDocument($doc); $html = parent::getRoot(); if ($this->getDocument()->doctype->name == 'xhtml') { $html->attr('xmlns', 'http://www.w3.org/1999/xhtml'); $html->attr('xml:lang', 'en'); } $head = parent::create('head'); $body = parent::create('body'); $title = parent::create('title'); $title->text($this->m_title); $head->append($title); if ($this->m_base) { $base = parent::create('base'); $base->attr('href', $this->m_base); $head->append($base); } $doc = ''; //$this->metaAddHttp( 'Content-Type', 'text/html; charset=' . $this->getEncoding() ); if ($this->m_keywords) { $this->metaAddName('keywords', $this->m_keywords); } if ($this->m_description) { $this->metaAddName('description', $this->m_description); } foreach ($this->m_meta as $m) { if (!is_array($m) || count($m) < 0) { continue; } $mnode = parent::create('meta'); foreach ($m as $key => $val) { $mnode->attr($key, $val); } $head->append($mnode); } foreach ($this->m_styles['inline'] as $s) { $style = parent::create('style'); $style->attr('type', 'text/css'); $style->text($s); $head->append($style); } foreach ($this->m_link as $link) { if (!is_array($link) || count($link) < 0) { continue; } $l = parent::create('link'); foreach ($link as $key => $val) { $l->attr($key, $val); } $head->append($l); } foreach ($this->m_scripts['header'] as $s) { $script = parent::create('script'); $script->attr('type', 'text/javascript'); $script->text($s); $head->append($script); } foreach ($this->m_styles['url'] as $s) { $style = parent::create('link'); $style->attr('rel', 'stylesheet'); $style->attr('type', 'text/css'); $style->attr('media', $s[1]); $style->attr('href', $s[0]); $head->append($style); } foreach ($this->m_styles['include'] as $s) { $style = parent::create('link'); $style->attr('rel', 'stylesheet'); $style->attr('type', 'text/css'); $style->attr('media', $s[1]); $style->attr('href', $s[0]); $head->append($style); } foreach ($this->m_scripts['url'] as $s) { $script = parent::create('script'); $script->attr('type', 'text/javascript'); $script->attr('src', $s); $script->text(''); $head->append($script); } $placeholder = '[-----REPLACE-HERE-' . md5(time()) . '-----]'; $body->text($placeholder); foreach ($this->m_scripts['include'] as $s) { $script = parent::create('script'); $script->attr('type', 'text/javascript'); $script->attr('src', $s); $script->text(''); $body->append($script); } foreach ($this->m_scripts['inline'] as $s) { $script = parent::create('script'); $script->attr('type', 'text/javascript'); $script->text($s); $body->append($script); } $d = $this->getDocument(); $d->preserveWhiteSpace = true; $d->recover = false; $d->formatOutput = true; $html->append($head); $html->append($body); parent::append($html); $d->normalizeDocument(); $content = str_replace($placeholder, $this->body(), $d->saveHtml()); return $content; }