1
0
Fork 0

Remove deprecated App::getHostName() - process methods to DI::baseUrl()->getHostName()

This commit is contained in:
Philipp Holzer 2019-12-16 00:47:24 +01:00
parent 2900389696
commit 50be94aa5e
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
23 changed files with 34 additions and 50 deletions

View file

@ -482,8 +482,6 @@ function get_server()
function get_temppath()
{
$a = \get_app();
$temppath = Config::get("system", "temppath");
if (($temppath != "") && System::isDirectoryUsable($temppath)) {
@ -500,7 +498,7 @@ function get_temppath()
$temppath = BasePath::getRealPath($temppath);
// To avoid any interferences with other systems we create our own directory
$new_temppath = $temppath . "/" . $a->getHostName();
$new_temppath = $temppath . "/" . DI::baseUrl()->getHostname();
if (!is_dir($new_temppath)) {
/// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
mkdir($new_temppath);

View file

@ -3563,10 +3563,8 @@ api_register_func('api/friendships/incoming', 'api_friendships_incoming', true);
*/
function api_statusnet_config($type)
{
$a = \get_app();
$name = Config::get('config', 'sitename');
$server = $a->getHostName();
$server = DI::baseUrl()->getHostname();
$logo = System::baseUrl() . '/images/friendica-64.png';
$email = Config::get('config', 'admin_email');
$closed = intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 'true' : 'false';

View file

@ -12,6 +12,7 @@ use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\User;
use Friendica\Protocol\Activity;
@ -68,7 +69,7 @@ function notification($params)
}
$sender_name = $sitename;
$hostname = $a->getHostName();
$hostname = DI::baseUrl()->getHostname();
if (strpos($hostname, ':')) {
$hostname = substr($hostname, 0, strpos($hostname, ':'));
}

View file

@ -455,7 +455,7 @@ function dfrn_request_post(App $a)
// Diaspora needs the uri in the format user@domain.tld
// Diaspora will support the remote subscription in a future version
if ($network == Protocol::DIASPORA) {
$uri = $nickname . '@' . $a->getHostName();
$uri = $nickname . '@' . DI::baseUrl()->getHostname();
if (DI::baseUrl()->getUrlPath()) {
$uri .= '/' . DI::baseUrl()->getUrlPath();

View file

@ -1127,8 +1127,8 @@ function settings_content(App $a)
$tpl_addr = Renderer::getMarkupTemplate('settings/nick_set.tpl');
$prof_addr = Renderer::replaceMacros($tpl_addr,[
'$desc' => L10n::t("Your Identity Address is <strong>'%s'</strong> or '%s'.", $nickname . '@' . $a->getHostName() . DI::baseUrl()->getUrlPath(), System::baseUrl() . '/profile/' . $nickname),
'$basepath' => $a->getHostName()
'$desc' => L10n::t("Your Identity Address is <strong>'%s'</strong> or '%s'.", $nickname . '@' . DI::baseUrl()->getHostname() . DI::baseUrl()->getUrlPath(), System::baseUrl() . '/profile/' . $nickname),
'$basepath' => DI::baseUrl()->getHostname()
]);
$stpl = Renderer::getMarkupTemplate('settings/settings.tpl');

View file

@ -299,18 +299,6 @@ class App
$this->baseURL->saveByURL($url);
}
/**
* Returns the current hostname
*
* @return string
*
* @deprecated 2019.06 - use BaseURL->getHostname() instead
*/
public function getHostName()
{
return $this->baseURL->getHostname();
}
/**
* Returns the current UserAgent as a String
*

View file

@ -182,7 +182,7 @@ class System
if (is_bool($prefix) && !$prefix) {
$prefix = '';
} elseif (empty($prefix)) {
$prefix = hash('crc32', DI::app()->getHostName());
$prefix = hash('crc32', DI::baseUrl()->getHostname());
}
while (strlen($prefix) < ($size - 13)) {

View file

@ -2269,7 +2269,7 @@ class Contact
if (strlen(DI::baseUrl()->getUrlPath())) {
$myaddr = bin2hex(System::baseUrl() . '/profile/' . $a->user['nickname']);
} else {
$myaddr = bin2hex($a->user['nickname'] . '@' . $a->getHostName());
$myaddr = bin2hex($a->user['nickname'] . '@' . DI::baseUrl()->getHostname());
}
DI::baseUrl()->redirect($ret['request'] . "&addr=$myaddr");

View file

@ -1279,7 +1279,7 @@ class Item
if ($notify) {
// We have to avoid duplicates. So we create the GUID in form of a hash of the plink or uri.
// We add the hash of our own host because our host is the original creator of the post.
$prefix_host = \get_app()->getHostName();
$prefix_host = DI::baseUrl()->getHostname();
} else {
$prefix_host = '';
@ -2752,8 +2752,6 @@ class Item
public static function isRemoteSelf($contact, &$datarray)
{
$a = \get_app();
if (!$contact['remote_self']) {
return false;
}
@ -2765,7 +2763,7 @@ class Item
}
// Prevent to forward already forwarded posts
if ($datarray["app"] == $a->getHostName()) {
if ($datarray["app"] == DI::baseUrl()->getHostname()) {
Logger::log('Already forwarded (second test)', Logger::DEBUG);
return false;
}

View file

@ -23,6 +23,7 @@ use Friendica\Core\System;
use Friendica\Core\Theme;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora;
use Friendica\Util\DateTimeFormat;
@ -1175,7 +1176,7 @@ class Profile
$a->contact = $arr['visitor'];
info(L10n::t('OpenWebAuth: %1$s welcomes %2$s', $a->getHostName(), $visitor['name']));
info(L10n::t('OpenWebAuth: %1$s welcomes %2$s', DI::baseUrl()->getHostname(), $visitor['name']));
Logger::log('OpenWebAuth: auth success from ' . $visitor['addr'], Logger::DEBUG);
}

View file

@ -18,6 +18,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\TwoFactor\AppSpecificPassword;
use Friendica\Object\Image;
use Friendica\Util\Crypto;
@ -587,7 +588,6 @@ class User
*/
public static function create(array $data)
{
$a = \get_app();
$return = ['user' => null, 'password' => ''];
$using_invites = Config::get('system', 'invitation_only');
@ -633,7 +633,7 @@ class User
$_SESSION['register'] = 1;
$_SESSION['openid'] = $openid_url;
$openid = new LightOpenID($a->getHostName());
$openid = new LightOpenID(DI::baseUrl()->getHostname());
$openid->identity = $openid_url;
$openid->returnUrl = System::baseUrl() . '/openid';
$openid->required = ['namePerson/friendly', 'contact/email', 'namePerson'];

View file

@ -80,7 +80,7 @@ class Magic extends BaseModule
$headers = HTTPSignature::createSig(
$headers,
$user['prvkey'],
'acct:' . $user['nickname'] . '@' . $a->getHostName() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '')
'acct:' . $user['nickname'] . '@' . DI::baseUrl()->getHostname()() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '')
);
// Try to get an authentication token from the other instance.

View file

@ -21,7 +21,7 @@ class OpenSearch extends BaseModule
{
header('Content-type: application/opensearchdescription+xml');
$hostname = DI::app()->getHostName();
$hostname = DI::baseUrl()->getHostname()();
$baseUrl = DI::app()->getBaseURL();
/** @var DOMDocument $xml */

View file

@ -120,7 +120,7 @@ class Profile extends BaseModule
$a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/" title="' . L10n::t('%s\'s posts', $a->profile['username']) . '"/>' . "\n";
$a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/comments" title="' . L10n::t('%s\'s comments', $a->profile['username']) . '"/>' . "\n";
$a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/activity" title="' . L10n::t('%s\'s timeline', $a->profile['username']) . '"/>' . "\n";
$uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->getHostName() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : ''));
$uri = urlencode('acct:' . $a->profile['nickname'] . '@' . DI::baseUrl()->getHostname() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : ''));
$a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . System::baseUrl() . '/xrd/?uri=' . $uri . '" />' . "\n";
header('Link: <' . System::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);

