function on_submit() { $id = intval(AZLib::getParam('id')); $cmd = AZLib::getParam('cmd'); $exact = AZLib::getParam('exact'); $is_phone = AZLib::getParam('is_phone'); // $contents = trim(AZLib::getParam('contents')); // $contents = AZLib::delDoubleSpace(AZLib::trimSpace($contents)); // $contents = trim($contents,","); $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 . '", checksum="' . md5($contents) . '" WHERE id="' . $id . '"')) { AZLib::get_badword(1, 0); } } elseif ($cmd == 'add' && $contents) { if (DB::query('INSERT INTO bad_words(contents,exact,is_phone,checksum,reason) VALUES ("' . $contents . '","' . $exact . '","' . $is_phone . '","' . md5($contents) . '","' . $reason . '")')) { AZLib::get_badword(1, 0); } } Url::redirect_current(); }
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 = eregi_replace("<br[^>]*>", "\n", $str_check); $str_check = eregi_replace("<p[^>]*>", "\n", $str_check); $str_check = eregi_replace("</p[^>]*>", "\n", $str_check); $str_check = strip_tags($str_check); $str_check = str_replace(chr(9), ' ', $str_check); $str_check = str_replace(" ", " ", $str_check); $matches = array(); $arr_badword = AZLib::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; } } }