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;
+ }
}
$fluidbookBaseURL=$fluidbook->getPreviewURL();
@endphp
- <h2 class="mt-4">
+ <h2 data-title-excel="{{ __('Résumé') }}" class="mt-4">
{{ __('Statistiques') }}
</h2>
<form action="{{ route("generateexcel", compact('fluidbook_id', 'hash') + ['date'=>$start_date.','.$end_date, 'period_override'=>$period]) }}" method="POST">
{{-- Period (segmentation) override controls [ Day / Week / Month / Year ] --}}
<div class="chart-header mt-5">
- <h2>{!! $chart_heading !!}</h2>
+ <h2 data-title-excel="{{ __('Détails') }}">{!! $chart_heading !!}</h2>
<div class="btn-group m-t-10">
@foreach($period_map as $period_key => $period_title)
<a class="btn @if($period_key === $period)
</table>
{{-- Stats segregated by page number --}}
- <h3 class="mt-5">{{ __('Détails par page') }} <small>({!! $formatted_date_range !!})</small></h3>
+ <h3 data-title-excel="{{ __('Page') }}" class="mt-5">{{ __('Détails par page') }} <small>({!! $formatted_date_range !!})</small></h3>
<table class="{!! $tableClasses !!}">
<thead>
];
@endphp
- <h3 class="mt-5">{{ __('Contenus multimédia') }}</h3>
+ <h3 data-title-excel="{{ __('Multimédia') }}" class="mt-5">{{ __('Contenus multimédia') }}</h3>
<table class="{!! $tableClasses !!}">
<thead>
{{-- Outgoing Links --}}
@if($outlinks->isNotEmpty())
<div>
- <h3>{{ __('Liens sortants') }}</h3>
+ <h3 data-title-excel="{{ __('Liens') }}">{{ __('Liens sortants') }}</h3>
<table class="{!! $tableClasses !!}">
<thead>
{{-- Search Keywords --}}
@if($searches->isNotEmpty())
<div>
- <h3>{{ __('Mots recherchés') }}</h3>
+ <h3 data-title-excel="{{ __('Mots') }}">{{ __('Mots recherchés') }}</h3>
<table class="{!! $tableClasses !!}">
<thead>
{{-- Visitor Countries --}}
@if($countries->isNotEmpty())
<div>
- <h3>{{ __('Origine des visiteurs') }}</h3>
+ <h3 data-title-excel="{{ __('Origine') }}">{{ __('Origine des visiteurs') }}</h3>
<table class="{!! $tableClasses !!}">
<thead>