Rename App Methods

- renamed a lot of App methods to CamelCase
- replaced direct public variables with get-/set-Methods
This commit is contained in:
Philipp Holzer 2018-10-09 19:58:58 +02:00
parent 5f9dd11cfb
commit 5a02e39a65
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
94 changed files with 481 additions and 338 deletions

View file

@ -141,7 +141,7 @@ class ExAuth
$sUser = str_replace(['%20', '(a)'], [' ', '@'], $aCommand[1]);
// Does the hostname match? So we try directly
if ($a->get_hostname() == $aCommand[2]) {
if ($a->getHostName() == $aCommand[2]) {
$this->writeLog(LOG_INFO, 'internal user check for ' . $sUser . '@' . $aCommand[2]);
$found = DBA::exists('user', ['nickname' => $sUser]);
} else {
@ -221,7 +221,7 @@ class ExAuth
$sUser = str_replace(['%20', '(a)'], [' ', '@'], $aCommand[1]);
// Does the hostname match? So we try directly
if ($a->get_hostname() == $aCommand[2]) {
if ($a->getHostName() == $aCommand[2]) {
$this->writeLog(LOG_INFO, 'internal auth for ' . $sUser . '@' . $aCommand[2]);
$aUser = DBA::selectFirst('user', ['uid', 'password', 'legacy_password'], ['nickname' => $sUser]);

View file

@ -303,7 +303,7 @@ class HTTPSignature
$headers[] = 'Content-Type: application/activity+json';
Network::post($target, $content, $headers);
$return_code = BaseObject::getApp()->get_curl_code();
$return_code = BaseObject::getApp()->getCurlCode();
logger('Transmit to ' . $target . ' returned ' . $return_code);
}

View file

@ -9,6 +9,8 @@ use Friendica\Core\Addon;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Network\Curl;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\Probe;
use Friendica\Object\Image;
use Friendica\Util\XML;
@ -17,6 +19,25 @@ use DomXPath;
class Network
{
/**
* @var Curl The latest Curl output
*/
private static $curl;
/**
* Returns the latest Curl output
*
* @return Curl The latest Curl output
*/
public static function getCurl()
{
if (empty(self::$curl)) {
self::$curl = new Curl();
}
return self::$curl;
}
/**
* Curl wrapper
*
@ -35,7 +56,7 @@ class Network
*
* @return string The fetched content
*/
public static function fetchUrl($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0)
public static function fetchUrl($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = '')
{
$ret = self::fetchUrlFull($url, $binary, $redirects, $timeout, $accept_content, $cookiejar);
@ -59,7 +80,7 @@ class Network
*
* @return array With all relevant information, 'body' contains the actual fetched content.
*/
public static function fetchUrlFull($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0)
public static function fetchUrlFull($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = '')
{
return self::curl(
$url,
@ -145,7 +166,7 @@ class Network
}
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
@curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
$range = intval(Config::get('system', 'curl_range_bytes', 0));
@ -203,8 +224,6 @@ class Network
@curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
}
$a->set_curl_code(0);
// don't let curl abort the entire application
// if it throws any errors.
@ -242,9 +261,7 @@ class Network
$base = substr($base, strlen($chunk));
}
$a->set_curl_code($http_code);
$a->set_curl_content_type($curl_info['content_type']);
$a->set_curl_headers($header);
self::$curl = new Curl($http_code, (isset($curl_info['content_type']) ? $curl_info['content_type'] : ''), $header);
if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
$new_location_info = @parse_url($curl_info['redirect_url']);
@ -277,8 +294,10 @@ class Network
}
}
$a->set_curl_code($http_code);
$a->set_curl_content_type($curl_info['content_type']);
self::$curl->setCode($http_code);
if (isset($curl_info['content_type'])) {
self::$curl->setContentType($curl_info['content_type']);
}
$rc = intval($http_code);
$ret['return_code'] = $rc;
@ -301,7 +320,7 @@ class Network
@curl_close($ch);
$a->save_timestamp($stamp1, 'network');
$a->saveTimestamp($stamp1, 'network');
return($ret);
}
@ -339,7 +358,7 @@ class Network
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
if (Config::get('system', 'ipv4_resolve', false)) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
@ -384,7 +403,7 @@ class Network
}
}
$a->set_curl_code(0);
self::getCurl()->setCode(0);
// don't let curl abort the entire application
// if it throws any errors.
@ -427,15 +446,15 @@ class Network
}
}
$a->set_curl_code($http_code);
self::getCurl()->setCode($http_code);
$body = substr($s, strlen($header));
$a->set_curl_headers($header);
self::getCurl()->setHeaders($header);
curl_close($ch);
$a->save_timestamp($stamp1, 'network');
$a->saveTimestamp($stamp1, 'network');
logger('post_url: end ' . $url, LOGGER_DATA);
@ -729,14 +748,14 @@ class Network
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
curl_exec($ch);
$curl_info = @curl_getinfo($ch);
$http_code = $curl_info['http_code'];
curl_close($ch);
$a->save_timestamp($stamp1, "network");
$a->saveTimestamp($stamp1, "network");
if ($http_code == 0) {
return $url;
@ -773,12 +792,12 @@ class Network
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
$body = curl_exec($ch);
curl_close($ch);
$a->save_timestamp($stamp1, "network");
$a->saveTimestamp($stamp1, "network");
if (trim($body) == "") {
return $url;

View file

@ -91,7 +91,7 @@ class Proxy
$url = html_entity_decode($url, ENT_NOQUOTES, 'utf-8');
// Creating a sub directory to reduce the amount of files in the cache directory
$basepath = $a->get_basepath() . '/proxy';
$basepath = $a->getBasePath() . '/proxy';
$shortpath = hash('md5', $url);
$longpath = substr($shortpath, 0, 2);