[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / inc / tourner.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
16 include_spip('inc/documents');
17 include_spip('inc/filtres');
18
19 // http://doc.spip.org/@inc_tourner_dist
20 function inc_tourner_dist($id_document, $document, $script, $flag, $type)
21 {
22 global $spip_lang_right;
23
24 if (!$document) {
25 // retour d'Ajax
26 $document = sql_fetsel("*", "spip_documents", "id_document = " . intval($id_document));
27 }
28
29 $prim = 'id_' . $type;
30 // si pas de doc le hash sera inutilisable
31 $id = intval(sql_getfetsel('id_objet', 'spip_documents_liens', "objet=".sql_quote($type)." AND id_document = " . intval($id_document)));
32
33 $titre = $document['titre'];
34 $id_vignette = $document['id_vignette'];
35 $fichier = entites_html($document['fichier']);
36
37 if (isset($document['url']))
38 $url = $document['url'];
39 else {
40 $url = generer_url_entite($id_document, 'document');
41 }
42
43 $res = '';
44
45 // Indiquer les documents manquants avec un panneau de warning
46
47 if ($document['distant'] != 'oui') {
48 if (!@file_exists(get_spip_doc($document['fichier']))){
49 $c = _T('fichier_introuvable',
50 array('fichier'=>basename($document['fichier'])));
51 $res = "<img src='" . chemin_image('warning-24.gif')
52 ."'\n\tstyle='float: right;'\n\talt=\"$c\"\n\ttitle=\"$c\" />";
53 } else {
54 if ($flag AND !$id_vignette)
55 $res = boutons_rotateurs($document, $type, $id, $id_document,$script);
56 }
57 } else {
58 $res = "\n<div class='verdana1' style='float: $spip_lang_right; text-align: $spip_lang_right;'>";
59
60 // Signaler les documents distants par une icone de trombone
61 $res .= "<img src='" . chemin_image('attachment.gif') . "'\n\t \n\talt=\"$fichier\"\n\ttitle=\"$fichier\" />\n";
62 // Bouton permettant de copier en local le fichier
63 $res .= bouton_copier_local($document, $type, $id, $id_document, $script);
64
65 $res .= "</div>\n";
66 }
67 return tourner_greffe($id_document, $document, $url, $res);
68 }
69
70 // http://doc.spip.org/@tourner_greffe
71 function tourner_greffe($id_document, $document, $url, $res)
72 {
73 $res .= "<div style='text-align: center;'>"
74 .document_et_vignette($document, $url, true)
75 ."</div>\n"
76 ."<div style='text-align: center; color: 333333;' class='verdana1 spip_x-small'>&lt;doc"
77 . $id_document
78 . "&gt;</div>";
79
80 return ajax_action_greffe("tourner", $id_document, $res);
81 }
82
83 // http://doc.spip.org/@boutons_rotateurs
84 function boutons_rotateurs($document, $type, $id, $id_document, $script) {
85 global $spip_lang_right;
86
87 $process = $GLOBALS['meta']['image_process'];
88
89 // bloc rotation de l'image
90 // si c'est une image, qu'on sait la faire tourner, qu'elle
91 // n'est pas distante, qu'elle est bien presente dans IMG/
92 // qu'elle n'a pas de vignette perso ; et qu'on a la bibli !
93 if ($document['distant']!='oui'
94 AND in_array($document['extension'], array('gif', 'jpg', 'png'))
95 AND (strpos($GLOBALS['meta']['formats_graphiques'], $document['extension'])!==false)
96 AND ($process == 'imagick'
97 OR $process == 'gd2'
98 OR $process == 'convert'
99 OR $process == 'netpbm')
100 AND @file_exists(get_spip_doc($document['fichier']))
101 ) {
102
103 return "\n<div class='verdana1' style='float: $spip_lang_right; text-align: $spip_lang_right;'>" .
104
105 bouton_tourner_document($id, $id_document, $script, -90, $type, 'tourner-gauche-10.gif', _T('image_tourner_gauche')) .
106
107 bouton_tourner_document($id, $id_document, $script, 90, $type, 'tourner-droite-10.gif', _T('image_tourner_droite')) .
108
109 bouton_tourner_document($id, $id_document, $script, 180, $type, 'tourner-demitour-10.gif', _T('image_tourner_180')) .
110 "</div>\n";
111 }
112 }
113
114 // http://doc.spip.org/@bouton_tourner_document
115 function bouton_tourner_document($id, $id_document, $script, $rot, $type, $img, $title)
116 {
117 return ajax_action_auteur("tourner",
118 "$id_document-$rot",
119 $script,
120 "show_docs=$id_document&id_$type=$id#tourner-$id_document",
121 array(http_img_pack($img, $title, ''),
122 " class='bouton_rotation'"),
123 "&id_document=$id_document&id=$id&type=$type");
124 }
125
126 // Retourne le code HTML du bouton "copier en local".
127 // http://doc.spip.org/@bouton_copier_local
128 function bouton_copier_local($document, $type, $id, $id_document, $script) {
129 global $spip_lang_right;
130
131 // pour etre sur qu'il s'agit bien d'un doc distant
132 // et qu'il existe
133 $bouton_copier = '';
134 if ($document['distant'] == 'oui' /* on pourrait verifier l'existence du
135 // fichier ici, mais ne risque pas-t-on de degrader les performances ?
136 // il sera toujours temps de le verifier lorsque l'utilisateur cliquera
137 // sur le bouton. */) {
138 $bouton_copier = ajax_action_auteur("copier_local",
139 "$id_document",
140 $script,
141 "show_docs=$id_document&id_$type=$id#tourner-$id_document",
142 array(http_img_pack('telecharger.gif', _T('copier_en_local'), ''),
143 " class='bouton_rotation'"),
144 // on aurait pu faire un nouveau style 'bouton-telecharger',
145 // mais pour l'instant on se contente de reutiliser celui-ci
146 // afin de garder une homogeneite entre les differents boutons.
147 "&id_document=$id_document&id=$id&type=$type");
148
149
150 // Hack ?
151 // demander confirmation javascript
152 $u = str_replace("'", "\\'", unicode_to_javascript(html2unicode(_T('copier_en_local') . ' ' . $document['fichier'])));
153 $bouton_copier = str_replace('return AjaxSqueeze',
154 "return (!confirm('$u'))?false:AjaxSqueeze", $bouton_copier);
155 }
156
157 return $bouton_copier;
158 }
159 ?>