Ignore:
Timestamp:
Jul 25, 2009, 6:03:50 PM (15 years ago)
Author:
flop25
Message:

instead of include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); I put the 2 functions needed in template class
=> test it works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/floOS/tools/floOS.class.php

    r3618 r3675  
    5757        closedir ($dh); // on ferme le repertoire courant
    5858        }
     59        function url_is_remote($url)
     60        {
     61          if ( strncmp($url, 'http://', 7)==0
     62                or strncmp($url, 'https://', 8)==0 )
     63          {
     64                return true;
     65          }
     66          return false;
     67        }
     68       
     69        function fetchRemote($src, &$dest, $user_agent='Piwigo', $step=0)
     70        {
     71          // Try to retrieve data from local file?
     72          if (!$this->url_is_remote($src))
     73          {
     74                $content = @file_get_contents($src);
     75                if ($content !== false)
     76                {
     77                  is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
     78                  return true;
     79                }
     80                else
     81                {
     82                  return false;
     83                }
     84          }
     85       
     86          // After 3 redirections, return false
     87          if ($step > 3) return false;
     88       
     89          // Initialize $dest
     90          is_resource($dest) or $dest = '';
     91       
     92          // Try curl to read remote file
     93          if (function_exists('curl_init'))
     94          {
     95                $ch = @curl_init();
     96                @curl_setopt($ch, CURLOPT_URL, $src);
     97                @curl_setopt($ch, CURLOPT_HEADER, 1);
     98                @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
     99                @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     100                $content = @curl_exec($ch);
     101                $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     102                $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
     103                @curl_close($ch);
     104                if ($content !== false and $status >= 200 and $status < 400)
     105                {
     106                  if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m))
     107                  {
     108                        return $this->fetchRemote($m[1], $dest, $user_agent, $step+1);
     109                  }
     110                  $content = substr($content, $header_length);
     111                  is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
     112                  return true;
     113                }
     114          }
     115       
     116          // Try file_get_contents to read remote file
     117          if (ini_get('allow_url_fopen'))
     118          {
     119                $content = @file_get_contents($src);
     120                if ($content !== false)
     121                {
     122                  is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
     123                  return true;
     124                }
     125          }
     126       
     127          // Try fsockopen to read remote file
     128          $src = parse_url($src);
     129          $host = $src['host'];
     130          $path = isset($src['path']) ? $src['path'] : '/';
     131          $path .= isset($src['query']) ? '?'.$src['query'] : '';
     132       
     133          if (($s = @fsockopen($host,80,$errno,$errstr,5)) === false)
     134          {
     135                return false;
     136          }
     137       
     138          fwrite($s,
     139                "GET ".$path." HTTP/1.0\r\n"
     140                ."Host: ".$host."\r\n"
     141                ."User-Agent: ".$user_agent."\r\n"
     142                ."Accept: */*\r\n"
     143                ."\r\n"
     144          );
     145       
     146          $i = 0;
     147          $in_content = false;
     148          while (!feof($s))
     149          {
     150                $line = fgets($s);
     151       
     152                if (rtrim($line,"\r\n") == '' && !$in_content)
     153                {
     154                  $in_content = true;
     155                  $i++;
     156                  continue;
     157                }
     158                if ($i == 0)
     159                {
     160                  if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/',rtrim($line,"\r\n"), $m))
     161                  {
     162                        fclose($s);
     163                        return false;
     164                  }
     165                  $status = (integer) $m[2];
     166                  if ($status < 200 || $status >= 400)
     167                  {
     168                        fclose($s);
     169                        return false;
     170                  }
     171                }
     172                if (!$in_content)
     173                {
     174                  if (preg_match('/Location:\s+?(.+)$/',rtrim($line,"\r\n"),$m))
     175                  {
     176                        fclose($s);
     177                        return $this->fetchRemote(trim($m[1]),$dest,$user_agent,$step+1);
     178                  }
     179                  $i++;
     180                  continue;
     181                }
     182                is_resource($dest) ? @fwrite($dest, $line) : $dest .= $line;
     183                $i++;
     184          }
     185          fclose($s);
     186          return true;
     187        }
     188
     189
    59190        function is_not_up_to_date($v_local, $eid)
    60191        {
    61192       
    62193        global $template, $user, $page;
    63         include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     194//      include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     195
    64196        load_language('template.lang', PHPWG_ROOT_PATH.'template/floOS/tools/');
    65197       
     
    68200        $versions_to_check = array();
    69201        $url = PEM_URL . '/api/get_version_list.php?category_id=12&format=php';
    70         if (fetchRemote($url, $result) and $pem_versions = @unserialize($result))
     202        if ($this->fetchRemote($url, $result) and $pem_versions = @unserialize($result))
    71203        {
    72204          if (!preg_match('/^\d+\.\d+\.\d+/', $version))
     
    89221        //$url .= '&lang=' . substr($user['language'], 0, 2);
    90222        $url .= '&extension_include='.$eid;
    91         fetchRemote($url, $result);
     223        $this->fetchRemote($url, $result);
    92224          $pem_res = @unserialize($result);
    93225          foreach($pem_res as $pem_floOS)
Note: See TracChangeset for help on using the changeset viewer.