2020-01-26 13:19:35 +00:00
|
|
|
<?php declare(strict_types=1);
|
2014-04-27 19:33:57 +00:00
|
|
|
/**
|
2015-08-02 19:39:41 +00:00
|
|
|
* @global UserClass[] $_shm_user_classes
|
2014-04-27 19:33:57 +00:00
|
|
|
*/
|
2015-08-02 19:39:41 +00:00
|
|
|
global $_shm_user_classes;
|
2019-05-28 16:59:38 +00:00
|
|
|
$_shm_user_classes = [];
|
2012-02-14 21:11:23 +00:00
|
|
|
|
2014-04-29 05:33:03 +00:00
|
|
|
/**
|
|
|
|
* Class UserClass
|
|
|
|
*/
|
2019-05-28 16:59:38 +00:00
|
|
|
class UserClass
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2019-05-28 19:27:23 +00:00
|
|
|
* @var ?string
|
2019-05-28 16:59:38 +00:00
|
|
|
*/
|
|
|
|
public $name = null;
|
|
|
|
|
|
|
|
/**
|
2019-05-28 19:27:23 +00:00
|
|
|
* @var ?UserClass
|
2019-05-28 16:59:38 +00:00
|
|
|
*/
|
|
|
|
public $parent = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $abilities = [];
|
|
|
|
|
2020-03-18 22:15:25 +00:00
|
|
|
public function __construct(string $name, string $parent = null, array $abilities = [])
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $_shm_user_classes;
|
|
|
|
|
|
|
|
$this->name = $name;
|
|
|
|
$this->abilities = $abilities;
|
|
|
|
|
|
|
|
if (!is_null($parent)) {
|
|
|
|
$this->parent = $_shm_user_classes[$parent];
|
|
|
|
}
|
|
|
|
|
|
|
|
$_shm_user_classes[$name] = $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if this class of user can perform an action or has ability.
|
|
|
|
*
|
|
|
|
* @throws SCoreException
|
|
|
|
*/
|
|
|
|
public function can(string $ability): bool
|
|
|
|
{
|
|
|
|
if (array_key_exists($ability, $this->abilities)) {
|
2020-01-26 13:19:35 +00:00
|
|
|
return $this->abilities[$ability];
|
2019-05-28 16:59:38 +00:00
|
|
|
} elseif (!is_null($this->parent)) {
|
|
|
|
return $this->parent->can($ability);
|
|
|
|
} else {
|
|
|
|
global $_shm_user_classes;
|
|
|
|
$min_dist = 9999;
|
|
|
|
$min_ability = null;
|
|
|
|
foreach ($_shm_user_classes['base']->abilities as $a => $cando) {
|
|
|
|
$v = levenshtein($ability, $a);
|
|
|
|
if ($v < $min_dist) {
|
|
|
|
$min_dist = $v;
|
|
|
|
$min_ability = $a;
|
|
|
|
}
|
|
|
|
}
|
2019-11-11 16:43:04 +00:00
|
|
|
throw new SCoreException("Unknown ability '$ability'. Did the developer mean '$min_ability'?");
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-14 21:11:23 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 13:37:14 +00:00
|
|
|
$_all_false = [];
|
2020-03-23 00:06:43 +00:00
|
|
|
foreach ((new ReflectionClass('Permissions'))->getConstants() as $k => $v) {
|
2020-03-19 13:37:14 +00:00
|
|
|
$_all_false[$v] = false;
|
|
|
|
}
|
|
|
|
new UserClass("base", null, $_all_false);
|
|
|
|
unset($_all_false);
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2019-11-28 17:20:23 +00:00
|
|
|
// Ghost users can't do anything
|
|
|
|
new UserClass("ghost", "base", [
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Anonymous users can't do anything by default, but
|
|
|
|
// the admin might grant them some permissions
|
2019-05-28 16:59:38 +00:00
|
|
|
new UserClass("anonymous", "base", [
|
2019-11-28 21:32:18 +00:00
|
|
|
Permissions::CREATE_USER => true,
|
2019-05-28 16:59:38 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
new UserClass("user", "base", [
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::BIG_SEARCH => true,
|
|
|
|
Permissions::CREATE_IMAGE => true,
|
|
|
|
Permissions::CREATE_COMMENT => true,
|
|
|
|
Permissions::EDIT_IMAGE_TAG => true,
|
|
|
|
Permissions::EDIT_IMAGE_SOURCE => true,
|
2019-07-09 14:23:46 +00:00
|
|
|
Permissions::EDIT_IMAGE_TITLE => true,
|
2020-02-08 00:24:13 +00:00
|
|
|
Permissions::EDIT_IMAGE_RELATIONSHIPS => true,
|
|
|
|
Permissions::EDIT_IMAGE_ARTIST => true,
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::CREATE_IMAGE_REPORT => true,
|
|
|
|
Permissions::EDIT_IMAGE_RATING => true,
|
2020-02-08 00:24:13 +00:00
|
|
|
Permissions::EDIT_FAVOURITES => true,
|
2019-12-15 20:40:05 +00:00
|
|
|
Permissions::SEND_PM => true,
|
|
|
|
Permissions::READ_PM => true,
|
2020-06-02 23:08:24 +00:00
|
|
|
Permissions::SET_PRIVATE_IMAGE => true,
|
2020-06-22 00:17:58 +00:00
|
|
|
Permissions::BULK_DOWNLOAD => true,
|
2020-10-26 15:13:28 +00:00
|
|
|
Permissions::CHANGE_USER_SETTING => true
|
2019-05-28 16:59:38 +00:00
|
|
|
]);
|
|
|
|
|
2020-03-19 13:37:14 +00:00
|
|
|
new UserClass("hellbanned", "user", [
|
|
|
|
Permissions::HELLBANNED => true,
|
|
|
|
]);
|
|
|
|
|
2020-03-18 22:15:25 +00:00
|
|
|
new UserClass("admin", "base", [
|
|
|
|
Permissions::CHANGE_SETTING => true,
|
2020-10-26 15:13:28 +00:00
|
|
|
Permissions::CHANGE_USER_SETTING => true,
|
|
|
|
Permissions::CHANGE_OTHER_USER_SETTING => true,
|
2020-03-18 22:15:25 +00:00
|
|
|
Permissions::OVERRIDE_CONFIG => true,
|
|
|
|
Permissions::BIG_SEARCH => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
|
|
|
Permissions::MANAGE_EXTENSION_LIST => true,
|
|
|
|
Permissions::MANAGE_ALIAS_LIST => true,
|
|
|
|
Permissions::MANAGE_AUTO_TAG => true,
|
|
|
|
Permissions::MASS_TAG_EDIT => true,
|
|
|
|
|
2020-03-18 22:15:25 +00:00
|
|
|
Permissions::VIEW_IP => true,
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::BAN_IP => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
|
|
|
Permissions::CREATE_USER => true,
|
2020-05-19 18:33:51 +00:00
|
|
|
Permissions::CREATE_OTHER_USER => true,
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::EDIT_USER_NAME => true,
|
|
|
|
Permissions::EDIT_USER_PASSWORD => true,
|
2020-03-18 22:15:25 +00:00
|
|
|
Permissions::EDIT_USER_INFO => true,
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::EDIT_USER_CLASS => true,
|
|
|
|
Permissions::DELETE_USER => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::CREATE_COMMENT => true,
|
|
|
|
Permissions::DELETE_COMMENT => true,
|
2020-03-18 22:15:25 +00:00
|
|
|
Permissions::BYPASS_COMMENT_CHECKS => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::REPLACE_IMAGE => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
Permissions::CREATE_IMAGE => true,
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::EDIT_IMAGE_TAG => true,
|
|
|
|
Permissions::EDIT_IMAGE_SOURCE => true,
|
|
|
|
Permissions::EDIT_IMAGE_OWNER => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
Permissions::EDIT_IMAGE_LOCK => true,
|
2019-07-09 14:23:46 +00:00
|
|
|
Permissions::EDIT_IMAGE_TITLE => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
Permissions::EDIT_IMAGE_RELATIONSHIPS => true,
|
|
|
|
Permissions::EDIT_IMAGE_ARTIST => true,
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::BULK_EDIT_IMAGE_TAG => true,
|
|
|
|
Permissions::BULK_EDIT_IMAGE_SOURCE => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
Permissions::DELETE_IMAGE => true,
|
|
|
|
|
|
|
|
Permissions::BAN_IMAGE => true,
|
|
|
|
|
|
|
|
Permissions::VIEW_EVENTLOG => true,
|
|
|
|
Permissions::IGNORE_DOWNTIME => true,
|
2020-03-19 13:37:14 +00:00
|
|
|
Permissions::VIEW_REGISTRATIONS => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::CREATE_IMAGE_REPORT => true,
|
2020-03-18 22:15:25 +00:00
|
|
|
Permissions::VIEW_IMAGE_REPORT => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-09-29 18:00:51 +00:00
|
|
|
Permissions::WIKI_ADMIN => true,
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::EDIT_WIKI_PAGE => true,
|
|
|
|
Permissions::DELETE_WIKI_PAGE => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::MANAGE_BLOCKS => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::MANAGE_ADMINTOOLS => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-12-15 20:40:05 +00:00
|
|
|
Permissions::SEND_PM => true,
|
|
|
|
Permissions::READ_PM => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
Permissions::VIEW_OTHER_PMS => true, # hm
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::EDIT_FEATURE => true,
|
|
|
|
Permissions::BULK_EDIT_VOTE => true,
|
|
|
|
Permissions::EDIT_OTHER_VOTE => true,
|
|
|
|
Permissions::VIEW_SYSINTO => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
|
|
|
Permissions::HELLBANNED => false,
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::VIEW_HELLBANNED => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2020-03-18 22:15:25 +00:00
|
|
|
Permissions::PROTECTED => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::EDIT_IMAGE_RATING => true,
|
|
|
|
Permissions::BULK_EDIT_IMAGE_RATING => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-07-09 14:10:21 +00:00
|
|
|
Permissions::VIEW_TRASH => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-07-13 22:39:27 +00:00
|
|
|
Permissions::PERFORM_BULK_ACTIONS => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-09-29 18:00:51 +00:00
|
|
|
Permissions::BULK_ADD => true,
|
|
|
|
Permissions::EDIT_FILES => true,
|
|
|
|
Permissions::EDIT_TAG_CATEGORIES => true,
|
|
|
|
Permissions::RESCAN_MEDIA => true,
|
|
|
|
Permissions::SEE_IMAGE_VIEW_COUNTS => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
|
|
|
Permissions::EDIT_FAVOURITES => true,
|
|
|
|
|
2019-09-29 18:00:51 +00:00
|
|
|
Permissions::ARTISTS_ADMIN => true,
|
|
|
|
Permissions::BLOTTER_ADMIN => true,
|
|
|
|
Permissions::FORUM_ADMIN => true,
|
|
|
|
Permissions::NOTES_ADMIN => true,
|
|
|
|
Permissions::POOLS_ADMIN => true,
|
|
|
|
Permissions::TIPS_ADMIN => true,
|
2019-10-17 19:22:33 +00:00
|
|
|
Permissions::CRON_ADMIN => true,
|
2020-03-18 22:06:55 +00:00
|
|
|
|
2019-10-14 18:43:49 +00:00
|
|
|
Permissions::APPROVE_IMAGE => true,
|
|
|
|
Permissions::APPROVE_COMMENT => true,
|
2020-06-02 23:05:09 +00:00
|
|
|
|
2020-10-08 22:14:15 +00:00
|
|
|
Permissions::CRON_RUN =>true,
|
|
|
|
|
2020-06-02 23:05:09 +00:00
|
|
|
Permissions::BULK_IMPORT =>true,
|
|
|
|
Permissions::BULK_EXPORT =>true,
|
2020-06-22 00:17:58 +00:00
|
|
|
Permissions::BULK_DOWNLOAD => true,
|
2020-06-02 23:08:24 +00:00
|
|
|
|
|
|
|
Permissions::SET_PRIVATE_IMAGE => true,
|
|
|
|
Permissions::SET_OTHERS_PRIVATE_IMAGES => true,
|
2019-05-28 16:59:38 +00:00
|
|
|
]);
|
|
|
|
|
2012-06-18 00:06:36 +00:00
|
|
|
@include_once "data/config/user-classes.conf.php";
|