From 66c5195ca172877c1003588d749874f762276604 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 17 May 2023 10:57:54 +0200 Subject: [PATCH] wip #5933 @1 --- app/Fluidbook/Compiler/Compiler.php | 61 +---- app/Fluidbook/Compiler/Stats.php | 83 ++++++ app/Models/Traits/PublicationSettings.php | 294 ++++++++++++---------- 3 files changed, 244 insertions(+), 194 deletions(-) create mode 100644 app/Fluidbook/Compiler/Stats.php diff --git a/app/Fluidbook/Compiler/Compiler.php b/app/Fluidbook/Compiler/Compiler.php index 760818baf..1c2cb8a13 100644 --- a/app/Fluidbook/Compiler/Compiler.php +++ b/app/Fluidbook/Compiler/Compiler.php @@ -270,6 +270,7 @@ class Compiler extends Base implements CompilerInterface use \App\Fluidbook\Compiler\Links; use Cart; + use Stats; /** * @param FluidbookPublication $book @@ -739,67 +740,7 @@ class Compiler extends Base implements CompilerInterface } } - protected function writeStats() - { - if ($this->fluidbookSettings->stats) { - $this->config->statsMatomo = $this->book_id; - $this->config->statsMatomoServer = 3; - if ($this->book_id >= 21210) { - $this->config->statsMatomoServer = 4 + ($this->book_id % 2); - } - } else { - $this->config->statsMatomo = false; - } - - if ($this->fluidbookSettings->tagcommander_id) { - $id = $this->fluidbookSettings->tagcommander_id; - if (!$this->fluidbookSettings->tagcommander_prod) { - $id .= '/uat'; - } - - $default = ['page_name' => '']; - $this->config->tagcommander_default_vars = array_merge($default, $this->parseVariables($this->fluidbookSettings->tagcommander_default_vars)); - $this->config->tagcommander_default_vars['env_work'] = $this->fluidbookSettings->tagcommander_prod ? 'prod' : 'pre-prod'; - - $scriptNames = explode(',', $this->config->tagcommander_scriptname); - $this->fluidbookSettings->googleAnalyticsCustom .= ''; - for ($i = 1; $i < count($scriptNames); $i++) { - $this->fluidbookSettings->statsCustom .= ''; - } - - if ($this->fluidbookSettings->tagcommander_plan) { - $planPath = $this->_wdirOrAbsolute($this->fluidbookSettings->tagcommander_plan); - $plan = ExcelToArray::excelToArrayKeyVars($planPath); - $fixedplan = []; - foreach ($plan as $k => $v) { - $e = explode('#', $k); - if (count($e) === 2) { - $k = $e[1]; - } - - $fixedplan[$this->_labelToPage($k)] = $v; - } - $this->config->tagcommander_plan = $fixedplan; - } - } - if (isset($this->fluidbookSettings->googleTagManager) && $this->fluidbookSettings->googleTagManager) { - $this->fluidbookSettings->googleAnalyticsCustom .= " - - -"; - $this->fluidbookSettings->statsCustom = ' - -'; - - - } - } protected function _wdirOrAbsolute($path) diff --git a/app/Fluidbook/Compiler/Stats.php b/app/Fluidbook/Compiler/Stats.php new file mode 100644 index 000000000..ad83a16ab --- /dev/null +++ b/app/Fluidbook/Compiler/Stats.php @@ -0,0 +1,83 @@ +fluidbookSettings->stats) { + $this->config->statsMatomo = $this->book_id; + $this->config->statsMatomoServer = 3; + if ($this->book_id >= 21210) { + $this->config->statsMatomoServer = 4 + ($this->book_id % 2); + } + if ($this->getFluidbook()->region == 'US') { + $this->config->statsMatomoServer = 6; + $this->config->stats = false; + } + } else { + $this->config->statsMatomo = false; + } + + if ($this->fluidbookSettings->tagcommander_id) { + $id = $this->fluidbookSettings->tagcommander_id; + if (!$this->fluidbookSettings->tagcommander_prod) { + $id .= '/uat'; + } + + $default = ['page_name' => '']; + $this->config->tagcommander_default_vars = array_merge($default, $this->parseVariables($this->fluidbookSettings->tagcommander_default_vars)); + $this->config->tagcommander_default_vars['env_work'] = $this->fluidbookSettings->tagcommander_prod ? 'prod' : 'pre-prod'; + + $scriptNames = explode(',', $this->config->tagcommander_scriptname); + $this->fluidbookSettings->googleAnalyticsCustom .= ''; + for ($i = 1; $i < count($scriptNames); $i++) { + $this->fluidbookSettings->statsCustom .= ''; + } + + if ($this->fluidbookSettings->tagcommander_plan) { + $this->config->tagcommander_plan = $this->_parsePlan($this->fluidbookSettings->tagcommander_plan); + } + } + if (isset($this->fluidbookSettings->googleTagManager) && $this->fluidbookSettings->googleTagManager) { + $this->fluidbookSettings->googleAnalyticsCustom .= " + + +"; + $this->fluidbookSettings->statsCustom = ' + +'; + } + if ($this->fluidbookSettings->xiti) { + $this->fluidbookSettings->googleAnalyticsCustom .= $this->fluidbookSettings->xiti; + if ($this->fluidbookSettings->piano_plan) { + $this->config->piano_plan = $this->_parsePlan($this->fluidbookSettings->piano_plan); + } + } + } + + protected function _parsePlan($filename) + { + $planPath = $this->_wdirOrAbsolute($filename); + + $plan = ExcelToArray::excelToArrayKeyVars($planPath); + $fixedplan = []; + foreach ($plan as $k => $v) { + $e = explode('#', $k); + if (count($e) === 2) { + $k = $e[1]; + } + + $fixedplan[$this->_labelToPage($k)] = $v; + } + return $fixedplan; + } +} diff --git a/app/Models/Traits/PublicationSettings.php b/app/Models/Traits/PublicationSettings.php index 126b06737..57e2c4272 100644 --- a/app/Models/Traits/PublicationSettings.php +++ b/app/Models/Traits/PublicationSettings.php @@ -7,8 +7,10 @@ use App\Fields\FluidbookSignature; use App\Fields\SCORMVersion; use App\Models\FluidbookExternalInstallServer; use Cubist\Backpack\Magic\Fields\Checkbox; +use Cubist\Backpack\Magic\Fields\Code; use Cubist\Backpack\Magic\Fields\ExternalPath; use Cubist\Backpack\Magic\Fields\FilesOrURL; +use Cubist\Backpack\Magic\Fields\FormBigSection; use Cubist\Backpack\Magic\Fields\FormSection; use Cubist\Backpack\Magic\Fields\FormSeparator; use Cubist\Backpack\Magic\Fields\FormSuperSection; @@ -110,28 +112,6 @@ trait PublicationSettings 'store_in' => 'settings', 'translatable' => false, ]); - $this->addField('section_basicStats', FormSection::class, $this->__('Statistiques')); - $this->addField('stats', Checkbox::class, $this->__('Activer les statistiques Fluidbook'), [ - 'v2' => '{"type":"boolean","default":true,"editable":true,"label":"\\u00a7!\\u00a7Activer les statistiques Fluidbook!\\u00a7!","grade":3}', - 'default' => true, - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('googleAnalytics', LongText::class, $this->__('Code Google Analytics'), [ - 'v2' => '{"type":"text","default":"","editable":true,"label":"\\u00a7!\\u00a7Code Google Analytics!\\u00a7!","size":10}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('googleTagManager', LongText::class, $this->__('Code Google Tag Manager'), [ - 'v2' => '{"type":"text","default":"","editable":true,"label":"\\u00a7!\\u00a7Code Google Tag Manager!\\u00a7!","size":10}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); $this->addField('section_share', FormSection::class, $this->__('Fonctions de partage')); $this->addField('share', Checkbox::class, $this->__('Activer les fonctions de partage'), [ 'v2' => '{"type":"boolean","default":true,"editable":true,"label":"\\u00a7!\\u00a7Activer les fonctions de partage!\\u00a7!"}', @@ -1427,118 +1407,6 @@ trait PublicationSettings 'store_in' => 'settings', 'translatable' => false, ]); - $this->addField('section_stats', FormSection::class, $this->__('Statistiques avancées')); - $this->addField('tagcommander_id', LongText::class, 'Tag commander ID', [ - 'v2' => '{"type":"text","default":"","editable":true,"label":"Tag commander ID","grade":3}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('tagcommander_scriptname', LongText::class, 'Nom du script Tagcommander', [ - 'v2' => '{"type":"text","default":"tc_Multisite_Head.js,tc_Multisite_Analytics.js,tc_Multisite_Medias.js","editable":true,"label":"Nom du script Tagcommander","grade":3}', - 'default' => 'tc_Multisite_Head.js,tc_Multisite_Analytics.js,tc_Multisite_Medias.js', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('tagcommander_prod', Checkbox::class, 'Production', [ - 'v2' => '{"type":"boolean","default":true,"editable":true,"label":"Production","grade":3}', - 'default' => true, - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('tagcommander_plan', FilesOrURL::class, 'Plan de taggage "Tag commander"', [ - 'v2' => '{"type":"freefile","default":"","editable":true,"label":"Plan de taggage \\"Tag commander\\"","grade":3}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('tagcommander_event_page', Textarea::class, __('Nom de l\'évenement de vue de page'), [ - 'v2' => '{"type":"text","default":"page","editable":true,"grade":3}', - 'default' => 'page', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('tagcommander_default_vars', Textarea::class, 'Variables par défaut', [ - 'v2' => '{"type":"textarea","default":"","editable":true,"label":"Variables par d\\u00e9faut","grade":3}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('anchorsAliases', LongText::class, $this->__('Alias des ancres'), [ - 'v2' => '{"type":"text","default":"","editable":true,"label":"\\u00a7!\\u00a7Alias des ancres!\\u00a7!"}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('', FormSeparator::class); - $this->addField('stats_score', Checkbox::class, $this->__('Afficher les scores dans les rapports'), [ - 'v2' => '{"type":"boolean","default":true,"editable":true,"label":"\\u00a7!\\u00a7Afficher les scores dans les rapports!\\u00a7!","grade":5}', - 'default' => true, - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('stats_exclude_ip', Textarea::class, $this->__('Exclure les IP suivantes des statistiques'), [ - 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Exclure les IP suivantes des statistiques!\\u00a7!","grade":3,"hint":"\\u00a7!\\u00a7Indiquer une adresse ip de la forme www.xxx.yyy.zzz par ligne!\\u00a7!"}', - 'hint' => $this->__('Indiquer une adresse ip de la forme www.xxx.yyy.zzz par ligne'), - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('', FormSeparator::class); - $this->addField('relay_url_params', LongText::class, $this->__('Relayer les paramètres d\'url dans les liens sortants'), [ - 'v2' => '{"type":"text","default":"","editable":true,"label":"\\u00a7!\\u00a7Relayer les param\\u00e8tres d\'url dans les liens sortants!\\u00a7!","grade":3}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('', FormSeparator::class); - $this->addField('gtag_additional_code', Textarea::class, $this->__('Code additionnel Google Tag Manager'), [ - 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Code additionnel Google Tag Manager!\\u00a7!"}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('', FormSeparator::class); - $this->addField('googleAnalyticsCustom', Textarea::class, $this->__('Code Stats personnalisé (placé avant fermeture de head)'), [ - 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Code Stats personnalis\\u00e9 (plac\\u00e9 avant fermeture de head)!\\u00a7!"}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('statsCustom', Textarea::class, $this->__('Code Stats personnalisé (placé avant fermeture du body)'), [ - 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Code Stats personnalis\\u00e9 (plac\\u00e9 avant fermeture du body)!\\u00a7!"}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('', FormSeparator::class); - $this->addField('xiti', Textarea::class, $this->__('Code XiTi global'), [ - 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Code XiTi global!\\u00a7!"}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); - $this->addField('xiti_page', Textarea::class, $this->__('Modèle code xiti (pour tags relatifs aux pages)'), [ - 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Mod\\u00e8le code xiti (pour tags relatifs aux pages)!\\u00a7!"}', - 'default' => '', - 'fake' => true, - 'store_in' => 'settings', - 'translatable' => false, - ]); $this->addField('section_sommaire', FormSection::class, $this->__('Sommaire')); $this->addField('chaptersCaptionDisplay', Checkbox::class, $this->__('Afficher le titre "Sommaire" dans la popup'), [ 'v2' => '{"type":"boolean","default":true,"editable":true,"label":"\\u00a7!\\u00a7Afficher le titre \\"Sommaire\\" dans la popup!\\u00a7!","grade":3}', @@ -2955,6 +2823,14 @@ trait PublicationSettings } } + + $this->_stats(); + $this->_elearning(); + + } + + protected function _elearning() + { $this->addField('section_elearning', FormSuperSection::class, __('E-Learning')); $this->addField('section_gamify', FormSection::class, $this->__('Gamification')); $this->addField('gamify_coins_pages', Textarea::class, $this->__('Attribuer des coins lors de la visite des pages'), [ @@ -3098,7 +2974,157 @@ trait PublicationSettings 'store_in' => 'settings', 'translatable' => false, ]); + } + + protected function _stats() + { + $this->addField('bigsection_stats', FormSuperSection::class, $this->__('Statistiques')); + $this->addField('section_fluidbookStats', FormSection::class, $this->__('Statistiques Fluidbook')); + $this->addField('stats', Checkbox::class, $this->__('Activer les statistiques Fluidbook'), [ + 'v2' => '{"type":"boolean","default":true,"editable":true,"label":"\\u00a7!\\u00a7Activer les statistiques Fluidbook!\\u00a7!","grade":3}', + 'default' => true, + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('', FormSeparator::class); + $this->addField('stats_score', Checkbox::class, $this->__('Afficher les scores dans les rapports'), [ + 'v2' => '{"type":"boolean","default":true,"editable":true,"label":"\\u00a7!\\u00a7Afficher les scores dans les rapports!\\u00a7!","grade":5}', + 'default' => true, + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('stats_exclude_ip', Textarea::class, $this->__('Exclure les IP suivantes des statistiques'), [ + 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Exclure les IP suivantes des statistiques!\\u00a7!","grade":3,"hint":"\\u00a7!\\u00a7Indiquer une adresse ip de la forme www.xxx.yyy.zzz par ligne!\\u00a7!"}', + 'hint' => $this->__('Indiquer une adresse ip de la forme www.xxx.yyy.zzz par ligne'), + 'default' => '', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('section_gaStats', FormSection::class, $this->__('Google Analytics')); + $this->addField('googleAnalytics', LongText::class, $this->__('Code Google Analytics'), [ + 'v2' => '{"type":"text","default":"","editable":true,"label":"\\u00a7!\\u00a7Code Google Analytics!\\u00a7!","size":10}', + 'default' => '', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('section_gtmStats', FormSection::class, $this->__('Google Tag Manager')); + $this->addField('googleTagManager', LongText::class, $this->__('Code Google Tag Manager'), [ + 'v2' => '{"type":"text","default":"","editable":true,"label":"\\u00a7!\\u00a7Code Google Tag Manager!\\u00a7!","size":10}', + 'default' => '', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('gtag_additional_code', Code::class, $this->__('Code additionnel Google Tag Manager'), [ + 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Code additionnel Google Tag Manager!\\u00a7!"}', + 'default' => '', + 'fake' => true, + 'language' => 'html', + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('section_tc', FormSection::class, $this->__('Tag Commander')); + $this->addField('tagcommander_id', LongText::class, 'Tag commander ID', [ + 'v2' => '{"type":"text","default":"","editable":true,"label":"Tag commander ID","grade":3}', + 'default' => '', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('tagcommander_scriptname', LongText::class, 'Nom du script Tagcommander', [ + 'v2' => '{"type":"text","default":"tc_Multisite_Head.js,tc_Multisite_Analytics.js,tc_Multisite_Medias.js","editable":true,"label":"Nom du script Tagcommander","grade":3}', + 'default' => 'tc_Multisite_Head.js,tc_Multisite_Analytics.js,tc_Multisite_Medias.js', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('tagcommander_prod', Checkbox::class, 'Production', [ + 'v2' => '{"type":"boolean","default":true,"editable":true,"label":"Production","grade":3}', + 'default' => true, + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('tagcommander_plan', FilesOrURL::class, 'Plan de taggage "Tag commander"', [ + 'v2' => '{"type":"freefile","default":"","editable":true,"label":"Plan de taggage \\"Tag commander\\"","grade":3}', + 'default' => '', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('tagcommander_event_page', Textarea::class, __('Nom de l\'évenement de vue de page'), [ + 'v2' => '{"type":"text","default":"page","editable":true,"grade":3}', + 'default' => 'page', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('tagcommander_default_vars', Textarea::class, 'Variables par défaut', [ + 'v2' => '{"type":"textarea","default":"","editable":true,"label":"Variables par d\\u00e9faut","grade":3}', + 'default' => '', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('section_piano', FormSection::class, __('Piano Analytics')); + $this->addField('xiti', Code::class, $this->__('Code Piano Analytics'), [ + 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Code global!\\u00a7!"}', + 'default' => '', + 'fake' => true, + 'language' => 'html', + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('piano_plan', FilesOrURL::class, 'Plan de taggage', [ + 'v2' => '{"type":"freefile","default":"","editable":true,"label":"Plan de taggage","grade":3}', + 'default' => '', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('xiti_page', Textarea::class, $this->__('Modèle code xiti (pour tags relatifs aux pages)'), [ + 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Mod\\u00e8le code xiti (pour tags relatifs aux pages)!\\u00a7!"}', + 'default' => '', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('section_stats_custom', FormSection::class, __('Autres services')); + $this->addField('googleAnalyticsCustom', Code::class, $this->__('Code Stats personnalisé (placé avant fermeture de head)'), [ + 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Code Stats personnalis\\u00e9 (plac\\u00e9 avant fermeture de head)!\\u00a7!"}', + 'default' => '', + 'fake' => true, + 'language' => 'html', + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('statsCustom', Code::class, $this->__('Code Stats personnalisé (placé avant fermeture du body)'), [ + 'v2' => '{"type":"textarea","default":"","editable":true,"label":"\\u00a7!\\u00a7Code Stats personnalis\\u00e9 (plac\\u00e9 avant fermeture du body)!\\u00a7!"}', + 'default' => '', + 'fake' => true, + 'language' => 'html', + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('anchorsAliases', LongText::class, $this->__('Alias des ancres'), [ + 'v2' => '{"type":"text","default":"","editable":true,"label":"\\u00a7!\\u00a7Alias des ancres!\\u00a7!"}', + 'default' => '', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); + $this->addField('relay_url_params', LongText::class, $this->__('Relayer les paramètres d\'url dans les liens sortants'), [ + 'v2' => '{"type":"text","default":"","editable":true,"label":"\\u00a7!\\u00a7Relayer les param\\u00e8tres d\'url dans les liens sortants!\\u00a7!","grade":3}', + 'default' => '', + 'fake' => true, + 'store_in' => 'settings', + 'translatable' => false, + ]); } } -- 2.39.5