Move mod/lockview to Module\PermissionTooltip

- Add explicit type parameter to lockview() in main.js
This commit is contained in:
Hypolite Petovan 2020-07-26 18:35:02 -04:00
parent 639e2b3892
commit d7b5674476
20 changed files with 158 additions and 45 deletions

View file

@ -604,10 +604,6 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep-
Hook::callAll('post_local_end', $arr);
### mod/lockview.php
Hook::callAll('lockview_content', $item);
### mod/uexport.php
Hook::callAll('uexport_options', $options);
@ -679,6 +675,10 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep-
Hook::callAll('register_account', $uid);
Hook::callAll('remove_user', $user);
### src/Module/PermissionTooltip.php
Hook::callAll('lockview_content', $item);
### src/Content/ContactBlock.php
Hook::callAll('contact_block_end', $arr);

View file

@ -312,10 +312,6 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap
Hook::callAll('post_local_end', $arr);
### mod/lockview.php
Hook::callAll('lockview_content', $item);
### mod/uexport.php
Hook::callAll('uexport_options', $options);
@ -422,6 +418,10 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap
Hook::callAll('storage_instance', $data);
### src/Module/PermissionTooltip.php
Hook::callAll('lockview_content', $item);
### src/Worker/Directory.php
Hook::callAll('globaldir_update', $arr);

View file

@ -0,0 +1,122 @@
<?php
namespace Friendica\Module;
use Friendica\Core\Hook;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Group;
use Friendica\Network\HTTPException;
/**
* Outputs the permission tooltip HTML content for the provided item, photo or event id.
*/
class PermissionTooltip extends \Friendica\BaseModule
{
public static function rawContent(array $parameters = [])
{
parent::rawContent($parameters); // TODO: Change the autogenerated stub
$type = $parameters['type'];
$referenceId = $parameters['id'];
$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'];
$model = Item::selectFirst($fields, $condition);
} else {
$fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
$model = DBA::selectFirst($type, $fields, $condition);
}
if (!DBA::isResult($model)) {
throw new HttpException\NotFoundException(DI::l10n()->t('Model not found'));
}
if (isset($model['psid'])) {
$permissionSet = DI::permissionSet()->selectFirst(['id' => $model['psid']]);
$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;
}
$aclFormatter = DI::aclFormatter();
$allowed_users = $aclFormatter->expand($model['allow_cid']);
$allowed_groups = $aclFormatter->expand($model['allow_gid']);
$deny_users = $aclFormatter->expand($model['deny_cid']);
$deny_groups = $aclFormatter->expand($model['deny_gid']);
$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();
}
}

View file

