1 | <?php |
---|
2 | |
---|
3 | /***************************************************************************\ |
---|
4 | * SPIP, Systeme de publication pour l'internet * |
---|
5 | * * |
---|
6 | * Copyright (c) 2001-2009 * |
---|
7 | * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
---|
8 | * * |
---|
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 | \***************************************************************************/ |
---|
12 | |
---|
13 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
14 | |
---|
15 | include_spip('inc/ajouter_documents'); // a enlever apres nettoyage du core |
---|
16 | |
---|
17 | /** |
---|
18 | * recuperer les infos distantes d'une url, |
---|
19 | * et renseigner pour une insertion en base |
---|
20 | * utilise une variable static car appellee plusieurs fois au cours du meme hit |
---|
21 | * (verification puis traitement) |
---|
22 | * |
---|
23 | * @param unknown_type $source |
---|
24 | */ |
---|
25 | function renseigner_source_distante($source){ |
---|
26 | static $infos = array(); |
---|
27 | if (isset($infos[$source])) |
---|
28 | return $infos[$source]; |
---|
29 | |
---|
30 | include_spip('inc/distant'); |
---|
31 | if ($a = recuperer_infos_distantes($source)) { |
---|
32 | |
---|
33 | # NB: dans les bonnes conditions (fichier autorise et pas trop gros) |
---|
34 | # $a['fichier'] est une copie locale du fichier |
---|
35 | unset($a['body']); |
---|
36 | |
---|
37 | $a['distant'] = 'oui'; |
---|
38 | $a['mode'] = 'document'; |
---|
39 | $a['fichier'] = set_spip_doc($source); |
---|
40 | $infos[$source] = $a; |
---|
41 | return $infos[$source]; |
---|
42 | } |
---|
43 | |
---|
44 | return _T('gestdoc:erreur_chemin_distant',array('nom'=>$source)); |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * Renseigner les informations de taille et dimenssion d'une image |
---|
49 | * |
---|
50 | * @param <type> $fichier |
---|
51 | * @param <type> $ext |
---|
52 | * @return <type> |
---|
53 | */ |
---|
54 | function renseigner_taille_dimension_image($fichier,$ext){ |
---|
55 | $infos = array(); |
---|
56 | |
---|
57 | $infos['type_image'] = false; |
---|
58 | |
---|
59 | // Quelques infos sur le fichier |
---|
60 | if ( |
---|
61 | !$fichier |
---|
62 | OR !@file_exists($fichier) |
---|
63 | OR !$infos['taille'] = @intval(filesize($fichier))) { |
---|
64 | spip_log ("Echec copie du fichier $fichier"); |
---|
65 | return _T('gestdoc:erreur_copie_fichier',array('nom'=> $fichier)); |
---|
66 | } |
---|
67 | |
---|
68 | // VIDEOS : Prevoir traitement specifique ? |
---|
69 | // (http://www.getid3.org/ peut-etre) |
---|
70 | if ($ext == "mov") { |
---|
71 | $infos['largeur'] = 0; |
---|
72 | $infos['hauteur'] = 0; |
---|
73 | } |
---|
74 | |
---|
75 | // SVG : recuperer les dimensions et supprimer les scripts |
---|
76 | elseif ($ext == "svg") { |
---|
77 | list($infos['largeur'],$infos['hauteur'])= traite_svg($fichier); |
---|
78 | } |
---|
79 | |
---|
80 | // image ? |
---|
81 | else { |
---|
82 | |
---|
83 | // Si c'est une image, recuperer sa taille et son type (detecte aussi swf) |
---|
84 | $size_image = @getimagesize($fichier); |
---|
85 | $infos['largeur'] = intval($size_image[0]); |
---|
86 | $infos['hauteur'] = intval($size_image[1]); |
---|
87 | $infos['type_image'] = decoder_type_image($size_image[2]); |
---|
88 | } |
---|
89 | |
---|
90 | return $infos; |
---|
91 | } |
---|
92 | |
---|
93 | if (!function_exists('traite_svg')){ |
---|
94 | /** |
---|
95 | * Determiner les dimensions d'un svg, et enlever ses scripts si necessaire |
---|
96 | * |
---|
97 | * @param string $file |
---|
98 | * @return array |
---|
99 | */ |
---|
100 | // http://doc.spip.org/@traite_svg |
---|
101 | function traite_svg($file) |
---|
102 | { |
---|
103 | $texte = spip_file_get_contents($file); |
---|
104 | |
---|
105 | // Securite si pas admin : virer les scripts et les references externes |
---|
106 | // sauf si on est en mode javascript 'ok' (1), cf. inc_version |
---|
107 | if ($GLOBALS['filtrer_javascript'] < 1 |
---|
108 | AND $GLOBALS['visiteur_session']['statut'] != '0minirezo') { |
---|
109 | include_spip('inc/texte'); |
---|
110 | $new = trim(safehtml($texte)); |
---|
111 | // petit bug safehtml |
---|
112 | if (substr($new,0,2) == ']>') $new = ltrim(substr($new,2)); |
---|
113 | if ($new != $texte) ecrire_fichier($file, $texte = $new); |
---|
114 | } |
---|
115 | |
---|
116 | $width = $height = 150; |
---|
117 | if (preg_match(',<svg[^>]+>,', $texte, $s)) { |
---|
118 | $s = $s[0]; |
---|
119 | if (preg_match(',\WviewBox\s*=\s*.\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+),i', $s, $r)){ |
---|
120 | $width = $r[3]; |
---|
121 | $height = $r[4]; |
---|
122 | } else { |
---|
123 | // si la taille est en centimetre, estimer le pixel a 1/64 de cm |
---|
124 | if (preg_match(',\Wwidth\s*=\s*.(\d+)([^"\']*),i', $s, $r)){ |
---|
125 | if ($r[2] != '%') { |
---|
126 | $width = $r[1]; |
---|
127 | if ($r[2] == 'cm') $width <<=6; |
---|
128 | } |
---|
129 | } |
---|
130 | if (preg_match(',\Wheight\s*=\s*.(\d+)([^"\']*),i', $s, $r)){ |
---|
131 | if ($r[2] != '%') { |
---|
132 | $height = $r[1]; |
---|
133 | if ($r[2] == 'cm') $height <<=6; |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | } |
---|
138 | return array($width, $height); |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | if (!function_exists('decoder_type_image')){ |
---|
143 | /** |
---|
144 | * Convertit le type numerique retourne par getimagesize() en extension fichier |
---|
145 | * |
---|
146 | * @param int $type |
---|
147 | * @param bool $strict |
---|
148 | * @return string |
---|
149 | */ |
---|
150 | // http://doc.spip.org/@decoder_type_image |
---|
151 | function decoder_type_image($type, $strict = false) { |
---|
152 | switch ($type) { |
---|
153 | case 1: |
---|
154 | return "gif"; |
---|
155 | case 2: |
---|
156 | return "jpg"; |
---|
157 | case 3: |
---|
158 | return "png"; |
---|
159 | case 4: |
---|
160 | return $strict ? "" : "swf"; |
---|
161 | case 5: |
---|
162 | return "psd"; |
---|
163 | case 6: |
---|
164 | return "bmp"; |
---|
165 | case 7: |
---|
166 | case 8: |
---|
167 | return "tif"; |
---|
168 | default: |
---|
169 | return ""; |
---|
170 | } |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | ?> |
---|