diff --git a/src/Module/Acctlink.php b/src/Module/Acctlink.php index 692e90591..1c2500a22 100644 --- a/src/Module/Acctlink.php +++ b/src/Module/Acctlink.php @@ -13,10 +13,10 @@ class Acctlink extends BaseModule { public static function content() { - $addr = defaults($_GET, 'addr', false); + $addr = trim($_GET['addr'] ?? ''); if ($addr) { - $url = defaults(Probe::uri(trim($addr)), 'url', false); + $url = Probe::uri($addr)['url'] ?? ''; if ($url) { System::externalRedirect($url); diff --git a/src/Module/Admin/Addons/Details.php b/src/Module/Admin/Addons/Details.php index 1fadf6768..1965102f0 100644 --- a/src/Module/Admin/Addons/Details.php +++ b/src/Module/Admin/Addons/Details.php @@ -53,7 +53,7 @@ class Details extends BaseAdminModule $a->internalRedirect('admin/addons'); } - if (defaults($_GET, 'action', '') == 'toggle') { + if (($_GET['action'] ?? '') == 'toggle') { parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_themes', 't'); // Toggle addon status diff --git a/src/Module/Admin/Addons/Index.php b/src/Module/Admin/Addons/Index.php index 2fa39d8e4..eed47defb 100644 --- a/src/Module/Admin/Addons/Index.php +++ b/src/Module/Admin/Addons/Index.php @@ -26,7 +26,7 @@ class Index extends BaseAdminModule break; case 'toggle' : - $addon = defaults($_GET, 'addon', ''); + $addon = $_GET['addon'] ?? ''; if (Addon::isEnabled($addon)) { Addon::uninstall($addon); info(L10n::t('Addon %s disabled.', $addon)); diff --git a/src/Module/Admin/Blocklist/Contact.php b/src/Module/Admin/Blocklist/Contact.php index de3c717e3..bf1c7bc08 100644 --- a/src/Module/Admin/Blocklist/Contact.php +++ b/src/Module/Admin/Blocklist/Contact.php @@ -15,9 +15,9 @@ class Contact extends BaseAdminModule { parent::post(); - $contact_url = defaults($_POST, 'contact_url', ''); - $block_reason = defaults($_POST, 'contact_block_reason', ''); - $contacts = defaults($_POST, 'contacts', []); + $contact_url = $_POST['contact_url'] ?? ''; + $block_reason = $_POST['contact_block_reason'] ?? ''; + $contacts = $_POST['contacts'] ?? []; parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock'); diff --git a/src/Module/Admin/Logs/Settings.php b/src/Module/Admin/Logs/Settings.php index b9a5e3832..be060e053 100644 --- a/src/Module/Admin/Logs/Settings.php +++ b/src/Module/Admin/Logs/Settings.php @@ -20,7 +20,7 @@ class Settings extends BaseAdminModule $logfile = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : ''); $debugging = !empty($_POST['debugging']); - $loglevel = defaults($_POST, 'loglevel', LogLevel::ERROR); + $loglevel = ($_POST['loglevel'] ?? '') ?: LogLevel::ERROR; if (is_file($logfile) && !is_writeable($logfile)) { diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index dff869df2..18a1cbf2a 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -200,7 +200,7 @@ class Site extends BaseAdminModule /** * @var $storagebackend \Friendica\Model\Storage\IStorage */ - $storagebackend = Strings::escapeTags(trim(defaults($_POST, 'storagebackend', ''))); + $storagebackend = Strings::escapeTags(trim($_POST['storagebackend'] ?? '')); // save storage backend form if (!is_null($storagebackend) && $storagebackend != "") { @@ -216,7 +216,7 @@ class Site extends BaseAdminModule $value = !empty($_POST[$fieldname]); break; default: - $value = defaults($_POST, $fieldname, ''); + $value = $_POST[$fieldname] ?? ''; } $storage_opts_data[$name] = $value; } diff --git a/src/Module/Admin/Themes/Index.php b/src/Module/Admin/Themes/Index.php index d29b4c33c..af2d1f28e 100644 --- a/src/Module/Admin/Themes/Index.php +++ b/src/Module/Admin/Themes/Index.php @@ -36,7 +36,7 @@ class Index extends BaseAdminModule break; case 'toggle' : - $theme = defaults($_GET, 'addon', ''); + $theme = $_GET['addon'] ?? ''; if ($theme) { $theme = Strings::sanitizeFilePathItem($theme); if (!is_dir("view/theme/$theme")) { diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 92dddd9f7..a949c9331 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -21,11 +21,11 @@ class Users extends BaseAdminModule $a = self::getApp(); - $pending = defaults($_POST, 'pending' , []); - $users = defaults($_POST, 'user' , []); - $nu_name = defaults($_POST, 'new_user_name' , ''); - $nu_nickname = defaults($_POST, 'new_user_nickname', ''); - $nu_email = defaults($_POST, 'new_user_email' , ''); + $pending = $_POST['pending'] ?? []; + $users = $_POST['user'] ?? []; + $nu_name = $_POST['new_user_name'] ?? ''; + $nu_nickname = $_POST['new_user_nickname'] ?? ''; + $nu_email = $_POST['new_user_email'] ?? ''; $nu_language = Config::get('system', 'language'); parent::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users'); diff --git a/src/Module/AllFriends.php b/src/Module/AllFriends.php index b0e6ea149..e5fbe6971 100644 --- a/src/Module/AllFriends.php +++ b/src/Module/AllFriends.php @@ -78,7 +78,7 @@ class AllFriends extends BaseModule $entry = [ 'url' => Model\Contact::magicLinkbyId($friend['id'], $friend['url']), - 'itemurl' => defaults($contactDetails, 'addr', $friend['url']), + 'itemurl' => ($contactDetails['addr'] ?? '') ?: $friend['url'], 'name' => $contactDetails['name'], 'thumb' => ProxyUtils::proxifyUrl($contactDetails['thumb'], false, ProxyUtils::SIZE_THUMB), 'img_hover' => $contactDetails['name'], diff --git a/src/Module/Bookmarklet.php b/src/Module/Bookmarklet.php index 283ab0117..92130eeff 100644 --- a/src/Module/Bookmarklet.php +++ b/src/Module/Bookmarklet.php @@ -27,7 +27,7 @@ class Bookmarklet extends BaseModule return $output; } - $referer = Strings::normaliseLink(defaults($_SERVER, 'HTTP_REFERER', '')); + $referer = Strings::normaliseLink($_SERVER['HTTP_REFERER'] ?? ''); $page = Strings::normaliseLink($app->getBaseURL() . "/bookmarklet"); if (!strstr($referer, $page)) { @@ -48,7 +48,7 @@ class Bookmarklet extends BaseModule 'bang' => '', 'visitor' => 'block', 'profile_uid' => local_user(), - 'title' => trim(defaults($_REQUEST, 'title', ''), '*'), + 'title' => trim($_REQUEST['title'] ?? '', '*'), 'content' => $content ]; $output = status_editor($app, $x, 0, false); diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 0b27f0e4a..c8bbbfe2e 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -103,7 +103,7 @@ class Contact extends BaseModule Hook::callAll('contact_edit_post', $_POST); - $profile_id = intval(defaults($_POST, 'profile-assign', 0)); + $profile_id = intval($_POST['profile-assign'] ?? 0); if ($profile_id) { if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) { notice(L10n::t('Could not locate selected profile.') . EOL); @@ -115,16 +115,16 @@ class Contact extends BaseModule $notify = !empty($_POST['notify']); - $fetch_further_information = intval(defaults($_POST, 'fetch_further_information', 0)); + $fetch_further_information = intval($_POST['fetch_further_information'] ?? 0); - $ffi_keyword_blacklist = Strings::escapeHtml(trim(defaults($_POST, 'ffi_keyword_blacklist', ''))); + $ffi_keyword_blacklist = Strings::escapeHtml(trim($_POST['ffi_keyword_blacklist'] ?? '')); - $priority = intval(defaults($_POST, 'poll', 0)); + $priority = intval($_POST['poll'] ?? 0); if ($priority > 5 || $priority < 0) { $priority = 0; } - $info = Strings::escapeHtml(trim(defaults($_POST, 'info', ''))); + $info = Strings::escapeHtml(trim($_POST['info'] ?? '')); $r = DBA::update('contact', [ 'profile-id' => $profile_id, @@ -188,21 +188,42 @@ class Contact extends BaseModule Model\GContact::updateFromProbe($contact['url']); } + /** + * Toggles the blocked status of a contact identified by id. + * + * @param $contact_id + * @throws \Exception + */ private static function blockContact($contact_id) { $blocked = !Model\Contact::isBlockedByUser($contact_id, local_user()); Model\Contact::setBlockedForUser($contact_id, local_user(), $blocked); } + /** + * Toggles the ignored status of a contact identified by id. + * + * @param $contact_id + * @throws \Exception + */ private static function ignoreContact($contact_id) { $ignored = !Model\Contact::isIgnoredByUser($contact_id, local_user()); Model\Contact::setIgnoredForUser($contact_id, local_user(), $ignored); } + /** + * Toggles the archived status of a contact identified by id. + * If the current status isn't provided, this will always archive the contact. + * + * @param $contact_id + * @param $orig_record + * @return bool + * @throws \Exception + */ private static function archiveContact($contact_id, $orig_record) { - $archived = (defaults($orig_record, 'archive', '') ? 0 : 1); + $archived = empty($orig_record['archive']); $r = DBA::update('contact', ['archive' => $archived], ['id' => $contact_id, 'uid' => local_user()]); return DBA::isResult($r); @@ -227,8 +248,8 @@ class Contact extends BaseModule $a = self::getApp(); - $nets = defaults($_GET, 'nets', ''); - $rel = defaults($_GET, 'rel' , ''); + $nets = $_GET['nets'] ?? ''; + $rel = $_GET['rel'] ?? ''; if (empty($a->page['aside'])) { $a->page['aside'] = ''; @@ -290,7 +311,7 @@ class Contact extends BaseModule '$name' => $contact['name'], '$photo' => $contact['photo'], '$url' => Model\Contact::magicLinkByContact($contact, $contact['url']), - '$addr' => defaults($contact, 'addr', ''), + '$addr' => $contact['addr'] ?? '', '$network_link' => $network_link, '$network' => L10n::t('Network:'), '$account_type' => Model\Contact::getAccountType($contact), @@ -626,7 +647,7 @@ class Contact extends BaseModule } // @TODO: Replace with parameter from router - $type = defaults($a->argv, 1, ''); + $type = $a->argv[1] ?? ''; switch ($type) { case 'blocked': @@ -651,9 +672,9 @@ class Contact extends BaseModule $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM); - $search = Strings::escapeTags(trim(defaults($_GET, 'search', ''))); - $nets = Strings::escapeTags(trim(defaults($_GET, 'nets' , ''))); - $rel = Strings::escapeTags(trim(defaults($_GET, 'rel' , ''))); + $search = Strings::escapeTags(trim($_GET['search'] ?? '')); + $nets = Strings::escapeTags(trim($_GET['nets'] ?? '')); + $rel = Strings::escapeTags(trim($_GET['rel'] ?? '')); $tabs = [ [ @@ -1016,7 +1037,7 @@ class Contact extends BaseModule 'username' => $rr['name'], 'account_type' => Model\Contact::getAccountType($rr), 'sparkle' => $sparkle, - 'itemurl' => defaults($rr, 'addr', $rr['url']), + 'itemurl' => ($rr['addr'] ?? '') ?: $rr['url'], 'url' => $url, 'network' => ContactSelector::networkToName($rr['network'], $rr['url']), 'nick' => $rr['nick'], diff --git a/src/Module/Debug/Babel.php b/src/Module/Debug/Babel.php index 19e3ec213..cf1f86955 100644 --- a/src/Module/Debug/Babel.php +++ b/src/Module/Debug/Babel.php @@ -25,7 +25,7 @@ class Babel extends BaseModule $results = []; if (!empty($_REQUEST['text'])) { - switch (defaults($_REQUEST, 'type', 'bbcode')) { + switch (($_REQUEST['type'] ?? '') ?: 'bbcode') { case 'bbcode': $bbcode = trim($_REQUEST['text']); $results[] = [ @@ -176,10 +176,10 @@ class Babel extends BaseModule $tpl = Renderer::getMarkupTemplate('babel.tpl'); $o = Renderer::replaceMacros($tpl, [ - '$text' => ['text', L10n::t('Source text'), defaults($_REQUEST, 'text', ''), ''], - '$type_bbcode' => ['type', L10n::t('BBCode'), 'bbcode', '', defaults($_REQUEST, 'type', 'bbcode') == 'bbcode'], - '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', defaults($_REQUEST, 'type', 'bbcode') == 'markdown'], - '$type_html' => ['type', L10n::t('HTML'), 'html', '', defaults($_REQUEST, 'type', 'bbcode') == 'html'], + '$text' => ['text', L10n::t('Source text'), $_REQUEST['text'] ?? '', ''], + '$type_bbcode' => ['type', L10n::t('BBCode'), 'bbcode', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'bbcode'], + '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'markdown'], + '$type_html' => ['type', L10n::t('HTML'), 'html', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'html'], '$results' => $results ]); diff --git a/src/Module/Debug/Feed.php b/src/Module/Debug/Feed.php index a11df59b7..cc0be643b 100644 --- a/src/Module/Debug/Feed.php +++ b/src/Module/Debug/Feed.php @@ -46,7 +46,7 @@ class Feed extends BaseModule $tpl = Renderer::getMarkupTemplate('feedtest.tpl'); return Renderer::replaceMacros($tpl, [ - '$url' => ['url', L10n::t('Source URL'), defaults($_REQUEST, 'url', ''), ''], + '$url' => ['url', L10n::t('Source URL'), $_REQUEST['url'] ?? '', ''], '$result' => $result ]); } diff --git a/src/Module/Debug/Localtime.php b/src/Module/Debug/Localtime.php index 7af9cb8da..197149837 100644 --- a/src/Module/Debug/Localtime.php +++ b/src/Module/Debug/Localtime.php @@ -12,7 +12,7 @@ class Localtime extends BaseModule { public static function post() { - $time = defaults($_REQUEST, 'time', 'now'); + $time = ($_REQUEST['time'] ?? '') ?: 'now'; $bd_format = L10n::t('l F d, Y \@ g:i A'); @@ -25,7 +25,7 @@ class Localtime extends BaseModule { $app = self::getApp(); - $time = defaults($_REQUEST, 'time', 'now'); + $time = ($_REQUEST['time'] ?? '') ?: 'now'; $output = '
' . L10n::t('Friendica provides this service for sharing events with other networks and friends in unknown timezones.') . '
'; @@ -41,7 +41,7 @@ class Localtime extends BaseModule $output .= ''; return $output; diff --git a/src/Module/Debug/Probe.php b/src/Module/Debug/Probe.php index f29f3b3bb..6762c5b82 100644 --- a/src/Module/Debug/Probe.php +++ b/src/Module/Debug/Probe.php @@ -21,7 +21,7 @@ class Probe extends BaseModule throw $e; } - $addr = defaults($_GET, 'addr', ''); + $addr = $_GET['addr'] ?? ''; $res = ''; if (!empty($addr)) { diff --git a/src/Module/Debug/WebFinger.php b/src/Module/Debug/WebFinger.php index 2b0b9c53b..18cf4bb2a 100644 --- a/src/Module/Debug/WebFinger.php +++ b/src/Module/Debug/WebFinger.php @@ -20,7 +20,7 @@ class WebFinger extends BaseModule throw $e; } - $addr = defaults($_GET, 'addr', ''); + $addr = $_GET['addr'] ?? ''; $res = ''; if (!empty($addr)) { diff --git a/src/Module/Feed.php b/src/Module/Feed.php index 15b2026e2..49ecfed96 100644 --- a/src/Module/Feed.php +++ b/src/Module/Feed.php @@ -27,7 +27,7 @@ class Feed extends BaseModule { $a = self::getApp(); - $last_update = defaults($_GET, 'last_update', ''); + $last_update = $_GET['last_update'] ?? ''; $nocache = !empty($_GET['nocache']) && local_user(); // @TODO: Replace with parameter from router diff --git a/src/Module/Filer/RemoveTag.php b/src/Module/Filer/RemoveTag.php index 7e88b2e72..1dcc2e41e 100644 --- a/src/Module/Filer/RemoveTag.php +++ b/src/Module/Filer/RemoveTag.php @@ -23,8 +23,8 @@ class RemoveTag extends BaseModule $item_id = (($app->argc > 1) ? intval($app->argv[1]) : 0); - $term = XML::unescape(trim(defaults($_GET, 'term', ''))); - $cat = XML::unescape(trim(defaults($_GET, 'cat', ''))); + $term = XML::unescape(trim($_GET['term'] ?? '')); + $cat = XML::unescape(trim($_GET['cat'] ?? '')); $category = (($cat) ? true : false); diff --git a/src/Module/Filer/SaveTag.php b/src/Module/Filer/SaveTag.php index 08ff1a32d..e8e311268 100644 --- a/src/Module/Filer/SaveTag.php +++ b/src/Module/Filer/SaveTag.php @@ -27,7 +27,7 @@ class SaveTag extends BaseModule $a = self::getApp(); $logger = $a->getLogger(); - $term = XML::unescape(trim(defaults($_GET, 'term', ''))); + $term = XML::unescape(trim($_GET['term'] ?? '')); // @TODO: Replace with parameter from router $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); diff --git a/src/Module/FollowConfirm.php b/src/Module/FollowConfirm.php index 1921e748a..f4f2a877c 100644 --- a/src/Module/FollowConfirm.php +++ b/src/Module/FollowConfirm.php @@ -28,10 +28,10 @@ class FollowConfirm extends BaseModule return; } - $intro_id = intval(defaults($_POST, 'intro_id' , 0)); - $duplex = intval(defaults($_POST, 'duplex' , 0)); - $cid = intval(defaults($_POST, 'contact_id', 0)); - $hidden = intval(defaults($_POST, 'hidden' , 0)); + $intro_id = intval($_POST['intro_id'] ?? 0); + $duplex = intval($_POST['duplex'] ?? 0); + $cid = intval($_POST['contact_id'] ?? 0); + $hidden = intval($_POST['hidden'] ?? 0); if (empty($cid)) { notice(L10n::t('No given contact.') . EOL); diff --git a/src/Module/Followers.php b/src/Module/Followers.php index 79f34021b..5bd3fe0ce 100644 --- a/src/Module/Followers.php +++ b/src/Module/Followers.php @@ -29,7 +29,7 @@ class Followers extends BaseModule throw new \Friendica\Network\HTTPException\NotFoundException(); } - $page = defaults($_REQUEST, 'page', null); + $page = $_REQUEST['page'] ?? null; $followers = ActivityPub\Transmitter::getFollowers($owner, $page); diff --git a/src/Module/Following.php b/src/Module/Following.php index 3a68e7e0a..5b5f4dc98 100644 --- a/src/Module/Following.php +++ b/src/Module/Following.php @@ -29,7 +29,7 @@ class Following extends BaseModule throw new \Friendica\Network\HTTPException\NotFoundException(); } - $page = defaults($_REQUEST, 'page', null); + $page = $_REQUEST['page'] ?? null; $Following = ActivityPub\Transmitter::getFollowing($owner, $page); diff --git a/src/Module/Install.php b/src/Module/Install.php index 7ba403966..39d6a062a 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -73,7 +73,7 @@ class Install extends BaseModule // so we may not have a css at all. Here we set a static css file for the install procedure pages Renderer::$theme['stylesheet'] = $a->getBaseURL() . '/view/install/style.css'; - self::$currentWizardStep = defaults($_POST, 'pass', self::SYSTEM_CHECK); + self::$currentWizardStep = ($_POST['pass'] ?? '') ?: self::SYSTEM_CHECK; } public static function post() @@ -345,8 +345,8 @@ class Install extends BaseModule { $configCache->set($cat, $key, Strings::escapeTags( - trim(defaults($post, sprintf('%s-%s', $cat, $key), - (!isset($default) ? $configCache->get($cat, $key) : $default)) + trim(($post[sprintf('%s-%s', $cat, $key)] ?? '') ?: + ($default ?? $configCache->get($cat, $key)) ) ) ); diff --git a/src/Module/Like.php b/src/Module/Like.php index a43e38045..cc450dd9d 100644 --- a/src/Module/Like.php +++ b/src/Module/Like.php @@ -36,7 +36,7 @@ class Like extends BaseModule // Decide how to return. If we were called with a 'return' argument, // then redirect back to the calling page. If not, just quietly end - $returnPath = defaults($_REQUEST, 'return', ''); + $returnPath = $_REQUEST['return'] ?? ''; if (!empty($returnPath)) { $rand = '_=' . time(); diff --git a/src/Module/Login.php b/src/Module/Login.php index 8affd7755..b67f48fb9 100644 --- a/src/Module/Login.php +++ b/src/Module/Login.php @@ -53,7 +53,7 @@ class Login extends BaseModule && (!empty($_POST['openid_url']) || !empty($_POST['username'])) ) { - $openid_url = trim(defaults($_POST, 'openid_url', $_POST['username'])); + $openid_url = trim(($_POST['openid_url'] ?? '') ?: $_POST['username']); self::openIdAuthentication($openid_url, !empty($_POST['remember'])); } diff --git a/src/Module/Magic.php b/src/Module/Magic.php index 4cb3dc732..b04ea80c0 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -28,8 +28,8 @@ class Magic extends BaseModule Logger::log('args: ' . print_r($_REQUEST, true), Logger::DATA); - $addr = defaults($_REQUEST, 'addr', ''); - $dest = defaults($_REQUEST, 'dest', ''); + $addr = $_REQUEST['addr'] ?? ''; + $dest = $_REQUEST['dest'] ?? ''; $test = (!empty($_REQUEST['test']) ? intval($_REQUEST['test']) : 0); $owa = (!empty($_REQUEST['owa']) ? intval($_REQUEST['owa']) : 0); $cid = 0; diff --git a/src/Module/Outbox.php b/src/Module/Outbox.php index 148256779..4fc050763 100644 --- a/src/Module/Outbox.php +++ b/src/Module/Outbox.php @@ -28,7 +28,7 @@ class Outbox extends BaseModule throw new \Friendica\Network\HTTPException\NotFoundException(); } - $page = defaults($_REQUEST, 'page', null); + $page = $_REQUEST['page'] ?? null; /// @todo Add Authentication to enable fetching of non public content // $requester = HTTPSignature::getSigner('', $_SERVER); diff --git a/src/Module/Profile.php b/src/Module/Profile.php index cb710b10b..ed3754075 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -102,7 +102,7 @@ class Profile extends BaseModule // site block if (!$blocked && !$userblock) { - $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], defaults($a->profile, 'pub_keywords', '')); + $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], $a->profile['pub_keywords'] ?? ''); if (strlen($keywords)) { $a->page['htmlhead'] .= '' . "\n"; } @@ -146,10 +146,10 @@ class Profile extends BaseModule } if (empty($category)) { - $category = defaults($_GET, 'category', ''); + $category = $_GET['category'] ?? ''; } - $hashtags = defaults($_GET, 'tag', ''); + $hashtags = $_GET['tag'] ?? ''; if (Config::get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['profile_uid'])) { return Login::form(); @@ -174,7 +174,7 @@ class Profile extends BaseModule } if (!$update) { - $tab = Strings::escapeTags(trim(defaults($_GET, 'tab', ''))); + $tab = Strings::escapeTags(trim($_GET['tab'] ?? '')); $o .= ProfileModel::getTabs($a, $tab, $is_owner, $a->profile['nickname']); diff --git a/src/Module/Profile/Contacts.php b/src/Module/Profile/Contacts.php index ed41f421b..1bf88d7c5 100644 --- a/src/Module/Profile/Contacts.php +++ b/src/Module/Profile/Contacts.php @@ -28,7 +28,7 @@ class Contacts extends BaseModule //@TODO: Get value from router parameters $nickname = $a->argv[1]; - $type = defaults($a->argv, 3, 'all'); + $type = ($a->argv[3] ?? '') ?: 'all'; Nav::setSelected('home'); diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index 38a9b17e0..2b8ad01dd 100644 --- a/src/Module/Proxy.php +++ b/src/Module/Proxy.php @@ -210,7 +210,7 @@ class Proxy extends BaseModule $url = base64_decode(strtr($url, '-_', '+/'), true); } else { - $url = defaults($_REQUEST, 'url', ''); + $url = $_REQUEST['url'] ?? ''; } return [ diff --git a/src/Module/Register.php b/src/Module/Register.php index 367eeb5ad..03f9dbb69 100644 --- a/src/Module/Register.php +++ b/src/Module/Register.php @@ -62,12 +62,12 @@ class Register extends BaseModule } } - $username = defaults($_REQUEST, 'username' , ''); - $email = defaults($_REQUEST, 'email' , ''); - $openid_url = defaults($_REQUEST, 'openid_url', ''); - $nickname = defaults($_REQUEST, 'nickname' , ''); - $photo = defaults($_REQUEST, 'photo' , ''); - $invite_id = defaults($_REQUEST, 'invite_id' , ''); + $username = $_REQUEST['username'] ?? ''; + $email = $_REQUEST['email'] ?? ''; + $openid_url = $_REQUEST['openid_url'] ?? ''; + $nickname = $_REQUEST['nickname'] ?? ''; + $photo = $_REQUEST['photo'] ?? ''; + $invite_id = $_REQUEST['invite_id'] ?? ''; if (Config::get('system', 'no_openid')) { $fillwith = ''; @@ -290,7 +290,7 @@ class Register extends BaseModule 'source_photo' => $base_url . '/photo/avatar/' . $user['uid'] . '.jpg', 'to_email' => $admin['email'], 'uid' => $admin['uid'], - 'language' => defaults($admin, 'language', 'en'), + 'language' => ($admin['language'] ?? '') ?: 'en', 'show_in_notification_page' => false ]); } diff --git a/src/Module/Search/Acl.php b/src/Module/Search/Acl.php index 95ebd1cf7..101675600 100644 --- a/src/Module/Search/Acl.php +++ b/src/Module/Search/Acl.php @@ -275,8 +275,8 @@ class Acl extends BaseModule 'id' => intval($g['id']), 'network' => $g['network'], 'link' => $g['url'], - 'nick' => htmlentities(defaults($g, 'attag', $g['nick'])), - 'addr' => htmlentities(defaults($g, 'addr', $g['url'])), + 'nick' => htmlentities(($g['attag'] ?? '') ?: $g['nick']), + 'addr' => htmlentities(($g['addr'] ?? '') ?: $g['url']), 'forum' => !empty($g['forum']) || !empty($g['prv']) ? 1 : 0, ]; if ($entry['forum']) { @@ -336,8 +336,8 @@ class Acl extends BaseModule 'id' => intval($contact['cid']), 'network' => $contact['network'], 'link' => $contact['url'], - 'nick' => htmlentities(defaults($contact, 'nick', $contact['addr'])), - 'addr' => htmlentities(defaults($contact, 'addr', $contact['url'])), + 'nick' => htmlentities(($contact['nick'] ?? '') ?: $contact['addr']), + 'addr' => htmlentities(($contact['addr'] ?? '') ?: $contact['url']), 'forum' => $contact['forum'] ]; } diff --git a/src/Module/Settings/TwoFactor/Index.php b/src/Module/Settings/TwoFactor/Index.php index 79b92f159..e7694225c 100644 --- a/src/Module/Settings/TwoFactor/Index.php +++ b/src/Module/Settings/TwoFactor/Index.php @@ -26,12 +26,12 @@ class Index extends BaseSettingsModule self::checkFormSecurityTokenRedirectOnError('settings/2fa', 'settings_2fa'); try { - User::getIdFromPasswordAuthentication(local_user(), defaults($_POST, 'password', '')); + User::getIdFromPasswordAuthentication(local_user(), $_POST['password'] ?? ''); $has_secret = (bool) PConfig::get(local_user(), '2fa', 'secret'); $verified = PConfig::get(local_user(), '2fa', 'verified'); - switch (defaults($_POST, 'action', '')) { + switch ($_POST['action'] ?? '') { case 'enable': if (!$has_secret && !$verified) { $Google2FA = new Google2FA(); diff --git a/src/Module/Settings/TwoFactor/Verify.php b/src/Module/Settings/TwoFactor/Verify.php index caed464ec..b9205852d 100644 --- a/src/Module/Settings/TwoFactor/Verify.php +++ b/src/Module/Settings/TwoFactor/Verify.php @@ -49,12 +49,12 @@ class Verify extends BaseSettingsModule return; } - if (defaults($_POST, 'action', null) == 'verify') { + if (($_POST['action'] ?? '') == 'verify') { self::checkFormSecurityTokenRedirectOnError('settings/2fa/verify', 'settings_2fa_verify'); $google2fa = new Google2FA(); - $valid = $google2fa->verifyKey(PConfig::get(local_user(), '2fa', 'secret'), defaults($_POST, 'verify_code', '')); + $valid = $google2fa->verifyKey(PConfig::get(local_user(), '2fa', 'secret'), $_POST['verify_code'] ?? ''); if ($valid) { PConfig::set(local_user(), '2fa', 'verified', true); diff --git a/src/Module/Smilies.php b/src/Module/Smilies.php index 422f37d3e..ded58768f 100644 --- a/src/Module/Smilies.php +++ b/src/Module/Smilies.php @@ -29,7 +29,7 @@ class Smilies extends BaseModule public static function content() { $smilies = Content\Smilies::getList(); - $count = count(defaults($smilies, 'texts', [])); + $count = count($smilies['texts'] ?? []); $tpl = Renderer::getMarkupTemplate('smilies.tpl'); return Renderer::replaceMacros($tpl, [ diff --git a/src/Module/Special/HTTPException.php b/src/Module/Special/HTTPException.php index 6446ec38c..36c770fba 100644 --- a/src/Module/Special/HTTPException.php +++ b/src/Module/Special/HTTPException.php @@ -36,7 +36,7 @@ class HTTPException 500 => L10n::t('Internal Server Error'), 503 => L10n::t('Service Unavailable'), ]; - $title = defaults($titles, $e->getCode(), 'Error ' . $e->getCode()); + $title = ($titles[$e->getCode()] ?? '') ?: 'Error ' . $e->getCode(); if (empty($message)) { // Explanations are taken from https://en.wikipedia.org/wiki/List_of_HTTP_status_codes @@ -49,7 +49,7 @@ class HTTPException 503 => L10n::t('The server is currently unavailable (because it is overloaded or down for maintenance). Please try again later.'), ]; - $message = defaults($explanation, $e->getCode(), ''); + $message = $explanation[$e->getCode()] ?? ''; } return ['$title' => $title, '$message' => $message, '$back' => L10n::t('Go back')]; diff --git a/src/Module/Starred.php b/src/Module/Starred.php index df7da4099..70cd39735 100644 --- a/src/Module/Starred.php +++ b/src/Module/Starred.php @@ -41,7 +41,7 @@ class Starred extends BaseModule Item::update(['starred' => $starred], ['id' => $itemId]); // See if we've been passed a return path to redirect to - $returnPath = defaults($_REQUEST, 'return', ''); + $returnPath = $_REQUEST['return'] ?? ''; if ($returnPath) { $rand = '_=' . time(); if (strpos($returnPath, '?')) { diff --git a/src/Module/ThemeDetails.php b/src/Module/ThemeDetails.php index 7b53d1cfd..9a2e913bc 100644 --- a/src/Module/ThemeDetails.php +++ b/src/Module/ThemeDetails.php @@ -17,9 +17,9 @@ class ThemeDetails extends BaseModule $info = Theme::getInfo($theme); // Unfortunately there will be no translation for this string - $description = defaults($info, 'description', ''); - $version = defaults($info, 'version' , ''); - $credits = defaults($info, 'credits' , ''); + $description = $info['description'] ?? ''; + $version = $info['version'] ?? ''; + $credits = $info['credits'] ?? ''; echo json_encode([ 'img' => Theme::getScreenshot($theme), diff --git a/src/Module/TwoFactor/Recovery.php b/src/Module/TwoFactor/Recovery.php index 60f443c35..7c17fdace 100644 --- a/src/Module/TwoFactor/Recovery.php +++ b/src/Module/TwoFactor/Recovery.php @@ -28,12 +28,12 @@ class Recovery extends BaseModule return; } - if (defaults($_POST, 'action', null) == 'recover') { + if (($_POST['action'] ?? '') == 'recover') { self::checkFormSecurityTokenRedirectOnError('2fa', 'twofactor_recovery'); $a = self::getApp(); - $recovery_code = defaults($_POST, 'recovery_code', ''); + $recovery_code = $_POST['recovery_code'] ?? ''; if (RecoveryCode::existsForUser(local_user(), $recovery_code)) { RecoveryCode::markUsedForUser(local_user(), $recovery_code); diff --git a/src/Module/Xrd.php b/src/Module/Xrd.php index ae020d355..5e108c3b5 100644 --- a/src/Module/Xrd.php +++ b/src/Module/Xrd.php @@ -28,7 +28,7 @@ class Xrd extends BaseModule } $uri = urldecode(Strings::escapeTags(trim($_GET['uri']))); - if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/jrd+json') { + if (($_SERVER['HTTP_ACCEPT'] ?? '') == 'application/jrd+json') { $mode = 'json'; } else { $mode = 'xml'; @@ -39,7 +39,7 @@ class Xrd extends BaseModule } $uri = urldecode(Strings::escapeTags(trim($_GET['resource']))); - if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/xrd+xml') { + if (($_SERVER['HTTP_ACCEPT'] ?? '') == 'application/xrd+xml') { $mode = 'xml'; } else { $mode = 'json';