X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdiaspora.php;h=93fe2a472feb47268375709fd4f771614c8e7634;hb=cd1f3cde00612a4798fc0c42fd5daa37ff393964;hp=d61ec016c783ba45f80e76f1417831d806f5fee5;hpb=7e83ba090f7ff3889aec8a2e8f2b578210a66dc8;p=friendica.git diff --git a/include/diaspora.php b/include/diaspora.php index d61ec016c7..93fe2a472f 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -14,6 +14,7 @@ require_once('include/queue_fn.php'); require_once('include/lock.php'); require_once('include/threads.php'); require_once('mod/share.php'); +require_once('include/enotify.php'); function diaspora_dispatch_public($msg) { @@ -728,7 +729,7 @@ function diaspora_request($importer,$xml) { require_once('include/Photo.php'); - $photos = import_profile_photo($contact_record['photo'],$importer['uid'],$contact_record['id']); + update_contact_avatar($contact_record['photo'],$importer['uid'],$contact_record['id']); // technically they are sharing with us (CONTACT_IS_SHARING), // but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX @@ -739,26 +740,17 @@ function diaspora_request($importer,$xml) { else $new_relation = CONTACT_IS_FOLLOWER; - $r = q("UPDATE `contact` SET - `photo` = '%s', - `thumb` = '%s', - `micro` = '%s', - `rel` = %d, + $r = q("UPDATE `contact` SET `rel` = %d, `name-date` = '%s', `uri-date` = '%s', - `avatar-date` = '%s', `blocked` = 0, `pending` = 0, `writable` = 1 WHERE `id` = %d ", - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), intval($new_relation), dbesc(datetime_convert()), dbesc(datetime_convert()), - dbesc(datetime_convert()), intval($contact_record['id']) ); @@ -826,6 +818,23 @@ function diaspora_plink($addr, $guid) { return 'https://'.substr($addr,strpos($addr,'@')+1).'/posts/'.$guid; } +function diaspora_repair_signature($signature, $handle = "", $level = 1) { + + if ($signature == "") + return($signature); + + if (base64_encode(base64_decode(base64_decode($signature))) == base64_decode($signature)) { + $signature = base64_decode($signature); + logger("Repaired double encoded signature from Diaspora/Hubzilla handle ".$handle." - level ".$level, LOGGER_DEBUG); + + // Do a recursive call to be able to fix even multiple levels + if ($level < 10) + $signature = diaspora_repair_signature($signature, $handle, ++$level); + } + + return($signature); +} + function diaspora_post($importer,$xml,$msg) { $a = get_app(); @@ -1565,62 +1574,22 @@ function diaspora_comment($importer,$xml,$msg) { //); //} - if(($parent_item['origin']) && (! $parent_author_signature)) { + // If we are the origin of the parent we store the original signature and notify our followers + if($parent_item['origin']) { + $author_signature_base64 = base64_encode($author_signature); + $author_signature_base64 = diaspora_repair_signature($author_signature_base64, $diaspora_handle); + 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($author_signature_base64), 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. - + // notify others proc_run('php','include/notifier.php','comment-import',$message_id); } - $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['uid']) - ); - - 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['uid'], - 'item' => $datarray, - 'link' => $a->get_baseurl().'/display/'.urlencode($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; - } - } return; } @@ -1775,7 +1744,6 @@ function diaspora_conversation($importer,$xml,$msg) { intval($conversation['id']) ); - require_once('include/enotify.php'); notification(array( 'type' => NOTIFY_MAIL, 'notify_flags' => $importer['notify-flags'], @@ -2226,21 +2194,21 @@ EOT; // ); //} - if(! $parent_author_signature) { + // If we are the origin of the parent we store the original signature and notify our followers + if($parent_item['origin']) { + $author_signature_base64 = base64_encode($author_signature); + $author_signature_base64 = diaspora_repair_signature($author_signature_base64, $diaspora_handle); + 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($author_signature_base64), 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. The parent_item['origin'] indicates the message was created on our system - if(($parent_item['origin']) && (! $parent_author_signature)) + // notify others proc_run('php','include/notifier.php','comment-import',$message_id); + } return; } @@ -2336,8 +2304,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) { return; } - } - else { + } else { $sig_decode = base64_decode($sig); @@ -2371,7 +2338,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) { intval($r[0]['parent']) ); if(count($p)) { - if(($p[0]['origin']) && (! $parent_author_signature)) { + if($p[0]['origin']) { q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", $r[0]['id'], dbesc($signed_data), @@ -2456,7 +2423,7 @@ function diaspora_profile($importer,$xml,$msg) { require_once('include/Photo.php'); - $images = import_profile_photo($image_url,$importer['uid'],$contact['id']); + update_contact_avatar($image_url,$importer['uid'],$contact['id']); // Generic birthday. We don't know the timezone. The year is irrelevant. @@ -2474,15 +2441,12 @@ function diaspora_profile($importer,$xml,$msg) { /// @TODO Update name on item['author-name'] if the name changed. See consume_feed() /// (Not doing this currently because D* protocol is scheduled for revision soon). - $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d", + $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', `bd` = '%s', + `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($name), dbesc($nick), dbesc($diaspora_handle), dbesc(datetime_convert()), - dbesc($image_url), - dbesc($images[1]), - dbesc($images[2]), - dbesc(datetime_convert()), dbesc($birthday), dbesc($location), dbesc($about), @@ -2819,7 +2783,7 @@ 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 = $positive . ';' . $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $myaddr; else $signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $myaddr; @@ -2911,10 +2875,6 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $authorsig = $orig_sign['signature']; $handle = $orig_sign['signer']; - // Friendica servers lower than 3.5 had double encoded the signature ... - if (substr($authorsig, -1, 1) != "=") - $authorsig = base64_decode($authorsig); - // Split the signed text $signed_parts = explode(";", $signed_text);