Checks if the types of the passed arguments in a function/method call are compatible.
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 | |||
15 | $entity = $vars['entity']; |
||
16 | /* @var ElggEntity $entity */ |
||
17 | |||
18 | $icon_sizes = elgg_get_icon_sizes($entity->type, $entity->getSubtype()); |
||
19 | // Get size |
||
20 | $size = elgg_extract('size', $vars, 'medium'); |
||
21 | if (!array_key_exists($size, $icon_sizes)) { |
||
22 | $size = "medium"; |
||
23 | } |
||
24 | $vars['size'] = $size; |
||
25 | |||
26 | $class = elgg_extract('img_class', $vars, ''); |
||
27 | |||
28 | if (isset($entity->name)) { |
||
29 | $title = $entity->name; |
||
30 | } else { |
||
31 | $title = $entity->title; |
||
32 | } |
||
33 | $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8', false); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
34 | |||
35 | $url = $entity->getURL(); |
||
36 | if (isset($vars['href'])) { |
||
37 | $url = $vars['href']; |
||
38 | } |
||
39 | |||
40 | if (!isset($vars['width'])) { |
||
41 | $vars['width'] = $size != 'master' ? $icon_sizes[$size]['w'] : null; |
||
42 | } |
||
43 | if (!isset($vars['height'])) { |
||
44 | $vars['height'] = $size != 'master' ? $icon_sizes[$size]['h'] : null; |
||
45 | } |
||
46 | |||
47 | $img_params = [ |
||
48 | 'src' => $entity->getIconURL($size), |
||
49 | 'alt' => $title, |
||
50 | ]; |
||
51 | |||
52 | if (!empty($class)) { |
||
53 | $img_params['class'] = $class; |
||
54 | } |
||
55 | |||
56 | if (!empty($vars['width'])) { |
||
57 | $img_params['width'] = $vars['width']; |
||
58 | } |
||
59 | |||
60 | if (!empty($vars['height'])) { |
||
61 | $img_params['height'] = $vars['height']; |
||
62 | } |
||
63 | |||
64 | $img = elgg_view('output/img', $img_params); |
||
65 | |||
66 | if ($url) { |
||
67 | $params = [ |
||
68 | 'href' => $url, |
||
69 | 'text' => $img, |
||
70 | 'is_trusted' => true, |
||
71 | ]; |
||
72 | $class = elgg_extract('link_class', $vars, ''); |
||
73 | if ($class) { |
||
74 | $params['class'] = $class; |
||
75 | } |
||
76 | |||
77 | echo elgg_view('output/url', $params); |
||
78 | } else { |
||
79 | echo $img; |
||
80 | } |
||
81 |