- 類(lèi)型:源碼相關(guān)大。9.4M語(yǔ)言:中文 評(píng)分:3.3
- 標(biāo)簽:
立即下載
看了PHP和Dedecms有三天了,記錄一下自定義標(biāo)簽的筆記。
我拿一個(gè)簡(jiǎn)單的標(biāo)簽flink來(lái)解釋一下:
<?php<BR>//檢查是否定義include文件夾的路徑DEDEINC<BR> if(!defined('DEDEINC'))
|
//寫(xiě)標(biāo)簽時(shí),默認(rèn)調(diào)用的方法
|
function lib_flink(&$ctag,&$refObj)
|
{<BR> //聲明全局的數(shù)據(jù)庫(kù)連接<BR> global $dsql;<BR> //標(biāo)簽擁有的屬性和默認(rèn)值<BR> $attlist="type|textall,row|24,titlelen|24,linktype|1,typeid|0";
|
FillAttsDefault($ctag->CAttribute->Items,$attlist);<BR> //將標(biāo)簽中的值導(dǎo)入到當(dāng)前符號(hào)表中<BR> extract($ctag->CAttribute->Items, EXTR_SKIP);
|
$wsql = " where ischeck >= '$linktype' ";
|
$wsql .= "And typeid = '$typeid'";
|
$wsql .= " And logo<>'' ";
|
$wsql .= " And logo='' ";
|
$equery = "Select * from #@__flink $wsql order by sortrank asc limit 0,$totalrow";
|
//檢查標(biāo)記中是否已經(jīng)包含innertext底層模板
|
if(trim($ctag->GetInnerText())=='') $innertext = "<li>[field:link /]</li>";
|
else $innertext = $ctag->GetInnerText();
|
$dsql->SetQuery($equery);
|
$dsql->Execute();<BR> //通過(guò)循環(huán)獲取查詢的對(duì)象<BR> while($dbrow=$dsql->GetObject())
|
{<BR> if($type=='text'||$type=='textall')
|
$link = "<a href='".$dbrow->url."' target='_blank'>".cn_substr($dbrow->webname,$titlelen)."</a> ";
|
$link = "<a href='".$dbrow->url."' target='_blank'><img src='".$dbrow->logo."' width='88' height='31' border='0'></a> ";
|
$link = "<a href='".$dbrow->url."' target='_blank'>".cn_substr($dbrow->webname,$titlelen)."</a> ";
|
$link = "<a href='".$dbrow->url."' target='_blank'><img src='".$dbrow->logo."' width='88' height='31' border='0'></a> ";
|
}<BR> //對(duì)innertext中的字符串進(jìn)行值替換(暫時(shí)不清楚為什么標(biāo)簽里面的row只是一個(gè)數(shù)值,但是卻在這里能成為一個(gè)數(shù)組,求解答)<BR> $rbtext = preg_replace("/\[field:url([\/\s]{0,})\]/isU", $row['url'], $innertext);
|
$rbtext = preg_replace("/\[field:webname([\/\s]{0,})\]/isU", $row['webname'], $rbtext);
|
$rbtext = preg_replace("/\[field:logo([\/\s]{0,})\]/isU", $row['logo'], $rbtext);
|
$rbtext = preg_replace("/\[field:link([\/\s]{0,})\]/isU", $link, $rbtext);
|
}<BR> //返回替換處理好的字符串<BR> return $revalue;
|
如果有讀者對(duì)方法的參數(shù)&$ctag,&$refObj不是很清楚,請(qǐng)從index.php中的處理開(kāi)始查看,具體的應(yīng)該是在include目錄下的Dedetag.class.php中。
下面,我們仿照上面的例子自己去寫(xiě)一個(gè)標(biāo)簽
if (! defined ( 'DEDEINC' )) {
|
exit ( "Request Error!" );
|
function lib_aaa(&$ctag, &$refObj)
|
$attlist = "topid|0,row|10";
|
FillAttsDefault ( $ctag->CAttribute->Items, $attlist );
|
extract ( $ctag->CAttribute->Items, EXTR_SKIP );
|
$condtion.=" where topid=0";
|
$condtion.=" where topid <> 0";
|
$equery="select * from `#@__arctype` $condtion";
|
if(trim($ctag->GetInnerText())=='') $innertext = "<li>[field:typename /]</li>";
|
else $innertext = $ctag->GetInnerText();
|
$dsql->SetQuery($equery);
|
while($dbrows=$dsql->GetObject())
|
$rbtext = preg_replace("/\[field:typename([\/\s]{0,})\]/isU",$dbrows->typename, $innertext);
|
上面的代碼比較簡(jiǎn)單,在這里就不做解釋了,直接看測(cè)試結(jié)果:
//這個(gè)測(cè)試不包含innertext,默認(rèn)輸出應(yīng)該是<li><BR>{dede:aaa topid='0'row=10}
|
輸出結(jié)果:
//自帶的innertext,應(yīng)該輸出是按照加粗+分割線格式
|
{dede:aaa topid='0'row=10}
|
<b>[field:typename /]</b><hr />
|
輸出結(jié)果:
聲明:本人菜鳥(niǎo)這幾天在學(xué)PHP的Dedecms時(shí)發(fā)現(xiàn)能用的資料并不是很多,而且關(guān)于自定義標(biāo)簽的解讀也很少,所以記錄下來(lái),希望出錯(cuò)的地方大家能提出,幫助我進(jìn)步!