Move group numbers from Container to constants

And fix update page.
This commit is contained in:
Visman 2021-11-29 21:46:50 +07:00
parent f8d12617aa
commit a76d1c1788
17 changed files with 81 additions and 69 deletions

View file

@ -37,7 +37,7 @@ class Install
}
$uri = \rawurldecode($uri);
$this->c->user = $this->c->users->create(['id' => 2, 'group_id' => $this->c->GROUP_ADMIN]);
$this->c->user = $this->c->users->create(['id' => 2, 'group_id' => FORK_GROUP_ADMIN]);
$this->c->Lang->load('common');
$r = $this->c->Router;

View file

@ -42,7 +42,7 @@ class Primary
|| ! isset($this->c->admins->list[$this->c->user->id])
) {
if (! $this->c->isInit('user')) {
$this->c->user = $this->c->users->create(['id' => 1, 'group_id' => $this->c->GROUP_GUEST]);
$this->c->user = $this->c->users->create(['id' => 1, 'group_id' => FORK_GROUP_GUEST]);
}
return $this->c->Maintenance;

View file

@ -77,7 +77,7 @@ class Update
}
$uri = \rawurldecode($uri);
$this->c->user = $this->c->users->create(['id' => 2, 'group_id' => $this->c->GROUP_ADMIN]); //???? id?
$this->c->user = $this->c->users->create(['id' => 2, 'group_id' => FORK_GROUP_ADMIN]); //???? id?
$this->c->Lang->load('common');
$r = $this->c->Router;

View file

