Ignore:
Timestamp:
Dec 11, 2010, 10:37:44 PM (13 years ago)
Author:
patdenice
Message:

merge r8079, r8080, r8082, r8083, r8084 from trunk to branch 2.1
feature 2057: fetchRemote can send POST data
feature 2048: Use POST to send server data
feature 2048: add $confsend_hosting_technical_details parameter
feature 2057: use $get_data parameter to send GET data.
feature 2048: send technical details only to get_version_list.php of PEM API.

Location:
branches/2.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.1

  • branches/2.1/admin/include/functions.php

    r8023 r8086  
    16851685 * @return bool
    16861686 */
    1687 function fetchRemote($src, &$dest, $user_agent='Piwigo', $step=0)
     1687function fetchRemote($src, &$dest, $get_data=array(), $post_data=array(), $user_agent='Piwigo', $step=0)
    16881688{
    16891689  // Try to retrieve data from local file?
     
    17021702  }
    17031703
    1704   // Send anonymous data to piwigo server
    1705   if ($_SERVER['HTTP_HOST'] != 'localhost' and $step==0
    1706     and preg_match('#^http://(?:[a-z]+\.)?piwigo\.org#', $src))
    1707   {
    1708     global $conf;
    1709 
    1710     $src = add_url_params($src, array(
    1711       'uuid' => hash_hmac('md5', get_absolute_root_url(), $conf['secret_key']),
    1712       'os' => urlencode(PHP_OS),
    1713       'pwgversion' => urlencode(PHPWG_VERSION),
    1714       'phpversion' => urlencode(phpversion()),
    1715       'dbengine' => urlencode(DB_ENGINE),
    1716       'dbversion' => urlencode(pwg_get_db_version()),
    1717       )
    1718     );
    1719     $src = str_replace('&', '&', $src);
    1720   }
    1721 
    17221704  // After 3 redirections, return false
    17231705  if ($step > 3) return false;
     1706
     1707  // Initialization
     1708  $method  = empty($post_data) ? 'GET' : 'POST';
     1709  $request = empty($post_data) ? '' : http_build_query($post_data, '', '&');
     1710  $src     = add_url_params($src, $get_data, '&');
    17241711
    17251712  // Initialize $dest
     
    17341721    @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    17351722    @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     1723    if ($method == 'POST')
     1724    {
     1725      @curl_setopt($ch, CURLOPT_POST, 1);
     1726      @curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
     1727    }
    17361728    $content = @curl_exec($ch);
    17371729    $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     
    17421734      if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m))
    17431735      {
    1744         return fetchRemote($m[1], $dest, $user_agent, $step+1);
     1736        return fetchRemote($m[1], $dest, array(), array(), $user_agent, $step+1);
    17451737      }
    17461738      $content = substr($content, $header_length);
     
    17531745  if (ini_get('allow_url_fopen'))
    17541746  {
    1755     $content = @file_get_contents($src);
     1747    $opts = array(
     1748      'http' => array(
     1749        'method' => $method,
     1750        'content' => $request,
     1751        'user_agent' => $user_agent,
     1752      )
     1753    );
     1754    $context = @stream_context_create($opts);
     1755    $content = @file_get_contents($src, false, $context);
    17561756    if ($content !== false)
    17571757    {
     
    17721772  }
    17731773
    1774   fwrite($s,
    1775     "GET ".$path." HTTP/1.0\r\n"
    1776     ."Host: ".$host."\r\n"
    1777     ."User-Agent: ".$user_agent."\r\n"
    1778     ."Accept: */*\r\n"
    1779     ."\r\n"
    1780   );
     1774  $http_request  = $method." ".$path." HTTP/1.0\r\n";
     1775  $http_request .= "Host: ".$host."\r\n";
     1776  $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
     1777  $http_request .= "Content-Length: ".strlen($request)."\r\n";
     1778  $http_request .= "User-Agent: ".$user_agent."\r\n";
     1779  $http_request .= "Accept: */*\r\n";
     1780  $http_request .= "\r\n";
     1781  $http_request .= $request;
     1782
     1783  fwrite($s, $http_request);
    17811784
    17821785  $i = 0;
     
    18111814      {
    18121815        fclose($s);
    1813         return fetchRemote(trim($m[1]),$dest,$user_agent,$step+1);
     1816        return fetchRemote(trim($m[1]),$dest,array(),array(),$user_agent,$step+1);
    18141817      }
    18151818      $i++;
     
    20242027  return $tag_ids;
    20252028}
     2029
     2030function get_hosting_technical_details()
     2031{
     2032  global $conf;
     2033
     2034  $details = array();
     2035  if ($conf['send_hosting_technical_details'] and $_SERVER['HTTP_HOST'] != 'localhost')
     2036  {
     2037    $details = array(
     2038      'uuid' => hash_hmac('md5', get_absolute_root_url(), $conf['secret_key']),
     2039      'os' => urlencode(PHP_OS),
     2040      'pwgversion' => urlencode(PHPWG_VERSION),
     2041      'phpversion' => urlencode(phpversion()),
     2042      'dbengine' => urlencode(DB_ENGINE),
     2043      'dbversion' => urlencode(pwg_get_db_version()),
     2044    );
     2045  }
     2046
     2047  return $details;
     2048}
    20262049?>
Note: See TracChangeset for help on using the changeset viewer.