@ -237,6 +237,8 @@ return [
'/openid' => [Module\Security\OpenID::class, [R::GET]],
'/opensearch' => [Module\OpenSearch::class, [R::GET]],
'/permission/tooltip/{type}/{id:\d+}' => [Module\PermissionTooltip::class, [R::GET]],
'/photo' => [
'/{name}' => [Module\Photo::class, [R::GET]],
'/{type}/{name}' => [Module\Photo::class, [R::GET]],

View file

@ -750,24 +750,21 @@ function getPosition(e) {
var lockvisible = false;
function lockview(event,id) {
function lockview(event, type, id) {
event = event || window.event;
cursor = getPosition(event);
if (lockvisible) {
lockviewhide();
} else {
lockvisible = true;
$.get('lockview/' + id, function(data) {
$('#panel').html(data);
$('#panel').css({'left': cursor.x + 5 , 'top': cursor.y + 5});
$('#panel').show();
});
}
}
function lockviewhide() {
lockvisible = false;
$('#panel').hide();
} else {
lockvisible = true;
$.get('permission/tooltip/' + type + '/' + id, function(data) {
$('#panel')
.html(data)
.css({'left': cursor.x + 5 , 'top': cursor.y + 5})
.show();
});
}
}
function post_comment(id) {
@ -940,14 +937,6 @@ function groupChangeMember(gid, cid, sec_token) {
});
}
function profChangeMember(gid,cid) {
$('body .fakelink').css('cursor', 'wait');
$.get('profperm/' + gid + '/' + cid, function(data) {
$('#prof-update-wrapper').html(data);
$('body .fakelink').css('cursor', 'auto');
});
}
function contactgroupChangeMember(checkbox, gid, cid) {
let url;
// checkbox.checked is the checkbox state after the click

View file

@ -17,7 +17,7 @@
| <a id="photo-toprofile-link" href="{{$tools.profile.0}}">{{$tools.profile.1}}</a>
{{/if}}
{{if $tools.lock}}
| <img src="images/lock_icon.gif" class="lockview" alt="{{$tools.lock}}" onclick="lockview(event,'photo/{{$id}}');" />
| <img src="images/lock_icon.gif" class="lockview" alt="{{$tools.lock}}" onclick="lockview(event, 'photo', {{$id}});" />
{{/if}}
{{/if}}
</div>

View file

@ -17,7 +17,7 @@
</div>
<div class="wall-item-photo-end"></div>
<div class="wall-item-wrapper" id="wall-item-wrapper-{{$item.id}}" >
{{if $item.lock}}<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="{{$item.lock}}" onclick="lockview(event,{{$item.id}});" /></div>
{{if $item.lock}}<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="{{$item.lock}}" onclick="lockview(event, 'item', {{$item.id}});" /></div>
{{else}}<div class="wall-item-lock"></div>{{/if}}
<div class="wall-item-location" id="wall-item-location-{{$item.id}}">{{$item.location nofilter}}</div>
</div>

View file

@ -43,7 +43,7 @@
</div>
<div class="wall-item-photo-end"></div>
<div class="wall-item-wrapper" id="wall-item-wrapper-{{$item.id}}" >
{{if $item.lock}}<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="{{$item.lock}}" onclick="lockview(event,{{$item.id}});" /></div>
{{if $item.lock}}<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="{{$item.lock}}" onclick="lockview(event, 'item', {{$item.id}});" /></div>
{{else}}<div class="wall-item-lock"></div>{{/if}}
<div class="wall-item-location" id="wall-item-location-{{$item.id}}">{{$item.location nofilter}}</div>
</div>

View file

@ -37,7 +37,7 @@
{{/if}}
{{if $tools.lock}}
<span class="icon-padding"> </span>
<a id="photo-lock-link" onclick="lockview(event,'photo/{{$id}}');" title="{{$tools.lock}}" data-toggle="tooltip">
<a id="photo-lock-link" onclick="lockview(event, 'photo', {{$id}});" title="{{$tools.lock}}" data-toggle="tooltip">
<i class="page-action faded-icon fa fa-lock"></i>
</a>
{{/if}}

View file

@ -1,7 +1,7 @@
<!-- TODO => Unknow block -->
<div class="wall-item-decor" style="display:none;">
<span class="icon s22 star {{$item.isstarred}}" id="starred-{{$item.id}}" title="{{$item.star.starred}}">{{$item.star.starred}}</span>
{{if $item.lock}}<span class="navicon lock fakelink" onclick="lockview(event, {{$item.id}});" title="{{$item.lock}}"></span><span class="fa fa-lock" aria-hidden="true"></span>{{/if}}
{{if $item.lock}}<span class="navicon lock fakelink" onclick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}"></span><span class="fa fa-lock" aria-hidden="true"></span>{{/if}}
</div>
<!-- ./TODO => Unknow block -->
@ -56,7 +56,7 @@
</a>
{{/if}}
{{if $item.lock}}
<span class="navicon lock fakelink" onClick="lockview(event, {{$item.id}});" title="{{$item.lock}}">
<span class="navicon lock fakelink" onClick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}">
&nbsp;<small><i class="fa fa-lock" aria-hidden="true"></i></small>
</span>
{{/if}}

View file

@ -63,7 +63,7 @@ as the value of $top_child_total (this is done at the end of this file)
{{if $item.star}}
<span class="icon s22 star {{$item.isstarred}}" id="starred-{{$item.id}}" title="{{$item.star.starred}}">{{$item.star.starred}}</span>
{{/if}}
{{if $item.lock}}<span class="navicon lock fakelink" onclick="lockview(event,{{$item.id}});" title="{{$item.lock}}"></span><span class="fa fa-lock"></span>{{/if}}
{{if $item.lock}}<span class="navicon lock fakelink" onclick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}"></span><span class="fa fa-lock"></span>{{/if}}
</div>
{{* /TODO => Unknown block *}}
@ -138,7 +138,7 @@ as the value of $top_child_total (this is done at the end of this file)
</a>
{{/if}}
{{if $item.lock}}
<span class="navicon lock fakelink" onClick="lockview(event,{{$item.id}});" title="{{$item.lock}}" data-toggle="tooltip">
<span class="navicon lock fakelink" onClick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}" data-toggle="tooltip">
&nbsp;<small><i class="fa fa-lock" aria-hidden="true"></i></small>
</span>
{{/if}}

View file

@ -16,7 +16,7 @@
| <a id="photo-toprofile-link" href="{{$tools.profile.0}}">{{$tools.profile.1}}</a>
{{/if}}
{{if $tools.lock}}
| <img src="images/lock_icon.gif" class="lockview" alt="{{$tools.lock}}" onclick="lockview(event,'photo/{{$id}}');" />
| <img src="images/lock_icon.gif" class="lockview" alt="{{$tools.lock}}" onclick="lockview(event, 'photo', {{$id}});" />
{{/if}}
{{/if}}
</div>

View file

@ -1,6 +1,6 @@
<div class="wall-item-decor">
{{if $item.star}}<span class="icon s22 star {{$item.isstarred}}" id="starred-{{$item.id}}" title="{{$item.star.starred}}">{{$item.star.starred}}</span>{{/if}}
{{if $item.lock}}<span class="icon s22 lock fakelink" onclick="lockview(event,{{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}
{{if $item.lock}}<span class="icon s22 lock fakelink" onclick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}
<img id="like-rotator-{{$item.id}}" class="like-rotator" src="images/rotator.gif" alt="{{$item.wait}}" title="{{$item.wait}}" style="display: none;" />
</div>

