4 * REJECT 'ONLY ASCII' COMMENT AND TRACKBACK PLUGIN FOR NucleusCMS
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * (see nucleus/documentation/index.html#license for more info)
15 * @copyright 2006-2007 shizuki
16 * @license http://www.gnu.org/licenses/gpl.txt
17 * GNU GENERAL PUBLIC LICENSE Version 2, June 1991
19 * @link http://shizuki.kinezumi.net
22 * 0.2 supports SpamCheck API 2
23 * supports NP_TrackBack
28 class NP_RejectASCIIComment extends NucleusPlugin
34 $retData = 'Reject ASCII Comment and TrackBack';
45 // an URL to the plugin website
48 $retData = 'http://shizuki.kinezumi.net';
52 // version of the plugin
59 // a description to be shown on the installed plugins listing
60 function getDescription()
62 $retData = _REJECT_ASCII_DESCRIPTION;
63 if (_CHARSET != 'UTF-8') {
64 mb_convert_encoding($retData, _CHARSET, 'UTF-8');
69 function getEventList()
79 $optionData = _REJECT_ASCII_HOOK;
80 if (_CHARSET != 'UTF-8') {
81 mb_convert_encoding($optionData, _CHARSET, 'UTF-8');
83 $this->createBlogOption('hook', $optionData, 'yesno', 'no');
84 $optionData = _REJECT_ASCII_DELTB;
85 if (_CHARSET != 'UTF-8') {
86 mb_convert_encoding($optionData, _CHARSET, 'UTF-8');
88 $this->createBlogOption('deltb', $optionData, 'yesno', 'no');
91 function supportsFeature ($what)
95 case 'SqlTablePrefix':
105 $langFile = $this->getDirectory() . 'japanese.php';
106 if (file_exists($langFile)) {
107 include_once($langFile);
111 function event_SpamCheck(&$data)
113 global $DIR_PLUGINS, $member;
115 $spamCheck = $data['spamcheck'];
116 if ($spamCheck['result'] == TRUE) {
120 if ($member->isLoggedIn()) {
124 $type = (!empty($spamCheck['type'])) ? $spamCheck['type'] : 'post';
125 $encoding = $this->_detect_encoding($excerpt);
128 $checkData = $spamCheck['body'];
129 $item_id = intval($spamCheck['id']);
132 $checkData = $spamCheck['excerpt'] . $spamCheck['title'] . $spamCheck['blogname'];
133 $item_id = intval($spamCheck['id']);
137 $bid = intval(getBlogIDFromItemID($item_id));
138 $bname = getBlogNameFromID($bid);
139 $inque = 'SELECT ititle as result FROM %s WHERE inumber = %d';
140 $inque = sprintf($inque, sql_table('item'), $item_id);
141 $iname = quickQuery($inque);
142 $checkData = str_replace($bname, '', $checkData);
143 $checkData = str_replace($iname, '', $checkData);
144 $checkData = ereg_replace("\r|\n","",$checkData);
145 $checkData = mb_convert_encoding($checkData, 'UTF-8', $encoding);
146 if ($checkData && !preg_match('/[\x80-\xff]/', $checkData)) {
148 'comment' => _REJECT_ASCII_COMMENT,
149 'trackback' => _REJECT_ASCII_TRACKBACK,
151 $info = _REJECT_ASCII_INFOHEAD . $item_id . $checkType[$type];
152 if (_CHARSET != 'UTF-8') {
153 mb_convert_encoding($info, _CHARSET, 'UTF-8');
155 // ACTIONLOG :: add(INFO, 'RejectASCII: ' . $info . shorten(strip_tags($checkData), 50, '...') . ')');
156 $data['spamcheck']['result'] = TRUE;
157 if ($type == 'trackback' && $this->getBlogOption($bid, 'deltb') == 'yes') {
158 header("Location: " . createItemLink($item_id));
167 function event_ValidateForm(&$data) {
168 global $DIR_PLUGINS, $member;
169 if (getNucleusVersion() >= '330' || $data['type'] != 'comment') {
172 $item_id = intval($data['comment']['itemid']);
173 $blog_id = intval(getBlogIDFromItemID($item_id));
175 if ($this->getBlogOption($blog_id, 'hook') == 'no') {
179 if ($member->isLoggedIn()) {
186 'user' => $data['comment']['user'],
187 'body' => $data['comment']['body'],
191 'spamcheck' => &$spamcheck
193 $this->event_SpamCheck($param);
195 if (isset($spamcheck['result']) && $spamcheck['result'] == TRUE) {
197 header("Location: " . createItemLink($item_id));
204 function _detect_encoding($string)
206 if (preg_match("/;\s*charset=([^\n]+)/is", serverVar("CONTENT_TYPE"), $regs)) {
207 $encoding = strtoupper(trim($regs[1]));
211 $mbstrInput = strtolower(ini_get("mbstring.http_input"));
212 if (!empty($encoding) && (mb_http_input('P') == '' || $mbstrInput == 'pass')) {
215 if (_CHARSET == 'UTF-8') {
216 $encChars = 'UTF-8,EUC-JP,SJIS,ISO-8859-1,ASCII,JIS';
218 $encChars = 'EUC-JP,UTF-8,SJIS,ISO-8859-1,ASCII,JIS';
220 $encoding = mb_detect_encoding($string, $encChars);
222 return ($encoding) ? $encoding : 'ISO-8859-1';