zoukankan      html  css  js  c++  java
  • dedecms讲解-arc.listview.class.php分析,列表页展示

    ./plus/list.php - 动态展示栏目列表页(也可能是频道封面)

    arc.listview.class.php 是dedecms的列表页的相关处理类

    __construct()           // 初始化一些字段,变量
    CountRecord()           // 统计列表记录,总条目数,每页条目数,并对列表模板进行解析
    MakeHtml()              // 创建列表页HTML,主要是后台批量生成
    Display()               // 解析并展示列表页
    MakePartTemplets()      // 创建 '频道封面',或得到 '外部链接' 目录
    DisplayPartTemplets()   // 同上,只是直接展示,不生成
    ParseTempletsFirst()    // 只解析模板中的 include/taglib/* 固定标签
    ParseDMFields()         // 解析模板中的动态字段(list, pagelist, field标签解析)
    GetArcList()            // 获取展示列表详情
    GetPageListST()         // 获取静态分页导航

    GetPageListDM()         // 获取动态分页导航(当列表页是动态页,分页自然也得使用动态链接)

    查看了文件的主要源码,进行了注释,就整个文件黏贴过来了。列表页详情,分页导航方法等方法未做注释

    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. <?php   if(!defined('DEDEINC')) exit('Request Error!');  
    2. /**  
    3.  * 文档列表类  
    4.  *  
    5.  * @version        $Id: arc.listview.class.php 2 15:15 2010年7月7日Z tianya $  
    6.  * @package        DedeCMS.Libraries  
    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. require_once(DEDEINC.'/arc.partview.class.php');  
    12. require_once(DEDEINC.'/ftp.class.php');  
    13.   
    14. helper('cache');  
    15. @set_time_limit(0);  
    16.   
    17. /**  
    18.  * 自由列表类  
    19.  *  
    20.  * @package          ListView  
    21.  * @subpackage       DedeCMS.Libraries  
    22.  * @link             http://www.dedecms.com  
    23.  */  
    24. class ListView  
    25. {  
    26.     var $dsql;  
    27.     var $dtp;  
    28.     var $dtp2;  
    29.     var $TypeID;  
    30.     var $TypeLink;  
    31.     var $PageNo;  
    32.     var $TotalPage;  
    33.     var $TotalResult;  
    34.     var $PageSize;  
    35.     var $ChannelUnit;  
    36.     var $ListType;  
    37.     var $Fields;  
    38.     var $PartView;  
    39.     var $upPageType;  
    40.     var $addSql;  
    41.     var $IsError;  
    42.     var $CrossID;  
    43.     var $IsReplace;  
    44.     var $ftp;  
    45.     var $remoteDir;  
    46.       
    47.     /**  
    48.      *  php5构造函数  
    49.      *  
    50.      * @access    public  
    51.      * @param     int  $typeid  栏目ID  
    52.      * @param     int  $uppage  上一页  
    53.      * @return    string  
    54.      */  
    55.     function __construct($typeid, $uppage=1)  
    56.     {  
    57.         global $dsql,$ftp;  
    58.         $this->TypeID = $typeid;  
    59.         $this->dsql = &$dsql;  
    60.         $this->CrossID = '';  
    61.         $this->IsReplace = false;  
    62.         $this->IsError = false;  
    63.         $this->dtp = new DedeTagParse();  
    64.         $this->dtp->SetRefObj($this);  
    65.         $this->dtp->SetNameSpace("dede", "{", "}");  
    66.         $this->dtp2 = new DedeTagParse();  
    67.         $this->dtp2->SetNameSpace("field","[","]");  
    68.         $this->TypeLink = new TypeLink($typeid);    // 实例化 '栏目链接' 类  
    69.         $this->upPageType = $uppage;  
    70.         $this->ftp = &$ftp;  
    71.         $this->remoteDir = '';  
    72.         $this->TotalResult = is_numeric($this->TotalResult)? $this->TotalResult : "";  
    73.           
    74.         if(!is_array($this->TypeLink->TypeInfos))  
    75.         {  
    76.             $this->IsError = true;  
    77.         }  
    78.         if(!$this->IsError)  
    79.         {  
    80.             $this->ChannelUnit = new ChannelUnit($this->TypeLink->TypeInfos['channeltype']);    // 实例化频道类  
    81.             $this->Fields = $this->TypeLink->TypeInfos;  
    82.             $this->Fields['id'] = $typeid;  
    83.             $this->Fields['position'] = $this->TypeLink->GetPositionLink(true);     // 面包屑导航  
    84.             $this->Fields['title'] = preg_replace("/[<>]/", " / ", $this->TypeLink->GetPositionLink(false));    // 获取页面title  
    85.   
    86.             //设置一些全局参数的值  
    87.             foreach($GLOBALS['PubFields'] as $k=>$v) $this->Fields[$k] = $v;  
    88.             $this->Fields['rsslink'] = $GLOBALS['cfg_cmsurl']."/data/rss/".$this->TypeID.".xml";    // rss订阅,'data/rss/栏目id.xml'  
    89.   
    90.             //设置环境变量  
    91.             SetSysEnv($this->TypeID,$this->Fields['typename'],0,'','list');  
    92.             $this->Fields['typeid'] = $this->TypeID;  
    93.   
    94.             //获得交叉栏目ID  
    95.             /*  
    96.                 cross - 栏目交叉(仅用于 "最终列表栏目"-也就是 "ispart=0")  
    97.                     0 - 不交差  
    98.                     1 - 自动获取同名栏目内容  
    99.                     2 - 手工指定交叉栏目ID(用逗号分开)  
    100.                         会获取一个 'crossid' 表单内容  
    101.              */  
    102.             if($this->TypeLink->TypeInfos['cross']>0 && $this->TypeLink->TypeInfos['ispart']==0)  
    103.             {  
    104.                 $selquery = '';  
    105.                 if($this->TypeLink->TypeInfos['cross']==1)  
    106.                 {  
    107.                     $selquery = "SELECT id,topid FROM `#@__arctype` WHERE typename LIKE '{$this->Fields['typename']}' AND id<>'{$this->TypeID}' AND topid<>'{$this->TypeID}'  ";  
    108.                 }  
    109.                 else  
    110.                 {  
    111.                     $this->Fields['crossid'] = preg_replace('/[^0-9,]/', '', trim($this->Fields['crossid']));  
    112.                     if($this->Fields['crossid']!='')  
    113.                     {  
    114.                         $selquery = "SELECT id,topid FROM `#@__arctype` WHERE id in({$this->Fields['crossid']}) AND id<>{$this->TypeID} AND topid<>{$this->TypeID}  ";  
    115.                     }  
    116.                 }  
    117.                 if($selquery!='')  
    118.                 {  
    119.                     $this->dsql->SetQuery($selquery);  
    120.                     $this->dsql->Execute();  
    121.                     while($arr = $this->dsql->GetArray())  
    122.                     {  
    123.                         $this->CrossID .= ($this->CrossID=='' ? $arr['id'] : ','.$arr['id']);  
    124.                     }  
    125.                 }  
    126.             }  
    127.   
    128.         }//!error  
    129.   
    130.     }  
    131.   
    132.     //php4构造函数  
    133.     function ListView($typeid,$uppage=0){  
    134.         $this->__construct($typeid,$uppage);  
    135.     }  
    136.       
    137.     //关闭相关资源  
    138.     function Close()  
    139.     {  
    140.   
    141.     }  
    142.   
    143.     /**  
    144.      *  统计列表里的记录  
    145.      *  
    146.      * @access    public  
    147.      * @param     string  
    148.      * @return    string  
    149.      */  
    150.     function CountRecord()  
    151.     {  
    152.         /*  
    153.             $cfg_list_son - 栏目是否允许列出下级栏目的内容  
    154.             $cfg_need_typeid2 - 是否启用副栏目  
    155.             $cfg_cross_sectypeid - 支持交叉栏目显示副栏目内容  
    156.          */  
    157.         global $cfg_list_son,$cfg_need_typeid2,$cfg_cross_sectypeid;  
    158.         if(empty($cfg_need_typeid2)) $cfg_need_typeid2 = 'N';  
    159.           
    160.         //统计数据库记录  
    161.         $this->TotalResult = -1;  
    162.         if(isset($GLOBALS['TotalResult'])) $this->TotalResult = $GLOBALS['TotalResult'];  
    163.         if(isset($GLOBALS['PageNo'])) $this->PageNo = $GLOBALS['PageNo'];  
    164.         else $this->PageNo = 1;  
    165.         $this->addSql  = " arc.arcrank > -1 ";  
    166.           
    167.         $typeid2like = " '%,{$this->TypeID},%' ";   // 副栏目,多个之间用 ',' 分隔,采用like查询  
    168.         if($cfg_list_son=='N')  
    169.         {  
    170.               
    171.             if($cfg_need_typeid2=='N')  
    172.             {  
    173.                 if($this->CrossID=='') $this->addSql .= " AND (arc.typeid='".$this->TypeID."') ";  
    174.                 else $this->addSql .= " AND (arc.typeid in({$this->CrossID},{$this->TypeID})) ";  
    175.             }  
    176.             else  
    177.             {  
    178.                 if($this->CrossID=='')   
    179.                 {  
    180.                     $this->addSql .= " AND ( (arc.typeid='".$this->TypeID."') OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like) ";  
    181.                 } else {  
    182.                     if($cfg_cross_sectypeid == 'Y')  
    183.                     {  
    184.                         $typeid2Clike = " '%,{$this->CrossID},%' ";  
    185.                         $this->addSql .= " AND ( arc.typeid IN({$this->CrossID},{$this->TypeID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2Clike)";  
    186.                     } else {  
    187.                         $this->addSql .= " AND ( arc.typeid IN({$this->CrossID},{$this->TypeID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like)";  
    188.                     }  
    189.                 }  
    190.             }  
    191.         }  
    192.         else  
    193.         {  
    194.             $sonids = GetSonIds($this->TypeID,$this->Fields['channeltype']);    // 获得某栏目的所有下级栏目id(递归)  
    195.             if(!preg_match("/,/", $sonids)) {  
    196.                 $sonidsCon = " arc.typeid = '$sonids' ";  
    197.             }  
    198.             else {  
    199.                 $sonidsCon = " arc.typeid IN($sonids) ";  
    200.             }  
    201.             if($cfg_need_typeid2=='N')  
    202.             {  
    203.                 if($this->CrossID=='') $this->addSql .= " AND ( $sonidsCon ) ";  
    204.                 else $this->addSql .= " AND ( arc.typeid IN ({$sonids},{$this->CrossID}) ) ";  
    205.             }  
    206.             else  
    207.             {  
    208.                 if($this->CrossID=='')   
    209.                 {  
    210.                     $this->addSql .= " AND ( $sonidsCon OR CONCAT(',', arc.typeid2, ',') like $typeid2like  ) ";  
    211.                 } else {  
    212.                     if($cfg_cross_sectypeid == 'Y')  
    213.                     {  
    214.                         $typeid2Clike = " '%,{$this->CrossID},%' ";  
    215.                         $this->addSql .= " AND ( arc.typeid IN ({$sonids},{$this->CrossID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2Clike) ";  
    216.                     } else {  
    217.                         $this->addSql .= " AND ( arc.typeid IN ({$sonids},{$this->CrossID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like) ";  
    218.                     }  
    219.                       
    220.                 }  
    221.             }  
    222.         }  
    223.   
    224.         // 获取栏目下的文章总数(使用 'arctiny' 表来进行查询的,该表数据较少,速度更快)  
    225.         if($this->TotalResult==-1)  
    226.         {  
    227.             $cquery = "SELECT COUNT(*) AS dd FROM `#@__arctiny` arc WHERE ".$this->addSql;  
    228.             $row = $this->dsql->GetOne($cquery);  
    229.             if(is_array($row))  
    230.             {  
    231.                 $this->TotalResult = $row['dd'];  
    232.             }  
    233.             else  
    234.             {  
    235.                 $this->TotalResult = 0;  
    236.             }  
    237.         }  
    238.   
    239.         /*  
    240.             获取列表页模板  
    241.          */  
    242.   
    243.         //初始化列表模板,并统计页面总数  
    244.         $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$this->TypeLink->TypeInfos['templist'];  
    245.         $tempfile = str_replace("{tid}", $this->TypeID, $tempfile);  
    246.         $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);  
    247.   
    248.         // 手机版模板(新增了 'm' 目录)  
    249.         if ( defined('DEDEMOB') )  
    250.         {  
    251.             $tempfile =str_replace('.htm','_m.htm',$tempfile);  
    252.         }  
    253.         if(!file_exists($tempfile))  
    254.         {  
    255.             $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/list_default.htm";  
    256.             if ( defined('DEDEMOB') )  
    257.             {  
    258.                 $tempfile =str_replace('.htm','_m.htm',$tempfile);  
    259.             }  
    260.         }  
    261.           
    262.         if(!file_exists($tempfile)||!is_file($tempfile))  
    263.         {  
    264.             echo "模板文件不存在,无法解析文档!";  
    265.             exit();  
    266.         }  
    267.         $this->dtp->LoadTemplate($tempfile);    // 解析模板  
    268.         $ctag = $this->dtp->GetTag("page");     // 获取解析后的 'page标签'  
    269.         if(!is_object($ctag))  
    270.         {  
    271.             $ctag = $this->dtp->GetTag("list"); // page标签不存在,获取 'list标签'  
    272.         }  
    273.   
    274.         // 获取每页条数设置  
    275.         if(!is_object($ctag))  
    276.         {  
    277.             $this->PageSize = 20;  
    278.         }  
    279.         else  
    280.         {  
    281.             if($ctag->GetAtt("pagesize")!="")  
    282.             {  
    283.                 $this->PageSize = $ctag->GetAtt("pagesize");  
    284.             }  
    285.             else  
    286.             {  
    287.                 $this->PageSize = 20;  
    288.             }  
    289.         }  
    290.         $this->TotalPage = ceil($this->TotalResult/$this->PageSize);  
    291.     }  
    292.   
    293.     /**  
    294.      *  列表创建HTML - 应该是后台 '更新栏目HTML'  
    295.      *  
    296.      * @access    public  
    297.      * @param     string  $startpage  开始页面  
    298.      * @param     string  $makepagesize  创建文件数目  
    299.      * @param     string  $isremote  是否为远程  
    300.      * @return    string  
    301.      */  
    302.     function MakeHtml($startpage=1, $makepagesize=0, $isremote=0)  
    303.     {  
    304.         global $cfg_remote_site;  
    305.         if(empty($startpage))  
    306.         {  
    307.             $startpage = 1;  
    308.         }  
    309.   
    310.         //创建封面模板文件  
    311.         /*  
    312.             isdefault - 栏目列表选项  
    313.                 1 - 链接到默认页  
    314.                 0 - 链接到列表第一页  
    315.                 -1 - 使用动态页  
    316.             defaultname - 默认页名称(isdefault=1使用)  
    317.          */  
    318.         if($this->TypeLink->TypeInfos['isdefault']==-1)  
    319.         {  
    320.             echo '这个类目是动态类目!';  
    321.             return '../plus/list.php?tid='.$this->TypeLink->TypeInfos['id'];  
    322.         }  
    323.   
    324.         //单独页面  
    325.         /*  
    326.             ispart - 栏目属性  
    327.                 0 - 最终列表栏目(允许在本栏目发布文档,并生成文档列表)  
    328.                 1 - 频道封面(栏目本身不允许发布文档)  
    329.                 2 - 外部连接(在"文件保存目录"处填写网址)  
    330.          */  
    331.         else if($this->TypeLink->TypeInfos['ispart']>0)  
    332.         {  
    333.   
    334.             // 得到1和2的访问链接地址  
    335.             $reurl = $this->MakePartTemplets();  
    336.             return $reurl;  
    337.         }  
    338.   
    339.         /*  
    340.             现在开始,获取列表页  
    341.          */  
    342.         if(empty($this->TotalResult)) $this->CountRecord();     // 计算列表条目总数,根据每页条目,得到总页数;并解析 '列表模板'  
    343.         //初步给固定值的标记赋值  
    344.         $this->ParseTempletsFirst();    // 调用 'include/channelunit.func.php中的MakeOneTag(),对模板中的标签(include/taglib/*),进行计算  
    345.         $totalpage = ceil($this->TotalResult/$this->PageSize);  
    346.         if($totalpage==0)  
    347.         {  
    348.             $totalpage = 1;  
    349.         }  
    350.         CreateDir(MfTypedir($this->Fields['typedir']));  
    351.         $murl = '';  
    352.         if($makepagesize > 0)  
    353.         {  
    354.             $endpage = $startpage+$makepagesize;  
    355.         }  
    356.         else  
    357.         {  
    358.             $endpage = ($totalpage+1);  
    359.         }  
    360.         if( $endpage >= $totalpage+1 )  
    361.         {  
    362.             $endpage = $totalpage+1;  
    363.         }  
    364.         if($endpage==1)  
    365.         {  
    366.             $endpage = 2;  
    367.         }  
    368.   
    369.         /*  
    370.             生成指定数目的列表页  
    371.          */  
    372.         for($this->PageNo=$startpage; $this->PageNo < $endpage; $this->PageNo++)  
    373.         {  
    374.             $this->ParseDMFields($this->PageNo,1);  // list和pagelist标签的执行  
    375.   
    376.             // 列表页静态文件生成路径 和 静态文件访问url(默认使用最后一个页面的url)  
    377.             $makeFile = $this->GetMakeFileRule($this->Fields['id'],'list',$this->Fields['typedir'],'',$this->Fields['namerule2']);  
    378.             $makeFile = str_replace("{page}", $this->PageNo, $makeFile);  
    379.             $murl = $makeFile;  
    380.             if(!preg_match("/^//", $makeFile))  
    381.             {  
    382.                 $makeFile = "/".$makeFile;  
    383.             }  
    384.             $makeFile = $this->GetTruePath().$makeFile;  
    385.             $makeFile = preg_replace("//{1,}/", "/", $makeFile);  
    386.             $murl = $this->GetTrueUrl($murl);  
    387.             $this->dtp->SaveTo($makeFile);  
    388.             //如果启用远程发布则需要进行判断  
    389.             if($cfg_remote_site=='Y'&& $isremote == 1)  
    390.             {  
    391.                 //分析远程文件路径  
    392.                 $remotefile = str_replace(DEDEROOT, '',$makeFile);  
    393.                 $localfile = '..'.$remotefile;  
    394.                 $remotedir = preg_replace('/[^/]*.html/', '',$remotefile);  
    395.                 //不相等则说明已经切换目录则可以创建镜像  
    396.                 $this->ftp->rmkdir($remotedir);  
    397.                 $this->ftp->upload($localfile, $remotefile, 'acii');  
    398.             }  
    399.         }  
    400.   
    401.         /*   
    402.             如果从第一页开始生成列表页  
    403.                 设置了 'isdefault=1 - 链接到默认页'  
    404.                 设置了 'ispart=0 - 最终列表栏目'  
    405.             获取第一页的列表页,并复制给 '默认页',并返回默认页的url  
    406.         */  
    407.         if($startpage==1)  
    408.         {  
    409.             //如果列表启用封面文件,复制这个文件第一页  
    410.             if($this->TypeLink->TypeInfos['isdefault']==1  
    411.             && $this->TypeLink->TypeInfos['ispart']==0)  
    412.             {  
    413.                 $onlyrule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],'',$this->Fields['namerule2']);  
    414.                 $onlyrule = str_replace("{page}","1",$onlyrule);  
    415.                 $list_1 = $this->GetTruePath().$onlyrule;  
    416.                 $murl = MfTypedir($this->Fields['typedir']).'/'.$this->Fields['defaultname'];  
    417.                 //如果启用远程发布则需要进行判断  
    418.                 if($cfg_remote_site=='Y'&& $isremote == 1)  
    419.                 {  
    420.                     //分析远程文件路径  
    421.                     $remotefile = $murl;  
    422.                     $localfile = '..'.$remotefile;  
    423.                     $remotedir = preg_replace('/[^/]*.html/', '',$remotefile);  
    424.                     //不相等则说明已经切换目录则可以创建镜像  
    425.                     $this->ftp->rmkdir($remotedir);  
    426.                     $this->ftp->upload($localfile, $remotefile, 'acii');  
    427.                 }  
    428.                 $indexname = $this->GetTruePath().$murl;  
    429.                 copy($list_1,$indexname);  
    430.             }  
    431.         }  
    432.         return $murl;  
    433.     }  
    434.   
    435.     /**  
    436.      *  显示列表  
    437.      *  
    438.      * @access    public  
    439.      * @return    void  
    440.      */  
    441.     function Display()  
    442.     {  
    443.         if($this->TypeLink->TypeInfos['ispart']>0)  
    444.         {  
    445.             $this->DisplayPartTemplets();  
    446.             return ;  
    447.         }  
    448.         $this->CountRecord();  
    449.         if((empty($this->PageNo) || $this->PageNo==1)  
    450.         && $this->TypeLink->TypeInfos['ispart']==1)  
    451.         {  
    452.             $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];  
    453.             $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);  
    454.             $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);  
    455.             $tempfile = $tmpdir."/".$tempfile;  
    456.             if ( defined('DEDEMOB') )  
    457.             {  
    458.                 $tempfile =str_replace('.htm','_m.htm',$tempfile);  
    459.             }  
    460.             if(!file_exists($tempfile))  
    461.             {  
    462.                 $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";  
    463.                 if ( defined('DEDEMOB') )  
    464.                 {  
    465.                     $tempfile =str_replace('.htm','_m.htm',$tempfile);  
    466.                 }  
    467.             }  
    468.             $this->dtp->LoadTemplate($tempfile);  
    469.         }  
    470.         $this->ParseTempletsFirst();  
    471.         $this->ParseDMFields($this->PageNo,0);  
    472.         $this->dtp->Display();  
    473.     }  
    474.   
    475.     /**  
    476.      *  创建单独模板页面  
    477.      *  
    478.      * @access    public  
    479.      * @return    string  
    480.      */  
    481.     function MakePartTemplets()  
    482.     {  
    483.         $this->PartView = new PartView($this->TypeID,false);  
    484.         $this->PartView->SetTypeLink($this->TypeLink);  
    485.         $nmfa = 0;  
    486.         $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];  
    487.   
    488.         // 频道封面  
    489.         if($this->Fields['ispart']==1)  
    490.         {  
    491.   
    492.             // 使用 'tempindex - 封面模板' 作为模板,并解析模板  
    493.             $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);  
    494.             $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);  
    495.             $tempfile = $tmpdir."/".$tempfile;  
    496.             if ( defined('DEDEMOB') )  
    497.             {  
    498.                 $tempfile =str_replace('.htm','_m.htm',$tempfile);  
    499.             }  
    500.             if(!file_exists($tempfile))  
    501.             {  
    502.                 $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";  
    503.                 if ( defined('DEDEMOB') )  
    504.                 {  
    505.                     $tempfile =str_replace('.htm','_m.htm',$tempfile);  
    506.                 }  
    507.             }  
    508.             $this->PartView->SetTemplet($tempfile);  
    509.         }  
    510.   
    511.         // 外部链接(使用的是 '文件保存目录' 填写的内容)  
    512.         else if($this->Fields['ispart']==2)  
    513.         {  
    514.             //跳转网址  
    515.             return $this->Fields['typedir'];  
    516.         }  
    517.   
    518.         /*  
    519.             开始生成 '频道封面'  
    520.          */  
    521.         CreateDir(MfTypedir($this->Fields['typedir']));     // 创建目录  
    522.   
    523.         // 生成静态文件  
    524.         $makeUrl = $this->GetMakeFileRule($this->Fields['id'],"index",MfTypedir($this->Fields['typedir']),$this->Fields['defaultname'],$this->Fields['namerule2']);  
    525.         $makeUrl = preg_replace("//{1,}/", "/", $makeUrl);  
    526.         $makeFile = $this->GetTruePath().$makeUrl;  
    527.         if($nmfa==0)  
    528.         {  
    529.             $this->PartView->SaveToHtml($makeFile);  
    530.             //如果启用远程发布则需要进行判断  
    531.             if($GLOBALS['cfg_remote_site']=='Y'&& $isremote == 1)  
    532.             {  
    533.                 //分析远程文件路径  
    534.                 $remotefile = str_replace(DEDEROOT, '',$makeFile);  
    535.                 $localfile = '..'.$remotefile;  
    536.                 $remotedir = preg_replace('/[^/]*.html/', '',$remotefile);  
    537.                 //不相等则说明已经切换目录则可以创建镜像  
    538.                 $this->ftp->rmkdir($remotedir);  
    539.                 $this->ftp->upload($localfile, $remotefile, 'acii');  
    540.             }  
    541.         }  
    542.         else  
    543.         {  
    544.             if(!file_exists($makeFile))  
    545.             {  
    546.                 $this->PartView->SaveToHtml($makeFile);  
    547.                 //如果启用远程发布则需要进行判断  
    548.                 if($cfg_remote_site=='Y'&& $isremote == 1)  
    549.                 {  
    550.                     //分析远程文件路径  
    551.                     $remotefile = str_replace(DEDEROOT, '',$makeFile);  
    552.                     $localfile = '..'.$remotefile;  
    553.                     $remotedir = preg_replace('/[^/]*.html/', '',$remotefile);  
    554.                     //不相等则说明已经切换目录则可以创建镜像  
    555.                     $this->ftp->rmkdir($remotedir);  
    556.                     $this->ftp->upload($localfile, $remotefile, 'acii');  
    557.               }  
    558.             }  
    559.         }  
    560.   
    561.         // 返回 '频道封面访问url'  
    562.         return $this->GetTrueUrl($makeUrl);  
    563.     }  
    564.   
    565.     /**  
    566.      *  显示单独模板页面 - 同上面逻辑基本一样,只是不用生成静态页面,直接展示频道页内容  
    567.      *  
    568.      * @access    public  
    569.      * @param     string  
    570.      * @return    string  
    571.      */  
    572.     function DisplayPartTemplets()  
    573.     {  
    574.         $this->PartView = new PartView($this->TypeID,false);  
    575.         $this->PartView->SetTypeLink($this->TypeLink);  
    576.         $nmfa = 0;  
    577.         $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];  
    578.         if($this->Fields['ispart']==1)  
    579.         {  
    580.             //封面模板  
    581.             $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);  
    582.             $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);  
    583.             $tempfile = $tmpdir."/".$tempfile;  
    584.             if ( defined('DEDEMOB') )  
    585.             {  
    586.                 $tempfile =str_replace('.htm','_m.htm',$tempfile);  
    587.             }  
    588.             if(!file_exists($tempfile))  
    589.             {  
    590.                 $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default.htm";  
    591.                 if ( defined('DEDEMOB') )  
    592.                 {  
    593.                     $tempfile =str_replace('.htm','_m.htm',$tempfile);  
    594.                 }  
    595.             }  
    596.             $this->PartView->SetTemplet($tempfile);  
    597.         }  
    598.         else if($this->Fields['ispart']==2)  
    599.         {  
    600.             //跳转网址  
    601.             $gotourl = $this->Fields['typedir'];  
    602.             header("Location:$gotourl");  
    603.             exit();  
    604.         }  
    605.         CreateDir(MfTypedir($this->Fields['typedir']));  
    606.         $makeUrl = $this->GetMakeFileRule($this->Fields['id'],"index",MfTypedir($this->Fields['typedir']),$this->Fields['defaultname'],$this->Fields['namerule2']);  
    607.         $makeFile = $this->GetTruePath().$makeUrl;  
    608.         if($nmfa==0)  
    609.         {  
    610.             $this->PartView->Display();  
    611.         }  
    612.         else  
    613.         {  
    614.             if(!file_exists($makeFile))  
    615.             {  
    616.                 $this->PartView->Display();  
    617.             }  
    618.             else  
    619.             {  
    620.                 include($makeFile);  
    621.             }  
    622.         }  
    623.     }  
    624.   
    625.     /**  
    626.      *  获得站点的真实根路径  
    627.      *  
    628.      * @access    public  
    629.      * @return    string  
    630.      */  
    631.     function GetTruePath()  
    632.     {  
    633.         $truepath = $GLOBALS["cfg_basedir"];  
    634.         return $truepath;  
    635.     }  
    636.   
    637.     /**  
    638.      *  获得真实连接路径  
    639.      *  
    640.      * @access    public  
    641.      * @param     string  $nurl  地址  
    642.      * @return    string  
    643.      */  
    644.     function GetTrueUrl($nurl)  
    645.     {  
    646.         if($this->Fields['moresite']==1)  
    647.         {  
    648.             if($this->Fields['sitepath']!='')  
    649.             {  
    650.                 $nurl = preg_replace("/^".$this->Fields['sitepath']."/", '', $nurl);  
    651.             }  
    652.             $nurl = $this->Fields['siteurl'].$nurl;  
    653.         }  
    654.         return $nurl;  
    655.     }  
    656.   
    657.     /**  
    658.      *  解析模板,对固定的标记进行初始给值  
    659.      *  
    660.      * @access    public  
    661.      * @return    string  
    662.      */  
    663.     function ParseTempletsFirst()  
    664.     {  
    665.         if(isset($this->TypeLink->TypeInfos['reid']))  
    666.         {  
    667.             $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];  
    668.         }  
    669.         $GLOBALS['envs']['typeid'] = $this->TypeID;  
    670.         $GLOBALS['envs']['topid'] = GetTopid($this->Fields['typeid']);  
    671.         $GLOBALS['envs']['cross'] = 1;  
    672.         MakeOneTag($this->dtp,$this);  
    673.     }  
    674.   
    675.     /**  
    676.      *  解析模板,对内容里的变动进行赋值  
    677.      *  
    678.      * @access    public  
    679.      * @param     int  $PageNo  页数  
    680.      * @param     int  $ismake  是否编译  
    681.      * @return    string  
    682.      */  
    683.     function ParseDMFields($PageNo,$ismake=1)  
    684.     {  
    685.         //替换第二页后的内容  
    686.         if(($PageNo>1 || strlen($this->Fields['content'])<10 ) && !$this->IsReplace)  
    687.         {  
    688.             $this->dtp->SourceString = str_replace('[cmsreplace]','display:none',$this->dtp->SourceString);  
    689.             $this->IsReplace = true;  
    690.         }  
    691.         foreach($this->dtp->CTags as $tagid=>$ctag)  
    692.         {  
    693.   
    694.             // 解析 'list标签',控制 '列表展示'  
    695.             if($ctag->GetName()=="list")  
    696.             {  
    697.                 $limitstart = ($this->PageNo-1) * $this->PageSize;  
    698.                 $row = $this->PageSize;  
    699.                 if(trim($ctag->GetInnerText())=="")  
    700.                 {  
    701.                     $InnerText = GetSysTemplets("list_fulllist.htm");  
    702.                 }  
    703.                 else  
    704.                 {  
    705.                     $InnerText = trim($ctag->GetInnerText());  
    706.                 }  
    707.                 $this->dtp->Assign($tagid,  
    708.                 $this->GetArcList(  
    709.                 $limitstart,  
    710.                 $row,  
    711.                 $ctag->GetAtt("col"),  
    712.                 $ctag->GetAtt("titlelen"),  
    713.                 $ctag->GetAtt("infolen"),  
    714.                 $ctag->GetAtt("imgwidth"),  
    715.                 $ctag->GetAtt("imgheight"),  
    716.                 $ctag->GetAtt("listtype"),  
    717.                 $ctag->GetAtt("orderby"),  
    718.                 $InnerText,  
    719.                 $ctag->GetAtt("tablewidth"),  
    720.                 $ismake,  
    721.                 $ctag->GetAtt("orderway")  
    722.                 )  
    723.                 );  
    724.             }  
    725.   
    726.             // 解析 'pagelist标签',控制 '分页导航展示'  
    727.             else if($ctag->GetName()=="pagelist")  
    728.             {  
    729.                 $list_len = trim($ctag->GetAtt("listsize"));  
    730.                 $ctag->GetAtt("listitem")=="" ? $listitem="index,pre,pageno,next,end,option" : $listitem=$ctag->GetAtt("listitem");  
    731.                 if($list_len=="")  
    732.                 {  
    733.                     $list_len = 3;  
    734.                 }  
    735.                 if($ismake==0)  
    736.                 {  
    737.                     $this->dtp->Assign($tagid,$this->GetPageListDM($list_len,$listitem));  
    738.                 }  
    739.                 else  
    740.                 {  
    741.                     $this->dtp->Assign($tagid,$this->GetPageListST($list_len,$listitem));  
    742.                 }  
    743.             }  
    744.             else if($PageNo!=1 && $ctag->GetName()=='field' && $ctag->GetAtt('display')!='')  
    745.             {  
    746.                 $this->dtp->Assign($tagid,'');  
    747.             }  
    748.         }  
    749.     }  
    750.   
    751.     /**  
    752.      *  获得要创建的文件名称规则  
    753.      *  
    754.      * @access    public  
    755.      * @param     int  $typeid  栏目ID  
    756.      * @param     string  $wname  
    757.      * @param     string  $typedir  栏目目录  
    758.      * @param     string  $defaultname  默认名称  
    759.      * @param     string  $namerule2  栏目规则  
    760.      * @return    string  
    761.      */  
    762.     function GetMakeFileRule($typeid,$wname,$typedir,$defaultname,$namerule2)  
    763.     {  
    764.         $typedir = MfTypedir($typedir);  
    765.         if($wname=='index')  
    766.         {  
    767.             return $typedir.'/'.$defaultname;  
    768.         }  
    769.         else  
    770.         {  
    771.             $namerule2 = str_replace('{tid}',$typeid,$namerule2);  
    772.             $namerule2 = str_replace('{typedir}',$typedir,$namerule2);  
    773.             return $namerule2;  
    774.         }  
    775.     }  
    776.   
    777.     /**  
    778.      *  获得一个单列的文档列表  
    779.      *  
    780.      * @access    public  
    781.      * @param     int  $limitstart  限制开始    
    782.      * @param     int  $row  行数   
    783.      * @param     int  $col  列数  
    784.      * @param     int  $titlelen  标题长度  
    785.      * @param     int  $infolen  描述长度  
    786.      * @param     int  $imgwidth  图片宽度  
    787.      * @param     int  $imgheight  图片高度  
    788.      * @param     string  $listtype  列表类型  
    789.      * @param     string  $orderby  排列顺序  
    790.      * @param     string  $innertext  底层模板  
    791.      * @param     string  $tablewidth  表格宽度  
    792.      * @param     string  $ismake  是否编译  
    793.      * @param     string  $orderWay  排序方式  
    794.      * @return    string  
    795.      */  
    796.     function GetArcList($limitstart=0,$row=10,$col=1,$titlelen=30,$infolen=250,  
    797.     $imgwidth=120,$imgheight=90,$listtype="all",$orderby="default",$innertext="",$tablewidth="100",$ismake=1,$orderWay='desc')  
    798.     {  
    799.         global $cfg_list_son,$cfg_digg_update;  
    800.           
    801.         $typeid=$this->TypeID;  
    802.           
    803.         if($row=='') $row = 10;  
    804.         if($limitstart=='') $limitstart = 0;  
    805.         if($titlelen=='') $titlelen = 100;  
    806.         if($infolen=='') $infolen = 250;  
    807.         if($imgwidth=='') $imgwidth = 120;  
    808.         if($imgheight=='') $imgheight = 120;  
    809.         if($listtype=='') $listtype = 'all';  
    810.         if($orderWay=='') $orderWay = 'desc';  
    811.           
    812.         if($orderby=='') {  
    813.             $orderby='default';  
    814.         }  
    815.         else {  
    816.             $orderby=strtolower($orderby);  
    817.         }  
    818.           
    819.         $tablewidth = str_replace('%','',$tablewidth);  
    820.         if($tablewidth=='') $tablewidth=100;  
    821.         if($col=='') $col=1;  
    822.         $colWidth = ceil(100/$col);  
    823.         $tablewidth = $tablewidth.'%';  
    824.         $colWidth = $colWidth.'%';  
    825.           
    826.         $innertext = trim($innertext);  
    827.         if($innertext=='') {  
    828.             $innertext = GetSysTemplets('list_fulllist.htm');  
    829.         }  
    830.   
    831.         //排序方式  
    832.         $ordersql = '';  
    833.         if($orderby=="senddate" || $orderby=="id") {  
    834.             $ordersql=" ORDER BY arc.id $orderWay";  
    835.         }  
    836.         else if($orderby=="hot" || $orderby=="click") {  
    837.             $ordersql = " ORDER BY arc.click $orderWay";  
    838.         }  
    839.         else if($orderby=="lastpost") {  
    840.             $ordersql = "  ORDER BY arc.lastpost $orderWay";  
    841.         }  
    842.         else {  
    843.             $ordersql=" ORDER BY arc.sortrank $orderWay";  
    844.         }  
    845.   
    846.         //获得附加表的相关信息  
    847.         $addtable  = $this->ChannelUnit->ChannelInfos['addtable'];  
    848.         if($addtable!="")  
    849.         {  
    850.             $addJoin = " LEFT JOIN `$addtable` ON arc.id = ".$addtable.'.aid ';  
    851.             $addField = '';  
    852.             $fields = explode(',',$this->ChannelUnit->ChannelInfos['listfields']);  
    853.             foreach($fields as $k=>$v)  
    854.             {  
    855.                 $nfields[$v] = $k;  
    856.             }  
    857.             if(is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields))  
    858.             {  
    859.                 foreach($this->ChannelUnit->ChannelFields as $k=>$arr)  
    860.                 {  
    861.                     if(isset($nfields[$k]))  
    862.                     {  
    863.                         if(!empty($arr['rename'])) {  
    864.                             $addField .= ','.$addtable.'.'.$k.' as '.$arr['rename'];  
    865.                         }  
    866.                         else {  
    867.                             $addField .= ','.$addtable.'.'.$k;  
    868.                         }  
    869.                     }  
    870.                 }  
    871.             }  
    872.         }  
    873.         else  
    874.         {  
    875.             $addField = '';  
    876.             $addJoin = '';  
    877.         }  
    878.   
    879.         //如果不用默认的sortrank或id排序,使用联合查询(数据量大时非常缓慢)  
    880.         if(preg_match('/hot|click|lastpost/', $orderby))  
    881.         {  
    882.             $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,  
    883.            tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath  
    884.            $addField  
    885.            FROM `#@__archives` arc  
    886.            LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id  
    887.            $addJoin  
    888.            WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row";  
    889.         }  
    890.         //普通情况先从arctiny表查出ID,然后按ID查询(速度非常快)  
    891.         else  
    892.         {  
    893.             $t1 = ExecTime();  
    894.             $ids = array();  
    895.             $query = "SELECT id FROM `#@__arctiny` arc WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row ";  
    896.             $this->dsql->SetQuery($query);  
    897.             $this->dsql->Execute();  
    898.             while($arr=$this->dsql->GetArray())  
    899.             {  
    900.                 $ids[] = $arr['id'];  
    901.             }  
    902.             $idstr = join(',',$ids);  
    903.             if($idstr=='')  
    904.             {  
    905.                 return '';  
    906.             }  
    907.             else  
    908.             {  
    909.                 $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,  
    910.                        tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath  
    911.                        $addField  
    912.                        FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id  
    913.                        $addJoin  
    914.                        WHERE arc.id in($idstr) $ordersql ";  
    915.             }  
    916.             $t2 = ExecTime();  
    917.             //echo $t2-$t1;  
    918.   
    919.         }  
    920.         $this->dsql->SetQuery($query);  
    921.         $this->dsql->Execute('al');  
    922.         $t2 = ExecTime();  
    923.   
    924.         //echo $t2-$t1;  
    925.         $artlist = '';  
    926.         $this->dtp2->LoadSource($innertext);  
    927.         $GLOBALS['autoindex'] = 0;  
    928.         for($i=0;$i<$row;$i++)  
    929.         {  
    930.             if($col>1)  
    931.             {  
    932.                 $artlist .= "<div> ";  
    933.             }  
    934.             for($j=0;$j<$col;$j++)  
    935.             {  
    936.                 if($row = $this->dsql->GetArray("al"))  
    937.                 {  
    938.                     $GLOBALS['autoindex']++;  
    939.                     $ids[$row['id']] = $row['id'];  
    940.   
    941.                     //处理一些特殊字段  
    942.                     $row['infos'] = cn_substr($row['description'],$infolen);  
    943.                     $row['id'] =  $row['id'];  
    944.                     if($cfg_digg_update > 0)  
    945.                     {  
    946.                         $prefix = 'diggCache';  
    947.                         $key = 'aid-'.$row['id'];  
    948.                         $cacherow = GetCache($prefix, $key);  
    949.                         $row['goodpost'] = $cacherow['goodpost'];  
    950.                         $row['badpost'] = $cacherow['badpost'];  
    951.                         $row['scores'] = $cacherow['scores'];  
    952.                     }  
    953.   
    954.                     if($row['corank'] > 0 && $row['arcrank']==0)  
    955.                     {  
    956.                         $row['arcrank'] = $row['corank'];  
    957.                     }  
    958.   
    959.                     $row['filename'] = $row['arcurl'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],  
    960.                     $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);  
    961.                     $row['typeurl'] = GetTypeUrl($row['typeid'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],  
    962.                     $row['ispart'],$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);  
    963.                     if($row['litpic'] == '-' || $row['litpic'] == '')  
    964.                     {  
    965.                         $row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';  
    966.                     }  
    967.                     if(!preg_match("/^http:///i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')  
    968.                     {  
    969.                         $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];  
    970.                     }  
    971.                     $row['picname'] = $row['litpic'];  
    972.                     $row['stime'] = GetDateMK($row['pubdate']);  
    973.                     $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";  
    974.                     $row['image'] = "<img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".preg_replace("/['><]/", "", $row['title'])."'>";  
    975.                     $row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";  
    976.                     $row['fulltitle'] = $row['title'];  
    977.                     $row['title'] = cn_substr($row['title'],$titlelen);  
    978.                     if($row['color']!='')  
    979.                     {  
    980.                         $row['title'] = "<font color='".$row['color']."'>".$row['title']."</font>";  
    981.                     }  
    982.                     if(preg_match('/c/', $row['flag']))  
    983.                     {  
    984.                         $row['title'] = "<b>".$row['title']."</b>";  
    985.                     }  
    986.                     $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";  
    987.                     $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];  
    988.                     $row['memberurl'] = $GLOBALS['cfg_memberurl'];  
    989.                     $row['templeturl'] = $GLOBALS['cfg_templeturl'];  
    990.   
    991.                     //编译附加表里的数据  
    992.                     foreach($row as $k=>$v)  
    993.                     {  
    994.                         $row[strtolower($k)] = $v;  
    995.                     }  
    996.                     foreach($this->ChannelUnit->ChannelFields as $k=>$arr)  
    997.                     {  
    998.                         if(isset($row[$k]))  
    999.                         {  
    1000.                             $row[$k] = $this->ChannelUnit->MakeField($k,$row[$k]);  
    1001.                         }  
    1002.                     }  
    1003.                     if(is_array($this->dtp2->CTags))  
    1004.                     {  
    1005.                         foreach($this->dtp2->CTags as $k=>$ctag)  
    1006.                         {  
    1007.                             if($ctag->GetName()=='array')  
    1008.                             {  
    1009.                                 //传递整个数组,在runphp模式中有特殊作用  
    1010.                                 $this->dtp2->Assign($k,$row);  
    1011.                             }  
    1012.                             else  
    1013.                             {  
    1014.                                 if(isset($row[$ctag->GetName()]))  
    1015.                                 {  
    1016.                                     $this->dtp2->Assign($k,$row[$ctag->GetName()]);  
    1017.                                 }  
    1018.                                 else  
    1019.                                 {  
    1020.                                     $this->dtp2->Assign($k,'');  
    1021.                                 }  
    1022.                             }  
    1023.                         }  
    1024.                     }  
    1025.                     $artlist .= $this->dtp2->GetResult();  
    1026.                 }//if hasRow  
    1027.   
    1028.             }//Loop Col  
    1029.   
    1030.             if($col>1)  
    1031.             {  
    1032.                 $i += $col - 1;  
    1033.                 $artlist .= "    </div> ";  
    1034.             }  
    1035.         }//Loop Line  
    1036.   
    1037.         $t3 = ExecTime();  
    1038.   
    1039.         //echo ($t3-$t2);  
    1040.         $this->dsql->FreeResult('al');  
    1041.         return $artlist;  
    1042.     }  
    1043.   
    1044.     /**  
    1045.      *  获取静态的分页列表  
    1046.      *  
    1047.      * @access    public  
    1048.      * @param     string  $list_len  列表宽度  
    1049.      * @param     string  $list_len  列表样式  
    1050.      * @return    string  
    1051.      */  
    1052.     function GetPageListST($list_len,$listitem="index,end,pre,next,pageno")  
    1053.     {  
    1054.         $prepage = $nextpage = '';  
    1055.         $prepagenum = $this->PageNo-1;  
    1056.         $nextpagenum = $this->PageNo+1;  
    1057.         if($list_len=='' || preg_match("/[^0-9]/", $list_len))  
    1058.         {  
    1059.             $list_len=3;  
    1060.         }  
    1061.         $totalpage = ceil($this->TotalResult/$this->PageSize);  
    1062.         if($totalpage<=1 && $this->TotalResult>0)  
    1063.         {  
    1064.   
    1065.             return "<li><span class="pageinfo">共 <strong>1</strong>页<strong>".$this->TotalResult."</strong>条记录</span></li> ";  
    1066.         }  
    1067.         if($this->TotalResult == 0)  
    1068.         {  
    1069.             return "<li><span class="pageinfo">共 <strong>0</strong>页<strong>".$this->TotalResult."</strong>条记录</span></li> ";  
    1070.         }  
    1071.         $purl = $this->GetCurUrl();  
    1072.         $maininfo = "<li><span class="pageinfo">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li> ";  
    1073.         $tnamerule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],$this->Fields['defaultname'],$this->Fields['namerule2']);  
    1074.         $tnamerule = preg_replace("/^(.*)//", '', $tnamerule);  
    1075.   
    1076.         //获得上一页和主页的链接  
    1077.         if($this->PageNo != 1)  
    1078.         {  
    1079.             $prepage.="<li><a href='".str_replace("{page}",$prepagenum,$tnamerule)."'>上一页</a></li> ";  
    1080.             $indexpage="<li><a href='".str_replace("{page}",1,$tnamerule)."'>首页</a></li> ";  
    1081.         }  
    1082.         else  
    1083.         {  
    1084.             $indexpage="<li>首页</li> ";  
    1085.         }  
    1086.   
    1087.         //下一页,未页的链接  
    1088.         if($this->PageNo!=$totalpage && $totalpage>1)  
    1089.         {  
    1090.             $nextpage.="<li><a href='".str_replace("{page}",$nextpagenum,$tnamerule)."'>下一页</a></li> ";  
    1091.             $endpage="<li><a href='".str_replace("{page}",$totalpage,$tnamerule)."'>末页</a></li> ";  
    1092.         }  
    1093.         else  
    1094.         {  
    1095.             $endpage="<li>末页</li> ";  
    1096.         }  
    1097.   
    1098.         //option链接  
    1099.         $optionlist = '';  
    1100.   
    1101.         $optionlen = strlen($totalpage);  
    1102.         $optionlen = $optionlen*12 + 18;  
    1103.         if($optionlen < 36) $optionlen = 36;  
    1104.         if($optionlen > 100) $optionlen = 100;  
    1105.         $optionlist = "<li><select name='sldd' style='{$optionlen}px' onchange='location.href=this.options[this.selectedIndex].value;'> ";  
    1106.         for($mjj=1;$mjj<=$totalpage;$mjj++)  
    1107.         {  
    1108.             if($mjj==$this->PageNo)  
    1109.             {  
    1110.                 $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."' selected>$mjj</option> ";  
    1111.             }  
    1112.             else  
    1113.             {  
    1114.                 $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."'>$mjj</option> ";  
    1115.             }  
    1116.         }  
    1117.         $optionlist .= "</select></li> ";  
    1118.   
    1119.         //获得数字链接  
    1120.         $listdd="";  
    1121.         $total_list = $list_len * 2 + 1;  
    1122.         if($this->PageNo >= $total_list)  
    1123.         {  
    1124.             $j = $this->PageNo-$list_len;  
    1125.             $total_list = $this->PageNo+$list_len;  
    1126.             if($total_list>$totalpage)  
    1127.             {  
    1128.                 $total_list=$totalpage;  
    1129.             }  
    1130.         }  
    1131.         else  
    1132.         {  
    1133.             $j=1;  
    1134.             if($total_list>$totalpage)  
    1135.             {  
    1136.                 $total_list=$totalpage;  
    1137.             }  
    1138.         }  
    1139.         for($j;$j<=$total_list;$j++)  
    1140.         {  
    1141.             if($j==$this->PageNo)  
    1142.             {  
    1143.                 $listdd.= "<li class="thisclass">$j</li> ";  
    1144.             }  
    1145.             else  
    1146.             {  
    1147.                 $listdd.="<li><a href='".str_replace("{page}",$j,$tnamerule)."'>".$j."</a></li> ";  
    1148.             }  
    1149.         }  
    1150.         $plist = '';  
    1151.         if(preg_match('/index/i', $listitem)) $plist .= $indexpage;  
    1152.         if(preg_match('/pre/i', $listitem)) $plist .= $prepage;  
    1153.         if(preg_match('/pageno/i', $listitem)) $plist .= $listdd;  
    1154.         if(preg_match('/next/i', $listitem)) $plist .= $nextpage;  
    1155.         if(preg_match('/end/i', $listitem)) $plist .= $endpage;  
    1156.         if(preg_match('/option/i', $listitem)) $plist .= $optionlist;  
    1157.         if(preg_match('/info/i', $listitem)) $plist .= $maininfo;  
    1158.           
    1159.         return $plist;  
    1160.     }  
    1161.   
    1162.     /**  
    1163.      *  获取动态的分页列表  
    1164.      *  
    1165.      * @access    public  
    1166.      * @param     string  $list_len  列表宽度  
    1167.      * @param     string  $list_len  列表样式  
    1168.      * @return    string  
    1169.      */  
    1170.     function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno")  
    1171.     {  
    1172.         global $cfg_rewrite;  
    1173.         $prepage = $nextpage = '';  
    1174.         $prepagenum = $this->PageNo-1;  
    1175.         $nextpagenum = $this->PageNo+1;  
    1176.         if($list_len=='' || preg_match("/[^0-9]/", $list_len))  
    1177.         {  
    1178.             $list_len=3;  
    1179.         }  
    1180.         $totalpage = ceil($this->TotalResult/$this->PageSize);  
    1181.         if($totalpage<=1 && $this->TotalResult>0)  
    1182.         {  
    1183.             return "<li><span class="pageinfo">共 1 页/".$this->TotalResult." 条记录</span></li> ";  
    1184.         }  
    1185.         if($this->TotalResult == 0)  
    1186.         {  
    1187.             return "<li><span class="pageinfo">共 0 页/".$this->TotalResult." 条记录</span></li> ";  
    1188.         }  
    1189.         $maininfo = "<li><span class="pageinfo">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span></li> ";  
    1190.           
    1191.         $purl = $this->GetCurUrl();  
    1192.         // 如果开启为静态,则对规则进行替换  
    1193.         if($cfg_rewrite == 'Y')  
    1194.         {  
    1195.             $nowurls = preg_replace("/-/", ".php?", $purl);  
    1196.             $nowurls = explode("?", $nowurls);  
    1197.             $purl = $nowurls[0];  
    1198.         }  
    1199.   
    1200.         $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";  
    1201.         $purl .= '?'.$geturl;  
    1202.           
    1203.         $optionlist = '';  
    1204.         //$hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."'> ";  
    1205.         //$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'> ";  
    1206.   
    1207.         //获得上一页和下一页的链接  
    1208.         if($this->PageNo != 1)  
    1209.         {  
    1210.             $prepage.="<li><a href='".$purl."PageNo=$prepagenum'>上一页</a></li> ";  
    1211.             $indexpage="<li><a href='".$purl."PageNo=1'>首页</a></li> ";  
    1212.         }  
    1213.         else  
    1214.         {  
    1215.             $indexpage="<li><a>首页</a></li> ";  
    1216.         }  
    1217.         if($this->PageNo!=$totalpage && $totalpage>1)  
    1218.         {  
    1219.             $nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>下一页</a></li> ";  
    1220.             $endpage="<li><a href='".$purl."PageNo=$totalpage'>末页</a></li> ";  
    1221.         }  
    1222.         else  
    1223.         {  
    1224.             $endpage="<li><a>末页</a></li> ";  
    1225.         }  
    1226.   
    1227.   
    1228.         //获得数字链接  
    1229.         $listdd="";  
    1230.         $total_list = $list_len * 2 + 1;  
    1231.         if($this->PageNo >= $total_list)  
    1232.         {  
    1233.             $j = $this->PageNo-$list_len;  
    1234.             $total_list = $this->PageNo+$list_len;  
    1235.             if($total_list>$totalpage)  
    1236.             {  
    1237.                 $total_list=$totalpage;  
    1238.             }  
    1239.         }  
    1240.         else  
    1241.         {  
    1242.             $j=1;  
    1243.             if($total_list>$totalpage)  
    1244.             {  
    1245.                 $total_list=$totalpage;  
    1246.             }  
    1247.         }  
    1248.         for($j;$j<=$total_list;$j++)  
    1249.         {  
    1250.             if($j==$this->PageNo)  
    1251.             {  
    1252.                 $listdd.= "<li class="thisclass"><a>$j</a></li> ";  
    1253.             }  
    1254.             else  
    1255.             {  
    1256.                 $listdd.="<li><a href='".$purl."PageNo=$j'>".$j."</a></li> ";  
    1257.             }  
    1258.         }  
    1259.   
    1260.         $plist = '';  
    1261.         if(preg_match('/index/i', $listitem)) $plist .= $indexpage;  
    1262.         if(preg_match('/pre/i', $listitem)) $plist .= $prepage;  
    1263.         if(preg_match('/pageno/i', $listitem)) $plist .= $listdd;  
    1264.         if(preg_match('/next/i', $listitem)) $plist .= $nextpage;  
    1265.         if(preg_match('/end/i', $listitem)) $plist .= $endpage;  
    1266.         if(preg_match('/option/i', $listitem)) $plist .= $optionlist;  
    1267.         if(preg_match('/info/i', $listitem)) $plist .= $maininfo;  
    1268.           
    1269.         if($cfg_rewrite == 'Y')  
    1270.         {  
    1271.             $plist = str_replace('.php?tid=', '-', $plist);  
    1272.             $plist = str_replace('&TotalResult=', '-', $plist);  
    1273.             $plist = preg_replace("/&PageNo=(d+)/i",'-\1.html',$plist);  
    1274.         }  
    1275.         return $plist;  
    1276.     }  
    1277.   
    1278.     /**  
    1279.      *  获得当前的页面文件的url  
    1280.      *  
    1281.      * @access    public  
    1282.      * @return    string  
    1283.      */  
    1284.     function GetCurUrl()  
    1285.     {  
    1286.         if(!empty($_SERVER['REQUEST_URI']))  
    1287.         {  
    1288.             $nowurl = $_SERVER['REQUEST_URI'];  
    1289.             $nowurls = explode('?', $nowurl);  
    1290.             $nowurl = $nowurls[0];  
    1291.         }  
    1292.         else  
    1293.         {  
    1294.             $nowurl = $_SERVER['PHP_SELF'];  
    1295.         }  
    1296.         return $nowurl;  
    1297.     }  
    1298. }//End Class  
     
     
     
     
    原文链接:http://blog.csdn.net/beyond__devil/article/details/52816358
  • 相关阅读:
    方法的调用机制
    类的成员之二:方法
    类的成员之一:属性
    关键字static
    构造器
    this关键字
    递归方法(recursion)
    方法重载(二)
    GTID 跳过脚本
    mydumper 找不到libmysqlclient.so.20
  • 原文地址:https://www.cnblogs.com/weibo806/p/6193887.html
Copyright © 2011-2022 走看看