Пример #1
0
 function postFilter()
 {
     // $_SERVER['REQUEST_URI'] から hyp_preload 固有のキーを削除
     (isset($_GET[$this->encodehint_name]) || isset($_GET[$this->post_spam_trap])) && ($_SERVER['REQUEST_URI'] = preg_replace('/&?(' . $this->encodehint_name . '|' . $this->post_spam_trap . ')=[^&]*/', '', $_SERVER['REQUEST_URI'])) && ($_SERVER['REQUEST_URI'] = str_replace('?&', '?', $_SERVER['REQUEST_URI'])) && ($_SERVER['REQUEST_URI'] = rtrim($_SERVER['REQUEST_URI'], "?"));
     // <xoops_dhtmltarea editor=bbcode>
     if (XPWIKI_RENDERER_USE_WIKIHELPER_BBCODE && defined('LEGACY_BASE_VERSION') && version_compare(LEGACY_BASE_VERSION, '2.2', '>=')) {
         if (!$this->mRoot->mContext->mUser->isInRole('Site.Administrator') || strpos($_SERVER['REQUEST_URI'], 'action=CustomBlockEdit') === false && strpos($_SERVER['REQUEST_URI'], '__CustomBlocks__&op=edit') === false) {
             if (defined('XCUBE_DELEGATE_CHAIN_BREAK')) {
                 $this->mRoot->mDelegateManager->add('Site.TextareaEditor.BBCode.Show', array(&$this, 'BBCode_wiki_render'), XCUBE_DELEGATE_PRIORITY_FIRST);
                 $this->mRoot->mDelegateManager->add('Site.TextareaEditor.BBCode.Show', array(&$this, 'BBCode_add_switch'), XCUBE_DELEGATE_PRIORITY_FINAL + 10);
             } else {
                 $this->mRoot->mDelegateManager->reset('Site.TextareaEditor.BBCode.Show');
                 $this->mRoot->mDelegateManager->add('Site.TextareaEditor.BBCode.Show', array(&$this, 'BBCode_wiki_render'));
             }
         }
     }
     if (defined('HYP_COMMON_SKIP_POST_FILTER')) {
         return;
     }
     // Set mb_detect_order
     if ($this->detect_order) {
         mb_detect_order($this->detect_order);
     }
     // For WizMobile
     if (XC_CLASS_EXISTS('WizMobile')) {
         define('HYP_WIZMOBILE_USE', true);
     }
     // XOOPS の表示文字エンコーディング
     $this->encode = strtoupper(_CHARSET);
     // 設定ファイルのエンコーディングを検査
     if ($this->encode !== 'UTF-8' && $this->encode !== strtoupper($this->configEncoding)) {
         $this->encodehint_word = '';
     }
     if (!$this->wizMobileUse && !empty($_GET)) {
         // 文字コードを正規化
         $enchint = isset($_GET[$this->encodehint_name]) ? $_GET[$this->encodehint_name] : (isset($_GET['encode_hint']) ? $_GET['encode_hint'] : '');
         if ($enchint && function_exists('mb_detect_encoding')) {
             define('HYP_GET_ENCODING', strtoupper(mb_detect_encoding($enchint)));
             $_GET = HypCommonFunc::input_filter($_GET, $this->input_filter_strength, HYP_GET_ENCODING);
             if (HYP_GET_ENCODING !== $this->encode) {
                 mb_convert_variables($this->encode === 'EUC-JP' ? 'eucJP-win' : $this->encode, HYP_GET_ENCODING === 'EUC-JP' ? 'eucJP-win' : HYP_GET_ENCODING, $_GET);
                 if (isset($_GET['charset'])) {
                     $_GET['charset'] = $this->encode;
                 }
             }
         } else {
             $_GET = HypCommonFunc::input_filter($_GET, $this->input_filter_strength);
         }
     }
     global $xoopsUser, $xoopsUserIsAdmin, $xoopsModule;
     if (is_object($xoopsModule)) {
         $this->nowModuleDirname = $xoopsModule->getVar('dirname');
     }
     // For addHeadTag()
     if (!isset($GLOBALS['hyp_preload_head_tag'])) {
         $GLOBALS['hyp_preload_head_tag'] = '';
     }
     // For CSRF Protection
     $this->csrfToken = null;
     if ($this->use_csrf_protect) {
         $this->csrfToken = md5($_SERVER['REMOTE_ADDR'] . XOOPS_DB_PASS . time());
     }
     if (!empty($_POST)) {
         // CSRF Token check
         if (!defined('DISABLE_HYP_CSRF_PROTECTION') && !empty($this->use_csrf_protect)) {
             if (empty($_POST['HypToken']) && isset($_SERVER['HTTP_X_HYPTOKEN'])) {
                 $_POST['HypToken'] = $_SERVER['HTTP_X_HYPTOKEN'];
             }
             if (empty($_POST['HypToken']) || empty($_SESSION['HYP_CSRF_TOKEN']) || $_POST['HypToken'] !== $_SESSION['HYP_CSRF_TOKEN']) {
                 @session_start();
                 $_SESSION['HYP_CSRF_TOKEN'] = $this->csrfToken;
                 $this->_rePost();
                 exit;
             }
         }
         // POST 文字列の文字エンコードを判定
         $enchint = isset($_POST[$this->encodehint_name]) ? $_POST[$this->encodehint_name] : (isset($_POST['encode_hint']) ? $_POST['encode_hint'] : '');
         if ($enchint && function_exists('mb_detect_encoding')) {
             define('HYP_POST_ENCODING', strtoupper(mb_detect_encoding($enchint)));
         } else {
             if (isset($_POST['charset'])) {
                 define('HYP_POST_ENCODING', strtoupper($_POST['charset']));
             }
         }
         // 携帯レンダーの場合絵文字変換
         if (defined('HYP_K_TAI_RENDER') && HYP_K_TAI_RENDER || isset($_SERVER['HTTP_X_ORIGINAL_USER_AGENT'])) {
             $_POST = $this->_modKtaiEmojiEncode($_POST);
         }
         // Input フィルター (remove "\0")
         $_POST = HypCommonFunc::input_filter($_POST, $this->input_filter_strength, defined('HYP_POST_ENCODING') ? HYP_POST_ENCODING : null);
         // Proxy Check
         if ($this->use_proxy_check) {
             if (!defined('HYP_K_TAI_RENDER') || HYP_K_TAI_RENDER !== 1 || !$this->HypKTaiRender->vars['ua']['inIPRange']) {
                 HypCommonFunc::BBQ_Check($this->no_proxy_check, $this->msg_proxy_check, NULL, $this->post_spam_checkers);
             }
         }
         // 文字エンコーディング外の文字を数値エンティティに変換
         if (defined('HYP_POST_ENCODING') && HYP_POST_ENCODING === 'UTF-8' && $this->encode !== 'UTF-8') {
             HypCommonFunc::encode_numericentity($_POST, $this->encode, 'UTF-8');
         }
         // 機種依存文字フィルター
         if (defined('HYP_POST_ENCODING') && $this->use_dependence_filter) {
             $_POST = HypCommonFunc::dependence_filter($_POST);
         }
         // 文字コードを正規化
         if (!$this->wizMobileUse && defined('HYP_POST_ENCODING') && $this->encode !== HYP_POST_ENCODING) {
             mb_convert_variables($this->encode === 'EUC-JP' ? 'eucJP-win' : $this->encode, HYP_POST_ENCODING === 'EUC-JP' ? 'eucJP-win' : HYP_POST_ENCODING, $_POST);
             if (isset($_POST['charset'])) {
                 $_POST['charset'] = $this->encode;
             }
         }
         // PostSpam をチェック
         if ($this->use_post_spam_filter) {
             // spamdat 自動アップデート用タグ
             $GLOBALS['hyp_preload_head_tag'] .= "\n" . '<script type="text/javascript" src="' . XOOPS_URL . '/class/hyp_common/gate.php?way=spamdatup" defer="defer"></script>';
             // 加算 pt
             if ($this->post_spam_rules) {
                 foreach ($this->post_spam_rules as $rule => $point) {
                     if ($rule && $point) {
                         HypCommonFunc::PostSpam_filter($rule, $point);
                     }
                 }
             }
             // チェックをパスするフィールド名
             if (!empty($this->post_spam_pass_names)) {
                 HypCommonFunc::PostSpam_filter('pass_keys', explode(',', $this->post_spam_pass_names));
             }
             // 無効なフィールド定義
             if (!empty($this->post_spam_trap)) {
                 $this->ignore_fileds[$this->post_spam_trap] = array('');
             }
             if (is_array($this->ignore_fileds) && $this->ignore_fileds) {
                 HypCommonFunc::PostSpam_filter('array_rule', array('ignore_fileds' => array($this->ignore_fileds, $this->post_spam_filed)));
             }
             // PukiWikiMod のスパム定義読み込み 31pt
             $datfile = XOOPS_ROOT_PATH . '/modules/pukiwiki/cache/spamdeny.dat';
             if (is_file($datfile)) {
                 HypCommonFunc::PostSpam_filter("/" . trim(join("", file($datfile))) . "/i", 31);
             }
             // Default スパムサイト定義読み込み
             $datfiles = array();
             if (is_file(XOOPS_TRUST_PATH . '/uploads/hyp_common/spamsites.dat')) {
                 $datfiles[] = XOOPS_TRUST_PATH . '/uploads/hyp_common/spamsites.dat';
             } else {
                 $datfiles[] = HYP_COMMON_ROOT_PATH . '/dat/spamsites.dat';
             }
             $datfiles[] = HYP_COMMON_ROOT_PATH . '/config/spamsites.conf.dat';
             $checks = array();
             $mtime = 0;
             foreach ($datfiles as $datfile) {
                 if (is_file($datfile)) {
                     $mtime = max(filemtime($datfile), $mtime);
                     $checks[] = $datfile;
                 }
             }
             if ($checks) {
                 $cachefile = XOOPS_TRUST_PATH . '/cache/hyp_spamsites.dat';
                 if ($mtime > @filemtime($cachefile)) {
                     $words = array();
                     foreach ($checks as $datfile) {
                         $words = array_merge($words, file($datfile));
                     }
                     $regs = HypCommonFunc::get_matcher_regex_safe($words, "");
                     HypCommonFunc::flock_put_contents($cachefile, $regs);
                 } else {
                     $regs = join('', file($cachefile));
                 }
                 foreach (explode("", $regs) as $reg) {
                     HypCommonFunc::PostSpam_filter('/((ht|f)tps?:\\/\\/(.+\\.)*|@|url=)' . $reg . '/i', $this->post_spam_host);
                 }
             }
             // Default スパムワード定義読み込み
             $datfiles = array();
             if (is_file(XOOPS_TRUST_PATH . '/uploads/hyp_common/spamwords.dat')) {
                 $datfiles[] = XOOPS_TRUST_PATH . '/uploads/hyp_common/spamwords.dat';
             } else {
                 $datfiles[] = HYP_COMMON_ROOT_PATH . '/dat/spamwords.dat';
             }
             $datfiles[] = HYP_COMMON_ROOT_PATH . '/config/spamwords.conf.dat';
             $checks = array();
             $mtime = 0;
             foreach ($datfiles as $datfile) {
                 if (is_file($datfile)) {
                     $mtime = max(filemtime($datfile), $mtime);
                     $checks[] = $datfile;
                 }
             }
             if ($checks) {
                 $cachefile = XOOPS_TRUST_PATH . '/cache/hyp_spamwords_' . $this->encode . '.dat';
                 if ($mtime > @filemtime($cachefile)) {
                     $words = array();
                     foreach ($checks as $datfile) {
                         $_lines = file($datfile);
                         if ($_lines[0][0] === '@') {
                             $_enc = trim(substr(rtrim($_lines[0]), 1));
                             array_shift($_lines);
                             mb_convert_variables($this->encode, $_enc, $_lines);
                         }
                         $words = array_merge($words, $_lines);
                     }
                     $regs = HypCommonFunc::get_matcher_regex_safe($words, "");
                     HypCommonFunc::flock_put_contents($cachefile, $regs);
                 } else {
                     $regs = join('', file($cachefile));
                 }
                 foreach (explode("", $regs) as $reg) {
                     HypCommonFunc::PostSpam_filter('/' . $reg . '/i', $this->post_spam_word);
                 }
             }
             // 判定
             if (!$xoopsUserIsAdmin && !defined('HYP_COMMON_HYPCONF_ADMIN_MODE')) {
                 // 閾値
                 $spamlev = is_object($xoopsUser) ? $this->post_spam_user : $this->post_spam_guest;
                 $level = HypCommonFunc::get_postspam_avr($this->post_spam_a, $this->post_spam_bb, $this->post_spam_url, $this->encode, $this->encodehint_name);
                 // URL中の存在しないホスト名をチェック
                 if ($this->post_spam_unhost && !is_object($xoopsUser)) {
                     $level += HypCommonFunc::URL_Check($_POST) * $this->post_spam_unhost;
                 }
                 if ($level > $spamlev) {
                     $ttl = $level > $this->post_spam_badip_forever ? $this->post_spam_badip_ttl0 : $this->post_spam_badip_ttl;
                     if ($level > $this->post_spam_badip) {
                         HypCommonFunc::register_bad_ips(null, $ttl);
                     }
                     if ($this->use_mail_notify) {
                         $this->sendMail($level);
                     }
                     // dat/spam*.dat の自動アップデート
                     HypCommonFunc::spamdat_auto_update();
                     // config/spamsites.conf.dat への自動登録
                     $confFile = XOOPS_TRUST_PATH . '/class/hyp_common/config/spamsites.conf.dat';
                     if ($this->post_spam_site_auto_regist && isset($_POST[$this->post_spam_trap]) && is_writable($confFile)) {
                         if (preg_match('#^https?://(?:www\\.)?([\\-_.!~*\'()a-zA-Z0-9;/?:@&=+$,%]+)#', $_POST[$this->post_spam_trap], $_match)) {
                             $badurl = rtrim($_match[1], '/');
                             $badurl = preg_replace('#^(.+)/[^/]+\\.[0-9a-zA-Z]+$#', '$1', $badurl);
                             // ドット"."で区切られていないアイテムは除外 ( com だけとかのアイテムの誤登録防止 )
                             if (preg_match('/.+\\..+/', $badurl)) {
                                 $myhost = parse_url(XOOPS_URL, PHP_URL_HOST);
                                 // 正規表現の検査
                                 if (@preg_match('#(?:' . $this->post_spam_safe_url . ')#i', '') === false) {
                                     $this->post_spam_safe_url = '(?!)';
                                 }
                                 if (!preg_match('#' . preg_quote($myhost, '#') . '|(?:' . $this->post_spam_safe_url . ')#i', $badurl)) {
                                     $confUrls = file($confFile);
                                     $confUrls = array_map('rtrim', $confUrls);
                                     if (!in_array($badurl, $confUrls)) {
                                         file_put_contents($confFile, $badurl . "\n", FILE_APPEND | LOCK_EX);
                                     }
                                 }
                             }
                         }
                     }
                     exit('Processing was not completed.' . $level);
                 } else {
                     if ($this->use_mail_notify > 1) {
                         $this->sendMail($level);
                     }
                 }
             }
         }
     }
     // set CSRF Token
     if (!isset($_SESSION['HYP_CSRF_TOKEN']) && $this->csrfToken) {
         $_SESSION['HYP_CSRF_TOKEN'] = $this->csrfToken;
     }
     // Insert tag into <head>
     if (!defined('HYP_K_TAI_RENDER') || HYP_K_TAI_RENDER !== 1) {
         ob_start(array(&$this, 'addHeadTag'));
     }
     // Set Query Words
     if ($this->use_set_query_words) {
         HypCommonFunc::set_query_words($this->q_word, $this->q_word2, $this->se_name, $this->kakasi_cache_dir, $this->encode);
         if ($this->use_words_highlight) {
             if (constant($this->q_word)) {
                 $GLOBALS['hyp_preload_head_tag'] .= '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/class/hyp_common/words_highlight.css" />';
             }
             ob_start(array(&$this, 'wordsHighlight'));
         }
     }
     // Use K_TAI Render
     if (defined('HYP_K_TAI_RENDER') && HYP_K_TAI_RENDER) {
         // docomo i-mode ID のチェック
         $idCheck = $this->HypKTaiRender->checkDeviceId(XOOPS_DB_PASS);
         if ($idCheck === 'redirect') {
             exit;
         } else {
             if (!$idCheck && is_object($xoopsUser)) {
                 // ログインしている場合のみ
                 $_SESSION = array();
                 exit('Device ID does not match.');
             }
         }
         // Redirect 指定ファイルの確認 ( by _onShutdownKtai() )
         $this->_checkRedirectFile();
         // Check login
         $this->_checkEasyLogin();
         // Setup session ID
         $this->HypKTaiRender->setupSID();
         // HTTP_REFERER
         if (empty($this->HypKTaiRender->SERVER['HTTP_REFERER'])) {
             if (!empty($_SESSION['hypKtaiReferer'])) {
                 $_SERVER['HTTP_REFERER'] = $this->HypKTaiRender->SERVER['HTTP_REFERER'] = $_SESSION['hypKtaiReferer'];
             } else {
                 if (!empty($_SERVER['HTTP_REFERER'])) {
                     // セッションに積んでないのに preFilter() で自動セット = CSRF
                     exit('Bad Request.');
                 }
             }
         }
         $_SESSION['hypKtaiReferer'] = $this->HypKTaiRender->myRoot . $this->HypKTaiRender->SERVER['REQUEST_URI'];
         if (isset($_SERVER['HTTP_REFERER'])) {
             $_SERVER['HTTP_REFERER'] = $this->HypKTaiRender->removeQueryFromUrl($_SERVER['HTTP_REFERER'], array($this->HypKTaiRender->session_name, 'guid'));
         }
         // Remove control keys
         $this->k_tai_conf['getKeys'][] = $this->HypKTaiRender->session_name;
         $this->k_tai_conf['getKeys'][] = 'guid';
         if (isset($_SERVER['QUERY_STRING'])) {
             $_SERVER['QUERY_STRING'] = ltrim($this->HypKTaiRender->removeQueryFromUrl('?' . $_SERVER['QUERY_STRING'], $this->k_tai_conf['getKeys']), '?');
         }
         if (isset($_SERVER['argv'][0])) {
             $_SERVER['argv'][0] = ltrim($this->HypKTaiRender->removeQueryFromUrl('?' . $_SERVER['argv'][0], $this->k_tai_conf['getKeys']), '?');
         }
         foreach (array('REQUEST_URI', '_REQUEST_URI') as $_key) {
             if (isset($_SERVER[$_key])) {
                 $_SERVER[$_key] = $this->HypKTaiRender->removeQueryFromUrl($_SERVER[$_key], $this->k_tai_conf['getKeys']);
             }
         }
         // $this->k_tai_conf['msg'] 文字コード変換
         if ($this->encode !== strtoupper($this->configEncoding)) {
             if (function_exists('mb_convert_encoding') && $this->configEncoding && $this->encode !== $this->configEncoding) {
                 mb_convert_variables($this->encode, $this->configEncoding, $this->k_tai_conf['msg']);
                 mb_convert_variables($this->encode, $this->configEncoding, $this->k_tai_conf['rebuilds']);
             }
         }
         // 言語定数セット
         foreach ($this->k_tai_conf['msg'] as $key => $val) {
             define('KTAI_RENDER_MSG_' . strtoupper($key), $val);
         }
         // Set theme set
         if (isset($this->k_tai_conf['themeSet']) && is_file(XOOPS_THEME_PATH . '/' . $this->k_tai_conf['themeSet'] . '/theme.html')) {
             $GLOBALS['xoopsConfig']['theme_set'] = $this->k_tai_conf['themeSet'];
             // For ImpressCMS 1.2
             if (isset($GLOBALS['icmsConfig'])) {
                 $GLOBALS['icmsConfig']['theme_set'] = $this->k_tai_conf['themeSet'];
             }
             if (defined('XOOPS_CUBE_LEGACY')) {
                 // Over write user setting
                 $this->mRoot->mContext->setThemeName($this->k_tai_conf['themeSet']);
             }
         }
         // Set template set
         if (!empty($this->k_tai_conf['templateSet'])) {
             $GLOBALS['xoopsConfig']['template_set'] = $this->k_tai_conf['templateSet'];
             // For ImpressCMS 1.2
             if (isset($GLOBALS['icmsConfig'])) {
                 $GLOBALS['icmsConfig']['template_set'] = $this->k_tai_conf['templateSet'];
             }
         }
         // Hint character for encoding judgment (use preload side function)
         $this->HypKTaiRender->Config_encodeHintWord = '';
         // google AdSense
         if ($this->k_tai_conf['googleAdsense']['config']) {
             $this->HypKTaiRender->Config_googleAdSenseConfig = $this->k_tai_conf['googleAdsense']['config'];
             $this->HypKTaiRender->Config_googleAdSenseBelow = $this->k_tai_conf['googleAdsense']['below'];
         }
         // keitai Filter
         ob_start(array(&$this, 'keitaiFilter'));
         // <from> Filter
         ob_start(array(&$this, 'formFilter'));
         // smart redirection for smartphone
         if (HYP_K_TAI_RENDER > 1) {
             ob_start(array(&$this, 'smartRedirect'));
         }
         register_shutdown_function(array(&$this, '_onShutdownKtai'));
     } else {
         // <from> Filter
         ob_start(array(&$this, 'formFilter'));
         // emoji Filter
         if (!empty($this->use_k_tai_render)) {
             ob_start(array(&$this, 'emojiFilter'));
         }
         if (isset($_SERVER['HTTP_X_ORIGINAL_USER_AGENT']) && $this->encode !== 'UTF-8') {
             ob_start(array(&$this, 'utf8Filter'));
         }
         // Add button to smartphone style
         if (!empty($_COOKIE['_hypktaipc'])) {
             // $this->k_tai_conf['msg'] 文字コード変換
             if ($this->encode !== strtoupper($this->configEncoding)) {
                 if (function_exists('mb_convert_encoding') && $this->configEncoding && $this->encode !== $this->configEncoding) {
                     mb_convert_variables($this->encode, $this->configEncoding, $this->k_tai_conf['msg']);
                 }
             }
             ob_start(array(&$this, 'switchOfSmartPhone'));
         }
         // smart redirection
         if (!empty($this->use_smart_redirect)) {
             ob_start(array(&$this, 'smartRedirect'));
         }
     }
     // Restor mb_detect_order
     if ($this->detect_order_org) {
         mb_detect_order($this->detect_order_org);
     }
 }
