From 7103915310d0ee5bc57cf07a55cb7c3fb38b1204 Mon Sep 17 00:00:00 2001 From: Nicolas Domenech Date: Thu, 4 Apr 2024 18:23:16 +0200 Subject: [PATCH 1/3] #31 [Admin] add: improve config label of short_url --- admin/setup.php | 12 ++++++++++++ langs/fr_FR/easyurl.lang | 30 +++++++++++++++++------------- lib/easyurl_function.lib.php | 7 ++++++- view/easyurltools.php | 20 ++++++++++---------- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/admin/setup.php b/admin/setup.php index 2d4d157..2806b63 100644 --- a/admin/setup.php +++ b/admin/setup.php @@ -120,6 +120,18 @@ print ''; print ''; +print '' . $langs->trans('UseMainInfoCompanyName') . ''; +print '' . $langs->trans('UseMainInfoCompanyNameDescription') . ''; +print ''; +print ajax_constantonoff('EASYURL_USE_MAIN_INFO_SOCIETE_NAME'); +print ''; + +print '' . $langs->trans('UseShortenerRef') . ''; +print '' . $langs->trans('UseShortenerRefDescription') . ''; +print ''; +print ajax_constantonoff('EASYURL_USE_SHORTENER_REF'); +print ''; + print '' . $langs->trans('UseShaUrl') . ''; print '' . $langs->trans('UseShaUrlDescription') . ''; print ''; diff --git a/langs/fr_FR/easyurl.lang b/langs/fr_FR/easyurl.lang index ad9cad9..63908ca 100644 --- a/langs/fr_FR/easyurl.lang +++ b/langs/fr_FR/easyurl.lang @@ -36,6 +36,10 @@ SignatureTokenYourlsAPI = Token de signature SignatureTokenYourlsAPIDescription = Cette option permet de configurer le token de signature d'API YOURLS DefaultOriginalUrl = URL d'origine par défaut DefaultOriginalUrlDescription = Cette option permet de configurer l'URL d'origine par défaut +UseMainInfoCompanyName = Nom de la societe dans l'URL raccourcie +UseMainInfoCompanyNameDescription = Cette option permet d'ajouter le nom de la societe dans le raccourcissement des URLs +UseShortenerRef = Ref dans l'URL raccourcie +UseShortenerRefDescription = Cette option permet d'ajouter la référence dans le raccourcissement des URLs UseShaUrl = SHA dans l'URL raccourcie UseShaUrlDescription = Cette option permet d'ajouter un SHA (8 caractères) dans le raccourcissement des URLs AutomaticEasyUrlGeneration = Génération automatique des URLs raccourcies @@ -67,19 +71,19 @@ GetEasyURLErrors = Erreur : URL raccourcie non trouvée # # Data - Donnée -GenerateUrlManagement = Gestion de la génération des raccourcissements d'URLs -NbUrl = Nombre d'URL -NbUrlDescription = Cette option permet de choisir le nombre d'URL à générée -OriginalUrl = URL d'origine -OriginalUrlDescription = Cette option permet de choisir l'URL d'origine -OriginalUrlMoreDescription =
(par défaut si aucune URL n'est renseignée alors l'URL par défaut est : %s) -UrlParameters = Paramètre d'URL supplémentaire -UrlParametersDescription = Cette option permet d'ajouter des paramètres d'URLs supplémentaires
(exemple : un tiret/une valeur) -UrlMethode = Méthode d'API URL -UrlMethodeDescription = Cette option permet de choisir la méthode d'API URL utilisée dans le raccourcissement des URLs
(deux valeurs possibles : YOURLS ou WordPress) -GenerateUrlSuccess = Génération réussie des %d raccourcissements d'URLs -OriginalUrlFail = Erreur(s) possible(s) :
- Nombre d'URL est vide
- l'URL d'origine est vide
- l'URL d'origine par défaut n'as pas été configurée -DefaultOriginalUrlConfiguration = Vous n'avez pas configuré d'URL d'origine par défaut, veuillez cliquer ici pour vous rendre sur la page de configuration +GenerateUrlManagement = Gestion de la génération des raccourcissements d'URLs +NbUrl = Nombre d'URL +NbUrlDescription = Cette option permet de choisir le nombre d'URL à générée +OriginalUrl = URL d'origine +OriginalUrlDescription = Cette option permet de choisir l'URL d'origine +OriginalUrlMoreDescription =
(par défaut si aucune URL n'est renseignée alors l'URL par défaut est : %s) +OriginalUrlParameters = Paramètre d'URL d'origine supplémentaire +OriginalUrlParametersDescription = Cette option permet d'ajouter des paramètres d'URLs d'origine supplémentaires
(exemple : un tiret/une valeur) +UrlMethode = Méthode d'API URL +UrlMethodeDescription = Cette option permet de choisir la méthode d'API URL utilisée dans le raccourcissement des URLs
(deux valeurs possibles : YOURLS ou WordPress) +GenerateUrlSuccess = Génération réussie des %d raccourcissements d'URLs +OriginalUrlFail = Erreur(s) possible(s) :
- Nombre d'URL est vide
- l'URL d'origine est vide
- l'URL d'origine par défaut n'as pas été configurée +DefaultOriginalUrlConfiguration = Vous n'avez pas configuré d'URL d'origine par défaut, veuillez cliquer ici pour vous rendre sur la page de configuration # diff --git a/lib/easyurl_function.lib.php b/lib/easyurl_function.lib.php index 6138e67..e2f7a63 100644 --- a/lib/easyurl_function.lib.php +++ b/lib/easyurl_function.lib.php @@ -75,7 +75,12 @@ function set_easy_url_link(CommonObject $object, string $urlType, string $urlMet break; } - $title = dol_sanitizeFileName(dol_strtolower($conf->global->MAIN_INFO_SOCIETE_NOM . '-' . $object->ref) . (getDolGlobalInt('EASYURL_USE_SHA_URL') ? '-' . generate_random_id(8) : '')); + $title = getDolGlobalInt('EASYURL_USE_MAIN_INFO_SOCIETE_NAME') ? dol_strtolower($conf->global->MAIN_INFO_SOCIETE_NOM) : ''; + $title .= getDolGlobalInt('EASYURL_USE_MAIN_INFO_SOCIETE_NAME') && getDolGlobalInt('EASYURL_USE_SHORTENER_REF') ? '-' : ''; + $title .= getDolGlobalInt('EASYURL_USE_SHORTENER_REF') ? dol_strtolower($object->ref) : ''; + $title .= (getDolGlobalInt('EASYURL_USE_MAIN_INFO_SOCIETE_NAME') || getDolGlobalInt('EASYURL_USE_SHORTENER_REF')) && getDolGlobalInt('EASYURL_USE_SHA_URL') ? '-' : ''; + $title .= getDolGlobalInt('EASYURL_USE_SHA_URL') ? generate_random_id(8) : ''; + $title = dol_sanitizeFileName($title); // Init the CURL session $ch = curl_init(); diff --git a/view/easyurltools.php b/view/easyurltools.php index 3970085..28ae4e8 100644 --- a/view/easyurltools.php +++ b/view/easyurltools.php @@ -56,19 +56,19 @@ */ if ($action == 'generate_url' && $permissionToAdd) { - $error = 0; - $urlMethode = GETPOST('url_methode'); - $NbUrl = GETPOST('nb_url'); - $originalUrl = GETPOST('original_url'); - $urlParameters = GETPOST('url_parameters'); + $error = 0; + $urlMethode = GETPOST('url_methode'); + $NbUrl = GETPOST('nb_url'); + $originalUrl = GETPOST('original_url'); + $originalUrlParameters = GETPOST('original_url_parameters'); if ((dol_strlen($originalUrl) > 0 || dol_strlen(getDolGlobalString('EASYURL_DEFAULT_ORIGINAL_URL')) > 0) && $NbUrl > 0) { for ($i = 1; $i <= $NbUrl; $i++) { $shortener = new Shortener($db); $shortener->ref = $shortener->getNextNumRef(); if (dol_strlen($originalUrl) > 0) { - $shortener->original_url = $originalUrl . $urlParameters; + $shortener->original_url = $originalUrl . $originalUrlParameters; } else { - $shortener->original_url = getDolGlobalString('EASYURL_DEFAULT_ORIGINAL_URL') . $urlParameters; + $shortener->original_url = getDolGlobalString('EASYURL_DEFAULT_ORIGINAL_URL') . $originalUrlParameters; } $shortener->methode = $urlMethode; @@ -144,9 +144,9 @@ print ''; print ''; -print ''; -print '' . $langs->trans('UrlParametersDescription') . ''; -print ''; +print ''; +print '' . $langs->trans('OriginalUrlParametersDescription') . ''; +print ''; print ''; print ''; From 278b70f0d22a96fb05c4dafa3dc55c38df7e03be Mon Sep 17 00:00:00 2001 From: Nicolas Domenech Date: Wed, 10 Apr 2024 14:08:44 +0200 Subject: [PATCH 2/3] #31 [Admin] add: change config for use substitution on shortener label --- admin/setup.php | 58 ++++++++++++++++---- core/modules/modEasyURL.class.php | 3 +- core/substitutions/functions_easyurl.lib.php | 9 +++ langs/fr_FR/easyurl.lang | 6 +- lib/easyurl_function.lib.php | 11 ++-- 5 files changed, 64 insertions(+), 23 deletions(-) diff --git a/admin/setup.php b/admin/setup.php index 2806b63..0ebd033 100644 --- a/admin/setup.php +++ b/admin/setup.php @@ -32,6 +32,7 @@ // Load Dolibarr libraries require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; // Load EasyURL libraries require_once __DIR__ . '/../lib/easyurl.lib.php'; @@ -75,6 +76,15 @@ exit; } +if ($action == 'set_shortener_label') { + $shortenerSetLabel = GETPOST('EASYURL_SHORTENER_SET_LABEL', 'none'); + dolibarr_set_const($db, 'EASYURL_SHORTENER_SET_LABEL', $shortenerSetLabel, 'chaine', 0, '', $conf->entity); + + setEventMessage('SavedConfig'); + header('Location: ' . $_SERVER['PHP_SELF']); + exit; +} + /* * View */ @@ -120,18 +130,6 @@ print ''; print ''; -print '' . $langs->trans('UseMainInfoCompanyName') . ''; -print '' . $langs->trans('UseMainInfoCompanyNameDescription') . ''; -print ''; -print ajax_constantonoff('EASYURL_USE_MAIN_INFO_SOCIETE_NAME'); -print ''; - -print '' . $langs->trans('UseShortenerRef') . ''; -print '' . $langs->trans('UseShortenerRefDescription') . ''; -print ''; -print ajax_constantonoff('EASYURL_USE_SHORTENER_REF'); -print ''; - print '' . $langs->trans('UseShaUrl') . ''; print '' . $langs->trans('UseShaUrlDescription') . ''; print ''; @@ -154,5 +152,41 @@ print $form->buttonsSaveCancel('Save', ''); print ''; +print load_fiche_titre($langs->trans('Config'), '', ''); + +print '
'; +print ''; +print ''; + +print ''; +print ''; +print ''; +print ''; +print ''; + +$substitutionArray = getCommonSubstitutionArray($langs); +complete_substitutions_array($substitutionArray, $langs); + +// Substitution array/string +$helpForSubstitution = ''; +if (is_array($substitutionArray) && count($substitutionArray)) { + $helpForSubstitution .= $langs->trans('AvailableVariables') . ' :
'; +} +foreach ($substitutionArray as $key => $val) { + $helpForSubstitution .= $key . ' -> '. $langs->trans(dol_string_nohtmltag(dolGetFirstLineOfText($val))) . '
'; +} + +// Shortener set label +$shortenerSetLabel = $langs->transnoentities($conf->global->EASYURL_SHORTENER_SET_LABEL) ?: $langs->transnoentities('ShortenerSetLabel'); +print ''; + +print '
' . $langs->trans('Parameters') . '' . $langs->trans('Value') . '
' . $form->textwithpicto($langs->transnoentities('ShortenerSetLabelTitle'), $helpForSubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody'); +print ''; +$dolEditor = new DolEditor('EASYURL_SHORTENER_SET_LABEL', $shortenerSetLabel, '100%', 120, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_MAIL, ROWS_2, 70); +$dolEditor->Create(); +print '
'; +print $form->buttonsSaveCancel('Save', ''); +print '
'; + $db->close(); llxFooter(); diff --git a/core/modules/modEasyURL.class.php b/core/modules/modEasyURL.class.php index 769723f..97f03ba 100644 --- a/core/modules/modEasyURL.class.php +++ b/core/modules/modEasyURL.class.php @@ -148,7 +148,7 @@ public function __construct($db) $this->hidden = false; // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) - $this->depends = ['modAgenda', 'modSaturne']; + $this->depends = ['modAgenda', 'modSaturne', 'modFckeditor']; $this->requiredby = []; // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = []; // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) @@ -184,6 +184,7 @@ public function __construct($db) // CONST SHORTENER $i++ => ['EASYURL_SHORTENER_ADDON', 'chaine', 'mod_shortener_standard', '', 0, 'current'], + $i++ => ['EASYURL_SHORTENER_SET_lABEL', 'chaine', $langs->trans('ShortenerSetLabel'), '', 0, 'current'], // CONST DOLIBARR $i++ => ['CONTRACT_ALLOW_ONLINESIGN', 'integer', 1, '', 0, 'current'], diff --git a/core/substitutions/functions_easyurl.lib.php b/core/substitutions/functions_easyurl.lib.php index 4db8cbe..c474a01 100644 --- a/core/substitutions/functions_easyurl.lib.php +++ b/core/substitutions/functions_easyurl.lib.php @@ -50,4 +50,13 @@ function easyurl_completesubstitutionarray(&$substitutionarray, $langs, $object) $substitutionarray['__EASY_URL_PAYMENT_LINK__'] = $langs->trans('EasyUrlPaymentLink'); break; } + + $shortenerLabel = dol_strlen(getDolGlobalString('EASYURL_SHORTENER_SET_LABEL')) > 0 ? getDolGlobalString('EASYURL_SHORTENER_SET_LABEL') : $langs->transnoentities('ShortenerSetLabel'); + if (strpos($shortenerLabel, '__EASYURL_SHA_') !== false) { + require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php'; + + $SHAshortenerLabel = explode('__EASYURL_SHA_', $shortenerLabel); + $SHAshortenerLabel = explode('__', $SHAshortenerLabel[1]); + $substitutionarray['__EASYURL_SHA_' . $SHAshortenerLabel[0] . '__'] = generate_random_id($SHAshortenerLabel[0]); + } } diff --git a/langs/fr_FR/easyurl.lang b/langs/fr_FR/easyurl.lang index 63908ca..40d2193 100644 --- a/langs/fr_FR/easyurl.lang +++ b/langs/fr_FR/easyurl.lang @@ -36,16 +36,14 @@ SignatureTokenYourlsAPI = Token de signature SignatureTokenYourlsAPIDescription = Cette option permet de configurer le token de signature d'API YOURLS DefaultOriginalUrl = URL d'origine par défaut DefaultOriginalUrlDescription = Cette option permet de configurer l'URL d'origine par défaut -UseMainInfoCompanyName = Nom de la societe dans l'URL raccourcie -UseMainInfoCompanyNameDescription = Cette option permet d'ajouter le nom de la societe dans le raccourcissement des URLs -UseShortenerRef = Ref dans l'URL raccourcie -UseShortenerRefDescription = Cette option permet d'ajouter la référence dans le raccourcissement des URLs UseShaUrl = SHA dans l'URL raccourcie UseShaUrlDescription = Cette option permet d'ajouter un SHA (8 caractères) dans le raccourcissement des URLs AutomaticEasyUrlGeneration = Génération automatique des URLs raccourcies AutomaticEasyUrlGenerationDescription = Crée automatiquement l'URL raccourcie lors de la validation d'un objet
(proposition commerciale, commande, facture) ManualEasyUrlGeneration = Génération manuelle des URLs raccourcies ManualEasyUrlGenerationDescription = Ajout d'un bouton pour créer une URL raccourcie sur un objet
(proposition commerciale, commande, facture) +ShortenerSetLabel = __MYCOMPANY_NAME__-__REF__-__EASYURL_SHA_8__ +ShortenerSetLabelTitle = Libellé dans l'URL raccourcie diff --git a/lib/easyurl_function.lib.php b/lib/easyurl_function.lib.php index e2f7a63..f749687 100644 --- a/lib/easyurl_function.lib.php +++ b/lib/easyurl_function.lib.php @@ -75,12 +75,11 @@ function set_easy_url_link(CommonObject $object, string $urlType, string $urlMet break; } - $title = getDolGlobalInt('EASYURL_USE_MAIN_INFO_SOCIETE_NAME') ? dol_strtolower($conf->global->MAIN_INFO_SOCIETE_NOM) : ''; - $title .= getDolGlobalInt('EASYURL_USE_MAIN_INFO_SOCIETE_NAME') && getDolGlobalInt('EASYURL_USE_SHORTENER_REF') ? '-' : ''; - $title .= getDolGlobalInt('EASYURL_USE_SHORTENER_REF') ? dol_strtolower($object->ref) : ''; - $title .= (getDolGlobalInt('EASYURL_USE_MAIN_INFO_SOCIETE_NAME') || getDolGlobalInt('EASYURL_USE_SHORTENER_REF')) && getDolGlobalInt('EASYURL_USE_SHA_URL') ? '-' : ''; - $title .= getDolGlobalInt('EASYURL_USE_SHA_URL') ? generate_random_id(8) : ''; - $title = dol_sanitizeFileName($title); + $substitutionArray = getCommonSubstitutionArray($langs, 0, null, $shortener); + complete_substitutions_array($substitutionArray, $langs, $shortener); + $shortenerSetLabel = make_substitutions($langs->transnoentities($conf->global->EASYURL_SHORTENER_SET_LABEL), $substitutionArray); + + $title = dol_sanitizeFileName(dol_strtolower(dol_strlen($shortenerSetLabel) > 0 ? $shortenerSetLabel : $langs->transnoentities('ShortenerSetLabel'))); // Init the CURL session $ch = curl_init(); From c6a02d4e5111462b02774b2a78af758cdd3632fb Mon Sep 17 00:00:00 2001 From: Nicolas Domenech Date: Wed, 24 Apr 2024 11:01:38 +0200 Subject: [PATCH 3/3] #31 [Admin] fix: conf name --- core/modules/modEasyURL.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/modEasyURL.class.php b/core/modules/modEasyURL.class.php index 97f03ba..c4851d1 100644 --- a/core/modules/modEasyURL.class.php +++ b/core/modules/modEasyURL.class.php @@ -184,7 +184,7 @@ public function __construct($db) // CONST SHORTENER $i++ => ['EASYURL_SHORTENER_ADDON', 'chaine', 'mod_shortener_standard', '', 0, 'current'], - $i++ => ['EASYURL_SHORTENER_SET_lABEL', 'chaine', $langs->trans('ShortenerSetLabel'), '', 0, 'current'], + $i++ => ['EASYURL_SHORTENER_SET_LABEL', 'chaine', $langs->trans('ShortenerSetLabel'), '', 0, 'current'], // CONST DOLIBARR $i++ => ['CONTRACT_ALLOW_ONLINESIGN', 'integer', 1, '', 0, 'current'],