3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2013 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
14 include_spip('inc/autoriser');
17 * Determiner les dimensions d'un svg, et enlever ses scripts si necessaire
18 * on utilise safehtml qui n'est pas apropriee pour ca en attendant mieux
19 * cf http://www.slideshare.net/x00mario/the-image-that-called-me
20 * http://heideri.ch/svgpurifier/SVGPurifier/index.php
25 // http://doc.spip.org/@traite_svg
26 function medata_svg_dist($file){
29 $texte = spip_file_get_contents($file);
31 // Securite si pas autorise : virer les scripts et les references externes
32 // sauf si on est en mode javascript 'ok' (1), cf. inc_version
33 if ($GLOBALS['filtrer_javascript'] < 1
34 AND !autoriser('televerser','script')) {
35 include_spip('inc/texte');
36 $new = trim(safehtml($texte));
38 if (substr($new,0,2) == ']>') $new = ltrim(substr($new,2));
39 if ($new != $texte) ecrire_fichier($file, $texte = $new);
42 $width = $height = 150;
43 if (preg_match(',<svg[^>]+>,', $texte, $s)) {
45 if (preg_match(',\WviewBox\s*=\s*.\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+),i', $s, $r)){
49 // si la taille est en centimetre, estimer le pixel a 1/64 de cm
50 if (preg_match(',\Wwidth\s*=\s*.(\d+)([^"\']*),i', $s, $r)){
53 if ($r[2] == 'cm') $width <<=6;
56 if (preg_match(',\Wheight\s*=\s*.(\d+)([^"\']*),i', $s, $r)){
59 if ($r[2] == 'cm') $height <<=6;
64 $meta['largeur'] = $width;
65 $meta['hauteur'] = $height;