[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins-dist / medias / action / copier_local.php
index b1bf543..0ab0d11 100644 (file)
@@ -10,7 +10,9 @@
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
 \***************************************************************************/
 
-if (!defined("_ECRIRE_INC_VERSION")) return;
+if (!defined('_ECRIRE_INC_VERSION')) {
+       return;
+}
 
 /**
  * Fonction appellee lorsque l'utilisateur clique sur le bouton
@@ -18,32 +20,33 @@ if (!defined("_ECRIRE_INC_VERSION")) return;
  * Il s'agit de la partie logique, c'est a dire que cette fonction
  * realise la copie.
  *
- * http://code.spip.net/@action_copier_local_dist
+ * https://code.spip.net/@action_copier_local_dist
  *
  * @param null $id_document
  * @return bool|mixed|string
  */
-function action_copier_local_dist($id_document=null) {
+function action_copier_local_dist($id_document = null) {
 
-       if (!$id_document){
+       if (!$id_document) {
                // Recupere les arguments.
                $securiser_action = charger_fonction('securiser_action', 'inc');
                $arg = $securiser_action();
-       
+
                $id_document = intval($arg);
        }
 
        if (!$id_document) {
                spip_log("action_copier_local_dist $arg pas compris");
+
                return false;
-       } else  {
+       } else {
                // arguments recuperes, on peut maintenant appeler la fonction.
                return action_copier_local_post($id_document);
        }
 }
 
 /**
- * http://code.spip.net/@action_copier_local_post
+ * https://code.spip.net/@action_copier_local_post
  *
  * @param  $id_document
  * @return bool|mixed|string
@@ -51,38 +54,40 @@ function action_copier_local_dist($id_document=null) {
 function action_copier_local_post($id_document) {
 
        // Il faut la source du document pour le copier
-       $row = sql_fetsel("mode,fichier, descriptif, credits", "spip_documents", "id_document=$id_document");
+       $row = sql_fetsel('mode,fichier, descriptif, credits', 'spip_documents', 'id_document='.intval($id_document));
        $source = $row['fichier'];
 
        // si la source est bien un fichier distant
        // sinon c'est une donnee moisie, on ne fait rien
-       if (tester_url_absolue($source)){
-       
+       if (tester_url_absolue($source)) {
                include_spip('inc/distant'); // pour 'copie_locale'
                $fichier = copie_locale($source);
-               if ($fichier) {
+               if ($fichier
+                       and tester_url_absolue($source)) {
                        $fichier = _DIR_RACINE . $fichier;
-                       $files[] = array('tmp_name'=>$fichier,'name'=>basename($fichier));
-                       $ajouter_documents = charger_fonction('ajouter_documents','action');
-                       spip_log("convertit doc $id_document en local: $source => $fichier");
+                       $files = array();
+                       $files[] = array('tmp_name' => $fichier, 'name' => basename($fichier));
+                       $ajouter_documents = charger_fonction('ajouter_documents', 'action');
+                       spip_log("convertit doc $id_document en local: $source => $fichier", 'medias');
                        $liste = array();
-                       $ajouter_documents($id_document,$files,'',0,$row['mode'],$liste);
-       
+                       $ajouter_documents($id_document, $files, '', 0, $row['mode'], $liste);
+
                        spip_unlink($fichier);
-                       
+
                        // ajouter l'origine du document aux credits
                        include_spip('action/editer_document');
-                       document_modifier($id_document,array('credits'=>($row['credits']?$row['credits'].', ':'').$source));
+                       document_modifier(
+                               $id_document,
+                               array('credits' => ($row['credits'] ? $row['credits'] . ', ' : '') . $source)
+                       );
+
                        return true;
-                       
                } else {
-                       spip_log("echec copie locale $source");
+                       spip_log("echec copie locale $source", 'medias' . _LOG_ERREUR);
                }
        } else {
-               spip_log("echec copie locale $source n'est pas une URL distante", "medias" . _LOG_ERREUR);
+               spip_log("echec copie locale $source n'est pas une URL distante", 'medias' . _LOG_ERREUR);
        }
-               
-       return _T('medias:erreur_copie_fichier',array('nom'=>$source));
-}
 
-?>
+       return _T('medias:erreur_copie_fichier', array('nom' => $source));
+}