The global contacts now contain the network name so that the suggestions can select between this.

This commit is contained in:
Michael Vogel 2015-01-08 07:59:20 +01:00
parent 46db8575a0
commit 8f1cfac20a
5 changed files with 59 additions and 25 deletions

View file

@ -619,6 +619,7 @@ function db_definition() {
"photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"), "updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"),
"network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("id"), "PRIMARY" => array("id"),

View file

@ -1348,7 +1348,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["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']);
// Set "success_update" to the date of the last time we heard from this contact // Set "success_update" to the date of the last time we heard from this contact
// This can be used to filter for inactive contacts and poco. // This can be used to filter for inactive contacts and poco.

View file

@ -12,10 +12,10 @@ require_once('include/datetime.php');
* *
* Once the global contact is stored add (if necessary) the contact linkage which associates * Once the global contact is stored add (if necessary) the contact linkage which associates
* the given uid, cid to the global contact entry. There can be many uid/cid combinations * the given uid, cid to the global contact entry. There can be many uid/cid combinations
* pointing to the same global contact id. * pointing to the same global contact id.
* *
*/ */
@ -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' : '?fields=displayName,urls,photos,updated') ; $url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos,updated,network' : '?fields=displayName,urls,photos,updated,network') ;
logger('poco_load: ' . $url, LOGGER_DEBUG); logger('poco_load: ' . $url, LOGGER_DEBUG);
@ -67,6 +67,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
$profile_photo = ''; $profile_photo = '';
$connect_url = ''; $connect_url = '';
$name = ''; $name = '';
$network = '';
$updated = '0000-00-00 00:00:00'; $updated = '0000-00-00 00:00:00';
$name = $entry->displayName; $name = $entry->displayName;
@ -95,7 +96,10 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
if(isset($entry->updated)) if(isset($entry->updated))
$updated = date("Y-m-d H:i:s", strtotime($entry->updated)); $updated = date("Y-m-d H:i:s", strtotime($entry->updated));
poco_check($profile_url, $name, $profile_photo, $connect_url, $updated, $cid, $uid, $zcid); if(isset($entry->network))
$network = $entry->network;
poco_check($profile_url, $name, $network, $profile_photo, $connect_url, $updated, $cid, $uid, $zcid);
} }
logger("poco_load: loaded $total entries",LOGGER_DEBUG); logger("poco_load: loaded $total entries",LOGGER_DEBUG);
@ -108,7 +112,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
} }
function poco_check($profile_url, $name, $profile_photo, $connect_url, $updated, $cid = 0, $uid = 0, $zcid = 0) { function poco_check($profile_url, $name, $network, $profile_photo, $connect_url, $updated, $cid = 0, $uid = 0, $zcid = 0) {
$gcid = ""; $gcid = "";
if (($profile_url == "") OR ($name == "") OR ($profile_photo == "")) if (($profile_url == "") OR ($name == "") OR ($profile_photo == ""))
@ -124,9 +128,10 @@ function poco_check($profile_url, $name, $profile_photo, $connect_url, $updated,
$gcid = $x[0]['id']; $gcid = $x[0]['id'];
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', `photo` = '%s', `connect` = '%s', `url` = '%s', `updated` = '%s' q("update gcontact set `name` = '%s', `network` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `updated` = '%s'
where `nurl` = '%s'", where `nurl` = '%s'",
dbesc($name), dbesc($name),
dbesc($network),
dbesc($profile_photo), dbesc($profile_photo),
dbesc($connect_url), dbesc($connect_url),
dbesc($profile_url), dbesc($profile_url),
@ -135,9 +140,10 @@ function poco_check($profile_url, $name, $profile_photo, $connect_url, $updated,
); );
} }
} else { } else {
q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`, `updated`) q("insert into `gcontact` (`name`,`network`, `url`,`nurl`,`photo`,`connect`, `updated`)
values ('%s', '%s', '%s', '%s','%s', '%s')", values ('%s', '%s', '%s', '%s', '%s','%s', '%s')",
dbesc($name), dbesc($name),
dbesc($network),
dbesc($profile_url), dbesc($profile_url),
dbesc(normalise_link($profile_url)), dbesc(normalise_link($profile_url)),
dbesc($profile_photo), dbesc($profile_photo),
@ -213,9 +219,9 @@ function common_friends($uid,$cid,$start = 0,$limit=9999,$shuffle = false) {
if($shuffle) if($shuffle)
$sql_extra = " order by rand() "; $sql_extra = " order by rand() ";
else else
$sql_extra = " order by `gcontact`.`name` asc "; $sql_extra = " order by `gcontact`.`name` asc ";
$r = q("SELECT `gcontact`.* $r = q("SELECT `gcontact`.*
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
where `glink`.`cid` = %d and `glink`.`uid` = %d where `glink`.`cid` = %d and `glink`.`uid` = %d
and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 and id != %d ) and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 and id != %d )
@ -235,7 +241,7 @@ function common_friends($uid,$cid,$start = 0,$limit=9999,$shuffle = false) {
function count_common_friends_zcid($uid,$zcid) { function count_common_friends_zcid($uid,$zcid) {
$r = q("SELECT count(*) as `total` $r = q("SELECT count(*) as `total`
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
where `glink`.`zcid` = %d where `glink`.`zcid` = %d
and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) ", and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) ",
@ -254,9 +260,9 @@ function common_friends_zcid($uid,$zcid,$start = 0, $limit = 9999,$shuffle = fal
if($shuffle) if($shuffle)
$sql_extra = " order by rand() "; $sql_extra = " order by rand() ";
else else
$sql_extra = " order by `gcontact`.`name` asc "; $sql_extra = " order by `gcontact`.`name` asc ";
$r = q("SELECT `gcontact`.* $r = q("SELECT `gcontact`.*
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
where `glink`.`zcid` = %d where `glink`.`zcid` = %d
and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 ) and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 )
@ -290,9 +296,9 @@ function count_all_friends($uid,$cid) {
function all_friends($uid,$cid,$start = 0, $limit = 80) { function all_friends($uid,$cid,$start = 0, $limit = 80) {
$r = q("SELECT `gcontact`.* $r = q("SELECT `gcontact`.*
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id` FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
where `glink`.`cid` = %d and `glink`.`uid` = %d where `glink`.`cid` = %d and `glink`.`uid` = %d
order by `gcontact`.`name` asc LIMIT %d, %d ", order by `gcontact`.`name` asc LIMIT %d, %d ",
intval($cid), intval($cid),
intval($uid), intval($uid),
@ -310,17 +316,30 @@ function suggestion_query($uid, $start = 0, $limit = 80) {
if(! $uid) if(! $uid)
return array(); return array();
$network = array("", NETWORK_DFRN);
if (get_config('system','diaspora_enabled'))
$network[] = NETWORK_DIASPORA;
if (!get_config('system','ostatus_disabled'))
$network[] = NETWORK_OSTATUS;
$sql_network = implode("', '", $network);
$sql_network = substr($sql_network, 2)."', ''";
$r = q("SELECT count(glink.gcid) as `total`, gcontact.* from gcontact $r = q("SELECT count(glink.gcid) as `total`, gcontact.* from gcontact
INNER JOIN glink on glink.gcid = gcontact.id INNER JOIN glink on glink.gcid = gcontact.id
where uid = %d and not gcontact.nurl in ( select nurl from contact where uid = %d ) where uid = %d and not gcontact.nurl in ( select nurl from contact where uid = %d )
and not gcontact.name in ( select name from contact where uid = %d ) and not gcontact.name in ( select name from contact where uid = %d )
and not gcontact.id in ( select gcid from gcign where uid = %d ) and not gcontact.id in ( select gcid from gcign where uid = %d )
AND `gcontact`.`updated` != '0000-00-00 00:00:00' AND `gcontact`.`updated` != '0000-00-00 00:00:00'
AND `gcontact`.`network` IN (%s)
group by glink.gcid order by gcontact.updated desc,total desc limit %d, %d ", group by glink.gcid order by gcontact.updated desc,total desc limit %d, %d ",
intval($uid), intval($uid),
intval($uid), intval($uid),
intval($uid), intval($uid),
intval($uid), intval($uid),
$sql_network,
intval($start), intval($start),
intval($limit) intval($limit)
); );
@ -334,10 +353,12 @@ function suggestion_query($uid, $start = 0, $limit = 80) {
and not gcontact.name in ( select name from contact where uid = %d ) and not gcontact.name in ( select name from contact where uid = %d )
and not gcontact.id in ( select gcid from gcign where uid = %d ) and not gcontact.id in ( select gcid from gcign where uid = %d )
AND `gcontact`.`updated` != '0000-00-00 00:00:00' AND `gcontact`.`updated` != '0000-00-00 00:00:00'
AND `gcontact`.`network` IN (%s)
order by rand() limit %d, %d ", order by rand() limit %d, %d ",
intval($uid), intval($uid),
intval($uid), intval($uid),
intval($uid), intval($uid),
$sql_network,
intval($start), intval($start),
intval($limit) intval($limit)
); );

