// +---------------------------------------------------------------------- // $Id$ namespace Think\Template\Driver; // 属性类型标签库 class Attr extends \Think\TagLib{ // 标签定义 protected $tags = array( // 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次 'attr'=>array('attr'=>'var,complex,type,default','close'=>0), ); // public function _attr($tag,$content){ $var = $tag['var']; $default = isset($tag['default'])?$tag['default']:1; $read = isset($tag['read'])?$tag['read']:false; if(!empty($tag['type'])) { $parse = $this->_{$tag['type']}($var); }else{ $parse = ''.$this->_string($var,$default,$read); $parse .= ''.$this->_num($var,$default,$read); $parse .= ''.$this->_bool($var,$default,$read); $parse .= ''.$this->_textarea($var,$default,$read); $parse .= ''.$this->_text($var,$default,$read); $parse .= ''.$this->_editor($var,$default,$read); $parse .= ''.$this->_file($var,$read); $parse .= ''.$this->_files($var,$read); $parse .= ''.$this->_radio($var,$default,$read); $parse .= ''.$this->_checkbox($var,$default,$read); $parse .= ''.$this->_select($var,$default,$read); $parse .= ''.$this->_image($var,$read); $parse .= ''.$this->_images($var,$read); $parse .= ''.$this->_date($var,$default,$read); $parse .= ''.$this->_zone($var,$read); $parse .= ''.$this->_html($var,$read); $parse .= ''.$this->_dynamic($var,$read); $parse .= ''.$this->_hidden($var,$read); $parse .= ''.$this->_verify($var,$read); $parse .= ''.$this->_password($var,$default,$read); $parse .= ''.$this->_serialize($var,$read); $parse .= ''.$this->_link($var,$read); if(!empty($tag['complex'])) { $parse .= ''.$this->_complex($var,$read); } $parse .= ''; } return $parse; } // 验证码类型 protected function _verify($var) { $parse = ' '; return $parse; } // 密码类型 protected function _password($var,$default) { $value = $default?'{$'.$var.'.value}':''; $parse = ' '; return $parse; } // 字符串类型 protected function _string($var,$default,$read) { $value = $default?'{$'.$var.'.value}':''; if($read) { $parse = $value; }else{ $parse = ' '; } return $parse; } // 字符串类型 protected function _link($var,$read) { $value = '{$'.$var.'.value}'; if($read) { $parse = $value; }else{ $parse = ' '; } return $parse; } // 数字类型 protected function _num($var,$default,$read) { $value = $default?'{$'.$var.'.value}':''; if($read) { $parse = $value; }else{ $parse = ' '; } return $parse; } // 布尔类型 采用下拉列表模拟 protected function _bool($var,$default,$read) { if($read) { $parse = ''; $parse = ''; }else{ $parse = ' '; } return $parse; } // 文本域类型 protected function _textarea($var,$default,$read) { $value = $default?'{$'.$var.'.value}':''; if($read) { $parse = $value; }else{ $parse = ' '; } return $parse; } // 文本型 protected function _text($var,$default,$read) { $value = $default?'{$'.$var.'.value}':''; if($read) { $parse = $value; }else{ $parse = ' '; } return $parse; } // 编辑器型 protected function _editor($var,$default,$read) { $value = $default?'{$'.$var.'.value}':''; if($read) { $parse = $value; }else{ $parse = ' '; } return $parse; } // 附件上传型 可配置 protected function _file($var) { $parse = '
{$'.$var.'.value|extension|showExt} {$'.$var.'.value}
'; return $parse; } // 多附件型 protected function _files($var) { $parse = '
$array = explode(\',\',$'.$var.'[\'value\']);
. {$attach|extension|showExt} {$attach}
'; return $parse; } // 单选型 // 选项1,选项2,... // 选项1:显示1,选项2:显示2,... // @model.id 调用模型 // :fun 函数 protected function _radio($var,$default) { $parse = ' $array = explode(\':\',$extra);$value = $array[0];$show = isset($array[1])?$array[1]:$array[0]; checked':'').' value="{$value}" class="{$'.$var.'.readonly}" {$'.$var.'.readonly} /> {$show} '; return $parse; } // 组合字段 protected function _complex($var,$read) { if($read) { $parse = ' '; }else{ $parse = ' '; } return $parse; } // 多选型 用多选下拉列表模拟 支持函数定义 // 选项1,选项2,... // 选项1:显示1,选项2:显示2,... // @model.id 调用模型 // :fun 函数 protected function _checkbox($var,$default) { $parse = '
选择{$'.$var.'.title}
'; return $parse; } // 枚举型 采用下拉列表模拟 // 选项1,选项2,... // 选项1:显示1,选项2:显示2,... // @model.id 调用模型 // :fun 函数 protected function _select($var,$default,$read) { if($read) { $parse = ' $array = explode(\':\',$option);$value = $array[0];$show = isset($array[1])?$array[1]:$array[0]; '; }else{ $parse = ' '; } return $parse; } // 序列化型 只支持字符串类型 // 字段名1:显示名称:样式,... protected function _serialize($var) { $parse = ' $array = explode(\':\',$option);$var = $array[0];$show = isset($array[1])?$array[1]:\'\';$class = isset($array[2])?$array[2]:\'medium\';$value = $'.$var.'[\'value\'][$var]; {$show} '; return $parse; } // 图片型 支持配置 protected function _image($var,$read) { if($read) { $parse = 'parse_str($'.$var.'[\'extra\'],$extra);$array = explode(\',\',$extra[\'thumbPrefix\']);   '; }else{ $parse = '
parse_str($'.$var.'[\'extra\'],$extra);$array = explode(\',\',$extra[\'thumbPrefix\']);   
'; } return $parse; } // 多图型 protected function _images($var) { $parse = '
$array = explode(\',\',$'.$var.'[\'value\']);
  
'; return $parse; } // 日期型 protected function _date($var,$default) { $parse = ''; return $parse; } // 动态型 用方法控制输出显示 protected function _dynamic($var) { $parse = '$fun = $'.$var.'[\'extra\'];echo $fun($'.$var.'[\'value\']); '; return $parse; } // 地区联动 protected function _zone($var) { $parse = '
'; return $parse; } // 固定值 采用隐藏字段模拟 protected function _hidden($var) { $parse = ' '; return $parse; } // HTML型 protected function _html($var) { $parse = '{$'.$var.'.value}'; return $parse; } } ?>