码迷,mamicode.com
首页 > 其他好文 > 详细

织梦字段属性筛选

时间:2019-04-27 11:37:08      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:调用函数   file   字段   删除   覆盖   .com   serve   names   ext   

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("&lt;","&gt;","","","","","","",""),
               $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}

织梦字段属性筛选

标签:调用函数   file   字段   删除   覆盖   .com   serve   names   ext   

原文地址:https://www.cnblogs.com/bubuchu/p/10778104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!