Caching favicons locally

This commit is contained in:
Julian Prieber 2022-11-28 19:44:02 +01:00
parent 4b1054fc1f
commit 19a49fedad
10 changed files with 63 additions and 23 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/studio/favicon/icons
/node_modules
/public/hot
/public/storage

View File

@ -390,7 +390,16 @@ class UserController extends Controller
Link::where('id', $linkId)->delete();
return back()->with('success', 'Link Deleted');
$directory = base_path("studio/favicon/icons");
$files = scandir($directory);
foreach($files as $file) {
if (strpos($file, $linkId.".") !== false) {
$pathinfo = pathinfo($file, PATHINFO_EXTENSION);}}
if (isset($pathinfo)) {
try{File::delete(base_path("studio/favicon/icons")."/".$linkId.".".$pathinfo);} catch (exception $e) {}
}
return redirect('/studio/links');
}
//Raise link on the littlelink page

View File

@ -0,0 +1,14 @@
<?php
function localIcon($id) {
$directory = base_path("studio/favicon/icons");
$files = scandir($directory);
$pathinfo = "error.error";
foreach($files as $file) {
if (strpos($file, $id.'.') !== false) {
$pathinfo = $id. "." . pathinfo($file, PATHINFO_EXTENSION);
}}
return $pathinfo;
}
?>

View File

