织梦mip改造
前2天接了個織夢改造mip,之前沒怎么接觸過織夢,mip也沒怎么接觸過,這里記錄下改造過程,其實需要改造的地方不多。
首先頁面改造:
按照mip標(biāo)準(zhǔn):
? ? ? ?1、需要給html標(biāo)簽加上mip,即:<html mip>
? ? ? ?2、字符集統(tǒng)一為utf-8
? ? ? ?3、需要meta:?<meta name="viewport" content="width=device-width,initial-scale=1">
? ? ? ?4、引入mip樣式支持和javascript支持:<link rel="stylesheet" type="text/css" href="https://mipcache.bdstatic.com/static/v1/mip.css" >
<script src="https://mipcache.bdstatic.com/static/v1/mip.js" ></script >
? ? ? ?5、head標(biāo)簽中引入 <link rel="canonical" href="http(s)://xxx" > xxx代表原來的網(wǎng)站,如果只有手機端頁面,那么這個href就是當(dāng)前頁面就可以了,如果還有電腦端的頁面,那這個href可以指向電腦端的頁面
? ? ? ?6、其他的就按照mip標(biāo)準(zhǔn)套, 其實大部分還是修改img標(biāo)簽為mip-img,a標(biāo)簽可以不用修改, 還是樣式不能直接用style=寫在標(biāo)簽上了,如果實在需要在當(dāng)前頁寫css,需要在頭部添加<style mip-custom></style>
程序改造:
程序需要改造的地方有2個:
1、分頁: 找到include/arc.listview.class.php里的GetPageListDM($list_len,$listitem="index,end,pre,next,pageno"),大概在981行,在這個函數(shù)里面添加:
$typeDir = str_replace('{cmspath}', '', $this->Fields['typedir']);
然后在有href=的地方添加:.$GLOBALS['cfg_basehost']."/".$typeDir."/"
完整鏈接如:
if($this->PageNo != 1)
? ? ? ? {
? ? ? ? ? ? $prepage.="<li><a href='".$GLOBALS['cfg_basehost']."/".$typeDir."/".str_replace("{page}",$prepagenum,$tnamerule)."'>上一頁</a></li>\r\n";
? ? ? ? ? ? $indexpage="<li><a href='".$GLOBALS['cfg_basehost']."/".$typeDir."/".str_replace("{page}",1,$tnamerule)."'>首頁</a></li>\r\n";
? ? ? ? }
if($this->PageNo!=$totalpage && $totalpage>1)
? ? ? ? {
? ? ? ? ? ? $nextpage.="<li><a href='".$GLOBALS['cfg_basehost']."/".$typeDir."/".str_replace("{page}",$nextpagenum,$tnamerule)."'>下一頁</a></li>\r\n";
? ? ? ? ? ? $endpage="<li><a href='".$GLOBALS['cfg_basehost']."/".$typeDir."/".str_replace("{page}",$totalpage,$tnamerule)."'>末頁</a></li>\r\n";
? ? ? ? }
到此,分頁改造完畢。
2、內(nèi)容改造比較復(fù)雜:
(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;
? ? }
(2)、在函數(shù)ParAddTable()里的$this->SplitTitles = Array();上面,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標(biāo)簽內(nèi)添加如下代碼:
<style mip-custom>
? {dede:field.custom_style/}
? </style>
(5)、最后一步,到后臺:核心-頻道模型-內(nèi)容模型管理列表找到普通文章,并點擊編輯,進入字段管理并添加字段custom_style,表示從內(nèi)容編輯器中提取出來的樣式,選多行文本。
到此,織夢簡單改造mip已完成,但是mip對js有限制,目前還沒有比較完善的文檔,對于評論那塊以后研究下mip的js再想辦法。最后記住,a標(biāo)簽的href和mip-img的src都需要完整地址,包括域名。
總結(jié)
- 上一篇: c++汉字字符处理
- 下一篇: 第一次软件工程作业(One who wa