织梦如何实现筛选功能,二次开发实现联动

本文介绍了在织梦CMS中如何实现筛选功能,涉及模板中的PHP标签使用,需要解除后台模板引擎对PHP标签的禁用。关键步骤包括修改`arc.listview.class.php`和`extend.func.php`两个PHP文件,关注字段类型设置。最后,通过模板调用AddFilter函数完成自定义筛选项的设置,例如AddFilter(4,1,'linestyle,linethem,youdays,jgqujian'),其中4为频道ID,其余为自定义字段。" 51348409,1387450,Windows上搭建ZooKeeper集群实战,"['zookeeper', 'windows', '集群环境', '分布式协调']
摘要由CSDN通过智能技术生成

首先需要说明的是这个功能需要在模板里面用到php标签,所以需要在后台模板引擎禁用标签里面解除这个标签的禁用,具体方法:

后台——系统——系统基本参数——其它选项——模板引擎禁用标签:php

首先需要更改2个PHP文件 都是 include/ 下面的以下PHP已修改完毕

1、arc.listview.class.php

<?php   if(!defined('DEDEINC')) exit('Request Error!');
/**
 * 文档列表类
 *
 * @version        $Id: arc.listview.class.php 2 15:15 2010年7月7日Z tianya $
 * @package        DedeCMS.Libraries
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
require_once(DEDEINC.'/arc.partview.class.php');
require_once(DEDEINC.'/ftp.class.php');

helper('cache');
@set_time_limit(0);

/**
 * 自由列表类
 *
 * @package          ListView
 * @subpackage       DedeCMS.Libraries
 * @link             http://www.dedecms.com
 */
class ListView
{
   
    var $dsql;
    var $dtp;
    var $dtp2;
    var $TypeID;
    var $TypeLink;
    var $PageNo;
    var $TotalPage;
    var $TotalResult;
    var $PageSize;
    var $ChannelUnit;
    var $ListType;
    var $Fields;
    var $PartView;
    var $upPageType;
    var $addSql;
    var $IsError;
    var $CrossID;
    var $IsReplace;
    var $ftp;
    var $remoteDir;
    
