【網(wǎng)頁(yè)圖片加速】PbootCMS自動(dòng)替換圖片地址為七牛云cdn鏡像鏈接
1、configconfig.php里增加:(注意前一行需要以逗號(hào)結(jié)尾,默認(rèn)官方版本無(wú)逗號(hào)需要自行加上)
// cdn鏈接地址,http(s)://img.xxx.com,尾巴不帶“/”,單獨(dú)調(diào)用{pboot:cdnurl} 'cdn_url' => '',
2、appshomecontrollerParserController.php里搜索function adjustLabelData,在其下方增加:
// 自動(dòng)替換圖片鏈接 @mk-cdn if ($cdn_url = $this->config('cdn_url')) { if (strpos($data,$cdn_url)===false) { $src_ori_file = ROOT_PATH . $data; $out_cdn_file = rtrim($cdn_url,'/') . $data; if (! file_exists($out_cdn_file) && file_exists($src_ori_file) && $out_cdn_file!=rtrim($cdn_url,'/')) { $data = $out_cdn_file; } } }
3、appshomecontrollerParserController.php里搜索{pboot:pageurl},在其下方增加:
$content = str_replace('{pboot:cdnurl}', rtrim($this->config('cdn_url'),'/'), $content); // 單獨(dú)cdn地址調(diào)用標(biāo)簽 @mk-cdn
4、appshomecontrollerIndexController.php里搜索$this->getContent($data),在其上方增加:
// 編輯器圖片加cdn @mk-cdn if ($cdn_url = Config::get('cdn_url')) { $data->content = str_replace('="/static/upload/', '="'.rtrim($cdn_url,'/').'/static/upload/', $data->content); }
2021-07-26更新補(bǔ)充
經(jīng)測(cè)試發(fā)現(xiàn)如果前臺(tái)圖片做了裁剪cdn替換圖片地址會(huì)失效,因此還要做以下調(diào)整。
1、打開(kāi)appshomecontrollerParserController.php
2、找到$maxheight = isset($params['maxheight']) ? $params['maxheight'] : null;下面增加一行
if ($cdn_url) $data = str_replace(rtrim($cdn_url,'/'), '', $data);
3、在這個(gè)判斷if (! file_exists($max_out_file) && file_exists($max_src_file)) {結(jié)束的下一行增加
if ($cdn_url && file_exists($max_out_file)) { if (strpos($data,$cdn_url)===false) { $out_cdn_file_2 = rtrim($cdn_url,'/') . $data; if (! file_exists($out_cdn_file_2) && file_exists($max_out_file) && $out_cdn_file_2!=rtrim($cdn_url,'/')) { $data = $out_cdn_file_2; } } }
4、找到$height = isset($params['height']) ? $params['height'] : null;下面增加一行
if ($cdn_url) $data = str_replace(rtrim($cdn_url,'/'), '', $data);
5、在這個(gè)判斷if (! file_exists($out_file) && file_exists($src_file)) {結(jié)束的下一行增加
if ($cdn_url && file_exists($out_file)) { if (strpos($data,$cdn_url)===false) { $out_cdn_file_3 = rtrim($cdn_url,'/') . $data; if (! file_exists($out_cdn_file_3) && file_exists($out_file) && $out_cdn_file_3!=rtrim($cdn_url,'/')) { $data = $out_cdn_file_3; } } }
2021-08-23 單頁(yè)編輯器替換補(bǔ)充
打開(kāi)appshomecontrollerIndexController.php,找到function getAbout后,
$content = $this->parser->parserAfter($content); // CMS公共標(biāo)簽后置解析
把上面代碼下方增加:
// 編輯器圖片加cdn @mk-cdn if ($cdn_url = Config::get('cdn_url')) { $content = str_replace('="/static/upload/', '="'.rtrim($cdn_url,'/').'/static/upload/', $content); }
效果截圖:
如果您的問(wèn)題還未解決可以聯(lián)系站長(zhǎng)付費(fèi)協(xié)助。

有問(wèn)題可以加入技術(shù)QQ群一起交流學(xué)習(xí)
本站vip會(huì)員 請(qǐng)加入無(wú)憂模板網(wǎng) VIP群(50604020) PS:加入時(shí)備注用戶名或昵稱(chēng)
普通注冊(cè)會(huì)員或訪客 請(qǐng)加入無(wú)憂模板網(wǎng) 技術(shù)交流群(50604130)
客服微信號(hào):15898888535
聲明:本站所有文章資源內(nèi)容,如無(wú)特殊說(shuō)明或標(biāo)注,均為采集網(wǎng)絡(luò)資源。如若內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系站長(zhǎng)刪除。