use Friendica\App;
use Friendica\Content\OEmbed;
+use Friendica\Core\Addon;
use Friendica\Core\Config;
+use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\User;
use Friendica\Object\Image;
use Friendica\Protocol\OStatus;
+use Friendica\Util\Crypto;
use Friendica\Util\XML;
use dba;
use DOMDocument;
use DOMXPath;
+use HTMLPurifier;
+use HTMLPurifier_Config;
require_once 'boot.php';
require_once 'include/dba.php';
$root = self::addHeader($doc, $owner, $author, $alternatelink, true);
/// @TODO This hook can't work anymore
- // call_hooks('atom_feed', $atom);
+ // Addon::callHooks('atom_feed', $atom);
if (!DBM::is_result($items) || $onlyheader) {
$atom = trim($doc->saveXML());
- call_hooks('atom_feed_end', $atom);
+ Addon::callHooks('atom_feed_end', $atom);
return $atom;
}
$atom = trim($doc->saveXML());
- call_hooks('atom_feed_end', $atom);
+ Addon::callHooks('atom_feed_end', $atom);
return $atom;
}
// "comment-allow" is some old fashioned stuff for old Friendica versions.
// It is included in the rewritten code for completeness
if ($comment) {
- XML::addElement($doc, $entry, "dfrn:comment-allow", intval($item['last-child']));
+ XML::addElement($doc, $entry, "dfrn:comment-allow", 1);
}
if ($item['location']) {
XML::addElement($doc, $entry, "dfrn:diaspora_signature", $sign);
}
- XML::addElement($doc, $entry, "activity:verb", construct_verb($item));
+ XML::addElement($doc, $entry, "activity:verb", self::constructVerb($item));
if ($item['object-type'] != "") {
XML::addElement($doc, $entry, "activity:object-type", $item['object-type']);
switch ($rino_remote_version) {
case 1:
- // Deprecated rino version!
$key = openssl_random_pseudo_bytes(16);
$data = self::aesEncrypt($postvars['data'], $key);
break;
- case 2:
- // RINO 2 based on php-encryption
- try {
- $key = \Crypto::CreateNewRandomKey();
- } catch (\CryptoTestFailedException $ex) {
- logger('Cannot safely create a key');
- return -4;
- } catch (\CannotPerformOperationException $ex) {
- logger('Cannot safely create a key');
- return -5;
- }
- try {
- $data = \Crypto::Encrypt($postvars['data'], $key);
- } catch (\CryptoTestFailedException $ex) {
- logger('Cannot safely perform encryption');
- return -6;
- } catch (\CannotPerformOperationException $ex) {
- logger('Cannot safely perform encryption');
- return -7;
- }
- break;
default:
logger("rino: invalid requested version '$rino_remote_version'");
return -8;
$postvars['rino'] = $rino_remote_version;
$postvars['data'] = bin2hex($data);
- //logger('rino: sent key = ' . $key, LOGGER_DEBUG);
-
-
if ($dfrn_version >= 2.1) {
if (($contact['duplex'] && strlen($contact['pubkey']))
|| ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey']))
logger("updating birthday: ".$birthday." for contact ".$contact["id"]);
- $bdtext = sprintf(t("%s\'s birthday"), $contact["name"]);
- $bdtext2 = sprintf(t("Happy Birthday %s"), " [url=".$contact["url"]."]".$contact["name"]."[/url]");
+ $bdtext = L10n::t("%s\'s birthday", $contact["name"]);
+ $bdtext2 = L10n::t("Happy Birthday %s", " [url=".$contact["url"]."]".$contact["name"]."[/url]");
$r = q(
"INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`)
Worker::add(PRIORITY_HIGH, "Notifier", "comment-import", $current["id"]);
}
}
-
- // update last-child if it changes
- if ($item["last-child"] && ($item["last-child"] != $current["last-child"])) {
- $r = q(
- "UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` IN (0, %d)",
- dbesc(datetime_convert()),
- dbesc($item["parent-uri"]),
- intval($importer["importer_uid"])
- );
- $r = q(
- "UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` IN (0, %d)",
- intval($item["last-child"]),
- dbesc(datetime_convert()),
- dbesc($item["uri"]),
- intval($importer["importer_uid"])
- );
- }
return $changed;
}
* valid community action. Also forum_mode makes it valid for sure.
* If neither, it's not.
*/
-
- /// @TODO Maybe merge these if() blocks into one?
if ($is_a_remote_action && $community && (!$r[0]["forum_mode"]) && (!$r[0]["wall"])) {
$is_a_remote_action = false;
logger("not a community action");
$title = "";
foreach ($links as $link) {
foreach ($link->attributes as $attributes) {
- /// @TODO Rewrite these repeated (same) if () statements to a switch()
- if ($attributes->name == "href") {
- $href = $attributes->textContent;
- }
- if ($attributes->name == "rel") {
- $rel = $attributes->textContent;
- }
- if ($attributes->name == "type") {
- $type = $attributes->textContent;
- }
- if ($attributes->name == "length") {
- $length = $attributes->textContent;
- }
- if ($attributes->name == "title") {
- $title = $attributes->textContent;
+ switch ($attributes->name) {
+ case "href" : $href = $attributes->textContent; break;
+ case "rel" : $rel = $attributes->textContent; break;
+ case "type" : $type = $attributes->textContent; break;
+ case "length": $length = $attributes->textContent; break;
+ case "title" : $title = $attributes->textContent; break;
}
}
if (($rel != "") && ($href != "")) {
$item["edited"] = $xpath->query("atom:updated/text()", $entry)->item(0)->nodeValue;
$current = q(
- "SELECT `id`, `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ "SELECT `id`, `uid`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item["uri"]),
intval($importer["importer_uid"])
);
$item['body'] = OEmbed::HTML2BBCode($item['body']);
- $config = \HTMLPurifier_Config::createDefault();
+ $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);
+ $purifier = new HTMLPurifier($config);
$item['body'] = $purifier->purify($item['body']);
$item['body'] = @html2bbcode($item['body']);
// We don't need the content element since "dfrn:env" is always present
//$item["body"] = $xpath->query("atom:content/text()", $entry)->item(0)->nodeValue;
- $item["last-child"] = $xpath->query("dfrn:comment-allow/text()", $entry)->item(0)->nodeValue;
$item["location"] = $xpath->query("dfrn:location/text()", $entry)->item(0)->nodeValue;
$georsspoint = $xpath->query("georss:point", $entry);
if (($item["network"] != $author["network"]) && ($author["network"] != "")) {
$item["network"] = $author["network"];
}
-
- /// @TODO maybe remove this old-lost code then?
- // This code was taken from the old DFRN code
- // When activated, forums don't work.
- // And: Why should we disallow commenting by followers?
- // the behaviour is now similar to the Diaspora part.
- //if ($importer["rel"] == CONTACT_IS_FOLLOWER) {
- // logger("Contact ".$importer["id"]." is only follower. Quitting", LOGGER_DEBUG);
- // return;
- //}
}
if ($entrytype == DFRN_REPLY_RC) {
$ev = bbtoevent($item["body"]);
if ((x($ev, "desc") || x($ev, "summary")) && x($ev, "start")) {
logger("Event in item ".$item["uri"]." was found.", LOGGER_DEBUG);
- /// @TODO Mixure of "/' ahead ...
- $ev["cid"] = $importer["id"];
- $ev["uid"] = $importer["uid"];
- $ev["uri"] = $item["uri"];
- $ev["edited"] = $item["edited"];
- $ev['private'] = $item['private'];
- $ev["guid"] = $item["guid"];
+ $ev["cid"] = $importer["id"];
+ $ev["uid"] = $importer["uid"];
+ $ev["uri"] = $item["uri"];
+ $ev["edited"] = $item["edited"];
+ $ev["private"] = $item["private"];
+ $ev["guid"] = $item["guid"];
$r = q(
"SELECT `id` FROM `event` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
$parent_uri = $r[0]["parent-uri"];
}
- if (!$is_like) {
- $r1 = q(
- "UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `uid` = %d AND `parent` = %d",
- dbesc(datetime_convert()),
- intval($importer["importer_uid"]),
- intval($r[0]["parent"])
- );
-
- $r2 = q(
- "UPDATE `item` SET `last-child` = 1, `changed` = '%s' WHERE `uid` = %d AND `id` = %d",
- dbesc(datetime_convert()),
- intval($importer["importer_uid"]),
- intval($posted_id)
- );
- }
-
if ($posted_id && $parent && ($entrytype == DFRN_REPLY_RC)) {
logger("Notifying followers about comment ".$posted_id, LOGGER_DEBUG);
Worker::add(PRIORITY_HIGH, "Notifier", "comment-import", $posted_id);
create_tags_from_itemuri($uri, $importer["uid"]);
Term::createFromItemURI($uri, $importer["uid"]);
update_thread_uri($uri, $importer["importer_uid"]);
- if ($item["last-child"]) {
- // ensure that last-child is set in case the comment that had it just got wiped.
- q(
- "UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` IN (0, %d)",
- dbesc(datetime_convert()),
- dbesc($item["parent-uri"]),
- intval($item["uid"])
- );
- // who is the last child now?
- $r = q(
- "SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `moderated` = 0 AND `uid` = %d
- ORDER BY `created` DESC LIMIT 1",
- dbesc($item["parent-uri"]),
- intval($importer["uid"])
- );
- if (DBM::is_result($r)) {
- q(
- "UPDATE `item` SET `last-child` = 1 WHERE `id` = %d",
- intval($r[0]["id"])
- );
- }
- }
+
// if this is a relayed delete, propagate it to other recipients
if ($entrytype == DFRN_REPLY_RC) {
return;
}
+
+ /**
+ * @brief Returns the activity verb
+ *
+ * @param array $item Item array
+ *
+ * @return string activity verb
+ */
+ private static function constructVerb(array $item)
+ {
+ if ($item['verb']) {
+ return $item['verb'];
+ }
+ return ACTIVITY_POST;
+ }
}