phpcms v9採集中遇到的相對路徑的問題

一、採集網址時,遇上網址是相對路徑的問題。(網上抄的,可用)

修改數據庫v9_collection_node,增加兩個字段replace_from,replace_to(varchar(200)) 

1、 /phpcms/modules/collection/templates/node_form.tpl.php第99行後增加(位置在</table></fieldset>之前) 

<tr> 

<td width="120">網址替換:</td> 

<td> 

<input type="text" name="data[replace_from]" style="width:250px" value="<?php if(isset($data['replace_from'])) echo $data['replace_from']?>"/>替換爲 

<input type="text" name="data[replace_to]" style="width:250px" value="<?php if(isset($data['replace_to'])) echo $data['replace_to']?>"/> 

</td> 

</tr> 

2、 /phpcms/modules/collection/classes/collection.class.php第177行後增加(位置在:$html = str_replace(array("</a>", "</A>"), "</a> ", $html);之後) 

if(!empty($config['replace_from'])){ 

$html = str_replace($config['replace_from'], $config['replace_to'], $html);} 

3、 進入數據庫給 數據庫名_collection_node 增加字段:replace_from 和 replace_to 兩個字段。字數50-100都可以。 

然後在採集管理中我們能看到有替換網址的選項啦。將多餘的../之類的替換掉就行了。


二、採集內容頁中包含相對路徑的問題。(原創)

修改phpcms/modules/collection/classes/collection.class.php中get_content方法

在return $data;前面加入2行代碼

$data=str_replace('./','',$data);//這句把所有./去掉

$data=str_replace('http://qxj.nanjing.gov.cn/xwzx/qxyw_1',dirname($url),$data);

//這句把錯誤的地址替換爲正確地址。其中http://qxj.nanjing.gov.cn/xwzx/qxyw_1這個地址是我的地址,記得換哦。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章