2017-05-11 14:54:26 +02:00
< ? php
/**
2020-02-09 16:18:46 +01:00
* @ copyright Copyright ( C ) 2020 , Friendica
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*
2020-01-19 07:05:23 +01:00
* View for user import
2017-05-11 14:54:26 +02:00
*/
use Friendica\App ;
2018-10-29 22:20:46 +01:00
use Friendica\Core\Logger ;
2018-01-13 15:14:37 +01:00
use Friendica\Core\UserImport ;
2018-10-31 15:35:50 +01:00
use Friendica\Core\Renderer ;
2020-01-18 22:07:07 +01:00
use Friendica\DI ;
2017-05-11 14:54:26 +02:00
2018-01-22 15:16:25 +01:00
function uimport_post ( App $a )
{
2020-01-19 21:21:13 +01:00
if (( DI :: config () -> get ( 'config' , 'register_policy' ) != \Friendica\Module\Register :: OPEN ) && ! is_site_admin ()) {
2020-07-23 08:25:01 +02:00
notice ( DI :: l10n () -> t ( 'Permission denied.' ));
2018-08-27 13:55:08 +02:00
return ;
2017-05-11 14:54:26 +02:00
}
2018-08-27 13:55:08 +02:00
if ( ! empty ( $_FILES [ 'accountfile' ])) {
2019-12-16 00:28:31 +01:00
UserImport :: importAccount ( $_FILES [ 'accountfile' ]);
2017-05-11 14:54:26 +02:00
return ;
}
}
2018-08-27 13:55:08 +02:00
function uimport_content ( App $a )
{
2020-01-19 21:21:13 +01:00
if (( DI :: config () -> get ( 'config' , 'register_policy' ) != \Friendica\Module\Register :: OPEN ) && ! is_site_admin ()) {
2020-07-23 08:25:01 +02:00
notice ( DI :: l10n () -> t ( 'User imports on closed servers can only be done by an administrator.' ));
2017-05-11 14:54:26 +02:00
return ;
}
2020-01-19 21:21:13 +01:00
$max_dailies = intval ( DI :: config () -> get ( 'system' , 'max_daily_registrations' ));
2017-05-11 14:54:26 +02: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 22:20:46 +01:00
Logger :: log ( 'max daily registrations exceeded.' );
2020-07-23 08:25:01 +02:00
notice ( DI :: l10n () -> t ( 'This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.' ));
2017-05-11 14:54:26 +02:00
return ;
}
}
2018-10-31 15:44:06 +01:00
$tpl = Renderer :: getMarkupTemplate ( " uimport.tpl " );
2018-10-31 15:35:50 +01:00
return Renderer :: replaceMacros ( $tpl , [
2020-01-18 20:52:34 +01:00
'$regbutt' => DI :: l10n () -> t ( 'Import' ),
2018-01-15 14:05:12 +01:00
'$import' => [
2020-01-18 20:52:34 +01: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 14:05:12 +01:00
],
]);
2017-05-11 14:54:26 +02:00
}