From: Martín Marrese Date: Tue, 29 Jul 2003 18:27:58 +0000 (+0000) Subject: Se arreglan bugs y se hace que en el addBodyContent() se busquen metodos X-Git-Tag: svn_import~350 X-Git-Url: https://git.llucax.com/mecon/meconlib.git/commitdiff_plain/2db057a4f421908b02b8c9c0459ffa31cca059be?ds=inline Se arreglan bugs y se hace que en el addBodyContent() se busquen metodos toStyleSheet() y toScript() para agregar scripts y CSS automaticamente. --- diff --git a/pear_lib_tmp/HTML/Page.php b/pear_lib_tmp/HTML/Page.php index 2e32634..1e80189 100644 --- a/pear_lib_tmp/HTML/Page.php +++ b/pear_lib_tmp/HTML/Page.php @@ -387,9 +387,7 @@ class HTML_Page extends HTML_Common { } // Generate stylesheet links - $count = count($this->_styleSheets); - for($intCounter=0; $intCounter < $count; $intCounter++) { - $strStyleSheet = $this->_styleSheets[$intCounter]; + foreach ($this->_styleSheets as $strStyleSheet) { $strHtml .= $tab . "" . $lnEnd; } @@ -422,10 +420,7 @@ class HTML_Page extends HTML_Common { } // Generate script file links - $count = count($this->_scripts); - for($intCounter=0; $intCounter < $count; $intCounter++) { - $strType = $this->_scripts[$intCounter]["type"]; - $strSrc = $this->_scripts[$intCounter]["src"]; + foreach ($this->_scripts as $strSrc => $strType) { $strHtml .= $tab . "" . $lnEnd; } @@ -519,6 +514,35 @@ class HTML_Page extends HTML_Common { function addBodyContent($content) { $this->_body[] =& $content; + if (is_object($content)) { + if (method_exists($content, "toStyleSheet")) { + $this->addStyleSheet($content->toStyleSheet()); + } + if (method_exists($content, "toScript")) { + $script = $content->toScript(); + if (is_array($script)) { + $this->addScript($script[0], $script[1]); + } else { + $this->addScript($script); + } + } + } elseif (is_array($content)) { + foreach ($content as $element) { + if (is_object($content)) { + if (method_exists($element, "toStyleSheet")) { + $this->addStyleSheet($element->toStyleSheet()); + } + if (method_exists($element, "toScript")) { + $script = $element->toScript(); + if (is_array($script)) { + $this->addScript($script[0], $script[1]); + } else { + $this->addScript($script); + } + } + } + } + } } // end addBodyContent /** @@ -530,7 +554,7 @@ class HTML_Page extends HTML_Common { */ function addScript($url, $type="text/javascript") { - $this->_scripts["$type$url"] = array("type"=>$type, "src"=>$url); + $this->_scripts[$url] = $type; } // end func addScript /** @@ -639,7 +663,7 @@ class HTML_Page extends HTML_Common { function setBody($content) { $this->unsetBody(); - $this->_body[] =& $content; + $this->addBodyContent($content); } // end setBody /**