【phpcms-v9】content_output.class.php文件分析-前台内容详情页显示
发布:smiling 来源: PHP粉丝网 添加日期:2014-10-23 08:54:00 浏览: 评论:0
【phpcms-v9】content_output.class.php文件分析-前台内容详情页显示数据的过滤
- <?php
- //路径:caches/caches_model/caches_data/content_output.class.php
- //在phpcms/modules/content/index.php控制器中的show()方法中会调用content_output类的实例,show()方法主要用来完成前台内容详情页内容的显示
- class content_output {
- var $fields;
- var $data;
- function __construct($modelid,$catid = 0,$categorys = array()) {
- $this->modelid = $modelid; //模型id
- $this->catid = $catid; //栏目id
- $this->categorys = $categorys; //当前站点下所有栏目的详细配置信息
- $this->fields = getcache('model_field_'.$modelid,'model'); //当前模型id下所有模型字段详细配置信息
- }
- function get($data) { //参数:从数据库中查询到某条记录
- $this->data = $data;
- $this->id = $data['id']; //记录id
- $info = array();
- foreach($this->fields as $field=>$v) {
- if(!isset($data[$field])) continue; //如果不存在,则跳出本次循环
- $func = $v['formtype']; //方法名:通过表单类型来获取,作用:主要是对当前表单数据进行过滤等
- $value = $data[$field]; //表单值
- //如果方法存在,执行方法并返回数据
- $result = method_exists($this, $func) ? $this->$func($field, $data[$field]) : $data[$field];
- if($result !== false) $info[$field] = $result;
- }
- return $info;
- }
- function editor($field, $value) {
- $setting = string2array($this->fields[$field]['setting']);
- if($setting['enablekeylink']) {
- $value = $this->_keylinks($value, $setting['replacenum'],$setting['link_mode']);
- }
- return $value;
- }
- function _base64_encode($t,$str) {
- return $t."\"".base64_encode($str)."\"";
- }
- function _base64_decode($t,$str) {
- return $t."\"".base64_decode($str)."\"";
- }
- function _keylinks($txt, $replacenum = '',$link_mode = 1) {
- $search = "/(alt\s*=\s*|title\s*=\s*)[\"|\'](.+?)[\"|\']/ise";
- $replace = "\$this->_base64_encode('\\1','\\2')";
- $replace1 = "\$this->_base64_decode('\\1','\\2')";
- $txt = preg_replace($search, $replace, $txt);
- $keywords = $this->data['keywords'];
- if($keywords) $keywords = strpos(',',$keywords) === false ? explode(' ',$keywords) : explode(',',$keywords);
- if($link_mode && !emptyempty($keywords)) {
- foreach($keywords as $keyword) {
- $linkdatas[] = $keyword;
- }
- } else {
- $linkdatas = getcache('keylink','commons');
- }
- if($linkdatas) {
- $word = $replacement = array();
- foreach($linkdatas as $v) {
- if($link_mode && $keywords) {
- $word1[] = '/(?!(<a.*?))' . preg_quote($v, '/') . '(?!.*<\/a>)/s';
- $word2[] = $v;
- $replacement[] = '<a href="javascript:;" onclick="show_ajax(this)" class="keylink">'.$v.'</a>';
- } else {
- $word1[] = '/(?!(<a.*?))' . preg_quote($v[0], '/') . '(?!.*<\/a>)/s';
- $word2[] = $v[0];
- $replacement[] = '<a href="'.$v[1].'" target="_blank" class="keylink">'.$v[0].'</a>';
- }
- }
- if($replacenum != '') {
- $txt = preg_replace($word1, $replacement, $txt, $replacenum);
- } else {
- $txt = str_replace($word2, $replacement, $txt);
- }
- }
- $txt = preg_replace($search, $replace1, $txt);
- return $txt;
- }
- //对title进行过滤
- function title($field, $value) {
- $value = htmlspecialchars($value);
- return $value;
- }
- function box($field, $value) {
- extract(string2array($this->fields[$field]['setting']));
- if($outputtype) {
- return $value;
- } else {
- $options = explode("\n",$this->fields[$field]['options']);
- foreach($options as $_k) {
- $v = explode("|",$_k);
- $k = trim($v[1]);
- $option[$k] = $v[0];
- }
- $string = '';
- switch($this->fields[$field]['boxtype']) {
- case 'radio':
- $string = $option[$value];
- break;
- case 'checkbox':
- $value_arr = explode(',',$value);
- foreach($value_arr as $_v) {
- if($_v) $string .= $option[$_v].' 、';
- }
- break;
- case 'select':
- $string = $option[$value];
- break;
- case 'multiple':
- $value_arr = explode(',',$value);
- foreach($value_arr as $_v) {
- if($_v) $string .= $option[$_v].' 、';
- }
- break;
- }
- return $string;
- }
- }
- function images($field, $value) {
- return string2array($value);
- }
- function datetime($field, $value) {
- $setting = string2array($this->fields[$field]['setting']);
- extract($setting);
- if($fieldtype=='date' || $fieldtype=='datetime') {
- return $value;
- } else {
- $format_txt = $format;
- }
- if(strlen($format_txt)<6) {
- $isdatetime = 0;
- } else {
- $isdatetime = 1;
- }
- if(!$value) $value = SYS_TIME;
- $value = date($format_txt,$value);
- return $value;
- }
- function keyword($field, $value) {
- if($value == '') return '';
- $v = '';
- if(strpos($value, ',')===false) {
- $tags = explode(' ', $value);
- } else {
- $tags = explode(',', $value);
- }
- return $tags;
- }
- function copyfrom($field, $value) {
- static $copyfrom_array;
- if(!$copyform_array) $copyfrom_array = getcache('copyfrom','admin');
- if($value && strpos($value,'|')!==false) {
- $arr = explode('|',$value);
- $value = $arr[0];
- $value_data = $arr[1];
- }
- if($value_data) {
- $copyfrom_link = $copyfrom_array[$value_data];
- if(!emptyempty($copyfrom_array)) {
- $imgstr = '';
- if($value=='') $value = $copyfrom_link['siteurl'];
- if($copyfrom_link['thumb']) $imgstr = "<a href='{$copyfrom_link[siteurl]}' target='_blank'><img src='{$copyfrom_link[thumb]}' height='15'></a> ";
- return $imgstr."<a href='$value' target='_blank' style='color:#AAA'>{$copyfrom_link[sitename]}</a>";
- }
- } else {
- return $value;
- }
- }
- function groupid($field, $value) {
- if($value) $value = explode(',',$value);
- return $value;
- }
- function linkage($field, $value) {
- $setting = string2array($this->fields[$field]['setting']);
- $datas = getcache($setting['linkageid'],'linkage');
- $infos = $datas['data'];
- if($setting['showtype']==1 || $setting['showtype']==3) {
- $result = get_linkage($value, $setting['linkageid'], $setting['space'], $setting['showtype']);
- } elseif($setting['showtype']==2) {
- $result = $value;
- } else {
- $result = get_linkage($value, $setting['linkageid'], $setting['space'], 2);
- }
- return $result;
- }
- function downfile($field, $value) {
- extract(string2array($this->fields[$field]['setting']));
- $list_str = array();
- if($value){
- $value_arr = explode('|',$value);
- $fileurl = $value_arr['0'];
- if($fileurl) {
- $sel_server = $value_arr['1'] ? explode(',',$value_arr['1']) : '';
- $server_list = getcache('downservers','commons');
- if(is_array($server_list)) {
- foreach($server_list as $_k=>$_v) {
- if($value && is_array($sel_server) && in_array($_k,$sel_server)) {
- $downloadurl = $_v[siteurl].$fileurl;
- if($downloadlink) {
- $a_k = urlencode(sys_auth("i=$this->id&s=$_v[siteurl]&m=1&f=$fileurl&d=$downloadtype&modelid=$this->modelid&catid=$this->catid", 'ENCODE', pc_base::load_config('system','auth_key')));
- $list_str[] = "<a href='".APP_PATH."index.php?m=content&c=down&a_k={$a_k}' target='_blank'>{$_v[sitename]}</a>";
- } else {
- $list_str[] = "<a href='{$downloadurl}' target='_blank'>{$_v[sitename]}</a>";
- }
- }
- }
- }
- return $list_str;
- }
- }
- }
- function downfiles($field, $value) {
- extract(string2array($this->fields[$field]['setting']));
- $list_str = array();
- $file_list = string2array($value);
- if(is_array($file_list)) {
- foreach($file_list as $_k=>$_v) {
- if($_v[fileurl]){
- $filename = $_v[filename] ? $_v[filename] : L('click_to_down');
- if($downloadlink) {
- $a_k = urlencode(sys_auth("i=$this->id&s=&m=1&f=$_v[fileurl]&d=$downloadtype&modelid=$this->modelid&catid=$this->catid", 'ENCODE', pc_base::load_config('system','auth_key')));
- $list_str[] = "<a href='".APP_PATH."index.php?m=content&c=down&a_k={$a_k}' target='_blank'>{$filename}</a>";
- } else {
- $list_str[] = "<a href='{$_v[fileurl]}' target='_blank'>{$filename}</a>";
- }
- }
- }
- }
- return $list_str;
- }
- function map($field, $value) {
- $str = '';
- $setting = string2array($this->fields[$field]['setting']);
- $setting[width] = $setting[width] ? $setting[width] : '600';
- $setting[height] = $setting[height] ? $setting[height] : '400';
- list($lngX, $latY,$zoom) = explode('|', $value);
- if($setting['maptype']==1) {
- $str = "<script src='http://app.mapabc.com/apis?&t=flashmap&v=2.4&key=$setting[api_key]&hl=zh-CN' type='text/javascript'></script>";
- } elseif($setting['maptype']==2) {
- $str = "<script type='text/javascript' src='http://api.map.baidu.com/api?v=1.2&key=$setting[api_key]'></script>";
- }
- $str .= '<div id="mapObj" class="view" style="width: '.$setting[width].'px; height:'.$setting[height].'px"></div>';
- $str .='<script type="text/javascript">';
- if($setting['maptype']==1) {
- $str .='
- var mapObj=null;
- lngX = "'.$lngX.'";
- latY = "'.$latY.'";
- zoom = "'.$zoom.'";
- var mapOptions = new MMapOptions();
- mapOptions.toolbar = MConstants.MINI;
- mapOptions.scale = new MPoint(20,20);
- mapOptions.zoom = zoom;
- mapOptions.mapComButton = MConstants.SHOW_NO
- mapOptions.center = new MLngLat(lngX,latY);
- var mapObj = new MMap("mapObj", mapOptions);
- var maptools = new MMapTools(mapObj);
- drawPoints(); //phpfensi.com
- ';
- $str .='
- function drawPoints(){
- var markerOption = new MMarkerOptions();
- var tipOption=new MTipOptions();//添加信息窗口
- var address = "'.$address.'";
- tipOption.tipType = MConstants.HTML_BUBBLE_TIP;//信息窗口标题
- tipOption.title = address;//信息窗口标题
- tipOption.content = address;//信息窗口内容
- var markerOption = new MMarkerOptions();
- markerOption.imageUrl="'.IMG_PATH.'icon/mak.png";
- markerOption.picAgent=false;
- markerOption.imageAlign=MConstants.BOTTOM_CENTER;
- markerOption.tipOption = tipOption;
- markerOption.canShowTip= address ? true : false;
- markerOption.dimorphicColor="0x00A0FF";
- Mmarker = new MMarker(new MLngLat(lngX,latY),markerOption);
- Mmarker.id="mark101";
- mapObj.addOverlay(Mmarker,true)
- }';
- } elseif($setting['maptype']==2) {
- $str .='
- var mapObj=null;
- lngX = "'.$lngX.'";
- latY = "'.$latY.'";
- zoom = "'.$zoom.'";
- var mapObj = new BMap.Map("mapObj");
- var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
- mapObj.addControl(ctrl_nav);
- mapObj.enableDragging();
- mapObj.enableScrollWheelZoom();
- mapObj.enableDoubleClickZoom();
- mapObj.centerAndZoom(new BMap.Point(lngX,latY),zoom);
- drawPoints();
- ';
- $str .='
- function drawPoints(){
- var myIcon = new BMap.Icon("'.IMG_PATH.'icon/mak.png", new BMap.Size(27, 45));
- var center = mapObj.getCenter();
- var point = new BMap.Point(lngX,latY);
- var marker = new BMap.Marker(point, {icon: myIcon});
- mapObj.addOverlay(marker);
- }';
- }
- $str .='</script>';
- return $str;
- }
- }
- ?>
Tags: content_output class php phpcms详情页
相关文章
- ·PHPCMS源文件研究记录之框架主类库ftps.class.phpFTP操作类(2014-10-20)
- ·PHPCMS源文件研究记录之框架主类库db_factory.class.php数据库工厂(2014-10-20)
- ·PHPCMS源文件研究记录之框架主类库mysql.class.php文件(2014-10-20)
- ·关于phpcms中模块_tag.class.php中的pc_tag()方法的含义(2014-10-21)
- ·【phpcms-v9】model.class.php文件分析-数据模型的基类(2014-10-22)
- ·【phpcms-v9】phpcms-v9中model.class.php文件分析(2014-10-23)
- ·【phpcms-v9】phpcms/modules/admin/classes/admin.class.php文件分析(2014-10-24)
- ·phpcms数据库操作(2013-11-15)
- ·phpcms的安装和卸载文件(2013-11-15)
- ·phpcms 模版源码分析(2013-11-15)
- ·phpcms更新首页(2013-11-15)
- ·PHPCMS 采集规则(2013-11-15)
- ·phpcms 仿站小结(2013-11-15)
- ·phpcms数据结构(2013-11-15)
- ·让PHPCms内容页支持JavaScript(2013-11-15)
- ·phpcms v9 二次开发记录(2014-01-09)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)