Zhimeng DedeCMS secondary development realizes linkage screening function (including multiple selection function)

The default list page of Zhimeng has no filtering function, but sometimes when we create a product list page, there are many fields of the product, and many people need to use the filtering function, which can make it easier for users to find what they need. To achieve this linkage filtering function, it requires secondary development of Zhimeng, Now let's tell you how to carry out the secondary development of Dream Weaving to realize the screening function that many people need, as shown in the following figure:

First of all, it should be noted that this function needs to use the php tag in the template, so you need to disable this tag in the background template engine disable tag. The specific methods are as follows:
Background - system - basic system parameters - other options - template engine disable tag: php
Remove this PHP and save it!
Ok, let's get down to business.

1、 Linkage filtering single selection function

First, you need to modify two PHP files under the include directory.
1. Modify the arc.listview.class.php file. This file has changed a lot. It is recommended that you download the file in the attachment package directly to replace it. If you have changed this file before, please search the file in the downloaded package for the "Dream Technology Research Center" comments, which are all modified, However, I manually insert the commented code into my own file!

2. Modify the extend.func.php file and add the following code at the end:

 //Start of dedecms linkage filtering function code 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 | |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; } /** *Load custom form (for publishing) * * @access    public *@ param string $fieldset field list *@ 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 ` # [Separator] @ __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 ` # [Separator] @ __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="All" href="'. str_replace ("&". $ctag ->GetName()."=". $fields_value," ", $filterarr).'">All</a>':'<span>All</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]) ? '< a title="'.$addonfields_items[$i].'" href="'.$href.'">'.$ addonfields_items[$i].'</ a>' : '<span>'.$ addonfields_items[$i].'</ span>'). "&nbsp;"; } $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).'">All</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; }
Special note: After the code is copied, you need to manually remove the two [Separators] in the above code.
The file download that has been modified mentioned above is provided below. Note that this is to modify the file that has not been modified by default. If you have modified these two files, please see the comments of these two files to modify accordingly,
Download address:
OK, here is the PHP file modification part! Next, you need to add fields to the specified model. What you need to pay attention to here is the selection of field types. You need to select radio buttons or use the select drop-down box for field types, as shown in the following figure:

The following is the call of the list page template filter tag. The call of the filter tag is very simple and can be completed with a single code. The tag code is as follows:

 {dede:php}AddFilter(4,1,'linestyle,linethem,youdays,jgqujian'); {/dede:php}
Label explanation:
The first number 4 in the AddFilter function is the ID number of the content model. Please check the ID of each content model in the background content model management;
The second number, 1, indicates the filtering style, 1, uses the hyperlink to select, 2, uses the select drop-down box to select, and you can set your own viewing effect;
The third part, 'linestyle, linethem, youdays, jgqujian', is the name of the field to add the filtering function. There are four fields, which should be separated by half commas.
Here, the function of linked filtering single selection is finished. If you only need the function of single selection, you can use it directly, but if you need the function of multiple selection, please continue to look below.
2、 Linkage filtering multiple selection function
The search is similar to the following figure: N values can be selected for each custom field value (url cannot exceed 255 characters)

Then open the previously modified arc.listview.class.php file, and find the following code around line 117 and 809: $filtersql= ($key!="tid" && $key!="TotalResult" && $key!="PageNo") ? " AND $addtable.".wwwcms_filter($key). " = ".wwwcms_filter(iconv("UTF-8", "gb2312", $value)). "": "; The codes in both places are modified as follows:

 If ($key=="goodtype" | | $key=="goodscolor") {//The field name of your custom field (the English name) $count=0; $nowsql =''; $var=explode(",",wwwcms_filter(iconv("UTF-8", "gb2312", $value)));// Iconv means transcoding. If the parameter from your url is in Chinese, you need to transcode if(!empty($var)){ foreach($var as $value){  if($count==0){ $filtersql.= "and ($addtable.".wwwcms_filter($key). " like '%".$ value. "%'"; $count++; }else{ $filtersql.= "or $addtable.".wwwcms_filter($key). " like '%".$ value. "%'"; } } $filtersql.= ")"; } }else{ $filtersql .=  ($key!="tid" && $key!="TotalResult" && $key!="PageNo") ?  " AND $addtable.".wwwcms_filter($key). " = ".wwwcms_filter(iconv("UTF-8", "gb2312", $value)). "" : '';// As above, if the value passed is in Chinese, transcoding is required }
Then when calling in the foreground, for example, the parameter is //xxx.com/plus/list.php?tid=4&goodstype= Type 1, Type 2&goodscolor=grey, red, blue
Remember, it must be separated by English half commas. If your code is gbk, you can directly use the above code if the url displays Chinese when transferring values. Otherwise, it may need to be slightly modified during transcoding.
At this point, the development of the multi selection function of linkage filtering will be completed.

Post reply

Can't comment until