"network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"name" => 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" => ""),
+ "about" => array("type" => "text", "not null" => "1"),
"attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"photo" => array("type" => "text", "not null" => "1"),
"thumb" => array("type" => "text", "not null" => "1"),
if((! $name) || (! $profile_url) || (! $profile_photo))
continue;
- $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))
);
}
- }
- else {
+ } else {
q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`, `updated`)
values ( '%s', '%s', '%s', '%s','%s') ",
dbesc($name),
dbesc($connect_url),
dbesc($updated)
);
- $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))
);
if(count($x))
if(! $gcid)
return;
- $r = q("select * from glink where `cid` = %d and `uid` = %d and `gcid` = %d and `zcid` = %d limit 1",
+ $r = q("SELECT * FROM `glink` WHERE `cid` = %d AND `uid` = %d AND `gcid` = %d AND `zcid` = %d LIMIT 1",
intval($cid),
intval($uid),
intval($gcid),
intval($zcid)
);
if(! count($r)) {
- q("insert into glink ( `cid`,`uid`,`gcid`,`zcid`, `updated`) values (%d,%d,%d,%d, '%s') ",
+ q("INSERT INTO `glink` (`cid`,`uid`,`gcid`,`zcid`, `updated`) VALUES (%d,%d,%d,%d, '%s') ",
intval($cid),
intval($uid),
intval($gcid),
);
}
else {
- q("update glink set updated = '%s' where `cid` = %d and `uid` = %d and `gcid` = %d and zcid = %d",
+ q("UPDATE `glink` SET `updated` = '%s' WHERE `cid` = %d AND `uid` = %d AND `gcid` = %d AND `zcid` = %d",
dbesc(datetime_convert()),
intval($cid),
intval($uid),
);
}
+ // For unknown reasons there are sometimes duplicates
+ q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d AND
+ NOT EXISTS (SELECT `gcid` FROM `glink` WHERE `gcid` = `gcontact`.`id`)",
+ dbesc(normalise_link($profile_url)),
+ intval($gcid)
+ );
+
}
logger("poco_load: loaded $total entries",LOGGER_DEBUG);
- q("delete from glink where `cid` = %d and `uid` = %d and `zcid` = %d and `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY",
+ q("DELETE FROM `glink` WHERE `cid` = %d AND `uid` = %d AND `zcid` = %d AND `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY",
intval($cid),
intval($uid),
intval($zcid)
if(! $uid)
return array();
- $r = q("SELECT count(glink.gcid) as `total`, gcontact.* from gcontact
- INNER JOIN glink on glink.gcid = gcontact.id
+ $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 )
- group by glink.gcid order by total desc limit %d, %d ",
+ AND `gcontact`.`updated` != '0000-00-00 00:00:00'
+ group by glink.gcid order by gcontact.updated desc,total desc limit %d, %d ",
intval($uid),
intval($uid),
intval($uid),
if(count($r) && count($r) >= ($limit -1))
return $r;
- $r2 = q("SELECT gcontact.* from gcontact
- INNER JOIN glink on glink.gcid = gcontact.id
+ $r2 = q("SELECT gcontact.* from gcontact
+ INNER JOIN glink on glink.gcid = gcontact.id
where glink.uid = 0 and glink.cid = 0 and glink.zcid = 0 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'
order by rand() limit %d, %d ",
intval($uid),
intval($uid),
intval($limit)
);
+ $list = array();
+ foreach ($r2 AS $suggestion)
+ $list[$suggestion["nurl"]] = $suggestion;
- return array_merge($r,$r2);
+ foreach ($r AS $suggestion)
+ $list[$suggestion["nurl"]] = $suggestion;
+ return $list;
}
function update_suggestions() {