Skip to content

Commit b9a371b

Browse files
committed
Turned function findFile() into helper function
1 parent 09c9bec commit b9a371b

File tree

5 files changed

+18
-38
lines changed

5 files changed

+18
-38
lines changed

app/Functions/findfile.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
function findFile($name){
4+
$directory = base_path('/littlelink/images/');
5+
$files = scandir($directory);
6+
$pathinfo = "error.error";
7+
foreach($files as $file) {
8+
if (strpos($file, $name.'.') !== false) {
9+
$pathinfo = $name. "." . pathinfo($file, PATHINFO_EXTENSION);
10+
}}
11+
return $pathinfo;
12+
}

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"phpunit/phpunit": "^9.3.3"
3131
},
3232
"autoload": {
33+
"files": [
34+
"app/Functions/findfile.php"
35+
],
3336
"psr-4": {
3437
"App\\": "app/",
3538
"Database\\Factories\\": "database/factories/",

resources/views/layouts/lang.blade.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,6 @@
55
<html lang="en">
66
@endif
77

8-
@php
9-
function findFile($name){
10-
$directory = base_path('/littlelink/images/');
11-
$files = scandir($directory);
12-
$pathinfo = "error.error";
13-
foreach($files as $file) {
14-
if (strpos($file, $name.'.') !== false) {
15-
$pathinfo = $name. "." . pathinfo($file, PATHINFO_EXTENSION);
16-
}}
17-
return $pathinfo;
18-
}
19-
@endphp
20-
218
{{-- Redirects to https if enabled in the advanced-config --}}
229
@if(env('FORCE_ROUTE_HTTPS') == 'true')
2310
@php

resources/views/panel/edit-user.blade.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
@extends('layouts.sidebar')
22

3-
@php
4-
function findFiles($name){
5-
$directory = base_path('/littlelink/images/');
6-
$files = scandir($directory);
7-
$pathinfo = "error.error";
8-
foreach($files as $file) {
9-
if (strpos($file, $name.'.') !== false) {
10-
$pathinfo = $name. "." . pathinfo($file, PATHINFO_EXTENSION);}}
11-
return $pathinfo;}
12-
@endphp
13-
143
@section('content')
154

165
<section class="shadow text-gray-400">

resources/views/panel/site.blade.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,19 @@
33
@section('content')
44

55
<script src="{{ asset('resources/ckeditor/ckeditor.js') }}"></script>
6-
@php
7-
function findFileSite($name){
8-
$directory = base_path('/littlelink/images/');
9-
$files = scandir($directory);
10-
$pathinfo = "error.error";
11-
foreach($files as $file) {
12-
if (strpos($file, $name.'.') !== false) {
13-
$pathinfo = $name. "." . pathinfo($file, PATHINFO_EXTENSION);
14-
}}
15-
return $pathinfo;
16-
}
17-
@endphp
6+
187
<section class="shadow text-gray-400">
198
<h2 class="mb-4 card-header"><i class="bi bi-person"> Site</i></h2>
209
<div class="card-body p-0 p-md-3">
2110

2211
<form action="{{ route('editSite') }}" enctype="multipart/form-data" method="post">
2312
@csrf
2413
<div class="form-group col-lg-8">
25-
<label>Site logo</label>@if(file_exists(base_path("littlelink/images/").findFileSite('avatar')))<a title="Remove icon" class="hvr-grow p-1 text-danger" style="padding-left:5px;" href="{{ route('delAvatar') }}"><i class="bi bi-trash-fill"></i></a>@endif
14+
<label>Site logo</label>@if(file_exists(base_path("littlelink/images/").findFile('avatar')))<a title="Remove icon" class="hvr-grow p-1 text-danger" style="padding-left:5px;" href="{{ route('delAvatar') }}"><i class="bi bi-trash-fill"></i></a>@endif
2615
<input type="file" class="form-control-file" name="image">
2716
</div>
2817
<div class="form-group col-lg-8">
29-
<label>Favicon</label>@if(file_exists(base_path("littlelink/images/").findFileSite('favicon')))<a title="Remove icon" class="hvr-grow p-1 text-danger" style="padding-left:5px;" href="{{ route('delFavicon') }}"><i class="bi bi-trash-fill"></i></a>@endif
18+
<label>Favicon</label>@if(file_exists(base_path("littlelink/images/").findFile('favicon')))<a title="Remove icon" class="hvr-grow p-1 text-danger" style="padding-left:5px;" href="{{ route('delFavicon') }}"><i class="bi bi-trash-fill"></i></a>@endif
3019
<input type="file" class="form-control-file" name="icon">
3120
</div>
3221
<div class="form-group col-lg-8">

0 commit comments

Comments
 (0)