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\Network\HTTPException;
13 * Outputs the permission tooltip HTML content for the provided item, photo or event id.
15 class PermissionTooltip extends \Friendica\BaseModule
17 public static function rawContent(array $parameters = [])
19 parent::rawContent($parameters); // TODO: Change the autogenerated stub
21 $type = $parameters['type'];
22 $referenceId = $parameters['id'];
24 $expectedTypes = ['item', 'photo', 'event'];
25 if (!in_array($type, $expectedTypes)) {
26 throw new HTTPException\BadRequestException(DI::l10n()->t('Wrong type "%s", expected one of: %s', $type, implode(', ', $expectedTypes)));
29 $condition = ['id' => $referenceId];
30 if ($type == 'item') {
31 $fields = ['uid', 'psid', 'private'];
32 $model = Item::selectFirst($fields, $condition);
34 $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
35 $model = DBA::selectFirst($type, $fields, $condition);
38 if (!DBA::isResult($model)) {
39 throw new HttpException\NotFoundException(DI::l10n()->t('Model not found'));
42 if (isset($model['psid'])) {
43 $permissionSet = DI::permissionSet()->selectFirst(['id' => $model['psid']]);
44 $model['allow_cid'] = $permissionSet->allow_cid;
45 $model['allow_gid'] = $permissionSet->allow_gid;
46 $model['deny_cid'] = $permissionSet->deny_cid;
47 $model['deny_gid'] = $permissionSet->deny_gid;
50 // Kept for backwards compatiblity
51 Hook::callAll('lockview_content', $model);
53 if ($model['uid'] != local_user() ||
54 isset($model['private'])
55 && $model['private'] == Item::PRIVATE
56 && empty($model['allow_cid'])
57 && empty($model['allow_gid'])
58 && empty($model['deny_cid'])
59 && empty($model['deny_gid']))
61 echo DI::l10n()->t('Remote privacy information not available.');
65 $aclFormatter = DI::aclFormatter();
67 $allowed_users = $aclFormatter->expand($model['allow_cid']);
68 $allowed_groups = $aclFormatter->expand($model['allow_gid']);
69 $deny_users = $aclFormatter->expand($model['deny_cid']);
70 $deny_groups = $aclFormatter->expand($model['deny_gid']);
72 $o = DI::l10n()->t('Visible to:') . '<br />';
75 if (count($allowed_groups)) {
76 $key = array_search(Group::FOLLOWERS, $allowed_groups);
78 $l[] = '<b>' . DI::l10n()->t('Followers') . '</b>';
79 unset($allowed_groups[$key]);
82 $key = array_search(Group::MUTUALS, $allowed_groups);
84 $l[] = '<b>' . DI::l10n()->t('Mutuals') . '</b>';
85 unset($allowed_groups[$key]);
88 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
89 $l[] = '<b>' . $group['name'] . '</b>';
93 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $allowed_users]) as $contact) {
94 $l[] = $contact['name'];
97 if (count($deny_groups)) {
98 $key = array_search(Group::FOLLOWERS, $deny_groups);
100 $l[] = '<b><strike>' . DI::l10n()->t('Followers') . '</strike></b>';
101 unset($deny_groups[$key]);
104 $key = array_search(Group::MUTUALS, $deny_groups);
105 if ($key !== false) {
106 $l[] = '<b><strike>' . DI::l10n()->t('Mutuals') . '</strike></b>';
107 unset($deny_groups[$key]);
110 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
111 $l[] = '<b><strike>' . $group['name'] . '</strike></b>';
115 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $deny_users]) as $contact) {
116 $l[] = '<strike>' . $contact['name'] . '</strike>';
119 echo $o . implode(', ', $l);