Changeset 2881 for branches/2.0/admin


Ignore:
Timestamp:
Nov 15, 2008, 10:11:58 PM (15 years ago)
Author:
patdenice
Message:

merge -c2880 from trunk to branch 2.0

  • Add fetchRemote function which allow to retrieve datas over HTTP protocol using cURL method, file_get_contents function or fsockopen method. This allow to retrieve datas or files even if allow_url_fopen is deactivated.
  • Use fetchRemote function in plugins manager and in latest version checking.
  • Add german translations for upgrade.lang.php.
  • Remove empty line at the end of pclzip.lib.php.
  • Change display of deactivated plugins after upgrade.
Location:
branches/2.0/admin
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0/admin/include/functions.php

    r2776 r2881  
    19231923}
    19241924
     1925/**
     1926 * Retrieve data from external URL
     1927 *
     1928 * @param string $src: URL
     1929 * @param global $dest: can be a file ressource or string
     1930 * @return bool
     1931 */
     1932function fetchRemote($src, &$dest, $user_agent='Piwigo', $step=0)
     1933{
     1934  is_resource($dest) or $dest = '';
     1935
     1936  // Try curl to read remote file
     1937  if (function_exists('curl_init'))
     1938  {
     1939    $ch = @curl_init();
     1940    @curl_setopt($ch, CURLOPT_URL, $src);
     1941    @curl_setopt($ch, CURLOPT_HEADER, 0);
     1942    @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
     1943    is_resource($dest) ?
     1944      @curl_setopt($ch, CURLOPT_FILE, $dest):
     1945      @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     1946    $content = @curl_exec($ch);
     1947    @curl_close($ch);
     1948    if ($content !== false)
     1949    {
     1950      is_resource($dest) or $dest = $content;
     1951      return true;
     1952    }
     1953  }
     1954
     1955  // Try file_get_contents to read remote file
     1956  if (ini_get('allow_url_fopen'))
     1957  {
     1958    $content = @file_get_contents($src);
     1959    if ($content !== false)
     1960    {
     1961      is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
     1962      return true;
     1963    }
     1964  }
     1965
     1966  // Try fsockopen to read remote file
     1967  if ($step > 3)
     1968  {
     1969    return false;
     1970  }
     1971
     1972  $src = parse_url($src);
     1973  $host = $src['host'];
     1974  $path = isset($src['path']) ? $src['path'] : '/';
     1975  $path .= isset($src['query']) ? '?'.$src['query'] : '';
     1976 
     1977  if (($s = @fsockopen($host,80,$errno,$errstr,5)) === false)
     1978  {
     1979    return false;
     1980  }
     1981
     1982  fwrite($s,
     1983    "GET ".$path." HTTP/1.0\r\n"
     1984    ."Host: ".$host."\r\n"
     1985    ."User-Agent: ".$user_agent."\r\n"
     1986    ."Accept: */*\r\n"
     1987    ."\r\n"
     1988  );
     1989
     1990  $i = 0;
     1991  $in_content = false;
     1992  while (!feof($s))
     1993  {
     1994    $line = fgets($s);
     1995
     1996    if (rtrim($line,"\r\n") == '' && !$in_content)
     1997    {
     1998      $in_content = true;
     1999      $i++;
     2000      continue;
     2001    }
     2002    if ($i == 0)
     2003    {
     2004      if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/',rtrim($line,"\r\n"), $m))
     2005      {
     2006        fclose($s);
     2007        return false;
     2008      }
     2009      $status = (integer) $m[2];
     2010      if ($status < 200 || $status >= 400)
     2011      {
     2012        fclose($s);
     2013        return false;
     2014      }
     2015    }
     2016    if (!$in_content)
     2017    {
     2018      if (preg_match('/Location:\s+?(.+)$/',rtrim($line,"\r\n"),$m))
     2019      {
     2020        fclose($s);
     2021        return fetchRemote(trim($m[1]),$dest,$user_agent,$step+1);
     2022      }
     2023      $i++;
     2024      continue;
     2025    }
     2026    is_resource($dest) ? @fwrite($dest, $line) : $dest .= $line;
     2027    $i++;
     2028  }
     2029  fclose($s);
     2030  return true;
     2031}
     2032
    19252033?>
  • branches/2.0/admin/include/functions_upgrade.php

    r2839 r2881  
    128128
    129129    array_push($page['infos'],
    130       l10n('deactivated plugins') . '<pre>' . implode(', ', $plugins) . '</pre>');
     130      l10n('deactivated plugins').'<br /><br /><i>'.implode(', ', $plugins).'</i><br />');
    131131  }
    132132}
  • branches/2.0/admin/include/plugins.class.php

    r2701 r2881  
    269269    $versions_to_check = array();
    270270    $url = PEM_URL . '/api/get_version_list.php?category_id=12&format=php';
    271     if ($source = @file_get_contents($url)
    272       and $pem_versions = @unserialize($source))
     271    if (fetchRemote($url, $result) and $pem_versions = @unserialize($result))
    273272    {
    274273      if (!preg_match('/^\d+\.\d+\.\d+/', $version))
     
    309308      $url .= implode(',', $plugins_to_check);
    310309    }
    311     if ($source = @file_get_contents($url))
    312     {
    313       $pem_plugins = @unserialize($source);
     310    if (fetchRemote($url, $result))
     311    {
     312      $pem_plugins = @unserialize($result);
    314313      if (!is_array($pem_plugins))
    315314      {
     
    322321      return true;
    323322    }
     323    return false;
    324324  }
    325325 
     
    358358      $url = PEM_URL . '/download.php?rid=' . $revision;
    359359      $url .= '&origin=piwigo_' . $action;
    360       if (@copy($url, $archive))
    361       {
     360
     361      if ($handle = @fopen($archive, 'wb') and fetchRemote($url, $handle))
     362      {
     363        fclose($handle);
    362364        include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
    363365        $zip = new PclZip($archive);
  • branches/2.0/admin/intro.php

    r2529 r2881  
    4343if (isset($_GET['action']) and 'check_upgrade' == $_GET['action'])
    4444{
    45   if (!ini_get('allow_url_fopen'))
     45  if (!fetchRemote(PHPWG_URL.'/latest_version', $result))
    4646  {
    47     array_push(
    48       $page['errors'],
    49       l10n('Unable to check for upgrade since allow_url_fopen is disabled.')
    50       );
     47    array_push($page['errors'], l10n('Unable to check for upgrade.'));
    5148  }
    5249  else
    5350  {
    5451    $versions = array('current' => PHPWG_VERSION);
    55     $lines = @file(PHPWG_URL.'/latest_version');
     52    $lines = @explode("\r\n", $result);
    5653
    5754    // if the current version is a BSF (development branch) build, we check
  • branches/2.0/admin/plugins_new.php

    r2652 r2881  
    9090// |                     start template output                             |
    9191// +-----------------------------------------------------------------------+
    92 if (!ini_get('allow_url_fopen'))
    93 {
    94   array_push($page['errors'], l10n('Unable to retrieve server informations since allow_url_fopen is disabled.'));
    95 }
    96 elseif ($plugins->get_server_plugins(true))
     92if ($plugins->get_server_plugins(true))
    9793{
    9894  $plugins->sort_server_plugins($order);
  • branches/2.0/admin/plugins_update.php

    r2652 r2881  
    9898// |                     start template output                             |
    9999// +-----------------------------------------------------------------------+
    100 if (!ini_get('allow_url_fopen'))
    101 {
    102   array_push($page['errors'], l10n('Unable to connect to PEM server since allow_url_fopen is disabled.'));
    103 }
    104 elseif ($plugins->get_server_plugins())
     100if ($plugins->get_server_plugins())
    105101{
    106102  foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
Note: See TracChangeset for help on using the changeset viewer.