    /**
     *  php5构造函数
     *
     * @access    public
     * @param     int  $typeid  栏目ID
     * @param     int  $uppage  上一页
     * @return    string
     */
    function __construct($typeid, $uppage=1)
    {
   
        global $dsql,$ftp;
        $this->TypeID = $typeid;
        $this->dsql = &$dsql;
        $this->CrossID = '';
        $this->IsReplace = false;
        $this->IsError = false;
        $this->dtp = new DedeTagParse();
        $this->dtp->SetRefObj($this);
        $this->dtp->SetNameSpace("dede", "{", "}");
        $this->dtp2 = new DedeTagParse();
        $this->dtp2->SetNameSpace("field","[","]");
        $this->TypeLink = new TypeLink($typeid);
        $this->upPageType = $uppage;
        $this->ftp = &$ftp;
        $this->remoteDir = '';
        $this->TotalResult = is_numeric($this->TotalResult)? $this->TotalResult : "";
        
        if(!is_array($this->TypeLink->TypeInfos))
        {
   
            $this->IsError = true;
        }
        if(!$this->IsError)
        {
   
            $this->ChannelUnit = new ChannelUnit($this->TypeLink->TypeInfos['channeltype']);
            $this->Fields = $this->TypeLink->TypeInfos;
            $this->Fields['id'] = $typeid;
            $this->Fields['position'] = $this->TypeLink->GetPositionLink(true);
            $this->Fields['title'] = preg_replace("/[<>]/", " / ", $this->TypeLink->GetPositionLink(false));
			//dedecms单选 增加开始
			if (isset($_REQUEST['tid']))
			{
   
				foreach($_GET as $key => $value) {
   
					if ($key!="tid" && $key!="TotalResult" && $key!="PageNo") {
   
						$this->Fields[string_filter($key)] = string_filter(urldecode($value));
					}
				}
			}
			//dedecms单选 增加结束
            //设置一些全局参数的值
            foreach($GLOBALS['PubFields'] as $k=>$v) $this->Fields[$k] = $v;
            $this->Fields['rsslink'] = $GLOBALS['cfg_cmsurl']."/data/rss/".$this->TypeID.".xml";

            //设置环境变量
            SetSysEnv($this->TypeID,$this->Fields['typename'],0,'','list');
            $this->Fields['typeid'] = $this->TypeID;

            //获得交叉栏目ID
            if($this->TypeLink->TypeInfos['cross']>0 && $this->TypeLink->TypeInfos['ispart']==0)
            {
   
                $selquery = '';
                if($this->TypeLink->TypeInfos['cross']==1)
                {
   
                    $selquery = "SELECT id,topid FROM `#@__arctype` WHERE typename LIKE '{
     $this->Fields['typename']}' AND id<>'{
     $this->TypeID}' AND topid<>'{
     $this->TypeID}'  ";
                }
                else
                {
   
                    $this->Fields['crossid'] = preg_replace('/[^0-9,]/', '', trim($this->Fields['crossid']));
                    if($this->Fields['crossid']!='')
                    {
   
                        $selquery = "SELECT id,topid FROM `#@__arctype` WHERE id in({
     $this->Fields['crossid']}) AND id<>{
     $this->TypeID} AND topid<>{
     $this->TypeID}  ";
                    }
                }
                if($selquery!='')
                {
   
                    $this->dsql->SetQuery($selquery);
                    $this->dsql->Execute();
                    while($arr = $this->dsql->GetArray())
                    {
   
                        $this->CrossID .= ($this->CrossID=='' ? $arr['id'] : ','.$arr['id']);
                    }
                }
            }

        }//!error

    }

    //php4构造函数
    function ListView($typeid,$uppage=0){
   
        $this->__construct($typeid,$uppage);
    }
    
    //关闭相关资源
    function Close()
    {
   

    }

    /**
     *  统计列表里的记录
     *
     * @access    public
     * @param     string
     * @return    string
     */
    function CountRecord()
    {
   
        global $cfg_list_son,$cfg_need_typeid2,$cfg_cross_sectypeid;
        if(empty($cfg_need_typeid2)) $cfg_need_typeid2 = 'N';
		//dedecms单选 增加开始
		//获得附加表的相关信息
		$addtable  = $this->ChannelUnit->ChannelInfos['addtable'];
		if($addtable!="")
		{
   
			$addJoin = " LEFT JOIN `$addtable` ON arc.id = ".$addtable.'.aid ';
			$addField = '';
			$fields = explode(',',$this->ChannelUnit->ChannelInfos['listfields']);
			foreach($fields as $k=>$v)
			{
   
				$nfields[$v] = $k;
			}
			if(is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields))
			{
   
				foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
				{
   
					if(isset($nfields[$k]))
					{
   
						if(!empty($arr['rename'])) {
   
							$addField .= ','.$addtable.'.'.$k.' as '.$arr['rename'];
						}
						else {
   
							$addField .= ','.$addtable.'.'.$k;
						}
					}
				}
			}
			if (isset($_REQUEST['tid']))
			{
   
				foreach($_GET as $key => $value) {
   
					$filtersql .= ($key!="tid" && $key!="TotalResult" && $key!="PageNo") ? " AND $addtable.".string_filter($key)." = '".string_filter(urldecode($value))."'" : '';
				}
			}
		}
		else
		{
   
			$addField = '';
			$addJoin = '';
		}
		//dedecms单选 增加结束
        //统计数据库记录
        $this->TotalResult = -1;
        if(isset($GLOBALS['TotalResult'])) $this->TotalResult = $GLOBALS['TotalResult'];
        if(isset($GLOBALS['PageNo'])) $this->PageNo = $GLOBALS['PageNo'];
        else $this->PageNo = 1;
        $this->addSql  = " arc.arcrank > -1 ";
        
        $typeid2like = " '%,{
     $this->TypeID},%' ";
        if($cfg_list_son=='N')
        {
   
            
            if($cfg_need_typeid2=='N')
            {
   
                if($this->CrossID=='') $this->addSql .= " AND (arc.typeid='".$this->TypeID."') ";
                else $this->addSql .= " AND (arc.typeid in({
     $this->CrossID},{
     $this->TypeID})) ";
            }
            else
            {
   
                if($this->CrossID=='') 
				{
   
					$this->addSql .= " AND ( (arc.typeid='".$this->TypeID."') OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like) ";
				} else {
   
					if($cfg_cross_sectypeid == 'Y')
					{
   
						$typeid2Clike = " '%,{
     $this->CrossID},%' ";
						$this->addSql .= " AND ( arc.typeid IN({
     $this->CrossID},{
     $this->TypeID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2Clike)";
					} else {
   
						$this->addSql .= " AND ( arc.typeid IN({
     $this->CrossID},{
     $this->TypeID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like)";
					}
				}
            }
        }
        else
        {
   
            $sonids = GetSonIds($this->TypeID,$this->Fields['channeltype']);
            if(!preg_match("/,/", $sonids)) {
   
                $sonidsCon = " arc.typeid = '$sonids' ";
            }
            else {
   
                $sonidsCon = " arc.typeid IN($sonids) ";
            }
            if($cfg_need_typeid2=='N')
            {
   
                if($this->CrossID=='') $this->addSql .= " AND ( $sonidsCon ) ";
                else $this->addSql .= " AND ( arc.typeid IN ({
     $sonids},{
     $this->CrossID}) ) ";
            }
            else
            {
   
                if($this->CrossID=='') 
				{
   
					$this->addSql .= " AND ( $sonidsCon OR CONCAT(',', arc.typeid2, ',') like $typeid2like  ) ";
				} else {
   
					if($cfg_cross_sectypeid == 'Y')
					{
   
						$typeid2Clike = " '%,{
     $this->CrossID},%' ";
						$this->addSql .= " AND ( arc.typeid IN ({
     $sonids},{
     $this->CrossID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2Clike) ";
					} else {
   
						$this->addSql .= " AND ( arc.typeid IN ({
     $sonids},{
     $this->CrossID}) OR CONCAT(',', arc.typeid2, ',') LIKE $typeid2like) ";
					}
					
				}
            }
        }
        if($this->TotalResult==-1)
        {
   
			//dedecms单选 修改开始
            $cquery = "SELECT COUNT(*) AS dd FROM `#@__arctiny` arc $addJoin WHERE ".$this->addSql.$filtersql;
			//dedecms单选 修改结束
            $row = $this->dsql->GetOne($cquery);
            if(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值