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