Browse Source

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

Hypolite Petovan 1 month ago
parent
commit
cef6757c92

+ 1
- 1
config/local-sample.config.php View File

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

+ 5
- 4
config/settings.config.php View File

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

+ 1
- 1
include/api.php View File

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

+ 4
- 3
mod/admin.php View File

@@ -26,6 +26,7 @@ use Friendica\Model\Contact;
26 26
 use Friendica\Model\Item;
27 27
 use Friendica\Model\Register;
28 28
 use Friendica\Model\User;
29
+use Friendica\Module;
29 30
 use Friendica\Module\Login;
30 31
 use Friendica\Module\Tos;
31 32
 use Friendica\Util\Arrays;
@@ -1509,9 +1510,9 @@ function admin_page_site(App $a)
1509 1510
 
1510 1511
 	/* Register policy */
1511 1512
 	$register_choices = [
1512
-		REGISTER_CLOSED => L10n::t("Closed"),
1513
-		REGISTER_APPROVE => L10n::t("Requires approval"),
1514
-		REGISTER_OPEN => L10n::t("Open")
1513
+		Module\Register::CLOSED => L10n::t("Closed"),
1514
+		Module\Register::APPROVE => L10n::t("Requires approval"),
1515
+		Module\Register::OPEN => L10n::t("Open")
1515 1516
 	];
1516 1517
 
