mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
测试
This commit is contained in:
382
Think/Template/Driver/Attr.php
Normal file
382
Think/Template/Driver/Attr.php
Normal file
@@ -0,0 +1,382 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | TOPThink
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
// $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),
|
||||
);
|
||||
|
||||
// <attr var='' complex='' />
|
||||
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 = '<?php switch($'.$var.'[\'type\']): ';
|
||||
$parse .= ' case "string":?>'.$this->_string($var,$default,$read);
|
||||
$parse .= '<?php break;case "num":?>'.$this->_num($var,$default,$read);
|
||||
$parse .= '<?php break;case "bool":?>'.$this->_bool($var,$default,$read);
|
||||
$parse .= '<?php break;case "textarea":?>'.$this->_textarea($var,$default,$read);
|
||||
$parse .= '<?php break;case "text":?>'.$this->_text($var,$default,$read);
|
||||
$parse .= '<?php break;case "editor":?>'.$this->_editor($var,$default,$read);
|
||||
$parse .= '<?php break;case "file":?>'.$this->_file($var,$read);
|
||||
$parse .= '<?php break;case "files":?>'.$this->_files($var,$read);
|
||||
$parse .= '<?php break;case "radio":?>'.$this->_radio($var,$default,$read);
|
||||
$parse .= '<?php break;case "checkbox":?>'.$this->_checkbox($var,$default,$read);
|
||||
$parse .= '<?php break;case "select":?>'.$this->_select($var,$default,$read);
|
||||
$parse .= '<?php break;case "image":?>'.$this->_image($var,$read);
|
||||
$parse .= '<?php break;case "images":?>'.$this->_images($var,$read);
|
||||
$parse .= '<?php break;case "date":?>'.$this->_date($var,$default,$read);
|
||||
$parse .= '<?php break;case "zone":?>'.$this->_zone($var,$read);
|
||||
$parse .= '<?php break;case "html":?>'.$this->_html($var,$read);
|
||||
$parse .= '<?php break;case "dynamic":?>'.$this->_dynamic($var,$read);
|
||||
$parse .= '<?php break;case "hidden":?>'.$this->_hidden($var,$read);
|
||||
$parse .= '<?php break;case "verify":?>'.$this->_verify($var,$read);
|
||||
$parse .= '<?php break;case "password":?>'.$this->_password($var,$default,$read);
|
||||
$parse .= '<?php break;case "serialize":?>'.$this->_serialize($var,$read);
|
||||
$parse .= '<?php break;case "link":?>'.$this->_link($var,$read);
|
||||
if(!empty($tag['complex'])) {
|
||||
$parse .= '<?php break;case "complex":?>'.$this->_complex($var,$read);
|
||||
}
|
||||
$parse .= '<?php endswitch;?>';
|
||||
}
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 验证码类型
|
||||
protected function _verify($var) {
|
||||
$parse = '<input type="text" name="{$'.$var.'.name}" class=" {$'.$var.'.is_must|getFieldMust} small" /> <img src="__GROUP__/Public/verify/" style="cursor:hand" onclick="this.src=\'__APP__/Public/verify/\'+new Date().getTime()" align="absmiddle" /> ';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 密码类型
|
||||
protected function _password($var,$default) {
|
||||
$value = $default?'{$'.$var.'.value}':'';
|
||||
$parse = '<input type="password" name="{$'.$var.'.name}" class="{$'.$var.'.is_must|getFieldMust} medium" value="'.$value.'" /> ';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 字符串类型
|
||||
protected function _string($var,$default,$read) {
|
||||
$value = $default?'{$'.$var.'.value}':'';
|
||||
if($read) {
|
||||
$parse = $value;
|
||||
}else{
|
||||
$parse = '<input type="text" class="{$'.$var.'.is_must|getFieldMust} {$'.$var.'.length|default=\'medium\'} {$'.$var.'.readonly}" title="{$'.$var.'.remark}" name="{$'.$var.'.name}" value="'.$value.'" {$'.$var.'.readonly}> ';
|
||||
}
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 字符串类型
|
||||
protected function _link($var,$read) {
|
||||
$value = '{$'.$var.'.value}';
|
||||
if($read) {
|
||||
$parse = $value;
|
||||
}else{
|
||||
$parse = '<input type="text" class="{$'.$var.'.length|default=\'medium\'} {$'.$var.'.readonly}" title="{$'.$var.'.remark}" name="{$'.$var.'.name}" value="'.$value.'" {$'.$var.'.readonly}> ';
|
||||
}
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 数字类型
|
||||
protected function _num($var,$default,$read) {
|
||||
$value = $default?'{$'.$var.'.value}':'';
|
||||
if($read) {
|
||||
$parse = $value;
|
||||
}else{
|
||||
$parse = '<input type="text" class="{$'.$var.'.is_must|getFieldMust} {$'.$var.'.length|default=\'small\'} {$'.$var.'.readonly}" title="{$'.$var.'.remark}" check="Number" warning="{$'.$var.'.title}必须是数字" name="{$'.$var.'.name}" value="'.$value.'" {$'.$var.'.readonly}> ';
|
||||
}
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 布尔类型 采用下拉列表模拟
|
||||
protected function _bool($var,$default,$read) {
|
||||
if($read) {
|
||||
$parse = '<?php $option = explode(\',\',$'.$var.'[\'extra\']);?>';
|
||||
$parse = '<?php echo $'.$var.'[\'value\']==\'0\'?$options[0]:$options[1];unset($options);?>';
|
||||
}else{
|
||||
$parse = '<select name="{$'.$var.'.name}" class="{$'.$var.'.is_must|getFieldMust} {$'.$var.'.length|default=\'medium\'} {$'.$var.'.readonly}" title="{$'.$var.'.remark}" {$'.$var.'.readonly} <present name="'.$var.'.readonly">onbeforeactivate="return false" onfocus="this.blur()" onmouseover="this.setCapture()" onmouseout="this.releaseCapture()"</present>>
|
||||
<option value="">选择</option>
|
||||
<?php if (!empty($'.$var.'[\'extra\'])) { $option = explode(\',\',$'.$var.'[\'extra\']);?>
|
||||
<option '.($default?'<?php if ($'.$var.'[\'value\']==\'0\'){ ?>selected<?php };?>':'').' value="0"> {$option[0]} </option>
|
||||
<option '.($default?'<?php if ($'.$var.'[\'value\']==\'1\'){ ?>selected<?php };?>':'').' value="1"> {$option[1]} </option>
|
||||
<?php }; ?>
|
||||
</select> ';
|
||||
}
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 文本域类型
|
||||
protected function _textarea($var,$default,$read) {
|
||||
$value = $default?'{$'.$var.'.value}':'';
|
||||
if($read) {
|
||||
$parse = $value;
|
||||
}else{
|
||||
$parse = '<textarea style="overflow:auto" class="{$'.$var.'.is_must|getFieldMust} {$'.$var.'.length|default=\'large\'} {$'.$var.'.readonly}" title="{$'.$var.'.remark}" name="{$'.$var.'.name}" ROWS="5" COLS="35" {$'.$var.'.readonly}>'.$value.'</textarea> ';
|
||||
}
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 文本型
|
||||
protected function _text($var,$default,$read) {
|
||||
$value = $default?'{$'.$var.'.value}':'';
|
||||
if($read) {
|
||||
$parse = $value;
|
||||
}else{
|
||||
$parse = '<script src="__PUBLIC__/Js/jquery.min.js" type="text/javascript"></script>
|
||||
<script src="__PUBLIC__/Js/jquery.shortcuts.js" type="text/javascript"></script><textarea style="overflow:auto;width:545px" class="{$'.$var.'.is_must|getFieldMust} {$'.$var.'.length|default=\'huge\'} {$'.$var.'.readonly}" id="{$'.$var.'.name}" title="{$'.$var.'.remark}" name="{$'.$var.'.name}" ROWS="8" COLS="35" {$'.$var.'.readonly}>'.$value.'</textarea><script> $("#{$'.$var.'.name}").shortcuts();</script>';
|
||||
}
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 编辑器型
|
||||
protected function _editor($var,$default,$read) {
|
||||
$value = $default?'{$'.$var.'.value}':'';
|
||||
if($read) {
|
||||
$parse = $value;
|
||||
}else{
|
||||
$parse = '<script type="text/javascript"> KE.show({ id : \'{$'.$var.'.name}\' ,urlType : "absolute"});</script><textarea id="{$'.$var.'.name}" style="width:550px;height:220px" name="{$'.$var.'.name}" {$'.$var.'.readonly}>'.$value.'</textarea> ';
|
||||
}
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 附件上传型 可配置
|
||||
protected function _file($var) {
|
||||
$parse = '<div class="impBtn fLeft" ><input type="file" name="{$'.$var.'.name}" class="{$'.$var.'.is_must|getFieldMust} file {$'.$var.'.length|default=\'huge\'} {$'.$var.'.readonly}" {$'.$var.'.readonly}></div><INPUT TYPE="button" value="删 除" onclick="delPic(\'{$'.$var.'.name}\');" class="button small" {$'.$var.'.readonly}><input type="hidden" name="__upload_{$'.$var.'.name}" value="{$'.$var.'.extra|base64_encode}"/><neq name="'.$var.'.value" value=""><div class="cBoth">{$'.$var.'.value|extension|showExt} <a href="__UPLOAD__/{$'.$var.'.value}" title="{$'.$var.'.name}" >{$'.$var.'.value}</a></div></neq> ';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 多附件型
|
||||
protected function _files($var) {
|
||||
$parse = '<input type="button" class="button {$'.$var.'.readonly}" value="添加" onclick="__addFileAttach()" {$'.$var.'.readonly}/> <INPUT TYPE="button" value="删 除" onclick="delPic(\'{$'.$var.'.name}\');" class="button small {$'.$var.'.readonly}" {$'.$var.'.readonly}><input type="hidden" name="__upload_{$'.$var.'.name}" value="{$'.$var.'.extra|base64_encode}"/><div id=\'__fileattach__\' style="clear:both"><div class="impBtn fLeft" ><input type="file" name="{$'.$var.'.name}[]" class="file large {$'.$var.'.readonly}" {$'.$var.'.readonly}></div></div><script type="text/javascript">
|
||||
<!--
|
||||
function __addFileAttach(){
|
||||
document.getElementById(\'__fileattach__\').innerHTML +=\'<div class="cBoth"><div class="impBtn fLeft" ><input type="file" name="{$'.$var.'.name}[]" class="file huge"></div></div> \';
|
||||
}
|
||||
//-->
|
||||
</script>
|
||||
<neq name="v.value" value=""><php>$array = explode(\',\',$'.$var.'[\'value\']);</php>
|
||||
<iterate name="array" id="attach">
|
||||
<div class="cBoth">
|
||||
<switch name="attach|extension">
|
||||
<case value=\'mp3\'>
|
||||
<object type="application/x-shockwave-flash" data="__PUBLIC__/Images/player.swf" width="290" height="24" id="audioplayer1"><param name="movie" value="__PUBLIC__/Images/player.swf" /><param name="FlashVars" value="playerID=1&bg=0xf8f8f8&leftbg=0xeeeeee&lefticon=0x666666&rightbg=0xcccccc&rightbghover=0x999999&righticon=0x666666&righticonhover=0xffffff&text=0x666666&slider=0x666666&track=0xFFFFFF&border=0x666666&loader=0x9FFFB8&soundFile=__UPLOAD__/{$attach}" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="bgcolor" value="#FFFFFF" /></object>
|
||||
</case>
|
||||
<case value= \'wav\'>
|
||||
<embed src="__UPLOAD__/{$attach}" width="290" height="24" style="border:1px solid silver" autostart="false"></embed>.
|
||||
</case>
|
||||
<case value="gif|jpg|jpeg|png">
|
||||
<a href="__UPLOAD__/{$attach}" alt="点击查看原图" target="_blank"><img src="__UPLOAD__/{$vo._module}/{$attach}" class="pic" width="100px" /></a>
|
||||
</case>
|
||||
<default />{$attach|extension|showExt} <A HREF="__UPLOAD__/{$attach}">{$attach}</A>
|
||||
</switch>
|
||||
</div>
|
||||
</iterate></neq> ';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 单选型
|
||||
// 选项1,选项2,...
|
||||
// 选项1:显示1,选项2:显示2,...
|
||||
// @model.id 调用模型
|
||||
// :fun 函数
|
||||
protected function _radio($var,$default) {
|
||||
$parse = '<?php if(0===strpos($'.$var.'[\'extra\'],\':\')):
|
||||
$fun = substr($'.$var.'[\'extra\'],1);
|
||||
$options = $fun();
|
||||
elseif(0===strpos($'.$var.'[\'extra\'],\'@\')):
|
||||
$options = parseT(substr($'.$var.'[\'extra\'],1));
|
||||
else:
|
||||
$options = explode(\',\',$'.$var.'[\'extra\']);
|
||||
endif;?>
|
||||
<iterate name="options" id="extra">
|
||||
<php>$array = explode(\':\',$extra);$value = $array[0];$show = isset($array[1])?$array[1]:$array[0];</php>
|
||||
<input type="radio" name="{$'.$var.'.name}" '.($default?'<?php if ($'.$var.'[\'value\']==$value){ ?>checked<?php };?>':'').' value="{$value}" class="{$'.$var.'.readonly}" {$'.$var.'.readonly} /> {$show}
|
||||
</iterate> ';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 组合字段
|
||||
protected function _complex($var,$read) {
|
||||
if($read) {
|
||||
$parse = '<iterate name="'.$var.'.complex" id="_v"><attr var="_v" read="1" /> </iterate>';
|
||||
}else{
|
||||
$parse = '<iterate name="'.$var.'.complex" id="_v"><attr var="_v" /> </iterate>';
|
||||
}
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 多选型 用多选下拉列表模拟 支持函数定义
|
||||
// 选项1,选项2,...
|
||||
// 选项1:显示1,选项2:显示2,...
|
||||
// @model.id 调用模型
|
||||
// :fun 函数
|
||||
protected function _checkbox($var,$default) {
|
||||
$parse = '<table class="select" style="width:245px" id="{$'.$var.'.name}">
|
||||
<tr><td height="5" colspan="3" class="topTd" ></td></tr>
|
||||
<tr><th class="tCenter">选择{$'.$var.'.title}</th></tr>
|
||||
<tr><td >
|
||||
<select name="{$'.$var.'.name}[]" class="hMargin medium multiSelect {$'.$var.'.readonly}" multiple="multiple" size="12" {$'.$var.'.readonly} <present name="'.$var.'.readonly">onbeforeactivate="return false" onfocus="this.blur()" onmouseover="this.setCapture()" onmouseout="this.releaseCapture()"</present>>
|
||||
<?php if(0===strpos($'.$var.'[\'extra\'],\':\')):
|
||||
$fun = substr($'.$var.'[\'extra\'],1);
|
||||
$options = $fun();
|
||||
elseif(0===strpos($'.$var.'[\'extra\'],\'@\')):
|
||||
$options = parseT(substr($'.$var.'[\'extra\'],1));
|
||||
else:
|
||||
$options = explode(\',\',$'.$var.'[\'extra\']);
|
||||
endif;?>
|
||||
<iterate name="options" id="option">
|
||||
<php>$array = explode(\':\',$option);$value = $array[0];$show = isset($array[1])?$array[1]:$array[0];</php>
|
||||
<option '.($default?'<?php if (in_array($value,explode(",",$'.$var.'[\'value\']),true)){ ?>selected<?php };?>':'').' value="{$value}" >{$show}</option>
|
||||
</iterate>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><th class="tCenter"><input type="button" onclick="allSelect(\'{$'.$var.'.name}\')" value="全 选" class="submit ">
|
||||
<input type="button" onclick="InverSelect(\'{$'.$var.'.name}\')" value="反 选" class="submit ">
|
||||
<input type="button" onclick="allUnSelect(\'{$'.$var.'.name}\')" value="全 否" class="submit ">
|
||||
</th></tr>
|
||||
<tr>
|
||||
<td height="5" class="bottomTd" >
|
||||
</td>
|
||||
</tr>
|
||||
</table> ';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 枚举型 采用下拉列表模拟
|
||||
// 选项1,选项2,...
|
||||
// 选项1:显示1,选项2:显示2,...
|
||||
// @model.id 调用模型
|
||||
// :fun 函数
|
||||
protected function _select($var,$default,$read) {
|
||||
if($read) {
|
||||
$parse = '<?php if(0===strpos($'.$var.'[\'extra\'],\'@\')):
|
||||
$options = parseT(substr($'.$var.'[\'extra\'],1));
|
||||
elseif(0===strpos($'.$var.'[\'extra\'],\':\')):
|
||||
$fun = substr($'.$var.'[\'extra\'],1);
|
||||
$options = $fun();
|
||||
else:
|
||||
$options = explode(\',\',$'.$var.'[\'extra\']);
|
||||
endif;?><iterate name="options" id="option">
|
||||
<php>$array = explode(\':\',$option);$value = $array[0];$show = isset($array[1])?$array[1]:$array[0];</php>
|
||||
<?php if ($'.$var.'[\'value\']==$value){ echo $show;unset($options);break;}?></iterate>
|
||||
';
|
||||
}else{
|
||||
$parse = '<select name="{$'.$var.'.name}" class="{$'.$var.'.is_must|getFieldMust} {$'.$var.'.length|default=\'medium\'} {$'.$var.'.readonly}" title="{$'.$var.'.remark}" {$'.$var.'.readonly} <present name="'.$var.'.readonly">onbeforeactivate="return false" onfocus="this.blur()" onmouseover="this.setCapture()" onmouseout="this.releaseCapture()"</present>>
|
||||
<option value=""> --选择-- </option>
|
||||
<?php if (!empty($'.$var.'[\'extra\'])) {
|
||||
if(0===strpos($'.$var.'[\'extra\'],\'@\')):
|
||||
$options = parseT(substr($'.$var.'[\'extra\'],1));
|
||||
elseif(0===strpos($'.$var.'[\'extra\'],\':\')):
|
||||
$fun = substr($'.$var.'[\'extra\'],1);
|
||||
$options = $fun();
|
||||
else:
|
||||
$options = explode(\',\',$'.$var.'[\'extra\']);
|
||||
endif;?>
|
||||
<iterate name="options" id="option">
|
||||
<php>$array = explode(\':\',$option);$value = $array[0];$show = isset($array[1])?$array[1]:$array[0];</php>
|
||||
<option '.($default?'<?php if ($'.$var.'[\'value\']==$value){ ?>selected<?php };?>':'').' value="{$value}"> {$show} </option>
|
||||
</iterate>
|
||||
<?php }; ?>
|
||||
</select> ';
|
||||
}
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 序列化型 只支持字符串类型
|
||||
// 字段名1:显示名称:样式,...
|
||||
protected function _serialize($var) {
|
||||
$parse = '<?php $options = explode(\',\',$'.$var.'[\'extra\']);?>
|
||||
<iterate name="options" id="option">
|
||||
<php>$array = explode(\':\',$option);$var = $array[0];$show = isset($array[1])?$array[1]:\'\';$class = isset($array[2])?$array[2]:\'medium\';$value = $'.$var.'[\'value\'][$var];</php>
|
||||
{$show} <input type="text" class="{$class}" title="{$show}" name="{$var}" value="{$value}" {$'.$var.'.readonly} >
|
||||
</iterate>';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 图片型 支持配置
|
||||
protected function _image($var,$read) {
|
||||
if($read) {
|
||||
$parse = '<neq name="v.value" value=""><php>parse_str($'.$var.'[\'extra\'],$extra);$array = explode(\',\',$extra[\'thumbPrefix\']);</php>
|
||||
<eq name="extra.thumb" value="1">
|
||||
<iterate name="array" id="thumbPre"><a href="__UPLOAD__/{$'.$var.'.value}" title="点击查看原图" target="_blank"><img class="cBoth pic" src="__UPLOAD__/{$thumbPre}{$'.$var.'.value}"></a> </iterate><else/><a href="__UPLOAD__/{$'.$var.'.value}" title="点击查看原图" target="_blank"><img class="cBoth pic" src="__UPLOAD__/{$'.$var.'.value}"></a></eq></neq>';
|
||||
}else{
|
||||
$parse = '<div class="impBtn" ><input type="file" name="{$'.$var.'.name}" class="{$'.$var.'.is_must|getFieldMust} file {$'.$var.'.length|default=\'medium\'} {$'.$var.'.readonly}" {$'.$var.'.readonly}></div><div><input type="hidden" class="fNone" name="__upload_{$'.$var.'.name}" value="{$'.$var.'.extra|base64_encode}"/><neq name="v.value" value=""><php>parse_str($'.$var.'[\'extra\'],$extra);$array = explode(\',\',$extra[\'thumbPrefix\']);</php>
|
||||
<eq name="extra.thumb" value="1">
|
||||
<iterate name="array" id="thumbPre"><a href="__UPLOAD__/{$'.$var.'.value}" title="点击查看原图" target="_blank"><img class="cBoth pic" src="__UPLOAD__/{$thumbPre}{$'.$var.'.value}"></a> </iterate><else/><a href="__UPLOAD__/{$'.$var.'.value}" title="点击查看原图" target="_blank"><img class="cBoth pic" src="__UPLOAD__/{$'.$var.'.value}"></a></eq><INPUT TYPE="button" value="删 除" onclick="delPic(\'{$'.$var.'.name}\');" class="button small"></neq></div> ';
|
||||
}
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 多图型
|
||||
protected function _images($var) {
|
||||
$parse = '<input type="button" class="button {$'.$var.'.readonly}" value="添加" onclick="__addAttach()" {$'.$var.'.readonly} /> <INPUT TYPE="button" value="删 除" onclick="delPic(\'{$'.$var.'.name}\');" class="button small {$'.$var.'.readonly}" {$'.$var.'.readonly}><input type="hidden" name="__upload_{$'.$var.'.name}" value="{$'.$var.'.extra|base64_encode}"/><div id=\'__attach__\' style="clear:both"><div class="impBtn fLeft" ><input type="file" name="{$'.$var.'.name}[]" class="file huge {$'.$var.'.readonly}" {$'.$var.'.readonly}></div></div><script type="text/javascript">
|
||||
<!--
|
||||
function __addAttach(){
|
||||
document.getElementById(\'__attach__\').innerHTML +=\'<div class="cBoth"><div class="impBtn fLeft" ><input type="file" name="{$'.$var.'.name}[]" class="file huge"></div></div> \';
|
||||
}
|
||||
//-->
|
||||
</script>
|
||||
<neq name="v.value" value=""><php>$array = explode(\',\',$'.$var.'[\'value\']);</php>
|
||||
<iterate name="array" id="attach">
|
||||
<div class="cBoth"><a href="__UPLOAD__/{$attach}" title="点击查看原图" target="_blank"><img class="cBoth pic" src="__UPLOAD__/{$thumbPre}{$attach}"></a> </div>
|
||||
</iterate></neq> ';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 日期型
|
||||
protected function _date($var,$default) {
|
||||
$parse = '<present name="'.$var.'.readonly"><input type="text" name="{$'.$var.'.name}" value="'.($default?'{$'.$var.'.value|toDate=\'Y-m-d\'}':'').'" class="Wdate {$'.$var.'.is_must|getFieldMust} {$'.$var.'.readonly}" {$'.$var.'.readonly}><else/><input type="text" name="{$'.$var.'.name}" value="'.($default?'{$'.$var.'.value|toDate=\'Y-m-d\'}':'').'" onClick="WdatePicker()" class="Wdate {$'.$var.'.is_must|getFieldMust} " ></present>';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 动态型 用方法控制输出显示
|
||||
protected function _dynamic($var) {
|
||||
$parse = '<php>$fun = $'.$var.'[\'extra\'];echo $fun($'.$var.'[\'value\']);</php> ';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 地区联动
|
||||
protected function _zone($var) {
|
||||
$parse = '<style>#ppc select{ width:100px }</style>
|
||||
<script src="__PUBLIC__/Js/ppc/jquery-1.4.js" type="text/javascript"></script>
|
||||
<script src="__PUBLIC__/Js/ppc/jquery.provincesCity.1.4.js" type="text/javascript"></script>
|
||||
<script src="__PUBLIC__/Js/ppc/provincesdata.js" type="text/javascript"></script>
|
||||
<script>
|
||||
//调用插件
|
||||
$(function(){
|
||||
$("#ppc").ProvinceCity(\'{$vo[\'province\']}\', \'{$vo[\'city\']}\', \'{$vo[\'county\']}\');
|
||||
});
|
||||
</script>
|
||||
<div id="ppc"></div> ';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// 固定值 采用隐藏字段模拟
|
||||
protected function _hidden($var) {
|
||||
$parse = '<input type="hidden" name="{$'.$var.'.name}" value="{$'.$var.'.value}"> ';
|
||||
return $parse;
|
||||
}
|
||||
|
||||
// HTML型
|
||||
protected function _html($var) {
|
||||
$parse = '{$'.$var.'.value}';
|
||||
return $parse;
|
||||
}
|
||||
}
|
||||
?>
|
||||
614
Think/Template/Driver/Cx.php
Normal file
614
Think/Template/Driver/Cx.php
Normal file
@@ -0,0 +1,614 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace Think\Template\Driver;
|
||||
use Think\TagLib;
|
||||
/**
|
||||
* CX标签库解析类
|
||||
* @category Think
|
||||
* @package Think
|
||||
* @subpackage Driver.Taglib
|
||||
* @author liu21st <liu21st@gmail.com>
|
||||
*/
|
||||
class Cx extends TagLib {
|
||||
|
||||
// 标签定义
|
||||
protected $tags = array(
|
||||
// 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次
|
||||
'php' => array(),
|
||||
'volist' => array('attr'=>'name,id,offset,length,key,mod','level'=>3,'alias'=>'iterate'),
|
||||
'foreach' => array('attr'=>'name,item,key','level'=>3),
|
||||
'if' => array('attr'=>'condition','level'=>2),
|
||||
'elseif' => array('attr'=>'condition','close'=>0),
|
||||
'else' => array('attr'=>'','close'=>0),
|
||||
'switch' => array('attr'=>'name','level'=>2),
|
||||
'case' => array('attr'=>'value,break'),
|
||||
'default' => array('attr'=>'','close'=>0),
|
||||
'compare' => array('attr'=>'name,value,type','level'=>3,'alias'=>'eq,equal,notequal,neq,gt,lt,egt,elt,heq,nheq'),
|
||||
'range' => array('attr'=>'name,value,type','level'=>3,'alias'=>'in,notin,between,notbetween'),
|
||||
'empty' => array('attr'=>'name','level'=>3),
|
||||
'notempty' => array('attr'=>'name','level'=>3),
|
||||
'present' => array('attr'=>'name','level'=>3),
|
||||
'notpresent'=> array('attr'=>'name','level'=>3),
|
||||
'defined' => array('attr'=>'name','level'=>3),
|
||||
'notdefined'=> array('attr'=>'name','level'=>3),
|
||||
'import' => array('attr'=>'file,href,type,value,basepath','close'=>0,'alias'=>'load,css,js'),
|
||||
'assign' => array('attr'=>'name,value','close'=>0),
|
||||
'define' => array('attr'=>'name,value','close'=>0),
|
||||
'for' => array('attr'=>'start,end,name,comparison,step', 'level'=>3),
|
||||
);
|
||||
|
||||
/**
|
||||
* php标签解析
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _php($tag,$content) {
|
||||
$parseStr = '<?php '.$content.' ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* volist标签解析 循环输出数据集
|
||||
* 格式:
|
||||
* <volist name="userList" id="user" empty="" >
|
||||
* {user.username}
|
||||
* {user.email}
|
||||
* </volist>
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string|void
|
||||
*/
|
||||
public function _volist($tag,$content) {
|
||||
$name = $tag['name'];
|
||||
$id = $tag['id'];
|
||||
$empty = isset($tag['empty'])?$tag['empty']:'';
|
||||
$key = !empty($tag['key'])?$tag['key']:'i';
|
||||
$mod = isset($tag['mod'])?$tag['mod']:'2';
|
||||
// 允许使用函数设定数据集 <volist name=":fun('arg')" id="vo">{$vo.name}</volist>
|
||||
$parseStr = '<?php ';
|
||||
if(0===strpos($name,':')) {
|
||||
$parseStr .= '$_result='.substr($name,1).';';
|
||||
$name = '$_result';
|
||||
}else{
|
||||
$name = $this->autoBuildVar($name);
|
||||
}
|
||||
$parseStr .= 'if(is_array('.$name.')): $'.$key.' = 0;';
|
||||
if(isset($tag['length']) && '' !=$tag['length'] ) {
|
||||
$parseStr .= ' $__LIST__ = array_slice('.$name.','.$tag['offset'].','.$tag['length'].',true);';
|
||||
}elseif(isset($tag['offset']) && '' !=$tag['offset']){
|
||||
$parseStr .= ' $__LIST__ = array_slice('.$name.','.$tag['offset'].',null,true);';
|
||||
}else{
|
||||
$parseStr .= ' $__LIST__ = '.$name.';';
|
||||
}
|
||||
$parseStr .= 'if( count($__LIST__)==0 ) : echo "'.$empty.'" ;';
|
||||
$parseStr .= 'else: ';
|
||||
$parseStr .= 'foreach($__LIST__ as $key=>$'.$id.'): ';
|
||||
$parseStr .= '$mod = ($'.$key.' % '.$mod.' );';
|
||||
$parseStr .= '++$'.$key.';?>';
|
||||
$parseStr .= ($content);
|
||||
$parseStr .= '<?php endforeach; endif; else: echo "'.$empty.'" ;endif; ?>';
|
||||
|
||||
if(!empty($parseStr)) {
|
||||
return $parseStr;
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
/**
|
||||
* foreach标签解析 循环输出数据集
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string|void
|
||||
*/
|
||||
public function _foreach($tag,$content) {
|
||||
$name = $tag['name'];
|
||||
$item = $tag['item'];
|
||||
$key = !empty($tag['key'])?$tag['key']:'key';
|
||||
$name = $this->autoBuildVar($name);
|
||||
$parseStr = '<?php if(is_array('.$name.')): foreach('.$name.' as $'.$key.'=>$'.$item.'): ?>';
|
||||
$parseStr .= ($content);
|
||||
$parseStr .= '<?php endforeach; endif; ?>';
|
||||
if(!empty($parseStr)) {
|
||||
return $parseStr;
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
/**
|
||||
* if标签解析
|
||||
* 格式:
|
||||
* <if condition=" $a eq 1" >
|
||||
* <elseif condition="$a eq 2" />
|
||||
* <else />
|
||||
* </if>
|
||||
* 表达式支持 eq neq gt egt lt elt == > >= < <= or and || &&
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _if($tag,$content) {
|
||||
$condition = $this->parseCondition($tag['condition']);
|
||||
$parseStr = '<?php if('.$condition.'): ?>'.$content.'<?php endif; ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* else标签解析
|
||||
* 格式:见if标签
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _elseif($tag,$content) {
|
||||
$condition = $this->parseCondition($tag['condition']);
|
||||
$parseStr = '<?php elseif('.$condition.'): ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* else标签解析
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @return string
|
||||
*/
|
||||
public function _else($tag) {
|
||||
$parseStr = '<?php else: ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* switch标签解析
|
||||
* 格式:
|
||||
* <switch name="a.name" >
|
||||
* <case value="1" break="false">1</case>
|
||||
* <case value="2" >2</case>
|
||||
* <default />other
|
||||
* </switch>
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _switch($tag,$content) {
|
||||
$name = $tag['name'];
|
||||
$varArray = explode('|',$name);
|
||||
$name = array_shift($varArray);
|
||||
$name = $this->autoBuildVar($name);
|
||||
if(count($varArray)>0)
|
||||
$name = $this->parseVarFunction($name,$varArray);
|
||||
$parseStr = '<?php switch('.$name.'): ?>'.$content.'<?php endswitch;?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* case标签解析 需要配合switch才有效
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _case($tag,$content) {
|
||||
$value = $tag['value'];
|
||||
if('$' == substr($value,0,1)) {
|
||||
$varArray = explode('|',$value);
|
||||
$value = array_shift($varArray);
|
||||
$value = $this->autoBuildVar(substr($value,1));
|
||||
if(count($varArray)>0)
|
||||
$value = $this->parseVarFunction($value,$varArray);
|
||||
$value = 'case '.$value.': ';
|
||||
}elseif(strpos($value,'|')){
|
||||
$values = explode('|',$value);
|
||||
$value = '';
|
||||
foreach ($values as $val){
|
||||
$value .= 'case "'.addslashes($val).'": ';
|
||||
}
|
||||
}else{
|
||||
$value = 'case "'.$value.'": ';
|
||||
}
|
||||
$parseStr = '<?php '.$value.' ?>'.$content;
|
||||
$isBreak = isset($tag['break']) ? $tag['break'] : '';
|
||||
if('' ==$isBreak || $isBreak) {
|
||||
$parseStr .= '<?php break;?>';
|
||||
}
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* default标签解析 需要配合switch才有效
|
||||
* 使用: <default />ddfdf
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _default($tag) {
|
||||
$parseStr = '<?php default: ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* compare标签解析
|
||||
* 用于值的比较 支持 eq neq gt lt egt elt heq nheq 默认是eq
|
||||
* 格式: <compare name="" type="eq" value="" >content</compare>
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _compare($tag,$content,$type='eq') {
|
||||
$name = $tag['name'];
|
||||
$value = $tag['value'];
|
||||
$type = isset($tag['type'])?$tag['type']:$type;
|
||||
$type = $this->parseCondition(' '.$type.' ');
|
||||
$varArray = explode('|',$name);
|
||||
$name = array_shift($varArray);
|
||||
$name = $this->autoBuildVar($name);
|
||||
if(count($varArray)>0)
|
||||
$name = $this->parseVarFunction($name,$varArray);
|
||||
if('$' == substr($value,0,1)) {
|
||||
$value = $this->autoBuildVar(substr($value,1));
|
||||
}else {
|
||||
$value = '"'.$value.'"';
|
||||
}
|
||||
$parseStr = '<?php if(('.$name.') '.$type.' '.$value.'): ?>'.$content.'<?php endif; ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
public function _eq($tag,$content) {
|
||||
return $this->_compare($tag,$content,'eq');
|
||||
}
|
||||
|
||||
public function _equal($tag,$content) {
|
||||
return $this->_compare($tag,$content,'eq');
|
||||
}
|
||||
|
||||
public function _neq($tag,$content) {
|
||||
return $this->_compare($tag,$content,'neq');
|
||||
}
|
||||
|
||||
public function _notequal($tag,$content) {
|
||||
return $this->_compare($tag,$content,'neq');
|
||||
}
|
||||
|
||||
public function _gt($tag,$content) {
|
||||
return $this->_compare($tag,$content,'gt');
|
||||
}
|
||||
|
||||
public function _lt($tag,$content) {
|
||||
return $this->_compare($tag,$content,'lt');
|
||||
}
|
||||
|
||||
public function _egt($tag,$content) {
|
||||
return $this->_compare($tag,$content,'egt');
|
||||
}
|
||||
|
||||
public function _elt($tag,$content) {
|
||||
return $this->_compare($tag,$content,'elt');
|
||||
}
|
||||
|
||||
public function _heq($tag,$content) {
|
||||
return $this->_compare($tag,$content,'heq');
|
||||
}
|
||||
|
||||
public function _nheq($tag,$content) {
|
||||
return $this->_compare($tag,$content,'nheq');
|
||||
}
|
||||
|
||||
/**
|
||||
* range标签解析
|
||||
* 如果某个变量存在于某个范围 则输出内容 type= in 表示在范围内 否则表示在范围外
|
||||
* 格式: <range name="var|function" value="val" type='in|notin' >content</range>
|
||||
* example: <range name="a" value="1,2,3" type='in' >content</range>
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @param string $type 比较类型
|
||||
* @return string
|
||||
*/
|
||||
public function _range($tag,$content,$type='in') {
|
||||
$name = $tag['name'];
|
||||
$value = $tag['value'];
|
||||
$varArray = explode('|',$name);
|
||||
$name = array_shift($varArray);
|
||||
$name = $this->autoBuildVar($name);
|
||||
if(count($varArray)>0)
|
||||
$name = $this->parseVarFunction($name,$varArray);
|
||||
|
||||
$type = isset($tag['type'])?$tag['type']:$type;
|
||||
|
||||
if('$' == substr($value,0,1)) {
|
||||
$value = $this->autoBuildVar(substr($value,1));
|
||||
$str = 'is_array('.$value.')?'.$value.':explode(\',\','.$value.')';
|
||||
}else{
|
||||
$value = '"'.$value.'"';
|
||||
$str = 'explode(\',\','.$value.')';
|
||||
}
|
||||
if($type=='between') {
|
||||
$parseStr = '<?php $_RANGE_VAR_='.$str.';if('.$name.'>= $_RANGE_VAR_[0] && '.$name.'<= $_RANGE_VAR_[1]):?>'.$content.'<?php endif; ?>';
|
||||
}elseif($type=='notbetween'){
|
||||
$parseStr = '<?php $_RANGE_VAR_='.$str.';if('.$name.'<$_RANGE_VAR_[0] && '.$name.'>$_RANGE_VAR_[1]):?>'.$content.'<?php endif; ?>';
|
||||
}else{
|
||||
$fun = ($type == 'in')? 'in_array' : '!in_array';
|
||||
$parseStr = '<?php if('.$fun.'(('.$name.'), '.$str.')): ?>'.$content.'<?php endif; ?>';
|
||||
}
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
// range标签的别名 用于in判断
|
||||
public function _in($tag,$content) {
|
||||
return $this->_range($tag,$content,'in');
|
||||
}
|
||||
|
||||
// range标签的别名 用于notin判断
|
||||
public function _notin($tag,$content) {
|
||||
return $this->_range($tag,$content,'notin');
|
||||
}
|
||||
|
||||
public function _between($tag,$content){
|
||||
return $this->_range($tag,$content,'between');
|
||||
}
|
||||
|
||||
public function _notbetween($tag,$content){
|
||||
return $this->_range($tag,$content,'notbetween');
|
||||
}
|
||||
|
||||
/**
|
||||
* present标签解析
|
||||
* 如果某个变量已经设置 则输出内容
|
||||
* 格式: <present name="" >content</present>
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _present($tag,$content) {
|
||||
$name = $tag['name'];
|
||||
$name = $this->autoBuildVar($name);
|
||||
$parseStr = '<?php if(isset('.$name.')): ?>'.$content.'<?php endif; ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* notpresent标签解析
|
||||
* 如果某个变量没有设置,则输出内容
|
||||
* 格式: <notpresent name="" >content</notpresent>
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _notpresent($tag,$content) {
|
||||
$name = $tag['name'];
|
||||
$name = $this->autoBuildVar($name);
|
||||
$parseStr = '<?php if(!isset('.$name.')): ?>'.$content.'<?php endif; ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* empty标签解析
|
||||
* 如果某个变量为empty 则输出内容
|
||||
* 格式: <empty name="" >content</empty>
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _empty($tag,$content) {
|
||||
$name = $tag['name'];
|
||||
$name = $this->autoBuildVar($name);
|
||||
$parseStr = '<?php if(empty('.$name.')): ?>'.$content.'<?php endif; ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
public function _notempty($tag,$content) {
|
||||
$name = $tag['name'];
|
||||
$name = $this->autoBuildVar($name);
|
||||
$parseStr = '<?php if(!empty('.$name.')): ?>'.$content.'<?php endif; ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否已经定义了该常量
|
||||
* <defined name='TXT'>已定义</defined>
|
||||
* @param <type> $tag
|
||||
* @param <type> $content
|
||||
* @return string
|
||||
*/
|
||||
public function _defined($tag,$content) {
|
||||
$name = $tag['name'];
|
||||
$parseStr = '<?php if(defined("'.$name.'")): ?>'.$content.'<?php endif; ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
public function _notdefined($tag,$content) {
|
||||
$name = $tag['name'];
|
||||
$parseStr = '<?php if(!defined("'.$name.'")): ?>'.$content.'<?php endif; ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* import 标签解析 <import file="Js.Base" />
|
||||
* <import file="Css.Base" type="css" />
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @param boolean $isFile 是否文件方式
|
||||
* @param string $type 类型
|
||||
* @return string
|
||||
*/
|
||||
public function _import($tag,$content,$isFile=false,$type='') {
|
||||
$file = isset($tag['file'])?$tag['file']:$tag['href'];
|
||||
$parseStr = '';
|
||||
$endStr = '';
|
||||
// 判断是否存在加载条件 允许使用函数判断(默认为isset)
|
||||
if (isset($tag['value'])) {
|
||||
$varArray = explode('|',$tag['value']);
|
||||
$name = array_shift($varArray);
|
||||
$name = $this->autoBuildVar($name);
|
||||
if (!empty($varArray))
|
||||
$name = $this->parseVarFunction($name,$varArray);
|
||||
else
|
||||
$name = 'isset('.$name.')';
|
||||
$parseStr .= '<?php if('.$name.'): ?>';
|
||||
$endStr = '<?php endif; ?>';
|
||||
}
|
||||
if($isFile) {
|
||||
// 根据文件名后缀自动识别
|
||||
$type = $type?$type:(!empty($tag['type'])?strtolower($tag['type']):null);
|
||||
// 文件方式导入
|
||||
$array = explode(',',$file);
|
||||
foreach ($array as $val){
|
||||
if (!$type || isset($reset)) {
|
||||
$type = $reset = strtolower(substr(strrchr($val, '.'),1));
|
||||
}
|
||||
switch($type) {
|
||||
case 'js':
|
||||
$parseStr .= '<script type="text/javascript" src="'.$val.'"></script>';
|
||||
break;
|
||||
case 'css':
|
||||
$parseStr .= '<link rel="stylesheet" type="text/css" href="'.$val.'" />';
|
||||
break;
|
||||
case 'php':
|
||||
$parseStr .= '<?php require_cache("'.$val.'"); ?>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
// 命名空间导入模式 默认是js
|
||||
$type = $type?$type:(!empty($tag['type'])?strtolower($tag['type']):'js');
|
||||
$basepath = !empty($tag['basepath'])?$tag['basepath']:__ROOT__.'/Public';
|
||||
// 命名空间方式导入外部文件
|
||||
$array = explode(',',$file);
|
||||
foreach ($array as $val){
|
||||
list($val,$version) = explode('?',$val);
|
||||
switch($type) {
|
||||
case 'js':
|
||||
$parseStr .= '<script type="text/javascript" src="'.$basepath.'/'.str_replace(array('.','#'), array('/','.'),$val).'.js'.($version?'?'.$version:'').'"></script>';
|
||||
break;
|
||||
case 'css':
|
||||
$parseStr .= '<link rel="stylesheet" type="text/css" href="'.$basepath.'/'.str_replace(array('.','#'), array('/','.'),$val).'.css'.($version?'?'.$version:'').'" />';
|
||||
break;
|
||||
case 'php':
|
||||
$parseStr .= '<?php import("'.$val.'"); ?>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $parseStr.$endStr;
|
||||
}
|
||||
|
||||
// import别名 采用文件方式加载(要使用命名空间必须用import) 例如 <load file="__PUBLIC__/Js/Base.js" />
|
||||
public function _load($tag,$content) {
|
||||
return $this->_import($tag,$content,true);
|
||||
}
|
||||
|
||||
// import别名使用 导入css文件 <css file="__PUBLIC__/Css/Base.css" />
|
||||
public function _css($tag,$content) {
|
||||
return $this->_import($tag,$content,true,'css');
|
||||
}
|
||||
|
||||
// import别名使用 导入js文件 <js file="__PUBLIC__/Js/Base.js" />
|
||||
public function _js($tag,$content) {
|
||||
return $this->_import($tag,$content,true,'js');
|
||||
}
|
||||
|
||||
/**
|
||||
* assign标签解析
|
||||
* 在模板中给某个变量赋值 支持变量赋值
|
||||
* 格式: <assign name="" value="" />
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _assign($tag,$content) {
|
||||
$name = $this->autoBuildVar($tag['name']);
|
||||
if('$'==substr($tag['value'],0,1)) {
|
||||
$value = $this->autoBuildVar(substr($tag['value'],1));
|
||||
}else{
|
||||
$value = '\''.$tag['value']. '\'';
|
||||
}
|
||||
$parseStr = '<?php '.$name.' = '.$value.'; ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* define标签解析
|
||||
* 在模板中定义常量 支持变量赋值
|
||||
* 格式: <define name="" value="" />
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _define($tag,$content) {
|
||||
$name = '\''.$tag['name']. '\'';
|
||||
if('$'==substr($tag['value'],0,1)) {
|
||||
$value = $this->autoBuildVar(substr($tag['value'],1));
|
||||
}else{
|
||||
$value = '\''.$tag['value']. '\'';
|
||||
}
|
||||
$parseStr = '<?php define('.$name.', '.$value.'); ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* for标签解析
|
||||
* 格式: <for start="" end="" comparison="" step="" name="" />
|
||||
* @access public
|
||||
* @param array $tag 标签属性
|
||||
* @param string $content 标签内容
|
||||
* @return string
|
||||
*/
|
||||
public function _for($tag, $content){
|
||||
//设置默认值
|
||||
$start = 0;
|
||||
$end = 0;
|
||||
$step = 1;
|
||||
$comparison = 'lt';
|
||||
$name = 'i';
|
||||
$rand = rand(); //添加随机数,防止嵌套变量冲突
|
||||
//获取属性
|
||||
foreach ($tag as $key => $value){
|
||||
$value = trim($value);
|
||||
if(':'==substr($value,0,1))
|
||||
$value = substr($value,1);
|
||||
elseif('$'==substr($value,0,1))
|
||||
$value = $this->autoBuildVar(substr($value,1));
|
||||
switch ($key){
|
||||
case 'start':
|
||||
$start = $value; break;
|
||||
case 'end' :
|
||||
$end = $value; break;
|
||||
case 'step':
|
||||
$step = $value; break;
|
||||
case 'comparison':
|
||||
$comparison = $value; break;
|
||||
case 'name':
|
||||
$name = $value; break;
|
||||
}
|
||||
}
|
||||
|
||||
$parseStr = '<?php $__FOR_START_'.$rand.'__='.$start.';$__FOR_END_'.$rand.'__='.$end.';';
|
||||
$parseStr .= 'for($'.$name.'=$__FOR_START_'.$rand.'__;'.$this->parseCondition('$'.$name.' '.$comparison.' $__FOR_END_'.$rand.'__').';$'.$name.'+='.$step.'){ ?>';
|
||||
$parseStr .= $content;
|
||||
$parseStr .= '<?php } ?>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
}
|
||||
570
Think/Template/Driver/Html.php
Normal file
570
Think/Template/Driver/Html.php
Normal file
@@ -0,0 +1,570 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
// $Id: TagLibHtml.class.php 2730 2012-02-12 04:45:34Z liu21st $
|
||||
|
||||
namespace Think\Template\Driver;
|
||||
/**
|
||||
+-------------------------------
|
||||
* Html标签库驱动
|
||||
+-------------------------------
|
||||
*/
|
||||
class Html extends \Think\TagLib{
|
||||
// 标签定义
|
||||
protected $tags = array(
|
||||
// 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次
|
||||
'editor' => array('attr'=>'id,name,style,width,height,type','close'=>1),
|
||||
'select' => array('attr'=>'name,options,values,output,multiple,id,size,first,change,selected,dblclick','close'=>0),
|
||||
'grid' => array('attr'=>'id,pk,style,action,actionlist,show,datasource','close'=>0),
|
||||
'list' => array('attr'=>'id,pk,style,action,actionlist,show,datasource,checkbox','close'=>0),
|
||||
'imagebtn' => array('attr'=>'id,name,value,type,style,click','close'=>0),
|
||||
'checkbox' => array('attr'=>'name,checkboxes,checked,separator','close'=>0),
|
||||
'radio' => array('attr'=>'name,radios,checked,separator','close'=>0)
|
||||
);
|
||||
|
||||
/**
|
||||
+----------------------------------------------------------
|
||||
* editor标签解析 插入可视化编辑器
|
||||
* 格式: <html:editor id="editor" name="remark" type="FCKeditor" style="" >{$vo.remark}</html:editor>
|
||||
+----------------------------------------------------------
|
||||
* @access public
|
||||
+----------------------------------------------------------
|
||||
* @param string $attr 标签属性
|
||||
+----------------------------------------------------------
|
||||
* @return string|void
|
||||
+----------------------------------------------------------
|
||||
*/
|
||||
public function _editor($tag,$content) {
|
||||
$id = !empty($tag['id'])?$tag['id']: '_editor';
|
||||
$name = $tag['name'];
|
||||
$style = !empty($tag['style'])?$tag['style']:'';
|
||||
$width = !empty($tag['width'])?$tag['width']: '100%';
|
||||
$height = !empty($tag['height'])?$tag['height'] :'320px';
|
||||
// $content = $tag['content'];
|
||||
$type = $tag['type'] ;
|
||||
switch(strtoupper($type)) {
|
||||
case 'FCKEDITOR':
|
||||
$parseStr = '<!-- 编辑器调用开始 --><script type="text/javascript" src="__ROOT__/Public/Js/FCKeditor/fckeditor.js"></script><textarea id="'.$id.'" name="'.$name.'">'.$content.'</textarea><script type="text/javascript"> var oFCKeditor = new FCKeditor( "'.$id.'","'.$width.'","'.$height.'" ) ; oFCKeditor.BasePath = "__ROOT__/Public/Js/FCKeditor/" ; oFCKeditor.ReplaceTextarea() ;function resetEditor(){setContents("'.$id.'",document.getElementById("'.$id.'").value)}; function saveEditor(){document.getElementById("'.$id.'").value = getContents("'.$id.'");} function InsertHTML(html){ var oEditor = FCKeditorAPI.GetInstance("'.$id.'") ;if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG ){oEditor.InsertHtml(html) ;}else alert( "FCK必须处于WYSIWYG模式!" ) ;}</script> <!-- 编辑器调用结束 -->';
|
||||
break;
|
||||
case 'FCKMINI':
|
||||
$parseStr = '<!-- 编辑器调用开始 --><script type="text/javascript" src="__ROOT__/Public/Js/FCKMini/fckeditor.js"></script><textarea id="'.$id.'" name="'.$name.'">'.$content.'</textarea><script type="text/javascript"> var oFCKeditor = new FCKeditor( "'.$id.'","'.$width.'","'.$height.'" ) ; oFCKeditor.BasePath = "__ROOT__/Public/Js/FCKMini/" ; oFCKeditor.ReplaceTextarea() ;function resetEditor(){setContents("'.$id.'",document.getElementById("'.$id.'").value)}; function saveEditor(){document.getElementById("'.$id.'").value = getContents("'.$id.'");} function InsertHTML(html){ var oEditor = FCKeditorAPI.GetInstance("'.$id.'") ;if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG ){oEditor.InsertHtml(html) ;}else alert( "FCK必须处于WYSIWYG模式!" ) ;}</script> <!-- 编辑器调用结束 -->';
|
||||
break;
|
||||
case 'EWEBEDITOR':
|
||||
$parseStr = "<!-- 编辑器调用开始 --><script type='text/javascript' src='__ROOT__/Public/Js/eWebEditor/js/edit.js'></script><input type='hidden' id='{$id}' name='{$name}' value='{$conent}'><iframe src='__ROOT__/Public/Js/eWebEditor/ewebeditor.htm?id={$name}' frameborder=0 scrolling=no width='{$width}' height='{$height}'></iframe><script type='text/javascript'>function saveEditor(){document.getElementById('{$id}').value = getHTML();} </script><!-- 编辑器调用结束 -->";
|
||||
break;
|
||||
case 'NETEASE':
|
||||
$parseStr = '<!-- 编辑器调用开始 --><textarea id="'.$id.'" name="'.$name.'" style="display:none">'.$content.'</textarea><iframe ID="Editor" name="Editor" src="__ROOT__/Public/Js/HtmlEditor/index.html?ID='.$name.'" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" style="height:'.$height.';width:'.$width.'"></iframe><!-- 编辑器调用结束 -->';
|
||||
break;
|
||||
case 'UBB':
|
||||
$parseStr = '<script type="text/javascript" src="__ROOT__/Public/Js/UbbEditor.js"></script><div style="padding:1px;width:'.$width.';border:1px solid silver;float:left;"><script LANGUAGE="JavaScript"> showTool(); </script></div><div><TEXTAREA id="UBBEditor" name="'.$name.'" style="clear:both;float:none;width:'.$width.';height:'.$height.'" >'.$content.'</TEXTAREA></div><div style="padding:1px;width:'.$width.';border:1px solid silver;float:left;"><script LANGUAGE="JavaScript">showEmot(); </script></div>';
|
||||
break;
|
||||
case 'KINDEDITOR':
|
||||
$parseStr = '<script type="text/javascript" src="__ROOT__/Public/Js/KindEditor/kindeditor.js"></script><script type="text/javascript"> KE.show({ id : \''.$id.'\' ,urlType : "absolute"});</script><textarea id="'.$id.'" style="'.$style.'" name="'.$name.'" >'.$content.'</textarea>';
|
||||
break;
|
||||
default :
|
||||
$parseStr = '<textarea id="'.$id.'" style="'.$style.'" name="'.$name.'" >'.$content.'</textarea>';
|
||||
}
|
||||
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
+----------------------------------------------------------
|
||||
* imageBtn标签解析
|
||||
* 格式: <html:imageBtn type="" value="" />
|
||||
+----------------------------------------------------------
|
||||
* @access public
|
||||
+----------------------------------------------------------
|
||||
* @param string $attr 标签属性
|
||||
+----------------------------------------------------------
|
||||
* @return string|void
|
||||
+----------------------------------------------------------
|
||||
*/
|
||||
public function _imageBtn($tag) {
|
||||
$name = $tag['name']; //名称
|
||||
$value = $tag['value']; //文字
|
||||
$id = isset($tag['id'])?$tag['id']:''; //ID
|
||||
$style = isset($tag['style'])?$tag['style']:''; //样式名
|
||||
$click = isset($tag['click'])?$tag['click']:''; //点击
|
||||
$type = empty($tag['type'])?'button':$tag['type']; //按钮类型
|
||||
|
||||
if(!empty($name)) {
|
||||
$parseStr = '<div class="'.$style.'" ><input type="'.$type.'" id="'.$id.'" name="'.$name.'" value="'.$value.'" onclick="'.$click.'" class="'.$name.' imgButton"></div>';
|
||||
}else {
|
||||
$parseStr = '<div class="'.$style.'" ><input type="'.$type.'" id="'.$id.'" name="'.$name.'" value="'.$value.'" onclick="'.$click.'" class="button"></div>';
|
||||
}
|
||||
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
+----------------------------------------------------------
|
||||
* imageLink标签解析
|
||||
* 格式: <html:imageLink type="" value="" />
|
||||
+----------------------------------------------------------
|
||||
* @access public
|
||||
+----------------------------------------------------------
|
||||
* @param string $attr 标签属性
|
||||
+----------------------------------------------------------
|
||||
* @return string|void
|
||||
+----------------------------------------------------------
|
||||
*/
|
||||
public function _imgLink($tag) {
|
||||
$name = $tag['name']; //名称
|
||||
$alt = $tag['alt']; //文字
|
||||
$id = $tag['id']; //ID
|
||||
$style = $tag['style']; //样式名
|
||||
$click = $tag['click']; //点击
|
||||
$type = $tag['type']; //点击
|
||||
if(empty($type)) {
|
||||
$type = 'button';
|
||||
}
|
||||
$parseStr = '<span class="'.$style.'" ><input title="'.$alt.'" type="'.$type.'" id="'.$id.'" name="'.$name.'" onmouseover="this.style.filter=\'alpha(opacity=100)\'" onmouseout="this.style.filter=\'alpha(opacity=80)\'" onclick="'.$click.'" align="absmiddle" class="'.$name.' imgLink"></span>';
|
||||
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
+----------------------------------------------------------
|
||||
* select标签解析
|
||||
* 格式: <html:select options="name" selected="value" />
|
||||
+----------------------------------------------------------
|
||||
* @access public
|
||||
+----------------------------------------------------------
|
||||
* @param string $attr 标签属性
|
||||
+----------------------------------------------------------
|
||||
* @return string|void
|
||||
+----------------------------------------------------------
|
||||
*/
|
||||
public function _select($tag) {
|
||||
$name = $tag['name'];
|
||||
$options = $tag['options'];
|
||||
$values = $tag['values'];
|
||||
$output = $tag['output'];
|
||||
$multiple = $tag['multiple'];
|
||||
$id = $tag['id'];
|
||||
$size = $tag['size'];
|
||||
$first = $tag['first'];
|
||||
$selected = $tag['selected'];
|
||||
$style = $tag['style'];
|
||||
$ondblclick = $tag['dblclick'];
|
||||
$onchange = $tag['change'];
|
||||
|
||||
if(!empty($multiple)) {
|
||||
$parseStr = '<select id="'.$id.'" name="'.$name.'" ondblclick="'.$ondblclick.'" onchange="'.$onchange.'" multiple="multiple" class="'.$style.'" size="'.$size.'" >';
|
||||
}else {
|
||||
$parseStr = '<select id="'.$id.'" name="'.$name.'" onchange="'.$onchange.'" ondblclick="'.$ondblclick.'" class="'.$style.'" >';
|
||||
}
|
||||
if(!empty($first)) {
|
||||
$parseStr .= '<option value="" >'.$first.'</option>';
|
||||
}
|
||||
if(!empty($options)) {
|
||||
$parseStr .= '<?php foreach($'.$options.' as $key=>$val) { ?>';
|
||||
if(!empty($selected)) {
|
||||
$parseStr .= '<?php if(!empty($'.$selected.') && ($'.$selected.' == $key || in_array($key,$'.$selected.'))) { ?>';
|
||||
$parseStr .= '<option selected="selected" value="<?php echo $key ?>"><?php echo $val ?></option>';
|
||||
$parseStr .= '<?php }else { ?><option value="<?php echo $key ?>"><?php echo $val ?></option>';
|
||||
$parseStr .= '<?php } ?>';
|
||||
}else {
|
||||
$parseStr .= '<option value="<?php echo $key ?>"><?php echo $val ?></option>';
|
||||
}
|
||||
$parseStr .= '<?php } ?>';
|
||||
}else if(!empty($values)) {
|
||||
$parseStr .= '<?php for($i=0;$i<count($'.$values.');$i++) { ?>';
|
||||
if(!empty($selected)) {
|
||||
$parseStr .= '<?php if(isset($'.$selected.') && ((is_string($'.$selected.') && $'.$selected.' == $'.$values.'[$i]) || (is_array($'.$selected.') && in_array($'.$values.'[$i],$'.$selected.')))) { ?>';
|
||||
$parseStr .= '<option selected="selected" value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
|
||||
$parseStr .= '<?php }else { ?><option value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
|
||||
$parseStr .= '<?php } ?>';
|
||||
}else {
|
||||
$parseStr .= '<option value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
|
||||
}
|
||||
$parseStr .= '<?php } ?>';
|
||||
}
|
||||
$parseStr .= '</select>';
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
+----------------------------------------------------------
|
||||
* checkbox标签解析
|
||||
* 格式: <html:checkbox checkboxes="" checked="" />
|
||||
+----------------------------------------------------------
|
||||
* @access public
|
||||
+----------------------------------------------------------
|
||||
* @param string $attr 标签属性
|
||||
+----------------------------------------------------------
|
||||
* @return string|void
|
||||
+----------------------------------------------------------
|
||||
*/
|
||||
public function _checkbox($tag,$content) {
|
||||
$name = $tag['name'];
|
||||
$checkboxes = $tag['checkboxes'];
|
||||
$checked = $tag['checked'];
|
||||
$separator = $tag['separator'];
|
||||
$checkboxes = $this->tpl->get($checkboxes);
|
||||
$checked = $this->tpl->get($checked)?$this->tpl->get($checked):$checked;
|
||||
$parseStr = '';
|
||||
foreach($checkboxes as $key=>$val) {
|
||||
if($checked == $key || in_array($key,$checked) ) {
|
||||
$parseStr .= '<input type="checkbox" checked="checked" name="'.$name.'[]" value="'.$key.'">'.$val.$separator;
|
||||
}else {
|
||||
$parseStr .= '<input type="checkbox" name="'.$name.'[]" value="'.$key.'">'.$val.$separator;
|
||||
}
|
||||
}
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
+----------------------------------------------------------
|
||||
* radio标签解析
|
||||
* 格式: <html:radio radios="name" checked="value" />
|
||||
+----------------------------------------------------------
|
||||
* @access public
|
||||
+----------------------------------------------------------
|
||||
* @param string $attr 标签属性
|
||||
+----------------------------------------------------------
|
||||
* @return string|void
|
||||
+----------------------------------------------------------
|
||||
*/
|
||||
public function _radio($tag,$content) {
|
||||
$name = $tag['name'];
|
||||
$radios = $tag['radios'];
|
||||
$checked = $tag['checked'];
|
||||
$separator = $tag['separator'];
|
||||
$radios = $this->tpl->get($radios);
|
||||
$checked = $this->tpl->get($checked)?$this->tpl->get($checked):$checked;
|
||||
$parseStr = '';
|
||||
foreach($radios as $key=>$val) {
|
||||
if($checked == $key ) {
|
||||
$parseStr .= '<input type="radio" checked="checked" name="'.$name.'[]" value="'.$key.'">'.$val.$separator;
|
||||
}else {
|
||||
$parseStr .= '<input type="radio" name="'.$name.'[]" value="'.$key.'">'.$val.$separator;
|
||||
}
|
||||
|
||||
}
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
+----------------------------------------------------------
|
||||
* list标签解析
|
||||
* 格式: <html:grid datasource="" show="vo" />
|
||||
*
|
||||
+----------------------------------------------------------
|
||||
* @access public
|
||||
+----------------------------------------------------------
|
||||
* @param string $attr 标签属性
|
||||
+----------------------------------------------------------
|
||||
* @return string
|
||||
+----------------------------------------------------------
|
||||
*/
|
||||
public function _grid($tag,$content) {
|
||||
$id = $tag['id']; //表格ID
|
||||
$datasource = $tag['datasource']; //列表显示的数据源VoList名称
|
||||
$pk = empty($tag['pk'])?'id':$tag['pk'];//主键名,默认为id
|
||||
$style = $tag['style']; //样式名
|
||||
$name = !empty($tag['name'])?$tag['name']:'vo'; //Vo对象名
|
||||
$action = !empty($tag['action'])?$tag['action']:false; //是否显示功能操作
|
||||
$key = !empty($tag['key'])?true:false;
|
||||
if(isset($tag['actionlist'])) {
|
||||
$actionlist = explode(',',trim($tag['actionlist'])); //指定功能列表
|
||||
}
|
||||
|
||||
if(substr($tag['show'],0,1)=='$') {
|
||||
$show = $this->tpl->get(substr($tag['show'],1));
|
||||
}else {
|
||||
$show = $tag['show'];
|
||||
}
|
||||
$show = explode(',',$show); //列表显示字段列表
|
||||
|
||||
//计算表格的列数
|
||||
$colNum = count($show);
|
||||
if(!empty($action)) $colNum++;
|
||||
if(!empty($key)) $colNum++;
|
||||
|
||||
//显示开始
|
||||
$parseStr = "<!-- Think 系统列表组件开始 -->\n";
|
||||
$parseStr .= '<table id="'.$id.'" class="'.$style.'" cellpadding=0 cellspacing=0 >';
|
||||
$parseStr .= '<tr><td height="5" colspan="'.$colNum.'" class="topTd" ></td></tr>';
|
||||
$parseStr .= '<tr class="row" >';
|
||||
//列表需要显示的字段
|
||||
$fields = array();
|
||||
foreach($show as $val) {
|
||||
$fields[] = explode(':',$val);
|
||||
}
|
||||
|
||||
if(!empty($key)) {
|
||||
$parseStr .= '<th width="12">No</th>';
|
||||
}
|
||||
foreach($fields as $field) {//显示指定的字段
|
||||
$property = explode('|',$field[0]);
|
||||
$showname = explode('|',$field[1]);
|
||||
if(isset($showname[1])) {
|
||||
$parseStr .= '<th width="'.$showname[1].'">';
|
||||
}else {
|
||||
$parseStr .= '<th>';
|
||||
}
|
||||
$parseStr .= $showname[0].'</th>';
|
||||
}
|
||||
if(!empty($action)) {//如果指定显示操作功能列
|
||||
$parseStr .= '<th >操作</th>';
|
||||
}
|
||||
$parseStr .= '</tr>';
|
||||
$parseStr .= '<volist name="'.$datasource.'" id="'.$name.'" ><tr class="row" >'; //支持鼠标移动单元行颜色变化 具体方法在js中定义
|
||||
|
||||
if(!empty($key)) {
|
||||
$parseStr .= '<td>{$i}</td>';
|
||||
}
|
||||
foreach($fields as $field) {
|
||||
//显示定义的列表字段
|
||||
$parseStr .= '<td>';
|
||||
if(!empty($field[2])) {
|
||||
// 支持列表字段链接功能 具体方法由JS函数实现
|
||||
$href = explode('|',$field[2]);
|
||||
if(count($href)>1) {
|
||||
//指定链接传的字段值
|
||||
// 支持多个字段传递
|
||||
$array = explode('^',$href[1]);
|
||||
if(count($array)>1) {
|
||||
foreach ($array as $a){
|
||||
$temp[] = '\'{$'.$name.'.'.$a.'|addslashes}\'';
|
||||
}
|
||||
$parseStr .= '<a href="javascript:'.$href[0].'('.implode(',',$temp).')">';
|
||||
}else{
|
||||
$parseStr .= '<a href="javascript:'.$href[0].'(\'{$'.$name.'.'.$href[1].'|addslashes}\')">';
|
||||
}
|
||||
}else {
|
||||
//如果没有指定默认传编号值
|
||||
$parseStr .= '<a href="javascript:'.$field[2].'(\'{$'.$name.'.'.$pk.'|addslashes}\')">';
|
||||
}
|
||||
}
|
||||
if(strpos($field[0],'^')) {
|
||||
$property = explode('^',$field[0]);
|
||||
foreach ($property as $p){
|
||||
$unit = explode('|',$p);
|
||||
if(count($unit)>1) {
|
||||
$parseStr .= '{$'.$name.'.'.$unit[0].'|'.$unit[1].'} ';
|
||||
}else {
|
||||
$parseStr .= '{$'.$name.'.'.$p.'} ';
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$property = explode('|',$field[0]);
|
||||
if(count($property)>1) {
|
||||
$parseStr .= '{$'.$name.'.'.$property[0].'|'.$property[1].'}';
|
||||
}else {
|
||||
$parseStr .= '{$'.$name.'.'.$field[0].'}';
|
||||
}
|
||||
}
|
||||
if(!empty($field[2])) {
|
||||
$parseStr .= '</a>';
|
||||
}
|
||||
$parseStr .= '</td>';
|
||||
|
||||
}
|
||||
if(!empty($action)) {//显示功能操作
|
||||
if(!empty($actionlist[0])) {//显示指定的功能项
|
||||
$parseStr .= '<td>';
|
||||
foreach($actionlist as $val) {
|
||||
if(strpos($val,':')) {
|
||||
$a = explode(':',$val);
|
||||
if(count($a)>2) {
|
||||
$parseStr .= '<a href="javascript:'.$a[0].'(\'{$'.$name.'.'.$a[2].'}\')">'.$a[1].'</a> ';
|
||||
}else {
|
||||
$parseStr .= '<a href="javascript:'.$a[0].'(\'{$'.$name.'.'.$pk.'}\')">'.$a[1].'</a> ';
|
||||
}
|
||||
}else{
|
||||
$array = explode('|',$val);
|
||||
if(count($array)>2) {
|
||||
$parseStr .= ' <a href="javascript:'.$array[1].'(\'{$'.$name.'.'.$array[0].'}\')">'.$array[2].'</a> ';
|
||||
}else{
|
||||
$parseStr .= ' {$'.$name.'.'.$val.'} ';
|
||||
}
|
||||
}
|
||||
}
|
||||
$parseStr .= '</td>';
|
||||
}
|
||||
}
|
||||
$parseStr .= '</tr></volist><tr><td height="5" colspan="'.$colNum.'" class="bottomTd"></td></tr></table>';
|
||||
$parseStr .= "\n<!-- Think 系统列表组件结束 -->\n";
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
+----------------------------------------------------------
|
||||
* list标签解析
|
||||
* 格式: <html:list datasource="" show="" />
|
||||
*
|
||||
+----------------------------------------------------------
|
||||
* @access public
|
||||
+----------------------------------------------------------
|
||||
* @param string $attr 标签属性
|
||||
+----------------------------------------------------------
|
||||
* @return string
|
||||
+----------------------------------------------------------
|
||||
*/
|
||||
public function _list($tag,$content) {
|
||||
$id = $tag['id']; //表格ID
|
||||
$datasource = $tag['datasource']; //列表显示的数据源VoList名称
|
||||
$pk = empty($tag['pk'])?'id':$tag['pk'];//主键名,默认为id
|
||||
$style = $tag['style']; //样式名
|
||||
$name = !empty($tag['name'])?$tag['name']:'vo'; //Vo对象名
|
||||
$action = $tag['action']=='true'?true:false; //是否显示功能操作
|
||||
$key = !empty($tag['key'])?true:false;
|
||||
$sort = $tag['sort']=='false'?false:true;
|
||||
$checkbox = $tag['checkbox']; //是否显示Checkbox
|
||||
if(isset($tag['actionlist'])) {
|
||||
if(substr($tag['actionlist'],0,1)=='$') {
|
||||
$actionlist = $this->tpl->get(substr($tag['actionlist'],1));
|
||||
}else {
|
||||
$actionlist = $tag['actionlist'];
|
||||
}
|
||||
$actionlist = explode(',',trim($actionlist)); //指定功能列表
|
||||
}
|
||||
|
||||
if(substr($tag['show'],0,1)=='$') {
|
||||
$show = $this->tpl->get(substr($tag['show'],1));
|
||||
}else {
|
||||
$show = $tag['show'];
|
||||
}
|
||||
$show = explode(',',$show); //列表显示字段列表
|
||||
|
||||
//计算表格的列数
|
||||
$colNum = count($show);
|
||||
if(!empty($checkbox)) $colNum++;
|
||||
if(!empty($action)) $colNum++;
|
||||
if(!empty($key)) $colNum++;
|
||||
|
||||
//显示开始
|
||||
$parseStr = "<!-- Think 系统列表组件开始 -->\n";
|
||||
$parseStr .= '<table id="'.$id.'" class="'.$style.'" cellpadding=0 cellspacing=0 >';
|
||||
$parseStr .= '<tr><td height="3" colspan="'.$colNum.'" class="topTd" ></td></tr>';
|
||||
$parseStr .= '<tr class="row" >';
|
||||
//列表需要显示的字段
|
||||
$fields = array();
|
||||
foreach($show as $val) {
|
||||
$fields[] = explode(':',$val);
|
||||
}
|
||||
if(!empty($checkbox) && 'true'==strtolower($checkbox)) {//如果指定需要显示checkbox列
|
||||
$parseStr .='<th width="8"><input type="checkbox" id="check" onclick="CheckAll(\''.$id.'\')"></th>';
|
||||
}
|
||||
if(!empty($key)) {
|
||||
$parseStr .= '<th width="12">No</th>';
|
||||
}
|
||||
foreach($fields as $field) {//显示指定的字段
|
||||
$property = explode('|',$field[0]);
|
||||
$showname = explode('|',$field[1]);
|
||||
if(isset($showname[1])) {
|
||||
$parseStr .= '<th width="'.$showname[1].'">';
|
||||
}else {
|
||||
$parseStr .= '<th>';
|
||||
}
|
||||
$showname[2] = isset($showname[2])?$showname[2]:$showname[0];
|
||||
if($sort) {
|
||||
$parseStr .= '<a href="javascript:sortBy(\''.$property[0].'\',\'{$sort}\',\''.ACTION_NAME.'\')" title="按照'.$showname[2].'{$sortType} ">'.$showname[0].'<eq name="order" value="'.$property[0].'" ><img src="../Public/images/{$sortImg}.gif" width="12" height="17" border="0" align="absmiddle"></eq></a></th>';
|
||||
}else{
|
||||
$parseStr .= $showname[0].'</th>';
|
||||
}
|
||||
|
||||
}
|
||||
if(!empty($action)) {//如果指定显示操作功能列
|
||||
$parseStr .= '<th >操作</th>';
|
||||
}
|
||||
|
||||
$parseStr .= '</tr>';
|
||||
$parseStr .= '<volist name="'.$datasource.'" id="'.$name.'" ><tr class="row" '; //支持鼠标移动单元行颜色变化 具体方法在js中定义
|
||||
if(!empty($checkbox)) {
|
||||
$parseStr .= 'onmouseover="over(event)" onmouseout="out(event)" onclick="change(event)" ';
|
||||
}
|
||||
$parseStr .= '>';
|
||||
if(!empty($checkbox)) {//如果需要显示checkbox 则在每行开头显示checkbox
|
||||
$parseStr .= '<td><input type="checkbox" name="key" value="{$'.$name.'.'.$pk.'}"></td>';
|
||||
}
|
||||
if(!empty($key)) {
|
||||
$parseStr .= '<td>{$i}</td>';
|
||||
}
|
||||
foreach($fields as $field) {
|
||||
//显示定义的列表字段
|
||||
$parseStr .= '<td>';
|
||||
if(!empty($field[2])) {
|
||||
// 支持列表字段链接功能 具体方法由JS函数实现
|
||||
$href = explode('|',$field[2]);
|
||||
if(count($href)>1) {
|
||||
//指定链接传的字段值
|
||||
// 支持多个字段传递
|
||||
$array = explode('^',$href[1]);
|
||||
if(count($array)>1) {
|
||||
foreach ($array as $a){
|
||||
$temp[] = '\'{$'.$name.'.'.$a.'|addslashes}\'';
|
||||
}
|
||||
$parseStr .= '<a href="javascript:'.$href[0].'('.implode(',',$temp).')">';
|
||||
}else{
|
||||
$parseStr .= '<a href="javascript:'.$href[0].'(\'{$'.$name.'.'.$href[1].'|addslashes}\')">';
|
||||
}
|
||||
}else {
|
||||
//如果没有指定默认传编号值
|
||||
$parseStr .= '<a href="javascript:'.$field[2].'(\'{$'.$name.'.'.$pk.'|addslashes}\')">';
|
||||
}
|
||||
}
|
||||
if(strpos($field[0],'^')) {
|
||||
$property = explode('^',$field[0]);
|
||||
foreach ($property as $p){
|
||||
$unit = explode('|',$p);
|
||||
if(count($unit)>1) {
|
||||
$parseStr .= '{$'.$name.'.'.$unit[0].'|'.$unit[1].'} ';
|
||||
}else {
|
||||
$parseStr .= '{$'.$name.'.'.$p.'} ';
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$property = explode('|',$field[0]);
|
||||
if(count($property)>1) {
|
||||
$parseStr .= '{$'.$name.'.'.$property[0].'|'.$property[1].'}';
|
||||
}else {
|
||||
$parseStr .= '{$'.$name.'.'.$field[0].'}';
|
||||
}
|
||||
}
|
||||
if(!empty($field[2])) {
|
||||
$parseStr .= '</a>';
|
||||
}
|
||||
$parseStr .= '</td>';
|
||||
|
||||
}
|
||||
if(!empty($action)) {//显示功能操作
|
||||
if(!empty($actionlist[0])) {//显示指定的功能项
|
||||
$parseStr .= '<td>';
|
||||
foreach($actionlist as $val) {
|
||||
if(strpos($val,':')) {
|
||||
$a = explode(':',$val);
|
||||
if(count($a)>2) {
|
||||
$parseStr .= '<a href="javascript:'.$a[0].'(\'{$'.$name.'.'.$a[2].'}\')">'.$a[1].'</a> ';
|
||||
}else {
|
||||
$parseStr .= '<a href="javascript:'.$a[0].'(\'{$'.$name.'.'.$pk.'}\')">'.$a[1].'</a> ';
|
||||
}
|
||||
}else{
|
||||
$array = explode('|',$val);
|
||||
if(count($array)>2) {
|
||||
$parseStr .= ' <a href="javascript:'.$array[1].'(\'{$'.$name.'.'.$array[0].'}\')">'.$array[2].'</a> ';
|
||||
}else{
|
||||
$parseStr .= ' {$'.$name.'.'.$val.'} ';
|
||||
}
|
||||
}
|
||||
}
|
||||
$parseStr .= '</td>';
|
||||
}
|
||||
}
|
||||
$parseStr .= '</tr></volist><tr><td height="3" colspan="'.$colNum.'" class="bottomTd"></td></tr></table>';
|
||||
$parseStr .= "\n<!-- Think 系统列表组件结束 -->\n";
|
||||
return $parseStr;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user