phpcms 字段生成详解析

<?php
//此文件主要根据caches/caches_model/caches_data/model_field_1.php文件中的模型字段来动态的生成表单
//路径:phpcms/caches/caches_model/caches_data/content_form.class.php文件,主要用来返回内容添加页面左侧动态生成的表单
//此类主要用来动态生成内容添加页面的所有表单:内容添加页面左侧表单不是直接写在html中的,而是通过程序动态生成的,现将其分析一下
//此文件需要参考:model_feild_模型ID.cache.php文件,因为通过后台 模型管理->字段管理 中所有已存在或新加的字段都会被缓存在这个文件中.
 
class content_form {
    var $modelid; //模型id 1-文章模型 2-图片模型 3-下载模型 ,不同的模型在添加内容时会动态生成不同的表单
    var $fields; //所有模型字段信息
    var $id;
    var $formValidator; //表单验证
 
    function __construct($modelid,$catid = 0,$categorys = array()) {
        $this->modelid = $modelid;
        $this->catid = $catid;
        $this->categorys = $categorys;
        $this->fields = getcache('model_field_'.$modelid,'model'); //此缓存文件主要用来缓存模型字        段信息
        $this->siteid = get_siteid();
    }
 
//此方法主要用来获取所有动态生成好的表单,以便于在前台循环显示
 
