织梦做装修网站-筛选篇

正能量 yun 8年前 (2017-04-01) 3159次浏览 扫描二维码

案例或者设计师栏目需要用到筛选功能,需要对织梦进行二次开发


  筛选功能首先需要在后台开启 php 功能
  后台-系统-系统基本参数-其它选项-模板引擎禁用标签:php
  涉及文件:

extend.func.php      arc.listview.class.php

一、程序修改

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("<",">","","","","","","",""), 
      $str); 
 } 
 return $str; 
} 
/** 
 *  载入自定义表单(用于发布) 
 * AddFilter 复制本段并更改 AddFilter 为 AddFilter1/2/3/4/...n 可以设置 n 样式 前台调用只需更改名称即可
 * @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>').' '; 
      
      $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]) ? '<a title="'.$addonfields_items[$i].'" href="'.$href.'">'.$addonfields_items[$i].'</a>' : '<span>'.$addonfields_items[$i].'</span>')." "; 
      } 
      $dede_addonfields .= '</div>'; 
     break; 
      
     case 2: 
      $dede_addonfields .= '<select name="filter"'.$ctag->GetName().' onchange="window.location=this.options[this.selectedIndex].value"> 
       '.'<option value="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'">全部</option>'; 
      $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]); 
       $dede_addonfields .= '<option value="'.$href.'"'.($fields_value==urlencode($addonfields_items[$i]) ? ' selected="selected"' : '').'>'.$addonfields_items[$i].'</option> 
       '; 
      } 
      $dede_addonfields .= '</select><br/> 
      '; 
     break; 
    } 
            } 
        } 
    } 
 echo $dede_addonfields; 
} 

  第一处添加 搜索

if(empty($cfg_need_typeid2)) $cfg_need_typeid2 = 'N'; 

在下面添加以下代码

		//获得附加表的相关信息!!此段为添加内容!!! 联动筛选功能 1
		$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.".wwwcms_filter($key)." = '".wwwcms_filter(urldecode($value))."'" : '';
				}
			}
		}
		else
		{
			$addField = '';
			$addJoin = '';
		}
		//添加内容结束!!! 联动筛选功能 1

  第二处添加 搜索 if(preg_match(‘/hot|click|lastpost/’, $orderby)) 在

		}
		else
		{
			$addField = '';
			$addJoin = '';
		}

        //如果不用默认的 sortrank 或 id 排序,使用联合查询(数据量大时非常缓慢)
        if(preg_match('/hot|click|lastpost/', $orderby))

上面(注意:是上面)添加下面的代码

			//此段为添加内容 联动筛选功能 2
			if (isset($_REQUEST['tid']))
			{
			foreach($_GET as $key => $value) {
				$filtersql .= ($key!="tid" && $key!="TotalResult" && $key!="PageNo") ? " AND $addtable.".wwwcms_filter($key)." = '".wwwcms_filter(urldecode($value))."'" : '';
			}
			}
			//添加内容结束 联动筛选功能 2

  第三处添加 搜索

$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>\r\n";

在下面添加

		//获取筛选参数 此段为添加内容 联动筛选功能 3
		foreach($_GET as $key => $value) {
			$pageaddurl .= ($key!="tid" && $key!="TotalResult" && $key!="PageNo") ? "&".wwwcms_filter($key)."=".wwwcms_filter($value) : '';
		}
		//添加内容结束  联动筛选功能 3 

  添加三处完成,还有四处修改

  第一处修改 搜索

if($this->TotalResult==-1)  将$cquery = 

后面的修改为

"SELECT COUNT(*) AS dd FROM `#@__arctiny` arc $addJoin WHERE ".$this->addSql.$filtersql;//修改 1! 联动筛选功能 

  第二处修改 搜索

 //如果不用默认的 sortrank 或 id 排序,使用联合查询(数据量大时非常缓慢)

将 if(preg_match(‘/hot|click|lastpost/’, $orderby)) {}括号里面的内容修改为

            $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,
           tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
           $addField
           FROM `#@__archives` arc
           LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
           $addJoin
           WHERE {$this->addSql} $filtersql $ordersql LIMIT $limitstart,$row";//修改 2 联动筛选功能 

  第三处修改 搜索

//普通情况先从 arctiny 表查出 ID,然后按 ID 查询(速度非常快)

(接着第二处下面)将$cquery = 后面的修改为

"SELECT id FROM `#@__arctiny` arc $addJoin WHERE {$this->addSql} $filtersql $ordersql LIMIT $limitstart,$row ";//修改 3 联动筛选功能 

  第四处 搜索

if($this->PageNo!=$totalpage && $totalpage>1) 

搜索内容有两个结果,此处修改处为获取动态的分页列表下面,将下面{}内容修改为如下代码

{   //修改 4 联动筛选功能 
            $nextpage.="<a href='".$purl."PageNo=$nextpagenum".$pageaddurl."'class=\"a1\">下一页</a>\r\n";
            $endpage="<a href='".$purl."PageNo=$totalpage".$pageaddurl."'class=\"a1\">末页</a>\r\n";
	//修改 4 联动筛选功能 
}

二、后台添加

  如图所示:所有参与筛选的字段都必须使用 select 下拉框
织梦筛选

三、前台调用

{dede:php}AddFilter(4,1,'需要调用的字段 1,需要调用的字段 2');{/dede:php}  //样式 1
{dede:php}AddFilter1(4,1,'需要调用的字段 1,需要调用的字段 2');{/dede:php}  //样式 2

个人分享+网络资源丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 随意转载织梦做装修网站-筛选篇
喜欢 (1)
[info@ldzgr.com]
分享 (0)