コード例 #1
0
ファイル: funpost.php プロジェクト: thu0ng91/jmc
/**
 * 发帖提交后的内容校验
 * 
 * $post_set 相关参数:
 * 'module' - 程序所属模块名
 * 'ownerid' - 论坛或所有者ID
 * 'topicid' - 主题ID
 * 'postid' - 帖子ID
 * 'posttime' - 发帖时间
 * 'title' - 标题在$_POST里面的键名
 * 'content' - 内容在$_POST里面的键名
 * 'checkcode' - 验证码
 * 'attachment' - 附件信息,附件数组serialize后的字符串
 * 'emptytitle' - bool类型,主题贴是都允许不填主题,false-不允许,true-允许
 * 'isnew' - bool类型,true表示发新帖,false表示编辑帖子
 * 'istopic' - bool类型,true表示主题帖子,false表示回复帖子
 * 'istop' - bool类型,是否全区置顶帖子
 * 'sname' - string类型,发帖时间在session里面保存的变量名
 * 'attachfile' - array类型,附件上传信息变量
 * 'oldattach' - array类型,老的附件是否保留信息
 * 
 * $configs 相关参数:
 * 'minposttime' - int类型,发帖最少时间间隔,单位是秒
 * 'badpostwords' - string类型,禁止发表的词语,每个一行
 * 'checkpostrubbish' - bool类型,是否检查灌水贴
 * 'minpostsize' - int类型,帖子内容最少几个字节
 * 'maxpostsize' - int类型,帖子内容最多几个字节
 * 'hidepostwords' - string类型,发表后隐藏的词语,每个一行
 * 
 * @param      array       $post_set 发帖信息设置
 * @param      array       $configs 检查相关参数设置
 * @param      array       $check_errors 错误信息数组
 * @access     public
 * @return     bool
 */
function jieqi_post_checkvar(&$post_set, $configs, &$check_errors)
{
    global $jieqiLang;
    global $jieqiConfigs;
    if (!isset($jieqiLang['system']['post'])) {
        jieqi_loadlang('post', 'system');
    }
    if (!isset($jieqiConfigs['system'])) {
        jieqi_getconfigs('system', 'configs');
    }
    if (!is_array($check_errors)) {
        $check_errors = array();
    }
    $num_errors = count($check_errors);
    include_once JIEQI_ROOT_PATH . '/include/checker.php';
    $checker = new JieqiChecker();
    //提交处理
    if (isset($jieqiConfigs['system']['posttitlemax'])) {
        $jieqiConfigs['system']['posttitlemax'] = intval($jieqiConfigs['system']['posttitlemax']);
    }
    if (empty($jieqiConfigs['system']['posttitlemax']) || $jieqiConfigs['system']['posttitlemax'] <= 10) {
        $jieqiConfigs['system']['posttitlemax'] = 60;
    }
    $post_set['topictitle'] = jieqi_substr(trim($post_set['topictitle']), 0, $jieqiConfigs['system']['posttitlemax'], '...');
    //检查禁止发帖时间段
    if (!empty($jieqiConfigs['system']['postdenytimes'])) {
        if (!$checker->deny_time($jieqiConfigs['system']['postdenytimes'])) {
            $check_errors[] = sprintf($jieqiLang['system']['post_deny_times'], jieqi_htmlstr($jieqiConfigs['system']['postdenytimes']));
        }
    }
    //检查时间间隔,是否允许发贴
    if (!empty($jieqiConfigs['system']['postintervaltime']) && !empty($post_set['isnew'])) {
        if (!$checker->interval_time($jieqiConfigs['system']['postintervaltime'], $post_set['sname'], 'jieqiVisitTime')) {
            $check_errors[] = sprintf($jieqiLang['system']['post_time_limit'], $jieqiConfigs['system']['postintervaltime']);
        }
    }
    //验证码
    if ($jieqiConfigs['system']['postcheckcode'] > 0) {
        if ($post_set['checkcode'] != $_SESSION['jieqiCheckCode']) {
            $check_errors[] = $jieqiLang['system']['post_checkcode_error'];
        }
    }
    //检查禁用单词
    if (!empty($jieqiConfigs['system']['postdenywords'])) {
        $matchwords1 = $checker->deny_words($post_set['topictitle'], $jieqiConfigs['system']['postdenywords'], true);
        $matchwords2 = $checker->deny_words($post_set['posttext'], $jieqiConfigs['system']['postdenywords'], true);
        if (is_array($matchwords1) || is_array($matchwords2)) {
            $matchwords = array();
            if (is_array($matchwords1)) {
                $matchwords = array_merge($matchwords, $matchwords1);
            }
            if (is_array($matchwords2)) {
                $matchwords = array_merge($matchwords, $matchwords2);
            }
            $check_errors[] = sprintf($jieqiLang['system']['post_words_deny'], implode(' ', jieqi_funtoarray('htmlspecialchars', $matchwords)));
        }
    }
    //检查灌水
    if (!empty($jieqiConfigs['system']['postdenyrubbish'])) {
        if (!$checker->deny_rubbish($post_set['posttext'], $jieqiConfigs['system']['postdenyrubbish'])) {
            $check_errors[] = $jieqiLang['system']['post_words_water'];
        }
    }
    //检查标题
    if (!empty($post_set['istopic']) && $checker->is_required($post_set['topictitle']) == false) {
        if ($post_set['emptytitle']) {
            $post_set['topictitle'] = jieqi_substr(str_replace(array("\r", "\n", "\t", " "), '', preg_replace('/\\[[^\\[\\]]+\\]([^\\[\\]]*)\\[\\/[^\\[\\]]+\\]/isU', '\\1', $post_set['posttext'])), 0, 60);
            if (strlen($post_set['emptytitle']) == 0) {
                $post_set['emptytitle'] = '--';
            }
        } else {
            $check_errors[] = $jieqiLang['system']['post_need_title'];
        }
    }
    //检查内容
    if (!$checker->is_required($post_set['posttext'])) {
        $check_errors[] = $jieqiLang['system']['post_need_content'];
    }
    //检查最少字数
    if (!empty($jieqiConfigs['system']['postminsize']) && !$checker->str_min($post_set['posttext'], $jieqiConfigs['system']['postminsize'])) {
        $check_errors[] = sprintf($jieqiLang['system']['post_min_content'], $jieqiConfigs['system']['postminsize']);
    }
    //检查最多字数
    if (!empty($jieqiConfigs['system']['postmaxsize']) && !$checker->str_max($post_set['posttext'], $jieqiConfigs['system']['postmaxsize'])) {
        $check_errors[] = sprintf($jieqiLang['system']['post_max_content'], $jieqiConfigs['system']['postmaxsize']);
    }
    //替换单词
    if (isset($jieqiConfigs['system']['postreplacewords']) && !empty($jieqiConfigs['system']['postreplacewords'])) {
        $checker->replace_words($post_set['topictitle'], $jieqiConfigs['system']['postreplacewords']);
        $checker->replace_words($post_set['posttext'], $jieqiConfigs['system']['postreplacewords']);
    }
    return count($check_errors) > $num_errors ? false : true;
}