View file

@ -124,7 +124,7 @@ class Register extends BaseModule
'$ask_password' => $ask_password,
'$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')],
'$password2' => ['confirm', L10n::t('Confirm:'), '', ''],
'$nickdesc' => L10n::t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be "<strong>nickname@%s</strong>".', DI::app()->getHostName()),
'$nickdesc' => L10n::t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be "<strong>nickname@%s</strong>".', DI::baseUrl()->getHostname()),
'$nicklabel' => L10n::t('Choose a nickname: '),
'$photo' => $photo,
'$publish' => $profile_publish,
@ -132,7 +132,7 @@ class Register extends BaseModule
'$username' => $username,
'$email' => $email,
'$nickname' => $nickname,
'$sitename' => DI::app()->getHostName(),
'$sitename' => DI::baseUrl()->getHostname()(),
'$importh' => L10n::t('Import'),
'$importt' => L10n::t('Import your profile to this friendica instance'),
'$showtoslink' => Config::get('system', 'tosdisplay'),

View file

@ -30,7 +30,7 @@ class HostMeta extends BaseModule
$tpl = Renderer::getMarkupTemplate('xrd_host.tpl');
echo Renderer::replaceMacros($tpl, [
'$zhost' => $app->getHostName(),
'$zhost' => DI::baseUrl()->getHostname()(),
'$zroot' => $app->getBaseURL(),
'$domain' => $app->getBaseURL(),
'$bigkey' => Salmon::salmonKey($config->get('system', 'site_pubkey'))

View file

@ -17,6 +17,7 @@ use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Protocol\ActivityNamespace;
@ -76,7 +77,7 @@ class Probe
*/
private static function ownHost($host)
{
$own_host = \get_app()->getHostName();
$own_host = DI::baseUrl()->getHostname();
$parts = parse_url($host);

View file

@ -13,6 +13,7 @@ use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Protocol\ActivityNamespace;
use Friendica\Util\ParseUrl;
@ -465,7 +466,7 @@ class Feed {
// Distributed items should have a well formatted URI.
// Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
if ($notify) {
$item['guid'] = Item::guidFromUri($orig_plink, $a->getHostName());
$item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname()());
unset($item['uri']);
unset($item['parent-uri']);

View file

@ -17,6 +17,7 @@ use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\APContact;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
@ -1846,7 +1847,7 @@ class OStatus
}
$item["uri"] = $item['parent-uri'] = $item['thr-parent']
= 'tag:'.get_app()->getHostName().
= 'tag:' . DI::baseUrl()->getHostname()().
','.date('Y-m-d').':'.$action.':'.$owner['uid'].
':person:'.$connect_id.':'.$item['created'];

View file

@ -37,6 +37,7 @@ namespace Friendica\Util;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;
class ExAuth
@ -123,8 +124,6 @@ class ExAuth
*/
private function isUser(array $aCommand)
{
$a = \get_app();
// Check if there is a username
if (!isset($aCommand[1])) {
$this->writeLog(LOG_NOTICE, 'invalid isuser command, no username given');
@ -140,7 +139,7 @@ class ExAuth
$sUser = str_replace(['%20', '(a)'], [' ', '@'], $aCommand[1]);
// Does the hostname match? So we try directly
if ($a->getHostName() == $aCommand[2]) {
if (DI::baseUrl()->getHostname() == $aCommand[2]) {
$this->writeLog(LOG_INFO, 'internal user check for ' . $sUser . '@' . $aCommand[2]);
$found = DBA::exists('user', ['nickname' => $sUser]);
} else {
@ -205,8 +204,6 @@ class ExAuth
*/
private function auth(array $aCommand)
{
$a = \get_app();
// check user authentication
if (sizeof($aCommand) != 4) {
$this->writeLog(LOG_NOTICE, 'invalid auth command, data missing');
@ -222,7 +219,7 @@ class ExAuth
$sUser = str_replace(['%20', '(a)'], [' ', '@'], $aCommand[1]);
// Does the hostname match? So we try directly
if ($a->getHostName() == $aCommand[2]) {
if (DI::baseUrl()->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

@ -47,7 +47,7 @@ class CronJobs
Logger::info('cron_start');
Nodeinfo::update();
// Now trying to register
$url = 'http://the-federation.info/register/' . $a->getHostName();
$url = 'http://the-federation.info/register/' . DI::baseUrl()->getHostname();
Logger::debug('Check registering url', ['url' => $url]);
$ret = Network::fetchUrl($url);
Logger::debug('Check registering answer', ['answer' => $ret]);

View file

@ -140,7 +140,7 @@ class Delivery
// if $parent['wall'] == 1 we will already have the parent message in our array
// and we will relay the whole lot.
$localhost = DI::app()->getHostName();
$localhost = DI::baseUrl()->getHostname();
if (strpos($localhost, ':')) {
$localhost = substr($localhost, 0, strpos($localhost, ':'));
}
@ -548,7 +548,7 @@ class Delivery
$headers = 'From: ' . Email::encodeHeader($local_user['username'],'UTF-8') . ' <' . $local_user['email'] . '>' . "\n";
}
} else {
$headers = 'From: '. Email::encodeHeader($local_user['username'], 'UTF-8') . ' <noreply@' . DI::app()->getHostName() . '>' . "\n";
$headers = 'From: '. Email::encodeHeader($local_user['username'], 'UTF-8') . ' <noreply@' . DI::baseUrl()->getHostname() . '>' . "\n";
}
$headers .= 'Message-Id: <' . Email::iri2msgid($target_item['uri']) . '>' . "\n";

View file

@ -180,7 +180,7 @@ class Notifier
// if $parent['wall'] == 1 we will already have the parent message in our array
// and we will relay the whole lot.
$localhost = str_replace('www.','',$a->getHostName());
$localhost = str_replace('www.','', DI::baseUrl()->getHostname());
if (strpos($localhost,':')) {
$localhost = substr($localhost,0,strpos($localhost,':'));
}