default.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Generic icon view.
  4. *
  5. * @package Elgg
  6. * @subpackage Core
  7. *
  8. * @uses $vars['entity'] The entity the icon represents - uses getIconURL() method
  9. * @uses $vars['size'] topbar, tiny, small, medium (default), large, master
  10. * @uses $vars['href'] Optional override for link
  11. * @uses $vars['img_class'] Optional CSS class added to img
  12. * @uses $vars['link_class'] Optional CSS class for the link
  13. */
  14. $entity = $vars['entity'];
  15. $icon_sizes = elgg_get_config('icon_sizes');
  16. // Get size
  17. $size = elgg_extract('size', $vars, 'medium');
  18. if (!array_key_exists($size, $icon_sizes)) {
  19. $size = "medium";
  20. }
  21. $vars['size'] = $size;
  22. $class = elgg_extract('img_class', $vars, '');
  23. if (isset($entity->name)) {
  24. $title = $entity->name;
  25. } else {
  26. $title = $entity->title;
  27. }
  28. $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8', false);
  29. $url = $entity->getURL();
  30. if (isset($vars['href'])) {
  31. $url = $vars['href'];
  32. }
  33. if (!isset($vars['width'])) {
  34. $vars['width'] = $size != 'master' ? $icon_sizes[$size]['w'] : null;
  35. }
  36. if (!isset($vars['height'])) {
  37. $vars['height'] = $size != 'master' ? $icon_sizes[$size]['h'] : null;
  38. }
  39. $img_params = array(
  40. 'src' => $entity->getIconURL($size),
  41. 'alt' => $title,
  42. );
  43. if (!empty($class)) {
  44. $img_params['class'] = $class;
  45. }
  46. if (!empty($vars['width'])) {
  47. $img_params['width'] = $vars['width'];
  48. }
  49. if (!empty($vars['height'])) {
  50. $img_params['height'] = $vars['height'];
  51. }
  52. $img = elgg_view('output/img', $img_params);
  53. if ($url) {
  54. $params = array(
  55. 'href' => $url,
  56. 'text' => $img,
  57. 'is_trusted' => true,
  58. );
  59. $class = elgg_extract('link_class', $vars, '');
  60. if ($class) {
  61. $params['class'] = $class;
  62. }
  63. echo elgg_view('output/url', $params);
  64. } else {
  65. echo $img;
  66. }