|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace ElePHPant\Favicon; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Favicon |
|
9
|
|
|
* |
|
10
|
|
|
* Please report bugs on https://github.com/wilderamorim/favicon/issues |
|
11
|
|
|
* |
|
12
|
|
|
* @package ElePHPant\Favicon |
|
13
|
|
|
* @author Wilder Amorim <[email protected]> |
|
14
|
|
|
* @copyright Copyright (c) 2020, Uebi. All rights reserved |
|
15
|
|
|
* @license MIT License |
|
16
|
|
|
*/ |
|
17
|
|
|
class Favicon extends Tags |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Favicon constructor. |
|
21
|
|
|
* @param string $sourceImage |
|
22
|
|
|
* @param string $saveInPath |
|
23
|
|
|
* @param string $websiteUrl |
|
24
|
|
|
* @param string|null $websiteTitle |
|
25
|
|
|
* @param string|null $backgroundColor |
|
26
|
|
|
* @param string|null $rssFeedUrl |
|
27
|
|
|
* @param bool $cropper |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct( |
|
30
|
|
|
string $sourceImage, |
|
31
|
|
|
string $saveInPath, |
|
32
|
|
|
string $websiteUrl, |
|
33
|
|
|
?string $websiteTitle = null, |
|
34
|
|
|
?string $backgroundColor = '#FFFFFF', |
|
35
|
|
|
?string $rssFeedUrl = null, |
|
36
|
|
|
bool $cropper = true |
|
37
|
|
|
) { |
|
38
|
|
|
parent::__construct($sourceImage, $saveInPath, $websiteUrl, $websiteTitle, $backgroundColor, $rssFeedUrl); |
|
39
|
|
|
|
|
40
|
|
|
if ($cropper) { |
|
41
|
|
|
try { |
|
42
|
|
|
(new Cropper($sourceImage, $saveInPath, $websiteUrl, $websiteTitle, $backgroundColor, $rssFeedUrl)) |
|
43
|
|
|
->create(); |
|
44
|
|
|
} catch (\Exception $e) { |
|
45
|
|
|
// |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return $this |
|
52
|
|
|
*/ |
|
53
|
|
|
public function favicon(): Favicon |
|
54
|
|
|
{ |
|
55
|
|
|
$this->appleTouchIconPrecomposed(); |
|
56
|
|
|
$this->icon(); |
|
57
|
|
|
$this->applicationName($this->websiteTitle); |
|
58
|
|
|
$this->msApplication(); |
|
59
|
|
|
$this->msApplicationNotification($this->rssFeedUrl); |
|
60
|
|
|
|
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return Favicon |
|
66
|
|
|
*/ |
|
67
|
|
|
private function appleTouchIconPrecomposed(): Favicon |
|
68
|
|
|
{ |
|
69
|
|
|
foreach (self::APPLE_TOUCH_ICON_PRECOMPOSED as $item) { |
|
70
|
|
|
$this->buildLink('apple-touch-icon-precomposed', "{$this->websiteUrl}/apple-touch-icon-{$item}.png", $item); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return Favicon |
|
78
|
|
|
*/ |
|
79
|
|
|
private function icon(): Favicon |
|
80
|
|
|
{ |
|
81
|
|
|
foreach (self::ICON as $item) { |
|
82
|
|
|
$this->buildLink('icon', "{$this->websiteUrl}/favicon-{$item}.png", $item, 'image/png'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param string|null $name |
|
90
|
|
|
* @return Favicon |
|
91
|
|
|
*/ |
|
92
|
|
|
private function applicationName(?string $name = ' '): Favicon |
|
93
|
|
|
{ |
|
94
|
|
|
$this->buildMeta('name', ['application-name' => $name]); |
|
95
|
|
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return Favicon |
|
100
|
|
|
*/ |
|
101
|
|
|
private function msApplication(): Favicon |
|
102
|
|
|
{ |
|
103
|
|
|
$tileColor = $this->msApplication['TileColor']; |
|
104
|
|
|
|
|
105
|
|
|
foreach ($this->msApplication as $key => $value) { |
|
106
|
|
|
if ($value == $tileColor) { |
|
107
|
|
|
$this->buildMeta('name', ["msapplication-{$key}" => $value]); |
|
108
|
|
|
} else { |
|
109
|
|
|
$this->buildMeta('name', ["msapplication-{$key}" => "{$this->websiteUrl}/{$value}"]); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param string|null $rss |
|
118
|
|
|
* @return Favicon|null |
|
119
|
|
|
*/ |
|
120
|
|
|
private function msApplicationNotification(?string $rss = null): ?Favicon |
|
121
|
|
|
{ |
|
122
|
|
|
if (!$rss) { |
|
123
|
|
|
return null; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
$content = "frequency=30;polling-uri=https://notifications.buildmypinnedsite.com/?feed={$rss}&id=1;polling-uri2=https://notifications.buildmypinnedsite.com/?feed={$rss}&id=2;polling-uri3=https://notifications.buildmypinnedsite.com/?feed={$rss}&id=3;polling-uri4=https://notifications.buildmypinnedsite.com/?feed={$rss}&id=4;polling-uri5=https://notifications.buildmypinnedsite.com/?feed={$rss}&id=5;cycle=1"; |
|
127
|
|
|
$this->buildMeta('name', ['msapplication-notification' => $content]); |
|
128
|
|
|
|
|
129
|
|
|
return $this; |
|
130
|
|
|
} |
|
131
|
|
|
} |