织梦上传图片样式代码修改

时间:2019-11-05 15:06 / 来源:ChinaZ / 作者:酱油 / 点击:

关于SEO的朋友当然知道百度MIP,这里不多做介绍。因为个人一直喜欢FCK编辑器,所以这里提及就是FCK编辑器。

使用FCK编辑,上传图片的效果如下图


<img src="/uploads/allimg/191105/1_191105151101_1.jpg" width="500" border="0" height="500" alt="" styleb="cursor:pointer" onclick="window.open('/uploads/allimg/191105/1_191105151101_1.jpg')" /><br />

加入我们所需要的效果如下

<img src="/uploads/allimg/191105/1_191105151101_1.jpg" width="500" border="0" height="500" alt="" /><br />

有两种方法修改,第一,include/extend.func.php,添加如下代码(以下代码仅举例,根据实际情况修改)

function mipBody($body)
{
$body = str_replace(' style="white-space:pre"', '', $body);
preg_match_all('/<img (.*?)\>/', $body, $images);
if (!is_null($images)) {
foreach ($images[1] as $index => $value) {
$mip_img = str_replace('<img', '<mip-img', $images[0][$index]);
$mip_img = str_replace('>', '></mip-img>', $mip_img);
$mip_img = preg_replace('/(width|height)="\d*"\s/', '', $mip_img);
$mip_img = preg_replace('/ style=\".*?\"/', '', $mip_img);
$mip_img = preg_replace('/ class=\".*?\"/', '', $mip_img);
$body = $content = str_replace($images[0][$index], $mip_img, $body);
}
}
preg_match_all('/<a (.*?)>/', $body, $imagess);
if (!is_null($imagess)) {
foreach ($imagess[1] as $index => $value) {
$mip_imgs = str_replace('<a href', '<a data-type="mip" href"', $imagess[0][$index]);
$body = $content = str_replace($imagess[0][$index], $mip_imgs, $body);
}
}
return $body;
}

第二种方法,直接修改上传文件,\include\FCKeditor\editor\dialog\dede_image.php,找到如下代码

if($cfg_remote_site=='Y' && $remoteuploads == 1)
     {
          $imgsrcValue = $remoteupUrl.$imgsrcValue;
          $urlValue = $remoteupUrl.$urlValue;
          $imgHtml .=  "<img src=\"$imgsrcValue\" width=\"$imgwidthValue\" border=\"0\" height=\"$imgheightValue\" alt=\"$altname\" stylea=\"cursor:pointer\" onclick=\"window.open('$urlValue')\" /><br />\r\n";
     } else {
            if($cfg_multi_site=='N')
            {
                $imgHtml .=  "<img src=\"$imgsrcValue\" width=\"$imgwidthValue\" border=\"0\" height=\"$imgheightValue\" alt=\"$altname\" styleb=\"cursor:pointer\" onclick=\"window.open('$urlValue')\" /><br />\r\n";
            }
            else
            {
                if(empty($cfg_basehost)) $cfg_basehost = 'http://'.$_SERVER["HTTP_HOST"];
                $imgHtml .=  "<img src=\"imgsrcValue\" alt=\"$altname\" />\r\n";
            }
      }
          
        if($alttitle==1 && !empty($altname)) {
            $imgHtml .= "$altname<br />\r\n";
        }
          
    }
}

根据实际情况修改,但是这里有一个问题,那就是cfg_multi_site(系统参数,是否打开绝对链接),根据Y/N来修改即可,第二种方法只适合FCK编辑器,第一种方法依葫芦画瓢。

猜你喜欢

推荐栏目

DEDECMS
DEDECMS

DEDE使用经验和技巧

WordPress
Wordpress

WP使用经验和技巧

Zblog
Zblog

Zblog使用经验和技巧

CSS
CSS

CSS使用经验和技巧

网络资料
网络资料

转载实用网络资料

按键伤人
按键伤人

转载乱七八糟的网络资源

我是酱油
我是酱油

随笔札记 记录生活点滴

本站推荐

百度站内搜索

专业博客主机