greatly simplify consume_feed() - a lot of this was friendica specific and somebody may want to put some of it back in, but we'd be much better off building a zot compatible feed for friendica (hint,hint) - even if it didn't support the other protocol bits. Special purpose feed handlers for things like likes, dislikes, events, and community tags are better handled as zot arrays. We have all those handlers. We just need to pass them a JSON message instead of an XML/Atom message. Handlers for statusnet follow messages are another casualty. That's easy to bring back - but we need to keep driving nails into the XML coffin or the damn zombies will get out.

This commit is contained in:
friendica 2014-08-20 04:38:17 -07:00
parent 0fef39a326
commit b102986929
2 changed files with 50 additions and 196 deletions

View File

@ -3019,10 +3019,6 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) {
$feed = new SimplePie(); $feed = new SimplePie();
$feed->set_raw_data($xml); $feed->set_raw_data($xml);
if($datedir)
$feed->enable_order_by_date(true);
else
$feed->enable_order_by_date(false);
$feed->init(); $feed->init();
if($feed->error()) if($feed->error())
@ -3032,7 +3028,6 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) {
// Check at the feed level for updated contact name and/or photo // Check at the feed level for updated contact name and/or photo
// process any deleted entries // process any deleted entries
$del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry'); $del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry');
@ -3052,41 +3047,18 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) {
if($deleted && is_array($contact)) { if($deleted && is_array($contact)) {
/* $r = q("SELECT * from item where mid = '%s' and author_xchan = '%s' and uid = %d limit 1",
$r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join `contact` on `item`.`contact-id` = `contact`.`id`
WHERE `mid` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1",
dbesc($mid), dbesc($mid),
intval($importer['channel_id']), dbesc($contact['xchan_hash']),
intval($contact['id']) intval($importer['channel_id'])
); );
*/
if(count($r)) { if($r) {
$item = $r[0]; $item = $r[0];
if(! $item['deleted']) if(! ($item['item_restrict'] & ITEM_DELETED)) {
logger('consume_feed: deleting item ' . $item['id'] . ' mid=' . $item['mid'], LOGGER_DEBUG); logger('consume_feed: deleting item ' . $item['id'] . ' mid=' . $item['mid'], LOGGER_DEBUG);
drop_item($item['id'],false);
if($item['mid'] == $item['parent_mid']) {
$r = q("UPDATE `item` SET item_restrict = (item_restrict | %d), `edited` = '%s', `changed` = '%s',
`body` = '', `title` = ''
WHERE `parent_mid` = '%s' AND `uid` = %d",
intval(ITEM_DELETED),
dbesc($when),
dbesc(datetime_convert()),
dbesc($item['mid']),
intval($importer['channel_id'])
);
}
else {
$r = q("UPDATE `item` SET item_restrict = ( item_restrict | %d ), `edited` = '%s', `changed` = '%s',
`body` = '', `title` = ''
WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
intval(ITEM_DELETED),
dbesc($when),
dbesc(datetime_convert()),
dbesc($mid),
intval($importer['channel_id'])
);
} }
} }
} }
@ -3097,21 +3069,16 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) {
if($feed->get_item_quantity()) { if($feed->get_item_quantity()) {
logger('consume_feed: feed item count = ' . $feed->get_item_quantity()); logger('consume_feed: feed item count = ' . $feed->get_item_quantity(), LOGGER_DEBUG);
// in inverse date order
if ($datedir)
$items = array_reverse($feed->get_items());
else
$items = $feed->get_items();
$items = $feed->get_items();
foreach($items as $item) { foreach($items as $item) {
$is_reply = false; $is_reply = false;
$item_id = $item->get_id(); $item_id = $item->get_id();
logger('consume_feed: processing ' . $item_id); logger('consume_feed: processing ' . $item_id, LOGGER_DEBUG);
$rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to'); $rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to');
if(isset($rawthread[0]['attribs']['']['ref'])) { if(isset($rawthread[0]['attribs']['']['ref'])) {
@ -3130,21 +3097,14 @@ logger('consume_feed: processing ' . $item_id);
$item_id = $item->get_id(); $item_id = $item->get_id();
$datarray = get_atom_elements($feed,$item); $datarray = get_atom_elements($feed,$item);
/* if(! x($datarray,'author_name'))
if((! x($datarray,'author-name')) && ($contact['network'] != NETWORK_DFRN)) $datarray['author_name'] = $contact['xchan_name'];
$datarray['author-name'] = $contact['name']; if(! x($datarray,'author_link'))
if((! x($datarray,'author-link')) && ($contact['network'] != NETWORK_DFRN)) $datarray['author_link'] = $contact['xchan_url'];
$datarray['author-link'] = $contact['url']; if(! x($datarray,'author_photo'))
if((! x($datarray,'author-avatar')) && ($contact['network'] != NETWORK_DFRN)) $datarray['author_photo'] = $contact['xchan_photo_m'];
$datarray['author-avatar'] = $contact['thumb'];
*/
if((! x($datarray,'author_name')) || (! x($datarray,'author_link'))) {
logger('consume_feed: no author information! ' . print_r($datarray,true));
continue;
}
$r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1",
$r = q("SELECT `uid`, `edited`, `body` FROM `item` WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id), dbesc($item_id),
intval($importer['channel_id']) intval($importer['channel_id'])
); );
@ -3152,70 +3112,26 @@ logger('consume_feed: processing ' . $item_id);
// Update content if 'updated' changes // Update content if 'updated' changes
if($r) { if($r) {
if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) { if((x($datarray,'edited') !== false)
&& (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
// do not accept (ignore) an earlier edit than one we currently have. // do not accept (ignore) an earlier edit than one we currently have.
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
continue; continue;
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `mid` = '%s' AND `uid` = %d LIMIT 1", update_feed_item($importer['channel_id'],$datarray);
dbesc($datarray['title']),
dbesc($datarray['body']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
dbesc($item_id),
intval($importer['channel_id'])
);
} }
continue; continue;
} }
$datarray['parent_mid'] = $parent_mid; $datarray['parent_mid'] = $parent_mid;
$datarray['uid'] = $importer['channel_id']; $datarray['uid'] = $importer['channel_id'];
// $datarray['contact-id'] = $contact['id']; $datarray['author_xchan'] = $contact['xchan_hash'];
if((activity_match($datarray['verb'],ACTIVITY_LIKE)) || (activity_match($datarray['verb'],ACTIVITY_DISLIKE))) { // FIXME pull out the author and owner
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
// only one like or dislike per person
$r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent_mid` = '%s' OR `thr_parent` = '%s') limit 1",
intval($datarray['uid']),
intval($datarray['contact-id']),
dbesc($datarray['verb']),
dbesc($parent_mid),
dbesc($parent_mid)
);
if($r && count($r))
continue;
}
if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['obj_type'] === ACTIVITY_OBJ_TAGTERM)) {
$xo = parse_xml_string($datarray['object'],false);
$xt = parse_xml_string($datarray['target'],false);
if($xt->type == ACTIVITY_OBJ_NOTE) { logger('consume_feed: ' . print_r($datarray,true),LOGGER_DATA);
$r = q("select * from item where `mid` = '%s' AND `uid` = %d limit 1",
dbesc($xt->id),
intval($importer['channel_id'])
);
if(! count($r))
continue;
// extract tag, if not duplicate, add to parent item
if($xo->id && $xo->content) {
$newtag = '#[zrl=' . $xo->id . ']'. $xo->content . '[/zrl]';
if(! (stristr($r[0]['tag'],$newtag))) {
q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1",
dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . $newtag),
intval($r[0]['id'])
);
}
}
}
}
logger('consume_feed: ' . print_r($datarray,true));
// $xx = item_store($datarray); // $xx = item_store($datarray);
$r = $xx['item_id']; $r = $xx['item_id'];
@ -3231,43 +3147,21 @@ logger('consume_feed: ' . print_r($datarray,true));
$datarray = get_atom_elements($feed,$item); $datarray = get_atom_elements($feed,$item);
if(is_array($contact)) { if(is_array($contact)) {
if((! x($datarray,'author-name')) && ($contact['network'] != NETWORK_DFRN)) if(! x($datarray,'author_name'))
$datarray['author-name'] = $contact['name']; $datarray['author_name'] = $contact['xchan_name'];
if((! x($datarray,'author-link')) && ($contact['network'] != NETWORK_DFRN)) if(! x($datarray,'author_link'))
$datarray['author-link'] = $contact['url']; $datarray['author_link'] = $contact['xchan_url'];
if((! x($datarray,'author-avatar')) && ($contact['network'] != NETWORK_DFRN)) if(! x($datarray,'author_photo'))
$datarray['author-avatar'] = $contact['thumb']; $datarray['author_photo'] = $contact['xchan_photo_m'];
} }
if((! x($datarray,'author-name')) || (! x($datarray,'author-link'))) { if((! x($datarray,'author_name')) || (! x($datarray,'author_link'))) {
logger('consume_feed: no author information! ' . print_r($datarray,true)); logger('consume_feed: no author information! ' . print_r($datarray,true));
continue; continue;
} }
// special handling for events
if((x($datarray,'obj_type')) && ($datarray['obj_type'] === ACTIVITY_OBJ_EVENT)) { $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1",
$ev = bbtoevent($datarray['body']);
if(x($ev,'desc') && x($ev,'start')) {
$ev['uid'] = $importer['channel_id'];
$ev['mid'] = $item_id;
$ev['edited'] = $datarray['edited'];
$ev['private'] = $datarray['private'];
if(is_array($contact))
$ev['cid'] = $contact['id'];
$r = q("SELECT * FROM `event` WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['channel_id'])
);
if(count($r))
$ev['id'] = $r[0]['id'];
// $xyz = event_store($ev);
continue;
}
}
$r = q("SELECT `uid`, `edited`, `body` FROM `item` WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id), dbesc($item_id),
intval($importer['channel_id']) intval($importer['channel_id'])
); );
@ -3275,79 +3169,32 @@ logger('consume_feed: ' . print_r($datarray,true));
// Update content if 'updated' changes // Update content if 'updated' changes
if($r) { if($r) {
if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) { if((x($datarray,'edited') !== false)
&& (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
// do not accept (ignore) an earlier edit than one we currently have. // do not accept (ignore) an earlier edit than one we currently have.
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
continue; continue;
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `mid` = '%s' AND `uid` = %d LIMIT 1", update_feed_item($importer['channel_id'],$datarray);
dbesc($datarray['title']),
dbesc($datarray['body']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
dbesc($item_id),
intval($importer['channel_id'])
);
} }
continue; continue;
} }
if(activity_match($datarray['verb'],ACTIVITY_FOLLOW)) {
logger('consume-feed: New follower');
new_follower($importer,$contact,$datarray,$item);
return;
}
if(activity_match($datarray['verb'],ACTIVITY_UNFOLLOW)) {
lose_follower($importer,$contact,$datarray,$item);
return;
}
if(activity_match($datarray['verb'],ACTIVITY_REQ_FRIEND)) {
logger('consume-feed: New friend request');
new_follower($importer,$contact,$datarray,$item,true);
return;
}
if(activity_match($datarray['verb'],ACTIVITY_UNFRIEND)) {
lose_sharer($importer,$contact,$datarray,$item);
return;
}
// if(! is_array($contact))
// return;
// This is my contact on another system, but it's really me.
// Turn this into a wall post.
if($contact['remote_self']) {
$datarray['wall'] = 1;
}
$datarray['parent_mid'] = $item_id; $datarray['parent_mid'] = $item_id;
$datarray['uid'] = $importer['channel_id']; $datarray['uid'] = $importer['channel_id'];
$datarray['contact-id'] = $contact['id']; $datarray['author_xchan'] = $contact['author_xchan'];
if(! link_compare($datarray['owner-link'],$contact['url'])) { // if(! link_compare($datarray['owner_link'],$contact['xchan_url'])) {
// The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, // logger('consume_feed: Correcting item owner.', LOGGER_DEBUG);
// but otherwise there's a possible data mixup on the sender's system. // $datarray['owner-name'] = $contact['name'];
// the tgroup delivery code called from item_store will correct it if it's a forum, // $datarray['owner-link'] = $contact['url'];
// but we're going to unconditionally correct it here so that the post will always be owned by our contact. // $datarray['owner-avatar'] = $contact['thumb'];
logger('consume_feed: Correcting item owner.', LOGGER_DEBUG); // }
$datarray['owner-name'] = $contact['name'];
$datarray['owner-link'] = $contact['url'];
$datarray['owner-avatar'] = $contact['thumb'];
}
// We've allowed "followers" to reach this point so we can decide if they are logger('consume_feed: ' . print_r($datarray,true),LOGGER_DATA);
// posting an @-tag delivery, which followers are allowed to do for certain
// page types. Now that we've parsed the post, let's check if it is legit. Otherwise ignore it.
if(($contact['rel'] == CONTACT_IS_FOLLOWER) && (! tgroup_check($importer['channel_id'],$datarray)))
continue;
logger('consume_feed: ' . print_r($datarray,true));
// $xx = item_store($datarray); // $xx = item_store($datarray);
$r = $xx['item_id']; $r = $xx['item_id'];
@ -3358,6 +3205,13 @@ logger('consume_feed: ' . print_r($datarray,true));
} }
}
function update_feed_item($uid,$datarray) {
logger('update_feed_item: ' . $uid . ' ' . print_r($datarray,true), LOGGER_DATA);
} }

View File

@ -1 +1 @@
2014-08-19.772 2014-08-20.773