use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
+use Friendica\Core\Protocol;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
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();
-
// Define the needed keys
$consumer_key = PConfig::get(local_user(), 'pumpio', 'consumer_key');
$consumer_secret = PConfig::get(local_user(), 'pumpio', 'consumer_secret');
// Create a new instance of the oauth_client_class library. For this step, all we need to give the library is our
// Consumer Key and Consumer Secret
$client = new oauth_client_class;
- $client->debug = 1;
+ $client->debug = 0;
$client->server = '';
$client->oauth_version = '1.0a';
$client->request_token_url = 'https://'.$hostname.'/oauth/request_token';
if ($success) {
logger("pumpio_connect: authenticated");
- $o .= L10n::t("You are now authenticated to pumpio.");
+ $o = L10n::t("You are now authenticated to pumpio.");
$o .= '<br /><a href="'.$a->get_baseurl().'/settings/connectors">'.L10n::t("return to the connector page").'</a>';
} else {
logger("pumpio_connect: could not connect");
$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', 'post' , defaults($_POST, 'pumpio', false));
+ PConfig::set(local_user(), 'pumpio', 'import' , defaults($_POST, 'pumpio_import', false));
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', 'public' , defaults($_POST, 'pumpio_public', false));
+ PConfig::set(local_user(), 'pumpio', 'mirror' , defaults($_POST, 'pumpio_mirror', false));
+ PConfig::set(local_user(), 'pumpio', 'post_by_default', defaults($_POST, 'pumpio_bydefault', false));
- if (!$_POST['pumpio_mirror']) {
+ if (!empty($_POST['pumpio_mirror'])) {
PConfig::delete(local_user(), 'pumpio', 'lastdate');
}
-
- //header("Location: ".$a->get_baseurl()."/pumpio/connect");
}
}
}
if ($b['parent'] != $b['id']) {
// Looking if its a reply to a pumpio post
- $condition = ['id' => $b['parent'], 'network' => NETWORK_PUMPIO];
+ $condition = ['id' => $b['parent'], 'network' => Protocol::PUMPIO];
$orig_post = Item::selectFirst([], $condition);
if (!DBA::isResult($orig_post)) {
$s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $params]);
- Queue::add($a->contact, NETWORK_PUMPIO, $s);
+ Queue::add($a->contact, Protocol::PUMPIO, $s);
notice(L10n::t('Pump.io post failed. Queued for retry.').EOL);
}
}
$s = serialize(['url' => $url, 'item' => $orig_post["id"], 'post' => $params]);
- Queue::add($a->contact, NETWORK_PUMPIO, $s);
+ Queue::add($a->contact, Protocol::PUMPIO, $s);
notice(L10n::t('Pump.io like failed. Queued for retry.').EOL);
}
}
$success = $client->CallAPI($url, 'GET', [], ['FailOnAccessError'=>true], $user);
} else {
$success = false;
+ $user = [];
}
if (!$success) {
$_REQUEST["source"] = "pump.io";
if (isset($post->object->id)) {
- $_REQUEST['message_id'] = NETWORK_PUMPIO.":".$post->object->id;
+ $_REQUEST['message_id'] = Protocol::PUMPIO.":".$post->object->id;
}
if ($post->object->displayName != "") {
}
$condition = ['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']];
- if (DBA::exists('item', $condition)) {
+ if (Item::exists($condition)) {
logger("pumpio_dolike: found existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
return;
}
$likedata['gravity'] = GRAVITY_ACTIVITY;
$likedata['uid'] = $uid;
$likedata['wall'] = 0;
- $likedata['network'] = NETWORK_PUMPIO;
+ $likedata['network'] = Protocol::PUMPIO;
$likedata['uri'] = Item::newURI($uid);
$likedata['parent-uri'] = $orig_post["uri"];
$likedata['contact-id'] = $contactid;
$likedata['app'] = $post->generator->displayName;
$likedata['author-name'] = $post->actor->displayName;
$likedata['author-link'] = $post->actor->url;
- $likedata['author-avatar'] = $post->actor->image->url;
+ if (!empty($post->actor->image)) {
+ $likedata['author-avatar'] = $post->actor->image->url;
+ }
$author = '[url=' . $likedata['author-link'] . ']' . $likedata['author-name'] . '[/url]';
$objauthor = '[url=' . $orig_post['author-link'] . ']' . $orig_post['author-name'] . '[/url]';
function pumpio_get_contact($uid, $contact, $no_insert = false)
{
- $gcontact = ["url" => $contact->url, "network" => NETWORK_PUMPIO, "generation" => 2,
+ $gcontact = ["url" => $contact->url, "network" => Protocol::PUMPIO, "generation" => 2,
"name" => $contact->displayName, "hide" => true,
"nick" => $contact->preferredUsername,
"addr" => str_replace("acct:", "", $contact->id)];
DBA::escape($contact->displayName),
DBA::escape($contact->preferredUsername),
DBA::escape($contact->image->url),
- DBA::escape(NETWORK_PUMPIO),
- intval(CONTACT_IS_FRIEND),
+ DBA::escape(Protocol::PUMPIO),
+ intval(Contact::FRIEND),
intval(1),
DBA::escape($contact->location->displayName),
DBA::escape($contact->summary),
{
// Two queries for speed issues
$condition = ['uri' => $post->object->id, 'uid' => $uid];
- if (DBA::exists('item', $condition)) {
+ if (Item::exists($condition)) {
Item::delete($condition);
return true;
}
$condition = ['extid' => $post->object->id, 'uid' => $uid];
- if (DBA::exists('item', $condition)) {
+ if (Item::exists($condition)) {
Item::delete($condition);
return true;
}
if ($post->verb != "update") {
// Two queries for speed issues
- if (DBA::exists('item', ['uri' => $post->object->id, 'uid' => $uid])) {
+ if (Item::exists(['uri' => $post->object->id, 'uid' => $uid])) {
return false;
}
- if (DBA::exists('item', ['extid' => $post->object->id, 'uid' => $uid])) {
+ if (Item::exists(['extid' => $post->object->id, 'uid' => $uid])) {
return false;
}
}
}
$postarray = [];
- $postarray['network'] = NETWORK_PUMPIO;
+ $postarray['network'] = Protocol::PUMPIO;
$postarray['uid'] = $uid;
$postarray['wall'] = 0;
$postarray['uri'] = $post->object->id;
$reply->cc = $post->cc;
}
- $reply->to = $post->to;
+ if (isset($post->to)) {
+ $reply->to = $post->to;
+ }
+
$reply->object = new stdClass;
$reply->object->objectType = $post->object->inReplyTo->objectType;
$reply->object->content = $post->object->inReplyTo->content;
$postarray['parent-uri'] = $post->object->inReplyTo->id;
}
+ // When there is no content there is no need to continue
+ if (empty($post->object->content)) {
+ return false;
+ }
+
if (!empty($post->object->pump_io->proxyURL)) {
$postarray['extid'] = $post->object->pump_io->proxyURL;
}
$postarray['verb'] = ACTIVITY_POST;
$postarray['owner-name'] = $post->actor->displayName;
$postarray['owner-link'] = $post->actor->url;
- $postarray['owner-avatar'] = $post->actor->image->url;
- $postarray['author-name'] = $post->actor->displayName;
- $postarray['author-link'] = $post->actor->url;
- $postarray['author-avatar'] = $post->actor->image->url;
+ $postarray['author-name'] = $postarray['owner-name'];
+ $postarray['author-link'] = $postarray['owner-link'];
+ if (!empty($post->actor->image)) {
+ $postarray['owner-avatar'] = $post->actor->image->url;
+ $postarray['author-avatar'] = $postarray['owner-avatar'];
+ }
$postarray['plink'] = $post->object->url;
$postarray['app'] = $post->generator->displayName;
+ $postarray['title'] = '';
$postarray['body'] = HTML::toBBCode($post->object->content);
$postarray['object'] = json_encode($post);
$share_author = $post->object->author->url;
}
+ if (isset($post->object->created)) {
+ $created = DateTimeFormat::utc($post->object->created);
+ } else {
+ $created = '';
+ }
+
$postarray['body'] = share_header($share_author, $post->object->author->url,
$post->object->author->image->url, "",
- DateTimeFormat::utc($post->object->created),
- $post->links->self->href).
+ $created, $post->links->self->href).
$postarray['body']."[/share]";
}
INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
WHERE `thread`.`network` = '%s' AND `thread`.`uid` = %d AND `item`.`extid` != ''
ORDER BY `thread`.`commented` DESC LIMIT 10",
- DBA::escape(NETWORK_PUMPIO),
+ DBA::escape(Protocol::PUMPIO),
intval($uid)
);
$success = false;
}
+ if (empty($users)) {
+ return;
+ }
+
if ($users->totalItems > count($users->items)) {
$url = 'https://'.$hostname.'/api/user/'.$username.'/following?count='.$users->totalItems;
function pumpio_queue_hook(App $a, array &$b)
{
$qi = q("SELECT * FROM `queue` WHERE `network` = '%s'",
- DBA::escape(NETWORK_PUMPIO)
+ DBA::escape(Protocol::PUMPIO)
);
if (!DBA::isResult($qi)) {
}
foreach ($qi as $x) {
- if ($x['network'] !== NETWORK_PUMPIO) {
+ if ($x['network'] !== Protocol::PUMPIO) {
continue;
}
}
Queue::removeItem($x['id']);
} else {
- logger('pumpio_queue: send '.$username.': '.$url.' general error: ' . print_r($user, true));
+ logger('pumpio_queue: send '.$username.': '.$z['url'].' general error: ' . print_r($user, true));
}
} else {
logger("pumpio_queue: Error getting tokens for user ".$userdata['uid']);
$r = q("SELECT `name`, `nick`, `url` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `network` = '%s' AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
intval($cid),
intval($b["uid"]),
- DBA::escape(NETWORK_PUMPIO)
+ DBA::escape(Protocol::PUMPIO)
);
if (DBA::isResult($r)) {
"FROM `group_member`, `contact` WHERE `group_member`.`gid` = %d ".
"AND `contact`.`id` = `group_member`.`contact-id` AND `contact`.`network` = '%s'",
intval($gid),
- DBA::escape(NETWORK_PUMPIO)
+ DBA::escape(Protocol::PUMPIO)
);
foreach ($r AS $row)
$r = q("SELECT `name`, `nick`, `url` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `network` = '%s' AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
intval($cid),
intval($b["uid"]),
- DBA::escape(NETWORK_PUMPIO)
+ DBA::escape(Protocol::PUMPIO)
);
if (DBA::isResult($r)) {
}
// Checking if the comment already exists - Two queries for speed issues
- if (DBA::exists('item', ['uri' => $item->id, 'uid' => $uid])) {
+ if (Item::exists(['uri' => $item->id, 'uid' => $uid])) {
continue;
}
- if (DBA::exists('item', ['extid' => $item->id, 'uid' => $uid])) {
+ if (Item::exists(['extid' => $item->id, 'uid' => $uid])) {
continue;
}