Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions resources/views/elfinder.blade.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
@extends(backpack_view('blank'))

@section('after_scripts')

@include('backpack.filemanager::common_scripts')
@include('backpack.filemanager::common_styles')

<!-- elFinder initialization (REQUIRED) -->
<script type="text/javascript" charset="utf-8">
// Documentation for client options:
// https://github.com/Studio-42/elFinder/wiki/Client-configuration-options
$(document).ready(function() {
$('#elfinder').elfinder({
// set your elFinder options here
@if($locale)
lang: '{{ $locale }}', // locale
@include('backpack.filemanager::localization')

@include('backpack.filemanager::common_scripts', ['locale' => in_array($locale, array_keys($elfinderConfiguredLanguages)) ? $locale : null])
@include('backpack.filemanager::common_styles')

<!-- elFinder initialization (REQUIRED) -->
<script type="text/javascript" charset="utf-8">
// Documentation for client options:
// https://github.com/Studio-42/elFinder/wiki/Client-configuration-options
$(document).ready(function() {
$('#elfinder').elfinder({
// set your elFinder options here
commandsOptions: {
preference: {
langs: @json($elfinderConfiguredLanguages)
}
},
@if($locale)
lang: '{{ $locale }}', // locale
@if($locale !== 'en')
i18nBaseUrl: '{{ \Illuminate\Support\Str::beforeLast(Basset::getUrl("bp-elfinder-i18n-".$locale), "elfinder.") }}/',
@endif
customData: {
_token: '{{ csrf_token() }}'
},
url : '{{ route("elfinder.connector") }}', // connector URL
soundPath: '{{ Basset::getUrl(base_path("vendor/studio-42/elfinder/sounds")) }}',
cssAutoLoad : false,
});
@endif
customData: {
_token: '{{ csrf_token() }}'
},
url : '{{ route("elfinder.connector") }}', // connector URL
soundPath: '{{ Basset::getUrl(base_path("vendor/studio-42/elfinder/sounds")) }}',
cssAutoLoad: false,
});
</script>
});
</script>
@endsection

@php
Expand All @@ -46,8 +55,6 @@
@endsection

@section('content')

<!-- Element where elFinder will be created (REQUIRED) -->
<div id="elfinder"></div>

@endsection
25 changes: 25 additions & 0 deletions resources/views/localization.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@php
$elfinderLanguages = [
'ar', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es', 'fa', 'fo', 'fr', 'fr_CA', 'he', 'hr', 'hu', 'id', 'it', 'ja', 'ko', 'nl', 'no', 'pl', 'pt_BR', 'ro', 'ru', 'si', 'sk', 'sl', 'sr', 'sv', 'tr', 'ug_CN', 'uk', 'vi', 'zh_CN', 'zh_TW',
];
$locales = config('backpack.crud.locales', []);
$elfinderConfiguredLanguages = [];
foreach ($locales as $code => $name) {
if (in_array($code, $elfinderLanguages)) {
$elfinderConfiguredLanguages[$code] = $name;
}
}
// Add English if not present, as it's the fallback
if (!array_key_exists('en', $elfinderConfiguredLanguages)) {
$elfinderConfiguredLanguages['en'] = 'English';
}

// Pre-load other configured languages so they are available when switching in UI
foreach ($elfinderConfiguredLanguages as $lang => $name) {
if ($lang !== 'en' && $lang !== $locale) {
try {
\Backpack\Basset\Facades\Basset::basset('bp-elfinder-i18n-'.$lang, false);
} catch (\Throwable $e) {}
}
}
@endphp
10 changes: 8 additions & 2 deletions resources/views/standalonepopup.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>

@include('backpack.filemanager::common_scripts')
@include('backpack.filemanager::localization')
@include('backpack.filemanager::common_scripts', ['locale' => in_array($locale, array_keys($elfinderConfiguredLanguages)) ? $locale : null])
@include('backpack.filemanager::common_styles', ['styleBodyElement' => true])
<style type="text/css">
.elfinder-workzone {
Expand All @@ -25,6 +25,9 @@
// set your elFinder options here
@if($locale)
lang: '{{ $locale }}', // locale
@if($locale !== 'en')
i18nBaseUrl: '{{ \Illuminate\Support\Str::beforeLast(Basset::getUrl("bp-elfinder-i18n-".$locale), ".elfinder") }}/',
@endif
@endif
customData: {
_token: '{{ csrf_token() }}'
Expand All @@ -37,6 +40,9 @@
getfile: {
multiple: {{ request('multiple') ? 'true' : 'false' }},
oncomplete: 'destroy'
},
preference: {
langs: @json($elfinderConfiguredLanguages)
}
},
getFileCallback: (file) => {
Expand Down
14 changes: 14 additions & 0 deletions src/BackpackElfinderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Backpack\FileManager;

use Backpack\Basset\Facades\Basset;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Log;

Expand Down Expand Up @@ -41,4 +42,17 @@ public function showIndex()
->make('backpack.filemanager::elfinder')
->with($this->getViewVars());
}

protected function getViewVars()
{
$locale = str_replace('-', '_', $this->app->config->get('app.locale'));

if (! array_key_exists('bp-elfinder-i18n-'.$locale, Basset::getNamedAssets())) {
$locale = false;
}

$csrf = true;

return compact('locale', 'csrf');
}
}
2 changes: 1 addition & 1 deletion src/FileManagerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function boot()
// Fallback to package views
$this->loadViewsFrom(__DIR__.'/../resources/views', 'backpack.filemanager');

$crudLanguages = array_keys(config('backpack.crud.languages', []));
$crudLanguages = array_keys(config('backpack.crud.locales', []));
foreach ($crudLanguages as $language) {
if ($language === 'en') {
continue;
Expand Down