Advertisement
Guest User

templates/TEMPLATE_NAME/html/renderer/head.php

a guest
Mar 20th, 2015
1,482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.52 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Document
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM') or die;
  11.  
  12. /**
  13.  * JDocument head renderer
  14.  *
  15.  * @since  11.1
  16.  */
  17. class JDocumentRendererHead extends JDocumentRenderer
  18. {
  19.     /**
  20.      * Renders the document head and returns the results as a string
  21.      *
  22.      * @param   string  $head     (unused)
  23.      * @param   array   $params   Associative array of values
  24.      * @param   string  $content  The script
  25.      *
  26.      * @return  string  The output of the script
  27.      *
  28.      * @since   11.1
  29.      *
  30.      * @note    Unused arguments are retained to preserve backward compatibility.
  31.      */
  32.     public function render($head, $params = array(), $content = null)
  33.     {
  34.  
  35.         if ($params['name'] == 'head')
  36.         {
  37.             return $this->fetchHead($this->_doc);
  38.         }
  39.         elseif ($params['name'] == 'footer')
  40.         {
  41.             return $this->fetchFooter($this->_doc);
  42.         }
  43.     }
  44.  
  45.     /**
  46.      * Generates the head HTML and return the results as a string
  47.      *
  48.      * @param   JDocument  $document  The document for which the head will be created
  49.      *
  50.      * @return  string  The head hTML
  51.      *
  52.      * @since   11.1
  53.      */
  54.     public function fetchHead($document)
  55.     {
  56.         // Convert the tagids to titles
  57.         if (isset($document->_metaTags['standard']['tags']))
  58.         {
  59.             $tagsHelper = new JHelperTags;
  60.             $document->_metaTags['standard']['tags'] = implode(', ', $tagsHelper->getTagNames($document->_metaTags['standard']['tags']));
  61.         }
  62.  
  63.         // Trigger the onBeforeCompileHead event
  64.         $app = JFactory::getApplication();
  65.         $app->triggerEvent('onBeforeCompileHead');
  66.  
  67.         // Get line endings
  68.         $lnEnd = $document->_getLineEnd();
  69.         $tab = $document->_getTab();
  70.         $tagEnd = ' />';
  71.         $buffer = '';
  72.  
  73.         // Generate charset when using HTML5 (should happen first)
  74.         if ($document->isHtml5())
  75.         {
  76.             $buffer .= $tab . '<meta charset="' . $document->getCharset() . '" />' . $lnEnd;
  77.         }
  78.  
  79.         // Generate base tag (need to happen early)
  80.         $base = $document->getBase();
  81.  
  82.         if (!empty($base))
  83.         {
  84.             $buffer .= $tab . '<base href="' . $document->getBase() . '" />' . $lnEnd;
  85.         }
  86.  
  87.         // Generate META tags (needs to happen as early as possible in the head)
  88.         foreach ($document->_metaTags as $type => $tag)
  89.         {
  90.             foreach ($tag as $name => $content)
  91.             {
  92.                 if ($type == 'http-equiv' && !($document->isHtml5() && $name == 'content-type'))
  93.                 {
  94.                     $buffer .= $tab . '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
  95.                 }
  96.                 elseif ($type == 'standard' && !empty($content))
  97.                 {
  98.                     $buffer .= $tab . '<meta name="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
  99.                 }
  100.             }
  101.         }
  102.  
  103.         // Don't add empty descriptions
  104.         $documentDescription = $document->getDescription();
  105.  
  106.         if ($documentDescription)
  107.         {
  108.             $buffer .= $tab . '<meta name="description" content="' . htmlspecialchars($documentDescription) . '" />' . $lnEnd;
  109.         }
  110.  
  111.         // Don't add empty generators
  112.         $generator = $document->getGenerator();
  113.  
  114.         if ($generator)
  115.         {
  116.             $buffer .= $tab . '<meta name="generator" content="' . htmlspecialchars($generator) . '" />' . $lnEnd;
  117.         }
  118.  
  119.         $buffer .= $tab . '<title>' . htmlspecialchars($document->getTitle(), ENT_COMPAT, 'UTF-8') . '</title>' . $lnEnd;
  120.  
  121.         // Generate link declarations
  122.         foreach ($document->_links as $link => $linkAtrr)
  123.         {
  124.             $buffer .= $tab . '<link href="' . $link . '" ' . $linkAtrr['relType'] . '="' . $linkAtrr['relation'] . '"';
  125.  
  126.             if ($temp = JArrayHelper::toString($linkAtrr['attribs']))
  127.             {
  128.                 $buffer .= ' ' . $temp;
  129.             }
  130.  
  131.             $buffer .= ' />' . $lnEnd;
  132.         }
  133.  
  134.         // Generate stylesheet links
  135.         foreach ($document->_styleSheets as $strSrc => $strAttr)
  136.         {
  137.             $buffer .= $tab . '<link rel="stylesheet" href="' . $strSrc . '"';
  138.  
  139.             if (!is_null($strAttr['mime']) && (!$document->isHtml5() || $strAttr['mime'] != 'text/css'))
  140.             {
  141.                 $buffer .= ' type="' . $strAttr['mime'] . '"';
  142.             }
  143.  
  144.             if (!is_null($strAttr['media']))
  145.             {
  146.                 $buffer .= ' media="' . $strAttr['media'] . '"';
  147.             }
  148.  
  149.             if ($temp = JArrayHelper::toString($strAttr['attribs']))
  150.             {
  151.                 $buffer .= ' ' . $temp;
  152.             }
  153.  
  154.             $buffer .= $tagEnd . $lnEnd;
  155.         }
  156.  
  157.         // Generate stylesheet declarations
  158.         foreach ($document->_style as $type => $content)
  159.         {
  160.             $buffer .= $tab . '<style type="' . $type . '">' . $lnEnd;
  161.  
  162.             // This is for full XHTML support.
  163.             if ($document->_mime != 'text/html')
  164.             {
  165.                 $buffer .= $tab . $tab . '/*<![CDATA[*/' . $lnEnd;
  166.             }
  167.  
  168.             $buffer .= $content . $lnEnd;
  169.  
  170.             // See above note
  171.             if ($document->_mime != 'text/html')
  172.             {
  173.                 $buffer .= $tab . $tab . '/*]]>*/' . $lnEnd;
  174.             }
  175.  
  176.             $buffer .= $tab . '</style>' . $lnEnd;
  177.         }
  178.  
  179.         foreach ($document->_custom as $custom)
  180.         {
  181.             $buffer .= $tab . $custom . $lnEnd;
  182.         }
  183.  
  184.         return $buffer;
  185.     }
  186.  
  187.     /**
  188.      * Generates the head HTML and return the results as a string
  189.      *
  190.      * @param   JDocument  $document  The document for which the head will be created
  191.      *
  192.      * @return  string  The head hTML
  193.      *
  194.      * @since   11.1
  195.      */
  196.     public function fetchFooter($document)
  197.     {
  198.         // Convert the tagids to titles
  199.         if (isset($document->_metaTags['standard']['tags']))
  200.         {
  201.             $tagsHelper = new JHelperTags;
  202.             $document->_metaTags['standard']['tags'] = implode(', ', $tagsHelper->getTagNames($document->_metaTags['standard']['tags']));
  203.         }
  204.  
  205.         // Trigger the onBeforeCompileHead event
  206.         $app = JFactory::getApplication();
  207.         $app->triggerEvent('onBeforeCompileHead');
  208.  
  209.         // Get line endings
  210.         $lnEnd = $document->_getLineEnd();
  211.         $tab = $document->_getTab();
  212.         $tagEnd = ' />';
  213.         $buffer = '';
  214.  
  215.         // Generate script file links
  216.         foreach ($document->_scripts as $strSrc => $strAttr)
  217.         {
  218.             $buffer .= $tab . '<script src="' . $strSrc . '"';
  219.             $defaultMimes = array(
  220.                 'text/javascript', 'application/javascript', 'text/x-javascript', 'application/x-javascript'
  221.             );
  222.  
  223.             if (!is_null($strAttr['mime']) && (!$document->isHtml5() || !in_array($strAttr['mime'], $defaultMimes)))
  224.             {
  225.                 $buffer .= ' type="' . $strAttr['mime'] . '"';
  226.             }
  227.  
  228.             if ($strAttr['defer'])
  229.             {
  230.                 $buffer .= ' defer="defer"';
  231.             }
  232.  
  233.             if ($strAttr['async'])
  234.             {
  235.                 $buffer .= ' async="async"';
  236.             }
  237.  
  238.             $buffer .= '></script>' . $lnEnd;
  239.         }
  240.  
  241.         // Generate script declarations
  242.         foreach ($document->_script as $type => $content)
  243.         {
  244.             $buffer .= $tab . '<script type="' . $type . '">' . $lnEnd;
  245.  
  246.             // This is for full XHTML support.
  247.             if ($document->_mime != 'text/html')
  248.             {
  249.                 $buffer .= $tab . $tab . '//<![CDATA[' . $lnEnd;
  250.             }
  251.  
  252.             $buffer .= $content . $lnEnd;
  253.  
  254.             // See above note
  255.             if ($document->_mime != 'text/html')
  256.             {
  257.                 $buffer .= $tab . $tab . '//]]>' . $lnEnd;
  258.             }
  259.  
  260.             $buffer .= $tab . '</script>' . $lnEnd;
  261.         }
  262.  
  263.         // Generate script language declarations.
  264.         if (count(JText::script()))
  265.         {
  266.             $buffer .= $tab . '<script type="text/javascript">' . $lnEnd;
  267.  
  268.             if ($document->_mime != 'text/html')
  269.             {
  270.                 $buffer .= $tab . $tab . '//<![CDATA[' . $lnEnd;
  271.             }
  272.  
  273.             $buffer .= $tab . $tab . '(function() {' . $lnEnd;
  274.             $buffer .= $tab . $tab . $tab . 'Joomla.JText.load(' . json_encode(JText::script()) . ');' . $lnEnd;
  275.             $buffer .= $tab . $tab . '})();' . $lnEnd;
  276.  
  277.             if ($document->_mime != 'text/html')
  278.             {
  279.                 $buffer .= $tab . $tab . '//]]>' . $lnEnd;
  280.             }
  281.  
  282.             $buffer .= $tab . '</script>' . $lnEnd;
  283.         }
  284.  
  285.         foreach ($document->_custom as $custom)
  286.         {
  287.             $buffer .= $tab . $custom . $lnEnd;
  288.         }
  289.  
  290.         return $buffer;
  291.     }
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement