summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@gmail.com>2014-04-27 09:22:27 +0100
committerGreg Roach <fisharebest@gmail.com>2014-04-27 09:22:27 +0100
commit949f080c5ac17eae6c3f02de9f635538649d7745 (patch)
treeb9988f88c3722c2e0a7d847b8caac15dada966cd
parenta24329d817c8980a540b020fbbd1be52e1766d32 (diff)
downloadwebtrees-949f080c5ac17eae6c3f02de9f635538649d7745.tar.gz
webtrees-949f080c5ac17eae6c3f02de9f635538649d7745.tar.bz2
webtrees-949f080c5ac17eae6c3f02de9f635538649d7745.zip
Remove function from global scope
-rw-r--r--includes/functions/functions.php33
-rw-r--r--library/WT/File.php9
2 files changed, 9 insertions, 33 deletions
diff --git a/includes/functions/functions.php b/includes/functions/functions.php
index ab72ab9f50..ec8ae61b77 100644
--- a/includes/functions/functions.php
+++ b/includes/functions/functions.php
@@ -26,42 +26,17 @@ if (!defined('WT_WEBTREES')) {
exit;
}
-// Fetch a remote file. Stream wrappers are disabled on
-// many hosts, and do not allow the detection of timeout.
-function fetch_remote_file($host, $path, $timeout=3) {
- $fp=@fsockopen($host, '80', $errno, $errstr, $timeout );
- if (!$fp) {
- return null;
- }
-
- fputs($fp, "GET $path HTTP/1.0\r\nHost: $host\r\nConnection: Close\r\n\r\n");
-
- $response='';
- while ($data=fread($fp, 65536)) {
- $response.=$data;
- }
- fclose($fp);
-
- // Take account of a “moved” response.
- if (substr($response, 0, 12)=='HTTP/1.1 303' && preg_match('/\nLocation: http:\/\/([a-z0-9.-]+)(.+)/', $response, $match)) {
- return fetch_remote_file($match[1], $match[2]);
- } else {
- // The response includes headers, a blank line, then the content
- return substr($response, strpos($response, "\r\n\r\n") + 4);
- }
-}
-
// Check with the webtrees.net server for the latest version of webtrees.
// Fetching the remote file can be slow, so check infrequently, and cache the result.
// Pass the current versions of webtrees, PHP and MySQL, as the response
// may be different for each. The server logs are used to generate
// installation statistics which can be found at http://svn.webtrees.net/statistics.html
function fetch_latest_version() {
- $last_update_timestamp=WT_Site::preference('LATEST_WT_VERSION_TIMESTAMP');
+ $last_update_timestamp = WT_Site::preference('LATEST_WT_VERSION_TIMESTAMP');
if ($last_update_timestamp < WT_TIMESTAMP - 24*60*60) {
- $row=WT_DB::prepare("SHOW VARIABLES LIKE 'version'")->fetchOneRow();
- $params='?w='.WT_VERSION.'&p='.PHP_VERSION.'&m='.$row->value.'&o='.(DIRECTORY_SEPARATOR=='/'?'u':'w');
- $latest_version_txt=fetch_remote_file('svn.webtrees.net', '/build/latest-version.txt'.$params);
+ $row = WT_DB::prepare("SHOW VARIABLES LIKE 'version'")->fetchOneRow();
+ $params = '?w='.WT_VERSION.'&p='.PHP_VERSION.'&m='.$row->value.'&o='.(DIRECTORY_SEPARATOR=='/'?'u':'w');
+ $latest_version_txt = WT_File::fetchUrl('http://svn.webtrees.net/build/latest-version.txt' . $params);
if ($latest_version_txt) {
WT_Site::preference('LATEST_WT_VERSION', $latest_version_txt);
WT_Site::preference('LATEST_WT_VERSION_TIMESTAMP', WT_TIMESTAMP);
diff --git a/library/WT/File.php b/library/WT/File.php
index d86862ef3c..4f39d2a97a 100644
--- a/library/WT/File.php
+++ b/library/WT/File.php
@@ -34,9 +34,10 @@ class WT_File {
//////////////////////////////////////////////////////////////////////////////
public static function fetchUrl($url, $stream=null) {
- $host = parse_url($url, PHP_URL_HOST);
- $port = parse_url($url, PHP_URL_PORT);
- $path = parse_url($url, PHP_URL_PATH);
+ $host = parse_url($url, PHP_URL_HOST);
+ $port = parse_url($url, PHP_URL_PORT);
+ $path = parse_url($url, PHP_URL_PATH);
+ $query = parse_url($url, PHP_URL_QUERY);
if (!$port) {
$port = parse_url($url, PHP_URL_SCHEME) == 'https' ? 443 : 80;
@@ -49,7 +50,7 @@ class WT_File {
return null;
}
- fputs($fp, "GET $path HTTP/1.0\r\nHost: $host\r\nConnection: Close\r\n\r\n");
+ fputs($fp, "GET $path?$query HTTP/1.0\r\nHost: $host\r\nConnection: Close\r\n\r\n");
// The first part of the response include the HTTP headers
$response = fread($fp, 65536);