Skip to content
Extraits de code Groupes Projets
Valider f4b023b1 rédigé par esj's avatar esj
Parcourir les fichiers

Tâche #587, mais on en profite pour revoir l'interface de la fonction d'ajout...

Tâche #587, mais on en profite pour revoir l'interface de la fonction d'ajout de document qui était bancale.
parent 32e353e0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -93,8 +93,7 @@ function action_joindre_dist() ...@@ -93,8 +93,7 @@ function action_joindre_dist()
// http://doc.spip.org/@spip_action_joindre2 // http://doc.spip.org/@spip_action_joindre2
function spip_action_joindre2($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect) function spip_action_joindre2($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect)
{ {
$ajouter_documents = charger_fonction('ajouter_documents', 'inc'); return joindre_documents(array(
return $ajouter_documents(array(
array('name' => basename($path), array('name' => basename($path),
'tmp_name' => $path) 'tmp_name' => $path)
), 'distant', $type, $id, $id_document, ), 'distant', $type, $id, $id_document,
...@@ -106,7 +105,6 @@ function spip_action_joindre2($path, $mode, $type, $id, $id_document,$hash, $red ...@@ -106,7 +105,6 @@ function spip_action_joindre2($path, $mode, $type, $id, $id_document,$hash, $red
// http://doc.spip.org/@spip_action_joindre1 // http://doc.spip.org/@spip_action_joindre1
function spip_action_joindre1($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect) function spip_action_joindre1($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect)
{ {
$ajouter_documents = charger_fonction('ajouter_documents', 'inc');
$files = array(); $files = array();
if (is_array($path)) if (is_array($path))
foreach ($path as $file) { foreach ($path as $file) {
...@@ -114,7 +112,7 @@ function spip_action_joindre1($path, $mode, $type, $id, $id_document,$hash, $red ...@@ -114,7 +112,7 @@ function spip_action_joindre1($path, $mode, $type, $id, $id_document,$hash, $red
$files[]=$file; $files[]=$file;
} }
return $ajouter_documents($files, $mode, $type, $id, $id_document, return joindre_documents($files, $mode, $type, $id, $id_document,
$hash, $redirect, $actifs, $iframe_redirect); $hash, $redirect, $actifs, $iframe_redirect);
} }
...@@ -144,17 +142,60 @@ function spip_action_joindre3($path, $mode, $type, $id, $id_document,$hash, $red ...@@ -144,17 +142,60 @@ function spip_action_joindre3($path, $mode, $type, $id, $id_document,$hash, $red
} }
} }
return joindre_documents($files, $mode, $type, $id, $id_document, $hash, $redirect, $actifs, $iframe_redirect);
}
//
// Charger la fonction surchargeable receptionnant un fichier
// et l'appliquer sur celui ou ceux indiques.
// http://doc.spip.org/@inc_ajouter_documents
function joindre_documents($files, $mode, $type, $id, $id_document, $hash, $redirect, &$actifs, $iframe_redirect)
{
$ajouter_documents = charger_fonction('ajouter_documents', 'inc'); $ajouter_documents = charger_fonction('ajouter_documents', 'inc');
return $ajouter_documents($files, $mode, $type, $id, $id_document, $hash, $redirect, $actifs, $iframe_redirect);
if (function_exists('gzopen')
AND !($mode == 'distant')
AND (count($files) == 1)) {
$desc = $files[0];
if (preg_match('/\.zip$/i', $desc['name'])
OR ($desc['type'] == 'application/zip')) {
// on pose le fichier dans le repertoire zip
// (nota : copier_document n'ecrase pas un fichier avec lui-meme
// ca autorise a boucler)
$zip = copier_document("zip",
$desc['name'],
$desc['tmp_name']
);
if (!$zip) die ('Erreur upload zip'); # pathologique
// Est-ce qu'on sait le lire ?
include_spip('inc/pclzip');
$archive = new PclZip($zip);
if ($archive) {
$valables = verifier_compactes($archive);
if ($valables) {
echo liste_archive_jointe($valables, $mode, $type, $id, $id_document, $hash, $redirect, $zip, $iframe_redirect);
// a tout de suite en joindre4, joindre5, ou joindre6
exit;
}
}
}
}
foreach ($files as $arg) {
check_upload_error($arg['error']);
$x = $ajouter_documents($arg['tmp_name'], $arg['name'],
$type, $id, $mode, $id_document, $actifs);
}
return $x;
} }
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
// sous-actions suite a l'envoi d'un Zip: // sous-actions suite a l'envoi d'un Zip:
// la fonction ajouter_documents standard a construit un formulaire // la fonction joindre_documents ci-dessus a construit un formulaire
// qui renvoie sur une des 3 sous-actions qui suivent. // qui renvoie sur une des 3 sous-actions qui suivent.
// On recharge ajouter_document sans l'appeler, car son fichier doit
// contenir les acolytes qui nous interessent (pas bien beau)
// Zip avec confirmation "tel quel" // Zip avec confirmation "tel quel"
...@@ -166,7 +207,7 @@ function spip_action_joindre5($path, $mode, $type, $id, $id_document,$hash, $red ...@@ -166,7 +207,7 @@ function spip_action_joindre5($path, $mode, $type, $id, $id_document,$hash, $red
if (!$pos) { if (!$pos) {
$pos = strpos($path, '/zip_'); $pos = strpos($path, '/zip_');
} }
return ajouter_un_document($path, substr($path, $pos+5), $type, $id, $mode, $id_document, $actifs); return $ajouter_documents($path, substr($path, $pos+5), $type, $id, $mode, $id_document, $actifs);
} }
// Zip a deballer. // Zip a deballer.
...@@ -174,7 +215,6 @@ function spip_action_joindre5($path, $mode, $type, $id, $id_document,$hash, $red ...@@ -174,7 +215,6 @@ function spip_action_joindre5($path, $mode, $type, $id, $id_document,$hash, $red
// http://doc.spip.org/@spip_action_joindre6 // http://doc.spip.org/@spip_action_joindre6
function spip_action_joindre6($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect) function spip_action_joindre6($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect)
{ {
$ajouter_documents = charger_fonction('ajouter_documents', 'inc');
$x = joindre_deballes($path, $mode, $type, $id, $id_document,$hash, $redirect, $actifs); $x = joindre_deballes($path, $mode, $type, $id, $id_document,$hash, $redirect, $actifs);
// suppression de l'archive en zip // suppression de l'archive en zip
@unlink($path); @unlink($path);
...@@ -186,10 +226,34 @@ function spip_action_joindre6($path, $mode, $type, $id, $id_document,$hash, $red ...@@ -186,10 +226,34 @@ function spip_action_joindre6($path, $mode, $type, $id, $id_document,$hash, $red
// http://doc.spip.org/@spip_action_joindre4 // http://doc.spip.org/@spip_action_joindre4
function spip_action_joindre4($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect) function spip_action_joindre4($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs, $iframe_redirect)
{ {
$ajouter_documents = charger_fonction('ajouter_documents', 'inc');
joindre_deballes($path, $mode, $type, $id, $id_document,$hash, $redirect, $actifs); joindre_deballes($path, $mode, $type, $id, $id_document,$hash, $redirect, $actifs);
return spip_action_joindre5($path, $mode, $type, $id, $id_document,$hash, $redirect, $actifs); return spip_action_joindre5($path, $mode, $type, $id, $id_document,$hash, $redirect, $actifs);
} }
// http://doc.spip.org/@joindre_deballes
function joindre_deballes($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs)
{
$ajouter_documents = charger_fonction('ajouter_documents', 'inc');
define('_tmp_dir', creer_repertoire_documents($hash));
if (_tmp_dir == _DIR_DOC) die(_L('Opération impossible'));
include_spip('inc/pclzip');
$archive = new PclZip($path);
$archive->extract(
PCLZIP_OPT_PATH, _tmp_dir,
PCLZIP_CB_PRE_EXTRACT, 'callback_deballe_fichier'
);
$contenu = verifier_compactes($archive);
foreach ($contenu as $fichier) {
$f = basename($fichier);
$x = $ajouter_documents(_tmp_dir. $f, $f,
$type, $id, $mode, $id_document, $actifs);
}
effacer_repertoire_temporaire(_tmp_dir);
return $x;
}
?> ?>
...@@ -28,8 +28,7 @@ include_spip('inc/getdocument'); ...@@ -28,8 +28,7 @@ include_spip('inc/getdocument');
# $id_document, # pour une vignette, l'id_document de maman # $id_document, # pour une vignette, l'id_document de maman
# $actifs # les documents dont il faudra ouvrir la boite de dialogue # $actifs # les documents dont il faudra ouvrir la boite de dialogue
// http://doc.spip.org/@ajouter_un_document function inc_ajouter_documents_dist ($source, $nom_envoye, $type_lien, $id_lien, $mode, $id_document, &$documents_actifs) {
function ajouter_un_document ($source, $nom_envoye, $type_lien, $id_lien, $mode, $id_document, &$documents_actifs) {
// Documents distants : pas trop de verifications bloquantes, mais un test // Documents distants : pas trop de verifications bloquantes, mais un test
// via une requete HEAD pour savoir si la ressource existe (non 404), si le // via une requete HEAD pour savoir si la ressource existe (non 404), si le
...@@ -251,48 +250,6 @@ function ajouter_un_document ($source, $nom_envoye, $type_lien, $id_lien, $mode, ...@@ -251,48 +250,6 @@ function ajouter_un_document ($source, $nom_envoye, $type_lien, $id_lien, $mode,
} }
//
// Traiter la liste des fichiers (action joindre3)
//
// http://doc.spip.org/@inc_ajouter_documents
function inc_ajouter_documents($files, $mode, $type, $id, $id_document, $hash, $redirect, &$actifs, $iframe_redirect)
{
if (function_exists('gzopen')
AND !($mode == 'distant')
AND (count($files) == 1)) {
$desc = $files[0];
if (preg_match('/\.zip$/i', $desc['name'])
OR ($desc['type'] == 'application/zip')) {
// on pose le fichier dans le repertoire zip
// (nota : copier_document n'ecrase pas un fichier avec lui-meme
// ca autorise a boucler)
$zip = copier_document("zip",
$desc['name'],
$desc['tmp_name']
);
if (!$zip) die ('Erreur upload zip'); # pathologique
// Est-ce qu'on sait le lire ?
include_spip('inc/pclzip');
$archive = new PclZip($zip);
if ($archive) {
$valables = verifier_compactes($archive);
if ($valables) {
liste_archive_jointe($valables, $mode, $type, $id, $id_document, $hash, $redirect, $zip, $iframe_redirect);
exit;
}
}
}
}
foreach ($files as $arg) {
check_upload_error($arg['error']);
$x = ajouter_un_document($arg['tmp_name'], $arg['name'],
$type, $id, $mode, $id_document, $actifs);
}
return $x;
}
// http://doc.spip.org/@verifier_compactes // http://doc.spip.org/@verifier_compactes
...@@ -310,28 +267,6 @@ function verifier_compactes($zip) { ...@@ -310,28 +267,6 @@ function verifier_compactes($zip) {
return $aff_fichiers; return $aff_fichiers;
} }
// http://doc.spip.org/@joindre_deballes
function joindre_deballes($path, $mode, $type, $id, $id_document,$hash, $redirect, &$actifs)
{
define('_tmp_dir', creer_repertoire_documents($hash));
if (_tmp_dir == _DIR_DOC) die(_L('Opération impossible'));
include_spip('inc/pclzip');
$archive = new PclZip($path);
$archive->extract(
PCLZIP_OPT_PATH, _tmp_dir,
PCLZIP_CB_PRE_EXTRACT, 'callback_deballe_fichier'
);
$contenu = verifier_compactes($archive);
foreach ($contenu as $fichier)
$x = ajouter_un_document(_tmp_dir.basename($fichier),
basename($fichier),
$type, $id, $mode, $id_document, $actifs);
effacer_repertoire_temporaire(_tmp_dir);
return $x;
}
// //
// Convertit le type numerique retourne par getimagesize() en extension fichier // Convertit le type numerique retourne par getimagesize() en extension fichier
// //
...@@ -449,8 +384,7 @@ function liste_archive_jointe($valables, $mode, $type, $id, $id_document, $hash, ...@@ -449,8 +384,7 @@ function liste_archive_jointe($valables, $mode, $type, $id, $id_document, $hash,
"<div style='text-align: right;'><input class='fondo' style='font-size: 9px;' type='submit' value='". "<div style='text-align: right;'><input class='fondo' style='font-size: 9px;' type='submit' value='".
_T('bouton_valider'). _T('bouton_valider').
"'></div>"; "'></div>";
echo "<p>build form $iframe_redirect</p>"; $action = construire_upload($texte, array(
$action = construire_upload($texte, array(
'redirect' => $redirect, 'redirect' => $redirect,
'iframe_redirect' => $iframe_redirect, 'iframe_redirect' => $iframe_redirect,
'hash' => $hash, 'hash' => $hash,
...@@ -458,25 +392,24 @@ function liste_archive_jointe($valables, $mode, $type, $id, $id_document, $hash, ...@@ -458,25 +392,24 @@ function liste_archive_jointe($valables, $mode, $type, $id, $id_document, $hash,
'arg' => $arg)); 'arg' => $arg));
if(_request("iframe")=="iframe") { if(_request("iframe")=="iframe") {
echo "<div class='upload_answer upload_zip_list'><p>" . return "<p>build form $iframe_redirect</p>" .
_T('upload_fichier_zip_texte') . "<div class='upload_answer upload_zip_list'><p>" .
_T('upload_fichier_zip_texte') .
"</p><p>" . "</p><p>" .
_T('upload_fichier_zip_texte2') . _T('upload_fichier_zip_texte2') .
"</p>" . "</p>" .
$action. $action.
"</div>"; "</div>";
exit; } else {
}
echo minipres(_T('upload_fichier_zip'), return minipres(_T('upload_fichier_zip'),
"<p>" . "<p>" .
_T('upload_fichier_zip_texte') . _T('upload_fichier_zip_texte') .
"</p><p>" . "</p><p>" .
_T('upload_fichier_zip_texte2') . _T('upload_fichier_zip_texte2') .
"</p>" . "</p>" .
$action); $action);
exit; }
// a tout de suite en joindre4, joindre5, ou joindre6
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter