From 42165b6aebb71b477c8534910b70601cf96f3a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Sun, 22 Jul 2018 15:08:43 +0200 Subject: [PATCH 1/3] [pumpio] Fixes/imports: - added curly braces and spaces for better readability - merged 2 `if()` blocks into one for lesser nested code blocks - added type-hint `App` and `array` where applyable - better "import" (`use` under PHP) classes and not reference them directly, reducing and improving readability --- pumpio/pumpio.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 191f8505..5030c642 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -6,6 +6,7 @@ * Author: Michael Vogel */ +use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; use Friendica\Core\Addon; @@ -211,13 +212,14 @@ function pumpio_connect(&$a) return $o; } -function pumpio_jot_nets(&$a, &$b) +function pumpio_jot_nets(App $a, &$b) { - if (!local_user()) { + if (! local_user()) { return; } $pumpio_post = PConfig::get(local_user(), 'pumpio', 'post'); + if (intval($pumpio_post) == 1) { $pumpio_defpost = PConfig::get(local_user(), 'pumpio', 'post_by_default'); $selected = ((intval($pumpio_defpost) == 1) ? ' checked="checked" ' : ''); @@ -326,10 +328,10 @@ function pumpio_settings(&$a, &$s) $s .= '
'; } -function pumpio_settings_post(&$a, &$b) +function pumpio_settings_post(App $a, array &$b) { - if (x($_POST, 'pumpio-submit')) { - if (x($_POST, 'pumpio_delete')) { + if (x($_POST,'pumpio-submit')) { + if (x($_POST,'pumpio_delete')) { PConfig::set(local_user(), 'pumpio', 'consumer_key', ''); PConfig::set(local_user(), 'pumpio', 'consumer_secret', ''); PConfig::set(local_user(), 'pumpio', 'oauth_token', ''); @@ -348,6 +350,7 @@ function pumpio_settings_post(&$a, &$b) $user = $_POST['pumpio_user']; if (strstr($user, "@")) { $pos = strpos($user, "@"); + if ($pos > 0) { $user = substr($user, 0, $pos); } @@ -375,12 +378,12 @@ function pumpio_settings_post(&$a, &$b) } } -function pumpio_load_config(\Friendica\App $a) +function pumpio_load_config(App $a) { $a->loadConfigFile(__DIR__. '/config/pumpio.ini.php'); } -function pumpio_post_local(&$a, &$b) +function pumpio_post_local(App $a, array &$b) { if (!local_user() || (local_user() != $b['uid'])) { return; @@ -405,12 +408,10 @@ function pumpio_post_local(&$a, &$b) $b['postopts'] .= 'pumpio'; } -function pumpio_send(&$a, &$b) +function pumpio_send(App $a, array &$b) { - if (!PConfig::get($b["uid"], 'pumpio', 'import')) { - if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) { - return; - } + if (!PConfig::get($b["uid"], 'pumpio', 'import') && ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))) { + return; } logger("pumpio_send: parameter ".print_r($b, true), LOGGER_DATA); @@ -1398,11 +1399,12 @@ function pumpio_getallusers(&$a, $uid) } } -function pumpio_queue_hook(&$a, &$b) +function pumpio_queue_hook(App $a, array &$b) { $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'", dbesc(NETWORK_PUMPIO) ); + if (!DBM::is_result($qi)) { return; } -- 2.43.5 From 651226859ecc2223aa624b4464a6f02b3f8df3c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Sun, 22 Jul 2018 16:22:22 +0200 Subject: [PATCH 2/3] [pumpio] Fixes: - x() is deprecated, let's use !empty() instead - added spaces for better readability --- pumpio/pumpio.php | 78 +++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 5030c642..288c7bd3 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -330,21 +330,21 @@ function pumpio_settings(&$a, &$s) function pumpio_settings_post(App $a, array &$b) { - if (x($_POST,'pumpio-submit')) { - if (x($_POST,'pumpio_delete')) { - PConfig::set(local_user(), 'pumpio', 'consumer_key', ''); - PConfig::set(local_user(), 'pumpio', 'consumer_secret', ''); - PConfig::set(local_user(), 'pumpio', 'oauth_token', ''); + if (!empty($_POST['pumpio-submit'])) { + if (!empty($_POST['pumpio_delete'])) { + PConfig::set(local_user(), 'pumpio', 'consumer_key' , ''); + PConfig::set(local_user(), 'pumpio', 'consumer_secret' , ''); + PConfig::set(local_user(), 'pumpio', 'oauth_token' , ''); PConfig::set(local_user(), 'pumpio', 'oauth_token_secret', ''); - PConfig::set(local_user(), 'pumpio', 'post', false); - PConfig::set(local_user(), 'pumpio', 'import', false); - PConfig::set(local_user(), 'pumpio', 'host', ''); - PConfig::set(local_user(), 'pumpio', 'user', ''); - PConfig::set(local_user(), 'pumpio', 'public', false); - PConfig::set(local_user(), 'pumpio', 'mirror', false); - PConfig::set(local_user(), 'pumpio', 'post_by_default', false); - PConfig::set(local_user(), 'pumpio', 'lastdate', 0); - PConfig::set(local_user(), 'pumpio', 'last_id', ''); + PConfig::set(local_user(), 'pumpio', 'post' , false); + PConfig::set(local_user(), 'pumpio', 'import' , false); + PConfig::set(local_user(), 'pumpio', 'host' , ''); + PConfig::set(local_user(), 'pumpio', 'user' , ''); + PConfig::set(local_user(), 'pumpio', 'public' , false); + PConfig::set(local_user(), 'pumpio', 'mirror' , false); + PConfig::set(local_user(), 'pumpio', 'post_by_default' , false); + PConfig::set(local_user(), 'pumpio', 'lastdate' , 0); + PConfig::set(local_user(), 'pumpio', 'last_id' , ''); } else { // filtering the username if it is filled wrong $user = $_POST['pumpio_user']; @@ -361,13 +361,13 @@ function pumpio_settings_post(App $a, array &$b) $host = trim($host); $host = str_replace(["https://", "http://"], ["", ""], $host); - PConfig::set(local_user(), 'pumpio', 'post',intval($_POST['pumpio'])); - PConfig::set(local_user(), 'pumpio', 'import', $_POST['pumpio_import']); - PConfig::set(local_user(), 'pumpio', 'host', $host); - PConfig::set(local_user(), 'pumpio', 'user', $user); - PConfig::set(local_user(), 'pumpio', 'public', $_POST['pumpio_public']); - PConfig::set(local_user(), 'pumpio', 'mirror', $_POST['pumpio_mirror']); - PConfig::set(local_user(), 'pumpio', 'post_by_default',intval($_POST['pumpio_bydefault'])); + PConfig::set(local_user(), 'pumpio', 'post' , intval($_POST['pumpio'])); + PConfig::set(local_user(), 'pumpio', 'import' , $_POST['pumpio_import']); + PConfig::set(local_user(), 'pumpio', 'host' , $host); + PConfig::set(local_user(), 'pumpio', 'user' , $user); + PConfig::set(local_user(), 'pumpio', 'public' , $_POST['pumpio_public']); + PConfig::set(local_user(), 'pumpio', 'mirror' , $_POST['pumpio_mirror']); + PConfig::set(local_user(), 'pumpio', 'post_by_default', intval($_POST['pumpio_bydefault'])); if (!$_POST['pumpio_mirror']) { PConfig::delete(local_user(), 'pumpio', 'lastdate'); @@ -391,7 +391,7 @@ function pumpio_post_local(App $a, array &$b) $pumpio_post = intval(PConfig::get(local_user(), 'pumpio', 'post')); - $pumpio_enable = (($pumpio_post && x($_REQUEST, 'pumpio_enable')) ? intval($_REQUEST['pumpio_enable']) : 0); + $pumpio_enable = (($pumpio_post && !empty($_REQUEST['pumpio_enable'])) ? intval($_REQUEST['pumpio_enable']) : 0); if ($b['api_source'] && intval(PConfig::get(local_user(), 'pumpio', 'post_by_default'))) { $pumpio_enable = 1; @@ -1286,12 +1286,12 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet return $top_item; } -function pumpio_fetchinbox(&$a, $uid) +function pumpio_fetchinbox(App $a, $uid) { - $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); - $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); - $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); - $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); + $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); + $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); + $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); + $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); $lastdate = PConfig::get($uid, 'pumpio', 'lastdate'); $hostname = PConfig::get($uid, 'pumpio', 'host'); $username = PConfig::get($uid, "pumpio", "user"); @@ -1348,19 +1348,19 @@ function pumpio_fetchinbox(&$a, $uid) } } - foreach ($lastitems AS $item) { + foreach ($lastitems as $item) { pumpio_fetchallcomments($a, $uid, $item["uri"]); } PConfig::set($uid, 'pumpio', 'last_id', $last_id); } -function pumpio_getallusers(&$a, $uid) +function pumpio_getallusers(App &$a, $uid) { - $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); - $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); - $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); - $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); + $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); + $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); + $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); + $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); $hostname = PConfig::get($uid, 'pumpio', 'host'); $username = PConfig::get($uid, "pumpio", "user"); @@ -1377,7 +1377,7 @@ function pumpio_getallusers(&$a, $uid) $url = 'https://'.$hostname.'/api/user/'.$username.'/following'; if (pumpio_reachable($url)) { - $success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError'=>true], $users); + $success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError' => true], $users); } else { $success = false; } @@ -1386,14 +1386,14 @@ function pumpio_getallusers(&$a, $uid) $url = 'https://'.$hostname.'/api/user/'.$username.'/following?count='.$users->totalItems; if (pumpio_reachable($url)) { - $success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError'=>true], $users); + $success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError' => true], $users); } else { $success = false; } } if (is_array($users->items)) { - foreach ($users->items AS $user) { + foreach ($users->items as $user) { pumpio_get_contact($uid, $user); } } @@ -1428,10 +1428,10 @@ function pumpio_queue_hook(App $a, array &$b) //logger('pumpio_queue: fetching userdata '.print_r($userdata, true)); - $oauth_token = PConfig::get($userdata['uid'], "pumpio", "oauth_token"); + $oauth_token = PConfig::get($userdata['uid'], "pumpio", "oauth_token"); $oauth_token_secret = PConfig::get($userdata['uid'], "pumpio", "oauth_token_secret"); - $consumer_key = PConfig::get($userdata['uid'], "pumpio","consumer_key"); - $consumer_secret = PConfig::get($userdata['uid'], "pumpio","consumer_secret"); + $consumer_key = PConfig::get($userdata['uid'], "pumpio", "consumer_key"); + $consumer_secret = PConfig::get($userdata['uid'], "pumpio", "consumer_secret"); $host = PConfig::get($userdata['uid'], "pumpio", "host"); $user = PConfig::get($userdata['uid'], "pumpio", "user"); -- 2.43.5 From 994a6610ad951bfac862d3d6e31d9ee105bc2eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Sun, 22 Jul 2018 17:31:39 +0200 Subject: [PATCH 3/3] [pumpio] Fixes: - added missing App "imports" (thanks to @MrPetovan) - added type-hint array for $b - added some spaces --- pumpio/pumpio.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 288c7bd3..b3442ed7 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -60,7 +60,7 @@ function pumpio_uninstall() function pumpio_module() {} -function pumpio_content(&$a) +function pumpio_content(App $a) { if (!local_user()) { notice(L10n::t('Permission denied.') . EOL); @@ -93,7 +93,7 @@ function pumpio_check_item_notification($a, &$notification_data) $notification_data["profiles"][] = "https://".$hostname."/".$username; } -function pumpio_registerclient(&$a, $host) +function pumpio_registerclient(App $a, $host) { $url = "https://".$host."/api/client/register"; @@ -136,7 +136,7 @@ function pumpio_registerclient(&$a, $host) } -function pumpio_connect(&$a) +function pumpio_connect(App $a) { // Start a session. This is necessary to hold on to a few keys the callback script will also need session_start(); @@ -228,7 +228,7 @@ function pumpio_jot_nets(App $a, &$b) } } -function pumpio_settings(&$a, &$s) +function pumpio_settings(App $a, &$s) { if (!local_user()) { return; @@ -585,7 +585,7 @@ function pumpio_send(App $a, array &$b) } } -function pumpio_action(&$a, $uid, $uri, $action, $content = "") +function pumpio_action(App $a, $uid, $uri, $action, $content = "") { // Don't do likes and other stuff if you don't import the timeline if (!PConfig::get($uid, 'pumpio', 'import')) { @@ -661,7 +661,7 @@ function pumpio_action(&$a, $uid, $uri, $action, $content = "") } } -function pumpio_sync(&$a) +function pumpio_sync(App $a) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = 'pumpio'"); @@ -731,12 +731,12 @@ function pumpio_sync(&$a) Config::set('pumpio', 'last_poll', time()); } -function pumpio_cron(&$a, $b) +function pumpio_cron(App $a, $b) { Worker::add(PRIORITY_MEDIUM,"addon/pumpio/pumpio_sync.php"); } -function pumpio_fetchtimeline(&$a, $uid) +function pumpio_fetchtimeline(App $a, $uid) { $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); @@ -866,7 +866,7 @@ function pumpio_fetchtimeline(&$a, $uid) } } -function pumpio_dounlike(&$a, $uid, $self, $post, $own_id) +function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) { // Searching for the unliked post // Two queries for speed issues @@ -906,7 +906,7 @@ function pumpio_dounlike(&$a, $uid, $self, $post, $own_id) } } -function pumpio_dolike(&$a, $uid, $self, $post, $own_id, $threadcompletion = true) +function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = true) { require_once('include/items.php'); @@ -1076,7 +1076,7 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) return $contact_id; } -function pumpio_dodelete(&$a, $uid, $self, $post, $own_id) +function pumpio_dodelete(App $a, $uid, $self, $post, $own_id) { // Two queries for speed issues $condition = ['uri' => $post->object->id, 'uid' => $uid]; @@ -1093,7 +1093,7 @@ function pumpio_dodelete(&$a, $uid, $self, $post, $own_id) return false; } -function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcompletion = true) +function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcompletion = true) { require_once('include/items.php'); @@ -1483,7 +1483,7 @@ function pumpio_queue_hook(App $a, array &$b) } } -function pumpio_getreceiver(&$a, $b) +function pumpio_getreceiver(App $a, array $b) { $receiver = []; @@ -1568,12 +1568,12 @@ function pumpio_getreceiver(&$a, $b) return $receiver; } -function pumpio_fetchallcomments(&$a, $uid, $id) +function pumpio_fetchallcomments(App $a, $uid, $id) { - $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); - $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); - $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); - $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); + $ckey = PConfig::get($uid, 'pumpio', 'consumer_key'); + $csecret = PConfig::get($uid, 'pumpio', 'consumer_secret'); + $otoken = PConfig::get($uid, 'pumpio', 'oauth_token'); + $osecret = PConfig::get($uid, 'pumpio', 'oauth_token_secret'); $hostname = PConfig::get($uid, 'pumpio', 'host'); $username = PConfig::get($uid, "pumpio", "user"); -- 2.43.5