More item calls have been converted to current functions

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

View file

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