From 00de0b972a098586727cdc1eeeada6e9916c3b8f Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Sat, 8 Oct 2005 07:07:09 +0000 Subject: [PATCH] spip_image enfin generique, meme qu'elle a fusionne avec spip_acces_doc qui peut sauter --- .gitattributes | 1 + ecrire/config-fonctions.php3 | 2 +- ecrire/inc_documents.php3 | 24 +- ecrire/inc_getdocument.php3 | 391 ---------------------- ecrire/inc_logos.php3 | 10 +- ecrire/inc_spip_image.php | 621 +++++++++++++++++++++++++++++++++++ ecrire/inc_urls.php3 | 2 +- inc-urls-html.php3 | 2 +- inc-urls-propres.php3 | 4 +- inc-urls-standard.php3 | 2 +- spip_acces_doc.php3 | 77 +---- spip_image.php3 | 78 +---- 12 files changed, 657 insertions(+), 557 deletions(-) create mode 100644 ecrire/inc_spip_image.php diff --git a/.gitattributes b/.gitattributes index 4343ec31fb..f95059008e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -268,6 +268,7 @@ ecrire/inc_lang_liste.php -text ecrire/inc_magicquotes.php -text ecrire/inc_mini_nav.php -text ecrire/inc_naviguer.php -text +ecrire/inc_spip_image.php -text ecrire/lang/ecrire_ru.php3 -text ecrire/lang/public_ru.php3 -text ecrire/lang/spip_ru.php3 -text diff --git a/ecrire/config-fonctions.php3 b/ecrire/config-fonctions.php3 index ae088ca724..8093a03985 100644 --- a/ecrire/config-fonctions.php3 +++ b/ecrire/config-fonctions.php3 @@ -63,7 +63,7 @@ function afficher_choix_vignette($process) { } */ - echo "<td width='".($taille_preview+4)."'><div align='center' valign='bottom' width='".($taille_preview+4)."'><a href='config-fonctions.php3?image_process=$process'><img src='../spip_image.php3?test_vignette=$process' border='$border' /></a><br />"; + echo "<td width='".($taille_preview+4)."'><div align='center' valign='bottom' width='".($taille_preview+4)."'><a href='config-fonctions.php3?image_process=$process'><img src='../spip_image.php3?action=tester&doc=$process' border='$border' /></a><br />"; if ($border) echo "<b>$process</b>"; else echo "$process"; echo "</div></td>\n"; diff --git a/ecrire/inc_documents.php3 b/ecrire/inc_documents.php3 index f15dff92ec..7509a98b1e 100644 --- a/ecrire/inc_documents.php3 +++ b/ecrire/inc_documents.php3 @@ -772,11 +772,11 @@ function bouton_tourner_document($url, $redirect, $id, $album, $rot) { global $connect_id_auteur; $link_rot = new Link ($url); - $action = 'tourner_document'; + $action = 'tourner'; $link_rot->addVar('hash', calculer_action_auteur("$action $id")); $link_rot->addVar('hash_id_auteur', $connect_id_auteur); - $link_rot->addVar('doc', $id); $link_rot->addVar('action', $action); + $link_rot->addVar('doc', $id); $link_rot->addVar('var_rot', $rot); $link_rot->addVar('redirect', $redirect.'&show_docs='.$id); $link_rot->addVar('ancre', $album); @@ -787,13 +787,13 @@ function bouton_supprime_document_et_vignette($url, $redirect, $id, $album) { global $connect_id_auteur; - $action = 'supprime_document_et_vignette'; + $action = 'supprimer'; $link_supp = new Link ($url); - $link_supp->addVar('redirect', $redirect); $link_supp->addVar('hash', calculer_action_auteur($action ." ".$id)); $link_supp->addVar('hash_id_auteur', $connect_id_auteur); $link_supp->addVar('action', $action); $link_supp->addVar('doc', $id); + $link_supp->addVar('redirect', $redirect); $link_supp->addVar('ancre', $album); return $link_supp->getUrl(); } @@ -1175,16 +1175,11 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d afficher_formulaire_taille($document, $type_inclus); echo "<div align='".$GLOBALS['spip_lang_right']."'>"; - echo "<input TYPE='submit' class='fondo' style='font-size:9px;' NAME='Valider' VALUE='"._T('bouton_enregistrer')."'>"; + echo "<input TYPE='submit' class='fondo' style='font-size:9px;' ' VALUE='"._T('bouton_enregistrer')."'>"; echo "</div>"; echo "</form>"; - $link_supp = new Link ($image_url); - $link_supp->addVar('redirect', $redirect_url); - $link_supp->addVar('hash', calculer_action_auteur("supp_doc ".$id_document)); - $link_supp->addVar('hash_id_auteur', $connect_id_auteur); - $link_supp->addVar('doc_supp', $id_document); - $link_supp->addVar('ancre', 'documents'); + $link_supp = bouton_supprime_document_et_vignette($image_url, $redirect_url, $id_document, 'documents'); echo "</div>"; echo fin_block(); @@ -1301,12 +1296,7 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d echo "</form>"; echo "<center>"; - $link = new Link ($image_url); - $link->addVar('redirect', $redirect_url); - $link->addVar('hash', calculer_action_auteur("supp_doc ".$id_document)); - $link->addVar('hash_id_auteur', $connect_id_auteur); - $link->addVar('doc_supp', $id_document); - $link->addVar('ancre', 'images'); + $link = bouton_supprime_document_et_vignette($image_url, $redirect_url, $id_document, 'images'); icone_horizontale (_T('icone_supprimer_image'), $link->getUrl(), "image-24.gif", "supprimer.gif"); echo "</center>\n"; diff --git a/ecrire/inc_getdocument.php3 b/ecrire/inc_getdocument.php3 index 904df847c9..0c3316a2ef 100644 --- a/ecrire/inc_getdocument.php3 +++ b/ecrire/inc_getdocument.php3 @@ -19,7 +19,6 @@ if (defined("_ECRIRE_INC_GETDOCUMENT")) return; define("_ECRIRE_INC_GETDOCUMENT", "1"); - // Creer IMG/pdf/ function creer_repertoire_documents($ext) { $rep = _DIR_DOC . creer_repertoire(_DIR_DOC, $ext); @@ -578,102 +577,6 @@ function examiner_les_fichiers($files, $mode, $type, $id, $id_document, $hash, $ } } -// -// Fonctions referencees dans spip-image par calcul -// - -// Cas d'un document distant reference sur internet - -function joindre2($arg, $mode, $type, $id, $id_document,$hash, $hash_id_auteur, $redirect, &$actifs) -{ - examiner_les_fichiers(array( - array('name' => basename($arg), - 'tmp_name' => $arg) - ), 'distant', $type, $id, $id_document, - $hash, $hash_id_auteur, $redirect, $actifs); -} - -// Cas d'un fichier transmis - -function joindre1($arg, $mode, $type, $id, $id_document,$hash, $hash_id_auteur, $redirect, &$actifs) -{ - $files = array(); - if (is_array($arg)) - foreach ($arg as $file) { - if (!$file['error'] == 4 /* UPLOAD_ERR_NO_FILE */) - $files[]=$file; - } - examiner_les_fichiers($files, $mode, $type, $id, $id_document, - $hash, $hash_id_auteur, $redirect, $actifs); -} - -// copie de tout ou partie du repertoire upload - -function joindre3($arg, $mode, $type, $id, $id_document,$hash, $hash_id_auteur, $redirect, &$actifs) -{ - if (!$arg || strstr($arg, '..')) return; - - $upload = (_DIR_TRANSFERT .$arg); - - if (!is_dir($upload)) - // seul un fichier est demande - $files = array(array ('name' => basename($upload), - 'tmp_name' => $upload) - ); - else { - $files = array(); - foreach (fichiers_upload($upload) as $fichier) { - $files[]= array ( - 'name' => basename($fichier), - 'tmp_name' => $fichier - ); - } - } - - examiner_les_fichiers($files, $mode, $type, $id, $id_document, - $hash, $hash_id_auteur, $redirect, $actifs); -} - -// identifie les repertoires de upload aux rubriques Spip - -function joindre4($arg, $mode, $type, $id, $id_document, $hash, $hash_id_auteur, $redirect, &$documents_actifs) -{ - if (!$arg || strstr($arg, '..')) return; - $upload = (_DIR_TRANSFERT .$arg); - identifie_repertoire_et_rubrique($upload, $id, $id_auteur); - include_ecrire("inc_rubriques.php3"); - calculer_rubriques(); -} - -// Zip avec confirmation "tel quel" - -function joindre5($arg, $mode, $type, $id, $id_document,$hash, $hash_id_auteur, $redirect, &$actifs) -{ - ajouter_un_document($arg, basename($arg), $type, $id, $mode, $id_document, $actifs); -} - -// cas du zip a deballer. On ressort la bibli - -function joindre6($arg, $mode, $type, $id, $id_document,$hash, $hash_id_auteur, $redirect, &$actifs) -{ - define('_tmp_dir', creer_repertoire_documents($hash)); - if (_tmp_dir == _DIR_DOC) die(_L('Opération impossible')); - require_once(_DIR_RESTREINT . 'pclzip.lib.php'); - $archive = new PclZip($arg); - $archive->extract( - PCLZIP_OPT_PATH, _tmp_dir, - PCLZIP_CB_PRE_EXTRACT, 'callback_deballe_fichier' - ); - $contenu = verifier_compactes($archive); - // on supprime la copie temporaire - @unlink($arg); - - foreach ($contenu as $fichier) - ajouter_un_document(_tmp_dir.basename($fichier), - basename($fichier), - $type, $id, $mode, $id_document, $actifs); - effacer_repertoire_temporaire(_tmp_dir); -} function identifie_repertoire_et_rubrique($DIR, $id_rubrique, $id_auteur, $art=0) { @@ -819,208 +722,6 @@ function corriger_extension($ext) { } -// -// Ajouter un logo -// - -// $source = $_FILES[0] -// $dest = arton12.xxx -function ajout_logo($source, $dest) { - - if (!$source) return; - $f =_DIR_DOC . $dest . '.tmp'; - - if (!is_array($source)) - // fichier dans upload/ - $ok = @copy(_DIR_TRANSFERT . $source, $f); - else { - // Intercepter une erreur a l'envoi - if (check_upload_error($source['error'])) return; - - // analyse le type de l'image (on ne fait pas confiance au nom de - // fichier envoye par le browser : pour les Macs c'est plus sur) - - $ok = deplacer_fichier_upload($source['tmp_name'], $f); - } - if (!$ok) {spip_log("pb de copie pour $f"); return;} - - $size = @getimagesize($f); - $type = decoder_type_image($size[2], true); - - if ($type) { - $poids = filesize($f); - if (_LOGO_MAX_SIZE > 0 - AND $poids > _LOGO_MAX_SIZE*1024) { - @unlink ($f); - check_upload_error(6, - _T('info_logo_max_poids', - array('maxi' => taille_en_octets(_LOGO_MAX_SIZE*1024), - 'actuel' => taille_en_octets($poids)))); - } - - if (_LOGO_MAX_WIDTH * _LOGO_MAX_HEIGHT - AND ($size[0] > _LOGO_MAX_WIDTH - OR $size[1] > _LOGO_MAX_HEIGHT)) { - @unlink ($f); - check_upload_error(6, - _T('info_logo_max_taille', - array( - 'maxi' => - _T('info_largeur_vignette', - array('largeur_vignette' => _LOGO_MAX_WIDTH, - 'hauteur_vignette' => _LOGO_MAX_HEIGHT)), - 'actuel' => - _T('info_largeur_vignette', - array('largeur_vignette' => $size[0], - 'hauteur_vignette' => $size[1])) - ))); - } - @rename ($f, _DIR_DOC . $dest . ".$type"); - } - else { - @unlink ($f); - check_upload_error(6, - _T('info_logo_format_interdit', - array ('formats' => 'GIF, JPG, PNG')) - ); - } -} - - -function effacer_logo($nom) { - if (!strstr($nom, "..")) - @unlink(_DIR_IMG . $nom); -} - - - -// -// Creation automatique de vignette -// - -// Tester nos capacites -function tester_vignette ($test_vignette) { - global $pnmscale_command; - - // verifier les formats acceptes par GD - if ($test_vignette == "gd1") { - // Si GD est installe et php >= 4.0.2 - if (function_exists('imagetypes')) { - - if (imagetypes() & IMG_GIF) { - $gd_formats[] = "gif"; - } else { - # Attention GD sait lire le gif mais pas forcement l'ecrire - if (function_exists('ImageCreateFromGIF')) { - $srcImage = @ImageCreateFromGIF(_DIR_IMG . "test.gif"); - if ($srcImage) { - $gd_formats_read_gif = ",gif"; - ImageDestroy( $srcImage ); - } - } - } - - if (imagetypes() & IMG_JPG) - $gd_formats[] = "jpg"; - if (imagetypes() & IMG_PNG) - $gd_formats[] = "png"; - } - - else { # ancienne methode de detection des formats, qui en plus - # est bugguee car elle teste les formats en lecture - # alors que la valeur deduite sert a identifier - # les formats disponibles en ecriture... (cf. inc_logos.php3) - - $gd_formats = Array(); - if (function_exists('ImageCreateFromJPEG')) { - $srcImage = @ImageCreateFromJPEG(_DIR_IMG . "test.jpg"); - if ($srcImage) { - $gd_formats[] = "jpg"; - ImageDestroy( $srcImage ); - } - } - if (function_exists('ImageCreateFromGIF')) { - $srcImage = @ImageCreateFromGIF(_DIR_IMG . "test.gif"); - if ($srcImage) { - $gd_formats[] = "gif"; - ImageDestroy( $srcImage ); - } - } - if (function_exists('ImageCreateFromPNG')) { - $srcImage = @ImageCreateFromPNG(_DIR_IMG . "test.png"); - if ($srcImage) { - $gd_formats[] = "png"; - ImageDestroy( $srcImage ); - } - } - } - - if ($gd_formats) $gd_formats = join(",", $gd_formats); - ecrire_meta("gd_formats_read", $gd_formats.$gd_formats_read_gif); - ecrire_meta("gd_formats", $gd_formats); - ecrire_metas(); - } - - // verifier les formats netpbm - else if ($test_vignette == "netpbm" - AND $pnmscale_command) { - $netpbm_formats= Array(); - - $jpegtopnm_command = str_replace("pnmscale", - "jpegtopnm", $pnmscale_command); - $pnmtojpeg_command = str_replace("pnmscale", - "pnmtojpeg", $pnmscale_command); - - $vignette = _DIR_IMG . "test.jpg"; - $dest = _DIR_IMG . "test-jpg.jpg"; - $commande = "$jpegtopnm_command $vignette | $pnmscale_command -width 10 | $pnmtojpeg_command > $dest"; - spip_log($commande); - exec($commande); - if ($taille = @getimagesize($dest)) { - if ($taille[1] == 10) $netpbm_formats[] = "jpg"; - } - $giftopnm_command = ereg_replace("pnmscale", "giftopnm", $pnmscale_command); - $pnmtojpeg_command = ereg_replace("pnmscale", "pnmtojpeg", $pnmscale_command); - $vignette = _DIR_IMG . "test.gif"; - $dest = _DIR_IMG . "test-gif.jpg"; - $commande = "$giftopnm_command $vignette | $pnmscale_command -width 10 | $pnmtojpeg_command > $dest"; - spip_log($commande); - exec($commande); - if ($taille = @getimagesize($dest)) { - if ($taille[1] == 10) $netpbm_formats[] = "gif"; - } - - $pngtopnm_command = ereg_replace("pnmscale", "pngtopnm", $pnmscale_command); - $vignette = _DIR_IMG . "test.png"; - $dest = _DIR_IMG . "test-gif.jpg"; - $commande = "$pngtopnm_command $vignette | $pnmscale_command -width 10 | $pnmtojpeg_command > $dest"; - spip_log($commande); - exec($commande); - if ($taille = @getimagesize($dest)) { - if ($taille[1] == 10) $netpbm_formats[] = "png"; - } - - - if ($netpbm_formats) - $netpbm_formats = join(",", $netpbm_formats); - else - $netpbm_formats = ''; - ecrire_meta("netpbm_formats", $netpbm_formats); - ecrire_metas(); - } - - // et maintenant envoyer la vignette de tests - if (ereg("^(gd1|gd2|imagick|convert|netpbm)$", $test_vignette)) { - include_ecrire('inc_logos.php3'); - //$taille_preview = lire_meta("taille_preview"); - if ($taille_preview < 10) $taille_preview = 150; - if ($preview = creer_vignette(_DIR_IMG . 'test_image.jpg', $taille_preview, $taille_preview, 'jpg', '', "test_$test_vignette", $test_vignette, true)) - - return ($preview['fichier']); - } - - return _DIR_IMG_PACK . 'puce-rouge-anim.gif'; # image echec -} // Creation function creer_fichier_vignette($vignette, $test_cache_only=false) { @@ -1083,49 +784,6 @@ function inserer_vignette_base($image, $vignette) { } -// Effacer un doc (et sa vignette) -function supprime_document_et_vignette($doc_supp) { - - $result = spip_query("SELECT id_vignette, fichier - FROM spip_documents - WHERE id_document=$doc_supp"); - if ($row = spip_fetch_array($result)) { - $fichier = $row['fichier']; - $id_vignette = $row['id_vignette']; - spip_query("DELETE FROM spip_documents - WHERE id_document=$doc_supp"); - spip_query("UPDATE spip_documents SET id_vignette=0 - WHERE id_vignette=$doc_supp"); - spip_query("DELETE FROM spip_documents_articles - WHERE id_document=$doc_supp"); - spip_query("DELETE FROM spip_documents_rubriques - WHERE id_document=$doc_supp"); - spip_query("DELETE FROM spip_documents_breves - WHERE id_document=$doc_supp"); - @unlink($fichier); - - if ($id_vignette > 0) { - $query = "SELECT id_vignette, fichier FROM spip_documents - WHERE id_document=$id_vignette"; - $result = spip_query($query); - if ($row = spip_fetch_array($result)) { - $fichier = $row['fichier']; - @unlink($fichier); - } - spip_query("DELETE FROM spip_documents - WHERE id_document=$id_vignette"); - spip_query("DELETE FROM spip_documents_articles - WHERE id_document=$id_vignette"); - spip_query("DELETE FROM spip_documents_rubriques - WHERE id_document=$id_vignette"); - spip_query("DELETE FROM spip_documents_breves - WHERE id_document=$id_vignette"); - } - } -} - - - ///////////////////////////////////////////////////////////////////// // // Faire tourner une image @@ -1220,54 +878,5 @@ function gdRotate ($imagePath,$rtt){ $save($dst_img,$imagePath); } -function tourner_document($var_rot, $doc_rotate, $convert_command) { - - $var_rot = intval($var_rot); - - $query = "SELECT id_vignette, fichier FROM spip_documents WHERE id_document=$doc_rotate"; - $result = spip_query($query); - if ($row = spip_fetch_array($result)) { - $id_vignette = $row['id_vignette']; - $image = $row['fichier']; - - $process = lire_meta('image_process'); - - // imagick (php4-imagemagick) - if ($process == 'imagick') { - $handle = imagick_readimage($image); - imagick_rotate($handle, $var_rot); - imagick_write($handle, $image); - if (!@file_exists($image)) return; // echec imagick - } - else if ($process == "gd2") { // theoriquement compatible gd1, mais trop forte degradation d'image - if ($var_rot == 180) { // 180 = 90+90 - gdRotate ($image, 90); - gdRotate ($image, 90); - } else { - gdRotate ($image, $var_rot); - } - } - else if ($process = "convert") { - $commande = "$convert_command -rotate $var_rot ./" - . escapeshellcmd($image).' ./'.escapeshellcmd($image); -# spip_log($commande); - exec($commande); - } - - $size_image = @getimagesize($image); - $largeur = $size_image[0]; - $hauteur = $size_image[1]; - -/* - A DESACTIVER PEUT-ETRE ? QUE SE PASSE--IL SI JE TOURNE UNE IMAGE AYANT UNE VGNETTE "MANUELLE" -> NE PAS CREER DE VIGNETTE TOURNEE -- EN VERITE IL NE FAUT PAS PERMETTRE DE TOURNER UNE IMAGE AYANT UNE VIGNETTE MANUELLE - if ($id_vignette > 0) { - creer_fichier_vignette($image); - } -*/ - - spip_query("UPDATE spip_documents SET largeur=$largeur, hauteur=$hauteur WHERE id_document=$doc_rotate"); - - } -} ?> diff --git a/ecrire/inc_logos.php3 b/ecrire/inc_logos.php3 index 6052802e70..41bd64bb3c 100644 --- a/ecrire/inc_logos.php3 +++ b/ecrire/inc_logos.php3 @@ -101,7 +101,7 @@ function afficher_logo($racine, $titre, $logo, $id_objet, $id) { if ($logo) { list ($fichier, $taille) = $logo; - $hash = calculer_action_auteur("effacer_logo $fichier"); + $hash = calculer_action_auteur("effacer $fichier"); echo "<p><center><div><a href='"._DIR_IMG.$fichier."'>"; echo reduire_image_logo(_DIR_IMG.$fichier, 170); @@ -110,12 +110,12 @@ function afficher_logo($racine, $titre, $logo, $id_objet, $id) { echo $taille; echo "\n<br />[<a href='../spip_image.php3?"; echo "$id_objet=$id&"; - echo "action=effacer_logo&doc=$fichier&hash_id_auteur=$connect_id_auteur&hash=$hash&redirect=".urlencode($redirect)."'>"._T('lien_supprimer')."</a>]"; + echo "action=effacer&doc=$fichier&hash_id_auteur=$connect_id_auteur&hash=$hash&redirect=".urlencode($redirect)."'>"._T('lien_supprimer')."</a>]"; echo fin_block(); echo "</center></p>"; } else { - $hash = calculer_action_auteur("ajout_logo $racine"); + $hash = calculer_action_auteur("ajouter $racine"); echo debut_block_invisible(md5($titre)); echo "\n\n<FORM ACTION='../spip_image.php3' METHOD='POST' @@ -125,7 +125,7 @@ function afficher_logo($racine, $titre, $logo, $id_objet, $id) { echo "\n<INPUT NAME='$id_objet' TYPE=Hidden VALUE='$id' />"; echo "\n<INPUT NAME='hash_id_auteur' TYPE=Hidden VALUE='$connect_id_auteur' />"; echo "\n<INPUT NAME='hash' TYPE=Hidden VALUE='$hash' />"; - echo "\n<INPUT NAME='action' TYPE=Hidden VALUE='ajout_logo' />"; + echo "\n<INPUT NAME='action' TYPE=Hidden VALUE='ajouter' />"; echo "\n<INPUT NAME='doc' TYPE=Hidden VALUE='$racine' />"; echo "\n"._T('info_telecharger_nouveau_logo')."<br />"; echo "\n<INPUT NAME='image' type='File' class='forml' style='font-size:9px;' SIZE=15>"; @@ -148,7 +148,7 @@ function afficher_logo($racine, $titre, $logo, $id_objet, $id) { echo _T('info_installer_images_dossier'); } else { echo "\n<div style='text-align: left'>"._T('info_selectionner_fichier').":</div>"; - echo "\n<SELECT NAME='chemin' CLASS='forml' size='1'>"; + echo "\n<SELECT NAME='source' CLASS='forml' size='1'>"; echo $afficher; echo "\n</SELECT>"; echo "<div align='", $GLOBALS['spip_lang_right'], "'>"; diff --git a/ecrire/inc_spip_image.php b/ecrire/inc_spip_image.php new file mode 100644 index 0000000000..b3d0a44a2f --- /dev/null +++ b/ecrire/inc_spip_image.php @@ -0,0 +1,621 @@ +<?php + +/***************************************************************************\ + * SPIP, Systeme de publication pour l'internet * + * * + * Copyright (c) 2001-2005 * + * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * + * * + * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * + * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * +\***************************************************************************/ + + +// +// Fonctions invoquees par spip_image.php3 en fonction du parametre "action" +// Les globales sont les variables CGI. + +// +// Ce fichier ne sera execute qu'une fois +if (defined("_ECRIRE_INC_SPIP_IMAGE")) return; +define("_ECRIRE_INC_SPIP_IMAGE", "1"); + +// faudrait ne charger qu'a bon escient + +include_ecrire('inc_presentation.php3');# regler la langue en cas d'erreur +include_ecrire('inc_getdocument.php3'); # diverses fonctions de ce fichier +include_ecrire("inc_charsets.php3"); # pour le nom de fichier +include_ecrire("inc_meta.php3"); # ne pas faire confiance au cache + # (alea_ephemere a peut-etre change) +include_ecrire("inc_admin.php3"); # verifier_action_auteur +include_ecrire("inc_abstract_sql.php3");# spip_insert / spip_fetch... +include_ecrire('inc_documents.php3'); # fichiers_upload() + + +function spip_image_joindre($doc) +{ + global + $sousaction1, + $sousaction2, + $sousaction3, + $sousaction4, + $sousaction5, + $action, $hash, $hash_id_auteur, + $url, $chemin, $ancre, $type, $id_article, $id_document, $redirect, + $_FILES, $HTTP_POST_FILES; + + if (!verifier_action_auteur("$action $doc", $hash, $hash_id_auteur)) + die ($action . '!!!'); + + // pas terrible, mais c'est le pb du bouton Submit qui retourne son texte, + // et son transcodage est couteux et perilleux + $action = 'spip_image_joindre' . + ($sousaction1 ? 1 : + ($sousaction2 ? 2 : + ($sousaction3 ? 3 : + ($sousaction4 ? 4 : + $sousaction5 )))); + + $arg = ($sousaction1 ? ($_FILES ? $_FILES : $HTTP_POST_FILES) : + ($sousaction2 ? $url : $chemin)); + + $documents_actifs = array(); + + if (function_exists($action)) + $action($arg, $doc, $type, $id_article, $id_document, + $hash, $hash_id_auteur, $redirect, $documents_actifs); + + else spip_log("spip_image: action inconnue $action"); + + $link = new Link(_DIR_RESTREINT_ABS . $redirect); + if ($documents_actifs) { + $link->addVar('show_docs',join('-',$documents_actifs)); + } + redirige_par_entete($link->getUrl($ancre)); +} + + +// Cas d'un document distant reference sur internet + +function spip_image_joindre2($arg, $mode, $type, $id, $id_document,$hash, $hash_id_auteur, $redirect, &$actifs) +{ + examiner_les_fichiers(array( + array('name' => basename($arg), + 'tmp_name' => $arg) + ), 'distant', $type, $id, $id_document, + $hash, $hash_id_auteur, $redirect, $actifs); +} + +// Cas d'un fichier transmis + +function spip_image_joindre1($arg, $mode, $type, $id, $id_document,$hash, $hash_id_auteur, $redirect, &$actifs) +{ + $files = array(); + if (is_array($arg)) + foreach ($arg as $file) { + if (!$file['error'] == 4 /* UPLOAD_ERR_NO_FILE */) + $files[]=$file; + } + examiner_les_fichiers($files, $mode, $type, $id, $id_document, + $hash, $hash_id_auteur, $redirect, $actifs); +} + +// copie de tout ou partie du repertoire upload + +function spip_image_joindre3($arg, $mode, $type, $id, $id_document,$hash, $hash_id_auteur, $redirect, &$actifs) +{ + if (!$arg || strstr($arg, '..')) return; + + $upload = (_DIR_TRANSFERT .$arg); + + if (!is_dir($upload)) + // seul un fichier est demande + $files = array(array ('name' => basename($upload), + 'tmp_name' => $upload) + ); + else { + $files = array(); + foreach (fichiers_upload($upload) as $fichier) { + $files[]= array ( + 'name' => basename($fichier), + 'tmp_name' => $fichier + ); + } + } + + examiner_les_fichiers($files, $mode, $type, $id, $id_document, + $hash, $hash_id_auteur, $redirect, $actifs); +} + +// identifie les repertoires de upload aux rubriques Spip + +function spip_image_joindre4($arg, $mode, $type, $id, $id_document, $hash, $hash_id_auteur, $redirect, &$documents_actifs) +{ + if (!$arg || strstr($arg, '..')) return; + $upload = (_DIR_TRANSFERT .$arg); + identifie_repertoire_et_rubrique($upload, $id, $id_auteur); + include_ecrire("inc_rubriques.php3"); + calculer_rubriques(); +} + +// Zip avec confirmation "tel quel" + +function spip_image_joindre5($arg, $mode, $type, $id, $id_document,$hash, $hash_id_auteur, $redirect, &$actifs) +{ + ajouter_un_document($arg, basename($arg), $type, $id, $mode, $id_document, $actifs); +} + +// cas du zip a deballer. On ressort la bibli + +function spip_image_joindre6($arg, $mode, $type, $id, $id_document,$hash, $hash_id_auteur, $redirect, &$actifs) +{ + define('_tmp_dir', creer_repertoire_documents($hash)); + if (_tmp_dir == _DIR_DOC) die(_L('Opération impossible')); + require_once(_DIR_RESTREINT . 'pclzip.lib.php'); + $archive = new PclZip($arg); + $archive->extract( + PCLZIP_OPT_PATH, _tmp_dir, + PCLZIP_CB_PRE_EXTRACT, 'callback_deballe_fichier' + ); + $contenu = verifier_compactes($archive); + // on supprime la copie temporaire + @unlink($arg); + + foreach ($contenu as $fichier) + ajouter_un_document(_tmp_dir.basename($fichier), + basename($fichier), + $type, $id, $mode, $id_document, $actifs); + effacer_repertoire_temporaire(_tmp_dir); +} + +// +// Ajouter un logo +// + +// $source = $_FILES[0] +// $dest = arton12.xxx +function spip_image_ajouter($doc) { + global $sousaction2, $source; + global $action, $hash, $hash_id_auteur; + + if (!verifier_action_auteur("$action $doc", $hash, $hash_id_auteur)) + die ($action . '!!!'); + + if (!$sousaction2) { + if (!$_FILES) $_FILES = $HTTP_POST_FILES; + $source = (is_array($_FILES) ? array_pop($_FILES) : ""); + } + if ($source) { + $f =_DIR_DOC . $doc . '.tmp'; + + if (!is_array($source)) + // fichier dans upload/ + $source = @copy(_DIR_TRANSFERT . $source, $f); + else { + // Intercepter une erreur a l'envoi + if (check_upload_error($source['error'])) + $source =""; + else + // analyse le type de l'image (on ne fait pas confiance au nom de + // fichier envoye par le browser : pour les Macs c'est plus sur) + + $source = deplacer_fichier_upload($source['tmp_name'], $f); + } + } + if (!$source) + spip_log("pb de copie pour $f"); + else { + + $size = @getimagesize($f); + $type = decoder_type_image($size[2], true); + + if ($type) { + $poids = filesize($f); + if (_LOGO_MAX_SIZE > 0 + AND $poids > _LOGO_MAX_SIZE*1024) { + @unlink ($f); + check_upload_error(6, + _T('info_logo_max_poids', + array('maxi' => taille_en_octets(_LOGO_MAX_SIZE*1024), + 'actuel' => taille_en_octets($poids)))); + } + + if (_LOGO_MAX_WIDTH * _LOGO_MAX_HEIGHT + AND ($size[0] > _LOGO_MAX_WIDTH + OR $size[1] > _LOGO_MAX_HEIGHT)) { + @unlink ($f); + check_upload_error(6, + _T('info_logo_max_taille', + array( + 'maxi' => + _T('info_largeur_vignette', + array('largeur_vignette' => _LOGO_MAX_WIDTH, + 'hauteur_vignette' => _LOGO_MAX_HEIGHT)), + 'actuel' => + _T('info_largeur_vignette', + array('largeur_vignette' => $size[0], + 'hauteur_vignette' => $size[1])) + ))); + } + @rename ($f, _DIR_DOC . $doc . ".$type"); + } + else { + @unlink ($f); + check_upload_error(6, + _T('info_logo_format_interdit', + array ('formats' => 'GIF, JPG, PNG')) + ); + } + + } + $link = new Link(_DIR_RESTREINT_ABS . $GLOBALS['redirect']); + redirige_par_entete($link->getUrl($GLOBALS['ancre'])); +} + + +function spip_image_effacer($doc) { + global $action, $hash, $hash_id_auteur; + if (!verifier_action_auteur("$action $doc", $hash, $hash_id_auteur)) + die ($action . '!!!'); + + if (!strstr($doc, "..")) + @unlink(_DIR_IMG . $doc); + $link = new Link(_DIR_RESTREINT_ABS . $GLOBALS['redirect']); + redirige_par_entete($link->getUrl($GLOBALS['ancre'])); +} + +// +// Creation automatique de vignette +// + +// Tester nos capacites +function spip_image_tester ($test_vignette) { + global $pnmscale_command; + + // verifier les formats acceptes par GD + if ($test_vignette == "gd1") { + // Si GD est installe et php >= 4.0.2 + if (function_exists('imagetypes')) { + + if (imagetypes() & IMG_GIF) { + $gd_formats[] = "gif"; + } else { + # Attention GD sait lire le gif mais pas forcement l'ecrire + if (function_exists('ImageCreateFromGIF')) { + $srcImage = @ImageCreateFromGIF(_DIR_IMG . "test.gif"); + if ($srcImage) { + $gd_formats_read_gif = ",gif"; + ImageDestroy( $srcImage ); + } + } + } + + if (imagetypes() & IMG_JPG) + $gd_formats[] = "jpg"; + if (imagetypes() & IMG_PNG) + $gd_formats[] = "png"; + } + + else { # ancienne methode de detection des formats, qui en plus + # est bugguee car elle teste les formats en lecture + # alors que la valeur deduite sert a identifier + # les formats disponibles en ecriture... (cf. inc_logos.php3) + + $gd_formats = Array(); + if (function_exists('ImageCreateFromJPEG')) { + $srcImage = @ImageCreateFromJPEG(_DIR_IMG . "test.jpg"); + if ($srcImage) { + $gd_formats[] = "jpg"; + ImageDestroy( $srcImage ); + } + } + if (function_exists('ImageCreateFromGIF')) { + $srcImage = @ImageCreateFromGIF(_DIR_IMG . "test.gif"); + if ($srcImage) { + $gd_formats[] = "gif"; + ImageDestroy( $srcImage ); + } + } + if (function_exists('ImageCreateFromPNG')) { + $srcImage = @ImageCreateFromPNG(_DIR_IMG . "test.png"); + if ($srcImage) { + $gd_formats[] = "png"; + ImageDestroy( $srcImage ); + } + } + } + + if ($gd_formats) $gd_formats = join(",", $gd_formats); + ecrire_meta("gd_formats_read", $gd_formats.$gd_formats_read_gif); + ecrire_meta("gd_formats", $gd_formats); + ecrire_metas(); + } + + // verifier les formats netpbm + else if ($test_vignette == "netpbm" + AND $pnmscale_command) { + $netpbm_formats= Array(); + + $jpegtopnm_command = str_replace("pnmscale", + "jpegtopnm", $pnmscale_command); + $pnmtojpeg_command = str_replace("pnmscale", + "pnmtojpeg", $pnmscale_command); + + $vignette = _DIR_IMG . "test.jpg"; + $dest = _DIR_IMG . "test-jpg.jpg"; + $commande = "$jpegtopnm_command $vignette | $pnmscale_command -width 10 | $pnmtojpeg_command > $dest"; + spip_log($commande); + exec($commande); + if ($taille = @getimagesize($dest)) { + if ($taille[1] == 10) $netpbm_formats[] = "jpg"; + } + $giftopnm_command = ereg_replace("pnmscale", "giftopnm", $pnmscale_command); + $pnmtojpeg_command = ereg_replace("pnmscale", "pnmtojpeg", $pnmscale_command); + $vignette = _DIR_IMG . "test.gif"; + $dest = _DIR_IMG . "test-gif.jpg"; + $commande = "$giftopnm_command $vignette | $pnmscale_command -width 10 | $pnmtojpeg_command > $dest"; + spip_log($commande); + exec($commande); + if ($taille = @getimagesize($dest)) { + if ($taille[1] == 10) $netpbm_formats[] = "gif"; + } + + $pngtopnm_command = ereg_replace("pnmscale", "pngtopnm", $pnmscale_command); + $vignette = _DIR_IMG . "test.png"; + $dest = _DIR_IMG . "test-gif.jpg"; + $commande = "$pngtopnm_command $vignette | $pnmscale_command -width 10 | $pnmtojpeg_command > $dest"; + spip_log($commande); + exec($commande); + if ($taille = @getimagesize($dest)) { + if ($taille[1] == 10) $netpbm_formats[] = "png"; + } + + + if ($netpbm_formats) + $netpbm_formats = join(",", $netpbm_formats); + else + $netpbm_formats = ''; + ecrire_meta("netpbm_formats", $netpbm_formats); + ecrire_metas(); + } + + // et maintenant envoyer la vignette de tests + if (ereg("^(gd1|gd2|imagick|convert|netpbm)$", $test_vignette)) { + include_ecrire('inc_logos.php3'); + //$taille_preview = lire_meta("taille_preview"); + if ($taille_preview < 10) $taille_preview = 150; + if ($preview = creer_vignette(_DIR_IMG . 'test_image.jpg', $taille_preview, $taille_preview, 'jpg', '', "test_$test_vignette", $test_vignette, true)) + + header("Location: " . $preview['fichier']); + } + + # image echec + header("Location: " . _DIR_IMG_PACK . 'puce-rouge-anim.gif'); +} + + +// Effacer un doc (et sa vignette) +function spip_image_supprimer($doc) { + + global $action, $hash, $hash_id_auteur; + if (!verifier_action_auteur("$action $doc", $hash, $hash_id_auteur)) + die ($action . '!!!'); + + $result = spip_query("SELECT id_vignette, fichier + FROM spip_documents + WHERE id_document=$doc"); + if ($row = spip_fetch_array($result)) { + $fichier = $row['fichier']; + $id_vignette = $row['id_vignette']; + spip_query("DELETE FROM spip_documents + WHERE id_document=$doc"); + spip_query("UPDATE spip_documents SET id_vignette=0 + WHERE id_vignette=$doc"); + spip_query("DELETE FROM spip_documents_articles + WHERE id_document=$doc"); + spip_query("DELETE FROM spip_documents_rubriques + WHERE id_document=$doc"); + spip_query("DELETE FROM spip_documents_breves + WHERE id_document=$doc"); + @unlink($fichier); + + if ($id_vignette > 0) { + $query = "SELECT id_vignette, fichier FROM spip_documents + WHERE id_document=$id_vignette"; + $result = spip_query($query); + if ($row = spip_fetch_array($result)) { + $fichier = $row['fichier']; + @unlink($fichier); + } + spip_query("DELETE FROM spip_documents + WHERE id_document=$id_vignette"); + spip_query("DELETE FROM spip_documents_articles + WHERE id_document=$id_vignette"); + spip_query("DELETE FROM spip_documents_rubriques + WHERE id_document=$id_vignette"); + spip_query("DELETE FROM spip_documents_breves + WHERE id_document=$id_vignette"); + } + } + $link = new Link(_DIR_RESTREINT_ABS . $GLOBALS['redirect']); + redirige_par_entete($link->getUrl($GLOBALS['ancre'])); +} + + +function spip_image_tourner($doc) { + + global $action, $hash, $hash_id_auteur; + if (!verifier_action_auteur("$action $doc", $hash, $hash_id_auteur)) + die ($action . '!!!'); + + global $var_rot, $convert_command; + $var_rot = intval($var_rot); + + $query = "SELECT id_vignette, fichier FROM spip_documents WHERE id_document=$doc"; + $result = spip_query($query); + if ($row = spip_fetch_array($result)) { + $id_vignette = $row['id_vignette']; + $image = $row['fichier']; + + $process = lire_meta('image_process'); + + // imagick (php4-imagemagick) + if ($process == 'imagick') { + $handle = imagick_readimage($image); + imagick_rotate($handle, $var_rot); + imagick_write($handle, $image); + if (!@file_exists($image)) return; // echec imagick + } + else if ($process == "gd2") { // theoriquement compatible gd1, mais trop forte degradation d'image + if ($var_rot == 180) { // 180 = 90+90 + gdRotate ($image, 90); + gdRotate ($image, 90); + } else { + gdRotate ($image, $var_rot); + } + } + else if ($process = "convert") { + $commande = "$convert_command -rotate $var_rot ./" + . escapeshellcmd($image).' ./'.escapeshellcmd($image); +# spip_log($commande); + exec($commande); + } + + $size_image = @getimagesize($image); + $largeur = $size_image[0]; + $hauteur = $size_image[1]; + +/* + A DESACTIVER PEUT-ETRE ? QUE SE PASSE--IL SI JE TOURNE UNE IMAGE AYANT UNE VGNETTE "MANUELLE" -> NE PAS CREER DE VIGNETTE TOURNEE -- EN VERITE IL NE FAUT PAS PERMETTRE DE TOURNER UNE IMAGE AYANT UNE VIGNETTE MANUELLE + if ($id_vignette > 0) { + creer_fichier_vignette($image); + } +*/ + + spip_query("UPDATE spip_documents SET largeur=$largeur, hauteur=$hauteur WHERE id_document=$doc"); + + } + $link = new Link(_DIR_RESTREINT_ABS . $GLOBALS['redirect']); + redirige_par_entete($link->getUrl($GLOBALS['ancre'])); +} + + +// acces aux documents joints securise +// est appelee avec id_document comme parametre CGI +// mais peu aussi etre appelle avec le parametre file directement +// il verifie soit que le demandeur est authentifie +// soit que le fichier est joint à au moins 1 article, breve ou rubrique publie + +function spip_image_autoriser($id_document) +{ + global $file; + + $file = urldecode($file); + + $refus = false; + if (strpos($file,'../') !== false) + $refus = 1; + else + { + if ($cookie_session = $_COOKIE['spip_session']) + { + include_ecrire("inc_session.php3"); + global $auteur_session; + + if (verifier_session($cookie_session)) + { + + if ($auteur_session['statut'] == '0minirezo' + OR $auteur_session['statut'] == '1comite') + $auth_login = $auteur_session['login']; + } + } + + if (!$id_document) { + $id_document = spip_query("select id_document from spip_documents as documents where documents.fichier='".$file."'"); + $id_document = spip_fetch_array($id_document); + if (!$id_document) $refus = 2; + $id_document = $id_document['id_document']; + } else { + $file = spip_query("select fichier from spip_documents as documents where id_document='". $id_document ."'"); + $file = spip_fetch_array($file); + if (!$file) $refus = 3; + $file = $file['fichier']; + } + } + spip_log("ici $file"); +if (!$auth_login && !$refus) { + if (!spip_num_rows(spip_query("select articles.id_article +from spip_documents_articles as rel_articles, spip_articles as articles +where rel_articles.id_article = articles.id_article AND +articles.statut = 'publie' AND rel_articles.id_document ='". + $id_document . + "' LIMIT 1"))) { + if (!spip_num_rows(spip_query("select rubriques.id_rubrique +from spip_documents_rubriques as rel_rubriques, spip_rubriques as rubriques +where rel_rubriques.id_rubrique = rubriques.id_rubrique AND +rubriques.statut = 'publie' AND rel_rubriques.id_document ='". + $id_document . + "' LIMIT 1"))) { + if (!spip_num_rows(spip_query("select breves.id_breve +from spip_documents_breves as rel_breves, spip_breves as breves +where rel_breves.id_breve = breves.id_breve AND +breves.statut = 'publie' AND rel_breves.id_document ='". + $id_document . + "' LIMIT 1"))) + $refus = 4; } } } + + spip_log("$refus"); + if (is_int($refus)) { + spip_log("Acces refuse ($refus) au document " . $id_document . ': ' . $file); + $fond = 404; + include("inc-public.php3"); + } + else + { + if (!function_exists('mime_content_type')) { + function mime_content_type($f) {preg_match("/\.(\w+)/",$f,$r); return $r[1];} + } + spip_log("envoi $file"); + $ct = mime_content_type($file); + $cl = filesize($file); + $filename = basename($file); + header("Content-Type: ". $ct); + header("Content-Disposition: attachment; filename=\"". $filename ."\";"); + if ($file) header("Content-Description: " . $dcc); + if ($cl) header("Content-Length: ". $cl); + + header("Content-Transfer-Encoding: binary"); + readfile($file); + } +} + +// pour envoyer un article proprement +// spip_image.php3?action=telecharger&doc=$id_article + +function spip_image_telecharger($id_article) +{ + $r = spip_query(" +SELECT texte, soustitre, titre, date +FROM spip_articles +WHERE id_article=" . $id_article + ); + $r = spip_fetch_array($r); + if (!$r) + return 0; + else + { + $titre = $r['titre']; + $text =ereg_replace("^<code>[[:space:]]*",'', + ereg_replace('</code>$','',$r['texte'])); + header("Content-Type: text/plain; charset='iso-8859-1'"); + if ($titre) header("Content-Description: $titre"); + header("Content-Disposition: attachment; filename=" . + ($r['soustitre'] ? $r['soustitre'] : ($id_article . ".txt")) . + ";" ); + header("Content-Length: ". strlen($text)+1); + print $text; + } +} + +?> diff --git a/ecrire/inc_urls.php3 b/ecrire/inc_urls.php3 index df9b8e2a28..a15e8aee65 100644 --- a/ecrire/inc_urls.php3 +++ b/ecrire/inc_urls.php3 @@ -74,7 +74,7 @@ function generer_url_document($id_document) { } else { $url = '../' . ($row['fichier']); if ((lire_meta("creer_htaccess")) == 'oui') - $url = "../spip_acces_doc.php3?id_document=$id_document"; + $url = "../spip_image.php3?action=autoriser&doc=$id_document"; } } return $url; diff --git a/inc-urls-html.php3 b/inc-urls-html.php3 index 9bab46b8c7..54cab2b1ab 100644 --- a/inc-urls-html.php3 +++ b/inc-urls-html.php3 @@ -65,7 +65,7 @@ function generer_url_document($id_document) { if (intval($id_document) <= 0) return ''; if ((lire_meta("creer_htaccess")) == 'oui') - return "spip_acces_doc.php3?id_document=$id_document"; + return "spip_image.php3?action=autoriser&doc=$id_document"; if ($row = @spip_fetch_array(spip_query("SELECT fichier FROM spip_documents WHERE id_document = $id_document"))) return ($row['fichier']); return ''; diff --git a/inc-urls-propres.php3 b/inc-urls-propres.php3 index 470ea93faa..f0978d59e3 100644 --- a/inc-urls-propres.php3 +++ b/inc-urls-propres.php3 @@ -179,7 +179,7 @@ function generer_url_document($id_document) { if (intval($id_document) <= 0) return ''; if ((lire_meta("creer_htaccess")) == 'oui') - return "spip_acces_doc.php3?id_document=$id_document"; + return "spip_image.php3?action=autoriser&doc=$id_document"; if ($row = @spip_fetch_array(spip_query("SELECT fichier FROM spip_documents WHERE id_document = $id_document"))) return ($row['fichier']); return ''; @@ -198,7 +198,7 @@ preg_match(',(^|/)((article|breve|rubrique|mot|auteur|site)(\.php3?|[0-9]+\.html $url_propre = $func($id_objet); if ($url_propre AND ($url_propre<>$regs[2])) { - include_ecrire('inc_headers.php'); +> include_ecrire('inc_headers.php'); http_status(301); // recuperer les arguments supplementaires (&debut_xxx=...) $reste = preg_replace('/^&/','?', diff --git a/inc-urls-standard.php3 b/inc-urls-standard.php3 index 3247d3139e..76ff357ab0 100644 --- a/inc-urls-standard.php3 +++ b/inc-urls-standard.php3 @@ -43,7 +43,7 @@ function generer_url_document($id_document) { if (intval($id_document) <= 0) return ''; if ((lire_meta("creer_htaccess")) == 'oui') - return "spip_acces_doc.php3?id_document=$id_document"; + return "spip_image.php3?action=autoriser&doc=$id_document"; if ($row = @spip_fetch_array(spip_query("SELECT fichier FROM spip_documents WHERE id_document = $id_document"))) return ($row['fichier']); return ''; diff --git a/spip_acces_doc.php3 b/spip_acces_doc.php3 index ce2b4cee38..32551f02f1 100644 --- a/spip_acces_doc.php3 +++ b/spip_acces_doc.php3 @@ -9,78 +9,9 @@ * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * \***************************************************************************/ + // compatibilite -# script d'acces aux documents joints -# doit etre appele avec un de ces 2 parametres de GET: -# - id_document -# - file -# il verifie soit que le demandeur est authentifie -# soit que le fichier est joint à au moins 1 article, breve ou rubrique - -$id_document = ($_GET['id_document']); -$file = urldecode($_GET['file']); -if (strpos($file,'../') !== false) - $refus = 1; -else - { - $refus = false; - include ("ecrire/inc_version.php3"); - include_local(_FILE_CONNECT); - include_ecrire("inc_meta.php3"); - include_ecrire("inc_session.php3"); - - global $auteur_session; - if ($cookie_session = $_COOKIE['spip_session']) - { - if (verifier_session($cookie_session)) - { - if ($auteur_session['statut'] == '0minirezo' - OR $auteur_session['statut'] == '1comite') - $auth_login = $auteur_session['login']; - } - } - - if (!$id_document) { - $id_document = @spip_fetch_array(spip_query("select id_document from spip_documents as documents where documents.fichier='".$file."'")); - if (!$id_document) $refus = 2; - $id_document = $id_document['id_document']; - } else { - $file = @spip_fetch_array(spip_query("select fichier from spip_documents as documents where id_document='". $id_document ."'")); - if (!$file) $refus = 3; - $file = $file['fichier']; - } - } - -if (!$auth_login && !$refus) { - if (!spip_num_rows(spip_query("select articles.id_article -from spip_documents_articles as rel_articles, spip_articles as articles -where rel_articles.id_article = articles.id_article AND -articles.statut = 'publie' AND rel_articles.id_document ='". - $id_document . - "' LIMIT 1"))) { - if (!spip_num_rows(spip_query("select rubriques.id_rubrique -from spip_documents_rubriques as rel_rubriques, spip_rubriques as rubriques -where rel_rubriques.id_rubrique = rubriques.id_rubrique AND -rubriques.statut = 'publie' AND rel_rubriques.id_document ='". - $id_document . - "' LIMIT 1"))) { - if (!spip_num_rows(spip_query("select breves.id_breve -from spip_documents_breves as rel_breves, spip_breves as breves -where rel_breves.id_breve = breves.id_breve AND -breves.statut = 'publie' AND rel_breves.id_document ='". - $id_document . - "' LIMIT 1"))) - $refus = 4; } } } - -if (!$refus) - { - header("Content-Type: ". mime_content_type($file)); - header("Content-Length: ". filesize($file)); - header("Content-Disposition: attachment; filename=\"". basename($file) ."\";"); - header("Content-Transfer-Encoding: binary"); - readfile($file); - } - else - spip_log("Acces refuse ($refus) au document " . ($_GET['id_document']) . ': ' .($_GET['file'])); - +header("Location: " . + str_replace('spip_acces_doc.php', 'spip_image.php', + $_SERVER['REQUEST_URI'])); ?> \ No newline at end of file diff --git a/spip_image.php3 b/spip_image.php3 index 6e7bb4c495..bc7e3db12b 100644 --- a/spip_image.php3 +++ b/spip_image.php3 @@ -10,78 +10,26 @@ * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * \***************************************************************************/ - // Charger un document, une image, un logo, un repertoire // supprimer cet element, creer les vignettes, etc. include ("ecrire/inc_version.php3"); -include_ecrire('inc_presentation.php3');# regler la langue en cas d'erreur -include_ecrire('inc_getdocument.php3'); # diverses fonctions de ce fichier -include_ecrire("inc_charsets.php3"); # pour le nom de fichier -include_ecrire("inc_meta.php3"); # ne pas faire confiance au cache - # (alea_ephemere a peut-etre change) -include_ecrire("inc_admin.php3"); # verifier_action_auteur -include_ecrire("inc_abstract_sql.php3");# spip_insert -include_ecrire('inc_documents.php3'); # fichiers_upload() - -if ($test_vignette) - redirige_par_entete(tester_vignette($test_vignette)); - -else { - if (!verifier_action_auteur("$action $doc", $hash, $hash_id_auteur)) - die ('Interdit'); - - $documents_actifs = array(); - - if ($action == 'joindre') { - - // pas terrible, mais c'est le pb du bouton Submit qui retourne son texte, - // et son transcodage est couteux et perilleux - $action .= - ($sousaction1 ? 1 : - ($sousaction2 ? 2 : - ($sousaction3 ? 3 : - ($sousaction4 ? 4 : - $sousaction5 )))); - - $arg = ($sousaction1 ? ($_FILES ? $_FILES : $HTTP_POST_FILES) : - ($sousaction2 ? $url : $chemin)); - - if (function_exists($action)) - $action($arg, $doc, $type, $id_article, $id_document, - $hash, $hash_id_auteur, $redirect, $documents_actifs); - - else spip_log("spip_image: action inconnue $action"); - } - else if ($action == 'ajout_logo') { - - if (!$_FILES) $_FILES = $HTTP_POST_FILES; - $desc = $sousaction2 ? $chemin : (is_array($_FILES) ? array_pop($_FILES) : ""); - if ($desc) ajout_logo($desc, $doc); - } - - else if ($action == "effacer_logo") { - effacer_logo($doc); - } - else if ($action == 'supprime_document_et_vignette') { - supprime_document_et_vignette($doc); - } +$nom = "spip_image"; - else if ($action = 'tourner_document') { - tourner_document($var_rot, $doc, $convert_command); - } +$f = find_in_path('inc_' . $nom . '.php'); - else spip_log("spip_image: action inconnue $action"); - } -// -// Retour a l'envoyeur -// +if ($f) + include($f); +elseif (file_exists($f = (_DIR_INCLUDE . 'inc_' . $nom . '.php'))) + include($f); +$nom .= '_' . $action; -$link = new Link(_DIR_RESTREINT_ABS . $redirect); -if ($documents_actifs) { - $link->addVar('show_docs',join('-',$documents_actifs)); - } -redirige_par_entete($link->getUrl($ancre)); +if (function_exists($nom)) + $nom($doc); +elseif (function_exists($f = $nom . '_' . "_dist")) + $f($doc); + else + spip_log("fonction $nom indisponible"); ?> -- GitLab