1
1
Fork 0

Support for keywords and gender in (global) contacts.

This commit is contained in:
Michael Vogel 2015-01-25 13:19:37 +01:00
parent dff2384e82
commit 2f400627c7
6 changed files with 109 additions and 19 deletions

View file

@ -415,6 +415,8 @@ function db_definition() {
"nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"about" => array("type" => "text", "not null" => "1"), "about" => array("type" => "text", "not null" => "1"),
"keywords" => array("type" => "text", "not null" => "1"),
"gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"photo" => array("type" => "text", "not null" => "1"), "photo" => array("type" => "text", "not null" => "1"),
"thumb" => array("type" => "text", "not null" => "1"), "thumb" => array("type" => "text", "not null" => "1"),
@ -621,6 +623,8 @@ function db_definition() {
"updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"), "updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
"location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"about" => array("type" => "text", "not null" => "1"), "about" => array("type" => "text", "not null" => "1"),
"keywords" => array("type" => "text", "not null" => "1"),
"gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
), ),
"indexes" => array( "indexes" => array(

View file

@ -2252,7 +2252,19 @@ function diaspora_profile($importer,$xml,$msg) {
$birthday = unxmlify($xml->birthday); $birthday = unxmlify($xml->birthday);
$location = diaspora2bb(unxmlify($xml->location)); $location = diaspora2bb(unxmlify($xml->location));
$about = diaspora2bb(unxmlify($xml->bio)); $about = diaspora2bb(unxmlify($xml->bio));
$gender = unxmlify($xml->gender);
$tags = unxmlify($xml->tag_string);
$tags = explode("#", $tags);
$keywords = array();
foreach ($tags as $tag) {
$tag = trim(strtolower($tag));
if ($tag != "")
$keywords[] = $tag;
}
$keywords = implode(", ", $keywords);
$handle_parts = explode("@", $diaspora_handle); $handle_parts = explode("@", $diaspora_handle);
if($name === '') { if($name === '') {
@ -2288,7 +2300,7 @@ function diaspora_profile($importer,$xml,$msg) {
// TODO: update name on item['author-name'] if the name changed. See consume_feed() // 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. // 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' WHERE `id` = %d AND `uid` = %d", $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",
dbesc($name), dbesc($name),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($images[0]), dbesc($images[0]),
@ -2298,10 +2310,18 @@ function diaspora_profile($importer,$xml,$msg) {
dbesc($birthday), dbesc($birthday),
dbesc($location), dbesc($location),
dbesc($about), dbesc($about),
dbesc($keywords),
dbesc($gender),
intval($contact['id']), intval($contact['id']),
intval($importer['uid']) intval($importer['uid'])
); );
if (unxmlify($xml->searchable) == "true") {
require_once('include/socgraph.php');
poco_check($contact['url'], $name, NETWORK_DIASPORA, $images[0], $about, $location, $gender, $keywords, "",
datetime_convert(), $contact['id'], $importer['uid']);
}
$profileurl = ""; $profileurl = "";
$author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", $author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
dbesc(normalise_link($contact['url']))); dbesc(normalise_link($contact['url'])));

View file

@ -1380,7 +1380,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
// Contacts from the statusnet connector are also added since you could add them in OStatus as well. // Contacts from the statusnet connector are also added since you could add them in OStatus as well.
if (!$arr['private'] AND in_array($arr["network"], if (!$arr['private'] AND in_array($arr["network"],
array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_STATUSNET, ""))) { array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_STATUSNET, ""))) {
poco_check($arr["author-link"], $arr["author-name"], $arr["network"], $arr["author-avatar"], "", "", "", $arr["received"], $arr["contact-id"], $arr["uid"]); poco_check($arr["author-link"], $arr["author-name"], $arr["network"], $arr["author-avatar"], "", "", "", "", "", $arr["received"], $arr["contact-id"], $arr["uid"]);
// Maybe its a body with a shared item? Then extract a global contact from it. // Maybe its a body with a shared item? Then extract a global contact from it.
poco_contact_from_body($arr["body"], $arr["received"], $arr["contact-id"], $arr["uid"]); poco_contact_from_body($arr["body"], $arr["received"], $arr["contact-id"], $arr["uid"]);

View file

@ -39,7 +39,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
if(! $url) if(! $url)
return; return;
$url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation' : '?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation') ; $url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender' : '?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender') ;
logger('poco_load: ' . $url, LOGGER_DEBUG); logger('poco_load: ' . $url, LOGGER_DEBUG);
@ -71,6 +71,8 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
$updated = '0000-00-00 00:00:00'; $updated = '0000-00-00 00:00:00';
$location = ''; $location = '';
$about = ''; $about = '';
$keywords = '';
$gender = '';
$name = $entry->displayName; $name = $entry->displayName;
@ -107,13 +109,24 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
if(isset($entry->aboutMe)) if(isset($entry->aboutMe))
$about = $entry->aboutMe; $about = $entry->aboutMe;
poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $connect_url, $updated, $cid, $uid, $zcid); if(isset($entry->gender))
$gender = $entry->gender;
if (($location != "") OR ($about != "")) if(isset($entry->tags))
q("UPDATE `contact` SET `location` = '%s', `about` = '%s' WHERE `nurl` = '%s' AND NOT `self`", $keywords = implode(", ", $entry->tags);
poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $cid, $uid, $zcid);
// Update the Friendica contacts. Diaspora is doing it via a message. (See include/diaspora.php)
if (($location != "") OR ($about != "") OR ($keywords != "") OR ($gender != ""))
q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s'
WHERE `nurl` = '%s' AND NOT `self` AND `network` = '%s'",
dbesc($location), dbesc($location),
dbesc($about), dbesc($about),
dbesc(normalise_link($profile_url))); dbesc($keywords),
dbesc($gender),
dbesc(normalise_link($profile_url)),
dbesc(NETWORK_DFRN));
} }
logger("poco_load: loaded $total entries",LOGGER_DEBUG); logger("poco_load: loaded $total entries",LOGGER_DEBUG);
@ -126,7 +139,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
} }
function poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $connect_url, $updated, $cid = 0, $uid = 0, $zcid = 0) { function poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $cid = 0, $uid = 0, $zcid = 0) {
$gcid = ""; $gcid = "";
if ($profile_url == "") if ($profile_url == "")
@ -162,8 +175,15 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
if (($about == "") AND ($x[0]['about'] != "")) if (($about == "") AND ($x[0]['about'] != ""))
$about = $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($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) { if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) {
q("update gcontact set `name` = '%s', `network` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `updated` = '%s', `location` = '%s', `about` = '%s' q("update gcontact set `name` = '%s', `network` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s',
`updated` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s'
where `nurl` = '%s'", where `nurl` = '%s'",
dbesc($name), dbesc($name),
dbesc($network), dbesc($network),
@ -173,12 +193,14 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
dbesc($updated), dbesc($updated),
dbesc($location), dbesc($location),
dbesc($about), dbesc($about),
dbesc($keywords),
dbesc($gender),
dbesc(normalise_link($profile_url)) dbesc(normalise_link($profile_url))
); );
} }
} else { } else {
q("insert into `gcontact` (`name`,`network`, `url`,`nurl`,`photo`,`connect`, `updated`, `location`, `about`) q("insert into `gcontact` (`name`,`network`, `url`,`nurl`,`photo`,`connect`, `updated`, `location`, `about`, `keywords`, `gender`)
values ('%s', '%s', '%s', '%s', '%s','%s', '%s')", values ('%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s')",
dbesc($name), dbesc($name),
dbesc($network), dbesc($network),
dbesc($profile_url), dbesc($profile_url),
@ -187,7 +209,9 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
dbesc($connect_url), dbesc($connect_url),
dbesc($updated), dbesc($updated),
dbesc($location), dbesc($location),
dbesc($about) dbesc($about),
dbesc($keywords),
dbesc($gender)
); );
$x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
dbesc(normalise_link($profile_url)) dbesc(normalise_link($profile_url))
@ -254,7 +278,7 @@ function sub_poco_from_share($share, $created, $cid, $uid) {
return; return;
logger("prepare poco_check for profile ".$profile, LOGGER_DEBUG); logger("prepare poco_check for profile ".$profile, LOGGER_DEBUG);
poco_check($profile, "", "", "", "", "", "", $created, $cid, $uid); poco_check($profile, "", "", "", "", "", "", "", "", $created, $cid, $uid);
} }
function count_common_friends($uid,$cid) { function count_common_friends($uid,$cid) {

View file

@ -83,8 +83,9 @@ function poco_init(&$a) {
if($system_mode) { if($system_mode) {
$r = q("SELECT `contact`.*, `profile`.`about` AS `pabout`, `profile`.`locality` AS `plocation` FROM `contact` INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid` $r = q("SELECT `contact`.*, `profile`.`about` AS `pabout`, `profile`.`locality` AS `plocation`, `profile`.`pub_keywords`, `profile`.`gender` AS `pgender`
WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '') FROM `contact` INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid`
WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '') AND `profile`.`is-default`
AND `contact`.`uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d", AND `contact`.`uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d",
dbesc(NETWORK_DFRN), dbesc(NETWORK_DFRN),
dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DIASPORA),
@ -129,7 +130,9 @@ function poco_init(&$a) {
'photos' => false, 'photos' => false,
'aboutMe' => false, 'aboutMe' => false,
'currentLocation' => false, 'currentLocation' => false,
'network' => false 'network' => false,
'gender' => false,
'tags' => false
); );
if((! x($_GET,'fields')) || ($_GET['fields'] === '@all')) if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
@ -150,6 +153,12 @@ function poco_init(&$a) {
if (($rr['location'] == "") AND isset($rr['plocation'])) if (($rr['location'] == "") AND isset($rr['plocation']))
$rr['location'] = $rr['plocation']; $rr['location'] = $rr['plocation'];
if (($rr['gender'] == "") AND isset($rr['pgender']))
$rr['gender'] = $rr['pgender'];
if (($rr['keywords'] == "") AND isset($rr['pub_keywords']))
$rr['keywords'] = $rr['pub_keywords'];
$entry = array(); $entry = array();
if($fields_ret['id']) if($fields_ret['id'])
$entry['id'] = $rr['id']; $entry['id'] = $rr['id'];
@ -159,6 +168,8 @@ function poco_init(&$a) {
$entry['aboutMe'] = bbcode($rr['about'], false, false); $entry['aboutMe'] = bbcode($rr['about'], false, false);
if($fields_ret['currentLocation']) if($fields_ret['currentLocation'])
$entry['currentLocation'] = $rr['location']; $entry['currentLocation'] = $rr['location'];
if($fields_ret['gender'])
$entry['gender'] = $rr['gender'];
if($fields_ret['urls']) { if($fields_ret['urls']) {
$entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile')); $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL)) if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
@ -189,6 +200,20 @@ function poco_init(&$a) {
if (($entry['network'] == "") AND ($rr['self'])) if (($entry['network'] == "") AND ($rr['self']))
$entry['network'] = NETWORK_DFRN; $entry['network'] = NETWORK_DFRN;
} }
if($fields_ret['tags']) {
$tags = str_replace(","," ",$rr['keywords']);
$tags = explode(" ", $tags);
$cleaned = array();
foreach ($tags as $tag) {
$tag = trim(strtolower($tag));
if ($tag != "")
$cleaned[] = $tag;
}
$entry['tags'] = array($cleaned);
}
$ret['entry'][] = $entry; $ret['entry'][] = $entry;
} }
} }

View file

@ -142,6 +142,22 @@ function profiles_init(&$a) {
} }
function profile_clean_keywords($keywords) {
$keywords = str_replace(","," ",$keywords);
$keywords = explode(" ", $keywords);
$cleaned = array();
foreach ($keywords as $keyword) {
$keyword = trim(strtolower($keyword));
if ($keyword != "")
$cleaned[] = $keyword;
}
$keywords = implode(", ", $cleaned);
return $keywords;
}
function profiles_post(&$a) { function profiles_post(&$a) {
if(! local_user()) { if(! local_user()) {
@ -212,8 +228,8 @@ function profiles_post(&$a) {
$region = notags(trim($_POST['region'])); $region = notags(trim($_POST['region']));
$postal_code = notags(trim($_POST['postal_code'])); $postal_code = notags(trim($_POST['postal_code']));
$country_name = notags(trim($_POST['country_name'])); $country_name = notags(trim($_POST['country_name']));
$pub_keywords = notags(trim($_POST['pub_keywords'])); $pub_keywords = profile_clean_keywords(notags(trim($_POST['pub_keywords'])));
$prv_keywords = notags(trim($_POST['prv_keywords'])); $prv_keywords = profile_clean_keywords(notags(trim($_POST['prv_keywords'])));
$marital = notags(trim($_POST['marital'])); $marital = notags(trim($_POST['marital']));
$howlong = notags(trim($_POST['howlong'])); $howlong = notags(trim($_POST['howlong']));
@ -469,9 +485,10 @@ function profiles_post(&$a) {
if($is_default) { if($is_default) {
$r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s' WHERE `self` = 1 AND `uid` = %d", $r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s' WHERE `self` = 1 AND `uid` = %d",
dbesc($about), dbesc($about),
dbesc($locality), dbesc($locality),
dbesc($pub_keywords),
intval(local_user()) intval(local_user())
); );