Plugin Directory

Changeset 3420609


Ignore:
Timestamp:
12/16/2025 02:59:30 AM (4 months ago)
Author:
infility
Message:

v2.14.42 (20251216) Ben: 导入产品抓取网页产品时,html图片转换成本地图片

Location:
infility-global/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • infility-global/trunk/infility_global.php

    r3419855 r3420609  
    44Plugin URI: https://www.infility.cn/
    55Description: Infility公共插件
    6 Version: 2.14.41
     6Version: 2.14.42
    77Author: Infility
    88Author URI: https://www.infility.cn/
     
    142142    function __construct()
    143143    {
    144         define( 'INFILITY_GLOBAL_VERSION', '2.14.41' );
     144        define( 'INFILITY_GLOBAL_VERSION', '2.14.42' );
    145145        define( 'INFILITY_GLOBAL_PATH', plugin_dir_path( __FILE__ ) ); // fullpath/wp-content/plugins/infility-global/ // 有斜杠
    146146        define( 'INFILITY_GLOBAL_URL', plugins_url( '/', __FILE__ ) ); // https://the_domain/wp-content/plugins/infility-global/ // 斜杠是自己加的
  • infility-global/trunk/widgets/infility-import-data/include/infility-import-site.php

    r3397907 r3420609  
    793793    }
    794794
    795     public function replace_image_src($html,$site,$post_id){
    796         $dom = new \DOMDocument();
     795    public function replace_image_src($html,$site='',$post_id = 0){
     796        $dom = new \DOMDocument('1.0', 'UTF-8');
     797
    797798        // 加载HTML内容,第二个参数设置为true,以避免将HTML当作HTML实体处理
    798         @$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
     799        @$dom->loadHTML('<?xml encoding="utf-8" ?>'.$html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
    799800        // 移除不需要的空白节点,可选步骤,但有助于清理DOM结构
    800801        $dom->normalize();
    801802
    802803        $imgs = $dom->getElementsByTagName('img');
    803         foreach ($imgs as $img) {
    804             $src = $img->getAttribute('src');
    805             if(empty($src)){continue;}
    806             $src = $this->format_link($src,$site);
    807             $attach_id = $this->add_image_to_media_library($src,$post_id);
    808             $image_url = wp_get_attachment_url($attach_id);
    809             if(!$image_url){continue;}
    810             $img->setAttribute('src', $image_url);// 修改img标签的src属性
     804        if(!empty($imgs->length) && $imgs->length>0){
     805            foreach ($imgs as $img) {
     806                $src = $img->getAttribute('src');
     807                if(empty($src)){continue;}
     808                $src = $this->format_link($src,$site);
     809                $attach_id = $this->add_image_to_media_library($src,$post_id);
     810                $image_url = wp_get_attachment_url($attach_id);
     811                if(!$image_url){continue;}
     812                $img->setAttribute('src', $image_url);// 修改img标签的src属性
     813            }
    811814        }
    812815
     
    815818    }
    816819
    817     public function format_link($link,$site){
     820    public function format_link($link,$site=''){
    818821        $parsed_url = parse_url($link);
    819822        if(!isset($parsed_url['host'])){
     
    12751278            $attach_id = $this->add_image_to_media_library($data);
    12761279            $format_value = $attach_id;
     1280        }else if($type=='wysiwyg'){
     1281            if(is_array($data)){
     1282                $format_value = '';
     1283                foreach($data as $k=>$v){
     1284                    $format_value .= $this->replace_image_src($v,'').PHP_EOL;
     1285                }
     1286            }else{
     1287                $format_value = $this->replace_image_src($data,'');
     1288            }
    12771289        }else{
    12781290            if(is_array($data)){
Note: See TracChangeset for help on using the changeset viewer.