View file

@ -52,20 +52,22 @@ function poco_init(&$a) {
$sql_extra = sprintf(" AND `contact`.`id` = %d ",intval($cid)); $sql_extra = sprintf(" AND `contact`.`id` = %d ",intval($cid));
if($system_mode) { if($system_mode) {
$r = q("SELECT count(*) AS `total` FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '') $r = q("SELECT count(*) AS `total` FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '')
AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) ", AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) ",
dbesc(NETWORK_DFRN), dbesc(NETWORK_DFRN),
dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DIASPORA),
dbesc(NETWORK_OSTATUS) dbesc(NETWORK_OSTATUS),
dbesc(NETWORK_STATUSNET)
); );
} }
else { else {
$r = q("SELECT count(*) AS `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 $r = q("SELECT count(*) AS `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
AND `network` IN ('%s', '%s', '%s', '') $sql_extra", AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra",
intval($user['uid']), intval($user['uid']),
dbesc(NETWORK_DFRN), dbesc(NETWORK_DFRN),
dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DIASPORA),
dbesc(NETWORK_OSTATUS) dbesc(NETWORK_OSTATUS),
dbesc(NETWORK_STATUSNET)
); );
} }
if(count($r)) if(count($r))
@ -80,22 +82,24 @@ function poco_init(&$a) {
if($system_mode) { if($system_mode) {
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '') $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '')
AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d", AND `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),
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),
dbesc(NETWORK_STATUSNET),
intval($startIndex), intval($startIndex),
intval($itemsPerPage) intval($itemsPerPage)
); );
} }
else { else {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
AND `network` IN ('%s', '%s', '%s', '') $sql_extra LIMIT %d, %d", AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra LIMIT %d, %d",
intval($user['uid']), intval($user['uid']),
dbesc(NETWORK_DFRN), dbesc(NETWORK_DFRN),
dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DIASPORA),
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),
dbesc(NETWORK_STATUSNET),
intval($startIndex), intval($startIndex),
intval($itemsPerPage) intval($itemsPerPage)
); );
@ -120,7 +124,8 @@ function poco_init(&$a) {
'urls' => false, 'urls' => false,
'updated' => false, 'updated' => false,
'preferredUsername' => false, 'preferredUsername' => false,
'photos' => false 'photos' => false,
'network' => false
); );
if((! x($_GET,'fields')) || ($_GET['fields'] === '@all')) if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
@ -163,6 +168,11 @@ function poco_init(&$a) {
} }
if($fields_ret['photos']) if($fields_ret['photos'])
$entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile')); $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
if($fields_ret['network']) {
$entry['network'] = $rr['network'];
if ($entry['network'] == NETWORK_STATUSNET)
$entry['network'] = NETWORK_OSTATUS;
}
$ret['entry'][] = $entry; $ret['entry'][] = $entry;
} }
} }

View file

@ -44,13 +44,15 @@ function suggest_init(&$a) {
} }
} }
function suggest_content(&$a) { function suggest_content(&$a) {
require_once("mod/proxy.php");
$o = ''; $o = '';
if(! local_user()) { if(! local_user()) {
notice( t('Permission denied.') . EOL); notice( t('Permission denied.') . EOL);
@ -82,7 +84,7 @@ function suggest_content(&$a) {
$o .= replace_macros($tpl,array( $o .= replace_macros($tpl,array(
'$url' => zrl($rr['url']), '$url' => zrl($rr['url']),
'$name' => $rr['name'], '$name' => $rr['name'],
'$photo' => $rr['photo'], '$photo' => proxy_url($rr['photo']),
'$ignlnk' => $a->get_baseurl() . '/suggest?ignore=' . $rr['id'], '$ignlnk' => $a->get_baseurl() . '/suggest?ignore=' . $rr['id'],
'$ignid' => $rr['id'], '$ignid' => $rr['id'],
'$conntxt' => t('Connect'), '$conntxt' => t('Connect'),