Skip to content

Commit 40964d9

Browse files
Merge pull request #239 from JulianPrieber/dev
Caching favicons locally
2 parents 5cc9c17 + f6d1015 commit 40964d9

File tree

12 files changed

+62
-26
lines changed

12 files changed

+62
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/studio/favicon/icons
12
/node_modules
23
/public/hot
34
/public/storage

app/Http/Controllers/UserController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,16 @@ public function deleteLink(request $request)
390390

391391
Link::where('id', $linkId)->delete();
392392

393-
return back()->with('success', 'Link Deleted');
393+
$directory = base_path("studio/favicon/icons");
394+
$files = scandir($directory);
395+
foreach($files as $file) {
396+
if (strpos($file, $linkId.".") !== false) {
397+
$pathinfo = pathinfo($file, PATHINFO_EXTENSION);}}
398+
if (isset($pathinfo)) {
399+
try{File::delete(base_path("studio/favicon/icons")."/".$linkId.".".$pathinfo);} catch (exception $e) {}
400+
}
401+
402+
return redirect('/studio/links');
394403
}
395404

396405
//Raise link on the littlelink page
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
function localIcon($id) {
4+
$directory = base_path("studio/favicon/icons");
5+
$files = scandir($directory);
6+
$pathinfo = "error.error";
7+
foreach($files as $file) {
8+
if (strpos($file, $id.'.') !== false) {
9+
$pathinfo = $id. "." . pathinfo($file, PATHINFO_EXTENSION);
10+
}}
11+
return $pathinfo;
12+
}
13+
14+
?>

resources/views/components/favicon.blade.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,7 +2356,9 @@ function loadFile()
23562356

23572357

23582358
<?php
2359-
function getFavIcon($url) {
2359+
function getFavIcon($id) {
2360+
$link = Link::find($id);
2361+
$url = $link->link;
23602362
try {
23612363
$urlICO = $url . "/favicon.ico";
23622364
$urlICO = str_replace("//favicon.ico","/favicon.ico",$urlICO);
@@ -2430,21 +2432,17 @@ function get_headers($url,$format=0)
24302432
24312433
}
24322434
} catch (exception $e) {$favicon = url('littlelink/icons/website.svg');}
2433-
return $favicon;
2434-
}
24352435
2436-
?>
24372436
2438-
2439-
<?php
2440-
if($_SERVER['QUERY_STRING'] !== ''){
24412437
try{
2442-
$link = Link::find($_SERVER['QUERY_STRING']);
2443-
$link = $link->link;
2444-
header("HTTP/1.1 302 Found");
2445-
$header = getFavIcon($link);
2446-
header("Location: $header");
2447-
exit();
2438+
$header = $favicon;
2439+
$extension = pathinfo($header, PATHINFO_EXTENSION);
2440+
if(!file_exists(base_path("studio/favicon/icons")."/".$id.".".$extension)){
2441+
if($id.".".$extension !== ".".$id){file_put_contents(base_path("studio/favicon/icons")."/".$id.".".$extension, file_get_contents($header));}
2442+
}
24482443
} catch (exception $e) {exit();}
2444+
2445+
return $favicon;
24492446
}
2447+
24502448
?>

resources/views/components/pageitems/link-display.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
44
@endphp
55

6+
@include('components.favicon')
7+
@include('components.favicon-extension')
8+
69
<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>
710
@if($params->GetSiteIcon ?? true)
8-
<img alt="button-icon" class="icon hvr-icon" src="{{asset('studio/favicon/favicon.gif')}}" onload="this.src='{{url('ico').'?'.$link->id}}'" loading="lazy">
11+
<img alt="button-icon" class="icon hvr-icon" src="{{getFavIcon($link->id)}}">
912
@endif
1013

1114
{{ $link->title }}

resources/views/home.blade.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ function themeAsset($path){
128128
}
129129
</style>
130130

131+
@include('components.favicon')
132+
@include('components.favicon-extension')
133+
131134
</head>
132135
<body>
133136

