badword.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. [UCenter] (C)2001-2099 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: badword.php 1059 2011-03-01 07:25:09Z monkey $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. class badwordmodel {
  9. var $db;
  10. var $base;
  11. function __construct(&$base) {
  12. $this->badwordmodel($base);
  13. }
  14. function badwordmodel(&$base) {
  15. $this->base = $base;
  16. $this->db = $base->db;
  17. }
  18. function add_badword($find, $replacement, $admin, $type = 1) {
  19. if($find) {
  20. $find = trim($find);
  21. $replacement = trim($replacement);
  22. $findpattern = $this->pattern_find($find);
  23. if($type == 1) {
  24. $this->db->query("REPLACE INTO ".UC_DBTABLEPRE."badwords SET find='$find', replacement='$replacement', admin='$admin', findpattern='$findpattern'");
  25. } elseif($type == 2) {
  26. $this->db->query("INSERT INTO ".UC_DBTABLEPRE."badwords SET find='$find', replacement='$replacement', admin='$admin', findpattern='$findpattern'", 'SILENT');
  27. }
  28. }
  29. return $this->db->insert_id();
  30. }
  31. function get_total_num() {
  32. $data = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."badwords");
  33. return $data;
  34. }
  35. function get_list($page, $ppp, $totalnum) {
  36. $start = $this->base->page_get_start($page, $ppp, $totalnum);
  37. $data = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."badwords LIMIT $start, $ppp");
  38. return $data;
  39. }
  40. function delete_badword($arr) {
  41. $badwordids = $this->base->implode($arr);
  42. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."badwords WHERE id IN ($badwordids)");
  43. return $this->db->affected_rows();
  44. }
  45. function truncate_badword() {
  46. $this->db->query("TRUNCATE ".UC_DBTABLEPRE."badwords");
  47. }
  48. function update_badword($find, $replacement, $id) {
  49. $findpattern = $this->pattern_find($find);
  50. $this->db->query("UPDATE ".UC_DBTABLEPRE."badwords SET find='$find', replacement='$replacement', findpattern='$findpattern' WHERE id='$id'");
  51. return $this->db->affected_rows();
  52. }
  53. function pattern_find($find) {
  54. $find = preg_quote($find, "/'");
  55. $find = str_replace("\\", "\\\\", $find);
  56. $find = str_replace("'", "\\'", $find);
  57. return '/'.preg_replace("/\\\{(\d+)\\\}/", ".{0,\\1}", $find).'/is';
  58. }
  59. }
  60. ?>