/** @deprecated since 2019.03, use Term::OBJECT_TYPE_PHOTO instead */
define('TERM_OBJ_PHOTO', Term::OBJECT_TYPE_PHOTO);
-/**
- * @name Namespaces
- *
- * Various namespaces we may need to parse
- * @{
- */
-define('NAMESPACE_ZOT', 'http://purl.org/zot');
-define('NAMESPACE_DFRN', 'http://purl.org/macgirvin/dfrn/1.0');
-define('NAMESPACE_THREAD', 'http://purl.org/syndication/thread/1.0');
-define('NAMESPACE_TOMB', 'http://purl.org/atompub/tombstones/1.0');
-define('NAMESPACE_ACTIVITY2', 'https://www.w3.org/ns/activitystreams#');
-define('NAMESPACE_ACTIVITY', 'http://activitystrea.ms/spec/1.0/');
-define('NAMESPACE_ACTIVITY_SCHEMA', 'http://activitystrea.ms/schema/1.0/');
-define('NAMESPACE_MEDIA', 'http://purl.org/syndication/atommedia');
-define('NAMESPACE_SALMON_ME', 'http://salmon-protocol.org/ns/magic-env');
-define('NAMESPACE_OSTATUSSUB', 'http://ostatus.org/schema/1.0/subscribe');
-define('NAMESPACE_GEORSS', 'http://www.georss.org/georss');
-define('NAMESPACE_POCO', 'http://portablecontacts.net/spec/1.0');
-define('NAMESPACE_FEED', 'http://schemas.google.com/g/2010#updates-from');
-define('NAMESPACE_OSTATUS', 'http://ostatus.org/schema/1.0');
-define('NAMESPACE_STATUSNET', 'http://status.net/schema/api/1/');
-define('NAMESPACE_ATOM1', 'http://www.w3.org/2005/Atom');
-define('NAMESPACE_MASTODON', 'http://mastodon.social/schema/1.0');
-/* @}*/
-
-/**
- * @name Activity
- *
- * Activity stream defines
- * @{
- */
-define('ACTIVITY_LIKE', NAMESPACE_ACTIVITY_SCHEMA . 'like');
-define('ACTIVITY_DISLIKE', NAMESPACE_DFRN . '/dislike');
-define('ACTIVITY_ATTEND', NAMESPACE_ZOT . '/activity/attendyes');
-define('ACTIVITY_ATTENDNO', NAMESPACE_ZOT . '/activity/attendno');
-define('ACTIVITY_ATTENDMAYBE', NAMESPACE_ZOT . '/activity/attendmaybe');
-
-define('ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart');
-
-define('ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend');
-define('ACTIVITY_REQ_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'request-friend');
-define('ACTIVITY_UNFRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'remove-friend');
-define('ACTIVITY_FOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'follow');
-define('ACTIVITY_UNFOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'stop-following');
-define('ACTIVITY_JOIN', NAMESPACE_ACTIVITY_SCHEMA . 'join');
-
-define('ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post');
-define('ACTIVITY_UPDATE', NAMESPACE_ACTIVITY_SCHEMA . 'update');
-define('ACTIVITY_TAG', NAMESPACE_ACTIVITY_SCHEMA . 'tag');
-define('ACTIVITY_FAVORITE', NAMESPACE_ACTIVITY_SCHEMA . 'favorite');
-define('ACTIVITY_UNFAVORITE', NAMESPACE_ACTIVITY_SCHEMA . 'unfavorite');
-define('ACTIVITY_SHARE', NAMESPACE_ACTIVITY_SCHEMA . 'share');
-define('ACTIVITY_DELETE', NAMESPACE_ACTIVITY_SCHEMA . 'delete');
-define('ACTIVITY2_ANNOUNCE', NAMESPACE_ACTIVITY2 . 'Announce');
-
-define('ACTIVITY_POKE', NAMESPACE_ZOT . '/activity/poke');
-
-define('ACTIVITY_OBJ_BOOKMARK', NAMESPACE_ACTIVITY_SCHEMA . 'bookmark');
-define('ACTIVITY_OBJ_COMMENT', NAMESPACE_ACTIVITY_SCHEMA . 'comment');
-define('ACTIVITY_OBJ_NOTE', NAMESPACE_ACTIVITY_SCHEMA . 'note');
-define('ACTIVITY_OBJ_PERSON', NAMESPACE_ACTIVITY_SCHEMA . 'person');
-define('ACTIVITY_OBJ_IMAGE', NAMESPACE_ACTIVITY_SCHEMA . 'image');
-define('ACTIVITY_OBJ_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'photo');
-define('ACTIVITY_OBJ_VIDEO', NAMESPACE_ACTIVITY_SCHEMA . 'video');
-define('ACTIVITY_OBJ_P_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'profile-photo');
-define('ACTIVITY_OBJ_ALBUM', NAMESPACE_ACTIVITY_SCHEMA . 'photo-album');
-define('ACTIVITY_OBJ_EVENT', NAMESPACE_ACTIVITY_SCHEMA . 'event');
-define('ACTIVITY_OBJ_GROUP', NAMESPACE_ACTIVITY_SCHEMA . 'group');
-define('ACTIVITY_OBJ_TAGTERM', NAMESPACE_DFRN . '/tagterm');
-define('ACTIVITY_OBJ_PROFILE', NAMESPACE_DFRN . '/profile');
-define('ACTIVITY_OBJ_QUESTION', 'http://activityschema.org/object/question');
-/* @}*/
-
/**
* @name Gravity
*
"ext-xml": "*",
"asika/simple-console": "^1.0",
"bacon/bacon-qr-code": "^1.0",
- "divineomega/password_exposed": "^2.4",
- "ezyang/htmlpurifier": "~4.7.0",
+ "divineomega/password_exposed": "^2.8",
+ "ezyang/htmlpurifier": "^4.7",
"friendica/json-ld": "^1.0",
- "league/html-to-markdown": "~4.8.0",
- "level-2/dice": ">1.0",
+ "league/html-to-markdown": "^4.8",
+ "level-2/dice": "^4",
"lightopenid/lightopenid": "dev-master",
"michelf/php-markdown": "^1.7",
- "mobiledetect/mobiledetectlib": "2.8.*",
- "monolog/monolog": "^1.24",
+ "mobiledetect/mobiledetectlib": "^2.8",
+ "monolog/monolog": "^1.25",
"nikic/fast-route": "^1.3",
"paragonie/hidden-string": "^1.0",
"pear/console_table": "^1.3",
"psr/container": "^1.0",
"seld/cli-prompt": "^1.0",
"smarty/smarty": "^3.1",
- "fxp/composer-asset-plugin": "~1.3",
+ "fxp/composer-asset-plugin": "^1.4",
"bower-asset/base64": "^1.0",
- "bower-asset/chart-js": "^2.7",
+ "bower-asset/chart-js": "^2.8",
"bower-asset/dompurify": "^1.0",
"bower-asset/perfect-scrollbar": "^0.6",
- "bower-asset/vue": "^2.5",
+ "bower-asset/vue": "^2.6",
"npm-asset/jquery": "^2.0",
"npm-asset/jquery-colorbox": "^1.6",
- "npm-asset/jquery-datetimepicker": "^2.4.0",
+ "npm-asset/jquery-datetimepicker": "^2.5",
"npm-asset/jgrowl": "^1.4",
- "npm-asset/moment": "^2.20.1",
- "npm-asset/fullcalendar": "^3.0.1",
+ "npm-asset/moment": "^2.24",
+ "npm-asset/fullcalendar": "^3.10",
"npm-asset/cropperjs": "1.2.2",
"npm-asset/imagesloaded": "4.1.4",
"npm-asset/typeahead.js": "^0.11.1",
"include/dba.php",
"include/enotify.php",
"include/items.php",
- "include/text.php",
"boot.php"
]
},
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "eda94f02683bea49b3d506d770749277",
+ "content-hash": "34ad225ce21474eb84ce78047d9f2c01",
"packages": [
{
"name": "asika/simple-console",
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/cropperjs/-/cropperjs-1.2.2.tgz",
+ "reference": null,
"shasum": "30dc7a7ce872155b23a33bd10ad4c76c0d613f55"
},
"require-dev": {
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/ev-emitter/-/ev-emitter-1.1.1.tgz",
+ "reference": null,
"shasum": "8f18b0ce5c76a5d18017f71c0a795c65b9138f2a"
},
"type": "npm-asset-library",
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/fullcalendar/-/fullcalendar-3.10.1.tgz",
+ "reference": null,
"shasum": "cca3f9a2656a7e978a3f3facb7f35934a91185db"
},
"type": "npm-asset-library",
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/imagesloaded/-/imagesloaded-4.1.4.tgz",
+ "reference": null,
"shasum": "1376efcd162bb768c34c3727ac89cc04051f3cc7"
},
"require": {
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/jgrowl/-/jgrowl-1.4.6.tgz",
+ "reference": null,
"shasum": "2736e332aaee73ccf0a14a5f0066391a0a13f4a3"
},
"require-dev": {
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/jquery/-/jquery-2.2.4.tgz",
+ "reference": null,
"shasum": "2c89d6889b5eac522a7eea32c14521559c6cbf02"
},
"require-dev": {
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/jquery-colorbox/-/jquery-colorbox-1.6.4.tgz",
+ "reference": null,
"shasum": "799452523a6c494839224ef702e807deb9c06cc5"
},
"require": {
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/jquery-datetimepicker/-/jquery-datetimepicker-2.5.21.tgz",
+ "reference": null,
"shasum": "00c388a78df2732fedfdb5c6529b6e84d53e0235"
},
"require": {
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/jquery-mousewheel/-/jquery-mousewheel-3.1.13.tgz",
+ "reference": null,
"shasum": "06f0335f16e353a695e7206bf50503cb523a6ee5"
},
"require-dev": {
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",
+ "reference": null,
"shasum": "0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
},
"type": "npm-asset-library",
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/typeahead.js/-/typeahead.js-0.11.1.tgz",
+ "reference": null,
"shasum": "4e64e671b22310a8606f4aec805924ba84b015b8"
},
"require": {
"packages-dev": [
{
"name": "doctrine/instantiator",
- "version": "1.2.0",
+ "version": "1.0.5",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
- "reference": "a2c590166b2133a4633738648b6b064edae0814a"
+ "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a",
- "reference": "a2c590166b2133a4633738648b6b064edae0814a",
+ "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
+ "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
"shasum": ""
},
"require": {
- "php": "^7.1"
+ "php": ">=5.3,<8.0-DEV"
},
"require-dev": {
- "doctrine/coding-standard": "^6.0",
+ "athletic/athletic": "~0.1.8",
"ext-pdo": "*",
"ext-phar": "*",
- "phpbench/phpbench": "^0.13",
- "phpstan/phpstan-phpunit": "^0.11",
- "phpstan/phpstan-shim": "^0.11",
- "phpunit/phpunit": "^7.0"
+ "phpunit/phpunit": "~4.0",
+ "squizlabs/php_codesniffer": "~2.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.2.x-dev"
+ "dev-master": "1.0.x-dev"
}
},
"autoload": {
}
],
"description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
- "homepage": "https://www.doctrine-project.org/projects/instantiator.html",
+ "homepage": "https://github.com/doctrine/instantiator",
"keywords": [
"constructor",
"instantiate"
],
- "time": "2019-03-17T17:37:11+00:00"
+ "time": "2015-06-14T21:17:01+00:00"
},
{
"name": "hamcrest/hamcrest-php",
},
{
"name": "myclabs/deep-copy",
- "version": "1.9.3",
+ "version": "1.7.0",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
- "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea"
+ "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea",
- "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea",
+ "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e",
+ "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e",
"shasum": ""
},
"require": {
- "php": "^7.1"
- },
- "replace": {
- "myclabs/deep-copy": "self.version"
+ "php": "^5.6 || ^7.0"
},
"require-dev": {
"doctrine/collections": "^1.0",
"doctrine/common": "^2.6",
- "phpunit/phpunit": "^7.1"
+ "phpunit/phpunit": "^4.1"
},
"type": "library",
"autoload": {
"object",
"object graph"
],
- "time": "2019-08-09T12:45:53+00:00"
+ "time": "2017-10-19T19:58:43+00:00"
},
{
"name": "phpdocumentor/reflection-common",
}
],
"description": "Provides the functionality to compare PHP values for equality",
- "homepage": "http://www.github.com/sebastianbergmann/comparator",
+ "homepage": "https://github.com/sebastianbergmann/comparator",
"keywords": [
"comparator",
"compare",
}
],
"description": "Provides functionality to handle HHVM/PHP environments",
- "homepage": "http://www.github.com/sebastianbergmann/environment",
+ "homepage": "https://github.com/sebastianbergmann/environment",
"keywords": [
"Xdebug",
"environment",
}
],
"description": "Provides the functionality to export PHP variables for visualization",
- "homepage": "http://www.github.com/sebastianbergmann/exporter",
+ "homepage": "https://github.com/sebastianbergmann/exporter",
"keywords": [
"export",
"exporter"
}
],
"description": "Snapshotting of global state",
- "homepage": "http://www.github.com/sebastianbergmann/global-state",
+ "homepage": "https://github.com/sebastianbergmann/global-state",
"keywords": [
"global state"
],
}
],
"description": "Provides functionality to recursively process PHP variables",
- "homepage": "http://www.github.com/sebastianbergmann/recursion-context",
+ "homepage": "https://github.com/sebastianbergmann/recursion-context",
"time": "2016-11-19T07:33:16+00:00"
},
{
},
{
"name": "symfony/yaml",
- "version": "v4.3.4",
+ "version": "v3.4.32",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
- "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686"
+ "reference": "768f817446da74a776a31eea335540f9dcb53942"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/yaml/zipball/5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686",
- "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686",
+ "url": "https://api.github.com/repos/symfony/yaml/zipball/768f817446da74a776a31eea335540f9dcb53942",
+ "reference": "768f817446da74a776a31eea335540f9dcb53942",
"shasum": ""
},
"require": {
- "php": "^7.1.3",
+ "php": "^5.5.9|>=7.0.8",
"symfony/polyfill-ctype": "~1.8"
},
"conflict": {
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "4.3-dev"
+ "dev-master": "3.4-dev"
}
},
"autoload": {
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
- "time": "2019-08-20T14:27:59+00:00"
+ "time": "2019-09-10T10:38:46+00:00"
},
{
"name": "webmozart/assert",
Hook::callAll('item_photo_menu', $args);
Hook::callAll('jot_tool', $jotplugins);
-### include/text.php
-
- Hook::callAll('contact_block_end', $arr);
- Hook::callAll('poke_verbs', $arr);
- Hook::callAll('put_item_in_cache', $hook_data);
- Hook::callAll('prepare_body_init', $item);
- Hook::callAll('prepare_body_content_filter', $hook_data);
- Hook::callAll('prepare_body', $hook_data);
- Hook::callAll('prepare_body_final', $hook_data);
-
### include/items.php
Hook::callAll('page_info_data', $data);
Hook::callAll('post_remote_end', $posted_item);
Hook::callAll('tagged', $arr);
Hook::callAll('post_local_end', $new_item);
+ Hook::callAll('put_item_in_cache', $hook_data);
+ Hook::callAll('prepare_body_init', $item);
+ Hook::callAll('prepare_body_content_filter', $hook_data);
+ Hook::callAll('prepare_body', $hook_data);
+ Hook::callAll('prepare_body_final', $hook_data);
### src/Model/Contact.php
Hook::callAll('register_account', $uid);
Hook::callAll('remove_user', $user);
+### src/Content/ContactBlock.php
+
+ Hook::callAll('contact_block_end', $arr);
+
### src/Content/Text/BBCode.php
Hook::callAll('bbcode', $text);
self::callSingle(self::getApp(), 'hook_fork', $fork_hook, $hookdata);
+### src/Core/L10n/L10n.php
+
+ Hook::callAll('poke_verbs', $arr);
+
### src/Core/Worker.php
Hook::callAll("proc_run", $arr);
Hook::callAll('item_photo_menu', $args);
Hook::callAll('jot_tool', $jotplugins);
-### include/text.php
-
- Hook::callAll('contact_block_end', $arr);
- Hook::callAll('poke_verbs', $arr);
- Hook::callAll('put_item_in_cache', $hook_data);
- Hook::callAll('prepare_body_init', $item);
- Hook::callAll('prepare_body_content_filter', $hook_data);
- Hook::callAll('prepare_body', $hook_data);
- Hook::callAll('prepare_body_final', $hook_data);
-
### include/items.php
Hook::callAll('page_info_data', $data);
Hook::callAll('post_remote_end', $posted_item);
Hook::callAll('tagged', $arr);
Hook::callAll('post_local_end', $new_item);
+ Hook::callAll('put_item_in_cache', $hook_data);
+ Hook::callAll('prepare_body_init', $item);
+ Hook::callAll('prepare_body_content_filter', $hook_data);
+ Hook::callAll('prepare_body', $hook_data);
+ Hook::callAll('prepare_body_final', $hook_data);
### src/Model/Contact.php
Hook::callAll('register_account', $uid);
Hook::callAll('remove_user', $user);
+
+### src/Content/ContactBlock.php
+
+ Hook::callAll('contact_block_end', $arr);
### src/Content/Text/BBCode.php
Hook::callAll($a->module.'_post_'.$selname, $o);
Hook::callAll('jot_networks', $jotnets);
+### src/Core/Authentication.php
+
+ Hook::callAll('logged_in', $a->user);
+
+### src/Core/Hook.php
+
+ self::callSingle(self::getApp(), 'hook_fork', $fork_hook, $hookdata);
+
+### src/Core/L10n/L10n.php
+
+ Hook::callAll('poke_verbs', $arr);
+
### src/Core/Worker.php
Hook::callAll("proc_run", $arr);
use Friendica\Network\HTTPException\TooManyRequestsException;
use Friendica\Network\HTTPException\UnauthorizedException;
use Friendica\Object\Image;
+use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
// get user data and add it to the array of the activity
$user = api_get_user($a, $parent_item['author-id']);
switch ($parent_item['verb']) {
- case ACTIVITY_LIKE:
+ case Activity::LIKE:
$activities['like'][] = $user;
break;
- case ACTIVITY_DISLIKE:
+ case Activity::DISLIKE:
$activities['dislike'][] = $user;
break;
- case ACTIVITY_ATTEND:
+ case Activity::ATTEND:
$activities['attendyes'][] = $user;
break;
- case ACTIVITY_ATTENDNO:
+ case Activity::ATTENDNO:
$activities['attendno'][] = $user;
break;
- case ACTIVITY_ATTENDMAYBE:
+ case Activity::ATTENDMAYBE:
$activities['attendmaybe'][] = $user;
break;
default:
}
$fields = ['author-id', 'author-name', 'author-link', 'author-avatar'];
- $activity = Item::activityToIndex(ACTIVITY2_ANNOUNCE);
+ $activity = Item::activityToIndex(Activity::ANNOUNCE);
$condition = ['parent-uri' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY, 'uid' => [0, $item['uid']], 'activity' => $activity];
$announce = Item::selectFirstForUser($item['uid'], $fields, $condition, ['order' => ['received' => true]]);
if (!DBA::isResult($announce)) {
*/
use Friendica\App;
+use Friendica\BaseObject;
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
+use Friendica\Content\Item as ContentItem;
use Friendica\Content\Pager;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Config;
use Friendica\Model\Term;
use Friendica\Object\Post;
use Friendica\Object\Thread;
+use Friendica\Protocol\Activity;
+use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Proxy as ProxyUtils;
-use Friendica\Util\Temporal;
use Friendica\Util\Strings;
+use Friendica\Util\Temporal;
use Friendica\Util\XML;
-use Friendica\Util\Crypto;
function item_extract_images($body) {
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']]);
$objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
switch ($obj['verb']) {
- case ACTIVITY_POST:
+ case Activity::POST:
switch ($obj['object-type']) {
- case ACTIVITY_OBJ_EVENT:
+ case Activity\ObjectType::EVENT:
$post_type = L10n::t('event');
break;
default:
$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 ($item['object-type']=="" || $item['object-type']!== Activity\ObjectType::PERSON) return;
$Aname = $item['author-name'];
$Alink = $item['author-link'];
$item['body'] = L10n::t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$Bphoto;
}
- if (stristr($item['verb'], ACTIVITY_POKE)) {
+ if (stristr($item['verb'], Activity::POKE)) {
$verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
if (!$verb) {
return;
}
- if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) {
+ if ($item['object-type']=="" || $item['object-type']!== Activity\ObjectType::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']]);
$objauthor = '[url=' . Contact::magicLinkByContact($author_arr) . ']' . $obj['author-name'] . '[/url]';
switch ($obj['verb']) {
- case ACTIVITY_POST:
+ case Activity::POST:
switch ($obj['object-type']) {
- case ACTIVITY_OBJ_EVENT:
+ case Activity\ObjectType::EVENT:
$post_type = L10n::t('event');
break;
default:
$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) {
- /*
- * 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)) {
- return false;
- }
+ /** @var Activity $activity */
+ $activity = BaseObject::getClass(Activity::class);
+
+ if ($activity->isHidden($item['verb'])) {
+ 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\ObjectType::NOTE &&
+ empty($item['self']) &&
+ $item['uid'] == local_user()) {
return false;
}
$body = Item::prepareBody($item, true, $preview);
- list($categories, $folders) = get_cats_and_terms($item);
+ /** @var ContentItem $contItem */
+ $contItem = BaseObject::getClass(ContentItem::class);
+
+ list($categories, $folders) = $contItem->determineCategoriesTerms($item);
if (!empty($item['content-warning']) && PConfig::get(local_user(), 'system', 'disable_cw', false)) {
$title = ucfirst($item['content-warning']);
$received = '';
while ($row = Item::fetch($thread_items)) {
- if (($row['verb'] == ACTIVITY2_ANNOUNCE) && !empty($row['contact-uid']) && ($row['received'] > $received) && ($row['thr-parent'] == $row['parent-uri'])) {
+ if (($row['verb'] == Activity::ANNOUNCE) && !empty($row['contact-uid']) && ($row['received'] > $received) && ($row['thr-parent'] == $row['parent-uri'])) {
$actor = ['link' => $row['author-link'], 'avatar' => $row['author-avatar'], 'name' => $row['author-name']];
$received = $row['received'];
}
switch ($mode) {
case 'like':
- $verb = ACTIVITY_LIKE;
+ $verb = Activity::LIKE;
break;
case 'dislike':
- $verb = ACTIVITY_DISLIKE;
+ $verb = Activity::DISLIKE;
break;
case 'attendyes':
- $verb = ACTIVITY_ATTEND;
+ $verb = Activity::ATTEND;
break;
case 'attendno':
- $verb = ACTIVITY_ATTENDNO;
+ $verb = Activity::ATTENDNO;
break;
case 'attendmaybe':
- $verb = ACTIVITY_ATTENDMAYBE;
+ $verb = Activity::ATTENDMAYBE;
break;
case 'announce':
- $verb = ACTIVITY2_ANNOUNCE;
+ $verb = Activity::ANNOUNCE;
break;
default:
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);
if (isset($child['children']) && count($child['children'])) {
// This helps counting only the regular posts
$count_post_closure = function($var) {
- return $var['verb'] === ACTIVITY_POST;
+ return $var['verb'] === Activity::POST;
};
$child_post_count = count(array_filter($child['children'], $count_post_closure));
// Searches the post item in the children
$j = 0;
- while($child['children'][$j]['verb'] !== ACTIVITY_POST && $j < count($child['children'])) {
+ while($child['children'][$j]['verb'] !== Activity::POST && $j < count($child['children'])) {
$j ++;
}
use Friendica\Database\DBA;
use Friendica\Model\Item;
use Friendica\Model\User;
+use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Emailer;
use Friendica\Util\Strings;
$hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'">'.$sitename.'</a>');
switch ($params['verb']) {
- case ACTIVITY_FRIEND:
+ case Activity::FRIEND:
// someone started to share with user (mostly OStatus)
$subject = L10n::t('[Friendica:Notify] A new person is sharing with you');
$sitename
);
break;
- case ACTIVITY_FOLLOW:
+ case Activity::FOLLOW:
// someone started to follow the user (mostly OStatus)
$subject = L10n::t('[Friendica:Notify] You have a new follower');
}
if ($params['type'] == NOTIFY_CONFIRM) {
- if ($params['verb'] == ACTIVITY_FRIEND) { // mutual connection
+ if ($params['verb'] == Activity::FRIEND) { // mutual connection
$itemlink = $params['link'];
$subject = L10n::t('[Friendica:Notify] Connection accepted');
if ($send_notification) {
$params["type"] = NOTIFY_SHARE;
- $params["verb"] = ACTIVITY_TAG;
+ $params["verb"] = Activity::TAG;
}
}
if ($item["mention"] || $tagged || ($defaulttype == NOTIFY_TAGSELF)) {
$params["type"] = NOTIFY_TAGSELF;
- $params["verb"] = ACTIVITY_TAG;
+ $params["verb"] = Activity::TAG;
}
// Is it a post that the user had started?
if ($thread['mention'] && !$thread['ignored'] && !isset($params["type"])) {
$params["type"] = NOTIFY_COMMENT;
- $params["verb"] = ACTIVITY_POST;
+ $params["verb"] = Activity::POST;
}
// And now we check for participation of one of our contacts in the thread
if (!$thread['ignored'] && !isset($params["type"]) && Item::exists($condition)) {
$params["type"] = NOTIFY_COMMENT;
- $params["verb"] = ACTIVITY_POST;
+ $params["verb"] = Activity::POST;
}
if (isset($params["type"])) {
+++ /dev/null
-<?php
-/**
- * @file include/text.php
- */
-
-use Friendica\App;
-use Friendica\Content\Text\BBCode;
-use Friendica\Core\Protocol;
-use Friendica\Model\Contact;
-use Friendica\Model\FileTag;
-use Friendica\Model\Group;
-use Friendica\Util\Strings;
-
-/**
- * Turn user/group ACLs stored as angle bracketed text into arrays
- *
- * @param string $s
- * @return array
- */
-function expand_acl($s) {
- // turn string array of angle-bracketed elements into numeric array
- // e.g. "<1><2><3>" => array(1,2,3);
- preg_match_all('/<(' . Group::FOLLOWERS . '|'. Group::MUTUALS . '|[0-9]+)>/', $s, $matches, PREG_PATTERN_ORDER);
-
- return $matches[1];
-}
-
-
-/**
- * Wrap ACL elements in angle brackets for storage
- * @param string $item
- */
-function sanitise_acl(&$item) {
- if (intval($item)) {
- $item = '<' . intval(Strings::escapeTags(trim($item))) . '>';
- } elseif (in_array($item, [Group::FOLLOWERS, Group::MUTUALS])) {
- $item = '<' . $item . '>';
- } else {
- unset($item);
- }
-}
-
-
-/**
- * Convert an ACL array to a storable string
- *
- * Normally ACL permissions will be an array.
- * We'll also allow a comma-separated string.
- *
- * @param string|array $p
- * @return string
- */
-function perms2str($p) {
- $ret = '';
- if (is_array($p)) {
- $tmp = $p;
- } else {
- $tmp = explode(',', $p);
- }
-
- if (is_array($tmp)) {
- array_walk($tmp, 'sanitise_acl');
- $ret = implode('', $tmp);
- }
- return $ret;
-}
-
-/**
- * for html,xml parsing - let's say you've got
- * an attribute foobar="class1 class2 class3"
- * and you want to find out if it contains 'class3'.
- * you can't use a normal sub string search because you
- * might match 'notclass3' and a regex to do the job is
- * possible but a bit complicated.
- * pass the attribute string as $attr and the attribute you
- * are looking for as $s - returns true if found, otherwise false
- *
- * @param string $attr attribute value
- * @param string $s string to search
- * @return boolean True if found, False otherwise
- */
-function attribute_contains($attr, $s) {
- $a = explode(' ', $attr);
- return (count($a) && in_array($s,$a));
-}
-
-/**
- * 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)));
-}
-
-/**
- * quick and dirty quoted_printable encoding
- *
- * @param string $s
- * @return string
- */
-function qp($s) {
- return str_replace("%", "=", rawurlencode($s));
-}
-
-/**
- * @brief Find any non-embedded images in private items and add redir links to them
- *
- * @param App $a
- * @param array &$item The field array of an item row
- */
-function redir_private_images($a, &$item)
-{
- $matches = [];
- $cnt = preg_match_all('|\[img\](http[^\[]*?/photo/[a-fA-F0-9]+?(-[0-9]\.[\w]+?)?)\[\/img\]|', $item['body'], $matches, PREG_SET_ORDER);
- if ($cnt) {
- foreach ($matches as $mtch) {
- if (strpos($mtch[1], '/redir') !== false) {
- continue;
- }
-
- if ((local_user() == $item['uid']) && ($item['private'] == 1) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == Protocol::DFRN)) {
- $img_url = 'redir/' . $item['contact-id'] . '?url=' . urlencode($mtch[1]);
- $item['body'] = str_replace($mtch[0], '[img]' . $img_url . '[/img]', $item['body']);
- }
- }
- }
-}
-
-/**
- * @brief Given a text string, convert from bbcode to html and add smilie icons.
- *
- * @param string $text String with bbcode.
- * @return string Formatted HTML
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
-function prepare_text($text)
-{
- $s = BBCode::convert($text);
- return trim($s);
-}
-
-/**
- * return array with details for categories and folders for an item
- *
- * @param array $item
- * @return array
- *
- * [
- * [ // categories array
- * {
- * 'name': 'category name',
- * 'removeurl': 'url to remove this category',
- * 'first': 'is the first in this array? true/false',
- * 'last': 'is the last in this array? true/false',
- * } ,
- * ....
- * ],
- * [ //folders array
- * {
- * 'name': 'folder name',
- * 'removeurl': 'url to remove this folder',
- * 'first': 'is the first in this array? true/false',
- * 'last': 'is the last in this array? true/false',
- * } ,
- * ....
- * ]
- * ]
- */
-function get_cats_and_terms($item)
-{
- $categories = [];
- $folders = [];
- $first = true;
-
- foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
- $categories[] = [
- 'name' => $savedFolderName,
- 'url' => "#",
- 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
- 'first' => $first,
- 'last' => false
- ];
- $first = false;
- }
-
- if (count($categories)) {
- $categories[count($categories) - 1]['last'] = true;
- }
-
- if (local_user() == $item['uid']) {
- foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
- $folders[] = [
- 'name' => $savedFolderName,
- 'url' => "#",
- 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
- 'first' => $first,
- 'last' => false
- ];
- $first = false;
- }
- }
-
- if (count($folders)) {
- $folders[count($folders) - 1]['last'] = true;
- }
-
- return [$categories, $folders];
-}
-
-/**
- * return number of bytes in size (K, M, G)
- * @param string $size_str
- * @return int
- */
-function return_bytes($size_str) {
- switch (substr ($size_str, -1)) {
- case 'M': case 'm': return (int)$size_str * 1048576;
- case 'K': case 'k': return (int)$size_str * 1024;
- case 'G': case 'g': return (int)$size_str * 1073741824;
- default: return $size_str;
- }
-}
-
-function bb_translate_video($s) {
-
- $matches = null;
- $r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
- if ($r) {
- foreach ($matches as $mtch) {
- if ((stristr($mtch[1], 'youtube')) || (stristr($mtch[1], 'youtu.be'))) {
- $s = str_replace($mtch[0], '[youtube]' . $mtch[1] . '[/youtube]', $s);
- } elseif (stristr($mtch[1], 'vimeo')) {
- $s = str_replace($mtch[0], '[vimeo]' . $mtch[1] . '[/vimeo]', $s);
- }
- }
- }
- return $s;
-}
-
-function undo_post_tagging($s) {
- $matches = null;
- $cnt = preg_match_all('/([!#@])\[url=(.*?)\](.*?)\[\/url\]/ism', $s, $matches, PREG_SET_ORDER);
- if ($cnt) {
- foreach ($matches as $mtch) {
- if (in_array($mtch[1], ['!', '@'])) {
- $contact = Contact::getDetailsByURL($mtch[2]);
- $mtch[3] = empty($contact['addr']) ? $mtch[2] : $contact['addr'];
- }
- $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s);
- }
- }
- return $s;
-}
-
-/// @TODO Rewrite this
-function is_a_date_arg($s) {
- $i = intval($s);
-
- if ($i > 1900) {
- $y = date('Y');
-
- if ($i <= $y + 1 && strpos($s, '-') == 4) {
- $m = intval(substr($s, 5));
-
- if ($m > 0 && $m <= 12) {
- return true;
- }
- }
- }
-
- return false;
-}
use Friendica\Model\Group;
use Friendica\Model\User;
use Friendica\Network\Probe;
+use Friendica\Protocol\Activity;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
'source_name' => ((strlen(stripslashes($combined['name']))) ? stripslashes($combined['name']) : L10n::t('[Name Withheld]')),
'source_link' => $combined['url'],
'source_photo' => $combined['photo'],
- 'verb' => ($mutual?ACTIVITY_FRIEND:ACTIVITY_FOLLOW),
+ 'verb' => ($mutual ? Activity::FRIEND : Activity::FOLLOW),
'otype' => 'intro'
]);
}
use Friendica\Model\User;
use Friendica\Module\Login;
use Friendica\Network\Probe;
+use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Strings;
'source_name' => ((strlen(stripslashes($r[0]['name']))) ? stripslashes($r[0]['name']) : L10n::t('[Name Withheld]')),
'source_link' => $r[0]['url'],
'source_photo' => $r[0]['photo'],
- 'verb' => ACTIVITY_REQ_FRIEND,
+ 'verb' => Activity::REQ_FRIEND,
'otype' => 'intro'
]);
}
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
+use Friendica\Database\DBA;
+use Friendica\Model\Contact;
use Friendica\Model\FileTag;
use Friendica\Model\Item;
-use Friendica\Database\DBA;
use Friendica\Util\Crypto;
function editpost_content(App $a)
return $o;
}
+
+function undo_post_tagging($s) {
+ $matches = null;
+ $cnt = preg_match_all('/([!#@])\[url=(.*?)\](.*?)\[\/url\]/ism', $s, $matches, PREG_SET_ORDER);
+ if ($cnt) {
+ foreach ($matches as $mtch) {
+ if (in_array($mtch[1], ['!', '@'])) {
+ $contact = Contact::getDetailsByURL($mtch[2]);
+ $mtch[3] = empty($contact['addr']) ? $mtch[2] : $contact['addr'];
+ }
+ $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s);
+ }
+ }
+ return $s;
+}
*/
use Friendica\App;
+use Friendica\BaseObject;
use Friendica\Content\Nav;
use Friendica\Content\Widget\CalendarExport;
use Friendica\Core\ACL;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Module\Login;
+use Friendica\Util\ACLFormatter;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
if ($share) {
- $str_group_allow = perms2str($_POST['group_allow'] ?? '');
- $str_contact_allow = perms2str($_POST['contact_allow'] ?? '');
- $str_group_deny = perms2str($_POST['group_deny'] ?? '');
- $str_contact_deny = perms2str($_POST['contact_deny'] ?? '');
+
+ /** @var ACLFormatter $aclFormatter */
+ $aclFormatter = BaseObject::getClass(ACLFormatter::class);
+
+ $str_group_allow = $aclFormatter->toString($_POST['group_allow'] ?? '');
+ $str_contact_allow = $aclFormatter->toString($_POST['contact_allow'] ?? '');
+ $str_group_deny = $aclFormatter->toString($_POST['group_deny'] ?? '');
+ $str_contact_deny = $aclFormatter->toString($_POST['contact_deny'] ?? '');
// Undo the pseudo-contact of self, since there are real contacts now
if (strpos($str_contact_allow, '<' . $self . '>') !== false) {
+++ /dev/null
-<?php
-
-use Friendica\App;
-use Friendica\Database\DBA;
-use Friendica\Model\Item;
-
-function ignored_init(App $a)
-{
- if (!local_user()) {
- exit();
- }
-
- if ($a->argc > 1) {
- $message_id = intval($a->argv[1]);
- }
-
- if (empty($message_id)) {
- exit();
- }
-
- $thread = Item::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]);
- if (!DBA::isResult($thread)) {
- exit();
- }
-
- // Numeric values are needed for the json output further below
- $ignored = ($thread['ignored'] ? 0 : 1);
-
- if ($thread['uid'] != 0) {
- DBA::update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
- } else {
- DBA::update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
- }
-
- // See if we've been passed a return path to redirect to
- $return_path = $_REQUEST['return'] ?? '';
- if ($return_path) {
- $rand = '_=' . time();
- if (strpos($return_path, '?')) {
- $rand = "&$rand";
- } else {
- $rand = "?$rand";
- }
-
- $a->internalRedirect($return_path . $rand);
- }
-
- // the json doesn't really matter, it will either be 0 or 1
-
- echo json_encode($ignored);
- exit();
-}
*/
use Friendica\App;
+use Friendica\BaseObject;
use Friendica\Content\Pager;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
-use Friendica\Core\System;
use Friendica\Core\Session;
+use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\Attach;
use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\Term;
+use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\Email;
+use Friendica\Util\ACLFormatter;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Emailer;
use Friendica\Util\Security;
$toplevel_item_id = $toplevel_item['id'];
$parent_user = $toplevel_item['uid'];
- $objecttype = ACTIVITY_OBJ_COMMENT;
+ $objecttype = Activity\ObjectType::COMMENT;
}
if ($toplevel_item_id) {
$str_contact_deny = $user['deny_cid'];
} else {
// use the posted permissions
- $str_group_allow = perms2str($_REQUEST['group_allow'] ?? '');
- $str_contact_allow = perms2str($_REQUEST['contact_allow'] ?? '');
- $str_group_deny = perms2str($_REQUEST['group_deny'] ?? '');
- $str_contact_deny = perms2str($_REQUEST['contact_deny'] ?? '');
+
+ /** @var ACLFormatter $aclFormatter */
+ $aclFormatter = BaseObject::getClass(ACLFormatter::class);
+
+ $str_group_allow = $aclFormatter->toString($_REQUEST['group_allow'] ?? '');
+ $str_contact_allow = $aclFormatter->toString($_REQUEST['contact_allow'] ?? '');
+ $str_group_deny = $aclFormatter->toString($_REQUEST['group_deny'] ?? '');
+ $str_contact_deny = $aclFormatter->toString($_REQUEST['contact_deny'] ?? '');
}
$title = Strings::escapeTags(trim($_REQUEST['title'] ?? ''));
$match = null;
if (!$preview && Photo::setPermissionFromBody($body, $profile_uid, $original_contact_id, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny)) {
- $objecttype = ACTIVITY_OBJ_IMAGE;
+ $objecttype = Activity\ObjectType::IMAGE;
}
/*
if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) || isset($data["type"]))
&& ($posttype != Item::PT_PERSONAL_NOTE)) {
$posttype = Item::PT_PAGE;
- $objecttype = ACTIVITY_OBJ_BOOKMARK;
+ $objecttype = Activity\ObjectType::BOOKMARK;
}
- $body = bb_translate_video($body);
-
+ /** @var BBCode\Video $bbCodeVideo */
+ $bbCodeVideo = BaseObject::getClass(BBCode\Video::class);
+ $body = $bbCodeVideo->transform($body);
// Fold multi-line [code] sequences
$body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body);
// Setting the object type if not defined before
if (!$objecttype) {
- $objecttype = ACTIVITY_OBJ_NOTE; // Default value
+ $objecttype = Activity\ObjectType::NOTE; // Default value
$objectdata = BBCode::getAttachedData($body);
if ($objectdata["type"] == "link") {
- $objecttype = ACTIVITY_OBJ_BOOKMARK;
+ $objecttype = Activity\ObjectType::BOOKMARK;
} elseif ($objectdata["type"] == "video") {
- $objecttype = ACTIVITY_OBJ_VIDEO;
+ $objecttype = Activity\ObjectType::VIDEO;
} elseif ($objectdata["type"] == "photo") {
- $objecttype = ACTIVITY_OBJ_IMAGE;
+ $objecttype = Activity\ObjectType::IMAGE;
}
}
}
if (!strlen($verb)) {
- $verb = ACTIVITY_POST;
+ $verb = Activity::POST;
}
if ($network == "") {
'source_name' => $datarray['author-name'],
'source_link' => $datarray['author-link'],
'source_photo' => $datarray['author-avatar'],
- 'verb' => ACTIVITY_POST,
+ 'verb' => Activity::POST,
'otype' => 'item',
'parent' => $toplevel_item_id,
'parent_uri' => $toplevel_item['uri']
'source_name' => $datarray['author-name'],
'source_link' => $datarray['author-link'],
'source_photo' => $datarray['author-avatar'],
- 'verb' => ACTIVITY_POST,
+ 'verb' => Activity::POST,
'otype' => 'item'
]);
}
* @file mod/lockview.php
*/
use Friendica\App;
+use Friendica\BaseObject;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Database\DBA;
use Friendica\Model\Group;
use Friendica\Model\Item;
+use Friendica\Util\ACLFormatter;
function lockview_content(App $a)
{
exit();
}
- $allowed_users = expand_acl($item['allow_cid']);
- $allowed_groups = expand_acl($item['allow_gid']);
- $deny_users = expand_acl($item['deny_cid']);
- $deny_groups = expand_acl($item['deny_gid']);
+ /** @var ACLFormatter $aclFormatter */
+ $aclFormatter = BaseObject::getClass(ACLFormatter::class);
+
+ $allowed_users = $aclFormatter->expand($item['allow_cid']);
+ $allowed_groups = $aclFormatter->expand($item['allow_gid']);
+ $deny_users = $aclFormatter->expand($item['deny_cid']);
+ $deny_groups = $aclFormatter->expand($item['deny_gid']);
$o = L10n::t('Visible to:') . '<br />';
$l = [];
*/
use Friendica\App;
+use Friendica\BaseObject;
use Friendica\Content\Feature;
use Friendica\Content\ForumManager;
use Friendica\Content\Nav;
$group_id = 0;
}
+ /** @var DateTimeFormat $dtFormat */
+ $dtFormat = BaseObject::getClass(DateTimeFormat::class);
+
if ($a->argc > 1) {
for ($x = 1; $x < $a->argc; $x ++) {
- if (is_a_date_arg($a->argv[$x])) {
+ if ($dtFormat->isYearMonth($a->argv[$x])) {
$is_a_date_query = true;
break;
}
$default_permissions = [];
+ /** @var DateTimeFormat $dtFormat */
+ $dtFormat = BaseObject::getClass(DateTimeFormat::class);
+
if ($a->argc > 1) {
for ($x = 1; $x < $a->argc; $x ++) {
- if (is_a_date_arg($a->argv[$x])) {
+ if ($dtFormat->isYearMonth($a->argv[$x])) {
if ($datequery) {
$datequery2 = Strings::escapeHtml($a->argv[$x]);
} else {
*/
use Friendica\App;
+use Friendica\BaseObject;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
-use Friendica\Core\System;
use Friendica\Core\Session;
+use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
-use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Object\Image;
-use Friendica\Protocol\DFRN;
+use Friendica\Protocol\Activity;
+use Friendica\Util\ACLFormatter;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
$albname = !empty($_POST['albname']) ? Strings::escapeTags(trim($_POST['albname'])) : '';
$origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
- $str_group_allow = !empty($_POST['group_allow']) ? perms2str($_POST['group_allow']) : '';
- $str_contact_allow = !empty($_POST['contact_allow']) ? perms2str($_POST['contact_allow']) : '';
- $str_group_deny = !empty($_POST['group_deny']) ? perms2str($_POST['group_deny']) : '';
- $str_contact_deny = !empty($_POST['contact_deny']) ? perms2str($_POST['contact_deny']) : '';
+ /** @var ACLFormatter $aclFormatter */
+ $aclFormatter = BaseObject::getClass(ACLFormatter::class);
+
+ $str_group_allow = !empty($_POST['group_allow']) ? $aclFormatter->toString($_POST['group_allow']) : '';
+ $str_contact_allow = !empty($_POST['contact_allow']) ? $aclFormatter->toString($_POST['contact_allow']) : '';
+ $str_group_deny = !empty($_POST['group_deny']) ? $aclFormatter->toString($_POST['group_deny']) : '';
+ $str_contact_deny = !empty($_POST['contact_deny']) ? $aclFormatter->toString($_POST['contact_deny']) : '';
$resource_id = $a->argv[3];
$arr['deny_cid'] = $photo['deny_cid'];
$arr['deny_gid'] = $photo['deny_gid'];
$arr['visible'] = 1;
- $arr['verb'] = ACTIVITY_TAG;
+ $arr['verb'] = Activity::TAG;
$arr['gravity'] = GRAVITY_PARENT;
- $arr['object-type'] = ACTIVITY_OBJ_PERSON;
- $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
+ $arr['object-type'] = Activity\ObjectType::PERSON;
+ $arr['target-type'] = Activity\ObjectType::IMAGE;
$arr['tag'] = $tagged[4];
$arr['inform'] = $tagged[2];
$arr['origin'] = 1;
$arr['body'] = L10n::t('%1$s was tagged in %2$s by %3$s', '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . L10n::t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
$arr['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . '[img]' . System::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
- $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
+ $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
$arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
if ($tagged[3]) {
$arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
}
$arr['object'] .= '</link></object>' . "\n";
- $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
+ $arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
. System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
$arr['target'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '" />' . "\n" . '<link rel="preview" type="' . $photo['type'] . '" href="' . System::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
$group_deny = $_REQUEST['group_deny'] ?? [];
$contact_deny = $_REQUEST['contact_deny'] ?? [];
- $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
- $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
- $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
- $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
+ /** @var ACLFormatter $aclFormatter */
+ $aclFormatter = BaseObject::getClass(ACLFormatter::class);
+
+ $str_group_allow = $aclFormatter->toString(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
+ $str_contact_allow = $aclFormatter->toString(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
+ $str_group_deny = $aclFormatter->toString(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
+ $str_contact_deny = $aclFormatter->toString(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
$ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
$template = $tpl;
$sparkle = '';
- if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
+ /** @var Activity $activity */
+ $activity = BaseObject::getClass(Activity::class);
+
+ if (($activity->match($item['verb'], Activity::LIKE) ||
+ $activity->match($item['verb'], Activity::DISLIKE)) &&
+ ($item['id'] != $item['parent'])) {
continue;
}
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Item;
+use Friendica\Protocol\Activity;
use Friendica\Util\Strings;
use Friendica\Util\XML;
return;
}
- $activity = ACTIVITY_POKE . '#' . urlencode($verbs[$verb][0]);
+ $activity = Activity::POKE . '#' . urlencode($verbs[$verb][0]);
$contact_id = intval($_GET['cid']);
if (!$contact_id) {
$arr['visible'] = 1;
$arr['verb'] = $activity;
$arr['private'] = $private;
- $arr['object-type'] = ACTIVITY_OBJ_PERSON;
+ $arr['object-type'] = Activity\ObjectType::PERSON;
$arr['origin'] = 1;
$arr['body'] = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . L10n::t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]';
- $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . $target['url'] . '</id>';
+ $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $target['name'] . '</title><id>' . $target['url'] . '</id>';
$arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n");
$arr['object'] .= XML::escape('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n");
/**
* @file mod/salmon.php
*/
+
use Friendica\App;
use Friendica\Core\Logger;
use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
-use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
+use Friendica\Protocol\ActivityNamespace;
use Friendica\Protocol\OStatus;
use Friendica\Protocol\Salmon;
use Friendica\Util\Crypto;
-use Friendica\Util\Strings;
use Friendica\Util\Network;
+use Friendica\Util\Strings;
function salmon_post(App $a, $xml = '') {
// parse the xml
- $dom = simplexml_load_string($xml,'SimpleXMLElement',0,NAMESPACE_SALMON_ME);
+ $dom = simplexml_load_string($xml,'SimpleXMLElement',0, ActivityNamespace::SALMON_ME);
$base = null;
use Friendica\App;
use Friendica\BaseModule;
+use Friendica\BaseObject;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
use Friendica\Core\ACL;
use Friendica\Model\User;
use Friendica\Module\Login;
use Friendica\Protocol\Email;
+use Friendica\Util\ACLFormatter;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
date_default_timezone_set($timezone);
}
- $str_group_allow = !empty($_POST['group_allow']) ? perms2str($_POST['group_allow']) : '';
- $str_contact_allow = !empty($_POST['contact_allow']) ? perms2str($_POST['contact_allow']) : '';
- $str_group_deny = !empty($_POST['group_deny']) ? perms2str($_POST['group_deny']) : '';
- $str_contact_deny = !empty($_POST['contact_deny']) ? perms2str($_POST['contact_deny']) : '';
+ /** @var ACLFormatter $aclFormatter */
+ $aclFormatter = BaseObject::getClass(ACLFormatter::class);
+
+ $str_group_allow = !empty($_POST['group_allow']) ? $aclFormatter->toString($_POST['group_allow']) : '';
+ $str_contact_allow = !empty($_POST['contact_allow']) ? $aclFormatter->toString($_POST['contact_allow']) : '';
+ $str_group_deny = !empty($_POST['group_deny']) ? $aclFormatter->toString($_POST['group_deny']) : '';
+ $str_contact_deny = !empty($_POST['contact_deny']) ? $aclFormatter->toString($_POST['contact_deny']) : '';
$openidserver = $a->user['openidserver'];
//$openid = Strings::normaliseOpenID($openid);
/**
* @file mod/subthread.php
*/
+
use Friendica\App;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Item;
+use Friendica\Protocol\Activity;
use Friendica\Util\Security;
use Friendica\Util\Strings;
use Friendica\Util\XML;
return;
}
- $activity = ACTIVITY_FOLLOW;
+ $activity = Activity::FOLLOW;
$item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
$uri = Item::newURI($owner_uid);
$post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
- $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
+ $objtype = (($item['resource-id']) ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE );
$link = XML::escape('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/display/' . $item['guid'] . '" />' . "\n");
$body = $item['body'];
/**
* @file mod/tagger.php
*/
+
use Friendica\App;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
-use Friendica\Core\System;
use Friendica\Core\Session;
+use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\Item;
+use Friendica\Protocol\Activity;
use Friendica\Util\Strings;
use Friendica\Util\XML;
use Friendica\Worker\Delivery;
$uri = Item::newURI($owner_uid);
$xterm = XML::escape($term);
$post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
- $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
+ $targettype = (($item['resource-id']) ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE );
$href = System::baseUrl() . '/display/' . $item['guid'];
$link = XML::escape('<link rel="alternate" type="text/html" href="'. $href . '" />' . "\n");
EOT;
$tagid = System::baseUrl() . '/search?tag=' . $xterm;
- $objtype = ACTIVITY_OBJ_TAGTERM;
+ $objtype = Activity\ObjectType::TAGTERM;
$obj = <<< EOT
<object>
$plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
$arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
- $arr['verb'] = ACTIVITY_TAG;
+ $arr['verb'] = Activity::TAG;
$arr['target-type'] = $targettype;
$arr['target'] = $target;
$arr['object-type'] = $objtype;
*
* @throws InternalServerErrorException
*/
- protected static function getClass(string $name)
+ public static function getClass(string $name)
{
if (empty(self::$dice)) {
throw new InternalServerErrorException('DICE isn\'t initialized.');
--- /dev/null
+<?php
+
+namespace Friendica\Content;
+
+use Friendica\Model\FileTag;
+
+/**
+ * A content helper class for displaying items
+ */
+final class Item
+{
+ /**
+ * Return array with details for categories and folders for an item
+ *
+ * @param array $item
+ * @return [array, array]
+ *
+ * [
+ * [ // categories array
+ * {
+ * 'name': 'category name',
+ * 'removeurl': 'url to remove this category',
+ * 'first': 'is the first in this array? true/false',
+ * 'last': 'is the last in this array? true/false',
+ * } ,
+ * ....
+ * ],
+ * [ //folders array
+ * {
+ * 'name': 'folder name',
+ * 'removeurl': 'url to remove this folder',
+ * 'first': 'is the first in this array? true/false',
+ * 'last': 'is the last in this array? true/false',
+ * } ,
+ * ....
+ * ]
+ * ]
+ */
+ public function determineCategoriesTerms(array $item)
+ {
+ $categories = [];
+ $folders = [];
+ $first = true;
+
+ foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
+ $categories[] = [
+ 'name' => $savedFolderName,
+ 'url' => "#",
+ 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
+ 'first' => $first,
+ 'last' => false
+ ];
+ $first = false;
+ }
+
+ if (count($categories)) {
+ $categories[count($categories) - 1]['last'] = true;
+ }
+
+ if (local_user() == $item['uid']) {
+ foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
+ $folders[] = [
+ 'name' => $savedFolderName,
+ 'url' => "#",
+ 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
+ 'first' => $first,
+ 'last' => false
+ ];
+ $first = false;
+ }
+ }
+
+ if (count($folders)) {
+ $folders[count($folders) - 1]['last'] = true;
+ }
+
+ return [$categories, $folders];
+ }
+}
use Friendica\Model\Photo;
use Friendica\Network\Probe;
use Friendica\Object\Image;
+use Friendica\Protocol\Activity;
use Friendica\Util\Map;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
if (preg_match_all("(\[url=(.*?)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) {
if ((count($pictures) == 1) && !$has_title) {
- if (!empty($item['object-type']) && ($item['object-type'] == ACTIVITY_OBJ_IMAGE)) {
+ if (!empty($item['object-type']) && ($item['object-type'] == Activity\ObjectType::IMAGE)) {
// Replace the preview picture with the real picture
$url = str_replace('-1.', '-0.', $pictures[0][2]);
$data = ['url' => $url, 'type' => 'photo'];
--- /dev/null
+<?php
+
+namespace Friendica\Content\Text\BBCode;
+
+/**
+ * Video specific BBCode util class
+ */
+final class Video
+{
+ /**
+ * Transforms video BBCode tagged links to youtube/vimeo tagged links
+ *
+ * @param string $bbCodeString The input BBCode styled string
+ *
+ * @return string The transformed text
+ */
+ public function transform(string $bbCodeString)
+ {
+ $matches = null;
+ $found = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$bbCodeString,$matches,PREG_SET_ORDER);
+ if ($found) {
+ foreach ($matches as $match) {
+ if ((stristr($match[1], 'youtube')) || (stristr($match[1], 'youtu.be'))) {
+ $bbCodeString = str_replace($match[0], '[youtube]' . $match[1] . '[/youtube]', $bbCodeString);
+ } elseif (stristr($match[1], 'vimeo')) {
+ $bbCodeString = str_replace($match[0], '[vimeo]' . $match[1] . '[/vimeo]', $bbCodeString);
+ }
+ }
+ }
+ return $bbCodeString;
+ }
+}
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Item;
+use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Temporal;
// Transform the different types of notification in an usable array
switch ($it['verb']) {
- case ACTIVITY_LIKE:
+ case Activity::LIKE:
$notif = [
'label' => 'like',
'link' => System::baseUrl(true) . '/display/' . $it['parent-guid'],
];
break;
- case ACTIVITY_DISLIKE:
+ case Activity::DISLIKE:
$notif = [
'label' => 'dislike',
'link' => System::baseUrl(true) . '/display/' . $it['parent-guid'],
];
break;
- case ACTIVITY_ATTEND:
+ case Activity::ATTEND:
$notif = [
'label' => 'attend',
'link' => System::baseUrl(true) . '/display/' . $it['parent-guid'],
];
break;
- case ACTIVITY_ATTENDNO:
+ case Activity::ATTENDNO:
$notif = [
'label' => 'attendno',
'link' => System::baseUrl(true) . '/display/' . $it['parent-guid'],
];
break;
- case ACTIVITY_ATTENDMAYBE:
+ case Activity::ATTENDMAYBE:
$notif = [
'label' => 'attendmaybe',
'link' => System::baseUrl(true) . '/display/' . $it['parent-guid'],
];
break;
- case ACTIVITY_FRIEND:
+ case Activity::FRIEND:
if (!isset($it['object'])) {
$notif = [
'label' => 'friend',
use Friendica\Core\Logger;
use Friendica\Database\Database;
use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Util\FileSystem;
use Friendica\Util\Introspection;
use Friendica\Util\Logger\Monolog\DevelopHandler;
use Friendica\Util\Logger\Monolog\IntrospectionProcessor;
* @param Database $database The Friendica Database instance
* @param Configuration $config The config
* @param Profiler $profiler The profiler of the app
+ * @param FileSystem $fileSystem FileSystem utils
*
* @return LoggerInterface The PSR-3 compliant logger instance
- *
- * @throws \Exception
- * @throws InternalServerErrorException
*/
- public function create( Database $database, Configuration $config, Profiler $profiler)
+ public function create(Database $database, Configuration $config, Profiler $profiler, FileSystem $fileSystem)
{
if (empty($config->get('system', 'debugging', false))) {
$logger = new VoidLogger();
// just add a stream in case it's either writable or not file
if (!is_file($stream) || is_writable($stream)) {
- static::addStreamHandler($logger, $stream, $loglevel);
+ try {
+ static::addStreamHandler($logger, $stream, $loglevel);
+ } catch (\Throwable $e) {
+ // No Logger ..
+ $logger = new VoidLogger();
+ }
}
break;
case 'syslog':
- $logger = new SyslogLogger($this->channel, $introspection, $loglevel);
+ try {
+ $logger = new SyslogLogger($this->channel, $introspection, $loglevel);
+ } catch (\Throwable $e) {
+ // No logger ...
+ $logger = new VoidLogger();
+ }
break;
case 'stream':
$stream = $config->get('system', 'logfile');
// just add a stream in case it's either writable or not file
if (!is_file($stream) || is_writable($stream)) {
- $logger = new StreamLogger($this->channel, $stream, $introspection, $loglevel);
+ try {
+ $logger = new StreamLogger($this->channel, $stream, $introspection, $fileSystem, $loglevel);
+ } catch (\Throwable $t) {
+ // No logger ...
+ $logger = new VoidLogger();
+ }
} else {
$logger = new VoidLogger();
}
*
* @param Configuration $config The config
* @param Profiler $profiler The profiler of the app
+ * @param FileSystem $fileSystem FileSystem utils
*
* @return LoggerInterface The PSR-3 compliant logger instance
*
* @throws InternalServerErrorException
* @throws \Exception
*/
- public static function createDev(Configuration $config, Profiler $profiler)
+ public static function createDev(Configuration $config, Profiler $profiler, FileSystem $fileSystem)
{
$debugging = $config->get('system', 'debugging');
$stream = $config->get('system', 'dlogfile');
case 'stream':
default:
- $logger = new StreamLogger(self::DEV_CHANNEL, $stream, $introspection, LogLevel::DEBUG);
+ $logger = new StreamLogger(self::DEV_CHANNEL, $stream, $introspection, $fileSystem, LogLevel::DEBUG);
break;
}
return LogLevel::INFO;
// legacy DATA
case "4":
- return LogLevel::DEBUG;
// legacy ALL
case "5":
return LogLevel::DEBUG;
*
* @return void
*
- * @throws InternalServerErrorException if the logger is incompatible to the logger factory
* @throws \Exception in case of general failures
*/
public static function addStreamHandler($logger, $stream, $level = LogLevel::NOTICE)
$fileHandler->setFormatter($formatter);
$logger->pushHandler($fileHandler);
- } else {
- throw new InternalServerErrorException('Logger instance incompatible for MonologFactory');
}
}
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
-use Friendica\Core\System;
use Friendica\Core\Session;
+use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Network\Probe;
use Friendica\Object\Image;
+use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\OStatus;
-use Friendica\Protocol\PortableContact;
use Friendica\Protocol\Salmon;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
} elseif (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
// create an unfollow slap
$item = [];
- $item['verb'] = NAMESPACE_OSTATUS . "/unfollow";
+ $item['verb'] = Activity::O_UNFOLLOW;
$item['follow'] = $contact["url"];
$item['body'] = '';
$item['title'] = '';
if (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
// create a follow slap
$item = [];
- $item['verb'] = ACTIVITY_FOLLOW;
+ $item['verb'] = Activity::FOLLOW;
$item['follow'] = $contact["url"];
$item['body'] = '';
$item['title'] = '';
'source_name' => ((strlen(stripslashes($contact_record['name']))) ? stripslashes($contact_record['name']) : L10n::t('[Name Withheld]')),
'source_link' => $contact_record['url'],
'source_photo' => $contact_record['photo'],
- 'verb' => ($sharing ? ACTIVITY_FRIEND : ACTIVITY_FOLLOW),
+ 'verb' => ($sharing ? Activity::FRIEND : Activity::FOLLOW),
'otype' => 'intro'
]);
}
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
+use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
use Friendica\Util\Strings;
$item = Item::selectFirst(['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
if (DBA::isResult($item)) {
- $object = '<object><type>' . XML::escape(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
+ $object = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
$object .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
$object .= '</object>' . "\n";
$item_arr['deny_gid'] = $event['deny_gid'];
$item_arr['private'] = $private;
$item_arr['visible'] = 1;
- $item_arr['verb'] = ACTIVITY_POST;
- $item_arr['object-type'] = ACTIVITY_OBJ_EVENT;
+ $item_arr['verb'] = Activity::POST;
+ $item_arr['object-type'] = Activity\ObjectType::EVENT;
$item_arr['origin'] = $event['cid'] === 0 ? 1 : 0;
$item_arr['body'] = self::getBBCode($event);
$item_arr['event-id'] = $event['id'];
- $item_arr['object'] = '<object><type>' . XML::escape(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
+ $item_arr['object'] = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
$item_arr['object'] .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
$item_arr['object'] .= '</object>' . "\n";
$tpl = Renderer::getMarkupTemplate('event_stream_item.tpl');
$return = Renderer::replaceMacros($tpl, [
'$id' => $item['event-id'],
- '$title' => prepare_text($item['event-summary']),
+ '$title' => BBCode::convert($item['event-summary']),
'$dtstart_label' => L10n::t('Starts:'),
'$dtstart_title' => $dtstart_title,
'$dtstart_dt' => $dtstart_dt,
'$author_name' => $item['author-name'],
'$author_link' => $profile_link,
'$author_avatar' => $item['author-avatar'],
- '$description' => prepare_text($item['event-desc']),
+ '$description' => BBCode::convert($item['event-desc']),
'$location_label' => L10n::t('Location:'),
'$show_map_label' => L10n::t('Show map'),
'$hide_map_label' => L10n::t('Hide map'),
}
}
- $location['name'] = prepare_text($location['name']);
+ $location['name'] = BBCode::convert($location['name']);
// Construct the map HTML.
if (isset($location['address'])) {
/**
* Update a global contact via an ActivityPub Outbox
*
- * @param string $data Probing result
+ * @param string $feed
+ * @param array $data Probing result
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function updateFromOutbox(string $feed, array $data)
{
$items = $outbox['orderedItems'];
} elseif (!empty($outbox['first']['orderedItems'])) {
$items = $outbox['first']['orderedItems'];
+ } elseif (!empty($outbox['first']['href'])) {
+ self::updateFromOutbox($outbox['first']['href'], $data);
+ return;
} elseif (!empty($outbox['first'])) {
self::updateFromOutbox($outbox['first'], $data);
return;
use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
-use Friendica\Core\System;
use Friendica\Core\Session;
+use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
+use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\OStatus;
+use Friendica\Util\ACLFormatter;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
use Friendica\Util\Network;
// Never reorder or remove entries from this list. Just add new ones at the end, if needed.
// The item-activity table only stores the index and needs this array to know the matching activity.
- const ACTIVITIES = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE, ACTIVITY_FOLLOW, ACTIVITY2_ANNOUNCE];
+ const ACTIVITIES = [
+ Activity::LIKE, Activity::DISLIKE,
+ Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE,
+ Activity::FOLLOW,
+ Activity::ANNOUNCE];
private static $legacy_mode = null;
$row['object'] = '';
}
if (array_key_exists('object-type', $row)) {
- $row['object-type'] = ACTIVITY_OBJ_NOTE;
+ $row['object-type'] = Activity\ObjectType::NOTE;
}
- } elseif (array_key_exists('verb', $row) && in_array($row['verb'], ['', ACTIVITY_POST, ACTIVITY_SHARE])) {
+ } elseif (array_key_exists('verb', $row) && in_array($row['verb'], ['', Activity::POST, Activity::SHARE])) {
// Posts don't have an object or target - but having tags or files.
// We safe some performance by building tag and file strings only here.
// We remove object and target since they aren't used for this type.
}
}
- if (!array_key_exists('verb', $row) || in_array($row['verb'], ['', ACTIVITY_POST, ACTIVITY_SHARE])) {
+ if (!array_key_exists('verb', $row) || in_array($row['verb'], ['', Activity::POST, Activity::SHARE])) {
// Build the tag string out of the term entries
if (array_key_exists('tag', $row) && empty($row['tag'])) {
$row['tag'] = Term::tagTextFromItemId($row['internal-iid']);
private static function deleteTagsFromItem($item)
{
- if (($item["verb"] != ACTIVITY_TAG) || ($item["object-type"] != ACTIVITY_OBJ_TAGTERM)) {
+ if (($item["verb"] != Activity::TAG) || ($item["object-type"] != Activity\ObjectType::TAGTERM)) {
return;
}
$xo = XML::parseString($item["object"], false);
$xt = XML::parseString($item["target"], false);
- if ($xt->type != ACTIVITY_OBJ_NOTE) {
+ if ($xt->type != Activity\ObjectType::NOTE) {
return;
}
$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
return 0;
}
- if ($item['verb'] == ACTIVITY_FOLLOW) {
+ if ($item['verb'] == Activity::FOLLOW) {
if (!$item['origin'] && ($item['author-id'] == Contact::getPublicIdByUserId($uid))) {
// Our own follow request can be relayed to us. We don't store it to avoid notification chaos.
Logger::log("Follow: Don't store not origin follow request from us for " . $item['parent-uri'], Logger::DEBUG);
return 0;
}
- $condition = ['verb' => ACTIVITY_FOLLOW, 'uid' => $item['uid'],
+ $condition = ['verb' => Activity::FOLLOW, 'uid' => $item['uid'],
'parent-uri' => $item['parent-uri'], 'author-id' => $item['author-id']];
if (self::exists($condition)) {
// It happens that we receive multiple follow requests by the same author - we only store one.
}
}
- if (stristr($item['verb'], ACTIVITY_POKE)) {
+ if (stristr($item['verb'], Activity::POKE)) {
$notify_type = Delivery::POKE;
}
}
// Only forward posts
- if ($datarray["verb"] != ACTIVITY_POST) {
+ if ($datarray["verb"] != Activity::POST) {
Logger::log('No post', Logger::DEBUG);
return false;
}
*/
public static function enumeratePermissions(array $obj, bool $check_dead = false)
{
- $allow_people = expand_acl($obj['allow_cid']);
- $allow_groups = Group::expand($obj['uid'], expand_acl($obj['allow_gid']), $check_dead);
- $deny_people = expand_acl($obj['deny_cid']);
- $deny_groups = Group::expand($obj['uid'], expand_acl($obj['deny_gid']), $check_dead);
+ /** @var ACLFormatter $aclFormater */
+ $aclFormater = self::getClass(ACLFormatter::class);
+
+ $allow_people = $aclFormater->expand($obj['allow_cid']);
+ $allow_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['allow_gid']), $check_dead);
+ $deny_people = $aclFormater->expand($obj['deny_cid']);
+ $deny_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['deny_gid']), $check_dead);
$recipients = array_unique(array_merge($allow_people, $allow_groups));
$deny = array_unique(array_merge($deny_people, $deny_groups));
$recipients = array_diff($recipients, $deny);
switch ($verb) {
case 'like':
case 'unlike':
- $activity = ACTIVITY_LIKE;
+ $activity = Activity::LIKE;
break;
case 'dislike':
case 'undislike':
- $activity = ACTIVITY_DISLIKE;
+ $activity = Activity::DISLIKE;
break;
case 'attendyes':
case 'unattendyes':
- $activity = ACTIVITY_ATTEND;
+ $activity = Activity::ATTEND;
break;
case 'attendno':
case 'unattendno':
- $activity = ACTIVITY_ATTENDNO;
+ $activity = Activity::ATTENDNO;
break;
case 'attendmaybe':
case 'unattendmaybe':
- $activity = ACTIVITY_ATTENDMAYBE;
+ $activity = Activity::ATTENDMAYBE;
break;
default:
Logger::log('like: unknown verb ' . $verb . ' for item ' . $item_id);
}
// Enable activity toggling instead of on/off
- $event_verb_flag = $activity === ACTIVITY_ATTEND || $activity === ACTIVITY_ATTENDNO || $activity === ACTIVITY_ATTENDMAYBE;
+ $event_verb_flag = $activity === Activity::ATTEND || $activity === Activity::ATTENDNO || $activity === Activity::ATTENDMAYBE;
Logger::log('like: verb ' . $verb . ' item ' . $item_id);
// event participation are essentially radio toggles. If you make a subsequent choice,
// we need to eradicate your first choice.
if ($event_verb_flag) {
- $verbs = [ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE];
+ $verbs = [Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE];
// Translate to the index based activity index
$activities = [];
return true;
}
- $objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE;
+ $objtype = $item['resource-id'] ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE;
$new_item = [
'guid' => System::createUUID(),
return L10n::t('event');
} elseif (!empty($item['resource-id'])) {
return L10n::t('photo');
- } elseif (!empty($item['verb']) && $item['verb'] !== ACTIVITY_POST) {
+ } elseif (!empty($item['verb']) && $item['verb'] !== Activity::POST) {
return L10n::t('activity');
} elseif ($item['id'] != $item['parent']) {
return L10n::t('comment');
|| $rendered_hash != hash("md5", $item["body"])
|| Config::get("system", "ignore_cache")
) {
- $a = self::getApp();
- redir_private_images($a, $item);
+ self::addRedirToImageTags($item);
- $item["rendered-html"] = prepare_text($item["body"]);
+ $item["rendered-html"] = BBCode::convert($item["body"]);
$item["rendered-hash"] = hash("md5", $item["body"]);
$hook_data = ['item' => $item, 'rendered-html' => $item['rendered-html'], 'rendered-hash' => $item['rendered-hash']];
$item["body"] = $body;
}
+ /**
+ * @brief Find any non-embedded images in private items and add redir links to them
+ *
+ * @param array &$item The field array of an item row
+ */
+ private static function addRedirToImageTags(array &$item)
+ {
+ $app = self::getApp();
+
+ $matches = [];
+ $cnt = preg_match_all('|\[img\](http[^\[]*?/photo/[a-fA-F0-9]+?(-[0-9]\.[\w]+?)?)\[\/img\]|', $item['body'], $matches, PREG_SET_ORDER);
+ if ($cnt) {
+ foreach ($matches as $mtch) {
+ if (strpos($mtch[1], '/redir') !== false) {
+ continue;
+ }
+
+ if ((local_user() == $item['uid']) && ($item['private'] == 1) && ($item['contact-id'] != $app->contact['id']) && ($item['network'] == Protocol::DFRN)) {
+ $img_url = 'redir/' . $item['contact-id'] . '?url=' . urlencode($mtch[1]);
+ $item['body'] = str_replace($mtch[0], '[img]' . $img_url . '[/img]', $item['body']);
+ }
+ }
+ }
+ }
+
/**
* @brief Given an item array, convert the body element from bbcode to html and add smilie icons.
* If attach is true, also add icons for item attachments.
// In order to provide theme developers more possibilities, event items
// are treated differently.
- if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) {
+ if ($item['object-type'] === Activity\ObjectType::EVENT && isset($item['event-id'])) {
$ev = Event::getItemHTML($item);
return $ev;
}
use Friendica\Model\Photo;
use Friendica\Database\DBA;
use Friendica\Network\Probe;
+use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Worker\Delivery;
'source_name' => $msg['from-name'],
'source_link' => $msg['from-url'],
'source_photo' => $msg['from-photo'],
- 'verb' => ACTIVITY_POST,
+ 'verb' => Activity::POST,
'otype' => 'mail'
];
use Friendica\Core\Theme;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
+use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
while ($rr = DBA::fetch($s)) {
$condition = ['parent-uri' => $rr['uri'], 'uid' => $rr['uid'], 'author-id' => public_contact(),
- 'activity' => [Item::activityToIndex(ACTIVITY_ATTEND), Item::activityToIndex(ACTIVITY_ATTENDMAYBE)],
+ 'activity' => [Item::activityToIndex( Activity::ATTEND), Item::activityToIndex(Activity::ATTENDMAYBE)],
'visible' => true, 'deleted' => false];
if (!Item::exists($condition)) {
continue;
$profile['religion'] = [L10n::t('Religion:'), $a->profile['religion']];
}
- if ($txt = prepare_text($a->profile['about'])) {
+ if ($txt = BBCode::convert($a->profile['about'])) {
$profile['about'] = [L10n::t('About:'), $txt];
}
- if ($txt = prepare_text($a->profile['interest'])) {
+ if ($txt = BBCode::convert($a->profile['interest'])) {
$profile['interest'] = [L10n::t('Hobbies/Interests:'), $txt];
}
- if ($txt = prepare_text($a->profile['likes'])) {
+ if ($txt = BBCode::convert($a->profile['likes'])) {
$profile['likes'] = [L10n::t('Likes:'), $txt];
}
- if ($txt = prepare_text($a->profile['dislikes'])) {
+ if ($txt = BBCode::convert($a->profile['dislikes'])) {
$profile['dislikes'] = [L10n::t('Dislikes:'), $txt];
}
- if ($txt = prepare_text($a->profile['contact'])) {
+ if ($txt = BBCode::convert($a->profile['contact'])) {
$profile['contact'] = [L10n::t('Contact information and Social Networks:'), $txt];
}
- if ($txt = prepare_text($a->profile['music'])) {
+ if ($txt = BBCode::convert($a->profile['music'])) {
$profile['music'] = [L10n::t('Musical interests:'), $txt];
}
- if ($txt = prepare_text($a->profile['book'])) {
+ if ($txt = BBCode::convert($a->profile['book'])) {
$profile['book'] = [L10n::t('Books, literature:'), $txt];
}
- if ($txt = prepare_text($a->profile['tv'])) {
+ if ($txt = BBCode::convert($a->profile['tv'])) {
$profile['tv'] = [L10n::t('Television:'), $txt];
}
- if ($txt = prepare_text($a->profile['film'])) {
+ if ($txt = BBCode::convert($a->profile['film'])) {
$profile['film'] = [L10n::t('Film/dance/culture/entertainment:'), $txt];
}
- if ($txt = prepare_text($a->profile['romance'])) {
+ if ($txt = BBCode::convert($a->profile['romance'])) {
$profile['romance'] = [L10n::t('Love/Romance:'), $txt];
}
- if ($txt = prepare_text($a->profile['work'])) {
+ if ($txt = BBCode::convert($a->profile['work'])) {
$profile['work'] = [L10n::t('Work/employment:'), $txt];
}
- if ($txt = prepare_text($a->profile['education'])) {
+ if ($txt = BBCode::convert($a->profile['education'])) {
$profile['education'] = [L10n::t('School/education:'), $txt];
}
use Friendica\Module\BaseAdminModule;
use Friendica\Util\ConfigFileLoader;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\FileSystem;
use Friendica\Util\Network;
class Summary extends BaseAdminModule
// Check logfile permission
if (Config::get('system', 'debugging')) {
- $stream = Config::get('system', 'logfile');
+ $file = Config::get('system', 'logfile');
- if (is_file($stream) &&
- !is_writeable($stream)) {
- $warningtext[] = L10n::t('The logfile \'%s\' is not writable. No logging possible', $stream);
+ /** @var FileSystem $fileSystem */
+ $fileSystem = self::getClass(FileSystem::class);
+
+ try {
+ $stream = $fileSystem->createStream($file);
+
+ if (is_file($stream) &&
+ !is_writeable($stream)) {
+ $warningtext[] = L10n::t('The logfile \'%s\' is not writable. No logging possible', $stream);
+ }
+
+ } catch (\Throwable $exception) {
+ $warningtext[] = L10n::t('The logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
}
$stream = Config::get('system', 'dlogfile');
use Friendica\App;
use Friendica\BaseModule;
use Friendica\Core\Config\Configuration;
+use Friendica\Core\L10n\L10n;
use Friendica\Model\User;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Diaspora;
$enabled = $config->get('system', 'diaspora_enabled', false);
if (!$enabled) {
self::$logger->info('Diaspora disabled.');
- throw new HTTPException\InternalServerErrorException('Diaspora disabled.');
+ $l10n = self::getClass(L10n::class);
+ throw new HTTPException\ForbiddenException($l10n->t('Access denied.'));
}
/** @var App\Arguments $args */
use Friendica\Model\User;
use Friendica\Module\Login;
use Friendica\Network\HTTPException\NotImplementedException;
+use Friendica\Util\ACLFormatter;
use Friendica\Util\Crypto;
class Compose extends BaseModule
$user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
+ /** @var ACLFormatter $aclFormatter */
+ $aclFormatter = self::getClass(ACLFormatter::class);
+
switch ($posttype) {
case Item::PT_PERSONAL_NOTE:
$compose_title = L10n::t('Compose new personal note');
$compose_title = L10n::t('Compose new post');
$type = 'post';
$doesFederate = true;
- $contact_allow = implode(',', expand_acl($user['allow_cid']));
- $group_allow = implode(',', expand_acl($user['allow_gid'])) ?: Group::FOLLOWERS;
+ $contact_allow = implode(',', $aclFormatter->expand($user['allow_cid']));
+ $group_allow = implode(',', $aclFormatter->expand($user['allow_gid'])) ?: Group::FOLLOWERS;
break;
}
$wall = $_REQUEST['wall'] ?? $type == 'post';
$contact_allow = $_REQUEST['contact_allow'] ?? $contact_allow;
$group_allow = $_REQUEST['group_allow'] ?? $group_allow;
- $contact_deny = $_REQUEST['contact_deny'] ?? implode(',', expand_acl($user['deny_cid']));
- $group_deny = $_REQUEST['group_deny'] ?? implode(',', expand_acl($user['deny_gid']));
+ $contact_deny = $_REQUEST['contact_deny'] ?? implode(',', $aclFormatter->expand($user['deny_cid']));
+ $group_deny = $_REQUEST['group_deny'] ?? implode(',', $aclFormatter->expand($user['deny_gid']));
$visibility = ($contact_allow . $user['allow_gid'] . $user['deny_cid'] . $user['deny_gid']) ? 'custom' : 'public';
$acl_contacts = Contact::selectToArray(['id', 'name', 'addr', 'micro'], ['uid' => local_user(), 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]);
--- /dev/null
+<?php
+
+namespace Friendica\Module\Item;
+
+use Friendica\App;
+use Friendica\BaseModule;
+use Friendica\Core\L10n\L10n;
+use Friendica\Core\Session;
+use Friendica\Core\System;
+use Friendica\Database\Database;
+use Friendica\Model\Item;
+use Friendica\Network\HTTPException;
+
+/**
+ * Module for ignoring threads or user items
+ */
+class Ignore extends BaseModule
+{
+ public static function rawContent()
+ {
+ /** @var L10n $l10n */
+ $l10n = self::getClass(L10n::class);
+
+ if (!Session::isAuthenticated()) {
+ throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
+ }
+
+ /** @var App\Arguments $args */
+ $args = self::getClass(App\Arguments::class);
+ /** @var Database $dba */
+ $dba = self::getClass(Database::class);
+
+ $message_id = intval($args->get(2));
+
+ if (empty($message_id) || !is_int($message_id)) {
+ throw new HTTPException\BadRequestException();
+ }
+
+ $thread = Item::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]);
+ if (!$dba->isResult($thread)) {
+ throw new HTTPException\BadRequestException();
+ }
+
+ // Numeric values are needed for the json output further below
+ $ignored = !empty($thread['ignored']) ? 0 : 1;
+
+ switch ($thread['uid'] ?? 0) {
+ // if the thread is from the current user
+ case local_user():
+ $dba->update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
+ break;
+ // 0 (null will get transformed to 0) => it's a public post
+ case 0:
+ $dba->update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
+ break;
+ // Throws a BadRequestException and not a ForbiddenException on purpose
+ // Avoids harvesting existing, but forbidden IIDs (security issue)
+ default:
+ throw new HTTPException\BadRequestException();
+ }
+
+ // See if we've been passed a return path to redirect to
+ $return_path = $_REQUEST['return'] ?? '';
+ if (!empty($return_path)) {
+ $rand = '_=' . time();
+ if (strpos($return_path, '?')) {
+ $rand = "&$rand";
+ } else {
+ $rand = "?$rand";
+ }
+
+ self::getApp()->internalRedirect($return_path . $rand);
+ }
+
+ // the json doesn't really matter, it will either be 0 or 1
+ System::jsonExit([$ignored]);
+ }
+}
$category = $datequery = $datequery2 = '';
+ /** @var DateTimeFormat $dtFormat */
+ $dtFormat = self::getClass(DateTimeFormat::class);
+
if ($a->argc > 2) {
for ($x = 2; $x < $a->argc; $x ++) {
- if (is_a_date_arg($a->argv[$x])) {
+ if ($dtFormat->isYearMonth($a->argv[$x])) {
if ($datequery) {
$datequery2 = Strings::escapeHtml($a->argv[$x]);
} else {
use Friendica\BaseModule;
use Friendica\Core\Hook;
-use Friendica\Database\DBA;
use Friendica\Core\Renderer;
-use Friendica\Core\System;
-use Friendica\Model\User;
+use Friendica\Database\DBA;
use Friendica\Model\Photo;
+use Friendica\Model\User;
+use Friendica\Protocol\ActivityNamespace;
use Friendica\Protocol\Salmon;
use Friendica\Util\Strings;
],
'links' => [
[
- 'rel' => NAMESPACE_DFRN,
+ 'rel' => ActivityNamespace::DFRN ,
'href' => $owner['url'],
],
[
- 'rel' => NAMESPACE_FEED,
+ 'rel' => ActivityNamespace::FEED,
'type' => 'application/atom+xml',
'href' => $owner['poll'],
],
'href' => $baseURL . '/hcard/' . $owner['nickname'],
],
[
- 'rel' => NAMESPACE_POCO,
+ 'rel' => ActivityNamespace::POCO,
'href' => $owner['poco'],
],
[
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Profile;
+use Friendica\Protocol\ActivityNamespace;
use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\Email;
use Friendica\Protocol\Feed;
use Friendica\Util\Crypto;
-use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\XML;
Logger::log('webfingerDfrn: '.$webbie.':'.print_r($links, true), Logger::DATA);
if (!empty($links) && is_array($links)) {
foreach ($links as $link) {
- if ($link['@attributes']['rel'] === NAMESPACE_DFRN) {
+ if ($link['@attributes']['rel'] === ActivityNamespace::DFRN) {
$profile_link = $link['@attributes']['href'];
}
- if (($link['@attributes']['rel'] === NAMESPACE_OSTATUSSUB) && ($profile_link == "")) {
+ if (($link['@attributes']['rel'] === ActivityNamespace::OSTATUSSUB) && ($profile_link == "")) {
$profile_link = 'stat:'.$link['@attributes']['template'];
}
if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') {
$has_key = false;
foreach ($webfinger['links'] as $link) {
- if ($link['rel'] == NAMESPACE_OSTATUSSUB) {
+ if ($link['rel'] == ActivityNamespace::OSTATUSSUB) {
$is_ostatus = true;
}
if ($link['rel'] == 'magic-public-key') {
// The array is reversed to take into account the order of preference for same-rel links
// See: https://tools.ietf.org/html/rfc7033#section-4.4.4
foreach (array_reverse($webfinger["links"]) as $link) {
- if (($link["rel"] == NAMESPACE_DFRN) && !empty($link["href"])) {
+ if (($link["rel"] == ActivityNamespace::DFRN) && !empty($link["href"])) {
$data["network"] = Protocol::DFRN;
- } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
+ } elseif (($link["rel"] == ActivityNamespace::FEED) && !empty($link["href"])) {
$data["poll"] = $link["href"];
} elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") && (($link["type"] ?? "") == "text/html") && !empty($link["href"])) {
$data["url"] = $link["href"];
} elseif (($link["rel"] == "http://microformats.org/profile/hcard") && !empty($link["href"])) {
$hcard_url = $link["href"];
- } elseif (($link["rel"] == NAMESPACE_POCO) && !empty($link["href"])) {
+ } elseif (($link["rel"] == ActivityNamespace::POCO) && !empty($link["href"])) {
$data["poco"] = $link["href"];
} elseif (($link["rel"] == "http://webfinger.net/rel/avatar") && !empty($link["href"])) {
$data["photo"] = $link["href"];
$data["guid"] = $link["href"];
} elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") && (($link["type"] ?? "") == "text/html") && !empty($link["href"])) {
$data["url"] = $link["href"];
- } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
+ } elseif (($link["rel"] == ActivityNamespace::FEED) && !empty($link["href"])) {
$data["poll"] = $link["href"];
- } elseif (($link["rel"] == NAMESPACE_POCO) && !empty($link["href"])) {
+ } elseif (($link["rel"] == ActivityNamespace::POCO) && !empty($link["href"])) {
$data["poco"] = $link["href"];
} elseif (($link["rel"] == "salmon") && !empty($link["href"])) {
$data["notify"] = $link["href"];
$data["url"] = $link["href"];
} elseif (($link["rel"] == "salmon") && !empty($link["href"])) {
$data["notify"] = $link["href"];
- } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
+ } elseif (($link["rel"] == ActivityNamespace::FEED) && !empty($link["href"])) {
$data["poll"] = $link["href"];
} elseif (($link["rel"] == "magic-public-key") && !empty($link["href"])) {
$pubkey = $link["href"];
use Friendica\BaseObject;
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
+use Friendica\Content\Item as ContentItem;
use Friendica\Core\Addon;
use Friendica\Core\Config;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
-use Friendica\Core\Session;
use Friendica\Core\Renderer;
+use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
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;
$isevent = false;
$attend = [];
- if ($item['object-type'] === ACTIVITY_OBJ_EVENT) {
+ if ($item['object-type'] === Activity\ObjectType::EVENT) {
$response_verbs[] = 'attendyes';
$response_verbs[] = 'attendno';
$response_verbs[] = 'attendmaybe';
$body = Item::prepareBody($item, true);
- list($categories, $folders) = get_cats_and_terms($item);
+ /** @var ContentItem $contItem */
+ $contItem = self::getClass(ContentItem::class);
+
+ list($categories, $folders) = $contItem->determineCategoriesTerms($item);
$body_e = $body;
$text_e = strip_tags($body);
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;
}
use Friendica\BaseObject;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
+use Friendica\Protocol\Activity;
use Friendica\Util\Security;
/**
return false;
}
- if ($item->getDataValue('verb') === ACTIVITY_LIKE || $item->getDataValue('verb') === ACTIVITY_DISLIKE) {
+ if ($item->getDataValue('verb') === Activity::LIKE || $item->getDataValue('verb') === Activity::DISLIKE) {
Logger::log('[WARN] Conversation::addThread : Thread is a (dis)like ('. $item->getId() .').', Logger::DEBUG);
return false;
}
--- /dev/null
+<?php
+
+namespace Friendica\Protocol;
+
+use Friendica\Protocol\ActivityNamespace;
+
+/**
+ * Base class for the Activity Verbs
+ */
+final class Activity
+{
+ /**
+ * Indicates that the actor marked the object as an item of special interest.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const LIKE = ActivityNamespace::ACTIVITY_SCHEMA . 'like';
+ /**
+ * Dislike a message ("I don't like the post")
+ *
+ * @see http://purl.org/macgirvin/dfrn/1.0/dislike
+ * @var string
+ */
+ const DISLIKE = ActivityNamespace::DFRN . '/dislike';
+
+ /**
+ * Attend an event
+ *
+ * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attend
+ * @var string
+ */
+ const ATTEND = ActivityNamespace::ZOT . '/activity/attendyes';
+ /**
+ * Don't attend an event
+ *
+ * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendno
+ * @var string
+ */
+ const ATTENDNO = ActivityNamespace::ZOT . '/activity/attendno';
+ /**
+ * Attend maybe an event
+ *
+ * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendmaybe
+ * @var string
+ */
+ const ATTENDMAYBE = ActivityNamespace::ZOT . '/activity/attendmaybe';
+
+ /**
+ * Indicates the creation of a friendship that is reciprocated by the object.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const FRIEND = ActivityNamespace::ACTIVITY_SCHEMA . 'make-friend';
+ /**
+ * Indicates the creation of a friendship that has not yet been reciprocated by the object.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const REQ_FRIEND = ActivityNamespace::ACTIVITY_SCHEMA . 'request-friend';
+ /**
+ * Indicates that the actor has removed the object from the collection of friends.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const UNFRIEND = ActivityNamespace::ACTIVITY_SCHEMA . 'remove-friend';
+ /**
+ * Indicates that the actor began following the activity of the object.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const FOLLOW = ActivityNamespace::ACTIVITY_SCHEMA . 'follow';
+ /**
+ * Indicates that the actor has stopped following the object.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const UNFOLLOW = ActivityNamespace::ACTIVITY_SCHEMA . 'stop-following';
+ /**
+ * Indicates that the actor has become a member of the object.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const JOIN = ActivityNamespace::ACTIVITY_SCHEMA . 'join';
+ /**
+ * Implementors SHOULD use verbs such as post where the actor is adding new items to a collection or similar.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const POST = ActivityNamespace::ACTIVITY_SCHEMA . 'post';
+ /**
+ * The "update" verb indicates that the actor has modified the object.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const UPDATE = ActivityNamespace::ACTIVITY_SCHEMA . 'update';
+ /**
+ * Indicates that the actor has identified the presence of a target inside another object.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const TAG = ActivityNamespace::ACTIVITY_SCHEMA . 'tag';
+ /**
+ * Indicates that the actor marked the object as an item of special interest.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const FAVORITE = ActivityNamespace::ACTIVITY_SCHEMA . 'favorite';
+ /**
+ * Indicates that the actor has removed the object from the collection of favorited items.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const UNFAVORITE = ActivityNamespace::ACTIVITY_SCHEMA . 'unfavorite';
+ /**
+ * Indicates that the actor has called out the object to readers.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const SHARE = ActivityNamespace::ACTIVITY_SCHEMA . 'share';
+ /**
+ * Indicates that the actor has deleted the object.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#verbs
+ * @var string
+ */
+ const DELETE = ActivityNamespace::ACTIVITY_SCHEMA . 'delete';
+ /**
+ * Indicates that the actor is calling the target's attention the object.
+ *
+ * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-announce
+ * @var string
+ */
+ const ANNOUNCE = ActivityNamespace::ACTIVITY2 . 'Announce';
+
+ /**
+ * Pokes an user.
+ *
+ * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_poke
+ * @var string
+ */
+ const POKE = ActivityNamespace::ZOT . '/activity/poke';
+
+
+ const O_UNFOLLOW = ActivityNamespace::OSTATUS . '/unfollow';
+ const O_UNFAVOURITE = ActivityNamespace::OSTATUS . '/unfavorite';
+
+ /**
+ * likes (etc.) can apply to other things besides posts. Check if they are post children,
+ * in which case we handle them specially
+ *
+ * Hidden activities, which doesn't need to be shown
+ */
+ const HIDDEN_ACTIVITIES = [
+ Activity::LIKE, Activity::DISLIKE,
+ Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE,
+ Activity::FOLLOW,
+ Activity::ANNOUNCE,
+ ];
+
+ /**
+ * Checks if the given activity is a hidden activity
+ *
+ * @param string $activity The current activity
+ *
+ * @return bool True, if the activity is hidden
+ */
+ public function isHidden(string $activity)
+ {
+ foreach (self::HIDDEN_ACTIVITIES as $hiddenActivity) {
+ if ($this->match($activity, $hiddenActivity)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * 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, ActivityNamespace::ACTIVITY_SCHEMA)));
+ }
+}
--- /dev/null
+<?php
+
+namespace Friendica\Protocol\Activity;
+
+use Friendica\Protocol\ActivityNamespace;
+
+/**
+ * This class contains the different object types in activities
+ */
+final class ObjectType
+{
+ /**
+ * The "bookmark" object type represents a pointer to some URL -- typically a web page.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#bookmark
+ * @var string
+ */
+ const BOOKMARK = ActivityNamespace::ACTIVITY_SCHEMA . 'bookmark';
+ /**
+ * The "comment" object type represents a textual response to another object.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#comment
+ * @var string
+ */
+ const COMMENT = ActivityNamespace::ACTIVITY_SCHEMA . 'comment';
+ /**
+ * The "comment" object type represents a textual response to another object.
+ * (Default type for items)
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#note
+ * @var string
+ */
+ const NOTE = ActivityNamespace::ACTIVITY_SCHEMA . 'note';
+ /**
+ * The "person" object type represents a user account.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#person
+ * @var string
+ */
+ const PERSON = ActivityNamespace::ACTIVITY_SCHEMA . 'person';
+ /**
+ * The "image" object type represents a graphical image.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#image
+ * @var string
+ */
+ const IMAGE = ActivityNamespace::ACTIVITY_SCHEMA . 'image';
+ /**
+ * @var string
+ */
+ const PHOTO = ActivityNamespace::ACTIVITY_SCHEMA . 'photo';
+ /**
+ * The "video" object type represents video content,
+ * which usually consists of a motion picture track and an audio track.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#video
+ * @var string
+ */
+ const VIDEO = ActivityNamespace::ACTIVITY_SCHEMA . 'video';
+ /**
+ * @var string
+ */
+ const PROFILE_PHOTO = ActivityNamespace::ACTIVITY_SCHEMA . 'profile-photo';
+ /**
+ * @var string
+ */
+ const ALBUM = ActivityNamespace::ACTIVITY_SCHEMA . 'photo-album';
+ /**
+ * The "event" object type represents an event that occurs in a certain place during a particular interval of time.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#event
+ * @var string
+ */
+ const EVENT = ActivityNamespace::ACTIVITY_SCHEMA . 'event';
+ /**
+ * The "group" object type represents a grouping of objects in which member objects can join or leave.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#group
+ * @var string
+ */
+ const GROUP = ActivityNamespace::ACTIVITY_SCHEMA . 'group';
+
+
+ /**
+ * @var string
+ */
+ const HEART = ActivityNamespace::DFRN . '/heart';
+ /**
+ * @var string
+ */
+ const TAGTERM = ActivityNamespace::DFRN . '/tagterm';
+ /**
+ * @var string
+ */
+ const PROFILE = ActivityNamespace::DFRN . '/profile';
+
+
+ /**
+ * The "question" object type represents a question or poll.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html#question
+ * @var string
+ */
+ const QUESTION = 'http://activityschema.org/object/question';
+}
--- /dev/null
+<?php
+
+namespace Friendica\Protocol;
+
+/**
+ * Activity namespaces constants
+ */
+final class ActivityNamespace
+{
+ /**
+ * Zot is a WebMTA which provides a decentralised identity and communications protocol using HTTPS/JSON.
+ *
+ * @var string
+ * @see https://zotlabs.org/page/zotlabs/specs+zot6+home
+ */
+ const ZOT = 'http://purl.org/zot';
+ /**
+ * Friendica is using ActivityStreams in version 1.0 for its activities and object types.
+ * Additional types are used for non standard activities.
+ *
+ * @var string
+ * @see https://github.com/friendica/friendica/wiki/ActivityStreams
+ */
+ const DFRN = 'http://purl.org/macgirvin/dfrn/1.0';
+ /**
+ * This namespace defines an extension for expressing threaded
+ * discussions within the Atom Syndication Format [RFC4287]
+ *
+ * @see https://tools.ietf.org/rfc/rfc4685.txt
+ * @var string
+ */
+ const THREAD = 'http://purl.org/syndication/thread/1.0';
+ /**
+ * This namespace adds mechanisms to the Atom Syndication Format
+ * that publishers of Atom Feed and Entry documents can use to
+ * explicitly identify Atom entries that have been removed.
+ *
+ * @see https://tools.ietf.org/html/rfc6721
+ * @var string
+ */
+ const TOMB = 'http://purl.org/atompub/tombstones/1.0';
+ /**
+ * This specification details a model for representing potential and completed activities
+ * using the JSON format.
+ *
+ * @see https://www.w3.org/ns/activitystreams
+ * @var string
+ */
+ const ACTIVITY2 = 'https://www.w3.org/ns/activitystreams#';
+ /**
+ * Atom Activities 1.0
+ *
+ * This namespace presents an XML format that allows activities on social objects
+ * to be expressed within the Atom Syndication Format.
+ *
+ * @see http://activitystrea.ms/spec/1.0
+ * @var string
+ */
+ const ACTIVITY = 'http://activitystrea.ms/spec/1.0/';
+ /**
+ * This namespace presents a base set of Object types and Verbs for use with Activity Streams.
+ *
+ * @see http://activitystrea.ms/head/activity-schema.html
+ * @var string
+ */
+ const ACTIVITY_SCHEMA = 'http://activitystrea.ms/schema/1.0/';
+ /**
+ * Atom Media Extensions
+ *
+ * @var string
+ */
+ const MEDIA = 'http://purl.org/syndication/atommedia';
+ /**
+ * The Salmon Protocol is an open, simple, standards-based solution that lets
+ * aggregators and sources unify the conversations.
+ *
+ * @see http://www.salmon-protocol.org/salmon-protocol-summary
+ * @var string
+ */
+ const SALMON_ME = 'http://salmon-protocol.org/ns/magic-env';
+ /**
+ * OStatus is a minimal specification for distributed status updates or microblogging.
+ *
+ * @see https://ostatus.github.io/spec/OStatus%201.0%20Draft%202.html
+ * @var string
+ */
+ const OSTATUSSUB = 'http://ostatus.org/schema/1.0/subscribe';
+ /**
+ * GeoRSS was designed as a lightweight, community driven way to extend existing feeds with geographic information.
+ *
+ * @see http://www.georss.org/
+ * @var string
+ */
+ const GEORSS = 'http://www.georss.org/georss';
+ /**
+ * The Portable Contacts specification is designed to make it easier for developers
+ * to give their users a secure way to access the address books and friends lists
+ * they have built up all over the web.
+ *
+ * @see http://portablecontacts.net/draft-spec/
+ * @var string
+ */
+ const POCO = 'http://portablecontacts.net/spec/1.0';
+ /**
+ * @var string
+ */
+ const FEED = 'http://schemas.google.com/g/2010#updates-from';
+ /**
+ * OStatus is a minimal specification for distributed status updates or microblogging.
+ *
+ * @see https://ostatus.github.io/spec/OStatus%201.0%20Draft%202.html
+ * @var string
+ */
+ const OSTATUS = 'http://ostatus.org/schema/1.0';
+ /**
+ * @var string
+ */
+ const STATUSNET = 'http://status.net/schema/api/1/';
+ /**
+ * This namespace describes the Atom Activity Streams in RDF Vocabulary (AAIR),
+ * defined as a dictionary of named properties and classes using W3C's RDF technology,
+ * and specifically a mapping of the Atom Activity Streams work to RDF.
+ *
+ * @see http://xmlns.notu.be/aair/#RFC4287
+ * @var string
+ */
+ const ATOM1 = 'http://www.w3.org/2005/Atom';
+ /**
+ * @var string
+ */
+ const MASTODON = 'http://mastodon.social/schema/1.0';
+}
*/
namespace Friendica\Protocol\ActivityPub;
-use Friendica\Database\DBA;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Config;
-use Friendica\Core\PConfig;
use Friendica\Core\Logger;
+use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
-use Friendica\Model\Contact;
+use Friendica\Database\DBA;
use Friendica\Model\APContact;
-use Friendica\Model\Item;
+use Friendica\Model\Contact;
use Friendica\Model\Event;
+use Friendica\Model\Item;
+use Friendica\Model\Mail;
use Friendica\Model\Term;
use Friendica\Model\User;
-use Friendica\Model\Mail;
+use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\JsonLD;
public static function createItem($activity)
{
$item = [];
- $item['verb'] = ACTIVITY_POST;
+ $item['verb'] = Activity::POST;
$item['thr-parent'] = $activity['reply-to-id'];
if ($activity['reply-to-id'] == $activity['id']) {
$item['gravity'] = GRAVITY_PARENT;
- $item['object-type'] = ACTIVITY_OBJ_NOTE;
+ $item['object-type'] = Activity\ObjectType::NOTE;
} else {
$item['gravity'] = GRAVITY_COMMENT;
- $item['object-type'] = ACTIVITY_OBJ_COMMENT;
+ $item['object-type'] = Activity\ObjectType::COMMENT;
}
if (empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Item::exists(['uri' => $activity['reply-to-id']])) {
$item['verb'] = $verb;
$item['thr-parent'] = $activity['object_id'];
$item['gravity'] = GRAVITY_ACTIVITY;
- $item['object-type'] = ACTIVITY_OBJ_NOTE;
+ $item['object-type'] = Activity\ObjectType::NOTE;
$item['diaspora_signed_text'] = $activity['diaspora:like'] ?? '';
use Friendica\Model\Conversation;
use Friendica\Model\Item;
use Friendica\Model\User;
+use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPSignature;
$announce_object_data['object_id'] = $object_data['object_id'];
$announce_object_data['object_type'] = $object_data['object_type'];
- ActivityPub\Processor::createActivity($announce_object_data, ACTIVITY2_ANNOUNCE);
+ ActivityPub\Processor::createActivity($announce_object_data, Activity::ANNOUNCE);
}
}
break;
case 'as:Like':
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
- ActivityPub\Processor::createActivity($object_data, ACTIVITY_LIKE);
+ ActivityPub\Processor::createActivity($object_data, Activity::LIKE);
}
break;
case 'as:Dislike':
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
- ActivityPub\Processor::createActivity($object_data, ACTIVITY_DISLIKE);
+ ActivityPub\Processor::createActivity($object_data, Activity::DISLIKE);
}
break;
case 'as:TentativeAccept':
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
- ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTENDMAYBE);
+ ActivityPub\Processor::createActivity($object_data, Activity::ATTENDMAYBE);
}
break;
ActivityPub\Processor::followUser($object_data);
} elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
$object_data['reply-to-id'] = $object_data['object_id'];
- ActivityPub\Processor::createActivity($object_data, ACTIVITY_FOLLOW);
+ ActivityPub\Processor::createActivity($object_data, Activity::FOLLOW);
}
break;
if ($object_data['object_type'] == 'as:Follow') {
ActivityPub\Processor::acceptFollowUser($object_data);
} elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
- ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTEND);
+ ActivityPub\Processor::createActivity($object_data, Activity::ATTEND);
}
break;
if ($object_data['object_type'] == 'as:Follow') {
ActivityPub\Processor::rejectFollowUser($object_data);
} elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
- ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTENDNO);
+ ActivityPub\Processor::createActivity($object_data, Activity::ATTENDNO);
}
break;
use Friendica\Core\Config;
use Friendica\Core\Logger;
use Friendica\Core\System;
+use Friendica\Protocol\Activity;
use Friendica\Util\HTTPSignature;
use Friendica\Core\Protocol;
use Friendica\Model\Conversation;
if ($reshared) {
$type = 'Announce';
- } elseif ($item['verb'] == ACTIVITY_POST) {
+ } elseif ($item['verb'] == Activity::POST) {
if ($item['created'] == $item['edited']) {
$type = 'Create';
} else {
$type = 'Update';
}
- } elseif ($item['verb'] == ACTIVITY_LIKE) {
+ } elseif ($item['verb'] == Activity::LIKE) {
$type = 'Like';
- } elseif ($item['verb'] == ACTIVITY_DISLIKE) {
+ } elseif ($item['verb'] == Activity::DISLIKE) {
$type = 'Dislike';
- } elseif ($item['verb'] == ACTIVITY_ATTEND) {
+ } elseif ($item['verb'] == Activity::ATTEND) {
$type = 'Accept';
- } elseif ($item['verb'] == ACTIVITY_ATTENDNO) {
+ } elseif ($item['verb'] == Activity::ATTENDNO) {
$type = 'Reject';
- } elseif ($item['verb'] == ACTIVITY_ATTENDMAYBE) {
+ } elseif ($item['verb'] == Activity::ATTENDMAYBE) {
$type = 'TentativeAccept';
- } elseif ($item['verb'] == ACTIVITY_FOLLOW) {
+ } elseif ($item['verb'] == Activity::FOLLOW) {
$type = 'Follow';
- } elseif ($item['verb'] == ACTIVITY_TAG) {
+ } elseif ($item['verb'] == Activity::TAG) {
$type = 'Add';
} else {
$type = '';
$uid = $first_user['uid'];
}
- $condition = ['verb' => ACTIVITY_FOLLOW, 'uid' => 0, 'parent-uri' => $object,
+ $condition = ['verb' => Activity::FOLLOW, 'uid' => 0, 'parent-uri' => $object,
'author-id' => Contact::getPublicIdByUserId($uid)];
if (Item::exists($condition)) {
Logger::log('Follow for ' . $object . ' for user ' . $uid . ' does already exist.', Logger::DEBUG);
use DOMDocument;
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;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;
-use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Object\Image;
+use Friendica\Protocol\ActivityNamespace;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
$type = 'html';
if ($conversation) {
- $root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
+ $root = $doc->createElementNS(ActivityNamespace::ATOM1, 'feed');
$doc->appendChild($root);
- $root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
- $root->setAttribute("xmlns:at", NAMESPACE_TOMB);
- $root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
- $root->setAttribute("xmlns:dfrn", NAMESPACE_DFRN);
- $root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
- $root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
- $root->setAttribute("xmlns:poco", NAMESPACE_POCO);
- $root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
- $root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
+ $root->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
+ $root->setAttribute("xmlns:at", ActivityNamespace::TOMB);
+ $root->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
+ $root->setAttribute("xmlns:dfrn", ActivityNamespace::DFRN);
+ $root->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
+ $root->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
+ $root->setAttribute("xmlns:poco", ActivityNamespace::POCO);
+ $root->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
+ $root->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
//$root = self::addHeader($doc, $owner, "dfrn:owner", "", false);
$alternatelink = $owner['url'];
}
- $root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
+ $root = $doc->createElementNS(ActivityNamespace::ATOM1, 'feed');
$doc->appendChild($root);
- $root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
- $root->setAttribute("xmlns:at", NAMESPACE_TOMB);
- $root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
- $root->setAttribute("xmlns:dfrn", NAMESPACE_DFRN);
- $root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
- $root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
- $root->setAttribute("xmlns:poco", NAMESPACE_POCO);
- $root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
- $root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
+ $root->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
+ $root->setAttribute("xmlns:at", ActivityNamespace::TOMB);
+ $root->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
+ $root->setAttribute("xmlns:dfrn", ActivityNamespace::DFRN);
+ $root->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
+ $root->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
+ $root->setAttribute("xmlns:poco", ActivityNamespace::POCO);
+ $root->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
+ $root->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
XML::addElement($doc, $root, "id", System::baseUrl()."/profile/".$owner["nick"]);
XML::addElement($doc, $root, "title", $owner["name"]);
if (!$single) {
$entry = $doc->createElement("entry");
} else {
- $entry = $doc->createElementNS(NAMESPACE_ATOM1, 'entry');
+ $entry = $doc->createElementNS(ActivityNamespace::ATOM1, 'entry');
$doc->appendChild($entry);
- $entry->setAttribute("xmlns:thr", NAMESPACE_THREAD);
- $entry->setAttribute("xmlns:at", NAMESPACE_TOMB);
- $entry->setAttribute("xmlns:media", NAMESPACE_MEDIA);
- $entry->setAttribute("xmlns:dfrn", NAMESPACE_DFRN);
- $entry->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
- $entry->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
- $entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
- $entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
- $entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
+ $entry->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
+ $entry->setAttribute("xmlns:at", ActivityNamespace::TOMB);
+ $entry->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
+ $entry->setAttribute("xmlns:dfrn", ActivityNamespace::DFRN);
+ $entry->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
+ $entry->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
+ $entry->setAttribute("xmlns:poco", ActivityNamespace::POCO);
+ $entry->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
+ $entry->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
}
if ($item['private']) {
if ($item['object-type'] != "") {
XML::addElement($doc, $entry, "activity:object-type", $item['object-type']);
} elseif ($item['id'] == $item['parent']) {
- XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
+ XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::NOTE);
} else {
- XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_COMMENT);
+ XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::COMMENT);
}
$actobj = self::createActivity($doc, "activity:object", $item['object']);
"link",
"",
["rel" => "mentioned",
- "ostatus:object-type" => ACTIVITY_OBJ_GROUP,
+ "ostatus:object-type" => Activity\ObjectType::GROUP,
"href" => $mention]
);
} else {
"link",
"",
["rel" => "mentioned",
- "ostatus:object-type" => ACTIVITY_OBJ_PERSON,
+ "ostatus:object-type" => Activity\ObjectType::PERSON,
"href" => $mention]
);
}
$obj_doc = new DOMDocument("1.0", "utf-8");
$obj_doc->formatOutput = true;
- $obj_element = $obj_doc->createElementNS(NAMESPACE_ATOM1, $element);
+ $obj_element = $obj_doc->createElementNS( ActivityNamespace::ATOM1, $element);
$activity_type = $xpath->query("activity:object-type/text()", $activity)->item(0)->nodeValue;
XML::addElement($obj_doc, $obj_element, "type", $activity_type);
'source_name' => $importer['name'],
'source_link' => $importer['url'],
'source_photo' => $importer['photo'],
- 'verb' => ACTIVITY_REQ_FRIEND,
+ 'verb' => Activity::REQ_FRIEND,
'otype' => 'intro']
);
}
$xo = XML::parseString($item["object"], false);
- if (($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) {
+ if (($xo->type == Activity\ObjectType::PERSON) && ($xo->id)) {
// somebody was poked/prodded. Was it me?
$Blink = '';
foreach ($xo->link as $l) {
// 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;
}
} else {
- if (($item["verb"] == ACTIVITY_LIKE)
- || ($item["verb"] == ACTIVITY_DISLIKE)
- || ($item["verb"] == ACTIVITY_ATTEND)
- || ($item["verb"] == ACTIVITY_ATTENDNO)
- || ($item["verb"] == ACTIVITY_ATTENDMAYBE)
+ if (($item["verb"] == Activity::LIKE)
+ || ($item["verb"] == Activity::DISLIKE)
+ || ($item["verb"] == Activity::ATTEND)
+ || ($item["verb"] == Activity::ATTENDNO)
+ || ($item["verb"] == Activity::ATTENDMAYBE)
) {
$is_like = true;
$item["gravity"] = GRAVITY_ACTIVITY;
$is_like = false;
}
- if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) {
+ if (($item["verb"] == Activity::TAG) && ($item["object-type"] == Activity\ObjectType::TAGTERM)) {
$xo = XML::parseString($item["object"], false);
$xt = XML::parseString($item["target"], false);
- if ($xt->type == ACTIVITY_OBJ_NOTE) {
+ if ($xt->type == Activity\ObjectType::NOTE) {
$item_tag = Item::selectFirst(['id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]);
if (!DBA::isResult($item_tag)) {
// Now assign the rest of the values that depend on the type of the message
if (in_array($entrytype, [DFRN::REPLY, DFRN::REPLY_RC])) {
if (!isset($item["object-type"])) {
- $item["object-type"] = ACTIVITY_OBJ_COMMENT;
+ $item["object-type"] = Activity\ObjectType::COMMENT;
}
if ($item["contact-id"] != $owner["contact-id"]) {
$item["wall"] = 1;
} elseif ($entrytype == DFRN::TOP_LEVEL) {
if (!isset($item["object-type"])) {
- $item["object-type"] = ACTIVITY_OBJ_NOTE;
+ $item["object-type"] = Activity\ObjectType::NOTE;
}
// Is it an event?
- if (($item["object-type"] == ACTIVITY_OBJ_EVENT) && !$owner_unknown) {
+ if (($item["object-type"] == Activity\ObjectType::EVENT) && !$owner_unknown) {
Logger::log("Item ".$item["uri"]." seems to contain an event.", Logger::DEBUG);
$ev = Event::fromBBCode($item["body"]);
if ((!empty($ev['desc']) || !empty($ev['summary'])) && !empty($ev['start'])) {
Item::distribute($posted_id);
}
- if (stristr($item["verb"], ACTIVITY_POKE)) {
+ if (stristr($item["verb"], Activity::POKE)) {
$item['id'] = $posted_id;
self::doPoke($item, $importer);
}
@$doc->loadXML($xml);
$xpath = new DOMXPath($doc);
- $xpath->registerNamespace("atom", NAMESPACE_ATOM1);
- $xpath->registerNamespace("thr", NAMESPACE_THREAD);
- $xpath->registerNamespace("at", NAMESPACE_TOMB);
- $xpath->registerNamespace("media", NAMESPACE_MEDIA);
- $xpath->registerNamespace("dfrn", NAMESPACE_DFRN);
- $xpath->registerNamespace("activity", NAMESPACE_ACTIVITY);
- $xpath->registerNamespace("georss", NAMESPACE_GEORSS);
- $xpath->registerNamespace("poco", NAMESPACE_POCO);
- $xpath->registerNamespace("ostatus", NAMESPACE_OSTATUS);
- $xpath->registerNamespace("statusnet", NAMESPACE_STATUSNET);
+ $xpath->registerNamespace("atom", ActivityNamespace::ATOM1);
+ $xpath->registerNamespace("thr", ActivityNamespace::THREAD);
+ $xpath->registerNamespace("at", ActivityNamespace::TOMB);
+ $xpath->registerNamespace("media", ActivityNamespace::MEDIA);
+ $xpath->registerNamespace("dfrn", ActivityNamespace::DFRN);
+ $xpath->registerNamespace("activity", ActivityNamespace::ACTIVITY);
+ $xpath->registerNamespace("georss", ActivityNamespace::GEORSS);
+ $xpath->registerNamespace("poco", ActivityNamespace::POCO);
+ $xpath->registerNamespace("ostatus", ActivityNamespace::OSTATUS);
+ $xpath->registerNamespace("statusnet", ActivityNamespace::STATUSNET);
$header = [];
$header["uid"] = $importer["importer_uid"];
if ($item['verb']) {
return $item['verb'];
}
- return ACTIVITY_POST;
+ return Activity::POST;
}
private static function tgroupCheck($uid, $item)
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Network\Probe;
+use Friendica\Protocol\ActivityNamespace;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
}
}
- $base = $basedom->children(NAMESPACE_SALMON_ME);
+ $base = $basedom->children(ActivityNamespace::SALMON_ME);
// Not sure if this cleaning is needed
$data = str_replace([" ", "\t", "\r", "\n"], ["", "", "", ""], $base->data);
$author_link = str_replace('acct:', '', $idom->author_id);
}
- $dom = $basedom->children(NAMESPACE_SALMON_ME);
+ $dom = $basedom->children(ActivityNamespace::SALMON_ME);
// figure out where in the DOM tree our data is hiding
$datarray["guid"] = $guid;
$datarray["uri"] = self::getUriFromGuid($author, $guid);
- $datarray["verb"] = ACTIVITY_POST;
+ $datarray["verb"] = Activity::POST;
$datarray["gravity"] = GRAVITY_COMMENT;
if ($thr_uri != "") {
$datarray["parent-uri"] = $parent_item["uri"];
}
- $datarray["object-type"] = ACTIVITY_OBJ_COMMENT;
+ $datarray["object-type"] = Activity\ObjectType::COMMENT;
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
$datarray["source"] = $xml;
// "positive" = "false" would be a Dislike - wich isn't currently supported by Diaspora
// We would accept this anyhow.
if ($positive == "true") {
- $verb = ACTIVITY_LIKE;
+ $verb = Activity::LIKE;
} else {
- $verb = ACTIVITY_DISLIKE;
+ $verb = Activity::DISLIKE;
}
$datarray = [];
$datarray["gravity"] = GRAVITY_ACTIVITY;
$datarray["parent-uri"] = $parent_item["uri"];
- $datarray["object-type"] = ACTIVITY_OBJ_NOTE;
+ $datarray["object-type"] = Activity\ObjectType::NOTE;
$datarray["body"] = $verb;
$datarray['uri'] = self::getUriFromGuid($author, $datarray['guid']);
$datarray['parent-uri'] = $parent['uri'];
- $datarray['verb'] = $datarray['body'] = ACTIVITY2_ANNOUNCE;
+ $datarray['verb'] = $datarray['body'] = Activity::ANNOUNCE;
$datarray['gravity'] = GRAVITY_ACTIVITY;
- $datarray['object-type'] = ACTIVITY_OBJ_NOTE;
+ $datarray['object-type'] = Activity\ObjectType::NOTE;
$datarray['protocol'] = $item['protocol'];
$datarray["guid"] = $guid;
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
- $datarray["verb"] = ACTIVITY_POST;
+ $datarray["verb"] = Activity::POST;
$datarray["gravity"] = GRAVITY_PARENT;
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
XML::unescape($photo->remote_photo_name)."[/img]\n".$body;
}
- $datarray["object-type"] = ACTIVITY_OBJ_IMAGE;
+ $datarray["object-type"] = Activity\ObjectType::IMAGE;
} else {
- $datarray["object-type"] = ACTIVITY_OBJ_NOTE;
+ $datarray["object-type"] = Activity\ObjectType::NOTE;
// Add OEmbed and other information to the body
if (!self::isRedmatrix($contact["url"])) {
$datarray["guid"] = $guid;
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
- $datarray["verb"] = ACTIVITY_POST;
+ $datarray["verb"] = Activity::POST;
$datarray["gravity"] = GRAVITY_PARENT;
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
$target_type = ($parent["uri"] === $parent["parent-uri"] ? "Post" : "Comment");
$positive = null;
- if ($item['verb'] === ACTIVITY_LIKE) {
+ if ($item['verb'] === Activity::LIKE) {
$positive = "true";
- } elseif ($item['verb'] === ACTIVITY_DISLIKE) {
+ } elseif ($item['verb'] === Activity::DISLIKE) {
$positive = "false";
}
}
switch ($item['verb']) {
- case ACTIVITY_ATTEND:
+ case Activity::ATTEND:
$attend_answer = 'accepted';
break;
- case ACTIVITY_ATTENDNO:
+ case Activity::ATTENDNO:
$attend_answer = 'declined';
break;
- case ACTIVITY_ATTENDMAYBE:
+ case Activity::ATTENDMAYBE:
$attend_answer = 'tentative';
break;
default:
*/
public static function sendFollowup(array $item, array $owner, array $contact, $public_batch = false)
{
- if (in_array($item['verb'], [ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE])) {
+ if (in_array($item['verb'], [Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE])) {
$message = self::constructAttend($item, $owner);
$type = "event_participation";
- } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+ } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
$message = self::constructLike($item, $owner);
$type = "like";
- } elseif (!in_array($item["verb"], [ACTIVITY_FOLLOW, ACTIVITY_TAG])) {
+ } elseif (!in_array($item["verb"], [Activity::FOLLOW, Activity::TAG])) {
$message = self::constructComment($item, $owner);
$type = "comment";
}
$message = ["author" => $item['signer'],
"target_guid" => $signed_parts[0],
"target_type" => $signed_parts[1]];
- } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+ } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
$message = ["author" => $signed_parts[4],
"guid" => $signed_parts[1],
"parent_guid" => $signed_parts[3],
{
if ($item["deleted"]) {
return self::sendRetraction($item, $owner, $contact, $public_batch, true);
- } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+ } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
$type = "like";
} else {
$type = "comment";
if ($item['id'] == $item['parent']) {
$target_type = "Post";
- } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+ } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
$target_type = "Like";
} else {
$target_type = "Comment";
return false;
}
- if (!in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+ if (!in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
return false;
}
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Item;
+use Friendica\Protocol\ActivityNamespace;
use Friendica\Util\Network;
use Friendica\Util\XML;
$doc = new DOMDocument();
@$doc->loadXML(trim($xml));
$xpath = new DOMXPath($doc);
- $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
+ $xpath->registerNamespace('atom', ActivityNamespace::ATOM1);
$xpath->registerNamespace('dc', "http://purl.org/dc/elements/1.1/");
$xpath->registerNamespace('content', "http://purl.org/rss/1.0/modules/content/");
$xpath->registerNamespace('rdf', "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
$xpath->registerNamespace('rss', "http://purl.org/rss/1.0/");
$xpath->registerNamespace('media', "http://search.yahoo.com/mrss/");
- $xpath->registerNamespace('poco', NAMESPACE_POCO);
+ $xpath->registerNamespace('poco', ActivityNamespace::POCO);
$author = [];
$entries = null;
$header["origin"] = 0;
$header["gravity"] = GRAVITY_PARENT;
$header["private"] = 2;
- $header["verb"] = ACTIVITY_POST;
- $header["object-type"] = ACTIVITY_OBJ_NOTE;
+ $header["verb"] = Activity::POST;
+ $header["object-type"] = Activity\ObjectType::NOTE;
$header["contact-id"] = $contact["id"];
$item["title"] = "";
$item["body"] = $item["body"].add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
$item["tag"] = add_page_keywords($item["plink"], $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
- $item["object-type"] = ACTIVITY_OBJ_BOOKMARK;
+ $item["object-type"] = Activity\ObjectType::BOOKMARK;
unset($item["attach"]);
} else {
if (!empty($summary)) {
use Friendica\Content\Text\HTML;
use Friendica\Core\Cache;
use Friendica\Core\Config;
-use Friendica\Core\PConfig;
use Friendica\Core\L10n;
-use Friendica\Core\Logger;
use Friendica\Core\Lock;
+use Friendica\Core\Logger;
+use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA;
+use Friendica\Model\APContact;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\GContact;
-use Friendica\Model\APContact;
use Friendica\Model\Item;
use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Object\Image;
+use Friendica\Protocol\ActivityNamespace;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils;
@$doc->loadXML($xml);
$xpath = new DOMXPath($doc);
- $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
- $xpath->registerNamespace('thr', NAMESPACE_THREAD);
- $xpath->registerNamespace('georss', NAMESPACE_GEORSS);
- $xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
- $xpath->registerNamespace('media', NAMESPACE_MEDIA);
- $xpath->registerNamespace('poco', NAMESPACE_POCO);
- $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
- $xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
+ $xpath->registerNamespace('atom', ActivityNamespace::ATOM1);
+ $xpath->registerNamespace('thr', ActivityNamespace::THREAD);
+ $xpath->registerNamespace('georss', ActivityNamespace::GEORSS);
+ $xpath->registerNamespace('activity', ActivityNamespace::ACTIVITY);
+ $xpath->registerNamespace('media', ActivityNamespace::MEDIA);
+ $xpath->registerNamespace('poco', ActivityNamespace::POCO);
+ $xpath->registerNamespace('ostatus', ActivityNamespace::OSTATUS);
+ $xpath->registerNamespace('statusnet', ActivityNamespace::STATUSNET);
$contact = ["id" => 0];
@$doc->loadXML($xml);
$xpath = new DOMXPath($doc);
- $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
- $xpath->registerNamespace('thr', NAMESPACE_THREAD);
- $xpath->registerNamespace('georss', NAMESPACE_GEORSS);
- $xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
- $xpath->registerNamespace('media', NAMESPACE_MEDIA);
- $xpath->registerNamespace('poco', NAMESPACE_POCO);
- $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
- $xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
+ $xpath->registerNamespace('atom', ActivityNamespace::ATOM1);
+ $xpath->registerNamespace('thr', ActivityNamespace::THREAD);
+ $xpath->registerNamespace('georss', ActivityNamespace::GEORSS);
+ $xpath->registerNamespace('activity', ActivityNamespace::ACTIVITY);
+ $xpath->registerNamespace('media', ActivityNamespace::MEDIA);
+ $xpath->registerNamespace('poco', ActivityNamespace::POCO);
+ $xpath->registerNamespace('ostatus', ActivityNamespace::OSTATUS);
+ $xpath->registerNamespace('statusnet', ActivityNamespace::STATUSNET);
$hub = "";
$hub_items = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0);
$item["verb"] = XML::getFirstNodeValue($xpath, 'activity:verb/text()', $entry);
// Delete a message
- if (in_array($item["verb"], ['qvitter-delete-notice', ACTIVITY_DELETE, 'delete'])) {
+ if (in_array($item["verb"], ['qvitter-delete-notice', Activity::DELETE, 'delete'])) {
self::deleteNotice($item);
continue;
}
- if (in_array($item["verb"], [NAMESPACE_OSTATUS."/unfavorite", ACTIVITY_UNFAVORITE])) {
+ if (in_array($item["verb"], [Activity::O_UNFAVOURITE, Activity::UNFAVORITE])) {
// Ignore "Unfavorite" message
Logger::log("Ignore unfavorite message ".print_r($item, true), Logger::DEBUG);
continue;
Logger::log('Processing post with URI '.$item["uri"].' for user '.$importer["uid"].'.', Logger::DEBUG);
}
- if ($item["verb"] == ACTIVITY_JOIN) {
+ if ($item["verb"] == Activity::JOIN) {
// ignore "Join" messages
Logger::log("Ignore join message ".print_r($item, true), Logger::DEBUG);
continue;
continue;
}
- if ($item["verb"] == ACTIVITY_FOLLOW) {
+ if ($item["verb"] == Activity::FOLLOW) {
Contact::addRelationship($importer, $contact, $item);
continue;
}
- if ($item["verb"] == NAMESPACE_OSTATUS."/unfollow") {
+ if ($item["verb"] == Activity::O_UNFOLLOW) {
$dummy = null;
Contact::removeFollower($importer, $contact, $item, $dummy);
continue;
}
- if ($item["verb"] == ACTIVITY_FAVORITE) {
+ if ($item["verb"] == Activity::FAVORITE) {
$orig_uri = $xpath->query("activity:object/atom:id", $entry)->item(0)->nodeValue;
Logger::log("Favorite ".$orig_uri." ".print_r($item, true));
- $item["verb"] = ACTIVITY_LIKE;
+ $item["verb"] = Activity::LIKE;
$item["parent-uri"] = $orig_uri;
$item["gravity"] = GRAVITY_ACTIVITY;
- $item["object-type"] = ACTIVITY_OBJ_NOTE;
+ $item["object-type"] = Activity\ObjectType::NOTE;
}
// http://activitystrea.ms/schema/1.0/rsvp-yes
- if (!in_array($item["verb"], [ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE])) {
+ if (!in_array($item["verb"], [Activity::POST, Activity::LIKE, Activity::SHARE])) {
Logger::log("Unhandled verb ".$item["verb"]." ".print_r($item, true), Logger::DEBUG);
}
if ($valid) {
// Never post a thread when the only interaction by our contact was a like
$valid = false;
- $verbs = [ACTIVITY_POST, ACTIVITY_SHARE];
+ $verbs = [Activity::POST, Activity::SHARE];
foreach (self::$itemlist as $item) {
if (in_array($item['verb'], $verbs) && Contact::isSharingByURL($item['author-link'], $item['uid'])) {
$valid = true;
{
$item["body"] = HTML::toBBCode(XML::getFirstNodeValue($xpath, 'atom:content/text()', $entry));
$item["object-type"] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $entry);
- if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
+ if (($item["object-type"] == Activity\ObjectType::BOOKMARK) || ($item["object-type"] == Activity\ObjectType::EVENT)) {
$item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
$item["body"] = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry);
- } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) {
+ } elseif ($item["object-type"] == Activity\ObjectType::QUESTION) {
$item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
}
}
}
// Is it a repeated post?
- if (($repeat_of != "") || ($item["verb"] == ACTIVITY_SHARE)) {
+ if (($repeat_of != "") || ($item["verb"] == Activity::SHARE)) {
$link_data = self::processRepeatedItem($xpath, $entry, $item, $importer);
if (!empty($link_data['add_body'])) {
$add_body .= $link_data['add_body'];
}
// Mastodon Content Warning
- if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
+ if (($item["verb"] == Activity::POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
$clear_text = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry);
if (!empty($clear_text)) {
$item['content-warning'] = HTML::toBBCode($clear_text);
@$doc->loadXML($xml);
$xpath = new DOMXPath($doc);
- $xpath->registerNamespace('atom', NAMESPACE_ATOM1);
- $xpath->registerNamespace('thr', NAMESPACE_THREAD);
- $xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
+ $xpath->registerNamespace('atom', ActivityNamespace::ATOM1);
+ $xpath->registerNamespace('thr', ActivityNamespace::THREAD);
+ $xpath->registerNamespace('ostatus', ActivityNamespace::OSTATUS);
$entries = $xpath->query('/atom:feed/atom:entry');
$item["object-type"] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $activityobject);
// Mastodon Content Warning
- if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $activityobject)) {
+ if (($item["verb"] == Activity::POST) && $xpath->evaluate('boolean(atom:summary)', $activityobject)) {
$clear_text = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $activityobject);
if (!empty($clear_text)) {
$item['content-warning'] = HTML::toBBCode($clear_text);
switch ($attribute['rel']) {
case "alternate":
$item["plink"] = $attribute['href'];
- if (($item["object-type"] == ACTIVITY_OBJ_QUESTION)
- || ($item["object-type"] == ACTIVITY_OBJ_EVENT)
+ if (($item["object-type"] == Activity\ObjectType::QUESTION)
+ || ($item["object-type"] == Activity\ObjectType::EVENT)
) {
$item["body"] .= add_page_info($attribute['href']);
}
}
break;
case "related":
- if ($item["object-type"] != ACTIVITY_OBJ_BOOKMARK) {
+ if ($item["object-type"] != Activity\ObjectType::BOOKMARK) {
if (!isset($item["parent-uri"])) {
$item["parent-uri"] = $attribute['href'];
}
*/
private static function addHeader(DOMDocument $doc, array $owner, $filter, $feed_mode = false)
{
- $root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
+ $root = $doc->createElementNS(ActivityNamespace::ATOM1, 'feed');
$doc->appendChild($root);
- $root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
- $root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
- $root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
- $root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
- $root->setAttribute("xmlns:poco", NAMESPACE_POCO);
- $root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
- $root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
- $root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
+ $root->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
+ $root->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
+ $root->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
+ $root->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
+ $root->setAttribute("xmlns:poco", ActivityNamespace::POCO);
+ $root->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
+ $root->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
+ $root->setAttribute("xmlns:mastodon", ActivityNamespace::MASTODON);
$title = '';
$selfUri = '/feed/' . $owner["nick"] . '/';
$author = $doc->createElement("author");
XML::addElement($doc, $author, "id", $owner["url"]);
if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
- XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_GROUP);
+ XML::addElement($doc, $author, "activity:object-type", Activity\ObjectType::GROUP);
} else {
- XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
+ XML::addElement($doc, $author, "activity:object-type", Activity\ObjectType::PERSON);
}
XML::addElement($doc, $author, "uri", $owner["url"]);
XML::addElement($doc, $author, "name", $owner["nick"]);
return $item['verb'];
}
- return ACTIVITY_POST;
+ return Activity::POST;
}
/**
*/
private static function constructObjecttype(array $item)
{
- if (!empty($item['object-type']) && in_array($item['object-type'], [ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT])) {
+ if (!empty($item['object-type']) && in_array($item['object-type'], [Activity\ObjectType::NOTE, Activity\ObjectType::COMMENT])) {
return $item['object-type'];
}
- return ACTIVITY_OBJ_NOTE;
+ return Activity\ObjectType::NOTE;
}
/**
return $xml;
}
- if ($item["verb"] == ACTIVITY_LIKE) {
+ if ($item["verb"] == Activity::LIKE) {
return self::likeEntry($doc, $item, $owner, $toplevel);
- } elseif (in_array($item["verb"], [ACTIVITY_FOLLOW, NAMESPACE_OSTATUS."/unfollow"])) {
+ } elseif (in_array($item["verb"], [Activity::FOLLOW, Activity::O_UNFOLLOW])) {
return self::followEntry($doc, $item, $owner, $toplevel);
} else {
return self::noteEntry($doc, $item, $owner, $toplevel, $feed_mode);
$title = $owner["nick"]." repeated a notice by ".$contact["nick"];
- self::entryContent($doc, $entry, $item, $owner, $title, ACTIVITY_SHARE, false);
+ self::entryContent($doc, $entry, $item, $owner, $title, Activity::SHARE, false);
$as_object = $doc->createElement("activity:object");
- XML::addElement($doc, $as_object, "activity:object-type", NAMESPACE_ACTIVITY_SCHEMA."activity");
+ XML::addElement($doc, $as_object, "activity:object-type", ActivityNamespace::ACTIVITY_SCHEMA . "activity");
self::entryContent($doc, $as_object, $repeated_item, $owner, "", "", false);
$entry = self::entryHeader($doc, $owner, $item, $toplevel);
- $verb = NAMESPACE_ACTIVITY_SCHEMA."favorite";
+ $verb = ActivityNamespace::ACTIVITY_SCHEMA . "favorite";
self::entryContent($doc, $entry, $item, $owner, "Favorite", $verb, false);
$parent = Item::selectFirst([], ['uri' => $item["thr-parent"], 'uid' => $item["uid"]]);
private static function addPersonObject(DOMDocument $doc, array $owner, array $contact)
{
$object = $doc->createElement("activity:object");
- XML::addElement($doc, $object, "activity:object-type", ACTIVITY_OBJ_PERSON);
+ XML::addElement($doc, $object, "activity:object-type", Activity\ObjectType::PERSON);
if ($contact['network'] == Protocol::PHANTOM) {
XML::addElement($doc, $object, "id", $contact['url']);
$connect_id = 0;
}
- if ($item['verb'] == ACTIVITY_FOLLOW) {
+ if ($item['verb'] == Activity::FOLLOW) {
$message = L10n::t('%s is now following %s.');
$title = L10n::t('following');
$action = "subscription";
$entry = self::entryHeader($doc, $owner, $item, $toplevel);
- XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
+ XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::NOTE);
self::entryContent($doc, $entry, $item, $owner, $title, '', true, $feed_mode);
$entry->appendChild($author);
}
} else {
- $entry = $doc->createElementNS(NAMESPACE_ATOM1, "entry");
+ $entry = $doc->createElementNS(ActivityNamespace::ATOM1, "entry");
- $entry->setAttribute("xmlns:thr", NAMESPACE_THREAD);
- $entry->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
- $entry->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
- $entry->setAttribute("xmlns:media", NAMESPACE_MEDIA);
- $entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
- $entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
- $entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
- $entry->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
+ $entry->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
+ $entry->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
+ $entry->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
+ $entry->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
+ $entry->setAttribute("xmlns:poco", ActivityNamespace::POCO);
+ $entry->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
+ $entry->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
+ $entry->setAttribute("xmlns:mastodon", ActivityNamespace::MASTODON);
$author = self::addAuthor($doc, $owner);
$entry->appendChild($author);
XML::addElement($doc, $entry, "link", "",
[
"rel" => "mentioned",
- "ostatus:object-type" => ACTIVITY_OBJ_GROUP,
+ "ostatus:object-type" => Activity\ObjectType::GROUP,
"href" => $mention]
);
} else {
XML::addElement($doc, $entry, "link", "",
[
"rel" => "mentioned",
- "ostatus:object-type" => ACTIVITY_OBJ_PERSON,
+ "ostatus:object-type" => Activity\ObjectType::PERSON,
"href" => $mention]
);
}
if ($filter === 'comments') {
$condition[0] .= " AND `object-type` = ? ";
- $condition[] = ACTIVITY_OBJ_COMMENT;
+ $condition[] = Activity\ObjectType::COMMENT;
}
if ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
--- /dev/null
+<?php
+
+namespace Friendica\Util;
+
+use Friendica\Model\Group;
+
+/**
+ * Util class for ACL formatting
+ */
+final class ACLFormatter
+{
+ /**
+ * Turn user/group ACLs stored as angle bracketed text into arrays
+ *
+ * @param string $ids A angle-bracketed list of IDs
+ *
+ * @return array The array based on the IDs
+ */
+ public function expand(string $ids)
+ {
+ // turn string array of angle-bracketed elements into numeric array
+ // e.g. "<1><2><3>" => array(1,2,3);
+ preg_match_all('/<(' . Group::FOLLOWERS . '|'. Group::MUTUALS . '|[0-9]+)>/', $ids, $matches, PREG_PATTERN_ORDER);
+
+ return $matches[1];
+ }
+
+ /**
+ * Wrap ACL elements in angle brackets for storage
+ *
+ * @param string $item The item to sanitise
+ */
+ private function sanitize(string &$item) {
+ if (intval($item)) {
+ $item = '<' . intval(Strings::escapeTags(trim($item))) . '>';
+ } elseif (in_array($item, [Group::FOLLOWERS, Group::MUTUALS])) {
+ $item = '<' . $item . '>';
+ } else {
+ $item = '';
+ }
+ }
+
+ /**
+ * Convert an ACL array to a storable string
+ *
+ * Normally ACL permissions will be an array.
+ * We'll also allow a comma-separated string.
+ *
+ * @param string|array $permissions
+ *
+ * @return string
+ */
+ function toString($permissions) {
+ $return = '';
+ if (is_array($permissions)) {
+ $item = $permissions;
+ } else {
+ $item = explode(',', $permissions);
+ }
+
+ if (is_array($item)) {
+ array_walk($item, [$this, 'sanitize']);
+ $return = implode('', $item);
+ }
+ return $return;
+ }
+}
return $d->format($format);
}
+
+ /**
+ * Checks, if the given string is a date with the pattern YYYY-MM
+ *
+ * @param string $dateString The given date
+ *
+ * @return boolean True, if the date is a valid pattern
+ */
+ public function isYearMonth(string $dateString)
+ {
+ // Check format (2019-01, 2019-1, 2019-10)
+ if (!preg_match('/^([12]\d{3}-(1[0-2]|0[1-9]|\d))$/', $dateString)) {
+ return false;
+ }
+
+ $date = DateTime::createFromFormat('Y-m', $dateString);
+
+ if (!$date) {
+ return false;
+ }
+
+ try {
+ $now = new DateTime();
+ } catch (\Throwable $t) {
+ return false;
+ }
+
+ if ($date > $now) {
+ return false;
+ }
+
+ return true;
+ }
}
--- /dev/null
+<?php
+
+namespace Friendica\Util;
+
+/**
+ * Util class for filesystem manipulation
+ */
+final class FileSystem
+{
+ /**
+ * @var string a error message
+ */
+ private $errorMessage;
+
+ /**
+ * Creates a directory based on a file, which gets accessed
+ *
+ * @param string $file The file
+ *
+ * @return string The directory name (empty if no directory is found, like urls)
+ */
+ public function createDir(string $file)
+ {
+ $dirname = null;
+ $pos = strpos($file, '://');
+
+ if (!$pos) {
+ $dirname = realpath(dirname($file));
+ }
+
+ if (substr($file, 0, 7) === 'file://') {
+ $dirname = realpath(dirname(substr($file, 7)));
+ }
+
+ if (isset($dirname) && !is_dir($dirname)) {
+ set_error_handler([$this, 'customErrorHandler']);
+ $status = mkdir($dirname, 0777, true);
+ restore_error_handler();
+
+ if (!$status && !is_dir($dirname)) {
+ throw new \UnexpectedValueException(sprintf('Directory "%s" cannot get created: ' . $this->errorMessage, $dirname));
+ }
+
+ return $dirname;
+ } elseif (isset($dirname) && is_dir($dirname)) {
+ return $dirname;
+ } else {
+ return '';
+ }
+ }
+
+ /**
+ * Creates a stream based on a URL (could be a local file or a real URL)
+ *
+ * @param string $url The file/url
+ *
+ * @return false|resource the open stream ressource
+ */
+ public function createStream(string $url)
+ {
+ $directory = $this->createDir($url);
+ set_error_handler([$this, 'customErrorHandler']);
+ if (!empty($directory)) {
+ $url = $directory . DIRECTORY_SEPARATOR . pathinfo($url, PATHINFO_BASENAME);
+ }
+
+ $stream = fopen($url, 'ab');
+ restore_error_handler();
+
+ if (!is_resource($stream)) {
+ throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: ' . $this->errorMessage, $url));
+ }
+
+ return $stream;
+ }
+
+ private function customErrorHandler($code, $msg)
+ {
+ $this->errorMessage = preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg);
+ }
+}
namespace Friendica\Util\Logger;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\FileSystem;
use Friendica\Util\Introspection;
use Psr\Log\LogLevel;
private $pid;
/**
- * An error message
- * @var string
+ * @var FileSystem
*/
- private $errorMessage;
+ private $fileSystem;
/**
* Translates LogLevel log levels to integer values
*
* @throws \Exception
*/
- public function __construct($channel, $stream, Introspection $introspection, $level = LogLevel::DEBUG)
+ public function __construct($channel, $stream, Introspection $introspection, FileSystem $fileSystem, $level = LogLevel::DEBUG)
{
+ $this->fileSystem = $fileSystem;
+
parent::__construct($channel, $introspection);
if (is_resource($stream)) {
} else {
throw new \InvalidArgumentException(sprintf('The level "%s" is not valid.', $level));
}
+
+ $this->checkStream();
}
public function close()
throw new \LogicException('Missing stream URL.');
}
- $this->createDir();
- set_error_handler([$this, 'customErrorHandler']);
- $this->stream = fopen($this->url, 'ab');
- restore_error_handler();
-
- if (!is_resource($this->stream)) {
- $this->stream = null;
-
- throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: ' . $this->errorMessage, $this->url));
- }
- }
-
- private function createDir()
- {
- $dirname = null;
- $pos = strpos($this->url, '://');
- if (!$pos) {
- $dirname = dirname($this->url);
- }
-
- if (substr($this->url, 0, 7) === 'file://') {
- $dirname = dirname(substr($this->url, 7));
- }
-
- if (isset($dirname) && !is_dir($dirname)) {
- set_error_handler([$this, 'customErrorHandler']);
- $status = mkdir($dirname, 0777, true);
- restore_error_handler();
-
- if (!$status && !is_dir($dirname)) {
- throw new \UnexpectedValueException(sprintf('Directory "%s" cannot get created: ' . $this->errorMessage, $dirname));
- }
- }
- }
-
- private function customErrorHandler($code, $msg)
- {
- $this->errorMessage = preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg);
+ $this->stream = $this->fileSystem->createStream($this->url);
}
}
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\OStatus;
use Friendica\Protocol\Salmon;
+use Friendica\Util\ACLFormatter;
require_once 'include/items.php';
$public_message = false; // private recipients, not public
}
- $allow_people = expand_acl($parent['allow_cid']);
- $allow_groups = Group::expand($uid, expand_acl($parent['allow_gid']),true);
- $deny_people = expand_acl($parent['deny_cid']);
- $deny_groups = Group::expand($uid, expand_acl($parent['deny_gid']));
+ /** @var ACLFormatter $aclFormatter */
+ $aclFormatter = BaseObject::getClass(ACLFormatter::class);
+
+ $allow_people = $aclFormatter->expand($parent['allow_cid']);
+ $allow_groups = Group::expand($uid, $aclFormatter->expand($parent['allow_gid']),true);
+ $deny_people = $aclFormatter->expand($parent['deny_cid']);
+ $deny_groups = Group::expand($uid, $aclFormatter->expand($parent['deny_gid']));
// if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
// a delivery fork. private groups (forum_mode == 2) do not uplink
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\User;
+use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\Email;
use Friendica\Protocol\PortableContact;
Logger::log("Mail: Parsing mail ".$msg_uid, Logger::DATA);
$datarray = [];
- $datarray['verb'] = ACTIVITY_POST;
- $datarray['object-type'] = ACTIVITY_OBJ_NOTE;
+ $datarray['verb'] = Activity::POST;
+ $datarray['object-type'] = Activity\ObjectType::NOTE;
$datarray['network'] = Protocol::MAIL;
// $meta = Email::messageMeta($mbox, $msg_uid);
'/{group:\d+}/add/{contact:\d+}' => [Module\Group::class, [R::GET, R::POST]],
'/{group:\d+}/remove/{contact:\d+}' => [Module\Group::class, [R::GET, R::POST]],
],
- '/hashtag' => [Module\Hashtag::class, [R::GET]],
- '/home' => [Module\Home::class, [R::GET]],
- '/help[/{doc:.+}]' => [Module\Help::class, [R::GET]],
- '/inbox[/{nickname}]' => [Module\Inbox::class, [R::GET, R::POST]],
- '/invite' => [Module\Invite::class, [R::GET, R::POST]],
+ '/hashtag' => [Module\Hashtag::class, [R::GET]],
+ '/home' => [Module\Home::class, [R::GET]],
+ '/help[/{doc:.+}]' => [Module\Help::class, [R::GET]],
+ '/inbox[/{nickname}]' => [Module\Inbox::class, [R::GET, R::POST]],
+ '/invite' => [Module\Invite::class, [R::GET, R::POST]],
'/install' => [
'[/]' => [Module\Install::class, [R::GET, R::POST]],
'/testrewrite' => [Module\Install::class, [R::GET]],
],
+
+ '/item' => [
+ '/ignore/{id}' => [Module\Item\Ignore::class, [R::GET]],
+ ],
+
'/like/{item:\d+}' => [Module\Like::class, [R::GET]],
'/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]],
'/login' => [Module\Login::class, [R::GET, R::POST]],
+++ /dev/null
-<?php
-/**
- * TextTest class.
- */
-
-namespace Friendica\Test;
-
-use Friendica\Model\Group;
-use PHPUnit\Framework\TestCase;
-
-/**
- * Tests for text functions.
- */
-class TextTest extends TestCase
-{
- /**
- * test attribute contains
- */
- public function testAttributeContains1()
- {
- $testAttr="class1 notclass2 class3";
- $this->assertTrue(attribute_contains($testAttr, "class3"));
- $this->assertFalse(attribute_contains($testAttr, "class2"));
- }
-
- /**
- * test attribute contains
- */
- public function testAttributeContains2()
- {
- $testAttr="class1 not-class2 class3";
- $this->assertTrue(attribute_contains($testAttr, "class3"));
- $this->assertFalse(attribute_contains($testAttr, "class2"));
- }
-
- /**
- * test with empty input
- */
- public function testAttributeContainsEmpty()
- {
- $testAttr="";
- $this->assertFalse(attribute_contains($testAttr, "class2"));
- }
-
- /**
- * test input with special chars
- */
- public function testAttributeContainsSpecialChars()
- {
- $testAttr="--... %\$ä() /(=?}";
- $this->assertFalse(attribute_contains($testAttr, "class2"));
- }
-
- /**
- * test expand_acl, perfect input
- */
- public function testExpandAclNormal()
- {
- $text='<1><2><3><' . Group::FOLLOWERS . '><' . Group::MUTUALS . '>';
- $this->assertEquals(array('1', '2', '3', Group::FOLLOWERS, Group::MUTUALS), expand_acl($text));
- }
-
- /**
- * test with a big number
- */
- public function testExpandAclBigNumber()
- {
- $text='<1><' . PHP_INT_MAX . '><15>';
- $this->assertEquals(array('1', (string)PHP_INT_MAX, '15'), expand_acl($text));
- }
-
- /**
- * test with a string in it.
- *
- * @todo is this valid input? Otherwise: should there be an exception?
- */
- public function testExpandAclString()
- {
- $text="<1><279012><tt>";
- $this->assertEquals(array('1', '279012'), expand_acl($text));
- }
-
- /**
- * test with a ' ' in it.
- *
- * @todo is this valid input? Otherwise: should there be an exception?
- */
- public function testExpandAclSpace()
- {
- $text="<1><279 012><32>";
- $this->assertEquals(array('1', '32'), expand_acl($text));
- }
-
- /**
- * test empty input
- */
- public function testExpandAclEmpty()
- {
- $text="";
- $this->assertEquals(array(), expand_acl($text));
- }
-
- /**
- * test invalid input, no < at all
- *
- * @todo should there be an exception?
- */
- public function testExpandAclNoBrackets()
- {
- $text="According to documentation, that's invalid. "; //should be invalid
- $this->assertEquals(array(), expand_acl($text));
- }
-
- /**
- * test invalid input, just open <
- *
- * @todo should there be an exception?
- */
- public function testExpandAclJustOneBracket1()
- {
- $text="<Another invalid string"; //should be invalid
- $this->assertEquals(array(), expand_acl($text));
- }
-
- /**
- * test invalid input, just close >
- *
- * @todo should there be an exception?
- */
- public function testExpandAclJustOneBracket2()
- {
- $text="Another invalid> string"; //should be invalid
- $this->assertEquals(array(), expand_acl($text));
- }
-
- /**
- * test invalid input, just close >
- *
- * @todo should there be an exception?
- */
- public function testExpandAclCloseOnly()
- {
- $text="Another> invalid> string>"; //should be invalid
- $this->assertEquals(array(), expand_acl($text));
- }
-
- /**
- * test invalid input, just open <
- *
- * @todo should there be an exception?
- */
- public function testExpandAclOpenOnly()
- {
- $text="<Another< invalid string<"; //should be invalid
- $this->assertEquals(array(), expand_acl($text));
- }
-
- /**
- * test invalid input, open and close do not match
- *
- * @todo should there be an exception?
- */
- public function testExpandAclNoMatching1()
- {
- $text="<Another<> invalid <string>"; //should be invalid
- $this->assertEquals(array(), expand_acl($text));
- }
-
- /**
- * test invalid input, empty <>
- *
- * @todo should there be an exception? Or array(1, 3)
- * (This should be array(1,3) - mike)
- */
- public function testExpandAclEmptyMatch()
- {
- $text="<1><><3>";
- $this->assertEquals(array('1', '3'), expand_acl($text));
- }
-
- /**
- * test hex2bin and reverse
- */
- public function testHex2Bin()
- {
- $this->assertEquals(-3, hex2bin(bin2hex(-3)));
- $this->assertEquals(0, hex2bin(bin2hex(0)));
- $this->assertEquals(12, hex2bin(bin2hex(12)));
- $this->assertEquals(PHP_INT_MAX, hex2bin(bin2hex(PHP_INT_MAX)));
- }
-}
--- /dev/null
+<?php
+
+namespace Friendica\Test\src\Content;
+
+use Friendica\Test\MockedTest;
+
+class ItemTest extends MockedTest
+{
+ public function testDetermineCategoriesTerms()
+ {
+ $this->markTestIncomplete('Test data needed.');
+ }
+}
--- /dev/null
+<?php
+
+namespace Friendica\Test\Content\Text\BBCode;
+
+use Friendica\Content\Text\BBCode\Video;
+use Friendica\Test\MockedTest;
+
+class VideoTest extends MockedTest
+{
+ public function dataVideo()
+ {
+ return [
+ 'youtube' => [
+ 'input' => '[video]https://youtube.link/4523[/video]',
+ 'assert' => '[youtube]https://youtube.link/4523[/youtube]',
+ ],
+ 'youtu.be' => [
+ 'input' => '[video]https://youtu.be.link/4523[/video]',
+ 'assert' => '[youtube]https://youtu.be.link/4523[/youtube]',
+ ],
+ 'vimeo' => [
+ 'input' => '[video]https://vimeo.link/2343[/video]',
+ 'assert' => '[vimeo]https://vimeo.link/2343[/vimeo]',
+ ],
+ 'mixed' => [
+ 'input' => '[video]https://vimeo.link/2343[/video] With other [b]string[/b] [video]https://youtu.be/blaa[/video]',
+ 'assert' => '[vimeo]https://vimeo.link/2343[/vimeo] With other [b]string[/b] [youtube]https://youtu.be/blaa[/youtube]',
+ ]
+ ];
+ }
+
+ /**
+ * Test if the BBCode is successfully transformed for video links
+ *
+ * @dataProvider dataVideo
+ */
+ public function testTransform(string $input, string $assert)
+ {
+ $bbCodeVideo = new Video();
+
+ $this->assertEquals($assert, $bbCodeVideo->transform($input));
+ }
+}
// Mocking that we can use CURL
$this->setFunctions(['curl_init' => true]);
- // needed because of "normalise_link"
- require_once __DIR__ . '/../../../include/text.php';
-
$install = new Installer();
$this->assertTrue($install->checkHtAccess('https://test'));
--- /dev/null
+<?php
+
+namespace Friendica\Test\Protocol;
+
+use Friendica\Protocol\Activity;
+use Friendica\Protocol\ActivityNamespace;
+use Friendica\Test\MockedTest;
+
+class ActivityTest extends MockedTest
+{
+ public function dataMatch()
+ {
+ return [
+ 'empty' => [
+ 'haystack' => '',
+ 'needle' => '',
+ 'assert' => true,
+ ],
+ 'simple' => [
+ 'haystack' => Activity\ObjectType::TAGTERM,
+ 'needle' => Activity\ObjectType::TAGTERM,
+ 'assert' => true,
+ ],
+ 'withNamespace' => [
+ 'haystack' => 'tagterm',
+ 'needle' => ActivityNamespace::ACTIVITY_SCHEMA . Activity\ObjectType::TAGTERM,
+ 'assert' => true,
+ ],
+ 'invalidSimple' => [
+ 'haystack' => 'tagterm',
+ 'needle' => '',
+ 'assert' => false,
+ ],
+ 'invalidWithOutNamespace' => [
+ 'haystack' => 'tagterm',
+ 'needle' => Activity\ObjectType::TAGTERM,
+ 'assert' => false,
+ ],
+ 'withSubPath' => [
+ 'haystack' => 'tagterm',
+ 'needle' => ActivityNamespace::ACTIVITY_SCHEMA . '/bla/' . Activity\ObjectType::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));
+ }
+
+ public function testIsHidden()
+ {
+ $activity = new Activity();
+
+ $this->assertTrue($activity->isHidden(Activity::LIKE));
+ $this->assertFalse($activity->isHidden(Activity\ObjectType::BOOKMARK));
+ }
+}
--- /dev/null
+<?php
+
+namespace Friendica\Test\src\Util;
+
+use Friendica\Model\Group;
+use Friendica\Util\ACLFormatter;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @brief ACLFormater utility testing class
+ */
+class ACLFormaterTest extends TestCase
+{
+ /**
+ * test expand_acl, perfect input
+ */
+ public function testExpandAclNormal()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text='<1><2><3><' . Group::FOLLOWERS . '><' . Group::MUTUALS . '>';
+ $this->assertEquals(array('1', '2', '3', Group::FOLLOWERS, Group::MUTUALS), $aclFormatter->expand($text));
+ }
+
+ /**
+ * test with a big number
+ */
+ public function testExpandAclBigNumber()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text='<1><' . PHP_INT_MAX . '><15>';
+ $this->assertEquals(array('1', (string)PHP_INT_MAX, '15'), $aclFormatter->expand($text));
+ }
+
+ /**
+ * test with a string in it.
+ *
+ * @todo is this valid input? Otherwise: should there be an exception?
+ */
+ public function testExpandAclString()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text="<1><279012><tt>";
+ $this->assertEquals(array('1', '279012'), $aclFormatter->expand($text));
+ }
+
+ /**
+ * test with a ' ' in it.
+ *
+ * @todo is this valid input? Otherwise: should there be an exception?
+ */
+ public function testExpandAclSpace()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text="<1><279 012><32>";
+ $this->assertEquals(array('1', '32'), $aclFormatter->expand($text));
+ }
+
+ /**
+ * test empty input
+ */
+ public function testExpandAclEmpty()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text="";
+ $this->assertEquals(array(), $aclFormatter->expand($text));
+ }
+
+ /**
+ * test invalid input, no < at all
+ *
+ * @todo should there be an exception?
+ */
+ public function testExpandAclNoBrackets()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text="According to documentation, that's invalid. "; //should be invalid
+ $this->assertEquals(array(), $aclFormatter->expand($text));
+ }
+
+ /**
+ * test invalid input, just open <
+ *
+ * @todo should there be an exception?
+ */
+ public function testExpandAclJustOneBracket1()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text="<Another invalid string"; //should be invalid
+ $this->assertEquals(array(), $aclFormatter->expand($text));
+ }
+
+ /**
+ * test invalid input, just close >
+ *
+ * @todo should there be an exception?
+ */
+ public function testExpandAclJustOneBracket2()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text="Another invalid> string"; //should be invalid
+ $this->assertEquals(array(), $aclFormatter->expand($text));
+ }
+
+ /**
+ * test invalid input, just close >
+ *
+ * @todo should there be an exception?
+ */
+ public function testExpandAclCloseOnly()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text="Another> invalid> string>"; //should be invalid
+ $this->assertEquals(array(), $aclFormatter->expand($text));
+ }
+
+ /**
+ * test invalid input, just open <
+ *
+ * @todo should there be an exception?
+ */
+ public function testExpandAclOpenOnly()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text="<Another< invalid string<"; //should be invalid
+ $this->assertEquals(array(), $aclFormatter->expand($text));
+ }
+
+ /**
+ * test invalid input, open and close do not match
+ *
+ * @todo should there be an exception?
+ */
+ public function testExpandAclNoMatching1()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text="<Another<> invalid <string>"; //should be invalid
+ $this->assertEquals(array(), $aclFormatter->expand($text));
+ }
+
+ /**
+ * test invalid input, empty <>
+ *
+ * @todo should there be an exception? Or array(1, 3)
+ * (This should be array(1,3) - mike)
+ */
+ public function testExpandAclEmptyMatch()
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $text="<1><><3>";
+ $this->assertEquals(array('1', '3'), $aclFormatter->expand($text));
+ }
+
+ public function dataAclToString()
+ {
+ return [
+ 'empty' => [
+ 'input' => '',
+ 'assert' => '',
+ ],
+ 'string' => [
+ 'input' => '1,2,3,4',
+ 'assert' => '<1><2><3><4>',
+ ],
+ 'array' => [
+ 'input' => [1, 2, 3, 4],
+ 'assert' => '<1><2><3><4>',
+ ],
+ 'invalid' => [
+ 'input' => [1, 'a', 3, 4],
+ 'assert' => '<1><3><4>',
+ ],
+ 'invalidString' => [
+ 'input' => 'a,bsd23,4',
+ 'assert' => '<4>',
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataAclToString
+ */
+ public function testAclToString($input, string $assert)
+ {
+ $aclFormatter = new ACLFormatter();
+
+ $this->assertEquals($assert, $aclFormatter->toString($input));
+ }
+}
--- /dev/null
+<?php
+
+namespace Friendica\Test\src\Util;
+
+use Friendica\Test\MockedTest;
+use Friendica\Util\DateTimeFormat;
+
+class DateTimeFormatTest extends MockedTest
+{
+ public function dataYearMonth()
+ {
+ return [
+ 'validNormal' => [
+ 'input' => '1990-10',
+ 'assert' => true,
+ ],
+ 'validOneCharMonth' => [
+ 'input' => '1990-1',
+ 'assert' => true,
+ ],
+ 'validTwoCharMonth' => [
+ 'input' => '1990-01',
+ 'assert' => true,
+ ],
+ 'invalidFormat' => [
+ 'input' => '199-11',
+ 'assert' => false,
+ ],
+ 'invalidFormat2' => [
+ 'input' => '1990-15',
+ 'assert' => false,
+ ],
+ 'invalidFormat3' => [
+ 'input' => '99-101',
+ 'assert' => false,
+ ],
+ 'invalidFormat4' => [
+ 'input' => '11-1990',
+ 'assert' => false,
+ ],
+ 'invalidFuture' => [
+ 'input' => '3030-12',
+ 'assert' => false,
+ ],
+ 'invalidYear' => [
+ 'input' => '-100-10',
+ 'assert' => false,
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataYearMonth
+ */
+ public function testIsYearMonth(string $input, bool $assert)
+ {
+ $dtFormat = new DateTimeFormat();
+
+ $this->assertEquals($assert, $dtFormat->isYearMonth($input));
+ }
+}
namespace Friendica\Test\src\Util\Logger;
+use Friendica\Util\FileSystem;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\Logger\StreamLogger;
use org\bovigo\vfs\vfsStream;
*/
private $logfile;
+ /**
+ * @var Filesystem
+ */
+ private $fileSystem;
+
protected function setUp()
{
parent::setUp();
$this->setUpVfsDir();
+
+ $this->fileSystem = new Filesystem();
}
/**
$this->logfile = vfsStream::newFile('friendica.log')
->at($this->root);
- $this->logger = new StreamLogger('test', $this->logfile->url(), $this->introspection, $level);
+ $this->logger = new StreamLogger('test', $this->logfile->url(), $this->introspection, $this->fileSystem, $level);
return $this->logger;
}
$filehandler = fopen($logfile->url(), 'ab');
- $logger = new StreamLogger('test', $filehandler, $this->introspection);
+ $logger = new StreamLogger('test', $filehandler, $this->introspection, $this->fileSystem);
$logger->emergency('working');
$text = $logfile->getContent();
$logfile = vfsStream::newFile('friendica.log')
->at($this->root);
- $logger = new StreamLogger('test', $logfile->url(), $this->introspection);
+ $logger = new StreamLogger('test', $logfile->url(), $this->introspection, $this->fileSystem);
$logger->emergency('working');
$logger->close();
// close doesn't affect
*/
public function testNoUrl()
{
- $logger = new StreamLogger('test', '', $this->introspection);
+ $logger = new StreamLogger('test', '', $this->introspection, $this->fileSystem);
$logger->emergency('not working');
}
$logfile = vfsStream::newFile('friendica.log')
->at($this->root)->chmod(0);
- $logger = new StreamLogger('test', $logfile->url(), $this->introspection);
+ $logger = new StreamLogger('test', $logfile->url(), $this->introspection, $this->fileSystem);
$logger->emergency('not working');
}
{
$this->markTestIncomplete('We need a platform independent way to set directory to readonly');
- $logger = new StreamLogger('test', '/$%/wrong/directory/file.txt', $this->introspection);
+ $logger = new StreamLogger('test', '/$%/wrong/directory/file.txt', $this->introspection, $this->fileSystem);
$logger->emergency('not working');
}
*/
public function testWrongMinimumLevel()
{
- $logger = new StreamLogger('test', 'file.text', $this->introspection, 'NOPE');
+ $logger = new StreamLogger('test', 'file.text', $this->introspection, $this->fileSystem, 'NOPE');
}
/**
$logfile = vfsStream::newFile('friendica.log')
->at($this->root);
- $logger = new StreamLogger('test', $logfile->url(), $this->introspection);
+ $logger = new StreamLogger('test', $logfile->url(), $this->introspection, $this->fileSystem);
$logger->log('NOPE', 'a test');
}
*/
public function testWrongFile()
{
- $logger = new StreamLogger('test', null, $this->introspection);
+ $logger = new StreamLogger('test', null, $this->introspection, $this->fileSystem);
+ }
+
+ /**
+ * Test a relative path
+ */
+ public function testRealPath()
+ {
+ $this->markTestSkipped('vfsStream isn\'t compatible with chdir, so not testable.');
+
+ $logfile = vfsStream::newFile('friendica.log')
+ ->at($this->root);
+
+ chdir($this->root->getChild('logs')->url());
+
+ $logger = new StreamLogger('test', '../friendica.log' , $this->introspection, $this->fileSystem);
+
+ $logger->info('Test');
}
}
function doignore(ident) {
ident = ident.toString();
$('#like-rotator-' + ident).show();
- $.get('ignored/' + ident, function(data) {
+ $.get('item/ignore/' + ident, function(data) {
if (data.match(/1/)) {
$('#ignored-' + ident).addClass('ignored');
$('#ignored-' + ident).removeClass('unignored');