aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorFriendika <info@friendika.com>2011-10-31 20:39:04 -0700
committerFriendika <info@friendika.com>2011-10-31 20:39:04 -0700
commitd4644d73392f335a3cc488fbd8935068a567edcf (patch)
tree1fe123926d95305a19c1999ab6f01232a9d43583 /include
parentd5ce13ee12f6d9fcebf905213b66938fb1ceb06c (diff)
downloadvolse-hubzilla-d4644d73392f335a3cc488fbd8935068a567edcf.tar.gz
volse-hubzilla-d4644d73392f335a3cc488fbd8935068a567edcf.tar.bz2
volse-hubzilla-d4644d73392f335a3cc488fbd8935068a567edcf.zip
name change continued, social graph tools and stuctures, fix for spanish province name
Diffstat (limited to 'include')
-rw-r--r--include/Scrape.php3
-rw-r--r--include/poller.php7
-rw-r--r--include/socgraph.php125
3 files changed, 135 insertions, 0 deletions
diff --git a/include/Scrape.php b/include/Scrape.php
index f5b15c82f..e42d22afc 100644
--- a/include/Scrape.php
+++ b/include/Scrape.php
@@ -369,6 +369,8 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$hcard = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
$profile = unamp($link['@attributes']['href']);
+ if($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0')
+ $poco = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') {
$diaspora_base = unamp($link['@attributes']['href']);
$diaspora = true;
@@ -684,6 +686,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$result['poll'] = $poll;
$result['request'] = $request;
$result['confirm'] = $confirm;
+ $result['poco'] = $poco;
$result['photo'] = $vcard['photo'];
$result['priority'] = $priority;
$result['network'] = $network;
diff --git a/include/poller.php b/include/poller.php
index a19f0716f..f81e879b4 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -298,6 +298,13 @@ function poller_run($argv, $argc){
if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
continue;
+ if(((float) $res->dfrn_version > 2.21) && ($contact['poco'] == '')) {
+ q("update contact set poco = '%s' where id = %d limit 1",
+ dbesc(str_replace('/profile/','/poco/', $contact['url'])),
+ intval($contact['id'])
+ );
+ }
+
$postvars = array();
$sent_dfrn_id = hex2bin((string) $res->dfrn_id);
diff --git a/include/socgraph.php b/include/socgraph.php
new file mode 100644
index 000000000..56de83af0
--- /dev/null
+++ b/include/socgraph.php
@@ -0,0 +1,125 @@
+<?php
+
+
+
+/*
+ * poco_load
+ *
+ * Given a contact-id (minimum), load the PortableContacts friend list for that contact,
+ * and add the entries to the gcontact (Global Contact) table, or update existing entries
+ * if anything (name or photo) has changed.
+ * We use normalised urls for comparison which ignore http vs https and www.domain vs domain
+ *
+ * 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
+ * pointing to the same global contact id.
+ *
+ */
+
+
+
+
+function poco_load($cid,$uid = 0,$url = null) {
+ $a = get_app();
+ if((! $url) || (! $uid)) {
+ $r = q("select `poco`, `uid` from `contact` where `id` = %d limit 1",
+ intval($cid)
+ );
+ if(count($r)) {
+ $url = $r[0]['poco'];
+ $uid = $r[0]['uid'];
+ }
+ }
+ if((! $url) || (! $uid))
+ return;
+ $s = fetch_url($url . '/@me/@all?fields=displayName,urls,photos');
+
+ if(($a->get_curl_code() > 299) || (! $s))
+ return;
+ $j = json_decode($s);
+ foreach($j->entry as $entry) {
+
+ $profile_url = '';
+ $profile_photo = '';
+ $name = '';
+
+ $name = $entry->displayName;
+
+ foreach($entry->urls as $url) {
+ if($url->type == 'profile') {
+ $profile_url = $url->value;
+ break;
+ }
+ }
+ foreach($entry->photos as $photo) {
+ if($photo->type == 'profile') {
+ $profile_photo = $photo->value;
+ break;
+ }
+ }
+
+ if((! $name) || (! $profile_url) || (! $profile_photo))
+ continue;
+
+ $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) {
+ q("update gcontact set `name` = '%s', `photo` = '%s' where
+ `nurl` = '%s' limit 1",
+ dbesc($name),
+ dbesc($profile_photo),
+ dbesc(normalise_link($profile_url))
+ );
+ }
+ }
+ else {
+ q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`)
+ values ( '%s', '%s', '%s', '%s') ",
+ dbesc($name),
+ dbesc($profile_url),
+ dbesc(normalise_link($profile_url)),
+ dbesc($profile_photo)
+ );
+ $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;
+
+ $r = q("select * from glink where `cid` = %d and `uid` = %d and `gcid` = %d limit 1",
+ intval($cid),
+ intval($uid),
+ intval($gcid)
+ );
+ if(! count($r)) {
+ q("insert into glink ( `cid`,`uid`,`gcid`,`updated`) values (%d,%d,%d,'%s') ",
+ intval($cid),
+ intval($uid),
+ intval($gcid),
+ dbesc(datetime_convert())
+ );
+ }
+ else {
+ q("update glink set updated = '%s' where `cid` = %d and `uid` = %d and `gcid` = %d limit 1",
+ dbesc(datetime_convert()),
+ intval($cid),
+ intval($uid),
+ intval($gcid)
+ );
+ }
+
+ }
+
+ q("delete from gcid where `cid` = %d and `uid` = %d and `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY",
+ intval($cid),
+ intval($uid)
+ );
+
+} \ No newline at end of file