織夢字段屬性篩選
阿新 • • 發佈:2019-04-27
首頁 typeid drop server style dso break load 參數
1. 後臺添加自己要篩選的字段
內容模型管理-編輯模型-字段管理-添加字段
2. 調整系統設置,允許運行php標簽
系統 - 系統設置 - 系統基本參數 - 其他選項 - 禁用模板標簽 ,把“php”刪除後保存。
3. 添加屬性調用函數
找到文件:inluce/extend.func.php,添加代碼:
function _extendFilter($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; } /** * 載入自定義表單(用於發布) * * @access public * @param string $fieldset 字段列表 * @param string $loadtype 載入類型
* @param string $column 文件路徑(手機端首頁調用時傳入值為:m) * @return string */ function AddFilter($channelid, $type=1, $fieldsnamef, $defaulttid, $loadtype=‘autofield‘, $column=‘plus‘) { global $tid,$dsql,$id; $tid = $defaulttid ? $defaulttid : $tid; if ($id!="") { $tidsq = $dsql->GetOne(" Select typeid From `#@__archives` where id=‘$id‘ "); $tid = $tidsq["typeid"]; } $nofilter = (isset($_REQUEST[‘TotalResult‘]) ? "&TotalResult=".$_REQUEST[‘TotalResult‘] : ‘‘).(isset($_REQUEST[‘PageNo‘]) ? "&PageNo=".$_REQUEST[‘PageNo‘] : ‘‘); $filterarr = _extendFilter(stripos($_SERVER[‘REQUEST_URI‘], "list.php?tid=") ? str_replace($nofilter, ‘‘, $_SERVER[‘REQUEST_URI‘]) : $GLOBALS[‘cfg_cmsurl‘]."/".$column."/list.php?tid=".$tid); $cInfos = $dsql->GetOne(" Select * From `#@__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 $tida=>$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>‘; $dede_addonfields .= ‘<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; }
4. 修改文檔列表核心文件:include/arc.listview.php
文件改動較大,可以下載後比對自己的文件修改,自己文件之前未改動的可直接覆蓋
點擊下載
5.調用示例,以欄目id15為列
PC端當前欄目調用:{dede:php} AddFilter(2,1,‘‘,15); {/dede:php}
PC端其他頁面調用 {dede:php} AddFilter(2,1,‘‘,15); {/dede:php}
手機端當前欄目調用:{dede:php} AddFilter(2,1,‘‘,15); {/dede:php}
手機端其他頁面調用: {dede:php} AddFilter(2,1,‘‘,15,‘autofield‘,‘m‘); {/dede:php}
織夢字段屬性篩選