2015-08-23 22:38:18 +02:00
< ? php
require_once ( 'include/identity.php' );
require_once ( 'include/permissions.php' );
function new_channel_init ( & $a ) {
$cmd = (( argc () > 1 ) ? argv ( 1 ) : '' );
if ( $cmd === 'autofill.json' ) {
require_once ( 'library/urlify/URLify.php' );
$result = array ( 'error' => false , 'message' => '' );
$n = trim ( $_REQUEST [ 'name' ]);
$x = strtolower ( URLify :: transliterate ( $n ));
$test = array ();
// first name
if ( strpos ( $x , ' ' ))
$test [] = legal_webbie ( substr ( $x , 0 , strpos ( $x , ' ' )));
if ( $test [ 0 ]) {
// first name plus first initial of last
$test [] = (( strpos ( $x , ' ' )) ? $test [ 0 ] . legal_webbie ( trim ( substr ( $x , strpos ( $x , ' ' ), 2 ))) : '' );
// first name plus random number
$test [] = $test [ 0 ] . mt_rand ( 1000 , 9999 );
}
// fullname
$test [] = legal_webbie ( $x );
// fullname plus random number
$test [] = legal_webbie ( $x ) . mt_rand ( 1000 , 9999 );
json_return_and_die ( check_webbie ( $test ));
}
if ( $cmd === 'checkaddr.json' ) {
require_once ( 'library/urlify/URLify.php' );
$result = array ( 'error' => false , 'message' => '' );
$n = trim ( $_REQUEST [ 'nick' ]);
$x = strtolower ( URLify :: transliterate ( $n ));
$test = array ();
$n = legal_webbie ( $x );
if ( strlen ( $n )) {
$test [] = $n ;
$test [] = $n . mt_rand ( 1000 , 9999 );
}
for ( $y = 0 ; $y < 100 ; $y ++ )
$test [] = 'id' . mt_rand ( 1000 , 9999 );
json_return_and_die ( check_webbie ( $test ));
}
}
function new_channel_post ( & $a ) {
$arr = $_POST ;
2016-04-17 16:29:18 +02:00
$acc = App :: get_account ();
2016-02-28 12:11:12 +01:00
$arr [ 'account_id' ] = get_account_id ();
// prevent execution by delegated channels as well as those not logged in.
2016-04-17 16:29:18 +02:00
// get_account_id() returns the account_id from the session. But App::$account
2016-02-28 12:11:12 +01:00
// may point to the original authenticated account.
if (( ! $acc ) || ( $acc [ 'account_id' ] != $arr [ 'account_id' ])) {
2015-08-23 22:38:18 +02:00
notice ( t ( 'Permission denied.' ) . EOL );
return ;
}
$result = create_identity ( $arr );
if ( ! $result [ 'success' ]) {
notice ( $result [ 'message' ]);
return ;
}
$newuid = $result [ 'channel' ][ 'channel_id' ];
change_channel ( $result [ 'channel' ][ 'channel_id' ]);
if ( ! strlen ( $next_page = get_config ( 'system' , 'workflow_channel_next' )))
$next_page = 'settings' ;
goaway ( z_root () . '/' . $next_page );
}
function new_channel_content ( & $a ) {
2016-04-17 16:29:18 +02:00
$acc = App :: get_account ();
2016-02-28 12:11:12 +01:00
if (( ! $acc ) || $acc [ 'account_id' ] != get_account_id ()) {
2015-08-23 22:38:18 +02:00
notice ( t ( 'Permission denied.' ) . EOL );
return ;
}
2016-01-12 02:47:38 +01:00
$default_role = '' ;
$aid = get_account_id ();
if ( $aid ) {
$r = q ( " select count(channel_id) as total from channel where channel_account_id = %d " ,
intval ( $aid )
);
if ( $r && ( ! intval ( $r [ 0 ][ 'total' ]))) {
$default_role = get_config ( 'system' , 'default_permissions_role' );
}
2016-03-20 08:06:33 +01:00
$limit = account_service_class_fetch ( get_account_id (), 'total_identities' );
if ( $r && ( $limit !== false )) {
$channel_usage_message = sprintf ( t ( " You have created %1 $ .0f of %2 $ .0f allowed channels. " ), $r [ 0 ][ 'total' ], $limit );
}
else {
$channel_usage_message = '' ;
}
2016-01-12 02:47:38 +01:00
}
2016-03-20 08:06:33 +01:00
$name = array ( 'name' , t ( 'Name or caption' ), (( x ( $_REQUEST , 'name' )) ? $_REQUEST [ 'name' ] : '' ), t ( 'Examples: "Bob Jameson", "Lisa and her Horses", "Soccer", "Aviation Group"' ));
2016-04-17 16:29:18 +02:00
$nickhub = '@' . App :: get_hostname ();
2016-03-20 08:06:33 +01:00
$nickname = array ( 'nickname' , t ( 'Choose a short nickname' ), (( x ( $_REQUEST , 'nickname' )) ? $_REQUEST [ 'nickname' ] : '' ), sprintf ( t ( 'Your nickname will be used to create an easy to remember channel address e.g. nickname%s' ), $nickhub ));
2015-08-23 22:38:18 +02:00
$privacy_role = (( x ( $_REQUEST , 'permissions_role' )) ? $_REQUEST [ 'permissions_role' ] : " " );
2016-03-20 08:06:33 +01:00
$role = array ( 'permissions_role' , t ( 'Channel role and privacy' ), ( $privacy_role ) ? $privacy_role : 'social' , t ( 'Select a channel role with your privacy requirements.' ) . ' <a href="help/roles" target="_blank">' . t ( 'Read more about roles' ) . '</a>' , get_roles ());
2015-08-23 22:38:18 +02:00
$o = replace_macros ( get_markup_template ( 'new_channel.tpl' ), array (
2016-03-20 08:06:33 +01:00
'$title' => t ( 'Create Channel' ),
'$desc' => t ( 'A channel is your identity on this network. It can represent a person, a blog, or a forum to name a few. Channels can make connections with other channels to share information with highly detailed permissions.' ),
'$label_import' => t ( 'or <a href="import">import an existing channel</a> from another location.' ),
2015-08-23 22:38:18 +02:00
'$name' => $name ,
2016-03-20 08:06:33 +01:00
'$role' => $role ,
2016-01-12 02:47:38 +01:00
'$default_role' => $default_role ,
2015-08-23 22:38:18 +02:00
'$nickname' => $nickname ,
2016-03-20 08:06:33 +01:00
'$submit' => t ( 'Create' ),
'$channel_usage_message' => $channel_usage_message
2015-08-23 22:38:18 +02:00
));
return $o ;
}