PageRenderTime 25ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/joomla/libraries/joomla/document/html/renderer/head.php

https://gitlab.com/ricardosanchez/prueba
PHP | 249 lines | 152 code | 44 blank | 53 comment | 37 complexity | 3ea202ad55665dffa532c2fc5337375f MD5 | raw file
  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. defined('JPATH_PLATFORM') or die;
  10. /**
  11. * JDocument head renderer
  12. *
  13. * @since 11.1
  14. */
  15. class JDocumentRendererHead extends JDocumentRenderer
  16. {
  17. /**
  18. * Renders the document head and returns the results as a string
  19. *
  20. * @param string $head (unused)
  21. * @param array $params Associative array of values
  22. * @param string $content The script
  23. *
  24. * @return string The output of the script
  25. *
  26. * @since 11.1
  27. *
  28. * @note Unused arguments are retained to preserve backward compatibility.
  29. */
  30. public function render($head, $params = array(), $content = null)
  31. {
  32. return $this->fetchHead($this->_doc);
  33. }
  34. /**
  35. * Generates the head HTML and return the results as a string
  36. *
  37. * @param JDocument $document The document for which the head will be created
  38. *
  39. * @return string The head hTML
  40. *
  41. * @since 11.1
  42. */
  43. public function fetchHead($document)
  44. {
  45. // Convert the tagids to titles
  46. if (isset($document->_metaTags['standard']['tags']))
  47. {
  48. $tagsHelper = new JHelperTags;
  49. $document->_metaTags['standard']['tags'] = implode(', ', $tagsHelper->getTagNames($document->_metaTags['standard']['tags']));
  50. }
  51. // Trigger the onBeforeCompileHead event
  52. $app = JFactory::getApplication();
  53. $app->triggerEvent('onBeforeCompileHead');
  54. // Get line endings
  55. $lnEnd = $document->_getLineEnd();
  56. $tab = $document->_getTab();
  57. $tagEnd = ' />';
  58. $buffer = '';
  59. // Generate charset when using HTML5 (should happen first)
  60. if ($document->isHtml5())
  61. {
  62. $buffer .= $tab . '<meta charset="' . $document->getCharset() . '" />' . $lnEnd;
  63. }
  64. // Generate base tag (need to happen early)
  65. $base = $document->getBase();
  66. if (!empty($base))
  67. {
  68. $buffer .= $tab . '<base href="' . $document->getBase() . '" />' . $lnEnd;
  69. }
  70. // Generate META tags (needs to happen as early as possible in the head)
  71. foreach ($document->_metaTags as $type => $tag)
  72. {
  73. foreach ($tag as $name => $content)
  74. {
  75. if ($type == 'http-equiv' && !($document->isHtml5() && $name == 'content-type'))
  76. {
  77. $buffer .= $tab . '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
  78. }
  79. elseif ($type == 'standard' && !empty($content))
  80. {
  81. $buffer .= $tab . '<meta name="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
  82. }
  83. }
  84. }
  85. // Don't add empty descriptions
  86. $documentDescription = $document->getDescription();
  87. if ($documentDescription)
  88. {
  89. $buffer .= $tab . '<meta name="description" content="' . htmlspecialchars($documentDescription) . '" />' . $lnEnd;
  90. }
  91. // Don't add empty generators
  92. $generator = $document->getGenerator();
  93. if ($generator)
  94. {
  95. $buffer .= $tab . '<meta name="generator" content="' . htmlspecialchars($generator) . '" />' . $lnEnd;
  96. }
  97. $buffer .= $tab . '<title>' . htmlspecialchars($document->getTitle(), ENT_COMPAT, 'UTF-8') . '</title>' . $lnEnd;
  98. // Generate link declarations
  99. foreach ($document->_links as $link => $linkAtrr)
  100. {
  101. $buffer .= $tab . '<link href="' . $link . '" ' . $linkAtrr['relType'] . '="' . $linkAtrr['relation'] . '"';
  102. if ($temp = JArrayHelper::toString($linkAtrr['attribs']))
  103. {
  104. $buffer .= ' ' . $temp;
  105. }
  106. $buffer .= ' />' . $lnEnd;
  107. }
  108. // Generate stylesheet links
  109. foreach ($document->_styleSheets as $strSrc => $strAttr)
  110. {
  111. $buffer .= $tab . '<link rel="stylesheet" href="' . $strSrc . '"';
  112. if (!is_null($strAttr['mime']) && (!$document->isHtml5() || $strAttr['mime'] != 'text/css'))
  113. {
  114. $buffer .= ' type="' . $strAttr['mime'] . '"';
  115. }
  116. if (!is_null($strAttr['media']))
  117. {
  118. $buffer .= ' media="' . $strAttr['media'] . '"';
  119. }
  120. if ($temp = JArrayHelper::toString($strAttr['attribs']))
  121. {
  122. $buffer .= ' ' . $temp;
  123. }
  124. $buffer .= $tagEnd . $lnEnd;
  125. }
  126. // Generate stylesheet declarations
  127. foreach ($document->_style as $type => $content)
  128. {
  129. $buffer .= $tab . '<style type="' . $type . '">' . $lnEnd;
  130. // This is for full XHTML support.
  131. if ($document->_mime != 'text/html')
  132. {
  133. $buffer .= $tab . $tab . '/*<![CDATA[*/' . $lnEnd;
  134. }
  135. $buffer .= $content . $lnEnd;
  136. // See above note
  137. if ($document->_mime != 'text/html')
  138. {
  139. $buffer .= $tab . $tab . '/*]]>*/' . $lnEnd;
  140. }
  141. $buffer .= $tab . '</style>' . $lnEnd;
  142. }
  143. // Generate script file links
  144. foreach ($document->_scripts as $strSrc => $strAttr)
  145. {
  146. $buffer .= $tab . '<script src="' . $strSrc . '"';
  147. $defaultMimes = array(
  148. 'text/javascript', 'application/javascript', 'text/x-javascript', 'application/x-javascript'
  149. );
  150. if (!is_null($strAttr['mime']) && (!$document->isHtml5() || !in_array($strAttr['mime'], $defaultMimes)))
  151. {
  152. $buffer .= ' type="' . $strAttr['mime'] . '"';
  153. }
  154. if ($strAttr['defer'])
  155. {
  156. $buffer .= ' defer="defer"';
  157. }
  158. if ($strAttr['async'])
  159. {
  160. $buffer .= ' async="async"';
  161. }
  162. $buffer .= '></script>' . $lnEnd;
  163. }
  164. // Generate script declarations
  165. foreach ($document->_script as $type => $content)
  166. {
  167. $buffer .= $tab . '<script type="' . $type . '">' . $lnEnd;
  168. // This is for full XHTML support.
  169. if ($document->_mime != 'text/html')
  170. {
  171. $buffer .= $tab . $tab . '//<![CDATA[' . $lnEnd;
  172. }
  173. $buffer .= $content . $lnEnd;
  174. // See above note
  175. if ($document->_mime != 'text/html')
  176. {
  177. $buffer .= $tab . $tab . '//]]>' . $lnEnd;
  178. }
  179. $buffer .= $tab . '</script>' . $lnEnd;
  180. }
  181. // Generate script language declarations.
  182. if (count(JText::script()))
  183. {
  184. $buffer .= $tab . '<script type="text/javascript">' . $lnEnd;
  185. if ($document->_mime != 'text/html')
  186. {
  187. $buffer .= $tab . $tab . '//<![CDATA[' . $lnEnd;
  188. }
  189. $buffer .= $tab . $tab . '(function() {' . $lnEnd;
  190. $buffer .= $tab . $tab . $tab . 'Joomla.JText.load(' . json_encode(JText::script()) . ');' . $lnEnd;
  191. $buffer .= $tab . $tab . '})();' . $lnEnd;
  192. if ($document->_mime != 'text/html')
  193. {
  194. $buffer .= $tab . $tab . '//]]>' . $lnEnd;
  195. }
  196. $buffer .= $tab . '</script>' . $lnEnd;
  197. }
  198. // Output the custom tags - array_unique makes sure that we don't output the same tags twice
  199. foreach (array_unique($document->_custom) as $custom)
  200. {
  201. $buffer .= $tab . $custom . $lnEnd;
  202. }
  203. return $buffer;
  204. }
  205. }