Changeset 4699


Ignore:
Timestamp:
01/17/10 23:54:23 (10 years ago)
Author:
patdenice
Message:

[Plugin][Piwigo Auto Upgrade]
Check upgrade with ajax (avoid timeout)
Check also plugins upgrades

Location:
extensions/autoupdate
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • extensions/autoupdate/autoupdate.php

    r4541 r4699  
    11<?php 
    22 
    3 /* Fetch remote function with timeout */ 
    4 function autoupdate_fetchRemote($src, &$dest, $timeout=15, $user_agent='Piwigo', $step=0) 
     3load_language('plugin.lang', dirname(__FILE__).'/'); 
     4 
     5if (isset($_GET['action']) and $_GET['action'] == 'check_autoupdate') 
    56{ 
    6   // Try to retrieve data from local file? 
    7   if (!url_is_remote($src)) 
    8   { 
    9     $content = @file_get_contents($src); 
    10     if ($content !== false) 
    11     { 
    12       is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 
    13       return true; 
    14     } 
    15     else 
    16     { 
    17       return false; 
    18     } 
    19   } 
    20  
    21   // After 3 redirections, return false 
    22   if ($step > 3) return false; 
    23  
    24   // Initialize $dest 
    25   is_resource($dest) or $dest = ''; 
    26  
    27   // Try curl to read remote file 
    28   if (function_exists('curl_init')) 
    29   { 
    30     $ch = @curl_init(); 
    31     @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
    32     @curl_setopt($ch, CURLOPT_URL, $src); 
    33     @curl_setopt($ch, CURLOPT_HEADER, 1); 
    34     @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); 
    35     @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    36     $content = @curl_exec($ch); 
    37     $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); 
    38     $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    39     @curl_close($content); 
    40     if ($content !== false and $status >= 200 and $status < 400) 
    41     { 
    42       if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m)) 
    43       { 
    44         return autoupdate_fetchRemote($m[1], $dest, $user_agent, $step+1); 
    45       } 
    46       $content = substr($content, $header_length); 
    47       is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 
    48       return true; 
    49     } 
    50   } 
    51  
    52   // Try file_get_contents to read remote file 
    53   if (ini_get('allow_url_fopen')) 
    54   { 
    55     $opts['http'] = array('timeout' => $timeout); 
    56     $ctx = stream_context_create($opts); 
    57     $content = @file_get_contents($src, 0, $ctx); 
    58     if ($content !== false) 
    59     { 
    60       is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 
    61       return true; 
    62     } 
    63   } 
    64  
    65   return false; 
     7  unset($_SESSION['need_update']); 
     8  unset($_SESSION['plugins_need_update']); 
    669} 
    67  
    68 function autoupdate_deltree($path) 
    69 { 
    70   if (is_dir($path)) 
    71   { 
    72     $fh = opendir($path); 
    73     while ($file = readdir($fh)) 
    74     { 
    75       if ($file != '.' and $file != '..') 
    76       { 
    77         $pathfile = $path . '/' . $file; 
    78         if (is_dir($pathfile)) 
    79         { 
    80           autoupdate_deltree($pathfile); 
    81         } 
    82         else 
    83         { 
    84           @unlink($pathfile); 
    85         } 
    86       } 
    87     } 
    88     closedir($fh); 
    89     return @rmdir($path); 
    90   } 
    91 } 
    92  
    93 function check_version_for_autoupdate($version=PHPWG_VERSION) 
    94 { 
    95   global $conf, $header_notes; 
    96  
    97   if (preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches) and @autoupdate_fetchRemote(PHPWG_URL.'/download/latest_version', $result, 1)) 
    98   { 
    99     $lines = @explode("\r\n", $result); 
    100     $new_version = trim($lines[1]); 
    101     $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $new_version); 
    102     $actual_branch = $matches[1]; 
    103     $update_to =  $actual_branch . '.' . ($matches[2]+1); 
    104  
    105     if (version_compare($version, $new_version) < 0 
    106       and $actual_branch == $new_branch) 
    107     { 
    108       $path = $conf['local_data_dir'].'/autoupdate/'; 
    109       $code = $version.'_to_'.$update_to; 
    110       $filename = $path.$version.'_to_'.$update_to.'.zip'; 
    111       mkgetdir($path); 
    112  
    113       if (!file_exists($filename) or !filesize($filename)) 
    114       { 
    115         $zip = @fopen($filename, 'w+'); 
    116         @autoupdate_fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.str_replace(array('.', '_'), '', $code), $zip); 
    117         @fclose($zip); 
    118       } 
    119  
    120       if (file_exists($filename) and filesize($filename)) 
    121       { 
    122         if (isset($_GET['autoupdate']) and preg_match('/\d+\.\d+\.\d+_to_'.preg_quote($version).'/', $_GET['autoupdate'])) 
    123         { 
    124           redirect('admin.php?autoupdate='.$code); 
    125         } 
    126         else 
    127         { 
    128           array_push($header_notes, 
    129             '<p>'.l10n('A new version of Piwigo is available.').'<br>', 
    130             '<a href="admin.php?autoupdate='.$code.'" onClick="return confirm(\''.l10n('autoupdate_alert').'\');">'.l10n('Click here to upgrade automatically').'</a></p>' 
    131           ); 
    132         } 
    133       } 
    134     } 
    135   } 
    136 } 
    137  
    138 load_language('plugin.lang', dirname(__FILE__).'/'); 
    13910 
    14011if (isset($_GET['autoupdate'])) 
     
    14617  elseif ($file = $conf['local_data_dir'].'/autoupdate/'.$_GET['autoupdate'].'.zip' and file_exists($file)) 
    14718  { 
     19    include(dirname(__FILE__).'/class.inc.php'); 
    14820    include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); 
     21    $autoupdate = new autoupdate(); 
    14922    $zip = new PclZip($file); 
    15023    if ($result = $zip->extract(PCLZIP_OPT_PATH, PHPWG_ROOT_PATH, 
     
    19467            elseif (is_dir($path)) 
    19568            { 
    196               autoupdate_deltree($path); 
     69              $autoupdate->deltree($path); 
    19770            } 
    19871          } 
     
    20073        if (preg_match('/\d+\.\d+\.\d+_to_(\d+\.\d+\.\d+)/', $_GET['autoupdate'], $matches)) 
    20174        { 
    202           check_version_for_autoupdate($matches[1]); 
     75          unset($_SESSION['need_update']); 
     76          $autoupdate->check_version($matches[1]); 
    20377        } 
    204         autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); 
     78        $autoupdate->deltree($conf['local_data_dir'].'/autoupdate'); 
    20579        invalidate_user_cache(true); 
    20680        $template->delete_compiled_templates(); 
     
    21690    else 
    21791    { 
    218       autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); 
     92      $autoupdate->deltree($conf['local_data_dir'].'/autoupdate'); 
    21993      array_push($page['errors'], l10n('autoupdate_fail')); 
    22094    } 
     
    226100  } 
    227101} 
    228 else 
    229 { 
    230   check_version_for_autoupdate(); 
    231 } 
     102 
     103$template->set_filename('autoupdate_head', realpath(dirname(__FILE__).'/head.tpl')); 
     104array_push($header_notes, $template->parse('autoupdate_head', true)); 
    232105 
    233106?> 
  • extensions/autoupdate/language/en_UK/plugin.lang.php

    r4007 r4699  
    88$lang['autoupdate_extract_fail'] = 'An error occured during extract. Please check files permissions of your piwigo installation.<br><a href="%s">Click here to show log error</a>.'; 
    99 
     10$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo cannot retrieve upgrade file from server'; 
     11$lang['Click here to see Piwigo %s release notes'] = 'Click here to see Piwigo %s release notes'; 
     12$lang['Some upgrades are available for you plugins'] = 'Some upgrades are available for you plugins'; 
     13$lang['Click here see upgrade plugins page'] = 'Click here see upgrade plugins page'; 
     14$lang['Gallery and plugins are up to date'] = 'Gallery and plugins are up to date'; 
     15$lang['Unable to check upgrades...'] = 'Unable to check upgrades...'; 
     16$lang['Piwigo will automaticaly try again later.'] = 'Piwigo will automaticaly try again later.'; 
     17$lang['Click here to check upgrades now'] = 'Click here to check upgrades now'; 
     18 
    1019?> 
  • extensions/autoupdate/language/es_ES/plugin.lang.php

    r4028 r4699  
    88$lang['autoupdate_extract_fail'] = 'Imposible extraer los ficheros. Por favor, verifique los permisos de los ficheros de su instalación. <Br> <a href="%s"> Haga clic aquí para ver el informe de error</a>.'; 
    99 
     10/*TODO*/$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo cannot retrieve upgrade file from server'; 
     11/*TODO*/$lang['Click here to see Piwigo %s release notes'] = 'Click here to see Piwigo %s release notes'; 
     12/*TODO*/$lang['Some upgrades are available for you plugins'] = 'Some upgrades are available for you plugins'; 
     13/*TODO*/$lang['Click here see upgrade plugins page'] = 'Click here see upgrade plugins page'; 
     14/*TODO*/$lang['Gallery and plugins are up to date'] = 'Gallery and plugins are up to date'; 
     15/*TODO*/$lang['Unable to check upgrades...'] = 'Unable to check upgrades...'; 
     16/*TODO*/$lang['Piwigo will automaticaly try again later.'] = 'Piwigo will automaticaly try again later.'; 
     17/*TODO*/$lang['Click here to check upgrades now'] = 'Click here to check upgrades now'; 
     18 
    1019?> 
  • extensions/autoupdate/language/fr_FR/plugin.lang.php

    r4007 r4699  
    88$lang['autoupdate_extract_fail'] = 'Impossible d\'extraire les fichiers. Veuillez vérifier les permissions des fichiers de votre installation.<br><a href="%s">Cliquez ici pour voir le rapport d\'erreur</a>.'; 
    99 
     10$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo ne peut pas récupérer le fichier de mise à jour depuis le serveur'; 
     11$lang['Click here to see Piwigo %s release notes'] = 'Cliquez ici pour afficher les informations relatives à Piwigo %s'; 
     12$lang['Some upgrades are available for you plugins'] = 'Des mises à jour sont disponibles pour vos plugins'; 
     13$lang['Click here see upgrade plugins page'] = 'Cliquez ici pour afficher la page de mise à jour des plugins'; 
     14$lang['Gallery and plugins are up to date'] = 'Votre galerie et vos plugins sont à jour'; 
     15$lang['Unable to check upgrades...'] = 'Impossible de vérifier les mises à jour...'; 
     16$lang['Click here to check upgrades now'] = 'Cliquez ici pour vérifier les mises à jour maintenant'; 
    1017?> 
  • extensions/autoupdate/language/hu_HU/plugin.lang.php

    r4232 r4699  
    88$lang['autoupdate_extract_fail'] = 'Hibajelentés (Információ). Kérjük ellenőrizze a telepített fájlok jogosultságait.<br><a href="%s">További információkért kattintson ide</a>.'; 
    99 
     10/*TODO*/$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo cannot retrieve upgrade file from server'; 
     11/*TODO*/$lang['Click here to see Piwigo %s release notes'] = 'Click here to see Piwigo %s release notes'; 
     12/*TODO*/$lang['Some upgrades are available for you plugins'] = 'Some upgrades are available for you plugins'; 
     13/*TODO*/$lang['Click here see upgrade plugins page'] = 'Click here see upgrade plugins page'; 
     14/*TODO*/$lang['Gallery and plugins are up to date'] = 'Gallery and plugins are up to date'; 
     15/*TODO*/$lang['Unable to check upgrades...'] = 'Unable to check upgrades...'; 
     16/*TODO*/$lang['Piwigo will automaticaly try again later.'] = 'Piwigo will automaticaly try again later.'; 
     17/*TODO*/$lang['Click here to check upgrades now'] = 'Click here to check upgrades now'; 
     18 
    1019?> 
  • extensions/autoupdate/language/it_IT/plugin.lang.php

    r4037 r4699  
    88$lang['autoupdate_extract_fail'] = 'Non è stato possibile estrarre i file. Verificare i permessi dei file della vostra installazione.<br><a href="%s">Cliccare qui per visualizzare il rapporto degli errori</a>.'; 
    99 
     10/*TODO*/$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo cannot retrieve upgrade file from server'; 
     11/*TODO*/$lang['Click here to see Piwigo %s release notes'] = 'Click here to see Piwigo %s release notes'; 
     12/*TODO*/$lang['Some upgrades are available for you plugins'] = 'Some upgrades are available for you plugins'; 
     13/*TODO*/$lang['Click here see upgrade plugins page'] = 'Click here see upgrade plugins page'; 
     14/*TODO*/$lang['Gallery and plugins are up to date'] = 'Gallery and plugins are up to date'; 
     15/*TODO*/$lang['Unable to check upgrades...'] = 'Unable to check upgrades...'; 
     16/*TODO*/$lang['Piwigo will automaticaly try again later.'] = 'Piwigo will automaticaly try again later.'; 
     17/*TODO*/$lang['Click here to check upgrades now'] = 'Click here to check upgrades now'; 
     18 
    1019?> 
  • extensions/autoupdate/language/pl_PL/plugin.lang.php

    r4277 r4699  
    88$lang['autoupdate_extract_fail'] = 'Wystąpił błąd podczas rozpokowywania. Sprawdź uprawnienia do plików w katalogu gdize jest zainstalowane piwigo.<br><a href="%s">Kliknij aby zobaczyć błędy</a>.'; 
    99 
     10/*TODO*/$lang['Piwigo cannot retrieve upgrade file from server'] = 'Piwigo cannot retrieve upgrade file from server'; 
     11/*TODO*/$lang['Click here to see Piwigo %s release notes'] = 'Click here to see Piwigo %s release notes'; 
     12/*TODO*/$lang['Some upgrades are available for you plugins'] = 'Some upgrades are available for you plugins'; 
     13/*TODO*/$lang['Click here see upgrade plugins page'] = 'Click here see upgrade plugins page'; 
     14/*TODO*/$lang['Gallery and plugins are up to date'] = 'Gallery and plugins are up to date'; 
     15/*TODO*/$lang['Unable to check upgrades...'] = 'Unable to check upgrades...'; 
     16/*TODO*/$lang['Piwigo will automaticaly try again later.'] = 'Piwigo will automaticaly try again later.'; 
     17/*TODO*/$lang['Click here to check upgrades now'] = 'Click here to check upgrades now'; 
     18 
    1019?> 
  • extensions/autoupdate/main.inc.php

    r3604 r4699  
    1616{ 
    1717  global $template, $page, $conf, $header_notes; 
    18   if ($page['page'] == 'intro') include(dirname(__FILE__).'/autoupdate.php'); 
     18 
     19  if ($page['page'] == 'intro') 
     20  { 
     21    include(dirname(__FILE__).'/autoupdate.php'); 
     22  } 
     23 
    1924  return $plugin_menu_links; 
    2025} 
Note: See TracChangeset for help on using the changeset viewer.