<?php
if(!defined('ClassCms')) {exit();}
class admin_input {
function text($action,$config=array()) {
switch($action) {
case 'name':
Return '文本框';
case 'hash':
Return 'text';
case 'group':
Return '';
case 'sql':
Return 'varchar(255)';
case 'form':
$config['value']=str_replace(array('"','<','>'),array('"','<','>'),$config['value']);
echo('<input type="text" name="'.$config['name'].'" lay-filter="'.$config['name'].'" value="'.($config['value']).'" placeholder="'.$config['placeholder'].'"');
if($config['disabled']) {
echo(' disabled');
}
if(($config['width'])) {
echo(' style="width:'.$config['width'].'"');
}
echo(' class="layui-input">');
Return '';
case 'view':
if(isset($config['titlelink']) && isset($config['article']['link']) && !empty($config['article']['link']) && $config['article']['link']!='#') {
Return '<a style="color:#1E9FFF" target="_blank" href="'.$config['article']['link'].'">'.htmlspecialchars($config['value']).'</a>';
}else {
Return false;
}
case 'post':
if(isset($config['regular']) && !empty($config['regular']) && isset($_POST[$config['name']]) && !empty($_POST[$config['name']])) {
if(is_hash($config['regular'])) {
if(!C('cms:common:verify',@$_POST[$config['name']],$config['regular'])) {
if(!empty($config['regulartips'])) {Return array('error'=>htmlspecialchars($config['regulartips']));}
Return false;
}
}elseif(!preg_match($config['regular'],@$_POST[$config['name']])) {
if(!empty($config['regulartips'])) {Return array('error'=>htmlspecialchars($config['regulartips']));}
Return false;
}
}
if(isset($config['nonull']) && $config['nonull']) {
if(!isset($_POST[$config['name']]) || empty($_POST[$config['name']])) {
Return array('error'=>'不能为空');
}
}
if(isset($config['max']) && $config['max'] && isset($_POST[$config['name']])) {
if(C('cms:common:text',$_POST[$config['name']],$config['max'])<>C('cms:common:text',$_POST[$config['name']])) {
Return array('error'=>'不能超过'.$config['max'].'个字符');
}
}
if(!isset($config['auth']['html']) || !$config['auth']['html']) {
Return htmlspecialchars(@$_POST[$config['name']]);
}
Return @$_POST[$config['name']];
case 'auth':
Return array('html'=>'允许HTML代码');
case 'config':
Return array(
array('configname'=>'数据效验','hash'=>'regular','inputhash'=>'text','tips'=>'常见类型:id,email,phone,hash,username,ip.也可输入正则表达式:纯字母:/^[a-z]+$/i 字母+数字:/^[0-9a-z]+$/i'),
array('configname'=>'效验提示','hash'=>'regulartips','inputhash'=>'text','tips'=>'如提交数据不能通过数据校验,则提示此信息'),
array('configname'=>'字数限制','hash'=>'max','inputhash'=>'number','tips'=>'允许的最大字符数,0则不限制','defaultvalue'=>'0'),
array('configname'=>'输入框提示','hash'=>'placeholder','inputhash'=>'text','tips'=>'输入框的placeholder'),
array('configname'=>'输入框宽度','hash'=>'width','inputhash'=>'text','tips'=>'使用百分比,如:40% 或者 固定宽度如:200px')
);
}
Return false;
}
function textarea($action,$config=array()) {
switch($action) {
case 'name':
Return '文本区域';
case 'hash':
Return 'textarea';
case 'group':
Return '';
case 'sql':
Return 'longtext';
case 'form':
echo('<textarea class="layui-textarea" name="'.$config['name'].'" lay-filter="'.$config['name'].'" placeholder="'.$config['placeholder'].'" ');
if($config['disabled']) {
echo(' disabled');
}
if($config['style']) {
echo(' style="'.$config['style'].'"');
}
echo('>');
echo(htmlspecialchars($config['value']));
echo('</textarea>');
Return '';
case 'post':
if(!isset($config['auth']['html']) || !$config['auth']['html']) {
Return htmlspecialchars(@$_POST[$config['name']]);
}
if(isset($config['nonull']) && $config['nonull']) {
if(!isset($_POST[$config['name']]) || empty($_POST[$config['name']])) {
Return array('error'=>'不能为空');
}
}
Return @$_POST[$config['name']];
case 'auth':
Return array('html'=>'允许HTML代码');
case 'config':
Return array(
array('configname'=>'输入框提示','hash'=>'placeholder','inputhash'=>'text','tips'=>'输入框的placeholder'),
array('configname'=>'输入框样式','hash'=>'style','inputhash'=>'text','tips'=>'如:width:50%;min-height:200px')
);
}
Return false;
}
function dateTime($action,$config=array()) {
switch($action) {
case 'name':
Return '日期时间';
case 'hash':
Return 'datetime';
case 'group':
Return '';
case 'sql':
Return 'bigint(10)';
case 'form':
if(isset($config['source']) && $config['source']=='admin_defaultvalue_setting') {
$config['nowtime']=0;
}
if(isset($config['source']) && $config['source']=='admin_article_edit') {
$config['nowtime']=0;
}
if(empty($config['value']) && $config['nowtime']) {
$config['value']=time();
}
if(!empty($config['value'])) {
if($config['time'] && is_numeric($config['value'])) {
$config['value']=date('Y-m-d H:i:s',$config['value']);
}elseif(is_numeric($config['value'])) {
$config['value']=date('Y-m-d',$config['value']);
}
}elseif($config['value']=='0') {
$config['value']='';
}
V('input/datetime',$config);
Return '';
case 'defaultvalue':
if(empty($config['defaultvalue']) && $config['nowtime']) {
$config['defaultvalue']=time();
}
Return $config['defaultvalue'];
case 'view':
if(empty($config['value'])) {
Return '';
}
if($config['time']) {
Return date('Y-m-d H:i:s',$config['value']);
}else {
Return date('Y-m-d',$config['value']);