correct item author for feeds with multiple or different authors
This commit is contained in:
parent
653ed27fc9
commit
3a10956b20
2
boot.php
2
boot.php
@ -450,6 +450,8 @@ define ( 'NAMESPACE_FEED', 'http://schemas.google.com/g/2010#updates-
|
|||||||
define ( 'NAMESPACE_OSTATUS', 'http://ostatus.org/schema/1.0' );
|
define ( 'NAMESPACE_OSTATUS', 'http://ostatus.org/schema/1.0' );
|
||||||
define ( 'NAMESPACE_STATUSNET', 'http://status.net/schema/api/1/' );
|
define ( 'NAMESPACE_STATUSNET', 'http://status.net/schema/api/1/' );
|
||||||
define ( 'NAMESPACE_ATOM1', 'http://www.w3.org/2005/Atom' );
|
define ( 'NAMESPACE_ATOM1', 'http://www.w3.org/2005/Atom' );
|
||||||
|
define ( 'NAMESPACE_YMEDIA', 'http://search.yahoo.com/mrss/' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* activity stream defines
|
* activity stream defines
|
||||||
*/
|
*/
|
||||||
|
@ -878,6 +878,10 @@ function import_author_xchan($x) {
|
|||||||
$y = import_author_rss($x);
|
$y = import_author_rss($x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($x['network'] === 'unknown') {
|
||||||
|
$y = import_author_unknown($x);
|
||||||
|
}
|
||||||
|
|
||||||
return(($y) ? $y : false);
|
return(($y) ? $y : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -940,6 +944,51 @@ function import_author_rss($x) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function import_author_unknown($x) {
|
||||||
|
|
||||||
|
if(! $x['url'])
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$r = q("select xchan_hash from xchan where xchan_network = 'unknown' and xchan_url = '%s' limit 1",
|
||||||
|
dbesc($x['url'])
|
||||||
|
);
|
||||||
|
if($r) {
|
||||||
|
logger('import_author_unknown: in cache' , LOGGER_DEBUG);
|
||||||
|
return $r[0]['xchan_hash'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = trim($x['name']);
|
||||||
|
|
||||||
|
$r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_url, xchan_name, xchan_network )
|
||||||
|
values ( '%s', '%s', '%s', '%s', '%s' )",
|
||||||
|
dbesc($x['url']),
|
||||||
|
dbesc($x['url']),
|
||||||
|
dbesc($x['url']),
|
||||||
|
dbesc(($name) ? $name : t('(Unknown)')),
|
||||||
|
dbesc('unknown')
|
||||||
|
);
|
||||||
|
if($r && $x['photo']) {
|
||||||
|
|
||||||
|
$photos = import_profile_photo($x['photo']['src'],$x['url']);
|
||||||
|
|
||||||
|
if($photos) {
|
||||||
|
$r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_url = '%s' and xchan_network = 'unknown' limit 1",
|
||||||
|
dbesc(datetime_convert('UTC','UTC',$arr['photo_updated'])),
|
||||||
|
dbesc($photos[0]),
|
||||||
|
dbesc($photos[1]),
|
||||||
|
dbesc($photos[2]),
|
||||||
|
dbesc($photos[3]),
|
||||||
|
dbesc($x['url'])
|
||||||
|
);
|
||||||
|
if($r)
|
||||||
|
return $x['url'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function encode_item($item) {
|
function encode_item($item) {
|
||||||
$x = array();
|
$x = array();
|
||||||
@ -1382,6 +1431,16 @@ function get_atom_elements($feed,$item,&$author) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check for a yahoo media element (github etc.)
|
||||||
|
|
||||||
|
if(! $author['author_photo']) {
|
||||||
|
$rawmedia = $item->get_item_tags(NAMESPACE_YMEDIA,'thumbnail');
|
||||||
|
if($rawmedia && $rawmedia[0]['attribs']['']['url']) {
|
||||||
|
$author['author_photo'] = strip_tags(unxmlify($rawmedia[0]['attribs']['']['url']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// No photo/profile-link on the item - look at the feed level
|
// No photo/profile-link on the item - look at the feed level
|
||||||
|
|
||||||
if((! (x($author,'author_link'))) || (! (x($author,'author_photo')))) {
|
if((! (x($author,'author_link'))) || (! (x($author,'author_photo')))) {
|
||||||
@ -3229,6 +3288,21 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) {
|
|||||||
if(! x($author,'author_photo'))
|
if(! x($author,'author_photo'))
|
||||||
$author['author_photo'] = $contact['xchan_photo_m'];
|
$author['author_photo'] = $contact['xchan_photo_m'];
|
||||||
|
|
||||||
|
$datarray['author_xchan'] = '';
|
||||||
|
|
||||||
|
if($author['author_link'] != $contact['xchan_url']) {
|
||||||
|
$x = import_author_unkown(array('name' => $author['author_name'],'url' => $author['author_link'],'photo' => array('src' => $author['author_photo'])));
|
||||||
|
if($x)
|
||||||
|
$datarray['author_xchan'] = $x;
|
||||||
|
|
||||||
|
}
|
||||||
|
if(! $datarray['author_xchan'])
|
||||||
|
$datarray['author_xchan'] = $contact['xchan_hash'];
|
||||||
|
|
||||||
|
|
||||||
|
$datarray['owner_xchan'] = $contact['xchan_hash'];
|
||||||
|
|
||||||
|
|
||||||
$r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1",
|
$r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1",
|
||||||
dbesc($item_id),
|
dbesc($item_id),
|
||||||
intval($importer['channel_id'])
|
intval($importer['channel_id'])
|
||||||
@ -3252,10 +3326,6 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) {
|
|||||||
$datarray['parent_mid'] = $parent_mid;
|
$datarray['parent_mid'] = $parent_mid;
|
||||||
$datarray['uid'] = $importer['channel_id'];
|
$datarray['uid'] = $importer['channel_id'];
|
||||||
|
|
||||||
//FIXME
|
|
||||||
$datarray['owner_xchan'] = $datarray['author_xchan'] = $contact['xchan_hash'];
|
|
||||||
|
|
||||||
// FIXME pull out the author and owner
|
|
||||||
|
|
||||||
|
|
||||||
logger('consume_feed: ' . print_r($datarray,true),LOGGER_DATA);
|
logger('consume_feed: ' . print_r($datarray,true),LOGGER_DATA);
|
||||||
@ -3287,6 +3357,20 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$datarray['author_xchan'] = '';
|
||||||
|
|
||||||
|
if($author['author_link'] != $contact['xchan_url']) {
|
||||||
|
$x = import_author_unkown(array('name' => $author['author_name'],'url' => $author['author_link'],'photo' => array('src' => $author['author_photo'])));
|
||||||
|
if($x)
|
||||||
|
$datarray['author_xchan'] = $x;
|
||||||
|
|
||||||
|
}
|
||||||
|
if(! $datarray['author_xchan'])
|
||||||
|
$datarray['author_xchan'] = $contact['xchan_hash'];
|
||||||
|
|
||||||
|
|
||||||
|
$datarray['owner_xchan'] = $contact['xchan_hash'];
|
||||||
|
|
||||||
|
|
||||||
$r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1",
|
$r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1",
|
||||||
dbesc($item_id),
|
dbesc($item_id),
|
||||||
@ -3312,9 +3396,7 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) {
|
|||||||
|
|
||||||
$datarray['parent_mid'] = $item_id;
|
$datarray['parent_mid'] = $item_id;
|
||||||
$datarray['uid'] = $importer['channel_id'];
|
$datarray['uid'] = $importer['channel_id'];
|
||||||
//FIXME
|
|
||||||
$datarray['owner_xchan'] = $datarray['author_xchan'] = $contact['xchan_hash'];
|
|
||||||
|
|
||||||
if(! link_compare($author['owner_link'],$contact['xchan_url'])) {
|
if(! link_compare($author['owner_link'],$contact['xchan_url'])) {
|
||||||
logger('consume_feed: Correcting item owner.', LOGGER_DEBUG);
|
logger('consume_feed: Correcting item owner.', LOGGER_DEBUG);
|
||||||
$author['owner_name'] = $contact['name'];
|
$author['owner_name'] = $contact['name'];
|
||||||
@ -3322,7 +3404,7 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) {
|
|||||||
$author['owner_avatar'] = $contact['thumb'];
|
$author['owner_avatar'] = $contact['thumb'];
|
||||||
}
|
}
|
||||||
|
|
||||||
logger('consume_feed: author ' . print_r($author,true));
|
logger('consume_feed: author ' . print_r($author,true),LOGGER_DEBUG);
|
||||||
|
|
||||||
|
|
||||||
logger('consume_feed: ' . print_r($datarray,true),LOGGER_DATA);
|
logger('consume_feed: ' . print_r($datarray,true),LOGGER_DATA);
|
||||||
|
Reference in New Issue
Block a user