1<?php 2/** 3 * Generic 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['use_link'] Hyperlink the icon 8 * @uses $vars['href'] Optional override for link 9 * @uses $vars['img_class'] Optional CSS class added to img 10 * @uses $vars['link_class'] Optional CSS class for the link 11 */ 12 13$entity = elgg_extract('entity', $vars); 14if (!$entity instanceof ElggEntity) { 15 return; 16} 17 18$icon_sizes = elgg_get_icon_sizes($entity->type, $entity->getSubtype()); 19// Get size 20$size = elgg_extract('size', $vars, 'medium'); 21if (!array_key_exists($size, $icon_sizes)) { 22 $size = "medium"; 23} 24$vars['size'] = $size; 25 26$class = elgg_extract('img_class', $vars, ''); 27 28$title = htmlspecialchars($entity->getDisplayName(), ENT_QUOTES, 'UTF-8', false); 29 30$url = false; 31if (elgg_extract('use_link', $vars, true)) { 32 $url = elgg_extract('href', $vars, $entity->getURL()); 33} 34 35if (!isset($vars['width'])) { 36 $vars['width'] = $size != 'master' ? $icon_sizes[$size]['w'] : null; 37} 38if (!isset($vars['height'])) { 39 $vars['height'] = $size != 'master' ? $icon_sizes[$size]['h'] : null; 40} 41 42$img_params = [ 43 'src' => $entity->getIconURL($size), 44 'alt' => $title, 45]; 46 47if (!empty($class)) { 48 $img_params['class'] = $class; 49} 50 51if (!empty($vars['width'])) { 52 $img_params['width'] = elgg_extract('width', $vars); 53} 54 55if (!empty($vars['height'])) { 56 $img_params['height'] = elgg_extract('height', $vars); 57} 58 59$img = elgg_view('output/img', $img_params); 60if (empty($img)) { 61 return; 62} 63 64if ($url) { 65 $params = [ 66 'href' => $url, 67 'text' => $img, 68 'is_trusted' => true, 69 ]; 70 $class = elgg_extract('link_class', $vars, ''); 71 if ($class) { 72 $params['class'] = $class; 73 } 74 75 echo elgg_view('output/url', $params); 76} else { 77 echo $img; 78} 79