Changeset 16085


Ignore:
Timestamp:
06/27/12 11:03:10 (7 years ago)
Author:
mistic100
Message:

add curl download, and display error if no download method (curl or allow_url_fopen) available

Location:
extensions/flickr2piwigo
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/flickr2piwigo/admin/import.php

    r16071 r16085  
    66{ 
    77  array_push($page['warnings'], l10n('Please fill your API keys on the configuration tab')); 
     8  $_GET['action'] = 'error'; 
     9} 
     10else if ( !function_exists('curl_init') and !ini_get('allow_url_fopen') ) 
     11{ 
     12  array_push($page['errors'], l10n('No download method available')); 
    813  $_GET['action'] = 'error'; 
    914} 
     
    2934  } 
    3035} 
     36 
    3137 
    3238if (!isset($_GET['action'])) $_GET['action'] = 'main'; 
  • extensions/flickr2piwigo/include/ws_functions.inc.php

    r16071 r16085  
    5555   
    5656  // copy file 
    57   $file = fopen($photo['url'], "rb"); 
    58   $newf = fopen($photo['path'], "wb"); 
    59   while (!feof($file)) 
     57  if (download_remote_file($photo['url'], $photo['path']) == false) 
    6058  { 
    61     fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 ); 
     59    return new PwgError(500, l10n('No download method available')); 
    6260  } 
    63   fclose($file); 
    64   fclose($newf); 
    6561   
    6662  // category 
     
    131127} 
    132128 
     129function download_remote_file($src, $dest) 
     130{ 
     131  if (function_exists('curl_init')) 
     132  { 
     133    $newf = fopen($dest, "wb"); 
     134    $ch = curl_init(); 
     135     
     136    curl_setopt($ch, CURLOPT_URL, $src); 
     137    curl_setopt($ch, CURLOPT_HEADER, 0); 
     138    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'); 
     139    curl_setopt($ch, CURLOPT_FILE, $newf); 
     140     
     141    curl_exec($ch); 
     142    curl_close($ch); 
     143    fclose($newf); 
     144     
     145    return true; 
     146  } 
     147  else if (ini_get('allow_url_fopen')) 
     148  { 
     149    $file = fopen($src, "rb"); 
     150    $newf = fopen($dest, "wb"); 
     151     
     152    while (!feof($file)) 
     153    { 
     154      fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 ); 
     155    } 
     156     
     157    fclose($file); 
     158    fclose($newf); 
     159     
     160    return true; 
     161  } 
     162   
     163  return false; 
     164} 
     165 
     166 
    133167?> 
  • extensions/flickr2piwigo/language/en_UK/plugin.lang.php

    r16071 r16085  
    2828$lang['Begin transfert'] = 'Begin transfert'; 
    2929$lang['Open Flickr page in a new tab'] = 'Open Flickr page in a new tab'; 
     30$lang['No download method available'] = 'No download method available'; 
    3031 
    3132?> 
  • extensions/flickr2piwigo/language/fr_FR/plugin.lang.php

    r16071 r16085  
    2828$lang['Begin transfert'] = 'Commencer les transfert'; 
    2929$lang['Open Flickr page in a new tab'] = 'Ouvrir la page Flickr dans un nouvel onglet'; 
     30$lang['No download method available'] = 'Aucune méthode de téléchargement n\'est disponible'; 
    3031 
    3132?> 
Note: See TracChangeset for help on using the changeset viewer.