Bugfix: When fetching a feed's name, take the title or description, but not the author name.

This commit is contained in:
Michael Vogel 2014-07-22 07:59:11 +02:00
parent ed1dce93d6
commit b1afaa50de

View file

@ -120,7 +120,7 @@ function scrape_meta($url) {
$s = fetch_url($url); $s = fetch_url($url);
if(! $s) if(! $s)
return $ret; return $ret;
$headers = $a->get_curl_headers(); $headers = $a->get_curl_headers();
@ -128,7 +128,7 @@ function scrape_meta($url) {
$lines = explode("\n",$headers); $lines = explode("\n",$headers);
if(count($lines)) { if(count($lines)) {
foreach($lines as $line) { foreach($lines as $line) {
// don't try and run feeds through the html5 parser // don't try and run feeds through the html5 parser
if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml')))) if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
return ret; return ret;
@ -169,13 +169,13 @@ function scrape_vcard($url) {
$s = fetch_url($url); $s = fetch_url($url);
if(! $s) if(! $s)
return $ret; return $ret;
$headers = $a->get_curl_headers(); $headers = $a->get_curl_headers();
$lines = explode("\n",$headers); $lines = explode("\n",$headers);
if(count($lines)) { if(count($lines)) {
foreach($lines as $line) { foreach($lines as $line) {
// don't try and run feeds through the html5 parser // don't try and run feeds through the html5 parser
if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml')))) if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
return ret; return ret;
@ -236,14 +236,14 @@ function scrape_feed($url) {
logger('scrape_feed: returns: ' . $code . ' headers=' . $headers, LOGGER_DEBUG); logger('scrape_feed: returns: ' . $code . ' headers=' . $headers, LOGGER_DEBUG);
if(! $s) { if(! $s) {
logger('scrape_feed: no data returned for ' . $url); logger('scrape_feed: no data returned for ' . $url);
return $ret; return $ret;
} }
$lines = explode("\n",$headers); $lines = explode("\n",$headers);
if(count($lines)) { if(count($lines)) {
foreach($lines as $line) { foreach($lines as $line) {
if(stristr($line,'content-type:')) { if(stristr($line,'content-type:')) {
if(stristr($line,'application/atom+xml') || stristr($s,'<feed')) { if(stristr($line,'application/atom+xml') || stristr($s,'<feed')) {
$ret['feed_atom'] = $url; $ret['feed_atom'] = $url;
@ -299,7 +299,7 @@ function scrape_feed($url) {
if(! x($ret,'feed_rss')) if(! x($ret,'feed_rss'))
$ret['feed_rss'] = $item->getAttribute('href'); $ret['feed_rss'] = $item->getAttribute('href');
} }
} }
} }
// Drupal and perhaps others only provide relative URL's. Turn them into absolute. // Drupal and perhaps others only provide relative URL's. Turn them into absolute.
@ -617,7 +617,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
if(x($feedret,'photo') && (! x($vcard,'photo'))) if(x($feedret,'photo') && (! x($vcard,'photo')))
$vcard['photo'] = $feedret['photo']; $vcard['photo'] = $feedret['photo'];
require_once('library/simplepie/simplepie.inc'); require_once('library/simplepie/simplepie.inc');
$feed = new SimplePie(); $feed = new SimplePie();
$xml = fetch_url($poll); $xml = fetch_url($poll);
logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA); logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA);
@ -628,7 +628,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
// Don't try and parse an empty string // Don't try and parse an empty string
$feed->set_raw_data(($xml) ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>'); $feed->set_raw_data(($xml) ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>');
$feed->init(); $feed->init();
if($feed->error()) if($feed->error())
logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error()); logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error());
@ -637,7 +637,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$vcard['photo'] = $feed->get_image_url(); $vcard['photo'] = $feed->get_image_url();
$author = $feed->get_author(); $author = $feed->get_author();
if($author) { if($author) {
$vcard['fn'] = unxmlify(trim($author->get_name())); $vcard['fn'] = unxmlify(trim($author->get_name()));
if(! $vcard['fn']) if(! $vcard['fn'])
$vcard['fn'] = trim(unxmlify($author->get_email())); $vcard['fn'] = trim(unxmlify($author->get_email()));
@ -648,18 +648,18 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$profile = trim(unxmlify($author->get_link())); $profile = trim(unxmlify($author->get_link()));
if(! $vcard['photo']) { if(! $vcard['photo']) {
$rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
if($rawtags) { if($rawtags) {
$elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo')) if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
$vcard['photo'] = $elems['link'][0]['attribs']['']['href']; $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
} }
} }
} }
else { else {
$item = $feed->get_item(0); $item = $feed->get_item(0);
if($item) { if($item) {
$author = $item->get_author(); $author = $item->get_author();
if($author) { if($author) {
$vcard['fn'] = trim(unxmlify($author->get_name())); $vcard['fn'] = trim(unxmlify($author->get_name()));
if(! $vcard['fn']) if(! $vcard['fn'])
$vcard['fn'] = trim(unxmlify($author->get_email())); $vcard['fn'] = trim(unxmlify($author->get_email()));
@ -676,11 +676,11 @@ function probe_url($url, $mode = PROBE_NORMAL) {
} }
if(! $vcard['photo']) { if(! $vcard['photo']) {
$rawtags = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); $rawtags = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
if($rawtags) { if($rawtags) {
$elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo')) if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
$vcard['photo'] = $elems['link'][0]['attribs']['']['href']; $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
} }
} }
} }
} }
@ -690,8 +690,13 @@ function probe_url($url, $mode = PROBE_NORMAL) {
if($poll === $profile) if($poll === $profile)
$lnk = $feed->get_permalink(); $lnk = $feed->get_permalink();
if(isset($lnk) && strlen($lnk)) if(isset($lnk) && strlen($lnk))
$profile = $lnk; $profile = $lnk;
if(! $network) {
$network = NETWORK_FEED;
// If it is a feed, don't take the author name as feed name
unset($vcard['fn']);
}
if(! (x($vcard,'fn'))) if(! (x($vcard,'fn')))
$vcard['fn'] = notags($feed->get_title()); $vcard['fn'] = notags($feed->get_title());
if(! (x($vcard,'fn'))) if(! (x($vcard,'fn')))
@ -706,8 +711,6 @@ function probe_url($url, $mode = PROBE_NORMAL) {
if(strpos($vcard['nick'],' ')) if(strpos($vcard['nick'],' '))
$vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' '))); $vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
} }
if(! $network)
$network = NETWORK_FEED;
if(! $priority) if(! $priority)
$priority = 2; $priority = 2;
} }
@ -715,7 +718,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
if(! x($vcard,'photo')) { if(! x($vcard,'photo')) {
$a = get_app(); $a = get_app();
$vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg' ; $vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg' ;
} }
if(! $profile) if(! $profile)
@ -728,7 +731,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$vcard['fn'] = notags($vcard['fn']); $vcard['fn'] = notags($vcard['fn']);
$vcard['nick'] = str_replace(' ','',notags($vcard['nick'])); $vcard['nick'] = str_replace(' ','',notags($vcard['nick']));
$result['name'] = $vcard['fn']; $result['name'] = $vcard['fn'];
$result['nick'] = $vcard['nick']; $result['nick'] = $vcard['nick'];
$result['url'] = $profile; $result['url'] = $profile;