예제 #1
0
 /**
  * Returns the rendered head tag
  * @param boolean echo result
  * @return string
  */
 public function render($output = false)
 {
     $close_single = Xhtml::instance()->is_xhtml ? ' />' : '>';
     $html = '<head>';
     $html .= '<title>' . $this->title . '</title>';
     foreach ($this->meta_extra as $key => $value) {
         $html .= '<meta' . Html::attributes(array('http-equiv' => $key, 'content' => $value)) . $close_single;
     }
     foreach ($this->metas as $key => $value) {
         $html .= '<meta' . Html::attributes(array('name' => $key, 'content' => $value)) . $close_single;
     }
     foreach ($this->links as $value) {
         $html .= '<link' . Html::attributes($value) . $close_single;
     }
     // styles
     if (Kohana::config('xhtml.cache_styles')) {
         $html .= Html::style($this->cached_styles);
     } else {
         foreach ($this->styles as $value) {
             $style_file = NULL;
             $style_atts = array();
             $style_cond = NULL;
             if (is_string($value)) {
                 $style_file = $value;
             } elseif (is_array($value)) {
                 if (isset($value['file'])) {
                     $style_file = $value['file'];
                     unset($value['file']);
                 }
                 if (isset($value['condition'])) {
                     $style_cond = $value['condition'];
                     unset($value['condition']);
                 }
                 $style_atts = $value;
             }
             if ($style_file) {
                 if ($style_cond) {
                     $html .= '<!--[if ' . $style_cond . ']>';
                 }
                 $html .= Html::style($style_file, $style_atts);
                 if ($style_cond) {
                     $html .= '<![endif]-->';
                 }
             }
         }
     }
     // scripts
     if (Kohana::config('xhtml.cache_scripts')) {
         $html .= Html::script($this->cached_scripts);
     } else {
         foreach ($this->scripts as $file) {
             $html .= Html::script($file);
         }
         foreach ($this->codes as $code) {
             $html .= '<script' . Html::attributes(array('type' => 'text/javascript')) . '>//<![CDATA[' . "\n" . $code . "\n" . '//]]></script>';
         }
     }
     $html .= '</head>';
     if ($output) {
         echo $html;
     }
     return $html;
 }