The global contacts now contain the network name so that the suggestions can select between this.
This commit is contained in:
parent
46db8575a0
commit
8f1cfac20a
5 changed files with 59 additions and 25 deletions
|
@ -619,6 +619,7 @@ function db_definition() {
|
|||
"photo" => 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"),
|
||||
"network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
|
|
|
@ -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.
|
||||
if (!$arr['private'] AND in_array($arr["network"],
|
||||
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
|
||||
// This can be used to filter for inactive contacts and poco.
|
||||
|
|
|
@ -39,7 +39,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
if(! $url)
|
||||
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);
|
||||
|
||||
|
@ -67,6 +67,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
$profile_photo = '';
|
||||
$connect_url = '';
|
||||
$name = '';
|
||||
$network = '';
|
||||
$updated = '0000-00-00 00:00:00';
|
||||
|
||||
$name = $entry->displayName;
|
||||
|
@ -95,7 +96,10 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
if(isset($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);
|
||||
|
@ -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 = "";
|
||||
|
||||
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'];
|
||||
|
||||
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'",
|
||||
dbesc($name),
|
||||
dbesc($network),
|
||||
dbesc($profile_photo),
|
||||
dbesc($connect_url),
|
||||
dbesc($profile_url),
|
||||
|
@ -135,9 +140,10 @@ function poco_check($profile_url, $name, $profile_photo, $connect_url, $updated,
|
|||
);
|
||||
}
|
||||
} else {
|
||||
q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`, `updated`)
|
||||
values ('%s', '%s', '%s', '%s','%s', '%s')",
|
||||
q("insert into `gcontact` (`name`,`network`, `url`,`nurl`,`photo`,`connect`, `updated`)
|
||||
values ('%s', '%s', '%s', '%s', '%s','%s', '%s')",
|
||||
dbesc($name),
|
||||
dbesc($network),
|
||||
dbesc($profile_url),
|
||||
dbesc(normalise_link($profile_url)),
|
||||
dbesc($profile_photo),
|
||||
|
@ -310,17 +316,30 @@ function suggestion_query($uid, $start = 0, $limit = 80) {
|
|||
if(! $uid)
|
||||
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
|
||||
INNER JOIN glink on glink.gcid = gcontact.id
|
||||
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.id in ( select gcid from gcign where uid = %d )
|
||||
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 ",
|
||||
intval($uid),
|
||||
intval($uid),
|
||||
intval($uid),
|
||||
intval($uid),
|
||||
$sql_network,
|
||||
intval($start),
|
||||
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.id in ( select gcid from gcign where uid = %d )
|
||||
AND `gcontact`.`updated` != '0000-00-00 00:00:00'
|
||||
AND `gcontact`.`network` IN (%s)
|
||||
order by rand() limit %d, %d ",
|
||||
intval($uid),
|
||||
intval($uid),
|
||||
intval($uid),
|
||||
$sql_network,
|
||||
intval($start),
|
||||
intval($limit)
|
||||
);
|
||||
|
|
24
mod/poco.php
24
mod/poco.php
|
@ -52,20 +52,22 @@ function poco_init(&$a) {
|
|||
$sql_extra = sprintf(" AND `contact`.`id` = %d ",intval($cid));
|
||||
|
||||
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) ",
|
||||
dbesc(NETWORK_DFRN),
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
dbesc(NETWORK_OSTATUS)
|
||||
dbesc(NETWORK_OSTATUS),
|
||||
dbesc(NETWORK_STATUSNET)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$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']),
|
||||
dbesc(NETWORK_DFRN),
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
dbesc(NETWORK_OSTATUS)
|
||||
dbesc(NETWORK_OSTATUS),
|
||||
dbesc(NETWORK_STATUSNET)
|
||||
);
|
||||
}
|
||||
if(count($r))
|
||||
|
@ -80,22 +82,24 @@ function poco_init(&$a) {
|
|||
|
||||
|
||||
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",
|
||||
dbesc(NETWORK_DFRN),
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
dbesc(NETWORK_OSTATUS),
|
||||
dbesc(NETWORK_STATUSNET),
|
||||
intval($startIndex),
|
||||
intval($itemsPerPage)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$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']),
|
||||
dbesc(NETWORK_DFRN),
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
dbesc(NETWORK_OSTATUS),
|
||||
dbesc(NETWORK_STATUSNET),
|
||||
intval($startIndex),
|
||||
intval($itemsPerPage)
|
||||
);
|
||||
|
@ -120,7 +124,8 @@ function poco_init(&$a) {
|
|||
'urls' => false,
|
||||
'updated' => false,
|
||||
'preferredUsername' => false,
|
||||
'photos' => false
|
||||
'photos' => false,
|
||||
'network' => false
|
||||
);
|
||||
|
||||
if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
|
||||
|
@ -163,6 +168,11 @@ function poco_init(&$a) {
|
|||
}
|
||||
if($fields_ret['photos'])
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ function suggest_init(&$a) {
|
|||
|
||||
function suggest_content(&$a) {
|
||||
|
||||
require_once("mod/proxy.php");
|
||||
|
||||
$o = '';
|
||||
if(! local_user()) {
|
||||
notice( t('Permission denied.') . EOL);
|
||||
|
@ -82,7 +84,7 @@ function suggest_content(&$a) {
|
|||
$o .= replace_macros($tpl,array(
|
||||
'$url' => zrl($rr['url']),
|
||||
'$name' => $rr['name'],
|
||||
'$photo' => $rr['photo'],
|
||||
'$photo' => proxy_url($rr['photo']),
|
||||
'$ignlnk' => $a->get_baseurl() . '/suggest?ignore=' . $rr['id'],
|
||||
'$ignid' => $rr['id'],
|
||||
'$conntxt' => t('Connect'),
|
||||
|
|
Loading…
Reference in a new issue