3 namespace Friendica\Module;
5 use Friendica\Core\Hook;
6 use Friendica\Database\DBA;
8 use Friendica\Model\Group;
9 use Friendica\Model\Item;
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);
35 $model['allow_cid'] = DI::aclFormatter()->expand($model['allow_cid']);
36 $model['allow_gid'] = DI::aclFormatter()->expand($model['allow_gid']);
37 $model['deny_cid'] = DI::aclFormatter()->expand($model['deny_cid']);
38 $model['deny_gid'] = DI::aclFormatter()->expand($model['deny_gid']);
41 if (!DBA::isResult($model)) {
42 throw new HttpException\NotFoundException(DI::l10n()->t('Model not found'));
45 if (isset($model['psid'])) {
46 $permissionSet = DI::permissionSet()->selectOneById($model['psid'], $model['uid']);
47 $model['allow_cid'] = $permissionSet->allow_cid;
48 $model['allow_gid'] = $permissionSet->allow_gid;
49 $model['deny_cid'] = $permissionSet->deny_cid;
50 $model['deny_gid'] = $permissionSet->deny_gid;
53 // Kept for backwards compatiblity
54 Hook::callAll('lockview_content', $model);
56 if ($model['uid'] != local_user() ||
57 isset($model['private'])
58 && $model['private'] == Item::PRIVATE
59 && empty($model['allow_cid'])
60 && empty($model['allow_gid'])
61 && empty($model['deny_cid'])
62 && empty($model['deny_gid']))
64 echo DI::l10n()->t('Remote privacy information not available.');
68 $allowed_users = $model['allow_cid'];
69 $allowed_groups = $model['allow_gid'];
70 $deny_users = $model['deny_cid'];
71 $deny_groups = $model['deny_gid'];
73 $o = DI::l10n()->t('Visible to:') . '<br />';
76 if (count($allowed_groups)) {
77 $key = array_search(Group::FOLLOWERS, $allowed_groups);
79 $l[] = '<b>' . DI::l10n()->t('Followers') . '</b>';
80 unset($allowed_groups[$key]);
83 $key = array_search(Group::MUTUALS, $allowed_groups);
85 $l[] = '<b>' . DI::l10n()->t('Mutuals') . '</b>';
86 unset($allowed_groups[$key]);
89 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
90 $l[] = '<b>' . $group['name'] . '</b>';
94 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $allowed_users]) as $contact) {
95 $l[] = $contact['name'];
98 if (count($deny_groups)) {
99 $key = array_search(Group::FOLLOWERS, $deny_groups);
100 if ($key !== false) {
101 $l[] = '<b><strike>' . DI::l10n()->t('Followers') . '</strike></b>';
102 unset($deny_groups[$key]);
105 $key = array_search(Group::MUTUALS, $deny_groups);
106 if ($key !== false) {
107 $l[] = '<b><strike>' . DI::l10n()->t('Mutuals') . '</strike></b>';
108 unset($deny_groups[$key]);
111 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
112 $l[] = '<b><strike>' . $group['name'] . '</strike></b>';
116 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $deny_users]) as $contact) {
117 $l[] = '<strike>' . $contact['name'] . '</strike>';
120 echo $o . implode(', ', $l);