Exemple #1
0
 function on_submit()
 {
     $id = intval(EClassApi::getParam('id'));
     $cmd = EClassApi::getParam('cmd');
     $exact = EClassApi::getParam('exact');
     $is_phone = EClassApi::getParam('is_phone');
     $contents = Url::get("contents");
     $reason = Url::get("reason");
     if ($is_phone == 1) {
         $contents = BadWord::badword_phone_type($contents);
     }
     $where = "";
     if ($cmd == 'edit' && $id && $contents) {
         $where = " AND id <> {$id}";
     }
     $re = DB::query("SELECT id FROM bad_words WHERE checksum = '" . md5($contents) . "' " . $where);
     $item = mysql_fetch_assoc($re);
     if ($item["id"]) {
         $this->setFormError('adv_banner', "<b>Từ khóa '{$contents}' đã tồn tại.</b>");
         return false;
     }
     if ($cmd == 'edit' && $id && $contents) {
         if (DB::query('UPDATE bad_words SET contents="' . $contents . '", exact="' . $exact . '", reason="' . $reason . '", is_phone="' . $is_phone . '",user_edit="' . User::user_name() . '",edit_time="' . TIME_NOW . '", checksum="' . md5($contents) . '" WHERE id="' . $id . '"')) {
             EClassApi::get_badword(1, 0);
         }
     } elseif ($cmd == 'add' && $contents) {
         if (DB::query('INSERT INTO bad_words(contents,exact,is_phone,checksum,reason,user_name,created_time) VALUES ("' . $contents . '","' . $exact . '","' . $is_phone . '","' . md5($contents) . '","' . $reason . '","' . User::user_name() . '","' . TIME_NOW . '")')) {
             EClassApi::get_badword(1, 0);
         }
     }
     Url::redirect_current();
 }
Exemple #2
0
    static function checkBadWord($str_check = '', $return = false, $del_cache = false, $getReason = false)
    {

        if ($str_check == "" && !$del_cache) {
            return false;
        }

        for ($i = 65; $i <= 90; $i++) {
            $str_check = str_replace("&#" . $i . ";", chr($i), $str_check);
        }

        for ($i = 97; $i <= 122; $i++) {
            $str_check = str_replace("&#" . $i . ";", chr($i), $str_check);
        }

        $str_check = preg_replace("/<br[^>]*>/", "\n", $str_check);
        $str_check = preg_replace("/<p[^>]*>/", "\n", $str_check);
        $str_check = preg_replace("/<\/p[^>]*>/", "\n", $str_check);

        $str_check = strip_tags($str_check);

        $str_check = str_replace(chr(9), ' ', $str_check);

        $str_check = str_replace("&nbsp;", " ", $str_check);

        $matches = array();
        $arr_badword = EClassApi::get_badword();

        if (!$del_cache) {

            foreach ($arr_badword as $badword) {
                $realBad = str_replace('*', '', $badword['contents']);
                $bad = preg_quote($badword['contents']);
                $badword['contents'] = preg_quote($badword['contents']);
                $badword['contents'] = str_replace(array('\*', '\?'), array('(.{0,3})', '(.+)'), $badword['contents']);

                if ($badword['exact']) {
                    if (preg_match('#(^|\s|\b)' . $badword['contents'] . '(\b|\s|!|\?|\.|,|$)#ui', $str_check, $match)) {
                        if ($return) {
                            $bad_arrs[$bad] = $bad;
                            $matches[] = $match[0];
                            $reason_arrs[$realBad] = $badword['reason'];
                        } else {
                            return true;
                        }
                    }
                } else {
                    if (preg_match('#' . $badword['contents'] . '#ui', $str_check, $match)) {
                        if ($return) {
                            $bad_arrs[$bad] = $bad;
                            $matches[] = $match[0];
                            $reason_arrs[$realBad] = $badword['reason'];
                        } else {
                            return true;
                        }
                    }
                }
            }

            if ($return && isset($bad_arrs)) {
                $arrReturn = array(
                    'bad' => implode(', ', $matches),
                    'bad_key' => str_replace(array('\*', '\?'), '', implode(', ', $bad_arrs))
                );
                if ($getReason) {

                    $arrReturn += array(
                        'reason' => $reason_arrs
                    );
                }
                return $arrReturn;
            } else {
                return false;
            }
        }
    }