From: soufiane Date: Mon, 6 Nov 2023 14:12:18 +0000 (+0100) Subject: wip #5475 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=821728c1d0a3972b8b7c4fec9fed5758fe195f03;p=fluidbook-toolbox.git wip #5475 # Conflicts: # resources/views/fluidbook_stats/stats.blade.php --- diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php index 2878ec371..e2ee7fa76 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php @@ -5,6 +5,8 @@ namespace App\Http\Controllers\Admin\Operations\FluidbookPublication; 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; @@ -92,28 +94,35 @@ trait StatsOperation $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; @@ -125,8 +134,10 @@ trait StatsOperation ); 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'); @@ -195,4 +206,16 @@ trait StatsOperation $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; + } } diff --git a/resources/views/fluidbook_stats/stats.blade.php b/resources/views/fluidbook_stats/stats.blade.php index 3bd5b58d5..b23b4c511 100644 --- a/resources/views/fluidbook_stats/stats.blade.php +++ b/resources/views/fluidbook_stats/stats.blade.php @@ -128,10 +128,6 @@ {{ $period_title['singular'] }} @endforeach -
$start_date.','.$end_date, 'period_override'=>$period]) }}" method="POST"> - @csrf - -
@@ -224,7 +220,7 @@ @foreach($multimedia as $label=>$media) - + {{$label }} @include('fluidbook_stats.pagelink',['group'=>$media['pages'][0]??'']) @@ -267,7 +263,7 @@ {{-- Search Keywords --}} @if($searches->isNotEmpty())
-

{{ __('Mots recherchés') }}

+

{{ __('Mots recherchés') }}

@@ -301,9 +297,9 @@ - @foreach($countries as $key => $country) + @foreach($countries as $country) -
+ {{ $country['label'] }} {{ $country['label'] }}