3 namespace Friendica\Module;
5 use Friendica\Core\Hook;
6 use Friendica\Database\DBA;
8 use Friendica\Model\Item;
9 use Friendica\Model\Group;
10 use Friendica\Model\Post;
11 use Friendica\Network\HTTPException;
14 * Outputs the permission tooltip HTML content for the provided item, photo or event id.
16 class PermissionTooltip extends \Friendica\BaseModule
18 public static function rawContent(array $parameters = [])
20 $type = $parameters['type'];
21 $referenceId = $parameters['id'];
23 $expectedTypes = ['item', 'photo', 'event'];
24 if (!in_array($type, $expectedTypes)) {
25 throw new HTTPException\BadRequestException(DI::l10n()->t('Wrong type "%s", expected one of: %s', $type, implode(', ', $expectedTypes)));
28 $condition = ['id' => $referenceId];
29 if ($type == 'item') {
30 $fields = ['uid', 'psid', 'private'];
31 $model = Post::selectFirst($fields, $condition);
33 $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
34 $model = DBA::selectFirst($type, $fields, $condition);
37 if (!DBA::isResult($model)) {
38 throw new HttpException\NotFoundException(DI::l10n()->t('Model not found'));
41 if (isset($model['psid'])) {
42 $permissionSet = DI::permissionSet()->selectOneById($model['psid'], $model['uid']);
43 $model['allow_cid'] = $permissionSet->allow_cid;
44 $model['allow_gid'] = $permissionSet->allow_gid;
45 $model['deny_cid'] = $permissionSet->deny_cid;
46 $model['deny_gid'] = $permissionSet->deny_gid;
49 // Kept for backwards compatiblity
50 Hook::callAll('lockview_content', $model);
52 if ($model['uid'] != local_user() ||
53 isset($model['private'])
54 && $model['private'] == Item::PRIVATE
55 && empty($model['allow_cid'])
56 && empty($model['allow_gid'])
57 && empty($model['deny_cid'])
58 && empty($model['deny_gid']))
60 echo DI::l10n()->t('Remote privacy information not available.');
64 $allowed_users = $model['allow_cid'];
65 $allowed_groups = $model['allow_gid'];
66 $deny_users = $model['deny_cid'];
67 $deny_groups = $model['deny_gid'];
69 $o = DI::l10n()->t('Visible to:') . '<br />';
72 if (count($allowed_groups)) {
73 $key = array_search(Group::FOLLOWERS, $allowed_groups);
75 $l[] = '<b>' . DI::l10n()->t('Followers') . '</b>';
76 unset($allowed_groups[$key]);
79 $key = array_search(Group::MUTUALS, $allowed_groups);
81 $l[] = '<b>' . DI::l10n()->t('Mutuals') . '</b>';
82 unset($allowed_groups[$key]);
85 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
86 $l[] = '<b>' . $group['name'] . '</b>';
90 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $allowed_users]) as $contact) {
91 $l[] = $contact['name'];
94 if (count($deny_groups)) {
95 $key = array_search(Group::FOLLOWERS, $deny_groups);
97 $l[] = '<b><strike>' . DI::l10n()->t('Followers') . '</strike></b>';
98 unset($deny_groups[$key]);
101 $key = array_search(Group::MUTUALS, $deny_groups);
102 if ($key !== false) {
103 $l[] = '<b><strike>' . DI::l10n()->t('Mutuals') . '</strike></b>';
104 unset($deny_groups[$key]);
107 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
108 $l[] = '<b><strike>' . $group['name'] . '</strike></b>';
112 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $deny_users]) as $contact) {
113 $l[] = '<strike>' . $contact['name'] . '</strike>';
116 echo $o . implode(', ', $l);