mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
Add PWA icon generation and update manifest to use favicon
This commit is contained in:
parent
d825e61fb0
commit
95f5dcf19c
3 changed files with 47 additions and 33 deletions
|
@ -90,6 +90,9 @@ if (!empty($_POST['faviconBase64'])) {
|
|||
$photoURL = $imagePath . $fileName;
|
||||
$bytes = file_put_contents($global['systemRootPath'] . $photoURL, $fileData);
|
||||
if ($bytes > 10) {
|
||||
|
||||
pwaIconsArray($global['systemRootPath'] . $photoURL, true);
|
||||
|
||||
$response2 = [
|
||||
"status" => 'success',
|
||||
"url" => $global['systemRootPath'] . $photoURL,
|
||||
|
|
|
@ -1108,3 +1108,42 @@ function createColorfulTextSpans($string)
|
|||
$output .= '</span>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
function pwaIconsArray($favicon = '', $forceDelete = false)
|
||||
{
|
||||
$icon = [];
|
||||
//$faviconICO = Configuration::_getFavicon(false);
|
||||
|
||||
$sizes = [72, 96, 120, 128, 144, 152, 180, 192, 384, 512];
|
||||
|
||||
if($favicon && $forceDelete){
|
||||
foreach ($sizes as $value) {
|
||||
$pwaIcon = "faviconPWA{$value}.png";
|
||||
if (file_exists(getVideosDir() . $pwaIcon)) {
|
||||
_error_log("pwaIconsArray: deleting $pwaIcon");
|
||||
unlink(getVideosDir() . $pwaIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($sizes as $value) {
|
||||
$pwaIcon = "faviconPWA{$value}.png";
|
||||
if ($favicon && !file_exists(getVideosDir() . $pwaIcon)) {
|
||||
im_resize($favicon['file'], getVideosDir() . $pwaIcon, $value, $value);
|
||||
}
|
||||
$icon[] = pwaIcon(getURL('videos/' . $pwaIcon), 'image/png', "{$value}x{$value}");
|
||||
}
|
||||
//$icon[] = pwaIcon($favicon['url'], 'image/png', '180x180');
|
||||
//$icon[] = pwaIcon($faviconICO['url'], 'image/x-icon', '16x16,24x24,32x32,48x48,144x144');
|
||||
|
||||
return $icon;
|
||||
}
|
||||
|
||||
function pwaIcon($src, $type, $sizes)
|
||||
{
|
||||
$icon = new stdClass();
|
||||
$icon->src = $src;
|
||||
$icon->type = $type;
|
||||
$icon->sizes = $sizes;
|
||||
return $icon;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,10 @@ $pwa->short_name = $config->getWebSiteTitle();
|
|||
$pwa->name = $config->getWebSiteTitle();
|
||||
$pwa->description = $config->getWebSiteTitle();
|
||||
|
||||
$pwa->icons = pwaIconsArray();
|
||||
|
||||
$favicon = Configuration::_getFavicon(true);
|
||||
|
||||
$pwa->icons = pwaIconsArray($favicon);
|
||||
|
||||
//$pwa->start_url = $global['webSiteRootURL'];
|
||||
$pwa->start_url = '/';
|
||||
|
@ -41,7 +44,7 @@ $shortcut->short_name = $config->getWebSiteTitle();
|
|||
$shortcut->description = $config->getWebSiteTitle();
|
||||
//$shortcut->url = $global['webSiteRootURL'];
|
||||
$shortcut->url = '/';
|
||||
$shortcut->icons = pwaIconsArray();
|
||||
$shortcut->icons = pwaIconsArray($favicon);
|
||||
|
||||
$pwa->shortcuts = [$shortcut];
|
||||
|
||||
|
@ -54,34 +57,3 @@ function pwaRelated_applications($platform, $url)
|
|||
$obj->url = $url;
|
||||
return $obj;
|
||||
}
|
||||
|
||||
function pwaIcon($src, $type, $sizes)
|
||||
{
|
||||
$icon = new stdClass();
|
||||
$icon->src = $src;
|
||||
$icon->type = $type;
|
||||
$icon->sizes = $sizes;
|
||||
return $icon;
|
||||
}
|
||||
|
||||
function pwaIconsArray()
|
||||
{
|
||||
$icon = [];
|
||||
|
||||
$favicon = Configuration::_getFavicon(true);
|
||||
//$faviconICO = Configuration::_getFavicon(false);
|
||||
|
||||
$sizes = [72, 96, 120, 128, 144, 152, 180, 192, 384, 512];
|
||||
|
||||
foreach ($sizes as $value) {
|
||||
$pwaIcon = "faviconPWA{$value}.png";
|
||||
if (!file_exists(getVideosDir() . $pwaIcon)) {
|
||||
im_resize($favicon['file'], getVideosDir() . $pwaIcon, $value, $value);
|
||||
}
|
||||
$icon[] = pwaIcon(getURL('videos/' . $pwaIcon), 'image/png', "{$value}x{$value}");
|
||||
}
|
||||
//$icon[] = pwaIcon($favicon['url'], 'image/png', '180x180');
|
||||
//$icon[] = pwaIcon($faviconICO['url'], 'image/x-icon', '16x16,24x24,32x32,48x48,144x144');
|
||||
|
||||
return $icon;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue