From 06b15a6ed0edc129143eca28ebe33009a59b3562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 30 Jun 2022 13:32:13 +0200 Subject: [PATCH] Changes: - added missing type-hints - avoided local variables - added some documentation - changed double-quotes to single --- blackout/blackout.php | 16 +++---- blockbot/blockbot.php | 2 +- cookienotice/cookienotice.php | 1 - curweather/curweather.php | 2 +- geocoordinates/geocoordinates.php | 57 ++++++++++++------------ gravatar/gravatar.php | 8 ++-- impressum/impressum.php | 23 ++++------ irc/irc.php | 2 +- keycloakpassword/keycloakpassword.php | 2 +- libravatar/libravatar.php | 7 ++- mailstream/mailstream.php | 62 ++++++++++++++++----------- mathjax/mathjax.php | 2 +- newmemberwidget/newmemberwidget.php | 25 +++++------ nitter/nitter.php | 17 ++++---- nominatim/nominatim.php | 9 ++-- notifyall/notifyall.php | 2 +- openstreetmap/openstreetmap.php | 25 +++++------ pageheader/pageheader.php | 10 ++--- piwik/piwik.php | 20 ++++----- public_server/public_server.php | 27 +++++------- qcomment/qcomment.php | 4 +- rendertime/rendertime.php | 5 +-- saml/saml.php | 12 +++--- showmore_dyn/showmore_dyn.php | 4 +- statusnet/statusnet.php | 2 +- tumblr/tumblr.php | 15 +++---- twitter/twitter.php | 8 ++-- viewsrc/viewsrc.php | 6 ++- webrtc/webrtc.php | 20 +++++---- 29 files changed, 191 insertions(+), 204 deletions(-) diff --git a/blackout/blackout.php b/blackout/blackout.php index e8efecd2..f2fb588b 100644 --- a/blackout/blackout.php +++ b/blackout/blackout.php @@ -83,7 +83,8 @@ function blackout_redirect (App $a, $b) } } -function blackout_addon_admin(App $a, &$o) { +function blackout_addon_admin(App $a, string &$o) +{ $mystart = DI::config()->get('blackout','begindate'); if (! is_string($mystart)) { $mystart = 'YYYY-MM-DD hh:mm'; } $myend = DI::config()->get('blackout','enddate'); @@ -110,11 +111,10 @@ function blackout_addon_admin(App $a, &$o) { '$aboutredirect' => DI::l10n()->t("Note: The redirect will be active from the moment you press the submit button. Users currently logged in will not be thrown out but can't login again after logging out while the blackout is still in place."), ]); } -function blackout_addon_admin_post (App $a) { - $begindate = trim($_POST['startdate']); - $enddate = trim($_POST['enddate']); - $url = trim($_POST['rurl']); - DI::config()->set('blackout','begindate',$begindate); - DI::config()->set('blackout','enddate',$enddate); - DI::config()->set('blackout','url',$url); + +function blackout_addon_admin_post (App $a) +{ + DI::config()->set('blackout', 'begindate', trim($_POST['startdate'])); + DI::config()->set('blackout', 'enddate', trim($_POST['enddate'])); + DI::config()->set('blackout', 'url', trim($_POST['rurl'])); } diff --git a/blockbot/blockbot.php b/blockbot/blockbot.php index e22dc471..f57498d9 100644 --- a/blockbot/blockbot.php +++ b/blockbot/blockbot.php @@ -24,7 +24,7 @@ function blockbot_install() Hook::register('init_1', __FILE__, 'blockbot_init_1'); } -function blockbot_addon_admin(App $a, &$o) +function blockbot_addon_admin(App $a, string &$o) { $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/blockbot/'); diff --git a/cookienotice/cookienotice.php b/cookienotice/cookienotice.php index a21e4204..5364573c 100644 --- a/cookienotice/cookienotice.php +++ b/cookienotice/cookienotice.php @@ -58,7 +58,6 @@ function cookienotice_addon_admin(App $a, &$s) * handles the post request from the admin panel * * @param App $a - * * @return void */ function cookienotice_addon_admin_post(App $a) diff --git a/curweather/curweather.php b/curweather/curweather.php index 975fbde3..dc634b59 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -212,7 +212,7 @@ function curweather_addon_admin_post(App $a) } } -function curweather_addon_admin(App $a, &$o) +function curweather_addon_admin(App $a, string &$o) { if (!$a->isSiteAdmin()) { return; diff --git a/geocoordinates/geocoordinates.php b/geocoordinates/geocoordinates.php index 73210b66..7830b330 100644 --- a/geocoordinates/geocoordinates.php +++ b/geocoordinates/geocoordinates.php @@ -18,58 +18,63 @@ function geocoordinates_install() Hook::register('post_remote', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); } -function geocoordinates_resolve_item(&$item) +function geocoordinates_resolve_item(array &$item) { - if((!$item["coord"]) || ($item["location"])) + if ((!$item['coord']) || ($item['location'])) { return; + } - $key = DI::config()->get("geocoordinates", "api_key"); - if ($key == "") + $key = DI::config()->get('geocoordinates', 'api_key'); + if ($key == '') { return; + } - $language = DI::config()->get("geocoordinates", "language"); - if ($language == "") - $language = "de"; + $language = DI::config()->get('geocoordinates', 'language'); + if ($language == '') { + $language = 'de'; + } - $coords = explode(' ',$item["coord"]); + $coords = explode(' ', $item['coord']); - if (count($coords) < 2) + if (count($coords) < 2) { return; + } $coords[0] = round($coords[0], 5); $coords[1] = round($coords[1], 5); - $result = DI::cache()->get("geocoordinates:".$language.":".$coords[0]."-".$coords[1]); + $result = DI::cache()->get('geocoordinates:' . $language . ':' . $coords[0] . '-' . $coords[1]); if (!is_null($result)) { - $item["location"] = $result; + $item['location'] = $result; return; } - $s = DI::httpClient()->fetch("https://api.opencagedata.com/geocode/v1/json?q=" . $coords[0] . "," . $coords[1] . "&key=" . $key . "&language=" . $language); + $s = DI::httpClient()->fetch('https://api.opencagedata.com/geocode/v1/json?q=' . $coords[0] . ',' . $coords[1] . '&key=' . $key . '&language=' . $language); if (!$s) { - Logger::info("API could not be queried"); + Logger::info('API could not be queried'); return; } $data = json_decode($s); - if ($data->status->code != "200") { - Logger::info("API returned error ".$data->status->code." ".$data->status->message); + if ($data->status->code != '200') { + Logger::info('API returned error ' . $data->status->code . ' ' . $data->status->message); return; } if (($data->total_results == 0) || (count($data->results) == 0)) { - Logger::info("No results found for coordinates ".$item["coord"]); + Logger::info('No results found for coordinates ' . $item['coord']); return; } - $item["location"] = $data->results[0]->formatted; + $item['location'] = $data->results[0]->formatted; - Logger::info("Got location for coordinates ".$coords[0]."-".$coords[1].": ".$item["location"]); + Logger::info('Got location for coordinates ' . $coords[0] . '-' . $coords[1] . ': ' . $item['location']); - if ($item["location"] != "") - DI::cache()->set("geocoordinates:".$language.":".$coords[0]."-".$coords[1], $item["location"]); + if ($item['location'] != '') { + DI::cache()->set('geocoordinates:' . $language.':' . $coords[0] . '-' . $coords[1], $item['location']); + } } function geocoordinates_post_hook(App $a, &$item) @@ -77,10 +82,9 @@ function geocoordinates_post_hook(App $a, &$item) geocoordinates_resolve_item($item); } -function geocoordinates_addon_admin(App $a, &$o) +function geocoordinates_addon_admin(App $a, string &$o) { - - $t = Renderer::getMarkupTemplate("admin.tpl", "addon/geocoordinates/"); + $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/geocoordinates/'); $o = Renderer::replaceMacros($t, [ '$submit' => DI::l10n()->t('Save Settings'), @@ -91,9 +95,6 @@ function geocoordinates_addon_admin(App $a, &$o) function geocoordinates_addon_admin_post(App $a) { - $api_key = trim($_POST['api_key'] ?? ''); - DI::config()->set('geocoordinates', 'api_key', $api_key); - - $language = trim($_POST['language'] ?? ''); - DI::config()->set('geocoordinates', 'language', $language); + DI::config()->set('geocoordinates', 'api_key', trim($_POST['api_key'] ?? '')); + DI::config()->set('geocoordinates', 'language', trim($_POST['language'] ?? '')); } diff --git a/gravatar/gravatar.php b/gravatar/gravatar.php index 3796f9dc..27e55002 100644 --- a/gravatar/gravatar.php +++ b/gravatar/gravatar.php @@ -62,7 +62,7 @@ function gravatar_lookup(App $a, array &$b) /** * Display admin settings for this addon */ -function gravatar_addon_admin (App $a, &$o) +function gravatar_addon_admin (App $a, string &$o) { $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/gravatar/" ); @@ -113,8 +113,6 @@ function gravatar_addon_admin_post (App $a) { BaseModule::checkFormSecurityToken('gravatarsave'); - $default_avatar = trim($_POST['avatar'] ?? 'identicon'); - $rating = trim($_POST['rating'] ?? 'g'); - DI::config()->set('gravatar', 'default_avatar', $default_avatar); - DI::config()->set('gravatar', 'rating', $rating); + DI::config()->set('gravatar', 'default_avatar', trim($_POST['avatar'] ?? 'identicon')); + DI::config()->set('gravatar', 'rating', $rating = trim($_POST['rating'] ?? 'g')); } diff --git a/impressum/impressum.php b/impressum/impressum.php index 3fba0085..ae5e2637 100644 --- a/impressum/impressum.php +++ b/impressum/impressum.php @@ -45,7 +45,7 @@ function obfuscate_email (string $s): string function impressum_footer(App $a, string &$body) { - $text = ProxyUtils::proxifyHtml(BBCode::convert(DI::config()->get('impressum','footer_text'))); + $text = ProxyUtils::proxifyHtml(BBCode::convert(DI::config()->get('impressum', 'footer_text'))); if ($text != '') { DI::page()['htmlhead'] .= ''; @@ -95,22 +95,15 @@ function impressum_show(App $a, string &$body) function impressum_addon_admin_post (App $a) { - $owner = trim($_POST['owner'] ?? ''); - $ownerprofile = trim($_POST['ownerprofile'] ?? ''); - $postal = trim($_POST['postal'] ?? ''); - $notes = trim($_POST['notes'] ?? ''); - $email = trim($_POST['email'] ?? ''); - $footer_text = trim($_POST['footer_text'] ?? ''); - - DI::config()->set('impressum', 'owner', strip_tags($owner)); - DI::config()->set('impressum', 'ownerprofile', strip_tags($ownerprofile)); - DI::config()->set('impressum', 'postal', strip_tags($postal)); - DI::config()->set('impressum', 'email', strip_tags($email)); - DI::config()->set('impressum', 'notes', strip_tags($notes)); - DI::config()->set('impressum', 'footer_text', strip_tags($footer_text)); + DI::config()->set('impressum', 'owner', strip_tags(trim($_POST['owner'] ?? ''))); + DI::config()->set('impressum', 'ownerprofile', strip_tags(trim($_POST['ownerprofile'] ?? ''))); + DI::config()->set('impressum', 'postal', strip_tags(trim($_POST['postal'] ?? ''))); + DI::config()->set('impressum', 'email', strip_tags(trim($_POST['notes'] ?? ''))); + DI::config()->set('impressum', 'notes', strip_tags(trim($_POST['email'] ?? ''))); + DI::config()->set('impressum', 'footer_text', strip_tags(trim($_POST['footer_text'] ?? ''))); } -function impressum_addon_admin (App $a, &$o) +function impressum_addon_admin (App $a, string &$o) { $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/impressum/' ); $o = Renderer::replaceMacros($t, [ diff --git a/irc/irc.php b/irc/irc.php index 10421845..206b1e7f 100644 --- a/irc/irc.php +++ b/irc/irc.php @@ -135,7 +135,7 @@ function irc_addon_admin_post (App $a) DI::config()->set('irc', 'sitechats', trim($_POST['sitechats'])); } } -function irc_addon_admin (App $a, &$o) { +function irc_addon_admin (App $a, string &$o) { $sitechats = DI::config()->get('irc', 'sitechats'); /* popular channels */ $autochans = DI::config()->get('irc', 'autochans'); /* auto connect chans */ $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/irc/' ); diff --git a/keycloakpassword/keycloakpassword.php b/keycloakpassword/keycloakpassword.php index 0da0eb2f..67376315 100644 --- a/keycloakpassword/keycloakpassword.php +++ b/keycloakpassword/keycloakpassword.php @@ -110,7 +110,7 @@ function keycloakpassword_admin_input($key, $label, $description) ]; } -function keycloakpassword_addon_admin(App $a, &$o) +function keycloakpassword_addon_admin(App $a, string &$o) { $form = keycloakpassword_admin_input( diff --git a/libravatar/libravatar.php b/libravatar/libravatar.php index e1ba4baa..1ddeccd4 100644 --- a/libravatar/libravatar.php +++ b/libravatar/libravatar.php @@ -57,9 +57,9 @@ function libravatar_lookup(array $a, array &$b) /** * Display admin settings for this addon */ -function libravatar_addon_admin(App $a, &$o) +function libravatar_addon_admin(App $a, string &$o) { - $t = Renderer::getMarkupTemplate("admin.tpl", "addon/libravatar"); + $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/libravatar'); $default_avatar = DI::config()->get('libravatar', 'default_avatar', 'identicon'); @@ -90,6 +90,5 @@ function libravatar_addon_admin(App $a, &$o) */ function libravatar_addon_admin_post(App $a) { - $default_avatar = trim($_POST['avatar'] ?? 'identicon'); - DI::config()->set('libravatar', 'default_avatar', $default_avatar); + DI::config()->set('libravatar', 'default_avatar', trim($_POST['avatar'] ?? 'identicon')); } diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 08fb46a6..8c6e2693 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -75,12 +75,13 @@ function mailstream_addon_admin(App $a, string &$o) $frommail = DI::config()->get('mailstream', 'frommail'); $template = Renderer::getMarkupTemplate('admin.tpl', 'addon/mailstream/'); $config = ['frommail', - DI::l10n()->t('From Address'), - $frommail, - DI::l10n()->t('Email address that stream items will appear to be from.')]; + DI::l10n()->t('From Address'), + $frommail, + DI::l10n()->t('Email address that stream items will appear to be from.')]; $o .= Renderer::replaceMacros($template, [ - '$frommail' => $config, - '$submit' => DI::l10n()->t('Save Settings')]); + '$frommail' => $config, + '$submit' => DI::l10n()->t('Save Settings') + ]); } /** @@ -101,7 +102,7 @@ function mailstream_addon_admin_post() * * @return string the created message ID */ -function mailstream_generate_id($uri) +function mailstream_generate_id(string $uri): string { $host = DI::baseUrl()->getHostname(); $resource = hash('md5', $uri); @@ -110,7 +111,7 @@ function mailstream_generate_id($uri) return $message_id; } -function mailstream_send_hook(App $a, $data) +function mailstream_send_hook(App $a, array $data) { $criteria = array('uid' => $data['uid'], 'contact-id' => $data['contact-id'], 'uri' => $data['uri']); $item = Post::selectFirst([], $criteria); @@ -140,8 +141,9 @@ function mailstream_send_hook(App $a, $data) * * @param App $a App object (unused) * @param array $item content of the item (may or may not already be stored in the item table) + * @return void */ -function mailstream_post_hook(App $a, &$item) +function mailstream_post_hook(App $a, array &$item) { mailstream_check_version(); @@ -174,11 +176,13 @@ function mailstream_post_hook(App $a, &$item) $message_id = mailstream_generate_id($item['uri']); - $send_hook_data = array('uid' => $item['uid'], - 'contact-id' => $item['contact-id'], - 'uri' => $item['uri'], - 'message_id' => $message_id, - 'tries' => 0); + $send_hook_data = [ + 'uid' => $item['uid'], + 'contact-id' => $item['contact-id'], + 'uri' => $item['uri'], + 'message_id' => $message_id, + 'tries' => 0, + ]; Hook::fork(PRIORITY_LOW, 'mailstream_send_hook', $send_hook_data); } @@ -193,25 +197,30 @@ function mailstream_post_hook(App $a, &$item) * * @return array new value of the attachments table (results are also stored in the reference parameter) */ -function mailstream_do_images(&$item, &$attachments) +function mailstream_do_images(arrat &$item, array &$attachments) { if (!DI::pConfig()->get($item['uid'], 'mailstream', 'attachimg')) { return; } + $attachments = []; + preg_match_all("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", $item["body"], $matches1); preg_match_all("/\[img\](.*?)\[\/img\]/ism", $item["body"], $matches2); preg_match_all("/\[img\=([^\]]*)\]([^[]*)\[\/img\]/ism", $item["body"], $matches3); + foreach (array_merge($matches1[3], $matches2[1], $matches3[1]) as $url) { $components = parse_url($url); + if (!$components) { continue; } + $cookiejar = tempnam(System::getTempPath(), 'cookiejar-mailstream-'); $curlResult = DI::httpClient()->fetchFull($url, HttpClientAccept::DEFAULT, 0, $cookiejar); $attachments[$url] = [ 'data' => $curlResult->getBody(), - 'guid' => hash("crc32", $url), + 'guid' => hash('crc32', $url), 'filename' => basename($components['path']), 'type' => $curlResult->getContentType() ]; @@ -221,6 +230,7 @@ function mailstream_do_images(&$item, &$attachments) continue; } } + return $attachments; } @@ -231,7 +241,7 @@ function mailstream_do_images(&$item, &$attachments) * * @return string sender suitable for use in the email */ -function mailstream_sender($item) +function mailstream_sender(array $item): string { $contact = Contact::getById($item['contact-id']); if (DBA::isResult($contact)) { @@ -249,7 +259,7 @@ function mailstream_sender($item) * * @return string plaintext subject line */ -function mailstream_decode_subject($subject) +function mailstream_decode_subject(string $subject): string { $html = BBCode::convert($subject); if (!$html) { @@ -264,7 +274,7 @@ function mailstream_decode_subject($subject) return $notags; } $nocodes = preg_replace_callback("/(&#[0-9]+;)/", function ($m) { - return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); + return mb_convert_encoding($m[1], 'UTF-8', 'HTML-ENTITIES'); }, $noentity); if (!$nocodes) { return $noentity; @@ -283,7 +293,7 @@ function mailstream_decode_subject($subject) * * @return string subject line suitable for use in the email */ -function mailstream_subject($item) +function mailstream_subject(array $item): string { if ($item['title']) { return mailstream_decode_subject($item['title']); @@ -345,11 +355,11 @@ function mailstream_subject($item) * * @return bool True if this message has been completed. False if it should be retried. */ -function mailstream_send($message_id, $item, $user) +function mailstream_send(string $message_id, array $item, array $user): bool { if (!is_array($item)) { Logger::error('mailstream_send item is empty', ['message_id' => $message_id]); - return; + return false; } if (!$item['visible']) { @@ -361,19 +371,20 @@ function mailstream_send($message_id, $item, $user) 'user email' => $user['email']]); return true; } - require_once(dirname(__file__).'/phpmailer/class.phpmailer.php'); + + require_once (dirname(__file__) . '/phpmailer/class.phpmailer.php'); $attachments = []; mailstream_do_images($item, $attachments); $frommail = DI::config()->get('mailstream', 'frommail'); - if ($frommail == "") { + if ($frommail == '') { $frommail = 'friendica@localhost.local'; } $address = DI::pConfig()->get($item['uid'], 'mailstream', 'address'); if (!$address) { $address = $user['email']; } - $mail = new PHPmailer; + $mail = new PHPmailer(); try { $mail->XMailer = 'Friendica Mailstream Addon'; $mail->SetFrom($frommail, mailstream_sender($item)); @@ -428,7 +439,7 @@ function mailstream_send($message_id, $item, $user) * * @param string $text text to word wrap - modified in-place */ -function mailstream_html_wrap(&$text) +function mailstream_html_wrap(string &$text): string { $lines = str_split($text, 200); for ($i = 0; $i < count($lines); $i++) { @@ -514,6 +525,7 @@ function mailstream_addon_settings(App &$a, array &$data) * Process data submitted to user's mailstream features form * @param App $a * @param array $post POST data + * @return void */ function mailstream_addon_settings_post(App $a, array $post) { diff --git a/mathjax/mathjax.php b/mathjax/mathjax.php index db47512b..7c3d9582 100644 --- a/mathjax/mathjax.php +++ b/mathjax/mathjax.php @@ -50,7 +50,7 @@ function mathjax_settings(App $a, array &$data) ]; } -function mathjax_footer(App $a, string &$b) +function mathjax_footer(App $a, string &$body) { // if the visitor of the page is not a local_user, use MathJax // otherwise check the users settings. diff --git a/newmemberwidget/newmemberwidget.php b/newmemberwidget/newmemberwidget.php index 31fc3ef2..10968935 100644 --- a/newmemberwidget/newmemberwidget.php +++ b/newmemberwidget/newmemberwidget.php @@ -48,24 +48,21 @@ function newmemberwidget_network_mod_init (App $a, $b) function newmemberwidget_addon_admin_post(App $a) { - $ft = (!empty($_POST['freetext']) ? trim($_POST['freetext']) : ""); - $lsn = trim($_POST['localsupportname'] ?? ''); - $gs = intval($_POST['linkglobalsupport']); - $ls = intval($_POST['linklocalsupport']); - DI::config()->set('newmemberwidget', 'freetext', trim($ft)); - DI::config()->set('newmemberwidget', 'linkglobalsupport', $gs); - DI::config()->set('newmemberwidget', 'linklocalsupport', $ls); - DI::config()->set('newmemberwidget', 'localsupport', trim($lsn)); + DI::config()->set('newmemberwidget', 'freetext', (!empty($_POST['freetext']) ? trim($_POST['freetext']) : "")); + DI::config()->set('newmemberwidget', 'linkglobalsupport', intval($_POST['linkglobalsupport'])); + DI::config()->set('newmemberwidget', 'linklocalsupport', intval($_POST['linklocalsupport'])); + DI::config()->set('newmemberwidget', 'localsupport', trim($_POST['localsupportname'] ?? '')); } -function newmemberwidget_addon_admin(App $a, &$o) +function newmemberwidget_addon_admin(App $a, string &$o) { $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/newmemberwidget'); + $o = Renderer::replaceMacros($t, [ - '$submit' => DI::l10n()->t('Save Settings'), - '$freetext' => [ "freetext", DI::l10n()->t("Message"), DI::config()->get("newmemberwidget", "freetext"), DI::l10n()->t("Your message for new members. You can use bbcode here.")], - '$linkglobalsupport' => [ "linkglobalsupport", DI::l10n()->t('Add a link to global support forum'), DI::config()->get('newmemberwidget', 'linkglobalsupport'), DI::l10n()->t('Should a link to the global support forum be displayed?')." (@helpers)"], - '$linklocalsupport' => [ "linklocalsupport", DI::l10n()->t('Add a link to the local support forum'), DI::config()->get('newmemberwidget', 'linklocalsupport'), DI::l10n()->t('If you have a local support forum and want to have a link displayed in the widget, check this box.')], - '$localsupportname' => [ "localsupportname", DI::l10n()->t('Name of the local support group'), DI::config()->get('newmemberwidget', 'localsupport'), DI::l10n()->t('If you checked the above, specify the nickname of the local support group here (i.e. helpers)')], + '$submit' => DI::l10n()->t('Save Settings'), + '$freetext' => ["freetext", DI::l10n()->t("Message"), DI::config()->get("newmemberwidget", "freetext"), DI::l10n()->t("Your message for new members. You can use bbcode here.")], + '$linkglobalsupport' => ["linkglobalsupport", DI::l10n()->t('Add a link to global support forum'), DI::config()->get('newmemberwidget', 'linkglobalsupport'), DI::l10n()->t('Should a link to the global support forum be displayed?')." (@helpers)"], + '$linklocalsupport' => ["linklocalsupport", DI::l10n()->t('Add a link to the local support forum'), DI::config()->get('newmemberwidget', 'linklocalsupport'), DI::l10n()->t('If you have a local support forum and want to have a link displayed in the widget, check this box.')], + '$localsupportname' => ["localsupportname", DI::l10n()->t('Name of the local support group'), DI::config()->get('newmemberwidget', 'localsupport'), DI::l10n()->t('If you checked the above, specify the nickname of the local support group here (i.e. helpers)')], ]); } diff --git a/nitter/nitter.php b/nitter/nitter.php index 83ee93fa..013d8fd2 100644 --- a/nitter/nitter.php +++ b/nitter/nitter.php @@ -37,14 +37,13 @@ function nitter_install() */ function nitter_addon_admin_post(App $a) { - $nitterserver = rtrim(trim($_POST['nitterserver']),'/'); - DI::config()->set('nitter', 'server', $nitterserver); + DI::config()->set('nitter', 'server', rtrim(trim($_POST['nitterserver']), '/')); } /* Hook into the admin settings to let the admin choose a * nitter server to use for the replacement. */ -function nitter_addon_admin(App $a, &$o) +function nitter_addon_admin(App $a, string &$o) { $nitterserver = DI::config()->get('nitter', 'server'); $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/nitter/'); @@ -58,20 +57,20 @@ function nitter_addon_admin(App $a, &$o) /* * replace "twitter.com" with "nitter.net" */ -function nitter_render(App $a, &$o) +function nitter_render(App $a, array &$b) { // this needs to be a system setting $replaced = false; $nitter = DI::config()->get('nitter', 'server', 'https://nitter.net'); - if (strstr($o['html'], 'https://mobile.twitter.com')) { - $o['html'] = str_replace('https://mobile.twitter.com', $nitter, $o['html']); + if (strstr($b['html'], 'https://mobile.twitter.com')) { + $b['html'] = str_replace('https://mobile.twitter.com', $nitter, $b['html']); $replaced = true; } - if (strstr($o['html'], 'https://twitter.com')) { - $o['html'] = str_replace('https://twitter.com', $nitter, $o['html']); + if (strstr($b['html'], 'https://twitter.com')) { + $b['html'] = str_replace('https://twitter.com', $nitter, $b['html']); $replaced = true; } if ($replaced) { - $o['html'] .= '

' . DI::l10n()->t('In an attempt to protect your privacy, links to Twitter in this posting were replaced by links to the Nitter instance at %s', $nitter) . '

'; + $b['html'] .= '

' . DI::l10n()->t('In an attempt to protect your privacy, links to Twitter in this posting were replaced by links to the Nitter instance at %s', $nitter) . '

'; } } diff --git a/nominatim/nominatim.php b/nominatim/nominatim.php index cedb6b43..a660b2ec 100644 --- a/nominatim/nominatim.php +++ b/nominatim/nominatim.php @@ -18,7 +18,7 @@ function nominatim_install() Hook::register('post_remote', 'addon/nominatim/nominatim.php', 'nominatim_post_hook'); } -function nominatim_resolve_item(&$item) +function nominatim_resolve_item(array &$item) { if(empty($item['coord']) || !empty($item['location'])) { return; @@ -65,12 +65,12 @@ function nominatim_resolve_item(&$item) } } -function nominatim_post_hook(App $a, &$item) +function nominatim_post_hook(App $a, array &$item) { nominatim_resolve_item($item); } -function nominatim_addon_admin(App $a, &$o) +function nominatim_addon_admin(App $a, string &$o) { $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/nominatim/'); @@ -83,6 +83,5 @@ function nominatim_addon_admin(App $a, &$o) function nominatim_addon_admin_post(App $a) { - $language = !empty($_POST['language']) ? trim($_POST['language']) : ''; - DI::config()->set('nominatim', 'language', $language); + DI::config()->set('nominatim', 'language', (!empty($_POST['language']) ? trim($_POST['language']) : '')); } diff --git a/notifyall/notifyall.php b/notifyall/notifyall.php index 7c852dd8..ef8e6470 100644 --- a/notifyall/notifyall.php +++ b/notifyall/notifyall.php @@ -22,7 +22,7 @@ use Friendica\DI; */ function notifyall_module() {} -function notifyall_addon_admin(App $a, &$o) +function notifyall_addon_admin(App $a, string &$o) { $o = '
    ' . DI::l10n()->t('Send email to all members') . '
'; } diff --git a/openstreetmap/openstreetmap.php b/openstreetmap/openstreetmap.php index e4d226f3..9d35df91 100644 --- a/openstreetmap/openstreetmap.php +++ b/openstreetmap/openstreetmap.php @@ -79,7 +79,7 @@ function openstreetmap_location(App $a, &$item) $nomserver = OSM_NOM; } - if ($item['coord'] != "") { + if ($item['coord'] != '') { $coords = explode(' ', $item['coord']); if (count($coords) > 1) { $lat = urlencode(round($coords[0], 5)); @@ -96,13 +96,13 @@ function openstreetmap_location(App $a, &$item) $target = $nomserver.'?q='.urlencode($item['location']); } - if ($item['location'] != "") { + if ($item['location'] != '') { $title = $item['location']; } else { $title = $item['coord']; } - $item['html'] = ''.$title.''; + $item['html'] = '' . $title . ''; } function openstreetmap_get_coordinates(App $a, array &$b) @@ -116,7 +116,7 @@ function openstreetmap_get_coordinates(App $a, array &$b) $args = '?q=' . urlencode($b['location']) . '&format=json'; - $cachekey = "openstreetmap:" . $b['location']; + $cachekey = 'openstreetmap:' . $b['location']; $j = DI::cache()->get($cachekey); if (is_null($j)) { @@ -178,9 +178,9 @@ function openstreetmap_generate_map(App $a, array &$b) Logger::debug('generate_map: ' . $b['html']); } -function openstreetmap_addon_admin(App $a, &$o) +function openstreetmap_addon_admin(App $a, string &$o) { - $t = Renderer::getMarkupTemplate("admin.tpl", "addon/openstreetmap/"); + $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/openstreetmap/'); $tmsserver = DI::config()->get('openstreetmap', 'tmsserver', OSM_TMS); $nomserver = DI::config()->get('openstreetmap', 'nomserver', OSM_NOM); $zoom = DI::config()->get('openstreetmap', 'zoom', OSM_ZOOM); @@ -202,13 +202,8 @@ function openstreetmap_addon_admin(App $a, &$o) function openstreetmap_addon_admin_post(App $a) { - $urltms = ($_POST['tmsserver'] ?? '') ?: OSM_TMS; - $urlnom = ($_POST['nomserver'] ?? '') ?: OSM_NOM; - $zoom = ($_POST['zoom'] ?? '') ?: OSM_ZOOM; - $marker = ($_POST['marker'] ?? '') ?: OSM_MARKER; - - DI::config()->set('openstreetmap', 'tmsserver', $urltms); - DI::config()->set('openstreetmap', 'nomserver', $urlnom); - DI::config()->set('openstreetmap', 'zoom', $zoom); - DI::config()->set('openstreetmap', 'marker', $marker); + DI::config()->set('openstreetmap', 'tmsserver', ($_POST['tmsserver'] ?? '') ?: OSM_TMS); + DI::config()->set('openstreetmap', 'nomserver', ($_POST['nomserver'] ?? '') ?: OSM_NOM); + DI::config()->set('openstreetmap', 'zoom', ($_POST['zoom'] ?? '') ?: OSM_ZOOM); + DI::config()->set('openstreetmap', 'marker', ($_POST['marker'] ?? '') ?: OSM_MARKER); } diff --git a/pageheader/pageheader.php b/pageheader/pageheader.php index f1a7f0cd..0f369268 100644 --- a/pageheader/pageheader.php +++ b/pageheader/pageheader.php @@ -54,15 +54,15 @@ function pageheader_addon_admin_post(App $a) function pageheader_fetch(App $a, string &$b) { - if(file_exists('pageheader.html')){ + if (file_exists('pageheader.html')) { $s = file_get_contents('pageheader.html'); } else { $s = DI::config()->get('pageheader', 'text'); } DI::page()->registerStylesheet(__DIR__ .'/pageheader.css'); - - if ($s) { - $b .= ''; - } + + if ($s) { + $b .= ''; + } } diff --git a/piwik/piwik.php b/piwik/piwik.php index 78d737d1..9c0708c5 100644 --- a/piwik/piwik.php +++ b/piwik/piwik.php @@ -91,8 +91,10 @@ function piwik_analytics(App $a, array &$b) $b .= ""; } } -function piwik_addon_admin (App $a, &$o) { +function piwik_addon_admin (App $a, string &$o) +{ $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/piwik/" ); + $o = Renderer::replaceMacros( $t, [ '$submit' => DI::l10n()->t('Save Settings'), '$piwikbaseurl' => ['baseurl', DI::l10n()->t('Matomo (Piwik) Base URL'), DI::config()->get('piwik','baseurl' ), DI::l10n()->t('Absolute path to your Matomo (Piwik) installation. (without protocol (http/s), with trailing slash)')], @@ -101,13 +103,11 @@ function piwik_addon_admin (App $a, &$o) { '$async' => ['async', DI::l10n()->t('Asynchronous tracking'), DI::config()->get('piwik','async' ), ''], ]); } -function piwik_addon_admin_post (App $a) { - $url = trim($_POST['baseurl'] ?? ''); - $id = trim($_POST['siteid'] ?? ''); - $optout = trim($_POST['optout'] ?? ''); - $async = trim($_POST['async'] ?? ''); - DI::config()->set('piwik', 'baseurl', $url); - DI::config()->set('piwik', 'siteid', $id); - DI::config()->set('piwik', 'optout', $optout); - DI::config()->set('piwik', 'async', $async); + +function piwik_addon_admin_post(App $a) +{ + DI::config()->set('piwik', 'baseurl', trim($_POST['baseurl'] ?? '')); + DI::config()->set('piwik', 'siteid', trim($_POST['siteid'] ?? '')); + DI::config()->set('piwik', 'optout', trim($_POST['optout'] ?? '')); + DI::config()->set('piwik', 'async', trim($_POST['async'] ?? '')); } diff --git a/public_server/public_server.php b/public_server/public_server.php index 7221e1b1..b388f00b 100644 --- a/public_server/public_server.php +++ b/public_server/public_server.php @@ -125,29 +125,24 @@ function public_server_login(App $a, $b) function public_server_addon_admin_post(App $a) { BaseModule::checkFormSecurityTokenRedirectOnError('/admin/addons/publicserver', 'publicserver'); - $expiredays = trim($_POST['expiredays'] ?? ''); - $expireposts = trim($_POST['expireposts'] ?? ''); - $nologin = trim($_POST['nologin'] ?? ''); - $flagusers = trim($_POST['flagusers'] ?? ''); - $flagposts = trim($_POST['flagposts'] ?? ''); - $flagpostsexpire = trim($_POST['flagpostsexpire'] ?? ''); - DI::config()->set('public_server', 'expiredays', $expiredays); - DI::config()->set('public_server', 'expireposts', $expireposts); - DI::config()->set('public_server', 'nologin', $nologin); - DI::config()->set('public_server', 'flagusers', $flagusers); - DI::config()->set('public_server', 'flagposts', $flagposts); - DI::config()->set('public_server', 'flagpostsexpire', $flagpostsexpire); + + DI::config()->set('public_server', 'expiredays', trim($_POST['expiredays'] ?? '')); + DI::config()->set('public_server', 'expireposts', trim($_POST['expireposts'] ?? '')); + DI::config()->set('public_server', 'nologin', trim($_POST['nologin'] ?? '')); + DI::config()->set('public_server', 'flagusers', trim($_POST['flagusers'] ?? '')); + DI::config()->set('public_server', 'flagposts', trim($_POST['flagposts'] ?? '')); + DI::config()->set('public_server', 'flagpostsexpire', trim($_POST['flagpostsexpire'] ?? '')); } -function public_server_addon_admin(App $a, &$o) +function public_server_addon_admin(App $a, string &$o) { - $token = BaseModule::getFormSecurityToken("publicserver"); - $t = Renderer::getMarkupTemplate("admin.tpl", "addon/public_server"); + $token = BaseModule::getFormSecurityToken('publicserver'); + $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/public_server'); $o = Renderer::replaceMacros($t, [ '$submit' => DI::l10n()->t('Save Settings'), '$form_security_token' => $token, '$infotext' => DI::l10n()->t('Set any of these options to 0 to deactivate it.'), - '$expiredays' => ["expiredays","Expire Days", intval(DI::config()->get('public_server', 'expiredays')), "When an account is created on the site, it is given a hard "], + '$expiredays' => ["expiredays", "Expire Days", intval(DI::config()->get('public_server', 'expiredays')), "When an account is created on the site, it is given a hard "], '$expireposts' => ["expireposts", "Expire Posts", intval(DI::config()->get('public_server', 'expireposts')), "Set the default days for posts to expire here"], '$nologin' => ["nologin", "No Login", intval(DI::config()->get('public_server', 'nologin')), "Remove users who have never logged in after nologin days "], '$flagusers' => ["flagusers", "Flag users", intval(DI::config()->get('public_server', 'flagusers')), "Remove users who last logged in over flagusers days ago"], diff --git a/qcomment/qcomment.php b/qcomment/qcomment.php index 1bde48aa..ab81026e 100644 --- a/qcomment/qcomment.php +++ b/qcomment/qcomment.php @@ -31,7 +31,7 @@ function qcomment_install() Hook::register('footer' , __FILE__, 'qcomment_footer'); } -function qcomment_footer(App $a, string &$b) +function qcomment_footer(App $a, string &$body) { DI::page()->registerFooterScript('addon/qcomment/qcomment.js'); } @@ -57,7 +57,7 @@ function qcomment_addon_settings(App &$a, array &$data) ]; } -function qcomment_addon_settings_post(App $a, array &$b) +function qcomment_addon_settings_post(App $a, array &$body) { if (!local_user()) { return; diff --git a/rendertime/rendertime.php b/rendertime/rendertime.php index 8e4e6c21..3e613d04 100644 --- a/rendertime/rendertime.php +++ b/rendertime/rendertime.php @@ -26,7 +26,7 @@ function rendertime_init_1(App $a) { } -function rendertime_addon_admin(App $a, &$o) +function rendertime_addon_admin(App $a, string &$o) { $t = Renderer::getMarkupTemplate("admin.tpl", "addon/rendertime/"); @@ -47,9 +47,8 @@ function rendertime_addon_admin_post(App $a) * @param App $a * @param string $o */ -function rendertime_page_end(App $a, &$o) +function rendertime_page_end(App $a, string &$o) { - $profiler = DI::profiler(); $duration = microtime(true) - $profiler->get('start'); diff --git a/saml/saml.php b/saml/saml.php index db74ce40..d511d90e 100755 --- a/saml/saml.php +++ b/saml/saml.php @@ -26,7 +26,7 @@ function saml_module($a) { } -function saml_init($a) +function saml_init(App $a) { if (DI::args()->getArgc() < 2) { return; @@ -80,15 +80,15 @@ function saml_install() Hook::register('footer', __FILE__, 'saml_footer'); } -function saml_head(App $a, string &$b) +function saml_head(App $a, string &$body) { DI::page()->registerStylesheet(__DIR__ . '/saml.css'); } -function saml_footer(App $a, string &$b) +function saml_footer(App $a, string &$body) { $fragment = addslashes(BBCode::convert(DI::config()->get('saml', 'settings_statement'))); - $b .= << var target=$("#settings-nickname-desc"); if (target.length) { target.append("

$fragment

"); } @@ -125,7 +125,7 @@ function saml_sso_initiate(App $a, array &$b) exit(); } -function saml_sso_reply($a) +function saml_sso_reply(App $a) { $auth = new \OneLogin\Saml2\Auth(saml_settings()); $requestID = null; @@ -225,7 +225,7 @@ function saml_input($key, $label, $description) ]; } -function saml_addon_admin(App $a, &$o) +function saml_addon_admin(App $a, string &$o) { $form = saml_input( diff --git a/showmore_dyn/showmore_dyn.php b/showmore_dyn/showmore_dyn.php index 517e65e2..a6f41411 100644 --- a/showmore_dyn/showmore_dyn.php +++ b/showmore_dyn/showmore_dyn.php @@ -24,12 +24,12 @@ function showmore_dyn_install() Hook::register('addon_settings_post', __FILE__, 'showmore_dyn_settings_post'); } -function showmore_dyn_head(App $a, string &$b) +function showmore_dyn_head(App $a, string &$body) { DI::page()->registerStylesheet(__DIR__ . '/showmore_dyn.css'); } -function showmore_dyn_footer(App $a, string &$b) +function showmore_dyn_footer(App $a, string &$body) { DI::page()->registerFooterScript(__DIR__ . '/showmore_dyn.js'); } diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index a6b5fec8..6bcf22b0 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -628,7 +628,7 @@ function statusnet_addon_admin_post(App $a) $sites = DI::config()->set('statusnet', 'sites', $sites); } -function statusnet_addon_admin(App $a, &$o) +function statusnet_addon_admin(App $a, string &$o) { $sites = DI::config()->get('statusnet', 'sites'); $sitesform = []; diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php index 74f24099..de980598 100644 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -64,7 +64,7 @@ function tumblr_content(App $a) return $o; } -function tumblr_addon_admin(App $a, &$o) +function tumblr_addon_admin(App $a, string &$o) { $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/tumblr/" ); @@ -78,11 +78,8 @@ function tumblr_addon_admin(App $a, &$o) function tumblr_addon_admin_post(App $a) { - $consumer_key = trim($_POST['consumer_key'] ?? ''); - $consumer_secret = trim($_POST['consumer_secret'] ?? ''); - - DI::config()->set('tumblr', 'consumer_key',$consumer_key); - DI::config()->set('tumblr', 'consumer_secret',$consumer_secret); + DI::config()->set('tumblr', 'consumer_key', trim($_POST['consumer_key'] ?? '')); + DI::config()->set('tumblr', 'consumer_secret', trim($_POST['consumer_secret'] ?? '')); } function tumblr_connect(App $a) @@ -99,7 +96,7 @@ function tumblr_connect(App $a) // The callback URL is the script that gets called after the user authenticates with tumblr // In this example, it would be the included callback.php - $callback_url = DI::baseUrl()->get()."/tumblr/callback"; + $callback_url = DI::baseUrl()->get() . '/tumblr/callback'; // Let's begin. First we need a Request Token. The request token is required to send the user // to Tumblr's login page. @@ -174,8 +171,8 @@ function tumblr_callback(App $a) } // What's next? Now that we have an Access Token and Secret, we can make an API call. - DI::pConfig()->set(local_user(), "tumblr", "oauth_token", $access_token['oauth_token']); - DI::pConfig()->set(local_user(), "tumblr", "oauth_token_secret", $access_token['oauth_token_secret']); + DI::pConfig()->set(local_user(), 'tumblr', 'oauth_token', $access_token['oauth_token']); + DI::pConfig()->set(local_user(), 'tumblr', 'oauth_token_secret', $access_token['oauth_token_secret']); $o = DI::l10n()->t("You are now authenticated to tumblr."); $o .= '
' . DI::l10n()->t("return to the connector page") . ''; diff --git a/twitter/twitter.php b/twitter/twitter.php index 3ed2a030..5e3a4b9c 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -903,13 +903,11 @@ function twitter_delete_item(array $item) function twitter_addon_admin_post(App $a) { - $consumerkey = trim($_POST['consumerkey'] ?? ''); - $consumersecret = trim($_POST['consumersecret'] ?? ''); - DI::config()->set('twitter', 'consumerkey', $consumerkey); - DI::config()->set('twitter', 'consumersecret', $consumersecret); + DI::config()->set('twitter', 'consumerkey', trim($_POST['consumerkey'] ?? '')); + DI::config()->set('twitter', 'consumersecret', trim($_POST['consumersecret'] ?? '')); } -function twitter_addon_admin(App $a, &$o) +function twitter_addon_admin(App $a, string &$o) { $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/twitter/'); diff --git a/viewsrc/viewsrc.php b/viewsrc/viewsrc.php index 48029835..84617744 100644 --- a/viewsrc/viewsrc.php +++ b/viewsrc/viewsrc.php @@ -11,12 +11,14 @@ use Friendica\App; use Friendica\Core\Hook; use Friendica\DI; -function viewsrc_install() { +function viewsrc_install() +{ Hook::register('item_photo_menu', 'addon/viewsrc/viewsrc.php', 'viewsrc_item_photo_menu'); Hook::register('page_end', 'addon/viewsrc/viewsrc.php', 'viewsrc_page_end'); } -function viewsrc_page_end(App $a, &$o){ +function viewsrc_page_end(App $a, string &$o) +{ DI::page()['htmlhead'] .= <<< EOS