From: Vincent Vanwaelscappel Date: Thu, 23 May 2024 10:33:20 +0000 (+0200) Subject: wip #6934 @7 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=bb35bca795a0ea8980074927e66f2f5c31fae04b;p=fluidbook-toolbox.git wip #6934 @7 --- diff --git a/app/Fluidbook/Compiler/Secure.php b/app/Fluidbook/Compiler/Secure.php index add45a2c5..2c5968dd2 100644 --- a/app/Fluidbook/Compiler/Secure.php +++ b/app/Fluidbook/Compiler/Secure.php @@ -158,7 +158,6 @@ trait Secure $variables['FONT'] = $this->fluidbookSettings->secureClientSideFont; $variables['LINKS'] .= ''; - foreach ($variables as $variable => $value) { $secure = str_replace('$' . $variable, $value, $secure); } diff --git a/app/Fluidbook/Stats.php b/app/Fluidbook/Stats.php index 344d43e63..5709850a0 100644 --- a/app/Fluidbook/Stats.php +++ b/app/Fluidbook/Stats.php @@ -85,7 +85,7 @@ class Stats extends Reporting public function getToken(): string { - return $this->getMatomoToken(static::getMatomoServer($this->fluidbook->id, $this->fluidbook->region)); + return static::getMatomoToken(static::getMatomoServer($this->fluidbook->id, $this->fluidbook->region)); } @@ -135,7 +135,7 @@ class Stats extends Reporting return 'stats5.fluidbook.com'; } - protected function getMatomoToken($server): bool|string + public static function getMatomoToken($server): bool|string { return self::TOKENS[$server] ?? false; } diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php index 6206115f9..de2498027 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php @@ -44,6 +44,20 @@ trait StatsOperation // Route to export datas to Excel Route::post($segment . '/stats/{fluidbook_id}_{hash}/{date?}/{period_override?}/generate', $controller . '@generateExcel') ->name('generateexcel'); + + Route::get('s/prxtm', $controller . '@matomoProxy')->withoutMiddleware([CheckIfAdmin::class]); + } + + protected function matomoProxy() + { + $u = base64_decode(request()->get('d')); + $c = parse_url($u); + $token = Stats::getMatomoToken($c['host']); + if ($token) { + $u .= '&token_auth=' . rawurlencode($token) . '&cip=' . rawurlencode($_SERVER['HTTP_X_REAL_IP']); + } + file_get_contents(html_entity_decode($u)); + return response('',204); } protected function setupStatsDefaults() @@ -89,11 +103,12 @@ trait StatsOperation * @throws ContainerExceptionInterface * @throws Exception */ - public function generateExcel($fluidbook_id, $hash, $date = null, $period_override = null) { + public function generateExcel($fluidbook_id, $hash, $date = null, $period_override = null) + { $url = route('stats', compact('fluidbook_id', 'hash', 'date', 'period_override')); - $dateForFilename = str_replace('-','',str_replace(',','_', $date)); - $name = "stats_".$fluidbook_id."_".$dateForFilename; + $dateForFilename = str_replace('-', '', str_replace(',', '_', $date)); + $name = "stats_" . $fluidbook_id . "_" . $dateForFilename; $locale = backpack_user()->locale; $acceptLang = [ @@ -101,7 +116,7 @@ trait StatsOperation "en" => "en-US,en;q=0.5" ]; - $html = $this->translateHtml($url,$acceptLang[$locale]); + $html = $this->translateHtml($url, $acceptLang[$locale]); $html = HtmlDomParser::str_get_html($html); $names = [...$html->find('h2'), ...$html->find('h3')]; @@ -143,7 +158,7 @@ trait StatsOperation $head = []; $datas = []; - if($theads) { + if ($theads) { foreach ($theads as $thead) { $head[] = $thead->text; } @@ -152,9 +167,9 @@ trait StatsOperation foreach ($tr as $k => $lines) { foreach ($lines->find('td') as $td) { $text = $td->text; - if($td->getAttribute('data-flag')) { + if ($td->getAttribute('data-flag')) { $text = $td->getAttribute('data-flag'); - } elseif($td->getAttribute('sorttable_customkey')) { + } elseif ($td->getAttribute('sorttable_customkey')) { $text = $td->getAttribute('sorttable_customkey'); } @@ -213,16 +228,17 @@ trait StatsOperation $writer->save($output); } - protected function translateHtml($url,$lang) { + protected function translateHtml($url, $lang) + { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL,$url); + curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $headers = [ - 'Accept-Language: '.$lang, + 'Accept-Language: ' . $lang, ]; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - $html = curl_exec ($ch); - curl_close ($ch); + $html = curl_exec($ch); + curl_close($ch); return $html; } } diff --git a/app/Models/Traits/PublicationSettings.php b/app/Models/Traits/PublicationSettings.php index e51689cf8..c9e82c7b9 100644 --- a/app/Models/Traits/PublicationSettings.php +++ b/app/Models/Traits/PublicationSettings.php @@ -2180,6 +2180,9 @@ trait PublicationSettings $this->addSettingField('matomoSiteId', Integer::class, $this->__('Site ID'), ['when' => ['matomoServer' => '_not_empty_']]); $this->addSettingField('', FormSeparator::class); $this->addSettingField('matomoTagManager', Text::class, 'Matomo Tag Manager', ['prefix' => 'https://']); + $this->addSettingField('', FormSeparator::class); + $this->addSettingField('matomoTracking', SelectFromArray::class, $this->__('Type de tracker'), + ['default' => 'js', 'options' => ['js' => __('Tracker JS') . ' (' . __('recommandé') . ')', 'pixel' => __('Pixel'), 'proxy' => __('Proxy')]]); } protected function _statsGoogleAnalytics() diff --git a/resources/views/fields/fluidbook_composition.blade.php b/resources/views/fields/fluidbook_composition.blade.php index 909245134..ae014d52f 100644 --- a/resources/views/fields/fluidbook_composition.blade.php +++ b/resources/views/fields/fluidbook_composition.blade.php @@ -888,7 +888,7 @@ @foreach($pdfArchives as $time)
  • {{__('Version du :date',['date'=>date('Y-m-d H:i:s')])}} + download="fluidbook_{{$entry->id}}_{{$time}}.pdf">{{__('Version du :date',['date'=>date('Y-m-d H:i:s',$time)])}}
  • @endforeach