default.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. $sizes = array('small', 'medium', 'large', 'tiny', 'master', 'topbar');
  16. // Get size
  17. //if (!in_array($vars['size'], $sizes)) {
  18. $vars['size'] = "medium";
  19. //}
  20. $class = elgg_extract('img_class', $vars, '');
  21. $span = '';
  22. $parent = au_subgroups_get_parent_group($entity);
  23. if ($parent) {
  24. if ($class) {
  25. $class .= ' ';
  26. }
  27. $class .= 'au_subgroup_icon';
  28. // $span = '<span class="au_subgroup au_subgroup_icon-' . $vars['size'] . '">' . elgg_echo('au_subgroups:subgroup') . '</span>';
  29. // $span = '<span class="au_subgroup au_subgroup_icon-' . $vars['size'] . '">' . '</span>';
  30. }
  31. if (isset($entity->name)) {
  32. $title = $entity->name;
  33. } else {
  34. $title = $entity->title;
  35. }
  36. $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8', false);
  37. $url = $entity->getURL();
  38. if (isset($vars['href'])) {
  39. $url = $vars['href'];
  40. }
  41. $icon_sizes = elgg_get_config('icon_sizes');
  42. $size = $vars['size'];
  43. // maintain aspect ratio
  44. $filehandler = new ElggFile();
  45. $filehandler->owner_guid = $entity->owner_guid;
  46. $filehandler->setFilename("groups/" . $entity->guid . $size . ".jpg");
  47. $location = elgg_get_plugins_path() . "groups/graphics/default{$size}.gif";
  48. if ($filehandler->open("read")) {
  49. $location = $filehandler->getFilenameOnFilestore();
  50. }
  51. $imginfo = getimagesize($location);
  52. if($imginfo){
  53. $realratio = $imginfo[0]/$imginfo[1];
  54. $img_height = $size != 'master' ? $icon_sizes[$size]['h'] : NULL;
  55. $img_width = $size != 'master' ? $icon_sizes[$size]['w'] : NULL;
  56. //set ratio greater than realratio by default in case $img_height = 0
  57. $setratio = $realratio + 1;
  58. if(!empty($img_height)){
  59. $setratio = $img_width/$img_height;
  60. }
  61. // set the largest dimension to "auto"
  62. if($realratio > $setratio || empty($img_height)){
  63. // constrain the height
  64. $img_height = NULL;
  65. }
  66. elseif($realratio < $setratio || empty($img_width)){
  67. $img_width = NULL;
  68. }
  69. }
  70. $img = '<div class="au_subgroups_group_icon au_subgroups_group_icon-' . $vars['size'] . '">';
  71. $img .= elgg_view('output/img', array(
  72. 'src' => $entity->getIconURL($vars['size']),
  73. 'alt' => $title,
  74. 'class' => $class,
  75. 'width' => $img_width,
  76. 'height' => $img_height,
  77. ));
  78. $img .= "{$span}</div>";
  79. if ($url) {
  80. $params = array(
  81. 'href' => $url,
  82. 'text' => $img,
  83. 'is_trusted' => true,
  84. );
  85. $class = elgg_extract('link_class', $vars, '');
  86. if ($class) {
  87. $params['class'] = $class;
  88. }
  89. echo elgg_view('output/url', $params);
  90. } else {
  91. echo $img;
  92. }