aboutsummaryrefslogtreecommitdiffstats
path: root/include/diaspora.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/diaspora.php')
-rwxr-xr-xinclude/diaspora.php228
1 files changed, 123 insertions, 105 deletions
diff --git a/include/diaspora.php b/include/diaspora.php
index d2e27aafe..1e0e48a86 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()),
@@ -799,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",
@@ -841,34 +842,21 @@ function diaspora_post($importer,$xml,$msg) {
$datarray = array();
- $tags = get_tags($body);
+ // Look for tags and linkify them
+ $results = linkify_tags(get_app(), $body, $importer['channel_id']);
+ $datarray['term'] = array();
- if(count($tags)) {
-
- $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);
-
+ if($results) {
+ 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']
);
}
}
@@ -903,6 +891,8 @@ function diaspora_post($importer,$xml,$msg) {
}
+
+
$plink = service_plink($contact,$guid);
@@ -926,6 +916,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;
@@ -992,11 +991,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']),
@@ -1053,12 +1047,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) {
@@ -1067,56 +1055,33 @@ 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);
-
+ // Look for tags and linkify them
+ $results = linkify_tags(get_app(), $body, $importer['channel_id']);
- if(count($tags)) {
-
- $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);
+ $datarray['term'] = array();
+ if($results) {
+ 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',$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 +1094,34 @@ function diaspora_reshare($importer,$xml,$msg) {
}
}
+ $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
+ . "' 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'];
@@ -1143,6 +1136,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;
@@ -1300,15 +1302,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 . '%';
@@ -1358,6 +1351,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')) {
@@ -1397,33 +1396,21 @@ function diaspora_comment($importer,$xml,$msg) {
$datarray = array();
- $tags = get_tags($body);
-
- if(count($tags)) {
-
- $datarray['term'] = array();
-
- foreach($tags as $tag) {
- if(strpos($tag,'#') === 0) {
- if((strpos($tag,'[url=')) || (strpos($tag,'[zrl')))
- continue;
+ // Look for tags and linkify them
+ $results = linkify_tags(get_app(), $body, $importer['channel_id']);
- // 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);
+ $datarray['term'] = array();
+ if($results) {
+ 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']
);
}
}
@@ -1442,6 +1429,21 @@ function diaspora_comment($importer,$xml,$msg) {
}
}
+ $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;
@@ -1473,6 +1475,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'])