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 ++++---- mod/item.php | 1 - view/tpl/profile_edit.tpl | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) 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' ); diff --git a/mod/item.php b/mod/item.php index 92dc3e7c6..27691eb4f 100644 --- a/mod/item.php +++ b/mod/item.php @@ -790,7 +790,6 @@ function item_post(&$a) { else $post_id = 0; - $post = item_store($datarray,$execflag); $post_id = $post['item_id']; diff --git a/view/tpl/profile_edit.tpl b/view/tpl/profile_edit.tpl index 87582da56..b453b1cfa 100755 --- a/view/tpl/profile_edit.tpl +++ b/view/tpl/profile_edit.tpl @@ -9,12 +9,12 @@ -- 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 +++-- mod/xrd.php | 21 +++++++++++++++++---- view/tpl/xrd_diaspora.tpl | 8 ++++++++ view/tpl/xrd_person.tpl | 10 +++++++++- 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 view/tpl/xrd_diaspora.tpl 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 @@ $a->get_baseurl(), + '$dspr_guid' => $r[0]['channel_guid'], + '$dspr_key' => base64_encode(pemtorsa($r[0]['channel_pubkey'])) + )); + } + else + $dspr = ''; + + + + $salmon_key = salmon_key($r[0]['channel_pubkey']); header('Access-Control-Allow-Origin: *'); header("Content-type: text/xml"); @@ -34,15 +47,15 @@ function xrd_init(&$a) { '$nick' => $r[0]['channel_address'], '$accturi' => $uri, '$profile_url' => $a->get_baseurl() . '/channel/' . $r[0]['channel_address'], -// '$hcard_url' => $a->get_baseurl() . '/hcard/' . $r[0]['channel_address'], + '$hcard_url' => $a->get_baseurl() . '/hcard/' . $r[0]['channel_address'], '$atom' => $a->get_baseurl() . '/feed/' . $r[0]['channel_address'], '$zot_post' => $a->get_baseurl() . '/post/' . $r[0]['channel_address'], '$poco_url' => $a->get_baseurl() . '/poco/' . $r[0]['channel_address'], '$photo' => $a->get_baseurl() . '/photo/profile/l/' . $r[0]['channel_id'], -// '$dspr' => $dspr, + '$dspr' => $dspr, // '$salmon' => $a->get_baseurl() . '/salmon/' . $r[0]['channel_address'], // '$salmen' => $a->get_baseurl() . '/salmon/' . $r[0]['channel_address'] . '/mention', -// '$modexp' => 'data:application/magic-public-key,' . $salmon_key, + '$modexp' => 'data:application/magic-public-key,' . $salmon_key, // '$bigkey' => salmon_key($r[0]['pubkey']) )); diff --git a/view/tpl/xrd_diaspora.tpl b/view/tpl/xrd_diaspora.tpl new file mode 100644 index 000000000..143980bcc --- /dev/null +++ b/view/tpl/xrd_diaspora.tpl @@ -0,0 +1,8 @@ +{{* + * AUTOMATICALLY GENERATED TEMPLATE + * DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN + * + *}} + + + diff --git a/view/tpl/xrd_person.tpl b/view/tpl/xrd_person.tpl index 20d438dd5..631ed3f18 100755 --- a/view/tpl/xrd_person.tpl +++ b/view/tpl/xrd_person.tpl @@ -14,5 +14,13 @@ - + + + + + {{$dspr}} + -- cgit v1.2.3 From e524835463fa0411723d2ec57276d1ac13c3aca6 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 21 Aug 2014 20:31:55 -0700 Subject: the rest of the diaspora local discovery stuff --- include/identity.php | 24 +++++++++++++++++++++--- view/tpl/profile_vcard.tpl | 3 +++ 2 files changed, 24 insertions(+), 3 deletions(-) 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, )); diff --git a/view/tpl/profile_vcard.tpl b/view/tpl/profile_vcard.tpl index a653dca7d..7dff8fdeb 100755 --- a/view/tpl/profile_vcard.tpl +++ b/view/tpl/profile_vcard.tpl @@ -43,6 +43,9 @@ {{if $homepage}}
{{$homepage}}
{{$profile.homepage}}
{{/if}} + {{if $diaspora}} + {{include file="diaspora_vcard.tpl"}} + {{/if}} {{if $connect}} {{$connect}} -- cgit v1.2.3 From 05515e3b10d2dcc6cf306e1749c1717e96dfcff2 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 21 Aug 2014 20:42:55 -0700 Subject: D* receive endpoint is receive/users/$guid - where $guid is really the channel_guid, not the channel_hash. We'll allow this to be truncated for older D* sites or those that can't process our 64 character guids. --- mod/receive.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mod/receive.php b/mod/receive.php index c5a2dc4e0..4071b169b 100644 --- a/mod/receive.php +++ b/mod/receive.php @@ -4,8 +4,6 @@ * Diaspora endpoint */ - -//require_once('include/salmon.php'); require_once('include/crypto.php'); require_once('include/diaspora.php'); @@ -31,8 +29,11 @@ function receive_post(&$a) { $guid = argv(2); - $r = q("SELECT * FROM channel left join account on account_id = channel_account_id WHERE channel_guid = '%s' AND account_flags = 0 LIMIT 1", - dbesc($guid) + // Diaspora sites *may* provide a truncated guid. + + $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_guid like '%s' AND NOT (channel_pageflags & %d ) LIMIT 1", + dbesc($guid . '%'), + intval(PAGE_REMOVED) ); if(! $r) http_status_exit(500); -- cgit v1.2.3 From 72a766432d90f6eec44641466e77567808f61aca Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 21 Aug 2014 20:45:15 -0700 Subject: missing template file --- view/tpl/diaspora_vcard.tpl | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 view/tpl/diaspora_vcard.tpl diff --git a/view/tpl/diaspora_vcard.tpl b/view/tpl/diaspora_vcard.tpl new file mode 100644 index 000000000..9d234a398 --- /dev/null +++ b/view/tpl/diaspora_vcard.tpl @@ -0,0 +1,57 @@ +
+
+
Nickname
+
+ {{$diaspora.nickname}} +
+
+
+
Full name
+
+ {{$diaspora.fullname}} +
+
+ +
+
First name
+
+ {{$diaspora.firstname}} +
+
+
+
Family name
+
+ {{$diaspora.lastname}} +
+
+
+
URL
+
+ {{$diaspora.podloc}}/ +
+
+
+
Photo
+
+ +
+
+
+
Photo
+
+ +
+
+
+
Photo
+
+ +
+
+
+
Searchable
+
+ {{$diaspora.searchable}} +
+
+
-- 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(-) 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(-) 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