pull out follow, unfollow and as:actor for handling
This commit is contained in:
parent
16b9c58412
commit
d850badf2b
2
boot.php
2
boot.php
|
@ -64,6 +64,8 @@ define ( 'ACTIVITY_DISLIKE', NAMESPACE_DFRN . '/dislike' );
|
||||||
define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' );
|
define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' );
|
||||||
|
|
||||||
define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' );
|
define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' );
|
||||||
|
define ( 'ACTIVITY_FOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'follow' );
|
||||||
|
define ( 'ACTIVITY_UNFOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'unfollow' );
|
||||||
define ( 'ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post' );
|
define ( 'ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post' );
|
||||||
define ( 'ACTIVITY_UPDATE', NAMESPACE_ACTIVITY_SCHEMA . 'update' );
|
define ( 'ACTIVITY_UPDATE', NAMESPACE_ACTIVITY_SCHEMA . 'update' );
|
||||||
|
|
||||||
|
|
|
@ -362,6 +362,19 @@ function get_atom_elements($item) {
|
||||||
if($rawgeo)
|
if($rawgeo)
|
||||||
$res['coord'] = unxmlify($rawgeo[0]['data']);
|
$res['coord'] = unxmlify($rawgeo[0]['data']);
|
||||||
|
|
||||||
|
$rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object');
|
||||||
|
if($rawactor && $rawactor[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'] === ACTIVITY_OBJ_PERSON) {
|
||||||
|
$base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
|
||||||
|
if($base && count($base)) {
|
||||||
|
foreach($base as $link) {
|
||||||
|
if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
|
||||||
|
$res['author-link'] = unxmlify($link['attribs']['']['href']);
|
||||||
|
if($link['attribs']['']['rel'] === 'avatar' && (! $res['author-avatar']))
|
||||||
|
$res['author-avatar'] = unxmlify($link['attribs']['']['href']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb');
|
$rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb');
|
||||||
// select between supported verbs
|
// select between supported verbs
|
||||||
if($rawverb)
|
if($rawverb)
|
||||||
|
@ -369,7 +382,6 @@ function get_atom_elements($item) {
|
||||||
|
|
||||||
$rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object');
|
$rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object');
|
||||||
|
|
||||||
|
|
||||||
if($rawobj) {
|
if($rawobj) {
|
||||||
$res['object'] = '<object>' . "\n";
|
$res['object'] = '<object>' . "\n";
|
||||||
if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) {
|
if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) {
|
||||||
|
@ -610,6 +622,22 @@ function dfrn_deliver($owner,$contact,$atom,$debugging = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* consume_feed - process atom feed and update anything/everything we might need to update
|
||||||
|
*
|
||||||
|
* $xml = the (atom) feed to consume - no RSS spoken here, it might partially work since simplepie
|
||||||
|
* handles both, but we don't claim it will work well, and are reasonably certain it won't.
|
||||||
|
* $importer = the contact_record (joined to user_record) of the local user who owns this relationship.
|
||||||
|
* It is this person's stuff that is going to be updated.
|
||||||
|
* $contact = the person who is sending us stuff. If not set, we MAY be processing a "follow" activity
|
||||||
|
* from an external network and MAY create an appropriate contact record. Otherwise, we MUST
|
||||||
|
* have a contact record.
|
||||||
|
* $hub = should wefind ahub declation in the feed, pass it back to our calling process, who might (or
|
||||||
|
* might not) try and subscribe to it.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
function consume_feed($xml,$importer,$contact, &$hub) {
|
function consume_feed($xml,$importer,$contact, &$hub) {
|
||||||
|
|
||||||
require_once('simplepie/simplepie.inc');
|
require_once('simplepie/simplepie.inc');
|
||||||
|
@ -651,7 +679,7 @@ function consume_feed($xml,$importer,$contact, &$hub) {
|
||||||
$photo_url = $feed->get_image_url();
|
$photo_url = $feed->get_image_url();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $contact['avatar-date'])) {
|
if((is_array($contact)) && ($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $contact['avatar-date'])) {
|
||||||
|
|
||||||
require_once("Photo.php");
|
require_once("Photo.php");
|
||||||
$photo_failure = false;
|
$photo_failure = false;
|
||||||
|
@ -688,7 +716,7 @@ function consume_feed($xml,$importer,$contact, &$hub) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($name_updated) && (strlen($new_name)) && ($name_updated > $contact['name-date'])) {
|
if((is_array($contact)) && ($name_updated) && (strlen($new_name)) && ($name_updated > $contact['name-date'])) {
|
||||||
q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
|
q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
|
||||||
dbesc(notags(trim($new_name))),
|
dbesc(notags(trim($new_name))),
|
||||||
dbesc(datetime_convert()),
|
dbesc(datetime_convert()),
|
||||||
|
@ -714,10 +742,11 @@ function consume_feed($xml,$importer,$contact, &$hub) {
|
||||||
else
|
else
|
||||||
$when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
|
$when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
if($deleted) {
|
if($deleted && is_array($contact)) {
|
||||||
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
|
||||||
dbesc($uri),
|
dbesc($uri),
|
||||||
intval($importer['uid'])
|
intval($importer['uid']),
|
||||||
|
intval($contact['id'])
|
||||||
);
|
);
|
||||||
if(count($r)) {
|
if(count($r)) {
|
||||||
$item = $r[0];
|
$item = $r[0];
|
||||||
|
@ -774,7 +803,7 @@ function consume_feed($xml,$importer,$contact, &$hub) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if($is_reply) {
|
if(($is_reply) && is_array($contact)) {
|
||||||
|
|
||||||
// Have we seen it? If not, import it.
|
// Have we seen it? If not, import it.
|
||||||
|
|
||||||
|
@ -837,6 +866,16 @@ function consume_feed($xml,$importer,$contact, &$hub) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$datarray = get_atom_elements($item);
|
$datarray = get_atom_elements($item);
|
||||||
|
if(($datarray['verb'] === ACTIVITY_FOLLOW) && (! is_array($contact))) {
|
||||||
|
new_follower($importer,$datarray);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if($datarray['verb'] === ACTIVITY_UNFOLLOW) {
|
||||||
|
lose_follower($importer,$contact,$datarray);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(! is_array($contact))
|
||||||
|
return;
|
||||||
$datarray['parent-uri'] = $item_id;
|
$datarray['parent-uri'] = $item_id;
|
||||||
$datarray['uid'] = $importer['uid'];
|
$datarray['uid'] = $importer['uid'];
|
||||||
$datarray['contact-id'] = $contact['id'];
|
$datarray['contact-id'] = $contact['id'];
|
||||||
|
@ -849,6 +888,16 @@ function consume_feed($xml,$importer,$contact, &$hub) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function new_follower($importer,$datarray) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function lose_follower($importer,$contact,$datarray) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function subscribe_to_hub($url,$importer,$contact) {
|
function subscribe_to_hub($url,$importer,$contact) {
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ function get_salmon_key($uri,$keyhash) {
|
||||||
$l = explode("\n",$h);
|
$l = explode("\n",$h);
|
||||||
if(count($l)) {
|
if(count($l)) {
|
||||||
foreach($l as $line) {
|
foreach($l as $line) {
|
||||||
|
// TODO alter the following regex to support multiple relations (space separated)
|
||||||
if((stristr($line,'link:')) && preg_match('/<([^>].*)>.*rel\=[\'\"]lrdd[\'\"]/',$line,$matches)) {
|
if((stristr($line,'link:')) && preg_match('/<([^>].*)>.*rel\=[\'\"]lrdd[\'\"]/',$line,$matches)) {
|
||||||
$link = $matches[1];
|
$link = $matches[1];
|
||||||
if($debugging)
|
if($debugging)
|
||||||
|
|
Loading…
Reference in a new issue