QQ咨询 官方微信

添加微信好友

官方小程序

百度小程序

微信小程序

头条小程序

关于我们

PHPCMS

phpcms v9实现对组图采集并本地化保存

 admin  2022-06-03 19:31:07
phpcms对图片采集一直不是很好,更不要说对组图采集了,关于修复phpcms无法采集https网站图片的问题可参考:https://www.pweb123.com/cms/zhcms/phpcms/show_770.html,下面来说一下具体怎么实现对组图的采集
(1)给数据库v9_collection_node表增加两个字段:pictureurls_rule和pictureurls_html_rule类型分别是char(100)和text

(2)找到\phpcms\modules\collection\templates\node_form.tpl.php文件大致216行的</fieldset>在此后边添加代码:
  1. <fieldset> 
  2.     <legend><a href="javascript:void(0)" onclick="$(this).parent().parent().children('table').toggle()"><?php echo L('pictureurls').L('rule')?></a></legend> 
  3.     <table width="100%" class="table_form" style="display:none"
  4.         <tr> 
  5.             <td width="120"><?php echo L('matching_rule')?>:</td>  
  6.             <td> 
  7.             <textarea rows="5" cols="40" name="data[pictureurls_rule]" id="pictureurls_rule"><?php if(isset($data['pictureurls_rule'])) echo $data['pictureurls_rule']?></textarea> <br><?php echo L('use')?>"<a href="javascript:insertText('content_rule''<?php echo L('[content]')?>')"><?php echo L('[content]')?></a>"<?php echo L('w_wildmenu')?> 
  8.             </td> 
  9.             <td width="120"><?php echo L('filtering')?>:</td>  
  10.             <td> 
  11.             <textarea rows="5" cols="50" name="data[pictureurls_html_rule]" id="pictureurls_html_rule"><?php if(isset($data['pictureurls_html_rule'])) echo $data['pictureurls_html_rule']?></textarea> 
  12.             <input type="button" value="<?php echo L('select')?>" class="button"  onclick="html_role('data[pictureurls_html_rule]')"
  13.             </td> 
  14.         </tr> 
  15.     </table> 
  16. </fieldset> 
(注意上面javascript:void(0)中间的冒号改成英文的)
由于上面代码用到了L('pictureurls')所以需要对phpcms\languages\zh-cn\collection.lang.php里增加代码:
  1. $LANG['pictureurls'] = '组图'
(3)找到phpcms\modules\collection\node.php大概471行把:
  1. $node_field = array(''=>L('please_choose'),'title'=>L('title'), 'author'=>L('author'), 'comeform'=>L('comeform'), 'time'=>L('time'), 'content'=>L('content')); 
改成:
  1. $node_field = array(''=>L('please_choose'),'title'=>L('title'), 'author'=>L('author'), 'comeform'=>L('comeform'), 'time'=>L('time'), 'content'=>L('content'), 'pictureurls'=>L('pictureurls')); 

(4)找到phpcms\modules\collection\classes\collection.class.php的第61行,在获取内容判断下边新增代码用于获取组图:
  1. //获取组图 
  2.             if ($config['pictureurls_rule']) { 
  3.                 $author_rule =  self::replace_sg($config['pictureurls_rule']); 
  4.                 $data['pictureurls'] = self::replace_item(self::cut_html($html, $author_rule[0], $author_rule[1]), $config['pictureurls_html_rule']); 
  5.                 $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png|\.bmp|\.jpeg]))[\'|\"].*?[\/]?>/"
  6.                 preg_match_all($pattern,$data['pictureurls'],$data['pictureurls']); 
  7.                 $pictureurls_list = $data['pictureurls'][0]; 
  8.                 $data['pictureurls'] =  array2string($pictureurls_list); 
  9.             } 
  10.              
  11.             //下载组图中的图片到本地 
  12.             if (!empty($data['pictureurls']) && !empty($pictureurls_list) && $config['down_attachment'] == 1) { 
  13.                  
  14.                 pc_base::load_sys_class('attachment','',0); 
  15.                 $attachment = new attachment('collection','0',get_siteid()); 
  16.                 $data['pictureurls'] = array();//清空重新赋值用 
  17.                 $array = $temp = array(); 
  18.                 $reg = '/<img.*?src=[\'"](.*?)[\'"]/i'
  19.                 foreach($pictureurls_list as $key => $pic){ 
  20.                     $tmp = $attachment->download('pictureurls', $pic,$config['watermark']); 
  21.                     preg_match_all($reg , $tmp , $results); 
  22.                     $fullpic = parse_url($results[1][0]); 
  23.                     $temp['url'] = $results[1][0]; 
  24.                     $temp['alt'] = end(explode('/', $fullpic['path'])); 
  25.                     $array[$key] = $temp; 
  26.                  
  27.                 } 
  28.                 $data['pictureurls'] = array2string($array,JSON_FORCE_OBJECT); 
  29.             } 

(5)找到phpcms\modules\content\fields\content_input.class.php找到:
  1. if(method_exists($this, $func)) $value = $this->$func($field, $value); 
改成:
  1. if(method_exists($this, $func)){ 
  2.             if($func == 'images' && $isimport){ 
  3.                 //采集的时候不对组图字段做处理 
  4.             }else
  5.                $value = $this->$func($field, $value); 
  6.             } 
  7.         }; 
修改好之后 一定要记得更新一下缓存,否则没效果!


测试效果如下:



¥ 打赏
×
如果您觉得文章帮助了您就打赏一下吧
非常感谢你的打赏,我们将继续分享更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

本文《phpcms v9实现对组图采集并本地化保存》发布于石头博客文章,作者:admin,如若转载,请注明出处:https://www.pweb123.com/cms/phpcms/771.html,否则禁止转载,谢谢配合!

文章点评

我来说两句 已有1条评论
点击图片更换
默认站点网友 2019-05-22 01:23:04
回复 支持0
文章不错非常喜欢

添加微信好友

添加微信好友

微信小程序

百度小程序