@ -36,7 +36,7 @@ class UpdateUsername extends Action
$this->c->DB->exec($query, $vars);
$forums = $this->c->ForumManager->init($this->c->groups->get($this->c->GROUP_ADMIN))->get(0)->descendants;
$forums = $this->c->ForumManager->init($this->c->groups->get(FORK_GROUP_ADMIN))->get(0)->descendants;
$isMod = false;
foreach ($forums as $forum) {

View file

@ -33,10 +33,10 @@ class Model extends DataModel
protected function getcanDelete(): bool
{
$notDeleted = [
$this->c->GROUP_ADMIN,
$this->c->GROUP_MOD,
$this->c->GROUP_GUEST,
$this->c->GROUP_MEMBER
FORK_GROUP_ADMIN,
FORK_GROUP_MOD,
FORK_GROUP_GUEST,
FORK_GROUP_MEMBER,
];
return ! \in_array($this->g_id, $notDeleted, true) && $this->g_id !== $this->c->config->i_default_user_group;
@ -62,7 +62,7 @@ class Model extends DataModel
*/
protected function getgroupGuest(): bool
{
return $this->g_id === $this->c->GROUP_GUEST;
return $this->g_id === FORK_GROUP_GUEST;
}
/**
@ -70,7 +70,7 @@ class Model extends DataModel
*/
protected function getgroupMember(): bool
{
return $this->g_id === $this->c->GROUP_MEMBER;
return $this->g_id === FORK_GROUP_MEMBER;
}
/**
@ -78,6 +78,6 @@ class Model extends DataModel
*/
protected function getgroupAdmin(): bool
{
return $this->g_id === $this->c->GROUP_ADMIN;
return $this->g_id === FORK_GROUP_ADMIN;
}
}

View file

@ -30,7 +30,7 @@ class Perm extends Action
{
$vars = [
':fid' => $forum->id > 0 ? $forum->id : 0,
':adm' => $this->c->GROUP_ADMIN,
':adm' => FORK_GROUP_ADMIN,
];
$query = 'SELECT g.g_id, fp.read_forum, fp.post_replies, fp.post_topics
FROM ::groups AS g

View file

@ -28,8 +28,8 @@ class Groups extends Admin
$groupsList = [];
$groupsNew = [];
$groupsDefault = [];
$notForNew = [$this->c->GROUP_ADMIN];
$notForDefault = [$this->c->GROUP_ADMIN, $this->c->GROUP_MOD, $this->c->GROUP_GUEST];
$notForNew = [FORK_GROUP_ADMIN];
$notForDefault = [FORK_GROUP_ADMIN, FORK_GROUP_MOD, FORK_GROUP_GUEST];
foreach ($this->c->groups->getList() as $key => $group) {
$groupsList[$key] = [$group->g_title, $group->linkEdit, $group->linkDelete];
@ -196,7 +196,7 @@ class Groups extends Admin
}
$group = clone $baseGroup;
$notNext = $this->c->GROUP_ADMIN . ',' . $this->c->GROUP_GUEST;
$notNext = FORK_GROUP_ADMIN . ',' . FORK_GROUP_GUEST;
if (isset($args['id'])) {
$marker = 'AdminGroupsEdit';
@ -403,7 +403,7 @@ class Groups extends Admin
foreach ($this->groupsNew as $key => $title) {
if (
$key !== $group->g_id
&& $key !== $this->c->GROUP_GUEST
&& $key !== FORK_GROUP_GUEST
) {
$options[$key] = $title;
}
@ -718,7 +718,7 @@ class Groups extends Admin
$move = 'required|integer|in:';
foreach ($this->groupsList as $key => $cur) {
if (
$key === $this->c->GROUP_GUEST
$key === FORK_GROUP_GUEST
|| $key === $group->g_id
) {
continue;

View file

@ -1110,24 +1110,24 @@ class Install extends Admin
$now = \time();
$groups = [
// g_id, g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_mod_promote_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_post_links, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood, g_report_flood, g_promote_min_posts, g_promote_next_group
[$this->c->GROUP_ADMIN, __('Administrators'), __('Administrator '), 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, ],
[$this->c->GROUP_MOD, __('Moderators'), __('Moderator '), 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, ],
[$this->c->GROUP_GUEST, __('Guests'), '', 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 120, 60, 0, 0, 0, 0, ],
[$this->c->GROUP_MEMBER, __('Members'), '', 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 30, 30, 60, 60, 0, 0, ],
[$this->c->GROUP_NEW_MEMBER, __('New members'), __('New member'), 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 60, 30, 120, 60, 5, $this->c->GROUP_MEMBER,],
// g_id, g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_mod_promote_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_post_links, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood, g_report_flood, g_promote_min_posts, g_promote_next_group
[FORK_GROUP_ADMIN, __('Administrators'), __('Administrator '), 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, ],
[FORK_GROUP_MOD, __('Moderators'), __('Moderator '), 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, ],
[FORK_GROUP_GUEST, __('Guests'), '', 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 120, 60, 0, 0, 0, 0, ],
[FORK_GROUP_MEMBER, __('Members'), '', 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 30, 30, 60, 60, 0, 0, ],
[FORK_GROUP_NEW_MEMBER, __('New members'), __('New member'), 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 60, 30, 120, 60, 5, FORK_GROUP_MEMBER, ],
];
foreach ($groups as $group) { //???? $db_type != 'pgsql'
$this->c->DB->exec('INSERT INTO ::groups (g_id, g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_mod_promote_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_post_links, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood, g_report_flood, g_promote_min_posts, g_promote_next_group) VALUES (?i, ?s, ?s, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i, ?i)', $group) ;
}
$this->c->DB->exec('UPDATE ::groups SET g_pm_limit=0 WHERE g_id=?i', [$this->c->GROUP_ADMIN]);
$this->c->DB->exec('UPDATE ::groups SET g_pm=0, g_sig_length=0, g_sig_lines=0 WHERE g_id=?i', [$this->c->GROUP_GUEST]);
$this->c->DB->exec('UPDATE ::groups SET g_pm_limit=0 WHERE g_id=?i', [FORK_GROUP_ADMIN]);
$this->c->DB->exec('UPDATE ::groups SET g_pm=0, g_sig_length=0, g_sig_lines=0 WHERE g_id=?i', [FORK_GROUP_GUEST]);
$ip = \filter_var($_SERVER['REMOTE_ADDR'], \FILTER_VALIDATE_IP) ?: '0.0.0.0';
$this->c->DB->exec('INSERT INTO ::users (group_id, username, password, signature, u_pm) VALUES (?i, ?s, ?s, \'\', ?i)', [$this->c->GROUP_GUEST, __('Guest '), __('Guest '), 0]);
$this->c->DB->exec('INSERT INTO ::users (group_id, username, password, email, email_normal, language, style, num_posts, last_post, registered, registration_ip, last_visit, signature, num_topics) VALUES (?i, ?s, ?s, ?s, ?s, ?s, ?s, 1, ?i, ?i, ?s, ?i, \'\', 1)', [$this->c->GROUP_ADMIN, $v->username, password_hash($v->password, \PASSWORD_DEFAULT), $v->email, $this->c->NormEmail->normalize($v->email), $v->defaultlang, $v->defaultstyle, $now, $now, $ip, $now]);
$this->c->DB->exec('INSERT INTO ::users (group_id, username, password, signature, u_pm) VALUES (?i, ?s, ?s, \'\', ?i)', [FORK_GROUP_GUEST, __('Guest '), __('Guest '), 0]);
$this->c->DB->exec('INSERT INTO ::users (group_id, username, password, email, email_normal, language, style, num_posts, last_post, registered, registration_ip, last_visit, signature, num_topics) VALUES (?i, ?s, ?s, ?s, ?s, ?s, ?s, 1, ?i, ?i, ?s, ?i, \'\', 1)', [FORK_GROUP_ADMIN, $v->username, password_hash($v->password, \PASSWORD_DEFAULT), $v->email, $this->c->NormEmail->normalize($v->email), $v->defaultlang, $v->defaultstyle, $now, $now, $ip, $now]);
$pun_config = [
'i_fork_revision' => $this->c->FORK_REVISION,
@ -1144,7 +1144,7 @@ class Install extends Admin
'o_make_links' => 1,
'o_default_lang' => $v->defaultlang,
'o_default_style' => $v->defaultstyle,
'i_default_user_group' => $this->c->GROUP_NEW_MEMBER,
'i_default_user_group' => FORK_GROUP_NEW_MEMBER,
'i_topic_review' => 15,
'i_disp_topics_default' => 30,
'i_disp_posts_default' => 25,

View file

@ -427,6 +427,7 @@ class Update extends Admin
'EOL',
'\\PHP_EOL'
);
$coreConfig->save();
return null;
@ -439,15 +440,14 @@ class Update extends Admin
{
$coreConfig = new CoreConfig($this->configFile);
$result = $coreConfig->delete(
'multiple=>AdminUsersRecalculate',
);
$result = $coreConfig->delete('multiple=>AdminUsersRecalculate');
$coreConfig->add(
'multiple=>UserManagerUpdateLoginIpCache',
'\\ForkBB\\Models\\User\\UpdateLoginIpCache::class',
'UserManagerUpdateCountTopics'
);
$coreConfig->save();
return null;
@ -490,6 +490,7 @@ class Update extends Admin
'\\ForkBB\\Models\\Pages\\Email::class',
'Report'
);
$coreConfig->save();
return null;
@ -515,7 +516,7 @@ class Update extends Admin
$this->c->DB->query($query, $vars);
$vars = [
':grp' => $this->c->GROUP_ADMIN,
':grp' => FORK_GROUP_ADMIN,
];
$query = 'UPDATE ::groups
SET g_sig_use=1, g_sig_length=10000, g_sig_lines=255
@ -524,7 +525,7 @@ class Update extends Admin
$this->c->DB->query($query, $vars);
$vars = [
':grp' => $this->c->GROUP_GUEST,
':grp' => FORK_GROUP_GUEST,
];
$query = 'UPDATE ::groups
SET g_sig_use=0, g_sig_length=0, g_sig_lines=0
@ -568,6 +569,7 @@ class Update extends Admin
'\\ForkBB\\Models\\Post\\Feed::class',
'PostManagerMove'
);
$coreConfig->save();
return null;
@ -597,6 +599,7 @@ class Update extends Admin
'\\ForkBB\\Models\\Subscription\\Model::class',
'search'
);
$coreConfig->save();
return null;
@ -614,6 +617,7 @@ class Update extends Admin
'\\ForkBB\\Models\\Search\\ActionF::class',
'SearchModelActionT'
);
$coreConfig->save();
return null;
@ -631,9 +635,8 @@ class Update extends Admin
'\\ForkBB\\Models\\Subscription\\Send::class'
);
$result = $coreConfig->delete(
'multiple=>BanListModelIsBanned',
);
$result = $coreConfig->delete('multiple=>BanListModelIsBanned');
$coreConfig->add(
'shared=>BanListModelIsBanned',
'\\ForkBB\\Models\\BanList\\IsBanned::class'
@ -651,9 +654,7 @@ class Update extends Admin
{
$coreConfig = new CoreConfig($this->configFile);
$result = $coreConfig->delete(
'multiple=>AdminPermissions',
);
$result = $coreConfig->delete('multiple=>AdminPermissions');
$coreConfig->add(
'multiple=>AdminParser',
@ -685,9 +686,8 @@ class Update extends Admin
{
$coreConfig = new CoreConfig($this->configFile);
$result = $coreConfig->delete(
'multiple=>SmileyListModelLoad',
);
$result = $coreConfig->delete('multiple=>SmileyListModelLoad');
$coreConfig->add(
'shared=>SmileyListModelLoad',
'\\ForkBB\\Models\\SmileyList\\Load::class'
@ -765,9 +765,7 @@ class Update extends Admin
$coreConfig = new CoreConfig($this->configFile);
$result = $coreConfig->delete(
'BBCODE_INFO=>forSign',
);
$result = $coreConfig->delete('BBCODE_INFO=>forSign');
$coreConfig->add(
'shared=>bbcode',
@ -895,9 +893,7 @@ class Update extends Admin
{
$coreConfig = new CoreConfig($this->configFile);
$result = $coreConfig->delete(
'shared=>FileCache',
);
$result = $coreConfig->delete('shared=>FileCache');
$coreConfig->add(
'shared=>Cache',
@ -961,7 +957,7 @@ class Update extends Admin
$this->c->config->i_feed_type = $this->c->config->o_feed_type ?? 2;
$this->c->config->i_feed_ttl = $this->c->config->o_feed_ttl ?? 0;
$this->c->config->i_report_method = $this->c->config->o_report_method ?? 0;
$this->c->config->i_default_user_group = $this->c->config->o_default_user_group ?? $this->c->GROUP_MEMBER;
$this->c->config->i_default_user_group = $this->c->config->o_default_user_group ?? FORK_GROUP_MEMBER;
$this->c->config->a_max_users = [
'number' => (int) ($this->c->config->st_max_users ?? 1),
'time' => (int) ($this->c->config->st_max_users_time ?? \time()),
@ -1424,7 +1420,7 @@ class Update extends Admin
*/
protected function stageNumber36(array $args): ?int
{
$this->c->DB->exec('UPDATE ::groups SET g_pm=0, g_sig_length=0, g_sig_lines=0 WHERE g_id=?i', [$this->c->GROUP_GUEST]);
$this->c->DB->exec('UPDATE ::groups SET g_pm=0, g_sig_length=0, g_sig_lines=0 WHERE g_id=?i', [FORK_GROUP_GUEST]);
$this->c->DB->renameField('users', 'messages_enable', 'u_pm');
$this->c->DB->renameField('users', 'messages_email', 'u_pm_notify');
@ -1614,4 +1610,21 @@ class Update extends Admin
return null;
}
/**
* rev.39 to rev.40
*/
protected function stageNumber39(array $args): ?int
{
$coreConfig = new CoreConfig($this->configFile);
$result = $coreConfig->delete('GROUP_ADMIN');
$result = $coreConfig->delete('GROUP_MOD');
$result = $coreConfig->delete('GROUP_GUEST');
$result = $coreConfig->delete('GROUP_MEMBER');
$coreConfig->save();
return null;
}
}

View file

@ -217,11 +217,11 @@ class Action extends Users
foreach ($this->c->groups->getList() as $id => $group) {
$list[$id] = $group->g_title;
}
unset($list[$this->c->GROUP_GUEST]);
unset($list[FORK_GROUP_GUEST]);
if (! $profile) {
unset($list[$this->c->GROUP_ADMIN]);
unset($list[FORK_GROUP_ADMIN]);
} elseif (! $this->user->isAdmin) {
$list = [$this->c->GROUP_MEMBER => $list[$this->c->GROUP_MEMBER]];
$list = [FORK_GROUP_MEMBER => $list[FORK_GROUP_MEMBER]];
}
return $list;

View file

@ -21,7 +21,7 @@ class AdminsIds extends Action
public function adminsIds(): array
{
$vars = [
':gid' => $this->c->GROUP_ADMIN,
':gid' => FORK_GROUP_ADMIN,
];
$query = 'SELECT u.id
FROM ::users AS u

View file

@ -46,7 +46,7 @@ class Delete extends Action
}
if ($moderators) {
$forums = $this->c->ForumManager->init($this->c->groups->get($this->c->GROUP_ADMIN));
$forums = $this->c->ForumManager->init($this->c->groups->get(FORK_GROUP_ADMIN));
$root = $forums->get(0);
if ($root instanceof Forum) {

View file

@ -49,7 +49,7 @@ class Model extends DataModel
*/
protected function getisGuest(): bool
{
return $this->group_id === $this->c->GROUP_GUEST
return $this->group_id === FORK_GROUP_GUEST
|| $this->id < 2
|| null === $this->group_id;
}
@ -59,7 +59,7 @@ class Model extends DataModel
*/
protected function getisAdmin(): bool
{
return $this->group_id === $this->c->GROUP_ADMIN;
return $this->group_id === FORK_GROUP_ADMIN;
}
/**
@ -67,7 +67,7 @@ class Model extends DataModel
*/
protected function getisAdmMod(): bool
{
return $this->group_id === $this->c->GROUP_ADMIN
return $this->group_id === FORK_GROUP_ADMIN
|| 1 == $this->g_moderator;
}

View file

@ -22,7 +22,7 @@ class UsersNumber extends Action
{
if (
empty($group->g_id)
|| $group->g_id === $this->c->GROUP_GUEST
|| $group->g_id === FORK_GROUP_GUEST
) {
return 0;
}

View file

@ -24,6 +24,12 @@ use RuntimeException;
\mb_internal_encoding('UTF-8');
\mb_substitute_character(0xFFFD);
define('FORK_GROUP_UNVERIFIED', 0);
define('FORK_GROUP_ADMIN', 1);
define('FORK_GROUP_MOD', 2);
define('FORK_GROUP_GUEST', 3);
define('FORK_GROUP_MEMBER', 4);
require __DIR__ . '/../vendor/autoload.php';
$errorHandler = new ErrorHandler();
@ -52,7 +58,7 @@ if (
}
$c->PUBLIC_URL = $c->BASE_URL . $forkPublicPrefix;
$c->FORK_REVISION = 39;
$c->FORK_REVISION = 40;
$c->START = $forkStart;
$c->DIR_APP = __DIR__;
$c->DIR_PUBLIC = \realpath(__DIR__ . '/../public');

View file

@ -12,6 +12,8 @@ declare(strict_types=1);
\ini_set('display_errors', '1');
\ini_set('log_errors', '1');
define('FORK_GROUP_NEW_MEMBER', 5);
function forkGetBaseURL()
{
$file = \str_replace(\realpath($_SERVER['DOCUMENT_ROOT']), '', \realpath($_SERVER['SCRIPT_FILENAME']));
@ -25,11 +27,6 @@ function forkGetBaseURL()
return [
'BASE_URL' => forkGetBaseURL(),
'DEBUG' => 0,
'GROUP_ADMIN' => 1,
'GROUP_MOD' => 2,
'GROUP_GUEST' => 3,
'GROUP_MEMBER' => 4,
'GROUP_NEW_MEMBER' => 5,
'EOL' => \PHP_EOL,
'MAX_EMAIL_LENGTH' => 80,
'FLOOD_INTERVAL' => 3600,

View file

@ -38,10 +38,6 @@ return [
'JQUERY_LINK' => '//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js',
'DEBUG' => 0,
'MAINTENANCE_OFF' => false,
'GROUP_ADMIN' => 1,
'GROUP_MOD' => 2,
'GROUP_GUEST' => 3,
'GROUP_MEMBER' => 4,
'BBCODE_INFO' => [
'smTpl' => '<img src="{url}" alt="{alt}">',
'smTplTag' => 'img',