/libraries/joomla/html/html/image.php

https://github.com/katalystsol/joomla-platform · PHP · 190 lines · 104 code · 22 blank · 64 comment · 22 complexity · 5aed6e82ba8177311252b07ae7a96790 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage HTML
  5. *
  6. * @copyright Copyright (C) 2005 - 2011 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. * Utility class working with images.
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage HTML
  15. * @since 11.1
  16. */
  17. abstract class JHtmlImage
  18. {
  19. /**
  20. * Checks to see if an image exists in the current templates image directory.
  21. * If it does it loads this image. Otherwise the default image is loaded.
  22. * Also can be used in conjunction with the menulist param to create the chosen image
  23. * load the default or use no image.
  24. *
  25. * @param string $file The file name, eg foobar.png.
  26. * @param string $folder The path to the image.
  27. * @param integer $altFile Empty: use $file and $folder, -1: show no image, not-empty: use $altFile and $altFolder.
  28. * @param string $altFolder Another path. Only used for the contact us form based on the value of the imagelist param.
  29. * @param string $alt Alternative text.
  30. * @param array $attribs An associative array of attributes to add.
  31. * @param boolean $asTag True (default) to display full tag, false to return just the path.
  32. *
  33. * @return string The value for the src or if $asTag is true, the full img html.
  34. *
  35. * @since 11.1
  36. *
  37. * @deprecated 12.1
  38. */
  39. public static function site($file, $folder = '/images/system/', $altFile = null, $altFolder = '/images/system/', $alt = null, $attribs = null,
  40. $asTag = true)
  41. {
  42. // Deprecation warning.
  43. JLog::add('JImage::site is deprecated.', JLog::WARNING, 'deprecated');
  44. static $paths;
  45. $app = JFactory::getApplication();
  46. if (!$paths)
  47. {
  48. $paths = array();
  49. }
  50. if (is_array($attribs))
  51. {
  52. $attribs = JArrayHelper::toString($attribs);
  53. }
  54. $cur_template = $app->getTemplate();
  55. // Strip HTML.
  56. $alt = html_entity_decode($alt, ENT_COMPAT, 'UTF-8');
  57. if ($altFile)
  58. {
  59. $src = $altFolder . $altFile;
  60. }
  61. else if ($altFile == -1)
  62. {
  63. return '';
  64. }
  65. else
  66. {
  67. $path = JPATH_SITE . '/templates/' . $cur_template . '/images/' . $file;
  68. if (!isset($paths[$path]))
  69. {
  70. if (file_exists(JPATH_SITE . '/templates/' . $cur_template . '/images/' . $file))
  71. {
  72. $paths[$path] = 'templates/' . $cur_template . '/images/' . $file;
  73. }
  74. else
  75. {
  76. // Outputs only path to image.
  77. $paths[$path] = $folder . $file;
  78. }
  79. }
  80. $src = $paths[$path];
  81. }
  82. if (substr($src, 0, 1) == "/")
  83. {
  84. $src = substr_replace($src, '', 0, 1);
  85. }
  86. // Prepend the base path.
  87. $src = JURI::base(true) . '/' . $src;
  88. // Outputs actual HTML <img> tag.
  89. if ($asTag)
  90. {
  91. return '<img src="' . $src . '" alt="' . $alt . '" ' . $attribs . ' />';
  92. }
  93. return $src;
  94. }
  95. /**
  96. * Checks to see if an image exists in the current templates image directory
  97. * if it does it loads this image. Otherwise the default image is loaded.
  98. * Also can be used in conjunction with the menulist param to create the chosen image
  99. * load the default or use no image
  100. *
  101. * @param string $file The file name, eg foobar.png.
  102. * @param string $folder The path to the image.
  103. * @param integer $altFile Empty: use $file and $folder, -1: show no image, not-empty: use $altFile and $altFolder.
  104. * @param string $altFolder Another path. Only used for the contact us form based on the value of the imagelist param.
  105. * @param string $alt Alternative text.
  106. * @param array $attribs An associative array of attributes to add.
  107. * @param boolean $asTag True (default) to display full tag, false to return just the path.
  108. *
  109. * @return string The src or the full img tag if $asTag is true.
  110. *
  111. * @since 11.1
  112. *
  113. * @deprecated 12.1
  114. */
  115. public static function administrator($file, $folder = '/images/', $altFile = null, $altFolder = '/images/', $alt = null, $attribs = null,
  116. $asTag = true)
  117. {
  118. // Deprecation warning.
  119. JLog::add('JImage::administrator is deprecated.', JLog::WARNING, 'deprecated');
  120. $app = JFactory::getApplication();
  121. if (is_array($attribs))
  122. {
  123. $attribs = JArrayHelper::toString($attribs);
  124. }
  125. $cur_template = $app->getTemplate();
  126. // Strip HTML.
  127. $alt = html_entity_decode($alt, ENT_COMPAT, 'UTF-8');
  128. if ($altFile)
  129. {
  130. $image = $altFolder . $altFile;
  131. }
  132. else if ($altFile == -1)
  133. {
  134. $image = '';
  135. }
  136. else
  137. {
  138. if (file_exists(JPATH_ADMINISTRATOR . '/templates/' . $cur_template . '/images/' . $file))
  139. {
  140. $image = 'templates/' . $cur_template . '/images/' . $file;
  141. }
  142. else
  143. {
  144. // Compability with previous versions.
  145. if (substr($folder, 0, 14) == "/administrator")
  146. {
  147. $image = substr($folder, 15) . $file;
  148. }
  149. else
  150. {
  151. $image = $folder . $file;
  152. }
  153. }
  154. }
  155. if (substr($image, 0, 1) == "/")
  156. {
  157. $image = substr_replace($image, '', 0, 1);
  158. }
  159. // Prepend the base path.
  160. $image = JURI::base(true) . '/' . $image;
  161. // Outputs actual HTML <img> tag.
  162. if ($asTag)
  163. {
  164. $image = '<img src="' . $image . '" alt="' . $alt . '" ' . $attribs . ' />';
  165. }
  166. return $image;
  167. }
  168. }