]> git.mxchange.org Git - friendica.git/blobdiff - mod/follow.php
linkify - need at least one character after ://
[friendica.git] / mod / follow.php
index d5651ea39e79a397f9cf42eae9c98979d0291ad2..e5eb7763bf620eea6a6248384de66e7e2422ebc5 100644 (file)
@@ -38,16 +38,18 @@ function follow_post(&$a) {
                $ret = scrape_dfrn($dfrn);
                if(is_array($ret) && x($ret,'dfrn-request')) {
                        if(strlen($a->path))
-                               $myaddr = urlencode($a->get_baseurl() . '/profile/' . $a->user['nickname']);
+                               $myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']);
                        else
-                               $myaddr = urlencode($a->user['nickname'] . '@' . $a->get_hostname());
+                               $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname());
  
-                       goaway($ret['dfrn-request'] . "&address=$myaddr");
+                       goaway($ret['dfrn-request'] . "&addr=$myaddr");
                
                        // NOTREACHED
                }
        }
 
+       $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
 
@@ -173,7 +223,8 @@ function follow_post(&$a) {
                '$type' => 'text',
                '$content' => t('following'),
                '$nick' => $a->user['nickname'],
-               '$verb' => ACTIVITY_FOLLOW
+               '$verb' => ACTIVITY_FOLLOW,
+               '$ostat_follow' => ''
        ));
 
        $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` 
@@ -182,7 +233,7 @@ function follow_post(&$a) {
        );
 
 
-       if((x($contact,'notify')) && (strlen($contact['notify']))) {
+       if((count($r)) && (x($contact,'notify')) && (strlen($contact['notify']))) {
                require_once('include/salmon.php');
                slapper($r[0],$contact['notify'],$slap);
        }