*/
use Friendica\App;
+use Friendica\BaseObject;
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
use Friendica\Content\Pager;
use Friendica\Model\Term;
use Friendica\Object\Post;
use Friendica\Object\Thread;
+use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Temporal;
During the further steps of the database restructuring I would like to address this issue.
*/
+ /** @var Activity $activity */
+ $activity = BaseObject::getClass(Activity::class);
+
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
- if (activity_match($item['verb'], ACTIVITY_LIKE)
- || activity_match($item['verb'], ACTIVITY_DISLIKE)
- || activity_match($item['verb'], ACTIVITY_ATTEND)
- || activity_match($item['verb'], ACTIVITY_ATTENDNO)
- || activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
+ if ($activity->match($item['verb'], ACTIVITY_LIKE)
+ || $activity->match($item['verb'], ACTIVITY_DISLIKE)
+ || $activity->match($item['verb'], ACTIVITY_ATTEND)
+ || $activity->match($item['verb'], ACTIVITY_ATTENDNO)
+ || $activity->match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
$fields = ['author-link', 'author-name', 'verb', 'object-type', 'resource-id', 'body', 'plink'];
$obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
$plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
$bodyverb = '';
- if (activity_match($item['verb'], ACTIVITY_LIKE)) {
+ if ($activity->match($item['verb'], ACTIVITY_LIKE)) {
$bodyverb = L10n::t('%1$s likes %2$s\'s %3$s');
- } elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
+ } elseif ($activity->match($item['verb'], ACTIVITY_DISLIKE)) {
$bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s');
- } elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
+ } elseif ($activity->match($item['verb'], ACTIVITY_ATTEND)) {
$bodyverb = L10n::t('%1$s attends %2$s\'s %3$s');
- } elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
+ } elseif ($activity->match($item['verb'], ACTIVITY_ATTENDNO)) {
$bodyverb = L10n::t('%1$s doesn\'t attend %2$s\'s %3$s');
- } elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
+ } elseif ($activity->match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
$bodyverb = L10n::t('%1$s attends maybe %2$s\'s %3$s');
}
$item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
}
- if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
+ if ($activity->match($item['verb'], ACTIVITY_FRIEND)) {
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
}
- if (activity_match($item['verb'], ACTIVITY_TAG)) {
+ if ($activity->match($item['verb'], ACTIVITY_TAG)) {
$fields = ['author-id', 'author-link', 'author-name', 'author-network',
'verb', 'object-type', 'resource-id', 'body', 'plink'];
$obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
$item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag);
}
- if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
+ if ($activity->match($item['verb'], ACTIVITY_FAVORITE)) {
if ($item['object-type'] == "") {
return;
}
function visible_activity($item) {
+ /** @var Activity $activity */
+ $activity = BaseObject::getClass(Activity::class);
+
/*
* likes (etc.) can apply to other things besides posts. Check if they are post children,
* in which case we handle them specially
*/
$hidden_activities = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE, ACTIVITY_FOLLOW, ACTIVITY2_ANNOUNCE];
foreach ($hidden_activities as $act) {
- if (activity_match($item['verb'], $act)) {
+ if ($activity->match($item['verb'], $act)) {
return false;
}
}
// @TODO below if() block can be rewritten to a single line: $isVisible = allConditionsHere;
- if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE && empty($item['self']) && $item['uid'] == local_user()) {
+ if ($activity->match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE && empty($item['self']) && $item['uid'] == local_user()) {
return false;
}
return;
}
- if (activity_match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
+ /** @var Activity $activity */
+ $activity = BaseObject::getClass(Activity::class);
+
+ if ($activity->match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
$author = ['uid' => 0, 'id' => $item['author-id'],
'network' => $item['author-network'], 'url' => $item['author-link']];
$url = Contact::magicLinkByContact($author);
* @file include/text.php
*/
-use Friendica\Content\Text\BBCode;
use Friendica\Model\FileTag;
-/**
- * Compare activity uri. Knows about activity namespace.
- *
- * @param string $haystack
- * @param string $needle
- * @return boolean
- */
-function activity_match($haystack,$needle) {
- return (($haystack === $needle) || ((basename($needle) === $haystack) && strstr($needle, NAMESPACE_ACTIVITY_SCHEMA)));
-}
-
/**
* return array with details for categories and folders for an item
*
$template = $tpl;
$sparkle = '';
- if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
+ /** @var \Friendica\Protocol\Activity $activity */
+ $activity = BaseObject::getClass(\Friendica\Protocol\Activity::class);
+
+ if (($activity->match($item['verb'], ACTIVITY_LIKE) ||
+ $activity->match($item['verb'], ACTIVITY_DISLIKE)) &&
+ ($item['id'] != $item['parent'])) {
continue;
}
use Friendica\Core\Session;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
+use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\OStatus;
$item['parent-uri'] = $item['thr-parent'];
}
+ /** @var Activity $activity */
+ $activity = self::getClass(Activity::class);
+
if (isset($item['gravity'])) {
$item['gravity'] = intval($item['gravity']);
} elseif ($item['parent-uri'] === $item['uri']) {
$item['gravity'] = GRAVITY_PARENT;
- } elseif (activity_match($item['verb'], ACTIVITY_POST)) {
+ } elseif ($activity->match($item['verb'], ACTIVITY_POST)) {
$item['gravity'] = GRAVITY_COMMENT;
- } elseif (activity_match($item['verb'], ACTIVITY_FOLLOW)) {
+ } elseif ($activity->match($item['verb'], ACTIVITY_FOLLOW)) {
$item['gravity'] = GRAVITY_ACTIVITY;
} else {
$item['gravity'] = GRAVITY_UNKNOWN; // Should not happen
use Friendica\Model\Item;
use Friendica\Model\Term;
use Friendica\Model\User;
+use Friendica\Protocol\Activity;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Proxy as ProxyUtils;
Logger::log('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').', Logger::DEBUG);
return false;
}
+
+ /** @var Activity $activity */
+ $activity = self::getClass(Activity::class);
+
/*
* Only add what will be displayed
*/
if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
return false;
- } elseif (activity_match($item->getDataValue('verb'), ACTIVITY_LIKE) || activity_match($item->getDataValue('verb'), ACTIVITY_DISLIKE)) {
+ } elseif ($activity->match($item->getDataValue('verb'), ACTIVITY_LIKE) ||
+ $activity->match($item->getDataValue('verb'), ACTIVITY_DISLIKE)) {
return false;
}
--- /dev/null
+<?php
+
+namespace Friendica\Protocol;
+
+/**
+ * Base class for the Activity namespace
+ */
+final class Activity
+{
+ /**
+ * Compare activity uri. Knows about activity namespace.
+ *
+ * @param string $haystack
+ * @param string $needle
+ *
+ * @return boolean
+ */
+ public function match(string $haystack, string $needle) {
+ return (($haystack === $needle) ||
+ ((basename($needle) === $haystack) &&
+ strstr($needle, NAMESPACE_ACTIVITY_SCHEMA)));
+ }
+}
use DOMXPath;
use Friendica\App;
use Friendica\App\BaseURL;
+use Friendica\BaseObject;
use Friendica\Content\OEmbed;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
// The functions below are partly used by ostatus.php as well - where we have this variable
$contact = Contact::selectFirst([], ['id' => $importer['id']]);
+ /** @var Activity $activity */
+ $activity = BaseObject::getClass(Activity::class);
+
// Big question: Do we need these functions? They were part of the "consume_feed" function.
// This function once was responsible for DFRN and OStatus.
- if (activity_match($item["verb"], ACTIVITY_FOLLOW)) {
+ if ($activity->match($item["verb"], ACTIVITY_FOLLOW)) {
Logger::log("New follower");
Contact::addRelationship($importer, $contact, $item);
return false;
}
- if (activity_match($item["verb"], ACTIVITY_UNFOLLOW)) {
+ if ($activity->match($item["verb"], ACTIVITY_UNFOLLOW)) {
Logger::log("Lost follower");
Contact::removeFollower($importer, $contact, $item);
return false;
}
- if (activity_match($item["verb"], ACTIVITY_REQ_FRIEND)) {
+ if ($activity->match($item["verb"], ACTIVITY_REQ_FRIEND)) {
Logger::log("New friend request");
Contact::addRelationship($importer, $contact, $item, true);
return false;
}
- if (activity_match($item["verb"], ACTIVITY_UNFRIEND)) {
+ if ($activity->match($item["verb"], ACTIVITY_UNFRIEND)) {
Logger::log("Lost sharer");
Contact::removeSharer($importer, $contact, $item);
return false;
<?php
-namespace src\Content\Text\BBCode;
+namespace Friendica\Test\Content\Text\BBCode;
use Friendica\Content\Text\BBCode\Video;
use Friendica\Test\MockedTest;
--- /dev/null
+<?php
+
+namespace Friendica\Test\Protocol;
+
+use Friendica\Protocol\Activity;
+use Friendica\Test\MockedTest;
+
+class ActivityTest extends MockedTest
+{
+ public function dataMatch()
+ {
+ return [
+ 'empty' => [
+ 'haystack' => '',
+ 'needle' => '',
+ 'assert' => true,
+ ],
+ 'simple' => [
+ 'haystack' => ACTIVITY_OBJ_TAGTERM,
+ 'needle' => ACTIVITY_OBJ_TAGTERM,
+ 'assert' => true,
+ ],
+ 'withNamespace' => [
+ 'haystack' => 'tagterm',
+ 'needle' => NAMESPACE_ACTIVITY_SCHEMA . ACTIVITY_OBJ_TAGTERM,
+ 'assert' => true,
+ ],
+ 'invalidSimple' => [
+ 'haystack' => 'tagterm',
+ 'needle' => '',
+ 'assert' => false,
+ ],
+ 'invalidWithOutNamespace' => [
+ 'haystack' => 'tagterm',
+ 'needle' => ACTIVITY_OBJ_TAGTERM,
+ 'assert' => false,
+ ],
+ 'withSubPath' => [
+ 'haystack' => 'tagterm',
+ 'needle' => NAMESPACE_ACTIVITY_SCHEMA . '/bla/' . ACTIVITY_OBJ_TAGTERM,
+ 'assert' => true,
+ ],
+ ];
+ }
+
+ /**
+ * Test the different, possible matchings
+ *
+ * @dataProvider dataMatch
+ */
+ public function testMatch(string $haystack, string $needle, bool $assert)
+ {
+ $activity = new Activity();
+
+ $this->assertEquals($assert, $activity->match($haystack, $needle));
+ }
+}