当前位置:网站首页>External information capture of edusoho enterprise training edition sometimes can't get pictures. Problem / can't get pictures of wechat official account
External information capture of edusoho enterprise training edition sometimes can't get pictures. Problem / can't get pictures of wechat official account
2022-07-18 08:59:00 【My sweet】


Some website pictures cannot be quoted by other websites , At this time, the best thing is image localization . Then change the edition
modify src/AppBundle/Controller/Admin/ArticleController.php Code
modify createFromUrlAction Method . Add two new methods saveImage,processImages
Add reference to header use Topxia\Service\Common\ServiceKernel;
public function createFromUrlAction(Request $request)
{
// If carrying url Parameters , Try to identify url Information of the corresponding page
$url = $request->query->get('url');
$isSafeDoman = $this->isSafeDoman($url);
$article = ['title' => '', 'body' => ''];
if ($url) {
$url = urldecode($url);
$readability = new Readability(new Configuration());
$html = file_get_contents($url);
try {
$readability->parse($html);
$article['title'] = $readability->getTitle();
$article['body'] = $this->processImages($readability->getContent());
$article['sourceUrl'] = $url;
$article['thumb'] = $this->saveImage($readability->getImage());
$article['originalThumb'] = $this->saveImage($readability->getImage());
} catch (ParseException $e) {
// echo sprintf('Error processing text: %s', $e->getMessage());
}
}
if ('POST' == $request->getMethod()) {
$formData = $request->request->all();
$article['tags'] = array_filter(explode(',', $formData['tags']));
$article = $this->getArticleService()->createArticle($formData);
$attachment = $request->request->get('attachment');
$this->getUploadFileService()->createUseFiles($attachment['fileIds'], $article['id'], $attachment['targetType'], $attachment['type']);
return $this->redirect($this->generateUrl('admin_article'));
}
$categoryTree = $this->getCategoryService()->getCategoryTree();
return $this->render('admin/article/article-from-url-modal.html.twig', [
'url' => $url,
'article' => $article,
'categoryTree' => $categoryTree,
'category' => ['id' => 0, 'parentId' => 0],
'isSafeDoman' => $isSafeDoman,
]);
}
public function saveImage($image){
$smallPath = ServiceKernel::instance()->getParameter('topxia.upload.public_directory').'/tmp/';
$imageContent = file_get_contents($image);
$name = time().rand(0,time()).".png";
file_put_contents($smallPath.$name,$imageContent);
return "tmp/".$name;
}
public function processImages($content){
$matched = preg_match_all('/<img (.*?) src="(.*?)"/', $content, $matches);
$images = $matches[2];
foreach ($images as $image){
$content = str_replace($image, "/files/".$this->saveImage($image), $content);
}
$matched = preg_match_all('/<img (.*?) data-src="(.*?)"/', $content, $matches2);
foreach ($matches2[2] as $image){
$content = str_replace($image, "/files/".$this->saveImage($image), $content);
}
$content = str_replace('data-src', "src", $content);
return $content;
}That's it

边栏推荐
- [leetcode binary tree -- maximum path sum] 124 Maximum path sum in binary tree
- 【LeetCode】11. Lowest Common Ancestor of a Binary Search Tree· 二叉搜索树的最近公共祖先
- Laravel reports an error: requires ext DOM * - > the requested PHP extension DOM is missing from your system
- (2021牛客多校三)J-Counting Triangles(思维)
- [2023 school recruitment questions] column planning (non final presentation status, for bloggers' personal reference)
- (codeforce453) A.little pony and expected maximum (mathematical expectation)
- iNFTnews | NFT門票將改變參與活動的方式
- 解读机器人编程课的示教准则
- 【2023校招刷题】专栏规划(非最终展现状态,供博主个人查阅)
- GET 请求和 POST 请求的区别与使用示例
猜你喜欢

Huawei's general card identification function enables multiple card bindings with one key
![[leetcode weekly -- string] 6114 Move the clip to get the string](/img/2f/1efd4d88d2ea3db5dfb77ff9887ba4.png)
[leetcode weekly -- string] 6114 Move the clip to get the string

【集训DAY2】Cinema ticket【组合数学】【卡特兰数】

这个国产编辑器,即将开源!

【集训DAY3】 Reconstruction of roads【SPFA】

实现有效的机器人教育培训管理模式

无需训练代码,推理性能提升1.4~7.1倍,业界首个自动模型压缩工具开源

Event 4624 is login successful!?! Is that true?

Codeforces Round #583 (Div. 1 + Div. 2) - A, D, E

九联科技开发板正式合入OpenHarmony主干
随机推荐
【LeetCode】9. Flood Fill·图像渲染
设置圆形头像--canvas和paint
[leetcode weekly -- string] 6114 Move the clip to get the string
小米摄像头修改wifi
USB驱动开发流程
HMS Core图形图像技术展现最新功能和应用场景,加速构建数智生活
【集训DAY1】Maximum benefit【离散化】【贪心】
MySQL中KEY、PRIMARY KEY、UNIQUE KEY、INDEX 的区别
ROS (25): release a static odometer Odom information
使用EventLog Analyzer进行实时用户会话跟踪
Leetcode 151. Invert words in string
HMS Core图形图像技术展现最新功能和应用场景,加速构建数智生活
Rendering and cloud rendering: 25% of the production time of a movie is "waiting"
九联科技开发板正式合入OpenHarmony主干
Laravel reports an error: requires ext DOM * - > the requested PHP extension DOM is missing from your system
[Halcon] WriteImage保存图像崩溃问题
VBA drives SAP GUI to complete initialization of interface element value
Chinese garbled code caused by Grails
(codeforce1699)A&B (构造)
PCIe knowledge point-011: relationship between PCIe configuration capability structure and protocol version