pbootcms自定義標籤開發_替換標題中的特殊符號
阿新 • • 發佈:2022-03-04
如題:最新在使用pbootcms進行建站,現有的標籤不符合自己的一些業務需求,想著自己做個符合自己的業務的標籤,於是參考了一下網上的資料以後便開始著手開發了,整個二開還是比較簡單,下面放出來需要修改的檔案.
前端使用標籤的地方
我的需求其實是在news.html也就是新聞中文章末尾新增一個自定義圖片(根據標題生成一張圖片,因為生成圖片的方法不能包含特殊符號所以需要把標題中的特殊符號尤其是?去掉)
<!-- 新增圖片_dcx--> <p style="text-align: center;" > <img style="width:450px;" src="http://img.mybancai.cn/{pboot:titlereplace title='{content:title}'}.png" alt="{pboot:titlereplace title='{content:title}'}" > </p>
其中{pboot:titlereplace title='{content:title}'}便是我要新增的標籤,title這個屬性是在下面的parserTitleReplaceLabel方法中進行case判斷用的
ParserController.php 解析標籤的類
1)在parserAfter方法中新增一行解析入口
$content = $this->parserTitleReplaceLabel($content);
public function parserAfter($content) { // 預設頁面資訊替換 $content = str_replace('{pboot:pagetitle}', $this->config('other_title') ?: '{pboot:sitetitle}-{pboot:sitesubtitle}', $content); $content = str_replace('{pboot:pagekeywords}', '{pboot:sitekeywords}', $content); $content = str_replace('{pboot:pagedescription}', '{pboot:sitedescription}', $content); $content = str_replace('{pboot:keyword}', get('keyword', 'vars'), $content); // 當前搜尋的關鍵字 // 解析個人擴充套件標籤,升級不覆蓋 if (file_exists(APP_PATH . '/home/controller/ExtLabelController.php')) { if (class_exists('app\home\controller\ExtLabelController')) { $extlabel = new ExtLabelController(); $content = $extlabel->run($content); } } $content = $this->parserSiteLabel($content); // 站點標籤 $content = $this->parserCompanyLabel($content); // 公司標籤 $content = $this->parserMemberLabel($content); // 會員標籤 $content = $this->parserNavLabel($content); // 分類列表 $content = $this->parserSelectAllLabel($content); // CMS篩選全部標籤解析 $content = $this->parserSelectLabel($content); // CMS篩選標籤解析 $content = $this->parserSpecifySortLabel($content); // 指定分類 $content = $this->parserListLabel($content); // 指定列表 $content = $this->parserSpecifyContentLabel($content); // 指定內容 $content = $this->parserContentPicsLabel($content); // 內容多圖 $content = $this->parserContentCheckboxLabel($content); // 內容多選調取 $content = $this->parserContentTagsLabel($content); // 內容tags調取 $content = $this->parserSlideLabel($content); // 幻燈片 $content = $this->parserLinkLabel($content); // 友情連結 $content = $this->parserMessageLabel($content); // 留言板 $content = $this->parserFormLabel($content); // 自定義表單 $content = $this->parserSubmitFormLabel($content); // 自定義表單提交 $content = $this->parserSqlListLabel($content); // 自定義SQL輸出 $content = $this->parserQrcodeLabel($content); // 二維碼生成 $content = $this->parserPageLabel($content); // CMS分頁標籤解析(需置後) $content = $this->parserIfLabel($content); // IF語句(需置最後) $content = $this->parserLoopLabel($content); // LOOP語句(需置後,不可放到if前面,否則有安全風險) $content = $this->restorePreLabel($content); // 還原不需要解析的內容 $content = $this->parserReplaceKeyword($content); // 頁面關鍵詞替換 $content = $this->parserTitleReplaceLabel($content); // 通用內容替換標籤 這裡是我新增的 return $content; }
function.php 替換方法titlereplace()在這裡寫
function titlereplace($data){ //把? ?都替換為空格 $search = array('?','?',' ','%',','); return str_replace($search, "_", $data); }
效果圖:
參考地址:
http://www.sdjlq.com/jgjwenti/89.html