[pumpio] Fixes/imports: (#661)

* [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] Fixes:
- x() is deprecated, let's use !empty() instead
- added spaces for better readability

* [pumpio] Fixes:
- added missing App "imports" (thanks to MrPetovan)
- added type-hint array for $b
- added some spaces
This commit is contained in:
Roland Häder 2018-07-22 18:01:05 +02:00 committed by Hypolite Petovan
parent c7764068cc
commit a9da9db7eb

View file

@ -6,6 +6,7 @@
* Author: Michael Vogel <http://pirati.ca/profile/heluecht>
*/
use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Addon;
@ -59,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);
@ -92,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";
@ -135,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();
@ -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" ' : '');
@ -226,7 +228,7 @@ function pumpio_jot_nets(&$a, &$b)
}
}
function pumpio_settings(&$a, &$s)
function pumpio_settings(App $a, &$s)
{
if (!local_user()) {
return;
@ -326,28 +328,29 @@ function pumpio_settings(&$a, &$s)
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="pumpio-submit" name="pumpio-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
}
function pumpio_settings_post(&$a, &$b)
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'];
if (strstr($user, "@")) {
$pos = strpos($user, "@");
if ($pos > 0) {
$user = substr($user, 0, $pos);
}
@ -358,13 +361,13 @@ function pumpio_settings_post(&$a, &$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');
@ -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;
@ -388,7 +391,7 @@ function pumpio_post_local(&$a, &$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;
@ -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);
@ -584,7 +585,7 @@ function pumpio_send(&$a, &$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')) {
@ -660,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'");
@ -730,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');
@ -865,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
@ -905,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');
@ -1075,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];
@ -1092,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');
@ -1285,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");
@ -1347,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");
@ -1376,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;
}
@ -1385,24 +1386,25 @@ 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);
}
}
}
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;
}
@ -1426,10 +1428,10 @@ function pumpio_queue_hook(&$a, &$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");
@ -1481,7 +1483,7 @@ function pumpio_queue_hook(&$a, &$b)
}
}
function pumpio_getreceiver(&$a, $b)
function pumpio_getreceiver(App $a, array $b)
{
$receiver = [];
@ -1566,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");