@ -1,3 +1,4 @@
<?php use App\Models\Link; ?>
<?php
/**
* Website: http://sourceforge.net/projects/simplehtmldom/
@ -2355,7 +2356,9 @@ class simple_html_dom
<?php
function getFavIcon($url) {
function getFavIcon($id) {
$link = Link::find($id);
$url = $link->link;
try {
$urlICO = $url . "/favicon.ico";
$urlICO = str_replace("//favicon.ico","/favicon.ico",$urlICO);
@ -2429,16 +2432,17 @@ foreach($dom->find('link') as $e)
}
} catch (exception $e) {$favicon = url('littlelink/icons/website.svg');}
try{
$header = $favicon;
$extension = pathinfo($header, PATHINFO_EXTENSION);
if(!file_exists(base_path("studio/favicon/icons")."/".$id.".".$extension)){
if($id.".".$extension !== ".".$id){file_put_contents(base_path("studio/favicon/icons")."/".$id.".".$extension, file_get_contents($header));}
}
} catch (exception $e) {exit();}
return $favicon;
}
?>
<?php
if($_SERVER['QUERY_STRING'] !== '' and $_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR']){
header("HTTP/1.1 302 Found");
$header = getFavIcon($_SERVER['QUERY_STRING']);
header("Location: $header");
exit();
}
?>

View File

@ -3,9 +3,12 @@
@endphp
@include('components.favicon')
@include('components.favicon-extension')
<a class="button button-custom button button-hover icon-hover" rel="noopener noreferrer nofollow" href="{{ route('clickNumber') . '/' . $link->id . '/' . $link->link}}" @if(theme('open_links_in_same_tab') !="true" )target="_blank" @endif>
@if($params->GetSiteIcon ?? true)
<img alt="button-icon" class="icon hvr-icon" src="{{url('ico').'?'.$BaseURL}}" loading="lazy">
<img alt="button-icon" class="icon hvr-icon" src="{{getFavIcon($link->id)}}">
@endif
{{ $link->title }}

View File

@ -128,6 +128,9 @@ return $path;}
}
</style>
@include('components.favicon')
@include('components.favicon-extension')
</head>
<body>
@ -213,9 +216,9 @@ foreach($pages as $page)
@elseif($button['button'] === "buy me a coffee")
<div style="--delay: {{ $initial++ }}s" class="button-entrance"><a class="button button-coffee button button-hover icon-hover" rel="noopener noreferrer nofollow" href="{{ $button['link'] }}" @if(theme('open_links_in_same_tab') != "true")target="_blank"@endif ><img alt="button-icon" class="icon hvr-icon" src="@if(theme('use_custom_icons') == "true"){{ url('themes/' . $GLOBALS['themeName'] . '/extra/custom-icons')}}/coffee{{theme('custom_icon_extension')}} @else{{ asset('\/littlelink/icons\/')}}coffee.svg @endif">Buy me a Coffee</a></div>
@elseif($button['button'] === "custom_website" and ($button['custom_css'] === "" or $button['custom_css'] === "NULL") or (theme('allow_custom_buttons') == "false" and $button['button'] === "custom_website"))
<div style="--delay: {{ $initial++ }}s" class="button-entrance"><a class="button button-custom_website button button-hover icon-hover" rel="noopener noreferrer nofollow" href="{{ $button['link'] }}" @if(theme('open_links_in_same_tab') != "true")target="_blank"@endif ><img alt="button-icon" class="icon hvr-icon" src="{{url('ico').'?'.$button['link']}}" loading="lazy">{{ $button['title'] }}</a></div>
<div style="--delay: {{ $initial++ }}s" class="button-entrance"><a class="button button-custom_website button button-hover icon-hover" rel="noopener noreferrer nofollow" href="{{ $button['link'] }}" @if(theme('open_links_in_same_tab') != "true")target="_blank"@endif ><img alt="button-icon" class="icon hvr-icon" src="@if(file_exists(base_path("studio/favicon/icons/").localIcon($button['id']))){{url('studio/favicon/icons/'.localIcon($button['id']))}}@else{{getFavIcon($button['id'])}}@endif">{{ $button['title'] }}</a></div>
@elseif($button['button'] === "custom_website" and $button['custom_css'] != "")
<div style="--delay: {{ $initial++ }}s" class="button-entrance"><a class="button button-hover icon-hover" style="{{ $button['custom_css'] }}" rel="noopener noreferrer nofollow" href="{{ $button['link'] }}" @if(theme('open_links_in_same_tab') != "true")target="_blank"@endif ><img alt="button-icon" class="icon hvr-icon" src="{{url('ico').'?'.$button['link']}}" loading="lazy">{{ $button['title'] }}</a></div>
<div style="--delay: {{ $initial++ }}s" class="button-entrance"><a class="button button-hover icon-hover" style="{{ $button['custom_css'] }}" rel="noopener noreferrer nofollow" href="{{ $button['link'] }}" @if(theme('open_links_in_same_tab') != "true")target="_blank"@endif ><img alt="button-icon" class="icon hvr-icon" src="@if(file_exists(base_path("studio/favicon/icons/").localIcon($button['id']))){{url('studio/favicon/icons/'.localIcon($button['id']))}}@else{{getFavIcon($button['id'])}}@endif">{{ $button['title'] }}</a></div>
@elseif($button['button'] === "space")
<?php
if (is_numeric($button['title']) and $button['title'] < 10)

View File

@ -151,6 +151,9 @@ return $path;}
<!-- End of parallax background animations -->
@endif
@include('components.favicon')
@include('components.favicon-extension')
<?php ////begin share button//// ?>
@if(config('advanced-config.display_share_button') != '')
@ -275,9 +278,9 @@ function get_operating_system() {
@elseif($link->name === "mastodon")
<div style="--delay: {{ $initial++ }}s" class="button-entrance"><a class="button button-{{ $link->name }} button button-hover icon-hover" rel="me noopener noreferrer nofollow" href="{{ route('clickNumber') . '/' . $link->id }}" @if(theme('open_links_in_same_tab') != "true")target="_blank"@endif ><img alt="button-icon" class="icon hvr-icon" src="@if(theme('use_custom_icons') == "true"){{ url('themes/' . $GLOBALS['themeName'] . '/extra/custom-icons')}}/{{$linkName}}{{theme('custom_icon_extension')}} @else{{ asset('\/littlelink/icons\/') . $linkName }}.svg @endif">{{ $link->title }}</a></div>
@elseif($link->name === "custom_website"and $link->custom_css === "" or $link->custom_css === "NULL" or (theme('allow_custom_buttons') == "false" and $link->name === "custom"))
<div style="--delay: {{ $initial++ }}s" class="button-entrance"><a class="button button-custom_website button button-hover icon-hover" rel="noopener noreferrer nofollow" href="{{ route('clickNumber') . '/' . $link->id }}" @if(theme('open_links_in_same_tab') != "true")target="_blank"@endif ><img alt="button-icon" class="icon hvr-icon" src="{{url('ico').'?'.$link->link}}" loading="lazy">{{ $link->title }}</a></div>
<div style="--delay: {{ $initial++ }}s" class="button-entrance"><a class="button button-custom_website button button-hover icon-hover" rel="noopener noreferrer nofollow" href="{{ route('clickNumber') . '/' . $link->id }}" @if(theme('open_links_in_same_tab') != "true")target="_blank"@endif ><img alt="button-icon" class="icon hvr-icon" src="@if(file_exists(base_path("studio/favicon/icons/").localIcon($link->id))){{url('studio/favicon/icons/'.localIcon($link->id))}}@else{{getFavIcon($link->id)}}@endif">{{ $link->title }}</a></div>
@elseif($link->name === "custom_website" and $link->custom_css != "")
<div style="--delay: {{ $initial++ }}s" class="button-entrance"><a class="button button-hover icon-hover" style="{{ $link->custom_css }}" rel="noopener noreferrer nofollow" href="{{ route('clickNumber') . '/' . $link->id }}" @if(theme('open_links_in_same_tab') != "true")target="_blank"@endif ><img alt="button-icon" class="icon hvr-icon" src="{{url('ico').'?'.$link->link}}" loading="lazy">{{ $link->title }}</a></div>
<div style="--delay: {{ $initial++ }}s" class="button-entrance"><a class="button button-hover icon-hover" style="{{ $link->custom_css }}" rel="noopener noreferrer nofollow" href="{{ route('clickNumber') . '/' . $link->id }}" @if(theme('open_links_in_same_tab') != "true")target="_blank"@endif ><img alt="button-icon" class="icon hvr-icon" src="@if(file_exists(base_path("studio/favicon/icons/").localIcon($link->id))){{url('studio/favicon/icons/'.localIcon($link->id))}}@else{{getFavIcon($link->id)}}@endif">{{ $link->title }}</a></div>
@elseif($link->name === "space")
<?php
if (is_numeric($link->title) and $link->title < 10)

View File

@ -1,6 +1,9 @@
@if(env('ENABLE_BUTTON_EDITOR') === true)
@extends('layouts.sidebar')
@include('components.favicon')
@include('components.favicon-extension')
@section('content')
@push('sidebar-scripts')
<?php function strp($urlStrp){return str_replace(array('http://', 'https://'), '', $urlStrp);} ?>
@ -216,7 +219,7 @@ var button_css = {
@if($buttonId == 1)
<center><div id="sample" style="--delay: 1s; border-radius:8px !important; max-width: 400px; width: 80%; class="button-entrance"><div class="button-demo button hvr-grow hvr-icon-wobble-vertical"><img class="icon hvr-icon" src="{{ asset('\/littlelink/icons\/') . 'custom' }}.svg">{{ $title }}</div></div></center>
@else
<center><div id="sample" style="--delay: 1s; border-radius:8px !important; max-width: 400px; width: 80%; class="button-entrance"><div class="button-demo button hvr-grow hvr-icon-wobble-vertical"><img class="wicon hvr-icon" src="{{url('ico').'?'.$link}}" loading="lazy">{{ $title }}</div></div></center>
<center><div id="sample" style="--delay: 1s; border-radius:8px !important; max-width: 400px; width: 80%; class="button-entrance"><div class="button-demo button hvr-grow hvr-icon-wobble-vertical"><img class="wicon hvr-icon" src="@if(file_exists(base_path("studio/favicon/icons/").localIcon($id))){{url('studio/favicon/icons/'.localIcon($id))}}@else{{getFavIcon($id)}}@endif">{{ $title }}</div></div></center>
@endif
</section>
@ -255,9 +258,9 @@ NULL
@if($custom_css === "" or $custom_css === "NULL" and $buttonId == 1)
<center><div style="--delay: 1s" class="button-entrance"><div class="button-demo button-custom button hvr-grow hvr-icon-wobble-vertical"><img class="icon hvr-icon fa {{$custom_icon}}">{{ $title }}</div></div></center>
@elseif($custom_css === "" or $custom_css === "NULL" and $buttonId == 2)
<center><div style="--delay: 1s" class="button-entrance"><div class="button-custom_website button hvr-grow hvr-icon-wobble-vertical"><img class="wicon hvr-icon" src="{{url('ico').'?'.$link}}" loading="lazy">{{ $title }}</div></div></center>
<center><div style="--delay: 1s" class="button-entrance"><div class="button-custom_website button hvr-grow hvr-icon-wobble-vertical"><img class="wicon hvr-icon" src="@if(file_exists(base_path("studio/favicon/icons/").localIcon($id))){{url('studio/favicon/icons/'.localIcon($id))}}@else{{getFavIcon($id)}}@endif">{{ $title }}</div></div></center>
@elseif($custom_css != "" and $buttonId == 2)
<center><div style="--delay: 1s" class="button-entrance"><div style="{{ $custom_css }}" class="button-custom_website button hvr-grow hvr-icon-wobble-vertical"><img class="wicon hvr-icon" src="{{url('ico').'?'.$link}}" loading="lazy">{{ $title }}</div></div></center>
<center><div style="--delay: 1s" class="button-entrance"><div style="{{ $custom_css }}" class="button-custom_website button hvr-grow hvr-icon-wobble-vertical"><img class="wicon hvr-icon" src="@if(file_exists(base_path("studio/favicon/icons/").localIcon($id))){{url('studio/favicon/icons/'.localIcon($id))}}@else{{getFavIcon($id)}}@endif">{{ $title }}</div></div></center>
@else
<center><div style="--delay: 1s" class="button-entrance"><div style="{{ $custom_css }}" class="button-demo hvr-grow hvr-icon-wobble-vertical"><i style="color: {{$custom_icon}}" class="icon hvr-icon fa {{$custom_icon}}"></i>{{ $title }}</div></div></center>
@endif

View File

@ -30,6 +30,9 @@
</style>
@endpush
@include('components.favicon')
@include('components.favicon-extension')
<?php function strp($urlStrp){return str_replace(array('http://', 'https://'), '', $urlStrp);} ?>
<div style="text-align: right;"><a href="{{ url('/studio/links') }}/10">10</a> | <a href="{{ url('/studio/links') }}/20">20</a> | <a href="{{ url('/studio/links') }}/30">30</a> | <a href="{{ url('/studio/links') }}/all">all</a></div>
@ -68,7 +71,7 @@
<span class='h6'>
<?php $button = Button::find($link->button_id); if(isset($button->name)){$buttonName = $button->name;}else{$buttonName = 0;} ?>
@if($button->name == "custom_website")
<span style="border: 1px solid #d0d4d7 !important;border-radius:5px;background-color:#6c757d;width:25px!important;height:25px!important;"><img style="margin-bottom:3px;margin-left:4px;margin-right:4px;max-width:15px;max-height:15px;" alt="button-icon" class="icon hvr-icon" src="{{url('ico').'?'.$link->link}}" loading="lazy"></span>
<span style="border: 1px solid #d0d4d7 !important;border-radius:5px;background-color:#6c757d;width:25px!important;height:25px!important;"><img style="margin-bottom:3px;margin-left:4px;margin-right:4px;max-width:15px;max-height:15px;" alt="button-icon" class="icon hvr-icon" src="@if(file_exists(base_path("studio/favicon/icons/").localIcon($link->id))){{url('studio/favicon/icons/'.localIcon($link->id))}}@else{{getFavIcon($link->id)}}@endif"></span>
@elseif($button->name == "space")
<span style="border: 1px solid #d0d4d7 !important;border-radius:5px;background-color:#6c757d;width:25px!important;height:25px!important;"><i style="margin-left:2.83px;margin-right:-1px;color:#fff;" class='bi bi-distribute-vertical'>&nbsp;</i></span>
@elseif($button->name == "heading")

View File

@ -82,9 +82,6 @@ Route::get('/@{littlelink}', [UserController::class, 'littlelink'])->name('littl
Route::get('/pages/{name}', [AdminController::class, 'pages'])->name('pages');
Route::get('/theme/@{littlelink}', [UserController::class, 'theme'])->name('theme');
//API
Route::get('/ico', function () {return view('components.favicon');});
//User route
Route::group([
'middleware' => env('REGISTER_AUTH'),