您现在的位置是:首页 > 教程 > pbootcms教程pbootcms教程

PbootCMS后台编辑器微信公众号图片本地化的实现方法

翠萱2025-02-25 21:35:16pbootcms教程已有5人查阅

导读为了实现PbootCMS后台编辑器将微信公众号上的图片本地化,可以按照你提供的方法进行修改。以下是详细的步骤和修改内容:1. 修改 coreextendueditor/phpction_crawler.php 文件

为了实现PbootCMS后台编辑器将微信公众号上的图片本地化,可以按照你提供的方法进行修改。以下是详细的步骤和修改内容:
1. 修改 coreextendueditor/phpction_crawler.php 文件原始代码
/* 抓取远程图片 */
$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)
));
}
2. 修改 coreextendueditor/php/Uploader.class.php 文件原始代码
private function saveRemote() {
$imgUrl = htmlspecialchars($this->fileField);
$imgUrl = str_replace("&", "&", $imgUrl);
}
修改后的代码
private function saveRemote() {
$imgUrl = htmlspecialchars($this->fileField);
$imgUrl = str_replace("&", "&", $imgUrl);
// 增加对微信图片的判断
if (strpos($imgUrl, '网址') !== false) {
$newstr = strtolower(strrchr($imgUrl, '?'));
$imgUrl = str_replace($newstr, '.jpg', $imgUrl);
}
}
3. 清理缓存并测试
清理缓存:确保清理浏览器缓存,以确保加载的是较新的代码。
测试:复制微信公众号的文章并粘贴到PbootCMS后台编辑器中,查看图片是否成功本地化。

本文标签:

很赞哦! (0)

暂无内容
暂无内容
暂无内容
暂无内容
留言与评论 (共有 0 条评论)
昵称:
匿名发表 登录账号
         
验证码: