X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdiaspora.php;h=f7c2c5e8ec2e77ac88f9dad8b08b80b70fae82aa;hb=598a2563e844477de2f688663c7c46962b26b602;hp=dca857a19833369cf9f5d43eca1e41e8e5820b41;hpb=a33031634efef94c0985cd2517f10ccd36b40b5f;p=friendica.git diff --git a/include/diaspora.php b/include/diaspora.php old mode 100755 new mode 100644 index dca857a198..f7c2c5e8ec --- a/include/diaspora.php +++ b/include/diaspora.php @@ -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; } } @@ -1159,6 +1179,48 @@ 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 AND `deleted` = 0 ", + dbesc($parent_item['uri']), + intval($importer['uid']) + ); + + if(count($myconv)) { + $importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname']; + + foreach($myconv as $conv) { + + // now if we find a match, it means we're in this conversation + + if(! link_compare($conv['author-link'],$importer_url)) + continue; + + require_once('include/enotify.php'); + + $conv_parent = $conv['parent']; + + notification(array( + 'type' => NOTIFY_COMMENT, + 'notify_flags' => $importer['notify-flags'], + 'language' => $importer['language'], + 'to_name' => $importer['username'], + 'to_email' => $importer['email'], + 'uid' => $importer['uid'], + 'item' => $datarray, + 'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id, + 'source_name' => $datarray['author-name'], + 'source_link' => $datarray['author-link'], + 'source_photo' => $datarray['author-avatar'], + 'verb' => ACTIVITY_POST, + 'otype' => 'item', + 'parent' => $conv_parent, + + )); + + // only send one notification + break; + } + } return; } @@ -1695,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']) ); @@ -1743,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']) ); @@ -1878,6 +1940,7 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { $images = array(); + $title = $item['title']; $body = $item['body']; /* @@ -1902,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) { @@ -1989,8 +2055,12 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) { $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); $theiraddr = $contact['addr']; - $p = q("select guid from item where parent = %d limit 1", - $item['parent'] + // The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always + // return the items ordered by `item`.`id`, in which case the wrong item is chosen as the parent. + // The only item with `parent` and `id` as the parent id is the parent item. + $p = q("select guid from item where parent = %d and id = %d limit 1", + intval($item['parent']), + intval($item['parent']) ); if(count($p)) $parent_guid = $p[0]['guid']; @@ -2045,8 +2115,12 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $theiraddr = $contact['addr']; - $p = q("select guid from item where parent = %d limit 1", - $item['parent'] + // The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always + // return the items ordered by `item`.`id`, in which case the wrong item is chosen as the parent. + // The only item with `parent` and `id` as the parent id is the parent item. + $p = q("select guid from item where parent = %d and id = %d limit 1", + intval($item['parent']), + intval($item['parent']) ); if(count($p)) $parent_guid = $p[0]['guid']; @@ -2225,6 +2299,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']); @@ -2235,14 +2314,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')))) {