function calculateUserWeight($pUserId = NULL) { global $gBitUser, $gBitSystem; if ($gBitSystem->isFeatureActive('stars_user_weight')) { // allow overriding of currently loaded user if (@BitBase::verifyId($pUserId)) { $tmpUser = new BitPermUser($pUserId); $tmpUser->load(TRUE); } else { $tmpUser =& $gBitUser; } // age relative to site age $query = "SELECT MIN( `registration_date` ) FROM `" . BIT_DB_PREFIX . "users_users`"; $age['site'] = BitDate::getUTCTime() - $this->mDb->getOne($query); $age['user'] = BitDate::getUTCTime() - $tmpUser->getField('registration_date'); $userWeight['age'] = $age['user'] / $age['site']; // permissioning relative to full number of permissions $query = "SELECT COUNT( `perm_name` ) FROM `" . BIT_DB_PREFIX . "users_permissions`"; if ($tmpUser->isAdmin()) { $userWeight['permission'] = 1; } else { $userWeight['permission'] = count($tmpUser->mPerms) / $this->mDb->getOne($query); } // activity - we could to the same using the history as well. $query = "SELECT COUNT( `content_id` ) FROM `" . BIT_DB_PREFIX . "liberty_content` WHERE `user_id`=?"; $activity['user'] = $this->mDb->getOne($query, array($tmpUser->getField('user_id'))); $query = "SELECT COUNT( `content_id` ) FROM `" . BIT_DB_PREFIX . "liberty_content`"; $activity['site'] = $this->mDb->getOne($query); $userWeight['activity'] = $activity['user'] / $activity['site']; // here we can add some weight to various areas $custom['age'] = $gBitSystem->getConfig('stars_weight_age'); $custom['permission'] = $gBitSystem->getConfig('stars_weight_permission'); $custom['activity'] = $gBitSystem->getConfig('stars_weight_activity'); foreach ($userWeight as $type => $value) { ${$type} = 10 * $value * $custom[$type]; if (empty(${$type})) { ${$type} = 1; } } // TODO: run some tests to see if this is a good way of evaluating power of a user // ensure that we always have a positive number here to avoid chaos - this also makes sure new users have at least a bit of a say if (($ret = round(log($age * $permission * $activity, 2))) < 1) { $ret = 1; } } else { $ret = 1; } return $ret; }