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;
$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"];
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;
// 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
$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;
}
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
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';
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";
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));
+ $r = dba::select('item', ['id'], ['deleted' => true, 'network' => NETWORK_TWITTER]);
+ while ($row = dba::fetch($r)) {
+ dba::delete('item', ['id' => $row['id']]);
}
+ dba::close($r);
require_once "include/items.php";
// $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 [];
}
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"];
+ $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 {
- $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;
- } else {
- $postarray['thr-parent'] = $postarray['uri'];
- $postarray['parent-uri'] = $postarray['uri'];
- $postarray['object-type'] = ACTIVITY_OBJ_NOTE;
- }
+ $postarray['thr-parent'] = $postarray['uri'];
+ $postarray['parent-uri'] = $postarray['uri'];
+ $postarray['object-type'] = ACTIVITY_OBJ_NOTE;
}
// Is it me?
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;
}