aboutsummaryrefslogtreecommitdiffstats
path: root/mod/item.php
diff options
context:
space:
mode:
authorZach Prezkuta <fermion@gmx.com>2012-06-09 18:39:21 -0600
committerZach Prezkuta <fermion@gmx.com>2012-06-25 19:03:03 -0600
commit8bb7ab88fb8a1bfef198f6a2aff53a15e667aa59 (patch)
tree7947b8b421da4e76758d1d04307dd59750d4b0ec /mod/item.php
parentfad2679c7e2ac32027ffd42064213ab48762dda2 (diff)
downloadvolse-hubzilla-8bb7ab88fb8a1bfef198f6a2aff53a15e667aa59.tar.gz
volse-hubzilla-8bb7ab88fb8a1bfef198f6a2aff53a15e667aa59.tar.bz2
volse-hubzilla-8bb7ab88fb8a1bfef198f6a2aff53a15e667aa59.zip
Clean up the Diaspora connectivity:
- Move Diaspora code into separate functions to make it more modular - Create more checks for whether Diaspora connectivity has been enabled
Diffstat (limited to 'mod/item.php')
-rw-r--r--mod/item.php58
1 files changed, 40 insertions, 18 deletions
diff --git a/mod/item.php b/mod/item.php
index 54f9fc06a..5c179bc7a 100644
--- a/mod/item.php
+++ b/mod/item.php
@@ -728,26 +728,13 @@ function item_post(&$a) {
}
- // We won't be able to sign Diaspora comments for authenticated visitors - we don't have their private key
-
- if($self) {
- require_once('include/bb2diaspora.php');
- $signed_body = html_entity_decode(bb2diaspora($datarray['body']));
- $myaddr = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
- if($datarray['verb'] === ACTIVITY_LIKE)
- $signed_text = $datarray['guid'] . ';' . 'Post' . ';' . $parent_item['guid'] . ';' . 'true' . ';' . $myaddr;
- else
- $signed_text = $datarray['guid'] . ';' . $parent_item['guid'] . ';' . $signed_body . ';' . $myaddr;
- $authorsig = base64_encode(rsa_sign($signed_text,$a->user['prvkey'],'sha256'));
+ // Store the comment signature information in case we need to relay to Diaspora
+ // May want to have this run for remote users too, in which case the function needs to be
+ // expanded
+ if($self)
+ store_diaspora_comment_sig($datarray, $a->user, $a->get_baseurl(), $parent_item, $post_id);
- 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($myaddr)
- );
- }
}
else {
$parent = $post_id;
@@ -1038,3 +1025,38 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
return array('replaced' => $replaced, 'contact' => $r[0]);
}
+
+
+function store_diaspora_comment_sig($datarray, $user, $baseurl, $parent_item, $post_id) {
+ // We won't be able to sign Diaspora comments for authenticated visitors - we don't have their private key
+
+ // May want to have this run for remote users too, in which case the function needs to be
+ // expanded
+
+ $enabled = intval(get_config('system','diaspora_enabled'));
+ if(! $enabled) {
+ return;
+ }
+
+
+ logger('mod_item: storing diaspora comment signature');
+
+ require_once('include/bb2diaspora.php');
+ $signed_body = html_entity_decode(bb2diaspora($datarray['body']));
+ $myaddr = $user['nickname'] . '@' . substr($baseurl, strpos($baseurl,'://') + 3);
+ if($datarray['verb'] === ACTIVITY_LIKE)
+ $signed_text = $datarray['guid'] . ';' . 'Post' . ';' . $parent_item['guid'] . ';' . 'true' . ';' . $myaddr;
+ else
+ $signed_text = $datarray['guid'] . ';' . $parent_item['guid'] . ';' . $signed_body . ';' . $myaddr;
+
+ $authorsig = base64_encode(rsa_sign($signed_text,$user['prvkey'],'sha256'));
+
+ 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($myaddr)
+ );
+
+ return;
+}