file.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * File icon view
  4. *
  5. * @uses $vars['entity'] The entity the icon represents - uses getIconURL() method
  6. * @uses $vars['size'] topbar, tiny, small, medium (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. */
  11. $entity = $vars['entity'];
  12. $sizes = array('small', 'medium', 'large', 'tiny', 'master', 'topbar');
  13. // Get size
  14. if (!in_array($vars['size'], $sizes)) {
  15. $vars['size'] = "medium";
  16. }
  17. $title = $entity->title;
  18. $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8', false);
  19. $url = $entity->getURL();
  20. if (isset($vars['href'])) {
  21. $url = $vars['href'];
  22. }
  23. $class = '';
  24. if (isset($vars['img_class'])) {
  25. $class = $vars['img_class'];
  26. }
  27. if ($entity->thumbnail) {
  28. $class = "class=\"elgg-photo $class\"";
  29. } else if ($class) {
  30. $class = "class=\"$class\"";
  31. }
  32. $img_src = $entity->getIconURL($vars['size']);
  33. $img_src = elgg_format_url($img_src);
  34. $img = "<img $class src=\"$img_src\" alt=\"$title\" />";
  35. if ($url) {
  36. $params = array(
  37. 'href' => $url,
  38. 'text' => $img,
  39. 'is_trusted' => true,
  40. );
  41. if (isset($vars['link_class'])) {
  42. $params['class'] = $vars['link_class'];
  43. }
  44. echo elgg_view('output/url', $params);
  45. } else {
  46. echo $img;
  47. }