Zu近在使用pbootcms进行建站,现有的标签不符合自己的一些业务需求,想着自己做个符合自己的业务的标签,于是参考了一下网上的资料以后便开始着手开发了,整个二开还是比较简单,下面放出来需要修改的文件.
apps/home/controller/ParserController.php 解析标签的类
1)在parserAfter方法中新增一行解析入口
$content = $this->parserTitleReplaceLabel($content);
01 |
public function parserAfter( $content ) |
04 |
$content = str_replace ( '{pboot:pagetitle}' , $this ->config( 'other_title' ) ?: '{pboot:sitetitle}-{pboot:sitesubtitle}' , $content ); |
05 |
$content = str_replace ( '{pboot:pagekeywords}' , '{pboot:sitekeywords}' , $content ); |
06 |
$content = str_replace ( '{pboot:pagedescription}' , '{pboot:sitedescription}' , $content ); |
07 |
$content = str_replace ( '{pboot:keyword}' , get( 'keyword' , 'vars' ), $content ); |
10 |
if ( file_exists (APP_PATH . '/home/controller/ExtLabelController.php' )) { |
11 |
if ( class_exists ( 'apphomecontrollerExtLabelController' )) { |
12 |
$extlabel = new ExtLabelController(); |
13 |
$content = $extlabel ->run( $content ); |
17 |
$content = $this ->parserSiteLabel( $content ); |
18 |
$content = $this ->parserCompanyLabel( $content ); |
19 |
$content = $this ->parserMemberLabel( $content ); |
20 |
$content = $this ->parserNavLabel( $content ); |
21 |
$content = $this ->parserSelectAllLabel( $content ); |
22 |
$content = $this ->parserSelectLabel( $content ); |
23 |
$content = $this ->parserSpecifySortLabel( $content ); |
24 |
$content = $this ->parserListLabel( $content ); |
25 |
$content = $this ->parserSpecifyContentLabel( $content ); |
26 |
$content = $this ->parserContentPicsLabel( $content ); |
27 |
$content = $this ->parserContentCheckboxLabel( $content ); |
28 |
$content = $this ->parserContentTagsLabel( $content ); |
29 |
$content = $this ->parserSlideLabel( $content ); |
30 |
$content = $this ->parserLinkLabel( $content ); |
31 |
$content = $this ->parserMessageLabel( $content ); |
32 |
$content = $this ->parserFormLabel( $content ); |
33 |
$content = $this ->parserSubmitFormLabel( $content ); |
34 |
$content = $this ->parserSqlListLabel( $content ); |
36 |
$content = $this ->parserQrcodeLabel( $content ); |
37 |
$content = $this ->parserPageLabel( $content ); |
38 |
$content = $this ->parserIfLabel( $content ); |
39 |
$content = $this ->parserLoopLabel( $content ); |
40 |
$content = $this ->restorePreLabel( $content ); |
41 |
$content = $this ->parserReplaceKeyword( $content ); |
42 |
$content = $this ->parserTitleReplaceLabel( $content ); |
|
2)添加对应的解析方法(写在上述文件的Zui后一个}前面)
03 |
public function parserTitleReplaceLabel( $content ) |
05 |
$pattern = '/{pboot:titlereplace(s+[^}]+)?}/' ; |
07 |
if (preg_match_all( $pattern , $content , $matches )) { |
08 |
$count = count ( $matches [0]); |
09 |
for ( $i = 0; $i < $count ; $i ++) { |
10 |
$params = $this ->parserParam( $matches [0][ $i ]); |
12 |
foreach ( $params as $key => $value ) { |
20 |
$data = titlereplace( $data ); |
24 |
$content = str_replace ( $matches [0][ $i ], $data , $content ); |
|
apps/common/function.php 文件Zui后面替换方法titlereplace()在这里写
1 |
function titlereplace( $data ){ |
3 |
$search = array ( '?' , '?' , ' ' , '%' , ',' ); |
4 |
return str_replace ( $search , "_" , $data ); |
|
前端使用标签的地方
我的需求其实是在news.html也就是新闻中文章末尾添加一个自定义图片(根据标题生成一张图片,因为生成图片的方法不能包含特殊符号所以需要把标题中的特殊符号尤其是?去掉)
{pboot:titlereplace title='{content:title}’}
其中{pboot:titlereplace title='{content:title}’}便是我要新增的标签,title这个属性是在上面的parserTitleReplaceLabel方法中进行case判断用的