From b735961560d676f46bc43679f169ec2b0134de69 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 22 Sep 2014 16:23:59 -0700 Subject: found the sucker --- include/notifier.php | 2 ++ include/zot.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/notifier.php b/include/notifier.php index 0c7a15452..47072415b 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -477,11 +477,13 @@ function notifier_run($argv, $argc){ where hubloc_hash in (" . implode(',',$recipients) . ") group by hubloc_sitekey order by hubloc_connected desc limit 1"); } else { + $r = q("select hubloc_guid, hubloc_url, hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc where hubloc_hash in (" . implode(',',$recipients) . ") and not (hubloc_flags & %d) and not (hubloc_status & %d) group by hubloc_sitekey", intval(HUBLOC_FLAGS_DELETED), intval(HUBLOC_OFFLINE) ); + } if(! $r) { diff --git a/include/zot.php b/include/zot.php index b7ffe14e4..828194c3a 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2399,7 +2399,7 @@ function process_channel_sync_delivery($sender,$arr,$deliveries) { ); if($r) { // don't count yourself - $total_friends = ((count($r) > 0) ? $count($r) - 1 : 0); + $total_friends = ((count($r) > 0) ? count($r) - 1 : 0); foreach($r as $rr) if($rr['abook_flags'] & ABOOK_FLAG_FEED) $total_feeds ++; @@ -2407,9 +2407,9 @@ function process_channel_sync_delivery($sender,$arr,$deliveries) { $disallowed = array('abook_id','abook_account','abook_channel'); - $clean = array(); foreach($arr['abook'] as $abook) { + $clean = array(); if($abook['abook_xchan'] && $abook['entry_deleted']) { logger('process_channel_sync_delivery: removing abook entry for ' . $abook['abook_xchan']); require_once('include/Contact.php'); -- cgit v1.2.3 From fb05919d90cac9bb360bbb62b7e89d5c0e59b484 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 22 Sep 2014 21:37:19 -0700 Subject: make discover items interactive --- include/ConversationObject.php | 12 ++++++------ include/ItemObject.php | 12 ++++++++++-- include/conversation.php | 10 +++++++++- 3 files changed, 25 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/ConversationObject.php b/include/ConversationObject.php index 767ef7360..c0fc376ae 100644 --- a/include/ConversationObject.php +++ b/include/ConversationObject.php @@ -52,14 +52,14 @@ class Conversation extends BaseObject { switch($mode) { case 'network': - if(array_key_exists('firehose',$a->data) && intval($a->data['firehose'])) { - $this->profile_owner = intval($a->data['firehose']); - $this->writable = false; - } - else { +// if(array_key_exists('firehose',$a->data) && intval($a->data['firehose'])) { +// $this->profile_owner = intval($a->data['firehose']); +// $this->writable = false; +// } +// else { $this->profile_owner = local_user(); $this->writable = true; - } +// } break; case 'channel': $this->profile_owner = $a->profile['profile_uid']; diff --git a/include/ItemObject.php b/include/ItemObject.php index 96abe4df6..7c75e35bd 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -101,11 +101,19 @@ class Item extends BaseObject { else $edpost = false; + if($observer['xchan_hash'] == $this->get_data_value('author_xchan') || $observer['xchan_hash'] == $this->get_data_value('owner_xchan') || $this->get_data_value('uid') == local_user()) $dropping = true; + + if(array_key_exists('real_uid',$item)) { + $edpost = false; + $dropping = false; + } + + if($dropping) { $drop = array( 'dropping' => $dropping, @@ -119,7 +127,7 @@ class Item extends BaseObject { ); } - $filer = (($conv->get_profile_owner() == local_user()) ? t("Save to Folder") : false); + $filer = ((($conv->get_profile_owner() == local_user()) && (! array_key_exists('real_uid',$item))) ? t("Save to Folder") : false); $profile_avatar = $item['author']['xchan_photo_m']; $profile_link = chanlink_url($item['author']['xchan_url']); @@ -163,7 +171,7 @@ class Item extends BaseObject { if($this->is_toplevel()) { // FIXME check this permission - if($conv->get_profile_owner() == local_user()) { + if(($conv->get_profile_owner() == local_user()) && (! array_key_exists('real_uid',$item))) { // FIXME we don't need all this stuff, some can be done in the template diff --git a/include/conversation.php b/include/conversation.php index b0a388a68..17792e09a 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1230,11 +1230,19 @@ function add_children_to_list($children, &$arr) { } } -function conv_sort($arr,$order) { +function conv_sort($arr,$order,$uid = 0) { if((!(is_array($arr) && count($arr)))) return array(); + if($uid) { + for($x = 0; $x < count($arr); $x ++) { + $arr[$x]['real_uid'] = $arr[$x]['uid']; + $arr[$x]['uid'] = $uid; + } + } + + $parents = array(); $children = array(); -- cgit v1.2.3 From e8854bb19dae01b18d2eb13af76d277847bdbb5a Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 22 Sep 2014 22:03:19 -0700 Subject: better way to deal with effective_uid --- include/conversation.php | 10 +--------- include/text.php | 10 +++++++++- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 17792e09a..b0a388a68 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1230,19 +1230,11 @@ function add_children_to_list($children, &$arr) { } } -function conv_sort($arr,$order,$uid = 0) { +function conv_sort($arr,$order) { if((!(is_array($arr) && count($arr)))) return array(); - if($uid) { - for($x = 0; $x < count($arr); $x ++) { - $arr[$x]['real_uid'] = $arr[$x]['uid']; - $arr[$x]['uid'] = $uid; - } - } - - $parents = array(); $children = array(); diff --git a/include/text.php b/include/text.php index 599c5d445..573af4d32 100644 --- a/include/text.php +++ b/include/text.php @@ -1851,9 +1851,17 @@ function ids_to_querystr($arr,$idx = 'id') { // author_xchan and owner_xchan. If $abook is true also include the abook info. // This is needed in the API to save extra per item lookups there. -function xchan_query(&$items,$abook = true) { +function xchan_query(&$items,$abook = true,$effective_uid = 0) { $arr = array(); if($items && count($items)) { + + if($effective_uid) { + for($x = 0; $x < count($items); $x ++) { + $items[$x]['real_uid'] = $items[$x]['uid']; + $items[$x]['uid'] = $effective_uid; + } + } + foreach($items as $item) { if($item['owner_xchan'] && (! in_array($item['owner_xchan'],$arr))) $arr[] = "'" . dbesc($item['owner_xchan']) . "'"; -- cgit v1.2.3 From 72ec78d0270ecc5036e02db984b0a5c5fd293c8b Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 22 Sep 2014 23:49:12 -0700 Subject: trying to call mod/magic on rss resources - which have no hub --- include/ConversationObject.php | 8 ++++---- include/text.php | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/ConversationObject.php b/include/ConversationObject.php index c0fc376ae..a02ba102f 100644 --- a/include/ConversationObject.php +++ b/include/ConversationObject.php @@ -177,11 +177,11 @@ class Conversation extends BaseObject { } } require_once('include/identity.php'); - $sys = get_sys_channel(); +// $sys = get_sys_channel(); - if($sys && $item->get_data_value('uid') == $sys['channel_id']) { - $item->set_commentable(false); - } +// if($sys && $item->get_data_value('uid') == $sys['channel_id']) { +// $item->set_commentable(false); +// } $item->set_conversation($this); $this->threads[] = $item; diff --git a/include/text.php b/include/text.php index 573af4d32..22cf17866 100644 --- a/include/text.php +++ b/include/text.php @@ -1183,7 +1183,11 @@ function theme_attachments(&$item) { $title = t('unknown.???'); $title .= ' ' . $r['length'] . ' ' . t('bytes'); - $url = z_root() . '/magic?f=&hash=' . $item['author_xchan'] . '&dest=' . $r['href'] . '/' . $r['revision']; + require_once('include/identity.php'); + if(is_foreigner($item['author_xchan'])) + $url = $r['href']; + else + $url = z_root() . '/magic?f=&hash=' . $item['author_xchan'] . '&dest=' . $r['href'] . '/' . $r['revision']; $s .= '' . $icon . ''; $attaches[] = array('title' => $title, 'url' => $url, 'icon' => $icon ); -- cgit v1.2.3 From 509a85cb12636dc01b59935febf9419cfb02fd48 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 23 Sep 2014 03:03:14 -0700 Subject: more work on d* private messages --- include/diaspora.php | 24 +++++++++++++++------ include/message.php | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 6f504b460..74dad177a 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1532,6 +1532,12 @@ function diaspora_conversation($importer,$xml,$msg) { continue; } + $key = get_config('system','pubkey'); + if($subject) + $subject = json_encode(crypto_encapsulate($subject,$key)); + if($body) + $body = json_encode(crypto_encapsulate($body,$key)); + 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')", intval($importer['channel_id']), intval($conversation['id']), @@ -1539,7 +1545,7 @@ function diaspora_conversation($importer,$xml,$msg) { dbesc($importer['channel_hash']), dbesc($subject), dbesc($body), - 0, + intval(MAIL_OBSCURED), dbesc($msg_guid), dbesc($parent_uri), dbesc($msg_created_at) @@ -1588,7 +1594,7 @@ function diaspora_message($importer,$xml,$msg) { $msg_diaspora_handle = notags(unxmlify($xml->diaspora_handle)); $msg_conversation_guid = notags(unxmlify($xml->conversation_guid)); - $parent_uri = $diaspora_handle . ':' . $msg_parent_guid; + $parent_uri = $msg_parent_guid; $contact = diaspora_get_contact_by_handle($importer['channel_id'],$msg_diaspora_handle); if(! $contact) { @@ -1607,7 +1613,7 @@ function diaspora_message($importer,$xml,$msg) { intval($importer['channel_id']), dbesc($msg_conversation_guid) ); - if(count($c)) + if($c) $conversation = $c[0]; else { logger('diaspora_message: conversation not available.'); @@ -1637,15 +1643,21 @@ function diaspora_message($importer,$xml,$msg) { return; } - $r = q("select id from mail where `uri` = '%s' and uid = %d limit 1", + $r = q("select id from mail where mid = '%s' and uid = %d limit 1", dbesc($message_id), intval($importer['channel_id']) ); - if(count($r)) { + if($r) { logger('diaspora_message: duplicate message already delivered.', LOGGER_DEBUG); return; } + $key = get_config('system','pubkey'); + if($subject) + $subject = json_encode(crypto_encapsulate($subject,$key)); + if($body) + $body = json_encode(crypto_encapsulate($body,$key)); + 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')", intval($importer['channel_id']), intval($conversation['id']), @@ -1653,7 +1665,7 @@ function diaspora_message($importer,$xml,$msg) { dbesc($importer['xchan_hash']), dbesc($conversation['subject']), dbesc($body), - 0, + intval(MAIL_OBSCURED), dbesc($msg_guid), dbesc($parent_uri), dbesc($msg_created_at) diff --git a/include/message.php b/include/message.php index 96c3532c1..6aba899f7 100644 --- a/include/message.php +++ b/include/message.php @@ -27,6 +27,9 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=' // else // $expires = datetime_convert(date_default_timezone_get(),'UTC',$expires); + + + if($uid) { $r = q("select * from channel where channel_id = %d limit 1", intval($uid) @@ -43,6 +46,59 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=' return $ret; } + + // look for any existing conversation structure + + if(strlen($replyto)) { + $r = q("select convid from mail where uid = %d and ( mid = '%s' or parent_mid = '%s' ) limit 1", + intval(local_user()), + dbesc($replyto), + dbesc($replyto) + ); + if($r) + $convid = $r[0]['convid']; + } + + if(! $convid) { + + // create a new conversation + + $conv_guid = random_string(); + + $recip = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($recipient) + ); + if($recip) + $recip_handle = $recip[0]['xchan_addr']; + + $sender_handle = $channel['channel_address'] . '@' . get_app()->get_hostname(); + + $handles = $recip_handle . ';' . $sender_handle; + + $r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ", + intval(local_user()), + dbesc($conv_guid), + dbesc($sender_handle), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($subject), + dbesc($handles) + ); + + $r = q("select * from conv where guid = '%s' and uid = %d limit 1", + dbesc($conv_guid), + intval(local_user()) + ); + if($r) + $convid = $r[0]['id']; + } + + if(! $convid) { + $ret['message'] = 'conversation not found'; + return $ret; + } + + // generate a unique message_id do { @@ -115,9 +171,10 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=' - $r = q("INSERT INTO mail ( account_id, mail_flags, channel_id, from_xchan, to_xchan, title, body, attach, mid, parent_mid, created, expires ) - VALUES ( %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", + $r = q("INSERT INTO mail ( account_id, convid, mail_flags, channel_id, from_xchan, to_xchan, title, body, attach, mid, parent_mid, created, expires ) + VALUES ( %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", intval($channel['channel_account_id']), + intval($convid), intval(MAIL_OBSCURED), intval($channel['channel_id']), dbesc($channel['channel_hash']), -- cgit v1.2.3 From ad86cc24c843ee577df508ba4d03c34788bec991 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 23 Sep 2014 04:34:35 -0700 Subject: d* PM cont. --- include/diaspora.php | 11 ++++++++++- include/message.php | 2 -- include/notifier.php | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 74dad177a..c71d04fbe 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2668,7 +2668,7 @@ function diaspora_send_mail($item,$owner,$contact) { $r = q("select * from conv where id = %d and uid = %d limit 1", intval($item['convid']), - intval($item['uid']) + intval($item['channel_id']) ); if(! count($r)) { @@ -2685,6 +2685,15 @@ 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($item['body']) + $item['body'] = crypto_unencapsulate(json_decode_plus($item['body']),$key); + } + + $body = bb2diaspora($item['body']); $created = datetime_convert('UTC','UTC',$item['created'],'Y-m-d H:i:s \U\T\C'); diff --git a/include/message.php b/include/message.php index 6aba899f7..88cfb7ba2 100644 --- a/include/message.php +++ b/include/message.php @@ -284,9 +284,7 @@ function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) { $r[$k]['to'] = find_xchan_in_array($rr['to_xchan'],$c); $r[$k]['seen'] = (($rr['mail_flags'] & MAIL_SEEN) ? 1 : 0); if($r[$k]['mail_flags'] & MAIL_OBSCURED) { - logger('unencrypting'); $key = get_config('system','prvkey'); - if($r[$k]['title']) $r[$k]['title'] = crypto_unencapsulate(json_decode_plus($r[$k]['title']),$key); if($r[$k]['body']) diff --git a/include/notifier.php b/include/notifier.php index 47072415b..79a6886ad 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -158,7 +158,7 @@ function notifier_run($argv, $argc){ $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1", intval($item_id) ); - if(! count($message)){ + if(! $message) { return; } xchan_mail_query($message[0]); -- cgit v1.2.3 From 2b466ccb8ca24197b510d21229a3b68ed3760a59 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 23 Sep 2014 04:40:36 -0700 Subject: d* little fixes --- include/diaspora.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index c71d04fbe..39fa29de5 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2132,15 +2132,9 @@ function diaspora_profile($importer,$xml,$msg) { $image_url = "http://" . $handle_parts[1] . $image_url; } -/* $r = q("SELECT DISTINCT ( `resource-id` ) FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' ", - intval($importer['channel_id']), - intval($contact['id']) - ); - $oldphotos = ((count($r)) ? $r : null);*/ - - require_once('include/Photo.php'); + require_once('include/photo/photo_driver.php'); - $images = import_profile_photo($image_url,$importer['channel_id'],$contact['id']); + $images = import_profile_photo($image_url,$contact['xchan_hash']); // Generic birthday. We don't know the timezone. The year is irrelevant. @@ -2157,7 +2151,7 @@ function diaspora_profile($importer,$xml,$msg) { // TODO: update name on item['author-name'] if the name changed. See consume_feed() // Not doing this currently because D* protocol is scheduled for revision soon. - $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s' WHERE `id` = %d AND `uid` = %d", +/* $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($name), dbesc(datetime_convert()), dbesc($images[0]), @@ -2168,7 +2162,7 @@ function diaspora_profile($importer,$xml,$msg) { intval($contact['id']), intval($importer['channel_id']) ); - +*/ /* if($r) { if($oldphotos) { foreach($oldphotos as $ph) { -- cgit v1.2.3 From f203d2a3b0955211b00743d2cc6c3a8a1347bbdd Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 23 Sep 2014 20:36:10 -0700 Subject: diaspora private mail seems to work now - but there's an obfuscation leak via the conversation structure that needs to be dealt with. --- include/diaspora.php | 21 +++++++++++---------- include/items.php | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 39fa29de5..f9fd3b4ee 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1622,6 +1622,7 @@ function diaspora_message($importer,$xml,$msg) { $reply = 0; + $subject = $conversation['subject']; $body = diaspora2bb($msg_text); $message_id = $msg_diaspora_handle . ':' . $msg_guid; @@ -1631,8 +1632,8 @@ function diaspora_message($importer,$xml,$msg) { $author_signature = base64_decode($msg_author_signature); $person = find_diaspora_person_by_handle($msg_diaspora_handle); - if(is_array($person) && x($person,'pubkey')) - $key = $person['pubkey']; + if(is_array($person) && x($person,'xchan_pubkey')) + $key = $person['xchan_pubkey']; else { logger('diaspora_message: unable to find author details'); return; @@ -1643,7 +1644,7 @@ function diaspora_message($importer,$xml,$msg) { return; } - $r = q("select id from mail where mid = '%s' and uid = %d limit 1", + $r = q("select id from mail where mid = '%s' and channel_id = %d limit 1", dbesc($message_id), intval($importer['channel_id']) ); @@ -1663,7 +1664,7 @@ function diaspora_message($importer,$xml,$msg) { intval($conversation['id']), dbesc($person['xchan_hash']), dbesc($importer['xchan_hash']), - dbesc($conversation['subject']), + dbesc($subject), dbesc($body), intval(MAIL_OBSCURED), dbesc($msg_guid), @@ -2394,7 +2395,7 @@ function diaspora_send_images($item,$owner,$contact,$images,$public_batch = fals function diaspora_send_followup($item,$owner,$contact,$public_batch = false) { $a = get_app(); - $myaddr = $owner['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + $myaddr = $owner['channel_address'] . '@' . get_app()->get_hostname(); $theiraddr = $contact['xchan_addr']; // Diaspora doesn't support threaded comments, but some @@ -2485,7 +2486,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $a = get_app(); - $myaddr = $owner['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + $myaddr = $owner['channel_address'] . '@' . get_app()->get_hostname(); $text = bb2diaspora_itembody($item); @@ -2627,7 +2628,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) { $a = get_app(); - $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + $myaddr = $owner['channel_address'] . '@' . get_app()->get_hostname(); // Check whether the retraction is for a top-level post or whether it's a relayable if( $item['mid'] !== $item['parent_mid'] ) { @@ -2658,7 +2659,7 @@ function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) { function diaspora_send_mail($item,$owner,$contact) { $a = get_app(); - $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + $myaddr = $owner['channel_address'] . '@' . get_app()->get_hostname(); $r = q("select * from conv where id = %d and uid = %d limit 1", intval($item['convid']), @@ -2691,13 +2692,13 @@ function diaspora_send_mail($item,$owner,$contact) { $body = bb2diaspora($item['body']); $created = datetime_convert('UTC','UTC',$item['created'],'Y-m-d H:i:s \U\T\C'); - $signed_text = $item['guid'] . ';' . $cnv['guid'] . ';' . $body . ';' + $signed_text = $item['mid'] . ';' . $cnv['guid'] . ';' . $body . ';' . $created . ';' . $myaddr . ';' . $cnv['guid']; $sig = base64_encode(rsa_sign($signed_text,$owner['channel_prvkey'],'sha256')); $msg = array( - 'guid' => xmlify($item['guid']), + 'guid' => xmlify($item['mid']), 'parent_guid' => xmlify($cnv['guid']), 'parent_author_signature' => (($item['reply']) ? null : xmlify($sig)), 'author_signature' => xmlify($sig), diff --git a/include/items.php b/include/items.php index 53a0b25a9..dbea5779c 100755 --- a/include/items.php +++ b/include/items.php @@ -1428,6 +1428,8 @@ function get_atom_elements($feed,$item,&$author) { $res['title'] = unxmlify($item->get_title()); $res['body'] = unxmlify($item->get_content()); $res['plink'] = unxmlify($item->get_link(0)); + $res['item_flags'] = ITEM_RSS; + // removing the content of the title if its identically to the body // This helps with auto generated titles e.g. from tumblr @@ -3196,7 +3198,6 @@ function mail_store($arr) { } - /** * * consume_feed - process atom feed and update anything/everything we might need to update -- cgit v1.2.3 From 81ee35e03bc45bc80aaabb9416bdee2968b8f504 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 23 Sep 2014 20:55:22 -0700 Subject: fix url mismatches of a single trailing slash for feed author/owner comparisons; update diaspora_compat --- include/bb2diaspora.php | 6 ++---- include/follow.php | 3 +++ include/items.php | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index e60f72add..089838e97 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -131,10 +131,8 @@ function diaspora2bb($s,$use_zrl = false) { // $s = preg_replace('/\@\{(.+?)\; (.+?)\@(.+?)\}/','@[url=https://$3/u/$2]$1[/url]',$s); // first try plustags - // nope don't do it. This will cause mis-attributed messages and runaway delivery chains - - // Diaspora doesn't have sufficient delivery loop detection. - // Leave the next line commented and leave this description here so future readers will know why. - // $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}\+/','diaspora_mention_callback',$s); + + $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}\+/','diaspora_mention_callback',$s); $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}/','diaspora_mention_callback',$s); diff --git a/include/follow.php b/include/follow.php index 38525982e..a967386e9 100644 --- a/include/follow.php +++ b/include/follow.php @@ -19,6 +19,9 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $is_red = false; $is_http = ((strpos($url,'://') !== false) ? true : false); + if($is_http && substr($url,-1,1) === '/') + $url = substr($url,0,-1); + if(! allowed_url($url)) { $result['message'] = t('Channel is blocked on this site.'); return $result; diff --git a/include/items.php b/include/items.php index dbea5779c..d972a1ce9 100755 --- a/include/items.php +++ b/include/items.php @@ -1424,6 +1424,9 @@ function get_atom_elements($feed,$item,&$author) { $author['author_link'] = unxmlify($feed->get_permalink()); } + if(substr($author['author_link'],-1,1) == '/') + $author['author_link'] = substr($author['author_link'],0,-1); + $res['mid'] = base64url_encode(unxmlify($item->get_id())); $res['title'] = unxmlify($item->get_title()); $res['body'] = unxmlify($item->get_content()); -- cgit v1.2.3 From 87b8e2725c454b9ddeb15836301736d366ff8482 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 24 Sep 2014 01:45:57 -0700 Subject: just an experiment - don't do anything with this until I'm finished with it. --- include/items.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index d972a1ce9..c5fc14a09 100755 --- a/include/items.php +++ b/include/items.php @@ -1581,6 +1581,15 @@ function get_atom_elements($feed,$item,&$author) { $res['body'] = escape_tags($res['body']); } + if(get_config('system','feedlinks')) { + if($res['plink'] && $res['title']) { + $res['body'] = '[url=' . $res['plink'] . ']' . $res['title'] . '[/url]' . "\n\n" . $res['body']; + } + elseif($res['plink']) { + $res['body'] = '[url]' . $res['plink'] . '[/url]' . "\n\n" . $res['body']; + } + } + $private = $item->get_item_tags(NAMESPACE_DFRN,'private'); if($private && intval($private[0]['data']) > 0) $res['item_private'] = ((intval($private[0]['data'])) ? 1 : 0); -- cgit v1.2.3 From be54f0d9e649f634f2b027e75aef07d197901512 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 24 Sep 2014 01:58:24 -0700 Subject: more testing --- include/items.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index c5fc14a09..e4339e5f6 100755 --- a/include/items.php +++ b/include/items.php @@ -1583,10 +1583,24 @@ function get_atom_elements($feed,$item,&$author) { if(get_config('system','feedlinks')) { if($res['plink'] && $res['title']) { - $res['body'] = '[url=' . $res['plink'] . ']' . $res['title'] . '[/url]' . "\n\n" . $res['body']; + $res['body'] = '#^[url=' . $res['plink'] . ']' . $res['title'] . '[/url]' . "\n\n" . $res['body']; + $terms = array(); + $terms[] = array( + 'otype' => TERM_OBJ_POST, + 'type' => TERM_BOOKMARK, + 'url' => $res['plink'], + 'term' => $res['title'], + ); } elseif($res['plink']) { - $res['body'] = '[url]' . $res['plink'] . '[/url]' . "\n\n" . $res['body']; + $res['body'] = '#^[url]' . $res['plink'] . '[/url]' . "\n\n" . $res['body']; + $terms = array(); + $terms[] = array( + 'otype' => TERM_OBJ_POST, + 'type' => TERM_BOOKMARK, + 'url' => $res['plink'], + 'term' => $res['plink'], + ); } } @@ -1678,7 +1692,8 @@ function get_atom_elements($feed,$item,&$author) { $cats = $item->get_categories(); if($cats) { - $terms = array(); + if(is_null($terms)) + $terms = array(); foreach($cats as $cat) { $term = $cat->get_term(); if(! $term) -- cgit v1.2.3 From 95470a9f9b1f2ceff096b1704eca6a9deb21418f Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 24 Sep 2014 02:08:35 -0700 Subject: one step closer --- include/items.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index e4339e5f6..e46d9351e 100755 --- a/include/items.php +++ b/include/items.php @@ -1718,9 +1718,11 @@ function get_atom_elements($feed,$item,&$author) { ); } } - $res['term'] = $terms; } + if(! is_null($terms)) + $res['term'] = $terms; + $attach = $item->get_enclosures(); if($attach) { $res['attach'] = array(); -- cgit v1.2.3 From c76b8febaac5e1ec925499dd63ff763dc512fab8 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 24 Sep 2014 02:18:13 -0700 Subject: make it the default --- include/items.php | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index e46d9351e..8c7a0a777 100755 --- a/include/items.php +++ b/include/items.php @@ -1581,28 +1581,27 @@ function get_atom_elements($feed,$item,&$author) { $res['body'] = escape_tags($res['body']); } - if(get_config('system','feedlinks')) { - if($res['plink'] && $res['title']) { - $res['body'] = '#^[url=' . $res['plink'] . ']' . $res['title'] . '[/url]' . "\n\n" . $res['body']; - $terms = array(); - $terms[] = array( - 'otype' => TERM_OBJ_POST, - 'type' => TERM_BOOKMARK, - 'url' => $res['plink'], - 'term' => $res['title'], - ); - } - elseif($res['plink']) { - $res['body'] = '#^[url]' . $res['plink'] . '[/url]' . "\n\n" . $res['body']; - $terms = array(); - $terms[] = array( - 'otype' => TERM_OBJ_POST, - 'type' => TERM_BOOKMARK, - 'url' => $res['plink'], - 'term' => $res['plink'], - ); - } + if($res['plink'] && $res['title']) { + $res['body'] = '#^[url=' . $res['plink'] . ']' . $res['title'] . '[/url]' . "\n\n" . $res['body']; + $terms = array(); + $terms[] = array( + 'otype' => TERM_OBJ_POST, + 'type' => TERM_BOOKMARK, + 'url' => $res['plink'], + 'term' => $res['title'], + ); } + elseif($res['plink']) { + $res['body'] = '#^[url]' . $res['plink'] . '[/url]' . "\n\n" . $res['body']; + $terms = array(); + $terms[] = array( + 'otype' => TERM_OBJ_POST, + 'type' => TERM_BOOKMARK, + 'url' => $res['plink'], + 'term' => $res['plink'], + ); + } + $private = $item->get_item_tags(NAMESPACE_DFRN,'private'); if($private && intval($private[0]['data']) > 0) -- cgit v1.2.3 From 24d402941f143503b5b0e07403d5567f3b9d0173 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 24 Sep 2014 14:27:18 -0700 Subject: if no rss/atom element author, use feed level contact --- include/items.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 8c7a0a777..4d89606da 100755 --- a/include/items.php +++ b/include/items.php @@ -1418,10 +1418,12 @@ function get_atom_elements($feed,$item,&$author) { if($found_author) { $author['author_name'] = unxmlify($found_author->get_name()); $author['author_link'] = unxmlify($found_author->get_link()); + $author['author_is_feed'] = false; } else { $author['author_name'] = unxmlify($feed->get_title()); $author['author_link'] = unxmlify($feed->get_permalink()); + $author['author_is_feed'] = true; } if(substr($author['author_link'],-1,1) == '/') @@ -1493,8 +1495,10 @@ function get_atom_elements($feed,$item,&$author) { if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; foreach($base as $link) { - if($link['attribs']['']['rel'] === 'alternate' && (! $author['author_link'])) + if($link['attribs']['']['rel'] === 'alternate' && (! $author['author_link'])) { $author['author_link'] = unxmlify($link['attribs']['']['href']); + $author['author_is_feed'] = true; + } if(! $author['author_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') $author['author_photo'] = unxmlify($link['attribs']['']['href']); @@ -3343,11 +3347,11 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { $author = array(); $datarray = get_atom_elements($feed,$item,$author); - if(! x($author,'author_name')) + if((! x($author,'author_name')) || ($author['author_is_feed'])) $author['author_name'] = $contact['xchan_name']; - if(! x($author,'author_link')) + if((! x($author,'author_link')) || ($author['author_is_feed'])) $author['author_link'] = $contact['xchan_url']; - if(! x($author,'author_photo')) + if((! x($author,'author_photo'))|| ($author['author_is_feed'])) $author['author_photo'] = $contact['xchan_photo_m']; $datarray['author_xchan'] = ''; @@ -3406,11 +3410,11 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { $datarray = get_atom_elements($feed,$item,$author); if(is_array($contact)) { - if(! x($author,'author_name')) + if((! x($author,'author_name')) || ($author['author_is_feed'])) $author['author_name'] = $contact['xchan_name']; - if(! x($author,'author_link')) + if((! x($author,'author_link')) || ($author['author_is_feed'])) $author['author_link'] = $contact['xchan_url']; - if(! x($author,'author_photo')) + if((! x($author,'author_photo'))|| ($author['author_is_feed'])) $author['author_photo'] = $contact['xchan_photo_m']; } -- cgit v1.2.3 From e75f1ccb2ee1d5219a385ae4ee05ab74ac4600fd Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Thu, 25 Sep 2014 19:47:06 +0100 Subject: Typo --- include/items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 4d89606da..315f9c44b 100755 --- a/include/items.php +++ b/include/items.php @@ -3357,7 +3357,7 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { $datarray['author_xchan'] = ''; if($author['author_link'] != $contact['xchan_url']) { - $x = import_author_unkown(array('name' => $author['author_name'],'url' => $author['author_link'],'photo' => array('src' => $author['author_photo']))); + $x = import_author_unknown(array('name' => $author['author_name'],'url' => $author['author_link'],'photo' => array('src' => $author['author_photo']))); if($x) $datarray['author_xchan'] = $x; -- cgit v1.2.3 From d8c03526ed24a4b26c589659d394848c81bacc53 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 25 Sep 2014 20:21:23 -0700 Subject: optionally include wall items (posts) in import/export --- include/api.php | 4 ++-- include/identity.php | 7 ++++--- include/items.php | 24 +++++++++++++++++++++++- 3 files changed, 29 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/api.php b/include/api.php index 47de945db..2505def4c 100644 --- a/include/api.php +++ b/include/api.php @@ -546,8 +546,8 @@ require_once('include/items.php'); } require_once('include/identity.php'); - - json_return_and_die(identity_basic_export(api_user())); + + json_return_and_die(identity_basic_export(api_user(),(($_REQUEST['posts']) ? intval($_REQUEST['posts']) : 0 ))); } api_register_func('api/export/basic','api_export_basic', true); api_register_func('api/red/channel/export/basic','api_export_basic', true); diff --git a/include/identity.php b/include/identity.php index 50c5d13b9..eaeb9f07f 100644 --- a/include/identity.php +++ b/include/identity.php @@ -431,14 +431,15 @@ function set_default_login_identity($account_id,$channel_id,$force = true) { } /** - * @function identity_basic_export($channel_id) + * @function identity_basic_export($channel_id,$items = false) * Create an array representing the important channel information * which would be necessary to create a nomadic identity clone. This includes * most channel resources and connection information with the exception of content. * * @param int $channel_id * Channel_id to export - * + * @param boolean $items + * Include channel posts (wall items), default false * * @returns array * See function for details @@ -521,7 +522,7 @@ function identity_basic_export($channel_id, $items = false) { return $ret; - $r = q("select * from item_id where uid = %d", + $r = q("select item_id.*, item.mid from item_id left join item on item_id.iid = item.id where item_id.uid = %d", intval($channel_id) ); diff --git a/include/items.php b/include/items.php index 315f9c44b..ac960258c 100755 --- a/include/items.php +++ b/include/items.php @@ -865,15 +865,37 @@ function get_item_elements($x) { // We have to do that here because we need to cleanse the input and prevent bad stuff from getting in, // and we need plaintext to do that. + $key = get_config('system','pubkey'); + + if(intval($arr['item_private'])) { $arr['item_flags'] = $arr['item_flags'] | ITEM_OBSCURED; - $key = get_config('system','pubkey'); if($arr['title']) $arr['title'] = json_encode(crypto_encapsulate($arr['title'],$key)); if($arr['body']) $arr['body'] = json_encode(crypto_encapsulate($arr['body'],$key)); } + + if(array_key_exists('revision',$x)) { + // extended export encoding + + $arr['revision'] = $x['revision']; + $arr['allow_cid'] = $x['allow_cid']; + $arr['allow_gid'] = $x['allow_gid']; + $arr['deny_cid'] = $x['deny_cid']; + $arr['deny_gid'] = $x['deny_gid']; + $arr['layout_mid'] = $x['layout_mid']; + $arr['postopts'] = $x['postopts']; + $arr['resource_id'] = $x['resource_id']; + $arr['resource_type'] = $x['resource_type']; + $arr['item_restrict'] = $x['item_restrict']; + $arr['item_flags'] = $x['item_flags']; + $arr['diaspora_meta'] = (($x['diaspora_meta']) ? json_encode(crypto_encapsulate($x['diaspora_meta'],$key)) : ''); + $arr['attach'] = $x['attach']; + + } + return $arr; } -- cgit v1.2.3