From 55c3c54ef6fe3f3d80df01c94d334bdfbf395683 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 9 Feb 2015 19:54:48 -0800 Subject: apply max_import_size to Diaspora posts --- include/diaspora.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'include/diaspora.php') diff --git a/include/diaspora.php b/include/diaspora.php index 22574f9f8..4280d9d77 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -827,6 +827,12 @@ function diaspora_post($importer,$xml,$msg) { $body = scale_external_images($body); } + $maxlen = get_max_import_size(); + + if($maxlen && mb_strlen($body) > $maxlen) { + $body = mb_substr($body,0,$maxlen,'UTF-8'); + logger('message length exceeds max_import_size: truncated'); + } //WTF? FIXME // Add OEmbed and other information to the body @@ -1040,6 +1046,14 @@ function diaspora_reshare($importer,$xml,$msg) { //return; } + $maxlen = get_max_import_size(); + + if($maxlen && mb_strlen($body) > $maxlen) { + $body = mb_substr($body,0,$maxlen,'UTF-8'); + logger('message length exceeds max_import_size: truncated'); + } + + //if(! $body) { // logger('diaspora_reshare: empty body: source= ' . $x); // return; @@ -1354,6 +1368,15 @@ function diaspora_comment($importer,$xml,$msg) { $body = diaspora2bb($text); + + $maxlen = get_max_import_size(); + + if($maxlen && mb_strlen($body) > $maxlen) { + $body = mb_substr($body,0,$maxlen,'UTF-8'); + logger('message length exceeds max_import_size: truncated'); + } + + $datarray = array(); $tags = get_tags($body); @@ -1540,6 +1563,15 @@ function diaspora_conversation($importer,$xml,$msg) { $body = diaspora2bb($msg_text); + + $maxlen = get_max_import_size(); + + if($maxlen && mb_strlen($body) > $maxlen) { + $body = mb_substr($body,0,$maxlen,'UTF-8'); + logger('message length exceeds max_import_size: truncated'); + } + + $author_signed_data = $msg_guid . ';' . $msg_parent_guid . ';' . $msg_text . ';' . unxmlify($mesg->created_at) . ';' . $msg_diaspora_handle . ';' . $msg_conversation_guid; $author_signature = base64_decode($msg_author_signature); @@ -1677,6 +1709,17 @@ function diaspora_message($importer,$xml,$msg) { $subject = $conversation['subject']; $body = diaspora2bb($msg_text); + + + $maxlen = get_max_import_size(); + + if($maxlen && mb_strlen($body) > $maxlen) { + $body = mb_substr($body,0,$maxlen,'UTF-8'); + logger('message length exceeds max_import_size: truncated'); + } + + + $message_id = $msg_diaspora_handle . ':' . $msg_guid; $author_signed_data = $msg_guid . ';' . $msg_parent_guid . ';' . $msg_text . ';' . unxmlify($xml->created_at) . ';' . $msg_diaspora_handle . ';' . $msg_conversation_guid; -- cgit v1.2.3 From da2349bb6a85d13f0aa29046bef3021cf0c884ba Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 12 Feb 2015 17:45:25 -0800 Subject: provide relief to sites that are severely impacted by the slow ITEM_UNSEEN searches. This does not incorporate any other flag optimisations as that will require a major DB update and possibly involve significant downtime. This is just to bite off a little chunk now and provide some much needed relief. --- include/diaspora.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/diaspora.php') diff --git a/include/diaspora.php b/include/diaspora.php index 4280d9d77..559a9d14d 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -923,8 +923,8 @@ function diaspora_post($importer,$xml,$msg) { $datarray['app'] = $app; - $datarray['item_flags'] = ITEM_UNSEEN|ITEM_THREAD_TOP; - + $datarray['item_flags'] = ITEM_THREAD_TOP; + $datarray['item_unseen'] = 1; $result = item_store($datarray); return; -- cgit v1.2.3 From e00be4de2353e1ca58570bf37fd247ff99fa549f Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 17 Feb 2015 19:47:36 -0800 Subject: The Diaspora communications policies allow comments to public posts literally from anybody. Allow this policy model by default for commenters from that network. This policy decision can be set or disabled on the addon/features settings page. --- include/diaspora.php | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'include/diaspora.php') diff --git a/include/diaspora.php b/include/diaspora.php index 559a9d14d..d2e27aafe 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1271,31 +1271,21 @@ function diaspora_comment($importer,$xml,$msg) { return; } - if((! $importer['system']) && (! perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'post_comments'))) { - logger('diaspora_comment: Ignoring this author.'); - return 202; - } - // Friendica is currently truncating guids at 64 chars + + $pubcomment = get_pconfig($importer['channel_id'],'system','diaspora_public_comments'); - $search_guid = $guid; - if(strlen($guid) == 64) - $search_guid = $guid . '%'; + // by default comments on public posts are allowed from anybody on Diaspora. That is their policy. + // Once this setting is set to something we'll track your preference and it will over-ride the default. - $r = q("SELECT * FROM item WHERE uid = %d AND mid like '%s' LIMIT 1", - intval($importer['channel_id']), - dbesc($search_guid) - ); - if($r) { - logger('diaspora_comment: our comment just got relayed back to us (or there was a guid collision) : ' . $guid); - return; - } + if($pubcomment === false) + $pubcomment = 1; + // Friendica is currently truncating guids at 64 chars $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($search_guid) @@ -1304,8 +1294,36 @@ function diaspora_comment($importer,$xml,$msg) { logger('diaspora_comment: parent item not found: parent: ' . $parent_guid . ' item: ' . $guid); return; } + $parent_item = $r[0]; + if(intval($parent_item['item_private'])) + $pubcomment = 0; + + // So basically if something arrives at the sys channel it's by definition public and we allow it. + // If $pubcomment and the parent was public, we allow it. + // In all other cases, honour the permissions for this Diaspora connection + + if((! $importer['system']) && (! $pubcomment) && (! perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'post_comments'))) { + logger('diaspora_comment: Ignoring this author.'); + return 202; + } + + $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($search_guid) + ); + if($r) { + logger('diaspora_comment: our comment just got relayed back to us (or there was a guid collision) : ' . $guid); + return; + } + + /* How Diaspora performs comment signature checking: -- cgit v1.2.3 From fc52536ce70774b24e6f38114ff1e46f392eb983 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 19 Feb 2015 15:07:41 -0800 Subject: diaspora: move reshare encapsulation after tag parsing, since it seriously screws up the tag parser and reshares end up with a lot of unlinked tags. --- include/diaspora.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'include/diaspora.php') diff --git a/include/diaspora.php b/include/diaspora.php index d2e27aafe..6523630f6 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1067,24 +1067,13 @@ function diaspora_reshare($importer,$xml,$msg) { $orig_author_photo = $person['xchan_photo_m']; } - $newbody = "[share author='" . urlencode($orig_author_name) - . "' profile='" . $orig_author_link - . "' avatar='" . $orig_author_photo - . "' link='" . $orig_url - . "' posted='" . datetime_convert('UTC','UTC',unxmlify($source_xml->post->status_message->created_at)) - . "' message_id='" . unxmlify($source_xml->post->status_message->guid) - . "']" . $body . "[/share]"; - $created = unxmlify($xml->created_at); $private = ((unxmlify($xml->public) == 'false') ? 1 : 0); $datarray = array(); - $str_tags = ''; - - $tags = get_tags($newbody); - + $tags = get_tags($body); if(count($tags)) { @@ -1116,7 +1105,7 @@ function diaspora_reshare($importer,$xml,$msg) { } } - $cnt = preg_match_all('/@\[url=(.*?)\](.*?)\[\/url\]/ism',$newbody,$matches,PREG_SET_ORDER); + $cnt = preg_match_all('/@\[url=(.*?)\](.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER); if($cnt) { foreach($matches as $mtch) { $datarray['term'][] = array( @@ -1129,6 +1118,16 @@ function diaspora_reshare($importer,$xml,$msg) { } } + + $newbody = "[share author='" . urlencode($orig_author_name) + . "' profile='" . $orig_author_link + . "' avatar='" . $orig_author_photo + . "' link='" . $orig_url + . "' posted='" . datetime_convert('UTC','UTC',unxmlify($source_xml->post->status_message->created_at)) + . "' message_id='" . unxmlify($source_xml->post->status_message->guid) + . "']" . $body . "[/share]"; + + $plink = service_plink($contact,$guid); $datarray['uid'] = $importer['channel_id']; -- cgit v1.2.3 From 8db367754621c7ee81c3157785a914cf8627d7b2 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 19 Feb 2015 16:29:49 -0800 Subject: Diaspora tag replacement was wretchedly buggy. Use our standard tag replacement calls instead. --- include/diaspora.php | 156 +++++++++------------------------------------------ 1 file changed, 27 insertions(+), 129 deletions(-) (limited to 'include/diaspora.php') diff --git a/include/diaspora.php b/include/diaspora.php index 6523630f6..553c7474c 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -841,68 +841,25 @@ function diaspora_post($importer,$xml,$msg) { $datarray = array(); - $tags = get_tags($body); - - - if(count($tags)) { + // Look for tags and linkify them + $results = linkify_tags(get_app(), $body, $importer['channel_id']); + if($results) { $datarray['term'] = array(); - - foreach($tags as $tag) { - if(strpos($tag,'#') === 0) { - if((strpos($tag,'[url=')) || (strpos($tag,'[zrl'))) - continue; - - // don't link tags that are already embedded in links - - if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body)) - continue; - 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); - + foreach($results as $result) { + $success = $result['success']; + if($success['replaced']) { $datarray['term'][] = array( 'uid' => $importer['channel_id'], - 'type' => TERM_HASHTAG, + 'type' => $success['termtype'], 'otype' => TERM_OBJ_POST, - 'term' => $basetag, - 'url' => z_root() . '/search?tag=' . rawurlencode($basetag) + 'term' => $success['term'], + 'url' => $success['url'] ); } } } - $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] - ); - } - } - - $cnt = preg_match_all('/@\[zrl=(.*?)\](.*?)\[\/zrl\]/ism',$body,$matches,PREG_SET_ORDER); - if($cnt) { - foreach($matches as $mtch) { - // don't include plustags in the term - $term = ((substr($mtch[2],-1,1) === '+') ? substr($mtch[2],0,-1) : $mtch[2]); - $datarray['term'][] = array( - 'uid' => $importer['channel_id'], - 'type' => TERM_MENTION, - 'otype' => TERM_OBJ_POST, - 'term' => $term, - 'url' => $mtch[1] - ); - } - } - - $plink = service_plink($contact,$guid); @@ -1053,12 +1010,6 @@ function diaspora_reshare($importer,$xml,$msg) { logger('message length exceeds max_import_size: truncated'); } - - //if(! $body) { - // logger('diaspora_reshare: empty body: source= ' . $x); - // return; - //} - $person = find_diaspora_person_by_handle($orig_author); if($person) { @@ -1073,52 +1024,25 @@ function diaspora_reshare($importer,$xml,$msg) { $datarray = array(); - $tags = get_tags($body); - - if(count($tags)) { + // Look for tags and linkify them + $results = linkify_tags(get_app(), $body, $importer['channel_id']); + if($results) { $datarray['term'] = array(); - - foreach($tags as $tag) { - if(strpos($tag,'#') === 0) { - if((strpos($tag,'[url=')) || (strpos($tag,'[zrl'))) - continue; - - // don't link tags that are already embedded in links - - if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$newbody)) - continue; - if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$newbody)) - continue; - - $basetag = str_replace('_',' ',substr($tag,1)); - $newbody = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$newbody); - + foreach($results as $result) { + $success = $result['success']; + if($success['replaced']) { $datarray['term'][] = array( 'uid' => $importer['channel_id'], - 'type' => TERM_HASHTAG, + 'type' => $success['termtype'], 'otype' => TERM_OBJ_POST, - 'term' => $basetag, - 'url' => z_root() . '/search?tag=' . rawurlencode($basetag) + 'term' => $success['term'], + 'url' => $success['url'] ); } } } - $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] - ); - } - } - - $newbody = "[share author='" . urlencode($orig_author_name) . "' profile='" . $orig_author_link . "' avatar='" . $orig_author_photo @@ -1396,51 +1320,25 @@ function diaspora_comment($importer,$xml,$msg) { $datarray = array(); - $tags = get_tags($body); - - if(count($tags)) { + // Look for tags and linkify them + $results = linkify_tags(get_app(), $body, $importer['channel_id']); + if($results) { $datarray['term'] = array(); - - foreach($tags as $tag) { - if(strpos($tag,'#') === 0) { - if((strpos($tag,'[url=')) || (strpos($tag,'[zrl'))) - continue; - - // don't link tags that are already embedded in links - - if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body)) - continue; - 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); - + foreach($results as $result) { + $success = $result['success']; + if($success['replaced']) { $datarray['term'][] = array( 'uid' => $importer['channel_id'], - 'type' => TERM_HASHTAG, + 'type' => $success['termtype'], 'otype' => TERM_OBJ_POST, - 'term' => $basetag, - 'url' => z_root() . '/search?tag=' . rawurlencode($basetag) + 'term' => $success['term'], + 'url' => $success['url'] ); } } } - $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['uid'] = $importer['channel_id']; $datarray['verb'] = ACTIVITY_POST; $datarray['mid'] = $guid; -- cgit v1.2.3 From b5683bfac4fd5e0e6cc15995c5c4f574e54e33da Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 8 Mar 2015 14:11:38 -0700 Subject: change default affinity (abook_closeness) to 80 for all new connections going forward (was 99). This way it can be adjusted down later without requiring you to change all your existing connections upward (since your existing connections are likely all sitting at 99 at the moment). The default setting is also configurable with a pconfig system.new_abook_closeness --- include/diaspora.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'include/diaspora.php') diff --git a/include/diaspora.php b/include/diaspora.php index 553c7474c..7295b4261 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -709,13 +709,19 @@ function diaspora_request($importer,$xml) { $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; + + $closeness = get_pconfig($importer['channel_id'],'system','new_abook_closeness'); + if($closeness === false) + $closeness = 80; + + $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_my_perms, abook_their_perms, abook_closeness, abook_rating, abook_created, abook_updated, abook_connected, abook_dob, abook_flags) values ( %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', %d )", intval($importer['channel_account_id']), intval($importer['channel_id']), dbesc($ret['xchan_hash']), intval($default_perms), intval($their_perms), - intval(99), + intval($closeness), intval(0), dbesc(datetime_convert()), dbesc(datetime_convert()), -- cgit v1.2.3 From 35fc14d6ab286a20bc8c510733c46cbd5f0d9676 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 11 Mar 2015 15:11:57 -0700 Subject: don't relay diaspora comments to sys channel --- include/diaspora.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include/diaspora.php') diff --git a/include/diaspora.php b/include/diaspora.php index 7295b4261..da55b8fb6 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1287,6 +1287,12 @@ function diaspora_comment($importer,$xml,$msg) { // our post, so he/she must be a contact of ours and his/her public key // should be in $msg['key'] + if($importer['system']) { + // don't relay to the sys channel + logger('diaspora_comment: relay to sys channel blocked.'); + return; + } + $author_signature = base64_decode($author_signature); if(! rsa_verify($signed_data,$author_signature,$key,'sha256')) { -- cgit v1.2.3 From f458c29a2bd3cadfc17324e35a9367c61d9bb19f Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 13 Mar 2015 14:48:44 -0700 Subject: invoke tgroup_check() on diaspora posts/comments in case the recipient is a forum with channel_w_stream permissions restricted. --- include/diaspora.php | 53 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) (limited to 'include/diaspora.php') diff --git a/include/diaspora.php b/include/diaspora.php index da55b8fb6..e3bfc2806 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -805,11 +805,6 @@ function diaspora_post($importer,$xml,$msg) { } - if((! $importer['system']) && (! perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'send_stream'))) { - logger('diaspora_post: Ignoring this author.'); - return 202; - } - $search_guid = ((strlen($guid) == 64) ? $guid . '%' : $guid); $r = q("SELECT id FROM item WHERE uid = %d AND mid like '%s' LIMIT 1", @@ -889,6 +884,15 @@ function diaspora_post($importer,$xml,$msg) { $datarray['item_flags'] = ITEM_THREAD_TOP; $datarray['item_unseen'] = 1; + + $tgroup = tgroup_check($importer['channel_id'],$datarray); + + if((! $importer['system']) && (! perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'send_stream')) && (! $tgroup)) { + logger('diaspora_post: Ignoring this author.'); + return 202; + } + + $result = item_store($datarray); return; @@ -955,11 +959,6 @@ function diaspora_reshare($importer,$xml,$msg) { if(! $contact) return; - if((! $importer['system']) && (! perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'send_stream'))) { - logger('diaspora_reshare: Ignoring this author: ' . $diaspora_handle . ' ' . print_r($xml,true)); - return 202; - } - $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']), @@ -1072,6 +1071,15 @@ function diaspora_reshare($importer,$xml,$msg) { $datarray['app'] = 'Diaspora'; + + $tgroup = tgroup_check($importer['channel_id'],$datarray); + + if((! $importer['system']) && (! perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'send_stream')) && (! $tgroup)) { + logger('diaspora_post: Ignoring this author.'); + return 202; + } + + $result = item_store($datarray); return; @@ -1229,15 +1237,6 @@ function diaspora_comment($importer,$xml,$msg) { if(intval($parent_item['item_private'])) $pubcomment = 0; - // So basically if something arrives at the sys channel it's by definition public and we allow it. - // If $pubcomment and the parent was public, we allow it. - // In all other cases, honour the permissions for this Diaspora connection - - if((! $importer['system']) && (! $pubcomment) && (! perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'post_comments'))) { - logger('diaspora_comment: Ignoring this author.'); - return 202; - } - $search_guid = $guid; if(strlen($guid) == 64) $search_guid = $guid . '%'; @@ -1382,6 +1381,22 @@ function diaspora_comment($importer,$xml,$msg) { $datarray['diaspora_meta'] = json_encode(crypto_encapsulate(json_encode($x),$key)); } + + + // So basically if something arrives at the sys channel it's by definition public and we allow it. + // If $pubcomment and the parent was public, we allow it. + // In all other cases, honour the permissions for this Diaspora connection + + $tgroup = tgroup_check($importer['channel_id'],$datarray); + + if((! $importer['system']) && (! $pubcomment) && (! perm_is_allowed($importer['channel_id'],$contact['xchan_hash'],'post_comments')) && (! $tgroup)) { + logger('diaspora_comment: Ignoring this author.'); + return 202; + } + + + + $result = item_store($datarray); if($result && $result['success']) -- cgit v1.2.3 From b76cdf82d298c92bdf5a59b6bf6b55da504a46ea Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 13 Mar 2015 19:24:17 -0700 Subject: create terms for Diaspora mention tags - which in Diaspora are handled differently than other tag links and have to be done separately; they aren't processed by linkify_tags which handles all of our other tag processing. Also move the abook_channel clause in mod_network to the join statement. This works fine in mysql and achievies the desired result. I hope postgres can handle an expression as a join clause. --- include/diaspora.php | 100 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 3 deletions(-) (limited to 'include/diaspora.php') diff --git a/include/diaspora.php b/include/diaspora.php index e3bfc2806..1e0e48a86 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -845,8 +845,9 @@ function diaspora_post($importer,$xml,$msg) { // Look for tags and linkify them $results = linkify_tags(get_app(), $body, $importer['channel_id']); + $datarray['term'] = array(); + if($results) { - $datarray['term'] = array(); foreach($results as $result) { $success = $result['success']; if($success['replaced']) { @@ -861,6 +862,37 @@ function diaspora_post($importer,$xml,$msg) { } } + $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] + ); + } + } + + $cnt = preg_match_all('/@\[zrl=(.*?)\](.*?)\[\/zrl\]/ism',$body,$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + // don't include plustags in the term + $term = ((substr($mtch[2],-1,1) === '+') ? substr($mtch[2],0,-1) : $mtch[2]); + $datarray['term'][] = array( + 'uid' => $importer['channel_id'], + 'type' => TERM_MENTION, + 'otype' => TERM_OBJ_POST, + 'term' => $term, + 'url' => $mtch[1] + ); + } + } + + + + $plink = service_plink($contact,$guid); @@ -1032,8 +1064,9 @@ function diaspora_reshare($importer,$xml,$msg) { // Look for tags and linkify them $results = linkify_tags(get_app(), $body, $importer['channel_id']); + $datarray['term'] = array(); + if($results) { - $datarray['term'] = array(); foreach($results as $result) { $success = $result['success']; if($success['replaced']) { @@ -1048,6 +1081,38 @@ function diaspora_reshare($importer,$xml,$msg) { } } + $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] + ); + } + } + + $cnt = preg_match_all('/@\[zrl=(.*?)\](.*?)\[\/zrl\]/ism',$body,$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + // don't include plustags in the term + $term = ((substr($mtch[2],-1,1) === '+') ? substr($mtch[2],0,-1) : $mtch[2]); + $datarray['term'][] = array( + 'uid' => $importer['channel_id'], + 'type' => TERM_MENTION, + 'otype' => TERM_OBJ_POST, + 'term' => $term, + 'url' => $mtch[1] + ); + } + } + + + + + $newbody = "[share author='" . urlencode($orig_author_name) . "' profile='" . $orig_author_link . "' avatar='" . $orig_author_photo @@ -1334,8 +1399,9 @@ function diaspora_comment($importer,$xml,$msg) { // Look for tags and linkify them $results = linkify_tags(get_app(), $body, $importer['channel_id']); + $datarray['term'] = array(); + if($results) { - $datarray['term'] = array(); foreach($results as $result) { $success = $result['success']; if($success['replaced']) { @@ -1350,6 +1416,34 @@ function diaspora_comment($importer,$xml,$msg) { } } + $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] + ); + } + } + + $cnt = preg_match_all('/@\[zrl=(.*?)\](.*?)\[\/zrl\]/ism',$body,$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + // don't include plustags in the term + $term = ((substr($mtch[2],-1,1) === '+') ? substr($mtch[2],0,-1) : $mtch[2]); + $datarray['term'][] = array( + 'uid' => $importer['channel_id'], + 'type' => TERM_MENTION, + 'otype' => TERM_OBJ_POST, + 'term' => $term, + 'url' => $mtch[1] + ); + } + } + $datarray['uid'] = $importer['channel_id']; $datarray['verb'] = ACTIVITY_POST; $datarray['mid'] = $guid; -- cgit v1.2.3 From c024668cf226da7211aaa8cdd04293cf00b8901c Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 24 Mar 2015 02:36:45 -0700 Subject: catche edge case of tag "@abcdef +1", which tags the first entry in your abook, regardless of abcdef. This holds true for other similar patterns as well. --- include/diaspora.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/diaspora.php') diff --git a/include/diaspora.php b/include/diaspora.php index 1e0e48a86..405fa1e40 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -843,7 +843,7 @@ function diaspora_post($importer,$xml,$msg) { // Look for tags and linkify them - $results = linkify_tags(get_app(), $body, $importer['channel_id']); + $results = linkify_tags(get_app(), $body, $importer['channel_id'], true); $datarray['term'] = array(); @@ -1062,7 +1062,7 @@ function diaspora_reshare($importer,$xml,$msg) { $datarray = array(); // Look for tags and linkify them - $results = linkify_tags(get_app(), $body, $importer['channel_id']); + $results = linkify_tags(get_app(), $body, $importer['channel_id'], true); $datarray['term'] = array(); @@ -1397,7 +1397,7 @@ function diaspora_comment($importer,$xml,$msg) { $datarray = array(); // Look for tags and linkify them - $results = linkify_tags(get_app(), $body, $importer['channel_id']); + $results = linkify_tags(get_app(), $body, $importer['channel_id'], true); $datarray['term'] = array(); -- cgit v1.2.3 From c29d3fc08ae4b5df72c3958ac790a56815413051 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 29 Mar 2015 18:42:05 -0700 Subject: mod_connections ajax failure see http://stackoverflow.com/questions/14347611/jquery-client-side-template-syntax-error-unrecognized-expression --- include/diaspora.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'include/diaspora.php') diff --git a/include/diaspora.php b/include/diaspora.php index 405fa1e40..75eac7681 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -698,6 +698,57 @@ function diaspora_request($importer,$xml) { return; } + +//FIXME +/* + if(feature_enabled($channel['channel_id'],'premium_channel')) { + $myaddr = $importer['channel_address'] . '@' . get_app()->get_hostname(); + $cnv = random_string(); + $mid = random_string(); + + $msg = t('You have started sharing with a Redmatrix premium channel.'); + $msg .= t('Redmatrix premium channels are not available for sharing with Diaspora members. This sharing request has been blocked.') . "\r"; + $msg .= t('Please do not reply to this message, as this channel is not sharing with you and any reply will not be seen by the recipient.') . "\r"; + + $created = datetime_convert('UTC','UTC',$item['created'],'Y-m-d H:i:s \U\T\C'); + $signed_text = $mid . ';' . $cnv . ';' . $msg . ';' + . $created . ';' . $myaddr . ';' . $cnv; + + $sig = base64_encode(rsa_sign($signed_text,$importer['channel_prvkey'],'sha256')); + + $conv = array( + 'guid' => xmlify($cnv), + 'subject' => xmlify(t('Sharing request failed.')), + 'created_at' => xmlify($created), + 'diaspora_handle' => xmlify($myaddr), + 'participant_handles' => xmlify($myaddr . ';' . $sender_handle) + ); + + $msg = array( + 'guid' => xmlify($mid), + 'parent_guid' => xmlify($cnv), + 'parent_author_signature' => xmlify($sig), + 'author_signature' => xmlify($sig), + 'text' => xmlify($msg), + 'created_at' => xmlify($created), + 'diaspora_handle' => xmlify($myaddr), + 'conversation_guid' => xmlify($cnv) + ); + + $conv['messages'] = array($msg); + $tpl = get_markup_template('diaspora_conversation.tpl'); + $xmsg = replace_macros($tpl, array('$conv' => $conv)); + + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg,$importer,$ret,$importer['channel_prvkey'],$ret['xchan_pubkey'],false))); + + diaspora_transmit($importer,$ret,$slap,false); + return; + } + +*/ +// End FIXME + + $role = get_pconfig($channel['channel_id'],'system','permissions_role'); if($role) { $x = get_role_perms($role); -- cgit v1.2.3