`keywords` text NOT NULL,
`gender` varchar(32) NOT NULL DEFAULT '',
`community` tinyint(1) NOT NULL DEFAULT 0,
+ `hide` tinyint(1) NOT NULL DEFAULT 0,
+ `nsfw` tinyint(1) NOT NULL DEFAULT 0,
`network` varchar(255) NOT NULL DEFAULT '',
`addr` varchar(255) NOT NULL DEFAULT '',
`generation` tinyint(3) NOT NULL DEFAULT 0,
INDEX `uid_thrparent` (`uid`,`thr-parent`),
INDEX `uid_parenturi` (`uid`,`parent-uri`),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
+ INDEX `uid_gcontactid_created` (`uid`,`gcontact-id`,`created`),
INDEX `wall_body` (`wall`,`body`(6)),
INDEX `uid_visible_moderated_created` (`uid`,`visible`,`moderated`,`created`),
INDEX `uid_uri` (`uid`,`uri`),
"about" => array("type" => "text", "not null" => "1"),
"keywords" => array("type" => "text", "not null" => "1"),
"gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
+ "birthday" => array("type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00"),
"community" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
+ "hide" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
+ "nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
if(! $contact)
return;
- if($contact['blocked']) {
- logger('diaspora_post: Ignoring this author.');
- return 202;
- }
+ //if($contact['blocked']) {
+ // logger('diaspora_post: Ignoring this author.');
+ // return 202;
+ //}
$name = unxmlify($xml->first_name) . ((strlen($xml->last_name)) ? ' ' . unxmlify($xml->last_name) : '');
$image_url = unxmlify($xml->image_url);
$location = diaspora2bb(unxmlify($xml->location));
$about = diaspora2bb(unxmlify($xml->bio));
$gender = unxmlify($xml->gender);
+ $searchable = (unxmlify($xml->searchable) == "true");
+ $nsfw = (unxmlify($xml->nsfw) == "true");
$tags = unxmlify($xml->tag_string);
$tags = explode("#", $tags);
$keywords = implode(", ", $keywords);
$handle_parts = explode("@", $diaspora_handle);
+ $nick = $handle_parts[0];
+
if($name === '') {
$name = $handle_parts[0];
}
/// @TODO Update name on item['author-name'] if the name changed. See consume_feed()
/// (Not doing this currently because D* protocol is scheduled for revision soon).
- $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d",
+ $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc($name),
+ dbesc($nick),
+ dbesc($diaspora_handle),
dbesc(datetime_convert()),
- dbesc($images[0]),
+ dbesc($image_url),
dbesc($images[1]),
dbesc($images[2]),
dbesc(datetime_convert()),
intval($importer['uid'])
);
- if (unxmlify($xml->searchable) == "true") {
+ if ($searchable) {
require_once('include/socgraph.php');
- poco_check($contact['url'], $name, NETWORK_DIASPORA, $images[0], $about, $location, $gender, $keywords, "",
+ poco_check($contact['url'], $name, NETWORK_DIASPORA, $image_url, $about, $location, $gender, $keywords, "",
datetime_convert(), 2, $contact['id'], $importer['uid']);
}
- // @todo:
- /*
- update_gcontact($contact["url"], $contact["network"],
- $author["author-avatar"], $contact["name"],
- $contact["nick"], $contact["location"],
- $contact["about"]);
- */
-
- $profileurl = "";
- $author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
- dbesc(normalise_link($contact['url'])));
-
- if (count($author) == 0) {
- q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`, `location`, `about`) VALUES ('%s', '%s', '%s', '%s', '%s')",
- dbesc(normalise_link($contact['url'])), dbesc($name), dbesc($location), dbesc($about), dbesc($images[0]));
-
- $author = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
- dbesc(normalise_link($contact['url'])));
- } else if (normalise_link($contact['url']).$name.$location.$about != normalise_link($author[0]["url"]).$author[0]["name"].$author[0]["location"].$author[0]["about"]) {
- q("UPDATE unique_contacts SET name = '%s', avatar = '%s', `location` = '%s', `about` = '%s' WHERE url = '%s'",
- dbesc($name), dbesc($images[0]), dbesc($location), dbesc($about), dbesc(normalise_link($contact['url'])));
- }
+ update_gcontact(array("url" => $contact['url'], "network" => NETWORK_DIASPORA, "generation" => 2,
+ "photo" => $image_url, "name" => $name, "location" => $location,
+ "about" => $about, "birthday" => $birthday, "gender" => $gender,
+ "addr" => $diaspora_handle, "nick" => $nick, "keywords" => $keywords,
+ "hide" => !$searchable, "nsfw" => $nsfw));
/* if($r) {
if($oldphotos) {
}
if ($arr["gcontact-id"] == 0)
- $arr["gcontact-id"] = get_gcontact_id($arr['author-link'], $arr['network'], $arr['author-avatar'], $arr['author-name']);
+ $arr["gcontact-id"] = get_gcontact_id(array("url" => $arr['author-link'], "network" => $arr['network'],
+ "photo" => $arr['author-avatar'], "name" => $arr['author-name']));
if ($arr['guid'] != "") {
// Checking if there is already an item with the same guid
}
// @todo: Addr
- update_gcontact($contact["url"], $contact["network"],
- $author["author-avatar"], $contact["name"],
- $contact["nick"], $contact["location"],
- $contact["about"]);
+ update_gcontact(array("url" => $contact["url"], "network" => $contact["network"],
+ "photo" => $author["author-avatar"], "name" => $contact["name"],
+ "nick" => $contact["nick"], "location" => $contact["location"],
+ "about" => $contact["about"], "generation" => 2));
}
return($author);
return $success;
}
-function get_gcontact_id($url, $network, $avatar = "", $name = "", $nick = "", $location = "", $about = "", $addr = "") {
+function get_gcontact_id($contact) {
$gcontact_id = 0;
- if ($network == NETWORK_STATUSNET)
- $network = NETWORK_OSTATUS;
+ if ($contact["network"] == NETWORK_STATUSNET)
+ $contact["network"] = NETWORK_OSTATUS;
- $r = q("SELECT `id`, `name`, `nick`, `network`, `photo`, `location`, `about` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
- dbesc(normalise_link($url)));
+ $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
+ dbesc(normalise_link($contact["url"])));
if ($r)
$gcontact_id = $r[0]["id"];
else {
- q("INSERT INTO `gcontact` (`name`, `nick`, `addr` , `network`, `url`, `nurl`, `photo`, `created`, `updated`, `location`, `about`)
- VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
- dbesc($name),
- dbesc($nick),
- dbesc($addr),
- dbesc($network),
- dbesc($url),
- dbesc(normalise_link($url)),
- dbesc($avatar),
+ q("INSERT INTO `gcontact` (`name`, `nick`, `addr` , `network`, `url`, `nurl`, `photo`, `created`, `updated`, `location`, `about`, `generation`)
+ VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
+ dbesc($contact["name"]),
+ dbesc($contact["nick"]),
+ dbesc($contact["addr"]),
+ dbesc($contact["network"]),
+ dbesc($contact["url"]),
+ dbesc(normalise_link($contact["url"])),
+ dbesc($contact["photo"]),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
- dbesc($location),
- dbesc($about)
+ dbesc($contact["location"]),
+ dbesc($contact["about"]),
+ intval($contact["generation"])
);
- $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($url)));
+ $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
+ dbesc(normalise_link($contact["url"])));
if ($r)
$gcontact_id = $r[0]["id"];
return $gcontact_id;
}
-function update_gcontact($url, $network, $avatar = "", $name = "", $nick = "", $location = "", $about = "", $addr = "") {
-
- if ($network == NETWORK_STATUSNET)
- $network = NETWORK_OSTATUS;
+function update_gcontact($contact) {
- $gcontact_id = get_gcontact_id($url, $network, $avatar, $name, $nick, $location, $about);
+ $gcontact_id = get_gcontact_id($contact);
if (!$gcontact_id)
return false;
- if (($avatar != $r[0]["photo"]) AND ($avatar != ""))
- q("UPDATE `gcontact` SET `photo` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `photo` = '')",
- dbesc($avatar), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network));
+ $r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, `hide`, `nsfw`
+ FROM `gcontact` WHERE `id` = %d LIMIT 1",
+ intval($gcontact_id));
+
+ if ($contact["generation"] == 0)
+ $contact["generation"] = $r[0]["generation"];
+
+ if ($contact["photo"] == "")
+ $contact["photo"] = $r[0]["photo"];
+
+ if ($contact["name"] == "")
+ $contact["name"] = $r[0]["name"];
+
+ if ($contact["nick"] == "")
+ $contact["nick"] = $r[0]["nick"];
- if (($name != $r[0]["name"]) AND ($name != ""))
- q("UPDATE `gcontact` SET `name` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `name` = '')",
- dbesc($name), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network));
+ if ($contact["addr"] == "")
+ $contact["addr"] = $r[0]["addr"];
- if (($nick != $r[0]["nick"]) AND ($nick != ""))
- q("UPDATE `gcontact` SET `nick` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `nick` = '')",
- dbesc($nick), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network));
+ if ($contact["location"] =="")
+ $contact["location"] = $r[0]["location"];
- if (($addr != $r[0]["addr"]) AND ($nick != ""))
- q("UPDATE `gcontact` SET `addr` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `addr` = '')",
- dbesc($addr), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network));
+ if ($contact["about"] =="")
+ $contact["about"] = $r[0]["about"];
- if (($location != $r[0]["location"]) AND ($location != ""))
- q("UPDATE `gcontact` SET `location` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `location` = '')",
- dbesc($location), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network));
+ if ($contact["birthday"] =="")
+ $contact["birthday"] = $r[0]["birthday"];
- if (($about != $r[0]["about"]) AND ($about != ""))
- q("UPDATE `gcontact` SET `about` = '%s', `updated` = '%s' WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `about` = '')",
- dbesc($about), dbesc(datetime_convert()), dbesc(normalise_link($url)), dbesc($network));
+ if ($contact["gender"] =="")
+ $contact["gender"] = $r[0]["gender"];
+
+ if ($contact["keywords"] =="")
+ $contact["keywords"] = $r[0]["keywords"];
+
+ if (!isset($contact["hide"]))
+ $contact["hide"] = $r[0]["hide"];
+
+ if (!isset($contact["nsfw"]))
+ $contact["nsfw"] = $r[0]["nsfw"];
+
+ if ($contact["network"] == NETWORK_STATUSNET)
+ $contact["network"] = NETWORK_OSTATUS;
+
+ if (($contact["photo"] != $r[0]["photo"]) OR ($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["addr"] != $r[0]["addr"]) OR
+ ($contact["birthday"] != $r[0]["birthday"]) OR ($contact["gender"] != $r[0]["gender"]) OR ($contact["keywords"] != $r[0]["keywords"]) OR
+ ($contact["hide"] != $r[0]["hide"]) OR ($contact["nsfw"] != $r[0]["nsfw"]) OR
+ ($contact["location"] != $r[0]["location"]) OR ($contact["about"] != $r[0]["about"]) OR ($contact["generation"] < $r[0]["generation"])) {
+
+ q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s',
+ `birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d,
+ `location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s'
+ WHERE `nurl` = '%s' AND `network` = '%s' AND (`generation` = 0 OR `generation` >= %d)",
+ dbesc($contact["photo"]), dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["addr"]),
+ dbesc($contact["birthday"]), dbesc($contact["gender"]), dbesc($contact["keywords"]),
+ intval($contact["hide"]), intval($contact["nsfw"]),
+ dbesc($contact["location"]), dbesc($contact["about"]), intval($contact["generation"]), dbesc(datetime_convert()),
+ dbesc(normalise_link($contact["url"])), dbesc($contact["network"]), intval($contact["generation"]));
+ }
return $gcontact_id;
}
else
$ostatus = NETWORK_DFRN;
- $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
- (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
- `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
+ $count = q("SELECT count(*) AS `total` FROM `gcontact`
+ LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
+ AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
+ AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
+ WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
+ ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
+ (`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
+ `gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql",
+ intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
dbesc(escape_tags($search)), dbesc(escape_tags($search)));
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
- WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
- ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
+ WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
+ ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
(`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
`gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
GROUP BY `gcontact`.`nurl`
$datarray['postopts'] = $postopts;
$datarray['origin'] = $origin;
$datarray['moderated'] = $allow_moderated;
- $datarray['gcontact-id'] = get_gcontact_id($datarray['author-link'], $datarray['network'],
- $datarray['author-avatar'], $datarray['author-name']);
-
+ $datarray['gcontact-id'] = get_gcontact_id(array("url" => $datarray['author-link'], "network" => $datarray['network'],
+ "photo" => $datarray['author-avatar'], "name" => $datarray['author-name']));
/**
* These fields are for the convenience of plugins...
* 'self' if true indicates the owner is posting on their own wall
$update_limit = date("Y-m-d H:i:s",strtotime($_GET['updatedSince']));
if ($global) {
- //$r = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND `network` IN ('%s')",
- $r = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND `updated` >= `last_failure` AND `network` IN ('%s', '%s', '%s')",
+ $r = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND `updated` >= `last_failure` AND NOT `hide` AND `network` IN ('%s', '%s', '%s')",
dbesc($update_limit),
dbesc(NETWORK_DFRN),
dbesc(NETWORK_DIASPORA),
if ($global) {
logger("Start global query", LOGGER_DEBUG);
- //$r = q("SELECT * FROM `gcontact` WHERE `updated` > '%s' AND `network` IN ('%s') AND ((`last_contact` >= `last_failure`) OR (`updated` > `last_failure`)) LIMIT %d, %d",
- $r = q("SELECT * FROM `gcontact` WHERE `updated` > '%s' AND `network` IN ('%s', '%s', '%s') AND `updated` > `last_failure`
+ $r = q("SELECT * FROM `gcontact` WHERE `updated` > '%s' AND NOT `hide` AND `network` IN ('%s', '%s', '%s') AND `updated` > `last_failure`
ORDER BY `updated` DESC LIMIT %d, %d",
dbesc($update_limit),
dbesc(NETWORK_DFRN),