channel permission roles

This commit is contained in:
friendica 2014-09-17 21:16:15 -07:00
parent eca420ec96
commit 51d9f0d97a
5 changed files with 46 additions and 9 deletions

View File

@ -219,13 +219,15 @@ function create_identity($arr) {
$perms_sql = ''; $perms_sql = '';
$role_permissions = null; $role_permissions = null;
$global_perms = get_perms();
if(array_key_exists('permissions_role',$arr) && $arr['permissions_role']) { if(array_key_exists('permissions_role',$arr) && $arr['permissions_role']) {
$role_permissions = get_role_perms($arr['permissions_role']); $role_permissions = get_role_perms($arr['permissions_role']);
if($role_permissions) { if($role_permissions) {
foreach($role_permissions as $p => $v) { foreach($role_permissions as $p => $v) {
if(strpos($p,'channel_') !== false) { if(strpos($p,'channel_') !== false) {
$perms_keys .= ', ' . $global_perms[$p][0]; $perms_keys .= ', ' . $p;
$perms_vals .= ', ' . intval($v); $perms_vals .= ', ' . intval($v);
} }
if($p === 'directory_publish') if($p === 'directory_publish')
@ -235,16 +237,16 @@ function create_identity($arr) {
} }
else { else {
$defperms = site_default_perms(); $defperms = site_default_perms();
$global_perms = get_perms();
foreach($defperms as $p => $v) { foreach($defperms as $p => $v) {
$perms_keys .= ', ' . $global_perms[$p][0]; $perms_keys .= ', ' . $global_perms[$p][0];
$perms_vals .= ', ' . intval($v); $perms_vals .= ', ' . intval($v);
} }
} }
$expire = get_config('system', 'default_expire_days'); $expire = get_config('system', 'default_expire_days');
$expire = (($expire===false)? '0': $expire); $expire = (($expire===false)? '0': $expire);
$r = q("insert into channel ( channel_account_id, channel_primary, $r = q("insert into channel ( channel_account_id, channel_primary,
channel_name, channel_address, channel_guid, channel_guid_sig, channel_name, channel_address, channel_guid, channel_guid_sig,
channel_hash, channel_prvkey, channel_pubkey, channel_pageflags, channel_expire_days $perms_keys ) channel_hash, channel_prvkey, channel_pubkey, channel_pageflags, channel_expire_days $perms_keys )
@ -264,8 +266,6 @@ function create_identity($arr) {
); );
$r = q("select * from channel where channel_account_id = %d $r = q("select * from channel where channel_account_id = %d
and channel_guid = '%s' limit 1", and channel_guid = '%s' limit 1",
intval($arr['account_id']), intval($arr['account_id']),

View File

@ -528,7 +528,7 @@ function get_role_perms($role) {
break; break;
case 'forum_public': case 'forum':
$ret['perms_auto'] = true; $ret['perms_auto'] = true;
$ret['default_collection'] = false; $ret['default_collection'] = false;
$ret['directory_publish'] = true; $ret['directory_publish'] = true;
@ -719,3 +719,28 @@ function get_role_perms($role) {
} }
function role_selector($current) {
$roles = array(
'social' => array( t('Social Networking'),
array('social' => t('Mostly Public'), 'social_restricted' => t('Restricted'), 'social_private' => t('Private'))),
'forum' => array( t('Community Forum'),
array('forum' => t('Mostly Public'), 'forum_restricted' => t('Restricted'), 'forum_private' => t('Private'))),
'feed' => array( t('Feed Republish'),
array('feed' => t('Mostly Public'), 'feed_restricted' => t('Restricted'))),
'soapbox' => array( t('Celebrity/Soapbox'),
array('soapbox' => t('Mostly Public'))),
'other' => array( t('Other'),
array('custom' => t('Custom/Expert Mode'))));
$o = '<select name="permissions_role" id="privacy-role-select">';
foreach($roles as $k => $v) {
$o .= '<optgroup label="'. htmlspecialchars($v[0]) . '" >';
foreach($v[1] as $kk => $vv) {
$selected = (($kk === $current) ? ' selected="selected" ' : '');
$o .= '<option value="' . $kk . '" ' . $selected . '>' . htmlspecialchars($vv) . '</option>';
}
$o .= '<optgroup>';
}
$o .= '</select>';
return $o;
}

View File

@ -1,6 +1,8 @@
<?php <?php
require_once('include/identity.php'); require_once('include/identity.php');
require_once('include/permissions.php');
function new_channel_init(&$a) { function new_channel_init(&$a) {
@ -100,7 +102,7 @@ function new_channel_content(&$a) {
$name = ((x($_REQUEST,'name')) ? $_REQUEST['name'] : "" ); $name = ((x($_REQUEST,'name')) ? $_REQUEST['name'] : "" );
$nickname = ((x($_REQUEST,'nickname')) ? $_REQUEST['nickname'] : "" ); $nickname = ((x($_REQUEST,'nickname')) ? $_REQUEST['nickname'] : "" );
$privacy_role = ((x($_REQUEST,'permissions_role')) ? $_REQUEST['permissions_role'] : "" );
$o = replace_macros(get_markup_template('new_channel.tpl'), array( $o = replace_macros(get_markup_template('new_channel.tpl'), array(
@ -113,6 +115,9 @@ function new_channel_content(&$a) {
'$nick_desc' => t('Your nickname will be used to create an easily remembered channel address (like an email address) which you can share with others.'), '$nick_desc' => t('Your nickname will be used to create an easily remembered channel address (like an email address) which you can share with others.'),
'$label_import' => t('Or <a href="import">import an existing channel</a> from another location'), '$label_import' => t('Or <a href="import">import an existing channel</a> from another location'),
'$name' => $name, '$name' => $name,
'$label_role' => t('Channel Type'),
'$help_role' => t('Please choose a channel role (such as social networking or community forum) and privacy requirements so we can select the best permissions for you'),
'$role_select' => role_selector(($privacy_role) ? $privacy_role : 'social'),
'$nickname' => $nickname, '$nickname' => $nickname,
'$submit' => t('Create') '$submit' => t('Create')
)); ));

View File

@ -1,13 +1,13 @@
h2 { h2 {
margin-left: 15%; margin-left: 15%;
margin-top: 15%; margin-top: 5%;
} }
#newchannel-form { #newchannel-form {
font-size: 1.4em; font-size: 1.4em;
margin-left: 15%; margin-left: 15%;
margin-top: 5%; margin-top: 20px;
width: 50%; width: 50%;
} }

View File

@ -4,6 +4,13 @@
<div id="newchannel-desc" class="descriptive-paragraph">{{$desc}}</div> <div id="newchannel-desc" class="descriptive-paragraph">{{$desc}}</div>
<div id="newchannel-role-help" class="descriptive-paragraph">{{$help_role}}</div>
<label for="newchannel-role" id="label-newchannel-role" class="newchannel-label" >{{$label_role}}</label>
{{$role_select}}
<div id="newchannel-role-end" class="newchannel-field-end"></div>
<label for="newchannel-name" id="label-newchannel-name" class="newchannel-label" >{{$label_name}}</label> <label for="newchannel-name" id="label-newchannel-name" class="newchannel-label" >{{$label_name}}</label>
<input type="text" name="name" id="newchannel-name" class="newchannel-input" value="{{$name}}" /> <input type="text" name="name" id="newchannel-name" class="newchannel-input" value="{{$name}}" />
<div id="newchannel-name-feedback" class="newchannel-feedback"></div> <div id="newchannel-name-feedback" class="newchannel-feedback"></div>