diff --git a/admin/setup.php b/admin/setup.php index 2d4d157..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 */ @@ -142,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..c4851d1 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 ad9cad9..40d2193 100644 --- a/langs/fr_FR/easyurl.lang +++ b/langs/fr_FR/easyurl.lang @@ -42,6 +42,8 @@ AutomaticEasyUrlGeneration = Génération automatique des URLs raccou 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 @@ -67,19 +69,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..f749687 100644 --- a/lib/easyurl_function.lib.php +++ b/lib/easyurl_function.lib.php @@ -75,7 +75,11 @@ 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) : '')); + $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(); 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 '';