From 422e75bc372f12dac62a33a54d9c34819e7716ca Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Thu, 20 Oct 2005 16:56:08 +0000 Subject: [PATCH] l'avait jamais du etre bien complexe le repertoire upload vu l'incoherence de l'affichage parfois; mais j'ai commis d'autres bugs a cote moi aussi --- ecrire/inc_documents.php3 | 29 +++++++++++++++++++---------- ecrire/inc_getdocument.php3 | 32 +++++++++++++++++++++++--------- ecrire/inc_spip_image.php | 2 +- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/ecrire/inc_documents.php3 b/ecrire/inc_documents.php3 index 8591e9d0bc..320b581364 100644 --- a/ecrire/inc_documents.php3 +++ b/ecrire/inc_documents.php3 @@ -387,7 +387,7 @@ function fichiers_upload($dir) { function texte_upload_manuel($dir, $inclus = '') { $fichiers = fichiers_upload($dir); $exts = array(); - + $dirs = array(); foreach ($fichiers as $f) { $f = ereg_replace("^$dir/","",$f); if (ereg("\.([^.]+)$", $f, $match)) { @@ -400,18 +400,27 @@ function texte_upload_manuel($dir, $inclus = '') { else $exts[$ext] = 'non'; } - $ledossier = substr($f, 0, strrpos($f,"/")); - $lefichier = substr($f, strrpos($f, "/"), strlen($f)); - - if ($ledossier != $ledossier_prec) { - $texte_upload .= "\n<option value=\"$ledossier\" style='font-weight: bold;'>" + $k = 2*substr_count($f,'/'); + $n = strrpos($f, "/"); + if ($n === false) + $lefichier = $f; + else { + $lefichier = substr($f, $n+1, strlen($f)); + $ledossier = substr($f, 0, $n); + if (!in_array($ledossier, $dirs)) { + $texte_upload .= "\n<option value=\"$ledossier\">" + . str_repeat(" ",$k) ._T('tout_dossier_upload', array('upload' => $ledossier)) ."</option>"; + $dirs[]= $ledossier; + } } - - $ledossier_prec = $ledossier; - - if ($exts[$ext] == 'oui') $texte_upload .= "\n<option value=\"$f\"> $lefichier</option>"; + + if ($exts[$ext] == 'oui') + $texte_upload .= "\n<option value=\"$f\">" . + str_repeat(" ",$k+2) . + $lefichier . + "</option>"; } } diff --git a/ecrire/inc_getdocument.php3 b/ecrire/inc_getdocument.php3 index 0c3316a2ef..d82ca42418 100644 --- a/ecrire/inc_getdocument.php3 +++ b/ecrire/inc_getdocument.php3 @@ -599,6 +599,7 @@ function identifie_repertoire_et_rubrique($DIR, $id_rubrique, $id_auteur, $art=0 if (is_readable($chemin) && (preg_match("/^([a-zA-Z0-9_].*)\.([a-zA-Z0-9]+)$/", $entree, $match))) { $ext = strtolower($match[2]); + if (($ext == 'html') || ($ext == 'htm') || ($ext == 'txt')) $textes[$match[1]] = $match[2]; else { @@ -615,6 +616,18 @@ function identifie_repertoire_et_rubrique($DIR, $id_rubrique, $id_auteur, $art=0 } } closedir($handle); + $collecte = count($textes); + if (isset($textes['index'])) { + + $texte = spip_file_get_contents($DIR . "/index." .$textes['index']); + if (preg_match(',<body[^>]*>(.*)</body>,is', $texte, $match)) + $texte = $match[1]; + $texte = '<html>'. $texte . '</html>'; + $texte = addslashes($texte); + spip_query("UPDATE spip_rubriques SET texte='" .$texte . "' +WHERE id_rubrique=$id_rubrique"); + unset($textes['index']); + } // integration a la base SQL en commencant par les textes, // afin de savoir combien ont ete crees, a chaque niveau. @@ -622,15 +635,15 @@ function identifie_repertoire_et_rubrique($DIR, $id_rubrique, $id_auteur, $art=0 if ($textes) { ksort($textes); foreach($textes as $k=>$v) { - $titre= addslashes(trim(preg_replace('/[-_]/', ' ', $k))); $chemin = "$DIR/$k." . $v; $texte = spip_file_get_contents($chemin); if ($v[0] == 'h') { // cas du html if (preg_match(',<body[^>]*>(.*)</body>,is', $texte, $match)) - $texte = '<html>'. $match[1] . '</html>'; - } + $texte = $match[1]; + $texte = '<html>'. $texte . '</html>'; + } else {$texte = '<pre>'. $texte . '</pre>';} $texte = addslashes($texte); $date = date("Y-m-d H:i:s", filemtime($chemin)); $art=spip_abstract_insert($GLOBALS['table_prefix']. "_articles", @@ -642,14 +655,15 @@ function identifie_repertoire_et_rubrique($DIR, $id_rubrique, $id_auteur, $art=0 } } + // si la rubrique a 0 ou 1 article, les documents sont // joints l'article present ou de niveau superieur, sinon a la rubrique. - $n = count($textes); - if (($n <= 1) AND $art) + + if (($collecte <= 1) AND $art) {$type = 'article'; $id = $art;} else - {$type = 'rubrique'; $id = $id_rubrique; $n = count($docs);} + {$type = 'rubrique'; $id = $id_rubrique; $collecte += count($docs);} if ($docs) { foreach($docs as $v) @@ -659,20 +673,20 @@ function identifie_repertoire_et_rubrique($DIR, $id_rubrique, $id_auteur, $art=0 if ($rubriques) { foreach ($rubriques as $k => $v) { + $rub=spip_abstract_insert($GLOBALS['table_prefix'] . "_rubriques", "(titre,id_parent,statut)", "('" . addslashes($v) . "', $id_rubrique, 'prepa')"); $m = identifie_repertoire_et_rubrique($k, $rub, $id_auteur, $art); if ($m) - $n++; + $collecte+=$m; else { // faudrait essayer de prevenir plutot que de guerir spip_query("DELETE FROM spip_rubriques WHERE id_rubrique=$rub"); } } } - - return $n; + return $collecte; } diff --git a/ecrire/inc_spip_image.php b/ecrire/inc_spip_image.php index a91052c59d..c46d1b55ea 100644 --- a/ecrire/inc_spip_image.php +++ b/ecrire/inc_spip_image.php @@ -133,7 +133,7 @@ function spip_image_joindre4($arg, $mode, $type, $id, $id_document, $hash, $hash { if (!$arg || strstr($arg, '..')) return; $upload = (_DIR_TRANSFERT .$arg); - identifie_repertoire_et_rubrique($upload, $id, $id_auteur); + identifie_repertoire_et_rubrique($upload, $id, $hash_id_auteur); include_ecrire("inc_rubriques.php3"); calculer_rubriques(); } -- GitLab