2016-10-01 22:41:25 +00:00
|
|
|
<?php
|
2012-03-01 10:44:33 +00:00
|
|
|
/**
|
2016-10-01 22:41:25 +00:00
|
|
|
* @file include/acl_selectors.php
|
|
|
|
*
|
|
|
|
* @package acl_selectors
|
2012-03-01 10:44:33 +00:00
|
|
|
*/
|
2010-07-13 01:00:58 +00:00
|
|
|
|
2011-06-24 04:55:27 +00:00
|
|
|
|
2010-08-08 06:54:22 +00:00
|
|
|
function fixacl(&$item) {
|
2018-02-06 04:31:24 +00:00
|
|
|
$item = str_replace( [ '<', '>' ], [ '', '' ], $item);
|
2010-08-08 06:54:22 +00:00
|
|
|
}
|
2010-07-13 01:00:58 +00:00
|
|
|
|
2016-05-04 13:55:32 +00:00
|
|
|
/**
|
|
|
|
* Builds a modal dialog for editing permissions, using acl_selector.tpl as the template.
|
|
|
|
*
|
2016-10-01 22:41:25 +00:00
|
|
|
* @param array $defaults Optional access control list for the initial state of the dialog.
|
2016-05-04 13:55:32 +00:00
|
|
|
* @param boolean $show_jotnets Whether plugins for federated networks should be included in the permissions dialog
|
2017-09-04 22:23:42 +00:00
|
|
|
* @param \Zotlabs\Lib\PermissionDescription $emptyACL_description - An optional description for the permission implied by selecting an empty ACL. Preferably an instance of PermissionDescription.
|
2016-05-05 15:34:52 +00:00
|
|
|
* @param string $dialog_description Optional message to include at the top of the dialog. E.g. "Warning: Post permissions cannot be changed once sent".
|
|
|
|
* @param string $context_help Allows the dialog to present a help icon. E.g. "acl_dialog_post"
|
2016-05-04 13:55:32 +00:00
|
|
|
* @param boolean $readonly Not implemented yet. When implemented, the dialog will use acl_readonly.tpl instead, so that permissions may be viewed for posts that can no longer have their permissions changed.
|
|
|
|
*
|
2016-05-05 15:34:52 +00:00
|
|
|
* @return string html modal dialog built from acl_selector.tpl
|
2016-05-04 13:55:32 +00:00
|
|
|
*/
|
2016-05-08 10:44:30 +00:00
|
|
|
function populate_acl($defaults = null,$show_jotnets = true, $emptyACL_description = '', $dialog_description = '', $context_help = '', $readonly = false) {
|
2010-08-08 06:54:22 +00:00
|
|
|
|
|
|
|
$allow_cid = $allow_gid = $deny_cid = $deny_gid = false;
|
2016-05-08 10:44:30 +00:00
|
|
|
$showall_origin = '';
|
|
|
|
$showall_icon = 'fa-globe';
|
2016-10-01 22:41:25 +00:00
|
|
|
$role = get_pconfig(local_channel(), 'system', 'permissions_role');
|
2016-05-08 10:44:30 +00:00
|
|
|
|
|
|
|
if(! $emptyACL_description) {
|
2016-05-04 13:55:32 +00:00
|
|
|
$showall_caption = t('Visible to your default audience');
|
2015-12-31 23:10:36 +00:00
|
|
|
|
2016-10-01 22:41:25 +00:00
|
|
|
} else if(is_a($emptyACL_description, '\\Zotlabs\\Lib\\PermissionDescription')) {
|
2016-05-08 10:44:30 +00:00
|
|
|
$showall_caption = $emptyACL_description->get_permission_description();
|
2016-05-18 19:23:24 +00:00
|
|
|
$showall_origin = (($role === 'custom') ? $emptyACL_description->get_permission_origin_description() : '');
|
2016-05-08 10:44:30 +00:00
|
|
|
$showall_icon = $emptyACL_description->get_permission_icon();
|
|
|
|
} else {
|
|
|
|
// For backwards compatibility we still accept a string... for now!
|
|
|
|
$showall_caption = $emptyACL_description;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-29 22:08:37 +00:00
|
|
|
if(is_array($defaults)) {
|
2016-10-01 22:41:25 +00:00
|
|
|
$allow_cid = ((strlen($defaults['allow_cid']))
|
2013-11-29 22:08:37 +00:00
|
|
|
? explode('><', $defaults['allow_cid']) : array() );
|
|
|
|
$allow_gid = ((strlen($defaults['allow_gid']))
|
|
|
|
? explode('><', $defaults['allow_gid']) : array() );
|
|
|
|
$deny_cid = ((strlen($defaults['deny_cid']))
|
|
|
|
? explode('><', $defaults['deny_cid']) : array() );
|
|
|
|
$deny_gid = ((strlen($defaults['deny_gid']))
|
|
|
|
? explode('><', $defaults['deny_gid']) : array() );
|
2010-08-08 06:54:22 +00:00
|
|
|
array_walk($allow_cid,'fixacl');
|
|
|
|
array_walk($allow_gid,'fixacl');
|
|
|
|
array_walk($deny_cid,'fixacl');
|
|
|
|
array_walk($deny_gid,'fixacl');
|
|
|
|
}
|
2014-04-11 14:06:39 +00:00
|
|
|
|
2016-10-18 03:52:02 +00:00
|
|
|
|
2020-08-12 23:30:29 +00:00
|
|
|
$channel = ((local_channel()) ? App::get_channel() : '');
|
2016-10-18 03:52:02 +00:00
|
|
|
$has_acl = false;
|
|
|
|
$single_group = false;
|
|
|
|
$just_me = false;
|
|
|
|
$custom = false;
|
|
|
|
|
|
|
|
if($allow_cid || $allow_gid || $deny_gid || $deny_cid) {
|
|
|
|
$has_acl = true;
|
|
|
|
$custom = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count($allow_gid) === 1 && (! $allow_cid) && (! $deny_gid) && (! $deny_cid)) {
|
|
|
|
$single_group = true;
|
|
|
|
$custom = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count($allow_cid) === 1 && $channel && $allow_cid[0] = $channel['channel_hash'] && (! $allow_gid) && (! $deny_gid) && (! $deny_cid)) {
|
|
|
|
$just_me = true;
|
|
|
|
$custom = false;
|
2017-09-04 22:23:42 +00:00
|
|
|
}
|
2016-10-18 03:52:02 +00:00
|
|
|
|
2018-09-26 00:47:43 +00:00
|
|
|
$r = q("SELECT id, hash, gname FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
|
2016-08-15 20:54:07 +00:00
|
|
|
intval(local_channel())
|
|
|
|
);
|
|
|
|
|
|
|
|
if($r) {
|
|
|
|
foreach($r as $rr) {
|
2016-10-18 03:52:02 +00:00
|
|
|
$selected = (($single_group && $rr['hash'] === $allow_gid[0]) ? ' selected = "selected" ' : '');
|
|
|
|
$groups .= '<option id="' . $rr['id'] . '" value="' . $rr['hash'] . '"' . $selected . '>' . $rr['gname'] . '</option>' . "\r\n";
|
2016-08-15 20:54:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-19 14:17:58 +00:00
|
|
|
$tpl = get_markup_template("acl_selector.tpl");
|
|
|
|
$o = replace_macros($tpl, array(
|
2016-05-04 13:55:32 +00:00
|
|
|
'$showall' => $showall_caption,
|
2016-05-19 21:35:19 +00:00
|
|
|
'$onlyme' => t('Only me'),
|
2016-10-18 03:52:02 +00:00
|
|
|
'$groups' => $groups,
|
|
|
|
'$public_selected' => (($has_acl) ? false : true),
|
|
|
|
'$justme_selected' => $just_me,
|
|
|
|
'$custom_selected' => $custom,
|
2016-05-08 10:44:30 +00:00
|
|
|
'$showallOrigin' => $showall_origin,
|
|
|
|
'$showallIcon' => $showall_icon,
|
2016-05-18 19:23:24 +00:00
|
|
|
'$select_label' => t('Who can see this?'),
|
2016-08-16 06:05:46 +00:00
|
|
|
'$custom' => t('Custom selection'),
|
2016-05-04 16:09:47 +00:00
|
|
|
'$showlimitedDesc' => t('Select "Show" to allow viewing. "Don\'t show" lets you override and limit the scope of "Show".'),
|
2016-10-01 22:41:25 +00:00
|
|
|
'$show' => t('Show'),
|
2016-01-02 00:12:43 +00:00
|
|
|
'$hide' => t("Don't show"),
|
2016-10-01 22:41:25 +00:00
|
|
|
'$search' => t('Search'),
|
2015-12-31 23:10:36 +00:00
|
|
|
'$allowcid' => json_encode($allow_cid),
|
|
|
|
'$allowgid' => json_encode($allow_gid),
|
|
|
|
'$denycid' => json_encode($deny_cid),
|
|
|
|
'$denygid' => json_encode($deny_gid),
|
|
|
|
'$aclModalTitle' => t('Permissions'),
|
2016-05-04 13:55:32 +00:00
|
|
|
'$aclModalDesc' => $dialog_description,
|
|
|
|
'$aclModalDismiss' => t('Close'),
|
2019-05-27 02:55:08 +00:00
|
|
|
// '$helpUrl' => (($context_help == '') ? '' : (z_root() . '/help/' . $context_help))
|
2011-07-19 14:17:58 +00:00
|
|
|
));
|
2014-10-16 01:35:56 +00:00
|
|
|
|
2010-07-13 01:00:58 +00:00
|
|
|
return $o;
|
2010-08-16 12:23:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 15:34:52 +00:00
|
|
|
/**
|
2016-10-01 22:41:25 +00:00
|
|
|
* Returns a string that's suitable for passing as the $dialog_description argument to a
|
|
|
|
* populate_acl() call for wall posts or network posts.
|
|
|
|
*
|
|
|
|
* This string is needed in 3 different files, and our .po translation system currently
|
|
|
|
* cannot be used as a string table (because the value is always the key in english) so
|
|
|
|
* I've centralized the value here (making this function name the "key") until we have a
|
|
|
|
* better way.
|
|
|
|
*
|
|
|
|
* @return string Description to present to user in modal permissions dialog
|
|
|
|
*/
|
2016-05-05 15:34:52 +00:00
|
|
|
function get_post_aclDialogDescription() {
|
|
|
|
|
|
|
|
// I'm trying to make two points in this description text - warn about finality of wall
|
|
|
|
// post permissions, and try to clear up confusion that these permissions set who is
|
|
|
|
// *shown* the post, istead of who is able to see the post, i.e. make it clear that clicking
|
|
|
|
// the "Show" button on a group does not post it to the feed of people in that group, it
|
|
|
|
// mearly allows those people to view the post if they are viewing/following this channel.
|
2019-05-27 02:55:08 +00:00
|
|
|
$description = t('Post permissions cannot be changed after a post is shared.</br />These permissions set who is allowed to view the post.');
|
2016-05-05 15:34:52 +00:00
|
|
|
|
|
|
|
// Lets keep the emphasis styling seperate from the translation. It may change.
|
|
|
|
$emphasisOpen = '<b><a href="' . z_root() . '/help/acl_dialog_post" target="hubzilla-help">';
|
|
|
|
$emphasisClose = '</a></b>';
|
|
|
|
|
2019-05-27 02:55:08 +00:00
|
|
|
return $description;
|
2016-05-05 15:34:52 +00:00
|
|
|
}
|