Skip to content

Commit

Permalink
Eoxia#31 [Admin] add: change config for use substitution on shortener…
Browse files Browse the repository at this point in the history
… label
  • Loading branch information
nicolas-eoxia committed Apr 10, 2024
1 parent 7103915 commit 278b70f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 23 deletions.
58 changes: 46 additions & 12 deletions admin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -120,18 +130,6 @@
print '<td><input class="minwidth300" type="text" name="default_original_url" value="' . $conf->global->EASYURL_DEFAULT_ORIGINAL_URL . '"></td>';
print '</td></tr>';

print '<tr class="oddeven"><td>' . $langs->trans('UseMainInfoCompanyName') . '</td>';
print '<td>' . $langs->trans('UseMainInfoCompanyNameDescription') . '</td>';
print '<td>';
print ajax_constantonoff('EASYURL_USE_MAIN_INFO_SOCIETE_NAME');
print '</td></tr>';

print '<tr class="oddeven"><td>' . $langs->trans('UseShortenerRef') . '</td>';
print '<td>' . $langs->trans('UseShortenerRefDescription') . '</td>';
print '<td>';
print ajax_constantonoff('EASYURL_USE_SHORTENER_REF');
print '</td></tr>';

print '<tr class="oddeven"><td>' . $langs->trans('UseShaUrl') . '</td>';
print '<td>' . $langs->trans('UseShaUrlDescription') . '</td>';
print '<td>';
Expand All @@ -154,5 +152,41 @@
print $form->buttonsSaveCancel('Save', '');
print '</form>';

print load_fiche_titre($langs->trans('Config'), '', '');

print '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
print '<input type="hidden" name="token" value="' .newToken(). '">';
print '<input type="hidden" name="action" value="set_shortener_label">';

print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>' . $langs->trans('Parameters') . '</td>';
print '<td>' . $langs->trans('Value') . '</td>';
print '</tr>';

$substitutionArray = getCommonSubstitutionArray($langs);
complete_substitutions_array($substitutionArray, $langs);

// Substitution array/string
$helpForSubstitution = '';
if (is_array($substitutionArray) && count($substitutionArray)) {
$helpForSubstitution .= $langs->trans('AvailableVariables') . ' : <br>';
}
foreach ($substitutionArray as $key => $val) {
$helpForSubstitution .= $key . ' -> '. $langs->trans(dol_string_nohtmltag(dolGetFirstLineOfText($val))) . '<br>';
}

// Shortener set label
$shortenerSetLabel = $langs->transnoentities($conf->global->EASYURL_SHORTENER_SET_LABEL) ?: $langs->transnoentities('ShortenerSetLabel');
print '<tr class="oddeven"><td>' . $form->textwithpicto($langs->transnoentities('ShortenerSetLabelTitle'), $helpForSubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody');
print '</td><td>';
$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 '</td></tr>';

print '</table>';
print $form->buttonsSaveCancel('Save', '');
print '</form>';

$db->close();
llxFooter();
3 changes: 2 additions & 1 deletion core/modules/modEasyURL.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', ...)

Expand Down Expand Up @@ -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'],
Expand Down
9 changes: 9 additions & 0 deletions core/substitutions/functions_easyurl.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
6 changes: 2 additions & 4 deletions langs/fr_FR/easyurl.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br> (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 <br> (proposition commerciale, commande, facture)
ShortenerSetLabel = __MYCOMPANY_NAME__-__REF__-__EASYURL_SHA_8__
ShortenerSetLabelTitle = Libellé dans l'URL raccourcie



Expand Down
11 changes: 5 additions & 6 deletions lib/easyurl_function.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 278b70f

Please sign in to comment.