From 50a60135691987dd150def3fa6b695433a26a329 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 19 Mar 2012 11:27:01 +0000 Subject: [PATCH] nicer custom classes --- README.txt | 15 +++++++++++++ core/default_config.inc.php | 44 ------------------------------------- core/userclass.class.php | 31 ++++++++++++++------------ 3 files changed, 32 insertions(+), 58 deletions(-) diff --git a/README.txt b/README.txt index b10dca09..796317cc 100644 --- a/README.txt +++ b/README.txt @@ -74,6 +74,21 @@ Take a look at "core/default_config.inc.php" for the available options that can used. +Custom User Classes +~~~~~~~~~~~~~~~~~~~ +User classes can be added to or altered by placing them in +`data/config/user-classes.conf.php`. For example, one can override the +default anonymous "allow nothing" permissions like so: + +new UserClass("anonymous", "base", array( + "edit_image_tag" => True, + "edit_image_source" => True, + "create_image_report" => True, +)); + +For a list of permissions, see core/userclass.class.php + + Development Info ~~~~~~~~~~~~~~~~ http://shimmie.shishnet.org/doc/ diff --git a/core/default_config.inc.php b/core/default_config.inc.php index 23faf3eb..f2ddfcda 100644 --- a/core/default_config.inc.php +++ b/core/default_config.inc.php @@ -11,7 +11,6 @@ * */ -// to change these system-level settings, do define("FOO", 123); in config.php function _d($name, $value) {if(!defined($name)) define($name, $value);} _d("DATABASE_DSN", null); // string PDO database connection details _d("CACHE_DSN", null); // string cache connection details @@ -30,47 +29,4 @@ _d("WH_SPLITS", 1); // int how many levels of subfolders to put in _d("VERSION", 'trunk'); // string shimmie version _d("SCORE_VERSION", 's2hack/'.VERSION); // string SCore version _d("TIMEZONE", null); // string timezone -_d("EXTRA_USER_CLASSES", serialize(array())); // array extra classes that a user can be* - -/** - * Defining extra user classes: - * see core/userclass.class.php for flags - * - * This is a kind of ugly way of doing things... - * - -define("EXTRA_USER_CLASSES", serialize(array( - // a regular user, with some extra powers - array( - "moderator", # name for the new class - "user", # class to base it on - array( # parts of the base class to override - "edit_image_lock" => True, - "view_ip" => True, - "ban_ip" => True, - "delete_image" => True, - "delete_comment" => True, - "manage_alias_list" => True, - "mass_tag_edit" => True, - "edit_image_tag" => True, - "edit_image_source" => True, - "edit_image_owner" => True, - "view_image_report" => True, - ) - ), - // an admin, minus the ability to create / remove other admins - array( - "manager", # name for the new class - "admin", # class to base it on - array( # parts of the base class to override - "override_config" => False, - "edit_user_password" => False, - "edit_user_info" => False, - "delete_user" => False, - "manage_extension_list" => False, - ) - ), -))); - - */ ?> diff --git a/core/userclass.class.php b/core/userclass.class.php index 9f0a769e..a8e324c3 100644 --- a/core/userclass.class.php +++ b/core/userclass.class.php @@ -7,9 +7,13 @@ class UserClass { var $abilities = array(); public function __construct($name, $parent=null, $abilities=array()) { + global $_user_classes; + $this->name = $name; $this->parent = $parent; $this->abilities = $abilities; + + $_user_classes[$name] = $this; } public function can(/*string*/ $ability) { @@ -17,8 +21,7 @@ class UserClass { if(array_key_exists($ability, $this->abilities)) { $val = $this->abilities[$ability]; - if(is_bool($val)) return $val; - else return $config->get_bool($val, false); + return $val; } else if(!is_null($this->parent)) { return $this->parent->can($ability); @@ -32,7 +35,7 @@ class UserClass { // action_object_attribute // action = create / view / edit / delete // object = image / user / tag / setting -$_user_class_base = new UserClass("base", null, array( +new UserClass("base", null, array( "change_setting" => False, # modify web-level settings, eg the config table "override_config" => False, # modify sys-level settings, eg config.php "big_search" => False, # search for more than 3 tags at once (speed mode only) @@ -62,18 +65,21 @@ $_user_class_base = new UserClass("base", null, array( "protected" => False, # only admins can modify protected users (stops a moderator changing an admin's password) )); -$_user_classes["anonymous"] = new UserClass("anonymous", $_user_class_base, array( - "edit_image_tag" => "tag_edit_anon", - "edit_image_source" => "source_edit_anon", - "create_image_report" => "create_image_report_anon", + +new UserClass("anonymous", "base", array( + "edit_image_tag" => True, + "edit_image_source" => True, + "create_image_report" => True, )); -$_user_classes["user"] = new UserClass("user", $_user_class_base, array( + +new UserClass("user", "base", array( "big_search" => True, "edit_image_tag" => True, "edit_image_source" => True, "create_image_report" => True, )); -$_user_classes["admin"] = new UserClass("admin", $_user_class_base, array( + +new UserClass("admin", "base", array( "change_setting" => True, "override_config" => True, "big_search" => True, @@ -97,10 +103,7 @@ $_user_classes["admin"] = new UserClass("admin", $_user_class_base, array( "protected" => True, )); -foreach(unserialize(EXTRA_USER_CLASSES) as $class_info) { - $name = $class_info[0]; - $base = $_user_classes[$class_info[1]]; - $abilities = $class_info[2]; - $_user_classes[$name] = new UserClass($name, $base, $abilities); +if(file_exists("data/config/user-classes.conf.php")) { + require_once("data/config/user-classes.conf.php"); } ?>