sensitiveword.ctrl.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->model('setting');
  8. $dos = array('display', 'add', 'delete');
  9. $do = in_array($_GPC['do'], $dos)? $do : 'display';
  10. $words_list = setting_load('sensitive_words');
  11. $words_list = !empty($words_list['sensitive_words']) ? $words_list['sensitive_words'] : array();
  12. if ($do == 'display') {
  13. $keyword = trim($_GPC['keyword']);
  14. $lists = $words_list;
  15. if (!empty($keyword)) {
  16. $lists = array();
  17. foreach ($words_list as $word) {
  18. if (strexists($word, $keyword)) {
  19. $lists[] = $word;
  20. }
  21. }
  22. }
  23. }
  24. if ($do == 'add') {
  25. $add_word = trim($_GPC['word']);
  26. if (empty($add_word)) {
  27. iajax(-1, '敏感词不能为空', url('system/sensitiveword'));
  28. }
  29. $add_word_array = explode("\n", $add_word);
  30. foreach ($add_word_array as &$word) {
  31. $word = safe_gpc_string(trim($word));
  32. }
  33. $words_list = array_merge($words_list, $add_word_array);
  34. $word_add = setting_save(array_unique($words_list), 'sensitive_words');
  35. if (is_error($words_add)) {
  36. iajax(-1, '添加失败', url('system/sensitiveword'));
  37. }
  38. iajax(0, '添加成功', url('system/sensitiveword'));
  39. }
  40. if ($do == 'delete') {
  41. $del_word = safe_gpc_string($_GPC['word']);
  42. if (empty($del_word)) {
  43. iajax(-1, '不能为空');
  44. }
  45. $del_word_index = array_search($del_word, $words_list);
  46. if ($del_word_index === false) {
  47. iajax(-1, '敏感词不存在');
  48. }
  49. unset($words_list[$del_word_index]);
  50. $update = setting_save($words_list, 'sensitive_words');
  51. iajax(0, '删除成功', url('system/sensitiveword'));
  52. }
  53. template('system/sensitive-word');