X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=pumpio%2Fpumpio.php;h=bf6bfda367e27e2b4d38d4b5561023ae1d4c7bba;hb=9c266e59cfa7939af7120506f9833448ca1615e3;hp=b196167a626bb9411880b0482ca05ec61955a769;hpb=93f8bbfe567dd8571a8269bdcd4c541dc75af4fd;p=friendica-addons.git diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index b196167a..bf6bfda3 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -18,12 +18,13 @@ use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\Item; +use Friendica\Model\Post; use Friendica\Model\User; +use Friendica\Network\HTTPClientOptions; use Friendica\Protocol\Activity; use Friendica\Protocol\ActivityNamespace; use Friendica\Util\ConfigFileLoader; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Network; use Friendica\Util\Strings; use Friendica\Util\XML; @@ -46,19 +47,6 @@ function pumpio_install() Hook::register('check_item_notification', 'addon/pumpio/pumpio.php', 'pumpio_check_item_notification'); } -function pumpio_uninstall() -{ - Hook::unregister('load_config', 'addon/pumpio/pumpio.php', 'pumpio_load_config'); - Hook::unregister('hook_fork', 'addon/pumpio/pumpio.php', 'pumpio_hook_fork'); - Hook::unregister('post_local', 'addon/pumpio/pumpio.php', 'pumpio_post_local'); - Hook::unregister('notifier_normal', 'addon/pumpio/pumpio.php', 'pumpio_send'); - Hook::unregister('jot_networks', 'addon/pumpio/pumpio.php', 'pumpio_jot_nets'); - 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('check_item_notification', 'addon/pumpio/pumpio.php', 'pumpio_check_item_notification'); -} - function pumpio_module() {} function pumpio_content(App $a) @@ -71,13 +59,13 @@ function pumpio_content(App $a) require_once("mod/settings.php"); settings_init($a); - if (isset($a->argv[1])) { - switch ($a->argv[1]) { + if (isset(DI::args()->getArgv()[1])) { + switch (DI::args()->getArgv()[1]) { case "connect": $o = pumpio_connect($a); break; default: - $o = print_r($a->argv, true); + $o = print_r(DI::args()->getArgv(), true); break; } } else { @@ -159,8 +147,7 @@ function pumpio_connect(App $a) if (($consumer_key == "") || ($consumer_secret == "")) { Logger::log("pumpio_connect: ".sprintf("Unable to register the client at the pump.io server '%s'.", $hostname)); - $o .= DI::l10n()->t("Unable to register the client at the pump.io server '%s'.", $hostname); - return $o; + return DI::l10n()->t("Unable to register the client at the pump.io server '%s'.", $hostname); } // The callback URL is the script that gets called after the user authenticates with pumpio @@ -403,7 +390,7 @@ function pumpio_hook_fork(App $a, array &$b) if (DI::pConfig()->get($post['uid'], 'pumpio', 'import')) { // Don't fork if it isn't a reply to a pump.io post - if (($post['parent'] != $post['id']) && !Item::exists(['id' => $post['parent'], 'network' => Protocol::PUMPIO])) { + if (($post['parent'] != $post['id']) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::PUMPIO])) { Logger::log('No pump.io parent found for item ' . $post['id']); $b['execute'] = false; return; @@ -450,10 +437,12 @@ function pumpio_send(App $a, array &$b) Logger::log("pumpio_send: parameter ".print_r($b, true), Logger::DATA); + $b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], $b['body']); + if ($b['parent'] != $b['id']) { // Looking if its a reply to a pumpio post $condition = ['id' => $b['parent'], 'network' => Protocol::PUMPIO]; - $orig_post = Item::selectFirst([], $condition); + $orig_post = Post::selectFirst([], $condition); if (!DBA::isResult($orig_post)) { Logger::log("pumpio_send: no pumpio post ".$b["parent"]); @@ -526,7 +515,7 @@ function pumpio_send(App $a, array &$b) if ($oauth_token && $oauth_token_secret) { $title = trim($b['title']); - $content = BBCode::convert($b['body'], false, 4); + $content = BBCode::convertForUriId($b['uri-id'], $b['body'], BBCode::CONNECTORS); $params = []; @@ -624,7 +613,7 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") $hostname = DI::pConfig()->get($uid, 'pumpio', 'host'); $username = DI::pConfig()->get($uid, "pumpio", "user"); - $orig_post = Item::selectFirst([], ['uri' => $uri, 'uid' => $uid]); + $orig_post = Post::selectFirst([], ['uri' => $uri, 'uid' => $uid]); if (!DBA::isResult($orig_post)) { return; @@ -672,7 +661,7 @@ function pumpio_action(App $a, $uid, $uri, $action, $content = "") if ($success) { Logger::log('pumpio_action '.$username.' '.$action.': success '.$uri); } else { - Logger::log('pumpio_action '.$username.' '.$action.': general error: '.$uri.' '.print_r($user, true)); + Logger::log('pumpio_action '.$username.' '.$action.': general error: '.$uri); Worker::defer(); } } @@ -887,9 +876,9 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) { // Searching for the unliked post // Two queries for speed issues - $orig_post = Item::selectFirst([], ['uri' => $post->object->id, 'uid' => $uid]); + $orig_post = Post::selectFirst([], ['uri' => $post->object->id, 'uid' => $uid]); if (!DBA::isResult($orig_post)) { - $orig_post = Item::selectFirst([], ['extid' => $post->object->id, 'uid' => $uid]); + $orig_post = Post::selectFirst([], ['extid' => $post->object->id, 'uid' => $uid]); if (!DBA::isResult($orig_post)) { return; } @@ -925,8 +914,6 @@ function pumpio_dounlike(App $a, $uid, $self, $post, $own_id) function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = true) { - require_once('include/items.php'); - if (empty($post->object->id)) { Logger::log('Got empty like: '.print_r($post, true), Logger::DEBUG); return; @@ -934,9 +921,9 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = // Searching for the liked post // Two queries for speed issues - $orig_post = Item::selectFirst([], ['uri' => $post->object->id, 'uid' => $uid]); + $orig_post = Post::selectFirst([], ['uri' => $post->object->id, 'uid' => $uid]); if (!DBA::isResult($orig_post)) { - $orig_post = Item::selectFirst([], ['extid' => $post->object->id, 'uid' => $uid]); + $orig_post = Post::selectFirst([], ['extid' => $post->object->id, 'uid' => $uid]); if (!DBA::isResult($orig_post)) { return; } @@ -970,7 +957,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = } $condition = ['verb' => Activity::LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']]; - if (Item::exists($condition)) { + if (Post::exists($condition)) { Logger::log("pumpio_dolike: found existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']); return; } @@ -983,7 +970,7 @@ function pumpio_dolike(App $a, $uid, $self, $post, $own_id, $threadcompletion = $likedata['wall'] = 0; $likedata['network'] = Protocol::PUMPIO; $likedata['uri'] = Item::newURI($uid); - $likedata['parent-uri'] = $orig_post["uri"]; + $likedata['thr-parent'] = $orig_post['uri']; $likedata['contact-id'] = $contactid; $likedata['app'] = $post->generator->displayName; $likedata['author-name'] = $post->actor->displayName; @@ -1071,7 +1058,7 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) } if (!empty($contact->image->url)) { - Contact::updateAvatar($contact->image->url, $uid, $contact_id); + Contact::updateAvatar($contact_id, $contact->image->url); } return $contact_id; @@ -1081,13 +1068,13 @@ function pumpio_dodelete(App $a, $uid, $self, $post, $own_id) { // Two queries for speed issues $condition = ['uri' => $post->object->id, 'uid' => $uid]; - if (Item::exists($condition)) { + if (Post::exists($condition)) { Item::markForDeletion($condition); return true; } $condition = ['extid' => $post->object->id, 'uid' => $uid]; - if (Item::exists($condition)) { + if (Post::exists($condition)) { Item::markForDeletion($condition); return true; } @@ -1096,8 +1083,6 @@ function pumpio_dodelete(App $a, $uid, $self, $post, $own_id) function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcompletion = true) { - require_once('include/items.php'); - if (($post->verb == "like") || ($post->verb == "favorite")) { return pumpio_dolike($a, $uid, $self, $post, $own_id); } @@ -1112,10 +1097,10 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp if ($post->verb != "update") { // Two queries for speed issues - if (Item::exists(['uri' => $post->object->id, 'uid' => $uid])) { + if (Post::exists(['uri' => $post->object->id, 'uid' => $uid])) { return false; } - if (Item::exists(['extid' => $post->object->id, 'uid' => $uid])) { + if (Post::exists(['extid' => $post->object->id, 'uid' => $uid])) { return false; } } @@ -1156,7 +1141,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp $contact_id = $self[0]['id']; } - $postarray['parent-uri'] = $post->object->id; + $postarray['thr-parent'] = $post->object->id; if (!$public) { $postarray['private'] = 1; @@ -1217,7 +1202,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp $reply->url = $post->object->inReplyTo->url; pumpio_dopost($a, $client, $uid, $self, $reply, $own_id, false); - $postarray['parent-uri'] = $post->object->inReplyTo->id; + $postarray['thr-parent'] = $post->object->inReplyTo->id; } // When there is no content there is no need to continue @@ -1277,9 +1262,8 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp $created = ''; } - $postarray['body'] = share_header($share_author, $post->object->author->url, - $post->object->author->image->url, "", - $created, $post->links->self->href). + $postarray['body'] = Friendica\Content\Text\BBCode::getShareOpeningTag($share_author, $post->object->author->url, + $post->object->author->image->url, $post->links->self->href, $created) . $postarray['body']."[/share]"; } @@ -1297,7 +1281,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp } if (($post->object->objectType == "comment") && $threadcompletion) { - pumpio_fetchallcomments($a, $uid, $postarray['parent-uri']); + pumpio_fetchallcomments($a, $uid, $postarray['thr-parent']); } return $top_item; @@ -1318,10 +1302,10 @@ function pumpio_fetchinbox(App $a, $uid) $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - $lastitems = q("SELECT `uri` FROM `thread` - 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", + $lastitems = q("SELECT `uri` FROM `post-thread-user` + INNER JOIN `post-view` ON `post-view`.`id` = `post-thread-user`.`id` + WHERE `post-thread-user`.`network` = '%s' AND `post-thread-user`.`uid` = %d AND `post-view`.`extid` != '' + ORDER BY `post-thread-user`.`commented` DESC LIMIT 10", DBA::escape(Protocol::PUMPIO), intval($uid) ); @@ -1523,12 +1507,12 @@ function pumpio_fetchallcomments(App $a, $uid, $id) // Fetching the original post $condition = ["`uri` = ? AND `uid` = ? AND `extid` != ''", $id, $uid]; - $item = Item::selectFirst(['extid'], $condition); - if (!DBA::isResult($item)) { + $original = Post::selectFirst(['extid'], $condition); + if (!DBA::isResult($original)) { return false; } - $url = $item["extid"]; + $url = $original["extid"]; $client = new oauth_client_class; $client->oauth_version = '1.0a'; @@ -1580,11 +1564,11 @@ function pumpio_fetchallcomments(App $a, $uid, $id) } // Checking if the comment already exists - Two queries for speed issues - if (Item::exists(['uri' => $item->id, 'uid' => $uid])) { + if (Post::exists(['uri' => $item->id, 'uid' => $uid])) { continue; } - if (Item::exists(['extid' => $item->id, 'uid' => $uid])) { + if (Post::exists(['extid' => $item->id, 'uid' => $uid])) { continue; } @@ -1610,7 +1594,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id) function pumpio_reachable($url) { - return Network::curl($url, false, ['timeout' => 10])->isSuccess(); + return DI::httpRequest()->get($url, [HTTPClientOptions::TIMEOUT => 10])->isSuccess(); } /*