X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FDFRN.php;h=4e5aac37d990d930bbda690e221d8e2d6c3a32dd;hb=dbad46c37847f894312c0f1318a21f5ce3606cb0;hp=4c88db1d944a47c0a70d69e7618566438fb652f9;hpb=6f0d40c6c0957751d5f0de844c81a7a140eb7ec7;p=friendica.git diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 4c88db1d94..4e5aac37d9 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -24,9 +24,7 @@ namespace Friendica\Protocol; 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; @@ -37,10 +35,13 @@ use Friendica\Model\Conversation; 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; @@ -49,8 +50,6 @@ use Friendica\Util\Images; 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 @@ -184,19 +183,12 @@ class DFRN $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 = ""; @@ -252,8 +244,8 @@ class DFRN $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) ); } @@ -685,18 +677,10 @@ class DFRN } // 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); @@ -821,7 +805,7 @@ class DFRN if ($activity) { $entry = $doc->createElement($element); - $r = XML::parseString($activity, false); + $r = XML::parseString($activity); if (!$r) { return false; } @@ -847,7 +831,7 @@ class DFRN $r->link = preg_replace('/\/', '', $r->link); // XML does need a single element as root element so we add a dummy element here - $data = XML::parseString("" . $r->link . "", false); + $data = XML::parseString("" . $r->link . ""); if (is_object($data)) { foreach ($data->link as $link) { $attributes = []; @@ -1072,7 +1056,7 @@ class DFRN // 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); } @@ -2117,7 +2101,7 @@ class DFRN 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? @@ -2240,11 +2224,11 @@ class DFRN } 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__); @@ -2253,6 +2237,8 @@ class DFRN // 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"]]); @@ -2369,32 +2355,11 @@ class DFRN $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 @@ -2428,6 +2393,10 @@ class DFRN $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 != "") { @@ -2444,7 +2413,7 @@ class DFRN $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; } @@ -2481,6 +2450,8 @@ class DFRN } $item["tag"] .= $termhash . "[url=" . $termurl . "]" . $term . "[/url]"; + + Tag::store($item['uri-id'], Tag::IMPLICIT_MENTION, $term, $termurl); } } } @@ -2716,7 +2687,7 @@ class DFRN Logger::log('deleting item '.$item['id'].' uri='.$uri, Logger::DEBUG); - Item::delete(['id' => $item['id']]); + Item::markForDeletion(['id' => $item['id']]); } /**