* @param string $element Element name for the activity
* @param string $activity activity value
* @param int $uriid Uri-Id of the post
- * @return DOMElement XML activity object
+ * @return DOMElement|false XML activity object or false on error
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @todo Find proper type-hints
*/
private static function createActivity(DOMDocument $doc, string $element, string $activity, int $uriid)
{
- if ($activity) {
- $entry = $doc->createElement($element);
+ if (!$activity) {
+ return false;
+ }
- $r = XML::parseString($activity);
- if (!$r) {
- return false;
- }
+ $entry = $doc->createElement($element);
- if ($r->type) {
- XML::addElement($doc, $entry, "activity:object-type", $r->type);
- }
+ $r = XML::parseString($activity);
+ if (!$r) {
+ return false;
+ }
- if ($r->id) {
- XML::addElement($doc, $entry, "id", $r->id);
- }
+ if ($r->type) {
+ XML::addElement($doc, $entry, "activity:object-type", $r->type);
+ }
- if ($r->title) {
- XML::addElement($doc, $entry, "title", $r->title);
- }
+ if ($r->id) {
+ XML::addElement($doc, $entry, "id", $r->id);
+ }
- if ($r->link) {
- if (substr($r->link, 0, 1) == '<') {
- if (strstr($r->link, '&') && (! strstr($r->link, '&'))) {
- $r->link = str_replace('&', '&', $r->link);
- }
+ if ($r->title) {
+ XML::addElement($doc, $entry, "title", $r->title);
+ }
- $r->link = preg_replace('/\<link(.*?)\"\>/', '<link$1"/>', $r->link);
-
- // XML does need a single element as root element so we add a dummy element here
- $data = XML::parseString("<dummy>" . $r->link . "</dummy>");
- if (is_object($data)) {
- foreach ($data->link as $link) {
- $attributes = [];
- foreach ($link->attributes() as $parameter => $value) {
- $attributes[$parameter] = $value;
- }
- XML::addElement($doc, $entry, "link", "", $attributes);
+ if ($r->link) {
+ if (substr($r->link, 0, 1) == '<') {
+ if (strstr($r->link, '&') && (! strstr($r->link, '&'))) {
+ $r->link = str_replace('&', '&', $r->link);
+ }
+
+ $r->link = preg_replace('/\<link(.*?)\"\>/', '<link$1"/>', $r->link);
+
+ // XML does need a single element as root element so we add a dummy element here
+ $data = XML::parseString("<dummy>" . $r->link . "</dummy>");
+ if (is_object($data)) {
+ foreach ($data->link as $link) {
+ $attributes = [];
+ foreach ($link->attributes() as $parameter => $value) {
+ $attributes[$parameter] = $value;
}
+ XML::addElement($doc, $entry, "link", "", $attributes);
}
- } else {
- $attributes = ["rel" => "alternate", "type" => "text/html", "href" => $r->link];
- XML::addElement($doc, $entry, "link", "", $attributes);
}
+ } else {
+ $attributes = ["rel" => "alternate", "type" => "text/html", "href" => $r->link];
+ XML::addElement($doc, $entry, "link", "", $attributes);
}
- if ($r->content) {
- XML::addElement($doc, $entry, "content", BBCode::convertForUriId($uriid, $r->content, BBCode::EXTERNAL), ["type" => "html"]);
- }
-
- return $entry;
+ }
+ if ($r->content) {
+ XML::addElement($doc, $entry, "content", BBCode::convertForUriId($uriid, $r->content, BBCode::EXTERNAL), ["type" => "html"]);
}
- return false;
+ return $entry;
}
/**
// Check if the message is wanted
if (!self::isSolicitedMessage($item, $importer)) {
DBA::delete('item-uri', ['uri' => $item['uri']]);
- return 403;
+ return;
}
// Get the type of the item (Top level post, reply or remote reply)
Item::distribute($posted_id);
}
- return true;
+ return;
}
} else { // $entrytype == self::TOP_LEVEL
if (($item['uid'] != 0) && !Contact::isSharing($item['owner-id'], $item['uid']) && !Contact::isSharing($item['author-id'], $item['uid'])) {
}
if (!$uri || !$importer['id']) {
- return false;
+ return;
}
$condition = ['uri' => $uri, 'uid' => $importer['importer_uid']];
* @param string $xml urldecoded Diaspora salmon
* @param string $privKey The private key of the importer
*
- * @return array
+ * @return array|false array with decoded data or false on error
* 'message' -> decoded Diaspora XML message
* 'author' -> author diaspora handle
* 'key' -> author public key (converted to pkcs#8)
* @param string $server The url of the server
* @param int $level Endless loop prevention
*
- * @return array
+ * @return array|false The message as array or false on error
* 'message' => The message XML
* 'author' => The author handle
* 'key' => The public key of the author
// without a public key nothing will work
if (!$pubkey) {
DI::logger()->notice('pubkey missing: contact id: ' . $contact['id']);
- return false;
+ return '';
}
$aes_key = random_bytes(32);
$encrypted_key_bundle = '';
if (!@openssl_public_encrypt($json, $encrypted_key_bundle, $pubkey)) {
- return false;
+ return '';
}
$json_object = json_encode(