- if(count($x)) {
- $gcid = $x[0]['id'];
-
- if (($location == "") AND ($x[0]['location'] != ""))
- $location = $x[0]['location'];
-
- if (($about == "") AND ($x[0]['about'] != ""))
- $about = $x[0]['about'];
-
- if (($gender == "") AND ($x[0]['gender'] != ""))
- $gender = $x[0]['gender'];
-
- if (($keywords == "") AND ($x[0]['keywords'] != ""))
- $keywords = $x[0]['keywords'];
-
- if (($addr == "") AND ($x[0]['addr'] != ""))
- $addr = $x[0]['addr'];
-
- if (($alias == "") AND ($x[0]['alias'] != ""))
- $alias = $x[0]['alias'];
-
- if (($notify == "") AND ($x[0]['notify'] != ""))
- $notify = $x[0]['notify'];
-
- if (($generation == 0) AND ($x[0]['generation'] > 0))
- $generation = $x[0]['generation'];
-
- if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) {
- q("UPDATE `gcontact` SET `name` = '%s', `addr` = '%s', `network` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `server_url` = '%s',
- `updated` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s', `generation` = %d,
- `alias` = '$s', `notify` = '%s'
- WHERE (`generation` >= %d OR `generation` = 0) AND `nurl` = '%s'",
- dbesc($name),
- dbesc($addr),
- dbesc($network),
- dbesc($profile_photo),
- dbesc($connect_url),
- dbesc($profile_url),
- dbesc($server_url),
- dbesc($updated),
- dbesc($location),
- dbesc($about),
- dbesc($keywords),
- dbesc($gender),
- dbesc($alias),
- dbesc($notify),
- intval($generation),
- intval($generation),
- dbesc(normalise_link($profile_url))
- );
- }
- } else {
- // Maybe another process had inserted the entry after the first check, so it again
- $x = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
- dbesc(normalise_link($profile_url))
- );
- if(!$x) {
- q("INSERT INTO `gcontact` (`name`, `nick`, `addr`, `network`, `url`, `nurl`, `photo`, `connect`, `server_url`, `created`, `updated`, `location`, `about`, `keywords`, `gender`, `alias`, `notify`, `generation`)
- VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
- dbesc($name),
- dbesc($nick),
- dbesc($addr),
- dbesc($network),
- dbesc($profile_url),
- dbesc(normalise_link($profile_url)),
- dbesc($profile_photo),
- dbesc($connect_url),
- dbesc($server_url),
- dbesc(datetime_convert()),
- dbesc($updated),
- dbesc($location),
- dbesc($about),
- dbesc($keywords),
- dbesc($gender),
- dbesc($alias),
- dbesc($notify),
- intval($generation)
- );
- $x = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
- dbesc(normalise_link($profile_url))
- );
- }
- if(count($x))
- $gcid = $x[0]['id'];
- }
-
- if(! $gcid)
+ $gcontact = array("url" => $profile_url,
+ "addr" => $addr,
+ "alias" => $alias,
+ "name" => $name,
+ "network" => $network,
+ "photo" => $profile_photo,
+ "about" => $about,
+ "location" => $location,
+ "gender" => $gender,
+ "keywords" => $keywords,
+ "server_url" => $server_url,
+ "connect" => $connect_url,
+ "notify" => $notify,
+ "updated" => $updated,
+ "generation" => $generation);
+
+ $gcid = update_gcontact($gcontact);
+
+ if(!$gcid)