diff options
Diffstat (limited to 'include/diaspora.php')
-rwxr-xr-x | include/diaspora.php | 95 |
1 files changed, 45 insertions, 50 deletions
diff --git a/include/diaspora.php b/include/diaspora.php index 79d3909ca..187793d2b 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -24,9 +24,8 @@ function diaspora_dispatch_public($msg) { // find everybody following or allowing this author - $r = q("SELECT * from channel where channel_id in ( SELECT abook_channel from abook left join xchan on abook_xchan = xchan_hash WHERE xchan_network like '%%diaspora%%' and xchan_addr = '%s' ) and ( channel_pageflags & %d ) = 0 ", - dbesc($msg['author']), - intval(PAGE_REMOVED) + $r = q("SELECT * from channel where channel_id in ( SELECT abook_channel from abook left join xchan on abook_xchan = xchan_hash WHERE xchan_network like '%%diaspora%%' and xchan_addr = '%s' ) and channel_removed = 0 ", + dbesc($msg['author']) ); // also need to look for those following public streams @@ -65,8 +64,6 @@ function diaspora_dispatch($importer,$msg) { } $allowed = get_pconfig($importer['channel_id'],'system','diaspora_allowed'); - if($allowed === false) - $allowed = 1; if(! intval($allowed)) { logger('mod-diaspora: disallowed for channel ' . $importer['channel_name']); @@ -179,8 +176,6 @@ function diaspora_process_outbound($arr) { $allowed = get_pconfig($arr['channel']['channel_id'],'system','diaspora_allowed'); - if($allowed === false) - $allowed = 1; if(! intval($allowed)) { logger('mod-diaspora: disallowed for channel ' . $arr['channel']['channel_name']); @@ -194,7 +189,7 @@ function diaspora_process_outbound($arr) { $target_item = $arr['target_item']; - if($target_item && array_key_exists('item_flags',$target_item) && ($target_item['item_flags'] & ITEM_OBSCURED)) { + if($target_item && array_key_exists('item_obscured',$target_item) && intval($target_item['item_obscured'])) { $key = get_config('system','prvkey'); if($target_item['title']) $target_item['title'] = crypto_unencapsulate(json_decode($target_item['title'],true),$key); @@ -243,7 +238,7 @@ function diaspora_process_outbound($arr) { if(! $contact['xchan_pubkey']) continue; - if(($target_item['item_restrict'] & ITEM_DELETED) + if(intval($target_item['item_deleted']) && (($target_item['mid'] === $target_item['parent_mid']) || $arr['followup'])) { // send both top-level retractions and relayable retractions for owner to relay diaspora_send_retraction($target_item,$arr['channel'],$contact); @@ -272,8 +267,8 @@ function diaspora_process_outbound($arr) { $contact = $arr['hub']; - if(($target_item['deleted']) - && ($target_item['mid'] === $target_item['parent_mod'])) { + if(intval($target_item['item_deleted']) + && ($target_item['mid'] === $target_item['parent_mid'])) { // top-level retraction logger('delivery: diaspora retract: ' . $loc); diaspora_send_retraction($target_item,$arr['channel'],$contact,true); @@ -334,6 +329,7 @@ function diaspora_get_contact_by_handle($uid,$handle) { function find_diaspora_person_by_handle($handle) { $person = false; + $refresh = false; if(diaspora_is_blacklisted($handle)) return false; @@ -344,17 +340,21 @@ function find_diaspora_person_by_handle($handle) { if($r) { $person = $r[0]; logger('find_diaspora_person_by handle: in cache ' . print_r($r,true), LOGGER_DATA); + if($person['xchan_name_date'] < datetime_convert('UTC','UTC', 'now - 1 month')) { + logger('Updating Diaspora cached record for ' . $handle); + $refresh = true; + } } - if(! $person) { + if((! $person) || ($refresh)) { // try webfinger. Make sure to distinguish between diaspora, - // redmatrix w/diaspora protocol and friendica w/diaspora protocol. + // hubzilla w/diaspora protocol and friendica w/diaspora protocol. $result = discover_by_webbie($handle); if($result) { $r = q("select * from xchan where xchan_addr = '%s' limit 1", - dbesc($handle) + dbesc(str_replace('acct:','',$handle)) ); if($r) { $person = $r[0]; @@ -728,6 +728,7 @@ function diaspora_request($importer,$xml) { $msg = t('You have started sharing with a $Projectname premium channel.'); $msg .= t('$Projectname premium channels are not available for sharing with Diaspora members. This sharing request has been blocked.') . "\r"; + $msg .= t('Please do not reply to this message, as this channel is not sharing with you and any reply will not be seen by the recipient.') . "\r"; $created = datetime_convert('UTC','UTC',$item['created'],'Y-m-d H:i:s \U\T\C'); @@ -786,19 +787,18 @@ function diaspora_request($importer,$xml) { $closeness = 80; - $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_my_perms, abook_their_perms, abook_closeness, abook_rating, abook_created, abook_updated, abook_connected, abook_dob, abook_flags) values ( %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', %d )", + $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_my_perms, abook_their_perms, abook_closeness, abook_created, abook_updated, abook_connected, abook_dob, abook_pending) values ( %d, %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', %d )", intval($importer['channel_account_id']), intval($importer['channel_id']), dbesc($ret['xchan_hash']), intval($default_perms), intval($their_perms), intval($closeness), - intval(0), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(NULL_DATE), - intval(($default_perms) ? 0 : ABOOK_FLAG_PENDING) + intval(($default_perms) ? 0 : 1) ); @@ -998,9 +998,8 @@ function diaspora_post($importer,$xml,$msg) { $datarray['app'] = $app; - $datarray['item_flags'] = ITEM_THREAD_TOP; $datarray['item_unseen'] = 1; - + $datarray['item_thread_top'] = 1; $tgroup = tgroup_check($importer['channel_id'],$datarray); @@ -1009,6 +1008,11 @@ function diaspora_post($importer,$xml,$msg) { return 202; } + if(! is_importable($datarray,$contact)) { + logger('diaspora_post: filtering this author.'); + return 202; + } + $result = item_store($datarray); return; @@ -1556,7 +1560,7 @@ function diaspora_comment($importer,$xml,$msg) { $key = get_config('system','pubkey'); $x = array('signer' => $diaspora_handle, 'body' => $text, 'signed_text' => $signed_data, 'signature' => base64_encode($author_signature)); - $datarray['diaspora_meta'] = json_encode(crypto_encapsulate(json_encode($x),$key)); + $datarray['diaspora_meta'] = json_encode($x); } @@ -1580,7 +1584,7 @@ function diaspora_comment($importer,$xml,$msg) { if($result && $result['success']) $message_id = $result['item_id']; - if(($parent_item['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature)) { + if(intval($parent_item['item_origin']) && (! $parent_author_signature)) { // if the message isn't already being relayed, notify others // the existence of parent_author_signature means the parent_author or owner // is already relaying. @@ -1737,20 +1741,19 @@ function diaspora_conversation($importer,$xml,$msg) { continue; } - $key = get_config('system','pubkey'); if($subject) - $subject = json_encode(crypto_encapsulate($subject,$key)); + $subject = str_rot47(base64url_encode($subject)); if($body) - $body = json_encode(crypto_encapsulate($body,$key)); + $body = str_rot47(base64url_encode($body)); - q("insert into mail ( `channel_id`, `convid`, `from_xchan`,`to_xchan`,`title`,`body`,`mail_flags`,`mid`,`parent_mid`,`created`) values ( %d, %d, '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s')", + q("insert into mail ( `channel_id`, `convid`, `from_xchan`,`to_xchan`,`title`,`body`,`mail_obscured`,`mid`,`parent_mid`,`created`) values ( %d, %d, '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s')", intval($importer['channel_id']), intval($conversation['id']), dbesc($person['xchan_hash']), dbesc($importer['channel_hash']), dbesc($subject), dbesc($body), - intval(MAIL_OBSCURED), + intval(1), dbesc($msg_guid), dbesc($parent_uri), dbesc($msg_created_at) @@ -1871,18 +1874,18 @@ function diaspora_message($importer,$xml,$msg) { $key = get_config('system','pubkey'); if($subject) - $subject = json_encode(crypto_encapsulate($subject,$key)); + $subject = str_rot47(base64url_encode($subject)); if($body) - $body = json_encode(crypto_encapsulate($body,$key)); + $body = str_rot47(base64url_encode($body)); - q("insert into mail ( `channel_id`, `convid`, `from_xchan`,`to_xchan`,`title`,`body`,`mail_flags`,`mid`,`parent_mid`,`created`) values ( %d, %d, '%s', '%s', '%s', '%s', '%d','%s','%s','%s')", + q("insert into mail ( `channel_id`, `convid`, `from_xchan`,`to_xchan`,`title`,`body`,`mail_obscured`,`mid`,`parent_mid`,`created`) values ( %d, %d, '%s', '%s', '%s', '%s', '%d','%s','%s','%s')", intval($importer['channel_id']), intval($conversation['id']), dbesc($person['xchan_hash']), dbesc($importer['xchan_hash']), dbesc($subject), dbesc($body), - intval(MAIL_OBSCURED), + intval(1), dbesc($msg_guid), dbesc($parent_uri), dbesc($msg_created_at) @@ -2170,7 +2173,7 @@ function diaspora_like($importer,$xml,$msg) { $key = get_config('system','pubkey'); $x = array('signer' => $diaspora_handle, 'body' => $text, 'signed_text' => $signed_data, 'signature' => base64_encode($author_signature)); - $arr['diaspora_meta'] = json_encode(crypto_encapsulate(json_encode($x),$key)); + $arr['diaspora_meta'] = json_encode($x); } $x = item_store($arr); @@ -2182,7 +2185,7 @@ function diaspora_like($importer,$xml,$msg) { // the existence of parent_author_signature means the parent_author or owner // is already relaying. The parent_item['origin'] indicates the message was created on our system - if(($parent_item['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature)) + if(intval($parent_item['item_origin']) && (! $parent_author_signature)) proc_run('php','include/notifier.php','comment-import',$message_id); return; @@ -2291,19 +2294,12 @@ function diaspora_signed_retraction($importer,$xml,$msg) { $r[0]['parent'] ); if($p) { - if(($p[0]['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature)) { -// FIXME so we can relay this -// q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", -// $r[0]['id'], -// dbesc($signed_data), -// dbesc($sig), -// dbesc($diaspora_handle) -// ); + if(intval($p[0]['item_origin']) && (! $parent_author_signature)) { // the existence of parent_author_signature would have meant the parent_author or owner // is already relaying. - logger('diaspora_signed_retraction: relaying relayable_retraction'); + logger('diaspora_signed_retraction: relaying relayable_retraction'); proc_run('php','include/notifier.php','drop',$r[0]['id']); } } @@ -2483,7 +2479,7 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { } */ - if($item['item_flags'] & ITEM_CONSENSUS) { + if(intval($item['item_consensus'])) { $poll = replace_macros(get_markup_template('diaspora_consensus.tpl'), array( '$guid_q' => random_string(), '$question' => t('Please choose'), @@ -2667,7 +2663,7 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) { $target_type = 'Post'; $positive = 'true'; - if(($item_['item_restrict'] & ITEM_DELETED)) + if(intval($item['item_deleted'])) logger('diaspora_send_followup: received deleted "like". Those should go to diaspora_send_retraction'); } else { @@ -2763,7 +2759,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $relay_retract = false; $sql_sign_id = 'iid'; - if( $item['item_restrict'] & ITEM_DELETED) { + if( intval($item['item_deleted'])) { $relay_retract = true; $target_type = ( ($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment'); @@ -2775,7 +2771,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $like = true; $target_type = ( $parent['mid'] === $parent['parent_mid'] ? 'Post' : 'Comment'); -// $positive = (($item['item_restrict'] & ITEM_DELETED) ? 'false' : 'true'); +// $positive = (intval($item['item_deleted']) ? 'false' : 'true'); $positive = 'true'; $tpl = get_markup_template('diaspora_like_relay.tpl'); @@ -2924,12 +2920,11 @@ function diaspora_send_mail($item,$owner,$contact) { 'participant_handles' => xmlify($cnv['recips']) ); - if(array_key_exists('mail_flags',$item) && ($item['mail_flags'] & MAIL_OBSCURED)) { - $key = get_config('system','prvkey'); -// if($item['title']) -// $item['title'] = crypto_unencapsulate(json_decode_plus($item['title']),$key); + if(array_key_exists('mail_obscured',$item) && intval($item['mail_obscured'])) { + if($item['title']) + $item['title'] = base64url_decode(str_rot47($item['title'])); if($item['body']) - $item['body'] = crypto_unencapsulate(json_decode_plus($item['body']),$key); + $item['body'] = base64url_decode(str_rot47($item['body'])); } |