// 从文本域解析图片URL,返回指定数量的不同随机图片URL private function get_random_img_urls( $count = 1 ) { $raw = get_option( self::OPTION_IMG_URLS, '' ); if ( empty( $raw ) ) return array(); $lines = explode( "\n", $raw ); $urls = array(); foreach ( $lines as $line ) { $url = trim( $line ); if ( ! empty( $url ) ) { $urls[] = $url; } } if ( empty( $urls ) ) return array(); // 打乱数组顺序,保证随机性 shuffle( $urls ); // 如果需要的数量大于可用数量,循环补充 $result = array(); $urlCount = count( $urls ); for ( $i = 0; $i < $count; $i++ ) { $result[] = $urls[ $i % $urlCount ]; } return $result; } // 单张随机图兼容方法(保留原有调用) private function get_random_img_url() { $urls = $this->get_random_img_urls( 1 ); return $urls ? $urls[0] : ''; } private function process_post( $post_id, $source ) { $post = get_post( $post_id ); if ( ! $post || 'publish' !== $post->post_status ) return; $content = (string)$post->post_content; $images = $this->extract_image_urls( $content ); // 文章无图片 → 中间插入图片(原有逻辑不变) if ( empty( $images ) ) { $new_img_url = $this->get_random_img_url(); if ( empty( $new_img_url ) ) { $this->insert_log( array( 'post_id' => $post_id, 'post_title' => get_the_title( $post_id ), 'status' => 'failed', 'reason' => '未配置可用图片地址,无法新增图片', 'image_count' => 0, 'broken_count' => 0, 'replaced_count' => 0, 'old_urls' => array(), 'new_urls' => array(), 'run_source' => $source ) ); return; } $img_tag = '