1517 1518
 	$ssl_choices = [

+ 1
- 1
mod/bookmarklet.php View File

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

+ 10
- 4
mod/friendica.php View File

@@ -10,16 +10,22 @@ use Friendica\Core\Hook;
10 10
 use Friendica\Core\L10n;
11 11
 use Friendica\Core\System;
12 12
 use Friendica\Database\DBA;
13
+use Friendica\Module\Register;
13 14
 
14 15
 function friendica_init(App $a)
15 16
 {
16 17
 	if (!empty($a->argv[1]) && ($a->argv[1] == "json")) {
17
-		$register_policies = ['REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN'];
18
-
19
-		$register_policy = $register_policies[intval(Config::get('config', 'register_policy'))];
18
+		$register_policies = [
19
+			Register::CLOSED  => 'REGISTER_CLOSED',
20
+			Register::APPROVE => 'REGISTER_APPROVE',
21
+			Register::OPEN    => 'REGISTER_OPEN'
22
+		];
20 23
 
21
-		if ($register_policy == 'REGISTER_OPEN' && Config::get('config', 'invitation_only')) {
24
+		$register_policy_int = intval(Config::get('config', 'register_policy'));
25
+		if ($register_policy_int === Register::OPEN && Config::get('config', 'invitation_only')) {
22 26
 			$register_policy = 'REGISTER_INVITATION';
27
+		} else {
28
+			$register_policy = $register_policies[$register_policy_int];
23 29
 		}
24 30
 
25 31
 		$sql_extra = '';

+ 1
- 1
mod/home.php View File

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

+ 3
- 2
mod/invite.php View File

@@ -13,6 +13,7 @@ use Friendica\Core\L10n;
13 13
 use Friendica\Core\PConfig;
14 14
 use Friendica\Core\Renderer;
15 15
 use Friendica\Core\System;
16
+use Friendica\Module\Register;
16 17
 use Friendica\Protocol\Email;
17 18
 use Friendica\Util\Strings;
18 19
 
@@ -125,14 +126,14 @@ function invite_content(App $a) {
125 126
 
126 127
 	$dirloc = Config::get('system', 'directory');
127 128
 	if (strlen($dirloc)) {
128
-		if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) {
129
+		if (intval(Config::get('config', 'register_policy')) === Register::CLOSED) {
129 130
 			$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');
130 131
 		} else {
131 132
 			$linktxt = L10n::t('To accept this invitation, please visit and register at %s or any other public Friendica website.', System::baseUrl())
132 133
 			. "\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');
133 134
 		}
134 135
 	} else { // there is no global directory URL defined
135
-		if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) {
136
+		if (intval(Config::get('config', 'register_policy')) === Register::CLOSED) {
136 137
 			$o = L10n::t('Our apologies. This system is not currently configured to connect with other public sites or invite members.');
137 138
 			return $o;
138 139
 		} else {

+ 1
- 1
mod/nodeinfo.php View File

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

+ 1
- 1
mod/openid.php View File

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

+ 1
- 1
mod/ping.php View File

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

+ 1
- 1
mod/regmod.php View File

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

+ 5
- 1
mod/statistics_json.php View File

@@ -16,11 +16,15 @@ function statistics_json_init(App $a) {
16 16
 		System::httpExit(404);
17 17
 	}
18 18
 
19
+	$registration_open =
20
+		intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED
21
+		&& ! Config::get('config', 'invitation_only');
22
+
19 23
 	$statistics = [
20 24
 		"name" => Config::get('config', 'sitename'),
21 25
 		"network" => FRIENDICA_PLATFORM,
22 26
 		"version" => FRIENDICA_VERSION . "-" . DB_UPDATE_VERSION,
23
-		"registrations_open" => intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED,
27
+		"registrations_open" => $registration_open,
24 28
 		"total_users" => Config::get('nodeinfo', 'total_users'),
25 29
 		"active_users_halfyear" => Config::get('nodeinfo', 'active_users_halfyear'),
26 30
 		"active_users_monthly" => Config::get('nodeinfo', 'active_users_monthly'),

+ 2
- 2
mod/uimport.php View File

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

+ 1
- 1
mods/local.config.vagrant.php View File

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

+ 1
- 1
src/Content/Nav.php View File

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

+ 1
- 1
src/Module/Login.php View File

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

+ 33
- 18
src/Protocol/PortableContact.php View File

@@ -20,6 +20,7 @@ use Friendica\Core\Worker;
20 20
 use Friendica\Database\DBA;
21 21
 use Friendica\Model\GContact;
22 22
 use Friendica\Model\Profile;
23
+use Friendica\Module\Register;
23 24
 use Friendica\Network\Probe;
24 25
 use Friendica\Util\DateTimeFormat;
25 26
 use Friendica\Util\Network;
@@ -705,10 +706,10 @@ class PortableContact
705 706
 
706 707
 		$server = [];
707 708
 
708
-		$server['register_policy'] = REGISTER_CLOSED;
709
+		$server['register_policy'] = Register::CLOSED;
709 710
 
710 711
 		if (is_bool($nodeinfo['openRegistrations']) && $nodeinfo['openRegistrations']) {
711
-			$server['register_policy'] = REGISTER_OPEN;
712
+			$server['register_policy'] = Register::OPEN;
712 713
 		}
713 714
 
714 715
 		if (is_array($nodeinfo['software'])) {
@@ -789,10 +790,10 @@ class PortableContact
789 790
 
790 791
 		$server = [];
791 792
 
792
-		$server['register_policy'] = REGISTER_CLOSED;
793
+		$server['register_policy'] = Register::CLOSED;
793 794
 
794 795
 		if (is_bool($nodeinfo['openRegistrations']) && $nodeinfo['openRegistrations']) {
795
-			$server['register_policy'] = REGISTER_OPEN;
796
+			$server['register_policy'] = Register::OPEN;
796 797
 		}
797 798
 
798 799
 		if (is_array($nodeinfo['software'])) {
@@ -1192,16 +1193,16 @@ class PortableContact
1192 1193
 				if (!empty($data['register_policy'])) {
1193 1194
 					switch ($data['register_policy']) {
1194 1195
 						case "REGISTER_OPEN":
1195
-							$register_policy = REGISTER_OPEN;
1196
+							$register_policy = Register::OPEN;
1196 1197
 							break;
1197 1198
 
1198 1199
 						case "REGISTER_APPROVE":
1199
-							$register_policy = REGISTER_APPROVE;
1200
+							$register_policy = Register::APPROVE;
1200 1201
 							break;
1201 1202
 
1202 1203
 						case "REGISTER_CLOSED":
1203 1204
 						default:
1204
-							$register_policy = REGISTER_CLOSED;
1205
+							$register_policy = Register::CLOSED;
1205 1206
 							break;
1206 1207
 					}
1207 1208
 				}
@@ -1267,11 +1268,11 @@ class PortableContact
1267 1268
 						}
1268 1269
 
1269 1270
 						if (!$closed && !$private and $inviteonly) {
1270
-							$register_policy = REGISTER_APPROVE;
1271
+							$register_policy = Register::APPROVE;
1271 1272
 						} elseif (!$closed && !$private) {
1272
-							$register_policy = REGISTER_OPEN;
1273
+							$register_policy = Register::OPEN;
1273 1274
 						} else {
1274
-							$register_policy = REGISTER_CLOSED;
1275
+							$register_policy = Register::CLOSED;
1275 1276
 						}
1276 1277
 					}
1277 1278
 				}
@@ -1305,9 +1306,9 @@ class PortableContact
1305 1306
 				}
1306 1307
 
1307 1308
 				if (!empty($data['registrations_open']) && $data['registrations_open']) {
1308
-					$register_policy = REGISTER_OPEN;
1309
+					$register_policy = Register::OPEN;
1309 1310
 				} else {
1310
-					$register_policy = REGISTER_CLOSED;
1311
+					$register_policy = Register::CLOSED;
1311 1312
 				}
1312 1313
 			}
1313 1314
 		}
@@ -1367,13 +1368,27 @@ class PortableContact
1367 1368
 					}
1368 1369
 
1369 1370
 					$info = defaults($data, 'info', '');
1370
-					$register_policy = defaults($data, 'register_policy', REGISTER_CLOSED);
1371
-					if (in_array($register_policy, ['REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN'])) {
1372
-						$register_policy = constant($register_policy);
1373
-					} else {
1374
-						Logger::log("Register policy '$register_policy' from $server_url is invalid.");
1375
-						$register_policy = REGISTER_CLOSED; // set a default value
1371
+
1372
+					$register_policy = defaults($data, 'register_policy', 'REGISTER_CLOSED');
1373
+					switch ($register_policy) {
1374
+						case 'REGISTER_OPEN':
1375
+							$register_policy = Register::OPEN;
1376
+							break;
1377
+
1378
+						case 'REGISTER_APPROVE':
1379
+							$register_policy = Register::APPROVE;
1380
+							break;
1381
+
1382
+						default:
1383
+							Logger::log("Register policy '$register_policy' from $server_url is invalid.");
1384
+							// Defaulting to closed
1385
+
1386
+						case 'REGISTER_CLOSED':
1387
+						case 'REGISTER_INVITATION':
1388
+							$register_policy = Register::CLOSED;
1389
+							break;
1376 1390
 					}
1391
+
1377 1392
 					$platform = defaults($data, 'platform', '');
1378 1393
 				}
1379 1394
 			}

+ 1
- 1
tests/src/Core/Console/AutomaticInstallationConsoleTest.php View File

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

+ 1
- 1
view/templates/local.config.tpl View File

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

Loading…
Cancel
Save