Elgg  Version 4.3
AddFaviconLinksHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Page;
4 
11 
19  public function __invoke(\Elgg\Hook $hook) {
20  $head_params = $hook->getValue();
21 
22  if (elgg_get_site_entity()->hasIcon('master', 'favicon')) {
23  $config = $this->getSiteIcons();
24  } else {
25  $config = $this->getDefaultIcons();
26  }
27 
28  foreach ($config as $name => $link) {
29  $head_params['links'][$name] = $link;
30  }
31 
32  return $head_params;
33  }
34 
40  protected function getDefaultIcons(): array {
41  return [
42  'apple-touch-icon' => [
43  'rel' => 'apple-touch-icon',
44  'type' => 'image/png',
45  'href' => elgg_get_simplecache_url('graphics/favicon-128.png'),
46  ],
47  'icon-ico' => [
48  'rel' => 'icon',
49  'href' => elgg_get_simplecache_url('graphics/favicon.ico'),
50  ],
51  'icon-16' => [
52  'rel' => 'icon',
53  'sizes' => '16x16',
54  'type' => 'image/png',
55  'href' => elgg_get_simplecache_url('graphics/favicon-16.png'),
56  ],
57  'icon-32' => [
58  'rel' => 'icon',
59  'sizes' => '32x32',
60  'type' => 'image/png',
61  'href' => elgg_get_simplecache_url('graphics/favicon-32.png'),
62  ],
63  'icon-64' => [
64  'rel' => 'icon',
65  'sizes' => '64x64',
66  'type' => 'image/png',
67  'href' => elgg_get_simplecache_url('graphics/favicon-64.png'),
68  ],
69  'icon-128' => [
70  'rel' => 'icon',
71  'sizes' => '128x128',
72  'type' => 'image/png',
73  'href' => elgg_get_simplecache_url('graphics/favicon-128.png'),
74  ],
75  ];
76  }
77 
83  protected function getSiteIcons(): array {
85 
86  $sizes = elgg_get_icon_sizes('site', null, 'favicon');
87  unset($sizes['master']);
88 
89  $result = [];
90 
91  if (isset($sizes['icon-128'])) {
92  $result['apple-touch-icon'] = [
93  'rel' => 'apple-touch-icon',
94  'type' => 'image/jpeg',
95  'href' => $site->getIconURL(['size' => 'icon-128', 'type' => 'favicon']),
96  ];
97  }
98 
99  if (isset($sizes['icon-32'])) {
100  $result['icon-ico'] = [
101  'rel' => 'icon',
102  'href' => $site->getIconURL(['size' => 'icon-32', 'type' => 'favicon']),
103  ];
104  }
105 
106  foreach ($sizes as $name => $size_config) {
107  if (!elgg_extract('square', $size_config, false)) {
108  continue;
109  }
110 
111  $result[$name] = [
112  'rel' => 'icon',
113  'type' => 'image/jpeg',
114  'sizes' => "{$size_config['w']}x{$size_config['h']}",
115  'href' => $site->getIconURL(['size' => $name, 'type' => 'favicon']),
116  ];
117  }
118 
119  return $result;
120  }
121 }
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
elgg_get_icon_sizes($entity_type=null, $entity_subtype=null, $type= 'icon')
Returns a configuration array of icon sizes.
elgg_get_simplecache_url($view, $subview= '')
Get the URL for the cached view.
Definition: cache.php:139
$site
Definition: icons.php:5
getDefaultIcons()
Returns default icons.
if(!$item instanceof ElggEntity) $link
Definition: container.php:16
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
Models an event passed to hook handlers.
Definition: Hook.php:11
__invoke(\Elgg\Hook $hook)
Add favicon link tags to HTML head.
elgg_get_site_entity()
Get the current site entity.
Definition: entities.php:99
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:547
getSiteIcons()
Returns icons for the site entity.
Add favicon links to page head.