Browse Source

Fix warning

Laurent Destailleur 1 year ago
parent
commit
9843f31814
2 changed files with 12 additions and 5 deletions
  1. 3 4
      htdocs/admin/company_socialnetworks.php
  2. 9 1
      htdocs/core/lib/functions.lib.php

+ 3 - 4
htdocs/admin/company_socialnetworks.php

@@ -120,7 +120,6 @@ print "</tr>\n";
 
 $listofnetworks = dol_sort_array($listofnetworks, 'label');
 //var_dump($listofnetworks);
-
 foreach ($listofnetworks as $key => $value) {
 	if (!empty($value['active'])) {
 		print '<tr class="oddeven">';
@@ -128,11 +127,11 @@ foreach ($listofnetworks as $key => $value) {
 		$networkconstname = 'MAIN_INFO_SOCIETE_'.strtoupper($key).'_URL';
 		$networkconstid = 'MAIN_INFO_SOCIETE_'.strtoupper($key);
 		print '<td class="nowraponall"><span class="paddingright fab '.($value['icon'] ? $value['icon'] : 'fa-link').'"></span>';
-		print '<input name="'.$key.'" id="'.$key.'" class="minwidth300" value="'.(!empty($conf->global->$networkconstid) ? dol_escape_htmltag(getDolGlobalString($networkconstid)) : '').'">';
+		print '<input name="'.$key.'" id="'.$key.'" class="minwidth300" value="'.dol_escape_htmltag(getDolGlobalString($networkconstid)).'">';
 		print '</td><td>';
-		print '<input name="'.$key.'url" id="'.$key.'url" class="minwidth300" value="'.(!empty($conf->global->$networkconstname) ? dol_escape_htmltag(getDolGlobalString($networkconstname)) : '').'">';
+		print '<input name="'.$key.'url" id="'.$key.'url" class="minwidth300" value="'.dol_escape_htmltag(getDolGlobalString($networkconstname)).'">';
 		print '</td>';
-		print '<td class="nowraponall">'.dol_print_socialnetworks((!empty($conf->global->$networkconstid) ? dol_escape_htmltag(getDolGlobalString($networkconstid)) : ''), 0, 0, $key, $listofnetworks).'</td>';
+		print '<td class="nowraponall">'.dol_print_socialnetworks(dol_escape_htmltag(getDolGlobalString($networkconstid)), 0, 0, $key, $listofnetworks).'</td>';
 		print '</tr>'."\n";
 	}
 }

+ 9 - 1
htdocs/core/lib/functions.lib.php

@@ -3441,7 +3441,15 @@ function dol_print_socialnetworks($value, $cid, $socid, $type, $dictsocialnetwor
 				$htmllink .= ($link ? ' '.$link : '');
 			}
 		} else {
-			if (!empty($dictsocialnetworks[$type]['url'])) {
+			$networkconstname = 'MAIN_INFO_SOCIETE_'.strtoupper($type).'_URL';
+			if (getDolGlobalString($networkconstname)) {
+				$link = str_replace('{socialid}', $value, getDolGlobalString($networkconstname));
+				if (preg_match('/^https?:\/\//i', $link)) {
+					$htmllink .= '<a href="'.dol_sanitizeUrl($link, 0).'" target="_blank" rel="noopener noreferrer">'.dol_escape_htmltag($value).'</a>';
+				} else {
+					$htmllink .= '<a href="'.dol_sanitizeUrl($link, 1).'" target="_blank" rel="noopener noreferrer">'.dol_escape_htmltag($value).'</a>';
+				}
+			} elseif (!empty($dictsocialnetworks[$type]['url'])) {
 				$tmpvirginurl = preg_replace('/\/?{socialid}/', '', $dictsocialnetworks[$type]['url']);
 				if ($tmpvirginurl) {
 					$value = preg_replace('/^www\.'.preg_quote($tmpvirginurl, '/').'\/?/', '', $value);