ecshop编辑商品,远程图片自动本地化插件,自动上传外链图片

1、admin\templates\goods_info.htm

 {$FCKeditor}下载远程图片和资源 

 

2、 admin\goods.php

    if (empty($_POST['goods_sn'])){  

    }else{

    }

 在这个下面添加代码:

$remote = !empty($_POST['remote']) ? $_POST['remote'] : 0;

 //保存远程资源

if($remote == 'true')

{

$goods_desc = GetContFile($_POST['goods_desc']);

}else{

  $goods_desc = $_POST['goods_desc'];

}

 

3、admin\includes\lib_main.php文件下添加

 

//上传文件保存路径

$cfg_image_dir = ROOT_PATH .'/images';

$cfg_soft_dir  = ROOT_PATH .'/soft';

$cfg_media_dir = ROOT_PATH .'/media';

//获得文章内容里的外部资源

function GetContFile($body)

{

global $cfg_image_dir;

//引入下载类

include_once(ROOT_PATH . 'includes/httpfile/down.class.php');

//初始化变量

$body = stripslashes($body);

$host = 'http://'.$_SERVER['HTTP_HOST'];

//过滤图片文件

$pic_arr = array();

preg_match_all("/src=[\"|'|\s]{0,}(http:\/\/([^>]*)\.(gif|jpg|png|bmp))/isU", $body, $pic_arr);

$pic_arr = array_unique($pic_arr[1]);

//初始化下载类

$htd = new HttpDown();

    foreach($pic_arr as $k=>$v)

    {

        if(preg_match('#'.$host.'#i', $v)) continue;

        if(!preg_match('#^http:\/\/#i', $v)) continue;

        $htd->OpenUrl($v);

        $type = $htd->GetHead('content-type');

        if($type == 'image/gif')

            $tempfile_ext = 'gif';

        else if($type == 'image/png')

            $tempfile_ext = 'png';

        else if($type == 'image/wbmp')

            $tempfile_ext = 'bmp';

        else

            $tempfile_ext = 'jpg';

$upload_url = 'images';

$upload_dir = $cfg_image_dir;

$ymd = date('Ymd');

$upload_url .= '/'.$ymd;

$upload_dir .= '/'.$ymd;

if(!file_exists($upload_dir))

{

mkdir($upload_dir);

$fp = fopen($upload_dir.'/index.htm', 'w');

fclose($fp);

}

//上传文件名称

$filename = time()+rand(1,9999).'.'.$tempfile_ext;

//上传文件路径

$save_url = '../'.$upload_url.'/'.$filename;

//生成本地路径

$self = explode('/', $_SERVER['PHP_SELF']);

$self_size = count($self) - 2;

$self_str  = '';

for($i=0; $i<$self_size; $i++)

{

$self_str .= $self[$i].'/';

}

   $save_url = $self_str.'../'.$upload_url.'/'.$filename;

   $save_dir = $upload_dir.'/'.$filename;

        $rs = $htd->SaveToBin($save_dir);

        if($rs)

        {

            $body = str_replace(trim($v), $save_url, $body);

        }

    }

    $htd->Close();

//回传转义字符串

    return addslashes($body);

}

 

4、这里修改,admin\goods.php

 

    if ($is_insert)

    {

        if ($code == '')

        {

            $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .

                    "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .

                    "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .

                    "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " .

                    "is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, rank_integral, suppliers_id)" .

                "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .

                    "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".

                    "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".

                    "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".

                    " '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', $is_shipping, ".

                    " '$goods_desc', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral', '$suppliers_id')";

        }

        else

        {

            $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .

                    "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .

                    "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .

                    "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, is_real, " .

                    "is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral)" .

                "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .

                    "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".

                    "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".

                    "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".

                    " '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', 0, '$is_on_sale', '$is_alone_sale', $is_shipping, ".

                    " '$goods_desc', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral')";

        }

    }

    else

    {

        

        $sql = "SELECT goods_thumb, goods_img, original_img " .

                    " FROM " . $ecs->table('goods') .

                    " WHERE goods_id = '$_REQUEST[goods_id]'";

        $row = $db->getRow($sql);

        if ($proc_thumb && $goods_img && $row['goods_img'] && !goods_parse_url($row['goods_img']))

        {

            @unlink(ROOT_PATH . $row['goods_img']);

            @unlink(ROOT_PATH . $row['original_img']);

        }

        if ($proc_thumb && $goods_thumb && $row['goods_thumb'] && !goods_parse_url($row['goods_thumb']))

        {

            @unlink(ROOT_PATH . $row['goods_thumb']);

        }

        $sql = "UPDATE " . $ecs->table('goods') . " SET " .

                "goods_name = '$_POST[goods_name]', " .

                "goods_name_style = '$goods_name_style', " .

                "goods_sn = '$goods_sn', " .

                "cat_id = '$catgory_id', " .

                "brand_id = '$brand_id', " .

                "shop_price = '$shop_price', " .

                "market_price = '$market_price', " .

                "is_promote = '$is_promote', " .

                "promote_price = '$promote_price', " .

                "promote_start_date = '$promote_start_date', " .

                "suppliers_id = '$suppliers_id', " .

                "promote_end_date = '$promote_end_date', ";

        

        if ($goods_img)

        {

            $sql .= "goods_img = '$goods_img', original_img = '$original_img', ";

        }

        if ($goods_thumb)

        {

            $sql .= "goods_thumb = '$goods_thumb', ";

        }

        if ($code != '')

        {

            $sql .= "is_real=0, extension_code='$code', ";

        }

        $sql .= "keywords = '$_POST[keywords]', " .

                "goods_brief = '$_POST[goods_brief]', " .

                "seller_note = '$_POST[seller_note]', " .

                "goods_weight = '$goods_weight'," .

                "goods_number = '$goods_number', " .

                "warn_number = '$warn_number', " .

                "integral = '$_POST[integral]', " .

                "give_integral = '$give_integral', " .

                "rank_integral = '$rank_integral', " .

                "is_best = '$is_best', " .

                "is_new = '$is_new', " .

                "is_hot = '$is_hot', " .

                "is_on_sale = '$is_on_sale', " .

                "is_alone_sale = '$is_alone_sale', " .

                "is_shipping = '$is_shipping', " .

                "goods_desc = '$goods_desc', " .

                "last_update = '". gmtime() ."', ".

                "goods_type = '$goods_type' " .

                "WHERE goods_id = '$_REQUEST[goods_id]' LIMIT 1";

    }

商品详情:
{$FCKeditor}下载远程图片和资源
商品详情:
{$FCKeditor}下载远程图片和资源

 

down.class.php代码:https://pan.baidu.com/s/1rBMZ2COP2i6A37FXo2-DCQ

 

没有更多推荐了,返回首页