@@ -213,9 +216,9 @@ function themeAsset($path){
213216
@elseif($button['button'] === "buy me a coffee")
214217
<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>
215218
@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"))
216-
<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="{{asset('studio/favicon/favicon.gif')}}" onload="this.src='{{url('ico').'?'.$button['id']}}'" loading="lazy">{{ $button['title'] }}</a></div>
219+
<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>
217220
@elseif($button['button'] === "custom_website" and $button['custom_css'] != "")
218-
<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="{{asset('studio/favicon/favicon.gif')}}" onload="this.src='{{url('ico').'?'.$button['id']}}'" loading="lazy">{{ $button['title'] }}</a></div>
221+
<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>
219222
@elseif($button['button'] === "space")
220223
<?php
221224
if (is_numeric($button['title']) and $button['title'] < 10)

resources/views/littlelink.blade.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ function themeAsset($path){
151151
<!-- End of parallax background animations -->
152152
@endif
153153

154+
@include('components.favicon')
155+
@include('components.favicon-extension')
156+
154157
<?php ////begin share button//// ?>
155158

156159
@if(config('advanced-config.display_share_button') != '')
@@ -275,9 +278,9 @@ function get_operating_system() {
275278
@elseif($link->name === "mastodon")
276279
<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>
277280
@elseif($link->name === "custom_website"and $link->custom_css === "" or $link->custom_css === "NULL" or (theme('allow_custom_buttons') == "false" and $link->name === "custom"))
278-
<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="{{asset('studio/favicon/favicon.gif')}}" onload="this.src='{{url('ico').'?'.$link->id}}'" loading="lazy">{{ $link->title }}</a></div>
281+
<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>
279282
@elseif($link->name === "custom_website" and $link->custom_css != "")
280-
<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="{{asset('studio/favicon/favicon.gif')}}" onload="this.src='{{url('ico').'?'.$link->id}}'" loading="lazy">{{ $link->title }}</a></div>
283+
<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>
281284
@elseif($link->name === "space")
282285
<?php
283286
if (is_numeric($link->title) and $link->title < 10)

resources/views/studio/button-editor.blade.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
@if(env('ENABLE_BUTTON_EDITOR') === true)
22
@extends('layouts.sidebar')
33

4+
@include('components.favicon')
5+
@include('components.favicon-extension')
6+
47
@section('content')
58
@push('sidebar-scripts')
69
<?php function strp($urlStrp){return str_replace(array('http://', 'https://'), '', $urlStrp);} ?>
@@ -216,7 +219,7 @@
216219
@if($buttonId == 1)
217220
<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>
218221
@else
219-
<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="{{asset('studio/favicon/favicon.gif')}}" onload="this.src='{{url('ico').'?'.$id}}'" loading="lazy">{{ $title }}</div></div></center>
222+
<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>
220223
@endif
221224

222225
</section>
@@ -255,9 +258,9 @@
255258
@if($custom_css === "" or $custom_css === "NULL" and $buttonId == 1)
256259
<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>
257260
@elseif($custom_css === "" or $custom_css === "NULL" and $buttonId == 2)
258-
<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="{{asset('studio/favicon/favicon.gif')}}" onload="this.src='{{url('ico').'?'.$id}}'" loading="lazy">{{ $title }}</div></div></center>
261+
<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>
259262
@elseif($custom_css != "" and $buttonId == 2)
260-
<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="{{asset('studio/favicon/favicon.gif')}}" onload="this.src='{{url('ico').'?'.$id}}'" loading="lazy">{{ $title }}</div></div></center>
263+
<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>
261264
@else
262265
<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>
263266
@endif

resources/views/studio/links.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
</style>
3131
@endpush
3232

33+
@include('components.favicon')
34+
@include('components.favicon-extension')
35+
3336
<?php function strp($urlStrp){return str_replace(array('http://', 'https://'), '', $urlStrp);} ?>
3437

3538
<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 @@
6871
<span class='h6'>
6972
<?php $button = Button::find($link->button_id); if(isset($button->name)){$buttonName = $button->name;}else{$buttonName = 0;} ?>
7073
@if($button->name == "custom_website")
71-
<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="{{asset('studio/favicon/favicon.gif')}}" onload="this.src='{{url('ico').'?'.$link->id}}'" loading="lazy"></span>
74+
<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>
7275
@elseif($button->name == "space")
7376
<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>
7477
@elseif($button->name == "heading")

routes/web.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@
8282
Route::get('/pages/{name}', [AdminController::class, 'pages'])->name('pages');
8383
Route::get('/theme/@{littlelink}', [UserController::class, 'theme'])->name('theme');
8484

85-
//API
86-
Route::get('/ico', function () {return view('components.favicon');});
87-
8885
//User route
8986
Route::group([
9087
'middleware' => env('REGISTER_AUTH'),

0 commit comments

Comments
 (0)