1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class UserLimitPlugin extends Plugin
- {
- const PLUGIN_VERSION = '2.0.0';
- public $maxUsers = null;
- public function onStartUserRegister(Profile $profile)
- {
- $this->_checkMaxUsers();
- return true;
- }
- function onStartRegistrationTry($action)
- {
- $this->_checkMaxUsers();
- return true;
- }
- function _checkMaxUsers()
- {
- if (!is_null($this->maxUsers)) {
- $cls = new User();
- $cnt = $cls->count();
- if ($cnt >= $this->maxUsers) {
-
-
- $msg = sprintf(_m('Cannot register because the maximum number of users (%d) for this site was reached.',
- 'Cannot register because the maximum number of users (%d) for this site was reached.',
- $this->maxUsers),
- $this->maxUsers);
- throw new ClientException($msg);
- }
- }
- }
- function onPluginVersion(array &$versions)
- {
- $versions[] = array('name' => 'UserLimit',
- 'version' => self::PLUGIN_VERSION,
- 'author' => 'Evan Prodromou',
- 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/UserLimit',
- 'description' =>
-
- _m('Limit the number of users who can register.'));
- return true;
- }
- }
|