From 50be94aa5ecdceb10de0d6b4764b8eeca78a826f Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 00:47:24 +0100 Subject: [PATCH] Remove deprecated App::getHostName() - process methods to DI::baseUrl()->getHostName() --- boot.php | 4 +--- include/api.php | 4 +--- include/enotify.php | 3 ++- mod/dfrn_request.php | 2 +- mod/settings.php | 4 ++-- src/App.php | 12 ------------ src/Core/System.php | 2 +- src/Model/Contact.php | 2 +- src/Model/Item.php | 6 ++---- src/Model/Profile.php | 3 ++- src/Model/User.php | 4 ++-- src/Module/Magic.php | 2 +- src/Module/OpenSearch.php | 2 +- src/Module/Profile.php | 2 +- src/Module/Register.php | 4 ++-- src/Module/WellKnown/HostMeta.php | 2 +- src/Network/Probe.php | 3 ++- src/Protocol/Feed.php | 3 ++- src/Protocol/OStatus.php | 3 ++- src/Util/ExAuth.php | 9 +++------ src/Worker/CronJobs.php | 2 +- src/Worker/Delivery.php | 4 ++-- src/Worker/Notifier.php | 2 +- 23 files changed, 34 insertions(+), 50 deletions(-) diff --git a/boot.php b/boot.php index ecf83854ff..fa99a7bb39 100644 --- a/boot.php +++ b/boot.php @@ -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); diff --git a/include/api.php b/include/api.php index d2b41f988d..2681b7b4ca 100644 --- a/include/api.php +++ b/include/api.php @@ -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'; diff --git a/include/enotify.php b/include/enotify.php index c0f23b0848..24f4429f67 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -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, ':')); } diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 24548c027a..0c0e5421ad 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -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(); diff --git a/mod/settings.php b/mod/settings.php index c01d179388..eb664e378a 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -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 '%s' or '%s'.", $nickname . '@' . $a->getHostName() . DI::baseUrl()->getUrlPath(), System::baseUrl() . '/profile/' . $nickname), - '$basepath' => $a->getHostName() + '$desc' => L10n::t("Your Identity Address is '%s' or '%s'.", $nickname . '@' . DI::baseUrl()->getHostname() . DI::baseUrl()->getUrlPath(), System::baseUrl() . '/profile/' . $nickname), + '$basepath' => DI::baseUrl()->getHostname() ]); $stpl = Renderer::getMarkupTemplate('settings/settings.tpl'); diff --git a/src/App.php b/src/App.php index 01702967e2..b414926006 100644 --- a/src/App.php +++ b/src/App.php @@ -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 * diff --git a/src/Core/System.php b/src/Core/System.php index 426eb0a53d..d5902c003a 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -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)) { diff --git a/src/Model/Contact.php b/src/Model/Contact.php index f06156d01e..84481b9fa5 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -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"); diff --git a/src/Model/Item.php b/src/Model/Item.php index 3f3de8f8f1..507ee654ec 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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; } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 8659506cb1..3f7877c558 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -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); } diff --git a/src/Model/User.php b/src/Model/User.php index 4f270d2d12..22a8b04744 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -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']; diff --git a/src/Module/Magic.php b/src/Module/Magic.php index b0d2b82b28..b878b0e701 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -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. diff --git a/src/Module/OpenSearch.php b/src/Module/OpenSearch.php index acab0f5ed4..dbf04040b8 100644 --- a/src/Module/OpenSearch.php +++ b/src/Module/OpenSearch.php @@ -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 */ diff --git a/src/Module/Profile.php b/src/Module/Profile.php index cbb953dd75..04364ba0cc 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -120,7 +120,7 @@ class Profile extends BaseModule $a->page['htmlhead'] .= '' . "\n"; $a->page['htmlhead'] .= '' . "\n"; $a->page['htmlhead'] .= '' . "\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'] .= '' . "\n"; header('Link: <' . System::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); diff --git a/src/Module/Register.php b/src/Module/Register.php index 2c9b00bf0c..613b3da7b5 100644 --- a/src/Module/Register.php +++ b/src/Module/Register.php @@ -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 "nickname@%s".', 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 "nickname@%s".', 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'), diff --git a/src/Module/WellKnown/HostMeta.php b/src/Module/WellKnown/HostMeta.php index aec95c2a27..2e63f300de 100644 --- a/src/Module/WellKnown/HostMeta.php +++ b/src/Module/WellKnown/HostMeta.php @@ -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')) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 878198504d..aa0b2e0441 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -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); diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 705a094c38..c30e08f7be 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -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']); diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index a63b12731d..f1cfa54c0f 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -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']; diff --git a/src/Util/ExAuth.php b/src/Util/ExAuth.php index 46452f6e4e..cf98312aa3 100644 --- a/src/Util/ExAuth.php +++ b/src/Util/ExAuth.php @@ -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]); diff --git a/src/Worker/CronJobs.php b/src/Worker/CronJobs.php index e8553ed1c1..6267bf6f33 100644 --- a/src/Worker/CronJobs.php +++ b/src/Worker/CronJobs.php @@ -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]); diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index ef5a7b9f20..ed2ff2979d 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -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') . ' getHostName() . '>' . "\n"; + $headers = 'From: '. Email::encodeHeader($local_user['username'], 'UTF-8') . ' getHostname() . '>' . "\n"; } $headers .= 'Message-Id: <' . Email::iri2msgid($target_item['uri']) . '>' . "\n"; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index d6bf0ef484..fea2da7e32 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -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,':')); } -- 2.39.5