function pumpio_get_contact($uid, $contact) { if (function_exists("update_gcontact")) { update_gcontact(array("url" => $contact->url, "network" => NETWORK_PUMPIO, "generation" => 2, "photo" => $contact->image->url, "name" => $contact->displayName, "hide" => true, "nick" => $contact->preferredUsername, "location" => $contact->location->displayName, "about" => $contact->summary, "addr" => str_replace("acct:", "", $contact->id))); } else { // Old Code $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($contact->url))); if (count($r) == 0) { q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')", dbesc(normalise_link($contact->url)), dbesc($contact->displayName), dbesc($contact->preferredUsername), dbesc($contact->image->url)); } else { q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'", dbesc($contact->displayName), dbesc($contact->preferredUsername), dbesc($contact->image->url), dbesc(normalise_link($contact->url))); } if (DB_UPDATE_VERSION >= "1177") { q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'", dbesc($contact->location->displayName), dbesc($contact->summary), dbesc(normalise_link($contact->url))); } } $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1", intval($uid), dbesc($contact->url)); if (!count($r)) { // create contact record q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,\n\t\t\t\t\t`name`, `nick`, `photo`, `network`, `rel`, `priority`,\n\t\t\t\t\t`writable`, `blocked`, `readonly`, `pending` )\n\t\t\t\tVALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ", intval($uid), dbesc(datetime_convert()), dbesc($contact->url), dbesc(normalise_link($contact->url)), dbesc(str_replace("acct:", "", $contact->id)), dbesc(''), dbesc($contact->id), dbesc('pump.io ' . $contact->id), dbesc($contact->displayName), dbesc($contact->preferredUsername), dbesc($contact->image->url), dbesc(NETWORK_PUMPIO), intval(CONTACT_IS_FRIEND), intval(1), intval(1)); $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", dbesc($contact->url), intval($uid)); if (!count($r)) { return false; } $contact_id = $r[0]['id']; $g = q("select def_gid from user where uid = %d limit 1", intval($uid)); if ($g && intval($g[0]['def_gid'])) { require_once 'include/group.php'; group_add_member($uid, '', $contact_id, $g[0]['def_gid']); } require_once "Photo.php"; $photos = import_profile_photo($contact->image->url, $uid, $contact_id); q("UPDATE `contact` SET `photo` = '%s',\n\t\t\t\t\t`thumb` = '%s',\n\t\t\t\t\t`micro` = '%s',\n\t\t\t\t\t`name-date` = '%s',\n\t\t\t\t\t`uri-date` = '%s',\n\t\t\t\t\t`avatar-date` = '%s'\n\t\t\t\tWHERE `id` = %d\n\t\t\t", dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), intval($contact_id)); if (DB_UPDATE_VERSION >= "1177") { q("UPDATE `contact` SET `location` = '%s',\n\t\t\t\t\t\t`about` = '%s'\n\t\t\t\t\tWHERE `id` = %d", dbesc($contact->location->displayName), dbesc($contact->summary), intval($contact_id)); } } else { // update profile photos once every two weeks as we have no notification of when they change. //$update_photo = (($r[0]['avatar-date'] < datetime_convert('','','now -14 days')) ? true : false); $update_photo = $r[0]['avatar-date'] < datetime_convert('', '', 'now -12 hours'); // check that we have all the photos, this has been known to fail on occasion if (!$r[0]['photo'] || !$r[0]['thumb'] || !$r[0]['micro'] || $update_photo) { require_once "Photo.php"; $photos = import_profile_photo($contact->image->url, $uid, $r[0]['id']); q("UPDATE `contact` SET `photo` = '%s',\n\t\t\t\t\t`thumb` = '%s',\n\t\t\t\t\t`micro` = '%s',\n\t\t\t\t\t`name-date` = '%s',\n\t\t\t\t\t`uri-date` = '%s',\n\t\t\t\t\t`avatar-date` = '%s',\n\t\t\t\t\t`name` = '%s',\n\t\t\t\t\t`nick` = '%s'\n\t\t\t\t\tWHERE `id` = %d\n\t\t\t\t", dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($contact->displayName), dbesc($contact->preferredUsername), intval($r[0]['id'])); if (DB_UPDATE_VERSION >= "1177") { q("UPDATE `contact` SET `location` = '%s',\n\t\t\t\t\t\t\t`about` = '%s'\n\t\t\t\t\t\tWHERE `id` = %d", dbesc($contact->location->displayName), dbesc($contact->summary), intval($r[0]['id'])); } } } return $r[0]["id"]; }
function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) { if (function_exists("update_gcontact")) { update_gcontact(array("url" => $contact["canonical_url"], "generation" => 2, "network" => NETWORK_APPNET, "photo" => $contact["avatar_image"]["url"], "name" => $contact["name"], "nick" => $contact["username"], "about" => $contact["description"]["text"], "hide" => true, "addr" => $contact["username"] . "@app.net")); } else { // Old Code $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($contact["canonical_url"]))); if (count($r) == 0) { q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')", dbesc(normalise_link($contact["canonical_url"])), dbesc($contact["name"]), dbesc($contact["username"]), dbesc($contact["avatar_image"]["url"])); } else { q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'", dbesc($contact["name"]), dbesc($contact["username"]), dbesc($contact["avatar_image"]["url"]), dbesc(normalise_link($contact["canonical_url"]))); } if (DB_UPDATE_VERSION >= "1177") { q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'", dbesc(""), dbesc($contact["description"]["text"]), dbesc(normalise_link($contact["canonical_url"]))); } } $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), dbesc("adn::" . $contact["id"])); if (!count($r) and !$create_user) { return $me["id"]; } if ($contact["canonical_url"] == "") { return $me["id"]; } if (count($r) and ($r[0]["readonly"] or $r[0]["blocked"])) { logger("appnet_fetchcontact: Contact '" . $r[0]["nick"] . "' is blocked or readonly.", LOGGER_DEBUG); return -1; } if (!count($r)) { if ($contact["name"] == "") { $contact["name"] = $contact["username"]; } if ($contact["username"] == "") { $contact["username"] = $contact["name"]; } // create contact record q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,\n\t\t\t\t\t`name`, `nick`, `photo`, `network`, `rel`, `priority`,\n\t\t\t\t\t`writable`, `blocked`, `readonly`, `pending` )\n\t\t\t\t\tVALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ", intval($uid), dbesc(datetime_convert()), dbesc($contact["canonical_url"]), dbesc(normalise_link($contact["canonical_url"])), dbesc($contact["username"] . "@app.net"), dbesc("adn::" . $contact["id"]), dbesc(''), dbesc("adn::" . $contact["id"]), dbesc($contact["name"]), dbesc($contact["username"]), dbesc($contact["avatar_image"]["url"]), dbesc(NETWORK_APPNET), intval(CONTACT_IS_FRIEND), intval(1), intval(1)); $r = q("SELECT * FROM `contact` WHERE `alias` = '%s' AND `uid` = %d LIMIT 1", dbesc("adn::" . $contact["id"]), intval($uid)); if (!count($r)) { return false; } $contact_id = $r[0]['id']; $g = q("SELECT def_gid FROM user WHERE uid = %d LIMIT 1", intval($uid)); if ($g && intval($g[0]['def_gid'])) { require_once 'include/group.php'; group_add_member($uid, '', $contact_id, $g[0]['def_gid']); } require_once "Photo.php"; $photos = import_profile_photo($contact["avatar_image"]["url"], $uid, $contact_id); q("UPDATE `contact` SET `photo` = '%s',\n\t\t\t\t\t`thumb` = '%s',\n\t\t\t\t\t`micro` = '%s',\n\t\t\t\t\t`name-date` = '%s',\n\t\t\t\t\t`uri-date` = '%s',\n\t\t\t\t\t`avatar-date` = '%s'\n\t\t\t\tWHERE `id` = %d", dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), intval($contact_id)); if (DB_UPDATE_VERSION >= "1177") { q("UPDATE `contact` SET `location` = '%s',\n\t\t\t\t\t\t`about` = '%s'\n\t\t\t\t\tWHERE `id` = %d", dbesc(""), dbesc($contact["description"]["text"]), intval($contact_id)); } } else { // update profile photos once every two weeks as we have no notification of when they change. //$update_photo = (($r[0]['avatar-date'] < datetime_convert('','','now -2 days')) ? true : false); $update_photo = $r[0]['avatar-date'] < datetime_convert('', '', 'now -12 hours'); // check that we have all the photos, this has been known to fail on occasion if (!$r[0]['photo'] || !$r[0]['thumb'] || !$r[0]['micro'] || $update_photo) { logger("appnet_fetchcontact: Updating contact " . $contact["username"], LOGGER_DEBUG); require_once "Photo.php"; $photos = import_profile_photo($contact["avatar_image"]["url"], $uid, $r[0]['id']); q("UPDATE `contact` SET `photo` = '%s',\n\t\t\t\t\t\t`thumb` = '%s',\n\t\t\t\t\t\t`micro` = '%s',\n\t\t\t\t\t\t`name-date` = '%s',\n\t\t\t\t\t\t`uri-date` = '%s',\n\t\t\t\t\t\t`avatar-date` = '%s',\n\t\t\t\t\t\t`url` = '%s',\n\t\t\t\t\t\t`nurl` = '%s',\n\t\t\t\t\t\t`addr` = '%s',\n\t\t\t\t\t\t`name` = '%s',\n\t\t\t\t\t\t`nick` = '%s'\n\t\t\t\t\tWHERE `id` = %d", dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($contact["canonical_url"]), dbesc(normalise_link($contact["canonical_url"])), dbesc($contact["username"] . "@app.net"), dbesc($contact["name"]), dbesc($contact["username"]), intval($r[0]['id'])); if (DB_UPDATE_VERSION >= "1177") { q("UPDATE `contact` SET `location` = '%s',\n\t\t\t\t\t\t\t`about` = '%s'\n\t\t\t\t\t\tWHERE `id` = %d", dbesc(""), dbesc($contact["description"]["text"]), intval($r[0]['id'])); } } } return $r[0]["id"]; }
function pumpio_get_contact($uid, $contact, $no_insert = false) { if (function_exists("update_gcontact")) { update_gcontact(array("url" => $contact->url, "network" => NETWORK_PUMPIO, "generation" => 2, "photo" => $contact->image->url, "name" => $contact->displayName, "hide" => true, "nick" => $contact->preferredUsername, "location" => $contact->location->displayName, "about" => $contact->summary, "addr" => str_replace("acct:", "", $contact->id))); $cid = get_contact($contact->url, $uid); } else { // Old Code $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($contact->url))); if (count($r) == 0) { q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')", dbesc(normalise_link($contact->url)), dbesc($contact->displayName), dbesc($contact->preferredUsername), dbesc($contact->image->url)); } else { q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'", dbesc($contact->displayName), dbesc($contact->preferredUsername), dbesc($contact->image->url), dbesc(normalise_link($contact->url))); } if (DB_UPDATE_VERSION >= "1177") { q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'", dbesc($contact->location->displayName), dbesc($contact->summary), dbesc(normalise_link($contact->url))); } $cid = 0; } if ($no_insert) { return $cid; } $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1", intval($uid), dbesc($contact->url)); if (!count($r)) { // create contact record q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,\n\t\t\t\t\t`name`, `nick`, `photo`, `network`, `rel`, `priority`,\n\t\t\t\t\t`writable`, `blocked`, `readonly`, `pending` )\n\t\t\t\tVALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ", intval($uid), dbesc(datetime_convert()), dbesc($contact->url), dbesc(normalise_link($contact->url)), dbesc(str_replace("acct:", "", $contact->id)), dbesc(''), dbesc($contact->id), dbesc('pump.io ' . $contact->id), dbesc($contact->displayName), dbesc($contact->preferredUsername), dbesc($contact->image->url), dbesc(NETWORK_PUMPIO), intval(CONTACT_IS_FRIEND), intval(1), intval(1)); $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", dbesc($contact->url), intval($uid)); if (!count($r)) { return false; } $contact_id = $r[0]['id']; $g = q("select def_gid from user where uid = %d limit 1", intval($uid)); if ($g && intval($g[0]['def_gid'])) { require_once 'include/group.php'; group_add_member($uid, '', $contact_id, $g[0]['def_gid']); } if (DB_UPDATE_VERSION >= "1177") { q("UPDATE `contact` SET `location` = '%s',\n\t\t\t\t\t\t`about` = '%s'\n\t\t\t\t\tWHERE `id` = %d", dbesc($contact->location->displayName), dbesc($contact->summary), intval($contact_id)); } } else { $contact_id = $r[0]["id"]; /* if (DB_UPDATE_VERSION >= "1177") q("UPDATE `contact` SET `location` = '%s', `about` = '%s' WHERE `id` = %d", dbesc($contact->location->displayName), dbesc($contact->summary), intval($r[0]['id']) ); */ } if (function_exists("update_contact_avatar")) { update_contact_avatar($contact->image->url, $uid, $contact_id); } return $contact_id; }