2017-05-11 08:54:26 -04:00
< ? php
/**
2018-01-13 09:14:37 -05:00
* @ file mod / uimport . php
2020-01-19 01:05:23 -05:00
* View for user import
2017-05-11 08:54:26 -04:00
*/
use Friendica\App ;
2017-11-06 21:22:52 -05:00
use Friendica\Core\Config ;
2018-10-29 17:20:46 -04:00
use Friendica\Core\Logger ;
2018-01-13 09:14:37 -05:00
use Friendica\Core\UserImport ;
2018-10-31 10:35:50 -04:00
use Friendica\Core\Renderer ;
2020-01-18 16:07:07 -05:00
use Friendica\DI ;
2017-05-11 08:54:26 -04:00
2018-01-22 09:16:25 -05:00
function uimport_post ( App $a )
{
2020-01-19 15:21:13 -05:00
if (( DI :: config () -> get ( 'config' , 'register_policy' ) != \Friendica\Module\Register :: OPEN ) && ! is_site_admin ()) {
2020-01-18 14:52:34 -05:00
notice ( DI :: l10n () -> t ( 'Permission denied.' ) . EOL );
2018-08-27 07:55:08 -04:00
return ;
2017-05-11 08:54:26 -04:00
}
2018-08-27 07:55:08 -04:00
if ( ! empty ( $_FILES [ 'accountfile' ])) {
2019-12-15 18:28:31 -05:00
UserImport :: importAccount ( $_FILES [ 'accountfile' ]);
2017-05-11 08:54:26 -04:00
return ;
}
}
2018-08-27 07:55:08 -04:00
function uimport_content ( App $a )
{
2020-01-19 15:21:13 -05:00
if (( DI :: config () -> get ( 'config' , 'register_policy' ) != \Friendica\Module\Register :: OPEN ) && ! is_site_admin ()) {
2020-01-18 14:52:34 -05:00
notice ( DI :: l10n () -> t ( 'User imports on closed servers can only be done by an administrator.' ) . EOL );
2017-05-11 08:54:26 -04:00
return ;
}
2020-01-19 15:21:13 -05:00
$max_dailies = intval ( DI :: config () -> get ( 'system' , 'max_daily_registrations' ));
2017-05-11 08:54:26 -04:00
if ( $max_dailies ) {
$r = q ( " select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day " );
if ( $r && $r [ 0 ][ 'total' ] >= $max_dailies ) {
2018-10-29 17:20:46 -04:00
Logger :: log ( 'max daily registrations exceeded.' );
2020-01-18 14:52:34 -05:00
notice ( DI :: l10n () -> t ( 'This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.' ) . EOL );
2017-05-11 08:54:26 -04:00
return ;
}
}
2018-10-31 10:44:06 -04:00
$tpl = Renderer :: getMarkupTemplate ( " uimport.tpl " );
2018-10-31 10:35:50 -04:00
return Renderer :: replaceMacros ( $tpl , [
2020-01-18 14:52:34 -05:00
'$regbutt' => DI :: l10n () -> t ( 'Import' ),
2018-01-15 08:05:12 -05:00
'$import' => [
2020-01-18 14:52:34 -05:00
'title' => DI :: l10n () -> t ( " Move account " ),
'intro' => DI :: l10n () -> t ( " You can import an account from another Friendica server. " ),
'instruct' => DI :: l10n () -> t ( " You need to export your account from the old server and upload it here. We will recreate your old account here with all your contacts. We will try also to inform your friends that you moved here. " ),
'warn' => DI :: l10n () -> t ( " This feature is experimental. We can't import contacts from the OStatus network \x28 GNU Social/Statusnet \x29 or from Diaspora " ),
'field' => [ 'accountfile' , DI :: l10n () -> t ( 'Account file' ), '<input id="id_accountfile" name="accountfile" type="file">' , DI :: l10n () -> t ( 'To export your account, go to "Settings->Export your personal data" and select "Export account"' )],
2018-01-15 08:05:12 -05:00
],
]);
2017-05-11 08:54:26 -04:00
}