image.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Image icon view
  4. *
  5. * @uses $vars['entity'] The entity the icon represents - uses getIconURL() method
  6. * @uses $vars['size'] tiny, small (default), large, master
  7. * @uses $vars['href'] Optional override for link
  8. * @uses $vars['img_class'] Optional CSS class added to img
  9. * @uses $vars['link_class'] Optional CSS class added to link
  10. * @uses $vars['title'] Optional title override
  11. *
  12. * @author Cash Costello
  13. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
  14. */
  15. $entity = $vars['entity'];
  16. $sizes = array('master', 'large', 'small', 'tiny');
  17. // Get size
  18. if (!in_array($vars['size'], $sizes)) {
  19. $vars['size'] = 'small';
  20. }
  21. if (!isset($vars['title'])) {
  22. $title = $entity->getTitle();
  23. } else {
  24. $title = $vars['title'];
  25. }
  26. $url = isset($vars['href']) ? $vars['href'] : $entity->getURL();
  27. if (isset($vars['href'])) {
  28. $url = $vars['href'];
  29. }
  30. $class = '';
  31. if (isset($vars['img_class'])) {
  32. $class = $vars['img_class'];
  33. }
  34. $class = "elgg-photo $class";
  35. $img_src = $entity->getIconURL($vars['size']);
  36. $img_src = elgg_format_url($img_src);
  37. $img = elgg_view('output/img', array(
  38. 'src' => $img_src,
  39. 'class' => $class,
  40. 'title' => $title,
  41. 'alt' => $title,
  42. ));
  43. if ($url) {
  44. $params = array(
  45. 'href' => $url,
  46. 'text' => $img,
  47. 'is_trusted' => true,
  48. );
  49. if (isset($vars['link_class'])) {
  50. $params['class'] = $vars['link_class'];
  51. }
  52. echo elgg_view('output/url', $params);
  53. } else {
  54. echo $img;
  55. }