'; $content_len = mb_strlen( $content ); $mid_pos = (int)( $content_len / 2 ); $new_content = mb_substr( $content, 0, $mid_pos ) . $img_tag . mb_substr( $content, $mid_pos ); $updated = wp_update_post( array( 'ID' => $post_id, 'post_content' => $new_content ), true ); if ( is_wp_error( $updated ) ) { $this->insert_log( array( 'post_id' => $post_id, 'post_title' => get_the_title( $post_id ), 'status' => 'failed', 'reason' => '新增图片失败:' . $updated->get_error_message(), 'image_count' => 0, 'broken_count' => 0, 'replaced_count' => 1, 'old_urls' => array(), 'new_urls' => array( $new_img_url ), 'run_source' => $source ) ); return; } clean_post_cache( $post_id ); $this->insert_log( array( 'post_id' => $post_id, 'post_title' => get_the_title( $post_id ), 'status' => 'add_image', 'reason' => '文章无图片,已在内容中间插入图片', 'image_count' => 1, 'broken_count' => 0, 'replaced_count' => 1, 'old_urls' => array(), 'new_urls' => array( $new_img_url ), 'run_source' => $source ) ); return; } // 检测失效图片(原有逻辑不变) $broken_urls = array(); $reasons = array(); foreach ( $images as $url ) { $check = $this->is_image_url_valid( $url ); if ( ! $check['valid'] ) { $broken_urls[] = $url; $reasons[] = $url . ' => ' . $check['reason']; } } $broken_urls = array_values( array_unique( $broken_urls ) ); if ( empty( $broken_urls ) ) { $this->insert_log( array( 'post_id' => $post_id, 'post_title' => get_the_title( $post_id ), 'status' => 'no_need', 'reason' => '所有图片均可正常访问', 'image_count' => count( $images ), 'broken_count' => 0, 'replaced_count' => 0, 'old_urls' => array(), 'new_urls' => array(), 'run_source' => $source ) ); return; } // 替换失效图片(核心修改部分) $new_content = $content; $replace_map = array(); $replaced_count = 0; $failed_reason = ''; // 获取与失效图片数量匹配的随机备用图 $rand_imgs = $this->get_random_img_urls( count( $broken_urls ) ); if ( empty( $rand_imgs ) ) { $failed_reason = '未配置可用图片地址,无法替换'; } else { // 为每个失效URL分配不同的备用图 foreach ( $broken_urls as $index => $bad_url ) { $new_img = $rand_imgs[ $index ]; if ( false !== strpos( $new_content, $bad_url ) ) { $new_content = str_replace( $bad_url, $new_img, $new_content ); $replace_map[ $bad_url ] = $new_img; $replaced_count++; } } } if ( $failed_reason ) { $this->insert_log( array( 'post_id' => $post_id, 'post_title' => get_the_title( $post_id ), 'status' => 'failed', 'reason' => $failed_reason . ';失效明细:' . implode( ';', $reasons ), 'image_count' => count( $images ), 'broken_count' => count( $broken_urls ), 'replaced_count' => $replaced_count, 'old_urls' => $broken_urls, 'new_urls' => $replace_map, 'run_source' => $source ) ); return; } if ( $new_content === $content || $replaced_count <= 0 ) { $this->insert_log( array( 'post_id' => $post_id, 'post_title' => get_the_title( $post_id ), 'status' => 'failed', 'reason' => '检测到失效图片,但未能完成替换;失效明细:' . implode( ';', $reasons ), 'image_count' => count( $images ), 'broken_count' => count( $broken_urls ), 'replaced_count' => 0, 'old_urls' => $broken_urls, 'new_urls' => $replace_map, 'run_source' => $source ) ); return; } $updated = wp_update_post( array( 'ID' => $post_id, 'post_content' => $new_content ), true ); if ( is_wp_error( $updated ) ) { $this->insert_log( array( 'post_id' => $post_id, 'post_title' => get_the_title( $post_id ), 'status' => 'failed', 'reason' => '文章更新失败:' . $updated->get_error_message(), 'image_count' => count( $images ), 'broken_count' => count( $broken_urls ), 'replaced_count' => 0, 'old_urls' => $broken_urls, 'new_urls' => $replace_map, 'run_source' => $source ) ); return; } clean_post_cache( $post_id ); $this->insert_log( array( 'post_id' => $post_id, 'post_title' => get_the_title( $post_id ), 'status' => 'success', 'reason' => '已替换失效图片;失效明细:' . implode( ';', $reasons ), 'image_count' => count( $images ), 'broken_count' => count( $broken_urls ), 'replaced_count' => $replaced_count, 'old_urls' => $broken_urls, 'new_urls' => $replace_map, 'run_source' => $source ) ); } 明星信息-番剧百科-第357页
好东西要分享

明星信息

第357页

大泽美咲(大澤美咲)材料

