]> git.llucax.com Git - mecon/meconlib.git/commitdiff
Se arreglan bugs y se hace que en el addBodyContent() se busquen metodos
authorMartín Marrese <marrese@gmail.com>
Tue, 29 Jul 2003 18:27:58 +0000 (18:27 +0000)
committerMartín Marrese <marrese@gmail.com>
Tue, 29 Jul 2003 18:27:58 +0000 (18:27 +0000)
toStyleSheet() y toScript() para agregar scripts y CSS automaticamente.

pear_lib_tmp/HTML/Page.php

index 2e32634886fc5c16aefcd49be2057b77661338fc..1e8018900957b13c3da084974ec792757e19eb20 100644 (file)
@@ -387,9 +387,7 @@ class HTML_Page extends HTML_Common {
         }
         
         // Generate stylesheet links
         }
         
         // Generate stylesheet links
-        $count = count($this->_styleSheets);
-        for($intCounter=0; $intCounter < $count; $intCounter++) {
-            $strStyleSheet = $this->_styleSheets[$intCounter];
+        foreach ($this->_styleSheets as $strStyleSheet) {
             $strHtml .= $tab . "<link rel=\"stylesheet\" href=\"$strStyleSheet\" type=\"text/css\" />" . $lnEnd;
         }
         
             $strHtml .= $tab . "<link rel=\"stylesheet\" href=\"$strStyleSheet\" type=\"text/css\" />" . $lnEnd;
         }
         
@@ -422,10 +420,7 @@ class HTML_Page extends HTML_Common {
         }
         
         // Generate script file links
         }
         
         // 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 . "<script type=\"$strType\" src=\"$strSrc\"></script>" . $lnEnd;
         }
         
             $strHtml .= $tab . "<script type=\"$strType\" src=\"$strSrc\"></script>" . $lnEnd;
         }
         
@@ -519,6 +514,35 @@ class HTML_Page extends HTML_Common {
     function addBodyContent($content)
     {
         $this->_body[] =& $content;
     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    
     
     /**
     } // end addBodyContent    
     
     /**
@@ -530,7 +554,7 @@ class HTML_Page extends HTML_Common {
      */
     function addScript($url, $type="text/javascript")
     {
      */
     function addScript($url, $type="text/javascript")
     {
-        $this->_scripts["$type$url"] = array("type"=>$type, "src"=>$url);
+        $this->_scripts[$url] = $type;
     } // end func addScript
     
     /**
     } // end func addScript
     
     /**
@@ -639,7 +663,7 @@ class HTML_Page extends HTML_Common {
     function setBody($content)
     {
         $this->unsetBody();
     function setBody($content)
     {
         $this->unsetBody();
-        $this->_body[] =& $content;
+        $this->addBodyContent($content);
     } // end setBody
     
     /**
     } // end setBody
     
     /**