zoukankan      html  css  js  c++  java
  • dedecms 频道标签 channel.lib.php的分析

      1 <?php
      2 /**
      3  * 获取栏目列表标签
      4  *
      5  * @version        $Id: channel.lib.php 1 9:29 2010年7月6日Z tianya $
      6  * @package        DedeCMS.Taglib
      7  * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
      8  * @license        http://help.dedecms.com/usersguide/license.html
      9  * @link           http://www.dedecms.com
     10  */
     11  
     12 /*>>dede>>
     13 <name>频道标签</name>
     14 <type>全局标记</type>
     15 <for>V55,V56,V57</for>
     16 <description>用于获取栏目列表</description>
     17 <demo>
     18 {dede:channel type='top' row='8' currentstyle="<li><a href='~typelink~' class='thisclass'>~typename~</a> </li>"} 
     19  <li><a href='[field:typelink/]'>[field:typename/]</a> </li> 
     20 {/dede:channel}
     21 </demo>
     22 <attributes>
     23     <iterm>typeid:栏目ID</iterm> 
     24     <iterm>reid:上级栏目ID</iterm>
     25     <iterm>row:调用栏目数</iterm>
     26     <iterm>col:分多少列显示(默认为单列)</iterm>
     27     <iterm>type:son表示下级栏目,self表示同级栏目,top顶级栏目</iterm>
     28     <iterm>currentstyle:应用样式</iterm>
     29 </attributes> 
     30 >>dede>>*/
     31  
     32 function lib_channel(&$ctag,&$refObj)
     33 {
     34     global $dsql;//连接数据库
     35 
     36     $attlist = "typeid|0,reid|0,row|100,col|1,type|son,currentstyle|,cacheid|";//设置标签属性
     37     FillAttsDefault($ctag->CAttribute->Items,$attlist);//设置标签属性
     38     extract($ctag->CAttribute->Items, EXTR_SKIP);//设置标签属性
     39     $innertext = $ctag->GetInnerText();//$ctag->GetInnerText获得当前底层模板的内容
     40     $line = empty($row) ? 100 : $row;//如果当前标签没有设置row属性 则默认显示100条数据
     41     
     42     $likeType = '';
     43     //读取固定的缓存块
     44     $cacheid = trim($cacheid);
     45     if($cacheid !='') {
     46         $likeType = GetCacheBlock($cacheid);
     47         if($likeType != '') return $likeType;
     48     }
     49 
     50     $reid = 0;
     51     $topid = 0;
     52     //如果属性里没指定栏目id,从引用类里获取栏目信息
     53     if(empty($typeid))
     54     {
     55         if( isset($refObj->TypeLink->TypeInfos['id']) )
     56         {
     57             $typeid = $refObj->TypeLink->TypeInfos['id'];
     58             $reid = $refObj->TypeLink->TypeInfos['reid'];
     59             $topid = $refObj->TypeLink->TypeInfos['topid'];
     60         }
     61         else {
     62           $typeid = 0;
     63       }
     64     }
     65     //如果指定了栏目id,从数据库获取栏目信息
     66     else
     67     {
     68         $row2 = $dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id='$typeid' ");
     69         $typeid = $row2['id'];
     70         $reid = $row2['reid'];
     71         $topid = $row2['topid'];
     72         $issetInfos = true;
     73     }
     74     
     75     if($type=='' || $type=='sun') $type='son';
     76     if($innertext=='') $innertext = GetSysTemplets("channel_list.htm");
     77 
     78     if($type=='top')
     79     {
     80         $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
     81           From `#@__arctype` WHERE reid=0 And ishidden<>1 order by sortrank asc limit 0, $line ";
     82     }
     83     else if($type=='son')
     84     {
     85         if($typeid==0) return '';
     86         $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
     87           From `#@__arctype` WHERE reid='$typeid' And ishidden<>1 order by sortrank asc limit 0, $line ";
     88     }
     89     else if($type=='self')
     90     {
     91         if($reid==0) return '';
     92         $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
     93             FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
     94     }
     95     //And id<>'$typeid'
     96     $needRel = false;
     97     $dtp2 = new DedeTagParse();
     98     $dtp2->SetNameSpace('field','[',']');
     99     $dtp2->LoadSource($innertext);
    100     //检查是否有子栏目,并返回rel提示(用于二级菜单)
    101     if(preg_match('#:rel#', $innertext)) $needRel = true;
    102     
    103     if(empty($sql)) return '';
    104     $dsql->SetQuery($sql);
    105     $dsql->Execute();
    106     
    107     $totalRow = $dsql->GetTotalRow();
    108     //如果用子栏目模式,当没有子栏目时显示同级栏目
    109     if($type=='son' && $reid!=0 && $totalRow==0)
    110     {
    111         $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
    112             FROM `#@__arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
    113         $dsql->SetQuery($sql);
    114       $dsql->Execute();
    115     }
    116     $GLOBALS['autoindex'] = 0;
    117     for($i=0;$i < $line;$i++)
    118     {
    119         if($col>1) $likeType .= "<dl>\r\n";
    120         for($j=0; $j<$col; $j++)
    121         {
    122             if($col>1) $likeType .= "<dd>\r\n";
    123             if($row=$dsql->GetArray())
    124             {
    125                 $row['sonids'] = $row['rel'] = '';
    126                 if($needRel)
    127                 {
    128                     $row['sonids'] = GetSonIds($row['id'], 0, false);
    129                     if($row['sonids']=='') $row['rel'] = '';
    130                     else $row['rel'] = " rel='dropmenu{$row['id']}'";
    131                 }
    132                 //处理同级栏目中,当前栏目的样式
    133                 if( ($row['id']==$typeid || ($topid==$row['id'] && $type=='top') ) && $currentstyle!='' )
    134                 {
    135                     $linkOkstr = $currentstyle;
    136                     $row['typelink'] = GetOneTypeUrlA($row);
    137                     $linkOkstr = str_replace("~rel~",$row['rel'],$linkOkstr);
    138                     $linkOkstr = str_replace("~id~",$row['id'],$linkOkstr);
    139                     $linkOkstr = str_replace("~typelink~",$row['typelink'],$linkOkstr);
    140                     $linkOkstr = str_replace("~typename~",$row['typename'],$linkOkstr);
    141                     $likeType .= $linkOkstr;
    142                 }
    143                 else
    144                 {
    145                     $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
    146                     if(is_array($dtp2->CTags))
    147                     {
    148                         foreach($dtp2->CTags as $tagid=>$ctag)
    149                         {
    150                             if(isset($row[$ctag->GetName()])) $dtp2->Assign($tagid,$row[$ctag->GetName()]);
    151                         }
    152                     }
    153                     $likeType .= $dtp2->GetResult();
    154                 }
    155             }
    156             if($col>1) $likeType .= "</dd>\r\n";
    157             $GLOBALS['autoindex']++;
    158         }
    159         //Loop Col
    160         if($col>1)
    161         {
    162             $i += $col - 1;
    163             $likeType .= "    </dl>\r\n";
    164         }
    165     }
    166     //Loop for $i
    167     $dsql->FreeResult();
    168     if($cacheid !='') {
    169         WriteCacheBlock($cacheid, $likeType);
    170     }
    171     return $likeType;
    172 }
  • 相关阅读:
    凤凰网CEO刘爽称鄙视微博连说20个屁示不齿
    科技创业网站
    梦想,在路上
    小本创业
    rails relevent
    MBA = married but available
    把UTF8编码转换为GB2312编码[转]
    FSFS和VDFS存储方式的区别
    如何让phpmyadmin输入密码再进入
    dede后台登陆后一片空白的解决办法汇总
  • 原文地址:https://www.cnblogs.com/saw2012/p/2772968.html
Copyright © 2011-2022 走看看