{"id":3171,"date":"2019-11-16T14:15:56","date_gmt":"2019-11-16T06:15:56","guid":{"rendered":"https:\/\/www.baishitou.cn\/?p=3171"},"modified":"2019-11-16T15:18:54","modified_gmt":"2019-11-16T07:18:54","slug":"%e7%bb%87%e6%a2%a6dedecms%e6%96%87%e7%ab%a0%e5%86%85%e5%ae%b9%e5%9b%be%e7%89%87img%e8%bd%acmip-img","status":"publish","type":"post","link":"https:\/\/www.baishitou.cn\/3171.html","title":{"rendered":"\u7ec7\u68a6DEDECMS\u6587\u7ae0\u5185\u5bb9\u56fe\u7247img\u8f6cmip-img"},"content":{"rendered":"

\u7ec7\u68a6DEDECMS\u6587\u7ae0\u5185\u5bb9\u56fe\u7247img\u8f6cmip-img\u7684\u65b9\u6cd5<\/p>\n

\u65b9\u6cd5\u4e00<\/h2>\n

\u6b64\u65b9\u6cd5\u529f\u80fd\u5c31\u662f\u5355\u4e00\u628aIMG\u8f6c\u6210mip-img\u3002<\/p>\n

\u6253\u5f00\/include\/extend.func.php\uff0c\u5728\u6700\u4e0b\u9762\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801 \uff1a<\/p>\n

function mipBody($body)\r\n{\r\n$body = str_replace(' style=\"white-space:pre\"', '', $body);\r\npreg_match_all('\/<img (.*?)\\>\/', $body, $images);\r\nif (!is_null($images)) {\r\nforeach ($images[1] as $index => $value) {\r\n$mip_img = str_replace('<img', '<mip-img', $images[0][$index]);\r\n$mip_img = str_replace('>', '><\/mip-img>', $mip_img);\r\n$mip_img = preg_replace('\/(width|height)=\"\\d*\"\\s\/', '', $mip_img);\r\n$mip_img = preg_replace('\/ style=\\\".*?\\\"\/', '', $mip_img);\r\n$mip_img = preg_replace('\/ class=\\\".*?\\\"\/', '', $mip_img);\r\n$body = $content = str_replace($images[0][$index], $mip_img, $body);\r\n}\r\n}\r\nreturn $body;\r\n}<\/code><\/pre>\n

\"\"<\/a><\/p>\n

\u5185\u5bb9\u8c03\u7528\uff1a<\/p>\n

{dede:field name='body' function='mipBody(@me)'\/}<\/code><\/pre>\n

\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n

\"\"<\/a><\/p>\n

\u65b9\u6cd5\u4e8c<\/h2>\n

\u6b64\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u4ee5\u4e0b\u529f\u80fd<\/p>\n

1\u3001\u628a<img \u66ff\u6362\u6210 <mip-img
\n2\u3001width|height \u53bb\u9664\u56fe\u7247\u5bbd\u9ad8
\n3\u3001style \u53bb\u9664\u5185\u8054\u6837\u5f0f
\n4\u3001\/uploads\/ \u76f8\u5bf9\u8def\u5f84\u56fe\u7247\u8def\u5f84\u66ff\u6362\u6210\u7edd\u5bf9\u8def\u5f84<\/p>\n

\/**\r\n *  MIP\u6587\u7ae0\u5185\u5bb9\u9875\u56fe\u7247\u9002\u914d\u767e\u5ea6MIP\u89c4\u8303\r\n *\r\n * @access    public\r\n * @param     string  $content  \t\u6587\u7ae0\u5185\u5bb9\r\n * @return    string\r\n *\/\r\nfunction mip($content){\r\n\tglobal $cfg_basehost;\r\n    preg_match_all('\/<img (.*?)\\>\/', $content, $images);\r\n    if(!is_null($images)) {\r\n        foreach($images[1] as $index => $value){\r\n            $mip_img = str_replace('<img', '<mip-img', $images[0][$index]);\r\n            $mip_img = str_replace('>', '><\/mip-img>', $mip_img);\r\n            $mip_img = preg_replace('\/(width|height)=\"\\d*\"\\s\/', '', $mip_img );\r\n            $mip_img = preg_replace('\/ style=\\\".*?\\\"\/', '',$mip_img);\r\n            $content = str_replace($images[0][$index], $mip_img, $content);\r\n        }\r\n    }\r\n    preg_match_all('\/ style=\\\".*?\\\"\/', $content, $style);\r\n    if(!is_null($style)) {\r\n        foreach($style[0] as $index => $value){\r\n            $mip_style = preg_replace('\/ style=\\\".*?\\\"\/', '',$style[0][$index]);\r\n            $content = str_replace($style[0][$index], $mip_style, $content);\r\n        }\r\n    }\r\n\t$content = str_replace('\/uploads\/', $cfg_basehost.'\/uploads\/', $content);\r\n    return $content;  \r\n}<\/code><\/pre>\n

\u5185\u5bb9\u9875\u8c03\u7528\uff1a<\/p>\n

{dede:field.body function=mip(@me)\/}<\/code><\/pre>\n

 <\/p>\n

 <\/p>\n","protected":false},"excerpt":{"rendered":"

\u7ec7\u68a6DEDECMS\u6587\u7ae0\u5185\u5bb9\u56fe\u7247img\u8f6cmip-img\u7684\u65b9\u6cd5 \u65b9\u6cd5\u4e00 \u6b64\u65b9\u6cd5\u529f\u80fd\u5c31\u662f\u5355\u4e00\u628aIMG\u8f6c\u6210mip-im […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[43,1080,180],"class_list":["post-3171","post","type-post","status-publish","format-standard","hentry","category-web","tag-dedecms","tag-mip-img","tag-180"],"_links":{"self":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/posts\/3171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/comments?post=3171"}],"version-history":[{"count":0,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/posts\/3171\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/media?parent=3171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/categories?post=3171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/tags?post=3171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}