/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
- * Copyright (c) 2001-2017 *
+ * Copyright (c) 2001-2019 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) {
return $lien;
}
- if (preg_match(';^((?:[a-z]{3,7}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
+ if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
$r = array_pad($r, 3, null);
return $r[1] . resolve_path($r[2]);
return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue);
}
+/**
+ * Verifier qu'une url est absolue et que son protocole est bien parmi une liste autorisee
+ * @param string $url_absolue
+ * @param array $protocoles_autorises
+ * @return bool
+ */
+function protocole_verifier($url_absolue, $protocoles_autorises = array('http','https')) {
+
+ if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
+ $protocole = $m[1];
+ if (in_array($protocole, $protocoles_autorises)
+ or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises))) {
+ return true;
+ }
+ }
+ return false;
+}
+
/**
* Transforme les URLs relatives en URLs absolues
*