    function get($data = array()) {
        $_groupid = param::get_cookie('_groupid');
        $this->data = $data;
        if(isset($data['id'])) $this->id = $data['id'];
        $info = array();
        $this->content_url = $data['url'];
 
/**
* $this->fields:主要存放从model_field_模型id.cache.php文件中获取过来的所有模型字段信息
* $field:单个模型字段信息
*/
 
    foreach($this->fields as $field=>$v) {
        if(defined('IN_ADMIN')) {
        if($v['iscore'] || check_in($_SESSION['roleid'], $v['unsetroleids'])) continue;
        } else {
        if($v['iscore'] || !$v['isadd'] || check_in($_groupid, $v['unsetgroupids'])) contin        ue;
    }
/**
* 表单类型:formtype
* 对应 后台->模型管理->字段管理->类型
* 对应 content_form.class.php文件中方法的名称
* 对应 caches/caches_model/caches_data/model_field_模型id.cache.php文件中键名
* 注意:通过 后台->模型管理->字段管理->添加字段 ,添加的新字段都将被缓存到model_field_模型id.cache.php文件中 */
 
    $func = $v['formtype']; //表单类型
    $value = isset($data[$field]) ? new_html_special_chars($data[$field]) : ''; //表单值
    if($func=='pages' && isset($data['maxcharperpage'])) {
        $value = $data['paginationtype'].'|'.$data['maxcharperpage'];
    }
    if(!method_exists($this, $func)) continue;
 
/**
* 1.$func:假设模型字段名称为text,则会调用$this->text()方法
* 2.$this->text()方法会生成并返回一个text类型的表单,如:<input type="text" name="info['keywords']" value="">
* 3.后面程序会将生成的表单放到$info[][]二维数组中,前台只需要循环此数组即可将网页所有的表单都呈现出来
*/
 
    $form = $this->$func($field, $value, $v);
    if($form !== false) {
    //默认情况下此常量已经被定义了
        if(defined('IN_ADMIN')) {
    //基本信息字段:基本信息字段将在添加页面左侧显示
        if($v['isbase']) {
    //添加内容页面:左侧部分的表单名称
            $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
            $info['base'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$            form, 'star'=>$star,'isomnipotent'=>                 $v['isomnipotent'],'formty            pe'=>$v['formtype']);
        } else {
    //添加内容页面:右侧部分的表单名称
            $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
            $info['senior'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=            >$form, 'star'=>$star,'                  isomnipotent'=>$v['isomnipotent'],'for            mtype'=>$v['formtype']);
        }
    } else {
        $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
        $info[$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'        =>$star,'isomnipote            nt'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
         }
    }
}
return $info;
}
 
//text方法主要用来生成一个text类型的表单:<span class="tag"><</span><span class="tag-name">input</span> <span class="attribute">type</span>=<span class="attribute-value">"text"</span> <span class="attribute">name</span>=<span class="attribute-value">"info[]"</span> <span class="attribute">value</span>=<span class="attribute-value">""</span> <span class="tag">/></span>  
function text($field, $value, $fieldinfo) {
 
}
 
//textarea方法主要用来生成一个textarea类型的表单:<span class="tag"><</span><span class="tag-name">textarea</span> <span class="attribute">name</span>=<span class="attribute-value">"info[]"</span> <span class="tag">></span><span class="tag"></</span><span class="tag-name">textarea</span><span class="tag">></span>  
function textarea($field, $value, $fieldinfo) { 
 
}
 
//editor方法主要用来生成一个在线编辑器,如:ckeditor编辑器
function editor($field, $value, $fieldinfo) {
 
}
下面还有很多,我就不贴代码了!


比如说:要查看title模型字段生成的表单:
一、caches/caches_model/caches_data/content_form.class.php文件中:$form = $this->$func($field, $value, $v);
这行代码其实就是在调用:function title($field, $value, $fieldinfo){}//参数1:模型字段或表单字段名称,如title    参数2:模型字段或表单字段的值    参数3:模型字段相关信息函数如下:
function title($field, $value, $fieldinfo) {
    extract($fieldinfo);
    $style_arr = explode(';',$this->data['style']);
    $style_color = $style_arr[0];
    $style_font_weight = $style_arr[1] ? $style_arr[1] : '';
 
    $style = 'color:'.$this->data['style'];
    if(!$value) $value = $defaultvalue;
    $errortips = $this->fields[$field]['errortips'];
    $errortips_max = L('title_is_empty');
    if($errortips) $this->formValidator .= '$("#'.$field.'").formValidator({onshow:"",onfoc    us:"'.$errortips.'"}).inputValidator({min:'.$minlength.',max:'.$maxlength.',onerror:"'.    $errortips_max.'"});';
    $str = '<input type="text" style="width:400px;'.($style_color ? 'color:'.$style_color.'    ;' : '').($style_font_weight ? 'font-weight:'.$style_font_weight.';' : '').'" name="inf o['.$field.']" id="'.$field.'" value="'.$value.'" style="'.$style.'" class="measure-inp    ut " onBlur="$.post(\'api.php?op=get_keywords&number=3&sid=\'+Math.random()*5, {data:$(    \'#title\').val()}, function(data){if(data && $(\'#keywords\').val()==\'\') $(\'#keywor    ds\').val(data); })" οnkeyup="strlen_verify(this, \'title_len\', '.$maxlength.');"/><in    put type="hidden" name="style_color" id="style_color" value="'.$style_color.'">
    <input type="hidden" name="style_font_weight" id="style_font_weight" value="'.$style_fo    nt_weight.'">';
    if(defined('IN_ADMIN')) $str .= '<input type="button" class="button" id="check_title_al    t" value="'.L('check_title','','content').'" οnclick="$.get(\'?m=content&c=content&a=pu    blic_check_title&catid='.$this->catid.'&sid=\'+Math.random()*5, {data:$(\'#title\').val    ()}, function(data){if(data==\'1\') {$(\'#check_title_alt\').val(\''.L('title_repeat').    '\');$(\'#check_title_alt\').css(\'background-color\',\'#FFCC66\');} else if(data==\'0\    ') {$(\'#check_title_alt\').val(\''.L('title_not_repeat').'\');$(\'#check_title_alt\').    css(\'background-color\',\'#F8FFE1\')}})" style="width:73px;"/><img src="'.IMG_PATH.'ic    on/colour.png" width="15" height="16" οnclick="colorpicker(\''.$field.'_colorpanel\',\'    set_title_color\');" style="cursor:hand"/>
     <img src="'.IMG_PATH.'icon/bold.png" width="10" height="10" οnclick="input_font_bold()    " style="cursor:hand"/> <span id="'.$field.'_colorpanel" style="position:absolute;" cla   ss="colorpanel"></span>';
    $str .= L('can_enter').'<B><span id="title_len">'.$maxlength.'</span></B> '.L('characte    rs');
 return $str; //返回的html表单
 }
 
 
 二、title()函数中的$filedinfo其实就是:caches/caches_model/caches_data/model_field_1.cache.php文件中如下代码:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
array (
 'fieldid' => '3',
 'modelid' => '1',
 'siteid' => '1',
 'field' => 'title',
 'name' => '标题',
 'tips' => '',
 'css' => 'inputtitle',
 'minlength' => '1',
 'maxlength' => '80',
 'pattern' => '',
 'errortips' => '请输入标题',
 'formtype' => 'title',
 'setting' => '',
 'formattribute' => '',
 'unsetgroupids' => '',
 'unsetroleids' => '',
 'iscore' => '0',
 'issystem' => '1',
 'isunique' => '0',
 'isbase' => '1',
 'issearch' => '1',
 'isadd' => '1',
 'isfulltext' => '1',
 'isposition' => '1',
 'listorder' => '4',
 'disabled' => '0',
 'isomnipotent' => '0',
 ),
生成如下表单




本文永久地址:http://blog.it985.com/6673.html
本文出自 IT985博客 ,转载时请注明出处及相应链
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值