[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / inc / legender.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2011 *
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/actions'); // *action_auteur et determine_upload
16 include_spip('inc/presentation');
17 include_spip('inc/documents');
18 include_spip('inc/date');
19
20 // Formulaire de description d'un document (titre, date etc)
21 // En mode Ajax pour eviter de recharger toute la page ou il se trouve
22 // (surtout si c'est un portfolio)
23
24 // http://doc.spip.org/@inc_legender_dist
25 function inc_legender_dist($id_document, $document, $script, $type, $id, $ancre, $deplier=false) {
26
27 // premier appel
28 if ($document) {
29 $flag = $deplier;
30 } elseif (!$id_document) {
31 return '';
32 } else {
33 // retour d'Ajax
34
35 $document = sql_fetsel("*", "spip_documents", "id_document = " . intval($id_document));
36
37 $document['vu'] = sql_getfetsel("vu", 'spip_documents_liens', "id_objet=" . intval($id) ." AND objet=" . sql_quote($type) . " AND id_document=".intval($id_document));
38
39 if (!$document['vu']) $document['vu'] = 'non';
40 $flag = 'ajax';
41 }
42
43 if ($document['mode'] == 'image') {
44 $supp = 'image-24.gif';
45 $label = _T('entree_titre_image');
46 $taille = $vignette = '';
47
48 } else {
49 $supp = 'doc-24.gif';
50 $label = _T('entree_titre_document');
51 $taille = formulaire_taille($document);
52 $vignette = "<div style='margin-bottom: 10px;'>".vignette_formulaire_legender($id_document, $document, $script, $type, $id, $ancre)."</div>";
53 }
54
55 $s = ($ancre =='documents' ? '': '-');
56 $corps = legender_corps($ancre, $flag, $id, $id_document, $script, $type, $document, $label, $taille) .
57 $vignette .
58 "\n\n" .
59 legender_suppression($id, $id_document, $ancre, $s, $script, $supp, $type);
60
61 // ne pas afficher le bouton de changement dans le portfolio ?
62 // mais tout cela n'est pas tr�s extensible et declenchera d'autres bugs plus tard...
63 if (preg_match(",_edit,",$script))
64 $corps .= legender_image_doc($document, $id_document, $id, $type, $s, $script, $ancre);
65
66 $corps = block_parfois_visible("legender-aff-$id_document", legender_entete($document), $corps, "text-align:center;", $flag);
67
68 return ajax_action_greffe("legender", $id_document, $corps);
69 }
70
71
72 function legender_entete($document)
73 {
74 $titre = $document['titre'];
75 $entete = basename($document['fichier']);
76 if (($n=strlen($entete)) > 20)
77 $entete = substr($entete, 0, 7)."...".substr($entete, $n-7, $n);
78 if (strlen($titre))
79 $entete = "<strong>". lignes_longues(typo($titre),25) . "</strong>";
80 return sinon($entete,_T('info_sans_titre'));
81 }
82
83 function legender_suppression($id, $id_document, $ancre, $s, $script, $supp, $type)
84 {
85 // le cas $id<0 correspond a un doc charge dans un article pas encore cree,
86 // et ca buggue si on propose de supprimer => on ne propose pas
87 // Le cas id = 0 correspond au cas d'une mediatheque : l'action est alors
88 // sans doute a revoir car le document serait alors peut-etre orphelin
89
90 if ($id <= 0) return '';
91
92 // la fonction 'supprimer_document' ne fait que de-associer si un document est utilise par ailleurs
93 $texte = _T('icone_supprimer_document');
94
95 if (preg_match('/_edit$/', $script)) {
96 $action = ajax_action_auteur('documenter', "$s$id/$type/$id_document", $script, "id_$type=$id&type=$type&s=$s#$ancre", array($texte), '', 'function() {jQuery(this).remove()}');
97 } else {
98 if (test_espace_prive())
99 $action = ajax_action_auteur('documenter', "$s$id/$type/$id_document", $script, "id_$type=$id&type=$type&s=$s#$ancre", array($texte));
100 else{
101 $redirect = str_replace('&amp;','&',$script);
102 $action = generer_action_auteur('documenter', "$s$id/$type/$id_document", $redirect);
103 $action = "<a href='$action'>$texte</a>";
104 }
105 }
106
107 return icone_horizontale($texte, $action, $supp, "supprimer.gif", false);
108 }
109
110
111 function legender_corps($ancre, $flag, $id, $id_document, $script, $type, $document, $label, $taille)
112 {
113 include_spip('inc/editer');
114
115 $contenu = '';
116 $descriptif = $document['descriptif'];
117 if ($descriptif)
118 $contenu .= "<p>".PtoBR(lignes_longues(propre($descriptif),25)) . "</p>\n";
119 if ($document['largeur'] OR $document['hauteur'])
120 $contenu .= _T('info_largeur_vignette',
121 array('largeur_vignette' => $document['largeur'],
122 'hauteur_vignette' => $document['hauteur']))
123 . ' &mdash; ';
124
125 $contenu .= taille_en_octets($document['taille']);
126
127 $date = $document['date'];
128 if ($date AND ($GLOBALS['meta']["documents_date"] == 'oui'))
129 $contenu .= "<br />\n" . affdate($date);
130
131 $corps = (!$contenu ? '' :
132 "<div class='verdana1' style='text-align: center; margin-bottom: 10px;'>$contenu</div>") .
133 "<div class='formulaire_spip formulaire_spip_compact'><ul><li class='editer_titre'><label for='titre_document$id_document'>$label</label>\n" .
134
135 "<input type='text' name='titre_document' id='titre_document$id_document' class='text' value=\"".entites_html($document['titre']).
136 "\" size='40' onfocus=\"changeVisible(true, 'valider_doc$id_document', 'block', 'block');\" /></li>\n"
137 . (($GLOBALS['meta']["documents_date"] == 'oui')
138 ? "<li class='editer_date'>".date_formulaire_legender($date, $id_document)."</li>"
139 :'' )
140 . "<li class='editer_descriptif'><label for='descriptif_document$id_document'>".
141 _T('info_description_2').
142 "</label>\n" .
143 "<textarea name='descriptif_document' id='descriptif_document$id_document' rows='4' class='textarea' cols='*' onfocus=\"changeVisible(true, 'valider_doc$id_document', 'block', 'block');\">" .
144 entites_html($descriptif) .
145 "</textarea></li></ul></div>\n" .
146 $taille
147
148 .controles_md5($document);
149
150 $att_bouton = "";
151
152 $att_span = " id='valider_doc$id_document' "
153 . ($flag == 'ajax' ? '' : "class='display_au_chargement'")
154 . " style='text-align:"
155 . $GLOBALS['spip_lang_right']
156 . ($flag == 'ajax' ? ';display:block' : "")
157 . "'";
158
159 if (test_espace_prive())
160 return ajax_action_post("legender", $id_document, $script, "show_docs=$id_document&id_$type=$id#legender-$id_document", $corps, _T('bouton_enregistrer'), $att_bouton, $att_span, "&id_document=$id_document&id=$id&type=$type&ancre=$ancre")
161 . "<div class='nettoyeur'></div>";
162 else {
163 $corps = "<div class='boutons'>"
164 . $corps
165 . "<span"
166 . $att_span
167 . "><input type='submit' value='"
168 . _T('bouton_enregistrer')
169 ."' /></span></div>";
170 $redirect = parametre_url($script,'show_docs',$id_document,'&');
171 $redirect = parametre_url($redirect,"id_$type",$id,'&');
172 $redirect = parametre_url($redirect,"id_$type",$id,'&');
173 $redirect = ancre_url($redirect,"legender-$id_document");
174 return generer_action_auteur("legender", $id_document, $redirect, $corps, "\nmethod='post'");
175 }
176 }
177
178 //
179 // Changement de mode image/document
180 //
181 function legender_image_doc($document, $id_document, $id, $type, $s, $script, $ancre)
182 {
183 define('_INTERFACE_DOCUMENTS', true);
184 define('_BOUTON_MODE_IMAGE', true);
185 if (!_INTERFACE_DOCUMENTS) return '';
186 if (!_BOUTON_MODE_IMAGE
187 OR !in_array($document['extension'], array('jpg', 'gif', 'png')))
188 return '';
189 if ($document['mode'] == 'image') {
190 $texte = _T('upload_info_mode_document');
191 $mode = 'document';
192 $logo = 'doc-24.gif';
193 } else {
194 $texte = _T('upload_info_mode_image');
195 $mode = 'image';
196 $logo = 'image-24.gif';
197 }
198
199 $action = redirige_action_auteur('changer_mode_document', "$id_document/$mode", $script,
200 (($id>0)
201 ? "id_$type=$id"
202 : "new=oui"
203 ) . "&type=$type&s=$s#$ancre");
204
205 return icone_horizontale($texte, $action, $logo, '', false," onclick=\"jQuery('#document$id_document').parent().animeajax().load(this.href+'&afficher_case=$id-$type-$script&var_noajax=1');return false;\"");
206 }
207
208
209 // http://doc.spip.org/@vignette_formulaire_legender
210 function vignette_formulaire_legender($id_document, $document, $script, $type, $id, $ancre)
211 {
212 $id_vignette = $document['id_vignette'];
213 $texte = _T('info_supprimer_vignette');
214
215 $s = ($ancre =='documents' ? '': '-');
216 if (preg_match('/_edit$/', $script)) {
217 $iframe_redirect = generer_url_ecrire("documents_colonne","id=$id&type=$type",true);
218 $action = redirige_action_auteur('documenter', "$s$id/$type/$id_vignette", $script, "id_$type=$id&show_docs=$id_document#$ancre");
219 } else {
220 $iframe_redirect = generer_url_ecrire("documenter","id_$type=$id&type=$type",true);
221 $action = ajax_action_auteur('documenter', "$s$id/$type/$id_vignette", $script, "id_$type=$id&type=$type&s=$s&show_docs=$id_document#$ancre", array($texte),'',"function(r,noeud) {noeud.innerHTML = r; \$('form.form_upload',noeud).async_upload(async_upload_portfolio_documents);}");
222 }
223
224 $joindre = charger_fonction('joindre', 'inc');
225
226 $supprimer = icone_horizontale($texte, $action, "vignette-24.png", "supprimer.gif", false);
227 if ($id<0) $supprimer = ''; // cf. ci-dessus, article pas encore cree
228
229 return "<hr style='margin-left: -5px; margin-right: -5px; height: 1px; border: 0px; color: #eeeeee; background-color: white;' />"
230 . (!$id_vignette
231 ? $joindre(array(
232 'script' => $script,
233 'args' => "id_$type=$id",
234 'id' => $id,
235 'intitule' => _T('info_vignette_personnalisee'),
236 'mode' => 'vignette',
237 'type' => $type,
238 'ancre' => $ancre,
239 'id_document' => $id_document,
240 'titre' => '',
241 'iframe_script' => $iframe_redirect
242 ))
243 : $supprimer
244 );
245 }
246
247
248 // Bloc d'edition de la taille du doc (pour embed)
249 // http://doc.spip.org/@formulaire_taille
250 function formulaire_taille($document) {
251
252 // (on ne le propose pas pour les images qu'on sait
253 // lire : gif jpg png), sauf bug, ou document distant
254 if (in_array($document['extension'], array('gif','jpg','png'))
255 AND $document['hauteur']
256 AND $document['largeur']
257 AND $document['distant']!='oui')
258 return '';
259 $id_document = $document['id_document'];
260
261 // Donnees sur le type de document
262 $extension = $document['extension'];
263 $t = sql_fetsel('inclus','spip_types_documents', "extension=".sql_quote($extension));
264 $type_inclus = $t['inclus'];
265
266 # TODO -- pour le MP3 "l x h pixels" ne va pas
267 if (($type_inclus == "embed" OR $type_inclus == "image")
268 AND (
269 // documents dont la taille est definie
270 ($document['largeur'] * $document['hauteur'])
271 // ou distants
272 OR $document['distant'] == 'oui'
273 // ou tous les formats qui s'affichent en embed
274 OR $type_inclus == "embed"
275 )) {
276 return "\n<br /><label for='largeur_document$id_document'>"._T('entree_dimensions')."</label><br />\n" .
277 "<input type='text' name='largeur_document' id='largeur_document$id_document' class='spip_xx-small' value=\"".$document['largeur']."\" size='5' onfocus=\"changeVisible(true, 'valider_doc$id_document', 'block', 'block');\" />" .
278 " &times; <input type='text' name='hauteur_document' id='hauteur_document$id_document' class='spip_xx-small' value=\"".$document['hauteur']."\" size='5' onfocus=\"changeVisible(true, 'valider_doc$id_document', 'block', 'block');\" /> "._T('info_pixels');
279 }
280 }
281
282 // http://doc.spip.org/@date_formulaire_legender
283 function date_formulaire_legender($date, $id_document) {
284
285 if (preg_match(",([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}),", $date, $regs)){
286 $mois = $regs[2];
287 $jour = $regs[3];
288 $annee = $regs[1];
289 $heure = $regs[4];
290 $minute = $regs[5];
291 }
292
293 return "<div>"._T('info_mise_en_ligne')."<br />\n" .
294 afficher_jour($jour, "name='jour_doc' id='jour_doc$id_document' size='1' class='spip_xx-small'\n\tonchange=\"changeVisible(true, 'valider_doc$id_document', 'block', 'block');\"") .
295 afficher_mois($mois, "name='mois_doc' id='mois_doc$id_document' size='1' class='spip_xx-small'\n\tonchange=\"changeVisible(true, 'valider_doc$id_document', 'block', 'block');\"") .
296 afficher_annee($annee, "name='annee_doc' id='annee_doc$id_document' size='1' class='spip_xx-small'\n\tonchange=\"changeVisible(true, 'valider_doc$id_document', 'block', 'block')\"") .
297 "<br />".
298 afficher_heure($heure, "name='heure_doc' size='1' class='spip_xx-small'\n\tonchange=\"changeVisible(true, 'valider_doc$id_document', 'block', 'block')\"") .
299 " : ".
300 afficher_minute($minute, "name='minute_doc' size='1' class='spip_xx-small'\n\tonchange=\"changeVisible(true, 'valider_doc$id_document', 'block', 'block')\"") .
301 "<br /><br /></div>\n";
302
303 }
304
305 ?>