From 39ed2ece8f1019fd42e70f9cdc3a39c7152373a5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Jan 2026 12:48:58 +0100 Subject: [PATCH] Backport fix for #36850 --- htdocs/core/lib/functions.lib.php | 61 ++++++++++++++----------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 1a30083040d..bacbc925e4c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4252,13 +4252,13 @@ function getArrayOfSocialNetworks() * Show social network link * * @param string $value Social network ID to show (only skype, without 'Name of recipient' before) - * @param int $cid Id of contact if known + * @param int $contactid Id of contact if known * @param int $socid Id of third party if known * @param string $type 'skype','facebook',... * @param array $dictsocialnetworks List of socialnetworks available * @return string HTML Link */ -function dol_print_socialnetworks($value, $cid, $socid, $type, $dictsocialnetworks = array()) +function dol_print_socialnetworks($value, $contactid, $socid, $type, $dictsocialnetworks = array()) { global $hookmanager, $langs, $user; @@ -4271,61 +4271,56 @@ function dol_print_socialnetworks($value, $cid, $socid, $type, $dictsocialnetwor if (!empty($type)) { $htmllink = '
'; // Use dictionary definition for picto $dictsocialnetworks[$type]['icon'] - $htmllink .= ''; + $htmllink .= ''; if ($type == 'skype') { $htmllink .= dol_escape_htmltag($value); $htmllink .= '  '; - $htmllink .= ''; + $htmllink .= '?call" alt="' . $langs->trans("Call") . ' ' . $value . '" title="' . dol_escape_htmltag($langs->trans("Call") . ' ' . $value) . '">'; + $htmllink .= ''; $htmllink .= ''; - $htmllink .= ''; + $htmllink .= '?chat" alt="' . $langs->trans("Chat") . ' ' . $value . '" title="' . dol_escape_htmltag($langs->trans("Chat") . ' ' . $value) . '">'; + $htmllink .= ''; $htmllink .= ''; - if (($cid || $socid) && isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) { + if (($contactid || $socid) && isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) { $addlink = 'AC_SKYPE'; $link = ''; if (getDolGlobalString('AGENDA_ADDACTIONFORSKYPE')) { - $link = ''.img_object($langs->trans("AddAction"), "calendar").''; + $link = '' . img_object($langs->trans("AddAction"), "calendar") . ''; } - $htmllink .= ($link ? ' '.$link : ''); + $htmllink .= ($link ? ' ' . $link : ''); } } else { - $networkconstname = 'MAIN_INFO_SOCIETE_'.strtoupper($type).'_URL'; - if (getDolGlobalString($networkconstname)) { - $link = str_replace('{socialid}', $value, getDolGlobalString($networkconstname)); - $valuetoshow = $value; - if (preg_match('/^https?:\/\//i', $link)) { - $valuetoshow = preg_replace('/https:\/\/www\.linkedin\./', 'linkedin.', $valuetoshow); - //$valuetoshow = preg_replace('/www\.twitter\./', 'twitter.', $valuetoshow); - $htmllink .= ''.dol_escape_htmltag($valuetoshow).''; - } elseif ($link) { - $htmllink .= ''.dol_escape_htmltag($valuetoshow).''; - } - } elseif (!empty($dictsocialnetworks[$type]['url'])) { + if (!empty($dictsocialnetworks[$type]['url'])) { $tmpvirginurl = preg_replace('/\/?{socialid}/', '', $dictsocialnetworks[$type]['url']); if ($tmpvirginurl) { - $value = preg_replace('/^www\.'.preg_quote($tmpvirginurl, '/').'\/?/', '', $value); - $value = preg_replace('/^'.preg_quote($tmpvirginurl, '/').'\/?/', '', $value); + $value = preg_replace('/^www\.' . preg_quote($tmpvirginurl, '/') . '\/?/', '', $value); + $value = preg_replace('/^' . preg_quote($tmpvirginurl, '/') . '\/?/', '', $value); $tmpvirginurl3 = preg_replace('/^https:\/\//i', 'https://www.', $tmpvirginurl); if ($tmpvirginurl3) { - $value = preg_replace('/^www\.'.preg_quote($tmpvirginurl3, '/').'\/?/', '', $value); - $value = preg_replace('/^'.preg_quote($tmpvirginurl3, '/').'\/?/', '', $value); + $value = preg_replace('/^www\.' . preg_quote($tmpvirginurl3, '/') . '\/?/', '', $value); + $value = preg_replace('/^' . preg_quote($tmpvirginurl3, '/') . '\/?/', '', $value); } $tmpvirginurl2 = preg_replace('/^https?:\/\//i', '', $tmpvirginurl); if ($tmpvirginurl2) { - $value = preg_replace('/^www\.'.preg_quote($tmpvirginurl2, '/').'\/?/', '', $value); - $value = preg_replace('/^'.preg_quote($tmpvirginurl2, '/').'\/?/', '', $value); + $value = preg_replace('/^www\.' . preg_quote($tmpvirginurl2, '/') . '\/?/', '', $value); + $value = preg_replace('/^' . preg_quote($tmpvirginurl2, '/') . '\/?/', '', $value); } } - $link = str_replace('{socialid}', $value, $dictsocialnetworks[$type]['url']); - if (preg_match('/^https?:\/\//i', $link)) { - $htmllink .= ''.dol_escape_htmltag($value).''; + if (preg_match('/^https?:\/\//i', $value)) { + $link = $value; } else { - $htmllink .= ''.dol_escape_htmltag($value).''; + $link = str_replace('{socialid}', $value, $dictsocialnetworks[$type]['url']); + } + $valuetoshow = $value; + $valuetoshow = preg_replace('/https:\/\/www\.(twitter|x|linkedin)\.com\/?/', '', $valuetoshow); + if (preg_match('/^https?:\/\//i', $link)) { + $htmllink .= '' . dol_escape_htmltag($valuetoshow) . ''; + } else { + $htmllink .= '' . dol_escape_htmltag($valuetoshow) . ''; } } else { $htmllink .= dol_escape_htmltag($value); @@ -4340,7 +4335,7 @@ function dol_print_socialnetworks($value, $cid, $socid, $type, $dictsocialnetwor if ($hookmanager) { $parameters = array( 'value' => $value, - 'cid' => $cid, + 'cid' => $contactid, 'socid' => $socid, 'type' => $type, 'dictsocialnetworks' => $dictsocialnetworks,