PageRenderTime 45ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/joebushi/joomla
PHP | 161 lines | 102 code | 21 blank | 38 comment | 19 complexity | e4a1965dac93615cdf15efdafe8a1fc0 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. // No direct access
  8. defined('JPATH_BASE') or die;
  9. /**
  10. * JDocument head renderer
  11. *
  12. * @package Joomla.Framework
  13. * @subpackage Document
  14. * @since 1.5
  15. */
  16. class JDocumentRendererHead extends JDocumentRenderer
  17. {
  18. /**
  19. * Renders the document head and returns the results as a string
  20. *
  21. * @param string $name (unused)
  22. * @param array $params Associative array of values
  23. * @return string The output of the script
  24. */
  25. public function render($head = null, $params = array(), $content = null)
  26. {
  27. ob_start();
  28. echo $this->fetchHead($this->_doc);
  29. $buffer = ob_get_contents();
  30. ob_end_clean();
  31. return $buffer;
  32. }
  33. /**
  34. * Generates the head html and return the results as a string
  35. *
  36. * @return string
  37. */
  38. public function fetchHead(&$document)
  39. {
  40. // get line endings
  41. $lnEnd = $document->_getLineEnd();
  42. $tab = $document->_getTab();
  43. $tagEnd = ' />';
  44. $buffer = '';
  45. // Generate base tag (need to happen first)
  46. $base = $document->getBase();
  47. if (!empty($base)) {
  48. $buffer .= $tab.'<base href="'.$document->getBase().'" />'.$lnEnd;
  49. }
  50. // Generate META tags (needs to happen as early as possible in the head)
  51. foreach ($document->_metaTags as $type => $tag)
  52. {
  53. foreach ($tag as $name => $content)
  54. {
  55. if ($type == 'http-equiv') {
  56. $buffer .= $tab.'<meta http-equiv="'.$name.'" content="'.$content.'"'.$tagEnd.$lnEnd;
  57. }
  58. else if ($type == 'standard') {
  59. $buffer .= $tab.'<meta name="'.$name.'" content="'.$content.'"'.$tagEnd.$lnEnd;
  60. }
  61. }
  62. }
  63. $buffer .= $tab.'<meta name="description" content="'.$document->getDescription().'" />'.$lnEnd;
  64. $buffer .= $tab.'<meta name="generator" content="'.$document->getGenerator().'" />'.$lnEnd;
  65. $buffer .= $tab.'<title>'.htmlspecialchars($document->getTitle()).'</title>'.$lnEnd;
  66. // Generate link declarations
  67. foreach ($document->_links as $link) {
  68. $buffer .= $tab.$link.$tagEnd.$lnEnd;
  69. }
  70. // Generate stylesheet links
  71. foreach ($document->_styleSheets as $strSrc => $strAttr)
  72. {
  73. $buffer .= $tab . '<link rel="stylesheet" href="'.$strSrc.'" type="'.$strAttr['mime'].'"';
  74. if (!is_null($strAttr['media'])){
  75. $buffer .= ' media="'.$strAttr['media'].'" ';
  76. }
  77. if ($temp = JArrayHelper::toString($strAttr['attribs'])) {
  78. $buffer .= ' '.$temp;;
  79. }
  80. $buffer .= $tagEnd.$lnEnd;
  81. }
  82. // Generate stylesheet declarations
  83. foreach ($document->_style as $type => $content)
  84. {
  85. $buffer .= $tab.'<style type="'.$type.'">'.$lnEnd;
  86. // This is for full XHTML support.
  87. if ($document->_mime == 'text/html') {
  88. $buffer .= $tab.$tab.'<!--'.$lnEnd;
  89. } else {
  90. $buffer .= $tab.$tab.'<![CDATA['.$lnEnd;
  91. }
  92. $buffer .= $content . $lnEnd;
  93. // See above note
  94. if ($document->_mime == 'text/html') {
  95. $buffer .= $tab.$tab.'-->'.$lnEnd;
  96. } else {
  97. $buffer .= $tab.$tab.']]>'.$lnEnd;
  98. }
  99. $buffer .= $tab.'</style>'.$lnEnd;
  100. }
  101. // Generate script file links
  102. foreach ($document->_scripts as $strSrc => $strType) {
  103. $buffer .= $tab.'<script type="'.$strType.'" src="'.$strSrc.'"></script>'.$lnEnd;
  104. }
  105. // Generate script declarations
  106. foreach ($document->_script as $type => $content)
  107. {
  108. $buffer .= $tab.'<script type="'.$type.'">'.$lnEnd;
  109. // This is for full XHTML support.
  110. if ($document->_mime != 'text/html') {
  111. $buffer .= $tab.$tab.'<![CDATA['.$lnEnd;
  112. }
  113. $buffer .= $content.$lnEnd;
  114. // See above note
  115. if ($document->_mime != 'text/html') {
  116. $buffer .= $tab.$tab.'// ]]>'.$lnEnd;
  117. }
  118. $buffer .= $tab.'</script>'.$lnEnd;
  119. }
  120. // Generate script language declarations.
  121. if (count(JText::script())) {
  122. $buffer .= $tab.'<script type="text/javascript">'.$lnEnd;
  123. $buffer .= $tab.$tab.'(function() {'.$lnEnd;
  124. $buffer .= $tab.$tab.$tab.'var strings = '.json_encode(JText::script()).';'.$lnEnd;
  125. $buffer .= $tab.$tab.$tab.'if (typeof Joomla == \'undefined\') {'.$lnEnd;
  126. $buffer .= $tab.$tab.$tab.$tab.'Joomla = {};'.$lnEnd;
  127. $buffer .= $tab.$tab.$tab.$tab.'Joomla.JText = strings;'.$lnEnd;
  128. $buffer .= $tab.$tab.$tab.'}'.$lnEnd;
  129. $buffer .= $tab.$tab.$tab.'else {'.$lnEnd;
  130. $buffer .= $tab.$tab.$tab.$tab.'Joomla.JText.load(strings);'.$lnEnd;
  131. $buffer .= $tab.$tab.$tab.'}'.$lnEnd;
  132. $buffer .= $tab.$tab.'})();'.$lnEnd;
  133. $buffer .= $tab.'</script>'.$lnEnd;
  134. }
  135. foreach($document->_custom as $custom) {
  136. $buffer .= $tab.$custom.$lnEnd;
  137. }
  138. return $buffer;
  139. }
  140. }