]> git.mxchange.org Git - friendica.git/commitdiff
following random feeds
authorFriendika <info@friendika.com>
Mon, 24 Jan 2011 04:09:34 +0000 (20:09 -0800)
committerFriendika <info@friendika.com>
Mon, 24 Jan 2011 04:09:34 +0000 (20:09 -0800)
include/Scrape.php
include/poller.php
mod/follow.php

index 10ec54d1347aa968ec35c3d9b1b9185ca61976dc..8478ea40714d389365522d02d685c7befbe51307 100644 (file)
@@ -22,6 +22,8 @@ function scrape_dfrn($url) {
 
        foreach($items as $item) {
                $x = $item->getAttribute('rel');
+               if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
+                       $ret['feed_atom'] = $item->getAttribute('href');
                if(substr($x,0,5) == "dfrn-")
                        $ret[$x] = $item->getAttribute('href');
                if($x === 'lrdd') {
@@ -135,3 +137,31 @@ function scrape_vcard($url) {
 
        return $ret;
 }}
+
+
+if(! function_exists('scrape_feed')) {
+function scrape_feed($url) {
+
+       $ret = array();
+       $s = fetch_url($url);
+
+       if(! $s) 
+               return $ret;
+
+       $dom = HTML5_Parser::parse($s);
+
+       if(! $dom)
+               return $ret;
+
+       $items = $dom->getElementsByTagName('link');
+
+       // get Atom link elements
+
+       foreach($items as $item) {
+               $x = $item->getAttribute('rel');
+               if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
+                       $ret['feed_atom'] = $item->getAttribute('href');
+       }
+
+       return $ret;
+}}
\ No newline at end of file
index 8234becbb92b95d7ec32dc3fef203f6314aa6abf..024b9fbcd38c0c6144c8a4751224e7e0f286f003 100644 (file)
        if(($argc > 1) && ($argv[1] == 'force'))
                $force = true;
 
+       if(($argc > 1) && intval($argv[1])) {
+               $manual_id = intval($argv[1]);
+               $force = true;
+       }
+
+       $sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
+
        // 'stat' clause is a temporary measure until we have federation subscriptions working both directions
        $contacts = q("SELECT * FROM `contact` 
                WHERE ( ( `network` = 'dfrn' AND ( `dfrn-id` != '' OR (`issued-id` != '' AND `duplex` = 1)))
-               OR ( `network` IN ( 'stat', 'feed' ) AND `poll` != '' )) 
+               OR ( `network` IN ( 'stat', 'feed' ) AND `poll` != '' ))
+               $sql_extra 
                AND `self` = 0 AND `blocked` = 0 AND `readonly` = 0 ORDER BY RAND()");
 
        if(! count($contacts))
index 14bdb9fc6d7d1809d11fa2026a3fd1c79f251cd6..e5eb7763bf620eea6a6248384de66e7e2422ebc5 100644 (file)
@@ -48,6 +48,8 @@ function follow_post(&$a) {
                }
        }
 
+       $network = 'stat';
+
        if($hcard) {
                $vcard = scrape_vcard($hcard);
 
@@ -63,13 +65,58 @@ function follow_post(&$a) {
        if(! $profile)
                $profile = $url;
 
-       // do we have enough information?
 
        if(! x($vcard,'fn'))
                if(x($vcard,'nick'))
                        $vcard['fn'] = $vcard['nick'];
 
+       if((! isset($vcard)) && (! $poll)) {
+
+               $ret = scrape_feed($url);
+
+               if(count($ret) && $ret['feed_atom']) {
+                       $poll = $ret['feed_atom'];
+                       $vcard = array();
+                       require_once('simplepie/simplepie.inc');
+                   $feed = new SimplePie();
+                       $xml = fetch_url($poll);
+
+               $feed->set_raw_data($xml);
+
+                   $feed->init();
+
+                       $vcard['photo'] = $feed->get_image_url();
+                       $author = $feed->get_author();
+                       if($author) {                   
+                               $vcard['fn'] = trim($author->get_name());
+                               $vcard['nick'] = strtolower($vcard['fn']);
+                               if(strpos($vcard['nick'],' '))
+                                       $vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
+                               $email = $author->get_email();
+                       }
+                       else {
+                               $item = $feed->get_item(0);
+                               if($item) {
+                                       $author = $item->get_author();
+                                       if($author) {                   
+                                               $vcard['fn'] = trim($author->get_name());
+                                               $vcard['nick'] = strtolower($vcard['fn']);
+                                               if(strpos($vcard['nick'],' '))
+                                                       $vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
+                                               $email = $author->get_email();
+                                       }
+                               }
+                       }
+                       if((! $vcard['photo']) && strlen($email))
+                               $vcard['photo'] = gravatar_img($email);
+                       $network = 'feed';
+        }
+       }
+
        logger('follow: poll=' . $poll . ' notify=' . $notify . ' profile=' . $profile . ' vcard=' . print_r($vcard,true));
+
+
+       // do we have enough information?
        
        if(! ((x($vcard['fn'])) && ($poll) && ($profile))) {
                notice( t('The profile address specified does not provide adequate information.') . EOL);
@@ -115,7 +162,7 @@ function follow_post(&$a) {
                        dbesc($vcard['fn']),
                        dbesc($vcard['nick']),
                        dbesc($vcard['photo']),
-                       dbesc('stat'),
+                       dbesc($network),
                        intval(REL_FAN)
                );
        }
@@ -158,6 +205,9 @@ function follow_post(&$a) {
 
        // pull feed and consume it, which should subscribe to the hub.
 
+       $php_path = ((x($a->config,'php_path') && strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
+       proc_close(proc_open("\"$php_path\" \"include/poller.php\" \"$contact_id\" &", array(), $foo));
+
 
        // create a follow slap