diff --git a/e107_handlers/userclass_class.php b/e107_handlers/userclass_class.php
index aeccd43f6..f2bdb605f 100644
--- a/e107_handlers/userclass_class.php
+++ b/e107_handlers/userclass_class.php
@@ -9,9 +9,9 @@
*
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/userclass_class.php,v $
- * $Revision: 1.46 $
- * $Date: 2009-11-18 01:04:43 $
- * $Author: e107coders $
+ * $Revision: 1.47 $
+ * $Date: 2009-12-07 20:43:37 $
+ * $Author: e107steved $
*/
/*
@@ -26,6 +26,8 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_userclass.php');
/*
+Fixed classes occupy a numeric block from e_UC_SPECIAL_BASE to e_UC_SPECIAL_END, plus zero = e_UC_PUBLIC
+(Note that in 0.7, class numbers stopped at 255. Now they can be up to 65535).
For info:
define("e_UC_PUBLIC", 0);
define("e_UC_MAINADMIN", 250);
@@ -42,7 +44,6 @@ define('e_UC_BOTS',246); // Reserved to identify search bots
define('e_UC_SPECIAL_BASE',243); // Assign class IDs 243 and above for fixed/special purposes
define('e_UC_SPECIAL_END',255); // Highest 'special' class
-// define('UC_CLASS_ICON_DIR','userclasses/'); // Directory for userclass icons - deprecated - the icon will be saved with the full path. {e_IMAGE} or {e_PLUGIN} / images/ etc.
define('UC_ICON_DIR',e_IMAGE.'generic/'); // Directory for the icons used in the admin tree displays
define('e_UC_BLANK','-1');
@@ -56,20 +57,20 @@ class user_class
var $class_tree; // Simple array, filled with current tree. Additional field class_children is an array of child user classes (by ID)
var $class_parents; // Array of class IDs of 'parent' (i.e. top level) classes
- var $fixed_classes = array(); // The 'predefined' classes of 0.7
+ var $fixed_classes = array(); // The 'predefined' core classes (constants beginning 'e_UC_')
var $text_class_link = array(); // List of 'core' user classes and the related constants
var $sql_r; // We'll use our own DB to avoid interactions
var $isAdmin; // Set true if we're an instance of user_class_admin
+
// Constructor
- function user_class()
+ public function __construct()
{
+ $this->sql_r = e107::getDb('sql_r');
+ $this->isAdmin = FALSE;
- $this->sql_r = e107::getDb('sql_r');
- $this->isAdmin = FALSE;
-
- $this->fixed_classes = array(e_UC_PUBLIC => UC_LAN_0,
+ $this->fixed_classes = array(e_UC_PUBLIC => UC_LAN_0,
e_UC_GUEST => UC_LAN_1,
e_UC_NOBODY => UC_LAN_2,
e_UC_MEMBER => UC_LAN_3,
@@ -80,105 +81,112 @@ class user_class
e_UC_BOTS => UC_LAN_10
);
- $this->text_class_link = array('public' => e_UC_PUBLIC, 'guest' => e_UC_GUEST, 'nobody' => e_UC_NOBODY, 'member' => e_UC_MEMBER,
+ $this->text_class_link = array('public' => e_UC_PUBLIC, 'guest' => e_UC_GUEST, 'nobody' => e_UC_NOBODY, 'member' => e_UC_MEMBER,
'admin' => e_UC_ADMIN, 'main' => e_UC_MAINADMIN, 'new' => e_UC_NEWUSER,
'bots' => e_UC_BOTS, 'readonly' => e_UC_READONLY);
- $this->readTree(TRUE); // Initialise the classes on entry
+ $this->readTree(TRUE); // Initialise the classes on entry
}
- /*
- Ensure the tree of userclass data is stored in our object.
- Only read if its either not present, or the $force flag is set
+ /**
+ Ensure the tree of userclass data is stored in our object ($this->class_tree).
+ Only read if its either not present, or the $force flag is set.
+ Data is cached if enabled
+ @param boolean $force - set to TRUE to force a re-read of the info regardless.
+ @return none
*/
- protected function readTree($force = FALSE)
- {
- if (isset($this->class_tree) && count($this->class_tree) && !$force) return $this->class_tree;
-
- global $e107;
- $this->class_tree = array();
- $this->class_parents = array();
-
- $array = new ArrayData;
- if ($temp = $e107->ecache->retrieve_sys(UC_CACHE_TAG))
+ protected function readTree($force = FALSE)
{
- $this->class_tree = $array->ReadArray($temp);
- unset($temp);
- }
- else
- {
- $this->sql_r->db_Select("userclass_classes", '*', "ORDER BY userclass_parent", 'nowhere'); // The order statement should give a consistent return
+ if (isset($this->class_tree) && count($this->class_tree) && !$force) return;
- while ($row = $this->sql_r->db_Fetch(MYSQL_ASSOC))
+ $e107 = e107::getInstance();
+
+ $this->class_tree = array();
+ $this->class_parents = array();
+
+ $array = new ArrayData;
+ if ($temp = $e107->ecache->retrieve_sys(UC_CACHE_TAG))
{
- $this->class_tree[$row['userclass_id']] = $row;
- $this->class_tree[$row['userclass_id']]['class_children'] = array(); // Create the child array in case needed
+ $this->class_tree = $array->ReadArray($temp);
+ unset($temp);
}
-
-
- // Add in any fixed classes that aren't already defined
- foreach ($this->fixed_classes as $c => $d)
+ else
{
-// if (!isset($this->class_tree[$c]) && ($c != e_UC_PUBLIC))
- if (!isset($this->class_tree[$c]))
+ $this->sql_r->db_Select('userclass_classes', '*', "ORDER BY userclass_parent", 'nowhere'); // The order statement should give a consistent return
+
+ while ($row = $this->sql_r->db_Fetch(MYSQL_ASSOC))
{
- switch ($c)
+ $this->class_tree[$row['userclass_id']] = $row;
+ $this->class_tree[$row['userclass_id']]['class_children'] = array(); // Create the child array in case needed
+ }
+
+
+ // Add in any fixed classes that aren't already defined
+ foreach ($this->fixed_classes as $c => $d)
+ {
+ if (!isset($this->class_tree[$c]))
{
- case e_UC_ADMIN :
- case e_UC_MAINADMIN :
- $this->class_tree[$c]['userclass_parent'] = e_UC_NOBODY;
- break;
- case e_UC_NEWUSER :
- $this->class_tree[$c]['userclass_parent'] = e_UC_MEMBER;
- break;
- default :
- $this->class_tree[$c]['userclass_parent'] = e_UC_PUBLIC;
+ switch ($c)
+ {
+ case e_UC_ADMIN :
+ case e_UC_MAINADMIN :
+ $this->class_tree[$c]['userclass_parent'] = e_UC_NOBODY;
+ break;
+ case e_UC_NEWUSER :
+ $this->class_tree[$c]['userclass_parent'] = e_UC_MEMBER;
+ break;
+ default :
+ $this->class_tree[$c]['userclass_parent'] = e_UC_PUBLIC;
+ }
+ $this->class_tree[$c]['userclass_id'] = $c;
+ $this->class_tree[$c]['userclass_name'] = $d;
+ $this->class_tree[$c]['userclass_description'] = 'Fixed class';
+ $this->class_tree[$c]['userclass_visibility'] = e_UC_PUBLIC;
+ $this->class_tree[$c]['userclass_editclass'] = e_UC_MAINADMIN;
+ $this->class_tree[$c]['userclass_accum'] = $c;
+ $this->class_tree[$c]['userclass_type'] = UC_TYPE_STD;
}
- $this->class_tree[$c]['userclass_id'] = $c;
- $this->class_tree[$c]['userclass_name'] = $d;
- $this->class_tree[$c]['userclass_description'] = 'Fixed class';
- $this->class_tree[$c]['userclass_visibility'] = e_UC_PUBLIC;
- $this->class_tree[$c]['userclass_editclass'] = e_UC_MAINADMIN;
- $this->class_tree[$c]['userclass_accum'] = $c;
- $this->class_tree[$c]['userclass_type'] = UC_TYPE_STD;
}
+
+ $userCache = $array->WriteArray($this->class_tree, FALSE);
+ $e107->ecache->set_sys(UC_CACHE_TAG,$userCache);
+ unset($userCache);
}
- $userCache = $array->WriteArray($this->class_tree, FALSE);
- $e107->ecache->set_sys(UC_CACHE_TAG,$userCache);
- unset($userCache);
- }
-
- // Now build the tree.
- // There are just two top-level classes - 'Everybody' and 'Nobody'
- $this->class_parents[e_UC_PUBLIC] = e_UC_PUBLIC;
- $this->class_parents[e_UC_NOBODY] = e_UC_NOBODY;
- foreach ($this->class_tree as $uc)
- {
- if (($uc['userclass_id'] != e_UC_PUBLIC) && ($uc['userclass_id'] != e_UC_NOBODY))
+ // Now build the tree.
+ // There are just two top-level classes - 'Everybody' and 'Nobody'
+ $this->class_parents[e_UC_PUBLIC] = e_UC_PUBLIC;
+ $this->class_parents[e_UC_NOBODY] = e_UC_NOBODY;
+ foreach ($this->class_tree as $uc)
{
-// if (!array_key_exists($uc['userclass_parent'],$this->class_tree))
- if (!isset($this->class_tree[$uc['userclass_parent']]))
+ if (($uc['userclass_id'] != e_UC_PUBLIC) && ($uc['userclass_id'] != e_UC_NOBODY))
{
- echo "Orphaned class record: ID=".$uc['userclass_id']." Name=".$uc['userclass_name']." Parent=".$uc['userclass_parent']." ";
- }
- else
- { // Add to array
- $this->class_tree[$uc['userclass_parent']]['class_children'][] = $uc['userclass_id'];
+ if (!isset($this->class_tree[$uc['userclass_parent']]))
+ {
+ echo "Orphaned class record: ID=".$uc['userclass_id']." Name=".$uc['userclass_name']." Parent=".$uc['userclass_parent']." ";
+ }
+ else
+ { // Add to array
+ $this->class_tree[$uc['userclass_parent']]['class_children'][] = $uc['userclass_id'];
+ }
}
}
}
- }
- // Given the list of 'base' classes a user belongs to, returns a comma separated list including ancestors. Duplicates stripped
- public function get_all_user_classes($start_list)
+ /** Given the list of 'base' classes a user belongs to, returns a comma separated list including ancestors. Duplicates stripped
+ *
+ * @param string $startList - comma-separated list of classes user belongs to
+ * @param boolean $asArray - if TRUE, result returned as array; otherwise result returned as string
+ * @return string|array of user classes; format determined by $asArray
+ */
+ public function get_all_user_classes($startList, $asArray = FALSE)
{
$is = array();
- $start_array = explode(',', $start_list);
+ $start_array = explode(',', $startList);
foreach ($start_array as $sa)
{ // Merge in latest values - should eliminate duplicates as it goes
if (isset($this->class_tree[$sa]))
@@ -186,16 +194,26 @@ class user_class
$is = array_merge($is,explode(',',$this->class_tree[$sa]['userclass_accum']));
}
}
+ if ($asArray)
+ {
+ return array_unique($is);
+ }
return implode(',',array_unique($is));
}
- // Returns a list of user classes which can be edited by the specified classlist (defaults to current user's classes)
- public function get_editable_classes($class_list = USERCLASS_LIST, $asArray = FALSE)
+
+ /** Returns a list of user classes which can be edited by the specified classlist
+ *
+ * @param string $classList - comma-separated list of classes to consider - default current user's class list
+ * @param boolean $asArray - if TRUE, result returned as array; otherwise result returned as string
+ * @return string|array of user classes; format determined by $asArray
+ */
+ public function get_editable_classes($classList = USERCLASS_LIST, $asArray = FALSE)
{
$ret = array();
$blockers = array(e_UC_PUBLIC => 1, e_UC_READONLY => 1, e_UC_MEMBER => 1, e_UC_NOBODY => 1, e_UC_GUEST => 1, e_UC_NEWUSER => 1, e_UC_BOTS => 1);
- $possibles = array_flip(explode(',',$class_list));
+ $possibles = array_flip(explode(',',$classList));
unset($possibles[e_UC_READONLY]);
foreach ($this->class_tree as $uc => $uv)
{
@@ -204,7 +222,6 @@ class user_class
$ec = $uv['userclass_editclass'];
if (isset($possibles[$ec]))
{
-// echo $uc." {$ec} {$uv['userclass_description']} ";
$ret[] = $uc;
}
}
@@ -215,11 +232,13 @@ class user_class
- // Combines the selected editable classes into the main class list for a user.
- // $combined - the complete list of current class memberships
- // $possible - the classes which are being edited
- // $actual - the actual membership of the editable classes
- // All classes may be passed as comma-separated lists or arrays
+ /** Combines the selected editable classes into the main class list for a user.
+ * @param array|string $combined - the complete list of current class memberships
+ * @param array|string $possible - the classes which are being edited
+ * @param array|string $actual - the actual membership of the editable classes
+ * @param boolean $asArray - if TRUE, result returned as array; otherwise result returned as string
+ * @return string|array of user classes; format determined by $asArray
+ */
public function mergeClassLists($combined, $possible, $actual, $asArray = FALSE)
{
if (!is_array($combined)) { $combined = explode(',',$combined); }
@@ -243,6 +262,12 @@ class user_class
}
+
+ /** Remove the fixed classes from a class list
+ * Removes all classes in the reserved block, as well as e_UC_PUBLIC
+ * @param array|string $inClasses - the complete list of current class memberships
+ * @return string|array of user classes; format is the same as $inClasses
+ */
public function stripFixedClasses($inClasses)
{
$asArray = TRUE;
@@ -251,44 +276,67 @@ class user_class
$asArray = FALSE;
$inClasses = explode(',',$inClasses);
}
+ /*
$inClasses = array_flip($inClasses);
foreach ($this->fixed_classes as $k => $v)
{
if (isset($inClasses[$k])) { unset($inClasses[$k]); }
}
$inClasses = array_keys($inClasses);
+ */
+ foreach ($inClasses as $k => $uc)
+ {
+ if ((($uc >= e_UC_SPECIAL_BASE) && ($uc <= e_UC_SPECIAL_END)) || ($uc == e_UC_PUBLIC))
+ {
+ unset($inClasses[$k]);
+ }
+ }
if ($asArray) { return ($inClasses); }
return implode(',',$inClasses);
}
- // Given a comma separated list, returns the minimum number of class memberships required to achieve this (i.e. strips classes 'above' another in the tree)
- // Requires the class tree to have been initialised
- public function normalise_classes($class_list)
- {
- $drop_classes = array();
- $old_classes = explode(',',$class_list);
- foreach ($old_classes as $c)
- { // Look at our parents (which are in 'userclass_accum') - if any of them are contained in old_classes, we can drop them.
- $tc = array_flip(explode(',',$this->class_tree[$c]['userclass_accum']));
- unset($tc[$c]); // Current class should be in $tc anyway
- foreach ($tc as $tc_c => $v)
- {
- if (in_array($tc_c,$old_classes))
+
+ /** Given a comma separated list, returns the minimum number of class memberships required to achieve this (i.e. strips classes 'above' another in the tree)
+ * Requires the class tree to have been initialised
+ * @param array|string $classList - the complete list of current class memberships
+ * @return string|array of user classes; format is the same as $inClasses
+ */
+ public function normalise_classes($classList)
+ {
+ $asArray = TRUE;
+ if (!is_array($inClasses))
{
- $drop_classes[] = $tc_c;
+ $asArray = FALSE;
+ $oldClasses = explode(',',$classList);
}
- }
+ $dropClasses = array();
+ foreach ($oldClasses as $c)
+ { // Look at our parents (which are in 'userclass_accum') - if any of them are contained in oldClasses, we can drop them.
+ $tc = array_flip(explode(',',$this->class_tree[$c]['userclass_accum']));
+ unset($tc[$c]); // Current class should be in $tc anyway
+ foreach ($tc as $tc_c => $v)
+ {
+ if (in_array($tc_c,$oldClasses))
+ {
+ $dropClasses[] = $tc_c;
+ }
+ }
+ }
+ $newClasses = array_diff($oldClasses,$dropClasses);
+ if ($asArray) { return $newClasses; }
+ return implode(',',$newClasses);
}
- $new_classes = array_diff($old_classes,$drop_classes);
- return implode(',',$new_classes);
- }
- /* Generate a dropdown list of user classes from which to select - virtually as r_userclass()
- $optlist allows selection of the classes to be shown in the dropdown. All or none can be included, separated by comma. Valid options are:
+ /** Generate a dropdown list of user classes from which to select - virtually as the deprecated r_userclass() function did
+ * [ $mode parameter of r_userclass() removed - $optlist is more flexible) ]
+ * @param string $fieldname - name of select list
+ * @param mixed $curval - current selected value (empty string if no current value)
+ * @param string $optlist - comma-separated list of classes/class types to be included in the list
+ It allows selection of the classes to be shown in the dropdown. All or none can be included, separated by comma. Valid options are:
public
guest
nobody
@@ -302,42 +350,42 @@ class user_class
matchclass - if 'classes' is set, this option will only show the classes that the user is a member of
blank - puts an empty option at the top of select dropdowns
- filter - only show those classes where member is in a class permitted to view them - i.e. as the new 'visible to' field - added for 0.8
+ filter - only show those classes where member is in a class permitted to view them - e.g. as the new 'visible to' field - added for 0.8
force - show all classes (subject to the other options, including matchclass) - added for 0.8
- $extra_js - can add JS handlers (e.g. 'onclick', 'onchange') if required
+ no-excludes - if present, doesn't show the 'not member of' list
- [ $mode parameter of r_userclass() removed - $optlist is more flexible) ]
-*/
- public function uc_dropdown($fieldname, $curval = 0, $optlist = "", $extra_js = '')
+ editable - can only appear on its own - returns list of those classes the user can edit (manage)
+
+ * @param string $extra_js - can add JS handlers (e.g. 'onclick', 'onchange') if required
+ */
+ public function uc_dropdown($fieldname, $curval = 0, $optlist = '', $extra_js = '')
{
- global $pref;
-
- $show_classes = self::uc_required_class_list($optlist);
+ $show_classes = self::uc_required_class_list($optlist); // Get list of classes which meet criteria
$text = '';
foreach ($show_classes as $k => $v)
{
if ($k == e_UC_BLANK)
{
- $text .= "\n";
+ $text .= "\n";
}
else
{
- $s = ($curval == $k && $curval !== '') ? "selected='selected'" : "";
- $text .= "\n";
+ $s = ($curval == $k && $curval !== '') ? "selected='selected'" : '';
+ $text .= "\n";
}
}
// Inverted Classes
- if(strpos($optlist, "no-excludes") !== TRUE)
+ if(strpos($optlist, 'no-excludes') !== TRUE)
{
$text .= "\n