fieldtype = ['BIGINT' => 10]; $this->defaulttype = 'BIGINT'; } /** * 字段相关属性参数 * * @param array $value 值 * @return string */ public function option($option) { return ['
'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'
'.$this->field_type($option['fieldtype'], $option['fieldlength']) , '
'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'
' ]; } /** * 创建sql语句 */ public function create_sql($name, $option, $cname = '') { // 时间戳:BIGINT(10),默认 0 $type = 'BIGINT(10)'; $info = "DEFAULT '0'"; $note = $cname ? (string)$cname : ''; $db = $this->_db_for_field_sql(); if ($db && method_exists($db, 'sqlAddField')) { return $db->sqlAddField($name, $type, $info, $note); } $tips = $note !== '' ? " COMMENT '".str_replace("'", "''", $note)."'" : ''; return 'ALTER TABLE `{tablename}` ADD `'.$name.'` '.$type.' '.$info.$tips; } /** * 字段输出 */ public function output($value) { return dr_date($value, null, ''); } /** * 字段入库值 * * @param array $field 字段信息 * @return void */ public function insert_value($field) { \Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = strtotime((string)\Phpcmf\Service::L('Field')->post[$field['fieldname']]); } /** * 字段表单输入 * * @return string */ public function input($field, $value = 0) { // 字段存储名称 $name = $field['fieldname']; // 字段禁止修改时就返回显示字符串 if ($this->_not_edit($field, $value)) { return $this->show($field, $value); } // 字段显示名称 $text = ($field['setting']['validate']['required'] ? ' * ' : '').dr_lang($field['name']); // 表单宽度设置 $width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'] : 200); // 风格 $style = 'style="width:'.$width.(is_numeric($width) ? 'px' : '').';"'; // 表单附加参数 $attr = $field['setting']['validate']['formattr']; // 按钮颜色 $color = $field['setting']['option']['color'] ? $field['setting']['option']['color'] : 'default'; // 字段提示信息 $tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? ''.$field['setting']['validate']['tips'].'' : ''; // 格式显示 $format = (int)$field['setting']['option']['format2']; // 是否必填 $required = $field['setting']['validate']['required'] ? ' required="required"' : ''; $str = ''; if (!$this->is_load_js($field['fieldtype'])) { $str.= ' '; $this->set_load_js($field['fieldtype'], 1); } $updatetime_select = 0; // 字段默认值 !$value && $value = (string)$this->get_default_value($field['setting']['option']['value']); if (APP_DIR && $name == 'updatetime' && \Phpcmf\Service::C()->module) { $updatetime_select = isset(\Phpcmf\Service::C()->module['setting']['updatetime_select']) && \Phpcmf\Service::C()->module['setting']['updatetime_select']; if ($updatetime_select) { // 勾选不更新时 !$value || $value == 'SYS_TIME' && $value = SYS_TIME; } else { $value = SYS_TIME; } } elseif ($value == 'SYS_TIME') { $value = SYS_TIME; } elseif (strpos($value, '-') === 0) { } elseif (strpos($value, '-') !== false) { $value = strtotime($value); } $value = $format ? dr_date($value, 'Y-m-d') : dr_date($value, 'Y-m-d H:i:s'); $shuru = ''; $tubiao = ' '; $str.= '
'; $str.= $field['setting']['option']['is_left'] ? $tubiao.$shuru : $shuru.$tubiao; $str.= '
'; if ($format) { // 日期 $str.= ' '; } else { // 日期 + 时间 $str.= ' '; } if (APP_DIR && \Phpcmf\Service::C()->module && $name == 'updatetime') { $str.= ''; } $str.= $tips; return $this->input_format($name, $text, '
'.$str.'
'); } /** * 字段表单显示 * * @param string $field 字段数组 * @param array $value 值 * @return string */ public function show($field, $value = null) { if (!is_numeric($value)) { $value = strtotime($value); } $value = (int)$field['setting']['option']['format2'] ? dr_date($value, 'Y-m-d') : dr_date($value, 'Y-m-d H:i:s'); return $this->input_format($field['fieldname'], $field['name'], '
'.$value.'
'); } }