]> git.mxchange.org Git - friendica-addons.git/blobdiff - pumpio/pumpio.php
buffer addon added CA translation THX obiolscat
[friendica-addons.git] / pumpio / pumpio.php
index e289256821084ff016bffced681553d58d154387..8731e251390616a023aa38faf45f9044a710962c 100644 (file)
@@ -18,11 +18,10 @@ use Friendica\Core\Protocol;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
-use Friendica\Model\GContact;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
-use Friendica\Model\Queue;
 use Friendica\Model\User;
+use Friendica\Util\ConfigFileLoader;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
@@ -30,7 +29,6 @@ use Friendica\Util\XML;
 
 require 'addon/pumpio/oauth/http.php';
 require 'addon/pumpio/oauth/oauth_client.php';
-require_once 'include/enotify.php';
 require_once "mod/share.php";
 
 define('PUMPIO_DEFAULT_POLL_INTERVAL', 5); // given in minutes
@@ -45,7 +43,6 @@ function pumpio_install()
        Hook::register('connector_settings',      'addon/pumpio/pumpio.php', 'pumpio_settings');
        Hook::register('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post');
        Hook::register('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron');
-       Hook::register('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook');
        Hook::register('check_item_notification', 'addon/pumpio/pumpio.php', 'pumpio_check_item_notification');
 }
 
@@ -59,7 +56,6 @@ function pumpio_uninstall()
        Hook::unregister('connector_settings',      'addon/pumpio/pumpio.php', 'pumpio_settings');
        Hook::unregister('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post');
        Hook::unregister('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron');
-       Hook::unregister('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook');
        Hook::unregister('check_item_notification', 'addon/pumpio/pumpio.php', 'pumpio_check_item_notification');
 }
 
@@ -214,19 +210,21 @@ function pumpio_connect(App $a)
        return $o;
 }
 
-function pumpio_jot_nets(App $a, &$b)
+function pumpio_jot_nets(App $a, array &$jotnets_fields)
 {
        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" ' : '');
-               $b .= '<div class="profile-jot-net"><input type="checkbox" name="pumpio_enable"' . $selected . ' value="1" /> '
-                       . L10n::t('Post to pumpio') . '</div>';
+       if (PConfig::get(local_user(), 'pumpio', 'post')) {
+               $jotnets_fields[] = [
+                       'type' => 'checkbox',
+                       'field' => [
+                               'pumpio_enable',
+                               L10n::t('Post to pumpio'),
+                               PConfig::get(local_user(), 'pumpio', 'post_by_default')
+                       ]
+               ];
        }
 }
 
@@ -378,9 +376,9 @@ function pumpio_settings_post(App $a, array &$b)
        }
 }
 
-function pumpio_load_config(App $a, Config\ConfigCacheLoader $loader)
+function pumpio_load_config(App $a, ConfigFileLoader $loader)
 {
-       $a->getConfig()->loadConfigArray($loader->loadAddonConfig('pumpio'));
+       $a->getConfigCache()->load($loader->loadAddonConfig('pumpio'));
 }
 
 function pumpio_hook_fork(App $a, array &$b)
@@ -607,16 +605,7 @@ function pumpio_send(App $a, array &$b)
                        }
                } else {
                        Logger::log('pumpio_send '.$username.': '.$url.' general error: ' . print_r($user, true));
-
-                       $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $b['uid']);
-                       if (DBA::isResult($r)) {
-                               $a->contact = $r[0]["id"];
-                       }
-
-                       $s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $params]);
-
-                       Queue::add($a->contact, Protocol::PUMPIO, $s);
-                       notice(L10n::t('Pump.io post failed. Queued for retry.').EOL);
+                       Worker::defer();
                }
        }
 }
@@ -684,16 +673,7 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "")
                Logger::log('pumpio_action '.$username.' '.$action.': success '.$uri);
        } else {
                Logger::log('pumpio_action '.$username.' '.$action.': general error: '.$uri.' '.print_r($user, true));
-
-               $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $uid);
-               if (DBA::isResult($r)) {
-                       $a->contact = $r[0]["id"];
-               }
-
-               $s = serialize(['url' => $url, 'item' => $orig_post["id"], 'post' => $params]);
-
-               Queue::add($a->contact, Protocol::PUMPIO, $s);
-               notice(L10n::t('Pump.io like failed. Queued for retry.').EOL);
+               Worker::defer();
        }
 }
 
