From 8b836189d473ef9ba752b4119ecd7eb042c0ad17 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 16 Oct 2019 08:43:59 -0400 Subject: [PATCH 1/2] Replace deprecated defaults() calls with ?? and ?: in include/ and view/ --- include/api.php | 2 +- include/conversation.php | 16 ++++++++-------- include/enotify.php | 22 +++++++++++----------- include/items.php | 2 +- view/theme/duepuntozero/style.php | 2 +- view/theme/frio/config.php | 2 +- view/theme/frio/php/default.php | 4 ++-- view/theme/frio/php/frio_boot.php | 2 +- view/theme/quattro/style.php | 2 +- view/theme/vier/style.php | 2 +- view/theme/vier/theme.php | 4 ++-- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/api.php b/include/api.php index e986a5173..7daf13455 100644 --- a/include/api.php +++ b/include/api.php @@ -322,7 +322,7 @@ function api_call(App $a) $stamp = microtime(true); $return = call_user_func($info['func'], $type); - $duration = (float) (microtime(true) - $stamp); + $duration = floatval(microtime(true) - $stamp); Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]); diff --git a/include/conversation.php b/include/conversation.php index 74c8a6d27..b6faa4d2c 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1208,7 +1208,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) '$new_post' => L10n::t('New Post'), '$return_path' => $query_str, '$action' => 'item', - '$share' => defaults($x, 'button', L10n::t('Share')), + '$share' => ($x['button'] ?? '') ?: L10n::t('Share'), '$upload' => L10n::t('Upload photo'), '$shortupload' => L10n::t('upload photo'), '$attach' => L10n::t('Attach file'), @@ -1225,17 +1225,17 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) '$shortsetloc' => L10n::t('set location'), '$noloc' => L10n::t('Clear browser location'), '$shortnoloc' => L10n::t('clear location'), - '$title' => defaults($x, 'title', ''), + '$title' => $x['title'] ?? '', '$placeholdertitle' => L10n::t('Set title'), - '$category' => defaults($x, 'category', ''), + '$category' => $x['category'] ?? '', '$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? L10n::t("Categories \x28comma-separated list\x29") : '', '$wait' => L10n::t('Please wait'), '$permset' => L10n::t('Permission settings'), '$shortpermset' => L10n::t('permissions'), '$wall' => $notes_cid ? 0 : 1, '$posttype' => $notes_cid ? Item::PT_PERSONAL_NOTE : Item::PT_ARTICLE, - '$content' => defaults($x, 'content', ''), - '$post_id' => defaults($x, 'post_id', ''), + '$content' => $x['content'] ?? '', + '$post_id' => $x['post_id'] ?? '', '$baseurl' => System::baseUrl(true), '$defloc' => $x['default_location'], '$visitor' => $x['visitor'], @@ -1527,9 +1527,9 @@ function get_responses(array $conv_responses, array $response_verbs, array $item $ret = []; foreach ($response_verbs as $v) { $ret[$v] = []; - $ret[$v]['count'] = defaults($conv_responses[$v], $item['uri'], 0); - $ret[$v]['list'] = defaults($conv_responses[$v], $item['uri'] . '-l', []); - $ret[$v]['self'] = defaults($conv_responses[$v], $item['uri'] . '-self', '0'); + $ret[$v]['count'] = $conv_responses[$v][$item['uri']] ?? 0; + $ret[$v]['list'] = $conv_responses[$v][$item['uri'] . '-l'] ?? []; + $ret[$v]['self'] = $conv_responses[$v][$item['uri'] . '-self'] ?? '0'; if (count($ret[$v]['list']) > MAX_LIKERS) { $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS); array_push($ret[$v]['list_part'], ''.$itemlink.''; diff --git a/include/items.php b/include/items.php index 4cc10e628..3868db40a 100644 --- a/include/items.php +++ b/include/items.php @@ -42,7 +42,7 @@ function add_page_info_data(array $data, $no_photos = false) $data["type"] = "link"; } - $data["title"] = defaults($data, "title", ""); + $data["title"] = $data["title"] ?? ''; if ((($data["type"] != "link") && ($data["type"] != "video") && ($data["type"] != "photo")) || ($data["title"] == $data["url"])) { return ""; diff --git a/view/theme/duepuntozero/style.php b/view/theme/duepuntozero/style.php index a5810f2dc..2758ada41 100644 --- a/view/theme/duepuntozero/style.php +++ b/view/theme/duepuntozero/style.php @@ -10,7 +10,7 @@ if (file_exists("$THEMEPATH/style.css")) { echo file_get_contents("$THEMEPATH/style.css"); } -$uid = defaults($_REQUEST, 'puid', 0); +$uid = $_REQUEST['puid'] ?? 0; $s_colorset = Config::get('duepuntozero', 'colorset'); $colorset = PConfig::get($uid, 'duepuntozero', 'colorset'); diff --git a/view/theme/frio/config.php b/view/theme/frio/config.php index df0f65a6b..125081235 100644 --- a/view/theme/frio/config.php +++ b/view/theme/frio/config.php @@ -132,7 +132,7 @@ function frio_form($arr) '$nav_icon_color' => array_key_exists('nav_icon_color', $disable) ? '' : ['frio_nav_icon_color', L10n::t('Navigation bar icon color '), $arr['nav_icon_color'], '', false], '$link_color' => array_key_exists('link_color', $disable) ? '' : ['frio_link_color', L10n::t('Link color'), $arr['link_color'], '', false], '$background_color' => array_key_exists('background_color', $disable) ? '' : ['frio_background_color', L10n::t('Set the background color'), $arr['background_color'], '', false], - '$contentbg_transp' => array_key_exists('contentbg_transp', $disable) ? '' : ['frio_contentbg_transp', L10n::t('Content background opacity'), defaults($arr, 'contentbg_transp', 100), ''], + '$contentbg_transp' => array_key_exists('contentbg_transp', $disable) ? '' : ['frio_contentbg_transp', L10n::t('Content background opacity'), ($arr['contentbg_transp'] ?? 0) ?: 100, ''], '$background_image' => array_key_exists('background_image', $disable) ? '' : ['frio_background_image', L10n::t('Set the background image'), $arr['background_image'], $background_image_help, false], '$bg_image_options_title' => L10n::t('Background image style'), '$bg_image_options' => Image::get_options($arr), diff --git a/view/theme/frio/php/default.php b/view/theme/frio/php/default.php index 22bb99580..6b39e68ac 100644 --- a/view/theme/frio/php/default.php +++ b/view/theme/frio/php/default.php @@ -28,7 +28,7 @@ $is_singleuser_class = $is_singleuser ? "is-singleuser" : "is-not-singleuser"; <?php if (!empty($page['title'])) echo $page['title'] ?> - + diff --git a/view/theme/frio/php/frio_boot.php b/view/theme/frio/php/frio_boot.php index dcb87b6d2..7ec81a356 100644 --- a/view/theme/frio/php/frio_boot.php +++ b/view/theme/frio/php/frio_boot.php @@ -22,7 +22,7 @@ function load_page(App $a) require 'view/theme/frio/none.php'; } else { $template = 'view/theme/' . $a->getCurrentTheme() . '/' - . defaults($a->page, 'template', 'default' ) . '.php'; + . (($a->page['template'] ?? '') ?: 'default' ) . '.php'; if (file_exists($template)) { require_once $template; } else { diff --git a/view/theme/quattro/style.php b/view/theme/quattro/style.php index cca458a25..84fa0b973 100644 --- a/view/theme/quattro/style.php +++ b/view/theme/quattro/style.php @@ -6,7 +6,7 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Model\Profile; -$uid = defaults($_REQUEST, 'puid', 0); +$uid = $_REQUEST['puid'] ?? 0; $color = false; $quattro_align = false; diff --git a/view/theme/vier/style.php b/view/theme/vier/style.php index 69bfc78d8..8a7c2f67d 100644 --- a/view/theme/vier/style.php +++ b/view/theme/vier/style.php @@ -7,7 +7,7 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Model\Profile; -$uid = defaults($_REQUEST, 'puid', 0); +$uid = $_REQUEST['puid'] ?? 0; $style = PConfig::get($uid, 'vier', 'style'); diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index f33f3017f..e5d71bdf5 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -29,7 +29,7 @@ function vier_init(App $a) Renderer::setActiveTemplateEngine('smarty3'); - if (!empty($a->argv[0]) && $a->argv[0] . defaults($a->argv, 1, '') === "profile".$a->user['nickname'] || $a->argv[0] === "network" && local_user()) { + if (!empty($a->argv[0]) && ($a->argv[0] . ($a->argv[1] ?? '')) === ('profile' . $a->user['nickname']) || $a->argv[0] === 'network' && local_user()) { vier_community_info(); $a->page['htmlhead'] .= "\n"; @@ -191,7 +191,7 @@ function vier_community_info() //Community_Pages at right_aside if ($show_pages && local_user()) { - $cid = defaults($_GET, 'cid', null); + $cid = $_GET['cid'] ?? null; //sort by last updated item $lastitem = true; From f65ebb937c181e0650f91ff525532abe6d4ee7d4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 16 Oct 2019 08:44:19 -0400 Subject: [PATCH 2/2] Remove deprecated defaults() function --- boot.php | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/boot.php b/boot.php index ae9c35ae5..3571a77c1 100644 --- a/boot.php +++ b/boot.php @@ -322,47 +322,6 @@ function get_app() return BaseObject::getApp(); } -/** - * Return the provided variable value if it exists and is truthy or the provided - * default value instead. - * - * Works with initialized variables and potentially uninitialized array keys - * - * Usages: - * - defaults($var, $default) - * - defaults($array, 'key', $default) - * - * @param array $args - * @brief Returns a defaut value if the provided variable or array key is falsy - * @return mixed - * @deprecated since version 2019.06, use native coalesce operator (??) instead - */ -function defaults(...$args) -{ - if (count($args) < 2) { - throw new BadFunctionCallException('defaults() requires at least 2 parameters'); - } - if (count($args) > 3) { - throw new BadFunctionCallException('defaults() cannot use more than 3 parameters'); - } - if (count($args) === 3 && is_null($args[1])) { - throw new BadFunctionCallException('defaults($arr, $key, $def) $key is null'); - } - - // The default value always is the last argument - $return = array_pop($args); - - if (count($args) == 2 && is_array($args[0]) && !empty($args[0][$args[1]])) { - $return = $args[0][$args[1]]; - } - - if (count($args) == 1 && !empty($args[0])) { - $return = $args[0]; - } - - return $return; -} - /** * @brief Used to end the current process, after saving session state. * @deprecated