首页 / 教程文章 / 网络传媒WordPress柔性内容智能审核流程构建教程

网络传媒WordPress柔性内容智能审核流程构建教程

网络传媒WordPress柔性内容智能审核流程构建教程

引言:内容审核的挑战与机遇

在当今数字化媒体时代,网络传媒平台每天都需要处理海量的内容投稿。传统的人工审核方式不仅效率低下,而且难以应对大规模的内容管理需求。WordPress作为全球最流行的内容管理系统,为网络传媒提供了强大的基础框架。本教程将指导您如何构建一个柔性、智能的内容审核流程,既能保证内容质量,又能提高审核效率。

系统架构设计

1.1 审核流程概览

我们的智能审核系统将采用分层过滤机制,结合自动化规则和人工审核,形成柔性的审核流程:

用户投稿 → 基础过滤 → 智能分析 → 分级处理 → 最终审核 → 发布

1.2 技术栈选择

  • WordPress核心 + 自定义插件
  • PHP 7.4+ 作为后端语言
  • MySQL数据库
  • 可选AI服务(如百度AI、腾讯云内容安全等)
  • JavaScript/jQuery用于前端交互

基础过滤模块实现

2.1 创建自定义审核插件

首先,我们创建一个WordPress插件来处理内容审核:

<?php
/**
 * Plugin Name: 柔性内容智能审核系统
 * Description: 网络传媒内容智能审核解决方案
 * Version: 1.0.0
 * Author: 网络传媒技术团队
 */

// 防止直接访问
if (!defined('ABSPATH')) {
    exit;
}

class FlexibleContentModeration {
    
    private $moderation_settings;
    
    public function __construct() {
        // 初始化插件
        add_action('init', array($this, 'init_moderation_system'));
        
        // 拦截新内容提交
        add_filter('wp_insert_post_data', array($this, 'pre_moderate_content'), 10, 2);
        
        // 添加管理菜单
        add_action('admin_menu', array($this, 'add_admin_menu'));
        
        // 注册设置
        add_action('admin_init', array($this, 'register_settings'));
    }
    
    /**
     * 初始化审核系统
     */
    public function init_moderation_system() {
        // 加载设置
        $this->moderation_settings = get_option('flexible_moderation_settings', array(
            'auto_reject_keywords' => ['赌博', '诈骗', '毒品'],
            'auto_approve_users' => [],
            'enable_ai_check' => true,
            'min_content_length' => 50
        ));
    }
    
    /**
     * 内容预审核处理
     * @param array $data 文章数据
     * @param array $postarr 原始数据
     * @return array 修改后的文章数据
     */
    public function pre_moderate_content($data, $postarr) {
        // 只处理投稿状态
        if ($data['post_status'] !== 'pending') {
            return $data;
        }
        
        $content = $data['post_content'] . ' ' . $data['post_title'];
        $author_id = $data['post_author'];
        
        // 执行基础过滤
        $basic_check = $this->basic_content_filter($content);
        
        if ($basic_check['status'] === 'reject') {
            $data['post_status'] = 'draft';
            $this->log_moderation_action($postarr['ID'], 'auto_rejected', $basic_check['reason']);
        } elseif ($basic_check['status'] === 'approve') {
            $data['post_status'] = 'publish';
            $this->log_moderation_action($postarr['ID'], 'auto_approved', '基础过滤通过');
        }
        // 其他情况保持pending状态,等待进一步审核
        
        return $data;
    }
    
    /**
     * 基础内容过滤
     * @param string $content 待审核内容
     * @return array 审核结果
     */
    private function basic_content_filter($content) {
        $settings = $this->moderation_settings;
        
        // 检查内容长度
        if (mb_strlen(strip_tags($content)) < $settings['min_content_length']) {
            return [
                'status' => 'reject',
                'reason' => '内容长度不足'
            ];
        }
        
        // 关键词过滤
        foreach ($settings['auto_reject_keywords'] as $keyword) {
            if (mb_strpos($content, $keyword) !== false) {
                return [
                    'status' => 'reject',
                    'reason' => '包含违禁关键词: ' . $keyword
                ];
            }
        }
        
        // 链接数量检查(防止垃圾信息)
        $link_count = preg_match_all('/<as+href=/i', $content);
        if ($link_count > 5) {
            return [
                'status' => 'pending',
                'reason' => '链接数量过多,需要人工审核'
            ];
        }
        
        return [
            'status' => 'pending',
            'reason' => '通过基础过滤,等待进一步审核'
        ];
    }
    