Пример #2
0
 function postFilter()
 {
     if (defined('HYP_COMMON_SKIP_POST_FILTER')) {
         return;
     }
     // Set mb_detect_order
     if ($this->detect_order) {
         mb_detect_order($this->detect_order);
     }
     // For WizMobile
     if (XC_CLASS_EXISTS('WizMobile')) {
         define('HYP_WIZMOBILE_USE', true);
     }
     // XOOPS の表示文字エンコーディング
     $this->encode = strtoupper(_CHARSET);
     // 設定ファイルのエンコーディングを検査
     if ($this->encode !== 'UTF-8' && $this->encode !== strtoupper($this->configEncoding)) {
         $this->encodehint_word = '';
     }
     if (!$this->wizMobileUse && !empty($_GET)) {
         // 文字コードを正規化
         $enchint = isset($_GET[$this->encodehint_name]) ? $_GET[$this->encodehint_name] : (isset($_GET['encode_hint']) ? $_GET['encode_hint'] : '');
         if ($enchint && function_exists('mb_detect_encoding')) {
             define('HYP_GET_ENCODING', strtoupper(mb_detect_encoding($enchint)));
             $_GET = HypCommonFunc::input_filter($_GET, $this->input_filter_strength, HYP_GET_ENCODING);
             if (HYP_GET_ENCODING !== $this->encode) {
                 mb_convert_variables($this->encode, HYP_GET_ENCODING, $_GET);
                 if (isset($_GET['charset'])) {
                     $_GET['charset'] = $this->encode;
                 }
             }
         } else {
             $_GET = HypCommonFunc::input_filter($_GET, $this->input_filter_strength);
         }
     }
     global $xoopsUser, $xoopsUserIsAdmin, $xoopsModule;
     if (is_object($xoopsModule)) {
         $this->nowModuleDirname = $xoopsModule->getVar('dirname');
     }
     // For addHeadTag()
     if (!isset($GLOBALS['hyp_preload_head_tag'])) {
         $GLOBALS['hyp_preload_head_tag'] = '';
     }
     if (!empty($_POST)) {
         // POST 文字列の文字エンコードを判定
         $enchint = isset($_POST[$this->encodehint_name]) ? $_POST[$this->encodehint_name] : (isset($_POST['encode_hint']) ? $_POST['encode_hint'] : '');
         if ($enchint && function_exists('mb_detect_encoding')) {
             define('HYP_POST_ENCODING', strtoupper(mb_detect_encoding($enchint)));
         } else {
             if (isset($_POST['charset'])) {
                 define('HYP_POST_ENCODING', strtoupper($_POST['charset']));
             }
         }
         // 携帯レンダーの場合絵文字変換
         if (defined('HYP_K_TAI_RENDER') && HYP_K_TAI_RENDER || isset($_SERVER['HTTP_X_ORIGINAL_USER_AGENT'])) {
             $_POST = $this->_modKtaiEmojiEncode($_POST);
         }
         // Input フィルター (remove "\0")
         $_POST = HypCommonFunc::input_filter($_POST, $this->input_filter_strength, defined('HYP_POST_ENCODING') ? HYP_POST_ENCODING : null);
         // Proxy Check
         if ($this->use_proxy_check) {
             if (!defined('HYP_K_TAI_RENDER') || HYP_K_TAI_RENDER !== 1 || !$this->HypKTaiRender->vars['ua']['inIPRange']) {
                 HypCommonFunc::BBQ_Check($this->no_proxy_check, $this->msg_proxy_check, NULL, $this->post_spam_checkers);
             }
         }
         // 文字エンコーディング外の文字を数値エンティティに変換
         if (defined('HYP_POST_ENCODING') && HYP_POST_ENCODING === 'UTF-8' && $this->encode !== 'UTF-8') {
             HypCommonFunc::encode_numericentity($_POST, $this->encode, 'UTF-8');
         }
         // 機種依存文字フィルター
         if (defined('HYP_POST_ENCODING') && $this->use_dependence_filter) {
             $_POST = HypCommonFunc::dependence_filter($_POST);
         }
         // 文字コードを正規化
         if (!$this->wizMobileUse && defined('HYP_POST_ENCODING') && $this->encode !== HYP_POST_ENCODING) {
             mb_convert_variables($this->encode, HYP_POST_ENCODING, $_POST);
             if (isset($_POST['charset'])) {
                 $_POST['charset'] = $this->encode;
             }
         }
         // PostSpam をチェック
         if ($this->use_post_spam_filter) {
             // 加算 pt
             if ($this->post_spam_rules) {
                 foreach ($this->post_spam_rules as $rule => $point) {
                     if ($rule && $point) {
                         HypCommonFunc::PostSpam_filter($rule, $point);
                     }
                 }
             }
             // チェックをパスするフィールド名
             if (!empty($this->post_spam_pass_names)) {
                 HypCommonFunc::PostSpam_filter('pass_keys', explode(',', $this->post_spam_pass_names));
             }
             // 無効なフィールド定義
             if (!empty($this->post_spam_trap)) {
                 $this->ignore_fileds[$this->post_spam_trap] = array('');
             }
             if (is_array($this->ignore_fileds) && $this->ignore_fileds) {
                 HypCommonFunc::PostSpam_filter('array_rule', array('ignore_fileds' => array($this->ignore_fileds, $this->post_spam_filed)));
             }
             // PukiWikiMod のスパム定義読み込み 31pt
             $datfile = XOOPS_ROOT_PATH . '/modules/pukiwiki/cache/spamdeny.dat';
             if (is_file($datfile)) {
                 HypCommonFunc::PostSpam_filter("/" . trim(join("", file($datfile))) . "/i", 31);
             }
             // Default スパムサイト定義読み込み
             $datfiles = array();
             $datfiles[] = HYP_COMMON_ROOT_PATH . '/dat/spamsites.dat';
             $datfiles[] = HYP_COMMON_ROOT_PATH . '/config/spamsites.conf.dat';
             $checks = array();
             $mtime = 0;
             foreach ($datfiles as $datfile) {
                 if (is_file($datfile)) {
                     $mtime = max(filemtime($datfile), $mtime);
                     $checks[] = $datfile;
                 }
             }
             if ($checks) {
                 $cachefile = XOOPS_TRUST_PATH . '/cache/hyp_spamsites.dat';
                 if ($mtime > @filemtime($cachefile)) {
                     $words = array();
                     foreach ($checks as $datfile) {
                         $words = array_merge($words, file($datfile));
                     }
                     $regs = HypCommonFunc::get_matcher_regex_safe($words, "");
                     HypCommonFunc::flock_put_contents($cachefile, $regs);
                 } else {
                     $regs = join('', file($cachefile));
                 }
                 foreach (explode("", $regs) as $reg) {
                     HypCommonFunc::PostSpam_filter('/((ht|f)tps?:\\/\\/(.+\\.)*|@|url=)' . $reg . '/i', $this->post_spam_host);
                 }
             }
             // Default スパムワード定義読み込み
             $datfiles = array();
             $datfiles[] = HYP_COMMON_ROOT_PATH . '/dat/spamwords.dat';
             $datfiles[] = HYP_COMMON_ROOT_PATH . '/config/spamwords.conf.dat';
             $checks = array();
             $mtime = 0;
             foreach ($datfiles as $datfile) {
                 if (is_file($datfile)) {
                     $mtime = max(filemtime($datfile), $mtime);
                     $checks[] = $datfile;
                 }
             }
             if ($checks) {
                 $cachefile = XOOPS_TRUST_PATH . '/cache/hyp_spamwords_' . $this->encode . '.dat';
                 if ($mtime > @filemtime($cachefile)) {
                     $words = array();
                     foreach ($checks as $datfile) {
                         $_lines = file($datfile);
                         if ($_lines[0][0] === '@') {
                             $_enc = trim(substr(rtrim($_lines[0]), 1));
                             array_shift($_lines);
                             mb_convert_variables($this->encode, $_enc, $_lines);
                         }
                         $words = array_merge($words, $_lines);
                     }
                     $regs = HypCommonFunc::get_matcher_regex_safe($words, "");
                     HypCommonFunc::flock_put_contents($cachefile, $regs);
                 } else {
                     $regs = join('', file($cachefile));
                 }
                 foreach (explode("", $regs) as $reg) {
                     HypCommonFunc::PostSpam_filter('/' . $reg . '/i', $this->post_spam_word);
                 }
             }
             // 判定
             if (!$xoopsUserIsAdmin) {
                 // 閾値
                 $spamlev = is_object($xoopsUser) ? $this->post_spam_user : $this->post_spam_guest;
                 $level = HypCommonFunc::get_postspam_avr($this->post_spam_a, $this->post_spam_bb, $this->post_spam_url, $this->encode, $this->encodehint_name);
                 // URL中の存在しないホスト名をチェック
                 if ($this->post_spam_unhost && !is_object($xoopsUser)) {
                     $level += HypCommonFunc::URL_Check($_POST) * $this->post_spam_unhost;
                 }
                 if ($level > $spamlev) {
                     $ttl = $level > $this->post_spam_badip_forever ? $this->post_spam_badip_ttl0 : $this->post_spam_badip_ttl;
                     if ($level > $this->post_spam_badip) {
                         HypCommonFunc::register_bad_ips(null, $ttl);
                     }
                     if ($this->use_mail_notify) {
                         $this->sendMail($level);
                     }
                     exit('Processing was not completed.');
                 } else {
                     if ($this->use_mail_notify > 1) {
                         $this->sendMail($level);
                     }
                 }
             }
         }
     }
     // Insert tag into <head>
     ob_start(array(&$this, 'addHeadTag'));
     // Set Query Words
     if ($this->use_set_query_words) {
         HypCommonFunc::set_query_words($this->q_word, $this->q_word2, $this->se_name, $this->kakasi_cache_dir, $this->encode);
         if ($this->use_words_highlight) {
             if (constant($this->q_word)) {
                 $GLOBALS['hyp_preload_head_tag'] .= '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/class/hyp_common/words_highlight.css" />';
             }
             ob_start(array(&$this, 'wordsHighlight'));
         }
     }
     // Use K_TAI Render
     if (defined('HYP_K_TAI_RENDER') && HYP_K_TAI_RENDER) {
         // docomo i-mode ID のチェック
         $idCheck = $this->HypKTaiRender->checkDeviceId(XOOPS_DB_PASS);
         if ($idCheck === 'redirect') {
             exit;
         } else {
             if (!$idCheck && is_object($xoopsUser)) {
                 // ログインしている場合のみ
                 $_SESSION = array();
                 exit('Device ID does not match.');
             }
         }
         // Redirect 指定ファイルの確認 ( by _onShutdownKtai() )
         $this->_checkRedirectFile();
         // Check login
         $this->_checkEasyLogin();
         // Setup session ID
         $this->HypKTaiRender->setupSID();
         // HTTP_REFERER
         if (empty($this->HypKTaiRender->SERVER['HTTP_REFERER'])) {
             if (!empty($_SESSION['hypKtaiReferer'])) {
                 $_SERVER['HTTP_REFERER'] = $this->HypKTaiRender->SERVER['HTTP_REFERER'] = $_SESSION['hypKtaiReferer'];
             } else {
                 if (!empty($_SERVER['HTTP_REFERER'])) {
                     // セッションに積んでないのに preFilter() で自動セット = CSRF
                     exit('Bad Request.');
                 }
             }
         }
         $_SESSION['hypKtaiReferer'] = $this->HypKTaiRender->myRoot . $this->HypKTaiRender->SERVER['REQUEST_URI'];
         if (isset($_SERVER['HTTP_REFERER'])) {
             $_SERVER['HTTP_REFERER'] = $this->HypKTaiRender->removeQueryFromUrl($_SERVER['HTTP_REFERER'], array($this->HypKTaiRender->session_name, 'guid'));
         }
         // Remove control keys
         $this->k_tai_conf['getKeys'][] = $this->HypKTaiRender->session_name;
         $this->k_tai_conf['getKeys'][] = 'guid';
         if (isset($_SERVER['QUERY_STRING'])) {
             $_SERVER['QUERY_STRING'] = ltrim($this->HypKTaiRender->removeQueryFromUrl('?' . $_SERVER['QUERY_STRING'], $this->k_tai_conf['getKeys']), '?');
         }
         if (isset($_SERVER['argv'][0])) {
             $_SERVER['argv'][0] = ltrim($this->HypKTaiRender->removeQueryFromUrl('?' . $_SERVER['argv'][0], $this->k_tai_conf['getKeys']), '?');
         }
         foreach (array('REQUEST_URI', '_REQUEST_URI') as $_key) {
             if (isset($_SERVER[$_key])) {
                 $_SERVER[$_key] = $this->HypKTaiRender->removeQueryFromUrl($_SERVER[$_key], $this->k_tai_conf['getKeys']);
             }
         }
         // $this->k_tai_conf['msg'] 文字コード変換
         if ($this->encode !== strtoupper($this->configEncoding)) {
             if (function_exists('mb_convert_encoding') && $this->configEncoding && $this->encode !== $this->configEncoding) {
                 mb_convert_variables($this->encode, $this->configEncoding, $this->k_tai_conf['msg']);
                 mb_convert_variables($this->encode, $this->configEncoding, $this->k_tai_conf['rebuilds']);
             }
         }
         // 言語定数セット
         foreach ($this->k_tai_conf['msg'] as $key => $val) {
             define('KTAI_RENDER_MSG_' . strtoupper($key), $val);
         }
         // Set theme set
         if (isset($this->k_tai_conf['themeSet']) && is_file(XOOPS_THEME_PATH . '/' . $this->k_tai_conf['themeSet'] . '/theme.html')) {
             $GLOBALS['xoopsConfig']['theme_set'] = $this->k_tai_conf['themeSet'];
             // For ImpressCMS 1.2
             if (isset($GLOBALS['icmsConfig'])) {
                 $GLOBALS['icmsConfig']['theme_set'] = $this->k_tai_conf['themeSet'];
             }
             if (defined('XOOPS_CUBE_LEGACY')) {
                 // Over write user setting
                 $this->mRoot->mContext->setThemeName($this->k_tai_conf['themeSet']);
             }
         }
         // Set template set
         if (!empty($this->k_tai_conf['templateSet'])) {
             $GLOBALS['xoopsConfig']['template_set'] = $this->k_tai_conf['templateSet'];
             // For ImpressCMS 1.2
             if (isset($GLOBALS['icmsConfig'])) {
                 $GLOBALS['icmsConfig']['template_set'] = $this->k_tai_conf['templateSet'];
             }
         }
         // Hint character for encoding judgment
         if (!empty($this->encodehint_word)) {
             if (function_exists('mb_convert_encoding') && $this->configEncoding && $this->encode !== $this->configEncoding) {
                 $encodehint_word = mb_convert_encoding($this->encodehint_word, $this->encode, $this->configEncoding);
             } else {
                 $encodehint_word = $this->encodehint_word;
             }
             $this->HypKTaiRender->Config_encodeHintWord = $encodehint_word;
             $this->HypKTaiRender->Config_encodeHintName = $this->encodehint_name;
             $this->encodehint_word = '';
         }
         // google AdSense
         if ($this->k_tai_conf['googleAdsense']['config']) {
             $this->HypKTaiRender->Config_googleAdSenseConfig = $this->k_tai_conf['googleAdsense']['config'];
             $this->HypKTaiRender->Config_googleAdSenseBelow = $this->k_tai_conf['googleAdsense']['below'];
         }
         // keitai Filter
         ob_start(array(&$this, 'keitaiFilter'));
         // smart redirection for smartphone
         if (HYP_K_TAI_RENDER > 1) {
             ob_start(array(&$this, 'smartRedirect'));
         }
         register_shutdown_function(array(&$this, '_onShutdownKtai'));
     } else {
         // <from> Filter
         if (!$this->wizMobileUse) {
             ob_start(array(&$this, 'formFilter'));
         }
         // emoji Filter
         if (!empty($this->use_k_tai_render)) {
             ob_start(array(&$this, 'emojiFilter'));
         }
         if (isset($_SERVER['HTTP_X_ORIGINAL_USER_AGENT']) && $this->encode !== 'UTF-8') {
             ob_start(array(&$this, 'utf8Filter'));
         }
         // Add button to smartphone style
         if (!empty($_COOKIE['_hypktaipc'])) {
             // $this->k_tai_conf['msg'] 文字コード変換
             if ($this->encode !== strtoupper($this->configEncoding)) {
                 if (function_exists('mb_convert_encoding') && $this->configEncoding && $this->encode !== $this->configEncoding) {
                     mb_convert_variables($this->encode, $this->configEncoding, $this->k_tai_conf['msg']);
                 }
             }
             ob_start(array(&$this, 'switchOfSmartPhone'));
         }
         // smart redirection
         if (!empty($this->use_smart_redirect)) {
             ob_start(array(&$this, 'smartRedirect'));
         }
     }
     // Restor mb_detect_order
     if ($this->detect_order_org) {
         mb_detect_order($this->detect_order_org);
     }
 }