]> git.mxchange.org Git - friendica.git/blobdiff - include/diaspora.php
Merge pull request #310 from simonlnu/master
[friendica.git] / include / diaspora.php
old mode 100755 (executable)
new mode 100644 (file)
index 19bba52..3f2cdf8
@@ -9,6 +9,12 @@ require_once('include/queue_fn.php');
 
 function diaspora_dispatch_public($msg) {
 
+       $enabled = intval(get_config('system','diaspora_enabled'));
+       if(! $enabled) {
+               logger('mod-diaspora: disabled');
+               return;
+       }
+
        $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN ( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' ) AND `account_expired` = 0 ",
                dbesc(NETWORK_DIASPORA),
                dbesc($msg['author'])
@@ -29,6 +35,12 @@ function diaspora_dispatch($importer,$msg) {
 
        $ret = 0;
 
+       $enabled = intval(get_config('system','diaspora_enabled'));
+       if(! $enabled) {
+               logger('mod-diaspora: disabled');
+               return;
+       }
+
        // php doesn't like dashes in variable names
 
        $msg['message'] = str_replace(
@@ -557,6 +569,14 @@ function diaspora_request($importer,$xml) {
                return;
        }
 
+       $g = q("select def_gid from user where uid = %d limit 1",
+               intval($importer['uid'])
+       );
+       if($g && intval($g[0]['def_gid'])) {
+               require_once('include/group.php');
+               group_add_member($importer['uid'],'',$contact_record['id'],$g[0]['def_gid']);
+       }
+
        if($importer['page-flags'] == PAGE_NORMAL) {
 
                $hash = random_string() . (string) time();   // Generate a confirm_key
@@ -688,16 +708,16 @@ function diaspora_post($importer,$xml) {
 
                                // don't link tags that are already embedded in links
 
-                               if(preg_match('/\[(.*?)' . preg_quote($tag) . '(.*?)\]/',$body))
+                               if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body))
                                        continue;
-                               if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag) . '(.*?)\)/',$body))
+                               if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body))
                                        continue;
 
                                $basetag = str_replace('_',' ',substr($tag,1));
-                               $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
+                               $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
                                if(strlen($str_tags))
                                        $str_tags .= ',';
-                               $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
+                               $str_tags .= '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
                                continue;
                        }
                }
@@ -853,17 +873,17 @@ function diaspora_reshare($importer,$xml) {
 
                                // don't link tags that are already embedded in links
 
-                               if(preg_match('/\[(.*?)' . preg_quote($tag) . '(.*?)\]/',$body))
+                               if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body))
                                        continue;
-                               if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag) . '(.*?)\)/',$body))
+                               if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body))
                                        continue;
 
 
                                $basetag = str_replace('_',' ',substr($tag,1));
-                               $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
+                               $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
                                if(strlen($str_tags))
                                        $str_tags .= ',';
-                               $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
+                               $str_tags .= '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
                                continue;
                        }
                }
@@ -1094,17 +1114,17 @@ function diaspora_comment($importer,$xml,$msg) {
 
                                // don't link tags that are already embedded in links
 
-                               if(preg_match('/\[(.*?)' . preg_quote($tag) . '(.*?)\]/',$body))
+                               if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body))
                                        continue;
-                               if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag) . '(.*?)\)/',$body))
+                               if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body))
                                        continue;
 
 
                                $basetag = str_replace('_',' ',substr($tag,1));
-                               $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
+                               $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
                                if(strlen($str_tags))
                                        $str_tags .= ',';
-                               $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
+                               $str_tags .= '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
                                continue;
                        }
                }
@@ -1160,7 +1180,7 @@ function diaspora_comment($importer,$xml,$msg) {
                proc_run('php','include/notifier.php','comment',$message_id);
        }
 
-       $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 ",
+       $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0 ",
                dbesc($parent_item['uri']),
                intval($importer['uid'])
        );
@@ -1187,7 +1207,7 @@ function diaspora_comment($importer,$xml,$msg) {
                                'to_email'     => $importer['email'],
                                'uid'          => $importer['uid'],
                                'item'         => $datarray,
-                               'link'             => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
+                               'link'             => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id,
                                'source_name'  => $datarray['author-name'],
                                'source_link'  => $datarray['author-link'],
                                'source_photo' => $datarray['author-avatar'],
@@ -1737,7 +1757,7 @@ function diaspora_retraction($importer,$xml) {
                contact_remove($contact['id']);
        }
        elseif($type === 'Post') {
-               $r = q("select * from item where guid = '%s' and uid = %d limit 1",
+               $r = q("select * from item where guid = '%s' and uid = %d and not file like '%%[%%' limit 1",
                        dbesc('guid'),
                        intval($importer['uid'])
                );
@@ -1785,7 +1805,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
        }
 
        if($type === 'StatusMessage') {
-               $r = q("select * from item where guid = '%s' and uid = %d limit 1",
+               $r = q("select * from item where guid = '%s' and uid = %d and not file like '%%[%%' limit 1",
                        dbesc($guid),
                        intval($importer['uid'])
                );
@@ -1920,6 +1940,7 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
 
        $images = array();
 
+       $title = $item['title'];
        $body = $item['body'];
 
 /*
@@ -1944,9 +1965,12 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
                }
        }       
 */
-
        $body = xmlify(html_entity_decode(bb2diaspora($body)));
 
+       if(strlen($title))
+               $body = xmlify('**' . html_entity_decode($title) . '**' . "\n") . $body;
+
+
        if($item['attach']) {
                $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism',$item['attach'],$matches,PREG_SET_ORDER);
                if(cnt) {
@@ -2267,6 +2291,11 @@ function diaspora_send_mail($item,$owner,$contact) {
 
 function diaspora_transmit($owner,$contact,$slap,$public_batch) {
 
+       $enabled = intval(get_config('system','diaspora_enabled'));
+       if(! $enabled) {
+               return 200;
+       }
+
        $a = get_app();
        $logid = random_string(4);
        $dest_url = (($public_batch) ? $contact['batch'] : $contact['notify']);
@@ -2277,14 +2306,20 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch) {
 
        logger('diaspora_transmit: ' . $logid . ' ' . $dest_url);
 
-       if(! intval(get_config('system','diaspora_test')))
-               post_url($dest_url . '/', $slap);
+       if(was_recently_delayed($contact['id'])) {
+               $return_code = 0;
+       }
        else {
-               logger('diaspora_transmit: test_mode');
-               return 200;
+               if(! intval(get_config('system','diaspora_test'))) {
+                       post_url($dest_url . '/', $slap);
+                       $return_code = $a->get_curl_code();
+               }
+               else {
+                       logger('diaspora_transmit: test_mode');
+                       return 200;
+               }
        }
-
-       $return_code = $a->get_curl_code();
+       
        logger('diaspora_transmit: ' . $logid . ' returns: ' . $return_code);
 
        if((! $return_code) || (($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after')))) {