happyxp 发表于 2020-8-11 17:42:19

UEditor百度编辑器微信公众号图片本地化

经常遇到要转载微信公众号上发布的文章,文字复制了,但是图片在微信服务器上就出出现无法显示的问题,迫切需要本地化。尝试过多种办法,分享一种简单可行的办法,对编辑器稍微加以修改即可。1、找到文件core\extend\ueditor\php\ction_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、找到文件core\extend\ueditor\php\Uploader.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,清理本地缓存,复制——粘贴,试试看本地化了没有?
页: [1]
查看完整版本: UEditor百度编辑器微信公众号图片本地化