Permalink
Browse files

- fix some inline docs

- add toFile method
- allow XML prolog disabling for XHTML documents (default is still enabled)


git-svn-id: http://svn.php.net/repository/pear/packages/HTML_Page/trunk@139372 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 9196b60 commit b8a15701ef50d53a0f4d4dd19b971d213cdc58bf Klaus Guenther committed Sep 1, 2003
Showing with 60 additions and 3 deletions.
  1. +60 −3 Page.php
View
@@ -147,6 +147,7 @@
*
* @author Adam Daniel <adaniel1@eesus.jnj.com>
* @author Klaus Guenther <klaus@capitalfocus.org>
+ * @package HTML_Page
* @version 2.0
* @since PHP 4.0.3pl1
*/
@@ -265,6 +266,14 @@ class HTML_Page extends HTML_Common {
var $_title = '';
/**
+ * Defines whether XML prolog should be prepended to XHTML documents
+ *
+ * @var bool
+ * @access private
+ */
+ var $_xmlProlog = true;
+
+ /**
* Class constructor
* Possible attributes are:
* - general options:
@@ -750,6 +759,28 @@ function apiVersion()
} // end func apiVersion
/**
+ * Disables prepending the XML prolog for XHTML documents
+ *
+ * @access public
+ * @returns void
+ */
+ function disableXmlProlog()
+ {
+ $this->_xmlProlog = false;
+ } // end func disableXmlProlog
+
+ /**
+ * Enables prepending the XML prolog for XHTML documents (default)
+ *
+ * @access public
+ * @returns void
+ */
+ function enableXmlProlog()
+ {
+ $this->_xmlProlog = true;
+ } // end func enableXmlProlog
+
+ /**
* Returns the document charset encoding.
*
* @access public
@@ -1003,9 +1034,13 @@ function toHTML()
$this->_namespace = $this->_getNamespace();
}
- $strHtml = '<?xml version="1.0" encoding="' . $this->_charset . '"?>' . $lnEnd;
- $strHtml .= $strDoctype . $lnEnd;
+ $strHtml = $strDoctype . $lnEnd;
$strHtml .= '<html xmlns="' . $this->_namespace . '" xml:lang="' . $this->_language . '">' . $lnEnd;
+
+ // check whether the XML prolog should be prepended
+ if ($this->_xmlProlog){
+ $strHtml = '<?xml version="1.0" encoding="' . $this->_charset . '"?>' . $lnEnd . $strHtml;
+ }
} else {
@@ -1019,7 +1054,29 @@ function toHTML()
$strHtml .= '</html>';
return $strHtml;
} // end func toHtml
-
+
+ /**
+ * Generates the document and outputs it to a file.
+ *
+ * @return void
+ * @since 2.0
+ * @access public
+ */
+ function toFile($filename)
+ {
+ if (function_exists('file_put_content')){
+ file_put_content($filename, $this->toHtml());
+ } else {
+ $file = fopen($filename,'wb');
+ fwrite($file, $this->toHtml());
+ fclose($file);
+ }
+ if (!file_exists($filename)){
+ PEAR::raiseError("HTML_Page::toFile() error: Failed to write to $filename");
+ }
+
+ } // end func toFile
+
/**
* Outputs the HTML content to the screen.
*

0 comments on commit b8a1570

Please sign in to comment.