    /**
     * 记录审核操作
     */
    private function log_moderation_action($post_id, $action, $reason) {
        $log_entry = array(
            'post_id' => $post_id,
            'action' => $action,
            'reason' => $reason,
            'timestamp' => current_time('mysql'),
            'moderator' => get_current_user_id() ?: 'system'
        );
        
        $logs = get_post_meta($post_id, '_moderation_logs', true);
        if (!is_array($logs)) {
            $logs = array();
        }
        
        $logs[] = $log_entry;
        update_post_meta($post_id, '_moderation_logs', $logs);
    }
    
    // 其他方法将在下文实现...
}

// 初始化插件
new FlexibleContentModeration();
?>

智能分析模块集成

3.1 集成AI内容审核服务

/**
 * AI内容审核类
 */
class AIContentModerator {
    
    private $api_key;
    private $api_secret;
    
    public function __construct($api_key, $api_secret) {
        $this->api_key = $api_key;
        $this->api_secret = $api_secret;
    }
    
    /**
     * 调用AI服务审核文本内容
     * @param string $content 待审核内容
     * @return array 审核结果
     */
    public function moderate_text($content) {
        // 这里以百度AI内容审核API为例
        $url = "https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined";
        
        // 获取访问令牌(实际应用中需要缓存token)
        $access_token = $this->get_access_token();
        
        // 准备请求数据
        $data = array(
            'text' => mb_substr($content, 0, 20000) // API可能有长度限制
        );
        
        // 发送请求
        $response = wp_remote_post($url . "?access_token=" . $access_token, array(
            'body' => $data,
            'timeout' => 30
        ));
        
        if (is_wp_error($response)) {
            return array(
                'status' => 'error',
                'message' => 'AI服务请求失败',
                'confidence' => 0
            );
        }
        
        $body = json_decode(wp_remote_retrieve_body($response), true);
        
        // 解析百度AI返回结果
        if (isset($body['conclusionType'])) {
            switch ($body['conclusionType']) {
                case 1: // 合规
                    return array(
                        'status' => 'approve',
                        'confidence' => 0.9,
                        'details' => $body['data'] ?? []
                    );
                case 2: // 不合规
                    return array(
                        'status' => 'reject',
                        'confidence' => $body['data'][0]['probability'] ?? 0.8,
                        'reason' => $body['data'][0]['msg'] ?? '内容违规',
                        'details' => $body['data']
                    );
                case 3: // 疑似
                    return array(
                        'status' => 'pending',
                        'confidence' => $body['data'][0]['probability'] ?? 0.6,
                        'reason' => '需要人工复核',
                        'details' => $body['data']
                    );
                default:
                    return array(
                        'status' => 'pending',
                        'confidence' => 0,
                        'reason' => 'AI审核未明确结果'
                    );
            }
        }
        
        return array(
            'status' => 'error',
            'message' => 'AI服务返回异常'
        );
    }
    
    /**
     * 获取百度AI访问令牌
     */
    private function get_access_token() {
        $token_url = 'https://aip.baidubce.com/oauth/2.0/token';
        $response = wp_remote_post($token_url, array(
            'body' => array(
                'grant_type' => 'client_credentials',
                'client_id' => $this->api_key,
                'client_secret' => $this->api_secret
            )
        ));
        
        if (!is_wp_error($response)) {
            $body = json_decode(wp_remote_retrieve_body($response), true);
            return $body['access_token'] ?? '';
        }
        
        return '';
    }
    
    /**
     * 图像内容审核(扩展功能)
     */
    public function moderate_image($image_url) {
        // 图像审核实现类似文本审核
        // 实际开发中需要调用相应的图像审核API
        return array(
            'status' => 'pending',
            'message' => '图像审核功能待实现'
        );
    }
}

分级处理与人工审核界面

4.1 创建审核管理界面

// 在FlexibleContentModeration类中添加以下方法

/**
 * 添加管理菜单
 */
