1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: /**
13: * Protector
14: *
15: * @copyright XOOPS Project (http://xoops.org)
16: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
17: * @package protector
18: * @author trabis <lusopoemas@gmail.com>
19: * @version $Id$
20: */
21:
22: // Don't enable this for site using single-byte
23: // Perhaps, japanese, schinese, tchinese, and korean can use it
24:
25: class protector_postcommon_post_need_multibyte extends ProtectorFilterAbstract
26: {
27: function execute()
28: {
29: $xoops = Xoops::getInstance();
30:
31: if (!function_exists('mb_strlen')) {
32: return true;
33: }
34:
35: // registered users always pass this plugin
36: if ($xoops->isUser()) {
37: return true;
38: }
39:
40: $lengths = array(
41: 0 => 100, // default value
42: 'message' => 2,
43: 'com_text' => 2,
44: 'excerpt' => 2,
45: );
46:
47: foreach ($_POST as $key => $data) {
48: // dare to ignore arrays/objects
49: if (!is_string($data)) {
50: continue;
51: }
52:
53: $check_length = isset($lengths[$key]) ? $lengths[$key] : $lengths[0];
54: if (strlen($data) > $check_length) {
55: if (strlen($data) == mb_strlen($data)) {
56: $this->protector->message .= "No multibyte character was found ($data)\n";
57: $this->protector->output_log('Singlebyte SPAM', 0, false, 128);
58: die('Protector rejects your post, because your post looks like SPAM');
59: }
60: }
61: }
62:
63: return true;
64: }
65: }
66: