X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FDFRN.php;h=9f690847a7bb9d543777c6ce9f57df3c006c40e0;hb=85c8bf022841fb53a42e012d2e90dd23f56df2ab;hp=6a839813712f14093e28a718bed47e753d28d7c6;hpb=6871481a7858495c204088e17beb5e7b4be2075a;p=friendica.git diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 6a83981371..9f690847a7 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -10,6 +10,7 @@ namespace Friendica\Protocol; use Friendica\App; use Friendica\Content\OEmbed; +use Friendica\Content\Text\BBCode; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; @@ -26,10 +27,9 @@ use Friendica\Model\User; use Friendica\Object\Image; use Friendica\Protocol\OStatus; use Friendica\Util\Crypto; +use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\XML; -use Friendica\Content\Text\BBCode; - use dba; use DOMDocument; use DOMXPath; @@ -39,9 +39,7 @@ use HTMLPurifier_Config; require_once 'boot.php'; require_once 'include/dba.php'; require_once "include/enotify.php"; -require_once "include/threads.php"; require_once "include/items.php"; -require_once "include/tags.php"; require_once "include/event.php"; require_once "include/text.php"; require_once "include/html2bbcode.php"; @@ -228,7 +226,7 @@ class DFRN } } - $check_date = datetime_convert('UTC', 'UTC', $last_update, 'Y-m-d H:i:s'); + $check_date = DateTimeFormat::utc($last_update); $r = q( "SELECT `item`.*, `item`.`id` AS `item_id`, @@ -420,7 +418,7 @@ class DFRN XML::addElement($doc, $mail, "dfrn:id", $item['uri']); XML::addElement($doc, $mail, "dfrn:in-reply-to", $item['parent-uri']); - XML::addElement($doc, $mail, "dfrn:sentdate", datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', ATOM_TIME)); + XML::addElement($doc, $mail, "dfrn:sentdate", DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM)); XML::addElement($doc, $mail, "dfrn:subject", $item['title']); XML::addElement($doc, $mail, "dfrn:content", $item['body']); @@ -586,7 +584,7 @@ class DFRN /// @todo We need a way to transmit the different page flags like "PAGE_PRVGROUP" - XML::addElement($doc, $root, "updated", datetime_convert("UTC", "UTC", "now", ATOM_TIME)); + XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM)); $author = self::addAuthor($doc, $owner, $authorelement, $public); $root->appendChild($author); @@ -621,9 +619,9 @@ class DFRN $author = $doc->createElement($authorelement); - $namdate = datetime_convert('UTC', 'UTC', $owner['name-date'].'+00:00', ATOM_TIME); - $uridate = datetime_convert('UTC', 'UTC', $owner['uri-date'].'+00:00', ATOM_TIME); - $picdate = datetime_convert('UTC', 'UTC', $owner['avatar-date'].'+00:00', ATOM_TIME); + $namdate = DateTimeFormat::utc($owner['name-date'].'+00:00', DateTimeFormat::ATOM); + $uridate = DateTimeFormat::utc($owner['uri-date'].'+00:00', DateTimeFormat::ATOM); + $picdate = DateTimeFormat::utc($owner['avatar-date'].'+00:00', DateTimeFormat::ATOM); $attributes = []; @@ -902,7 +900,7 @@ class DFRN } if ($item['deleted']) { - $attributes = ["ref" => $item['uri'], "when" => datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)]; + $attributes = ["ref" => $item['uri'], "when" => DateTimeFormat::utc($item['edited'] . '+00:00', DateTimeFormat::ATOM)]; return XML::createElement($doc, "at:deleted-entry", "", $attributes); } @@ -930,7 +928,7 @@ class DFRN } // Remove the abstract element. It is only locally important. - $body = remove_abstract($body); + $body = BBCode::stripAbstract($body); if ($type == 'html') { $htmlbody = $body; @@ -982,8 +980,8 @@ class DFRN XML::addElement($doc, $entry, "id", $item["uri"]); XML::addElement($doc, $entry, "title", $item["title"]); - XML::addElement($doc, $entry, "published", datetime_convert("UTC", "UTC", $item["created"] . "+00:00", ATOM_TIME)); - XML::addElement($doc, $entry, "updated", datetime_convert("UTC", "UTC", $item["edited"] . "+00:00", ATOM_TIME)); + XML::addElement($doc, $entry, "published", DateTimeFormat::utc($item["created"] . "+00:00", DateTimeFormat::ATOM)); + XML::addElement($doc, $entry, "updated", DateTimeFormat::utc($item["edited"] . "+00:00", DateTimeFormat::ATOM)); // "dfrn:env" is used to read the content XML::addElement($doc, $entry, "dfrn:env", base64url_encode($body, true)); @@ -1387,7 +1385,7 @@ class DFRN "SELECT `id` FROM `event` WHERE `uid` = %d AND `cid` = %d AND `start` = '%s' AND `type` = '%s' LIMIT 1", intval($contact["uid"]), intval($contact["id"]), - dbesc(datetime_convert("UTC", "UTC", $birthday)), + dbesc(DateTimeFormat::utc($birthday)), dbesc("birthday") ); @@ -1405,10 +1403,10 @@ class DFRN VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", intval($contact["uid"]), intval($contact["id"]), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(datetime_convert("UTC", "UTC", $birthday)), - dbesc(datetime_convert("UTC", "UTC", $birthday . " + 1 day ")), + dbesc(DateTimeFormat::utcNow()), + dbesc(DateTimeFormat::utcNow()), + dbesc(DateTimeFormat::utc($birthday)), + dbesc(DateTimeFormat::utc($birthday . " + 1 day ")), dbesc($bdtext), dbesc($bdtext2), dbesc("birthday") @@ -1888,7 +1886,7 @@ class DFRN intval($suggest["cid"]), dbesc($suggest["body"]), dbesc($hash), - dbesc(datetime_convert()), + dbesc(DateTimeFormat::utcNow()), intval(0) ); @@ -2080,19 +2078,16 @@ class DFRN if (self::isEditedTimestampNewer($current, $item)) { // do not accept (ignore) an earlier edit than one we currently have. - if (datetime_convert("UTC", "UTC", $item["edited"]) < $current["edited"]) { + if (DateTimeFormat::utc($item["edited"]) < $current["edited"]) { return false; } $fields = ['title' => $item["title"], 'body' => $item["body"], - 'tag' => $item["tag"], 'changed' => datetime_convert(), - 'edited' => datetime_convert("UTC", "UTC", $item["edited"])]; + 'tag' => $item["tag"], 'changed' => DateTimeFormat::utcNow(), + 'edited' => DateTimeFormat::utc($item["edited"])]; $condition = ["`uri` = ? AND `uid` IN (0, ?)", $item["uri"], $importer["importer_uid"]]; - dba::update('item', $fields, $condition); - - create_tags_from_itemuri($item["uri"], $importer["importer_uid"]); - update_thread_uri($item["uri"], $importer["importer_uid"]); + Item::update($fields, $condition); $changed = true; @@ -2329,13 +2324,9 @@ class DFRN // extract tag, if not duplicate, add to parent item if ($xo->content) { - if (!(stristr($r[0]["tag"], trim($xo->content)))) { - q( - "UPDATE `item` SET `tag` = '%s' WHERE `id` = %d", - dbesc($r[0]["tag"] . (strlen($r[0]["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'), - intval($r[0]["id"]) - ); - create_tags_from_item($r[0]["id"]); + if (!stristr($r[0]["tag"], trim($xo->content))) { + $tag = $r[0]["tag"] . (strlen($r[0]["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'; + Item::update(['tag' => $tag], ['id' => $r[0]["id"]]); } } } @@ -2421,7 +2412,7 @@ class DFRN // Is there an existing item? if (DBM::is_result($current) && self::isEditedTimestampNewer($current[0], $item) - && (datetime_convert("UTC", "UTC", $item["edited"]) < $current[0]["edited"]) + && (DateTimeFormat::utc($item["edited"]) < $current[0]["edited"]) ) { logger("Item ".$item["uri"]." already existed.", LOGGER_DEBUG); return; @@ -2747,121 +2738,35 @@ class DFRN if ($attributes->name == "ref") { $uri = $attributes->textContent; } - if ($attributes->name == "when") { - $when = $attributes->textContent; - } - } - if ($when) { - $when = datetime_convert("UTC", "UTC", $when, "Y-m-d H:i:s"); - } else { - $when = datetime_convert("UTC", "UTC", "now", "Y-m-d H:i:s"); } if (!$uri || !$importer["id"]) { return false; } - /// @todo Only select the used fields - $r = q( - "SELECT `item`.*, `contact`.`self` FROM `item` INNER JOIN `contact` on `item`.`contact-id` = `contact`.`id` - WHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1", - dbesc($uri), - intval($importer["uid"]), - intval($importer["id"]) - ); - if (!DBM::is_result($r)) { + $condition = ["`uri` = ? AND `uid` = ? AND `contact-id` = ? AND NOT `file` LIKE '%[%'", + $uri, $importer["uid"], $importer["id"]]; + $item = dba::selectFirst('item', ['id'], $condition); + if (!DBM::is_result($item)) { logger("Item with uri " . $uri . " from contact " . $importer["id"] . " for user " . $importer["uid"] . " wasn't found.", LOGGER_DEBUG); return; - } else { - $item = $r[0]; - - $entrytype = self::getEntryType($importer, $item); - - if (!$item["deleted"]) { - logger('deleting item '.$item["id"].' uri='.$uri, LOGGER_DEBUG); - } else { - return; - } - - if ($item["object-type"] == ACTIVITY_OBJ_EVENT) { - logger("Deleting event ".$item["event-id"], LOGGER_DEBUG); - event_delete($item["event-id"]); - } - - if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { - $xo = XML::parseString($item["object"], false); - $xt = XML::parseString($item["target"], false); - - if ($xt->type == ACTIVITY_OBJ_NOTE) { - $i = q( - "SELECT `id`, `contact-id`, `tag` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", - dbesc($xt->id), - intval($importer["importer_uid"]) - ); - if (DBM::is_result($i)) { - // For tags, the owner cannot remove the tag on the author's copy of the post. - - $owner_remove = (($item["contact-id"] == $i[0]["contact-id"]) ? true: false); - $author_remove = (($item["origin"] && $item["self"]) ? true : false); - $author_copy = (($item["origin"]) ? true : false); + } - if ($owner_remove && $author_copy) { - return; - } - if ($author_remove || $owner_remove) { - $tags = explode(',', $i[0]["tag"]); - $newtags = []; - if (count($tags)) { - foreach ($tags as $tag) { - if (trim($tag) !== trim($xo->body)) { - $newtags[] = trim($tag); - } - } - } - q( - "UPDATE `item` SET `tag` = '%s' WHERE `id` = %d", - dbesc(implode(',', $newtags)), - intval($i[0]["id"]) - ); - create_tags_from_item($i[0]["id"]); - } - } - } - } + $entrytype = self::getEntryType($importer, $item); - if ($entrytype == DFRN_TOP_LEVEL) { - $r = q( - "UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', - `body` = '', `title` = '' - WHERE `parent-uri` = '%s' AND `uid` IN (0, %d)", - dbesc($when), - dbesc(datetime_convert()), - dbesc($uri), - intval($importer["uid"]) - ); - create_tags_from_itemuri($uri, $importer["uid"]); - Term::createFromItemURI($uri, $importer["uid"]); - update_thread_uri($uri, $importer["uid"]); - } else { - $r = q( - "UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', - `body` = '', `title` = '' - WHERE `uri` = '%s' AND `uid` IN (0, %d)", - dbesc($when), - dbesc(datetime_convert()), - dbesc($uri), - intval($importer["uid"]) - ); - create_tags_from_itemuri($uri, $importer["uid"]); - Term::createFromItemURI($uri, $importer["uid"]); - update_thread_uri($uri, $importer["importer_uid"]); + if (!$item["deleted"]) { + logger('deleting item '.$item["id"].' uri='.$uri, LOGGER_DEBUG); + } else { + return; + } - // if this is a relayed delete, propagate it to other recipients + Item::deleteById($item["id"]); - if ($entrytype == DFRN_REPLY_RC) { - logger("Notifying followers about deletion of post " . $item["id"], LOGGER_DEBUG); - Worker::add(PRIORITY_HIGH, "Notifier", "drop", $item["id"]); - } + if ($entrytype != DFRN_TOP_LEVEL) { + // if this is a relayed delete, propagate it to other recipients + if ($entrytype == DFRN_REPLY_RC) { + logger("Notifying followers about deletion of post " . $item["id"], LOGGER_DEBUG); + Worker::add(PRIORITY_HIGH, "Notifier", "drop", $item["id"]); } } } @@ -3156,8 +3061,8 @@ class DFRN return false; } - $existing_edited = datetime_convert('UTC', 'UTC', $existing['edited']); - $update_edited = datetime_convert('UTC', 'UTC', $update['edited']); + $existing_edited = DateTimeFormat::utc($existing['edited']); + $update_edited = DateTimeFormat::utc($update['edited']); return (strcmp($existing_edited, $update_edited) < 0); }