View file

@ -24,7 +24,7 @@
<div class="wall-item-decor">
{{if $item.star}}<span class="icon s22 star {{$item.isstarred}}" id="starred-{{$item.id}}" title="{{$item.star.starred}}">{{$item.star.starred}}</span>{{/if}}
{{if $item.lock}}<span class="icon s22 lock fakelink" onclick="lockview(event,{{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}
{{if $item.lock}}<span class="icon s22 lock fakelink" onclick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}
<img id="like-rotator-{{$item.id}}" class="like-rotator" src="images/rotator.gif" alt="{{$item.wait}}" title="{{$item.wait}}" style="display: none;" />
</div>

View file

@ -18,7 +18,7 @@
<div class="wall-item-location" id="wall-item-location-{{$item.id}}">{{if $item.location}}<span class="icon globe"></span>{{$item.location nofilter}} {{/if}}</div>
</div>
<div class="wall-item-lock-wrapper">
{{if $item.lock}}<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="{{$item.lock}}" onclick="lockview(event,{{$item.id}});" /></div>
{{if $item.lock}}<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="{{$item.lock}}" onclick="lockview(event, 'item', {{$item.id}});" /></div>
{{else}}<div class="wall-item-lock"></div>{{/if}}
</div>
<div class="wall-item-tools" id="wall-item-tools-{{$item.id}}">

View file

@ -42,7 +42,7 @@
<div class="wall-item-lock-wrapper">
{{if $item.lock}}
<div class="wall-item-lock">
<img src="images/lock_icon.gif" class="lockview" alt="{{$item.lock}}" onclick="lockview(event,{{$item.id}});" />
<img src="images/lock_icon.gif" class="lockview" alt="{{$item.lock}}" onclick="lockview(event, 'item', {{$item.id}});" />
</div>
{{else}}
<div class="wall-item-lock"></div>

View file

@ -11,7 +11,7 @@
<a href="{{$profile_url}}" target="redir" title="{{$linktitle}}" class="wall-item-name-link"><span class="wall-item-name{{$sparkle}}">{{$name}}</span></a>
<span class="wall-item-ago">
{{if $plink}}<a class="link" title="{{$plink.title}}" href="{{$plink.href}}" style="color: #999">{{$ago}}</a>{{else}} {{$ago}} {{/if}}
{{if $lock}}<span class="fakelink" style="color: #999" onclick="lockview(event,{{$id}});">{{$lock}}</span> {{/if}}
{{if $lock}}<span class="fakelink" style="color: #999" onclick="lockview(event, 'item', {{$id}});">{{$lock}}</span> {{/if}}
</span>
</div>
<div class="wall-item-content">

View file

@ -17,7 +17,7 @@
| <a id="photo-toprofile-link" href="{{$tools.profile.0}}">{{$tools.profile.1}}</a>
{{/if}}
{{if $tools.lock}}
| <img src="images/lock_icon.gif" class="lockview" alt="{{$tools.lock}}" onclick="lockview(event,'photo/{{$id}}');" />
| <img src="images/lock_icon.gif" class="lockview" alt="{{$tools.lock}}" onclick="lockview(event, 'photo', {{$id}});" />
{{/if}}
{{/if}}
</div>

View file

@ -2,7 +2,7 @@
<div class="wall-item-decor">
{{if $item.star}}<span class="icon star {{$item.isstarred}}" id="starred-{{$item.id}}" title="{{$item.star.starred}}">{{$item.star.starred}}</span>{{/if}}
{{if $item.lock}}<span class="icon lock fakelink" onclick="lockview(event,{{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}
{{if $item.lock}}<span class="icon lock fakelink" onclick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}
<img id="like-rotator-{{$item.id}}" class="like-rotator" src="images/rotator.gif" alt="{{$item.wait}}" title="{{$item.wait}}" style="display: none;" />
</div>
@ -25,7 +25,7 @@
<a href="{{$item.profile_url}}" target="redir" title="{{$item.linktitle}}" class="wall-item-name-link"><span class="wall-item-name{{$item.sparkle}}">{{$item.name}}</span></a>
<span class="wall-item-ago">
{{if $item.plink}}<a class="link" title="{{$item.plink.title}}" href="{{$item.plink.href}}" style="color: #999">{{$item.ago}}</a>{{else}} {{$item.ago}} {{/if}}
{{if $item.lock}}<span class="fakelink" style="color: #999" onclick="lockview(event,{{$item.id}});">{{$item.lock}}</span> {{/if}}
{{if $item.lock}}<span class="fakelink" style="color: #999" onclick="lockview(event, 'item', {{$item.id}});">{{$item.lock}}</span> {{/if}}
</span>
</div>
<div class="wall-item-content">

View file

@ -65,7 +65,7 @@
{{/if}}
<span class="pinned">{{$item.pinned}}</span>
</span>
{{if $item.lock}}<span class="icon s10 lock fakelink" onclick="lockview(event,{{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}
{{if $item.lock}}<span class="icon s10 lock fakelink" onclick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}
<span class="wall-item-network" title="{{$item.app}}">
{{$item.network_name}}
</span>