@@ -1030,24 +1010,6 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion =
 
 function pumpio_get_contact($uid, $contact, $no_insert = false)
 {
-       $gcontact = ["url" => $contact->url, "network" => Protocol::PUMPIO, "generation" => 2,
-               "name" => $contact->displayName,  "hide" => true,
-               "nick" => $contact->preferredUsername,
-               "addr" => str_replace("acct:", "", $contact->id)];
-
-       if (!empty($contact->location->displayName)) {
-               $gcontact["location"] = $contact->location->displayName;
-       }
-
-       if (!empty($contact->summary)) {
-               $gcontact["about"] = $contact->summary;
-       }
-
-       if (!empty($contact->image->url)) {
-               $gcontact["photo"] = $contact->image->url;
-       }
-
-       GContact::update($gcontact);
        $cid = Contact::getIdForURL($contact->url, $uid);
 
        if ($no_insert) {
@@ -1458,90 +1420,6 @@ function pumpio_getallusers(App &$a, $uid)
        }
 }
 
-function pumpio_queue_hook(App $a, array &$b)
-{
-       $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'",
-               DBA::escape(Protocol::PUMPIO)
-       );
-
-       if (!DBA::isResult($qi)) {
-               return;
-       }
-
-       foreach ($qi as $x) {
-               if ($x['network'] !== Protocol::PUMPIO) {
-                       continue;
-               }
-
-               Logger::log('pumpio_queue: run');
-
-               $r = q("SELECT `user`.* FROM `user` LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
-                       WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1",
-                       intval($x['cid'])
-               );
-               if (!DBA::isResult($r)) {
-                       continue;
-               }
-
-               $userdata = $r[0];
-
-               //Logger::log('pumpio_queue: fetching userdata '.print_r($userdata, true));
-
-               $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");
-
-               $host = PConfig::get($userdata['uid'], "pumpio", "host");
-               $user = PConfig::get($userdata['uid'], "pumpio", "user");
-
-               $success = false;
-
-               if ($oauth_token && $oauth_token_secret &&
-                       $consumer_key && $consumer_secret) {
-                       $username = $user.'@'.$host;
-
-                       Logger::log('pumpio_queue: able to post for user '.$username);
-
-                       $z = unserialize($x['content']);
-
-                       $client = new oauth_client_class;
-                       $client->oauth_version = '1.0a';
-                       $client->url_parameters = false;
-                       $client->authorization_header = true;
-                       $client->access_token = $oauth_token;
-                       $client->access_token_secret = $oauth_token_secret;
-                       $client->client_id = $consumer_key;
-                       $client->client_secret = $consumer_secret;
-
-                       if (pumpio_reachable($z['url'])) {
-                               $success = $client->CallAPI($z['url'], 'POST', $z['post'], ['FailOnAccessError'=>true, 'RequestContentType'=>'application/json'], $user);
-                       } else {
-                               $success = false;
-                       }
-
-                       if ($success) {
-                               $post_id = $user->object->id;
-                               Logger::log('pumpio_queue: send '.$username.': success '.$post_id);
-                               if ($post_id && $iscomment) {
-                                       Logger::log('pumpio_send '.$username.': Update extid '.$post_id." for post id ".$z['item']);
-                                       Item::update(['extid' => $post_id], ['id' => $z['item']]);
-                               }
-                               Queue::removeItem($x['id']);
-                       } else {
-                               Logger::log('pumpio_queue: send '.$username.': '.$z['url'].' general error: ' . print_r($user, true));
-                       }
-               } else {
-                       Logger::log("pumpio_queue: Error getting tokens for user ".$userdata['uid']);
-               }
-
-               if (!$success) {
-                       Logger::log('pumpio_queue: delayed');
-                       Queue::updateTime($x['id']);
-               }
-       }
-}
-
 function pumpio_getreceiver(App $a, array $b)
 {
        $receiver = [];
@@ -1732,7 +1610,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id)
 
 function pumpio_reachable($url)
 {
-       return Network::curl($url, false, $redirects, ['timeout'=>10])->isSuccess();
+       return Network::curl($url, false, ['timeout' => 10])->isSuccess();
 }
 
 /*