PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/_plugins_/mots_partout/2.0/inc/legender.php

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