From 11c82816b330f247ce317d064f91c1ac7dd72990 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 4 Jan 2015 19:19:47 +0100 Subject: [PATCH 01/13] Poco now returns the last update date as well. This date will be stored in the gcontact table. --- boot.php | 2 +- include/dbstructure.php | 1 + include/items.php | 10 ++++++++++ include/socgraph.php | 18 ++++++++++++------ mod/poco.php | 21 ++++++++++++++++++--- update.php | 2 +- 6 files changed, 43 insertions(+), 11 deletions(-) diff --git a/boot.php b/boot.php index 34836a97aa..ec2a4a1acf 100644 --- a/boot.php +++ b/boot.php @@ -18,7 +18,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_CODENAME', 'Ginger'); define ( 'FRIENDICA_VERSION', '3.3.2' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1175 ); +define ( 'DB_UPDATE_VERSION', 1177 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/include/dbstructure.php b/include/dbstructure.php index 66e67c0a9a..08d772ef7c 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -616,6 +616,7 @@ function db_definition() { "nurl" => 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" => ""), + "updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"), ), "indexes" => array( "PRIMARY" => array("id"), diff --git a/include/items.php b/include/items.php index d6da0ed5a5..b82b5dc971 100644 --- a/include/items.php +++ b/include/items.php @@ -1343,6 +1343,16 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $current_post = $r[0]['id']; logger('item_store: created item ' . $current_post); + // 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. + // Only do this for public postings to avoid privacy problems, since poco data is public. + // Don't set this value if it isn't from the owner (could be an author that we don't know) + if (!$arr['private'] AND (($arr["author-link"] === $arr["owner-link"]) OR ($arr["parent-uri"] === $arr["uri"]))) + $r = q("UPDATE `contact` SET `success_update` = '%s' WHERE `id` = %d", + dbesc($arr['received']), + intval($arr['contact-id']) + ); + // Only check for notifications on start posts if ($arr['parent-uri'] === $arr['uri']) { add_thread($r[0]['id']); diff --git a/include/socgraph.php b/include/socgraph.php index daec03726e..333d2f04b1 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -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') ; + $url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos' : '?fields=displayName,urls,photos,updated') ; 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 = ''; + $updated = '0000-00-00 00:00:00'; $name = $entry->displayName; @@ -82,7 +83,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { } } } - if(isset($entry->photos)) { + if(isset($entry->photos)) { foreach($entry->photos as $photo) { if($photo->type == 'profile') { $profile_photo = $photo->value; @@ -91,6 +92,9 @@ 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)); + if((! $name) || (! $profile_url) || (! $profile_photo)) continue; @@ -101,25 +105,27 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { if(count($x)) { $gcid = $x[0]['id']; - if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo) { - q("update gcontact set `name` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s' + 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' where `nurl` = '%s'", dbesc($name), dbesc($profile_photo), dbesc($connect_url), dbesc($profile_url), + dbesc($updated), dbesc(normalise_link($profile_url)) ); } } else { - q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`) + q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`, `updated`) values ( '%s', '%s', '%s', '%s','%s') ", dbesc($name), dbesc($profile_url), dbesc(normalise_link($profile_url)), dbesc($profile_photo), - dbesc($connect_url) + dbesc($connect_url), + dbesc($updated) ); $x = q("select * from `gcontact` where `nurl` = '%s' limit 1", dbesc(normalise_link($profile_url)) diff --git a/mod/poco.php b/mod/poco.php index 624a48d9ff..9c08749f20 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -30,7 +30,7 @@ function poco_init(&$a) { $justme = true; if($a->argc > 4 && intval($a->argv[4]) && $justme == false) $cid = intval($a->argv[4]); - + if(! $system_mode) { $r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid` @@ -106,6 +106,7 @@ function poco_init(&$a) { 'id' => false, 'displayName' => false, 'urls' => false, + 'updated' => false, 'preferredUsername' => false, 'photos' => false ); @@ -130,10 +131,24 @@ function poco_init(&$a) { if($fields_ret['urls']) { $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile')); if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL)) - $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger'); + $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger'); } if($fields_ret['preferredUsername']) $entry['preferredUsername'] = $rr['nick']; + if($fields_ret['updated']) { + $entry['updated'] = $rr['success_update']; + + if ($rr['name-date'] > $entry['updated']) + $entry['updated'] = $rr['name-date']; + + if ($rr['uri-date'] > $entry['updated']) + $entry['updated'] = $rr['uri-date']; + + if ($rr['avatar-date'] > $entry['updated']) + $entry['updated'] = $rr['avatar-date']; + + $entry['updated'] = date("c", strtotime($entry['updated'])); + } if($fields_ret['photos']) $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile')); $ret['entry'][] = $entry; @@ -153,7 +168,7 @@ function poco_init(&$a) { if($format === 'json') { header('Content-type: application/json'); echo json_encode($ret); - killme(); + killme(); } else http_status_exit(500); diff --git a/update.php b/update.php index 10195c1baa..b4fb640486 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Mon, 5 Jan 2015 08:03:29 +0100 Subject: [PATCH 02/13] Suggest only active accounts. Remove duplicates from gcontact table. --- include/dbstructure.php | 2 ++ include/socgraph.php | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 1f6a7c4ef3..008003e1b0 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -413,6 +413,8 @@ function db_definition() { "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"), diff --git a/include/socgraph.php b/include/socgraph.php index 333d2f04b1..b9e890427c 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -98,7 +98,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { 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)) ); @@ -116,8 +116,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { 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), @@ -127,7 +126,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { 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)) @@ -136,14 +135,14 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { 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), @@ -152,7 +151,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { ); } 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), @@ -161,10 +160,17 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { ); } + // 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) @@ -295,12 +301,13 @@ function suggestion_query($uid, $start = 0, $limit = 80) { 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), @@ -312,11 +319,12 @@ function suggestion_query($uid, $start = 0, $limit = 80) { 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), @@ -325,9 +333,14 @@ function suggestion_query($uid, $start = 0, $limit = 80) { 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() { From 011f5b9cae2b1481ab2c48c2408dbe1f573461de Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 5 Jan 2015 14:28:17 +0100 Subject: [PATCH 03/13] Bugfix: Postings disappeared due to a small variable ... --- include/items.php | 2 +- mod/parse_url.php | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/items.php b/include/items.php index b82b5dc971..9d1e36f39b 100644 --- a/include/items.php +++ b/include/items.php @@ -1348,7 +1348,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa // Only do this for public postings to avoid privacy problems, since poco data is public. // Don't set this value if it isn't from the owner (could be an author that we don't know) if (!$arr['private'] AND (($arr["author-link"] === $arr["owner-link"]) OR ($arr["parent-uri"] === $arr["uri"]))) - $r = q("UPDATE `contact` SET `success_update` = '%s' WHERE `id` = %d", + q("UPDATE `contact` SET `success_update` = '%s' WHERE `id` = %d", dbesc($arr['received']), intval($arr['contact-id']) ); diff --git a/mod/parse_url.php b/mod/parse_url.php index 9df35c7612..9f7b31be30 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -93,6 +93,15 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co return($siteinfo); } + if ($do_oembed) { + require_once("include/oembed.php"); + + $oembed_data = oembed_fetch_url($url); + + if ($oembed_data->type != "error") + $siteinfo["type"] = $oembed_data->type; + } + // if the file is too large then exit if ($curl_info["download_content_length"] > 1000000) return($siteinfo); @@ -115,15 +124,6 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co $http_code = $curl_info['http_code']; curl_close($ch); - if ($do_oembed) { - require_once("include/oembed.php"); - - $oembed_data = oembed_fetch_url($url); - - if ($oembed_data->type != "error") - $siteinfo["type"] = $oembed_data->type; - } - // Fetch the first mentioned charset. Can be in body or header $charset = ""; if (preg_match('/charset=(.*?)['."'".'"\s\n]/', $header, $matches)) From 16e4e61cc5162b8f65584464002d8e337a759519 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 5 Jan 2015 22:44:55 +0100 Subject: [PATCH 04/13] Only show contacts from open networks --- mod/poco.php | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/mod/poco.php b/mod/poco.php index 9c08749f20..9b3e8d06af 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -12,7 +12,7 @@ function poco_init(&$a) { $user = notags(trim($a->argv[1])); } if(! x($user)) { - $c = q("select * from pconfig where cat = 'system' and k = 'suggestme' and v = 1"); + $c = q("SELECT * FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1"); if(! count($c)) http_status_exit(401); $system_mode = true; @@ -30,7 +30,7 @@ function poco_init(&$a) { $justme = true; if($a->argc > 4 && intval($a->argv[4]) && $justme == false) $cid = intval($a->argv[4]); - + if(! $system_mode) { $r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid` @@ -44,21 +44,28 @@ function poco_init(&$a) { } if($justme) - $sql_extra = " and `contact`.`self` = 1 "; + $sql_extra = " AND `contact`.`self` = 1 "; else - $sql_extra = " and `contact`.`self` = 0 "; + $sql_extra = " AND `contact`.`self` = 0 "; if($cid) - $sql_extra = sprintf(" and `contact`.`id` = %d ",intval($cid)); + $sql_extra = sprintf(" AND `contact`.`id` = %d ",intval($cid)); if($system_mode) { - $r = q("SELECT count(*) as `total` from `contact` where self = 1 - and uid in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = 1) "); + $r = q("SELECT count(*) AS `total` FROM `contact` WHERE `self` = 1 AND `network` IN ('%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) + ); } else { - $r = q("SELECT count(*) as `total` from `contact` where `uid` = %d and blocked = 0 and pending = 0 and hidden = 0 and archive = 0 - $sql_extra ", - intval($user['uid']) + $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", + intval($user['uid']), + dbesc(NETWORK_DFRN), + dbesc(NETWORK_DIASPORA), + dbesc(NETWORK_OSTATUS) ); } if(count($r)) @@ -73,17 +80,22 @@ function poco_init(&$a) { if($system_mode) { - $r = q("SELECT * from contact where self = 1 - and uid in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = 1) limit %d, %d ", + $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `network` IN ('%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), 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 - $sql_extra LIMIT %d, %d", + $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", intval($user['uid']), + dbesc(NETWORK_DFRN), + dbesc(NETWORK_DIASPORA), + dbesc(NETWORK_OSTATUS), intval($startIndex), intval($itemsPerPage) ); From 1a5a00bef8c90524b094dddd4de5dcc6a1a6545f Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 6 Jan 2015 07:23:11 +0100 Subject: [PATCH 05/13] While storing an item, now every contact is stored in the gcontact table. --- include/items.php | 7 ++++ include/socgraph.php | 78 +++++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/include/items.php b/include/items.php index 9d1e36f39b..a7e996015e 100644 --- a/include/items.php +++ b/include/items.php @@ -11,6 +11,7 @@ require_once('include/text.php'); require_once('include/email.php'); require_once('include/ostatus_conversation.php'); require_once('include/threads.php'); +require_once('include/socgraph.php'); function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) { @@ -1343,6 +1344,12 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $current_post = $r[0]['id']; logger('item_store: created item ' . $current_post); + // Add every contact to the global contact table + // 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"]); + // 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. // Only do this for public postings to avoid privacy problems, since poco data is public. diff --git a/include/socgraph.php b/include/socgraph.php index b9e890427c..8b8eb915cc 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -98,40 +98,8 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { if((! $name) || (! $profile_url) || (! $profile_photo)) continue; - $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", - dbesc(normalise_link($profile_url)) - ); + $gcid = poco_check($profile_url, $name, $profile_photo, $connect_url, $updated); - if(count($x)) { - $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' - where `nurl` = '%s'", - dbesc($name), - dbesc($profile_photo), - dbesc($connect_url), - dbesc($profile_url), - dbesc($updated), - dbesc(normalise_link($profile_url)) - ); - } - } else { - q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`, `updated`) - values ( '%s', '%s', '%s', '%s','%s') ", - dbesc($name), - dbesc($profile_url), - dbesc(normalise_link($profile_url)), - dbesc($profile_photo), - dbesc($connect_url), - dbesc($updated) - ); - $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", - dbesc(normalise_link($profile_url)) - ); - if(count($x)) - $gcid = $x[0]['id']; - } if(! $gcid) return; @@ -178,6 +146,50 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { } +function poco_check($profile_url, $name, $profile_photo, $connect_url, $updated) { + $gcid = ""; + + if (($profile_url == "") OR ($name == "") OR ($profile_photo == "")) + return $gcid; + + logger("profile-check URL: ".$profile_url." name: ".$name." avatar: ".$profile_photo, LOGGER_DEBUG); + + $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + dbesc(normalise_link($profile_url)) + ); + + if(count($x)) { + $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' + where `nurl` = '%s'", + dbesc($name), + dbesc($profile_photo), + dbesc($connect_url), + dbesc($profile_url), + dbesc($updated), + dbesc(normalise_link($profile_url)) + ); + } + } else { + q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`, `updated`) + values ('%s', '%s', '%s', '%s','%s', '%s')", + dbesc($name), + dbesc($profile_url), + dbesc(normalise_link($profile_url)), + dbesc($profile_photo), + dbesc($connect_url), + dbesc($updated) + ); + $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", + dbesc(normalise_link($profile_url)) + ); + if(count($x)) + $gcid = $x[0]['id']; + } + return $gcid; +} function count_common_friends($uid,$cid) { From 5684ba4442b3db9ea0c135f1013a70f515d98e1f Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 6 Jan 2015 08:16:15 +0100 Subject: [PATCH 06/13] Now the glink table is written as well in the poco_check function. --- include/socgraph.php | 77 +++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index 8b8eb915cc..623cf88cea 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -95,45 +95,7 @@ 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)); - if((! $name) || (! $profile_url) || (! $profile_photo)) - continue; - - $gcid = poco_check($profile_url, $name, $profile_photo, $connect_url, $updated); - - if(! $gcid) - return; - - $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') ", - intval($cid), - intval($uid), - intval($gcid), - intval($zcid), - dbesc(datetime_convert()) - ); - } - else { - 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), - intval($gcid), - intval($zcid) - ); - } - - // 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) - ); + poco_check($profile_url, $name, $profile_photo, $connect_url, $updated, $cid, $uid, $zcid); } logger("poco_load: loaded $total entries",LOGGER_DEBUG); @@ -146,7 +108,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { } -function poco_check($profile_url, $name, $profile_photo, $connect_url, $updated) { +function poco_check($profile_url, $name, $profile_photo, $connect_url, $updated, $cid = 0, $uid = 0, $zcid = 0) { $gcid = ""; if (($profile_url == "") OR ($name == "") OR ($profile_photo == "")) @@ -188,6 +150,41 @@ function poco_check($profile_url, $name, $profile_photo, $connect_url, $updated) if(count($x)) $gcid = $x[0]['id']; } + + if(! $gcid) + return $gcid; + + $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') ", + intval($cid), + intval($uid), + intval($gcid), + intval($zcid), + dbesc(datetime_convert()) + ); + } else { + 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), + intval($gcid), + intval($zcid) + ); + } + + // 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) + ); + return $gcid; } From a2a393a3c6c0446751f41c009dd5ae5a47b445d0 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 6 Jan 2015 12:31:44 +0100 Subject: [PATCH 07/13] Better check for Diaspora accounts so you can connect them from the /suggest page. --- include/Scrape.php | 9 +++++++++ include/items.php | 2 +- include/threads.php | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/Scrape.php b/include/Scrape.php index 99784af336..629f7a063b 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -750,5 +750,14 @@ function probe_url($url, $mode = PROBE_NORMAL) { logger('probe_url: ' . print_r($result,true), LOGGER_DEBUG); + // Trying if it maybe a diaspora account + if ($result['network'] == NETWORK_FEED) { + require_once('include/bbcode.php'); + $address = GetProfileUsername($url, "", true); + $result2 = probe_url($address, $mode); + if ($result2['network'] != "") + $result = $result2; + } + return $result; } diff --git a/include/items.php b/include/items.php index a7e996015e..c1352cebbe 100644 --- a/include/items.php +++ b/include/items.php @@ -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"]); + poco_check($arr["author-link"], $arr["author-name"], $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. diff --git a/include/threads.php b/include/threads.php index 28bf87f4da..8febe49e9b 100644 --- a/include/threads.php +++ b/include/threads.php @@ -153,6 +153,8 @@ function delete_thread_uri($itemuri, $uid) { } function delete_thread($itemid) { + // To-Do: + // There is no "uri" in the thread table ... $item = q("SELECT `uri`, `uid` FROM `thread` WHERE `iid` = %d", intval($itemid)); $result = q("DELETE FROM `thread` WHERE `iid` = %d", intval($itemid)); From b36d79904497bab6255a995921010a39eefc4a7e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 7 Jan 2015 01:46:13 +0100 Subject: [PATCH 08/13] Fetching "location" and "about" from diaspora. Displaying them on the "display" page. --- boot.php | 5 ++++- include/diaspora.php | 21 +++++++++++-------- include/items.php | 2 +- include/threads.php | 16 +++++++------- mod/display.php | 23 +++++++++++---------- view/templates/profile_vcard.tpl | 2 ++ view/theme/vier/templates/profile_vcard.tpl | 2 ++ 7 files changed, 40 insertions(+), 31 deletions(-) diff --git a/boot.php b/boot.php index ec2a4a1acf..9e5a32b66b 100644 --- a/boot.php +++ b/boot.php @@ -1649,8 +1649,10 @@ if(! function_exists('profile_sidebar')) { $homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False); + $about = ((x($profile,'about') == 1) ? t('About:') : False); + if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) { - $location = $pdesc = $gender = $marital = $homepage = False; + $location = $pdesc = $gender = $marital = $homepage = $about = False; } $firstname = ((strpos($profile['name'],' ')) @@ -1695,6 +1697,7 @@ if(! function_exists('profile_sidebar')) { '$pdesc' => $pdesc, '$marital' => $marital, '$homepage' => $homepage, + '$about' => $about, '$network' => t('Network:'), '$diaspora' => $diaspora, '$contact_block' => $contact_block, diff --git a/include/diaspora.php b/include/diaspora.php index 99288b773c..b5cb0f0e23 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2028,7 +2028,7 @@ function diaspora_retraction($importer,$xml) { dbesc(datetime_convert()), intval($r[0]['id']) ); - delete_thread($r[0]['id']); + delete_thread($r[0]['id'], $r[0]['parent-uri']); } } } @@ -2101,7 +2101,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) { dbesc(datetime_convert()), intval($r[0]['id']) ); - delete_thread($r[0]['id']); + delete_thread($r[0]['id'], $r[0]['parent-uri']); // Now check if the retraction needs to be relayed by us // @@ -2161,14 +2161,15 @@ function diaspora_profile($importer,$xml,$msg) { $name = unxmlify($xml->first_name) . ((strlen($xml->last_name)) ? ' ' . unxmlify($xml->last_name) : ''); $image_url = unxmlify($xml->image_url); $birthday = unxmlify($xml->birthday); + $location = unxmlify($xml->location); + $about = diaspora2bb(unxmlify($xml->bio)); $handle_parts = explode("@", $diaspora_handle); if($name === '') { $name = $handle_parts[0]; } - - + if( preg_match("|^https?://|", $image_url) === 0) { $image_url = "http://" . $handle_parts[1] . $image_url; } @@ -2182,8 +2183,8 @@ function diaspora_profile($importer,$xml,$msg) { require_once('include/Photo.php'); $images = import_profile_photo($image_url,$importer['uid'],$contact['id']); - - // Generic birthday. We don't know the timezone. The year is irrelevant. + + // Generic birthday. We don't know the timezone. The year is irrelevant. $birthday = str_replace('1000','1901',$birthday); @@ -2196,9 +2197,9 @@ function diaspora_profile($importer,$xml,$msg) { $birthday = $contact['bd']; // 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' 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' WHERE `id` = %d AND `uid` = %d", dbesc($name), dbesc(datetime_convert()), dbesc($images[0]), @@ -2206,9 +2207,11 @@ function diaspora_profile($importer,$xml,$msg) { dbesc($images[2]), dbesc(datetime_convert()), dbesc($birthday), + dbesc($location), + dbesc($about), intval($contact['id']), intval($importer['uid']) - ); + ); /* if($r) { if($oldphotos) { diff --git a/include/items.php b/include/items.php index c1352cebbe..1637de15b3 100644 --- a/include/items.php +++ b/include/items.php @@ -4509,7 +4509,7 @@ function drop_item($id,$interactive = true) { ); create_tags_from_item($item['id']); create_files_from_item($item['id']); - delete_thread($item['id']); + delete_thread($item['id'], $item['parent-uri']); // clean up categories and tags so they don't end up as orphans diff --git a/include/threads.php b/include/threads.php index 8febe49e9b..e9a0d7f1f2 100644 --- a/include/threads.php +++ b/include/threads.php @@ -149,28 +149,26 @@ function delete_thread_uri($itemuri, $uid) { if(count($messages)) foreach ($messages as $message) - delete_thread($message["id"]); + delete_thread($message["id"], $itemuri); } -function delete_thread($itemid) { - // To-Do: - // There is no "uri" in the thread table ... - $item = q("SELECT `uri`, `uid` FROM `thread` WHERE `iid` = %d", intval($itemid)); +function delete_thread($itemid, $itemuri = "") { + $item = q("SELECT `uid` FROM `thread` WHERE `iid` = %d", intval($itemid)); $result = q("DELETE FROM `thread` WHERE `iid` = %d", intval($itemid)); logger("delete_thread: Deleted thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG); - if (count($item)) { + if ($itemuri != "") { $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND NOT (`uid` IN (%d, 0))", - dbesc($item["uri"]), + dbesc($itemuri), intval($item["uid"]) ); if (!count($r)) { $r = q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = 0)", - dbesc($item["uri"]) + dbesc($itemuri) ); - logger("delete_thread: Deleted shadow for item ".$item["uri"]." - ".print_r($result, true), LOGGER_DEBUG); + logger("delete_thread: Deleted shadow for item ".$itemuri." - ".print_r($result, true), LOGGER_DEBUG); } } } diff --git a/mod/display.php b/mod/display.php index abb03b6d5b..d1da53cf16 100644 --- a/mod/display.php +++ b/mod/display.php @@ -16,7 +16,7 @@ function display_init(&$a) { // Does the local user have this item? if (local_user()) { - $r = q("SELECT `id`, `parent`, `author-name`, `author-link`, `author-avatar`, `network`, `body` FROM `item` + $r = q("SELECT `id`, `parent`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item` WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user()); if (count($r)) { @@ -43,7 +43,7 @@ function display_init(&$a) { } if (count($r)) { if ($r[0]["id"] != $r[0]["parent"]) - $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body` FROM `item` + $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item` WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 AND `id` = %d", $r[0]["parent"]); @@ -88,21 +88,22 @@ function display_fetchauthor($a, $item) { $profiledata["photo"] = proxy_url($item["author-avatar"]); $profiledata["url"] = $item["author-link"]; $profiledata["network"] = $item["network"]; + $profiledata["address"] = "Ort".print_r($item, true); - // Fetching profile data from unique contacts - // To-do: Extend "unique contacts" table for further contact data like location, ... - $r = q("SELECT `avatar`, `nick` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"])); + // Fetching further contact data from the contact table + $r = q("SELECT `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", + normalise_link($profiledata["url"]), $item["uid"]); if (count($r)) { - $profiledata["photo"] = proxy_url($r[0]["avatar"]); + $profiledata["photo"] = proxy_url($r[0]["photo"]); + $profiledata["address"] = $r[0]["location"]; + $profiledata["about"] = $r[0]["about"]; if ($r[0]["nick"] != "") $profiledata["nickname"] = $r[0]["nick"]; } else { - // Is this case possible? - // Fetching further contact data from the contact table, when it isn't available in the "unique contacts" - $r = q("SELECT `photo`, `nick` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", - normalise_link($profiledata["url"]), $itemuid); + // Fetching profile data from unique contacts + $r = q("SELECT `avatar`, `nick` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"])); if (count($r)) { - $profiledata["photo"] = proxy_url($r[0]["photo"]); + $profiledata["photo"] = proxy_url($r[0]["avatar"]); if ($r[0]["nick"] != "") $profiledata["nickname"] = $r[0]["nick"]; } diff --git a/view/templates/profile_vcard.tpl b/view/templates/profile_vcard.tpl index e72d25371d..9bbb7f8a42 100644 --- a/view/templates/profile_vcard.tpl +++ b/view/templates/profile_vcard.tpl @@ -35,6 +35,8 @@ {{if $homepage}}
{{$homepage}}
{{$profile.homepage}}
{{/if}} + {{if $about}}
{{$about}}
{{$profile.about}}
{{/if}} + {{include file="diaspora_vcard.tpl"}}