Replace REGISTER_* constants by Module\Register::* ones

This commit is contained in:
Hypolite Petovan 2018-12-27 20:56:15 -05:00
parent 0ccb6afdb5
commit cef6757c92
20 changed files with 75 additions and 47 deletions

View File

@ -34,7 +34,7 @@ return [
'config' => [
'admin_email' => '',
'sitename' => 'Friendica Social Network',
'register_policy' => REGISTER_OPEN,
'register_policy' => \Friendica\Module\Register::OPEN,
'register_text' => '',
],
'system' => [

View File

@ -16,10 +16,11 @@ return [
'info' => '',
// register_policy (Constant)
// Your choices are REGISTER_OPEN, REGISTER_APPROVE, or REGISTER_CLOSED.
// Be certain to create your own personal account before setting REGISTER_CLOSED.
// REGISTER_APPROVE requires you set system.admin_email to the email address of an already registered person who can authorize and/or approve/deny the request.
'register_policy' => REGISTER_CLOSED,
// Your choices are OPEN, APPROVE, or CLOSED.
// Be certain to create your own personal account before setting CLOSED.
// APPROVE requires you set system.admin_email to the email address of an
// already registered person who can authorize and/or approve/deny the request.
'register_policy' => \Friendica\Module\Register::CLOSED,
// register_text (String)
// Will be displayed prominently on the registration page.

View File

@ -3557,7 +3557,7 @@ function api_statusnet_config($type)
$server = $a->getHostName();
$logo = System::baseUrl() . '/images/friendica-64.png';
$email = Config::get('config', 'admin_email');
$closed = intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 'true' : 'false';
$closed = intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 'true' : 'false';
$private = Config::get('system', 'block_public') ? 'true' : 'false';
$textlimit = (string) Config::get('config', 'api_import_size', Config::get('config', 'max_import_size', 200000));
$ssl = Config::get('system', 'have_ssl') ? 'true' : 'false';

View File

@ -26,6 +26,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Register;
use Friendica\Model\User;
use Friendica\Module;
use Friendica\Module\Login;
use Friendica\Module\Tos;
use Friendica\Util\Arrays;
@ -1509,9 +1510,9 @@ function admin_page_site(App $a)
/* Register policy */
$register_choices = [
REGISTER_CLOSED => L10n::t("Closed"),
REGISTER_APPROVE => L10n::t("Requires approval"),
REGISTER_OPEN => L10n::t("Open")
Module\Register::CLOSED => L10n::t("Closed"),
Module\Register::APPROVE => L10n::t("Requires approval"),
Module\Register::OPEN => L10n::t("Open")
];
$ssl_choices = [

View File

@ -20,7 +20,7 @@ function bookmarklet_content(App $a)
{
if (!local_user()) {
$o = '<h2>' . L10n::t('Login') . '</h2>';
$o .= Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? false : true);
$o .= Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? false : true);
return $o;
}

View File

@ -10,16 +10,22 @@ use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Module\Register;
function friendica_init(App $a)
{
if (!empty($a->argv[1]) && ($a->argv[1] == "json")) {
$register_policies = ['REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN'];
$register_policies = [
Register::CLOSED => 'REGISTER_CLOSED',
Register::APPROVE => 'REGISTER_APPROVE',
Register::OPEN => 'REGISTER_OPEN'
];
$register_policy = $register_policies[intval(Config::get('config', 'register_policy'))];
if ($register_policy == 'REGISTER_OPEN' && Config::get('config', 'invitation_only')) {
$register_policy_int = intval(Config::get('config', 'register_policy'));
if ($register_policy_int === Register::OPEN && Config::get('config', 'invitation_only')) {
$register_policy = 'REGISTER_INVITATION';
} else {
$register_policy = $register_policies[$register_policy_int];
}
$sql_extra = '';

View File

@ -48,7 +48,7 @@ function home_content(App $a) {
}
}
$login = Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1);
$login = Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 0 : 1);
$content = '';
Hook::callAll("home_content",$content);

View File

@ -13,6 +13,7 @@ use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Module\Register;
use Friendica\Protocol\Email;
use Friendica\Util\Strings;
@ -125,14 +126,14 @@ function invite_content(App $a) {
$dirloc = Config::get('system', 'directory');
if (strlen($dirloc)) {
if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) {
if (intval(Config::get('config', 'register_policy')) === Register::CLOSED) {
$linktxt = L10n::t('Visit %s for a list of public sites that you can join. Friendica members on other sites can all connect with each other, as well as with members of many other social networks.', $dirloc . '/servers');
} else {
$linktxt = L10n::t('To accept this invitation, please visit and register at %s or any other public Friendica website.', System::baseUrl())
. "\r\n" . "\r\n" . L10n::t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks. See %s for a list of alternate Friendica sites you can join.', $dirloc . '/servers');
}
} else { // there is no global directory URL defined
if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) {
if (intval(Config::get('config', 'register_policy')) === Register::CLOSED) {
$o = L10n::t('Our apologies. This system is not currently configured to connect with other public sites or invite members.');
return $o;
} else {

View File

@ -59,7 +59,7 @@ function nodeinfo_init(App $a) {
$nodeinfo['usage'] = [];
$nodeinfo['openRegistrations'] = intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED;
$nodeinfo['openRegistrations'] = intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED;
$nodeinfo['metadata'] = ['nodeName' => Config::get('config', 'sitename')];

View File

@ -63,7 +63,7 @@ function openid_content(App $a) {
// Successful OpenID login - but we can't match it to an existing account.
// New registration?
if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) {
if (intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED) {
notice(L10n::t('Account not found and OpenID registration is not permitted on this site.') . EOL);
$a->internalRedirect();
}

View File

@ -188,7 +188,7 @@ function ping_init(App $a)
);
$mail_count = count($mails);
if (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE && is_site_admin()) {
if (intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::APPROVE && is_site_admin()) {
$regs = Friendica\Model\Register::getPending();
if (DBA::isResult($regs)) {

View File

@ -82,7 +82,7 @@ function regmod_content(App $a)
{
if (!local_user()) {
info(L10n::t('Please login.') . EOL);
return Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1);
return Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 0 : 1);
}
if (!is_site_admin() || !empty($_SESSION['submanage'])) {

View File

@ -16,11 +16,15 @@ function statistics_json_init(App $a) {
System::httpExit(404);
}
$registration_open =
intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED
&& ! Config::get('config', 'invitation_only');
$statistics = [
"name" => Config::get('config', 'sitename'),
"network" => FRIENDICA_PLATFORM,
"version" => FRIENDICA_VERSION . "-" . DB_UPDATE_VERSION,
"registrations_open" => intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED,
"registrations_open" => $registration_open,
"total_users" => Config::get('nodeinfo', 'total_users'),
"active_users_halfyear" => Config::get('nodeinfo', 'active_users_halfyear'),
"active_users_monthly" => Config::get('nodeinfo', 'active_users_monthly'),

View File

@ -13,7 +13,7 @@ use Friendica\Core\Renderer;
function uimport_post(App $a)
{
if ((Config::get('config', 'register_policy') != REGISTER_OPEN) && !is_site_admin()) {
if ((Config::get('config', 'register_policy') != \Friendica\Module\Register::OPEN) && !is_site_admin()) {
notice(L10n::t('Permission denied.') . EOL);
return;
}
@ -26,7 +26,7 @@ function uimport_post(App $a)
function uimport_content(App $a)
{
if ((Config::get('config', 'register_policy') != REGISTER_OPEN) && !is_site_admin()) {
if ((Config::get('config', 'register_policy') != \Friendica\Module\Register::OPEN) && !is_site_admin()) {
notice(L10n::t('User imports on closed servers can only be done by an administrator.') . EOL);
return;
}

View File

@ -31,7 +31,7 @@ return [
'config' => [
'admin_email' => 'admin@friendica.local',
'sitename' => 'Friendica Social Network',
'register_policy' => REGISTER_OPEN,
'register_policy' => \Friendica\Module\Register::OPEN,
'register_text' => '',
],
'system' => [

View File

@ -180,7 +180,7 @@ class Nav
$nav['home'] = [$homelink, L10n::t('Home'), '', L10n::t('Home Page')];
}
if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN && !local_user() && !remote_user()) {
if (intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::OPEN && !local_user() && !remote_user()) {
$nav['register'] = ['register', L10n::t('Register'), '', L10n::t('Create an account')];
}

View File

@ -43,7 +43,7 @@ class Login extends BaseModule
$a->internalRedirect();
}
return self::form(defaults($_SESSION, 'return_path', null), intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED);
return self::form(defaults($_SESSION, 'return_path', null), intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED);
}
public static function post()

View File

@ -20,6 +20,7 @@ use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\GContact;
use Friendica\Model\Profile;
use Friendica\Module\Register;
use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
@ -705,10 +706,10 @@ class PortableContact
$server = [];
$server['register_policy'] = REGISTER_CLOSED;
$server['register_policy'] = Register::CLOSED;
if (is_bool($nodeinfo['openRegistrations']) && $nodeinfo['openRegistrations']) {
$server['register_policy'] = REGISTER_OPEN;
$server['register_policy'] = Register::OPEN;
}
if (is_array($nodeinfo['software'])) {
@ -789,10 +790,10 @@ class PortableContact
$server = [];
$server['register_policy'] = REGISTER_CLOSED;
$server['register_policy'] = Register::CLOSED;
if (is_bool($nodeinfo['openRegistrations']) && $nodeinfo['openRegistrations']) {
$server['register_policy'] = REGISTER_OPEN;
$server['register_policy'] = Register::OPEN;
}
if (is_array($nodeinfo['software'])) {
@ -1192,16 +1193,16 @@ class PortableContact
if (!empty($data['register_policy'])) {
switch ($data['register_policy']) {
case "REGISTER_OPEN":
$register_policy = REGISTER_OPEN;
$register_policy = Register::OPEN;
break;
case "REGISTER_APPROVE":
$register_policy = REGISTER_APPROVE;
$register_policy = Register::APPROVE;
break;
case "REGISTER_CLOSED":
default:
$register_policy = REGISTER_CLOSED;
$register_policy = Register::CLOSED;
break;
}
}
@ -1267,11 +1268,11 @@ class PortableContact
}
if (!$closed && !$private and $inviteonly) {
$register_policy = REGISTER_APPROVE;
$register_policy = Register::APPROVE;
} elseif (!$closed && !$private) {
$register_policy = REGISTER_OPEN;
$register_policy = Register::OPEN;
} else {
$register_policy = REGISTER_CLOSED;
$register_policy = Register::CLOSED;
}
}
}
@ -1305,9 +1306,9 @@ class PortableContact
}
if (!empty($data['registrations_open']) && $data['registrations_open']) {
$register_policy = REGISTER_OPEN;
$register_policy = Register::OPEN;
} else {
$register_policy = REGISTER_CLOSED;
$register_policy = Register::CLOSED;
}
}
}
@ -1367,13 +1368,27 @@ class PortableContact
}
$info = defaults($data, 'info', '');
$register_policy = defaults($data, 'register_policy', REGISTER_CLOSED);
if (in_array($register_policy, ['REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN'])) {
$register_policy = constant($register_policy);
} else {
Logger::log("Register policy '$register_policy' from $server_url is invalid.");
$register_policy = REGISTER_CLOSED; // set a default value
$register_policy = defaults($data, 'register_policy', 'REGISTER_CLOSED');
switch ($register_policy) {
case 'REGISTER_OPEN':
$register_policy = Register::OPEN;
break;
case 'REGISTER_APPROVE':
$register_policy = Register::APPROVE;
break;
default:
Logger::log("Register policy '$register_policy' from $server_url is invalid.");
// Defaulting to closed
case 'REGISTER_CLOSED':
case 'REGISTER_INVITATION':
$register_policy = Register::CLOSED;
break;
}
$platform = defaults($data, 'platform', '');
}
}

View File

@ -209,7 +209,7 @@ return [
'config' => [
'admin_email' => '',
'sitename' => 'Friendica Social Network',
'register_policy' => REGISTER_OPEN,
'register_policy' => \Friendica\Module\Register::OPEN,
'register_text' => '',
],
'system' => [

View File

@ -24,7 +24,7 @@ return [
'php_path' => '{{$phpath}}',
'admin_email' => '{{$adminmail}}',
'sitename' => 'Friendica Social Network',
'register_policy' => REGISTER_OPEN,
'register_policy' => \Friendica\Module\Register::OPEN,
'max_import_size' => 200000,
],
'system' => [