Merge pull request #626 from annando/more-abstraction

And some more item class calls in the addons
pull/627/head
Hypolite Petovan 2018-06-19 08:13:18 -04:00 committed by GitHub
commit e1adeb377b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 129 deletions

View File

@ -403,17 +403,14 @@ function pumpio_send(&$a,&$b) {
if($b['parent'] != $b['id']) {
// Looking if its a reply to a pumpio post
$r = q("SELECT item.* FROM item, contact WHERE item.id = %d AND item.uid = %d AND contact.id = `contact-id` AND contact.network='%s'LIMIT 1",
intval($b["parent"]),
intval($b["uid"]),
dbesc(NETWORK_PUMPIO));
$condition = ['id' => $b['parent'], 'network' => NETWORK_PUMPIO];
$orig_post = Item::selectFirst([], $condition);
if(!count($r)) {
if(!DBM::is_result($orig_post)) {
logger("pumpio_send: no pumpio post ".$b["parent"]);
return;
} else {
$iscomment = true;
$orig_post = $r[0];
}
} else {
$iscomment = false;
@ -572,15 +569,11 @@ function pumpio_action(&$a, $uid, $uri, $action, $content = "") {
$hostname = PConfig::get($uid, 'pumpio','host');
$username = PConfig::get($uid, "pumpio", "user");
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($uri),
intval($uid)
);
$orig_post = Item::select([], ['uri' => $uri, 'uid' => $uid]);
if (!count($r))
if (!DBM::is_result($orig_post)) {
return;
$orig_post = $r[0];
}
if ($orig_post["extid"] && !strstr($orig_post["extid"], "/proxy/"))
$uri = $orig_post["extid"];
@ -828,23 +821,12 @@ function pumpio_fetchtimeline(&$a, $uid) {
function pumpio_dounlike(&$a, $uid, $self, $post, $own_id) {
// Searching for the unliked post
// Two queries for speed issues
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($post->object->id),
intval($uid)
);
if (count($r))
$orig_post = $r[0];
else {
$r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($post->object->id),
intval($uid)
);
if (!count($r))
$orig_post = Item::select([], ['uri' => $post->object->id, 'uid' => $uid]);
if (!DBM::is_result($r)) {
$orig_post = Item::select([], ['extid' => $post->object->id, 'uid' => $uid]);
if (!DBM::is_result($r)) {
return;
else
$orig_post = $r[0];
}
}
$contactid = 0;
@ -882,25 +864,12 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id, $threadcompletion = tru
// Searching for the liked post
// Two queries for speed issues
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `network` = '%s' LIMIT 1",
dbesc($post->object->id),
intval($uid),
dbesc(NETWORK_PUMPIO)
);
if (count($r))
$orig_post = $r[0];
else {
$r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d AND `network` = '%s' LIMIT 1",
dbesc($post->object->id),
intval($uid),
dbesc(NETWORK_PUMPIO)
);
if (!count($r))
$orig_post = Item::select([], ['uri' => $post->object->id, 'uid' => $uid]);
if (!DBM::is_result($r)) {
$orig_post = Item::select([], ['extid' => $post->object->id, 'uid' => $uid]);
if (!DBM::is_result($r)) {
return;
else
$orig_post = $r[0];
}
}
// thread completion
@ -927,14 +896,8 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id, $threadcompletion = tru
$contactid = $orig_post['contact-id'];
}
$r = q("SELECT parent FROM `item` WHERE `verb` = '%s' AND `uid` = %d AND `contact-id` = %d AND `thr-parent` = '%s' LIMIT 1",
dbesc(ACTIVITY_LIKE),
intval($uid),
intval($contactid),
dbesc($orig_post['uri'])
);
if(count($r)) {
$condition = ['verb' => ACTIVITY_LIKE, 'uid' => $uid, 'contact-id' => $contactid, 'thr-parent' => $orig_post['uri']];
if (dba::exists('item', $condition)) {
logger("pumpio_dolike: found existing like. User ".$own_id." ".$uid." Contact: ".$contactid." Url ".$orig_post['uri']);
return;
}
@ -1070,22 +1033,13 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
if ($post->verb != "update") {
// Two queries for speed issues
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($post->object->id),
intval($uid)
);
if (count($r))
if (dba::exists('item', ['uri' => $post->object->id, 'uid' => $uid])) {
return false;
$r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($post->object->id),
intval($uid)
);
if (count($r))
}
if (dba::exists('item', ['extid' => $post->object->id, 'uid' => $uid])) {
return false;
}
}
// Only handle these three types
if (!strstr("post|share|update", $post->verb))
@ -1525,15 +1479,13 @@ function pumpio_fetchallcomments(&$a, $uid, $id) {
intval($uid));
// Fetching the original post
$r = q("SELECT `extid` FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `extid` != '' LIMIT 1",
dbesc($id),
intval($uid)
);
if (!count($r))
$condition = ["`uri` = ? AND `uid` = ? AND `extid` != ''", $id, $uid];
$item = Item::selectFirst(['extid'], $condition);
if (!DBM::is_result($r)) {
return false;
}
$url = $r[0]["extid"];
$url = $item["extid"];
$client = new oauth_client_class;
$client->oauth_version = '1.0a';
@ -1579,21 +1531,13 @@ function pumpio_fetchallcomments(&$a, $uid, $id) {
continue;
// Checking if the comment already exists - Two queries for speed issues
$r = q("SELECT extid FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item->id),
intval($uid)
);
if (count($r))
if (dba::exists('item', ['uri' => $item->id, 'uid' => $uid])) {
continue;
}
$r = q("SELECT extid FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item->id),
intval($uid)
);
if (count($r))
if (dba::exists('item', ['extid' => $item->id, 'uid' => $uid])) {
continue;
}
$post = new stdClass;
$post->verb = "post";

View File

@ -721,15 +721,11 @@ function twitter_expire(App $a, $b)
return;
}
if (method_exists('dba', 'delete')) {
$r = dba::select('item', ['id'], ['deleted' => true, 'network' => NETWORK_TWITTER]);
while ($row = dba::fetch($r)) {
dba::delete('item', ['id' => $row['id']]);
}
dba::close($r);
} else {
$r = q("DELETE FROM `item` WHERE `deleted` AND `network` = '%s'", dbesc(NETWORK_TWITTER));
}
require_once "include/items.php";
@ -1322,12 +1318,7 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis
// $postarray['object'] = json_encode($post); // Activate for debugging
// Don't import our own comments
$r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($postarray['uri']),
intval($uid)
);
if (DBM::is_result($r)) {
if (dba::exists('item', ['extid' => $postarray['uri'], 'uid' => $uid])) {
logger("Item with extid " . $postarray['uri'] . " found.", LOGGER_DEBUG);
return [];
}
@ -1337,31 +1328,22 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis
if ($post->in_reply_to_status_id_str != "") {
$parent = "twitter::" . $post->in_reply_to_status_id_str;
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($parent),
intval($uid)
);
if (DBM::is_result($r)) {
$postarray['thr-parent'] = $r[0]["uri"];
$postarray['parent-uri'] = $r[0]["parent-uri"];
$postarray['parent'] = $r[0]["parent"];
$postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
} else {
$r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($parent),
intval($uid)
);
if (DBM::is_result($r)) {
$postarray['thr-parent'] = $r[0]['uri'];
$postarray['parent-uri'] = $r[0]['parent-uri'];
$postarray['parent'] = $r[0]['parent'];
$fields = ['uri', 'parent-uri', 'parent'];
$parent_item = Item::selectFirst($fields, ['uri' => $parent, 'uid' => $uid]);
if (!DBM::is_result($parent_item)) {
$parent_item = Item::selectFirst($fields, ['extid' => $parent, 'uid' => $uid]);
}
if (DBM::is_result($parent_item)) {
$postarray['thr-parent'] = $parent_item['uri'];
$postarray['parent-uri'] = $parent_item['parent-uri'];
$postarray['parent'] = $parent_item['parent'];
$postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
} else {
$postarray['thr-parent'] = $postarray['uri'];
$postarray['parent-uri'] = $postarray['uri'];
$postarray['object-type'] = ACTIVITY_OBJ_NOTE;
}
}
// Is it me?
$own_id = PConfig::get($uid, 'twitter', 'own_id');
@ -1506,12 +1488,7 @@ function twitter_fetchparentposts(App $a, $uid, $post, TwitterOAuth $connection,
break;
}
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc("twitter::".$post->id_str),
intval($uid)
);
if (DBM::is_result($r)) {
if (dba::exists('item', ['uri' => 'twitter::' . $post->id_str, 'uid' => $uid])) {
break;
}