// 从文本域解析图片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 ) ); } 赵磻老的诗代表作欣赏-番剧百科
好东西要分享

赵磻老的诗代表作欣赏

赵磻老是宋代妇孺皆知的诗人,至今流传的诗词大约有18首, 赵磻老的诗代表很多,今天分享一些优美的赵磻老的诗大全。

《鹧鸪天·堂上年时见烛花》

催召传,稳铺沙。罍尊今日枣如瓜。
诞辰更接传柑宴,莲炬通宵唤草麻。

《鹧鸪天·白日青天一旦明》

千万载,辅宗祊。擎天八柱愈峥嵘。
将军犁却龙庭后,岁傍龟山奏太平。

《浣溪沙》

貂蝉懒上头,渭水知何处。
风月共垂竿,脱帽须亲付。

《生查子》

漉酒未巾时,暑槛披风处。
子夏不兼人,并与诗筒付。

《生查子》

金门一免时,离绪纷如缕。想像切云高,晓日罗昏雾。峨冠补衮人,不是无心处。欲效贡公弹,衣钵知谁付。

《生查子》

斜日下平川,楼角销霞缕。摆尽浊尘缨,画栋萦非雾。平生许子穷,今到知音处。约伴玉簪游,好梦从天付。

《念奴娇·冰蟾驾月》

冰蟾驾月,荡寒光、不见层波层碧。几岁中秋争得似,云卷秋声寂寂。多谢星郎,来陪贤令,快赏鳌峰极。广寒宫近,素娥不靳余力。
夜久露落琼浆,神京归路,有云翘前迹。当日仙人曾驭气,只学神交龟息。今夜清尊,一齐分付,稳是乘槎客。天津重到,霓裳何似闻笛。

《南柯子/南歌子》<

/h2>

世上渊明酒,人间陆羽茶。东山无妓有莲花。隐隐仙家鸡犬、路非赊。积霭犹张幕,轻雷似卷车。要令长袖舞胡靴。须是檐头新霁、鹊查查。

《南柯子/南歌子》

体质娟娟静,花纹细细装。翠筠初得试新忙。睡起鬓云撩乱、趣泉汤。多病心常捧,新词字带香。管教涂泽到云窗。办下谢君言语、巧如簧。

《醉蓬莱·听都人歌咏》

听都人歌咏,便启金瓯,再登元老。山色溪声,与春风齐到。补衮工夫,望梅心绪,见丹青重好。鹊噪晴空,灯迎诞节,槐堂欢笑。
正是元宵,满天和气,璧月流光,雪消寒峭。今夜今年,表千年同照。万象森罗,一奁清莹,影山河多少。玉烛调新,彩眉常喜,寰瀛春晓。

《醉蓬莱·记青蛇感异》

记青蛇感异,后日扶颠,太平人瑞。壮岁弹冠,有经邦高志。晚上文墀,载严霜简,便云能交际。紫极旋枢,金蝉映衮,乾坤开霁。
底事当时,饮江胡马,一望云旗,倒戈投贽。此片丹心,几风声鹤唳。烟息尘收,水明山丽,只五湖相记。今夜华灯,火城信息,千年荣贵。

《永遇乐·香雪堆梅》

香雪堆梅,绣丝蹙柳,仙馆春到。午夜华灯,烘春艳粉,月借今宵好。衮衣摇曳,簪缨闲绕,共祝大椿难老。望台躔、明星一点,冰壶表里相照。诞弥令节,欣欣物态,共喜重生周召。八鼎勋庸,九夷姓字,策杖孤鸿杳。鸦啼鹊噪,兰馨松茂,把酒共春一笑。管如今、盐梅再梦,夜铃命诏。

相关推荐

  • 暂无文章

评论 抢沙发

评论前必须登录!