<!DOCTYPE html><html mip> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"><link rel="stylesheet" type="text/css" href="/d/file/202012/3frl03uqsdt440.html" ></mip-img><script src="/d/file/202012/h55ugozn0qx441.html"></mip-img>我增加了一個函數(shù),在include 里面的extend.func.php 下。這個應(yīng)該所有的php后臺都是試用的
function replaceurl($content){//$pattern = "/<img(.*?)src=('|")([^>]*).(bmp|gif|jpeg|jpg|png)('|")(.*?)>/i";$pattern="/<img.*?src=['|"](.*?(?:[.gif|.jpg|.jpeg]|.png]|.bmp]))['|"].*?[/]?>/";preg_match_all($pattern, $content,$matches);$full_img = $matches[0];$full_src = $matches[1];foreach ($full_img as $k => $v) {$v1 = str_replace("<img", "<mip-img", $v);$v1 = str_replace("/>", "></mip-img>", $v1);$v1 = str_replace('src="/ueditor','src="/ueditor',$v1);$new_path = $url.$full_src[$k];$v1 = str_replace($full_src[$k], $new_path, $v1);$content = str_replace($v, $v1, $content);}return $content;}后面又研究了下,如果是用的織夢的編輯器,就會產(chǎn)生style,于是我又弄了另外一個然后織夢調(diào)用主體內(nèi)容 {dede:field.body function='replaceurl(@me)'/} 執(zhí)行了下函數(shù)替換了img標簽。
function replaceurl($content){$pattern = Array("/<img(.*?)src=('|")([^>]*).(bmp|gif|jpeg|jpg|png)('|")(.*?)>/i","/style=(.*?)>/i");$replacement = Array("<mip-img popup src=$2$3.$4$2></mip-img>",">");$content = preg_replace($pattern, $replacement, $content);return $content; }這個的話就直接把style去掉了,好歹解決了吧!推薦用下面這個。
style標簽去除
我們在里面會更改字的樣子,就會產(chǎn)生style,又得替換
1function replaceurl($content){$pattern = Array("/<img(.*?)src=('|")([^>]*).(bmp|gif|jpeg|jpg|png)('|")(.*?)>/i","/style=(.*?)>/i");$replacement = Array("<mip-img popup src=$3.$4></mip-img>",">");$content = preg_replace($pattern, $replacement, $content);return $content;}還是一樣主體內(nèi)容 {dede:field.body function='replaceurl(@me)'/} 這樣調(diào)用,具體如果還需要詳細的話可以更改里面的正則表達式
不去掉文章style
比較麻煩,網(wǎng)上看見的,沒測試是否可行,可以自行研究下,大概就是提取body里面的style生成class然后再調(diào)用到頭部去
因為我的并沒有用多少style所以懶搞的了。
(1)、找到include/arc.archives.class.php,找到函數(shù)ReplaceKeyword($kw,&$body),大概1182行,在這個函數(shù)后面添加如下2個函數(shù):
function replacePicUrl($content = null, $url="") {$pattern = "/<img(.*?)src=('|")([^>]*).(bmp|gif|jpeg|jpg|png)('|")(.*?)>/i";$replacement = "<mip-img src={$url}$3.$4></mip-img>";$content = preg_replace($pattern, $replacement, $content);return $content;}function getStyle($content = null){preg_match_all("/style=('|")([^'"]+)('|")/",$content,$matches);$styles = $matches[0];$styles_value = $matches[2];$style_custom = "";$i = 0;foreach($styles_value as $key){$style_custom .= ".class".$i."{".$key."}";$class_name = 'class="class'.$i.'"';$replacements = $class_name;$patterns = $styles[$i];$content = str_replace($patterns, $replacements, $content);$i++;}$res['style_custom'] = $style_custom;$res['content'] = $content;return $res;}$this->SplitTitles = Array();上面,(2)在函數(shù)ParAddTable()里的
unset($row);下面,大概253行添加如下代碼:
$content = $this->replacePicUrl($this->Fields['body'], $GLOBALS['cfg_basehost']);$content_arr = $this->getStyle($content); $this->Fields['body'] = $content_arr['content'];$this->Fields['style_custom'] = $content_arr['style_custom'];(3)、找到函數(shù)MakeHtml($isremote=0),大概358行,在里面的
$this->Fields['filename'] = empty($this->Fields['filename'])? '' : $this->Fields['filename'];下面添加如下代碼:
$this->Fields['style_custom'] = empty($this->Fields['style_custom'])? '' : $this->Fields['style_custom'];(4)、在templete的article_article.htm模板中的head標簽內(nèi)添加如下代碼:<style mip-custom>{dede:field.custom_style/}</style>文章內(nèi)鏈更換
注明:內(nèi)鏈請勿填寫絕對地址,還是在上面2、3的方法里面改,還是增加一個變量正則,然后替換。www.lol9.cn
function replaceurl($content){$pattern = Array("/<img(.*?)src=('|")([^>]*).(bmp|gif|jpeg|jpg|png)('|")(.*?)>/i","/style=(.*?)>/i",'/<ab[^>]+bhref="([^"]*)"[^>]*>/i');$replacement = Array("<mip-img popup src=/$3.$4></mip-img>",">",'<a data-type="mip" href=http://mip.lol9.cn$1>');$content = preg_replace($pattern, $replacement, $content);return $content;}文章文檔關(guān)鍵詞鏈接更換
如果你用了織夢自帶的關(guān)鍵字加鏈接,在核心》批量維護》文檔關(guān)鍵詞維護里面,那么就要替換成絕對地址與增加mip鏈接格式
打開include/arc.archives.class.php 文件 ,大概在1219行,在變量$key_url前面加上自己的鏈接,與href前面加上 data-type=mip
1$query = "SELECT * FROM dede_keywords WHERE rpurl<>'' ORDER BY rank DESC";$this->dsql->SetQuery($query);$this->dsql->Execute();while($row = $this->dsql->GetArray()){$key = trim($row['keyword']);$key_url=trim($row['rpurl']);$karr[] = $key;$kaarr[] = "<a data-type=mip href='http://mip.lol9.cn$key_url'><u>$key</u></a>";}
新聞熱點
疑難解答
圖片精選