Index: extensions/flickr2piwigo/include/functions.inc.php
===================================================================
--- extensions/flickr2piwigo/include/functions.inc.php	(revision 17312)
+++ extensions/flickr2piwigo/include/functions.inc.php	(revision 17312)
@@ -0,0 +1,107 @@
+<?php
+if (!defined('FLICKR_PATH')) die('Hacking attempt!');
+
+/**
+ * download a remote file
+ *  - needs cURL or allow_url_fopen
+ *  - take care of SSL urls
+ *
+ * @param: string source url
+ * @param: mixed destination file (if true, file content is returned)
+ */
+if (!function_exists('download_remote_file'))
+{
+  function download_remote_file($src, $dest)
+  {
+    if (empty($src))
+    {
+      return false;
+    }
+    
+    $return = ($dest === true) ? true : false;
+    
+    /* curl */
+    if (function_exists('curl_init'))
+    {
+      if (!$return)
+      {
+        $newf = fopen($dest, "wb");
+      }
+      $ch = curl_init();
+      
+      curl_setopt($ch, CURLOPT_URL, $src);
+      curl_setopt($ch, CURLOPT_HEADER, 0);
+      curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-language: en"));
+      curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
+      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+      curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
+      if (strpos($src, 'https://') !== false)
+      {
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+      }
+      if (!$return)
+      {
+        curl_setopt($ch, CURLOPT_FILE, $newf);
+      }
+      else
+      {
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+      }
+      
+      if (($out = curl_exec($ch)) === false)
+      {
+        return 'file_error';
+      }
+      
+      curl_close($ch);
+      
+      if (!$return)
+      {
+        fclose($newf);
+        return true;
+      }
+      else
+      {
+        return $out;
+      }
+    }
+    /* file get content */
+    else if (ini_get('allow_url_fopen'))
+    {
+      if (strpos($src, 'https://') !== false and !extension_loaded('openssl'))
+      {
+        return false;
+      }
+      
+      $opts = array(
+        'http' => array(
+          'method' => "GET",
+          'user_agent' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
+          'header' => "Accept-language: en",
+        )
+      );
+
+      $context = stream_context_create($opts);
+      
+      if (($file = file_get_contents($src, false, $context)) === false)
+      {
+        return 'file_error';
+      }
+      
+      if (!$return)
+      {
+        file_put_contents($dest, $file);
+        return true;
+      }
+      else
+      {
+        return $file;
+      }
+    }
+    
+    return false;
+  }
+}
+
+?>
Index: extensions/flickr2piwigo/include/ws_functions.inc.php
===================================================================
--- extensions/flickr2piwigo/include/ws_functions.inc.php	(revision 17256)
+++ extensions/flickr2piwigo/include/ws_functions.inc.php	(revision 17312)
@@ -35,4 +35,5 @@
   include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
   include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
+  include_once(FLICKR_PATH . 'include/functions.inc.php');
   
   // init flickr API
@@ -127,41 +128,3 @@
 }
 
-function download_remote_file($src, $dest)
-{
-  if (function_exists('curl_init'))
-  {
-    $newf = fopen($dest, "wb");
-    $ch = curl_init();
-    
-    curl_setopt($ch, CURLOPT_URL, $src);
-    curl_setopt($ch, CURLOPT_HEADER, 0);
-    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
-    curl_setopt($ch, CURLOPT_FILE, $newf);
-    
-    curl_exec($ch);
-    curl_close($ch);
-    fclose($newf);
-    
-    return true;
-  }
-  else if (ini_get('allow_url_fopen'))
-  {
-    $file = fopen($src, "rb");
-    $newf = fopen($dest, "wb");
-    
-    while (!feof($file))
-    {
-      fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
-    }
-    
-    fclose($file);
-    fclose($newf);
-    
-    return true;
-  }
-  
-  return false;
-}
-
-
 ?>
