diff --git a/ecrire/inc/filtres.php b/ecrire/inc/filtres.php index db45fb426b1aa5a14d540f6ea33be79b3e0c5d62..1ca0564439a13966c83833f333f188e391a3acae 100644 --- a/ecrire/inc/filtres.php +++ b/ecrire/inc/filtres.php @@ -1394,31 +1394,35 @@ function afficher_tags($tags, $rels='tag,directory') { // Passe un <enclosure url="fichier" length="5588242" type="audio/mpeg"/> // au format microformat <a rel="enclosure" href="fichier" ...>fichier</a> +// attention length="zz" devient title="zz", pour rester conforme // http://doc.spip.org/@enclosure2microformat function enclosure2microformat($e) { - $url = extraire_attribut($e, 'url'); - $fichier = basename($url) OR $fichier; - $e = preg_replace(',<enclosure[[:space:]],iS','<a rel="enclosure" ', $e) - . $fichier.'</a>'; - $e = vider_attribut($e, 'url'); - $e = inserer_attribut($e, 'href', filtrer_entites($url)); - $e = str_replace('/>', '>', $e); - return $e; + $url = filtrer_entites(extraire_attribut($e, 'url')); + $type = extraire_attribut($e, 'type'); + $length = extraire_attribut($e, 'length'); + $fichier = basename($url); + return '<a rel="enclosure"' + . ($url? ' href="'.htmlspecialchars($url).'"' : '') + . ($type? ' type="'.htmlspecialchars($type).'"' : '') + . ($length? ' title="'.htmlspecialchars($length).'"' : '') + . '>'.$fichier.'</a>'; } // La fonction inverse // http://doc.spip.org/@microformat2enclosure function microformat2enclosure($tags) { $enclosures = array(); foreach (extraire_tags($tags) as $e) - if (extraire_attribut($e, rel) == 'enclosure') { - $url = extraire_attribut($e, 'href'); - $fichier = basename($url) OR $fichier; - $e = preg_replace(',<a[[:space:]],iS','<enclosure ', $e); - $e = preg_replace(',( ?/?)>.*,S',' />', $e); - $e = vider_attribut($e, 'href'); - $e = vider_attribut($e, 'rel'); - $e = inserer_attribut($e, 'url', filtrer_entites($url)); - $enclosures[] = $e; + if (extraire_attribut($e, 'rel') == 'enclosure') { + $url = filtrer_entites(extraire_attribut($e, 'href')); + $type = extraire_attribut($e, 'type'); + if (!$length = intval(extraire_attribut($e, 'title'))) + $length = intval(extraire_attribut($e, 'length')); # vieux data + $fichier = basename($url); + $enclosures[] = '<enclosure' + . ($url? ' url="'.htmlspecialchars($url).'"' : '') + . ($type? ' type="'.htmlspecialchars($type).'"' : '') + . ($length? ' length="'.$length.'"' : '') + . ' />'; } return join("\n", $enclosures); }