3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
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 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
15 include_spip('inc/actions'); // *action_auteur
16 include_spip('inc/documents');
17 include_spip('inc/filtres');
19 // http://doc.spip.org/@inc_tourner_dist
20 function inc_tourner_dist($id_document, $document, $script, $flag, $type)
22 global $spip_lang_right;
26 $document = sql_fetsel("*", "spip_documents", "id_document = " . intval($id_document));
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)));
33 $titre = $document['titre'];
34 $id_vignette = $document['id_vignette'];
35 $fichier = entites_html($document['fichier']);
37 if (isset($document['url']))
38 $url = $document['url'];
40 $url = generer_url_entite($id_document, 'document');
45 // Indiquer les documents manquants avec un panneau de warning
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\" />";
54 if ($flag AND !$id_vignette)
55 $res = boutons_rotateurs($document, $type, $id, $id_document,$script);
58 $res = "\n<div class='verdana1' style='float: $spip_lang_right; text-align: $spip_lang_right;'>";
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);
67 return tourner_greffe($id_document, $document, $url, $res);
70 // http://doc.spip.org/@tourner_greffe
71 function tourner_greffe($id_document, $document, $url, $res)
73 $res .= "<div style='text-align: center;'>"
74 .document_et_vignette($document, $url, true)
76 ."<div style='text-align: center; color: 333333;' class='verdana1 spip_x-small'><doc"
80 return ajax_action_greffe("tourner", $id_document, $res);
83 // http://doc.spip.org/@boutons_rotateurs
84 function boutons_rotateurs($document, $type, $id, $id_document, $script) {
85 global $spip_lang_right;
87 $process = $GLOBALS['meta']['image_process'];
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'
98 OR $process == 'convert'
99 OR $process == 'netpbm')
100 AND @file_exists
(get_spip_doc($document['fichier']))
103 return "\n<div class='verdana1' style='float: $spip_lang_right; text-align: $spip_lang_right;'>" .
105 bouton_tourner_document($id, $id_document, $script, -90, $type, 'tourner-gauche-10.gif', _T('image_tourner_gauche')) .
107 bouton_tourner_document($id, $id_document, $script, 90, $type, 'tourner-droite-10.gif', _T('image_tourner_droite')) .
109 bouton_tourner_document($id, $id_document, $script, 180, $type, 'tourner-demitour-10.gif', _T('image_tourner_180')) .
114 // http://doc.spip.org/@bouton_tourner_document
115 function bouton_tourner_document($id, $id_document, $script, $rot, $type, $img, $title)
117 return ajax_action_auteur("tourner",
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");
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;
131 // pour etre sur qu'il s'agit bien d'un doc distant
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",
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");
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);
157 return $bouton_copier;