日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁編程開發(fā)php教程 → PHP學習之Dedecms自定義標簽介紹

      PHP學習之Dedecms自定義標簽介紹

      相關(guān)軟件相關(guān)文章發(fā)表評論 來源:西西整理時間:2011/4/11 22:33:05字體大。A-A+

      作者:西西點擊:393次評論:0次標簽: Dedecms

      • 類型:源碼相關(guān)大。9.4M語言:中文 評分:3.3
      • 標簽:
      立即下載

      看了PHP和Dedecms有三天了,記錄一下自定義標簽的筆記。

      我拿一個簡單的標簽flink來解釋一下:

      <?php<BR>//檢查是否定義include文件夾的路徑DEDEINC<BR> if(!defined('DEDEINC'))
      {
          exit("Request Error!");
      }
      //寫標簽時,默認調(diào)用的方法
      function lib_flink(&$ctag,&$refObj)
      {<BR>   //聲明全局的數(shù)據(jù)庫連接<BR>   global $dsql;<BR>     //標簽擁有的屬性和默認值<BR>   $attlist="type|textall,row|24,titlelen|24,linktype|1,typeid|0";
          FillAttsDefault($ctag->CAttribute->Items,$attlist);<BR>   //將標簽中的值導入到當前符號表中<BR>   extract($ctag->CAttribute->Items, EXTR_SKIP);
          $totalrow = $row;
          $revalue = '';
         //以下為拼裝SQL查詢語句
          $wsql = " where ischeck >= '$linktype' ";
          if($typeid == 0)
          {
              $wsql .= '';
          }
          else
          {
              $wsql .= "And typeid = '$typeid'";
          }
          if($type=='image')
          {
              $wsql .= " And logo<>'' ";
          }
          else if($type=='text')
          {
              $wsql .= " And logo='' ";
          }
          $equery = "Select * from #@__flink $wsql order by sortrank asc limit 0,$totalrow";
          //檢查標記中是否已經(jīng)包含innertext底層模板
          if(trim($ctag->GetInnerText())=='') $innertext = "<li>[field:link /]</li>";
          else $innertext = $ctag->GetInnerText();
          //設(shè)置查詢條件并執(zhí)行查詢
          $dsql->SetQuery($equery);
          $dsql->Execute();<BR>   //通過循環(huán)獲取查詢的對象<BR>   while($dbrow=$dsql->GetObject())
          {<BR>       if($type=='text'||$type=='textall')
              {
                  $link = "<a href='".$dbrow->url."' target='_blank'>".cn_substr($dbrow->webname,$titlelen)."</a> ";
              }
              else if($type=='image')
              {
                  $link = "<a href='".$dbrow->url."' target='_blank'><img src='".$dbrow->logo."' width='88' height='31' border='0'></a> ";
              }
              else
              {
                  if($dbrow->logo=='')
                  {
                      $link = "<a href='".$dbrow->url."' target='_blank'>".cn_substr($dbrow->webname,$titlelen)."</a> ";
                  }
                  else
                  {
                      $link = "<a href='".$dbrow->url."' target='_blank'><img src='".$dbrow->logo."' width='88' height='31' border='0'></a> ";
                  }
              }<BR>      //對innertext中的字符串進行值替換(暫時不清楚為什么標簽里面的row只是一個數(shù)值,但是卻在這里能成為一個數(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);
              $revalue .= $rbtext;
          }<BR>   //返回替換處理好的字符串<BR>   return $revalue;
      }
      ?>


      如果有讀者對方法的參數(shù)&$ctag,&$refObj不是很清楚,請從index.php中的處理開始查看,具體的應該是在include目錄下的Dedetag.class.php中。

      下面,我們仿照上面的例子自己去寫一個標簽

      <?php
          if (! defined ( 'DEDEINC' )) {
              exit ( "Request Error!" );
          }
          function lib_aaa(&$ctag, &$refObj) 
          {
              global $dsql;
              $attlist = "topid|0,row|10";
              FillAttsDefault ( $ctag->CAttribute->Items, $attlist );
              extract ( $ctag->CAttribute->Items, EXTR_SKIP );
              $condtion="";
              $revalue='';
              if($topid==0)
              {
                  $condtion.=" where topid=0";
              }
              elseif ($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);
              $dsql->Execute();
              while($dbrows=$dsql->GetObject())
              {
                  $rbtext = preg_replace("/\[field:typename([\/\s]{0,})\]/isU",$dbrows->typename, $innertext);
                  $revalue.=$rbtext;
              }
              return $revalue;
          }
      ?>

      上面的代碼比較簡單,在這里就不做解釋了,直接看測試結(jié)果:

      //這個測試不包含innertext,默認輸出應該是<li><BR>{dede:aaa topid='0'row=10}
      {/dede:aaa}

      輸出結(jié)果:

      //自帶的innertext,應該輸出是按照加粗+分割線格式
      {dede:aaa topid='0'row=10}
      <b>[field:typename /]</b><hr />
      {/dede:aaa}

      輸出結(jié)果:

      聲明:本人菜鳥這幾天在學PHP的Dedecms時發(fā)現(xiàn)能用的資料并不是很多,而且關(guān)于自定義標簽的解讀也很少,所以記錄下來,希望出錯的地方大家能提出,幫助我進步!

        相關(guān)評論

        閱讀本文后您有什么感想? 已有人給出評價!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過難過
        • 5 囧
        • 3 圍觀圍觀
        • 2 無聊無聊

        熱門評論

        最新評論

        第 1 樓 遼寧沈陽沈陽建筑大學 網(wǎng)友 客人 發(fā)表于: 2012/4/10 10:12:51
        寫的很好,適合初學者~~

        支持( 0 ) 蓋樓(回復)

        發(fā)表評論 查看所有評論(0)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字數(shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)