forked from cashgithubs/Project
/
banword.php
executable file
·113 lines (105 loc) · 2.45 KB
/
banword.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/***************************************************************************
* LivSNS 0.1
* (C)2004-2010 HOGE Software.
*
* $Id: banword.php 39453 2014-08-16 02:24:18Z hanwenbin $
***************************************************************************/
require_once './global.php';
require_once CUR_CONF_PATH . 'lib/banword.class.php';
define('MOD_UNIQUEID', 'banword'); //模块标识
class banwordApi extends xsFrm
{
private $banword;
public function __construct()
{
parent::__construct();
$this->banword = new banwordClass();
}
public function __destruct()
{
parent::__destruct();
unset($this->banword);
}
/**
* 检测是否有屏蔽字操作
*/
public function exists()
{
$content = trim(urldecode($this->input['banword']));
if (empty($content)) $this->errorOutput(OBJECT_NULL);
$data = $this->banword($content);
$this->addItem($data);
$this->output();
}
/**
* 替换屏蔽字
*/
public function replace()
{
$content = trim(urldecode($this->input['banword']));
$symbol = trim(urldecode($this->input['symbol']));
if (empty($content))
{
$this->errorOutput(OBJECT_NULL);
}
$data = $this->banword($content);
if ($data)
{
$replace = array();
$find = array();
foreach ($data as $v)
{
if (!empty($symbol) && $symbol != '*')
{
$replace[] = $symbol;
}else {
if (!empty($v['banwd']))
{
$replace[] = $v['banwd'];
}else {
$replace[] = str_repeat('*', mb_strlen($v['banname'], 'utf-8'));
}
}
$find[] = $v['banname'];
}
$content = str_replace($find, $replace, $content);
}
$this->addItem($content);
$this->output();
}
/**
* 获取处理数据中存在的屏蔽字
* @param String $content
*/
private function banword($content)
{
$conResult = $this->xs_getResult($content);
if (is_array($conResult) && !empty($conResult))
{
$where = array();
foreach ($conResult as $v)
{
$where[] = 'banname = "' . $v['word'] . '"';
}
$where = implode(' OR ', $where);
$where = ' AND (' . $where . ')';
return $this->banword->show(0, -1, $where);
}
}
/**
* 方法不存在的时候调用的方法
*/
public function none()
{
$this->errorOutput('调用的方法不存在');
}
}
$out = new banwordApi();
$action = $_INPUT['a'];
if (!method_exists($out, $action))
{
$action = 'none';
}
$out->$action();
?>