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 $type = $parameters['type'];
20 $referenceId = $parameters['id'];
22 $expectedTypes = ['item', 'photo', 'event'];
23 if (!in_array($type, $expectedTypes)) {
24 throw new HTTPException\BadRequestException(DI::l10n()->t('Wrong type "%s", expected one of: %s', $type, implode(', ', $expectedTypes)));
27 $condition = ['id' => $referenceId];
28 if ($type == 'item') {
29 $fields = ['uid', 'psid', 'private'];
30 $model = Item::selectFirst($fields, $condition);
32 $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
33 $model = DBA::selectFirst($type, $fields, $condition);
36 if (!DBA::isResult($model)) {
37 throw new HttpException\NotFoundException(DI::l10n()->t('Model not found'));
40 if (isset($model['psid'])) {
41 $permissionSet = DI::permissionSet()->selectFirst(['id' => $model['psid']]);
42 $model['allow_cid'] = $permissionSet->allow_cid;
43 $model['allow_gid'] = $permissionSet->allow_gid;
44 $model['deny_cid'] = $permissionSet->deny_cid;
45 $model['deny_gid'] = $permissionSet->deny_gid;
48 // Kept for backwards compatiblity
49 Hook::callAll('lockview_content', $model);
51 if ($model['uid'] != local_user() ||
52 isset($model['private'])
53 && $model['private'] == Item::PRIVATE
54 && empty($model['allow_cid'])
55 && empty($model['allow_gid'])
56 && empty($model['deny_cid'])
57 && empty($model['deny_gid']))
59 echo DI::l10n()->t('Remote privacy information not available.');
63 $aclFormatter = DI::aclFormatter();
65 $allowed_users = $aclFormatter->expand($model['allow_cid']);
66 $allowed_groups = $aclFormatter->expand($model['allow_gid']);
67 $deny_users = $aclFormatter->expand($model['deny_cid']);
68 $deny_groups = $aclFormatter->expand($model['deny_gid']);
70 $o = DI::l10n()->t('Visible to:') . '<br />';
73 if (count($allowed_groups)) {
74 $key = array_search(Group::FOLLOWERS, $allowed_groups);
76 $l[] = '<b>' . DI::l10n()->t('Followers') . '</b>';
77 unset($allowed_groups[$key]);
80 $key = array_search(Group::MUTUALS, $allowed_groups);
82 $l[] = '<b>' . DI::l10n()->t('Mutuals') . '</b>';
83 unset($allowed_groups[$key]);
86 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
87 $l[] = '<b>' . $group['name'] . '</b>';
91 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $allowed_users]) as $contact) {
92 $l[] = $contact['name'];
95 if (count($deny_groups)) {
96 $key = array_search(Group::FOLLOWERS, $deny_groups);
98 $l[] = '<b><strike>' . DI::l10n()->t('Followers') . '</strike></b>';
99 unset($deny_groups[$key]);
102 $key = array_search(Group::MUTUALS, $deny_groups);
103 if ($key !== false) {
104 $l[] = '<b><strike>' . DI::l10n()->t('Mutuals') . '</strike></b>';
105 unset($deny_groups[$key]);
108 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
109 $l[] = '<b><strike>' . $group['name'] . '</strike></b>';
113 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $deny_users]) as $contact) {
114 $l[] = '<strike>' . $contact['name'] . '</strike>';
117 echo $o . implode(', ', $l);