[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / prive / formulaires / configurer_reducteur.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2017 *
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 /**
14 * Formulaire de configuration pour choisir la librairie graphique
15 * et les tailles de redimensionnement des vignettes
16 *
17 * @package SPIP\Core\Formulaires
18 **/
19
20 if (!defined('_ECRIRE_INC_VERSION')) {
21 return;
22 }
23
24 /**
25 * Chargement du formulaire de configuration de la librairie graphique
26 *
27 * @return array
28 * Environnement du formulaire
29 **/
30 function formulaires_configurer_reducteur_charger_dist() {
31 $valeurs = array();
32 foreach (array(
33 'image_process',
34 'formats_graphiques',
35 'creer_preview',
36 'taille_preview',
37 ) as $m) {
38 $valeurs[$m] = isset($GLOBALS['meta'][$m]) ? $GLOBALS['meta'][$m] : null;
39 }
40
41 $valeurs['taille_preview'] = intval($valeurs['taille_preview']);
42 if ($valeurs['taille_preview'] < 10) {
43 $valeurs['taille_preview'] = 120;
44 }
45
46 return $valeurs;
47 }
48
49
50 /**
51 * Traitements du formulaire de configuration de la librairie graphique
52 *
53 * @return array
54 * Retours des traitements
55 **/
56 function formulaires_configurer_reducteur_traiter_dist() {
57 $res = array('editable' => true);
58
59 if (is_array($image_process = _request('image_process_'))) {
60 $image_process = array_keys($image_process);
61 $image_process = reset($image_process);
62
63 // application du choix de vignette
64 if ($image_process) {
65 // mettre a jour les formats graphiques lisibles
66 switch ($image_process) {
67 case 'gd1':
68 case 'gd2':
69 $formats_graphiques = $GLOBALS['meta']['gd_formats_read'];
70 break;
71 case 'netpbm':
72 $formats_graphiques = $GLOBALS['meta']['netpbm_formats'];
73 break;
74 case 'convert':
75 case 'imagick':
76 $formats_graphiques = 'gif,jpg,png';
77 break;
78 default: #debug
79 $formats_graphiques = '';
80 $image_process = 'non';
81 break;
82 }
83 ecrire_meta('formats_graphiques', $formats_graphiques, 'non');
84 ecrire_meta('image_process', $image_process, 'non');
85 }
86 }
87
88 foreach (array(
89 'creer_preview'
90 ) as $m) {
91 if (!is_null($v = _request($m))) {
92 ecrire_meta($m, $v == 'oui' ? 'oui' : 'non');
93 }
94 }
95 if (!is_null($v = _request('taille_preview'))) {
96 ecrire_meta('taille_preview', intval($v));
97 }
98
99 $res['message_ok'] = _T('config_info_enregistree');
100
101 return $res;
102 }
103
104 /**
105 * Indique si une librairie graphique peut être utilisée et retourne alors
106 * une URL pour tester la librairie
107 *
108 * @param string $process
109 * Code de la libriairie, parmi gd2, gd1, netpbm, imagick ou convert
110 * @return string
111 * URL d'action pour tester la librairie graphique en créant une vignette
112 **/
113 function url_vignette_choix($process) {
114 switch ($process) {
115 case 'gd2':
116 if (!function_exists('ImageCreateTrueColor')) {
117 return '';
118 }
119 break;
120 case 'gd1':
121 if (!function_exists('ImageGif')
122 and !function_exists('ImageJpeg')
123 and !function_exists('ImagePng')
124 ) {
125 return '';
126 }
127 break;
128 case 'netpbm':
129 if (defined('_PNMSCALE_COMMAND') and _PNMSCALE_COMMAND == '') {
130 return '';
131 }
132 break;
133 case 'imagick':
134 if (!method_exists('Imagick', 'readImage')) {
135 return '';
136 }
137 break;
138 case 'convert':
139 if (defined('_CONVERT_COMMAND') and _CONVERT_COMMAND == '') {
140 return '';
141 }
142 break;
143 }
144
145 return generer_url_action('tester', "arg=$process&time=" . time());
146 }