Backport fix for #36850

This commit is contained in:
Laurent Destailleur 2026-01-11 12:48:58 +01:00
parent 6d6dfb3a5e
commit 39ed2ece8f

View file

@ -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<string,array{rowid:int,label:string,url:string,icon:string,active:int}> $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 = '<div class="divsocialnetwork inline-block valignmiddle">';
// Use dictionary definition for picto $dictsocialnetworks[$type]['icon']
$htmllink .= '<span class="fab pictofixedwidth '.($dictsocialnetworks[$type]['icon'] ? $dictsocialnetworks[$type]['icon'] : 'fa-link').'"></span>';
$htmllink .= '<span class="fab pictofixedwidth ' . ($dictsocialnetworks[$type]['icon'] ? $dictsocialnetworks[$type]['icon'] : 'fa-link') . '"></span>';
if ($type == 'skype') {
$htmllink .= dol_escape_htmltag($value);
$htmllink .= '&nbsp; <a href="skype:';
$htmllink .= dol_string_nospecial($value, '_', '', array('@'));
$htmllink .= '?call" alt="'.$langs->trans("Call").'&nbsp;'.$value.'" title="'.dol_escape_htmltag($langs->trans("Call").' '.$value).'">';
$htmllink .= '<img src="'.DOL_URL_ROOT.'/theme/common/skype_callbutton.png" border="0">';
$htmllink .= '?call" alt="' . $langs->trans("Call") . '&nbsp;' . $value . '" title="' . dol_escape_htmltag($langs->trans("Call") . ' ' . $value) . '">';
$htmllink .= '<img src="' . DOL_URL_ROOT . '/theme/common/skype_callbutton.png" border="0">';
$htmllink .= '</a><a href="skype:';
$htmllink .= dol_string_nospecial($value, '_', '', array('@'));
$htmllink .= '?chat" alt="'.$langs->trans("Chat").'&nbsp;'.$value.'" title="'.dol_escape_htmltag($langs->trans("Chat").' '.$value).'">';
$htmllink .= '<img class="paddingleft" src="'.DOL_URL_ROOT.'/theme/common/skype_chatbutton.png" border="0">';
$htmllink .= '?chat" alt="' . $langs->trans("Chat") . '&nbsp;' . $value . '" title="' . dol_escape_htmltag($langs->trans("Chat") . ' ' . $value) . '">';
$htmllink .= '<img class="paddingleft" src="' . DOL_URL_ROOT . '/theme/common/skype_chatbutton.png" border="0">';
$htmllink .= '</a>';
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 = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$addlink.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"), "calendar").'</a>';
$link = '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&backtopage=1&actioncode=' . $addlink . '&contactid=' . $contactid . '&socid=' . $socid . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
}
$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 .= '<a href="'.dol_sanitizeUrl($link, 0).'" target="_blank" rel="noopener noreferrer">'.dol_escape_htmltag($valuetoshow).'</a>';
} elseif ($link) {
$htmllink .= '<a href="'.dol_sanitizeUrl($link, 1).'" target="_blank" rel="noopener noreferrer">'.dol_escape_htmltag($valuetoshow).'</a>';
}
} 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 .= '<a href="'.dol_sanitizeUrl($link, 0).'" target="_blank" rel="noopener noreferrer">'.dol_escape_htmltag($value).'</a>';
if (preg_match('/^https?:\/\//i', $value)) {
$link = $value;
} else {
$htmllink .= '<a href="'.dol_sanitizeUrl($link, 1).'" target="_blank" rel="noopener noreferrer">'.dol_escape_htmltag($value).'</a>';
$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 .= '<a href="' . dol_sanitizeUrl($link, 0) . '" target="_blank" rel="noopener noreferrer">' . dol_escape_htmltag($valuetoshow) . '</a>';
} else {
$htmllink .= '<a href="' . dol_sanitizeUrl($link, 1) . '" target="_blank" rel="noopener noreferrer">' . dol_escape_htmltag($valuetoshow) . '</a>';
}
} 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,