PageRenderTime 56ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/controllers/admin/MemberController.php

https://bitbucket.org/likeping/lkp
PHP | 575 lines | 509 code | 16 blank | 50 comment | 109 complexity | 1232829def7026e0598b14dfd380232b MD5 | raw file
  1. <?php
  2. class MemberController extends Admin {
  3. private $mgroup;
  4. public function __construct() {
  5. parent::__construct();
  6. $this->member = $this->model('member');
  7. $this->mgroup = $this->model('member_group');
  8. $this->membergroup = $this->cache->get('membergroup');
  9. $this->membermodel = $this->cache->get('membermodel');
  10. }
  11. public function indexAction() {
  12. if ($this->post('submit') && $this->post('form')=='search') {
  13. $kw = $this->post('kw');
  14. } elseif ($this->post('submit_status_1') && $this->post('form')=='status_1') {
  15. foreach ($_POST as $var=>$value) {
  16. if (strpos($var, 'del_')!==false) {
  17. $ids = str_replace('del_', '', $var);
  18. list($_id, $_mid) = explode('_', $ids);
  19. $this->member->update(array('status'=>1), 'id=' . $_id);
  20. }
  21. }
  22. } elseif ($this->post('submit_status_0') && $this->post('form')=='status_0') {
  23. foreach ($_POST as $var=>$value) {
  24. if (strpos($var, 'del_')!==false) {
  25. $ids = str_replace('del_', '', $var);
  26. list($_id, $_mid) = explode('_', $ids);
  27. $this->member->update(array('status'=>0), 'id=' . $_id);
  28. }
  29. }
  30. }
  31. $kw = $kw ? $kw : $this->get('kw');
  32. $page = (int)$this->get('page');
  33. $page = (!$page) ? 1 : $page;
  34. $modelid = (int)$this->get('modelid');
  35. $groupid = (int)$this->get('groupid');
  36. $status = (int)$this->get('status');
  37. $pagelist = $this->instance('pagelist');
  38. $pagelist->loadconfig();
  39. $where = '1';
  40. if ($kw) $where .= " and username like '%" . $kw . "%'";
  41. if ($modelid) $where .= ' and modelid=' . $modelid;
  42. if ($groupid) $where .= ' and groupid=' . $groupid;
  43. if ($status == 1) {
  44. $where .= ' and status=1';
  45. } elseif ($status ==2) {
  46. $where .= ' and status=0';
  47. }
  48. $total = $this->member->count('member', null, $where);
  49. $pagesize = isset($this->site['SITE_ADMIN_PAGESIZE']) && $this->site['SITE_ADMIN_PAGESIZE'] ? $this->site['SITE_ADMIN_PAGESIZE'] : 8;
  50. $urlparam = array();
  51. if ($kw) $urlparam['kw'] = $kw;
  52. if ($groupid) $urlparam['groupid'] = $groupid;
  53. if ($modelid) $urlparam['modelid'] = $modelid;
  54. $urlparam['status'] = $status;
  55. $urlparam['page'] = '{page}';
  56. $url = url('admin/member/index', $urlparam);
  57. $select = $this->member->page_limit($page, $pagesize)->order(array('status ASC', 'regdate DESC', 'id DESC'));
  58. if ($kw) $select->where("username like '%" . $kw . "%'");
  59. if ($modelid) $select->where('modelid=' . $modelid);
  60. if ($groupid) $select->where('groupid = ' . $groupid);
  61. if ($status == 1) {
  62. $select->where('status=1');
  63. } elseif ($status ==2) {
  64. $select->where('status=0');
  65. }
  66. $data = $select->select();
  67. $pagelist = $pagelist->total($total)->url($url)->num($pagesize)->page($page)->output();
  68. $count = array();
  69. $count[0] = $this->member->count('member', null, '1');
  70. $count[1] = $this->member->count('member', null, 'status=1');
  71. $count[2] = $this->member->count('member', null, 'status=0');
  72. $count[$status] = $total;
  73. $this->view->assign(array(
  74. 'membermodel' => $this->membermodel,
  75. 'membergroup' => $this->membergroup,
  76. 'list' => $data,
  77. 'kw' => $kw,
  78. 'page' => $page,
  79. 'pagelist' => $pagelist,
  80. 'status' => $status,
  81. 'count' => $count,
  82. ));
  83. $this->view->display('admin/member_list');
  84. }
  85. /*
  86. * 用户组
  87. */
  88. public function groupAction() {
  89. $type = $this->get('type');
  90. switch ($type) {
  91. case 'add':
  92. if ($this->isPostForm()) {
  93. $data = $this->post('data');
  94. if (empty($data['name'])) $this->adminMsg(lang('a-mem-1'));
  95. $this->mgroup->insert($data);
  96. $this->adminMsg($this->getCacheCode('member') . lang('success'), url('admin/member/group/'), 3, 1, 1);
  97. }
  98. $this->view->display('admin/member_group_add');
  99. break;
  100. case 'edit':
  101. $id = $this->get('id');
  102. if ($this->isPostForm()) {
  103. $data = $this->post('data');
  104. if (empty($data['name'])) $this->adminMsg(lang('a-mem-1'));
  105. $this->mgroup->update($data, 'id=' . $id);
  106. $this->adminMsg($this->getCacheCode('member') . lang('success'), url('admin/member/group/'), 3, 1, 1);
  107. }
  108. $this->view->assign('data', $this->mgroup->find($id));
  109. $this->view->display('admin/member_group_add');
  110. break;
  111. case 'cache':
  112. $this->cacheAction();
  113. break;
  114. case 'delete':
  115. $id = $this->get('id');
  116. $this->mgroup->delete('id=' . $id);
  117. $this->adminMsg($this->getCacheCode('member') . lang('success'), url('admin/member/group/'), 3, 1, 1);
  118. break;
  119. default:
  120. if ($this->post('submit_order') && $this->post('form')=='order') {
  121. foreach ($_POST as $var=>$value) {
  122. if (strpos($var, 'order_')!==false) {
  123. $id = (int)str_replace('order_', '', $var);
  124. $this->mgroup->update(array('listorder'=>$value), 'id=' . $id);
  125. }
  126. }
  127. $this->cacheAction(1);
  128. } elseif ($this->post('submit_del') && $this->post('form')=='del') {
  129. foreach ($_POST as $var=>$value) {
  130. if (strpos($var, 'del_')!==false) {
  131. $id = (int)str_replace('del_', '', $var);
  132. $this->mgroup->delete('id=' . $id);
  133. }
  134. }
  135. $this->cacheAction(1);
  136. }
  137. $page = (int)$this->get('page');
  138. $page = (!$page) ? 1 : $page;
  139. $pagelist = $this->instance('pagelist');
  140. $pagelist->loadconfig();
  141. $total = $this->mgroup->count('member_group');
  142. $pagesize = isset($this->site['SITE_ADMIN_PAGESIZE']) && $this->site['SITE_ADMIN_PAGESIZE'] ? $this->site['SITE_ADMIN_PAGESIZE'] : 8;
  143. $url = url('admin/member/group', array('page'=>'{page}'));
  144. $select = $this->mgroup->page_limit($page, $pagesize)->order(array('listorder ASC', 'id DESC'));
  145. $data = $select->select();
  146. $pagelist = $pagelist->total($total)->url($url)->num($pagesize)->page($page)->output();
  147. $this->view->assign(array(
  148. 'list' => $data,
  149. 'pagelist' => $pagelist,
  150. ));
  151. $this->view->display('admin/member_group_list');
  152. }
  153. }
  154. /*
  155. * 配置信息
  156. */
  157. public function configAction() {
  158. $type = $this->get('type') ? $this->get('type') : 'reg';
  159. $member = $this->cache->get('member');
  160. if ($this->post('submit')) {
  161. $data = $this->post('data');
  162. $oauth = $this->post('oauth');
  163. if ($data['uc_use']) {
  164. $m = self::load_config('database');
  165. $s = '<?php ' . PHP_EOL . '/* UCenter配置 */' . PHP_EOL
  166. . stripslashes($data['uc_config'])
  167. . PHP_EOL . '/* FineCMS配置 */' . PHP_EOL
  168. . '$dbhost = \'' . $m['host'] . ':' . $m['port'] . '\';' . PHP_EOL
  169. . '$dbuser = \'' . $m['username'] . '\';' . PHP_EOL
  170. . '$dbpw = \'' . $m['password'] . '\';' . PHP_EOL
  171. . '$dbname = \'' . $m['dbname'] . '\';' . PHP_EOL
  172. . '$pconnect = 0;' . PHP_EOL
  173. . '$tablepre = \'' . $m['prefix'] . '\';' . PHP_EOL
  174. . '$dbcharset = \'' . $m['charset'] . '\';' . PHP_EOL
  175. . '/* 同步登录Cookie */' . PHP_EOL
  176. . '$cookiedomain = \'\';' . PHP_EOL
  177. . '$cookiepath = \'/\';' . PHP_EOL
  178. . '$cookiepre = \'' . SYS_VAR_PREX . '\';' . PHP_EOL
  179. . '$cookiecode = \'' . SITE_MEMBER_COOKIE . '\';' . PHP_EOL
  180. . '?>';
  181. $file = EXTENSION_DIR . 'ucenter' . DIRECTORY_SEPARATOR . 'config.inc.php';
  182. if (!file_put_contents($file, $s)) $this->adminMsg(lang('a-mem-2', array('1'=>$file)));
  183. }
  184. $this->cache->set('member', array_merge($data, array('oauth'=>$oauth)));
  185. $this->adminMsg(lang('success'), url('admin/member/config', array('type'=>$type)), 3, 1, 1);
  186. }
  187. $this->view->assign(array(
  188. 'string' => $string,
  189. 'data' => $member,
  190. 'type' => $type,
  191. 'membermodel' => $this->membermodel,
  192. 'membergroup' => $this->membergroup,
  193. ));
  194. $this->view->display('admin/member_config');
  195. }
  196. /*
  197. * 修改资料
  198. */
  199. public function editAction() {
  200. $id = (int)$this->get('id');
  201. $member = $this->member->find($id);
  202. if (empty($member)) $this->adminMsg(lang('a-mem-3'));
  203. $model = $this->membermodel[$member['modelid']];
  204. if (empty($model)) $this->adminMsg(lang('a-mem-4'));
  205. $info = $this->model($model['tablename']);
  206. $_data = $info->find($id);
  207. if ($this->isPostForm()) {
  208. $data = $this->post('data');
  209. if ($this->post('password')) $data['password'] = md5(md5($this->post('password')) . $member['salt'] . md5($this->post('password')));
  210. foreach ($data as $i=>$t) {
  211. if (is_array($t)) $data[$i] = array2string($t);
  212. }
  213. $this->member->update($data, 'id=' . $id);
  214. if ($_data) {
  215. $info->update($data, 'id=' . $id); //修改附表内容
  216. } else {
  217. $data['id'] = $id;
  218. $info->insert($data); //新增附表内容
  219. }
  220. $this->adminMsg(lang('success'), url('admin/member/edit', array('id'=>$id)), 3, 1, 1);
  221. }
  222. $fields = $this->membermodel[$member['modelid']]['fields'];
  223. $data_fields = $this->getFields($fields, $_data);
  224. $count = array();
  225. $count[0] = $this->member->count('member', null, '1');
  226. $count[1] = $this->member->count('member', null, 'status=1');
  227. $count[2] = $this->member->count('member', null, 'status=0');
  228. $oauth = $this->model('oauth');
  229. $odata = $oauth->where('username=?', $member['username'])->select();
  230. $this->view->assign(array(
  231. 'data' => $member,
  232. 'model' => $model,
  233. 'group' => $this->membergroup,
  234. 'info' => $_data,
  235. 'count' => $count,
  236. 'id' => $id,
  237. 'oauth' => $odata,
  238. 'data_fields' => $data_fields,
  239. ));
  240. $this->view->display('admin/member_edit');
  241. }
  242. /*
  243. * 注册会员
  244. */
  245. public function regAction() {
  246. if ($this->isPostForm()) {
  247. $addall = $this->post('addall');
  248. $modelid = $this->post('modelid');
  249. if (!$modelid) $this->adminMsg(lang('a-mem-5'));
  250. if ($addall) {
  251. //批量
  252. $data = $this->post('members');
  253. if (empty($data)) $this->adminMsg(lang('a-mem-6'));
  254. $data = explode(chr(13), $data);
  255. $y = $n = 0;
  256. foreach ($data as $val) {
  257. list($username, $password, $email) = explode(' ', $val);
  258. $username = trim($username);
  259. $password = trim($password);
  260. $email = trim($email);
  261. if (empty($username) || empty($password) || empty($email)) {
  262. $n ++;
  263. } elseif (!$this->is_username($username)) {
  264. $n ++;
  265. } elseif (!check::is_email($email)) {
  266. $n ++;
  267. } else {
  268. $row1 = $this->member->getOne('username=?', $username, 'id');
  269. $row2 = $this->member->getOne('email=?', $email, 'id');
  270. if (empty($row1) && empty($row2)) {
  271. $salt = substr(md5(rand(0, 999)), 0, 10);
  272. $insert = array(
  273. 'modelid' => $modelid,
  274. 'username' => $username,
  275. 'password' => md5(md5($password) . $salt . md5($password)),
  276. 'email' => $email,
  277. 'status' => $_POST['data']['status'],
  278. 'groupid' => 1,
  279. 'regdate' => time(),
  280. 'regip' => client::get_user_ip(),
  281. 'salt' => $salt,
  282. );
  283. if ($this->member->insert($insert)) {
  284. $y ++;
  285. } else {
  286. $n ++;
  287. }
  288. } else {
  289. $n ++;
  290. }
  291. }
  292. }
  293. $this->adminMsg(lang('a-mem-7', array('1'=>$y, '2'=>$n)), url('admin/member/index'), 3, 1, 1);
  294. } else {
  295. //注册
  296. $data = $this->post('data');
  297. if (empty($data['username']) || empty($data['password']) || empty($data['email'])) $this->adminMsg(lang('a-mem-8'));
  298. if (!$this->is_username($data['username'])) $this->adminMsg(lang('a-mem-9'));
  299. if (!check::is_email($data['email'])) $this->adminMsg(lang('a-mem-10'));
  300. $row = $this->member->getOne('username=?', $data['username'], 'id');
  301. if ($row) $this->adminMsg(lang('a-mem-11'));
  302. $row = $this->member->getOne('email=?', $data['email'], 'id');
  303. if ($row) $this->adminMsg(lang('a-mem-12'));
  304. $salt = substr(md5(rand(0, 999)), 0, 10);
  305. $insert = array(
  306. 'modelid' => $modelid,
  307. 'username' => $data['username'],
  308. 'password' => md5(md5($data['password']) . $salt . md5($data['password'])),
  309. 'email' => $data['email'],
  310. 'status' => $data['status'],
  311. 'groupid' => 1,
  312. 'regdate' => time(),
  313. 'regip' => client::get_user_ip(),
  314. 'salt' => $salt,
  315. );
  316. if ($this->member->insert($insert)) {
  317. $this->adminMsg(lang('success'), url('admin/member'), 3, 1, 1);
  318. } else {
  319. $this->adminMsg(lang('a-mem-13'));
  320. }
  321. }
  322. }
  323. $count = array();
  324. $count[0] = $this->member->count('member', null, '1');
  325. $count[1] = $this->member->count('member', null, 'status=1');
  326. $count[2] = $this->member->count('member', null, 'status=0');
  327. if ($this->memberconfig['uc_use'] == 1) {
  328. include EXTENSION_DIR . 'ucenter' . DIRECTORY_SEPARATOR . 'config.inc.php';
  329. }
  330. $this->view->assign(array(
  331. 'model' => $this->membermodel,
  332. 'count' => $count,
  333. 'uc' => $this->memberconfig['uc_use'],
  334. ));
  335. $this->view->display('admin/member_reg');
  336. }
  337. /*
  338. * 短消息
  339. */
  340. public function pmsAction() {
  341. $type = $this->get('type');
  342. $memberpms = $this->model('member_pms');
  343. switch ($type) {
  344. case 'show';
  345. $id = $this->get('id');
  346. if ($this->isPostForm()) {
  347. if ($id) $memberpms->delete('id=' . $id);
  348. $this->adminMsg(lang('success'), url('admin/member/pms'));
  349. }
  350. if (empty($id)) $this->adminMsg(lang('a-mem-14'));
  351. $data = $memberpms->find($id);
  352. if (empty($data)) $this->adminMsg(lang('a-mem-15'));
  353. $this->view->assign(array(
  354. 'model' => $this->membermodel,
  355. 'group' => $this->membergroup,
  356. 'data' => $data,
  357. ));
  358. $this->view->display('admin/member_pms_show');
  359. break;
  360. case 'send':
  361. if ($this->isPostForm()) {
  362. $type = $this->post('type');
  363. $data = $this->post('data');
  364. if (empty($type)) $this->adminMsg(lang('a-mem-16'));
  365. if (empty($data['title']) || empty($data['content'])) $this->adminMsg(lang('a-mem-17'));
  366. $data['sendname'] = $this->userinfo['username'];
  367. $data['sendid'] = $this->userinfo['userid'];
  368. $data['sendtime'] = time();
  369. $data['isadmin'] = 1;
  370. $sendtotal = 0;
  371. if ($type == 1) {
  372. //群发
  373. if (empty($data['modelid'])) $this->adminMsg(lang('a-mem-18'));
  374. $where = 'modelid=' . $data['modelid'];
  375. if ($data['groupid']) $where .= ' AND groupid=' . $data['groupid'];
  376. $list = $this->member->from(null, 'id,username')->where($where)->select();
  377. foreach ($list as $row) {
  378. $data['toid'] = $row['id'];
  379. $data['toname'] = $row['username'];
  380. if ($memberpms->insert($data)) $sendtotal ++;
  381. }
  382. } elseif ($type == 2) {
  383. //个人
  384. unset($data['togroupid'], $data['tomodelid']);
  385. if (empty($data['tonames'])) $this->adminMsg(lang('a-mem-19'));
  386. $users = explode(',', $data['tonames']);
  387. foreach ($users as $user) {
  388. $row = $this->member->from(null, 'id')->where('username=?', $user)->select(false);
  389. if ($row) {
  390. $data['toid'] = $row['id'];
  391. $data['toname'] = $user;
  392. if ($memberpms->insert($data)) $sendtotal ++;
  393. }
  394. }
  395. }
  396. $this->adminMsg(lang('a-mem-20') . '(' . $sendtotal . ')', url('admin/member/pms'), 3, 1, 1);
  397. }
  398. $this->view->assign(array(
  399. 'model' => $this->membermodel,
  400. 'group' => $this->membergroup,
  401. ));
  402. $this->view->display('admin/member_pms_send');
  403. break;
  404. default:
  405. if ($this->isPostForm()) {
  406. $ids = $this->post('ids');
  407. $ids = implode(',', $ids);
  408. if ($ids) $memberpms->delete('id IN(' . $ids . ')');
  409. }
  410. $page = (int)$this->get('page');
  411. $page = (!$page) ? 1 : $page;
  412. $pagelist = $this->instance('pagelist');
  413. $pagelist->loadconfig();
  414. $where = null;
  415. if ($this->get('toid')) $where = 'toid=' . $this->get('toid');
  416. $total = $memberpms->count('member_pms', 'id', $where);
  417. $pagesize = isset($this->site['SITE_ADMIN_PAGESIZE']) && $this->site['SITE_ADMIN_PAGESIZE'] ? $this->site['SITE_ADMIN_PAGESIZE'] : 8;
  418. $url = url('admin/member/pms', array('page'=>'{page}'));
  419. if ($this->get('toid')) $url = url('admin/member/pms', array('toid'=>$this->get('toid'), 'page'=>'{page}'));
  420. $select = $memberpms->page_limit($page, $pagesize)->order(array('sendtime DESC'));
  421. if ($this->get('toid')) $select->where('toid=' . $this->get('toid'));
  422. $data = $select->select();
  423. $pagelist = $pagelist->total($total)->url($url)->num($pagesize)->page($page)->output();
  424. $this->view->assign(array(
  425. 'list' => $data,
  426. 'pagelist' => $pagelist,
  427. 'model' => $this->membermodel,
  428. 'group' => $this->membergroup,
  429. ));
  430. $this->view->display('admin/member_pms_list');
  431. break;
  432. }
  433. }
  434. /**
  435. * 删除会员
  436. */
  437. public function delAction() {
  438. $id = $this->get('id');
  439. if (empty($id)) $this->adminMsg(lang('a-mem-14'));
  440. $data = $this->member->find($id);
  441. if (empty($data)) $this->adminMsg(lang('a-mem-3'));
  442. $content = $this->model('content');
  443. $modelist = $this->member->from('model')->where('typeid=1')->select();
  444. //删除内容表信息
  445. $list = $content->from(null, 'id,catid')->where('sysadd=0 and userid=' . $id)->select();
  446. foreach ($list as $t) {
  447. $content->del($t['id'], $t['catid']);
  448. }
  449. //删除会员
  450. $this->member->delete('id=' . $id);
  451. //删除模型数据
  452. $table = $this->membermodel[$data['modelid']]['tablename'];
  453. if ($table) {
  454. $model = $this->model($table);
  455. $model->delete('id=' . $id);
  456. }
  457. //删除会员统计表
  458. $count = $this->model('member_count');
  459. $count->delete('id=' . $id);
  460. //删除一键登录
  461. $oauth = $this->model('oauth');
  462. $oauth->delete('username=?', $data['username']);
  463. //删除短消息
  464. $pms = $this->model('member_pms');
  465. $pms->delete("sendid=" . $id . " AND sendname='" . $data['username'] . "'");
  466. //删除收藏夹
  467. $favorite = $this->model('favorite');
  468. $favorite->delete('userid=' . $id);
  469. //删除支付插件
  470. if (plugin('pay')) {
  471. $pay = $this->plugin_model('pay', 'pay_data');
  472. $pay->delete('userid=' . $id);
  473. }
  474. //删除关联表单
  475. $form = $this->cache->get('formmodel');
  476. if ($form) {
  477. foreach ($form as $m) {
  478. $db = $this->model($m['tablename']);
  479. $db->delete('userid=' . $id);
  480. }
  481. }
  482. //删除会员附件目录
  483. $path = 'uploadfiles/member/' . $id . '/';
  484. if (file_exists($path)) $this->delDir($path);
  485. $this->adminMsg(lang('success'), url('admin/member'), 3, 1, 1);
  486. }
  487. /**
  488. * 会员组缓存
  489. */
  490. public function cacheAction($show=0) {
  491. $data = $this->mgroup->order(array('listorder ASC', 'id DESC'))->select();
  492. $cache = array();
  493. foreach ($data as $t) {
  494. $cache[$t[id]] = $t;
  495. }
  496. $this->cache->set('membergroup', $cache);
  497. $show or $this->adminMsg(lang('a-update'), url('admin/member/group/'), 3, 1, 1);
  498. }
  499. /*
  500. * 连接测试
  501. */
  502. public function testAction() {
  503. $host = isset($_GET['host']) && trim($_GET['host']) ? trim($_GET['host']) : exit('0');
  504. $username = isset($_GET['username']) && trim($_GET['username']) ? trim($_GET['username']) : exit('0');
  505. if (@mysql_connect($host, $username, $password)) {
  506. exit('1');
  507. } else {
  508. exit('0');
  509. }
  510. }
  511. /**
  512. * Email是否重复检查
  513. */
  514. public function ajaxemailAction() {
  515. $email = $this->post('email');
  516. if (!check::is_email($email)) exit('<b><font color=red>' . lang('a-mem-21') . '</font></b>');
  517. $id = $this->post('id');
  518. if (empty($email)) exit('<b><font color=red>' . lang('a-mem-22') . '</font></b>');
  519. $where = $id ? "email='" . $email . "' and id<>" . $id : "email='" . $email . "'";
  520. $data = $this->member->getOne($where);
  521. if ($data) exit('<b><font color=red>' . lang('a-mem-23') . '</font></b>');
  522. exit('<b><font color=green>√</font></b>');
  523. }
  524. /**
  525. * username是否重复检查
  526. */
  527. public function ajaxusernameAction() {
  528. $name = $this->post('username');
  529. if (!$this->is_username($name)) exit('<b><font color=red>' . lang('a-mem-24') . '</font></b>');
  530. if (empty($name)) exit('<b><font color=red>' . lang('a-mem-25') . '</font></b>');
  531. $data = $this->member->getOne('username=?', $name, 'id');
  532. if ($data) exit('<b><font color=red>' . lang('a-mem-11') . '</font></b>');
  533. exit('<b><font color=green>√</font></b>');
  534. }
  535. /**
  536. * 检查会员名是否符合规定
  537. */
  538. private function is_username($username) {
  539. $strlen = strlen($username);
  540. if(!preg_match('/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/', $username)){
  541. return false;
  542. } elseif ( 20 < $strlen || $strlen < 2 ) {
  543. return false;
  544. }
  545. return true;
  546. }
  547. /**
  548. * 补填空格
  549. */
  550. private function setspace($var) {
  551. $len = strlen($var) + 2;
  552. $cha = 25 - $len;
  553. $str = '';
  554. for ($i = 0; $i < $cha; $i ++) {
  555. $str .= ' ';
  556. }
  557. return $str;
  558. }
  559. }