Update favicon.blade.php

This commit is contained in:
Julian Prieber 2023-11-23 15:19:10 +01:00
parent 3609d1477a
commit e201b4cbb1
1 changed files with 165 additions and 152 deletions

View File

@ -1,8 +1,9 @@
<?php
use App\Models\Link;
function getFaviconURL($url)
{
if (!function_exists('getFaviconURL')) {
function getFaviconURL($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
@ -60,18 +61,22 @@ function getFaviconURL($url)
$faviconURL = getAbsoluteUrl($url, $faviconURL);
}
return $faviconURL;
}
}
function getRedirectUrlFromHeaders($headers)
{
if (!function_exists('getRedirectUrlFromHeaders')) {
function getRedirectUrlFromHeaders($headers)
{
if (preg_match('/^Location:\s+(.*)$/mi', $headers, $matches)) {
return trim($matches[1]);
}
return null;
}
}
function extractFaviconUrlFromDOM($dom)
{
if (!function_exists('extractFaviconUrlFromDOM')) {
function extractFaviconUrlFromDOM($dom)
{
$xpath = new DOMXPath($dom);
// Check for the historical rel="shortcut icon"
@ -89,16 +94,20 @@ function extractFaviconUrlFromDOM($dom)
}
return null;
}
}
function checkURLExists($url)
{
if (!function_exists('checkURLExists')) {
function checkURLExists($url)
{
$headers = @get_headers($url);
return ($headers && strpos($headers[0], '200') !== false);
}
}
function extractFaviconUrlWithRegex($html)
{
if (!function_exists('extractFaviconUrlWithRegex')) {
function extractFaviconUrlWithRegex($html)
{
// Check for the historical rel="shortcut icon"
if (preg_match('/<link[^>]+rel=["\']shortcut icon["\'][^>]+href=["\']([^"\']+)["\']/', $html, $matches)) {
$faviconURL = $matches[1];
@ -112,10 +121,12 @@ function extractFaviconUrlWithRegex($html)
}
return null;
}
}
function getAbsoluteUrl($baseUrl, $relativeUrl)
{
if (!function_exists('getAbsoluteUrl')) {
function getAbsoluteUrl($baseUrl, $relativeUrl)
{
$parsedUrl = parse_url($baseUrl);
$scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] : 'http';
$host = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
@ -129,10 +140,12 @@ function getAbsoluteUrl($baseUrl, $relativeUrl)
} else {
return "$basePath/$relativeUrl"; // Path-relative URL
}
}
}
function getFavIcon($id)
{
if (!function_exists('getFavIcon')) {
function getFavIcon($id)
{
try {
$link = Link::find($id);
$page = $link->link;
@ -169,5 +182,5 @@ function getFavIcon($id)
return url('assets/favicon/icons/' . $filename);
}
}
}
?>