/** * Render this page into XHTML. * * This methods renders the whole page into a complete XHTML page. Usually * you want to use flush() to output the page to the browser. * * \return * The rendered page as a string. * * \see AnewtPage::flush */ public function render() { /* Create basic element nodes */ $head = new AnewtXMLDomElement('head'); $body = new AnewtXMLDomElement('body'); $head->always_render_closing_tag = true; $body->always_render_closing_tag = true; /* Content-type in meta tag. This must be the first element inside the * <head>...</head> element. */ $head->append_child(ax_meta(array('http-equiv' => 'Content-type', 'content' => $this->build_content_type_charset()))); /* Base URI */ $base_uri = $this->_get('base-uri'); if (!is_null($base_uri)) { assert('is_string($base_uri); // base-uri must be a simple string'); /* Employ a simple heuristic to make sure we use an absolute URI, as * is required by the HTML specification. */ if (!str_contains($base_uri, '://')) { $base_uri = AnewtRequest::canonical_base_url() . $base_uri; } $base = new AnewtXHTMLBase(); $base->set_attribute('href', $base_uri); $head->append_child($base); } /* Page title (always include, even if empty, since this is required by * the HTML specification) */ $title = $this->_get('title'); $head->append_child(ax_title($title)); /* Dublin Core metadata. See http://dublincore.org/documents/dcq-html/ * */ if ($this->_get('show-dublin-core')) { $head->append_child(ax_link(array('rel' => 'schema.DC', 'href' => 'http://purl.org/dc/elements/1.1/'))); $head->append_child(ax_meta_name_content('DC.language', $this->_get('language'))); if (!is_null($title)) { $head->append_child(ax_meta_name_content('DC.title', $title)); } if ($this->_isset('creator')) { $head->append_child(ax_meta_name_content('DC.creator', $this->_get('creator'))); } if ($this->_isset('description')) { $head->append_child(ax_meta_name_content('DC.description', $this->_get('description'))); } if ($this->_isset('date')) { $date = $this->get('date'); } else { $date = AnewtDateTime::now(); } $head->append_child(ax_meta_name_content('DC.date', AnewtDateTime::date($date))); } /* Powered by Anewt! */ $generator = $this->_get('generator'); if (!is_null($generator)) { assert('is_string($generator);'); $head->append_child(ax_meta_name_content('generator', $generator)); } /* Robots */ $robots = $this->_get('robots'); if (!is_null($robots)) { assert('is_string($robots);'); $head->append_child(ax_meta(array('name' => 'robots', 'content' => $robots))); } /* Links (including stylesheets) and JavaScripts */ $head->append_children($this->_links); $head->append_children($this->_javascripts); /* Favicon */ $favicon = $this->_get('favicon'); if (!is_null($favicon)) { assert('is_string($favicon);'); $head->append_child(ax_link_favicon($favicon)); } /* Body content */ if ($this->_get('blocks')) { /* This is a page using div blocks */ if ($this->_content && $this->_content->has_child_nodes()) { throw new AnewtException('Pages using blocks should not have content outside blocks.'); } /* The buffer holding all content is either a wrapper div or an * invisible fragment (both XML nodes, so the API is the same). */ if ($this->_get('use-wrapper-div')) { $buffer = ax_div_id(null, $this->_get('wrapper-div-id')); } else { $buffer = ax_fragment(); } /* Add the content */ foreach ($this->_get('blocks') as $block_name) { $block = $this->get_block($block_name); $buffer->append_child(ax_div_id($block, $block_name)); unset($block); unset($div); } $body->append_child($buffer); } else { /* This page has no blocks, so we use the nodes in _content instead * (if any) */ if ($this->_blocks) { throw new AnewtException('Pages not using blocks should not have content in blocks'); } if ($this->_content) { $body->append_child($this->_content); } } /* Assemble the top level elements */ $document = new AnewtXMLDomDocument(); $document->set_document_type($this->_get('document-type')); $document->set_content_type($this->_get('content-type')); $document->set_encoding($this->_get('encoding')); $html = new AnewtXMLDomElement('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => $this->_get('language'), 'lang' => $this->_get('language'))); $html->append_child($head); $html->append_child($body); $document->append_child($html); return $document; }
/** * \private * * Build an XML element representing this item. * * This method should not be called directly, it is only used by the * AnewtRssChannel class. * * \return * A XML element representing this item. */ public function _build_element() { $item = new AnewtXMLDomElement('item'); /* Loop over all properties of this item */ foreach ($this->properties as $property => $property_spec) { list($tagname, $status, $type) = $property_spec; $element = AnewtRssChannel::_build_rss_element($this, $property, $tagname, $status, $type); if (is_null($element)) { continue; } $item->append_child($element); unset($element); } return $item; }