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();