Merge pull request #7743 from MrPetovan/task/7190-remove-defaults-modules

Replace deprecated defaults() calls by ?? and ?: operators in src/Module/
This commit is contained in:
Philipp 2019-10-15 18:17:45 +02:00 committed by GitHub
commit c0b78a9720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 115 additions and 94 deletions

View File

@ -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);

View File

@ -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

View File

@ -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));

View File

@ -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');

View File

@ -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)) {

View File

@ -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;
}

View File

@ -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")) {

View File

@ -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');

View File

@ -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'],

View File

@ -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);

View File

@ -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'],

View File

@ -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
]);

View File

@ -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
]);
}

View File

@ -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 = '<h3>' . L10n::t('Time Conversion') . '</h3>';
$output .= '<p>' . L10n::t('Friendica provides this service for sharing events with other networks and friends in unknown timezones.') . '</p>';
@ -41,7 +41,7 @@ class Localtime extends BaseModule
$output .= '<form action ="' . $app->getBaseURL() . '/localtime?time=' . $time . '" method="post" >';
$output .= '<p>' . L10n::t('Please select your timezone:') . '</p>';
$output .= Temporal::getTimezoneSelect(defaults($_REQUEST, 'timezone', Installer::DEFAULT_TZ));
$output .= Temporal::getTimezoneSelect(($_REQUEST['timezone'] ?? '') ?: Installer::DEFAULT_TZ);
$output .= '<input type="submit" name="submit" value="' . L10n::t('Submit') . '" /></form>';
return $output;

View File

@ -21,7 +21,7 @@ class Probe extends BaseModule
throw $e;
}
$addr = defaults($_GET, 'addr', '');
$addr = $_GET['addr'] ?? '';
$res = '';
if (!empty($addr)) {

View File

@ -20,7 +20,7 @@ class WebFinger extends BaseModule
throw $e;
}
$addr = defaults($_GET, 'addr', '');
$addr = $_GET['addr'] ?? '';
$res = '';
if (!empty($addr)) {

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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))
)
)
);

View File

@ -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();

View File

@ -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']));
}

View File

@ -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;

View File

@ -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);

View File

@ -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'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\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']);

View File

@ -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');

View File

@ -210,7 +210,7 @@ class Proxy extends BaseModule
$url = base64_decode(strtr($url, '-_', '+/'), true);
} else {
$url = defaults($_REQUEST, 'url', '');
$url = $_REQUEST['url'] ?? '';
}
return [

View File

@ -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
]);
}

View File

@ -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']
];
}

View File

@ -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();

View File

@ -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);

View File

@ -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, [

View File

@ -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')];

View File

@ -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, '?')) {

View File

@ -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),

View File

@ -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);

View File

@ -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';