]> git.mxchange.org Git - friendica.git/blobdiff - mod/salmon.php
Merge pull request #1443 from fabrixxm/issue-1437
[friendica.git] / mod / salmon.php
index 6172d17a1ddda0e7c0816fc2cdfbf945f9becbb4..11e42d94364a36cc4eb6f155d4ccd49815e6dc87 100644 (file)
@@ -15,7 +15,7 @@ function salmon_return($val) {
        if($val >= 200 && $val < 300)
                $err = 'OK';
 
-       logger('mod-salmon returns ' . $val);   
+       logger('mod-salmon returns ' . $val);
        header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err);
        killme();
 
@@ -30,7 +30,7 @@ function salmon_post(&$a) {
        $nick       = (($a->argc > 1) ? notags(trim($a->argv[1])) : '');
        $mentions   = (($a->argc > 2 && $a->argv[2] === 'mention') ? true : false);
 
-       $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 LIMIT 1",
+       $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
                dbesc($nick)
        );
        if(! count($r))
@@ -50,7 +50,7 @@ function salmon_post(&$a) {
                $base = $dom->env;
        elseif($dom->data)
                $base = $dom;
-       
+
        if(! $base) {
                logger('mod-salmon: unable to locate salmon data in xml ');
                http_status_exit(400);
@@ -92,7 +92,7 @@ function salmon_post(&$a) {
        // Create a fake feed wrapper so simplepie doesn't choke
 
        $tpl = get_markup_template('fake_feed.tpl');
-       
+
        $base = substr($data,strpos($data,'<entry'));
 
        $feedxml = $tpl . $base . '</feed>';
@@ -100,7 +100,7 @@ function salmon_post(&$a) {
        logger('mod-salmon: Processed feed: ' . $feedxml);
 
        // Now parse it like a normal atom feed to scrape out the author URI
-       
+
     $feed = new SimplePie();
     $feed->set_raw_data($feedxml);
     $feed->enable_order_by_date(false);
@@ -170,15 +170,29 @@ function salmon_post(&$a) {
        *
        */
 
-       $r = q("SELECT * FROM `contact` WHERE `network` = 'stat' AND ( `url` = '%s' OR `alias` = '%s'
+       $r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND ( `url` = '%s' OR `alias` = '%s' 
                AND `uid` = %d LIMIT 1",
+               dbesc(NETWORK_OSTATUS),
                dbesc($author_link),
                dbesc($author_link),
                intval($importer['uid'])
        );
        if(! count($r)) {
                logger('mod-salmon: Author unknown to us.');
-       }       
+               if(get_pconfig($importer['uid'],'system','ostatus_autofriend')) {
+                       require_once('include/follow.php');
+                       $result = new_contact($importer['uid'],$author_link);
+                       if($result['success']) {
+                               $r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND ( `url` = '%s' OR `alias` = '%s' ) 
+                                       AND `uid` = %d LIMIT 1",
+                                       dbesc(NETWORK_OSTATUS),
+                                       dbesc($author_link),
+                                       dbesc($author_link),
+                                       intval($importer['uid'])
+                               );
+                       }
+               }
+       }
 
        // is this a follower? Or have we ignored the person?
        // If so we can not accept this post.
@@ -209,7 +223,3 @@ function salmon_post(&$a) {
 
        http_status_exit(200);
 }
-
-
-
-