经常遇到要转载微信公众号上发布的文章,文字复制了,但是图片在微信服务器上就出出现无法显示的问题,迫切需要本地化。

尝试过多种办法,分享一种简单可行的办法,对编辑器稍微加以修改即可。

1、找到文件coreextendueditorphpction_crawler.php文件大约在52行样子。

/* 抓取远程图片 */

$list = array();

if (isset($_POST@[$fieldName])) {

    $source = $_POST@[$fieldName];

} else {

    $source = $_GET@[$fieldName];

}

foreach ($source as $imgUrl) {

    $item = new Uploader($imgUrl, $config, "remote");

    $info = $item->getFileInfo();

    // 图片打水印

    $ext = array(

        '.jpg',

        '.png',

        '.gif'

    );

    if (in_array($info['type'], $ext)) {

        resize_img(ROOT_PATH . $info['url']); // 缩放大小

        watermark_img(ROOT_PATH . $info['url']); // 水印

    }

    array_push($list, array(

        "state" => $info["state"],

        "url" => $info["url"],

        "size" => $info["size"],

        "title" => htmlspecialchars($info["title"]),

        "original" => htmlspecialchars($info["original"]),

        "source" => htmlspecialchars($imgUrl)

    ));

}

修改为

/* 抓取远程图片 */

$list = array();

if (isset($_POST@[$fieldName])) {

    $source = $_POST@[$fieldName];

} else {

    $source = $_GET@[$fieldName];

}

foreach ($source as $imgUrl) {

    $item = new Uploader($imgUrl, $config, "remote");

    $info = $item->getFileInfo();

    // 图片打水印

    $ext = array(

        '.jpg',

        '.png',

        '.gif'

    );

    if (in_array($info['type'], $ext)) {

        resize_img(ROOT_PATH . $info['url']); // 缩放大小

        watermark_img(ROOT_PATH . $info['url']); // 水印

    }

    array_push($list, array(

        "state" => $info["state"],

        "url" => $info["url"],

        "size" => $info["size"],

        "title" => htmlspecialchars($info["title"]),

        "original" => htmlspecialchars($info["original"]),

        "source" => htmlspecialchars_decode($imgUrl)

    ));

}

主要修改的地方:"source" => htmlspecialchars($imgUrl),修改为"source" => htmlspecialchars_decode($imgUrl)。

2、找到文件coreextendueditorphpUploader.class.php(大约)第173行,private function saveRemote()函数。

 $imgUrl = htmlspecialchars($this->fileField);

 $imgUrl = str_replace("&", "&", $imgUrl);

下增加对微信图片的判断。

 $imgUrl = htmlspecialchars($this->fileField);

 $imgUrl = str_replace("&", "&", $imgUrl);

//增加对微信图片的判断

if(strpos($imgUrl,'https://mmbiz.qpic.cn')!==false){

$newstr = strtolower(strrchr($imgUrl,'?'));

$imgUrl = str_replace($newstr,'.jpg',$imgUrl);

}

‘.jpg’可以改为你喜欢的后缀,一般浏览器都能识别的。

到此处over,清理本地缓存,复制——粘贴,试试看本地化了没有?