织梦二次开发联动筛选(单选和多选)功能的实现

首先我把单选的代码贴出来,这个是我参考其他网站的,多选也是基于这个单选修改的,所以如果要做多选的话,也请先把单选的这些代码配置好.

联动筛选单选功能

搜索情况类似下图:每个自定义字段值能选择一个值联动筛选单选功能

 

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

 

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

将这个PHP去掉后保存就可以了!

 

好了,下面开始正题了。

 

首先需要修改2个PHP文件,都是include目录下面的。

 

1、修改arc.listview.class.php文件,这文件改动比较大,建议大家直接下载附件压缩包里面的文件替换,如果你之前对这个文件 改动过的话,请在下载下来的压缩包里的这个文件里面搜索有“Darren中博客”这些注释的这些地方,都是修改过的,然自己手动将有注释的代码插入到自己 的文件里面!

 

2、修改extend.func.php文件,在其最后面添加如下代码:

//dedecms联动筛选功能 By Darren中博客 QQ:604849147 字符过滤函数
function wwwcms_filter($str,$stype="inject") {
  if ($stype=="inject")  {
   $str = str_replace(
          array( "select", "insert", "update", "delete", "alter", "cas", "union", "into", "load_file", "outfile", "create", "join", "where", "like", "drop", "modify", "rename", "'", "/*", "*", "../", "./"),
       array("","","","","","","","","","","","","","","","","","","","","",""),
       $str);
  } else if ($stype=="xss") {
   $farr = array("/\s+/" ,
                 "/<(\/?)(script|META|STYLE|HTML|HEAD|BODY|STYLE |i?frame|b|strong|style|html|img|P|o:p|iframe|u |em|strike|BR|div|a|TABLE|TBODY|object|tr|td |st1:chsdate|FONT|span|MARQUEE|body|title |\r\n|link |meta|\?|\%)([^>]*?)>/isU",
        "/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU",
        );
   $tarr = array(" ",
                 "",
        "\\1\\2",
        );
   $str = preg_replace($farr, $tarr, $str);
   $str = str_replace(
          array( "<", ">", "'", "\"", ";", "/*", "*", "../", "./"),
       array("&lt;","&gt;","","","","","","",""),
       $str);
  }
  return $str;
 }
 
/**
  *  载入自定义表单(用于发布)
  *
  * @access    public
  * @param     string  $fieldset  字段列表
 * @param     string  $loadtype  载入类型
 * @return    string
  */
 
 function AddFilter($channelid, $type=1, $fieldsnamef, $defaulttid, $loadtype='autofield')
 {
  global $tid,$dsql,$id;
  $tid = $defaulttid ? $defaulttid : $tid;
  if ($id!="")
  {
   $tidsq = $dsql->GetOne(" Select typeid From `dede_archives` where id='$id' ");
   $tid = $tidsq["typeid"];
  }
  $nofilter = (isset($_REQUEST['TotalResult']) ? "&TotalResult=".$_REQUEST['TotalResult'] : '').(isset($_REQUEST['PageNo']) ? "&PageNo=".$_REQUEST['PageNo'] : '');
  $filterarr = wwwcms_filter(stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/plus/list.php?tid=".$tid);
     $cInfos = $dsql->GetOne(" Select * From  `dede_channeltype` where id='$channelid' ");
  $fieldset=$cInfos['fieldset'];
  $dtp = new DedeTagParse();
     $dtp->SetNameSpace('field','<','>');
     $dtp->LoadSource($fieldset);
     $dede_addonfields = '';
     if(is_array($dtp->CTags))
     {
         foreach($dtp->CTags as $tid=>$ctag)
         {
             $fieldsname = $fieldsnamef ? explode(",", $fieldsnamef) : explode(",", $ctag->GetName());
    if(($loadtype!='autofield' || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1)) && in_array($ctag->GetName(), $fieldsname) )
             {
                 $href1 = explode($ctag->GetName().'=', $filterarr);
     $href2 = explode('&', $href1[1]);
     $fields_value = $href2[0];
     $dede_addonfields .= '<div class="scv-shaixuan"><b>'.$ctag->GetAtt('itemname').':</b>';
     switch ($type) {
      case 1:
       $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? '<a title="全部" href="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'">全部</a>' : '<span>全部</span>').'&nbsp;';
 
       $addonfields_items = explode(",",$ctag->GetAtt('default'));
       for ($i=0; $i<count($addonfields_items); $i++)
       {
        $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);//echo $href;
        $dede_addonfields .= ($fields_value!=urlencode($addonfields_items[$i