Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added inline script functionality

updated some inline docs
fixed some potential bugs


git-svn-id: http://svn.php.net/repository/pear/packages/HTML_Page/trunk@135026 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 818e9fe93309ff7bdb9904ceeb5215b7b1ae9b56 1 parent 2012647
Klaus Guenther authored
Showing with 69 additions and 6 deletions.
  1. +69 −6 Page.php
View
75 Page.php
@@ -225,6 +225,14 @@ class HTML_Page extends HTML_Common {
var $_scripts = array();
/**
+ * Array of scripts placed in the header
+ *
+ * @var array
+ * @access private
+ */
+ var $_script = array();
+
+ /**
* Array of linked scripts
*
* @var array
@@ -434,8 +442,7 @@ function _generateHead()
foreach ($this->_style as $type => $content) {
$strHtml .= $tab . '<style type="' . $type . '">' . $lnEnd;
- // This is for when XHTML is fully supported. Until then,
- // <!-- will be used for both.
+ // This is for full XHTML supporte.
if ($this->_mime == 'text/html' ) {
$strHtml .= $tab . $tab . '<!--' . $lnEnd;
} else {
@@ -455,7 +462,7 @@ function _generateHead()
if (method_exists($content, "toString")) {
$strHtml .= $content->toString() . $lnEnd;
} else {
- return PEAR::raiseError('Error: Body content object does not support method toString().',
+ return PEAR::raiseError('Error: Style content object does not support method toString().',
0,PEAR_ERROR_TRIGGER);
}
@@ -481,6 +488,47 @@ function _generateHead()
$strHtml .= $tab . "<script type=\"$strType\" src=\"$strSrc\"></script>" . $lnEnd;
}
+ // Generate script declarations
+ foreach ($this->_script as $type => $content) {
+ $strHtml .= $tab . '<script type="' . $type . '">' . $lnEnd;
+
+ // This is for full XHTML support.
+ if ($this->_mime == 'text/html' ) {
+ $strHtml .= $tab . $tab . '<!--' . $lnEnd;
+ } else {
+ $strHtml .= $tab . $tab . '<![CDATA[' . $lnEnd;
+ }
+
+ if (is_object($content)) {
+
+ // first let's propagate line endings and tabs for other HTML_Common-based objects
+ if (is_subclass_of($content, "html_common")) {
+ $content->setTab($tab);
+ $content->setTabOffset(3);
+ $content->setLineEnd($lnEnd);
+ }
+
+ // now let's get a string from the object
+ if (method_exists($content, "toString")) {
+ $strHtml .= $content->toString() . $lnEnd;
+ } else {
+ return PEAR::raiseError('Error: Script content object does not support method toString().',
+ 0,PEAR_ERROR_TRIGGER);
+ }
+
+ } else {
+ $strHtml .= $content . $lnEnd;
+ }
+
+ // See above note
+ if ($this->_mime == 'text/html' ) {
+ $strHtml .= $tab . $tab . '-->' . $lnEnd;
+ } else {
+ $strHtml .= $tab . $tab . ']]>' . $lnEnd;
+ }
+ $strHtml .= $tab . '</script>' . $lnEnd;
+ }
+
// Close tag
$strHtml .= '</head>' . $lnEnd;
@@ -644,7 +692,7 @@ function addBodyContent($content)
/**
* Adds a linked script to the page
*
- * @param string $url URL to the linked style sheet
+ * @param string $url URL to the linked script
* @param string $type Type of script. Defaults to 'text/javascript'
* @access public
*/
@@ -654,6 +702,21 @@ function addScript($url, $type="text/javascript")
} // end func addScript
/**
+ * Adds a script to the page.
+ * Content can be a string or an object with a toString method.
+ * Defaults to text/javascript.
+ *
+ * @access public
+ * @param mixed $content Script (may be passed as a reference)
+ * @param string $type Scripting mime (defaults to 'text/javascript')
+ * @return void
+ */
+ function addScriptDeclaration($content, $type = 'text/javascript')
+ {
+ $this->_script[strtolower($type)] =& $content;
+ } // end func addScriptDeclaration
+
+ /**
* Adds a linked stylesheet to the page
*
* @param string $url URL to the linked style sheet
@@ -677,7 +740,7 @@ function addStyleSheet($url)
*/
function addStyleDeclaration($content, $type = 'text/css')
{
- $this->_style[$type] =& $content;
+ $this->_style[strtolower($type)] =& $content;
} // end func addStyleDeclaration
/**
@@ -887,7 +950,7 @@ function setMetaRefresh($time, $url = 'self', $https = false)
*/
function setMimeEncoding($type = 'text/html')
{
- $this->_mime = $type;
+ $this->_mime = strtolower($type);
} // end func setMimeEncoding
/**
Please sign in to comment.
Something went wrong with that request. Please try again.