Changeset 8086


Ignore:
Timestamp:
Dec 11, 2010, 10:37:44 PM (10 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:
8 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?>
  • branches/2.1/admin/include/languages.class.php

    r6551 r8086  
    197197    global $user;
    198198
    199     $pem_category_id = 8;
     199    $get_data = array(
     200      'category_id' => 8,
     201      'format' => 'php',
     202    );
    200203
    201204    // Retrieve PEM versions
    202205    $version = PHPWG_VERSION;
    203206    $versions_to_check = array();
    204     $url = PEM_URL . '/api/get_version_list.php?category_id='.$pem_category_id.'&format=php';
    205     if (fetchRemote($url, $result) and $pem_versions = @unserialize($result))
     207    $url = PEM_URL . '/api/get_version_list.php';
     208    if (fetchRemote($url, $result, $get_data, get_hosting_technical_details()) and $pem_versions = @unserialize($result))
    206209    {
    207210      if (!preg_match('/^\d+\.\d+\.\d+/', $version))
     
    224227
    225228    // Retrieve PEM languages infos
    226     $url = PEM_URL . '/api/get_revision_list.php?category_id='.$pem_category_id.'&format=php&last_revision_only=true';
    227     $url .= '&version=' . implode(',', $versions_to_check);
    228     $url .= '&lang='.$user['language'];
    229 
    230     if (fetchRemote($url, $result))
     229    $url = PEM_URL . '/api/get_revision_list.php';
     230    $get_data = array_merge($get_data, array(
     231      'last_revision_only' => 'true',
     232      'version' => implode(',', $versions_to_check),
     233      'lang' => $user['language'],
     234      )
     235    );
     236
     237    if (fetchRemote($url, $result, $get_data))
    231238    {
    232239      $pem_languages = @unserialize($result);
     
    259266    if ($archive = tempnam( PHPWG_ROOT_PATH.'language', 'zip'))
    260267    {
    261       $url = PEM_URL . '/download.php?rid=' . $revision;
    262       $url .= '&origin=piwigo_' . $action;
    263 
    264       if ($handle = @fopen($archive, 'wb') and fetchRemote($url, $handle))
     268      $url = PEM_URL . '/download.php';
     269      $get_data = array(
     270        'rid' => $revision,
     271        'origin' => 'piwigo_'.$action,
     272      );
     273
     274      if ($handle = @fopen($archive, 'wb') and fetchRemote($url, $handle, $get_data))
    265275      {
    266276        fclose($handle);
  • branches/2.1/admin/include/plugins.class.php

    r6724 r8086  
    291291    global $user;
    292292
     293    $get_data = array(
     294      'category_id' => 12,
     295      'format' => 'php',
     296    );
     297
    293298    // Retrieve PEM versions
    294299    $version = PHPWG_VERSION;
    295300    $versions_to_check = array();
    296     $url = PEM_URL . '/api/get_version_list.php?category_id=12&format=php';
    297     if (fetchRemote($url, $result) and $pem_versions = @unserialize($result))
     301    $url = PEM_URL . '/api/get_version_list.php';
     302    if (fetchRemote($url, $result, $get_data, get_hosting_technical_details()) and $pem_versions = @unserialize($result))
    298303    {
    299304      if (!preg_match('/^\d+\.\d+\.\d+/', $version))
     
    326331
    327332    // Retrieve PEM plugins infos
    328     $url = PEM_URL . '/api/get_revision_list.php?category_id=12&format=php&last_revision_only=true';
    329     $url .= '&version=' . implode(',', $versions_to_check);
    330     $url .= '&lang=' . substr($user['language'], 0, 2);
    331     $url .= '&get_nb_downloads=true';
     333    $url = PEM_URL . '/api/get_revision_list.php';
     334    $get_data = array_merge($get_data, array(
     335      'last_revision_only' => 'true',
     336      'version' => implode(',', $versions_to_check),
     337      'lang' => substr($user['language'], 0, 2),
     338      'get_nb_downloads' => 'true',
     339      )
     340    );
    332341
    333342    if (!empty($plugins_to_check))
    334343    {
    335       $url .= $new ? '&extension_exclude=' : '&extension_include=';
    336       $url .= implode(',', $plugins_to_check);
    337     }
    338     if (fetchRemote($url, $result))
     344      if ($new)
     345      {
     346        $get_data['extension_exclude'] = implode(',', $plugins_to_check);
     347      }
     348      else
     349      {
     350        $get_data['extension_include'] = implode(',', $plugins_to_check);
     351      }
     352    }
     353    if (fetchRemote($url, $result, $get_data))
    339354    {
    340355      $pem_plugins = @unserialize($result);
     
    387402    if ($archive = tempnam( PHPWG_PLUGINS_PATH, 'zip'))
    388403    {
    389       $url = PEM_URL . '/download.php?rid=' . $revision;
    390       $url .= '&origin=piwigo_' . $action;
    391 
    392       if ($handle = @fopen($archive, 'wb') and fetchRemote($url, $handle))
     404      $url = PEM_URL . '/download.php';
     405      $get_data = array(
     406        'rid' => $revision,
     407        'origin' => 'piwigo_'.$action,
     408      );
     409
     410      if ($handle = @fopen($archive, 'wb') and fetchRemote($url, $handle, $get_data))
    393411      {
    394412        fclose($handle);
  • branches/2.1/admin/include/themes.class.php

    r6551 r8086  
    448448    global $user;
    449449
    450     $pem_category_id = 10;
     450    $get_data = array(
     451      'category_id' => 10,
     452      'format' => 'php',
     453    );
    451454
    452455    // Retrieve PEM versions
    453456    $version = PHPWG_VERSION;
    454457    $versions_to_check = array();
    455     $url = PEM_URL . '/api/get_version_list.php?category_id='.$pem_category_id.'&format=php';
    456     if (fetchRemote($url, $result) and $pem_versions = @unserialize($result))
     458    $url = PEM_URL . '/api/get_version_list.php';
     459    if (fetchRemote($url, $result, $get_data, get_hosting_technical_details()) and $pem_versions = @unserialize($result))
    457460    {
    458461      if (!preg_match('/^\d+\.\d+\.\d+/', $version))
     
    485488
    486489    // Retrieve PEM themes infos
    487     $url = PEM_URL . '/api/get_revision_list.php?category_id='.$pem_category_id.'&format=php&last_revision_only=true';
    488     $url .= '&version=' . implode(',', $versions_to_check);
    489     $url .= '&lang=' . substr($user['language'], 0, 2);
    490     $url .= '&get_nb_downloads=true';
     490    $url = PEM_URL . '/api/get_revision_list.php';
     491    $get_data = array_merge($get_data, array(
     492      'last_revision_only' => 'true',
     493      'version' => implode(',', $versions_to_check),
     494      'lang' => substr($user['language'], 0, 2),
     495      'get_nb_downloads' => 'true',
     496      )
     497    );
    491498
    492499    if (!empty($themes_to_check))
    493500    {
    494       $url .= $new ? '&extension_exclude=' : '&extension_include=';
    495       $url .= implode(',', $themes_to_check);
    496     }
    497     if (fetchRemote($url, $result))
     501      if ($new)
     502      {
     503        $get_data['extension_exclude'] = implode(',', $themes_to_check);
     504      }
     505      else
     506      {
     507        $get_data['extension_include'] = implode(',', $themes_to_check);
     508      }
     509    }
     510    if (fetchRemote($url, $result, $get_data))
    498511    {
    499512      $pem_themes = @unserialize($result);
     
    547560    if ($archive = tempnam( PHPWG_THEMES_PATH, 'zip'))
    548561    {
    549       $url = PEM_URL . '/download.php?rid=' . $revision;
    550       $url .= '&origin=piwigo_' . $action;
    551 
    552       if ($handle = @fopen($archive, 'wb') and fetchRemote($url, $handle))
     562      $url = PEM_URL . '/download.php';
     563      $get_data = array(
     564        'rid' => $revision,
     565        'origin' => 'piwigo_'.$action,
     566      );
     567
     568      if ($handle = @fopen($archive, 'wb') and fetchRemote($url, $handle, $get_data))
    553569      {
    554570        fclose($handle);
  • branches/2.1/admin/site_manager.php

    r6364 r8086  
    117117      {
    118118        $clf_url = $url.'create_listing_file.php';
    119         $clf_url.= '?action=test';
    120         $clf_url.= '&version='.PHPWG_VERSION;
    121         if (fetchRemote($clf_url, $result))
     119        $get_data = array(
     120          'action' => 'test',
     121          'version' => PHPWG_VERSION,
     122        );
     123        if (fetchRemote($clf_url, $result, $get_data))
    122124        {
    123125          $lines = explode("\r\n", $result);
  • branches/2.1/include/config_default.inc.php

    r6715 r8086  
    485485// gives an empty value '' to deactivate
    486486$conf['show_php_errors'] = E_ALL;
     487
     488// sends your hosting PHP and MySQL versions to piwigo.org as anonymously as
     489// possible, for statistics purpose. No personnal data are transmitted
     490$conf['send_hosting_technical_details'] = true;
    487491
    488492// +-----------------------------------------------------------------------+
  • branches/2.1/include/functions_url.inc.php

    r6410 r8086  
    9090 * @return string
    9191 */
    92 function add_url_params($url, $params)
     92function add_url_params($url, $params, $arg_separator='&' )
    9393{
    9494  if ( !empty($params) )
     
    101101      {
    102102        $is_first = false;
    103         $url .= ( strpos($url, '?')===false ) ? '?' :'&';
     103        $url .= ( strpos($url, '?')===false ) ? '?' : $arg_separator;
    104104      }
    105105      else
    106106      {
    107         $url .= '&';
     107        $url .= $arg_separator;
    108108      }
    109109      $url .= $param;
Note: See TracChangeset for help on using the changeset viewer.