use App\Fluidbook\Stats;
use App\Http\Middleware\CheckIfAdmin;
use App\Models\FluidbookPublication;
+use App\Models\FluidbookTranslate;
+use App\Models\ToolboxTranslate;
use Carbon\Carbon;
use Carbon\CarbonInterface;
use Cubist\Matomo\Reporting;
$name = "excel";
$safename = Str::slug($name);
- $html = HtmlDomParser::file_get_html($url);
- foreach ($html->find('html') as $e) {
- $e->lang = "fr";
- }
+
+ $locale = backpack_user()->locale;
+ $acceptLang = [
+ "fr" => "fr-FR,fr;q=0.9",
+ "en" => "en-US,en;q=0.5"
+ ];
+
+ $html = $this->translateHtml($url,$acceptLang[$locale]);
+ $html = HtmlDomParser::str_get_html($html);
+
+ $names = [...$html->find('h2'), ...$html->find('h3')];
$tables = $html->find('table');
$tmpfile = Files::tempnam() . '.xlsx';
- $this->Excel_($tables, $name, null, $tmpfile);
+ $this->Excel_($tables, $names, null, $tmpfile);
return response()->download($tmpfile, $safename . '.xlsx')->deleteFileAfterSend(true);
die();
}
/**
* @param $tables array
- * @param $sheetname string
+ * @param $sheetnames array
* @param $head array|null
* @param $output string|null
* @param $width int|null
* @return Spreadsheet
* @throws \PhpOffice\PhpSpreadsheet\Exception
*/
- public function Excel_($tables, $sheetname, $head = null, $output = null, $width = null)
+ public function Excel_($tables, $sheetnames, $head = null, $output = null, $width = null)
{
$columns = 0;
);
foreach ($tables as $key => $table) {
- $sheet = $excel->createSheet();
- $sheet->setTitle($sheetname.'-'.$key);
+ $sheet = $key === 0 ? $excel->getActiveSheet() : $excel->createSheet();
+ $sheetname = strip_tags($sheetnames[$key]->getAttribute('data-title-excel'));
+ $sheetname = \Illuminate\Support\Str::limit($sheetname, 28, '...');
+ $sheet->setTitle($sheetname);
$tr = $table->find('tr');
$theads = $table->find('th');
$writer->save($output);
}
+ protected function translateHtml($url,$lang) {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL,$url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ $headers = [
+ 'Accept-Language: '.$lang,
+ ];
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+ $html = curl_exec ($ch);
+ curl_close ($ch);
+ return $html;
+ }
}
{{ $period_title['singular'] }}
</a>
@endforeach
- <form action="{{ route("generateexcel", compact('fluidbook_id', 'hash') + ['date'=>$start_date.','.$end_date, 'period_override'=>$period]) }}" method="POST">
- @csrf
- <button class="btn btn-primary ml-3" type="submit">{{ __('Exporter au format Excel') }}</button>
- </form>
</div>
</div>
{{-- Search Keywords --}}
@if($searches->isNotEmpty())
<div>
- <h3 data-title-excel="{{ __('Recherches') }}">{{ __('Mots recherchés') }}</h3>
+ <h3 data-title-excel="{{ __('Mots') }}">{{ __('Mots recherchés') }}</h3>
<table class="{!! $tableClasses !!}">
<thead>
</tr>
</thead>
<tbody>
- @foreach($countries as $key => $country)
+ @foreach($countries as $country)
<tr>
- <td data-flag="{{ $key }}" class="whitespace-nowrap" data-sort-value="{{ $country['label'] }}">
+ <td class="whitespace-nowrap" data-sort-value="{{ $country['label'] }}">
<img src="{{ $country['flag'] }}" alt="{{ $country['label'] }}"
style="width: 1.5em; margin-right: 0.75em;">
{{ $country['label'] }}