]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6934 @7
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 May 2024 10:33:20 +0000 (12:33 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 May 2024 10:33:20 +0000 (12:33 +0200)
app/Fluidbook/Compiler/Secure.php
app/Fluidbook/Stats.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php
app/Models/Traits/PublicationSettings.php
resources/views/fields/fluidbook_composition.blade.php

index add45a2c58f9d9a0a02d064a4a1ca40c48256f7b..2c5968dd2fa22acd86aa3c5f97bb2dc71640caa3 100644 (file)
@@ -158,7 +158,6 @@ trait Secure
         $variables['FONT'] = $this->fluidbookSettings->secureClientSideFont;
         $variables['LINKS'] .= '<link rel="stylesheet" href="style/fonts/' . $this->fluidbookSettings->secureClientSideFont . '/font.css">';
 
-
         foreach ($variables as $variable => $value) {
             $secure = str_replace('$' . $variable, $value, $secure);
         }
index 344d43e63f51a30f50d51f1945a87bd0e2db8ee8..5709850a07c290949da8d45dd9b344fbb733a290 100644 (file)
@@ -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;
     }
index 6206115f922a3194ff5766f7dbefe869e8efbef6..de2498027458d013365669e57d3ad5a419433faf 100644 (file)
@@ -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;
     }
 }
index e51689cf8bbb5d0011d5fb0ea6abe3d23851c11d..c9e82c7b9380c3317e7fcaad346a9faffe2c4895 100644 (file)
@@ -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()
index 9092451340a46d18995d8fdd08f8f91e7da02f9d..ae014d52fe572229f61320ea6dd17cefa4074c5a 100644 (file)
             </li>
             @foreach($pdfArchives as $time)
                 <li><a href="{{backpack_url('fluidbook-publication/'.$entry->id.'/pdfarchive/'.$time)}}"
-                       download="fluidbook_{{$entry->id}}_{{$time}}.pdf">{{__('Version du :date',['date'=>date('Y-m-d H:i:s')])}}</a>
+                       download="fluidbook_{{$entry->id}}_{{$time}}.pdf">{{__('Version du :date',['date'=>date('Y-m-d H:i:s',$time)])}}</a>
                 </li>
             @endforeach
         </ul>