finish ACL's in personal menus

This commit is contained in:
friendica 2013-12-07 13:05:17 -08:00
parent e33d9d358a
commit 6dc157a9f9
5 changed files with 128 additions and 39 deletions

View File

@ -170,14 +170,16 @@ function suggest_widget() {
// This will throw some entropy intot he situation so you won't
// be looking at the same two mug shots every time the widget runs
$index = mt_rand(0,count($r) - 2);
$index = ((count($r) > 2) ? mt_rand(0,count($r) - 2) : 0);
for($x = $index; $x <= ($index+1); $x ++) {
$rr = $r[$x];
if(! $rr['xchan_url'])
break;
$connlnk = z_root() . '/follow/?url=' . $rr['xchan_addr'];
$arr[] = array(

View File

@ -196,6 +196,31 @@ function menu_add_item($menu_id, $uid, $arr) {
$mitem_desc = escape_tags($arr['mitem_desc']);
$mitem_order = intval($arr['mitem_order']);
$mitem_flags = intval($arr['mitem_flags']);
if(local_user() == $uid) {
$channel = get_app()->get_channel();
}
if ((! $arr['contact_allow'])
&& (! $arr['group_allow'])
&& (! $arr['contact_deny'])
&& (! $arr['group_deny'])) {
$str_group_allow = $channel['channel_allow_gid'];
$str_contact_allow = $channel['channel_allow_cid'];
$str_group_deny = $channel['channel_deny_gid'];
$str_contact_deny = $channel['channel_deny_cid'];
}
else {
// use the posted permissions
$str_group_allow = perms2str($arr['group_allow']);
$str_contact_allow = perms2str($arr['contact_allow']);
$str_group_deny = perms2str($arr['group_deny']);
$str_contact_deny = perms2str($arr['contact_deny']);
}
$allow_cid = perms2str($arr['allow_cid']);
$allow_gid = perms2str($arr['allow_gid']);
$deny_cid = perms2str($arr['deny_cid']);
@ -205,10 +230,10 @@ function menu_add_item($menu_id, $uid, $arr) {
dbesc($mitem_link),
dbesc($mitem_desc),
intval($mitem_flags),
dbesc($allow_cid),
dbesc($allow_gid),
dbesc($deny_cid),
dbesc($deny_gid),
dbesc($str_contact_allow),
dbesc($str_group_allow),
dbesc($str_contact_deny),
dbesc($str_group_deny),
intval($uid),
intval($menu_id),
intval($mitem_order)
@ -225,19 +250,40 @@ function menu_edit_item($menu_id, $uid, $arr) {
$mitem_desc = escape_tags($arr['mitem_desc']);
$mitem_order = intval($arr['mitem_order']);
$mitem_flags = intval($arr['mitem_flags']);
$allow_cid = perms2str($arr['allow_cid']);
$allow_gid = perms2str($arr['allow_gid']);
$deny_cid = perms2str($arr['deny_cid']);
$deny_gid = perms2str($arr['deny_gid']);
if(local_user() == $uid) {
$channel = get_app()->get_channel();
}
if ((! $arr['contact_allow'])
&& (! $arr['group_allow'])
&& (! $arr['contact_deny'])
&& (! $arr['group_deny'])) {
$str_group_allow = $channel['channel_allow_gid'];
$str_contact_allow = $channel['channel_allow_cid'];
$str_group_deny = $channel['channel_deny_gid'];
$str_contact_deny = $channel['channel_deny_cid'];
}
else {
// use the posted permissions
$str_group_allow = perms2str($arr['group_allow']);
$str_contact_allow = perms2str($arr['contact_allow']);
$str_group_deny = perms2str($arr['group_deny']);
$str_contact_deny = perms2str($arr['contact_deny']);
}
$r = q("update menu_item set mitem_link = '%s', mitem_desc = '%s', mitem_flags = %d, allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', mitem_order = %d where mitem_channel_id = %d and mitem_menu_id = %d and mitem_id = %d limit 1",
dbesc($mitem_link),
dbesc($mitem_desc),
intval($mitem_flags),
dbesc($allow_cid),
dbesc($allow_gid),
dbesc($deny_cid),
dbesc($deny_gid),
dbesc($str_contact_allow),
dbesc($str_group_allow),
dbesc($str_contact_deny),
dbesc($str_group_deny),
intval($mitem_order),
intval($uid),
intval($menu_id),

View File

@ -1,6 +1,7 @@
<?php
require_once('include/menu.php');
require_once('include/acl_selectors.php');
function mitem_init(&$a) {
if(! local_user())
@ -25,6 +26,9 @@ function mitem_post(&$a) {
if(! $a->data['menu'])
return;
$channel = $a->get_channel();
$_REQUEST['mitem_channel_id'] = local_user();
$_REQUEST['menu_id'] = $a->data['menu']['menu_id'];
@ -34,29 +38,6 @@ function mitem_post(&$a) {
if($_REQUEST['newwin'])
$_REQUEST['mitem_flags'] |= MENU_ITEM_NEWWIN;
// FIXME!!!!
if ((! $_REQUEST['contact_allow'])
&& (! $_REQUEST['group_allow'])
&& (! $_REQUEST['contact_deny'])
&& (! $_REQUEST['group_deny'])) {
$str_group_allow = $channel['channel_allow_gid'];
$str_contact_allow = $channel['channel_allow_cid'];
$str_group_deny = $channel['channel_deny_gid'];
$str_contact_deny = $channel['channel_deny_cid'];
}
else {
// use the posted permissions
$str_group_allow = perms2str($_REQUEST['group_allow']);
$str_contact_allow = perms2str($_REQUEST['contact_allow']);
$str_group_deny = perms2str($_REQUEST['group_deny']);
$str_contact_deny = perms2str($_REQUEST['contact_deny']);
}
$mitem_id = ((argc() > 2) ? intval(argv(2)) : 0);
if($mitem_id) {
@ -98,6 +79,8 @@ function mitem_content(&$a) {
return '';
}
$channel = $a->get_channel();
$a->set_widget('design',design_tools());
@ -135,11 +118,24 @@ function mitem_content(&$a) {
if(argc() > 2) {
if(argv(2) === 'new') {
$perm_defaults = array(
'allow_cid' => $channel['channel_allow_cid'],
'allow_gid' => $channel['channel_allow_gid'],
'deny_cid' => $channel['channel_deny_cid'],
'deny_gid' => $channel['channel_deny_gid']
);
$o = replace_macros(get_markup_template('mitemedit.tpl'), array(
'$header' => t('New Menu Element'),
'$menu_id' => $a->data['menu']['menu_id'],
'$permissions' => t('Menu Item Permissions'),
'$permdesc' => t("\x28click to open/close\x29"),
'$aclselect' => populate_acl($perm_defaults),
'$mitem_desc' => array('mitem_desc', t('Link text'), '', '','*'),
'$mitem_link' => array('mitem_link', t('URL of link'), '', '', '*'),
'$usezid' => array('usezid', t('Use Red magic-auth if available'), true, ''),
@ -180,6 +176,9 @@ function mitem_content(&$a) {
$o = replace_macros(get_markup_template('mitemedit.tpl'), array(
'$header' => t('Edit Menu Element'),
'$menu_id' => $a->data['menu']['menu_id'],
'$permissions' => t('Menu Item Permissions'),
'$permdesc' => t("\x28click to open/close\x29"),
'$aclselect' => populate_acl($mitem),
'$mitem_id' => intval(argv(2)),
'$mitem_desc' => array('mitem_desc', t('Link text'), $mitem['mitem_desc'], '','*'),
'$mitem_link' => array('mitem_link', t('URL of link'), $mitem['mitem_link'], '', '*'),

22
view/js/mod_mitem.js Normal file
View File

@ -0,0 +1,22 @@
$(document).ready(function() {
$("a#settings-default-perms-menu").colorbox({
'inline' : true,
'transition' : 'elastic'
});
$('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
var selstr;
$('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
selstr = $(this).text();
$('#jot-perms-icon').removeClass('unlock').addClass('lock');
$('#jot-public').hide();
});
if(selstr == null) {
$('#jot-perms-icon').removeClass('lock').addClass('unlock');
$('#jot-public').show();
}
}).trigger('change');
});

View File

@ -14,6 +14,26 @@
{{include file="field_input.tpl" field=$mitem_order}}
{{include file="field_checkbox.tpl" field=$usezid}}
{{include file="field_checkbox.tpl" field=$newwin}}
<div id="settings-default-perms" class="settings-default-perms" >
<a href="#profile-jot-acl-wrapper" id="settings-default-perms-menu" >{{$permissions}} {{$permdesc}}</a>
<div id="settings-default-perms-menu-end"></div>
<div id="settings-default-perms-select" style="display: none; margin-bottom: 20px" >
<div style="display: none;">
<div id="profile-jot-acl-wrapper" style="width:auto;height:auto;overflow:auto;">
{{$aclselect}}
</div>
</div>
</div>
</div>
<br/>
<div id="settings-default-perms-end"></div>
<div class="mitemedit-submit-wrapper" >
<input type="submit" name="submit" class="mitemedit-submit" value="{{$submit}}" />
</div>