-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;
- }
-
- foreach ($qi as $x) {
- if ($x['network'] !== NETWORK_PUMPIO) {
- continue;
- }
-
- logger('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 (!DBM::is_result($r)) {
- continue;
- }
-
- $userdata = $r[0];
-
- //logger('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('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('pumpio_queue: send '.$username.': success '.$post_id);
- if ($post_id && $iscomment) {
- logger('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('pumpio_queue: send '.$username.': '.$url.' general error: ' . print_r($user, true));
- }
- } else {
- logger("pumpio_queue: Error getting tokens for user ".$userdata['uid']);
- }
-
- if (!$success) {
- logger('pumpio_queue: delayed');
- Queue::updateTime($x['id']);
- }
- }
-}
-