public function add_admin_menu() {
    add_menu_page(
        '内容审核中心',
        '内容审核',
        'moderate_content',
        'content-moderation',
        array($this, 'render_moderation_dashboard'),
        'dashicons-filter',
        30
    );
    
    add_submenu_page(
        'content-moderation',
        '审核设置',
        '审核设置',
        'manage_options',
        'moderation-settings',
        array($this, 'render_settings_page')
    );
}

/**
 * 渲染审核仪表板
 */
public function render_moderation_dashboard() {
    global $wpdb;
    
    // 获取待审核文章
    $pending_posts = get_posts(array(
        'post_status' => 'pending',
        'posts_per_page' => 20,
        'orderby' => 'date',
        'order' => 'ASC'
    ));
    
    ?>
    <div class="wrap">
        <h1>内容审核中心</h1>
        
        <div class="moderation-stats">
            <?php
            $counts = wp_count_posts();
            $pending_count = $counts->pending ?? 0;
            ?>
            <div class="stat-box pending">
                <h3>待审核</h3>
                <p class="count"><?php echo $pending_count; ?></p>
            </div>
        </div>
        
        <div class="moderation-queue">
            <h2>待审核内容 (<?php echo count($pending_posts); ?>)</h2>
            
            <?php if (empty($pending_posts)): ?>
                <p>暂无待审核内容。</p>
            <?php else: ?>
                <table class="wp-list-table widefat fixed striped">
                    <thead>
                        <tr>
                            <th width="5%">ID</th>
                            <th width="25%">标题</th>
                            <th width="15%">作者</th>
                            <th width="20%">提交时间</th>
                            <th width="15%">风险等级</th>
                            <th width="20%">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($pending_posts as $post): 
                            $risk_level = $this->calculate_risk_level($post);
                            $risk_class = $this->get_risk_class($risk_level);
                        ?>
                        <tr>
                            <td><?php echo $post->ID; ?></td>
                            <td>
                                <strong>
                                    <a href="<?php echo get_edit_post_link($post->ID); ?>" target="_blank">
                                        <?php echo esc_html($post->post_title); ?>
                                    </a>
                                </strong>
                                <br>
                                <small><?php echo wp_trim_words(strip_tags($post->post_content), 10); ?></small>
                            </td>
                            <td><?php echo get_the_author_meta('display_name', $post->post_author); ?></td>
                            <td><?php echo get_the_date('Y-m-d H:i', $post); ?></td>
                            <td>
                                <span class="risk-badge <?php echo $risk_class; ?>">
                                    风险等级: <?php echo $risk_level; ?>%
                                </span>
                            </td>
                            <td>
                                <button class="button button-primary approve-btn" 
                                        data-post-id="<?php echo $post->ID; ?>">
                                    通过
                                </button>
                                <button class="button button-secondary review-btn"
                                        data-post-id="<?php echo $post->ID; ?>">
                                    详细审核
                                </button>
                                <button class="button button-danger reject-btn"
                                        data-post-id="<?php echo $post->ID; ?>">
                                    拒绝
                                </button>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php endif; ?>
        </div>
    </div>
    
    <script>
    jQuery(document).ready(function($) {
        // 审核操作AJAX处理
        $('.approve-btn, .reject-btn').on('click', function() {
            var postId = $(this).data('post-id');
            var action = $(this).hasClass('approve-btn') ? 'approve' : 'reject';
            var button = $(this);
            
            $.ajax({
                url: ajaxurl,
                type: 'POST',
                data: {
                    action: 'process_moderation',
                    post_id: postId,
                    moderation_action: action,
                    nonce: '<?php echo wp_create_nonce("moderation_action"); ?>'
                },
                beforeSend: function() {
                    button.prop('disabled', true).text('处理中...');
                },
                success: function(response) {
                    if (response.success) {
                        button.closest('tr').fadeOut(300, function() {
                            $(this).remove();
                        });
                    } else {
                        alert('操作失败: ' + response.data);
                        button.prop('disabled', false).text(
                            action === 'approve' ? '通过' : '拒绝'
                        );
                    }
                }
            });
        });
    });
    </script>
    
    <style>
    .risk-badge {
        padding: 3px 8px;
        border-radius: 3px;
        font-size: 12px;
        font-weight: bold;
    }
    .risk-low { background: #d4edda; color: #155724; }
    .risk-medium { background: #fff3cd; color: #856404; }
    .risk-high { background: #f8d7da; color: #721c24; }
    .stat-box {
        display: inline-block;
        padding: 20px;
        margin: 10px;
        border-radius: 5px;
        text-align: center;
        min-width: 120px;
    }
    .stat-box.pending { background: #fff3cd; border: 1px solid #ffeaa7; }
    .stat-box .count {
        font-size: 32px;
        font-weight: bold;
        margin: 10px 0;
    }
    </style>
    <?php
}

/**
 * 计算内容风险等级
 */
private function calculate_risk_level($post) {
    $content = $post->post_content . ' ' . $post->post_title;
    $risk_score = 0;
    
    // 基于多种因素计算风险
    $author_posts = count_user_posts($post->post_author);
    if ($author_posts < 3) {
        $risk_score += 20; // 新作者风险加成
    }
    
    // 检查链接数量
    $link_count = preg_match_all('/<as+href=/i', $content);
    if ($link_count > 3) {
        $risk_score += min($link_count * 5, 30);
    }
    
    // 检查关键词
    $keywords = $this->moderation_settings['suspicious_keywords'] ?? [];
    foreach ($keywords as $keyword) {
        if (stripos($content, $keyword) !== false) {
            $risk_score += 15;
        }
    }
    
    return min($risk_score, 100);
}

/**
 * 根据风险等级获取CSS类
 */
private function get_risk_class($risk_level) {
    if ($risk_level < 30) {
        return 'risk-low';
    } elseif ($risk_level < 70) {
        return 'risk-medium';
    } else {
        return 'risk-high';
    }
}

审核流程优化与自动化

5.1 实现柔性审核规则

/**
 * 柔性审核规则引擎
 */
class FlexibleModerationRuleEngine {
    
    private $rules = [];
    
    public function __construct() {
        $this->load_rules();
    }
    
    /**
     * 加载审核规则
     */
    private function load_rules() {
        // 从数据库或配置文件加载规则
        $this->rules = [
            [
                'name' => '新作者限制',
                'condition' => 'author_post_count < 5',
                'action' => 'set_status',
                'value' => 'pending',
                'priority' => 10
            ],
            [
                'name' => '信任作者自动通过',
                'condition' => 'author_trust_level > 80',
                'action' => 'set_status',
                'value' => 'publish',
                'priority' => 5
            ],
            [
                'name' => '包含外部链接',
                'condition' => 'external_link_count > 2',

'flag_for_review',

            'value' => '需要检查外部链接',
            'priority' => 15
        ],
        [
            'name' => '短内容检查',
            'condition' => 'content_length < 100',
            'action' => 'set_status',
            'value' => 'draft',
            'message' => '内容过短,请补充详细信息',
            'priority' => 20
        ]
    ];
    
    // 按优先级排序
    usort($this->rules, function($a, $b) {
        return $a['priority'] - $b['priority'];
    });
}

/**
 * 应用规则到内容
 * @param array $content_data 内容数据
 * @return array 审核结果
 */
public function apply_rules($content_data) {
    $result = [
        'status' => 'pending', // 默认状态
        'actions' => [],
        'messages' => [],
        'flags' => []
    ];
    
    foreach ($this->rules as $rule) {
        if ($this->evaluate_condition($rule['condition'], $content_data)) {
            $this->apply_action($rule, $content_data, $result);
            
            // 如果规则设置了最终状态,停止后续规则评估
            if ($rule['action'] === 'set_status') {
                break;
            }
        }
    }
    
    return $result;
}

/**
 * 评估条件
 */
private function evaluate_condition($condition, $data) {
    // 解析条件表达式
    $conditions = [
        'author_post_count' => $data['author_post_count'] ?? 0,
        'author_trust_level' => $data['author_trust_level'] ?? 0,
        'external_link_count' => $data['external_link_count'] ?? 0,
        'content_length' => $data['content_length'] ?? 0
    ];
    
    // 简单的条件解析器
    preg_match('/(w+)s*([<>]=?|==|!=)s*(d+)/', $condition, $matches);
    
    if (count($matches) === 4) {
        $var = $matches[1];
        $operator = $matches[2];
        $value = (int)$matches[3];
        
        if (!isset($conditions[$var])) {
            return false;
        }
        
        switch ($operator) {
            case '<': return $conditions[$var] < $value;
            case '<=': return $conditions[$var] <= $value;
            case '>': return $conditions[$var] > $value;
            case '>=': return $conditions[$var] >= $value;
            case '==': return $conditions[$var] == $value;
            case '!=': return $conditions[$var] != $value;
        }
    }
    
    return false;
}

/**
 * 应用规则动作
 */
private function apply_action($rule, $content_data, &$result) {
    switch ($rule['action']) {
        case 'set_status':
            $result['status'] = $rule['value'];
            if (isset($rule['message'])) {
                $result['messages'][] = $rule['message'];
            }
            break;
            
        case 'flag_for_review':
            $result['flags'][] = [
                'type' => $rule['name'],
                'message' => $rule['value'],
                'priority' => $rule['priority']
            ];
            break;
            
        case 'add_metadata':
            $result['actions'][] = [
                'type' => 'add_meta',
                'key' => $rule['name'],
                'value' => $rule['value']
            ];
            break;
    }
}

}

// 在FlexibleContentModeration类中集成规则引擎
public function enhanced_moderation($post_id) {

$post = get_post($post_id);
$author_id = $post->post_author;

// 收集内容数据
$content_data = [
    'author_post_count' => count_user_posts($author_id),
    'author_trust_level' => $this->calculate_author_trust_level($author_id),
    'external_link_count' => $this->count_external_links($post->post_content),
    'content_length' => mb_strlen(strip_tags($post->post_content))
];

// 应用规则引擎
$rule_engine = new FlexibleModerationRuleEngine();
$rule_result = $rule_engine->apply_rules($content_data);

// 更新文章状态
if ($rule_result['status'] !== 'pending') {
    wp_update_post([
        'ID' => $post_id,
        'post_status' => $rule_result['status']
    ]);
    
    // 记录审核日志
    $this->log_moderation_action(
        $post_id,
        'rule_engine_' . $rule_result['status'],
        implode('; ', $rule_result['messages'])
    );
}

// 添加标记
foreach ($rule_result['flags'] as $flag) {
    add_post_meta($post_id, '_moderation_flag', $flag, false);
}

return $rule_result;

}

/**

  • 计算作者信任等级
    */

private function calculate_author_trust_level($author_id) {

$trust_score = 50; // 基础分

// 基于历史发布内容计算
$published_posts = get_posts([
    'author' => $author_id,
    'post_status' => 'publish',
    'posts_per_page' => -1
]);

$total_posts = count($published_posts);
if ($total_posts > 0) {
    // 文章数量加分
    $trust_score += min($total_posts * 2, 20);
    
    // 检查历史违规
    $violations = get_user_meta($author_id, '_content_violations', true) ?: 0;
    $trust_score -= $violations * 10;
    
    // 互动数据(评论、点赞等)
    $total_comments = get_comments([
        'user_id' => $author_id,
        'count' => true
    ]);
    $trust_score += min($total_comments * 0.5, 10);
}

return max(0, min(100, $trust_score));

}

/**

  • 统计外部链接
    */

private function count_external_links($content) {

$site_url = site_url();
$pattern = '/<as[^>]*href=["']([^"']+)["'][^>]*>/i';
preg_match_all($pattern, $content, $matches);

$external_count = 0;
if (!empty($matches[1])) {
    foreach ($matches[1] as $url) {
        // 检查是否为外部链接
        if (strpos($url, $site_url) === false && 
            strpos($url, 'http') === 0) {
            $external_count++;
        }
    }
}

return $external_count;

}


## 机器学习模型集成

### 6.1 基于用户行为的智能预测

/**

  • 机器学习预测模型类
    */

class ContentModerationPredictor {


private $model_data;
private $training_file;

public function __construct() {
    $this->training_file = WP_CONTENT_DIR . '/moderation_model.json';
    $this->load_model();
}

/**
 * 加载或训练模型
 */
private function load_model() {
    if (file_exists($this->training_file)) {
        $this->model_data = json_decode(file_get_contents($this->training_file), true);
    } else {
        $this->model_data = $this->train_initial_model();
    }
}

/**
 * 初始模型训练
 */
private function train_initial_model() {
    // 基于历史数据训练简单模型
    global $wpdb;
    
    $model = [
        'keyword_weights' => [],
        'author_patterns' => [],
        'time_patterns' => [],
        'content_patterns' => []
    ];
    
    // 分析历史审核数据
    $posts = $wpdb->get_results("
        SELECT p.ID, p.post_content, p.post_status, p.post_author, p.post_date
        FROM {$wpdb->posts} p
        WHERE p.post_type = 'post' 
        AND p.post_status IN ('publish', 'draft', 'trash')
        LIMIT 1000
    ");
    
    foreach ($posts as $post) {
        $this->update_model_from_post($model, $post);
    }
    
    // 保存模型
    file_put_contents($this->training_file, json_encode($model));
    
    return $model;
}

/**
 * 从单篇文章更新模型
 */
private function update_model_from_post(&$model, $post) {
    $content = strtolower($post->post_content);
    $words = str_word_count($content, 1);
    
    // 更新关键词权重
    foreach ($words as $word) {
        if (strlen($word) > 2) { // 忽略短词
            if (!isset($model['keyword_weights'][$word])) {
                $model['keyword_weights'][$word] = 0;
            }
            
            // 根据文章状态调整权重
            if ($post->post_status === 'publish') {
                $model['keyword_weights'][$word] += 0.1; // 正面信号
            } elseif ($post->post_status === 'trash') {
                $model['keyword_weights'][$word] -= 0.5; // 负面信号
            }
        }
    }
    
    // 记录作者模式
    $author_id = $post->post_author;
    if (!isset($model['author_patterns'][$author_id])) {
        $model['author_patterns'][$author_id] = [
            'total' => 0,
            'approved' => 0,
            'rejected' => 0
        ];
    }
    
    $model['author_patterns'][$author_id]['total']++;
    if ($post->post_status === 'publish') {
        $model['author_patterns'][$author_id]['approved']++;
    } elseif ($post->post_status === 'trash') {
        $model['author_patterns'][$author_id]['rejected']++;
    }
}

/**
 * 预测内容风险
 */
public function predict_content_risk($content, $author_id) {
    $risk_score = 0.5; // 默认中等风险
    
    // 基于关键词分析
    $content_lower = strtolower($content);
    $words = str_word_count($content_lower, 1);
    
    $keyword_impact = 0;
    $keyword_count = 0;
    
    foreach ($words as $word) {
        if (strlen($word) > 2 && isset($this->model_data['keyword_weights'][$word])) {
            $keyword_impact += $this->model_data['keyword_weights'][$word];
            $keyword_count++;
        }
    }
    
    if ($keyword_count > 0) {
        $avg_impact = $keyword_impact / $keyword_count;
        $risk_score += $avg_impact * 0.3; // 关键词影响权重
    }
    
    // 基于作者历史
    if (isset($this->model_data['author_patterns'][$author_id])) {
        $author_data = $this->model_data['author_patterns'][$author_id];
        if ($author_data['total'] > 0) {
            $rejection_rate = $author_data['rejected'] / $author_data['total'];
            $risk_score += $rejection_rate * 0.4; // 作者历史影响权重
        }
    }
    
    // 基于内容特征
    $content_features = $this->extract_content_features($content);
    $risk_score += $content_features['spam_likelihood'] * 0.3;
    
    // 确保在0-1范围内
    return max(0, min(1, $risk_score));
}

/**
 * 提取内容特征
 */
private function extract_content_features($content) {
    $features = [
        'spam_likelihood' => 0,
        'quality_score' => 0
    ];
    
    // 检查典型垃圾内容特征
    $link_density = $this->calculate_link_density($content);
    $caps_ratio = $this->calculate_caps_ratio($content);
    $keyword_density = $this->calculate_keyword_density($content);
    
    // 计算垃圾可能性
    $spam_score = 0;
    if ($link_density > 0.1) $spam_score += 0.3;
    if ($caps_ratio > 0.5) $spam_score += 0.2;
    if ($keyword_density > 0.05) $spam_score += 0.2;
    
    $features['spam_likelihood'] = min(1, $spam_score);
    
    // 计算质量分数(简化版)
    $word_count = str_word_count(strip_tags($content));
    $sentence_count = preg_match_all('/[.!?]+/', $content);
    
    if ($word_count > 0 && $sentence_count > 0) {
        $avg_sentence_length = $word_count / $sentence_count;
        if ($avg_sentence_length > 10 && $avg_sentence_length < 25) {
            $features['quality_score'] += 0.3;
        }
    }
    
    return $features;
}

/**
 * 计算链接密度
 */
private function calculate_link_density($content) {
    $total_chars = strlen($content);
    if ($total_chars === 0) return 0;
    
    preg_match_all('/<as[^>]*>/i', $content, $matches);
    $link_chars = 0;
    foreach ($matches[0] as $link) {
        $link_chars += strlen($link);
    }
    
    return $link_chars / $total_chars;
}

/**
 * 计算大写比例
 */
private function calculate_caps_ratio($content) {
    $text = strip_tags($content);
    $total_chars = strlen($text);
    if ($total_chars === 0) return 0;
    
    $caps_chars = preg_match_all('/[A-Z]/', $text);
    return $caps_chars / $total_chars;
}

/**
 * 计算关键词密度
 */
private function calculate_keyword_density($content) {
    $text = strip_tags($content);
    $words = str_word_count($text, 1);
    $total_words = count($words);
    
    if ($total_words === 0) return 0;
    
    // 常见营销关键词
    $marketing_keywords = ['免费', '优惠', '点击', '立即', '购买', '折扣'];
    $keyword_count = 0;
    
    foreach ($words as $word) {
        if (in_array($word, $marketing_keywords)) {
            $keyword_count++;
        }
    }
    
    return $keyword_count / $total_words;
}

}


## 审核工作流与通知系统

### 7.1 完整审核工作流实现

/**

  • 审核工作流管理器
    */

class ModerationWorkflowManager {


private $workflow_stages;

public function __construct() {
    $this->workflow_stages = [
        'initial_screening' => [
            'name' => '初步筛选',
            'handler' => 'handle_initial_screening',
            'next_stage' => 'ai_analysis',
            'timeout' => 3600 // 1小时
        ],
        'ai_analysis' => [
            'name' => 'AI分析',
            'handler' => 'handle_ai_analysis',
            'next_stage' => 'human_review',
            'conditions' => [
                'risk_score' => ['>', 0.3]
            ]
        ],
        'human_review' => [
            'name' => '人工审核',
            'handler' => 'handle_human_review',
            'next_stage' => 'final_decision',
            'assign_to' => 'moderator_group'
        ],
        'final_decision' => [
            'name' => '最终决定',
            'handler' => 'handle_final_decision',
            'next_stage' => null
        ]
    ];
}

/**
 * 处理内容审核工作流
 */
public function process_workflow($post_id) {
    $current_stage = get_post_meta($post_id, '_moderation_stage', true) ?: 'initial_screening';
    $workflow_data = get_post_meta($post_id, '_workflow_data', true) ?: [];
    
    while ($current_stage && isset($this->workflow_stages[$current_stage])) {
        $stage = $this->workflow_stages[$current_stage];
        
        // 执行当前阶段处理
        $result = $this->{$stage['handler']}($post_id, $workflow_data);
        
        // 更新工作流数据
        $workflow_data[$current_stage] = [
            'result' => $result,
            'processed_at' => current_time('mysql'),
            'processed_by' => 'system'
        ];
        
        update_post_meta($post_id, '_workflow_data', $workflow_data);
        
        // 检查是否满足进入下一阶段的条件
        if ($this->check_stage_conditions($stage, $result)) {
            $current_stage = $stage['next_stage'];
            update_post_meta($post_id, '_moderation_stage', $current_stage);
            
            // 触发阶段转换通知
            $this->notify_stage_transition($post_id, $stage['name'], $stage['next_stage']);
        } else {
            break; // 不满足条件,暂停工作流
        }
    }
    
    return $workflow_data;
}

/**
 * 初步筛选处理
 */
private function handle_initial_screening($post_id, $data) {
    $post = get_post($post_id);
    
    // 基础检查
    $checks = [
        'length_check'
本文来自网络,不代表柔性供应链服务中心立场,转载请注明出处:https://mall.org.cn/6130.html

EXCHANGES®作者

上一篇
下一篇

为您推荐

发表回复

联系我们

联系我们

18559313275

在线咨询: QQ交谈

邮箱: vip@exchanges.center

工作时间:周一至周五,9:00-17:30,节假日休息
返回顶部