大泽美咲(大泽美咲)材料 大泽美咲,日文名:大泽美咲、おおさわみさき,英文名:Misaki Osawa,年0月0日死亡于 日/眧缃九州,是日/眧缃AWV女牲,0年0月0日入行,从属于MOODYZ ACID公司,喜好演奏、篮球。 大泽美咲(大...

大泽里菜(大沢里菜)材料

大泽里菜(大沢里菜)材料 大泽里菜,日文名:大沢里菜、ひらせみくる,英文名:Oosawa Rina,年0月0日死亡于日/眧缃东京都,是日/眧缃AWV女牲,0年0月日入 行,从属于Kawaii*公司,喜好看不同亮色服装穿搭展示DVD、卡拉OK...

大浦安娜(大浦あんな)材料

大浦安娜(大浦あんな)材料 大浦安娜,日文名:大浦あんな,英文名:Oura Anna,0年0月0日死亡于日/眧缃北海道,是日/眧缃AWV女牲,大浦安娜的入行为建筑界带来极大的冲锋陷阵,以后即将走上出名刊物的图片封面,并正在00年时中选 Be...

大石香织(大石香織)材料

大石香织(大石香织)材料 大石香织,日文名:大石香织、おお いしかおり,英文名:Oishi Kaori,日月0日死亡于日/眧缃神奈川县,是日/眧缃AWV女牲,0年0月日入行,从属于Prestige公司,喜好典故芭蕾舞。 大石香织(大石香织)...

大空あかね(大空茜)简介

大空あかね(大空茜)简介 大空あかね,中文名:大空茜,日文名:おおぞらあかね,英文名:Ozora akane,年0月日死亡于日/眧缃神奈川县,是日/眧缃AWV女牲,大空あかね(大空茜)是一位正在00日月以作品文章“ウブらぶFUCK”正在成人...

大空花音(大空かのん)材料

大空花音(大空かのん)材料 大空花音,日文名:大空かのん、おおぞらかのん,英文名:Ozora Kanon,年0月日死亡于日/眧缃爱知县,是日/眧缃AWV女牲、写实时间的遗梦到哪里去了?这是最大的追忆,当大多数人都在拼命地往前看时,我却总是在...

大贯杏里(大貫杏里)材料

大贯杏里(大贯杏里)材料 大贯杏里,日文名:大贯杏里、おおぬきあんり,英文名:Anri Oonuki,年0月0日死亡于法国巴黎,是日/眧缃AWV女牲,0年0月入行,从属于プレステージ公司,喜好音乐、写实。 大贯杏 里(大贯杏里)材料 中文名...

大野步(大野歩)全副番号大全及图片封面

大野步(大野歩)全副番号大全及图片封面 0年大野步(大野歩)全副作品文章番号 人の极上性肉奴隷市场 MXSPS- / 0-0- この竞泳水着がスゴい! MXSPS- / 0-0- 雌猿 大野歩 MXGS- / 0-0- 高画质0本番 MXB...

大野步(大野歩)材料

大野步(大野歩)材料 大野步,日文名:大野歩、おおのあゆみ,英文名:No Ratings Yet,0在烧蓝阶段,珐琅釉料已变成玻璃态物质,在约650摄氏度左右即呈现软化,具有必定流动性。因此,在800摄氏度左右的高温炉中熔烧釉料,铜胎不会变...

天津破首例海军案,16人的团队涉险金额高度超800万

天津破首例海军案,16人的团队涉险金额高度超800万 海军某个词能够很多网友都没有生疏,实在随着互联网络的停滞和提高,海军某个职业也是应运而生,并且近多少年做海军的更是越来越多了兴起。近来,天津市就对准于这一度状况做成.. 海军某个词能够很...

天海丽简介

天海丽简介 天海丽,日文名:あまみれい,英文名:ReiAmami,年0月日死亡于日/眧缃静岗县,是日/眧缃AWV女牲,身体玲珑小巧,眼睛柔情似水,气质污浊浓艳,风格大胆泼辣。00年入行,0年引退。天海丽刚刚入行就赢得满堂彩,占有很高的气质美...

天海翼(天海つばさ)材料

天海翼(天海つばさ)材料 天海翼,日文名:天海つばさ、あまみつばさ,英文名:Amami Tsubasa,年0月0日死亡于日/眧 缃广岛县,是日/眧缃AWV女牲,00年0月0日入行,从属于名东公司,喜好陪宠物玩。天海翼是日/眧缃超人气女牲,组...

天羽茧(天羽繭)材料

天羽茧(天羽茧)材料 天羽茧,日文名:天羽茧、てんばまゆ,英文名:Mayu Tenba,年0月0日死亡于日/眧缃神奈川县,是日/ 眧缃AWV女牲,0年0月年终总结不仅关系到你的年终奖和未来的晋升机会,更是对你一年工作的回顾和反思,让你对自己...

天衣美津(天衣みつ-泷泽美铃)材料

天衣美津(天衣みつ/泷泽美铃)材料 天衣美津,日文名:天衣みつ、あまいみつ,英文名:Mitsu Amai,日月日死亡于日/眧缃东京都,是日/眧缃AWV女牲,00年入行,0年引退。天衣美津又所谓天衣蜜、泷泽美铃,天衣美津长得无比纯洁,她有一双...

天衣萌香材料

天衣萌香材料 天衣萌香,日文名:あまいもか,英文名:Amai Moka,年0月0日死亡于日/眧缃东京都,是日/眧缃AWV女牲、调酒师,0年0月0日入行,从属于メディアステーション公司,喜好逛雀巢咖啡店、鸡尾酒。 天衣萌香材料 中文名:天衣萌...