use DOMDocument;
use DOMXPath;
use Friendica\App\BaseURL;
-use Friendica\Content\OEmbed;
use Friendica\Content\Text\BBCode;
-use Friendica\Content\Text\HTML;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Model\Event;
use Friendica\Model\GContact;
use Friendica\Model\Item;
+use Friendica\Model\ItemURI;
use Friendica\Model\Mail;
use Friendica\Model\Notify\Type;
use Friendica\Model\PermissionSet;
use Friendica\Model\Profile;
+use Friendica\Model\Tag;
+use Friendica\Model\Term;
use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Util\Crypto;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\XML;
-use HTMLPurifier;
-use HTMLPurifier_Config;
/**
* This class contain functions to create and send DFRN XML files
$sql_extra = sprintf(" AND `item`.`private` != %s ", Item::PRIVATE);
- $r = q(
- "SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
- FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
- WHERE `contact`.`self` AND `user`.`nickname` = '%s' LIMIT 1",
- DBA::escape($owner_nick)
- );
-
- if (! DBA::isResult($r)) {
+ $owner = DBA::selectFirst('owner-view', [], ['nickname' => $owner_nick]);
+ if (!DBA::isResult($owner)) {
Logger::log(sprintf('No contact found for nickname=%d', $owner_nick), Logger::WARNING);
exit();
}
- $owner = $r[0];
$owner_id = $owner['uid'];
$sql_post_table = "";
$sql_post_table = sprintf(
"INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
DBA::escape(Strings::protectSprintf($category)),
- intval(TERM_OBJ_POST),
- intval(TERM_CATEGORY),
+ intval(Term::OBJECT_TYPE_POST),
+ intval(Term::CATEGORY),
intval($owner_id)
);
}
}
// Only show contact details when we are allowed to
- $r = q(
- "SELECT `profile`.`about`, `profile`.`name`, `profile`.`homepage`, `user`.`nickname`,
- `user`.`timezone`, `profile`.`locality`, `profile`.`region`, `profile`.`country-name`,
- `profile`.`pub_keywords`, `profile`.`xmpp`, `profile`.`dob`
- FROM `profile`
- INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
- WHERE NOT `user`.`hidewall` AND `user`.`uid` = %d",
- intval($owner['uid'])
- );
- if (DBA::isResult($r)) {
- $profile = $r[0];
-
+ $profile = DBA::selectFirst('owner-view',
+ ['about', 'name', 'homepage', 'nickname', 'timezone', 'locality', 'region', 'country-name', 'pub_keywords', 'xmpp', 'dob'],
+ ['uid' => $owner['uid'], 'hidewall' => false]);
+ if (DBA::isResult($profile)) {
XML::addElement($doc, $author, "poco:displayName", $profile["name"]);
XML::addElement($doc, $author, "poco:updated", $namdate);
if ($activity) {
$entry = $doc->createElement($element);
- $r = XML::parseString($activity, false);
+ $r = XML::parseString($activity);
if (!$r) {
return false;
}
$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>", false);
+ $data = XML::parseString("<dummy>" . $r->link . "</dummy>");
if (is_object($data)) {
foreach ($data->link as $link) {
$attributes = [];
if ($item['private']) {
// Friendica versions prior to 2020.3 can't handle "unlisted" properly. So we can only transmit public and private
XML::addElement($doc, $entry, "dfrn:private", ($item['private'] == Item::PRIVATE ? Item::PRIVATE : Item::PUBLIC));
+ XML::addElement($doc, $entry, "dfrn:unlisted", $item['private'] == Item::UNLISTED);
}
if ($item['extid']) {
// The signed text contains the content in Markdown, the sender handle and the signatur for the content
// It is needed for relayed comments to Diaspora.
if ($item['signed_text']) {
- $sign = base64_encode(json_encode(['signed_text' => $item['signed_text'],'signature' => $item['signature'],'signer' => $item['signer']]));
+ $sign = base64_encode(json_encode(['signed_text' => $item['signed_text'],'signature' => '','signer' => '']));
XML::addElement($doc, $entry, "dfrn:diaspora_signature", $sign);
}
if (!$verb) {
return;
}
- $xo = XML::parseString($item["object"], false);
+ $xo = XML::parseString($item["object"]);
if (($xo->type == Activity\ObjectType::PERSON) && ($xo->id)) {
// somebody was poked/prodded. Was it me?
}
if (($item["verb"] == Activity::TAG) && ($item["object-type"] == Activity\ObjectType::TAGTERM)) {
- $xo = XML::parseString($item["object"], false);
- $xt = XML::parseString($item["target"], false);
+ $xo = XML::parseString($item["object"]);
+ $xt = XML::parseString($item["target"]);
if ($xt->type == Activity\ObjectType::NOTE) {
- $item_tag = Item::selectFirst(['id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]);
+ $item_tag = Item::selectFirst(['id', 'uri-id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]);
if (!DBA::isResult($item_tag)) {
Logger::log("Query failed to execute, no result returned in " . __FUNCTION__);
// extract tag, if not duplicate, add to parent item
if ($xo->content) {
+ Tag::store($item_tag['uri-id'], Tag::HASHTAG, $xo->content);
+
if (!stristr($item_tag["tag"], trim($xo->content))) {
$tag = $item_tag["tag"] . (strlen($item_tag["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]';
Item::update(['tag' => $tag], ['id' => $item_tag["id"]]);
$item["body"] = XML::getFirstNodeValue($xpath, "dfrn:env/text()", $entry);
$item["body"] = str_replace([' ',"\t","\r","\n"], ['','','',''], $item["body"]);
- // make sure nobody is trying to sneak some html tags by us
+
$item["body"] = Strings::base64UrlDecode($item["body"]);
$item["body"] = BBCode::limitBodySize($item["body"]);
- /// @todo Do we really need this check for HTML elements? (It was copied from the old function)
- if ((strpos($item['body'], '<') !== false) && (strpos($item['body'], '>') !== false)) {
- $base_url = DI::baseUrl()->get();
- $item['body'] = HTML::relToAbs($item['body'], $base_url);
-
- $item['body'] = HTML::toBBCodeVideo($item['body']);
-
- $item['body'] = OEmbed::HTML2BBCode($item['body']);
-
- $config = HTMLPurifier_Config::createDefault();
- $config->set('Cache.DefinitionImpl', null);
-
- // we shouldn't need a whitelist, because the bbcode converter
- // will strip out any unsupported tags.
-
- $purifier = new HTMLPurifier($config);
- $item['body'] = $purifier->purify($item['body']);
-
- $item['body'] = @HTML::toBBCode($item['body']);
- }
-
/// @todo We should check for a repeated post and if we know the repeated author.
// We don't need the content element since "dfrn:env" is always present
$item["private"] = XML::getFirstNodeValue($xpath, "dfrn:private/text()", $entry);
+ $unlisted = XML::getFirstNodeValue($xpath, "dfrn:unlisted/text()", $entry);
+ if (!empty($unlisted) && ($item['private'] != Item::PRIVATE)) {
+ $item['private'] = Item::UNLISTED;
+ }
+
$item["extid"] = XML::getFirstNodeValue($xpath, "dfrn:extid/text()", $entry);
if (XML::getFirstNodeValue($xpath, "dfrn:bookmark/text()", $entry) == "true") {
$item["guid"] = XML::getFirstNodeValue($xpath, "dfrn:diaspora_guid/text()", $entry);
+ $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
+
+ Tag::storeFromBody($item['uri-id'], $item["body"]);
+
// We store the data from "dfrn:diaspora_signature" in a different table, this is done in "Item::insert"
$dsprsig = XML::unescape(XML::getFirstNodeValue($xpath, "dfrn:diaspora_signature/text()", $entry));
if ($dsprsig != "") {
$item["object"] = self::transformActivity($xpath, $object, "object");
if (trim($item["object"]) != "") {
- $r = XML::parseString($item["object"], false);
+ $r = XML::parseString($item["object"]);
if (isset($r->type)) {
$item["object-type"] = $r->type;
}
}
$item["tag"] .= $termhash . "[url=" . $termurl . "]" . $term . "[/url]";
+
+ Tag::store($item['uri-id'], Tag::IMPLICIT_MENTION, $term, $termurl);
}
}
}
Logger::log('deleting item '.$item['id'].' uri='.$uri, Logger::DEBUG);
- Item::delete(['id' => $item['id']]);
+ Item::markForDeletion(['id' => $item['id']]);
}
/**