(1)给数据库v9_collection_node表增加两个字段:pictureurls_rule和pictureurls_html_rule类型分别是char(100)和text
(2)找到phpcmsmodulescollectiontemplatesnode_form.tpl.php文件大致216行的</fieldset>在此后边添加代码:
(注意上面javascript:void(0)中间的冒号改成英文的)
- <fieldset>
- <legend><a href="javascript:void(0)" onclick="$(this).parent().parent().children('table').toggle()"><?php echo L('pictureurls').L('rule')?></a></legend>
- <table width="100%" class="table_form" style="display:none">
- <tr>
- <td width="120"><?php echo L('matching_rule')?>:</td>
- <td>
- <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')?>
- </td>
- <td width="120"><?php echo L('filtering')?>:</td>
- <td>
- <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>
- <input type="button" value="<?php echo L('select')?>" class="button" onclick="html_role('data[pictureurls_html_rule]')">
- </td>
- </tr>
- </table>
- </fieldset>
由于上面代码用到了L('pictureurls')所以需要对phpcmslanguageszh-cncollection.lang.php里增加代码:
(3)找到phpcmsmodulescollectionnode.php大概471行把:
- $LANG['pictureurls'] = '组图';
改成:
- $node_field = array(''=>L('please_choose'),'title'=>L('title'), 'author'=>L('author'), 'comeform'=>L('comeform'), 'time'=>L('time'), 'content'=>L('content'));
- $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)找到phpcmsmodulescollectionclassescollection.class.php的第61行,在获取内容判断下边新增代码用于获取组图:
- //获取组图
- if ($config['pictureurls_rule']) {
- $author_rule = self::replace_sg($config['pictureurls_rule']);
- $data['pictureurls'] = self::replace_item(self::cut_html($html, $author_rule[0], $author_rule[1]), $config['pictureurls_html_rule']);
- $pattern="/<[img|IMG].*?src=['|"](.*?(?:[.gif|.jpg|.png|.bmp|.jpeg]))['|"].*?[/]?>/";
- preg_match_all($pattern,$data['pictureurls'],$data['pictureurls']);
- $pictureurls_list = $data['pictureurls'][0];
- $data['pictureurls'] = array2string($pictureurls_list);
- }
- //下载组图中的图片到本地
- if (!empty($data['pictureurls']) && !empty($pictureurls_list) && $config['down_attachment'] == 1) {
- pc_base::load_sys_class('attachment','',0);
- $attachment = new attachment('collection','0',get_siteid());
- $data['pictureurls'] = array();//清空重新赋值用
- $array = $temp = array();
- $reg = '/<img.*?src=['"](.*?)['"]/i';
- foreach($pictureurls_list as $key => $pic){
- $tmp = $attachment->download('pictureurls', $pic,$config['watermark']);
- preg_match_all($reg , $tmp , $results);
- $fullpic = parse_url($results[1][0]);
- $temp['url'] = $results[1][0];
- $temp['alt'] = end(explode('/', $fullpic['path']));
- $array[$key] = $temp;
- }
- $data['pictureurls'] = array2string($array,JSON_FORCE_OBJECT);
- }
(5)找到phpcmsmodulescontentfieldscontent_input.class.php找到:
改成:
- if(method_exists($this, $func)) $value = $this->$func($field, $value);
修改好之后 一定要记得更新一下缓存,否则没效果!
- if(method_exists($this, $func)){
- if($func == 'images' && $isimport){
- //采集的时候不对组图字段做处理
- }else{
- $value = $this->$func($field, $value);
- }
- };
测试效果如下: