魔扣论坛

魔扣源码论坛业务
查看: 472|回复: 1

[织梦教程] 织梦CMS改造mip教程

[复制链接]
  • TA的每日心情
    奋斗
    18 小时前
  • 签到天数: 2959 天

    [LV.Master]开坛老将

    7万

    主题

    227

    回帖

    27万

    积分

    管理员

    Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30

    魔扣币
    745823
    贡献
    157923
    威望
    32799

    最佳新人活跃会员热心会员推广达人宣传达人突出贡献优秀版主荣誉管理论坛元老

    发表于 2020-8-13 22:19:24 | 显示全部楼层 |阅读模式
    魔扣币兑换比例:【 50以下 : ¥1 = 10 魔扣币 】丨【 50 - 100 :¥1 = 20 魔扣币】丨【 100以上:¥1 = 30 魔扣币 】

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    页面整体结构改造

    <!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="https://c.mipcdn.com/static/v1/mip.css">
    <script src="/dist/js/jquery.js" type="application/json" async></script>
    <style mip-custom>
    样式
    </style>
        </head>
        <body>
    <mip-img layout="responsive" src="[!--news.url--]dist/img/logo.png" ></mip-img>
    <script src="https://c.mipcdn.com/static/v1/mip.js"></script>
        </body>
    </html>

    mip规范结构大致如上代码,具体的就自行修改。

    mip图片改造
    图片的格式需要换成<mip-img layout="responsive" src="/st/images/logo-b.png"></mip-img>

    我增加了一个函数,在include 里面的extend.func.php 下。这个应该所有的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;
    }

    后面又研究了下,如果是用的织梦的编辑器,就会产生style,于是我又弄了另外一个然后织梦调用主体内容 {dede:field.body function='replaceurl(@me)'/} 执行了下函数替换了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标签去除
    我们在里面会更改字的样子,就会产生style,又得替换

    function 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;
    }

    还是一样主体内容 {dede:field.body function='replaceurl(@me)'/}  这样调用,具体如果还需要详细的话可以更改里面的正则表达式

    不去掉文章style
    比较麻烦,网上看见的,没测试是否可行,可以自行研究下,大概就是提取body里面的style生成class然后再调用到头部去

    因为我的并没有用多少style所以懒搞的了。

    (1)、找到include/arc.archives.class.php,找到函数ReplaceKeyword($kw,&$body),大概1182行,在这个函数后面添加如下2个函数:

    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)在函数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)、找到函数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标签内添加如下代码:
    <style mip-custom>
    {dede:field.custom_style/}
    </style>

    文章内链更换
    注明:内链请勿填写绝对地址,还是在上面2、3的方法里面改,还是增加一个变量正则,然后替换。www.adminbuy.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://www.adminbuy.cn$1>');
    $content = preg_replace($pattern, $replacement, $content);
    return $content;
    }

    文章文档关键词链接更换
    如果你用了织梦自带的关键字加链接,在核心》批量维护》文档关键词维护里面,那么就要替换成绝对地址与增加mip链接格式

    打开include/arc.archives.class.php 文件 ,大概在1219行,在变量$key_url前面加上自己的链接,与href前面加上 data-type=mip

    $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://www.morko.net$key_url'><u>$key</u></a>";
    }

    会员购买:>> 点击购买 << | 魔扣币购买:>> 点击购买 <<
    承接业务:服务器代维丨网站托管丨SEO
    联系客服:微信:morko-net | QQ:1367681973

    该用户从未签到

    1

    主题

    239

    回帖

    479

    积分

    中级魔扣

    Rank: 3Rank: 3

    魔扣币
    239
    贡献
    239
    威望
    0
    发表于 2020-8-13 23:31:09 | 显示全部楼层
    鄙视楼下的顶帖没我快,哈哈
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    • 联系我们
    • 新浪微博 :
    • 在线客服 :魔扣科技 
    • 源码QQ群 :魔扣源码论坛官方总群
    • 联系邮箱 :charlin#morko.net
    • 微信扫一扫
    快速回复 返回顶部 返回列表