]> git.mxchange.org Git - friendica.git/commitdiff
better twitter follow support
authorFriendika <info@friendika.com>
Tue, 5 Apr 2011 03:40:31 +0000 (20:40 -0700)
committerFriendika <info@friendika.com>
Tue, 5 Apr 2011 03:40:31 +0000 (20:40 -0700)
include/Scrape.php
mod/follow.php

index 21820ddaff10cdb2886e9cc87ea9d7edc8ccfb7f..002fdfb35ac2fdb5d33028f15b9b9bbf7cecb50c 100644 (file)
@@ -227,16 +227,36 @@ function scrape_feed($url) {
        if(! $dom)
                return $ret;
 
+
+       $items = $dom->getElementsByTagName('img');
+
+       // get img elements (twitter)
+
+       if($items) {
+               foreach($items as $item) {
+                       $x = $item->getAttribute('id');
+                       if($x === 'profile-image') {
+                               $ret['photo'] = $item->getAttribute('src');
+                       }
+               }
+       }
+
        $items = $dom->getElementsByTagName('link');
 
-       // get Atom link elements
+       // get Atom/RSS link elements, take the first one of either.
 
-       foreach($items as $item) {
-               $x = $item->getAttribute('rel');
-               if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
-                       $ret['feed_atom'] = $item->getAttribute('href');
-               if(($x === 'alternate') && ($item->getAttribute('type') === 'application/rss+xml'))
-                       $ret['feed_rss'] = $item->getAttribute('href');
+       if($items) {
+               foreach($items as $item) {
+                       $x = $item->getAttribute('rel');
+                       if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml')) {
+                               if(! x($ret,'feed_atom'))
+                                       $ret['feed_atom'] = $item->getAttribute('href');
+                       }
+                       if(($x === 'alternate') && ($item->getAttribute('type') === 'application/rss+xml')) {
+                               if(! x($ret,'feed_rss'))
+                                       $ret['feed_rss'] = $item->getAttribute('href');
+                       }
+               }       
        }
 
        return $ret;
index 06e81ceedd66b7aed2f7ac62d00fca875ff71842..48ad667476c788378b3326b1e8f7fd05f736b37a 100644 (file)
@@ -112,6 +112,8 @@ function follow_post(&$a) {
                if(count($ret) && ($ret['feed_atom'] || $ret['feed_rss'])) {
                        $poll = ((x($ret,'feed_atom')) ? unamp($ret['feed_atom']) : unamp($ret['feed_rss']));
                        $vcard = array();
+                               if(x($ret,'photo'))
+                                       $vcard['photo'] = $ret['photo'];
                        require_once('simplepie/simplepie.inc');
                    $feed = new SimplePie();
                        $xml = fetch_url($poll);
@@ -120,7 +122,8 @@ function follow_post(&$a) {
 
                    $feed->init();
 
-                       $vcard['photo'] = $feed->get_image_url();
+                       if(! x($vcard,'photo'))
+                               $vcard['photo'] = $feed->get_image_url();
                        $author = $feed->get_author();
                        if($author) {                   
                                $vcard['fn'] = unxmlify(trim($author->get_name()));