织梦字段属性筛选
1. 后台添加⾃⼰要筛选的字段
织梦管理系统php版本内容模型管理-编辑模型-字段管理-添加字段
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($addonf
ields_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}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论