2020-07-26 18:35:02 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Module;
|
|
|
|
|
|
|
|
use Friendica\Core\Hook;
|
|
|
|
use Friendica\Database\DBA;
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Model\Group;
|
2021-10-21 18:49:22 -04:00
|
|
|
use Friendica\Model\Item;
|
2021-01-15 23:16:09 -05:00
|
|
|
use Friendica\Model\Post;
|
2020-07-26 18:35:02 -04:00
|
|
|
use Friendica\Network\HTTPException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Outputs the permission tooltip HTML content for the provided item, photo or event id.
|
|
|
|
*/
|
|
|
|
class PermissionTooltip extends \Friendica\BaseModule
|
|
|
|
{
|
2021-11-14 14:46:25 -05:00
|
|
|
public static function rawContent()
|
2020-07-26 18:35:02 -04:00
|
|
|
{
|
2021-11-14 14:46:25 -05:00
|
|
|
$type = static::$parameters['type'];
|
|
|
|
$referenceId = static::$parameters['id'];
|
2020-07-26 18:35:02 -04:00
|
|
|
|
|
|
|
$expectedTypes = ['item', 'photo', 'event'];
|
|
|
|
if (!in_array($type, $expectedTypes)) {
|
|
|
|
throw new HTTPException\BadRequestException(DI::l10n()->t('Wrong type "%s", expected one of: %s', $type, implode(', ', $expectedTypes)));
|
|
|
|
}
|
|
|
|
|
|
|
|
$condition = ['id' => $referenceId];
|
|
|
|
if ($type == 'item') {
|
|
|
|
$fields = ['uid', 'psid', 'private'];
|
2021-01-15 23:16:09 -05:00
|
|
|
$model = Post::selectFirst($fields, $condition);
|
2020-07-26 18:35:02 -04:00
|
|
|
} else {
|
|
|
|
$fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
|
|
|
|
$model = DBA::selectFirst($type, $fields, $condition);
|
2021-10-21 18:49:22 -04:00
|
|
|
$model['allow_cid'] = DI::aclFormatter()->expand($model['allow_cid']);
|
|
|
|
$model['allow_gid'] = DI::aclFormatter()->expand($model['allow_gid']);
|
|
|
|
$model['deny_cid'] = DI::aclFormatter()->expand($model['deny_cid']);
|
|
|
|
$model['deny_gid'] = DI::aclFormatter()->expand($model['deny_gid']);
|
2020-07-26 18:35:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!DBA::isResult($model)) {
|
|
|
|
throw new HttpException\NotFoundException(DI::l10n()->t('Model not found'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($model['psid'])) {
|
2021-10-16 15:23:40 -04:00
|
|
|
$permissionSet = DI::permissionSet()->selectOneById($model['psid'], $model['uid']);
|
2020-07-26 18:35:02 -04:00
|
|
|
$model['allow_cid'] = $permissionSet->allow_cid;
|
|
|
|
$model['allow_gid'] = $permissionSet->allow_gid;
|
|
|
|
$model['deny_cid'] = $permissionSet->deny_cid;
|
|
|
|
$model['deny_gid'] = $permissionSet->deny_gid;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kept for backwards compatiblity
|
|
|
|
Hook::callAll('lockview_content', $model);
|
|
|
|
|
|
|
|
if ($model['uid'] != local_user() ||
|
|
|
|
isset($model['private'])
|
|
|
|
&& $model['private'] == Item::PRIVATE
|
|
|
|
&& empty($model['allow_cid'])
|
|
|
|
&& empty($model['allow_gid'])
|
|
|
|
&& empty($model['deny_cid'])
|
|
|
|
&& empty($model['deny_gid']))
|
|
|
|
{
|
|
|
|
echo DI::l10n()->t('Remote privacy information not available.');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2021-10-05 17:30:10 -04:00
|
|
|
$allowed_users = $model['allow_cid'];
|
|
|
|
$allowed_groups = $model['allow_gid'];
|
|
|
|
$deny_users = $model['deny_cid'];
|
|
|
|
$deny_groups = $model['deny_gid'];
|
2020-07-26 18:35:02 -04:00
|
|
|
|
|
|
|
$o = DI::l10n()->t('Visible to:') . '<br />';
|
|
|
|
$l = [];
|
|
|
|
|
|
|
|
if (count($allowed_groups)) {
|
|
|
|
$key = array_search(Group::FOLLOWERS, $allowed_groups);
|
|
|
|
if ($key !== false) {
|
|
|
|
$l[] = '<b>' . DI::l10n()->t('Followers') . '</b>';
|
|
|
|
unset($allowed_groups[$key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = array_search(Group::MUTUALS, $allowed_groups);
|
|
|
|
if ($key !== false) {
|
|
|
|
$l[] = '<b>' . DI::l10n()->t('Mutuals') . '</b>';
|
|
|
|
unset($allowed_groups[$key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
|
|
|
|
$l[] = '<b>' . $group['name'] . '</b>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $allowed_users]) as $contact) {
|
|
|
|
$l[] = $contact['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($deny_groups)) {
|
|
|
|
$key = array_search(Group::FOLLOWERS, $deny_groups);
|
|
|
|
if ($key !== false) {
|
|
|
|
$l[] = '<b><strike>' . DI::l10n()->t('Followers') . '</strike></b>';
|
|
|
|
unset($deny_groups[$key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = array_search(Group::MUTUALS, $deny_groups);
|
|
|
|
if ($key !== false) {
|
|
|
|
$l[] = '<b><strike>' . DI::l10n()->t('Mutuals') . '</strike></b>';
|
|
|
|
unset($deny_groups[$key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
|
|
|
|
$l[] = '<b><strike>' . $group['name'] . '</strike></b>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $deny_users]) as $contact) {
|
|
|
|
$l[] = '<strike>' . $contact['name'] . '</strike>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $o . implode(', ', $l);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|