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()->selectFirst(['id' => $model['psid']]);
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 $aclFormatter = DI::aclFormatter();
66 $allowed_users = $aclFormatter->expand($model['allow_cid']);
67 $allowed_groups = $aclFormatter->expand($model['allow_gid']);
68 $deny_users = $aclFormatter->expand($model['deny_cid']);
69 $deny_groups = $aclFormatter->expand($model['deny_gid']);
71 $o = DI::l10n()->t('Visible to:') . '<br />';
74 if (count($allowed_groups)) {
75 $key = array_search(Group::FOLLOWERS, $allowed_groups);
77 $l[] = '<b>' . DI::l10n()->t('Followers') . '</b>';
78 unset($allowed_groups[$key]);
81 $key = array_search(Group::MUTUALS, $allowed_groups);
83 $l[] = '<b>' . DI::l10n()->t('Mutuals') . '</b>';
84 unset($allowed_groups[$key]);
87 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
88 $l[] = '<b>' . $group['name'] . '</b>';
92 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $allowed_users]) as $contact) {
93 $l[] = $contact['name'];
96 if (count($deny_groups)) {
97 $key = array_search(Group::FOLLOWERS, $deny_groups);
99 $l[] = '<b><strike>' . DI::l10n()->t('Followers') . '</strike></b>';
100 unset($deny_groups[$key]);
103 $key = array_search(Group::MUTUALS, $deny_groups);
104 if ($key !== false) {
105 $l[] = '<b><strike>' . DI::l10n()->t('Mutuals') . '</strike></b>';
106 unset($deny_groups[$key]);
109 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
110 $l[] = '<b><strike>' . $group['name'] . '</strike></b>';
114 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $deny_users]) as $contact) {
115 $l[] = '<strike>' . $contact['name'] . '</strike>';
118 echo $o . implode(', ', $l);