X-Git-Url: http://git.cyclocoop.org/?p=velocampus%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fecrire%2Finc%2Fdocuments.php;fp=www%2Fecrire%2Finc%2Fdocuments.php;h=daa3e2aca5c79d4c29e04a84d67cd78c12aed359;hp=0000000000000000000000000000000000000000;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c
diff --git a/www/ecrire/inc/documents.php b/www/ecrire/inc/documents.php
new file mode 100644
index 0000000..daa3e2a
--- /dev/null
+++ b/www/ecrire/inc/documents.php
@@ -0,0 +1,527 @@
+ c'est a ca que sert la variable $portfolio
+// http://doc.spip.org/@vignette_automatique
+function vignette_automatique($img, $doc, $lien, $x=0, $y=0, $align='', $class='spip_logos')
+{
+ include_spip('inc/distant');
+ include_spip('inc/texte');
+ include_spip('inc/filtres_images_mini');
+ $e = $doc['extension'];
+ if (!$img) {
+ if ($img = image_du_document($doc)) {
+ if (!$x AND !$y) // eviter une double reduction
+ $img = image_reduire($img);
+ }
+ else{
+ $f = charger_fonction('vignette','inc');
+ $img = $f($e, false);
+ $size = @getimagesize($img);
+ $img = "";
+ }
+ }
+ else{
+ $size = @getimagesize($img);
+ $img = "";
+ }
+ // on appelle image_reduire independamment de la presence ou non
+ // des librairies graphiques
+ // la fonction sait se debrouiller et faire de son mieux dans tous les cas
+ if ($x OR $y) {
+ $img = image_reduire($img, $x, $y);
+ }
+ $img = inserer_attribut($img, 'alt', '');
+ $img = inserer_attribut($img, 'class', $class);
+ if ($align) $img = inserer_attribut($img, 'align', $align);
+
+ if (!$lien) return $img;
+
+ $titre = supprimer_tags(typo($doc['titre']));
+ $titre = " - " .taille_en_octets($doc['taille'])
+ . ($titre ? " - $titre" : "");
+
+ $type = sql_fetsel('titre, mime_type','spip_types_documents', "extension = " . sql_quote($e));
+
+ $mime = $type['mime_type'];
+ $titre = attribut_html(couper($type['titre'] . $titre, 80));
+
+ return "$img";
+}
+
+// Trouve une image caracteristique d'un document.
+// Si celui-ci est une image et que les outils graphiques sont dispos,
+// retourner le document (en exploitant sa copie locale s'il est distant).
+// Autrement retourner la vignette fournie par SPIP pour ce type MIME
+// Resultat: un fichier local existant
+
+function image_du_document($document)
+{
+ $e = $document['extension'];
+ if ((strpos($GLOBALS['meta']['formats_graphiques'], $e) !== false)
+ AND (!test_espace_prive() OR $GLOBALS['meta']['creer_preview']=='oui')
+ AND $document['fichier']) {
+ if ($document['distant'] == 'oui') {
+ $image = _DIR_RACINE.copie_locale($document['fichier']);
+ }
+ else
+ $image = get_spip_doc($document['fichier']);
+ if (@file_exists($image)) return $image;
+ }
+ return '';
+}
+
+//
+// Afficher un document dans la colonne de gauche
+//
+
+// http://doc.spip.org/@afficher_documents_colonne
+function afficher_documents_colonne($id, $type="article",$script=NULL) {
+ include_spip('inc/autoriser');
+
+ // il faut avoir les droits de modif sur l'article pour pouvoir uploader !
+ if (!autoriser('joindredocument',$type,$id))
+ return "";
+
+ include_spip('inc/presentation'); // pour l'aide quand on appelle afficher_documents_colonne depuis un squelette
+ // seuls cas connus : article, breve ou rubrique
+ if ($script==NULL){
+ $script = $type.'s_edit';
+ if (!test_espace_prive())
+ $script = parametre_url(self(),"show_docs",'');
+ }
+ $id_document_actif = _request('show_docs');
+
+ $joindre = charger_fonction('joindre', 'inc');
+
+ define('_INTERFACE_DOCUMENTS', true);
+ if (!_INTERFACE_DOCUMENTS
+ OR $GLOBALS['meta']["documents_$type"]=='non') {
+
+ // Ajouter nouvelle image
+ $ret = "
\n"
+ . $joindre(array(
+ 'cadre' => 'relief',
+ 'icone' => 'image-24.gif',
+ 'fonction' => 'creer.gif',
+ 'titre' => majuscules(_T('bouton_ajouter_image')).aide("ins_img"),
+ 'script' => $script,
+ 'args' => "id_$type=$id",
+ 'id' => $id,
+ 'intitule' => _T('info_telecharger'),
+ 'mode' => 'image',
+ 'type' => $type,
+ 'ancre' => '',
+ 'id_document' => 0,
+ 'iframe_script' => generer_url_ecrire("documents_colonne","id=$id&type=$type",true)
+ ))
+ . '
';
+
+ if (!_INTERFACE_DOCUMENTS) {
+ //// Images sans documents
+ $res = sql_select("D.id_document", "spip_documents AS D LEFT JOIN spip_documents_liens AS T ON T.id_document=D.id_document", "T.id_objet=" . intval($id) . " AND T.objet=" . sql_quote($type) . " AND D.mode='image'", "", "D.id_document");
+
+ $ret .= "\n";
+
+ while ($doc = sql_fetch($res)) {
+ $id_document = $doc['id_document'];
+ $deplier = ($id_document_actif==$id_document);
+ $ret .= afficher_case_document($id_document, $id, $script, $type, $deplier);
+ }
+
+ $ret .= "
\n";
+ }
+ }
+
+ /// Ajouter nouveau document
+ $bouton = !_INTERFACE_DOCUMENTS
+ ? majuscules(_T('bouton_ajouter_document')).aide("ins_doc")
+ : (_T('bouton_ajouter_image_document')).aide("ins_doc");
+
+ $ret .= "\n\n";
+ if ($GLOBALS['meta']["documents_$type"]!='non') {
+ $ret .= $joindre(array(
+ 'cadre' => _INTERFACE_DOCUMENTS ? 'relief' : 'enfonce',
+ 'icone' => 'doc-24.gif',
+ 'fonction' => 'creer.gif',
+ 'titre' => $bouton,
+ 'script' => $script,
+ 'args' => "id_$type=$id",
+ 'id' => $id,
+ 'intitule' => _T('info_telecharger'),
+ 'mode' => _INTERFACE_DOCUMENTS ? 'choix' : 'document',
+ 'type' => $type,
+ 'ancre' => '',
+ 'id_document' => 0,
+ 'iframe_script' => generer_url_ecrire("documents_colonne","id=$id&type=$type",true)
+ ));
+ }
+
+ // Afficher les documents lies
+ $ret .= "
\n";
+
+ //// Documents associes
+ $res = sql_select("D.id_document", "spip_documents AS D LEFT JOIN spip_documents_liens AS T ON T.id_document=D.id_document", "T.id_objet=" . intval($id) . " AND T.objet=" . sql_quote($type)
+ . ((!_INTERFACE_DOCUMENTS)
+ ? " AND D.mode='document'"
+ : " AND D.mode IN ('image','document')"
+ ), "", "D.mode, D.id_document");
+
+ while($row = sql_fetch($res))
+ $ret .= afficher_case_document($row['id_document'], $id, $script, $type, ($id_document_actif==$row['id_document']));
+
+ $ret .= "
";
+ if (test_espace_prive()){
+ $ret .= http_script('', "async_upload.js")
+ . http_script('$("form.form_upload").async_upload(async_upload_article_edit)');
+ }
+
+ return $ret;
+}
+
+//
+// Affiche le raccourci
+// et l'insere quand on le clique
+//
+// http://doc.spip.org/@affiche_raccourci_doc
+function affiche_raccourci_doc($doc, $id, $align) {
+ static $num = 0;
+
+ if ($align) {
+ $pipe = "|$align";
+
+ if ($GLOBALS['browser_barre'])
+ $onclick = "\nondblclick=\"barre_inserer('\\x3C$doc$id$pipe>', $('textarea[name=texte]')[0]);\"\ntitle=\"". str_replace('&', '&', entites_html(_T('double_clic_inserer_doc')))."\"";
+ } else {
+ $align='center';
+ }
+
+ return
+ ((++$num > 1) ? "" : http_script('', "spip_barre.js"))
+ . "\n<$doc$id$pipe>
\n";
+}
+
+
+// Est-ce que le document est inclus dans le texte ?
+// http://doc.spip.org/@est_inclus
+function est_inclus($id_document) {
+ return isset($GLOBALS['doublons_documents_inclus']) ?
+ in_array($id_document,$GLOBALS['doublons_documents_inclus']) : false;
+}
+
+//
+// Afficher un document sous forme de bloc depliable
+// en donnant un apercu
+// et en indiquer le raccourci permettant l'incrustation
+// Pour les distant, donner un bouton pour rappatriement (trombone)
+// Pour les images, donnner les boutons de rotations
+
+
+// http://doc.spip.org/@afficher_case_document
+function afficher_case_document($id_document, $id, $script, $type, $deplier=false) {
+ global $spip_lang_right;
+
+ $document = sql_fetsel("D.id_document, D.id_vignette,D.extension,D.titre,D.descriptif,D.fichier,D.largeur,D.hauteur,D.taille,D.mode,D.distant, D.date, L.vu", "spip_documents AS D INNER JOIN spip_documents_liens AS L ON L.id_document=D.id_document", "L.id_objet=".intval($id)." AND objet=".sql_quote($type)." AND L.id_document=".intval($id_document));
+
+ if (!$document) return "";
+
+ $id_vignette = $document['id_vignette'];
+ $extension = $document['extension'];
+ $descriptif = $document['descriptif'];
+ $fichier = $document['fichier'];
+ $largeur = $document['largeur'];
+ $hauteur = $document['hauteur'];
+ $mode = $document['mode'];
+ $distant = $document['distant'];
+ $titre = $document['titre'];
+ $legender = charger_fonction('legender', 'inc');
+ $dist = '';
+
+ $r = sql_fetsel("titre,inclus", "spip_types_documents", "extension=".sql_quote($extension));
+ if ($r) {
+ $type_inclus = $r['inclus'];
+ $type_titre = $r['titre'];
+ }
+
+ if ($mode == 'document') {
+
+ if ($distant == 'oui') {
+ include_spip('inc/tourner');
+ $dist = "\n"
+ . "\n
\n"
+ . bouton_copier_local($document, $type, $id, $id_document, $script)
+ . "
\n";
+ }
+
+ if (est_inclus($id_document))
+ $raccourci = affiche_raccourci_doc('doc', $id_document, '');
+ else {
+ $vign= (($type_inclus == "embed" OR $type_inclus == "image") AND $largeur > 0 AND $hauteur > 0);
+ $raccourci = $vign ? (""._T('info_inclusion_vignette')."
") : '';
+
+ $raccourci .= ""
+ . affiche_raccourci_doc('doc', $id_document, 'left')
+ . affiche_raccourci_doc('doc', $id_document, 'center')
+ . affiche_raccourci_doc('doc', $id_document, 'right')
+ . "
\n";
+
+ if ($vign) {
+ $raccourci .= "";
+ $raccourci .= "
"._T('info_inclusion_directe')."";
+ $raccourci .= "
"
+ . affiche_raccourci_doc('emb', $id_document, 'left')
+ . affiche_raccourci_doc('emb', $id_document, 'center')
+ . affiche_raccourci_doc('emb', $id_document, 'right')
+ . "
\n";
+ $raccourci .= "
";
+ }
+ }
+ $ninclus = false;
+ $icone = 'doc-24.gif';
+ $style = 'e';
+
+ } else if ($mode == 'image') {
+
+ $icone = 'image-24.gif';
+ $style = 'r';
+ $ninclus = ($type_inclus !== 'image');
+ $doc = ($descriptif OR $titre) ? 'doc' : 'img';
+
+ if (est_inclus($id_document))
+ $raccourci = affiche_raccourci_doc($doc, $id_document, '');
+ else {
+ $raccourci =
+ affiche_raccourci_doc($doc, $id_document, 'left')
+ . affiche_raccourci_doc($doc, $id_document, 'center')
+ . affiche_raccourci_doc($doc, $id_document, 'right');
+ }
+
+ }
+ $cadre = lignes_longues(typo($titre ? $titre : basename($fichier)), 20);
+ // encapsuler chaque document dans un container pour permettre son remplacement en ajax
+ return ''
+ . debut_cadre($style, $icone, '', $cadre, "document$id_document")
+ . ($ninclus ? '' :
+ ("\n
"
+ . $dist
+ . document_et_vignette($document, '', true)
+ . '
'
+ . "\n
\n"
+ . ($type_titre ? $type_titre :
+ ( _T('info_document').' '.majuscules($extension)))
+ . "
"))
+ . $apercu
+ . "\n
"
+ . $raccourci
+ . "
\n"
+ . $legender($id_document, $document, $script, $type, $id, "document$id_document", $deplier)
+ . fin_cadre($style)
+ . '
';
+}
+
+// Etablit la liste des documents orphelins, c'est-a-dire qui ne sont lies
+// a rien ; renvoie un tableau (id_document)
+// ici on ne join pas avec la table objet pour voir si l'objet existe vraiment
+// on considere que c'est le role d'optimiser que de nettoyer les liens morts
+// sinon eventuellement appeler avant une fonction nettoyer_liens_documents
+// http://doc.spip.org/@lister_les_documents_orphelins
+function lister_les_documents_orphelins() {
+ $s = sql_select("D.id_document, D.id_vignette", "spip_documents AS D LEFT JOIN spip_documents_liens AS L ON D.id_document=L.id_document", "(L.id_objet IS NULL)");
+
+ $orphelins = array();
+ while ($t = sql_fetch($s)) {
+ $orphelins[$t['id_document']] = true;
+ // la vignette d'un orphelin est orpheline
+ if ($t['id_vignette'])
+ $orphelins[$t['id_vignette']] = true;
+
+ }
+
+ // les vignettes qui n'appartiennent a aucun document sont aussi orphelines
+ $s = sql_select("V.id_document", "spip_documents AS V LEFT JOIN spip_documents AS D ON V.id_document=D.id_vignette", "V.mode='vignette' AND D.id_document IS NULL");
+ while ($t = sql_fetch($s))
+ $orphelins[$t['id_document']] = true;
+
+ return array_keys(array_filter($orphelins));
+}
+
+// Supprimer les documents de la table spip_documents,
+// ainsi que les fichiers correspondants dans IMG/
+// Fonction a n'appeler que sur des documents orphelins
+// http://doc.spip.org/@supprimer_documents
+function supprimer_documents($liste = array()) {
+ if (!count($liste))
+ return;
+
+ $in = sql_in('id_document', $liste);
+
+ // Supprimer les fichiers locaux et les copies locales
+ // des docs distants
+ $s = sql_select("fichier, distant", "spip_documents", $in);
+ while ($t = sql_fetch($s)) {
+ if ($t['distant'] == 'oui') {
+ include_spip('inc/distant');
+ if ($local = copie_locale($t['fichier'], 'test'))
+ spip_log("efface $local = ".$t['fichier']);
+ supprimer_fichier($local);
+ }
+ else {
+ if (@file_exists($f = get_spip_doc($t['fichier']))) {
+ spip_log("efface $f");
+ supprimer_fichier($f);
+ }
+ }
+ }
+
+ // Supprimer les entrees dans spip_documents et associees
+ sql_delete('spip_documents', $in);
+ // en principe il ne devrait rien y avoir ici si les documents sont bien orphelins
+ sql_delete('spip_documents_liens', $in);
+}
+
+?>