[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / ecrire / action / iconifier.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
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 /**
16 * L'entree par l'action ne sert plus qu'a une retro compat eventuelle
17 * le #FORMULAIRE_EDITER_LOGO utilise action_spip_image_ajouter_dist
18 */
19 function action_iconifier_dist()
20 {
21 include_spip('inc/actions');
22 $securiser_action = charger_fonction('securiser_action', 'inc');
23 $arg = $securiser_action();
24 $iframe_redirect = _request('iframe_redirect');
25
26 $arg = rawurldecode($arg);
27
28 if (!preg_match(',^-?\d*(\D)(.*)$,',$arg, $r))
29 spip_log("action iconifier: $arg pas compris");
30 elseif ($r[1] == '+')
31 action_spip_image_ajouter_dist($r[2], _request('sousaction2'), _request('source'));
32 else action_spip_image_effacer_dist($r[2]);
33
34 if(_request("iframe") == 'iframe') {
35 $redirect = urldecode($iframe_redirect)."&iframe=iframe";
36 redirige_par_entete(urldecode($redirect));
37 }
38 }
39
40 // http://doc.spip.org/@action_spip_image_effacer_dist
41 function action_spip_image_effacer_dist($arg) {
42
43 if (!strstr($arg, ".."))
44 spip_unlink(_DIR_LOGOS . $arg);
45 }
46
47 //
48 // Ajouter un logo
49 //
50
51 // $source = $_FILES[0]
52 // $dest = arton12.xxx
53 // http://doc.spip.org/@action_spip_image_ajouter_dist
54 function action_spip_image_ajouter_dist($arg,$sousaction2,$source,$return=false) {
55 global $formats_logos;
56
57 include_spip('inc/documents');
58 if (!$sousaction2) {
59 if (!$_FILES) $_FILES = $GLOBALS['HTTP_POST_FILES'];
60 $source = (is_array($_FILES) ? array_pop($_FILES) : "");
61 }
62 $erreur = "";
63 if (!$source)
64 spip_log("spip_image_ajouter : source inconnue");
65 else {
66 $f =_DIR_LOGOS . $arg . '.tmp';
67
68 if (!is_array($source))
69 // fichier dans upload/
70 $source = @copy(determine_upload() . $source, $f);
71 else {
72 // Intercepter une erreur a l'envoi
73 if ($erreur = check_upload_error($source['error'],"",$return))
74 $source ="";
75 else
76 // analyse le type de l'image (on ne fait pas confiance au nom de
77 // fichier envoye par le browser : pour les Macs c'est plus sur)
78
79 $source = deplacer_fichier_upload($source['tmp_name'], $f);
80 }
81 if (!$source)
82 spip_log("pb de copie pour $f");
83 }
84 if ($source AND $f) {
85 $size = @getimagesize($f);
86 $type = !$size ? '': ($size[2] > 3 ? '' : $formats_logos[$size[2]-1]);
87 if ($type) {
88 $poids = filesize($f);
89
90 if (_LOGO_MAX_SIZE > 0
91 AND $poids > _LOGO_MAX_SIZE*1024) {
92 spip_unlink ($f);
93 $erreur = _T('info_logo_max_poids',
94 array('maxi' => taille_en_octets(_LOGO_MAX_SIZE*1024),
95 'actuel' => taille_en_octets($poids)));
96 }
97
98 elseif (_LOGO_MAX_WIDTH * _LOGO_MAX_HEIGHT
99 AND ($size[0] > _LOGO_MAX_WIDTH
100 OR $size[1] > _LOGO_MAX_HEIGHT)) {
101 spip_unlink ($f);
102 $erreur = _T('info_logo_max_poids',
103 array(
104 'maxi' =>
105 _T('info_largeur_vignette',
106 array('largeur_vignette' => _LOGO_MAX_WIDTH,
107 'hauteur_vignette' => _LOGO_MAX_HEIGHT)),
108 'actuel' =>
109 _T('info_largeur_vignette',
110 array('largeur_vignette' => $size[0],
111 'hauteur_vignette' => $size[1]))
112 ));
113 }
114 else
115 @rename ($f, _DIR_LOGOS . $arg . ".$type");
116 }
117 else {
118 spip_unlink ($f);
119 $erreur = _T('info_logo_format_interdit',
120 array('formats' => join(', ', $formats_logos)));
121 }
122
123 }
124 if ($erreur){
125 if ($return)
126 return $erreur;
127 else
128 check_upload_error(6,$erreur);
129 }
130 }
131 ?>