diff options
author | tuscanhobbit <tuscanhobbit@users.noreply.github.com> | 2014-09-28 23:17:47 +0200 |
---|---|---|
committer | tuscanhobbit <tuscanhobbit@users.noreply.github.com> | 2014-09-28 23:17:47 +0200 |
commit | f104dc840c79f4ea666a85033bffbf4a33d06f4e (patch) | |
tree | f1fce3898b757e3a29e928cc1afe724edb620471 /include | |
parent | 6e141a8a53ba6cb7d91b989985744fdcd3d6f13d (diff) | |
parent | eaf96f987a5f22a54fdbb4cedef52b0159a37ad0 (diff) | |
download | volse-hubzilla-f104dc840c79f4ea666a85033bffbf4a33d06f4e.tar.gz volse-hubzilla-f104dc840c79f4ea666a85033bffbf4a33d06f4e.tar.bz2 volse-hubzilla-f104dc840c79f4ea666a85033bffbf4a33d06f4e.zip |
Merge from origin
Diffstat (limited to 'include')
-rw-r--r-- | include/ConversationObject.php | 20 | ||||
-rw-r--r-- | include/ItemObject.php | 12 | ||||
-rw-r--r-- | include/api.php | 4 | ||||
-rw-r--r-- | include/bb2diaspora.php | 6 | ||||
-rwxr-xr-x | include/diaspora.php | 68 | ||||
-rw-r--r-- | include/follow.php | 3 | ||||
-rw-r--r-- | include/identity.php | 7 | ||||
-rwxr-xr-x | include/items.php | 79 | ||||
-rw-r--r-- | include/message.php | 63 | ||||
-rw-r--r-- | include/notifier.php | 4 | ||||
-rw-r--r-- | include/text.php | 16 | ||||
-rw-r--r-- | include/zot.php | 4 |
12 files changed, 218 insertions, 68 deletions
diff --git a/include/ConversationObject.php b/include/ConversationObject.php index 767ef7360..a02ba102f 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']; @@ -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/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/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/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/diaspora.php b/include/diaspora.php index 6f504b460..f9fd3b4ee 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.'); @@ -1616,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; @@ -1625,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; @@ -1637,23 +1644,29 @@ 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 channel_id = %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']), dbesc($person['xchan_hash']), dbesc($importer['xchan_hash']), - dbesc($conversation['subject']), + dbesc($subject), dbesc($body), - 0, + intval(MAIL_OBSCURED), dbesc($msg_guid), dbesc($parent_uri), dbesc($msg_created_at) @@ -2120,15 +2133,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. @@ -2145,7 +2152,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]), @@ -2156,7 +2163,7 @@ function diaspora_profile($importer,$xml,$msg) { intval($contact['id']), intval($importer['channel_id']) ); - +*/ /* if($r) { if($oldphotos) { foreach($oldphotos as $ph) { @@ -2388,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 @@ -2479,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); @@ -2621,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'] ) { @@ -2652,11 +2659,11 @@ 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']), - intval($item['uid']) + intval($item['channel_id']) ); if(! count($r)) { @@ -2673,16 +2680,25 @@ 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'); - $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/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/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 53a0b25a9..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; } @@ -1418,16 +1440,23 @@ 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) == '/') + $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()); $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 @@ -1488,8 +1517,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']); @@ -1576,6 +1607,28 @@ function get_atom_elements($feed,$item,&$author) { $res['body'] = escape_tags($res['body']); } + 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) $res['item_private'] = ((intval($private[0]['data'])) ? 1 : 0); @@ -1664,7 +1717,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) @@ -1689,9 +1743,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(); @@ -3196,7 +3252,6 @@ function mail_store($arr) { } - /** * * consume_feed - process atom feed and update anything/everything we might need to update @@ -3314,17 +3369,17 @@ 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'] = ''; 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; @@ -3377,11 +3432,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']; } diff --git a/include/message.php b/include/message.php index 96c3532c1..88cfb7ba2 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']), @@ -227,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 0c7a15452..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]); @@ -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/text.php b/include/text.php index 599c5d445..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 .= '<a href="' . $url . '" title="' . $title . '" class="attachlink" >' . $icon . '</a>'; $attaches[] = array('title' => $title, 'url' => $url, 'icon' => $icon ); @@ -1851,9 +1855,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']) . "'"; 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'); |