From b522ab13cbf7653dcc5e0f91b10eed0a63560ecb Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 18 Aug 2014 20:03:48 -0700 Subject: nav channel selection --- include/features.php | 3 +++ include/nav.php | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/features.php b/include/features.php index 6bb444cb6..7530158ec 100644 --- a/include/features.php +++ b/include/features.php @@ -31,6 +31,9 @@ function get_features() { // prettyphoto has licensing issues and will no longer be provided in core - // in any event this setting should probably be a theme option or plugin // array('prettyphoto', t('Enhanced Photo Albums'), t('Enable photo album with enhanced features')), + array('nav_channel_select', t('Navigation Channel Select'), t('Change channels directly from within the navigation dropdown menu')), + + //FIXME - needs a description, but how the hell do we explain this to normals? array('sendzid', t('Extended Identity Sharing'), t('Share your identity with all websites on the internet. When disabled, identity is only shared with sites in the matrix.')), array('expert', t('Expert Mode'), t('Enable Expert Mode to provide advanced configuration options')), diff --git a/include/nav.php b/include/nav.php index 8133ecf67..799faf5ce 100644 --- a/include/nav.php +++ b/include/nav.php @@ -38,6 +38,14 @@ EOT; intval($channel['channel_id']) ); + $chans = q("select channel_name, channel_id from channel where channel_account_id = %d and not ( channel_pageflags & %d ) order by channel_name ", + intval(get_account_id()), + intval(PAGE_REMOVED) + ); + + + + } elseif(remote_user()) $observer = $a->get_observer(); @@ -78,6 +86,11 @@ EOT; $userinfo = null; if(local_user()) { + + + if($chans && count($chans) > 1 && feature_enabled(local_user(),'nav_channel_select')) + $nav['channels'] = $chans; + $nav['logout'] = Array('logout',t('Logout'), "", t('End this session')); // user menu @@ -193,7 +206,7 @@ EOT; $nav['all_events']['all']=array('events', t('See all events'), "", ""); $nav['all_events']['mark'] = array('', t('Mark all events seen'), '',''); - $nav['manage'] = array('manage', t('Channel Select'), "", t('Manage Your Channels')); + $nav['manage'] = array('manage', t('Channel Manager'), "", t('Manage Your Channels')); $nav['settings'] = array('settings', t('Settings'),"", t('Account/Channel Settings')); -- cgit v1.2.3 From b3d450626e830f648c4c2e596e449d6817a8b324 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 18 Aug 2014 22:44:03 -0700 Subject: provide an overt indication that a post/comment was edited. --- include/text.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index 1c5a78d4e..680e6fe95 100755 --- a/include/text.php +++ b/include/text.php @@ -1003,7 +1003,8 @@ function smilies($s, $sample = false) { ':like', ':dislike', 'red#', - 'r#' + 'r#', + 'red#matrix' ); $icons = array( @@ -1040,7 +1041,8 @@ function smilies($s, $sample = false) { ':like', ':dislike', 'redred#matrix', - 'redr#matrix' + 'redr#matrix', + 'redred#matrixmatrix' ); -- cgit v1.2.3 From dc212c80e2ed436b7e4c9cc555736485df111e34 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 19 Aug 2014 02:00:34 -0700 Subject: diaspora - crazy amount of work remaining --- include/diaspora.php | 143 +++++++++++++++++++++++---------------------------- 1 file changed, 63 insertions(+), 80 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 6121466f2..02d479d95 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -671,36 +671,24 @@ function diaspora_post($importer,$xml,$msg) { return 202; } - $message_id = $diaspora_handle . ':' . $guid; - $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1", + $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", intval($importer['channel_id']), - dbesc($message_id), dbesc($guid) ); - if(count($r)) { + if($r) { + // check dates if post editing is implemented logger('diaspora_post: message exists: ' . $guid); return; } - // allocate a guid on our system - we aren't fixing any collisions. - // we're ignoring them - - $g = q("select * from guid where guid = '%s' limit 1", - dbesc($guid) - ); - if(! count($g)) { - q("insert into guid ( guid ) values ( '%s' )", - dbesc($guid) - ); - } - $created = unxmlify($xml->created_at); $private = ((unxmlify($xml->public) == 'false') ? 1 : 0); $body = diaspora2bb($xml->raw_message); +//WTF? FIXME // Add OEmbed and other information to the body - $body = add_page_info_to_body($body, false, true); +// $body = add_page_info_to_body($body, false, true); $datarray = array(); @@ -708,6 +696,8 @@ function diaspora_post($importer,$xml,$msg) { $tags = get_tags($body); +// FIXME call handle_tags() + if(count($tags)) { foreach($tags as $tag) { if(strpos($tag,'#') === 0) { @@ -743,40 +733,36 @@ function diaspora_post($importer,$xml,$msg) { $plink = 'https://'.substr($diaspora_handle,strpos($diaspora_handle,'@')+1).'/posts/'.$guid; $datarray['uid'] = $importer['channel_id']; + +// FIXME $datarray['contact-id'] = $contact['id']; $datarray['wall'] = 0; $datarray['network'] = NETWORK_DIASPORA; + + $datarray['verb'] = ACTIVITY_POST; - $datarray['guid'] = $guid; - $datarray['uri'] = $datarray['parent-uri'] = $message_id; + $datarray['mid'] = $datarray['parent-mid'] = $guid; + $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); - $datarray['private'] = $private; - $datarray['parent'] = 0; + $datarray['item_private'] = $private; + + $datarray['plink'] = $plink; - $datarray['owner-name'] = $contact['name']; - $datarray['owner-link'] = $contact['url']; - //$datarray['owner-avatar'] = $contact['thumb']; - $datarray['owner-avatar'] = ((x($contact,'thumb')) ? $contact['thumb'] : $contact['photo']); - $datarray['author-name'] = $contact['name']; - $datarray['author-link'] = $contact['url']; - $datarray['author-avatar'] = $contact['thumb']; - $datarray['body'] = $body; - $datarray['tag'] = $str_tags; - $datarray['app'] = 'Diaspora'; - // if empty content it might be a photo that hasn't arrived yet. If a photo arrives, we'll make it visible. + $datarray['author_xchan'] = $contact['xchan_hash']; + $datarray['owner_xchan'] = $importer['channel_hash']; - $datarray['visible'] = ((strlen($body)) ? 1 : 0); + $datarray['body'] = $body; - $message_id = item_store($datarray); +// FIXME +// $datarray['tag'] = $str_tags; - //if($message_id) { - // q("update item set plink = '%s' where id = %d", - // dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), - // intval($message_id) - // ); - //} + $datarray['app'] = 'Diaspora'; + // if empty content it might be a photo that hasn't arrived yet. If a photo arrives, we'll make it visible. +// $datarray['visible'] = ((strlen($body)) ? 1 : 0); + + $result = item_store($datarray); return; } @@ -1105,20 +1091,20 @@ function diaspora_comment($importer,$xml,$msg) { return 202; } - $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", + $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `mid` = '%s' LIMIT 1", intval($importer['channel_id']), dbesc($guid) ); - if(count($r)) { + if($r) { logger('diaspora_comment: our comment just got relayed back to us (or there was a guid collision) : ' . $guid); return; } - $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", + $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `mid` = '%s' LIMIT 1", intval($importer['channel_id']), dbesc($parent_guid) ); - if(! count($r)) { + if(! $r) { logger('diaspora_comment: parent item not found: parent: ' . $parent_guid . ' item: ' . $guid); return; } @@ -1183,7 +1169,6 @@ function diaspora_comment($importer,$xml,$msg) { } $body = diaspora2bb($text); - $message_id = $diaspora_handle . ':' . $guid; $datarray = array(); @@ -1216,59 +1201,54 @@ function diaspora_comment($importer,$xml,$msg) { } $datarray['uid'] = $importer['channel_id']; - $datarray['contact-id'] = $contact['id']; - $datarray['type'] = 'remote-comment'; - $datarray['wall'] = $parent_item['wall']; - $datarray['network'] = NETWORK_DIASPORA; + +//FIXME +// $datarray['contact-id'] = $contact['id']; +// $datarray['type'] = 'remote-comment'; +// $datarray['wall'] = $parent_item['wall']; +// $datarray['network'] = NETWORK_DIASPORA; + $datarray['verb'] = ACTIVITY_POST; - $datarray['gravity'] = GRAVITY_COMMENT; - $datarray['guid'] = $guid; - $datarray['uri'] = $message_id; - $datarray['parent-uri'] = $parent_item['uri']; + $datarray['mid'] = $guid; + $datarray['parent_mid'] = $parent_item['mid']; + // No timestamps for comments? OK, we'll the use current time. $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert(); $datarray['private'] = $parent_item['private']; - $datarray['owner-name'] = $parent_item['owner-name']; - $datarray['owner-link'] = $parent_item['owner-link']; - $datarray['owner-avatar'] = $parent_item['owner-avatar']; + $datarray['owner_xchan'] = $parent_item['owner_xchan']; + $datarray['author_xchan'] = $person['xchan_hash']; - $datarray['author-name'] = $person['name']; - $datarray['author-link'] = $person['url']; - $datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']); $datarray['body'] = $body; - $datarray['tag'] = $str_tags; + +// FIXME +// $datarray['tag'] = $str_tags; // We can't be certain what the original app is if the message is relayed. - if(($parent_item['origin']) && (! $parent_author_signature)) - $datarray['app'] = 'Diaspora'; +// if(($parent_item['origin']) && (! $parent_author_signature)) +// $datarray['app'] = 'Diaspora'; - $message_id = item_store($datarray); + $result = item_store($datarray); - //if($message_id) { - //q("update item set plink = '%s' where id = %d", - // //dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), - // dbesc($a->get_baseurl().'/display/'.$datarray['guid']), - // intval($message_id) - //); - //} - - if(($parent_item['origin']) && (! $parent_author_signature)) { - q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", - intval($message_id), - dbesc($signed_data), - dbesc(base64_encode($author_signature)), - dbesc($diaspora_handle) - ); +// if(($parent_item['origin']) && (! $parent_author_signature)) { +// q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", +// intval($message_id), +// dbesc($signed_data), +// dbesc(base64_encode($author_signature)), +// dbesc($diaspora_handle) +// ); // 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. - proc_run('php','include/notifier.php','comment-import',$message_id); - } +// proc_run('php','include/notifier.php','comment-import',$message_id); +// } + +// FIXME +/* $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['channel_id']) @@ -1311,6 +1291,9 @@ function diaspora_comment($importer,$xml,$msg) { break; } } + +*/ + return; } -- cgit v1.2.3 From 6feaa2689d5cc30ef52a1b2e8ff82a8253aa5afb Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 19 Aug 2014 16:26:46 -0700 Subject: follow => connect --- include/conversation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 836bd1b24..daf1c723f 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -944,7 +944,7 @@ function item_photo_menu($item){ t("View Profile") => $profile_link, t("View Photos") => $photos_link, t("Matrix Activity") => $posts_link, - t("Follow") => $follow_url, + t("Connect") => $follow_url, t("Edit Contact") => $contact_url, t("Send PM") => $pm_url, t("Poke") => $poke_link -- cgit v1.2.3 From 8b5627e77773e40ee95e0ef18808ebbf3b61e094 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 19 Aug 2014 17:47:32 -0700 Subject: make sure privacy scope is completely reset on second delivery chain - revert if there are forum issues, this is subtle and complicated --- include/items.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 05ff1b078..2b9c937bb 100755 --- a/include/items.php +++ b/include/items.php @@ -2462,9 +2462,12 @@ function tag_deliver($uid,$item_id) { $private = (($u[0]['channel_allow_cid'] || $u[0]['channel_allow_gid'] || $u[0]['channel_deny_cid'] || $u[0]['channel_deny_gid']) ? 1 : 0); -//FIXME - add check for public_policy + $new_public_policy = map_scope($u[0]['channel_r_stream'],true); - $flag_bits = ITEM_WALL|ITEM_ORIGIN; + if((! $private) && $new_public_policy) + $private = 1; + + $flag_bits = $item['item_flags'] | ITEM_WALL|ITEM_ORIGIN; // maintain the original source, which will be the original item owner and was stored in source_xchan // when we created the delivery fork @@ -2474,8 +2477,28 @@ function tag_deliver($uid,$item_id) { intval($item_id) ); - $r = q("update item set item_flags = ( item_flags | %d ), owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', - deny_cid = '%s', deny_gid = '%s', item_private = %d where id = %d limit 1", + $title = $item['title']; + $body = $item['body']; + + if($private) { + if(!($flag_bits & ITEM_OBSCURED)) { + $key = get_config('system','pubkey'); + $flag_bits = $flag_bits|ITEM_OBSCURED; + $title = json_encode(aes_encapsulate($title,$key)); + $body = json_encode(aes_encapsulate($body,$key)); + } + } + else { + if($flag_bits & ITEM_OBSCURED) { + $key = get_config('system','prvkey'); + $flag_bits = $flag_bits ^ ITEM_OBSCURED; + $title = json_encode(aes_unencapsulate($title,$key)); + $body = json_encode(aes_unencapsulate($body,$key)); + } + } + + $r = q("update item set item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', + deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', title = '%s', body = '%s' where id = %d limit 1", intval($flag_bits), dbesc($u[0]['channel_hash']), dbesc($u[0]['channel_allow_cid']), @@ -2483,6 +2506,9 @@ function tag_deliver($uid,$item_id) { dbesc($u[0]['channel_deny_cid']), dbesc($u[0]['channel_deny_gid']), intval($private), + dbesc($new_public_policy), + dbesc($title), + dbesc($body), intval($item_id) ); if($r) @@ -2604,9 +2630,12 @@ function tag_deliver($uid,$item_id) { $private = (($u[0]['channel_allow_cid'] || $u[0]['channel_allow_gid'] || $u[0]['channel_deny_cid'] || $u[0]['channel_deny_gid']) ? 1 : 0); -// FIXME set public_policy and recheck private + $new_public_policy = map_scope($u[0]['channel_r_stream'],true); + + if((! $private) && $new_public_policy) + $private = 1; - $flag_bits = ITEM_WALL|ITEM_ORIGIN|ITEM_UPLINK; + $flag_bits = $item['item_flags'] | ITEM_WALL|ITEM_ORIGIN|ITEM_UPLINK; // preserve the source @@ -2614,8 +2643,30 @@ function tag_deliver($uid,$item_id) { intval($item_id) ); - $r = q("update item set item_flags = ( item_flags | %d ), owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', - deny_cid = '%s', deny_gid = '%s', item_private = %d where id = %d limit 1", + // make sure encryption matches the new scope + + $title = $item['title']; + $body = $item['body']; + + if($private) { + if(!($flag_bits & ITEM_OBSCURED)) { + $key = get_config('system','pubkey'); + $flag_bits = $flag_bits|ITEM_OBSCURED; + $title = json_encode(aes_encapsulate($title,$key)); + $body = json_encode(aes_encapsulate($body,$key)); + } + } + else { + if($flag_bits & ITEM_OBSCURED) { + $key = get_config('system','prvkey'); + $flag_bits = $flag_bits ^ ITEM_OBSCURED; + $title = json_encode(aes_unencapsulate($title,$key)); + $body = json_encode(aes_unencapsulate($body,$key)); + } + } + + $r = q("update item set item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', + deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', title = '%s', body = '%s' where id = %d limit 1", intval($flag_bits), dbesc($u[0]['channel_hash']), dbesc($u[0]['channel_allow_cid']), @@ -2623,6 +2674,9 @@ function tag_deliver($uid,$item_id) { dbesc($u[0]['channel_deny_cid']), dbesc($u[0]['channel_deny_gid']), intval($private), + dbesc($new_public_policy), + dbesc($title), + dbesc($body), intval($item_id) ); if($r) -- cgit v1.2.3 From 55d4ceb7e0c249eff337cb303c555bfa5d5bd2a0 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 19 Aug 2014 17:51:45 -0700 Subject: also reset comment policy on alternate delivery chains --- include/items.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 2b9c937bb..50ce9d3f5 100755 --- a/include/items.php +++ b/include/items.php @@ -2498,7 +2498,7 @@ function tag_deliver($uid,$item_id) { } $r = q("update item set item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', - deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', title = '%s', body = '%s' where id = %d limit 1", + deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s' where id = %d limit 1", intval($flag_bits), dbesc($u[0]['channel_hash']), dbesc($u[0]['channel_allow_cid']), @@ -2507,6 +2507,7 @@ function tag_deliver($uid,$item_id) { dbesc($u[0]['channel_deny_gid']), intval($private), dbesc($new_public_policy), + dbesc(map_scope($u[0]['channel_w_comment'])), dbesc($title), dbesc($body), intval($item_id) @@ -2666,7 +2667,7 @@ function tag_deliver($uid,$item_id) { } $r = q("update item set item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', - deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', title = '%s', body = '%s' where id = %d limit 1", + deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s' where id = %d limit 1", intval($flag_bits), dbesc($u[0]['channel_hash']), dbesc($u[0]['channel_allow_cid']), @@ -2675,6 +2676,7 @@ function tag_deliver($uid,$item_id) { dbesc($u[0]['channel_deny_gid']), intval($private), dbesc($new_public_policy), + dbesc(map_scope($u[0]['channel_w_comment'])), dbesc($title), dbesc($body), intval($item_id) -- cgit v1.2.3 From c7fe071a1fda1779ecb2a45016ea59b347695b67 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 19 Aug 2014 19:38:42 -0700 Subject: some work on network discovery --- include/diaspora.php | 91 ++++--------------- include/network.php | 244 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 167 insertions(+), 168 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 02d479d95..dda552536 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -140,85 +140,30 @@ function find_diaspora_person_by_handle($handle) { $endlessloop = 0; $maxloops = 10; - do { - $r = q("select * from xchan where xchan_addr = '%s' limit 1", - dbesc($handle) - ); - if($r) { - $person = $r[0]; - logger('find_diaspora_person_by handle: in cache ' . print_r($r,true), LOGGER_DEBUG); + + $r = q("select * from xchan where xchan_addr = '%s' limit 1", + dbesc($handle) + ); + if($r) { + $person = $r[0]; + logger('find_diaspora_person_by handle: in cache ' . print_r($r,true), LOGGER_DATA); // update record occasionally so it doesn't get stale - $d = strtotime($person['updated'] . ' +00:00'); - if($d < strtotime('now - 14 days')) - $update = true; - } +// $d = strtotime($person['updated'] . ' +00:00'); +// if($d < strtotime('now - 14 days')) +// $update = true; + } + if((! $person) || ($update)) { - // FETCHING PERSON INFORMATION FROM REMOTE SERVER - // - // If the person isn't in our 'fcontact' table, or if he/she is but - // his/her information hasn't been updated for more than 14 days, then - // we want to fetch the person's information from the remote server. - // - // Note that $person isn't changed by this block of code unless the - // person's information has been successfully fetched from the remote - // server. So if $person was 'false' to begin with (because he/she wasn't - // in the local cache), it'll stay false, and if $person held the local - // cache information to begin with, it'll keep that information. That way - // if there's a problem with the remote fetch, we can at least use our - // cached information--it's better than nothing. - -//fixme!!! - - if((! $person) || ($update)) { - // Lock the function to prevent race conditions if multiple items - // come in at the same time from a person who doesn't exist in - // fcontact - // - // Don't loop forever. On the last loop, try to create the contact - // whether the function is locked or not. Maybe the locking thread - // has died or something. At any rate, a duplicate in 'fcontact' - // is a much smaller problem than a deadlocked thread -// $got_lock = lock_function('find_diaspora_person_by_handle', false); - if(($endlessloop + 1) >= $maxloops) - $got_lock = true; - - if($got_lock) { - logger('find_diaspora_person_by_handle: create or refresh', LOGGER_DEBUG); - require_once('include/Scrape.php'); - $r = probe_url($handle, PROBE_DIASPORA); - - // Note that Friendica contacts can return a "Diaspora person" - // if Diaspora connectivity is enabled on their server - if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) { - add_fcontact($r,$update); - $person = ($r); - } + // try webfinger. Make sure to distinguish between diaspora, + // redmatrix w/diaspora protocol and friendica w/diaspora protocol. -// unlock_function('find_diaspora_person_by_handle'); - } - else { - logger('find_diaspora_person_by_handle: couldn\'t lock function', LOGGER_DEBUG); -// if(! $person) -// block_on_function_lock('find_diaspora_person_by_handle'); - } - } - } while((! $person) && (! $got_lock) && (++$endlessloop < $maxloops)); + $result = discover_by_webbie($handle); + + + } - // We need to try again if the person wasn't in 'fcontact' but the function was locked. - // The fact that the function was locked may mean that another process was creating the - // person's record. It could also mean another process was creating or updating an unrelated - // person. - // - // At any rate, we need to keep trying until we've either got the person or had a chance to - // try to fetch his/her remote information. But we don't want to block on locking the - // function, because if the other process is creating the record, then when we acquire the lock - // we'll dive right into creating another, duplicate record. We DO want to at least wait - // until the lock is released, so we don't flood the database with requests. - // - // If the person was in the 'fcontact' table, don't try again. It's not worth the time, since - // we do have some information for the person return $person; } diff --git a/include/network.php b/include/network.php index 66bba5b38..1a974a681 100644 --- a/include/network.php +++ b/include/network.php @@ -337,101 +337,6 @@ function convert_xml_element_to_array($xml_element, &$recursion_depth=0) { } } -// Given an email style address, perform webfinger lookup and -// return the resulting DFRN profile URL, or if no DFRN profile URL -// is located, returns an OStatus subscription template (prefixed -// with the string 'stat:' to identify it as on OStatus template). -// If this isn't an email style address just return $s. -// Return an empty string if email-style addresses but webfinger fails, -// or if the resultant personal XRD doesn't contain a supported -// subscription/friend-request attribute. - -// amended 7/9/2011 to return an hcard which could save potentially loading -// a lengthy content page to scrape dfrn attributes - - -function webfinger_dfrn($s,&$hcard) { - if(! strstr($s,'@')) { - return $s; - } - $profile_link = ''; - - $links = webfinger($s); - logger('webfinger_dfrn: ' . $s . ':' . print_r($links,true), LOGGER_DATA); - if(count($links)) { - foreach($links as $link) { - if($link['@attributes']['rel'] === NAMESPACE_DFRN) - $profile_link = $link['@attributes']['href']; - if($link['@attributes']['rel'] === NAMESPACE_OSTATUSSUB) - $profile_link = 'stat:' . $link['@attributes']['template']; - if($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') - $hcard = $link['@attributes']['href']; - } - } - return $profile_link; -} - -// Given an email style address, perform webfinger lookup and -// return the array of link attributes from the personal XRD file. -// On error/failure return an empty array. - - - -function webfinger($s, $debug = false) { - $host = ''; - if(strstr($s,'@')) { - $host = substr($s,strpos($s,'@') + 1); - } - if(strlen($host)) { - $tpl = fetch_lrdd_template($host); - logger('webfinger: lrdd template: ' . $tpl); - if(strlen($tpl)) { - $pxrd = str_replace('{uri}', urlencode('acct:' . $s), $tpl); - logger('webfinger: pxrd: ' . $pxrd); - $links = fetch_xrd_links($pxrd); - if(! count($links)) { - // try with double slashes - $pxrd = str_replace('{uri}', urlencode('acct://' . $s), $tpl); - logger('webfinger: pxrd: ' . $pxrd); - $links = fetch_xrd_links($pxrd); - } - return $links; - } - } - return array(); -} - - - - -// Given a host name, locate the LRDD template from that -// host. Returns the LRDD template or an empty string on -// error/failure. - - -function fetch_lrdd_template($host) { - $tpl = ''; - - $url1 = 'https://' . $host . '/.well-known/host-meta' ; - $url2 = 'http://' . $host . '/.well-known/host-meta' ; - $links = fetch_xrd_links($url1); - logger('fetch_lrdd_template from: ' . $url1); - logger('template (https): ' . print_r($links,true)); - if(! count($links)) { - logger('fetch_lrdd_template from: ' . $url2); - $links = fetch_xrd_links($url2); - logger('template (http): ' . print_r($links,true)); - } - if(count($links)) { - foreach($links as $link) - if($link['@attributes']['rel'] && $link['@attributes']['rel'] === 'lrdd') - $tpl = $link['@attributes']['template']; - } - if(! strpos($tpl,'{uri}')) - $tpl = ''; - return $tpl; -} - // Take a URL from the wild, prepend http:// if necessary // and check DNS to see if it's real (or check if is a valid IP address) // return true if it's OK, false if something is wrong with it @@ -912,3 +817,152 @@ function email_send($addr, $subject, $headers, $item) { logger('notifier: email delivery to ' . $addr); mail($addr, $subject, $body, $headers); } + + +function discover_by_webbie($webbie) { + + $x = webfinger_rfc7033($webbie); + if($x && array_key_exists('links',$x) && $x['links']) { + foreach($x['links'] as $link) { + if(array_key_exists('rel',$link) && $link['rel'] == 'http://purl.org/zot/protocol') { + logger('discover_by_webbie: zot found for ' . $webbie); + $z = z_fetch_url($link['href']); + if($z['success']) { + $j = json_decode($z['body'],true); + $i = import_xchan($j); + return true; + } + } + } + } + + $x = old_webfinger($webbie); + if($x) { + logger('old_webfinger: ' . print_r($x,true)); + } +} + + +function webfinger_rfc7033($webbie) { + + + if(! strpos($webbie,'@')) + return false; + $lhs = substr($webbie,0,strpos($webbie,'@')); + $rhs = substr($webbie,strpos($webbie,'@')+1); + + $resource = 'acct:' . $webbie; + + $s = z_fetch_url('https://' . $rhs . '/.well-known/webfinger?resource=' . $resource); + + if($s['success']) + $j = json_decode($s['body'],true); + else + return false; + return($j); +} + + +function old_webfinger($webbie) { + + $host = ''; + if(strstr($webbie,'@')) + $host = substr($webbie,strpos($webbie,'@') + 1); + + if(strlen($host)) { + $tpl = fetch_lrdd_template($host); + logger('old_webfinger: lrdd template: ' . $tpl,LOGGER_DATA); + if(strlen($tpl)) { + $pxrd = str_replace('{uri}', urlencode('acct:' . $webbie), $tpl); + logger('old_webfinger: pxrd: ' . $pxrd,LOGGER_DATA); + $links = fetch_xrd_links($pxrd); + if(! count($links)) { + // try with double slashes + $pxrd = str_replace('{uri}', urlencode('acct://' . $webbie), $tpl); + logger('old_webfinger: pxrd: ' . $pxrd,LOGGER_DATA); + $links = fetch_xrd_links($pxrd); + } + return $links; + } + } + return array(); +} + + +function fetch_lrdd_template($host) { + $tpl = ''; + + $url1 = 'https://' . $host . '/.well-known/host-meta' ; + $url2 = 'http://' . $host . '/.well-known/host-meta' ; + $links = fetch_xrd_links($url1); + logger('fetch_lrdd_template from: ' . $url1, LOGGER_DEBUG); + logger('template (https): ' . print_r($links,true),LOGGER_DEBUG); + if(! count($links)) { + logger('fetch_lrdd_template from: ' . $url2); + $links = fetch_xrd_links($url2); + logger('template (http): ' . print_r($links,true),LOGGER_DEBUG); + } + if(count($links)) { + foreach($links as $link) + if($link['@attributes']['rel'] && $link['@attributes']['rel'] === 'lrdd' && (!$link['@attributes']['type'] || $link['@attributes']['type'] === 'application/xrd+xml')) + $tpl = $link['@attributes']['template']; + } + if(! strpos($tpl,'{uri}')) + $tpl = ''; + return $tpl; + +} + + +function fetch_xrd_links($url) { + +logger('fetch_xrd_links: ' . $url); + + $redirects = 0; + $x = z_fetch_url($url,false,$redirects,array('timeout' => 20)); + + if(! $x['success']) + return array(); + + $xml = $x['body']; + logger('fetch_xrd_links: ' . $xml, LOGGER_DATA); + + if ((! $xml) || (! stristr($xml,''),array('href="','"/>'),$xml); + + $h = parse_xml_string($xml); + if(! $h) + return array(); + + $arr = convert_xml_element_to_array($h); + + $links = array(); + + if(isset($arr['xrd']['link'])) { + $link = $arr['xrd']['link']; + + if(! isset($link[0])) + $links = array($link); + else + $links = $link; + } + if(isset($arr['xrd']['alias'])) { + $alias = $arr['xrd']['alias']; + if(! isset($alias[0])) + $aliases = array($alias); + else + $aliases = $alias; + if(is_array($aliases) && count($aliases)) { + foreach($aliases as $alias) { + $links[]['@attributes'] = array('rel' => 'alias' , 'href' => $alias); + } + } + } + + logger('fetch_xrd_links: ' . print_r($links,true), LOGGER_DATA); + + return $links; +} \ No newline at end of file -- cgit v1.2.3 From 0c8866acdec1cef35ab5ac0e449f10a50e59a60e Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 19 Aug 2014 21:31:33 -0700 Subject: snakebite continued --- include/items.php | 161 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 108 insertions(+), 53 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 50ce9d3f5..0392e07a0 100755 --- a/include/items.php +++ b/include/items.php @@ -1233,13 +1233,14 @@ function get_atom_elements($feed,$item) { $author = $item->get_author(); if($author) { - $res['author-name'] = unxmlify($author->get_name()); - $res['author-link'] = unxmlify($author->get_link()); + $res['author_name'] = unxmlify($author->get_name()); + $res['author_link'] = unxmlify($author->get_link()); } else { - $res['author-name'] = unxmlify($feed->get_title()); - $res['author-link'] = unxmlify($feed->get_permalink()); + $res['author_name'] = unxmlify($feed->get_title()); + $res['author_link'] = unxmlify($feed->get_permalink()); } + $res['mid'] = unxmlify($item->get_id()); $res['title'] = unxmlify($item->get_title()); $res['body'] = unxmlify($item->get_content()); @@ -1264,9 +1265,9 @@ function get_atom_elements($feed,$item) { if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; foreach($base as $link) { - if(!x($res, 'author-avatar') || !$res['author-avatar']) { + if(!x($res, 'author_photo') || !$res['author_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') - $res['author-avatar'] = unxmlify($link['attribs']['']['href']); + $res['author_photo'] = unxmlify($link['attribs']['']['href']); } } } @@ -1277,11 +1278,11 @@ function get_atom_elements($feed,$item) { $base = $rawactor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; if($base && count($base)) { foreach($base as $link) { - if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link'])) - $res['author-link'] = unxmlify($link['attribs']['']['href']); - if(!x($res, 'author-avatar') || !$res['author-avatar']) { + if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) + $res['author_link'] = unxmlify($link['attribs']['']['href']); + if(!x($res, 'author_photo') || !$res['author_photo']) { if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') - $res['author-avatar'] = unxmlify($link['attribs']['']['href']); + $res['author_photo'] = unxmlify($link['attribs']['']['href']); } } } @@ -1289,16 +1290,16 @@ function get_atom_elements($feed,$item) { // No photo/profile-link on the item - look at the feed level - if((! (x($res,'author-link'))) || (! (x($res,'author-avatar')))) { + if((! (x($res,'author_link'))) || (! (x($res,'author_photo')))) { $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'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' && (! $res['author-link'])) - $res['author-link'] = unxmlify($link['attribs']['']['href']); - if(! $res['author-avatar']) { + if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) + $res['author_link'] = unxmlify($link['attribs']['']['href']); + if(! $res['author_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') - $res['author-avatar'] = unxmlify($link['attribs']['']['href']); + $res['author_photo'] = unxmlify($link['attribs']['']['href']); } } } @@ -1310,11 +1311,11 @@ function get_atom_elements($feed,$item) { if($base && count($base)) { foreach($base as $link) { - if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link'])) - $res['author-link'] = unxmlify($link['attribs']['']['href']); - if(! (x($res,'author-avatar'))) { + if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) + $res['author_link'] = unxmlify($link['attribs']['']['href']); + if(! (x($res,'author_photo'))) { if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') - $res['author-avatar'] = unxmlify($link['attribs']['']['href']); + $res['author_photo'] = unxmlify($link['attribs']['']['href']); } } } @@ -1378,9 +1379,9 @@ function get_atom_elements($feed,$item) { $private = $item->get_item_tags(NAMESPACE_DFRN,'private'); if($private && intval($private[0]['data']) > 0) - $res['private'] = intval($private[0]['data']); + $res['item_private'] = ((intval($private[0]['data'])) ? 1 : 0); else - $res['private'] = 0; + $res['item_private'] = 0; $rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location'); if($rawlocation) @@ -1419,21 +1420,21 @@ function get_atom_elements($feed,$item) { $rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner'); if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']) - $res['owner-name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']); + $res['owner_name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']); elseif($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']) - $res['owner-name'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']); + $res['owner_name'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']); if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']) - $res['owner-link'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']); + $res['owner_link'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']); elseif($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']) - $res['owner-link'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']); + $res['owner_link'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']); if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $base = $rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; foreach($base as $link) { - if(!x($res, 'owner-avatar') || !$res['owner-avatar']) { + if(!x($res, 'owner_photo') || !$res['owner_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') - $res['owner-avatar'] = unxmlify($link['attribs']['']['href']); + $res['owner_photo'] = unxmlify($link['attribs']['']['href']); } } } @@ -1488,6 +1489,7 @@ function get_atom_elements($feed,$item) { $attach = $item->get_enclosures(); if($attach) { + $res['attach'] = array(); $att_arr = array(); foreach($attach as $att) { $len = intval($att->get_length()); @@ -1503,33 +1505,32 @@ function get_atom_elements($feed,$item) { $title = ' '; if(! $type) $type = 'application/octet-stream'; - - $att_arr[] = '[attach]href="' . $link . '" length="' . $len . '" type="' . $type . '" title="' . $title . '"[/attach]'; } - $res['attach'] = implode(',', $att_arr); + $res['attach'][] = array('href' => $link, 'length' => $len, 'type' => $type, 'title' => $title ); } $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); if($rawobj) { - $res['object'] = '' . "\n"; + $obj = array(); + $child = $rawobj[0]['child']; if($child[NAMESPACE_ACTIVITY]['obj_type'][0]['data']) { $res['obj_type'] = $child[NAMESPACE_ACTIVITY]['obj_type'][0]['data']; - $res['object'] .= '' . $child[NAMESPACE_ACTIVITY]['obj_type'][0]['data'] . '' . "\n"; + $obj['type'] = $child[NAMESPACE_ACTIVITY]['obj_type'][0]['data']; } if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'id') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) - $res['object'] .= '' . $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '' . "\n"; + $obj['id'] = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']; if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) - $res['object'] .= '' . encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '' . "\n"; + $obj['link'] = encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']); if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'title') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']) - $res['object'] .= '' . $child[SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '' . "\n"; + $obj['title'] = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']; if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'content') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { $body = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']; if(! $body) $body = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data']; // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events - $res['object'] .= '' . xmlify($body) . '' . "\n"; + $obj['orig'] = xmlify($body); if((strpos($body,'<') !== false) || (strpos($body,'>') !== false)) { $body = purify_html($body); @@ -1537,48 +1538,52 @@ function get_atom_elements($feed,$item) { } - $res['object'] .= '' . $body . '' . "\n"; + $obj['content'] = $body; } - $res['object'] .= '' . "\n"; + $res['object'] = $obj; } $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'target'); if($rawobj) { - $res['target'] = '' . "\n"; + $obj = array(); + $child = $rawobj[0]['child']; if($child[NAMESPACE_ACTIVITY]['obj_type'][0]['data']) { - $res['target'] .= '' . $child[NAMESPACE_ACTIVITY]['obj_type'][0]['data'] . '' . "\n"; + $res['tgt_type'] = $child[NAMESPACE_ACTIVITY]['obj_type'][0]['data']; + $obj['type'] = $child[NAMESPACE_ACTIVITY]['obj_type'][0]['data']; } if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'id') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) - $res['target'] .= '' . $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '' . "\n"; + $obj['id'] = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']; if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) - $res['target'] .= '' . encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) . '' . "\n"; - if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'data') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']) - $res['target'] .= '' . $child[SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '' . "\n"; - if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'data') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { + $obj['link'] = encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']); + if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'title') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']) + $obj['title'] = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']; + if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'content') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { $body = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']; if(! $body) $body = $child[SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data']; // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events - $res['target'] .= '' . xmlify($body) . '' . "\n"; + $obj['orig'] = xmlify($body); if((strpos($body,'<') !== false) || (strpos($body,'>') !== false)) { $body = purify_html($body); $body = html2bbcode($body); + } - $res['target'] .= '' . $body . '' . "\n"; + $obj['content'] = $body; } - $res['target'] .= '' . "\n"; + $res['target'] = $obj; } // This is some experimental stuff. By now retweets are shown with "RT:" // But: There is data so that the message could be shown similar to native retweets // There is some better way to parse this array - but it didn't worked for me. +/* $child = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://activitystrea.ms/spec/1.0/"][object][0]["child"]; if (is_array($child)) { $message = $child["http://activitystrea.ms/spec/1.0/"]["object"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["content"][0]["data"]; @@ -1601,6 +1606,8 @@ function get_atom_elements($feed,$item) { } } +*/ + $arr = array('feed' => $feed, 'item' => $item, 'result' => $res); call_hooks('parse_atom', $arr); @@ -1613,6 +1620,10 @@ function encode_rel_links($links) { $o = ''; if(! ((is_array($links)) && (count($links)))) return $o; + +//fixme + return ''; + foreach($links as $link) { $o .= ' $uid, 'item' => $item, 'body' => $body); call_hooks('tagged',$arr); - // Valid tag. Send a notification + /** + * Kill two birds with one stone. As long as we're here, send a mention notification. + */ require_once('include/enotify.php'); notification(array( @@ -2624,6 +2660,10 @@ function tag_deliver($uid,$item_id) { return; } + /** + * At this point we're committed to setting up a second delivery chain. We just have to mangle some bits first. + */ + logger('tag_deliver: creating second delivery chain.'); // now change this copy of the post to a forum head message and deliver to all the tgroup members @@ -2688,6 +2728,16 @@ function tag_deliver($uid,$item_id) { } +/** + * @function tgroup_check($uid,$item) + * + * This function is called pre-deliver to see if a post matches the criteria to be tag delivered. + * We don't actually do anything except check that it matches the criteria. + * This is so that the channel with tag_delivery enabled can receive the post even if they turn off + * permissions for the sender to send their stream. tag_deliver() can't be called until the post is actually stored. + * By then it would be too late to reject it. + */ + function tgroup_check($uid,$item) { @@ -2999,8 +3049,11 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) else $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s'); } + + if($deleted && is_array($contact)) { -/* $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join `contact` on `item`.`contact-id` = `contact`.`id` +/* + $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join `contact` on `item`.`contact-id` = `contact`.`id` WHERE `mid` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1", dbesc($mid), intval($importer['channel_id']), @@ -3077,14 +3130,15 @@ logger('consume_feed: processing ' . $item_id); $item_id = $item->get_id(); $datarray = get_atom_elements($feed,$item); +/* if((! x($datarray,'author-name')) && ($contact['network'] != NETWORK_DFRN)) $datarray['author-name'] = $contact['name']; if((! x($datarray,'author-link')) && ($contact['network'] != NETWORK_DFRN)) $datarray['author-link'] = $contact['url']; if((! x($datarray,'author-avatar')) && ($contact['network'] != NETWORK_DFRN)) $datarray['author-avatar'] = $contact['thumb']; - - if((! x($datarray,'author-name')) || (! x($datarray,'author-link'))) { +*/ + if((! x($datarray,'author_name')) || (! x($datarray,'author_link'))) { logger('consume_feed: no author information! ' . print_r($datarray,true)); continue; } @@ -3119,7 +3173,8 @@ logger('consume_feed: processing ' . $item_id); $datarray['parent_mid'] = $parent_mid; $datarray['uid'] = $importer['channel_id']; - $datarray['contact-id'] = $contact['id']; +// $datarray['contact-id'] = $contact['id']; + if((activity_match($datarray['verb'],ACTIVITY_LIKE)) || (activity_match($datarray['verb'],ACTIVITY_DISLIKE))) { $datarray['type'] = 'activity'; $datarray['gravity'] = GRAVITY_LIKE; -- cgit v1.2.3 From 0fef39a3265602905d1f629c1209e8279c54f0d9 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 19 Aug 2014 22:47:11 -0700 Subject: fangs bared --- include/items.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 0392e07a0..30a685ed3 100755 --- a/include/items.php +++ b/include/items.php @@ -3005,7 +3005,7 @@ function mail_store($arr) { * recursion. */ -function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) { +function consume_feed($xml,$importer,&$contact,$pass = 0) { require_once('library/simplepie/simplepie.inc'); @@ -3361,6 +3361,28 @@ logger('consume_feed: ' . print_r($datarray,true)); } +function handle_feed($uid,$abook_id,$url) { + + require_once('include/Contact.php'); + $channel = channelx_by_n($uid); + if(! $channel) + return; + $x = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_channel = %d limit 1", + dbesc($abook_id), + intval($uid) + ); + + $recurse = 0; + $z = z_fetch_url($url,false,$recurse,array('novalidate' => true)); + +logger('handle_feed:' . print_r($z,true)); + + if($z['success']) { + consume_feed($z['body'],$channel,$x[0],0); + consume_feed($z['body'],$channel,$x[0],1); + } +} + function atom_author($tag,$name,$uri,$h,$w,$type,$photo) { $o = ''; -- cgit v1.2.3 From b1029869295e50040dba2cdc33c9ca797ca76ffb Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 20 Aug 2014 04:38:17 -0700 Subject: greatly simplify consume_feed() - a lot of this was friendica specific and somebody may want to put some of it back in, but we'd be much better off building a zot compatible feed for friendica (hint,hint) - even if it didn't support the other protocol bits. Special purpose feed handlers for things like likes, dislikes, events, and community tags are better handled as zot arrays. We have all those handlers. We just need to pass them a JSON message instead of an XML/Atom message. Handlers for statusnet follow messages are another casualty. That's easy to bring back - but we need to keep driving nails into the XML coffin or the damn zombies will get out. --- include/items.php | 244 +++++++++++------------------------------------------- 1 file changed, 49 insertions(+), 195 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 30a685ed3..03b493bc3 100755 --- a/include/items.php +++ b/include/items.php @@ -3019,10 +3019,6 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { $feed = new SimplePie(); $feed->set_raw_data($xml); - if($datedir) - $feed->enable_order_by_date(true); - else - $feed->enable_order_by_date(false); $feed->init(); if($feed->error()) @@ -3032,7 +3028,6 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { // Check at the feed level for updated contact name and/or photo - // process any deleted entries $del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry'); @@ -3052,41 +3047,18 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { if($deleted && is_array($contact)) { -/* - $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join `contact` on `item`.`contact-id` = `contact`.`id` - WHERE `mid` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1", + $r = q("SELECT * from item where mid = '%s' and author_xchan = '%s' and uid = %d limit 1", dbesc($mid), - intval($importer['channel_id']), - intval($contact['id']) + dbesc($contact['xchan_hash']), + intval($importer['channel_id']) ); -*/ - if(count($r)) { + + if($r) { $item = $r[0]; - if(! $item['deleted']) + if(! ($item['item_restrict'] & ITEM_DELETED)) { logger('consume_feed: deleting item ' . $item['id'] . ' mid=' . $item['mid'], LOGGER_DEBUG); - - if($item['mid'] == $item['parent_mid']) { - $r = q("UPDATE `item` SET item_restrict = (item_restrict | %d), `edited` = '%s', `changed` = '%s', - `body` = '', `title` = '' - WHERE `parent_mid` = '%s' AND `uid` = %d", - intval(ITEM_DELETED), - dbesc($when), - dbesc(datetime_convert()), - dbesc($item['mid']), - intval($importer['channel_id']) - ); - } - else { - $r = q("UPDATE `item` SET item_restrict = ( item_restrict | %d ), `edited` = '%s', `changed` = '%s', - `body` = '', `title` = '' - WHERE `mid` = '%s' AND `uid` = %d LIMIT 1", - intval(ITEM_DELETED), - dbesc($when), - dbesc(datetime_convert()), - dbesc($mid), - intval($importer['channel_id']) - ); + drop_item($item['id'],false); } } } @@ -3097,21 +3069,16 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { if($feed->get_item_quantity()) { - logger('consume_feed: feed item count = ' . $feed->get_item_quantity()); - - // in inverse date order - if ($datedir) - $items = array_reverse($feed->get_items()); - else - $items = $feed->get_items(); + logger('consume_feed: feed item count = ' . $feed->get_item_quantity(), LOGGER_DEBUG); + $items = $feed->get_items(); foreach($items as $item) { $is_reply = false; $item_id = $item->get_id(); -logger('consume_feed: processing ' . $item_id); + logger('consume_feed: processing ' . $item_id, LOGGER_DEBUG); $rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to'); if(isset($rawthread[0]['attribs']['']['ref'])) { @@ -3130,21 +3097,14 @@ logger('consume_feed: processing ' . $item_id); $item_id = $item->get_id(); $datarray = get_atom_elements($feed,$item); -/* - if((! x($datarray,'author-name')) && ($contact['network'] != NETWORK_DFRN)) - $datarray['author-name'] = $contact['name']; - if((! x($datarray,'author-link')) && ($contact['network'] != NETWORK_DFRN)) - $datarray['author-link'] = $contact['url']; - if((! x($datarray,'author-avatar')) && ($contact['network'] != NETWORK_DFRN)) - $datarray['author-avatar'] = $contact['thumb']; -*/ - if((! x($datarray,'author_name')) || (! x($datarray,'author_link'))) { - logger('consume_feed: no author information! ' . print_r($datarray,true)); - continue; - } + if(! x($datarray,'author_name')) + $datarray['author_name'] = $contact['xchan_name']; + if(! x($datarray,'author_link')) + $datarray['author_link'] = $contact['xchan_url']; + if(! x($datarray,'author_photo')) + $datarray['author_photo'] = $contact['xchan_photo_m']; - - $r = q("SELECT `uid`, `edited`, `body` FROM `item` WHERE `mid` = '%s' AND `uid` = %d LIMIT 1", + $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", dbesc($item_id), intval($importer['channel_id']) ); @@ -3152,70 +3112,26 @@ logger('consume_feed: processing ' . $item_id); // Update content if 'updated' changes if($r) { - if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) { + if((x($datarray,'edited') !== false) + && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) { // do not accept (ignore) an earlier edit than one we currently have. if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) continue; - $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `mid` = '%s' AND `uid` = %d LIMIT 1", - dbesc($datarray['title']), - dbesc($datarray['body']), - dbesc(datetime_convert('UTC','UTC',$datarray['edited'])), - dbesc($item_id), - intval($importer['channel_id']) - ); + update_feed_item($importer['channel_id'],$datarray); } - continue; } - $datarray['parent_mid'] = $parent_mid; $datarray['uid'] = $importer['channel_id']; -// $datarray['contact-id'] = $contact['id']; - - if((activity_match($datarray['verb'],ACTIVITY_LIKE)) || (activity_match($datarray['verb'],ACTIVITY_DISLIKE))) { - $datarray['type'] = 'activity'; - $datarray['gravity'] = GRAVITY_LIKE; - // only one like or dislike per person - $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent_mid` = '%s' OR `thr_parent` = '%s') limit 1", - intval($datarray['uid']), - intval($datarray['contact-id']), - dbesc($datarray['verb']), - dbesc($parent_mid), - dbesc($parent_mid) - ); - if($r && count($r)) - continue; - } - - if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['obj_type'] === ACTIVITY_OBJ_TAGTERM)) { - $xo = parse_xml_string($datarray['object'],false); - $xt = parse_xml_string($datarray['target'],false); + $datarray['author_xchan'] = $contact['xchan_hash']; - if($xt->type == ACTIVITY_OBJ_NOTE) { - $r = q("select * from item where `mid` = '%s' AND `uid` = %d limit 1", - dbesc($xt->id), - intval($importer['channel_id']) - ); - if(! count($r)) - continue; + // FIXME pull out the author and owner - // extract tag, if not duplicate, add to parent item - if($xo->id && $xo->content) { - $newtag = '#[zrl=' . $xo->id . ']'. $xo->content . '[/zrl]'; - if(! (stristr($r[0]['tag'],$newtag))) { - q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1", - dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . $newtag), - intval($r[0]['id']) - ); - } - } - } - } -logger('consume_feed: ' . print_r($datarray,true)); + logger('consume_feed: ' . print_r($datarray,true),LOGGER_DATA); // $xx = item_store($datarray); $r = $xx['item_id']; @@ -3231,43 +3147,21 @@ logger('consume_feed: ' . print_r($datarray,true)); $datarray = get_atom_elements($feed,$item); if(is_array($contact)) { - if((! x($datarray,'author-name')) && ($contact['network'] != NETWORK_DFRN)) - $datarray['author-name'] = $contact['name']; - if((! x($datarray,'author-link')) && ($contact['network'] != NETWORK_DFRN)) - $datarray['author-link'] = $contact['url']; - if((! x($datarray,'author-avatar')) && ($contact['network'] != NETWORK_DFRN)) - $datarray['author-avatar'] = $contact['thumb']; + if(! x($datarray,'author_name')) + $datarray['author_name'] = $contact['xchan_name']; + if(! x($datarray,'author_link')) + $datarray['author_link'] = $contact['xchan_url']; + if(! x($datarray,'author_photo')) + $datarray['author_photo'] = $contact['xchan_photo_m']; } - if((! x($datarray,'author-name')) || (! x($datarray,'author-link'))) { + if((! x($datarray,'author_name')) || (! x($datarray,'author_link'))) { logger('consume_feed: no author information! ' . print_r($datarray,true)); continue; } - // special handling for events - - if((x($datarray,'obj_type')) && ($datarray['obj_type'] === ACTIVITY_OBJ_EVENT)) { - $ev = bbtoevent($datarray['body']); - if(x($ev,'desc') && x($ev,'start')) { - $ev['uid'] = $importer['channel_id']; - $ev['mid'] = $item_id; - $ev['edited'] = $datarray['edited']; - $ev['private'] = $datarray['private']; - - if(is_array($contact)) - $ev['cid'] = $contact['id']; - $r = q("SELECT * FROM `event` WHERE `mid` = '%s' AND `uid` = %d LIMIT 1", - dbesc($item_id), - intval($importer['channel_id']) - ); - if(count($r)) - $ev['id'] = $r[0]['id']; -// $xyz = event_store($ev); - continue; - } - } - $r = q("SELECT `uid`, `edited`, `body` FROM `item` WHERE `mid` = '%s' AND `uid` = %d LIMIT 1", + $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", dbesc($item_id), intval($importer['channel_id']) ); @@ -3275,79 +3169,32 @@ logger('consume_feed: ' . print_r($datarray,true)); // Update content if 'updated' changes if($r) { - if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) { + if((x($datarray,'edited') !== false) + && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) { // do not accept (ignore) an earlier edit than one we currently have. if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited']) continue; - $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `mid` = '%s' AND `uid` = %d LIMIT 1", - dbesc($datarray['title']), - dbesc($datarray['body']), - dbesc(datetime_convert('UTC','UTC',$datarray['edited'])), - dbesc($item_id), - intval($importer['channel_id']) - ); + update_feed_item($importer['channel_id'],$datarray); } continue; } - if(activity_match($datarray['verb'],ACTIVITY_FOLLOW)) { - logger('consume-feed: New follower'); - new_follower($importer,$contact,$datarray,$item); - return; - } - if(activity_match($datarray['verb'],ACTIVITY_UNFOLLOW)) { - lose_follower($importer,$contact,$datarray,$item); - return; - } - - if(activity_match($datarray['verb'],ACTIVITY_REQ_FRIEND)) { - logger('consume-feed: New friend request'); - new_follower($importer,$contact,$datarray,$item,true); - return; - } - if(activity_match($datarray['verb'],ACTIVITY_UNFRIEND)) { - lose_sharer($importer,$contact,$datarray,$item); - return; - } - - -// if(! is_array($contact)) -// return; - - - // This is my contact on another system, but it's really me. - // Turn this into a wall post. - - if($contact['remote_self']) { - $datarray['wall'] = 1; - } $datarray['parent_mid'] = $item_id; $datarray['uid'] = $importer['channel_id']; - $datarray['contact-id'] = $contact['id']; - - if(! link_compare($datarray['owner-link'],$contact['url'])) { - // The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, - // but otherwise there's a possible data mixup on the sender's system. - // the tgroup delivery code called from item_store will correct it if it's a forum, - // but we're going to unconditionally correct it here so that the post will always be owned by our contact. - logger('consume_feed: Correcting item owner.', LOGGER_DEBUG); - $datarray['owner-name'] = $contact['name']; - $datarray['owner-link'] = $contact['url']; - $datarray['owner-avatar'] = $contact['thumb']; - } + $datarray['author_xchan'] = $contact['author_xchan']; - // We've allowed "followers" to reach this point so we can decide if they are - // posting an @-tag delivery, which followers are allowed to do for certain - // page types. Now that we've parsed the post, let's check if it is legit. Otherwise ignore it. +// if(! link_compare($datarray['owner_link'],$contact['xchan_url'])) { +// logger('consume_feed: Correcting item owner.', LOGGER_DEBUG); +// $datarray['owner-name'] = $contact['name']; +// $datarray['owner-link'] = $contact['url']; +// $datarray['owner-avatar'] = $contact['thumb']; +// } - if(($contact['rel'] == CONTACT_IS_FOLLOWER) && (! tgroup_check($importer['channel_id'],$datarray))) - continue; - -logger('consume_feed: ' . print_r($datarray,true)); + logger('consume_feed: ' . print_r($datarray,true),LOGGER_DATA); // $xx = item_store($datarray); $r = $xx['item_id']; @@ -3358,6 +3205,13 @@ logger('consume_feed: ' . print_r($datarray,true)); } +} + +function update_feed_item($uid,$datarray) { + + logger('update_feed_item: ' . $uid . ' ' . print_r($datarray,true), LOGGER_DATA); + + } -- cgit v1.2.3 From a6829f7dcb6735ee0b2f003647cc168e55002a5f Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 20 Aug 2014 17:15:13 -0700 Subject: move Friendica photo migrator to addons, bring back a few XML scraping functions that we're going to require (unfortunately) --- include/network.php | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index 1a974a681..614049299 100644 --- a/include/network.php +++ b/include/network.php @@ -965,4 +965,168 @@ logger('fetch_xrd_links: ' . $url); logger('fetch_xrd_links: ' . print_r($links,true), LOGGER_DATA); return $links; -} \ No newline at end of file +} + + +function scrape_vcard($url) { + + $a = get_app(); + + $ret = array(); + + logger('scrape_vcard: url=' . $url); + + $x = z_fetch_url($url); + if(! $x['success']) + return $ret; + + $s = $x['body']; + + if(! $s) + return $ret; + + $headers = $x['header']; + $lines = explode("\n",$headers); + if(count($lines)) { + foreach($lines as $line) { + // don't try and run feeds through the html5 parser + if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml')))) + return ret; + } + } + + try { + $dom = HTML5_Parser::parse($s); + } catch (DOMException $e) { + logger('scrape_vcard: parse error: ' . $e); + } + + if(! $dom) + return $ret; + + // Pull out hCard profile elements + + $largest_photo = 0; + + $items = $dom->getElementsByTagName('*'); + foreach($items as $item) { + if(attribute_contains($item->getAttribute('class'), 'vcard')) { + $level2 = $item->getElementsByTagName('*'); + foreach($level2 as $x) { + if(attribute_contains($x->getAttribute('class'),'fn')) + $ret['fn'] = $x->textContent; + if((attribute_contains($x->getAttribute('class'),'photo')) + || (attribute_contains($x->getAttribute('class'),'avatar'))) { + $size = intval($x->getAttribute('width')); + if(($size > $largest_photo) || (! $largest_photo)) { + $ret['photo'] = $x->getAttribute('src'); + $largest_photo = $size; + } + } + if((attribute_contains($x->getAttribute('class'),'nickname')) + || (attribute_contains($x->getAttribute('class'),'uid'))) { + $ret['nick'] = $x->textContent; + } + } + } + } + + return $ret; +} + + + +function scrape_feed($url) { + + $a = get_app(); + + $ret = array(); + $level = 0; + $x = z_fetch_url($url,false,$level,array('novalidate' => true)); + + if(! $x['success']) + return $ret; + + $headers = $x['header']; + $code = $x['return_code']; + $s = $x['body']; + + logger('scrape_feed: returns: ' . $code . ' headers=' . $headers, LOGGER_DEBUG); + + if(! $s) { + logger('scrape_feed: no data returned for ' . $url); + return $ret; + } + + + $lines = explode("\n",$headers); + if(count($lines)) { + foreach($lines as $line) { + if(stristr($line,'content-type:')) { + if(stristr($line,'application/atom+xml') || stristr($s,'')) { + $ret['feed_rss'] = $url; + return $ret; + } + } + + try { + $dom = HTML5_Parser::parse($s); + } catch (DOMException $e) { + logger('scrape_feed: parse error: ' . $e); + } + + if(! $dom) { + logger('scrape_feed: failed to parse.'); + return $ret; + } + + + $head = $dom->getElementsByTagName('base'); + if($head) { + foreach($head as $head0) { + $basename = $head0->getAttribute('href'); + break; + } + } + if(! $basename) + $basename = implode('/', array_slice(explode('/',$url),0,3)) . '/'; + + $items = $dom->getElementsByTagName('link'); + + // get Atom/RSS link elements, take the first one of either. + + if($items) { + foreach($items as $item) { + $x = $item->getAttribute('rel'); + if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml')) { + if(! x($ret,'feed_atom')) + $ret['feed_atom'] = $item->getAttribute('href'); + } + if(($x === 'alternate') && ($item->getAttribute('type') === 'application/rss+xml')) { + if(! x($ret,'feed_rss')) + $ret['feed_rss'] = $item->getAttribute('href'); + } + } + } + + // Drupal and perhaps others only provide relative URL's. Turn them into absolute. + + if(x($ret,'feed_atom') && (! strstr($ret['feed_atom'],'://'))) + $ret['feed_atom'] = $basename . $ret['feed_atom']; + if(x($ret,'feed_rss') && (! strstr($ret['feed_rss'],'://'))) + $ret['feed_rss'] = $basename . $ret['feed_rss']; + + return $ret; +} + -- cgit v1.2.3 From a169e5c4f3b54003a6a4dfaf61269eb18f34f17a Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 20 Aug 2014 18:35:36 -0700 Subject: restructure the author and owner info from feeds --- include/items.php | 143 ++++++++++++++++++++++-------------------------------- 1 file changed, 58 insertions(+), 85 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 03b493bc3..e5c9549e2 100755 --- a/include/items.php +++ b/include/items.php @@ -1224,21 +1224,21 @@ function get_profile_elements($x) { -function get_atom_elements($feed,$item) { +function get_atom_elements($feed,$item,&$author) { $best_photo = array(); $res = array(); - $author = $item->get_author(); - if($author) { - $res['author_name'] = unxmlify($author->get_name()); - $res['author_link'] = unxmlify($author->get_link()); + $found_author = $item->get_author(); + if($found_author) { + $author['author_name'] = unxmlify($found_author->get_name()); + $author['author_link'] = unxmlify($found_author->get_link()); } else { - $res['author_name'] = unxmlify($feed->get_title()); - $res['author_link'] = unxmlify($feed->get_permalink()); + $author['author_name'] = unxmlify($feed->get_title()); + $author['author_link'] = unxmlify($feed->get_permalink()); } $res['mid'] = unxmlify($item->get_id()); @@ -1265,9 +1265,9 @@ function get_atom_elements($feed,$item) { if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; foreach($base as $link) { - if(!x($res, 'author_photo') || !$res['author_photo']) { + if(!x($author, 'author_photo') || ! $author['author_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') - $res['author_photo'] = unxmlify($link['attribs']['']['href']); + $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } @@ -1279,10 +1279,10 @@ function get_atom_elements($feed,$item) { if($base && count($base)) { foreach($base as $link) { if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) - $res['author_link'] = unxmlify($link['attribs']['']['href']); - if(!x($res, 'author_photo') || !$res['author_photo']) { + $author['author_link'] = unxmlify($link['attribs']['']['href']); + if(!x($author, 'author_photo') || ! $author['author_photo']) { if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') - $res['author_photo'] = unxmlify($link['attribs']['']['href']); + $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } @@ -1290,16 +1290,16 @@ function get_atom_elements($feed,$item) { // No photo/profile-link on the item - look at the feed level - if((! (x($res,'author_link'))) || (! (x($res,'author_photo')))) { + if((! (x($author,'author_link'))) || (! (x($author,'author_photo')))) { $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'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' && (! $res['author_link'])) - $res['author_link'] = unxmlify($link['attribs']['']['href']); - if(! $res['author_photo']) { + if($link['attribs']['']['rel'] === 'alternate' && (! $author['author_link'])) + $author['author_link'] = unxmlify($link['attribs']['']['href']); + if(! $author['author_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') - $res['author_photo'] = unxmlify($link['attribs']['']['href']); + $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } @@ -1312,10 +1312,10 @@ function get_atom_elements($feed,$item) { if($base && count($base)) { foreach($base as $link) { if($link['attribs']['']['rel'] === 'alternate' && (! $res['author_link'])) - $res['author_link'] = unxmlify($link['attribs']['']['href']); - if(! (x($res,'author_photo'))) { + $author['author_link'] = unxmlify($link['attribs']['']['href']); + if(! (x($author,'author_photo'))) { if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo') - $res['author_photo'] = unxmlify($link['attribs']['']['href']); + $author['author_photo'] = unxmlify($link['attribs']['']['href']); } } } @@ -1419,22 +1419,25 @@ function get_atom_elements($feed,$item) { $res['edited'] = datetime_convert(); $rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner'); + if(! $rawowner) + $rawowner = $item->get_item_tags(NAMESPACE_ZOT,'owner'); + if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']) - $res['owner_name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']); + $author['owner_name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']); elseif($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']) - $res['owner_name'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']); + $author['owner_name'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['name'][0]['data']); if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']) - $res['owner_link'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']); + $author['owner_link'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']); elseif($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']) - $res['owner_link'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']); + $author['owner_link'] = unxmlify($rawowner[0]['child'][NAMESPACE_DFRN]['uri'][0]['data']); if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { $base = $rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']; foreach($base as $link) { - if(!x($res, 'owner_photo') || !$res['owner_photo']) { + if(!x($author, 'owner_photo') || ! $author['owner_photo']) { if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') - $res['owner_photo'] = unxmlify($link['attribs']['']['href']); + $author['owner_photo'] = unxmlify($link['attribs']['']['href']); } } } @@ -1579,39 +1582,11 @@ function get_atom_elements($feed,$item) { $res['target'] = $obj; } - // This is some experimental stuff. By now retweets are shown with "RT:" - // But: There is data so that the message could be shown similar to native retweets - // There is some better way to parse this array - but it didn't worked for me. - -/* - $child = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://activitystrea.ms/spec/1.0/"][object][0]["child"]; - if (is_array($child)) { - $message = $child["http://activitystrea.ms/spec/1.0/"]["object"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["content"][0]["data"]; - $author = $child[SIMPLEPIE_NAMESPACE_ATOM_10]["author"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]; - $uri = $author["uri"][0]["data"]; - $name = $author["name"][0]["data"]; - $avatar = @array_shift($author["link"][2]["attribs"]); - $avatar = $avatar["href"]; - - if (($name != "") and ($uri != "") and ($avatar != "") and ($message != "")) { - $res["owner-name"] = $res["author-name"]; - $res["owner-link"] = $res["author-link"]; - $res["owner-avatar"] = $res["author-avatar"]; - - $res["author-name"] = $name; - $res["author-link"] = $uri; - $res["author-avatar"] = $avatar; - - $res["body"] = html2bbcode($message); - } - } - -*/ - $arr = array('feed' => $feed, 'item' => $item, 'result' => $res); call_hooks('parse_atom', $arr); - logger('get_atom_elements: ' . print_r($res,true)); + logger('get_atom_elements: author: ' . print_r($author,true),LOGGER_DATA); + logger('get_atom_elements: ' . print_r($res,true),LOGGER_DATA); return $res; } @@ -1621,9 +1596,6 @@ function encode_rel_links($links) { if(! ((is_array($links)) && (count($links)))) return $o; -//fixme - return ''; - foreach($links as $link) { $o .= 'set_raw_data($xml); $feed->init(); @@ -3095,14 +3064,15 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { // Have we seen it? If not, import it. $item_id = $item->get_id(); - $datarray = get_atom_elements($feed,$item); + $author = array(); + $datarray = get_atom_elements($feed,$item,$author); - if(! x($datarray,'author_name')) - $datarray['author_name'] = $contact['xchan_name']; - if(! x($datarray,'author_link')) - $datarray['author_link'] = $contact['xchan_url']; - if(! x($datarray,'author_photo')) - $datarray['author_photo'] = $contact['xchan_photo_m']; + if(! x($author,'author_name')) + $author['author_name'] = $contact['xchan_name']; + if(! x($author,'author_link')) + $author['author_link'] = $contact['xchan_url']; + if(! x($author,'author_photo')) + $author['author_photo'] = $contact['xchan_photo_m']; $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", dbesc($item_id), @@ -3126,6 +3096,8 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { $datarray['parent_mid'] = $parent_mid; $datarray['uid'] = $importer['channel_id']; + +//FIXME $datarray['author_xchan'] = $contact['xchan_hash']; // FIXME pull out the author and owner @@ -3143,20 +3115,20 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { // Head post of a conversation. Have we seen it? If not, import it. $item_id = $item->get_id(); - - $datarray = get_atom_elements($feed,$item); + $author = array(); + $datarray = get_atom_elements($feed,$item,$author); if(is_array($contact)) { - if(! x($datarray,'author_name')) - $datarray['author_name'] = $contact['xchan_name']; - if(! x($datarray,'author_link')) - $datarray['author_link'] = $contact['xchan_url']; - if(! x($datarray,'author_photo')) - $datarray['author_photo'] = $contact['xchan_photo_m']; + if(! x($author,'author_name')) + $author['author_name'] = $contact['xchan_name']; + if(! x($author,'author_link')) + $author['author_link'] = $contact['xchan_url']; + if(! x($author,'author_photo')) + $author['author_photo'] = $contact['xchan_photo_m']; } - if((! x($datarray,'author_name')) || (! x($datarray,'author_link'))) { - logger('consume_feed: no author information! ' . print_r($datarray,true)); + if((! x($author,'author_name')) || (! x($author,'author_link'))) { + logger('consume_feed: no author information! ' . print_r($author,true)); continue; } @@ -3185,14 +3157,15 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { $datarray['parent_mid'] = $item_id; $datarray['uid'] = $importer['channel_id']; +//FIXME $datarray['author_xchan'] = $contact['author_xchan']; -// if(! link_compare($datarray['owner_link'],$contact['xchan_url'])) { -// logger('consume_feed: Correcting item owner.', LOGGER_DEBUG); -// $datarray['owner-name'] = $contact['name']; -// $datarray['owner-link'] = $contact['url']; -// $datarray['owner-avatar'] = $contact['thumb']; -// } + if(! link_compare($author['owner_link'],$contact['xchan_url'])) { + logger('consume_feed: Correcting item owner.', LOGGER_DEBUG); + $author['owner-name'] = $contact['name']; + $author['owner-link'] = $contact['url']; + $author['owner-avatar'] = $contact['thumb']; + } logger('consume_feed: ' . print_r($datarray,true),LOGGER_DATA); -- cgit v1.2.3 From af45b34ee044966210e6101585fe362acf1ca098 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 20 Aug 2014 20:49:03 -0700 Subject: verified that chatroom expire is working, so doing away with the second function to do the same thing. If you have a problem with chatroom expiration, check that it was created with cr_expire set to 120 (minutes). Chatrooms created during the first couple of days of the chat feature didn't have this. You can set the DB value manually. --- include/chat.php | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/chat.php b/include/chat.php index 5f69853e7..b8fb185df 100644 --- a/include/chat.php +++ b/include/chat.php @@ -128,8 +128,10 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) { } } - if(intval($x[0]['cr_expire'])) - $r = q("delete from chat where created < UTC_TIMESTAMP() - INTERVAL " . intval($x[0]['cr_expire']) . " MINUTE and chat_room = " . intval($x[0]['cr_id'])); + if(intval($x[0]['cr_expire'])) { + $sql = "delete from chat where created < UTC_TIMESTAMP() - INTERVAL " . intval($x[0]['cr_expire']) . " MINUTE and chat_room = " . intval($x[0]['cr_id']); + $r = q($sql); + } $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1", dbesc($observer_xchan), @@ -153,7 +155,6 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) { dbesc($client) ); - chatroom_flush($room_id,$xchan); return $r; } @@ -226,21 +227,5 @@ function chat_message($uid,$room_id,$xchan,$text) { ); $ret['success'] = true; - chatroom_flush($room_id,$xchan); return $ret; } - -/** - * Reduces the number of lines shown in chat by removing those older than MAX_CHATROOM_HOURS - */ - -function chatroom_flush($room_id,$xchan) { - - - $date_limit = date('Y-m-d H:i:s', time() - 3600 * MAX_CHATROOM_HOURS); - $d = q("delete from chat where chat_room = %d and chat_xchan = '%s' and created < '%s'", - intval($room_id), - dbesc($xchan), - datetime_convert('','', $date_limit)); - return true; -} -- cgit v1.2.3 From b4aed1212930e40377665dc45271f2b1f428511f Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 20 Aug 2014 23:01:25 -0700 Subject: extensible profiles - add the input form elements. Still needs styling and we're not yet storing the results. And right now we're ignoring the type and only doing type=string. Oh yeah - and I split off starting the second delivery chain into its own function in tag_deliver since it was largely duplicate code. --- include/items.php | 234 +++++++++++++++++++++++------------------------------- 1 file changed, 99 insertions(+), 135 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index e5c9549e2..fbe67817d 100755 --- a/include/items.php +++ b/include/items.php @@ -1340,6 +1340,12 @@ function get_atom_elements($feed,$item,&$author) { $res['body'] = str_replace(array(' ',"\t","\r","\n"), array('','','',''),$res['body']); // make sure nobody is trying to sneak some html tags by us $res['body'] = notags(base64url_decode($res['body'])); + + // We could probably turn these old Friendica bbcode bookmarks into bookmark tags but we'd have to + // create a term table item for them. For now just make sure they stay as links. + + $res['body'] = preg_replace('/\[bookmark(.*?)\](.*?)\[\/bookmark\]','[url$1]$2[/url]',$res['body']); + } @@ -2346,8 +2352,9 @@ function tag_deliver($uid,$item_id) { $item = $i[0]; - if(($item['source_xchan']) && ($item['item_flags'] & ITEM_UPLINK) && ($item['item_flags'] & ITEM_THREAD_TOP) && ($item['edited'] != $item['created'])) { - // this is an update to a post which was already processed by us and has a second delivery chain + if(($item['source_xchan']) && ($item['item_flags'] & ITEM_UPLINK) + && ($item['item_flags'] & ITEM_THREAD_TOP) && ($item['edited'] != $item['created'])) { + // this is an update (edit) to a post which was already processed by us and has a second delivery chain // Just start the second delivery chain to deliver the updated post proc_run('php','include/notifier.php','tgroup',$item['id']); return; @@ -2444,78 +2451,14 @@ function tag_deliver($uid,$item_id) { // This might be a followup (e.g. comment) by the original post author to a tagged forum // If so setup a second delivery chain - $r = null; - if( ! ($item['item_flags'] & ITEM_THREAD_TOP)) { $x = q("select * from item where id = parent and parent = %d and uid = %d limit 1", intval($item['parent']), intval($uid) ); - if(($x) && ($x[0]['item_flags'] & ITEM_UPLINK)) { - - logger('tag_deliver: creating second delivery chain for comment to tagged post.'); - - // now change this copy of the post to a forum head message and deliver to all the tgroup members - // also reset all the privacy bits to the forum default permissions - - $private = (($u[0]['channel_allow_cid'] || $u[0]['channel_allow_gid'] || $u[0]['channel_deny_cid'] || $u[0]['channel_deny_gid']) ? 1 : 0); - - $new_public_policy = map_scope($u[0]['channel_r_stream'],true); - - if((! $private) && $new_public_policy) - $private = 1; - - $flag_bits = $item['item_flags'] | ITEM_WALL|ITEM_ORIGIN; - - // maintain the original source, which will be the original item owner and was stored in source_xchan - // when we created the delivery fork - - $r = q("update item set source_xchan = '%s' where id = %d limit 1", - dbesc($x[0]['source_xchan']), - intval($item_id) - ); - - $title = $item['title']; - $body = $item['body']; - - if($private) { - if(!($flag_bits & ITEM_OBSCURED)) { - $key = get_config('system','pubkey'); - $flag_bits = $flag_bits|ITEM_OBSCURED; - $title = json_encode(aes_encapsulate($title,$key)); - $body = json_encode(aes_encapsulate($body,$key)); - } - } - else { - if($flag_bits & ITEM_OBSCURED) { - $key = get_config('system','prvkey'); - $flag_bits = $flag_bits ^ ITEM_OBSCURED; - $title = json_encode(aes_unencapsulate($title,$key)); - $body = json_encode(aes_unencapsulate($body,$key)); - } - } - - $r = q("update item set item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', - deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s' where id = %d limit 1", - intval($flag_bits), - dbesc($u[0]['channel_hash']), - dbesc($u[0]['channel_allow_cid']), - dbesc($u[0]['channel_allow_gid']), - dbesc($u[0]['channel_deny_cid']), - dbesc($u[0]['channel_deny_gid']), - intval($private), - dbesc($new_public_policy), - dbesc(map_scope($u[0]['channel_w_comment'])), - dbesc($title), - dbesc($body), - intval($item_id) - ); - if($r) - proc_run('php','include/notifier.php','tgroup',$item_id); - else - logger('tag_deliver: failed to update item'); + start_delivery_chain($u[0],$item,$item_id,$x[0]); } } @@ -2549,8 +2492,6 @@ function tag_deliver($uid,$item_id) { intval($item_id) ); - - // At this point we've determined that the person receiving this post was mentioned in it or it is a union. // Now let's check if this mention was inside a reshare so we don't spam a forum // If it's private we may have to unobscure it momentarily so that we can parse it. @@ -2622,81 +2563,20 @@ function tag_deliver($uid,$item_id) { return; } - // tgroup delivery - setup a second delivery chain // prevent delivery looping - only proceed // if the message originated elsewhere and is a top-level post - if(($item['item_flags'] & ITEM_WALL) || ($item['item_flags'] & ITEM_ORIGIN) || (!($item['item_flags'] & ITEM_THREAD_TOP)) || ($item['id'] != $item['parent'])) { + if(($item['item_flags'] & ITEM_WALL) + || ($item['item_flags'] & ITEM_ORIGIN) + || (!($item['item_flags'] & ITEM_THREAD_TOP)) + || ($item['id'] != $item['parent'])) { logger('tag_deliver: item was local or a comment. rejected.'); return; } - /** - * At this point we're committed to setting up a second delivery chain. We just have to mangle some bits first. - */ - logger('tag_deliver: creating second delivery chain.'); - - // now change this copy of the post to a forum head message and deliver to all the tgroup members - // also reset all the privacy bits to the forum default permissions - - $private = (($u[0]['channel_allow_cid'] || $u[0]['channel_allow_gid'] || $u[0]['channel_deny_cid'] || $u[0]['channel_deny_gid']) ? 1 : 0); - - $new_public_policy = map_scope($u[0]['channel_r_stream'],true); - - if((! $private) && $new_public_policy) - $private = 1; - - $flag_bits = $item['item_flags'] | ITEM_WALL|ITEM_ORIGIN|ITEM_UPLINK; - - // preserve the source - - $r = q("update item set source_xchan = owner_xchan where id = %d limit 1", - intval($item_id) - ); - - // make sure encryption matches the new scope - - $title = $item['title']; - $body = $item['body']; - - if($private) { - if(!($flag_bits & ITEM_OBSCURED)) { - $key = get_config('system','pubkey'); - $flag_bits = $flag_bits|ITEM_OBSCURED; - $title = json_encode(aes_encapsulate($title,$key)); - $body = json_encode(aes_encapsulate($body,$key)); - } - } - else { - if($flag_bits & ITEM_OBSCURED) { - $key = get_config('system','prvkey'); - $flag_bits = $flag_bits ^ ITEM_OBSCURED; - $title = json_encode(aes_unencapsulate($title,$key)); - $body = json_encode(aes_unencapsulate($body,$key)); - } - } - - $r = q("update item set item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', - deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s' where id = %d limit 1", - intval($flag_bits), - dbesc($u[0]['channel_hash']), - dbesc($u[0]['channel_allow_cid']), - dbesc($u[0]['channel_allow_gid']), - dbesc($u[0]['channel_deny_cid']), - dbesc($u[0]['channel_deny_gid']), - intval($private), - dbesc($new_public_policy), - dbesc(map_scope($u[0]['channel_w_comment'])), - dbesc($title), - dbesc($body), - intval($item_id) - ); - if($r) - proc_run('php','include/notifier.php','tgroup',$item_id); - else - logger('tag_deliver: failed to update item'); + start_delivery_chain($u[0],$item,$item_id,null); } @@ -2780,6 +2660,90 @@ function tgroup_check($uid,$item) { } +/** + * Sourced and tag-delivered posts are re-targetted for delivery to the connections of the channel + * receiving the post. This starts the second delivery chain, by resetting permissions and ensuring + * that ITEM_UPLINK is set on the parent post, and storing the current owner_xchan as the source_xchan. + * We'll become the new owner. If called without $parent, this *is* the parent post. + */ + +function start_delivery_chain($channel,$item,$item_id,$parent) { + + + // Change this copy of the post to a forum head message and deliver to all the tgroup members + // also reset all the privacy bits to the forum default permissions + + $private = (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] + || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 1 : 0); + + $new_public_policy = map_scope($channel['channel_r_stream'],true); + + if((! $private) && $new_public_policy) + $private = 1; + + $flag_bits = $item['item_flags'] | ITEM_WALL|ITEM_ORIGIN; + + // maintain the original source, which will be the original item owner and was stored in source_xchan + // when we created the delivery fork + + if($parent) { + $r = q("update item set source_xchan = '%s' where id = %d limit 1", + dbesc($parent['source_xchan']), + intval($item_id) + ); + } + else { + $flag_bits = $flag_bits | ITEM_UPLINK; + $r = q("update item set source_xchan = owner_xchan where id = %d limit 1", + intval($item_id) + ); + } + + $title = $item['title']; + $body = $item['body']; + + if($private) { + if(!($flag_bits & ITEM_OBSCURED)) { + $key = get_config('system','pubkey'); + $flag_bits = $flag_bits|ITEM_OBSCURED; + $title = json_encode(aes_encapsulate($title,$key)); + $body = json_encode(aes_encapsulate($body,$key)); + } + } + else { + if($flag_bits & ITEM_OBSCURED) { + $key = get_config('system','prvkey'); + $flag_bits = $flag_bits ^ ITEM_OBSCURED; + $title = json_encode(aes_unencapsulate($title,$key)); + $body = json_encode(aes_unencapsulate($body,$key)); + } + } + + $r = q("update item set item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', + deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s' where id = %d limit 1", + intval($flag_bits), + dbesc($channel['channel_hash']), + dbesc($channel['channel_allow_cid']), + dbesc($channel['channel_allow_gid']), + dbesc($channel['channel_deny_cid']), + dbesc($channel['channel_deny_gid']), + intval($private), + dbesc($new_public_policy), + dbesc(map_scope($channel['channel_w_comment'])), + dbesc($title), + dbesc($body), + intval($item_id) + ); + + if($r) + proc_run('php','include/notifier.php','tgroup',$item_id); + else + logger('start_delivery_chain: failed to update item'); + + return; +} + + /** * @function check_item_source($uid,$item) -- cgit v1.2.3 From 831714f0f0e5bd9a17c760a2476a12603be5d089 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 21 Aug 2014 16:46:24 -0700 Subject: profile edit - missing visibility and drop link on non-default profiles, re-arrange order of replacing red#matrix smilie so it works correctly, accept a post with body content of '0' which was interpreted by x() as nothing (was treated as integer). --- include/items.php | 8 ++++---- include/text.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index fbe67817d..783c67752 100755 --- a/include/items.php +++ b/include/items.php @@ -1664,8 +1664,8 @@ function item_store($arr,$allow_exec = false) { } - $arr['title'] = ((x($arr,'title')) ? trim($arr['title']) : ''); - $arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : ''); + $arr['title'] = ((array_key_exists('title',$arr) && strlen($arr['title'])) ? trim($arr['title']) : ''); + $arr['body'] = ((array_key_exists('body',$arr) && strlen($arr['body'])) ? trim($arr['body']) : ''); $arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : ''); $arr['allow_gid'] = ((x($arr,'allow_gid')) ? trim($arr['allow_gid']) : ''); @@ -2136,7 +2136,6 @@ function item_store_update($arr,$allow_exec = false) { $arr['commented'] = $orig[0]['commented']; $arr['received'] = datetime_convert(); $arr['changed'] = datetime_convert(); - $arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : ''); $arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : $orig[0]['location']); $arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : $orig[0]['coord']); $arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : $orig[0]['verb']); @@ -2152,7 +2151,8 @@ function item_store_update($arr,$allow_exec = false) { $arr['deny_gid'] = ((array_key_exists('deny_gid',$arr)) ? trim($arr['deny_gid']) : $orig[0]['deny_gid']); $arr['item_private'] = ((array_key_exists('item_private',$arr)) ? intval($arr['item_private']) : $orig[0]['item_private']); - $arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : ''); + $arr['title'] = ((array_key_exists('title',$arr) && strlen($arr['title'])) ? trim($arr['title']) : ''); + $arr['body'] = ((array_key_exists('body',$arr) && strlen($arr['body'])) ? trim($arr['body']) : ''); $arr['attach'] = ((x($arr,'attach')) ? notags(trim($arr['attach'])) : $orig[0]['attach']); $arr['app'] = ((x($arr,'app')) ? notags(trim($arr['app'])) : $orig[0]['app']); // $arr['item_restrict'] = ((x($arr,'item_restrict')) ? intval($arr['item_restrict']) : $orig[0]['item_restrict'] ); diff --git a/include/text.php b/include/text.php index 680e6fe95..d3d8b84a6 100755 --- a/include/text.php +++ b/include/text.php @@ -1002,9 +1002,9 @@ function smilies($s, $sample = false) { ':facepalm', ':like', ':dislike', + 'red#matrix', 'red#', - 'r#', - 'red#matrix' + 'r#' ); $icons = array( @@ -1040,9 +1040,9 @@ function smilies($s, $sample = false) { ':facepalm', ':like', ':dislike', + 'redred#matrixmatrix', 'redred#matrix', - 'redr#matrix', - 'redred#matrixmatrix' + 'redr#matrix' ); -- cgit v1.2.3 From 921799b045c376c2ffe80a0c4fe0dc6c2c78e854 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 21 Aug 2014 17:42:19 -0700 Subject: make the old personal xrd interface (old webfinger) work again --- include/crypto.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/crypto.php b/include/crypto.php index c053dfae2..07655e24f 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -1,5 +1,8 @@ Date: Thu, 21 Aug 2014 20:31:55 -0700 Subject: the rest of the diaspora local discovery stuff --- include/identity.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/identity.php b/include/identity.php index 9335673a0..8b742f53e 100644 --- a/include/identity.php +++ b/include/identity.php @@ -770,9 +770,26 @@ logger('online: ' . $profile['online']); $location = $pdesc = $gender = $marital = $homepage = $online = False; } - $firstname = ((strpos($profile['name'],' ')) - ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']); - $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'],strlen($firstname)))); + $firstname = ((strpos($profile['channel_name'],' ')) + ? trim(substr($profile['channel_name'],0,strpos($profile['channel_name'],' '))) : $profile['channel_name']); + $lastname = (($firstname === $profile['channel_name']) ? '' : trim(substr($profile['channel_name'],strlen($firstname)))); + + if(get_config('system','diaspora_enabled')) { + $diaspora = array( + 'podloc' => z_root(), + 'searchable' => (($block) ? 'false' : 'true'), + 'nickname' => $profile['channel_address'], + 'fullname' => $profile['channel_name'], + 'firstname' => $firstname, + 'lastname' => $lastname, + 'photo300' => z_root() . '/photo/profile/300/' . $profile['uid'] . '.jpg', + 'photo100' => z_root() . '/photo/profile/100/' . $profile['uid'] . '.jpg', + 'photo50' => z_root() . '/photo/profile/50/' . $profile['uid'] . '.jpg', + ); + } + else + $diaspora = null; + $contact_block = contact_block(); @@ -802,6 +819,7 @@ logger('online: ' . $profile['online']); '$marital' => $marital, '$homepage' => $homepage, '$chanmenu' => $channel_menu, + '$diaspora' => $diaspora, '$contact_block' => $contact_block, )); -- cgit v1.2.3 From 69d3e5468d970633412cbdc731a4e477181dbc8c Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 21 Aug 2014 21:07:32 -0700 Subject: provide the site blacklist everywhere it is needed --- include/diaspora.php | 26 ++++++++++++++++++++++++++ include/externals.php | 2 +- include/zot.php | 16 ++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index dda552536..2010b1494 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -106,6 +106,26 @@ function diaspora_dispatch($importer,$msg,$attempt=1) { return $ret; } + +function diaspora_is_blacklisted($s) { + + $bl1 = get_config('system','blacklisted_sites'); + if(is_array($bl1) && $bl1) { + foreach($bl1 as $bl) { + if($bl && strpos($s,$bl) !== false) { + logger('diaspora_is_blacklisted: blacklisted ' . $s); + return true; + } + } + } + return false; +} + + + + + + function diaspora_handle_from_contact($contact_id) { $handle = false; @@ -122,6 +142,10 @@ function diaspora_handle_from_contact($contact_id) { } function diaspora_get_contact_by_handle($uid,$handle) { + + if(diaspora_is_blacklisted($handle)) + return false; + $r = q("SELECT * FROM abook left join xchan on xchan_hash = abook_xchan where xchan_addr = '%s' and abook_channel = %d limit 1", dbesc($handle), intval($uid) @@ -140,6 +164,8 @@ function find_diaspora_person_by_handle($handle) { $endlessloop = 0; $maxloops = 10; + if(diaspora_is_blacklisted($handle)) + return false; $r = q("select * from xchan where xchan_addr = '%s' limit 1", dbesc($handle) diff --git a/include/externals.php b/include/externals.php index a96bf7c97..8944524b7 100644 --- a/include/externals.php +++ b/include/externals.php @@ -41,7 +41,7 @@ function externals_run($argv, $argc){ $bl1 = get_config('system','blacklisted_sites'); if(is_array($bl1) && $bl1) { foreach($bl1 as $bl) { - if(strpos($url,$bl) !== false) { + if($bl && strpos($url,$bl) !== false) { $blacklisted = true; break; } diff --git a/include/zot.php b/include/zot.php index 8b0efe09d..41d0bc1eb 100644 --- a/include/zot.php +++ b/include/zot.php @@ -507,6 +507,22 @@ function zot_refresh($them,$channel = null, $force = false) { function zot_gethub($arr) { if($arr['guid'] && $arr['guid_sig'] && $arr['url'] && $arr['url_sig']) { + + $blacklisted = false; + $bl1 = get_config('system','blacklisted_sites'); + if(is_array($bl1) && $bl1) { + foreach($bl1 as $bl) { + if($bl && strpos($arr['url'],$bl) !== false) { + $blacklisted = true; + break; + } + } + } + if($blacklisted) { + logger('zot_gethub: blacklisted site: ' . $arr['url']); + return null; + } + $r = q("select * from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' -- cgit v1.2.3 From 1abd2a2917504d102a6e4c6a9c34fa4a5fba4937 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 21 Aug 2014 22:28:09 -0700 Subject: another round of heavy lifting --- include/diaspora.php | 211 ++++++++++++++++++++++++--------------------------- 1 file changed, 99 insertions(+), 112 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 2010b1494..982e40f2f 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -126,19 +126,17 @@ function diaspora_is_blacklisted($s) { -function diaspora_handle_from_contact($contact_id) { - $handle = false; +function diaspora_handle_from_contact($contact_hash) { - logger("diaspora_handle_from_contact: contact id is " . $contact_id, LOGGER_DEBUG); + logger("diaspora_handle_from_contact: contact id is " . $contact_hash, LOGGER_DEBUG); - $r = q("SELECT * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d", - intval($contact_id) + $r = q("SELECT * from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' limit 1", + intval($contact_hash) ); if($r) { - $contact = $r[0]; + return $r[0]['xchan_addr']; } - $handle = $contact['xchan_addr']; - return $handle; + return false; } function diaspora_get_contact_by_handle($uid,$handle) { @@ -150,9 +148,7 @@ function diaspora_get_contact_by_handle($uid,$handle) { dbesc($handle), intval($uid) ); - if($r) - return $r[0]; - return false; + return (($r) ? $r[0] : false); } function find_diaspora_person_by_handle($handle) { @@ -188,6 +184,7 @@ function find_diaspora_person_by_handle($handle) { $result = discover_by_webbie($handle); + } @@ -195,13 +192,10 @@ function find_diaspora_person_by_handle($handle) { } -function get_diaspora_key($uri) { - logger('Fetching diaspora key for: ' . $uri); - - $r = find_diaspora_person_by_handle($uri); - if($r) - return $r['pubkey']; - return ''; +function get_diaspora_key($handle) { + logger('Fetching diaspora key for: ' . $handle, LOGGER_DEBUG); + $r = find_diaspora_person_by_handle($handle); + return(($r) ? $r['xchan_pubkey'] : ''); } @@ -376,7 +370,7 @@ function diaspora_decode($importer,$xml) { $ciphertext = base64_decode($encrypted_header->ciphertext); $outer_key_bundle = ''; - openssl_private_decrypt($encrypted_aes_key_bundle,$outer_key_bundle,$importer['prvkey']); + openssl_private_decrypt($encrypted_aes_key_bundle,$outer_key_bundle,$importer['channel_prvkey']); $j_outer_key_bundle = json_decode($outer_key_bundle); @@ -454,7 +448,6 @@ function diaspora_decode($importer,$xml) { $encoding = $base->encoding; $alg = $base->alg; - $signed_data = $data . '.' . base64url_encode($type) . '.' . base64url_encode($encoding) . '.' . base64url_encode($alg); @@ -606,15 +599,14 @@ function diaspora_request($importer,$xml) { return; } -//FIXME -// $g = q("select def_gid from user where uid = %d limit 1", -// intval($importer['channel_id']) -// ); -// if($g && intval($g[0]['def_gid'])) { -// require_once('include/group.php'); -// group_add_member($importer['channel_id'],'',$contact_record['id'],$g[0]['def_gid']); -// } + /** If there is a default group for this channel, add this member to it */ + if($importer['channel_default_group']) { + require_once('include/group.php'); + $g = group_rec_byhash($importer['channel_id'],$importer['channel_default_group']); + if($g) + group_add_member($importer['channel_id'],'',$contact_record['xchan_hash'],$g['id']); + } return; } @@ -706,9 +698,6 @@ function diaspora_post($importer,$xml,$msg) { $datarray['uid'] = $importer['channel_id']; // FIXME - $datarray['contact-id'] = $contact['id']; - $datarray['wall'] = 0; - $datarray['network'] = NETWORK_DIASPORA; $datarray['verb'] = ACTIVITY_POST; @@ -717,7 +706,6 @@ function diaspora_post($importer,$xml,$msg) { $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); $datarray['item_private'] = $private; - $datarray['plink'] = $plink; $datarray['author_xchan'] = $contact['xchan_hash']; @@ -2055,8 +2043,8 @@ function diaspora_profile($importer,$xml,$msg) { function diaspora_share($me,$contact) { $a = get_app(); - $myaddr = $me['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); - $theiraddr = $contact['addr']; + $myaddr = $me['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + $theiraddr = $contact['xchan_addr']; $tpl = get_markup_template('diaspora_share.tpl'); $msg = replace_macros($tpl, array( @@ -2093,8 +2081,8 @@ function diaspora_unshare($me,$contact) { function diaspora_send_status($item,$owner,$contact,$public_batch = false) { $a = get_app(); - $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); - $theiraddr = $contact['addr']; + $myaddr = $owner['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + $theiraddr = $contact['xchan_addr']; $images = array(); @@ -2146,44 +2134,44 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { } - $public = (($item['private']) ? 'false' : 'true'); + $public = (($item['item_private']) ? 'false' : 'true'); require_once('include/datetime.php'); $created = datetime_convert('UTC','UTC',$item['created'],'Y-m-d H:i:s \U\T\C'); // Detect a share element and do a reshare // see: https://github.com/Raven24/diaspora-federation/blob/master/lib/diaspora-federation/entities/reshare.rb - if (!$item['private'] AND ($ret = diaspora_is_reshare($item["body"]))) { + if (!$item['item_private'] AND ($ret = diaspora_is_reshare($item["body"]))) { $tpl = get_markup_template('diaspora_reshare.tpl'); $msg = replace_macros($tpl, array( '$root_handle' => xmlify($ret['root_handle']), '$root_guid' => $ret['root_guid'], - '$guid' => $item['guid'], + '$guid' => $item['mid'], '$handle' => xmlify($myaddr), '$public' => $public, '$created' => $created, - '$provider' => $item["app"] + '$provider' => $item['app'] )); } else { $tpl = get_markup_template('diaspora_post.tpl'); $msg = replace_macros($tpl, array( '$body' => $body, - '$guid' => $item['guid'], + '$guid' => $item['mid'], '$handle' => xmlify($myaddr), '$public' => $public, '$created' => $created, - '$provider' => $item["app"] + '$provider' => $item['app'] )); } - logger('diaspora_send_status: '.$owner['username'].' -> '.$contact['name'].' base message: '.$msg, LOGGER_DATA); + logger('diaspora_send_status: '.$owner['channel_name'].' -> '.$contact['xchan_name'].' base message: '.$msg, LOGGER_DATA); - $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch))); + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch))); //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); $return_code = diaspora_transmit($owner,$contact,$slap,$public_batch); - logger('diaspora_send_status: guid: '.$item['guid'].' result '.$return_code, LOGGER_DEBUG); + logger('diaspora_send_status: guid: '.$item['mid'].' result '.$return_code, LOGGER_DEBUG); if(count($images)) { diaspora_send_images($item,$owner,$contact,$images,$public_batch); @@ -2193,51 +2181,52 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { } function diaspora_is_reshare($body) { + $body = trim($body); - // Skip if it isn't a pure repeated messages - // Does it start with a share? - if (strpos($body, "[share") > 0) - return(false); + // Skip if it isn't a pure repeated messages + // Does it start with a share? + if(strpos($body, "[share") > 0) + return(false); - // Does it end with a share? - if (strlen($body) > (strrpos($body, "[/share]") + 8)) - return(false); + // Does it end with a share? + if(strlen($body) > (strrpos($body, "[/share]") + 8)) + return(false); - $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body); - // Skip if there is no shared message in there - if ($body == $attributes) - return(false); + $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body); + // Skip if there is no shared message in there + if ($body == $attributes) + return(false); - $profile = ""; - preg_match("/profile='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; + $profile = ""; + preg_match("/profile='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; - preg_match('/profile="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; + preg_match('/profile="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $profile = $matches[1]; - $ret= array(); + $ret= array(); - $ret["root_handle"] = preg_replace("=https?://(.*)/u/(.*)=ism", "$2@$1", $profile); - if (($ret["root_handle"] == $profile) OR ($ret["root_handle"] == "")) - return(false); + $ret["root_handle"] = preg_replace("=https?://(.*)/u/(.*)=ism", "$2@$1", $profile); + if (($ret["root_handle"] == $profile) OR ($ret["root_handle"] == "")) + return(false); - $link = ""; - preg_match("/link='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $link = $matches[1]; + $link = ""; + preg_match("/link='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $link = $matches[1]; - preg_match('/link="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $link = $matches[1]; + preg_match('/link="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $link = $matches[1]; - $ret["root_guid"] = preg_replace("=https?://(.*)/posts/(.*)=ism", "$2", $link); - if (($ret["root_guid"] == $link) OR ($ret["root_guid"] == "")) - return(false); + $ret["root_guid"] = preg_replace("=https?://(.*)/posts/(.*)=ism", "$2", $link); + if (($ret["root_guid"] == $link) OR ($ret["root_guid"] == "")) + return(false); - return($ret); + return($ret); } function diaspora_send_images($item,$owner,$contact,$images,$public_batch = false) { @@ -2253,18 +2242,18 @@ function diaspora_send_images($item,$owner,$contact,$images,$public_batch = fals $resource = str_replace('.jpg','',$image['file']); $resource = substr($resource,0,strpos($resource,'-')); - $r = q("select * from photo where `resource-id` = '%s' and `uid` = %d limit 1", + $r = q("select * from photo where `resource_id` = '%s' and `uid` = %d limit 1", dbesc($resource), intval($owner['uid']) ); - if(! count($r)) + if(! $r) continue; $public = (($r[0]['allow_cid'] || $r[0]['allow_gid'] || $r[0]['deny_cid'] || $r[0]['deny_gid']) ? 'false' : 'true' ); $msg = replace_macros($tpl,array( '$path' => xmlify($image['path']), '$filename' => xmlify($image['file']), '$msg_guid' => xmlify($image['guid']), - '$guid' => xmlify($r[0]['guid']), + '$guid' => xmlify($r[0]['resource_id']), '$handle' => xmlify($image['handle']), '$public' => xmlify($public), '$created_at' => xmlify(datetime_convert('UTC','UTC',$r[0]['created'],'Y-m-d H:i:s \U\T\C')) @@ -2272,7 +2261,7 @@ function diaspora_send_images($item,$owner,$contact,$images,$public_batch = fals logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA); - $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch))); + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch))); //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); diaspora_transmit($owner,$contact,$slap,$public_batch); @@ -2283,27 +2272,27 @@ 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['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); -// $theiraddr = $contact['addr']; + $myaddr = $owner['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + $theiraddr = $contact['xchan_addr']; // Diaspora doesn't support threaded comments, but some // versions of Diaspora (i.e. Diaspora-pistos) support // likes on comments - if($item['verb'] === ACTIVITY_LIKE && $item['thr-parent']) { - $p = q("select guid, type, uri, `parent-uri` from item where uri = '%s' limit 1", - dbesc($item['thr-parent']) - ); + if($item['verb'] === ACTIVITY_LIKE && $item['thr_parent']) { + $p = q("select mid, parent_mid from item where mid = '%s' limit 1", + dbesc($item['thr_parent']) + ); } else { // 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, type, uri, `parent-uri` from item where parent = %d and id = %d limit 1", + $p = q("select * from item where parent = %d and id = %d limit 1", intval($item['parent']), intval($item['parent']) ); } - if(count($p)) + if($p) $parent = $p[0]; else return; @@ -2311,12 +2300,10 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) { if($item['verb'] === ACTIVITY_LIKE) { $tpl = get_markup_template('diaspora_like.tpl'); $like = true; - $target_type = ( $parent['uri'] === $parent['parent-uri'] ? 'Post' : 'Comment'); -// $target_type = (strpos($parent['type'], 'comment') ? 'Comment' : 'Post'); -// $positive = (($item['deleted']) ? 'false' : 'true'); + $target_type = ( $parent['mid'] === $parent['parent_mid'] ? 'Post' : 'Comment'); $positive = 'true'; - if(($item['deleted'])) + if(($item_['item_restrict'] & ITEM_DELETED)) logger('diaspora_send_followup: received deleted "like". Those should go to diaspora_send_retraction'); } else { @@ -2329,15 +2316,15 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) { // sign it if($like) - $signed_text = $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $positive . ';' . $myaddr; + $signed_text = $item['mid'] . ';' . $target_type . ';' . $parent['mid'] . ';' . $positive . ';' . $myaddr; else - $signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $myaddr; + $signed_text = $item['mid'] . ';' . $parent['mid'] . ';' . $text . ';' . $myaddr; - $authorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256')); + $authorsig = base64_encode(rsa_sign($signed_text,$owner['channel_prvkey'],'sha256')); $msg = replace_macros($tpl,array( - '$guid' => xmlify($item['guid']), - '$parent_guid' => xmlify($parent['guid']), + '$guid' => xmlify($item['mid']), + '$parent_guid' => xmlify($parent['mid']), '$target_type' =>xmlify($target_type), '$authorsig' => xmlify($authorsig), '$body' => xmlify($text), @@ -2347,8 +2334,8 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) { logger('diaspora_followup: base message: ' . $msg, LOGGER_DATA); - $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch))); - //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch))); + return(diaspora_transmit($owner,$contact,$slap,$public_batch)); } @@ -2358,7 +2345,7 @@ function diaspora_send_relay($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'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); // $theiraddr = $contact['addr']; $body = $item['body']; @@ -2367,21 +2354,21 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { // Diaspora doesn't support threaded comments, but some // versions of Diaspora (i.e. Diaspora-pistos) support // likes on comments - if($item['verb'] === ACTIVITY_LIKE && $item['thr-parent']) { - $p = q("select guid, type, uri, `parent-uri` from item where uri = '%s' limit 1", - dbesc($item['thr-parent']) - ); + if($item['verb'] === ACTIVITY_LIKE && $item['thr_parent']) { + $p = q("select * from item where mid = '%s' limit 1", + dbesc($item['thr_parent']) + ); } else { // 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, type, uri, `parent-uri` from item where parent = %d and id = %d limit 1", + $p = q("select * from item where parent = %d and id = %d limit 1", intval($item['parent']), intval($item['parent']) ); } - if(count($p)) + if($p) $parent = $p[0]; else return; @@ -2389,7 +2376,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $like = false; $relay_retract = false; $sql_sign_id = 'iid'; - if( $item['deleted']) { + if( $item['item_restrict'] & ITEM_DELETED) { $relay_retract = true; $target_type = ( ($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment'); @@ -2400,8 +2387,8 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { elseif($item['verb'] === ACTIVITY_LIKE) { $like = true; - $target_type = ( $parent['uri'] === $parent['parent-uri'] ? 'Post' : 'Comment'); -// $positive = (($item['deleted']) ? 'false' : 'true'); + $target_type = ( $parent['mid'] === $parent['parent_mid'] ? 'Post' : 'Comment'); +// $positive = (($item['item_restrict'] & ITEM_DELETED) ? 'false' : 'true'); $positive = 'true'; $tpl = get_markup_template('diaspora_like_relay.tpl'); @@ -2445,7 +2432,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { * been done yet */ - $handle = diaspora_handle_from_contact($item['contact-id']); + $handle = diaspora_handle_from_contact($item['author_xchan']); if(! $handle) return; -- cgit v1.2.3 From 2dc705d9a04df4b5d5415a42ddd2cb86c99222e8 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 22 Aug 2014 15:51:48 -0700 Subject: issue #571 - use feed/nickname?top=1 --- include/items.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 783c67752..c0bc0ef83 100755 --- a/include/items.php +++ b/include/items.php @@ -400,6 +400,7 @@ function get_public_feed($channel,$params) { $params['records'] = ((x($params,'records')) ? $params['records'] : 40); $params['direction'] = ((x($params,'direction')) ? $params['direction'] : 'desc'); $params['pages'] = ((x($params,'pages')) ? intval($params['pages']) : 0); + $params['top'] = ((x($params,'top')) ? intval($params['top']) : 0); switch($params['type']) { case 'json': @@ -440,7 +441,8 @@ function get_feed_for($channel, $observer_hash, $params) { 'records' => $params['records'], // FIXME 'direction' => $params['direction'], // FIXME 'pages' => $params['pages'], - 'order' => 'post' + 'order' => 'post', + 'top' => $params['top'] ), $channel, $observer_hash, CLIENT_MODE_NORMAL, get_app()->module); @@ -4186,6 +4188,9 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C $parents_str = ids_to_querystr($r,'item_id'); + if($arr['top']) + $sql_extra = ' and id = parent ' . $sql_extra; + $items = q("SELECT item.*, item.id AS item_id FROM item WHERE $item_uids $item_restrict AND item.parent IN ( %s ) -- cgit v1.2.3 From 38f931618c779a0e10fb2549af8f35ac1c700268 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 22 Aug 2014 17:34:18 -0700 Subject: "false" issue --- include/items.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index c0bc0ef83..12e00ddc9 100755 --- a/include/items.php +++ b/include/items.php @@ -2672,6 +2672,7 @@ function tgroup_check($uid,$item) { function start_delivery_chain($channel,$item,$item_id,$parent) { + // Change this copy of the post to a forum head message and deliver to all the tgroup members // also reset all the privacy bits to the forum default permissions @@ -2708,16 +2709,20 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { if(!($flag_bits & ITEM_OBSCURED)) { $key = get_config('system','pubkey'); $flag_bits = $flag_bits|ITEM_OBSCURED; - $title = json_encode(aes_encapsulate($title,$key)); - $body = json_encode(aes_encapsulate($body,$key)); + if($title) + $title = json_encode(aes_encapsulate($title,$key)); + if($body) + $body = json_encode(aes_encapsulate($body,$key)); } } else { if($flag_bits & ITEM_OBSCURED) { $key = get_config('system','prvkey'); $flag_bits = $flag_bits ^ ITEM_OBSCURED; - $title = json_encode(aes_unencapsulate($title,$key)); - $body = json_encode(aes_unencapsulate($body,$key)); + if($title) + $title = crypto_unencapsulate(json_decode($title,true),$key); + if($body) + $body = crypto_unencapsulate(json_decode($body,true),$key); } } -- cgit v1.2.3 From 255ab8e9c9b86c7d38e03eb0d4913a823086366d Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 22 Aug 2014 18:01:21 -0700 Subject: issue #573 - this may not fix everything in that issue but should resolve some of it. --- include/items.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index 12e00ddc9..1f2b33579 100755 --- a/include/items.php +++ b/include/items.php @@ -296,6 +296,9 @@ function post_activity_item($arr) { return $ret; } + $arr['public_policy'] = ((x($_REQUEST,'public_policy')) ? escape_tags($_REQUEST['public_policy']) : map_scope($channel['channel_r_stream'],true)); + if($arr['public_policy']) + $arr['item_private'] = 1; if(! array_key_exists('mimetype',$arr)) $arr['mimetype'] = 'text/bbcode'; -- cgit v1.2.3 From 9196c9eef091e7f4a41fbc9452521d6ca2de55a3 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 22 Aug 2014 21:37:08 -0700 Subject: We really can't do this without a hubloc. I was hoping we could, but notifier is setup to take hublocs, not xchans. --- include/notifier.php | 2 +- include/zot.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/notifier.php b/include/notifier.php index 9d5c7cb8e..180a538bc 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -382,7 +382,7 @@ function notifier_run($argv, $argc){ $env_recips = (($private) ? array() : null); - $details = q("select xchan_hash, xchan_instance_url, xchan_addr, xchan_guid, xchan_guid_sig from xchan where xchan_hash in (" . implode(',',$recipients) . ")"); + $details = q("select xchan_hash, xchan_instance_url, xchan_network, xchan_addr, xchan_guid, xchan_guid_sig from xchan where xchan_hash in (" . implode(',',$recipients) . ")"); $recip_list = array(); diff --git a/include/zot.php b/include/zot.php index 41d0bc1eb..a155b2588 100644 --- a/include/zot.php +++ b/include/zot.php @@ -959,12 +959,13 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) { ); } logger('import_xchan: new hub: ' . $location['url']); - $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_flags, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_updated, hubloc_connected) - values ( '%s','%s','%s','%s', %d ,'%s','%s','%s','%s','%s','%s','%s')", + $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_flags, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_updated, hubloc_connected) + values ( '%s','%s','%s','%s', '%s', %d ,'%s','%s','%s','%s','%s','%s','%s')", dbesc($arr['guid']), dbesc($arr['guid_sig']), dbesc($xchan_hash), dbesc($location['address']), + dbesc('zot'), intval((intval($location['primary'])) ? HUBLOC_FLAGS_PRIMARY : 0), dbesc($location['url']), dbesc($location['url_sig']), -- cgit v1.2.3 From 5d2dc4e8fdb62785cf306496c7cdcefb31d4a0ed Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 23 Aug 2014 02:45:21 -0700 Subject: switch everything over to crypto_encapsulate() --- include/items.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 1f2b33579..bdf4007af 100755 --- a/include/items.php +++ b/include/items.php @@ -318,9 +318,9 @@ function post_activity_item($arr) { $key = get_config('system','pubkey'); $arr['item_flags'] = $arr['item_flags'] | ITEM_OBSCURED; if($arr['title']) - $arr['title'] = json_encode(aes_encapsulate($arr['title'],$key)); + $arr['title'] = json_encode(crypto_encapsulate($arr['title'],$key)); if($arr['body']) - $arr['body'] = json_encode(aes_encapsulate($arr['body'],$key)); + $arr['body'] = json_encode(crypto_encapsulate($arr['body'],$key)); } $arr['mid'] = ((x($arr,'mid')) ? $arr['mid'] : item_message_id()); @@ -2713,9 +2713,9 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { $key = get_config('system','pubkey'); $flag_bits = $flag_bits|ITEM_OBSCURED; if($title) - $title = json_encode(aes_encapsulate($title,$key)); + $title = json_encode(crypto_encapsulate($title,$key)); if($body) - $body = json_encode(aes_encapsulate($body,$key)); + $body = json_encode(crypto_encapsulate($body,$key)); } } else { -- cgit v1.2.3 From 56e8b2b9714336059d3b19a28ab0593c22068b0b Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 23 Aug 2014 15:22:26 -0700 Subject: add "any connections" to can_comment_on_post() - was missing --- include/items.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index bdf4007af..f10a5c570 100755 --- a/include/items.php +++ b/include/items.php @@ -132,6 +132,7 @@ function can_comment_on_post($observer_xchan,$item) { // false. return false; break; + case 'any connections': case 'contacts': case '': if(array_key_exists('owner',$item)) { -- cgit v1.2.3 From 5cba2096043cc16083da346f321834a0ef8a3f54 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 24 Aug 2014 04:27:10 -0700 Subject: diaspora discovery --- include/network.php | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'include') diff --git a/include/network.php b/include/network.php index 614049299..e06f4f80a 100644 --- a/include/network.php +++ b/include/network.php @@ -820,6 +820,7 @@ function email_send($addr, $subject, $headers, $item) { function discover_by_webbie($webbie) { + require_once('library/HTML5/Parser.php'); $x = webfinger_rfc7033($webbie); if($x && array_key_exists('links',$x) && $x['links']) { @@ -836,9 +837,121 @@ function discover_by_webbie($webbie) { } } + $result = array(); + $network = null; + $diaspora = false; + + $diaspora_base = ''; + $diaspora_guid = ''; + $diaspora_key = ''; + $dfrn = false; + $x = old_webfinger($webbie); if($x) { logger('old_webfinger: ' . print_r($x,true)); + foreach($x as $link) { + if($link['@attributes']['rel'] === NAMESPACE_DFRN) + $dfrn = unamp($link['@attributes']['href']); + if($link['@attributes']['rel'] === 'salmon') + $notify = unamp($link['@attributes']['href']); + if($link['@attributes']['rel'] === NAMESPACE_FEED) + $poll = unamp($link['@attributes']['href']); + if($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') + $hcard = unamp($link['@attributes']['href']); + if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') + $profile = unamp($link['@attributes']['href']); + if($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0') + $poco = unamp($link['@attributes']['href']); + if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') { + $diaspora_base = unamp($link['@attributes']['href']); + $diaspora = true; + } + if($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') { + $diaspora_guid = unamp($link['@attributes']['href']); + $diaspora = true; + } + if($link['@attributes']['rel'] === 'diaspora-public-key') { + $diaspora_key = base64_decode(unamp($link['@attributes']['href'])); + if(strstr($diaspora_key,'RSA ')) + $pubkey = rsatopem($diaspora_key); + else + $pubkey = $diaspora_key; + $diaspora = true; + } + } + + if($diaspora && $diaspora_base && $diaspora_guid) { + $notify = $diaspora_base . 'receive/users/' . $diaspora_guid; + $batch = $diaspora_base . 'receive/public' ; + if(strpos($webbie,'@')) + $addr = str_replace('acct:', '', $webbie); + $network = 'diaspora'; + if($dfrn) + $network = 'f-diaspora'; + if($hcard) + $vcard = scrape_vcard($hcard); + } + + $vcard['fn'] = notags($vcard['fn']); + $vcard['nick'] = str_replace(' ','',notags($vcard['nick'])); + + $result['name'] = $vcard['fn']; + $result['nick'] = $vcard['nick']; + $result['url'] = $profile; + $result['addr'] = $addr; + $result['batch'] = $batch; + $result['notify'] = $notify; + $result['poll'] = $poll; + $result['request'] = $request; + $result['confirm'] = $confirm; + $result['poco'] = $poco; + $result['photo'] = $vcard['photo']; + $result['priority'] = $priority; + $result['network'] = $network; + $result['alias'] = $alias; + $result['pubkey'] = $pubkey; + + logger('probe_url: ' . print_r($result,true), LOGGER_DEBUG); + + return $result; +/* +Array +( + [name] => Mike Macgirvin + [nick] => MikeMacgirvin + [url] => https://joindiaspora.com/u/macgirvin + [addr] => macgirvin@joindiaspora.com + [batch] => https://joindiaspora.com/receive/public + [notify] => https://joindiaspora.com/receive/users/a9174a618f8d269a + [poll] => https://joindiaspora.com/public/macgirvin.atom + [request] => + [confirm] => + [poco] => + [photo] => https://joindiaspora.s3.amazonaws.com/uploads/images/thumb_large_fec4e6eef13ae5e56207.jpg + [priority] => + [network] => diaspora + [alias] => + [pubkey] => -----BEGIN PUBLIC KEY----- +MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAtihtyIuRDWkDpCA+I1UaQ +jI4S7k625+A7EEJm+pL2ZVSJxeCKiFeEgHBQENjLMNNm8l8F6blxgQqE6ZJ9Spa7f +tlaXYTRCrfxKzh02L3hR7sNA+JS/nXJaUAIo+IwpIEspmcIRbD9GB7Wv/rr+M28uH +31EeYyDz8QL6InU/bJmnCdFvmEMBQxJOw1ih9tQp7UNJAbUMCje0WYFzBz7sfcaHL +OyYcCOqOCBLdGucUoJzTQ9iDBVzB8j1r1JkIHoEb2moUoKUp+tkCylNfd/3IVELF9 +7w1Qjmit3m50OrJk2DQOXvCW9KQxaQNdpRPSwhvemIt98zXSeyZ1q/YjjOwG0DWDq +AF8aLj3/oQaZndTPy/6tMiZogKaijoxj8xFLuPYDTw5VpKquriVC0z8oxyRbv4t9v +8JZZ9BXqzmayvY3xZGGp8NulrfjW+me2bKh0/df1aHaBwpZdDTXQ6kqAiS2FfsuPN +vg57fhfHbL1yJ4oDbNNNeI0kJTGchXqerr8C20khU/cQ2Xt31VyEZtnTB665Ceugv +kp3t2qd8UpAVKl430S5Quqx2ymfUIdxdW08CEjnoRNEL3aOWOXfbf4gSVaXmPCR4i +LSIeXnd14lQYK/uxW/8cTFjcmddsKxeXysoQxbSa9VdDK+KkpZdgYXYrTTofXs6v+ +4afAEhRaaY+MCAwEAAQ== +-----END PUBLIC KEY----- + +) +*/ + + + + } } -- cgit v1.2.3 From d57c57ad59f311aa8d1488a6985874bae7beae38 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 24 Aug 2014 05:26:00 -0700 Subject: onepoll: don't poll archived, blocked, or ignored connections --- include/onepoll.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/onepoll.php b/include/onepoll.php index e81d8bcf7..947e936ac 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -35,10 +35,12 @@ function onepoll_run($argv, $argc){ FROM abook LEFT JOIN account on abook_account = account_id left join xchan on xchan_hash = abook_xchan where abook_id = %d AND (( abook_flags & %d ) OR ( abook_flags = %d )) + AND NOT ( abook_flags & %d ) AND (( account_flags = %d ) OR ( account_flags = %d )) limit 1", intval($contact_id), intval(ABOOK_FLAG_HIDDEN|ABOOK_FLAG_PENDING|ABOOK_FLAG_UNCONNECTED), intval(0), + intval(ABOOK_FLAG_ARCHIVED|ABOOK_FLAG_BLOCKED|ABOOK_FLAG_IGNORED), intval(ACCOUNT_OK), intval(ACCOUNT_UNVERIFIED) ); -- cgit v1.2.3 From e0ee66d0b40247e05d4cbc1ca7687b74b1bc88d9 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 24 Aug 2014 17:52:26 -0700 Subject: Add d* folks to address book. WARNING - DO NOT ATTEMPT THIS. LEAVE IT THE FRUCK ALONE until the feature is stable. I won't help you if you try this and end up with a borked site. You are completely on your own. --- include/follow.php | 17 +- include/network.php | 656 +++++++++++++++++++++++++++++----------------------- 2 files changed, 378 insertions(+), 295 deletions(-) (limited to 'include') diff --git a/include/follow.php b/include/follow.php index d98a58198..55249db2b 100644 --- a/include/follow.php +++ b/include/follow.php @@ -117,14 +117,25 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) } else { - // attempt network auto-discovery - $my_perms = 0; $their_perms = 0; $xchan_hash = ''; - + $r = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($url) + ); + if(! $r) { + // attempt network auto-discovery + if(strpos($url,'@')) { + $r = discover_by_webbie($url); + } + } + if($r) { + $xchan_hash = $url; + $their_perms = 0; + $my_perms = PERMS_W_STREAM|PERMS_W_MAIL; + } } diff --git a/include/network.php b/include/network.php index e06f4f80a..83a3ea4d0 100644 --- a/include/network.php +++ b/include/network.php @@ -280,7 +280,7 @@ function xml_status($st, $message = '') { function http_status_exit($val,$msg = '') { - $err = ''; + $err = ''; if($val >= 400) $msg = (($msg) ? $msg : 'Error'); if($val >= 200 && $val < 300) @@ -298,43 +298,43 @@ function http_status_exit($val,$msg = '') { function convert_xml_element_to_array($xml_element, &$recursion_depth=0) { - // If we're getting too deep, bail out - if ($recursion_depth > 512) { - return(null); - } - - if (!is_string($xml_element) && - !is_array($xml_element) && - (get_class($xml_element) == 'SimpleXMLElement')) { - $xml_element_copy = $xml_element; - $xml_element = get_object_vars($xml_element); - } - - if (is_array($xml_element)) { - $result_array = array(); - if (count($xml_element) <= 0) { - return (trim(strval($xml_element_copy))); - } - - foreach($xml_element as $key=>$value) { - - $recursion_depth++; - $result_array[strtolower($key)] = - convert_xml_element_to_array($value, $recursion_depth); - $recursion_depth--; - } - if ($recursion_depth == 0) { - $temp_array = $result_array; - $result_array = array( - strtolower($xml_element_copy->getName()) => $temp_array, - ); - } - - return ($result_array); - - } else { - return (trim(strval($xml_element))); - } + // If we're getting too deep, bail out + if ($recursion_depth > 512) { + return(null); + } + + if (!is_string($xml_element) && + !is_array($xml_element) && + (get_class($xml_element) == 'SimpleXMLElement')) { + $xml_element_copy = $xml_element; + $xml_element = get_object_vars($xml_element); + } + + if (is_array($xml_element)) { + $result_array = array(); + if (count($xml_element) <= 0) { + return (trim(strval($xml_element_copy))); + } + + foreach($xml_element as $key=>$value) { + + $recursion_depth++; + $result_array[strtolower($key)] = + convert_xml_element_to_array($value, $recursion_depth); + $recursion_depth--; + } + if ($recursion_depth == 0) { + $temp_array = $result_array; + $result_array = array( + strtolower($xml_element_copy->getName()) => $temp_array, + ); + } + + return ($result_array); + + } else { + return (trim(strval($xml_element))); + } } // Take a URL from the wild, prepend http:// if necessary @@ -584,35 +584,35 @@ function scale_external_images($s, $include_link = true, $scale_replace = false) */ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = 'attribute') { - if(!$contents) return array(); + if(!$contents) return array(); - if(!function_exists('xml_parser_create')) { - logger('xml2array: parser function missing'); - return array(); - } + if(!function_exists('xml_parser_create')) { + logger('xml2array: parser function missing'); + return array(); + } libxml_use_internal_errors(true); libxml_clear_errors(); if($namespaces) - $parser = @xml_parser_create_ns("UTF-8",':'); + $parser = @xml_parser_create_ns("UTF-8",':'); else - $parser = @xml_parser_create(); + $parser = @xml_parser_create(); if(! $parser) { logger('xml2array: xml_parser_create: no resource'); return array(); } - xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); + xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); // http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); - xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); - @xml_parse_into_struct($parser, trim($contents), $xml_values); - @xml_parser_free($parser); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); + xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); + @xml_parse_into_struct($parser, trim($contents), $xml_values); + @xml_parser_free($parser); - if(! $xml_values) { + if(! $xml_values) { logger('xml2array: libxml: parse error: ' . $contents, LOGGER_DATA); foreach(libxml_get_errors() as $err) logger('libxml: parse: ' . $err->code . " at " . $err->line . ":" . $err->column . " : " . $err->message, LOGGER_DATA); @@ -620,40 +620,40 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = return; } - //Initializations - $xml_array = array(); - $parents = array(); - $opened_tags = array(); - $arr = array(); - - $current = &$xml_array; // Reference - - // Go through the tags. - $repeated_tag_index = array(); // Multiple tags with same name will be turned into an array - foreach($xml_values as $data) { - unset($attributes,$value); // Remove existing values, or there will be trouble - - // This command will extract these variables into the foreach scope - // tag(string), type(string), level(int), attributes(array). - extract($data); // We could use the array by itself, but this cooler. - - $result = array(); - $attributes_data = array(); - - if(isset($value)) { - if($priority == 'tag') $result = $value; - else $result['value'] = $value; // Put the value in a assoc array if we are in the 'Attribute' mode - } - - //Set the attributes too. - if(isset($attributes) and $get_attributes) { - foreach($attributes as $attr => $val) { - if($priority == 'tag') $attributes_data[$attr] = $val; - else $result['@attributes'][$attr] = $val; // Set all the attributes in a array called 'attr' - } - } - - // See tag status and do the needed. + //Initializations + $xml_array = array(); + $parents = array(); + $opened_tags = array(); + $arr = array(); + + $current = &$xml_array; // Reference + + // Go through the tags. + $repeated_tag_index = array(); // Multiple tags with same name will be turned into an array + foreach($xml_values as $data) { + unset($attributes,$value); // Remove existing values, or there will be trouble + + // This command will extract these variables into the foreach scope + // tag(string), type(string), level(int), attributes(array). + extract($data); // We could use the array by itself, but this cooler. + + $result = array(); + $attributes_data = array(); + + if(isset($value)) { + if($priority == 'tag') $result = $value; + else $result['value'] = $value; // Put the value in a assoc array if we are in the 'Attribute' mode + } + + //Set the attributes too. + if(isset($attributes) and $get_attributes) { + foreach($attributes as $attr => $val) { + if($priority == 'tag') $attributes_data[$attr] = $val; + else $result['@attributes'][$attr] = $val; // Set all the attributes in a array called 'attr' + } + } + + // See tag status and do the needed. if($namespaces && strpos($tag,':')) { $namespc = substr($tag,0,strrpos($tag,':')); $tag = strtolower(substr($tag,strlen($namespc)+1)); @@ -662,80 +662,80 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority = $tag = strtolower($tag); if($type == "open") { // The starting of the tag '' - $parent[$level-1] = &$current; - if(!is_array($current) or (!in_array($tag, array_keys($current)))) { // Insert New tag - $current[$tag] = $result; - if($attributes_data) $current[$tag. '_attr'] = $attributes_data; - $repeated_tag_index[$tag.'_'.$level] = 1; - - $current = &$current[$tag]; - - } else { // There was another element with the same tag name - - if(isset($current[$tag][0])) { // If there is a 0th element it is already an array - $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; - $repeated_tag_index[$tag.'_'.$level]++; - } else { // This section will make the value an array if multiple tags with the same name appear together - $current[$tag] = array($current[$tag],$result); // This will combine the existing item and the new item together to make an array - $repeated_tag_index[$tag.'_'.$level] = 2; - - if(isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well - $current[$tag]['0_attr'] = $current[$tag.'_attr']; - unset($current[$tag.'_attr']); - } - - } - $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1; - $current = &$current[$tag][$last_item_index]; - } - - } elseif($type == "complete") { // Tags that ends in 1 line '' - //See if the key is already taken. - if(!isset($current[$tag])) { //New Key - $current[$tag] = $result; - $repeated_tag_index[$tag.'_'.$level] = 1; - if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data; - - } else { // If taken, put all things inside a list(array) - if(isset($current[$tag][0]) and is_array($current[$tag])) { // If it is already an array... - - // ...push the new element into that array. - $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; - - if($priority == 'tag' and $get_attributes and $attributes_data) { - $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; - } - $repeated_tag_index[$tag.'_'.$level]++; - - } else { // If it is not an array... - $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value - $repeated_tag_index[$tag.'_'.$level] = 1; - if($priority == 'tag' and $get_attributes) { - if(isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well - - $current[$tag]['0_attr'] = $current[$tag.'_attr']; - unset($current[$tag.'_attr']); - } - - if($attributes_data) { - $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; - } - } - $repeated_tag_index[$tag.'_'.$level]++; // 0 and 1 indexes are already taken - } - } - - } elseif($type == 'close') { // End of tag '' - $current = &$parent[$level-1]; - } - } - - return($xml_array); + $parent[$level-1] = &$current; + if(!is_array($current) or (!in_array($tag, array_keys($current)))) { // Insert New tag + $current[$tag] = $result; + if($attributes_data) $current[$tag. '_attr'] = $attributes_data; + $repeated_tag_index[$tag.'_'.$level] = 1; + + $current = &$current[$tag]; + + } else { // There was another element with the same tag name + + if(isset($current[$tag][0])) { // If there is a 0th element it is already an array + $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; + $repeated_tag_index[$tag.'_'.$level]++; + } else { // This section will make the value an array if multiple tags with the same name appear together + $current[$tag] = array($current[$tag],$result); // This will combine the existing item and the new item together to make an array + $repeated_tag_index[$tag.'_'.$level] = 2; + + if(isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well + $current[$tag]['0_attr'] = $current[$tag.'_attr']; + unset($current[$tag.'_attr']); + } + + } + $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1; + $current = &$current[$tag][$last_item_index]; + } + + } elseif($type == "complete") { // Tags that ends in 1 line '' + //See if the key is already taken. + if(!isset($current[$tag])) { //New Key + $current[$tag] = $result; + $repeated_tag_index[$tag.'_'.$level] = 1; + if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data; + + } else { // If taken, put all things inside a list(array) + if(isset($current[$tag][0]) and is_array($current[$tag])) { // If it is already an array... + + // ...push the new element into that array. + $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; + + if($priority == 'tag' and $get_attributes and $attributes_data) { + $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; + } + $repeated_tag_index[$tag.'_'.$level]++; + + } else { // If it is not an array... + $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value + $repeated_tag_index[$tag.'_'.$level] = 1; + if($priority == 'tag' and $get_attributes) { + if(isset($current[$tag.'_attr'])) { // The attribute of the last(0th) tag must be moved as well + + $current[$tag]['0_attr'] = $current[$tag.'_attr']; + unset($current[$tag.'_attr']); + } + + if($attributes_data) { + $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; + } + } + $repeated_tag_index[$tag.'_'.$level]++; // 0 and 1 indexes are already taken + } + } + + } elseif($type == 'close') { // End of tag '' + $current = &$parent[$level-1]; + } + } + + return($xml_array); } function email_header_encode($in_str, $charset = 'UTF-8') { - $out_str = $in_str; + $out_str = $in_str; $need_to_convert = false; for($x = 0; $x < strlen($in_str); $x ++) { @@ -747,42 +747,42 @@ function email_header_encode($in_str, $charset = 'UTF-8') { if(! $need_to_convert) return $in_str; - if ($out_str && $charset) { - - // define start delimimter, end delimiter and spacer - $end = "?="; - $start = "=?" . $charset . "?B?"; - $spacer = $end . "\r\n " . $start; - - // determine length of encoded text within chunks - // and ensure length is even - $length = 75 - strlen($start) - strlen($end); - - /* - [EDIT BY danbrown AT php DOT net: The following - is a bugfix provided by (gardan AT gmx DOT de) - on 31-MAR-2005 with the following note: - "This means: $length should not be even, - but divisible by 4. The reason is that in - base64-encoding 3 8-bit-chars are represented - by 4 6-bit-chars. These 4 chars must not be - split between two encoded words, according - to RFC-2047. - */ - $length = $length - ($length % 4); - - // encode the string and split it into chunks - // with spacers after each chunk - $out_str = base64_encode($out_str); - $out_str = chunk_split($out_str, $length, $spacer); - - // remove trailing spacer and - // add start and end delimiters - $spacer = preg_quote($spacer,'/'); - $out_str = preg_replace("/" . $spacer . "$/", "", $out_str); - $out_str = $start . $out_str . $end; - } - return $out_str; + if ($out_str && $charset) { + + // define start delimimter, end delimiter and spacer + $end = "?="; + $start = "=?" . $charset . "?B?"; + $spacer = $end . "\r\n " . $start; + + // determine length of encoded text within chunks + // and ensure length is even + $length = 75 - strlen($start) - strlen($end); + + /* + [EDIT BY danbrown AT php DOT net: The following + is a bugfix provided by (gardan AT gmx DOT de) + on 31-MAR-2005 with the following note: + "This means: $length should not be even, + but divisible by 4. The reason is that in + base64-encoding 3 8-bit-chars are represented + by 4 6-bit-chars. These 4 chars must not be + split between two encoded words, according + to RFC-2047. + */ + $length = $length - ($length % 4); + + // encode the string and split it into chunks + // with spacers after each chunk + $out_str = base64_encode($out_str); + $out_str = chunk_split($out_str, $length, $spacer); + + // remove trailing spacer and + // add start and end delimiters + $spacer = preg_quote($spacer,'/'); + $out_str = preg_replace("/" . $spacer . "$/", "", $out_str); + $out_str = $start . $out_str . $end; + } + return $out_str; } function email_send($addr, $subject, $headers, $item) { @@ -793,7 +793,7 @@ function email_send($addr, $subject, $headers, $item) { $part = uniqid("", true); - $html = prepare_body($item); + $html = prepare_body($item); $headers .= "Mime-Version: 1.0\n"; $headers .= 'Content-Type: multipart/alternative; boundary="=_'.$part.'"'."\n\n"; @@ -822,11 +822,13 @@ function email_send($addr, $subject, $headers, $item) { function discover_by_webbie($webbie) { require_once('library/HTML5/Parser.php'); + $webbie = strtolower($webbie); + $x = webfinger_rfc7033($webbie); if($x && array_key_exists('links',$x) && $x['links']) { foreach($x['links'] as $link) { if(array_key_exists('rel',$link) && $link['rel'] == 'http://purl.org/zot/protocol') { - logger('discover_by_webbie: zot found for ' . $webbie); + logger('discover_by_webbie: zot found for ' . $webbie, LOGGER_DEBUG); $z = z_fetch_url($link['href']); if($z['success']) { $j = json_decode($z['body'],true); @@ -838,12 +840,12 @@ function discover_by_webbie($webbie) { } $result = array(); - $network = null; - $diaspora = false; + $network = null; + $diaspora = false; - $diaspora_base = ''; - $diaspora_guid = ''; - $diaspora_key = ''; + $diaspora_base = ''; + $diaspora_guid = ''; + $diaspora_key = ''; $dfrn = false; $x = old_webfinger($webbie); @@ -881,48 +883,118 @@ function discover_by_webbie($webbie) { } if($diaspora && $diaspora_base && $diaspora_guid) { - $notify = $diaspora_base . 'receive/users/' . $diaspora_guid; - $batch = $diaspora_base . 'receive/public' ; - if(strpos($webbie,'@')) - $addr = str_replace('acct:', '', $webbie); + $guid = $diaspora_guid; + $diaspora_base = trim($diaspora_base,'/'); + + $notify = $diaspora_base . '/receive'; + +// // '/users/' . $diaspora_guid; +// $batch = $diaspora_base . '/receive/public' ; + if(strpos($webbie,'@')) { + $addr = str_replace('acct:', '', $webbie); + $hostname = substr($webbie,strpos($webbie,'@')+1); + } $network = 'diaspora'; + // until we get a dfrn layer, we'll use diaspora protocols for Friendica, + // but give it a different network so we can go back and fix these when we get proper support. + // It really should be just 'friendica' but we also want to distinguish + // between Friendica sites that we can use D* protocols with and those we can't. + // Some Friendica sites will have Diaspora disabled. if($dfrn) - $network = 'f-diaspora'; - if($hcard) + $network = 'friendica-over-diaspora'; + if($hcard) { $vcard = scrape_vcard($hcard); + $vcard['nick'] = substr($webbie,0,strpos($webbie,'@')); + } + + $r = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($webbie) + ); + if($r) + return true; + + $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_pubkey, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_instance_url, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", + dbesc($addr), + dbesc($guid), + dbesc($pubkey), + dbesc($addr), + dbesc($profile), + dbesc($vcard['fn']), + dbesc($network), + dbesc(z_root()), + dbesc(datetime_convert()) + ); + + $r = q("select * from hubloc where hubloc_hash = '%s' limit 1", + dbesc($webbie) + ); + if(! $r) { + $r = q("insert into hubloc ( hubloc_guid, hubloc_hash, hubloc_addr, hubloc_network, hubloc_url, hubloc_host, hubloc_callback, hubloc_updated ) values ('%s','%s','%s','%s','%s','%s','%s','%s')", + dbesc($guid), + dbesc($addr), + dbesc($addr), + dbesc($network), + dbesc(trim($diaspora_base,'/')), + dbesc($hostname), + dbesc($notify), + dbesc(datetime_convert()) + ); + } + $photos = import_profile_photo($vcard['photo'],$addr); + $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s' limit 1", + dbesc(datetime_convert('UTC','UTC',$arr['photo_updated'])), + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc($photos[3]), + dbesc($addr) + ); + return true; + } - $vcard['fn'] = notags($vcard['fn']); - $vcard['nick'] = str_replace(' ','',notags($vcard['nick'])); - - $result['name'] = $vcard['fn']; - $result['nick'] = $vcard['nick']; - $result['url'] = $profile; - $result['addr'] = $addr; - $result['batch'] = $batch; - $result['notify'] = $notify; - $result['poll'] = $poll; - $result['request'] = $request; - $result['confirm'] = $confirm; - $result['poco'] = $poco; - $result['photo'] = $vcard['photo']; - $result['priority'] = $priority; - $result['network'] = $network; - $result['alias'] = $alias; - $result['pubkey'] = $pubkey; - - logger('probe_url: ' . print_r($result,true), LOGGER_DEBUG); - - return $result; + return false; + /* + $vcard['fn'] = notags($vcard['fn']); + $vcard['nick'] = str_replace(' ','',notags($vcard['nick'])); + + $result['name'] = $vcard['fn']; + $result['nick'] = $vcard['nick']; + $result['guid'] = $guid; + $result['url'] = $profile; + $result['hostname'] = $hostname; + $result['addr'] = $addr; + $result['batch'] = $batch; + $result['notify'] = $notify; + $result['poll'] = $poll; + $result['request'] = $request; + $result['confirm'] = $confirm; + $result['poco'] = $poco; + $result['photo'] = $vcard['photo']; + $result['priority'] = $priority; + $result['network'] = $network; + $result['alias'] = $alias; + $result['pubkey'] = $pubkey; + + logger('probe_url: ' . print_r($result,true), LOGGER_DEBUG); + + return $result; + +*/ + +/* Sample Diaspora result. + Array ( [name] => Mike Macgirvin - [nick] => MikeMacgirvin + [nick] => macgirvin + [guid] => a9174a618f8d269a [url] => https://joindiaspora.com/u/macgirvin + [hostname] => joindiaspora.com [addr] => macgirvin@joindiaspora.com - [batch] => https://joindiaspora.com/receive/public - [notify] => https://joindiaspora.com/receive/users/a9174a618f8d269a + [batch] => + [notify] => https://joindiaspora.com/receive [poll] => https://joindiaspora.com/public/macgirvin.atom [request] => [confirm] => @@ -996,33 +1068,33 @@ function old_webfinger($webbie) { $links = fetch_xrd_links($pxrd); } return $links; - } + } } - return array(); + return array(); } function fetch_lrdd_template($host) { - $tpl = ''; - - $url1 = 'https://' . $host . '/.well-known/host-meta' ; - $url2 = 'http://' . $host . '/.well-known/host-meta' ; - $links = fetch_xrd_links($url1); - logger('fetch_lrdd_template from: ' . $url1, LOGGER_DEBUG); - logger('template (https): ' . print_r($links,true),LOGGER_DEBUG); - if(! count($links)) { - logger('fetch_lrdd_template from: ' . $url2); - $links = fetch_xrd_links($url2); - logger('template (http): ' . print_r($links,true),LOGGER_DEBUG); - } - if(count($links)) { - foreach($links as $link) - if($link['@attributes']['rel'] && $link['@attributes']['rel'] === 'lrdd' && (!$link['@attributes']['type'] || $link['@attributes']['type'] === 'application/xrd+xml')) - $tpl = $link['@attributes']['template']; - } - if(! strpos($tpl,'{uri}')) - $tpl = ''; - return $tpl; + $tpl = ''; + + $url1 = 'https://' . $host . '/.well-known/host-meta' ; + $url2 = 'http://' . $host . '/.well-known/host-meta' ; + $links = fetch_xrd_links($url1); + logger('fetch_lrdd_template from: ' . $url1, LOGGER_DEBUG); + logger('template (https): ' . print_r($links,true),LOGGER_DEBUG); + if(! count($links)) { + logger('fetch_lrdd_template from: ' . $url2); + $links = fetch_xrd_links($url2); + logger('template (http): ' . print_r($links,true),LOGGER_DEBUG); + } + if(count($links)) { + foreach($links as $link) + if($link['@attributes']['rel'] && $link['@attributes']['rel'] === 'lrdd' && (!$link['@attributes']['type'] || $link['@attributes']['type'] === 'application/xrd+xml')) + $tpl = $link['@attributes']['template']; + } + if(! strpos($tpl,'{uri}')) + $tpl = ''; + return $tpl; } @@ -1032,52 +1104,52 @@ function fetch_xrd_links($url) { logger('fetch_xrd_links: ' . $url); $redirects = 0; - $x = z_fetch_url($url,false,$redirects,array('timeout' => 20)); + $x = z_fetch_url($url,false,$redirects,array('timeout' => 20)); if(! $x['success']) return array(); $xml = $x['body']; - logger('fetch_xrd_links: ' . $xml, LOGGER_DATA); - - if ((! $xml) || (! stristr($xml,''),array('href="','"/>'),$xml); - - $h = parse_xml_string($xml); - if(! $h) - return array(); - - $arr = convert_xml_element_to_array($h); - - $links = array(); - - if(isset($arr['xrd']['link'])) { - $link = $arr['xrd']['link']; - - if(! isset($link[0])) - $links = array($link); - else - $links = $link; - } - if(isset($arr['xrd']['alias'])) { - $alias = $arr['xrd']['alias']; - if(! isset($alias[0])) - $aliases = array($alias); - else - $aliases = $alias; - if(is_array($aliases) && count($aliases)) { - foreach($aliases as $alias) { - $links[]['@attributes'] = array('rel' => 'alias' , 'href' => $alias); - } - } - } - - logger('fetch_xrd_links: ' . print_r($links,true), LOGGER_DATA); - - return $links; + logger('fetch_xrd_links: ' . $xml, LOGGER_DATA); + + if ((! $xml) || (! stristr($xml,''),array('href="','"/>'),$xml); + + $h = parse_xml_string($xml); + if(! $h) + return array(); + + $arr = convert_xml_element_to_array($h); + + $links = array(); + + if(isset($arr['xrd']['link'])) { + $link = $arr['xrd']['link']; + + if(! isset($link[0])) + $links = array($link); + else + $links = $link; + } + if(isset($arr['xrd']['alias'])) { + $alias = $arr['xrd']['alias']; + if(! isset($alias[0])) + $aliases = array($alias); + else + $aliases = $alias; + if(is_array($aliases) && count($aliases)) { + foreach($aliases as $alias) { + $links[]['@attributes'] = array('rel' => 'alias' , 'href' => $alias); + } + } + } + + logger('fetch_xrd_links: ' . print_r($links,true), LOGGER_DATA); + + return $links; } -- cgit v1.2.3 From 86fb165dc98e096c71cd94ccfccea29283e42f4b Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 25 Aug 2014 02:14:48 -0700 Subject: re-obscure item body if localize_item() changes it. It's already flagged as obscured so we need it to actually be obscured. --- include/conversation.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index daf1c723f..b14e609dd 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -262,6 +262,8 @@ function localize_item(&$item){ $item['body'] = sprintf($txt, $A, t($verb)); } + + /* // FIXME store parent item as object or target // (and update to json storage) @@ -363,6 +365,17 @@ function localize_item(&$item){ // if($sparkle) // $item['plink'] = $y . '?f=&url=' . $item['plink']; // } + + // if item body was obscured and we changed it, re-obscure it + // FIXME - we need a better filter than just the string 'data'; try and + // match the fact that it's json encoded + + if(($item['item_flags'] & ITEM_OBSCURED) + && strlen($item['body']) && (! strpos($item['body'],'data'))) { + $item['body'] = json_encode(crypto_encapsulate($item['body'],get_config('system','pubkey'))); + } + + } /** -- cgit v1.2.3 From 84ff380302764703dcc0bdf9ab5d69bac549726e Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 25 Aug 2014 20:57:10 -0700 Subject: more diaspora heavy lifting --- include/account.php | 2 +- include/diaspora.php | 235 ++++++++++++++++++++++++++++++++++++++++----------- include/notifier.php | 77 +++++++++++++---- 3 files changed, 248 insertions(+), 66 deletions(-) (limited to 'include') diff --git a/include/account.php b/include/account.php index 138db3290..4ded069d5 100644 --- a/include/account.php +++ b/include/account.php @@ -423,7 +423,7 @@ function user_deny($hash) { if(! count($register)) return false; - $account = q("SELECT account_id FROM account WHERE account_id = %d LIMIT 1", + $account = q("SELECT account_id, account_email FROM account WHERE account_id = %d LIMIT 1", intval($register[0]['uid']) ); diff --git a/include/diaspora.php b/include/diaspora.php index 982e40f2f..d93baaaa0 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -121,7 +121,129 @@ function diaspora_is_blacklisted($s) { return false; } +function diaspora_process_outbound($arr) { +/* + + We are passed the following array from the notifier, providing everything we need to make delivery decisions. + + diaspora_process_outbound(array( + 'channel' => $channel, + 'env_recips' => $env_recips, + 'recipients' => $recipients, + 'item' => $item, + 'target_item' => $target_item, + 'hub' => $hub, + 'top_level_post' => $top_level_post, + 'private' => $private, + 'followup' => $followup, + 'relay_to_owner' => $relay_to_owner, + 'uplink' => $uplink, + 'cmd' => $cmd, + 'expire' => $expire, + 'mail' => $mail, + 'fsuggest' => $fsuggest, + 'normal_mode' => $normal_mode, + 'packet_type' => $packet_type, + 'walltowall' => $walltowall, + )); +*/ + + + if($arr['walltowall']) + return; + + if($arr['recipients']) { + $r = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s' + and xchan_hash in (" . implode(',',$arr['recipients']) . ") + and xchan_network in ('diaspora', 'friendica-over-diaspora') ", + dbesc($arr['hub']['hubloc_url']) + ); + if(! $r) { + logger('diaspora_process_outbound: no recipients'); + return; + } + + foreach($r as $contact) { + + if($arr['mail']) { + diaspora_send_mail($arr['item'],$arr['channel'],$contact); + continue; + } + + if(! $arr['normal_mode']) + continue; + + // special handling for followup to public post + // all other public posts processed as public batches further below + + if((! $arr['private']) && ($arr['followup'])) { + diaspora_send_followup($arr['target_item'],$arr['channel'],$contact, true); + continue; + } + + if(! $contact['xchan_pubkey']) + continue; + + if(activity_match($arr['target_item']['verb'],ACTIVITY_DISLIKE)) { + continue; + } + elseif(($arr['target_item']['item_restrict'] & ITEM_DELETED) + && (($arr['target_item']['mid'] === $arr['target_item']['parent_mid']) || $arr['followup'])) { + // send both top-level retractions and relayable retractions for owner to relay + diaspora_send_retraction($arr['target_item'],$arr['channel'],$contact); + continue; + } + elseif($arr['followup']) { + // send comments and likes to owner to relay + diaspora_send_followup($arr['target_item'],$arr['channel'],$contact); + continue; + } + + elseif($target_item['mid'] !== $target_item['parent_mid']) { + // we are the relay - send comments, likes and relayable_retractions + // (of comments and likes) to our conversants + diaspora_send_relay($arr['target_item'],$arr['channel'],$contact); + continue; + } + elseif($arr['top_level']) { + diaspora_send_status($arr['target_item'],$arr['channel'],$contact); + continue; + } + } + } + else { + // public message + + $contact = array('hubloc_callback' => $arr['hub']['hubloc_callback']); + + if($target_item['verb'] === ACTIVITY_DISLIKE) { + // unsupported + return; + } + elseif(($arr['target_item']['deleted']) + && ($arr['target_item']['mid'] === $arr['target_item']['parent_mod'])) { + // top-level retraction + logger('delivery: diaspora retract: ' . $loc); + diaspora_send_retraction($arr['target_item'],$arr['channel'],$contact,true); + return; + } + elseif($arr['target_item']['mid'] !== $mid['target_item']['parent_mid']) { + // we are the relay - send comments, likes and relayable_retractions to our conversants + logger('delivery: diaspora relay: ' . $loc); + diaspora_send_relay($arr['target_item'],$arr['channel'],$contact,true); + return; + } + elseif(($arr['top_level_post']) && (! $arr['walltowall'])) { + // currently no workable solution for sending walltowall + logger('delivery: diaspora status: ' . $loc); + diaspora_send_status($arr['target_item'],$arr['channel'],$contact,true); + return; + } + + } + +} @@ -226,13 +348,13 @@ $magic_env = <<< EOT
- $handle + $handle
- base64url - RSA-SHA256 - $data - $sig + base64url + RSA-SHA256 + $data + $sig
EOT; @@ -323,10 +445,10 @@ $magic_env = <<< EOT $encrypted_header - base64url - RSA-SHA256 - $data - $sig + base64url + RSA-SHA256 + $data + $sig EOT; @@ -386,19 +508,19 @@ function diaspora_decode($importer,$xml) { * $decrypted now contains something like * * - * 8e+G2+ET8l5BPuW0sVTnQw== - * UvSMb4puPeB14STkcDWq+4QE302Edu15oaprAQSkLKU= + * 8e+G2+ET8l5BPuW0sVTnQw== + * UvSMb4puPeB14STkcDWq+4QE302Edu15oaprAQSkLKU= ***** OBSOLETE - * - * Ryan Hughes - * acct:galaxor@diaspora.pirateship.org - * + * + * Ryan Hughes + * acct:galaxor@diaspora.pirateship.org + * ***** CURRENT - * galaxor@diaspora.priateship.org + * galaxor@diaspora.priateship.org ***** END DIFFS @@ -576,7 +698,7 @@ function diaspora_request($importer,$xml) { if($new_connection) { require_once('include/enotify.php'); notification(array( - 'type' => NOTIFY_INTRO, + 'type' => NOTIFY_INTRO, 'from_xchan' => $ret['xchan_hash'], 'to_xchan' => $importer['channel_hash'], 'link' => z_root() . '/connedit/' . $new_connection[0]['abook_id'], @@ -585,7 +707,7 @@ function diaspora_request($importer,$xml) { if($default_perms) { // Send back a sharing notification to them diaspora_share($importer['channel_id'],$new_connection[0]); - + } } } @@ -1309,11 +1431,11 @@ function diaspora_conversation($importer,$xml,$msg) { ); if($r) $c = q("select * from conv where uid = %d and guid = '%s' limit 1", - intval($importer['channel_id']), - dbesc($guid) - ); - if(count($c)) - $conversation = $c[0]; + intval($importer['channel_id']), + dbesc($guid) + ); + if(count($c)) + $conversation = $c[0]; } if(! $conversation) { logger('diaspora_conversation: unable to create conversation.'); @@ -1578,7 +1700,7 @@ function diaspora_photo($importer,$xml,$msg,$attempt=1) { $link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n"; $link_text = scale_external_images($link_text, true, - array($remote_photo_name, 'scaled_full_' . $remote_photo_name)); + array($remote_photo_name, 'scaled_full_' . $remote_photo_name)); if(strpos($parent_item['body'],$link_text) === false) { $r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d", @@ -2044,6 +2166,18 @@ function diaspora_profile($importer,$xml,$msg) { function diaspora_share($me,$contact) { $a = get_app(); $myaddr = $me['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + + if(! array_key_exists('xchan_hash',$contact)) { + $c = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where xchan_hash = '%s' limit 1", + dbesc($contact['hubloc_hash']) + ); + if(! $c) { + logger('diaspora_share: ' . $contact['hubloc_hash'] . ' not found.'); + return; + } + $contact = $c[0]; + } + $theiraddr = $contact['xchan_addr']; $tpl = get_markup_template('diaspora_share.tpl'); @@ -2052,29 +2186,25 @@ function diaspora_share($me,$contact) { '$recipient' => $theiraddr )); - $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey']))); - //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey'])); - + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['channel_prvkey'],$contact['xchan_pubkey']))); return(diaspora_transmit($owner,$contact,$slap, false)); } function diaspora_unshare($me,$contact) { $a = get_app(); - $myaddr = $me['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + $myaddr = $me['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); $tpl = get_markup_template('diaspora_retract.tpl'); $msg = replace_macros($tpl, array( - '$guid' => $me['guid'], + '$guid' => $me['channel_guid'], '$type' => 'Person', '$handle' => $myaddr )); - $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey']))); - //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey'])); + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['channel_prvkey'],$contact['xchan_pubkey']))); return(diaspora_transmit($owner,$contact,$slap, false)); - } @@ -2082,7 +2212,6 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { $a = get_app(); $myaddr = $owner['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); - $theiraddr = $contact['xchan_addr']; $images = array(); @@ -2167,7 +2296,6 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { logger('diaspora_send_status: '.$owner['channel_name'].' -> '.$contact['xchan_name'].' base message: '.$msg, LOGGER_DATA); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch))); - //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); $return_code = diaspora_transmit($owner,$contact,$slap,$public_batch); @@ -2210,7 +2338,7 @@ function diaspora_is_reshare($body) { $ret= array(); $ret["root_handle"] = preg_replace("=https?://(.*)/u/(.*)=ism", "$2@$1", $profile); - if (($ret["root_handle"] == $profile) OR ($ret["root_handle"] == "")) + if (($ret["root_handle"] == $profile) OR ($ret["root_handle"] == "")) return(false); $link = ""; @@ -2262,7 +2390,6 @@ function diaspora_send_images($item,$owner,$contact,$images,$public_batch = fals logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch))); - //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); diaspora_transmit($owner,$contact,$slap,$public_batch); } @@ -2346,7 +2473,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); -// $theiraddr = $contact['addr']; + $body = $item['body']; $text = html_entity_decode(bb2diaspora($body)); @@ -2356,7 +2483,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { // likes on comments if($item['verb'] === ACTIVITY_LIKE && $item['thr_parent']) { $p = q("select * from item where mid = '%s' limit 1", - dbesc($item['thr_parent']) + dbesc($item['thr_parent']) ); } else { @@ -2364,9 +2491,9 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { // 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 * from item where parent = %d and id = %d limit 1", - intval($item['parent']), - intval($item['parent']) - ); + intval($item['parent']), + intval($item['parent']) + ); } if($p) $parent = $p[0]; @@ -2471,8 +2598,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { logger('diaspora_send_relay: base message: ' . $msg, LOGGER_DATA); - $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch))); - //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch))); return(diaspora_transmit($owner,$contact,$slap,$public_batch)); @@ -2506,8 +2632,7 @@ function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) { '$signature' => xmlify(base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'))) )); - $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch))); - //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)); + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch))); return(diaspora_transmit($owner,$contact,$slap,$public_batch)); } @@ -2542,7 +2667,7 @@ function diaspora_send_mail($item,$owner,$contact) { $signed_text = $item['guid'] . ';' . $cnv['guid'] . ';' . $body . ';' . $created . ';' . $myaddr . ';' . $cnv['guid']; - $sig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256')); + $sig = base64_encode(rsa_sign($signed_text,$owner['channel_prvkey'],'sha256')); $msg = array( 'guid' => xmlify($item['guid']), @@ -2567,8 +2692,7 @@ function diaspora_send_mail($item,$owner,$contact) { logger('diaspora_conversation: ' . print_r($xmsg,true), LOGGER_DATA); - $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false))); - //$slap = 'xml=' . urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false)); + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],false))); return(diaspora_transmit($owner,$contact,$slap,false)); @@ -2582,6 +2706,21 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false) return 200; } + if($public_batch) + $dest_url = $contact['hubloc_callback'] . '/public'; + else + $dest_url = $contact['hubloc_callback'] . '/users/' . $contact['guid']; + + + + if(intval(get_config('system','diaspora_test'))) + return 200; + + + +return 200; + + $a = get_app(); $logid = random_string(4); $dest_url = (($public_batch) ? $contact['batch'] : $contact['notify']); diff --git a/include/notifier.php b/include/notifier.php index 180a538bc..0a5cf3f4c 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -103,28 +103,33 @@ function notifier_run($argv, $argc){ ); if($r) { // Get the sender - $s = q("select * from channel where channel_id = %d limit 1", + $s = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1", intval($r[0]['abook_channel']) ); if($s) { - - // send a refresh message to each hub they have registered here - $h = q("select * from hubloc where hubloc_hash = '%s'", - dbesc($r[0]['hubloc_hash']) - ); - if($h) { - foreach($h as $hh) { - $data = zot_build_packet($s[0],'refresh',array(array( - 'guid' => $hh['hubloc_guid'], - 'guid_sig' => $hh['hubloc_guid_sig'], - 'url' => $hh['hubloc_url']) - )); - if($data) { - $result = zot_zot($hh['hubloc_callback'],$data); + if($r[0]['hubloc_network'] === 'diaspora' || $r[0]['hubloc_network'] === 'friendica_over_diaspora') { + require_once('include/diaspora.php'); + diaspora_share($s[0],$r[0]); + } + else { + // send a refresh message to each hub they have registered here + $h = q("select * from hubloc where hubloc_hash = '%s'", + dbesc($r[0]['hubloc_hash']) + ); + if($h) { + foreach($h as $hh) { + $data = zot_build_packet($s[0],'refresh',array(array( + 'guid' => $hh['hubloc_guid'], + 'guid_sig' => $hh['hubloc_guid_sig'], + 'url' => $hh['hubloc_url']) + )); + if($data) { + $result = zot_zot($hh['hubloc_callback'],$data); // zot_queue_item is not yet written // if(! $result['success']) // zot_queue_item(); + } } } } @@ -366,6 +371,8 @@ function notifier_run($argv, $argc){ } + $walltowall = (($top_level_post && $channel['xchan_hash'] === $target_item['author_xchan']) ? true : false); + // Generic delivery section, we have an encoded item and recipients // Now start the delivery process @@ -438,11 +445,11 @@ function notifier_run($argv, $argc){ // aren't the owner or author. - $r = q("select hubloc_sitekey, hubloc_flags, hubloc_callback, hubloc_host from hubloc + $r = q("select hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc where hubloc_hash in (" . implode(',',$recipients) . ") group by hubloc_sitekey order by hubloc_connected desc limit 1"); } else { - $r = q("select hubloc_sitekey, hubloc_flags, hubloc_callback, hubloc_host from hubloc + $r = q("select hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc where hubloc_hash in (" . implode(',',$recipients) . ") $sql_extra group by hubloc_sitekey"); } @@ -485,6 +492,42 @@ function notifier_run($argv, $argc){ } } + + if($hub['network'] === 'diaspora' || $hub['network'] === 'friendica-over-diaspora') { + if(! get_config('system','diaspora_enabled')) + continue; + + require_once('include/diaspora.php'); + + diaspora_process_outbound(array( + 'channel' => $channel, + 'env_recips' => $env_recips, + 'recipients' => $recipients, + 'item' => $item, + 'target_item' => $target_item, + 'hub' => $hub, + 'top_level_post' => $top_level_post, + 'private' => $private, + 'followup' => $followup, + 'relay_to_owner' => $relay_to_owner, + 'uplink' => $uplink, + 'cmd' => $cmd, + 'expire' => $expire, + 'mail' => $mail, + 'fsuggest' => $fsuggest, + 'normal_mode' => $normal_mode, + 'packet_type' => $packet_type, + 'walltowall' => $walltowall + )); + + continue; + + } + + + // default: zot protocol + + $hash = random_string(); if($packet_type === 'refresh' || $packet_type === 'purge') { $n = zot_build_packet($channel,$packet_type); -- cgit v1.2.3 From eb8f194419975a6cd3debba145c8769da055b8dc Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 25 Aug 2014 21:42:46 -0700 Subject: sort out some anomalies --- include/diaspora.php | 6 +++--- include/network.php | 5 +++-- include/notifier.php | 4 ++-- include/zot.php | 13 ++++++++++++- 4 files changed, 20 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index d93baaaa0..ebd1906f3 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -215,7 +215,7 @@ function diaspora_process_outbound($arr) { else { // public message - $contact = array('hubloc_callback' => $arr['hub']['hubloc_callback']); + $contact = $arr['hub']; if($target_item['verb'] === ACTIVITY_DISLIKE) { // unsupported @@ -2709,9 +2709,9 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false) if($public_batch) $dest_url = $contact['hubloc_callback'] . '/public'; else - $dest_url = $contact['hubloc_callback'] . '/users/' . $contact['guid']; + $dest_url = $contact['hubloc_callback'] . '/users/' . $contact['hubloc_guid']; - + logger('diaspora_transmit: URL: ' . $dest_url, LOGGER_DEBUG); if(intval(get_config('system','diaspora_test'))) return 200; diff --git a/include/network.php b/include/network.php index 83a3ea4d0..ff0502f5a 100644 --- a/include/network.php +++ b/include/network.php @@ -929,7 +929,7 @@ function discover_by_webbie($webbie) { dbesc($webbie) ); if(! $r) { - $r = q("insert into hubloc ( hubloc_guid, hubloc_hash, hubloc_addr, hubloc_network, hubloc_url, hubloc_host, hubloc_callback, hubloc_updated ) values ('%s','%s','%s','%s','%s','%s','%s','%s')", + $r = q("insert into hubloc ( hubloc_guid, hubloc_hash, hubloc_addr, hubloc_network, hubloc_url, hubloc_host, hubloc_callback, hubloc_updated, hubloc_flags ) values ('%s','%s','%s','%s','%s','%s','%s','%s', %d)", dbesc($guid), dbesc($addr), dbesc($addr), @@ -937,7 +937,8 @@ function discover_by_webbie($webbie) { dbesc(trim($diaspora_base,'/')), dbesc($hostname), dbesc($notify), - dbesc(datetime_convert()) + dbesc(datetime_convert()), + intval(HUBLOC_FLAGS_PRIMARY) ); } $photos = import_profile_photo($vcard['photo'],$addr); diff --git a/include/notifier.php b/include/notifier.php index 0a5cf3f4c..7c4f64ae0 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -445,11 +445,11 @@ function notifier_run($argv, $argc){ // aren't the owner or author. - $r = q("select hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc + $r = q("select hubloc_guid, hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc where hubloc_hash in (" . implode(',',$recipients) . ") group by hubloc_sitekey order by hubloc_connected desc limit 1"); } else { - $r = q("select hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc + $r = q("select hubloc_guid, hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc where hubloc_hash in (" . implode(',',$recipients) . ") $sql_extra group by hubloc_sitekey"); } diff --git a/include/zot.php b/include/zot.php index a155b2588..65c092b93 100644 --- a/include/zot.php +++ b/include/zot.php @@ -198,11 +198,17 @@ function zot_finger($webbie,$channel,$autofallback = true) { if($r) { $url = $r[0]['hubloc_url']; + + if($r[0]['hubloc_network'] && $r[0]['hubloc_network'] !== 'zot') { + logger('zot_finger: alternate network: ' . $webbie); + return array('success' => false); + } } else { $url = 'https://' . $host; } - + + $rhs = '/.well-known/zot-info'; $https = ((strpos($url,'https://') === 0) ? true : false); @@ -271,6 +277,11 @@ function zot_finger($webbie,$channel,$autofallback = true) { function zot_refresh($them,$channel = null, $force = false) { + if(array_key_exists('xchan_network',$them) && ($them['xchan_network'] !== 'zot')) { + logger('zot_refresh: not got zot. ' . $them['xchan_name']); + return true; + } + logger('zot_refresh: them: ' . print_r($them,true), LOGGER_DATA); if($channel) logger('zot_refresh: channel: ' . print_r($channel,true), LOGGER_DATA); -- cgit v1.2.3 From 6e99848043d198af5013c2439e7a2d16d8a32c52 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 25 Aug 2014 22:43:44 -0700 Subject: more diaspora stuff - most of the basic bits are there except queueing and physical delivery (I'm keeping delivery turned off until some of the bugs are fixed so we don't cause inifinite loops or network meltdowns) - now it's just a matter of going through and methodically finding all the bugs --- include/diaspora.php | 47 ++++++++++++++++++++++++++++++++++++----------- include/items.php | 1 + include/notifier.php | 2 +- 3 files changed, 38 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index ebd1906f3..1e101b4a7 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -153,9 +153,9 @@ function diaspora_process_outbound($arr) { if($arr['walltowall']) return; - if($arr['recipients']) { + if($arr['env_recips']) { $r = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s' - and xchan_hash in (" . implode(',',$arr['recipients']) . ") + and xchan_hash in (" . implode(',',$arr['env_recips']) . ") and xchan_network in ('diaspora', 'friendica-over-diaspora') ", dbesc($arr['hub']['hubloc_url']) ); @@ -228,13 +228,13 @@ function diaspora_process_outbound($arr) { diaspora_send_retraction($arr['target_item'],$arr['channel'],$contact,true); return; } - elseif($arr['target_item']['mid'] !== $mid['target_item']['parent_mid']) { + elseif($arr['target_item']['mid'] !== $arr['target_item']['parent_mid']) { // we are the relay - send comments, likes and relayable_retractions to our conversants logger('delivery: diaspora relay: ' . $loc); diaspora_send_relay($arr['target_item'],$arr['channel'],$contact,true); return; } - elseif(($arr['top_level_post']) && (! $arr['walltowall'])) { + elseif($arr['top_level_post']) { // currently no workable solution for sending walltowall logger('delivery: diaspora status: ' . $loc); diaspora_send_status($arr['target_item'],$arr['channel'],$contact,true); @@ -2241,12 +2241,38 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { } */ - //if(strlen($title)) - // $body = "[b]".html_entity_decode($title)."[/b]\n\n".$body; + + $body = str_ireplace("[quote", "\n\n[quote", $body); + $body = str_ireplace("[/quote]", "[/quote]\n\n", $body); + + // strip bookmark indicators + + $body = preg_replace('/\#\^\[([zu])rl/i', '[$1rl', $body); + $body = preg_replace('/\#\^http/i', 'http', $body); + + // protect tags and mentions from hijacking + + if(! intval(get_pconfig($owner['channel_id'],'system','allow_tag_hijacking'))) { + $new_tag = html_entity_decode('⋕',ENT_COMPAT,'UTF-8'); + $new_mention = html_entity_decode('@',ENT_COMPAT,'UTF-8'); + + // #-tags + $body = preg_replace('/\#\[url/i', $new_tag . '[url', $body); + $body = preg_replace('/\#\[zrl/i', $new_tag . '[zrl', $body); + // @-mentions + $body = preg_replace('/\@\[url/i', $new_mention . '[url', $body); + $body = preg_replace('/\@\[zrl/i', $new_mention . '[zrl', $body); + } + + // remove multiple newlines + do { + $oldbody = $body; + $body = str_replace("\n\n\n", "\n\n", $body); + } while ($oldbody != $body); + // convert to markdown $body = xmlify(html_entity_decode(bb2diaspora($body))); - //$body = bb2diaspora($body); // Adding the title if(strlen($title)) @@ -2262,7 +2288,6 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { } } - $public = (($item['item_private']) ? 'false' : 'true'); require_once('include/datetime.php'); @@ -2279,7 +2304,7 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { '$handle' => xmlify($myaddr), '$public' => $public, '$created' => $created, - '$provider' => $item['app'] + '$provider' => (($item['app']) ? $item['app'] : 'redmatrix') )); } else { $tpl = get_markup_template('diaspora_post.tpl'); @@ -2289,11 +2314,11 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { '$handle' => xmlify($myaddr), '$public' => $public, '$created' => $created, - '$provider' => $item['app'] + '$provider' => (($item['app']) ? $item['app'] : 'redmatrix') )); } - logger('diaspora_send_status: '.$owner['channel_name'].' -> '.$contact['xchan_name'].' base message: '.$msg, LOGGER_DATA); + logger('diaspora_send_status: '.$owner['channel_name'].' -> '.$contact['xchan_name'].' base message: ' . $msg, LOGGER_DATA); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch))); diff --git a/include/items.php b/include/items.php index f10a5c570..e9f11ee4a 100755 --- a/include/items.php +++ b/include/items.php @@ -95,6 +95,7 @@ function collect_recipients($item,&$private_envelope) { $recipients[] = $item['author_xchan']; if($item['owner_xchan'] != $item['author_xchan']) $recipients[] = $item['owner_xchan']; + return $recipients; } diff --git a/include/notifier.php b/include/notifier.php index 7c4f64ae0..7f4d7a9f8 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -493,7 +493,7 @@ function notifier_run($argv, $argc){ } - if($hub['network'] === 'diaspora' || $hub['network'] === 'friendica-over-diaspora') { + if($hub['hubloc_network'] === 'diaspora' || $hub['hubloc_network'] === 'friendica-over-diaspora') { if(! get_config('system','diaspora_enabled')) continue; -- cgit v1.2.3 From cc2bef67dd17ac2d9352442aeac39963470ba67f Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Tue, 26 Aug 2014 19:09:00 +0100 Subject: HTML doesn't work without ACCOUNT_ROLE_ALLOWCODE, so don't offer it as an option. --- include/text.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index d3d8b84a6..42fad13b5 100755 --- a/include/text.php +++ b/include/text.php @@ -1552,7 +1552,6 @@ function mimetype_select($channel_id, $current = 'text/bbcode') { $x = array( 'text/bbcode', - 'text/html', 'text/markdown', 'text/plain' ); @@ -1564,8 +1563,10 @@ function mimetype_select($channel_id, $current = 'text/bbcode') { if($r) { if($r[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) { - if(local_user() && get_account_id() == $r[0]['account_id']) + if(local_user() && get_account_id() == $r[0]['account_id']) { + $x[] = 'text/html'; $x[] = 'application/x-php'; + } } } -- cgit v1.2.3 From 450434a6903790aacf70864633cd3ccb57b739f0 Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Tue, 26 Aug 2014 20:13:27 +0100 Subject: Revert - see comments. --- include/text.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100755 => 100644 include/text.php (limited to 'include') diff --git a/include/text.php b/include/text.php old mode 100755 new mode 100644 index 42fad13b5..410d9bc96 --- a/include/text.php +++ b/include/text.php @@ -1552,6 +1552,7 @@ function mimetype_select($channel_id, $current = 'text/bbcode') { $x = array( 'text/bbcode', + 'text/html', 'text/markdown', 'text/plain' ); @@ -1563,10 +1564,8 @@ function mimetype_select($channel_id, $current = 'text/bbcode') { if($r) { if($r[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) { - if(local_user() && get_account_id() == $r[0]['account_id']) { - $x[] = 'text/html'; + if(local_user() && get_account_id() == $r[0]['account_id']) $x[] = 'application/x-php'; - } } } @@ -2023,3 +2022,4 @@ function normalise_openid($s) { return trim(str_replace(array('http://','https://'),array('',''),$s),'/'); } + -- cgit v1.2.3 From 289ec34ae6890a2d82071b61a12fad866be9f0d0 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Aug 2014 16:35:06 -0700 Subject: take off the kid gloves --- include/Contact.php | 14 ++++++------ include/deliver.php | 14 ++++++++++++ include/diaspora.php | 63 ++++++++++++++++------------------------------------ 3 files changed, 40 insertions(+), 51 deletions(-) (limited to 'include') diff --git a/include/Contact.php b/include/Contact.php index 140f449af..66c94ef50 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -245,12 +245,12 @@ function channel_remove($channel_id, $local = true, $unset_session=true) { intval($channel_id) ); - $r = q("update hubloc set hubloc_flags = hubloc_flags | %d where hubloc_hash = '%s'", + $r = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_hash = '%s'", intval(HUBLOC_FLAGS_DELETED), dbesc($channel['channel_hash']) ); - $r = q("update xchan set xchan_flags = xchan_flags | %d where xchan_hash = '%s'", + $r = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s'", intval(XCHAN_FLAGS_DELETED), dbesc($channel['channel_hash']) ); @@ -274,7 +274,7 @@ function channel_remove($channel_id, $local = true, $unset_session=true) { q("DELETE FROM `spam` WHERE `uid` = %d", intval($channel_id)); - q("delete from abook where abook_xchan = '%s' and abook_flags & %d limit 1", + q("delete from abook where abook_xchan = '%s' and (abook_flags & %d) limit 1", dbesc($channel['channel_hash']), dbesc(ABOOK_FLAG_SELF) ); @@ -285,13 +285,13 @@ function channel_remove($channel_id, $local = true, $unset_session=true) { intval($channel_id) ); - $r = q("update hubloc set hubloc_flags = hubloc_flags | %d where hubloc_hash = '%s' and hubloc_url = '%s' ", + $r = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_hash = '%s' and hubloc_url = '%s' ", intval(HUBLOC_FLAGS_DELETED), dbesc($channel['channel_hash']), dbesc(z_root()) ); - $r = q("update xchan set xchan_flags = xchan_flags | %d where xchan_hash = '%s' ", + $r = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s' ", intval(XCHAN_FLAGS_DELETED), dbesc($channel['channel_hash']) ); @@ -435,12 +435,12 @@ function remove_all_xchan_resources($xchan, $channel_id = 0) { // directory servers need to keep the record around for sync purposes - mark it deleted - $r = q("update hubloc set hubloc_flags = hubloc_flags | %d where hubloc_hash = '%s'", + $r = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_hash = '%s'", intval(HUBLOC_FLAGS_DELETED), dbesc($xchan) ); - $r = q("update xchan set xchan_flags = xchan_flags | %d where xchan_hash = '%s'", + $r = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s'", intval(XCHAN_FLAGS_DELETED), dbesc($xchan) ); diff --git a/include/deliver.php b/include/deliver.php index 0ad008c23..6edf3d60f 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -20,6 +20,20 @@ function deliver_run($argv, $argc) { dbesc($argv[$x]) ); if($r) { + if($r[0]['outq_driver'] === 'post') { + $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); + if($result['success'] && $result['status_code'] < 300) { + logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); + } + else { + $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", + dbesc(datetime_convert()), + dbesc($argv[$x]) + ); + } + continue; + } + if($r[0]['outq_posturl'] === z_root() . '/post') { logger('deliver: local delivery', LOGGER_DEBUG); // local delivery diff --git a/include/diaspora.php b/include/diaspora.php index 1e101b4a7..8471cfbd7 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2741,56 +2741,31 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false) if(intval(get_config('system','diaspora_test'))) return 200; - - -return 200; - - $a = get_app(); $logid = random_string(4); - $dest_url = (($public_batch) ? $contact['batch'] : $contact['notify']); - if(! $dest_url) { - logger('diaspora_transmit: no url for contact: ' . $contact['id'] . ' batch mode =' . $public_batch); - return 0; - } - - logger('diaspora_transmit: ' . $logid . ' ' . $dest_url); - if( (! $queue_run) && (was_recently_delayed($contact['id'])) ) { - $return_code = 0; - } - else { - 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; - } - } + logger('diaspora_transmit: ' . $logid . ' ' . $dest_url, LOGGER_DEBUG); - logger('diaspora_transmit: ' . $logid . ' returns: ' . $return_code); + $hash = random_string(); - if((! $return_code) || (($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after')))) { - logger('diaspora_transmit: queue message'); + $interval = ((get_config('system','delivery_interval') !== false) + ? intval(get_config('system','delivery_interval')) : 2 ); - $r = q("SELECT id from queue where cid = %d and network = '%s' and content = '%s' and batch = %d limit 1", - intval($contact['id']), - dbesc(NETWORK_DIASPORA), - dbesc($slap), - intval($public_batch) - ); - if(count($r)) { - logger('diaspora_transmit: add_to_queue ignored - identical item already in queue'); - } - else { - // queue message for redelivery - add_to_queue($contact['id'],NETWORK_DIASPORA,$slap,$public_batch); - } - } + q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", + dbesc($hash), + intval($owner['account_id']), + intval($owner['channel_id']), + dbesc('post'), + dbesc($dest_url), + intval(1), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(''), + dbesc($slap) + ); + proc_run('php','include/deliver.php',$hash); + if($interval) + @time_sleep_until(microtime(true) + (float) $interval); - return(($return_code) ? $return_code : (-1)); } - - -- cgit v1.2.3 From e42205cec25fbe7ee93fde4a0f267d54b0e30193 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Aug 2014 17:32:51 -0700 Subject: houston we have liftoff --- include/diaspora.php | 24 +++++++++++++----------- include/notifier.php | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 8471cfbd7..0d2037666 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -330,7 +330,7 @@ function diaspora_pubmsg_build($msg,$user,$contact,$prvkey,$pubkey) { $handle = $user['xchan_addr']; - $b64url_data = base64url_encode($msg); + $b64url_data = base64url_encode($msg,false); $data = str_replace(array("\n","\r"," ","\t"),array('','','',''),$b64url_data); @@ -338,11 +338,11 @@ function diaspora_pubmsg_build($msg,$user,$contact,$prvkey,$pubkey) { $encoding = 'base64url'; $alg = 'RSA-SHA256'; - $signable_data = $data . '.' . base64url_encode($type) . '.' - . base64url_encode($encoding) . '.' . base64url_encode($alg) ; + $signable_data = $data . '.' . base64url_encode($type,false) . '.' + . base64url_encode($encoding,false) . '.' . base64url_encode($alg,false) ; $signature = rsa_sign($signable_data,$prvkey); - $sig = base64url_encode($signature); + $sig = base64url_encode($signature,false); $magic_env = <<< EOT @@ -400,18 +400,20 @@ function diaspora_msg_build($msg,$user,$contact,$prvkey,$pubkey,$public = false) $b64_data = base64_encode($inner_encrypted); - $b64url_data = base64url_encode($b64_data); + $b64url_data = base64url_encode($b64_data,false); $data = str_replace(array("\n","\r"," ","\t"),array('','','',''),$b64url_data); $type = 'application/xml'; $encoding = 'base64url'; $alg = 'RSA-SHA256'; - $signable_data = $data . '.' . base64url_encode($type) . '.' - . base64url_encode($encoding) . '.' . base64url_encode($alg) ; + $signable_data = $data . '.' . base64url_encode($type,false) . '.' + . base64url_encode($encoding,false) . '.' . base64url_encode($alg,false) ; + + logger('diaspora_msg_build: signable_data: ' . $signable_data, LOGGER_DATA); $signature = rsa_sign($signable_data,$prvkey); - $sig = base64url_encode($signature); + $sig = base64url_encode($signature,false); $decrypted_header = <<< EOT @@ -570,7 +572,7 @@ function diaspora_decode($importer,$xml) { $encoding = $base->encoding; $alg = $base->alg; - $signed_data = $data . '.' . base64url_encode($type) . '.' . base64url_encode($encoding) . '.' . base64url_encode($alg); + $signed_data = $data . '.' . base64url_encode($type,false) . '.' . base64url_encode($encoding,false) . '.' . base64url_encode($alg,false); // decode the data @@ -642,7 +644,7 @@ function diaspora_request($importer,$xml) { // perhaps we were already sharing with this person. Now they're sharing with us. // That makes us friends. Maybe. - $newperms = PERMS_R_STREAM|PERMS_R_PROFILE|PERMS_R_PHOTO|PERMS_R_ABOOK|PERMS_W_STREAM|PERMS_W_COMMENT|PERMS_W_MAIL|PERMS_W_CHAT; + $newperms = PERMS_R_STREAM|PERMS_R_PROFILE|PERMS_R_PHOTOS|PERMS_R_ABOOK|PERMS_W_STREAM|PERMS_W_COMMENT|PERMS_W_MAIL|PERMS_W_CHAT; $r = q("update abook set abook_their_perms = %d where abook_id = %d and abook_channel = %d limit 1", intval($newperms), @@ -655,7 +657,7 @@ function diaspora_request($importer,$xml) { $ret = find_diaspora_person_by_handle($sender_handle); - if((! $ret) || ($ret['xchan_network'] != 'diaspora')) { + if((! $ret) || (! strstr($ret['xchan_network'],'diaspora'))) { logger('diaspora_request: Cannot resolve diaspora handle ' . $sender_handle . ' for ' . $recipient_handle); return; } diff --git a/include/notifier.php b/include/notifier.php index 7f4d7a9f8..5f4462b6a 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -107,7 +107,7 @@ function notifier_run($argv, $argc){ intval($r[0]['abook_channel']) ); if($s) { - if($r[0]['hubloc_network'] === 'diaspora' || $r[0]['hubloc_network'] === 'friendica_over_diaspora') { + if($r[0]['hubloc_network'] === 'diaspora' || $r[0]['hubloc_network'] === 'friendica-over-diaspora') { require_once('include/diaspora.php'); diaspora_share($s[0],$r[0]); } -- cgit v1.2.3 From 6a42d6fe3b1e50af16942d0f22e8cfa01abfde39 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Aug 2014 18:58:48 -0700 Subject: works one way sort of - now to go the other way - which will require fixing a whole slew of FIXMEs --- include/deliver.php | 2 +- include/diaspora.php | 67 +++++++++++++++++++++++++++++++++------------------- include/notifier.php | 6 ++--- include/zot.php | 5 +++- 4 files changed, 51 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/deliver.php b/include/deliver.php index 6edf3d60f..08c4f9b64 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -22,7 +22,7 @@ function deliver_run($argv, $argc) { if($r) { if($r[0]['outq_driver'] === 'post') { $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); - if($result['success'] && $result['status_code'] < 300) { + if($result['success'] && $result['return_code'] < 300) { logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); } else { diff --git a/include/diaspora.php b/include/diaspora.php index 0d2037666..017fd4ed8 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -150,15 +150,32 @@ 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)) { + $key = get_config('system','prvkey'); + if($target_item['title']) + $target_item['title'] = crypto_unencapsulate(json_decode($target_item['title'],true),$key); + if($target_item['body']) + $target_item['body'] = crypto_unencapsulate(json_decode($target_item['body'],true),$key); + } + if($arr['walltowall']) return; if($arr['env_recips']) { + $hashes = array(); + + // re-explode the recipients, but only for this hub/pod + + foreach($arr['env_recips'] as $recip) + $hashes[] = "'" . $recip['hash'] . "'"; + $r = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s' - and xchan_hash in (" . implode(',',$arr['env_recips']) . ") - and xchan_network in ('diaspora', 'friendica-over-diaspora') ", + and xchan_hash in (" . implode(',', $hashes) . ") and xchan_network in ('diaspora', 'friendica-over-diaspora') ", dbesc($arr['hub']['hubloc_url']) ); + if(! $r) { logger('diaspora_process_outbound: no recipients'); return; @@ -178,36 +195,36 @@ function diaspora_process_outbound($arr) { // all other public posts processed as public batches further below if((! $arr['private']) && ($arr['followup'])) { - diaspora_send_followup($arr['target_item'],$arr['channel'],$contact, true); + diaspora_send_followup($target_item,$arr['channel'],$contact, true); continue; } if(! $contact['xchan_pubkey']) continue; - if(activity_match($arr['target_item']['verb'],ACTIVITY_DISLIKE)) { + if(activity_match($target_item['verb'],ACTIVITY_DISLIKE)) { continue; } - elseif(($arr['target_item']['item_restrict'] & ITEM_DELETED) - && (($arr['target_item']['mid'] === $arr['target_item']['parent_mid']) || $arr['followup'])) { + elseif(($target_item['item_restrict'] & 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($arr['target_item'],$arr['channel'],$contact); + diaspora_send_retraction($target_item,$arr['channel'],$contact); continue; } elseif($arr['followup']) { // send comments and likes to owner to relay - diaspora_send_followup($arr['target_item'],$arr['channel'],$contact); + diaspora_send_followup($target_item,$arr['channel'],$contact); continue; } elseif($target_item['mid'] !== $target_item['parent_mid']) { // we are the relay - send comments, likes and relayable_retractions // (of comments and likes) to our conversants - diaspora_send_relay($arr['target_item'],$arr['channel'],$contact); + diaspora_send_relay($target_item,$arr['channel'],$contact); continue; } - elseif($arr['top_level']) { - diaspora_send_status($arr['target_item'],$arr['channel'],$contact); + elseif($arr['top_level_post']) { + diaspora_send_status($target_item,$arr['channel'],$contact); continue; } } @@ -221,23 +238,23 @@ function diaspora_process_outbound($arr) { // unsupported return; } - elseif(($arr['target_item']['deleted']) - && ($arr['target_item']['mid'] === $arr['target_item']['parent_mod'])) { + elseif(($target_item['deleted']) + && ($target_item['mid'] === $target_item['parent_mod'])) { // top-level retraction logger('delivery: diaspora retract: ' . $loc); - diaspora_send_retraction($arr['target_item'],$arr['channel'],$contact,true); + diaspora_send_retraction($target_item,$arr['channel'],$contact,true); return; } - elseif($arr['target_item']['mid'] !== $arr['target_item']['parent_mid']) { + elseif($target_item['mid'] !== $target_item['parent_mid']) { // we are the relay - send comments, likes and relayable_retractions to our conversants logger('delivery: diaspora relay: ' . $loc); - diaspora_send_relay($arr['target_item'],$arr['channel'],$contact,true); + diaspora_send_relay($target_item,$arr['channel'],$contact,true); return; } elseif($arr['top_level_post']) { // currently no workable solution for sending walltowall logger('delivery: diaspora status: ' . $loc); - diaspora_send_status($arr['target_item'],$arr['channel'],$contact,true); + diaspora_send_status($target_item,$arr['channel'],$contact,true); return; } @@ -392,7 +409,7 @@ function diaspora_msg_build($msg,$user,$contact,$prvkey,$pubkey,$public = false) $outer_iv = random_string(16); $b_outer_iv = base64_encode($outer_iv); - $handle = $user['xchan_addr']; + $handle = $user['channel_address'] . '@' . get_app()->get_hostname(); $padded_data = pkcs5_pad($msg,16); $inner_encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $inner_aes_key, $padded_data, MCRYPT_MODE_CBC, $inner_iv); @@ -1174,18 +1191,20 @@ function diaspora_comment($importer,$xml,$msg) { return 202; } - $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `mid` = '%s' LIMIT 1", + // Friendica is truncating guids at 64 chars + + $r = q("SELECT * FROM item WHERE uid = %d AND mid like '%s' LIMIT 1", intval($importer['channel_id']), - dbesc($guid) + dbesc($guid . '%') ); if($r) { logger('diaspora_comment: our comment just got relayed back to us (or there was a guid collision) : ' . $guid); return; } - $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `mid` = '%s' LIMIT 1", + $r = q("SELECT * FROM item WHERE uid = %d AND mid LIKE '%s' LIMIT 1", intval($importer['channel_id']), - dbesc($parent_guid) + dbesc($parent_guid . '%') ); if(! $r) { logger('diaspora_comment: parent item not found: parent: ' . $parent_guid . ' item: ' . $guid); @@ -1298,7 +1317,7 @@ function diaspora_comment($importer,$xml,$msg) { // No timestamps for comments? OK, we'll the use current time. $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert(); - $datarray['private'] = $parent_item['private']; + $datarray['item_private'] = $parent_item['item_private']; $datarray['owner_xchan'] = $parent_item['owner_xchan']; $datarray['author_xchan'] = $person['xchan_hash']; @@ -2326,7 +2345,7 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { $return_code = diaspora_transmit($owner,$contact,$slap,$public_batch); - logger('diaspora_send_status: guid: '.$item['mid'].' result '.$return_code, LOGGER_DEBUG); +// logger('diaspora_send_status: guid: '.$item['mid'].' result '.$return_code, LOGGER_DEBUG); if(count($images)) { diaspora_send_images($item,$owner,$contact,$images,$public_batch); diff --git a/include/notifier.php b/include/notifier.php index 5f4462b6a..88bb9a0cb 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -412,7 +412,7 @@ function notifier_run($argv, $argc){ $recip_list[] = $d['xchan_addr'] . ' (' . $d['xchan_hash'] . ')'; if($private) - $env_recips[] = array('guid' => $d['xchan_guid'],'guid_sig' => $d['xchan_guid_sig']); + $env_recips[] = array('guid' => $d['xchan_guid'],'guid_sig' => $d['xchan_guid_sig'],'hash' => $d['xchan_hash']); } } @@ -445,11 +445,11 @@ function notifier_run($argv, $argc){ // aren't the owner or author. - $r = q("select hubloc_guid, hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc + $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) . ") group by hubloc_sitekey order by hubloc_connected desc limit 1"); } else { - $r = q("select hubloc_guid, hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc + $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) . ") $sql_extra group by hubloc_sitekey"); } diff --git a/include/zot.php b/include/zot.php index 65c092b93..54efe1343 100644 --- a/include/zot.php +++ b/include/zot.php @@ -117,8 +117,11 @@ function zot_build_packet($channel,$type = 'notify',$recipients = null, $remote_ 'version' => ZOT_REVISION ); - if($recipients) + if($recipients) { + for($x = 0; $x < count($recipients); $x ++) + unset($recipients[$x]['hash']); $data['recipients'] = $recipients; + } if($secret) { $data['secret'] = $secret; -- cgit v1.2.3 From 8c6067b411ee7f69b3df1341a8696ec1e5811601 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Aug 2014 20:51:59 -0700 Subject: more hard work --- include/diaspora.php | 220 +++++++++++++++++++++++---------------------------- 1 file changed, 99 insertions(+), 121 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 017fd4ed8..9add80d36 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -293,11 +293,6 @@ function diaspora_get_contact_by_handle($uid,$handle) { function find_diaspora_person_by_handle($handle) { $person = false; - $update = false; - $got_lock = false; - - $endlessloop = 0; - $maxloops = 10; if(diaspora_is_blacklisted($handle)) return false; @@ -308,25 +303,25 @@ 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); - - // update record occasionally so it doesn't get stale -// $d = strtotime($person['updated'] . ' +00:00'); -// if($d < strtotime('now - 14 days')) -// $update = true; } - if((! $person) || ($update)) { + if(! $person) { // try webfinger. Make sure to distinguish between diaspora, // redmatrix 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) + ); + if($r) { + $person = $r[0]; + logger('find_diaspora_person_by handle: discovered ' . print_r($r,true), LOGGER_DATA); + } + } } - return $person; } @@ -338,14 +333,13 @@ function get_diaspora_key($handle) { } -function diaspora_pubmsg_build($msg,$user,$contact,$prvkey,$pubkey) { +function diaspora_pubmsg_build($msg,$channel,$contact,$prvkey,$pubkey) { $a = get_app(); logger('diaspora_pubmsg_build: ' . $msg, LOGGER_DATA); - - $handle = $user['xchan_addr']; + $handle = $channel['xchan_addr']; $b64url_data = base64url_encode($msg,false); @@ -384,11 +378,11 @@ EOT; -function diaspora_msg_build($msg,$user,$contact,$prvkey,$pubkey,$public = false) { +function diaspora_msg_build($msg,$channel,$contact,$prvkey,$pubkey,$public = false) { $a = get_app(); if($public) - return diaspora_pubmsg_build($msg,$user,$contact,$prvkey,$pubkey); + return diaspora_pubmsg_build($msg,$channel,$contact,$prvkey,$pubkey); logger('diaspora_msg_build: ' . $msg, LOGGER_DATA); @@ -409,7 +403,7 @@ function diaspora_msg_build($msg,$user,$contact,$prvkey,$pubkey,$public = false) $outer_iv = random_string(16); $b_outer_iv = base64_encode($outer_iv); - $handle = $user['channel_address'] . '@' . get_app()->get_hostname(); + $handle = $channel['channel_address'] . '@' . get_app()->get_hostname(); $padded_data = pkcs5_pad($msg,16); $inner_encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $inner_aes_key, $padded_data, MCRYPT_MODE_CBC, $inner_iv); @@ -661,7 +655,10 @@ function diaspora_request($importer,$xml) { // perhaps we were already sharing with this person. Now they're sharing with us. // That makes us friends. Maybe. - $newperms = PERMS_R_STREAM|PERMS_R_PROFILE|PERMS_R_PHOTOS|PERMS_R_ABOOK|PERMS_W_STREAM|PERMS_W_COMMENT|PERMS_W_MAIL|PERMS_W_CHAT; + // Please note some of these permissions such as PERMS_R_PAGES are impossible for Disapora. + // They cannot authenticate to our system. + + $newperms = PERMS_R_STREAM|PERMS_R_PROFILE|PERMS_R_PHOTOS|PERMS_R_ABOOK|PERMS_W_STREAM|PERMS_W_COMMENT|PERMS_W_MAIL|PERMS_W_CHAT|PERMS_R_STORAGE|PERMS_R_PAGES; $r = q("update abook set abook_their_perms = %d where abook_id = %d and abook_channel = %d limit 1", intval($newperms), @@ -689,7 +686,7 @@ function diaspora_request($importer,$xml) { if($z) $default_perms = intval($z[0]['abook_my_perms']); - $their_perms = PERMS_R_STREAM|PERMS_R_PROFILE|PERMS_R_PHOTO|PERMS_R_ABOOK|PERMS_W_STREAM|PERMS_W_COMMENT|PERMS_W_MAIL|PERMS_CHAT; + $their_perms = PERMS_R_STREAM|PERMS_R_PROFILE|PERMS_R_PHOTOS|PERMS_R_ABOOK|PERMS_W_STREAM|PERMS_W_COMMENT|PERMS_W_MAIL|PERMS_W_CHAT|PERMS_R_STORAGE|PERMS_R_PAGES; $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, abook_profile) values ( %d, %d, '%s' %d %d, %d, %d, '%s', '%s', '%s', '%s', %d, '%s')", intval($importer['channel_account_id']), @@ -796,13 +793,17 @@ function diaspora_post($importer,$xml,$msg) { $datarray = array(); - $str_tags = ''; - + $tags = get_tags($body); -// FIXME call handle_tags() + + + if(count($tags)) { + + $datarray['term'] = array(); + foreach($tags as $tag) { if(strpos($tag,'#') === 0) { if(strpos($tag,'[url=')) @@ -817,20 +818,28 @@ function diaspora_post($importer,$xml,$msg) { $basetag = str_replace('_',' ',substr($tag,1)); $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?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; - continue; + + $datarray['term'][] = array( + 'uid' => $importer['channel_id'], + 'type' => TERM_HASHTAG, + 'otype' => TERM_OBJ_POST, + 'term' => $basetag, + 'url' => z_root() . '/search?tag=' . rawurlencode($basetag) + ); } } } - $cnt = preg_match_all('/@\[url=(.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER); + $cnt = preg_match_all('/@\[url=(.*?)\](.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER); if($cnt) { foreach($matches as $mtch) { - if(strlen($str_tags)) - $str_tags .= ','; - $str_tags .= '@[url=' . $mtch[1] . '[/url]'; + $datarray['term'][] = array( + 'uid' => $importer['channel_id'], + 'type' => TERM_MENTION, + 'otype' => TERM_OBJ_POST, + 'term' => $mtch[2], + 'url' => $mtch[1] + ); } } @@ -838,11 +847,8 @@ function diaspora_post($importer,$xml,$msg) { $datarray['uid'] = $importer['channel_id']; -// FIXME - - $datarray['verb'] = ACTIVITY_POST; - $datarray['mid'] = $datarray['parent-mid'] = $guid; + $datarray['mid'] = $datarray['parent_mid'] = $guid; $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); $datarray['item_private'] = $private; @@ -854,13 +860,10 @@ function diaspora_post($importer,$xml,$msg) { $datarray['body'] = $body; -// FIXME -// $datarray['tag'] = $str_tags; - $datarray['app'] = 'Diaspora'; - // if empty content it might be a photo that hasn't arrived yet. If a photo arrives, we'll make it visible. -// $datarray['visible'] = ((strlen($body)) ? 1 : 0); + $datarray['item_flags'] = ITEM_UNSEEN|ITEM_THREAD_TOP; + $result = item_store($datarray); return; @@ -1191,20 +1194,29 @@ function diaspora_comment($importer,$xml,$msg) { return 202; } - // Friendica is truncating guids at 64 chars + // Friendica is currently truncating guids at 64 chars + + $search_guid = $guid; + if(strlen($guid) == 64) + $search_guid = $guid . '%'; $r = q("SELECT * FROM item WHERE uid = %d AND mid like '%s' LIMIT 1", intval($importer['channel_id']), - dbesc($guid . '%') + dbesc($search_guid) ); if($r) { logger('diaspora_comment: our comment just got relayed back to us (or there was a guid collision) : ' . $guid); return; } + $search_guid = $parent_guid; + if(strlen($parent_guid) == 64) + $search_guid = $parent_guid . '%'; + + $r = q("SELECT * FROM item WHERE uid = %d AND mid LIKE '%s' LIMIT 1", intval($importer['channel_id']), - dbesc($parent_guid . '%') + dbesc($search_guid) ); if(! $r) { logger('diaspora_comment: parent item not found: parent: ' . $parent_guid . ' item: ' . $guid); @@ -1259,6 +1271,7 @@ function diaspora_comment($importer,$xml,$msg) { // Find the original comment author information. // We need this to make sure we display the comment author // information (name and avatar) correctly. + if(strcasecmp($diaspora_handle,$msg['author']) == 0) $person = $contact; else { @@ -1270,15 +1283,17 @@ function diaspora_comment($importer,$xml,$msg) { } } + $body = diaspora2bb($text); $datarray = array(); - $str_tags = ''; - $tags = get_tags($body); if(count($tags)) { + + $datarray['term'] = array(); + foreach($tags as $tag) { if(strpos($tag,'#') === 0) { if(strpos($tag,'[url=')) @@ -1291,24 +1306,32 @@ function diaspora_comment($importer,$xml,$msg) { if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body)) continue; - $basetag = str_replace('_',' ',substr($tag,1)); $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?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; - continue; + + $datarray['term'][] = array( + 'uid' => $importer['channel_id'], + 'type' => TERM_HASHTAG, + 'otype' => TERM_OBJ_POST, + 'term' => $basetag, + 'url' => z_root() . '/search?tag=' . rawurlencode($basetag) + ); } } } - $datarray['uid'] = $importer['channel_id']; - -//FIXME -// $datarray['contact-id'] = $contact['id']; -// $datarray['type'] = 'remote-comment'; -// $datarray['wall'] = $parent_item['wall']; -// $datarray['network'] = NETWORK_DIASPORA; + $cnt = preg_match_all('/@\[url=(.*?)\](.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + $datarray['term'][] = array( + 'uid' => $importer['channel_id'], + 'type' => TERM_MENTION, + 'otype' => TERM_OBJ_POST, + 'term' => $mtch[2], + 'url' => $mtch[1] + ); + } + } $datarray['verb'] = ACTIVITY_POST; $datarray['mid'] = $guid; @@ -1324,77 +1347,32 @@ function diaspora_comment($importer,$xml,$msg) { $datarray['body'] = $body; -// FIXME -// $datarray['tag'] = $str_tags; - - // We can't be certain what the original app is if the message is relayed. -// if(($parent_item['origin']) && (! $parent_author_signature)) -// $datarray['app'] = 'Diaspora'; + $datarray['app'] = 'Diaspora'; $result = item_store($datarray); -// if(($parent_item['origin']) && (! $parent_author_signature)) { -// q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", -// intval($message_id), -// dbesc($signed_data), -// dbesc(base64_encode($author_signature)), -// dbesc($diaspora_handle) -// ); + if(($parent_item['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature)) { + q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", + intval($message_id), + dbesc($signed_data), + dbesc(base64_encode($author_signature)), + dbesc($diaspora_handle) + ); // 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. -// proc_run('php','include/notifier.php','comment-import',$message_id); -// } - - -// FIXME -/* - $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['channel_id']) - ); - - 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['channel_id'], - 'item' => $datarray, - //'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id, - 'link' => $a->get_baseurl().'/display/'.$datarray['guid'], - 'source_name' => $datarray['author-name'], - 'source_link' => $datarray['author-link'], - 'source_photo' => $datarray['author-avatar'], - 'verb' => ACTIVITY_POST, - 'otype' => 'item', - 'parent' => $conv_parent, - 'parent_uri' => $parent_uri - )); - - // only send one notification - break; - } + proc_run('php','include/notifier.php','comment-import',$message_id); } -*/ + if($result['item_id']) { + $r = q("select * from item where id = %d limit 1", + intval($result['item_id']) + ); + if($r) + send_status_notifications($result['item_id'],$r[0]); + } return; } -- cgit v1.2.3 From 5e4298029a4f1bb8dbcef65ef0bd72db3e9a316a Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 26 Aug 2014 21:00:51 -0700 Subject: and ... we've got a comment coming the other way --- include/diaspora.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 9add80d36..0f0f50208 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1333,6 +1333,7 @@ function diaspora_comment($importer,$xml,$msg) { } } + $datarray['uid'] = $importer['channel_id']; $datarray['verb'] = ACTIVITY_POST; $datarray['mid'] = $guid; $datarray['parent_mid'] = $parent_item['mid']; -- cgit v1.2.3 From eb27bea794d5aff547be9722f7c058678b8cbb1d Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 27 Aug 2014 19:15:34 -0700 Subject: mind numbing drudgery continued... --- include/diaspora.php | 145 ++++++++++++++++++++++----------------------------- 1 file changed, 62 insertions(+), 83 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 0f0f50208..9652ecce7 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -772,10 +772,13 @@ function diaspora_post($importer,$xml,$msg) { return 202; } - $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", + $search_guid = ((strlen($guid) == 64) ? $guid . '%' : $guid); + + $r = q("SELECT id FROM item WHERE uid = %d AND mid like '%s' LIMIT 1", intval($importer['channel_id']), - dbesc($guid) + dbesc($search_guid) ); + if($r) { // check dates if post editing is implemented logger('diaspora_post: message exists: ' . $guid); @@ -797,9 +800,6 @@ function diaspora_post($importer,$xml,$msg) { $tags = get_tags($body); - - - if(count($tags)) { $datarray['term'] = array(); @@ -843,6 +843,7 @@ function diaspora_post($importer,$xml,$msg) { } } + // this won't work for Friendica or Redmatrix but it's probably the best we can do. $plink = 'https://'.substr($diaspora_handle,strpos($diaspora_handle,'@')+1).'/posts/'.$guid; $datarray['uid'] = $importer['channel_id']; @@ -893,13 +894,12 @@ function diaspora_reshare($importer,$xml,$msg) { return 202; } - $message_id = $diaspora_handle . ':' . $guid; - $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1", + $search_guid = ((strlen($guid) == 64) ? $guid . '%' : $guid); + $r = q("SELECT id FROM item WHERE uid = %d AND mid like '%s' LIMIT 1", intval($importer['channel_id']), - dbesc($message_id), - dbesc($guid) + dbesc($search_guid) ); - if(count($r)) { + if($r) { logger('diaspora_reshare: message exists: ' . $guid); return; } @@ -909,16 +909,17 @@ function diaspora_reshare($importer,$xml,$msg) { $source_url = 'https://' . substr($orig_author,strpos($orig_author,'@')+1) . '/p/' . $orig_guid . '.xml'; $orig_url = 'https://'.substr($orig_author,strpos($orig_author,'@')+1).'/posts/'.$orig_guid; - $x = fetch_url($source_url); - if(! $x) - $x = fetch_url(str_replace('https://','http://',$source_url)); - if(! $x) { + $x = z_fetch_url($source_url); + if(! $x['success']) + $x = z_fetch_url(str_replace('https://','http://',$source_url)); + if(! $x['success']) { logger('diaspora_reshare: unable to fetch source url ' . $source_url); return; } - logger('diaspora_reshare: source: ' . $x); + logger('diaspora_reshare: source: ' . $x['body']); + + $x = str_replace(array('',''),array('',''),$x['body']); - $x = str_replace(array('',''),array('',''),$x); $source_xml = parse_xml_string($x,false); if(strlen($source_xml->post->asphoto->objectId) && ($source_xml->post->asphoto->objectId != 0) && ($source_xml->post->asphoto->image_url)) { @@ -947,7 +948,7 @@ function diaspora_reshare($importer,$xml,$msg) { $body = scale_external_images($body); // Add OEmbed and other information to the body - $body = add_page_info_to_body($body, false, true); +// $body = add_page_info_to_body($body, false, true); } else { // Maybe it is a reshare of a photo that will be delivered at a later time (testing) @@ -971,18 +972,6 @@ function diaspora_reshare($importer,$xml,$msg) { $prefix = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . $details . "\n";*/ - // allocate a guid on our system - we aren't fixing any collisions. - // we're ignoring them - - $g = q("select * from guid where guid = '%s' limit 1", - dbesc($guid) - ); - if(! count($g)) { - q("insert into guid ( guid ) values ( '%s' )", - dbesc($guid) - ); - } - $created = unxmlify($xml->created_at); $private = ((unxmlify($xml->public) == 'false') ? 1 : 0); @@ -992,7 +981,11 @@ function diaspora_reshare($importer,$xml,$msg) { $tags = get_tags($body); + if(count($tags)) { + + $datarray['term'] = array(); + foreach($tags as $tag) { if(strpos($tag,'#') === 0) { if(strpos($tag,'[url=')) @@ -1005,63 +998,49 @@ function diaspora_reshare($importer,$xml,$msg) { if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body)) continue; - $basetag = str_replace('_',' ',substr($tag,1)); $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?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; - continue; + + $datarray['term'][] = array( + 'uid' => $importer['channel_id'], + 'type' => TERM_HASHTAG, + 'otype' => TERM_OBJ_POST, + 'term' => $basetag, + 'url' => z_root() . '/search?tag=' . rawurlencode($basetag) + ); } } } + $cnt = preg_match_all('/@\[url=(.*?)\](.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + $datarray['term'][] = array( + 'uid' => $importer['channel_id'], + 'type' => TERM_MENTION, + 'otype' => TERM_OBJ_POST, + 'term' => $mtch[2], + 'url' => $mtch[1] + ); + } + } + + // This won't work $plink = 'https://'.substr($diaspora_handle,strpos($diaspora_handle,'@')+1).'/posts/'.$guid; $datarray['uid'] = $importer['channel_id']; - $datarray['contact-id'] = $contact['id']; - $datarray['wall'] = 0; - $datarray['network'] = NETWORK_DIASPORA; - $datarray['guid'] = $guid; - $datarray['uri'] = $datarray['parent-uri'] = $message_id; + $datarray['mid'] = $datarray['parent_mid'] = $guid; $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); - $datarray['private'] = $private; - $datarray['parent'] = 0; + $datarray['item_private'] = $private; $datarray['plink'] = $plink; - $datarray['owner-name'] = $contact['name']; - $datarray['owner-link'] = $contact['url']; - $datarray['owner-avatar'] = ((x($contact,'thumb')) ? $contact['thumb'] : $contact['photo']); - if (!intval(get_config('system','wall-to-wall_share'))) { - $prefix = "[share author='".str_replace(array("'", "[", "]"), array("'", "[", "]"),$person['name']). - "' profile='".$person['url']. - "' avatar='".((x($person,'thumb')) ? $person['thumb'] : $person['photo']). - "' link='".str_replace(array("'", "[", "]"), array("'", "[", "]"),$orig_url)."']"; - $datarray['author-name'] = $contact['name']; - $datarray['author-link'] = $contact['url']; - $datarray['author-avatar'] = $contact['thumb']; - $datarray['body'] = $prefix.$body."[/share]"; - } else { - // Let reshared messages look like wall-to-wall posts - $datarray['author-name'] = $person['name']; - $datarray['author-link'] = $person['url']; - $datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']); - $datarray['body'] = $body; - } + $datarray['owner_xchan'] = $contact['xchan_hash']; + $datarray['author_xchan'] = $person['xchan_hash']; - $datarray['tag'] = $str_tags; + $datarray['body'] = $body; $datarray['app'] = 'Diaspora'; - // if empty content it might be a photo that hasn't arrived yet. If a photo arrives, we'll make it visible. (testing) - $datarray['visible'] = ((strlen($body)) ? 1 : 0); - - $message_id = item_store($datarray); - //if($message_id) { - // q("update item set plink = '%s' where id = %d", - // dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), - // intval($message_id) - // ); - //} + $result = item_store($datarray); return; @@ -1460,7 +1439,6 @@ function diaspora_conversation($importer,$xml,$msg) { } $body = diaspora2bb($msg_text); - $message_id = $msg_diaspora_handle . ':' . $msg_guid; $author_signed_data = $msg_guid . ';' . $msg_parent_guid . ';' . $msg_text . ';' . unxmlify($mesg->created_at) . ';' . $msg_diaspora_handle . ';' . $msg_conversation_guid; @@ -1473,8 +1451,8 @@ function diaspora_conversation($importer,$xml,$msg) { else { $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_conversation: unable to find author details'); continue; @@ -1499,7 +1477,7 @@ function diaspora_conversation($importer,$xml,$msg) { } } - $r = q("select id from mail where `uri` = '%s' limit 1", + $r = q("select id from mail where mid = '%s' limit 1", dbesc($message_id) ); if(count($r)) { @@ -1507,19 +1485,15 @@ function diaspora_conversation($importer,$xml,$msg) { continue; } - q("insert into mail ( `uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`) values ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')", + q("insert into mail ( `uid`, `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']), - dbesc($msg_guid), intval($conversation['id']), - dbesc($person['name']), - dbesc($person['photo']), - dbesc($person['url']), - intval($contact['id']), + dbesc($person['xchan_hash']), + dbesc($importer['channel_hash']), dbesc($subject), dbesc($body), 0, - 0, - dbesc($message_id), + dbesc($msg_guid), dbesc($parent_uri), dbesc($msg_created_at) ); @@ -1530,6 +1504,9 @@ function diaspora_conversation($importer,$xml,$msg) { ); require_once('include/enotify.php'); +/****** +//FIXME + notification(array( 'type' => NOTIFY_MAIL, 'notify_flags' => $importer['notify-flags'], @@ -1544,6 +1521,8 @@ function diaspora_conversation($importer,$xml,$msg) { 'verb' => ACTIVITY_POST, 'otype' => 'mail' )); +*******/ + } return; -- cgit v1.2.3 From a4f734e37c2092b91d3915b5f4bb90eba6a4b605 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 27 Aug 2014 22:56:24 -0700 Subject: begin embeddable/shareable design elements (blocks, webpages, layouts, menus, etc.) --- include/apps.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/apps.php b/include/apps.php index bd50b953a..7cfa07868 100644 --- a/include/apps.php +++ b/include/apps.php @@ -467,4 +467,36 @@ function app_encode($app,$embed = false) { function papp_encode($papp) { return chunk_split(base64_encode(json_encode($papp)),72,"\n"); -} \ No newline at end of file +} + + +/** + * install a shared design element (layout, webpage, block, menu, whatever) + * + */ + +function element_install($channel,$s) { + + $ret = array('success' => false); + + $s = str_replace(array('[element]','[/element]'),array('',''),$s); + $s = base64url_decode($s); + if(! $s) + return $ret; + $x = json_decode($s,true); + if(! $x) + return $ret; + + $d = array(); + + + + + + + + + $result = item_store($d); + +} + -- cgit v1.2.3 From f526a10f07086ffeb5018b913916827a556f2fa1 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Aug 2014 04:14:49 -0700 Subject: let's make this "specific" since that's what it is. --- include/items.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index e9f11ee4a..16670b731 100755 --- a/include/items.php +++ b/include/items.php @@ -976,6 +976,8 @@ function translate_scope($scope) { return t('Visible to all connections.'); if(strpos($scope,'contacts') === 0) return t('Visible to approved connections.'); + if(strpos($scope,'specific') === 0) + return t('Visible to specific connections.'); } function encode_item_xchan($xchan) { -- cgit v1.2.3 From 53b5cf7f507df53d3e382b6714caacf9551ed6db Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Aug 2014 16:56:13 -0700 Subject: Ability to close comments at a certain date/time - needed for loom.io emulation (and many other uses) --- include/ConversationObject.php | 29 +++++----- include/apps.php | 2 +- include/items.php | 118 ++++++++++++++++++++++++++++------------- 3 files changed, 93 insertions(+), 56 deletions(-) (limited to 'include') diff --git a/include/ConversationObject.php b/include/ConversationObject.php index 9bf410358..767ef7360 100644 --- a/include/ConversationObject.php +++ b/include/ConversationObject.php @@ -159,28 +159,23 @@ class Conversation extends BaseObject { return false; } -// if(local_user() && $item->get_data_value('uid') == local_user()) -// $this->commentable = true; - -// if($this->writable) -// $this->commentable = true; - $item->set_commentable(false); $ob_hash = (($this->observer) ? $this->observer['xchan_hash'] : ''); - if(($item->get_data_value('author_xchan') === $ob_hash) || ($item->get_data_value('owner_xchan') === $ob_hash)) - $item->set_commentable(true); + if(! comments_are_now_closed($item->get_data())) { + if(($item->get_data_value('author_xchan') === $ob_hash) || ($item->get_data_value('owner_xchan') === $ob_hash)) + $item->set_commentable(true); - if($item->get_data_value('item_flags') & ITEM_NOCOMMENT) { - $item->set_commentable(false); - } - elseif(($this->observer) && (! $item->is_commentable())) { - if((array_key_exists('owner',$item->data)) && ($item->data['owner']['abook_flags'] & ABOOK_FLAG_SELF)) - $item->set_commentable(perm_is_allowed($this->profile_owner,$this->observer['xchan_hash'],'post_comments')); - else - $item->set_commentable(can_comment_on_post($this->observer['xchan_hash'],$item->data)); + if($item->get_data_value('item_flags') & ITEM_NOCOMMENT) { + $item->set_commentable(false); + } + elseif(($this->observer) && (! $item->is_commentable())) { + if((array_key_exists('owner',$item->data)) && ($item->data['owner']['abook_flags'] & ABOOK_FLAG_SELF)) + $item->set_commentable(perm_is_allowed($this->profile_owner,$this->observer['xchan_hash'],'post_comments')); + else + $item->set_commentable(can_comment_on_post($this->observer['xchan_hash'],$item->data)); + } } - require_once('include/identity.php'); $sys = get_sys_channel(); diff --git a/include/apps.php b/include/apps.php index 7cfa07868..7ac4c7e4b 100644 --- a/include/apps.php +++ b/include/apps.php @@ -124,7 +124,7 @@ function translate_system_apps(&$arr) { 'Bookmarks' => t('Bookmarks'), 'Address Book' => t('Address Book'), 'Login' => t('Login'), - 'Channel Select' => t('Channel Select'), + 'Channel Manager' => t('Channel Manager'), 'Matrix' => t('Matrix'), 'Settings' => t('Settings'), 'Files' => t('Files'), diff --git a/include/items.php b/include/items.php index 16670b731..cf9b86f06 100755 --- a/include/items.php +++ b/include/items.php @@ -100,6 +100,17 @@ function collect_recipients($item,&$private_envelope) { } + +function comments_are_now_closed($item) { + if($item['comments_closed'] !== '0000-00-00 00:00:00') { + $d = datetime_convert(); + if($d > $item['comments_closed']) + return true; + } + return false; +} + + /** * @function can_comment_on_post($observer_xchan,$item); * @@ -109,6 +120,7 @@ function collect_recipients($item,&$private_envelope) { * Generally we should look at the item - in particular the author['book_flags'] and see if ABOOK_FLAG_SELF is set. * If it is, you should be able to use perm_is_allowed( ... 'post_comments'), and if it isn't you need to call * can_comment_on_post() + * We also check the comments_closed date/time on the item if this is set. */ function can_comment_on_post($observer_xchan,$item) { @@ -117,8 +129,14 @@ function can_comment_on_post($observer_xchan,$item) { if(! $observer_xchan) return false; + + if($item['comment_policy'] === 'none') return false; + + if(comments_are_now_closed($item)) + return false; + if($observer_xchan === $item['author_xchan'] || $observer_xchan === $item['owner_xchan']) return true; switch($item['comment_policy']) { @@ -703,6 +721,9 @@ function get_item_elements($x) { $arr['commented'] = ((x($x,'commented') && $x['commented']) ? datetime_convert('UTC','UTC',$x['commented']) : $arr['created']); + $arr['comments_closed'] = ((x($x,'comments_closed') && $x['comments_closed']) + ? datetime_convert('UTC','UTC',$x['comments_closed']) + : '0000-00-00 00:00:00'); $arr['title'] = (($x['title']) ? htmlspecialchars($x['title'], ENT_COMPAT,'UTF-8',false) : ''); @@ -891,38 +912,41 @@ function encode_item($item) { } - $x['message_id'] = $item['mid']; - $x['message_top'] = $item['parent_mid']; - $x['message_parent'] = $item['thr_parent']; - $x['created'] = $item['created']; - $x['edited'] = $item['edited']; - $x['expires'] = $item['expires']; - $x['commented'] = $item['commented']; - $x['mimetype'] = $item['mimetype']; - $x['title'] = $item['title']; - $x['body'] = $item['body']; - $x['app'] = $item['app']; - $x['verb'] = $item['verb']; - $x['object_type'] = $item['obj_type']; - $x['target_type'] = $item['tgt_type']; - $x['permalink'] = $item['plink']; - $x['location'] = $item['location']; - $x['longlat'] = $item['coord']; - $x['signature'] = $item['sig']; - $x['route'] = $item['route']; - - $x['owner'] = encode_item_xchan($item['owner']); - $x['author'] = encode_item_xchan($item['author']); + $x['message_id'] = $item['mid']; + $x['message_top'] = $item['parent_mid']; + $x['message_parent'] = $item['thr_parent']; + $x['created'] = $item['created']; + $x['edited'] = $item['edited']; + $x['expires'] = $item['expires']; + $x['commented'] = $item['commented']; + $x['mimetype'] = $item['mimetype']; + $x['title'] = $item['title']; + $x['body'] = $item['body']; + $x['app'] = $item['app']; + $x['verb'] = $item['verb']; + $x['object_type'] = $item['obj_type']; + $x['target_type'] = $item['tgt_type']; + $x['permalink'] = $item['plink']; + $x['location'] = $item['location']; + $x['longlat'] = $item['coord']; + $x['signature'] = $item['sig']; + $x['route'] = $item['route']; + + $x['owner'] = encode_item_xchan($item['owner']); + $x['author'] = encode_item_xchan($item['author']); if($item['object']) - $x['object'] = json_decode_plus($item['object']); + $x['object'] = json_decode_plus($item['object']); if($item['target']) - $x['target'] = json_decode_plus($item['target']); + $x['target'] = json_decode_plus($item['target']); if($item['attach']) - $x['attach'] = json_decode_plus($item['attach']); + $x['attach'] = json_decode_plus($item['attach']); if($y = encode_item_flags($item)) - $x['flags'] = $y; + $x['flags'] = $y; - $x['public_scope'] = $scope; + if($item['comments_closed'] !== '0000-00-00 00:00:00') + $x['comments_closed'] = $item['comments_closed']; + + $x['public_scope'] = $scope; if($item['item_flags'] & ITEM_NOCOMMENT) $x['comment_scope'] = 'none'; @@ -930,7 +954,7 @@ function encode_item($item) { $x['comment_scope'] = $c_scope; if($item['term']) - $x['tags'] = encode_item_terms($item['term']); + $x['tags'] = encode_item_terms($item['term']); logger('encode_item: ' . print_r($x,true), LOGGER_DATA); @@ -1749,6 +1773,8 @@ function item_store($arr,$allow_exec = false) { $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert()); $arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : '0000-00-00 00:00:00'); $arr['commented'] = ((x($arr,'commented') !== false) ? datetime_convert('UTC','UTC',$arr['commented']) : datetime_convert()); + $arr['comments_closed'] = ((x($arr,'comments_closed') !== false) ? datetime_convert('UTC','UTC',$arr['comments_closed']) : '0000-00-00 00:00:00'); + $arr['received'] = datetime_convert(); $arr['changed'] = datetime_convert(); $arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : ''); @@ -1768,7 +1794,6 @@ function item_store($arr,$allow_exec = false) { $arr['public_policy'] = ((x($arr,'public_policy')) ? notags(trim($arr['public_policy'])) : '' ); $arr['comment_policy'] = ((x($arr,'comment_policy')) ? notags(trim($arr['comment_policy'])) : 'contacts' ); - $arr['item_flags'] = $arr['item_flags'] | ITEM_UNSEEN; @@ -1800,6 +1825,7 @@ function item_store($arr,$allow_exec = false) { $deny_cid = $arr['deny_cid']; $deny_gid = $arr['deny_gid']; $public_policy = $arr['public_policy']; + $comments_closed = $arr['comments_closed']; $arr['item_flags'] = $arr['item_flags'] | ITEM_THREAD_TOP; } else { @@ -1814,6 +1840,12 @@ function item_store($arr,$allow_exec = false) { if($r) { + if(comments_are_now_closed($r[0])) { + logger('item_store: comments closed'); + $ret['message'] = 'Comments closed.'; + return ret; + } + // is the new message multi-level threaded? // even though we don't support it now, preserve the info // and re-attach to the conversation parent. @@ -1830,13 +1862,14 @@ function item_store($arr,$allow_exec = false) { $r = $z; } - $parent_id = $r[0]['id']; - $parent_deleted = $r[0]['item_restrict'] & ITEM_DELETED; - $allow_cid = $r[0]['allow_cid']; - $allow_gid = $r[0]['allow_gid']; - $deny_cid = $r[0]['deny_cid']; - $deny_gid = $r[0]['deny_gid']; - $public_policy = $r[0]['public_policy']; + $parent_id = $r[0]['id']; + $parent_deleted = $r[0]['item_restrict'] & ITEM_DELETED; + $allow_cid = $r[0]['allow_cid']; + $allow_gid = $r[0]['allow_gid']; + $deny_cid = $r[0]['deny_cid']; + $deny_gid = $r[0]['deny_gid']; + $public_policy = $r[0]['public_policy']; + $comments_closed = $r[0]['comments_closed']; if($r[0]['item_flags'] & ITEM_WALL) $arr['item_flags'] = $arr['item_flags'] | ITEM_WALL; @@ -1950,7 +1983,8 @@ function item_store($arr,$allow_exec = false) { // Set parent id - and also make sure to inherit the parent's ACL's. $r = q("UPDATE item SET parent = %d, allow_cid = '%s', allow_gid = '%s', - deny_cid = '%s', deny_gid = '%s', public_policy = '%s', item_private = %d WHERE id = %d LIMIT 1", + deny_cid = '%s', deny_gid = '%s', public_policy = '%s', item_private = %d, comments_closed = '%s' + WHERE id = %d LIMIT 1", intval($parent_id), dbesc($allow_cid), dbesc($allow_gid), @@ -1958,6 +1992,7 @@ function item_store($arr,$allow_exec = false) { dbesc($deny_gid), dbesc($public_policy), intval($private), + dbesc($comments_closed), intval($current_post) ); @@ -1970,7 +2005,8 @@ function item_store($arr,$allow_exec = false) { $arr['deny_gid'] = $deny_gid; $arr['public_policy'] = $public_policy; $arr['item_private'] = $private; - + $arr['comments_closed'] = $comments_closed; + // Store taxonomy if(($terms) && (is_array($terms))) { @@ -2142,6 +2178,12 @@ function item_store_update($arr,$allow_exec = false) { $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert()); $arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : $orig[0]['expires']); + + if(array_key_exists('comments_closed',$arr) && $arr['comments_closed'] != '0000-00-00 00:00:00') + $arr['comments_closed'] = datetime_convert('UTC','UTC',$arr['comments_closed']); + else + $arr['comments_closed'] = $orig[0]['comments_closed']; + $arr['commented'] = $orig[0]['commented']; $arr['received'] = datetime_convert(); $arr['changed'] = datetime_convert(); -- cgit v1.2.3 From ae3047791c5d7a9bd589509bf13dd1c740e6639f Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Aug 2014 17:25:00 -0700 Subject: when updating the commented timestamp on the parent post (item_store) don't include any time travelling posts. They can mess up the conversation sort order in a big way until they're actually published. --- include/conversation.php | 2 ++ include/items.php | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index b14e609dd..15ce8ce25 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1270,6 +1270,8 @@ function conv_sort($arr,$order) { } } +logger('conv_sort: ' . print_r($ret,true)); + return $ret; } diff --git a/include/items.php b/include/items.php index cf9b86f06..2a4242ea6 100755 --- a/include/items.php +++ b/include/items.php @@ -2029,9 +2029,10 @@ function item_store($arr,$allow_exec = false) { // update the commented timestamp on the parent - $z = q("select max(created) as commented from item where parent_mid = '%s' and uid = %d ", + $z = q("select max(created) as commented from item where parent_mid = '%s' and uid = %d and not ( item_restrict & %d ) ", dbesc($arr['parent_mid']), - intval($arr['uid']) + intval($arr['uid']), + intval(ITEM_DELAYED_PUBLISH) ); q("UPDATE item set commented = '%s', changed = '%s' WHERE id = %d LIMIT 1", -- cgit v1.2.3 From e20fe41f2310e77f57bece8e593a856b34bedc34 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Aug 2014 17:26:53 -0700 Subject: remove noisy log statement --- include/conversation.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 15ce8ce25..b14e609dd 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1270,8 +1270,6 @@ function conv_sort($arr,$order) { } } -logger('conv_sort: ' . print_r($ret,true)); - return $ret; } -- cgit v1.2.3 From 8a62b824f98ca55c94a2fc04afbea0c118d44486 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Aug 2014 21:49:13 -0700 Subject: lots of little Diaspora issues --- include/deliver.php | 3 +++ include/diaspora.php | 23 +++++++++++++++++++---- include/queue.php | 17 +++++++++++++++++ include/zot.php | 13 +++++++------ 4 files changed, 46 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/deliver.php b/include/deliver.php index 08c4f9b64..6f8bf0c98 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -24,6 +24,9 @@ function deliver_run($argv, $argc) { $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); if($result['success'] && $result['return_code'] < 300) { logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); + $y = q("update outq set outq_delivered = '%s' where outq_hash = '%s' limit 1", + dbesc($argv[$x]) + ); } else { $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", diff --git a/include/diaspora.php b/include/diaspora.php index 9652ecce7..352ed48e4 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -18,7 +18,7 @@ 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 WHERE abook_network = 'diaspora' and abook_xchan = '%s' )", + $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' )", dbesc($msg['author']) ); @@ -339,7 +339,8 @@ function diaspora_pubmsg_build($msg,$channel,$contact,$prvkey,$pubkey) { logger('diaspora_pubmsg_build: ' . $msg, LOGGER_DATA); - $handle = $channel['xchan_addr']; + $handle = $channel['channel_address'] . '@' . get_app()->get_hostname(); + $b64url_data = base64url_encode($msg,false); @@ -757,6 +758,10 @@ function diaspora_post($importer,$xml,$msg) { $a = get_app(); $guid = notags(unxmlify($xml->guid)); $diaspora_handle = notags(unxmlify($xml->diaspora_handle)); + $app = notags(xmlify($xml->provider_display_name)); + + + if($diaspora_handle != $msg['author']) { logger('diaspora_post: Potential forgery. Message handle is not the same as envelope sender.'); @@ -767,6 +772,16 @@ function diaspora_post($importer,$xml,$msg) { if(! $contact) return; + + + if(! $app) { + if(strstr($contact['xchan_network'],'friendica')) + $app = 'Friendica'; + else + $app = 'Diaspora'; + } + + if(! perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'send_stream')) { logger('diaspora_post: Ignoring this author.'); return 202; @@ -857,11 +872,11 @@ function diaspora_post($importer,$xml,$msg) { $datarray['plink'] = $plink; $datarray['author_xchan'] = $contact['xchan_hash']; - $datarray['owner_xchan'] = $importer['channel_hash']; + $datarray['owner_xchan'] = $contact['xchan_hash']; $datarray['body'] = $body; - $datarray['app'] = 'Diaspora'; + $datarray['app'] = $app; $datarray['item_flags'] = ITEM_UNSEEN|ITEM_THREAD_TOP; diff --git a/include/queue.php b/include/queue.php index 239d61fc0..378cc7816 100644 --- a/include/queue.php +++ b/include/queue.php @@ -46,6 +46,23 @@ function queue_run($argv, $argc){ foreach($r as $rr) { if(in_array($rr['outq_posturl'],$deadguys)) continue; + + if($rr['outq_driver'] === 'post') { + $result = z_post_url($rr['outq_posturl'],$rr['outq_msg']); + if($result['success'] && $result['return_code'] < 300) { + logger('deliver: queue post success to ' . $rr['outq_posturl'], LOGGER_DEBUG); + $y = q("update outq set outq_delivered = '%s' where outq_hash = '%s' limit 1", + dbesc($rr['ouq_hash']) + ); + } + else { + $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", + dbesc(datetime_convert()), + dbesc($rr['outq_hash']) + ); + } + continue; + } $result = zot_zot($rr['outq_posturl'],$rr['outq_notify']); if($result['success']) { zot_process_response($rr['outq_posturl'],$result, $rr); diff --git a/include/zot.php b/include/zot.php index 54efe1343..8627656c2 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1595,12 +1595,13 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false) { $arr['aid'] = $channel['channel_account_id']; $arr['uid'] = $channel['channel_id']; $item_result = item_store($arr); - $item_id = $item_result['item_id']; - $parr = array('item_id' => $item_id,'item' => $arr,'sender' => $sender,'channel' => $channel); - call_hooks('activity_received',$parr); - - add_source_route($item_id,$sender['hash']); - + $item_id = 0; + if($item_result['success']) { + $item_id = $item_result['item_id']; + $parr = array('item_id' => $item_id,'item' => $arr,'sender' => $sender,'channel' => $channel); + call_hooks('activity_received',$parr); + add_source_route($item_id,$sender['hash']); + } $result[] = array($d['hash'],(($item_id) ? 'posted' : 'storage failed:' . $item_result['message']),$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); } -- cgit v1.2.3 From 00004e1a12c74eb600919a3fe37c8f2c253a552f Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Aug 2014 22:42:19 -0700 Subject: the queue driver is universal now - we don't need to filter it. --- include/queue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/queue.php b/include/queue.php index 378cc7816..c1b891f3c 100644 --- a/include/queue.php +++ b/include/queue.php @@ -38,7 +38,7 @@ function queue_run($argv, $argc){ // The zot driver will deliver everything destined for a single hub once contact is made (*if* contact is made). // Other drivers will have to do something different here and may need their own query. - $r = q("SELECT * FROM outq WHERE outq_delivered = 0 and (( outq_created > UTC_TIMESTAMP() - INTERVAL 12 HOUR and outq_updated < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ) OR ( outq_updated < UTC_TIMESTAMP() - INTERVAL 1 HOUR )) and outq_driver in ('','zot') group by outq_posturl"); + $r = q("SELECT * FROM outq WHERE outq_delivered = 0 and (( outq_created > UTC_TIMESTAMP() - INTERVAL 12 HOUR and outq_updated < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ) OR ( outq_updated < UTC_TIMESTAMP() - INTERVAL 1 HOUR )) group by outq_posturl"); } if(! $r) return; -- cgit v1.2.3 From c6b67518d64fc74524938510ad15e49538847179 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Aug 2014 22:55:40 -0700 Subject: more queue tweaks --- include/deliver.php | 2 +- include/queue.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/deliver.php b/include/deliver.php index 6f8bf0c98..2693fe165 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -24,7 +24,7 @@ function deliver_run($argv, $argc) { $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); if($result['success'] && $result['return_code'] < 300) { logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); - $y = q("update outq set outq_delivered = '%s' where outq_hash = '%s' limit 1", + $y = q("delete from outq where outq_hash = '%s' limit 1", dbesc($argv[$x]) ); } diff --git a/include/queue.php b/include/queue.php index c1b891f3c..cd81e2aa4 100644 --- a/include/queue.php +++ b/include/queue.php @@ -51,7 +51,7 @@ function queue_run($argv, $argc){ $result = z_post_url($rr['outq_posturl'],$rr['outq_msg']); if($result['success'] && $result['return_code'] < 300) { logger('deliver: queue post success to ' . $rr['outq_posturl'], LOGGER_DEBUG); - $y = q("update outq set outq_delivered = '%s' where outq_hash = '%s' limit 1", + $y = q("delete from outq where outq_hash = '%s' limit 1", dbesc($rr['ouq_hash']) ); } -- cgit v1.2.3 From 88f8900ac52aa1b4bba90d000691dfa311ad2a92 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 29 Aug 2014 17:31:40 -0700 Subject: various diaspora issues --- include/deliver.php | 1 + include/diaspora.php | 44 +++++++++++++++++++++++++------------------- include/items.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- include/queue.php | 3 ++- 4 files changed, 76 insertions(+), 22 deletions(-) (limited to 'include') diff --git a/include/deliver.php b/include/deliver.php index 2693fe165..f4fae6061 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -29,6 +29,7 @@ function deliver_run($argv, $argc) { ); } else { + logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'],LOGGER_DEBUG); $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($argv[$x]) diff --git a/include/diaspora.php b/include/diaspora.php index 352ed48e4..b544dad53 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1228,7 +1228,7 @@ function diaspora_comment($importer,$xml,$msg) { check only the parent_author_signature. Basically, they trust that the top-level post owner has already verified the authenticity of anything he/she sends out - In either case, the signature that get checked is the signature created by the person - who sent the salmon + who sent the psuedo-salmon */ $signed_data = $guid . ';' . $parent_guid . ';' . $text . ';' . $diaspora_handle; @@ -1346,6 +1346,9 @@ function diaspora_comment($importer,$xml,$msg) { $result = item_store($datarray); + if($result && $result['success']) + $message_id = $result['item_id']; + if(($parent_item['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature)) { q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", intval($message_id), @@ -2500,6 +2503,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { // Diaspora doesn't support threaded comments, but some // versions of Diaspora (i.e. Diaspora-pistos) support // likes on comments + if($item['verb'] === ACTIVITY_LIKE && $item['thr_parent']) { $p = q("select * from item where mid = '%s' limit 1", dbesc($item['thr_parent']) @@ -2514,14 +2518,18 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { intval($item['parent']) ); } + if($p) $parent = $p[0]; - else + else { + logger('diaspora_send_relay: no parent'); return; + } $like = false; $relay_retract = false; $sql_sign_id = 'iid'; + if( $item['item_restrict'] & ITEM_DELETED) { $relay_retract = true; @@ -2544,10 +2552,10 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { } - // fetch the original signature if the relayable was created by a Diaspora - // or DFRN user. Relayables for other networks are not supported. + // fetch the original signature if the relayable was created by a Diaspora, Friendica-over Diaspora, + // or zot user. Relayables for other networks are not supported. -/* $r = q("select * from sign where " . $sql_sign_id . " = %d limit 1", + $r = q("select * from sign where " . $sql_sign_id . " = %d limit 1", intval($item['id']) ); if(count($r)) { @@ -2557,13 +2565,12 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $handle = $orig_sign['signer']; } else { - // Author signature information (for likes, comments, and retractions of likes or comments, // whether from Diaspora or Friendica) must be placed in the `sign` table before this // function is called logger('diaspora_send_relay: original author signature not found, cannot send relayable'); return; - }*/ + } /* Since the author signature is only checked by the parent, not by the relay recipients, * I think it may not be necessary for us to do so much work to preserve all the original @@ -2574,14 +2581,14 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { * versions of Diaspora (diaspora-pistos), but since there are a number of problems with * doing that, let's ignore it for now. * - * Currently, only DFRN contacts are supported. StatusNet shouldn't be hard, but it hasn't - * been done yet + * */ $handle = diaspora_handle_from_contact($item['author_xchan']); - if(! $handle) + if(! $handle) { + logger('diaspora_send_relay: no handle'); return; - + } if($relay_retract) $sender_signed_text = $item['guid'] . ';' . $target_type; @@ -2601,11 +2608,11 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { // markup at the top of this function, which is AFTER we placed the original $signed_text // in the database, it's hazardous to trust the original $signed_text. - $parentauthorsig = base64_encode(rsa_sign($sender_signed_text,$owner['uprvkey'],'sha256')); + $parentauthorsig = base64_encode(rsa_sign($sender_signed_text,$owner['channel_prvkey'],'sha256')); $msg = replace_macros($tpl,array( - '$guid' => xmlify($item['guid']), - '$parent_guid' => xmlify($parent['guid']), + '$guid' => xmlify($item['mid']), + '$parent_guid' => xmlify($parent['mid']), '$target_type' =>xmlify($target_type), '$authorsig' => xmlify($authorsig), '$parentsig' => xmlify($parentauthorsig), @@ -2616,7 +2623,6 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { logger('diaspora_send_relay: base message: ' . $msg, LOGGER_DATA); - $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch))); return(diaspora_transmit($owner,$contact,$slap,$public_batch)); @@ -2631,7 +2637,7 @@ function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) { $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); // Check whether the retraction is for a top-level post or whether it's a relayable - if( $item['uri'] !== $item['parent-uri'] ) { + if( $item['mid'] !== $item['parent_mid'] ) { $tpl = get_markup_template('diaspora_relay_retraction.tpl'); $target_type = (($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment'); @@ -2642,13 +2648,13 @@ function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) { $target_type = 'StatusMessage'; } - $signed_text = $item['guid'] . ';' . $target_type; + $signed_text = $item['mid'] . ';' . $target_type; $msg = replace_macros($tpl, array( - '$guid' => xmlify($item['guid']), + '$guid' => xmlify($item['mid']), '$type' => xmlify($target_type), '$handle' => xmlify($myaddr), - '$signature' => xmlify(base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'))) + '$signature' => xmlify(base64_encode(rsa_sign($signed_text,$owner['channel_prvkey'],'sha256'))) )); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch))); diff --git a/include/items.php b/include/items.php index 2a4242ea6..c0ff2ac81 100755 --- a/include/items.php +++ b/include/items.php @@ -1665,7 +1665,7 @@ function item_store($arr,$allow_exec = false) { if(! $arr['uid']) { logger('item_store: no uid'); $ret['message'] = 'No uid.'; - return ret; + return $ret; } $uplinked_comment = false; @@ -1843,7 +1843,7 @@ function item_store($arr,$allow_exec = false) { if(comments_are_now_closed($r[0])) { logger('item_store: comments closed'); $ret['message'] = 'Comments closed.'; - return ret; + return $ret; } // is the new message multi-level threaded? @@ -2287,6 +2287,52 @@ function item_store_update($arr,$allow_exec = false) { return $ret; } +function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id) { + + // We won't be able to sign Diaspora comments for authenticated visitors + // - we don't have their private key + + // since Diaspora doesn't handle edits we can only do this for the original text and not update it. + + $enabled = intval(get_config('system','diaspora_enabled')); + if(! $enabled) { + logger('mod_item: diaspora support disabled, not storing comment signature', LOGGER_DEBUG); + return; + } + + $body = $datarray['body']; + if(array_key_exists('item_flags',$datarray) && ($datarray['item_flags'] & ITEM_OBSCURED)) { + $key = get_config('system','prvkey'); + if($datarray['body']) + $body = crypto_unencapsulate(json_decode($datarray['body'],true),$key); + } + + logger('mod_item: storing diaspora comment signature',LOGGER_DEBUG); + + require_once('include/bb2diaspora.php'); + + $signed_body = html_entity_decode(bb2diaspora($body)); + + $diaspora_handle = $channel['channel_address'] . '@' . get_app()->get_hostname(); + + $signed_text = $datarray['mid'] . ';' . $parent_item['mid'] . ';' . $signed_body . ';' . $diaspora_handle; + + if( $uprvkey !== false ) + $authorsig = base64_encode(rsa_sign($signed_text,$channel['channel_prvkey'],'sha256')); + else + $authorsig = ''; + + $r = q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", + intval($post_id), + dbesc($signed_text), + dbesc(base64_encode($authorsig)), + dbesc($diaspora_handle) + ); + if(! $r) + logger('store_diaspora_comment_sig: DB write failed'); + + return; +} diff --git a/include/queue.php b/include/queue.php index cd81e2aa4..222ebada4 100644 --- a/include/queue.php +++ b/include/queue.php @@ -50,12 +50,13 @@ function queue_run($argv, $argc){ if($rr['outq_driver'] === 'post') { $result = z_post_url($rr['outq_posturl'],$rr['outq_msg']); if($result['success'] && $result['return_code'] < 300) { - logger('deliver: queue post success to ' . $rr['outq_posturl'], LOGGER_DEBUG); + logger('queue: queue post success to ' . $rr['outq_posturl'], LOGGER_DEBUG); $y = q("delete from outq where outq_hash = '%s' limit 1", dbesc($rr['ouq_hash']) ); } else { + logger('queue: queue post returned ' . $result['return_code'] . ' from ' . $rr['outq_posturl'],LOGGER_DEBUG); $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($rr['outq_hash']) -- cgit v1.2.3 From e9bf742cc7c0d54dd48a4ba4e0eddd620d8b6857 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 30 Aug 2014 17:03:26 -0700 Subject: insecure network filter --- include/items.php | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index c0ff2ac81..1a4363975 100755 --- a/include/items.php +++ b/include/items.php @@ -19,7 +19,9 @@ function collect_recipients($item,&$private_envelope) { // it is private $allow_people = expand_acl($item['allow_cid']); + $allow_groups = expand_groups(expand_acl($item['allow_gid'])); + $allow_groups = filter_insecure($item['uid'],$allow_groups); $recipients = array_unique(array_merge($allow_people,$allow_groups)); @@ -44,7 +46,13 @@ function collect_recipients($item,&$private_envelope) { $deny_groups = expand_groups(expand_acl($item['deny_gid'])); $deny = array_unique(array_merge($deny_people,$deny_groups)); - $recipients = array_diff($recipients,$deny); + + // Don't deny anybody if nobody was allowed (e.g. they were all filtered out) + // That would lead to array_diff doing the wrong thing. + // This will result in a private post that won't be delivered to anybody. + + if($recipients && $deny) + $recipients = array_diff($recipients,$deny); $private_envelope = true; } else { @@ -100,6 +108,37 @@ function collect_recipients($item,&$private_envelope) { } +/** + * If channel is configured to filter insecure members of privacy groups + * (those whose networks leak privacy via email notifications or other criteria) + * remove them from any privacy groups (collections) that were included in a post. + * They can still be addressed individually. + * Networks may need to be added or removed from this list as circumstances change. + */ + +function filter_insecure($channel_id,$arr) { + $insecure_nets = " and not xchan_network in ('diaspora', 'friendica-over-diaspora') "; + + $ret = array(); + + if((! intval(get_config($channel_id,'system','filter_insecure_collections'))) || (! $arr)) + return $arr; + + $str = ''; + foreach($arr as $rr) { + if(strlen($str)) + $str .= ','; + $str .= "'" . dbesc($rr) . "'"; + } + $r = q("select xchan_hash from xchan where xchan_hash in ($str) $insecure_nets "); + if($r) { + foreach($r as $rr) { + $ret[] = $rr['xchan_hash']; + } + } + return $ret; +} + function comments_are_now_closed($item) { if($item['comments_closed'] !== '0000-00-00 00:00:00') { -- cgit v1.2.3 From 45c35d97b8ce627cb90efa320b7daca4097aef75 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 30 Aug 2014 22:53:21 -0700 Subject: doc change - read it. --- include/items.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index 1a4363975..4614aa642 100755 --- a/include/items.php +++ b/include/items.php @@ -114,6 +114,9 @@ function collect_recipients($item,&$private_envelope) { * remove them from any privacy groups (collections) that were included in a post. * They can still be addressed individually. * Networks may need to be added or removed from this list as circumstances change. + * + * Update: this may need to be the default, which will force people to opt-in to sending stuff + * privately to insecure platforms. */ function filter_insecure($channel_id,$arr) { -- cgit v1.2.3 From 473e582d1f3e5067c1aecee9c9f2f579864db3ef Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Sun, 31 Aug 2014 16:58:17 +0100 Subject: Add check_upstream_directory() to check that your directory is still a directory, and if it isn't, let find_upstream_directory() find you a new one. --- include/dir_fns.php | 20 ++++++++++++++++++++ include/poller.php | 3 +++ 2 files changed, 23 insertions(+) (limited to 'include') diff --git a/include/dir_fns.php b/include/dir_fns.php index 815b6a197..5fad6567e 100644 --- a/include/dir_fns.php +++ b/include/dir_fns.php @@ -30,6 +30,26 @@ function find_upstream_directory($dirmode) { return array('url' => $preferred); } +function check_upstream_directory() { + /** + * Directories may come and go over time. We will need to check that our + * directory server is still valid occasionally, and reset to something that + * is if our directory has gone offline for any reason + */ + $directory = get_config('system','directory_server'); + if ($directory) { + $r = q("select * from site where site_url = '%s' and (site_flags & %d) ", + dbesc($directory), + intval(DIRECTORY_MODE_PRIMARY|DIRECTORY_MODE_SECONDARY|DIRECTORY_MODE_STANDALONE) + ); + } + // If we've got something, it's still a directory. If we haven't, we need to reset and let find_upstream_directory() fix it + if (! $r) { + set_config('system','directory_server',''); + } + return; +} + function dir_sort_links() { $o = replace_macros(get_markup_template('dir_sort_links.tpl'), array( diff --git a/include/poller.php b/include/poller.php index 546a2d6d1..b9d728e8d 100644 --- a/include/poller.php +++ b/include/poller.php @@ -111,6 +111,9 @@ function poller_run($argv, $argc){ if(($d2 != $d1) && ($h1 == $h2)) { + require_once('include/dir_fns.php'); + check_upstream_directory(); + call_hooks('cron_daily',datetime_convert()); -- cgit v1.2.3 From 2d0ad0625a1bc8bc54ad21d1a5ebb057b0afa357 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 31 Aug 2014 16:24:05 -0700 Subject: sql error in profile_activity --- include/activities.php | 2 +- include/zot.php | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/activities.php b/include/activities.php index 4502b758e..d978ebcd6 100644 --- a/include/activities.php +++ b/include/activities.php @@ -25,7 +25,7 @@ function profile_activity($changed, $value) { $arr['verb'] = ACTIVITY_UPDATE; $arr['obj_type'] = ACTIVITY_OBJ_PROFILE; - $arr['$plink'] = z_root() . '/channel/' . $self['channel_address'] . '/?f=&mid=' . $arr['mid']; + $arr['plink'] = z_root() . '/channel/' . $self['channel_address'] . '/?f=&mid=' . $arr['mid']; $A = '[url=' . z_root() . '/channel/' . $self['channel_address'] . ']' . $self['channel_name'] . '[/url]'; diff --git a/include/zot.php b/include/zot.php index 8627656c2..6ccee8c39 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1791,8 +1791,6 @@ function process_mail_delivery($sender,$arr,$deliveries) { function process_profile_delivery($sender,$arr,$deliveries) { - // deliveries is irrelevant, what to do about birthday notification....? - logger('process_profile_delivery', LOGGER_DEBUG); $r = q("select xchan_addr from xchan where xchan_hash = '%s' limit 1", @@ -1864,7 +1862,7 @@ function import_directory_profile($hash,$profile,$addr,$ud_flags = UPDATE_FLAGS_ $update = false; foreach($r[0] as $k => $v) { if((array_key_exists($k,$arr)) && ($arr[$k] != $v)) { - logger('import_directory_profile: update' . $k . ' => ' . $arr[$k]); + logger('import_directory_profile: update ' . $k . ' => ' . $arr[$k]); $update = true; break; } @@ -1906,7 +1904,7 @@ function import_directory_profile($hash,$profile,$addr,$ud_flags = UPDATE_FLAGS_ } else { $update = true; - logger('import_directory_profile: new profile'); + logger('import_directory_profile: new profile '); $x = q("insert into xprof (xprof_hash, xprof_desc, xprof_dob, xprof_age, xprof_gender, xprof_marital, xprof_sexual, xprof_locale, xprof_region, xprof_postcode, xprof_country, xprof_about, xprof_homepage, xprof_hometown, xprof_keywords) values ('%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", dbesc($arr['xprof_hash']), dbesc($arr['xprof_desc']), -- cgit v1.2.3 From f8e6395ef3a54d58c00153b032bbc1645e8b5627 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 31 Aug 2014 18:50:30 -0700 Subject: rss feed discovery --- include/follow.php | 21 ++++-- include/network.php | 182 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 178 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/include/follow.php b/include/follow.php index 55249db2b..1ef355208 100644 --- a/include/follow.php +++ b/include/follow.php @@ -35,10 +35,10 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if($arr['channel']['success']) $ret = $arr['channel']; - else + elseif(strpos($url,'://') === false) $ret = zot_finger($url,$channel); - if($ret['success']) { + if($ret && $ret['success']) { $is_red = true; $j = json_decode($ret['body'],true); } @@ -120,8 +120,10 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $my_perms = 0; $their_perms = 0; $xchan_hash = ''; + $is_http = false; - $r = q("select * from xchan where xchan_hash = '%s' limit 1", + $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", + dbesc($url), dbesc($url) ); @@ -130,9 +132,19 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if(strpos($url,'@')) { $r = discover_by_webbie($url); } + elseif(strpos($url,'://')) { + $r = discover_by_url($url); + $is_http = true; + } + if($r) { + $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", + dbesc($url), + dbesc($url) + ); + } } if($r) { - $xchan_hash = $url; + $xchan_hash = $r[0]['xchan_hash']; $their_perms = 0; $my_perms = PERMS_W_STREAM|PERMS_W_MAIL; } @@ -150,7 +162,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $hash = get_observer_hash(); $ch = $a->get_channel(); $default_group = $ch['channel_default_group']; - } else { $r = q("select * from channel where channel_id = %d limit 1", diff --git a/include/network.php b/include/network.php index ff0502f5a..89bcbdc25 100644 --- a/include/network.php +++ b/include/network.php @@ -819,6 +819,150 @@ function email_send($addr, $subject, $headers, $item) { } + +function discover_by_url($url,$arr = null) { + require_once('library/HTML5/Parser.php'); + + $x = scrape_feed($url); + if(! $x) { + if(! $arr) + return false; + $network = (($arr['network']) ? $arr['network'] : 'unknown'); + $name = (($arr['name']) ? $arr['name'] : 'unknown'); + $photo = (($arr['photo']) ? $arr['photo'] : ''); + $addr = (($arr['addr']) ? $arr['addr'] : ''); + $guid = $url; + } + + $profile = $url; + + logger('scrape_feed results: ' . print_r($x,true)); + + if($x['feed_atom']) + $guid = $x['feed_atom']; + if($x['feed_rss']) + $guid = $x['feed_rss']; + + if(! $guid) + return false; + + + // try and discover stuff from the feeed + + require_once('library/simplepie/simplepie.inc'); + $feed = new SimplePie(); + $level = 0; + $x = z_fetch_url($guid,false,$level,array('novalidate' => true)); + if(! $x['success']) { + logger('probe_url: feed fetch failed for ' . $poll); + return false; + } + $xml = $x['body']; + logger('probe_url: fetch feed: ' . $guid . ' returns: ' . $xml, LOGGER_DATA); + logger('probe_url: scrape_feed: headers: ' . $x['header'], LOGGER_DATA); + + // Don't try and parse an empty string + $feed->set_raw_data(($xml) ? $xml : ''); + + $feed->init(); + if($feed->error()) + logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error()); + + $photo = $feed->get_image_url(); + $author = $feed->get_author(); + + if($author) { + $name = unxmlify(trim($author->get_name())); + if(! $name) + $name = trim(unxmlify($author->get_email())); + if(strpos($name,'@') !== false) + $name = substr($name,0,strpos($name,'@')); + if(! $profile && $author->get_link()) + $profile = trim(unxmlify($author->get_link())); + if(! $photo) { + $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); + if($rawtags) { + $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; + if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo')) + $photo = $elems['link'][0]['attribs']['']['href']; + } + } + } + else { + $item = $feed->get_item(0); + if($item) { + $author = $item->get_author(); + if($author) { + $name = trim(unxmlify($author->get_name())); + if(! $name) + $name = trim(unxmlify($author->get_email())); + if(strpos($name,'@') !== false) + $name = substr($name,0,strpos($name,'@')); + if(! $profile && $author->get_link()) + $profile = trim(unxmlify($author->get_link())); + } + if(! $photo) { + $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/','thumbnail'); + if($rawmedia && $rawmedia[0]['attribs']['']['url']) + $photo = unxmlify($rawmedia[0]['attribs']['']['url']); + } + if(! $photo) { + $rawtags = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); + if($rawtags) { + $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; + if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo')) + $photo = $elems['link'][0]['attribs']['']['href']; + } + } + } + } + if($poll === $profile) + $lnk = $feed->get_permalink(); + if(isset($lnk) && strlen($lnk)) + $profile = $lnk; + + if(! $network) { + $network = 'rss'; + } + if(! $name) + $name = notags($feed->get_title()); + if(! $name) + $name = notags($feed->get_description()); + + if(! $guid) + return false; + + $r = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($guid) + ); + if($r) + return true; + + $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_pubkey, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_instance_url, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", + dbesc($guid), + dbesc($guid), + dbesc($pubkey), + dbesc($addr), + dbesc($profile), + dbesc($name), + dbesc($network), + dbesc(z_root()), + dbesc(datetime_convert()) + ); + + $photos = import_profile_photo($photo,$profile); + $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s' limit 1", + dbesc(datetime_convert('UTC','UTC',$arr['photo_updated'])), + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc($photos[3]), + dbesc($guid) + ); + return true; + +} + function discover_by_webbie($webbie) { require_once('library/HTML5/Parser.php'); @@ -882,14 +1026,12 @@ function discover_by_webbie($webbie) { } } - if($diaspora && $diaspora_base && $diaspora_guid) { + if($diaspora && $diaspora_base && $diaspora_guid && intval(get_config('system','diaspora_enabled'))) { $guid = $diaspora_guid; $diaspora_base = trim($diaspora_base,'/'); $notify = $diaspora_base . '/receive'; -// // '/users/' . $diaspora_guid; -// $batch = $diaspora_base . '/receive/public' ; if(strpos($webbie,'@')) { $addr = str_replace('acct:', '', $webbie); $hostname = substr($webbie,strpos($webbie,'@')+1); @@ -988,23 +1130,23 @@ function discover_by_webbie($webbie) { Array ( - [name] => Mike Macgirvin - [nick] => macgirvin - [guid] => a9174a618f8d269a - [url] => https://joindiaspora.com/u/macgirvin - [hostname] => joindiaspora.com - [addr] => macgirvin@joindiaspora.com - [batch] => - [notify] => https://joindiaspora.com/receive - [poll] => https://joindiaspora.com/public/macgirvin.atom - [request] => - [confirm] => - [poco] => - [photo] => https://joindiaspora.s3.amazonaws.com/uploads/images/thumb_large_fec4e6eef13ae5e56207.jpg - [priority] => - [network] => diaspora - [alias] => - [pubkey] => -----BEGIN PUBLIC KEY----- + [name] => Mike Macgirvin + [nick] => macgirvin + [guid] => a9174a618f8d269a + [url] => https://joindiaspora.com/u/macgirvin + [hostname] => joindiaspora.com + [addr] => macgirvin@joindiaspora.com + [batch] => + [notify] => https://joindiaspora.com/receive + [poll] => https://joindiaspora.com/public/macgirvin.atom + [request] => + [confirm] => + [poco] => + [photo] => https://joindiaspora.s3.amazonaws.com/uploads/images/thumb_large_fec4e6eef13ae5e56207.jpg + [priority] => + [network] => diaspora + [alias] => + [pubkey] => -----BEGIN PUBLIC KEY----- MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAtihtyIuRDWkDpCA+I1UaQ jI4S7k625+A7EEJm+pL2ZVSJxeCKiFeEgHBQENjLMNNm8l8F6blxgQqE6ZJ9Spa7f tlaXYTRCrfxKzh02L3hR7sNA+JS/nXJaUAIo+IwpIEspmcIRbD9GB7Wv/rr+M28uH -- cgit v1.2.3 From 89d5c42df16ccef9c6c849a98d37e58bbf3dd49a Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 31 Aug 2014 19:30:35 -0700 Subject: service class check for feeds. Note limit is account based, not channel based. --- include/follow.php | 54 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/follow.php b/include/follow.php index 1ef355208..8f14a5062 100644 --- a/include/follow.php +++ b/include/follow.php @@ -17,7 +17,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $a = get_app(); $is_red = false; - + $is_http = ((strpos($url,'://') !== false) ? true : false); if(! allowed_url($url)) { $result['message'] = t('Channel is blocked on this site.'); @@ -29,13 +29,29 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) return $result; } + + // check service class limits + + $r = q("select count(*) as total from abook where abook_channel = %d and not (abook_flags & %d) ", + intval($uid), + intval(ABOOK_FLAG_SELF) + ); + if($r) + $total_channels = $r[0]['total']; + + if(! service_class_allows($uid,'total_channels',$total_channels)) { + $result['message'] = upgrade_message(); + return $result; + } + + $arr = array('url' => $url, 'channel' => array()); call_hooks('follow', $arr); if($arr['channel']['success']) $ret = $arr['channel']; - elseif(strpos($url,'://') === false) + elseif($is_http) $ret = zot_finger($url,$channel); if($ret && $ret['success']) { @@ -61,20 +77,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if(array_key_exists('connect_url',$j) && (! $confirm)) goaway(zid($j['connect_url'])); - // check service class limits - - $r = q("select count(*) as total from abook where abook_channel = %d and not (abook_flags & %d) ", - intval($uid), - intval(ABOOK_FLAG_SELF) - ); - if($r) - $total_channels = $r[0]['total']; - - if(! service_class_allows($uid,'total_channels',$total_channels)) { - $result['message'] = upgrade_message(); - return $result; - } - // do we have an xchan and hubloc? // If not, create them. @@ -120,7 +122,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $my_perms = 0; $their_perms = 0; $xchan_hash = ''; - $is_http = false; $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", dbesc($url), @@ -132,9 +133,8 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if(strpos($url,'@')) { $r = discover_by_webbie($url); } - elseif(strpos($url,'://')) { + elseif($is_http) { $r = discover_by_url($url); - $is_http = true; } if($r) { $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", @@ -148,7 +148,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $their_perms = 0; $my_perms = PERMS_W_STREAM|PERMS_W_MAIL; } - } if(! $xchan_hash) { @@ -175,7 +174,20 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $hash = $r[0]['channel_hash']; $default_group = $r[0]['channel_default_group']; } - + + if($is_http) { + $r = q("select count(*) as total from abook where abook_account = %d and abook_network = 'rss'", + intval($aid) + ); + if($r) + $total_feeds = $r[0]['total']; + + if(! service_class_allows($uid,'total_feeds',$total_feeds)) { + $result['message'] = upgrade_message(); + return $result; + } + } + if($hash == $xchan_hash) { $result['message'] = t('Cannot connect to yourself.'); return $result; -- cgit v1.2.3 From a63de472cf1b5cff1ebda821d3a6ba39cf37f839 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 31 Aug 2014 20:51:05 -0700 Subject: various rss fixes --- include/items.php | 31 ++++++++++++++++++++----------- include/text.php | 5 +++++ 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 4614aa642..f489eeb0a 100755 --- a/include/items.php +++ b/include/items.php @@ -1499,6 +1499,9 @@ function get_atom_elements($feed,$item,&$author) { if($d2 > $d3) $res['edited'] = datetime_convert(); + $res['created'] = datetime_convert('UTC','UTC',$res['created']); + $res['edited'] = datetime_convert('UTC','UTC',$res['edited']); + $rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner'); if(! $rawowner) $rawowner = $item->get_item_tags(NAMESPACE_ZOT,'owner'); @@ -1560,7 +1563,7 @@ function get_atom_elements($feed,$item,&$author) { $termterm = notags(trim(unxmlify($term))); if($termterm) { - $terms = array( + $terms[] = array( 'otype' => TERM_OBJ_POST, 'type' => $termtype, 'url' => $termurl, @@ -1568,7 +1571,7 @@ function get_atom_elements($feed,$item,&$author) { ); } } - $res['term'] = implode(',', $tag_arr); + $res['term'] = $terms; } $attach = $item->get_enclosures(); @@ -1663,6 +1666,9 @@ function get_atom_elements($feed,$item,&$author) { $res['target'] = $obj; } + $res['public_policy'] = 'specific'; + $res['comment_policy'] = 'none'; + $arr = array('feed' => $feed, 'item' => $item, 'result' => $res); call_hooks('parse_atom', $arr); @@ -3207,14 +3213,14 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { $datarray['uid'] = $importer['channel_id']; //FIXME - $datarray['author_xchan'] = $contact['xchan_hash']; + $datarray['owner_xchan'] = $datarray['author_xchan'] = $contact['xchan_hash']; // FIXME pull out the author and owner logger('consume_feed: ' . print_r($datarray,true),LOGGER_DATA); -// $xx = item_store($datarray); + $xx = item_store($datarray); $r = $xx['item_id']; continue; } @@ -3267,18 +3273,21 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { $datarray['parent_mid'] = $item_id; $datarray['uid'] = $importer['channel_id']; //FIXME - $datarray['author_xchan'] = $contact['author_xchan']; - + $datarray['owner_xchan'] = $datarray['author_xchan'] = $contact['xchan_hash']; + if(! link_compare($author['owner_link'],$contact['xchan_url'])) { logger('consume_feed: Correcting item owner.', LOGGER_DEBUG); - $author['owner-name'] = $contact['name']; - $author['owner-link'] = $contact['url']; - $author['owner-avatar'] = $contact['thumb']; + $author['owner_name'] = $contact['name']; + $author['owner_link'] = $contact['url']; + $author['owner_avatar'] = $contact['thumb']; } + logger('consume_feed: author ' . print_r($author,true)); + + logger('consume_feed: ' . print_r($datarray,true),LOGGER_DATA); -// $xx = item_store($datarray); + $xx = item_store($datarray); $r = $xx['item_id']; continue; @@ -3311,7 +3320,7 @@ function handle_feed($uid,$abook_id,$url) { $recurse = 0; $z = z_fetch_url($url,false,$recurse,array('novalidate' => true)); -logger('handle_feed:' . print_r($z,true)); +//logger('handle_feed:' . print_r($z,true)); if($z['success']) { consume_feed($z['body'],$channel,$x[0],0); diff --git a/include/text.php b/include/text.php index 410d9bc96..7da6a8f2b 100644 --- a/include/text.php +++ b/include/text.php @@ -1865,6 +1865,11 @@ function xchan_query(&$items,$abook = true) { $chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash where xchan_hash in (" . implode(',', $arr) . ") and ( hubloc_flags & " . intval(HUBLOC_FLAGS_PRIMARY) . " )"); } + $xchans = q("select * from xchan where xchan_hash in (" . implode(',',$arr) . ") and xchan_network in ('rss','unknown')"); + if(! $chans) + $chans = $xchans; + else + $chans = array_merge($xchans,$chans); } if($items && count($items) && $chans && count($chans)) { for($x = 0; $x < count($items); $x ++) { -- cgit v1.2.3 From 2a37d99958d5591d5b9ccfc9bc615ee0588a6036 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 31 Aug 2014 22:15:00 -0700 Subject: get out the sunnies --- include/follow.php | 5 +++-- include/items.php | 2 +- include/onepoll.php | 17 ++++++++++++++--- include/poller.php | 15 ++++++++++++++- 4 files changed, 32 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/follow.php b/include/follow.php index 8f14a5062..102d84605 100644 --- a/include/follow.php +++ b/include/follow.php @@ -204,11 +204,12 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) ); } else { - $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_their_perms, abook_my_perms, abook_created, abook_updated ) - values( %d, %d, '%s', %d, %d, '%s', '%s' ) ", + $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_flags, abook_their_perms, abook_my_perms, abook_created, abook_updated ) + values( %d, %d, '%s', %d, %d, %d, '%s', '%s' ) ", intval($aid), intval($uid), dbesc($xchan_hash), + intval(($is_http) ? ABOOK_FLAG_FEED : 0), intval($their_perms), intval($my_perms), dbesc(datetime_convert()), diff --git a/include/items.php b/include/items.php index f489eeb0a..7764d2f62 100755 --- a/include/items.php +++ b/include/items.php @@ -1558,7 +1558,7 @@ function get_atom_elements($feed,$item,&$author) { $termurl = unxmlify(substr($scheme,9)); } else { - $termtype = TERM_UNKNOWN; + $termtype = TERM_CATEGORY; } $termterm = notags(trim(unxmlify($term))); diff --git a/include/onepoll.php b/include/onepoll.php index 947e936ac..d64785f92 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -38,7 +38,7 @@ function onepoll_run($argv, $argc){ AND NOT ( abook_flags & %d ) AND (( account_flags = %d ) OR ( account_flags = %d )) limit 1", intval($contact_id), - intval(ABOOK_FLAG_HIDDEN|ABOOK_FLAG_PENDING|ABOOK_FLAG_UNCONNECTED), + intval(ABOOK_FLAG_HIDDEN|ABOOK_FLAG_PENDING|ABOOK_FLAG_UNCONNECTED|ABOOK_FLAG_FEED), intval(0), intval(ABOOK_FLAG_ARCHIVED|ABOOK_FLAG_BLOCKED|ABOOK_FLAG_IGNORED), intval(ACCOUNT_OK), @@ -72,6 +72,19 @@ function onepoll_run($argv, $argc){ : datetime_convert('UTC','UTC',$contact['abook_updated'] . ' - 2 days') ); + if($contact['xchan_network'] === 'rss') { + logger('onepoll: processing feed ' . $contact['xchan_name'], LOGGER_DEBUG); + handle_feed($importer['channel_id'],$contact_id,$contact['xchan_hash']); + q("update abook set abook_connected = '%s' where abook_id = %d limit 1", + dbesc(datetime_convert()), + intval($contact['abook_id']) + ); + return; + } + + if($contact['xchan_network'] !== 'zot') + return; + // update permissions $x = zot_refresh($contact,$importer); @@ -130,11 +143,9 @@ function onepoll_run($argv, $argc){ } } - // fetch some items // set last updated timestamp - if($contact['xchan_connurl']) { $r = q("SELECT xlink_id from xlink where xlink_xchan = '%s' and xlink_updated > UTC_TIMESTAMP() - INTERVAL 1 DAY limit 1", diff --git a/include/poller.php b/include/poller.php index 546a2d6d1..52ca98c97 100644 --- a/include/poller.php +++ b/include/poller.php @@ -244,7 +244,7 @@ function poller_run($argv, $argc){ $sql_extra AND (( abook_flags & %d ) OR ( abook_flags = %d )) AND (( account_flags = %d ) OR ( account_flags = %d )) $abandon_sql ORDER BY RAND()", - intval(ABOOK_FLAG_HIDDEN|ABOOK_FLAG_PENDING|ABOOK_FLAG_UNCONNECTED), + intval(ABOOK_FLAG_HIDDEN|ABOOK_FLAG_PENDING|ABOOK_FLAG_UNCONNECTED|ABOOK_FLAG_FEED), intval(0), intval(ACCOUNT_OK), intval(ACCOUNT_UNVERIFIED) // FIXME @@ -260,6 +260,19 @@ function poller_run($argv, $argc){ $t = $contact['abook_updated']; $c = $contact['abook_connected']; + if($contact['abook_flags'] & ABOOK_FLAG_FEED) { + $min = intval(get_config('system','minimum_feedcheck_minutes')); + if(! $min) + $min = 60; + $x = datetime_convert('UTC','UTC',"now - $min minutes"); + if($c < $x) { + proc_run('php','include/onepoll.php',$contact['abook_id']); + if($interval) + @time_sleep_until(microtime(true) + (float) $interval); + } + continue; + } + if($c == $t) { if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) -- cgit v1.2.3 From 76a72a997d710f4cd53822313260fb259efb63cf Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 1 Sep 2014 04:17:10 -0700 Subject: honour the feed_contacts setting --- include/follow.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/follow.php b/include/follow.php index 102d84605..d1c6afbee 100644 --- a/include/follow.php +++ b/include/follow.php @@ -176,6 +176,11 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) } if($is_http) { + if(! intval(get_config('system','feed_contacts'))) { + $result['message'] = t('Protocol disabled.'); + return $result; + } + $r = q("select count(*) as total from abook where abook_account = %d and abook_network = 'rss'", intval($aid) ); -- cgit v1.2.3 From a2146021f3218ae66d32d6a28f3a79a2d1cee6ac Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 1 Sep 2014 16:32:35 -0700 Subject: use feed icon as default avatar for rss connections --- include/Contact.php | 2 +- include/network.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/Contact.php b/include/Contact.php index 66c94ef50..a9e737bde 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -323,7 +323,7 @@ function mark_orphan_hubsxchans() { return; $r = q("update hubloc set hubloc_status = (hubloc_status | %d) where not (hubloc_status & %d) - and hubloc_connected < utc_timestamp() - interval 36 day", + and hubloc_network != 'zot' and hubloc_connected < utc_timestamp() - interval 36 day", intval(HUBLOC_OFFLINE), intval(HUBLOC_OFFLINE) ); diff --git a/include/network.php b/include/network.php index 89bcbdc25..c44ed77c4 100644 --- a/include/network.php +++ b/include/network.php @@ -938,6 +938,9 @@ function discover_by_url($url,$arr = null) { if($r) return true; + if(! $photo) + $photo = z_root() . '/images/rss_icon.png'; + $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_pubkey, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_instance_url, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", dbesc($guid), dbesc($guid), @@ -950,9 +953,9 @@ function discover_by_url($url,$arr = null) { dbesc(datetime_convert()) ); - $photos = import_profile_photo($photo,$profile); + $photos = import_profile_photo($photo,$guid); $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s' limit 1", - dbesc(datetime_convert('UTC','UTC',$arr['photo_updated'])), + dbesc(datetime_convert()), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), -- cgit v1.2.3 From 148f4e8795391d80994fe8009f161b02f57a130f Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 1 Sep 2014 19:55:43 -0700 Subject: issue #578 - this won't fix old items but should work going forward. The extra time slop shouldn't be needed and will in fact result in possibly undesired redundancy. --- include/externals.php | 2 +- include/items.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/externals.php b/include/externals.php index 8944524b7..ad2c71ac9 100644 --- a/include/externals.php +++ b/include/externals.php @@ -61,7 +61,7 @@ function externals_run($argv, $argc){ if($url) { if($r[0]['site_pull'] !== '0000-00-00 00:00:00') - $mindate = urlencode($r[0]['site_pull']); + $mindate = urlencode(datetime_convert('','',$r[0]['site_pull'] . ' - 1 day')); else { $days = get_config('externals','since_days'); if($days === false) diff --git a/include/items.php b/include/items.php index 7764d2f62..ca6737f8f 100755 --- a/include/items.php +++ b/include/items.php @@ -4056,7 +4056,7 @@ function zot_feed($uid,$observer_xchan,$mindate) { } if($mindate != '0000-00-00 00:00:00') { - $sql_extra .= " and created > '$mindate' "; + $sql_extra .= " and ( created > '$mindate' or edited > '$mindate' ) "; $limit = ""; } else -- cgit v1.2.3 From f64abf3ad8b5c753a3e47669c69c4acda9696e5e Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 1 Sep 2014 20:41:05 -0700 Subject: logic inverted --- include/follow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/follow.php b/include/follow.php index d1c6afbee..cf6bfde77 100644 --- a/include/follow.php +++ b/include/follow.php @@ -51,7 +51,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if($arr['channel']['success']) $ret = $arr['channel']; - elseif($is_http) + elseif(! $is_http) $ret = zot_finger($url,$channel); if($ret && $ret['success']) { -- cgit v1.2.3 From 688722de5bf928c53fa694e0469f81c4ac2b646d Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 1 Sep 2014 20:59:53 -0700 Subject: fix phantom attachments in feeds --- include/follow.php | 2 +- include/items.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/follow.php b/include/follow.php index cf6bfde77..e6c42aad1 100644 --- a/include/follow.php +++ b/include/follow.php @@ -181,7 +181,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) return $result; } - $r = q("select count(*) as total from abook where abook_account = %d and abook_network = 'rss'", + $r = q("select count(*) as total from abook where abook_account = %d and ( abook_flags & ABOOK_FLAG_FEED )", intval($aid) ); if($r) diff --git a/include/items.php b/include/items.php index ca6737f8f..370dd5c72 100755 --- a/include/items.php +++ b/include/items.php @@ -1592,8 +1592,8 @@ function get_atom_elements($feed,$item,&$author) { $title = ' '; if(! $type) $type = 'application/octet-stream'; + $res['attach'][] = array('href' => $link, 'length' => $len, 'type' => $type, 'title' => $title ); } - $res['attach'][] = array('href' => $link, 'length' => $len, 'type' => $type, 'title' => $title ); } $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); -- cgit v1.2.3 From 9dac46ca25b11f80dded42db31e7e062fc7b5142 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 1 Sep 2014 22:59:11 -0700 Subject: minor nits --- include/diaspora.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index b544dad53..2f32053f8 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2584,18 +2584,22 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { * */ - $handle = diaspora_handle_from_contact($item['author_xchan']); + if($item['author_xchan'] === $owner['channel_hash']) + $handle = $owner['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + else + $handle = diaspora_handle_from_contact($item['author_xchan']); + if(! $handle) { logger('diaspora_send_relay: no handle'); return; } if($relay_retract) - $sender_signed_text = $item['guid'] . ';' . $target_type; + $sender_signed_text = $item['mid'] . ';' . $target_type; elseif($like) - $sender_signed_text = $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $positive . ';' . $handle; + $sender_signed_text = $item['mid'] . ';' . $target_type . ';' . $parent['mid'] . ';' . $positive . ';' . $handle; else - $sender_signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $handle; + $sender_signed_text = $item['mid'] . ';' . $parent['mid'] . ';' . $text . ';' . $handle; // Sign the relayable with the top-level owner's signature // -- cgit v1.2.3