Initial project files: BESCMS full source
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本代码基于MIT开源协议,协议规定此处版权信息不可去除
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Cat extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['INT' => 10];
|
||||
$this->defaulttype = 'INT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$_option = '';
|
||||
$_module = \Phpcmf\Service::C()->get_cache('module-'.SITE_ID.'-content');
|
||||
if ($_module) {
|
||||
$_option.= '<option value="share" '.('share' == $option['module'] ? 'selected' : '').'>'.dr_lang('共享栏目').'</option>';
|
||||
foreach ($_module as $dir => $t) {
|
||||
if (!$t['share']) {
|
||||
$_option.= '<option value="'.$dir.'" '.($dir == $option['module'] ? 'selected' : '').'>'.$t['name'].'</option>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('内容模块').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><select class="form-control" name="data[setting][option][module]">
|
||||
'.$_option.'
|
||||
</select></label>
|
||||
<span class="help-block">'.dr_lang('必须选择一个模块作为栏目的数据源').'</span>
|
||||
</div>
|
||||
</div><div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('选择父栏目').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][parent]" '.($option['parent'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('开启之后可以选择父级栏目').'</span>
|
||||
</div>
|
||||
</div><div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('启用选项搜索').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][is_search]" '.($option['is_search'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
|
||||
<span class="help-block">'.dr_lang('当选项值过多时,可以在选择框中搜索选项值').'</span>
|
||||
</div>
|
||||
</div>', ''];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return intval($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = intval(\Phpcmf\Service::L('Field')->post[$field['fieldname']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 开始输出
|
||||
$str = '';
|
||||
$str.= '<label style="min-width: 200px">'.\Phpcmf\Service::L('category', 'module')->select(
|
||||
$field['setting']['option']['module'],
|
||||
intval($value),
|
||||
' name=\'data['.$field['fieldname'].']\' data-actions-box="true" '.(isset($field['setting']['option']['is_search']) && $field['setting']['option']['is_search'] ? ' data-live-search="true" ' : ''),
|
||||
'', (isset($field['setting']['option']['parent']) && $field['setting']['option']['parent'] ? 0 : 1), 0
|
||||
).'</label>';
|
||||
$str.= '<span class="help-block">'.$tips.'</span>';
|
||||
return $this->input_format($name, $text, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], '<div class="form-control-static">'.dr_catpos($value, ' - ', false, '', $field['setting']['option']['module']).'</div>');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本代码基于MIT开源协议,协议规定此处版权信息不可去除
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Catids extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['TEXT' => ''];
|
||||
$this->defaulttype = 'TEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
|
||||
return ['
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('重要提醒').'</label>
|
||||
<div class="col-md-9"><label class="form-control-static">本字段名一定要是catids才能参与搜索</label></div>
|
||||
</div>
|
||||
', '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return dr_string2array($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
$save = [];
|
||||
$data = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
if ($data) {
|
||||
if (!IS_ADMIN) {
|
||||
// 验证发布权限
|
||||
$category = \Phpcmf\Service::C()->_get_module_member_category(\Phpcmf\Service::C()->module, 'add');
|
||||
if (!$category) {
|
||||
\Phpcmf\Service::C()->_json(1, dr_lang('模块[%s]没有可用栏目权限', \Phpcmf\Service::C()->module['dirname']));
|
||||
}
|
||||
foreach ($data as $t) {
|
||||
if ($t) {
|
||||
$save[] = $t;
|
||||
if (!$category[$t]) {
|
||||
\Phpcmf\Service::C()->_json(1, dr_lang('模块[%s]没有栏目(%s)权限', \Phpcmf\Service::C()->module['dirname'], $t));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($data as $t) {
|
||||
if ($t) {
|
||||
$save[] = $t;
|
||||
}
|
||||
}
|
||||
}
|
||||
$save = array_unique($save);
|
||||
}
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = dr_array2string($save);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 开始输出
|
||||
$str = '';
|
||||
$str.= '<label style="min-width: 200px">'.\Phpcmf\Service::L('category', 'module')->select(
|
||||
\Phpcmf\Service::C()->module['dirname'],
|
||||
dr_string2array($value),
|
||||
' name=\'data['.$field['fieldname'].'][]\' multiple="multiple" data-actions-box="true"',
|
||||
'', 1, 1
|
||||
).'</label>';
|
||||
$str.= '<span class="help-block">'.$tips.'</span>';
|
||||
return $this->input_format($name, $text, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], '<div class="form-control-static">'.dr_linkagepos($field['setting']['option']['linkage'], $value, ' - ').'</div>');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本代码基于MIT开源协议,协议规定此处版权信息不可去除
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Cats extends \Phpcmf\Field\Cat {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['TEXT' => ''];
|
||||
$this->defaulttype = 'TEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return dr_string2array($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = dr_array2string(\Phpcmf\Service::L('Field')->post[$field['fieldname']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 开始输出
|
||||
$str = '';
|
||||
$str.= '<label style="min-width: 200px">'.\Phpcmf\Service::L('category', 'module')->select(
|
||||
$field['setting']['option']['module'],
|
||||
dr_string2array($value),
|
||||
' name=\'data['.$field['fieldname'].'][]\' multiple="multiple" data-actions-box="true" '.(isset($field['setting']['option']['is_search']) && $field['setting']['option']['is_search'] ? ' data-live-search="true" ' : ''),
|
||||
'', (isset($field['setting']['option']['parent']) && $field['setting']['option']['parent'] ? 0 : 1), 0
|
||||
).'</label>';
|
||||
$str.= \Phpcmf\Service::L('Field')->get('select')->get_select_search_code().'<span class="help-block">'.$tips.'</span>';
|
||||
return $this->input_format($name, $text, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$html = '';
|
||||
$value = dr_string2array($value);
|
||||
if ($value) {
|
||||
foreach ($value as $t) {
|
||||
$html.= '<label class="btn btn-xs default">'.dr_catpos($t, ' - ', false, '', $field['setting']['option']['module']).'</label>';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], '<div class="form-control-static">'.$html.'</div>');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Checkbox extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->close_xss = 1;
|
||||
$this->fieldtype = ['TEXT' => ''];
|
||||
$this->defaulttype = 'TEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$option['options'] = isset($option['options']) ? $option['options'] : 'name1|1'.PHP_EOL.'name2|2';
|
||||
|
||||
return [$this->_search_field().
|
||||
'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('选项列表').'</label>
|
||||
<div class="col-md-9">
|
||||
<textarea class="form-control" name="data[setting][option][options]" style="height:150px;width:400px;">'.$option['options'].'</textarea>
|
||||
<span class="help-block">'.dr_lang('格式:选项名称|选项值[回车换行]选项名称2|值2....').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认选中项').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('默认选中项,多个选中项用|分隔').'</span>
|
||||
</div>
|
||||
</div>
|
||||
'
|
||||
,
|
||||
'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('显示格式').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][show_type]" value="0" '.(!$option['option']['show_type'] ? 'checked' : '').'> '.dr_lang('横排显示').'
|
||||
<span></span>
|
||||
</label>
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][show_type]" value="1" '.($option['option']['show_type'] ? 'checked' : '').'> '.dr_lang('竖排显示').'
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = dr_array2string(\Phpcmf\Service::L('Field')->post[$field['fieldname']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function output($value) {
|
||||
return dr_string2array($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 表单附加参数
|
||||
$attr = $field['setting']['validate']['formattr'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 字段默认值
|
||||
if ($value) {
|
||||
$value = dr_string2array($value);
|
||||
} elseif ($field['setting']['option']['value']) {
|
||||
$value = $this->get_default_value($field['setting']['option']['value']);
|
||||
$value = is_array($value) ? $value : explode('|', $value);
|
||||
} else {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
$str = '';
|
||||
|
||||
// 显示方式
|
||||
$show_type = (int)$field['setting']['option']['show_type'];
|
||||
|
||||
// 表单选项
|
||||
$options = dr_format_option_array($field['setting']['option']['options']);
|
||||
if ($options) {
|
||||
foreach ($options as $v => $n) {
|
||||
$s = is_array($value) && in_array($v, $value) ? ' checked' : '';
|
||||
$kj = '<input type="checkbox" name="data['.$name.'][]" value="'.$v.'" '.$s.' '.$attr.' />';
|
||||
$str.= '<label class="mt-checkbox mt-checkbox-outline">'.$kj.' '.dr_lang($n).' <span></span> </label>';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->input_format($name, $text, '<div class="'.(!$show_type ? 'mt-checkbox-inline' : 'mt-checkbox-list').'">'.$str.'</div>'.$tips);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$str = '';
|
||||
$value = dr_string2array($value);
|
||||
$options = dr_format_option_array($field['setting']['option']['options']);
|
||||
if ($options && $value) {
|
||||
foreach ($options as $v => $n) {
|
||||
is_array($value) && in_array($v, $value) && $str.= '<label class="label label-default"> '.dr_lang($n).' </label> ';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], '<div class="form-control-static">'.$str.'</div>');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Color extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['VARCHAR' => 30];
|
||||
$this->defaulttype = 'VARCHAR';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option, $field = NULL) {
|
||||
|
||||
$_field = [
|
||||
'<option value=""> -- </option>'
|
||||
];
|
||||
if ($field) {
|
||||
foreach ($field as $t) {
|
||||
if ($t['fieldtype'] == 'Text') {
|
||||
$st = $option['field'] == $t['fieldname'] ? 'selected' : '';
|
||||
$_field[] = '<option '.$st.' value="'.$t['fieldname'].'">'.$t['name'].'</option>';
|
||||
}
|
||||
}
|
||||
$_field = implode('', array_unique($_field));
|
||||
}
|
||||
|
||||
return [$this->_search_field().'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('附加到指定字段').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><select class="form-control" name="data[setting][option][field]">'.$_field.'</select></label>
|
||||
<span class="help-block">'.dr_lang('对文本类型字段有效,会实时变动颜色').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认填充值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
',
|
||||
'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
|
||||
// 字段提示信息
|
||||
$tips = $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$name.'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 表单宽度设置
|
||||
$width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'] : 200);
|
||||
|
||||
// 风格
|
||||
$style = 'style="width:'.$width.(is_numeric($width) ? 'px' : '').';"';
|
||||
|
||||
// 字段默认值
|
||||
$value = $value ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
$str = '';
|
||||
|
||||
// 加载js
|
||||
if (!$this->is_load_js($field['fieldtype'])) {
|
||||
$str.= '
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-colorpicker/css/colorpicker.css" rel="stylesheet" type="text/css" />
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/jquery-minicolors/jquery.minicolors.css" rel="stylesheet" type="text/css" />
|
||||
';
|
||||
$str.= '<script type="text/javascript" src="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.js?v='.CMF_UPDATE_TIME.'"></script>';
|
||||
$str.= '<script type="text/javascript" src="'.ROOT_THEME_PATH.'assets/global/plugins/jquery-minicolors/jquery.minicolors.min.js?v='.CMF_UPDATE_TIME.'"></script>';
|
||||
$this->set_load_js($field['fieldtype'], 1);
|
||||
}
|
||||
|
||||
$default = '';
|
||||
if ($field['setting']['option']['field'] && $value) {
|
||||
$default = '$("#dr_'.$field['setting']['option']['field'].'").css("color", "'.$value.'");';
|
||||
}
|
||||
|
||||
$str.= '
|
||||
<input type="text" class="form-control color '.$field['setting']['option']['css'].'" data-control="brightness" name="data['.$name.']" id="dr_'.$name.'" '.$style.' value="'.$value.'" >';
|
||||
$js = \Phpcmf\Service::L('js_packer');
|
||||
$str.= $js->pack('
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$("#dr_'.$name.'").minicolors({
|
||||
control: $("#dr_'.$name.'").attr("data-control") || "hue",
|
||||
defaultValue: $("#dr_'.$name.'").attr("data-defaultValue") || "",
|
||||
inline: "true" === $("#dr_'.$name.'").attr("data-inline"),
|
||||
letterCase: $("#dr_'.$name.'").attr("data-letterCase") || "lowercase",
|
||||
opacity: $("#dr_'.$name.'").attr("data-opacity"),
|
||||
position: $("#dr_'.$name.'").attr("data-position") || "bottom left",
|
||||
change: function(t, o) {
|
||||
t && (o && (t += ", " + o), "object" == typeof console && console.log(t));
|
||||
'.($field['setting']['option']['field'] ? '$("#dr_'.$field['setting']['option']['field'].'").css("color", $("#dr_'.$name.'").val());' : '').'
|
||||
},
|
||||
theme: "bootstrap"
|
||||
});
|
||||
'.$default.'
|
||||
});
|
||||
</script>', 0);
|
||||
|
||||
return $this->input_format($name, $text, $str.$tips);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], '<div class="form-control-static"><span style="color:'.$value.'" class="label label-danger"> </span></div>');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Date extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['BIGINT' => 10];
|
||||
$this->defaulttype = 'BIGINT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
return ['
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('字段格式').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][format2]" value="0" '.(!$option['format2'] ? 'checked' : '').'> '.dr_lang('日期时间格式').'
|
||||
<span></span>
|
||||
</label>
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][format2]" value="1" '.($option['format2'] ? 'checked' : '').'> '.dr_lang('日期格式').'
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图标显示').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][is_left]" value="1" '.($option['is_left'] ? 'checked' : '').'> '.dr_lang('左侧图标').'
|
||||
<span></span>
|
||||
</label>
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][is_left]" value="0" '.(!$option['is_left'] ? 'checked' : '').'> '.dr_lang('右侧图标').'
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认存储值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
'.$this->field_type($option['fieldtype'], $option['fieldlength'])
|
||||
|
||||
,
|
||||
|
||||
'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('按钮颜色').'</label>
|
||||
<div class="col-md-9">
|
||||
<label>'.$this->_color_select('color', $option['color']).'</label>
|
||||
</div>
|
||||
</div>
|
||||
'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建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'] ? '<span class="required" aria-required="true"> * </span>' : '').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'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 格式显示
|
||||
$format = (int)$field['setting']['option']['format2'];
|
||||
|
||||
// 是否必填
|
||||
$required = $field['setting']['validate']['required'] ? ' required="required"' : '';
|
||||
|
||||
$str = '';
|
||||
if (!$this->is_load_js($field['fieldtype'])) {
|
||||
$str.= '
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-daterangepicker/daterangepicker.min.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/moment.min.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.finecms.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.finecms.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
';
|
||||
$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 = '<input id="dr_'.$name.'" name="data['.$name.']" type="text" '.$style.' value="'.$value.'" '.$required.' class="form-control '.$field['setting']['option']['css'].'">';
|
||||
$tubiao = '<span class="input-group-btn">
|
||||
<button class="btn '.$color.' date-set" type="button">
|
||||
<i class="fa fa-calendar"></i>
|
||||
</button>
|
||||
</span>';
|
||||
$str.= '<div class="input-group date field_date_'.$name.'">';
|
||||
$str.= $field['setting']['option']['is_left'] ? $tubiao.$shuru : $shuru.$tubiao;
|
||||
$str.= '</div>';
|
||||
|
||||
if ($format) {
|
||||
// 日期
|
||||
$str.= '
|
||||
<script>
|
||||
$(function(){
|
||||
$(".field_date_'.$name.'").datepicker({
|
||||
isRTL: false,
|
||||
format: "yyyy-mm-dd",
|
||||
showMeridian: true,
|
||||
autoclose: true,
|
||||
pickerPosition: "bottom-right",
|
||||
todayBtn: "linked"
|
||||
});
|
||||
});
|
||||
</script>
|
||||
';
|
||||
} else {
|
||||
// 日期 + 时间
|
||||
$str.= '
|
||||
<script>
|
||||
$(function(){
|
||||
$(".field_date_'.$name.'").datetimepicker({
|
||||
isRTL: false,
|
||||
format: "yyyy-mm-dd hh:ii:ss",
|
||||
showMeridian: true,
|
||||
autoclose: true,
|
||||
pickerPosition: "bottom-right",
|
||||
todayBtn: "linked"
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
if (APP_DIR && \Phpcmf\Service::C()->module && $name == 'updatetime') {
|
||||
$str.= '<label><input name="no_time" '.($updatetime_select ? ' checked' : '').' class="dr_no_time" type="checkbox" value="1" /> '.dr_lang('不更新').'</label>';
|
||||
}
|
||||
|
||||
$str.= $tips;
|
||||
|
||||
return $this->input_format($name, $text, '<div class="form-date input-group">'.$str.'</div>');
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @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'], '<div class="form-control-static"><span> '.$value.' </span></div>');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Diy extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = TRUE;
|
||||
$this->defaulttype = 'VARCHAR';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$option['type'] = isset($option['type']) ? $option['type'] : 0;
|
||||
$option['code'] = isset($option['code']) ? $option['code'] : '';
|
||||
$option['file'] = isset($option['file']) ? $option['file'] : '';
|
||||
|
||||
$str = '<select class="form-control" name="data[setting][option][file]"><option value=""> -- </option>';
|
||||
$files = dr_file_map(CONFIGPATH.'myfield/', 1);
|
||||
if ($this->app) {
|
||||
$files2 = dr_file_map(dr_get_app_dir($this->app).'Config/myfield/', 1);
|
||||
$files2 && $files = dr_array2array($files2, $files);
|
||||
}
|
||||
if ($files) {
|
||||
foreach ($files as $t) {
|
||||
if ($t && strpos($t, '.php') !== 0) {
|
||||
$str.= '<option value="'.$t.'" '.($option['file'] == $t ? 'selected' : '').'> '.$t.' </option>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$str.= '</select>';
|
||||
|
||||
return ['
|
||||
<div class="form-group dr_type">
|
||||
<label class="col-md-2 control-label">'.dr_lang('自定义文件').'</label>
|
||||
<div class="col-md-9">
|
||||
<label>'.$str.'</label>
|
||||
<span class="help-block">'.dr_lang('将设计好的文件上传到./config/myfield/目录之下').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>'.$this->field_type($option['fieldtype'], $option['fieldlength'])];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
$data = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
$func = 'dr_diy_field_'.substr($field['setting']['option']['file'], 0, -4).'_insert_value';
|
||||
// 回调格式化函数
|
||||
if (function_exists($func)) {
|
||||
$data = call_user_func($func, $data);
|
||||
}
|
||||
is_array($data) && $data = dr_array2string($data);
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*
|
||||
* @param array $value 数据库值
|
||||
* @return string
|
||||
*/
|
||||
public function output($value) {
|
||||
|
||||
if (!$value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return strpos($value, '["') === 0 || strpos($value, '{"') === 0 ? dr_string2array($value) : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
// 回调格式化函数
|
||||
$func = 'dr_diy_field_'.substr($field['setting']['option']['file'], 0, -4).'_show';
|
||||
if (function_exists($func)) {
|
||||
$str = call_user_func($func, $field, $value);
|
||||
} else {
|
||||
$str = '<div class="form-control-static"> '.htmlspecialchars_decode((string)$value).' </div>';
|
||||
}
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $cname 字段
|
||||
* @param string $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = 0) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 表单附加参数
|
||||
$attr = isset($field['setting']['validate']['formattr']) && $field['setting']['validate']['formattr'] ? $field['setting']['validate']['formattr'] : '';
|
||||
// 字段提示信息
|
||||
$tips = isset($field['setting']['validate']['tips']) && $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
$name = $field['fieldname'];
|
||||
$code = '';
|
||||
|
||||
// 文件类型
|
||||
if (!$field['setting']['option']['file']) {
|
||||
$code = '<font color=red>没有设置文件</font>';
|
||||
} else {
|
||||
if (strpos((string)$field['setting']['option']['file'], '/') !== false
|
||||
&& is_file($field['setting']['option']['file'])) {
|
||||
require $field['setting']['option']['file'];
|
||||
} else {
|
||||
$file = CONFIGPATH.'myfield/'.$field['setting']['option']['file'];
|
||||
$file2 = dr_get_app_dir(APP_DIR).'Config/myfield/'.$field['setting']['option']['file'];
|
||||
if (is_file($file)) {
|
||||
require $file;
|
||||
} elseif (is_file($file2)) {
|
||||
require $file2;
|
||||
} elseif (!$field['setting']['option']['file']) {
|
||||
$code = '<font color=red>没有选择文件,在字段属性中选择</font>';
|
||||
} else {
|
||||
$code = '<font color=red>文件('.$file.')不存在</font>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->input_format($field['fieldname'], $text, $code);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,750 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Editor extends \Phpcmf\Library\A_Field {
|
||||
|
||||
protected $rid; // 附件入库标记字符
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['MEDIUMTEXT' => ''];
|
||||
$this->defaulttype = 'MEDIUMTEXT';
|
||||
$this->rid = md5(FC_NOW_URL.\Phpcmf\Service::L('input')->get_user_agent().\Phpcmf\Service::L('input')->ip_address().\Phpcmf\Service::C()->uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
if (!isset($option['attach_size']) || !$option['attach_size']) {
|
||||
$option['attach_size'] = 200;
|
||||
}
|
||||
if (!isset($option['toolbar']) || !$option['toolbar']) {
|
||||
$option['toolbar'] = "['style', ['style']],
|
||||
['font', ['bold', 'italic', 'underline', 'clear']],
|
||||
['fontname', ['fontsize']],
|
||||
['color', ['color']],
|
||||
['para', ['ul', 'ol', 'paragraph']],
|
||||
['table', ['table']],
|
||||
['link', ['link']],
|
||||
['attach', ['attach']],
|
||||
['picture', ['qsimage', 'picture', 'help']],
|
||||
['video', ['video', 'llvideo']],
|
||||
['view', ['codeview'] ]";
|
||||
}
|
||||
if (!isset($option['toolbar_home']) || !$option['toolbar_home']) {
|
||||
$option['toolbar_home'] = "['style', ['style']],
|
||||
['font', ['bold', 'italic', 'underline', 'clear']],
|
||||
['fontname', ['fontsize']],
|
||||
['color', ['color']],
|
||||
['para', ['ul', 'ol', 'paragraph']],
|
||||
['table', ['table']],
|
||||
['link', ['link']],
|
||||
['attach', ['attach']],
|
||||
['picture', ['qsimage', 'picture', 'help']],
|
||||
['video', ['video', 'llvideo']],
|
||||
['view', ['codeview'] ]";
|
||||
}
|
||||
if (!isset($option['attach_ext']) || !$option['attach_ext']) {
|
||||
$option['attach_ext'] = 'zip,rar,txt,doc';
|
||||
}
|
||||
if (!isset($option['video_ext']) || !$option['video_ext']) {
|
||||
$option['video_ext'] = 'mp4';
|
||||
}
|
||||
if (!isset($option['video_size']) || !$option['video_size']) {
|
||||
$option['video_size'] = 500;
|
||||
}
|
||||
if (!isset($option['image_ext']) || !$option['image_ext']) {
|
||||
$option['image_ext'] = 'jpg,gif,png,webp,jpeg';
|
||||
}
|
||||
if (!isset($option['imagecut_ext']) || !$option['imagecut_ext']) {
|
||||
$option['imagecut_ext'] = '';
|
||||
}
|
||||
if (!isset($option['image_size']) || !$option['image_size']) {
|
||||
$option['image_size'] = 10;
|
||||
}
|
||||
|
||||
$wm = \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') ? '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图片水印').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="form-control-static">
|
||||
'.dr_lang('系统强制开启水印').'
|
||||
</div>
|
||||
</div>
|
||||
</div>' : '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图片水印').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][watermark]" '.($option['watermark'] == 1 ? 'checked' : '').' > '.dr_lang('开启').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][watermark]" '.($option['watermark'] == 0 ? 'checked' : '').' > '.dr_lang('关闭').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('上传的图片会加上水印图').'</span>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
return [$this->_search_field().'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('底部工具栏').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" onclick="$(\'#sdmrx\').show()" value="1" name="data[setting][option][show_bottom_boot]" '.($option['show_bottom_boot'] == 1 ? 'checked' : '').' > '.dr_lang('开启').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" onclick="$(\'#sdmrx\').hide()" value="0" name="data[setting][option][show_bottom_boot]" '.($option['show_bottom_boot'] == 0 ? 'checked' : '').' > '.dr_lang('关闭').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('编辑器底部工具栏,有截取字符选择、提取缩略图、下载远程图等控制按钮').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" id="sdmrx" '.(!$option['show_bottom_boot'] ? 'style="display:none"' : '').'>
|
||||
<label class="col-md-1 control-label"> </label>
|
||||
<div class="col-md-9">
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang("提取描述").'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][tool_select_2]" value="1" '.($option['tool_select_2'] ? 'checked' : '').' data-on-text="'.dr_lang("默认选中").'" data-off-text="'.dr_lang("默认不选").'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang("提取缩略图").'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][tool_select_1]" value="1" '.($option['tool_select_1'] ? 'checked' : '').' data-on-text="'.dr_lang("默认选中").'" data-off-text="'.dr_lang("默认不选").'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang("去除站外链接").'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][tool_select_4]" value="1" '.($option['tool_select_4'] ? 'checked' : '').' data-on-text="'.dr_lang("默认选中").'" data-off-text="'.dr_lang("默认不选").'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang("下载远程图").'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][tool_select_3]" value="1" '.($option['tool_select_3'] ? 'checked' : '').' data-on-text="'.dr_lang("启用").'" data-off-text="'.dr_lang("不启用").'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" '.(!$option['show_bottom_boot'] ? 'style="display:none"' : '').'>
|
||||
<label class="col-md-2 control-label">'.dr_lang('提取缩略图限制').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="input-inline input-small">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">'.dr_lang('宽大于').'</span>
|
||||
<input type="text" name="data[setting][option][thumb][width]" value="'.($option['thumb']['width']).'" class="form-control" placeholder="px">
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-inline input-small">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">'.dr_lang('高大于').'</span>
|
||||
<input type="text" name="data[setting][option][thumb][height]" value="'.($option['thumb']['height']).'" class="form-control" placeholder="px">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图片title').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][imgtitle]" '.($option['imgtitle'] >0 ? 'checked' : '').' > '.dr_lang('内容标题').' <span></span></label>
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][imgtitle]" '.(!$option['imgtitle'] ? 'checked' : '').' > '.dr_lang('图片名称').' <span></span></label>
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="-1" name="data[setting][option][imgtitle]" '.($option['imgtitle'] < 0 ? 'checked' : '').' > '.dr_lang('不显示').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('将模块内容的标题作为图片title字符').'</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图片alt').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][imgalt]" '.($option['imgalt'] >0 ? 'checked' : '').' > '.dr_lang('内容标题').' <span></span></label>
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][imgalt]" '.(!$option['imgalt'] ? 'checked' : '').' > '.dr_lang('图片名称').' <span></span></label>
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="-1" name="data[setting][option][imgalt]" '.($option['imgalt'] < 0 ? 'checked' : '').' > '.dr_lang('不显示').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('将模块内容的标题作为图片alt字符').'</span>
|
||||
</div>
|
||||
</div>
|
||||
'.$wm.
|
||||
'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图片粘贴扩展名').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" name="data[setting][option][imagecut_ext]" value="'.$option['imagecut_ext'].'"></label>
|
||||
<span class="help-block">'.dr_lang('填写用于图片的扩展名格式,只能填写单个扩展名,用于截图粘贴时储存的扩展名').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图片上传扩展名').'</label>
|
||||
<div class="col-md-9">
|
||||
<span><input type="text" class="form-control" name="data[setting][option][image_ext]" value="'.$option['image_ext'].'"></span>
|
||||
<span class="help-block">'.dr_lang('填写用于图片上传的扩展名格式,格式:jpg,gif,png,webp,jpeg').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图片上传大小').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" name="data[setting][option][image_size]" value="'.$option['image_size'].'"></label>
|
||||
<span class="help-block">'.dr_lang('填写用于图片上传的最大允许上传的大小,单位MB').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('附件上传大小').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" name="data[setting][option][attach_size]" value="'.$option['attach_size'].'"></label>
|
||||
<span class="help-block">'.dr_lang('填写用于附件上传的最大允许上传的大小,单位MB').'</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('附件上传扩展名').'</label>
|
||||
<div class="col-md-9">
|
||||
<span><input type="text" class="form-control" name="data[setting][option][attach_ext]" value="'.$option['attach_ext'].'"></span>
|
||||
<span class="help-block">'.dr_lang('填写用于附件上传的扩展名,格式:rar,zip').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('视频上传扩展名').'</label>
|
||||
<div class="col-md-9">
|
||||
<span><input type="text" class="form-control" name="data[setting][option][video_ext]" value="'.$option['video_ext'].'"></span>
|
||||
<span class="help-block">'.dr_lang('填写用于视频上传的扩展名格式,格式:mp4,mov').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('视频上传大小').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" name="data[setting][option][video_size]" value="'.$option['video_size'].'"></label>
|
||||
<span class="help-block">'.dr_lang('填写用于视频上传的最大允许上传的大小,单位MB').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('后台工具栏图标').'</label>
|
||||
<div class="col-md-9">
|
||||
<textarea id="field_default_value" style="width: 90%;height: 100px;" class="form-control" name="data[setting][option][toolbar]">'.$option['toolbar'].'</textarea>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('前端工具栏图标').'</label>
|
||||
<div class="col-md-9">
|
||||
<textarea id="field_default_value" style="width: 90%;height: 100px;" class="form-control" name="data[setting][option][toolbar_home]">'.$option['toolbar_home'].'</textarea>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
'.$this->attachment($option, 0).'
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认存储值').'</label>
|
||||
<div class="col-md-9">
|
||||
<textarea id="field_default_value" style="width: 90%;height: 100px;" class="form-control" name="data[setting][option][value]">'.$option['value'].'</textarea>
|
||||
<p><label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span></p>
|
||||
</div>
|
||||
</div>
|
||||
'.$this->field_type($option['fieldtype'], $option['fieldlength']),
|
||||
|
||||
'<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件高度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" name="data[setting][option][height]" value="'.$option['height'].'"></label>
|
||||
<label>px</label>
|
||||
</div>
|
||||
</div>'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证字段属性
|
||||
*/
|
||||
public function edit_config($post) {
|
||||
|
||||
if (isset($post['setting']['option']['imagecut_ext']) && $post['setting']['option']['imagecut_ext']) {
|
||||
if (strpos($post['setting']['option']['imagecut_ext'], ',') !== false) {
|
||||
return dr_return_data(0, dr_lang('图片粘贴扩展名只能填写单个扩展名'));
|
||||
}
|
||||
}
|
||||
|
||||
return dr_return_data(1, 'ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
$value = str_replace('style=""', '', (string)$_POST['data'][$field['fieldname']]);
|
||||
$value = preg_replace("/cmsattachid=\"([0-9]+)\"/U", '', $value);
|
||||
// 第一张作为缩略图
|
||||
$slt = isset($_POST['data']['thumb']) && isset($_POST['is_auto_thumb_'.$field['fieldname']]) && !$_POST['data']['thumb'] && $_POST['is_auto_thumb_'.$field['fieldname']];
|
||||
|
||||
$base64 = strpos($value, ';base64,');
|
||||
|
||||
// 下载远程图片
|
||||
if ($slt || $base64) {
|
||||
$temp = preg_replace('/<pre(.*)<\/pre>/siU', '', $value);
|
||||
$temp = preg_replace('/<code(.*)<\/code>/siU', '', $temp);
|
||||
if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+)\\2/i", $temp, $imgs)) {
|
||||
$reps = array_unique($imgs[3]);
|
||||
usort($reps, function ($a, $b) {
|
||||
return dr_strlen($b) - dr_strlen($a);
|
||||
});
|
||||
foreach ($reps as $img) {
|
||||
|
||||
if ($base64 && preg_match('/^(data:\s*image\/(\w+);base64,)/i', $img, $result)) {
|
||||
// 处理图片
|
||||
$ext = strtolower($result[2]);
|
||||
if (!in_array($ext, ['png', 'jpg', 'jpeg', 'gif', 'webp'])) {
|
||||
CI_DEBUG && log_message('debug', 'Editor编辑器图片粘贴失败:扩展名不符合'.$ext);
|
||||
continue;
|
||||
}
|
||||
$content = base64_decode(str_replace($result[1], '', $img));
|
||||
if (strlen($content) > 30000000) {
|
||||
CI_DEBUG && log_message('debug', 'Editor编辑器图片粘贴失败:图片内容过大,超过30MB');
|
||||
continue;
|
||||
}
|
||||
$rt = \Phpcmf\Service::L('upload')->base64_image([
|
||||
'ext' => isset($field['setting']['option']['imagecut_ext']) && $field['setting']['option']['imagecut_ext'] ? $field['setting']['option']['imagecut_ext'] : $ext,
|
||||
'content' => $content,
|
||||
'watermark' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') || $field['setting']['option']['watermark'] ? 1 : 0,
|
||||
'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info(intval($field['setting']['option']['attachment']), $field['setting']['option']['image_reduce']),
|
||||
]);
|
||||
if (!$rt['code']) {
|
||||
CI_DEBUG && log_message('debug', 'Editor编辑器图片粘贴失败:'.$rt['msg']);
|
||||
continue;
|
||||
}
|
||||
$att = \Phpcmf\Service::M('Attachment')->save_data($rt['data'], 'ueditor:'.$this->rid);
|
||||
if ($att['code']) {
|
||||
// 归档成功
|
||||
$value = str_replace($img, $rt['data']['url'], $value);
|
||||
$img = $att['code'];
|
||||
// 标记附件
|
||||
\Phpcmf\Service::M('Attachment')->save_ueditor_aid($this->rid, $att['code']);
|
||||
} else {
|
||||
CI_DEBUG && log_message('debug', 'Editor编辑器图片归档失败:'.$rt['msg']);
|
||||
}
|
||||
}
|
||||
// 缩略图
|
||||
if ($img && $slt) {
|
||||
$_field = \Phpcmf\Service::L('form')->fields;
|
||||
if (isset($_field['thumb']) && $_field['thumb']['fieldtype'] == 'File' && !\Phpcmf\Service::L('Field')->data[$_field['thumb']['ismain']]['thumb']) {
|
||||
if (!is_numeric($img)) {
|
||||
// 下载缩略图
|
||||
$width = isset($field['setting']['option']['thumb']['width']) ? $field['setting']['option']['thumb']['width'] : 0;
|
||||
$height = isset($field['setting']['option']['thumb']['height']) ? $field['setting']['option']['thumb']['height'] : 0;
|
||||
// 获取图片信息
|
||||
if ($width || $height) {
|
||||
$imageInfo = getimagesize($img);
|
||||
if ($imageInfo !== false) {
|
||||
// 宽度
|
||||
if ($width && $imageInfo[0] < $width) {
|
||||
$img = '';
|
||||
continue;
|
||||
}
|
||||
if ($height && $imageInfo[1] < $height) {
|
||||
$img = '';
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$img = '';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 判断域名白名单
|
||||
$arr = parse_url($img);
|
||||
$domain = $arr['host'];
|
||||
if ($domain) {
|
||||
$sites = \Phpcmf\Service::R(WRITEPATH.'config/domain_site.php');
|
||||
if (isset($sites[$domain])) {
|
||||
// 过滤站点域名
|
||||
} elseif (strpos(SYS_UPLOAD_URL, $domain) !== false) {
|
||||
// 过滤附件白名单
|
||||
} else {
|
||||
$file = dr_catcher_data($img, 8);
|
||||
if (!$file) {
|
||||
CI_DEBUG && log_message('debug', '服务器无法下载图片:'.$img);
|
||||
} else {
|
||||
// 尝试找一找附件库
|
||||
$att = \Phpcmf\Service::M()->table('attachment')->like('related', 'ueditor')->where('filemd5', md5($file))->getRow();
|
||||
if ($att) {
|
||||
$img = $att['id'];
|
||||
} else {
|
||||
// 下载归档
|
||||
$rt = \Phpcmf\Service::L('upload')->down_file([
|
||||
'url' => html_entity_decode((string)$img),
|
||||
'timeout' => 5,
|
||||
'watermark' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') || $field['setting']['option']['watermark'] ? 1 : 0,
|
||||
'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info(intval($field['setting']['option']['attachment']), $field['setting']['option']['image_reduce']),
|
||||
'file_ext' => $ext,
|
||||
'file_content' => $file,
|
||||
]);
|
||||
if ($rt['code']) {
|
||||
$att = \Phpcmf\Service::M('Attachment')->save_data($rt['data'], 'ueditor:'.$this->rid);
|
||||
if ($att['code']) {
|
||||
// 归档成功
|
||||
$value = str_replace($img, $rt['data']['url'], $value);
|
||||
$img = $att['code'];
|
||||
// 标记附件
|
||||
\Phpcmf\Service::M('Attachment')->save_ueditor_aid($this->rid, $att['code']);
|
||||
}
|
||||
} else {
|
||||
CI_DEBUG && log_message('debug', 'Editor编辑器图片下载失败:'.$rt['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
\Phpcmf\Service::L('Field')->data[$_field['thumb']['ismain']]['thumb'] = $_POST['data']['thumb'] = $img;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 去除站外链接
|
||||
if (isset($_POST['is_remove_a_'.$field['fieldname']]) && $_POST['is_remove_a_'.$field['fieldname']]
|
||||
&& preg_match_all("/<a (.*)href=(.+)>(.*)<\/a>/Ui", $value, $arrs)) {
|
||||
$sites = \Phpcmf\Service::R(WRITEPATH.'config/domain_site.php');
|
||||
foreach ($arrs[2] as $i => $a) {
|
||||
if (strpos($a, ' ') !== false) {
|
||||
list($a) = explode(' ', $a);
|
||||
}
|
||||
$a = trim($a, '"');
|
||||
$a = trim($a, '\'');
|
||||
$arr = parse_url($a);
|
||||
if ($arr && $arr['host'] && !isset($sites[$arr['host']])) {
|
||||
// 去除a标签
|
||||
$value = str_replace($arrs[0][$i], $arrs[3][$i], $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 提取描述信息
|
||||
if (isset($_POST['data']['description']) && isset($_POST['is_auto_description_'.$field['fieldname']])
|
||||
&& $_POST['is_auto_description_'.$field['fieldname']]) {
|
||||
\Phpcmf\Service::L('Field')->data[1]['description'] = $_POST['data']['description'] = dr_get_description($value);
|
||||
}
|
||||
|
||||
// 替换分页
|
||||
$value = str_replace('_ueditor_page_break_tag_', '<hr class="pagebreak">', $value);
|
||||
$value = str_replace(' style=""', '', $value);
|
||||
if (isset($field['setting']['validate']['xss']) && $field['setting']['validate']['xss']) {
|
||||
// 开启xss
|
||||
$value = \Phpcmf\Service::L('Security')->xss_clean($value);
|
||||
}
|
||||
// 入库操作
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = htmlspecialchars($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取附件id
|
||||
*/
|
||||
public function get_attach_id($value) {
|
||||
return \Phpcmf\Service::M('Attachment')->get_ueditor_aid($this->rid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 附件处理
|
||||
*/
|
||||
public function attach($data, $_data) {
|
||||
|
||||
$add = \Phpcmf\Service::M('Attachment')->get_ueditor_aid($this->rid, true);
|
||||
if (isset($_POST['data'][$this->field['fieldname']]) && $_POST['data'][$this->field['fieldname']]
|
||||
&& preg_match_all("/<([a-z]+) cmsattachid=\"([0-9]+)\"/Ui", $_POST['data'][$this->field['fieldname']], $att)) {
|
||||
if ($add && is_array($add)) {
|
||||
$add = array_merge($add, $att[2]);
|
||||
} else {
|
||||
$add = $att[2];
|
||||
}
|
||||
}
|
||||
|
||||
return [$add, NULL];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*
|
||||
* @param array $value 数据库值
|
||||
* @return string
|
||||
*/
|
||||
public function output($value) {
|
||||
return dr_ueditor_html($value, isset(\Phpcmf\Service::L('Field')->data['title']) ? \Phpcmf\Service::L('Field')->data['title'] : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段显示
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
$html = '
|
||||
<div class="portlet bordered light">
|
||||
<div class="portlet-body">
|
||||
<div class="scroller" style="width:'.(\Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'].(is_numeric($field['setting']['option']['width']) ? 'px' : '') : '100%')).';height:'.($field['setting']['option']['height'] ? $field['setting']['option']['height'] : '300').'px" data-always-visible="1" data-rail-visible="1">
|
||||
'.htmlspecialchars_decode((string)$value).'
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
return $this->input_format($field['fieldname'], $field['name'], $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 表单宽度设置
|
||||
$width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'] : '100%');
|
||||
|
||||
// 表单高度设置
|
||||
$height = $field['setting']['option']['height'] ? $field['setting']['option']['height'] : '';
|
||||
|
||||
// 字段提示信息
|
||||
$tips = $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$name.'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
// 输出
|
||||
$str = '';
|
||||
|
||||
// 防止重复加载JS
|
||||
if (!$this->is_load_js($field['fieldtype'])) {
|
||||
$str.= '
|
||||
<link href="'.THEME_PATH.'assets/editor/summernote.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet">
|
||||
<script type="text/javascript" src="'.THEME_PATH.'assets/editor/summernote'.(IS_XRDEV ? '' : '.min').'.js?v='.CMF_UPDATE_TIME.'"></script>
|
||||
';
|
||||
$this->set_load_js($field['fieldtype'], 1);
|
||||
}
|
||||
if (!isset($field['setting']['option']['attach_size']) || !$field['setting']['option']['attach_size']) {
|
||||
$option['attach_size'] = 200;
|
||||
}
|
||||
|
||||
$p = dr_authcode([
|
||||
'size' => (!isset($field['setting']['option']['video_size']) || !$field['setting']['option']['video_size']) ? 500 : $field['setting']['option']['video_size'],
|
||||
'exts' => (!isset($field['setting']['option']['video_ext']) || !$field['setting']['option']['video_ext']) ? 'mp4' : $field['setting']['option']['video_ext'],
|
||||
'count' => 100,
|
||||
'attachment' => $field['setting']['option']['attachment'],
|
||||
], 'ENCODE');
|
||||
$p2 = dr_authcode([
|
||||
'size' => (!isset($field['setting']['option']['image_size']) || !$field['setting']['option']['image_size']) ? 10 : $field['setting']['option']['image_size'],
|
||||
'exts' => (!isset($field['setting']['option']['image_ext']) || !$field['setting']['option']['image_ext']) ? 'jpg,gif,png,webp,jpeg' : $field['setting']['option']['image_ext'],
|
||||
'count' => 100,
|
||||
'attachment' => $field['setting']['option']['attachment'],
|
||||
'image_reduce' => $field['setting']['option']['image_reduce'],
|
||||
], 'ENCODE');
|
||||
$p3 = dr_authcode([
|
||||
'size' => (!isset($field['setting']['option']['attach_size']) || !$field['setting']['option']['attach_size']) ? 200 : $field['setting']['option']['attach_size'],
|
||||
'exts' => (!isset($field['setting']['option']['attach_ext']) || !$field['setting']['option']['attach_ext']) ? 'zip,rar,txt,doc' : $field['setting']['option']['attach_ext'],
|
||||
'count' => 100,
|
||||
'attachment' => $field['setting']['option']['attachment'],
|
||||
], 'ENCODE');
|
||||
$str.= "<textarea class=\"dr_ueditor\" name=\"data[$name]\" id=\"dr_$name\">$value</textarea>";
|
||||
|
||||
if ($field['setting']['option']['imgtitle'] > 0) {
|
||||
$title = UEDITOR_IMG_TITLE;
|
||||
} elseif ($field['setting']['option']['imgtitle'] < 0) {
|
||||
$title = 'none';
|
||||
} else {
|
||||
$title = '';
|
||||
}
|
||||
if ($field['setting']['option']['imgalt'] > 0) {
|
||||
$alt = UEDITOR_IMG_TITLE;
|
||||
} elseif ($field['setting']['option']['imgalt'] < 0) {
|
||||
$alt = 'none';
|
||||
} else {
|
||||
$alt = '';
|
||||
}
|
||||
$tool = '';
|
||||
if (IS_ADMIN) {
|
||||
if ($field['setting']['option']['toolbar']) {
|
||||
$tool = $this->_toolbar($field['setting']['option']['toolbar']);
|
||||
}
|
||||
} else {
|
||||
if ($field['setting']['option']['toolbar_home']) {
|
||||
$tool = $this->_toolbar($field['setting']['option']['toolbar_home']);
|
||||
}
|
||||
}
|
||||
|
||||
$wm = \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') || $field['setting']['option']['watermark'] ? 1 : 0;
|
||||
$str.= \Phpcmf\Service::L('js_packer')->pack("
|
||||
<script type=\"text/javascript\">
|
||||
function dr_is_auto_description_".$field['fieldname']."() {
|
||||
var v = $(\"#is_auto_description_".$field['fieldname']."\").is(\":checked\");
|
||||
if (v == true) {
|
||||
$(\"#dr_description\").prop(\"readonly\", true);
|
||||
} else {
|
||||
$(\"#dr_description\").prop(\"readonly\", false);
|
||||
}
|
||||
}
|
||||
$(function(){
|
||||
dr_is_auto_description_".$field['fieldname']."();
|
||||
$('#dr_".$name."').summernote({
|
||||
field: '".$field['fieldname']."',
|
||||
isMobileWidth: '".(\Phpcmf\Service::IS_MOBILE_USER() ? '95%' : '80%')."',
|
||||
llVideoUrl: '".dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=input_file_list&is_iframe=1&p=' . $p)."',
|
||||
llImageUrl: '".dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=input_file_list&is_iframe=1&p=' . $p2."&is_wm=".$wm)."',
|
||||
attachUrl: '".dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=input_file_list&is_iframe=1&p=' . $p3)."',
|
||||
videoUrl: '".dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=upload&is_iframe=1&token='.dr_get_csrf_token().'&rid='.$this->rid.'&p=' . $p)."',
|
||||
videoLinkUrl: '".dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=video&is_iframe=1&token='.dr_get_csrf_token().'&rid='.$this->rid.'&p=' . $p)."',
|
||||
isImageTitle:'".$title."',
|
||||
isImageAlt:'".$alt."',
|
||||
height:'".$height."',
|
||||
width:'".$width."'
|
||||
".($tool)."
|
||||
});
|
||||
});
|
||||
function dr_editor_down_img_".$field['fieldname']."(){
|
||||
var index = layer.load(2, {
|
||||
shade: [0.3,'#fff'], //0.1透明度的白色背景
|
||||
time: 100000000
|
||||
});
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '".dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=down_img&is_iframe=1&token='.dr_get_csrf_token().'&rid='.$this->rid.'&p=' . $p2."&is_wm=".$wm)."',
|
||||
dataType: 'json',
|
||||
data: { value: $('#dr_".$field['fieldname']."').summernote('code') },
|
||||
success: function (json) {
|
||||
layer.close(index);
|
||||
if (json.code == 0) {
|
||||
dr_cmf_tips(0, json.msg, json.data.time);
|
||||
} else {
|
||||
|
||||
var width = '500px';
|
||||
var height = '70%';
|
||||
|
||||
if (is_mobile_cms == 1) {
|
||||
width = '95%';
|
||||
height = '90%';
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '',
|
||||
fix:true,
|
||||
scrollbar: false,
|
||||
maxmin: false,
|
||||
resize: true,
|
||||
shadeClose: true,
|
||||
shade: 0,
|
||||
area: [width, height],
|
||||
btn: [dr_lang('确定'), dr_lang('取消')],
|
||||
yes: function(index, layero){
|
||||
// 延迟加载
|
||||
var loading = layer.load(2, {
|
||||
shade: [0.3,'#fff'], //0.1透明度的白色背景
|
||||
time: 100000000
|
||||
});
|
||||
var body = layer.getChildFrame('body', index);
|
||||
$.ajax({type: 'POST',dataType:'json', url: json.msg, data: $(body).find('#myform').serialize(),
|
||||
success: function(json) {
|
||||
layer.close(loading);
|
||||
if (json.code) {
|
||||
layer.close(index);
|
||||
$('#dr_".$field['fieldname']."').summernote('reset');
|
||||
$('#dr_".$field['fieldname']."').summernote('pasteHTML', json.data);
|
||||
dr_cmf_tips(1, json.msg);
|
||||
} else {
|
||||
dr_cmf_tips(0, json.msg, json.data.time);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
error: function(HttpRequest, ajaxOptions, thrownError) {
|
||||
dr_ajax_alert_error(HttpRequest, this, thrownError);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
},
|
||||
success: function(layero, index){
|
||||
// 主要用于后台权限验证
|
||||
var body = layer.getChildFrame('body', index);
|
||||
var json = $(body).html();
|
||||
if (json.indexOf('\"code\":0') > 0 && json.length < 500){
|
||||
var obj = JSON.parse(json);
|
||||
layer.close(index);
|
||||
dr_cmf_tips(0, obj.msg);
|
||||
}
|
||||
},
|
||||
content: json.msg+'&is_iframe=1'
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
error: function(HttpRequest, ajaxOptions, thrownError) {
|
||||
dr_ajax_alert_error(HttpRequest, this, thrownError);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
", 0);
|
||||
|
||||
|
||||
if (isset($field['setting']['option']['show_bottom_boot']) && $field['setting']['option']['show_bottom_boot']) {
|
||||
$str.= '<div class="mt-checkbox-inline" style="margin-top: 10px;">';
|
||||
$str.= ' <label style="margin-bottom: 0;" class="mt-checkbox mt-checkbox-outline">
|
||||
<input name="is_auto_thumb_'.$field['fieldname'].'" type="checkbox" '.($field['setting']['option']['tool_select_1'] ? 'checked' : '').' value="1"> '.dr_lang('提取第一个图片为缩略图').' <span></span>
|
||||
</label>';
|
||||
$str.= '
|
||||
<label style="margin-bottom: 0;" class="mt-checkbox mt-checkbox-outline">
|
||||
<input id="is_auto_description_'.$field['fieldname'].'" onclick="dr_is_auto_description_'.$field['fieldname'].'()" name="is_auto_description_'.$field['fieldname'].'" type="checkbox" '.($field['setting']['option']['tool_select_2'] ? 'checked' : '').' value="1"> '.dr_lang('提取内容作为描述信息').' <span></span>
|
||||
</label>';
|
||||
$str.= '
|
||||
<label style="margin-bottom: 0;" class="mt-checkbox mt-checkbox-outline">
|
||||
<input name="is_remove_a_'.$field['fieldname'].'" type="checkbox" '.($field['setting']['option']['tool_select_4'] ? 'checked' : '').' value="1"> '.dr_lang('去除站外链接').' <span></span>
|
||||
</label>';
|
||||
if ($field['setting']['option']['tool_select_3']) {
|
||||
$str.= '
|
||||
<label style="margin-bottom: 0;" class="mt-checkbox mt-checkbox-outline">
|
||||
<a class="btn blue btn-xs" onclick="dr_editor_down_img_'.$field['fieldname'].'()"> '.dr_lang('一键下载远程图片').' </a>
|
||||
</label>';
|
||||
}
|
||||
$str.= '</div>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->input_format($name, $text, $str.$tips);
|
||||
}
|
||||
|
||||
private function _toolbar($json) {
|
||||
if (strpos($json, '"') !== false) {
|
||||
return '';
|
||||
}
|
||||
return ',toolbar: ['.$json.']';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
/**
|
||||
* 系统可用字段
|
||||
* id 文件名称
|
||||
* name 显示名称
|
||||
* used 数组 表示可以用到哪些地方
|
||||
* namespace 是哪个app专属的
|
||||
*/
|
||||
|
||||
return [
|
||||
[
|
||||
'id' => 'Text',
|
||||
'name' => '文本字段',
|
||||
],
|
||||
[
|
||||
'id' => 'Textbtn',
|
||||
'name' => '文本事件',
|
||||
],
|
||||
[
|
||||
'id' => 'Textselect',
|
||||
'name' => '文本选择',
|
||||
],
|
||||
[
|
||||
'id' => 'Textarea',
|
||||
'name' => '多行文本',
|
||||
],
|
||||
[
|
||||
'id' => 'Editor',
|
||||
'name' => '简化编辑器',
|
||||
],
|
||||
[
|
||||
'id' => 'Radio',
|
||||
'name' => '单选按钮',
|
||||
],
|
||||
[
|
||||
'id' => 'Select',
|
||||
'name' => '下拉选择(单选)',
|
||||
],
|
||||
[
|
||||
'id' => 'Selects',
|
||||
'name' => '下拉选择(多选)',
|
||||
],
|
||||
[
|
||||
'id' => 'Checkbox',
|
||||
'name' => '复选框',
|
||||
],
|
||||
[
|
||||
'id' => 'Color',
|
||||
'name' => '颜色选取',
|
||||
],
|
||||
[
|
||||
'id' => 'Date',
|
||||
'name' => '日期',
|
||||
],
|
||||
[
|
||||
'id' => 'Time',
|
||||
'name' => '时间',
|
||||
],
|
||||
[
|
||||
'id' => 'Diy',
|
||||
'name' => '自定义',
|
||||
],
|
||||
[
|
||||
'id' => 'File',
|
||||
'name' => '单文件',
|
||||
],
|
||||
[
|
||||
'id' => 'Files',
|
||||
'name' => '多文件',
|
||||
],
|
||||
[
|
||||
'id' => 'Group',
|
||||
'name' => '单行分组字段',
|
||||
],
|
||||
[
|
||||
'id' => 'Merge',
|
||||
'name' => '多行分组字段',
|
||||
'used' => ['module', 'form', 'mform', 'site'],
|
||||
],
|
||||
[
|
||||
'id' => 'Linkage',
|
||||
'name' => '联动菜单(单选)',
|
||||
],
|
||||
[
|
||||
'id' => 'Linkages',
|
||||
'name' => '联动菜单(多选)',
|
||||
],
|
||||
[
|
||||
'id' => 'Touchspin',
|
||||
'name' => '增减量',
|
||||
],
|
||||
[
|
||||
'id' => 'Property',
|
||||
'name' => '属性参数',
|
||||
],
|
||||
[
|
||||
'id' => 'Uid',
|
||||
'name' => '账号',
|
||||
],
|
||||
[
|
||||
'id' => 'Pay',
|
||||
'name' => '购买(单一)',
|
||||
],
|
||||
[
|
||||
'id' => 'Pays',
|
||||
'name' => '购买(组合)',
|
||||
],
|
||||
[
|
||||
'id' => 'Paystext',
|
||||
'name' => '购买(组合)参数',
|
||||
],
|
||||
[
|
||||
'id' => 'Image',
|
||||
'name' => '图片专用',
|
||||
],
|
||||
[
|
||||
'id' => 'Ftable',
|
||||
'name' => '填写表格',
|
||||
],
|
||||
[
|
||||
'id' => 'Join',
|
||||
'name' => '关联表',
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
@@ -0,0 +1,362 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class File extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = TRUE;
|
||||
$this->defaulttype = 'VARCHAR'; // 当用户没有选择字段类型时的缺省值
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$mthumb = '';
|
||||
if (\Phpcmf\Service::M('field')->relatedname == 'module') {
|
||||
$mthumb = '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('首图作为缩略图').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][stslt]" '.($option['stslt'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('当缩略图字段为空时,用本字段的图片来填充(仅对模块字段有效)').'</span>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
if ($this->field && $this->field['fieldname'] != 'thumb') {
|
||||
$mthumb = '';
|
||||
}
|
||||
|
||||
return [$this->field_type($option['fieldtype'], $option['fieldlength']).$this->_search_field().
|
||||
$mthumb.'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('手动输入').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][input]" '.($option['input'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('开启将会出现手动输入文件地址按钮').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('扩展名').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="40" name="data[setting][option][ext]" value="'.$option['ext'].'"></label>
|
||||
<span class="help-block">'.dr_lang('格式:jpg,gif,png,exe,html,php,rar,zip').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('文件大小').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" value="'.$option['size'].'" name="data[setting][option][size]"></label>
|
||||
<span class="help-block">'.dr_lang('单位MB').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('分段上传').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][chunk]" '.($option['chunk'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('当文件太大时可以采取分段上传,可以提升上传效率').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('显示浏览附件').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][unused]" '.($option['unused'] ? 'checked' : '').' value="1" data-off-text="'.dr_lang('已开启').'" data-on-text="'.dr_lang('已关闭').'" data-off-color="success" data-on-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('允许用户选取自己已经上传的附件').'</span>
|
||||
</div>
|
||||
</div>
|
||||
'.$this->attachment($option).'
|
||||
'
|
||||
,
|
||||
'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('提示扩展名显示').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][option][is_ext_tips]" value="0" '.(!$option['is_ext_tips'] ? 'checked' : '').' /> '.dr_lang('已显示').' <span></span></label>
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][option][is_ext_tips]" value="1" '.($option['is_ext_tips'] ? 'checked' : '').' /> '.dr_lang('已关闭').' <span></span></label>
|
||||
</div><span class="help-block">'.dr_lang('提示字段上传的扩展名和大小限制的文本信息').'</span>
|
||||
</div>
|
||||
</div>'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证字段属性
|
||||
*/
|
||||
public function edit_config($post) {
|
||||
|
||||
if (!isset($post['setting']['option']['ext']) || !$post['setting']['option']['ext']) {
|
||||
return dr_return_data(0, dr_lang('扩展名必须填写'));
|
||||
} elseif (!isset($post['setting']['option']['size']) || !$post['setting']['option']['size']) {
|
||||
return dr_return_data(0, dr_lang('文件大小必须填写'));
|
||||
}
|
||||
|
||||
return dr_return_data(1, 'ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取附件id
|
||||
*/
|
||||
public function get_attach_id($value) {
|
||||
|
||||
$data = [];
|
||||
if (!$value || !is_numeric($value)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data[] = $value;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 附件处理
|
||||
*/
|
||||
public function attach($data, $_data) {
|
||||
|
||||
// 新旧数据都无附件就跳出
|
||||
if (!$data && !$_data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 新旧数据都一样时表示没做改变就跳出
|
||||
if (dr_diff($data, $_data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 当无新数据且有旧数据表示删除旧附件
|
||||
if (!$data && $_data) {
|
||||
return [
|
||||
[],
|
||||
[$_data]
|
||||
];
|
||||
}
|
||||
|
||||
// 当无旧数据且有新数据表示增加新附件
|
||||
if ($data && !$_data) {
|
||||
return [
|
||||
[$data],
|
||||
[]
|
||||
];
|
||||
}
|
||||
|
||||
// 剩下的情况就是删除旧文件增加新文件
|
||||
return [
|
||||
[$data],
|
||||
[$_data]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
$value = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
|
||||
// 存在缩略图值时,自己就是缩略图
|
||||
if (!$value && $field['fieldname'] == 'thumb' && isset(\Phpcmf\Service::L('Field')->data[$field['ismain']]['thumb']) && \Phpcmf\Service::L('Field')->data[$field['ismain']]['thumb']) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 提取缩略图
|
||||
if ($value && $field['setting']['option']['stslt']) {
|
||||
$_field = \Phpcmf\Service::L('form')->fields;
|
||||
if (isset($_field['thumb']) && $_field['thumb']['fieldtype'] == 'File' && !\Phpcmf\Service::L('Field')->data[$_field['thumb']['ismain']]['thumb']) {
|
||||
$info = \Phpcmf\Service::C()->get_attachment($value, 1);
|
||||
if ($info && in_array($info['fileext'], ['jpg', 'jpeg', 'png', 'gif'])) {
|
||||
\Phpcmf\Service::L('Field')->data[$_field['thumb']['ismain']]['thumb'] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 表单附加参数
|
||||
$attr = $field['setting']['validate']['formattr'];
|
||||
|
||||
$ts = dr_lang('上传格式要求:%s(%s)', str_replace(',', '、', (string)$field['setting']['option']['ext']), ($field['setting']['option']['size']).'MB');
|
||||
|
||||
$p = dr_authcode([
|
||||
'size' => ($field['setting']['option']['size']),
|
||||
'exts' => $field['setting']['option']['ext'],
|
||||
'attachment' => $field['setting']['option']['attachment'],
|
||||
'image_reduce' => $field['setting']['option']['image_reduce'],
|
||||
], 'ENCODE');
|
||||
|
||||
// 显示模板
|
||||
$tpl = '<div id="dr_'.$name.'_files_row" class="file_row_html files_row">';
|
||||
$tpl.= '<div class="files_row_preview preview">{preview}</div>';
|
||||
$tpl.= '<input type="hidden" '.$attr.' id="dr_'.$name.'" class="files_row_id" name="data['.$name.']" value="{id}" />';
|
||||
$tpl.= '</div>';
|
||||
|
||||
// 已保存数据
|
||||
$val = '';
|
||||
$file_url = '';
|
||||
$show_delete = 0;
|
||||
if ($value) {
|
||||
$file = \Phpcmf\Service::C()->get_attachment($value, 1);
|
||||
if ($file) {
|
||||
$preview = dr_file_preview_html($file['url'], $file['id']);
|
||||
$filepath = $file['attachment'];
|
||||
$title = $file['filename'];
|
||||
$upload = '';
|
||||
} else {
|
||||
$file_url = $filepath = $value;
|
||||
$preview = dr_file_preview_html($value);
|
||||
$upload = '';
|
||||
$title = '';
|
||||
}
|
||||
$val.= str_replace(
|
||||
['{title}', '{id}', '{filepath}', '{preview}', '{upload}'],
|
||||
[$title, $value, dr_strcut($filepath, 30), $preview, $upload],
|
||||
$tpl
|
||||
);
|
||||
$show_delete = 1;
|
||||
} else {
|
||||
$val.= '<input type="hidden" '.$attr.' id="dr_'.$name.'" name="data['.$name.']" value="" />';
|
||||
}
|
||||
|
||||
$json = json_encode([
|
||||
'name' => $name,
|
||||
'ext' => !$field['setting']['option']['ext'] || $field['setting']['option']['ext'] == '*' ? 'null' : ' /(\.|\/)('.str_replace(',', '|', $field['setting']['option']['ext']).')$/i',
|
||||
'size' => floatval($field['setting']['option']['size']) * 1024 * 1024,
|
||||
'url' => dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&is_iframe=1&token='.dr_get_csrf_token()).'&siteid='.SITE_ID.'&m=upload&p='.$p.'&fid='.$field['id'],
|
||||
'unused_url' => dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=input_file_list&is_iframe=1&p=' . $p . '&fid=' . $field['id']),
|
||||
'input_url' => dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=input_file_url&is_iframe=1&token='.dr_get_csrf_token().'&siteid='.SITE_ID.'&p='.$p.'&fid='.$field['id'].'&file='.urlencode($file_url).'&one=1'),
|
||||
'tpl' => $tpl,
|
||||
'area' => \Phpcmf\Service::IS_MOBILE_USER() ? ["95%", "90%"] : ["80%", "80%"],
|
||||
'url_area' => \Phpcmf\Service::IS_MOBILE_USER() ? ["95%", "90%"] : ["50%", "300px"],
|
||||
'chunk' => $field['setting']['option']['chunk'] ? 20 * 1024 * 1024 : 0,
|
||||
]);
|
||||
|
||||
$use = '';
|
||||
if (!$field['setting']['option']['unused'] && \Phpcmf\Service::C()->uid) {
|
||||
$use.= '<button type="button" class="btn red btn-sm fileinput-unused">
|
||||
<i class="fa fa-folder-open"></i>
|
||||
<span> '.dr_lang('浏览').' </span>
|
||||
</button>';
|
||||
}
|
||||
if ($field['setting']['option']['input']) {
|
||||
$use.= '<button style="margin-left: 5px;" type="button" class="btn green btn-sm fileinput-url">
|
||||
<i class="fa fa-edit"></i>
|
||||
<span> '.dr_lang('地址').' </span>
|
||||
</button>';
|
||||
}
|
||||
$use.= '<button onclick="fileupload_file_remove(\''.$name.'\')" style="margin-left: 5px;'.(!$show_delete ? 'display:none' : '').'" type="button" class="btn red btn-sm fileinput-delete">
|
||||
<i class="fa fa-trash"></i>
|
||||
<span> '.dr_lang('删除').' </span>
|
||||
</button>';
|
||||
|
||||
// 表单输出
|
||||
$str = '
|
||||
<div class="row fileupload-buttonbar" id="fileupload_'.$name.'">
|
||||
<div class="col-lg-12">
|
||||
<button class="btn blue btn-sm fileinput-button">
|
||||
<i class="fa fa-plus"></i>
|
||||
<span> '.dr_lang('上传').' </span>
|
||||
<input type="file" name="file_data">
|
||||
</button>
|
||||
|
||||
'.$use.'
|
||||
|
||||
<span class="fileupload-process"> </span>
|
||||
</div>
|
||||
<div class="col-lg-12 fileupload-progress fade" style="display:none">
|
||||
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
|
||||
<div class="progress-bar progress-bar-success" style="width:0%;"> </div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
if (!$field['setting']['option']['is_ext_tips']) {
|
||||
$str.= '<p class="finecms-file-ts">'.$ts.'</p>';
|
||||
}
|
||||
$str.= '<div id="fileupload_'.$name.'_files" class="files">'.$val.'</div>';
|
||||
|
||||
if (!$this->is_load_js('File')) {
|
||||
$str.= '
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/jquery-fileupload/css/jquery.fileupload.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/jquery-fileupload/js/jquery.fileupload.min.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
';
|
||||
$this->set_load_js('File', 1);
|
||||
}
|
||||
|
||||
$str.= '<script type="text/javascript">
|
||||
$(function() {
|
||||
fileupload_file_init('.$json.');
|
||||
});
|
||||
</script>';
|
||||
|
||||
return $this->input_format($name, $text, $str.$tips);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$html = '';
|
||||
|
||||
if ($value) {
|
||||
// 显示模板
|
||||
$file = \Phpcmf\Service::C()->get_attachment($value, 1);
|
||||
if ($file) {
|
||||
$preview = dr_file_preview_html($file['url'], $file['id']);
|
||||
} else {
|
||||
$preview = dr_file_preview_html($value);
|
||||
}
|
||||
$html = '<div class="files_row_preview preview">'.$preview.'</div>';
|
||||
}
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,542 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Files extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->close_xss = 1; // 关闭xss验证
|
||||
$this->fieldtype = ['TEXT' => ''];
|
||||
$this->defaulttype = 'TEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$mthumb = '';
|
||||
if (\Phpcmf\Service::M('field')->relatedname == 'module') {
|
||||
$mthumb = '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('首图作为缩略图').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][stslt]" '.($option['stslt'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('当缩略图字段为空时,用本字段的图片来填充(仅对模块字段有效)').'</span>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
return [$this->_search_field().$mthumb.'
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('手动输入').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][input]" '.($option['input'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('开启将会出现手动输入文件地址按钮').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('附件名称').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][name]" '.($option['name'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('开启将会出现单行文本输入框').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('描述文本').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][desc]" '.($option['desc'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('开启将会出现多行文本输入框').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('文件大小').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" value="'.$option['size'].'" name="data[setting][option][size]"></label>
|
||||
<span class="help-block">'.dr_lang('单位MB').'</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('分段上传').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][chunk]" '.($option['chunk'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('当文件太大时可以采取分段上传,可以提升上传效率').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('滚动显示').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][scroller]" '.($option['scroller'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('当文件文件上传太多时,已上传文件列表可以以固定高度来下来滚动显示').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('显示方式').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][grid]" '.($option['grid'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('传统模式').'" data-off-text="'.dr_lang('卡片模式').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('上传后的文件列表采用卡片式显示,适用于图片类文件显示方式').'</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('上传数量').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" value="'.$option['count'].'" name="data[setting][option][count]"></label>
|
||||
<span class="help-block">'.dr_lang('每次最多上传的文件数量').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('扩展名').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="40" name="data[setting][option][ext]" value="'.$option['ext'].'"></label>
|
||||
<span class="help-block">'.dr_lang('格式:jpg,gif,png,exe,html,php,rar,zip').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('显示浏览附件').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][unused]" '.($option['unused'] ? 'checked' : '').' value="1" data-off-text="'.dr_lang('已开启').'" data-on-text="'.dr_lang('已关闭').'" data-off-color="success" data-on-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('允许用户选取自己已经上传的附件').'</span>
|
||||
</div>
|
||||
</div>
|
||||
'.$this->attachment($option).'',
|
||||
|
||||
'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('提示扩展名显示').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][option][is_ext_tips]" value="0" '.(!$option['is_ext_tips'] ? 'checked' : '').' /> '.dr_lang('已显示').' <span></span></label>
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][option][is_ext_tips]" value="1" '.($option['is_ext_tips'] ? 'checked' : '').' /> '.dr_lang('已关闭').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('提示字段上传的扩展名和大小限制的文本信息').'</span>
|
||||
</div>
|
||||
</div>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证字段属性
|
||||
*/
|
||||
public function edit_config($post) {
|
||||
|
||||
if (!isset($post['setting']['option']['ext']) || !$post['setting']['option']['ext']) {
|
||||
return dr_return_data(0, dr_lang('扩展名必须填写'));
|
||||
} elseif (!isset($post['setting']['option']['size']) || !$post['setting']['option']['size']) {
|
||||
return dr_return_data(0, dr_lang('文件大小必须填写'));
|
||||
} elseif (!isset($post['setting']['option']['count']) || !$post['setting']['option']['count']) {
|
||||
return dr_return_data(0, dr_lang('上传数量必须填写'));
|
||||
}
|
||||
|
||||
return dr_return_data(1, 'ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return dr_get_files($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取附件id
|
||||
*/
|
||||
public function get_attach_id($value) {
|
||||
|
||||
$data = [];
|
||||
$value = dr_string2array($value);
|
||||
|
||||
if (!$value) {
|
||||
return $data;
|
||||
} elseif (!isset($value['file'])) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
foreach ($value['file'] as $i => $file) {
|
||||
is_numeric($file) && $data[] = $file;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
$data = [];
|
||||
$value = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
if ($value && is_array($value) && $value['id']) {
|
||||
foreach ($value['id'] as $id => $aid) {
|
||||
$title = (string)$value['title'][$id];
|
||||
$data['file'][$id] = $aid ? $aid : (string)$value['file'][$id];
|
||||
$data['title'][$id] = trim($title);
|
||||
$data['description'][$id] = $value['description'][$id] ? trim($value['description'][$id]) : '';
|
||||
}
|
||||
}
|
||||
|
||||
// 提取缩略图
|
||||
if ($data['file'] && is_array($data['file']) && $field['setting']['option']['stslt']) {
|
||||
$_field = \Phpcmf\Service::L('form')->fields;
|
||||
if (isset($_field['thumb']) && $_field['thumb']['fieldtype'] == 'File' && !\Phpcmf\Service::L('Field')->data[intval($_field['thumb']['ismain'])]['thumb']) {
|
||||
$one = array_key_first($data['file']);
|
||||
if ($data['file'][$one]) {
|
||||
$info = \Phpcmf\Service::C()->get_attachment($data['file'][$one], 1);
|
||||
if ($info && in_array($info['fileext'], ['jpg', 'jpeg', 'png', 'gif'])) {
|
||||
\Phpcmf\Service::L('Field')->data[intval($_field['thumb']['ismain'])]['thumb'] = $data['file'][$one];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = dr_array2string($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 附件处理
|
||||
*/
|
||||
public function attach($data, $_data) {
|
||||
|
||||
$data = dr_string2array($data);
|
||||
$_data = dr_string2array($_data);
|
||||
|
||||
!isset($_data['file']) && $_data =['file' => NULL];
|
||||
!isset($data['file']) && $data = ['file' => NULL];
|
||||
|
||||
// 新旧数据都无附件就跳出
|
||||
if (!$data['file'] && !$_data['file']) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 新旧数据都一样时表示没做改变就跳出
|
||||
if (dr_diff($data['file'], $_data['file'])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 当无新数据且有旧数据表示删除旧附件
|
||||
if (!$data['file'] && $_data['file']) {
|
||||
return [ [], $_data['file'] ];
|
||||
}
|
||||
|
||||
// 当无旧数据且有新数据表示增加新附件
|
||||
if ($data['file'] && !$_data['file']) {
|
||||
|
||||
return [$data['file'], []];
|
||||
}
|
||||
|
||||
// 剩下的情况就是删除旧文件增加新文件
|
||||
|
||||
|
||||
// 新旧附件的交集,表示固定的
|
||||
$intersect = array_intersect($data['file'], $_data['file']);
|
||||
|
||||
return [
|
||||
array_diff($data['file'], $intersect), // 固有的与新文件中的差集表示新增的附件
|
||||
array_diff($_data['file'], $intersect), // 固有的与旧文件中的差集表示待删除的附件
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证加载变量设置
|
||||
*/
|
||||
public function set_load_js($name, $value) {
|
||||
\Phpcmf\Service::C()->loadjs['File'] = \Phpcmf\Service::C()->loadjs[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '') . dr_lang($field['name']);
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_' . $field['fieldname'] . '_tips">' . $field['setting']['validate']['tips'] . '</span>' : '';
|
||||
|
||||
$count = intval($field['setting']['option']['count']);
|
||||
$ts = dr_lang('上传格式要求:%s(%s),最多上传%s个文件', str_replace(',', '、', (string)$field['setting']['option']['ext']), ($field['setting']['option']['size']) . 'MB', $count);
|
||||
|
||||
|
||||
$p = dr_authcode([
|
||||
'size' => ($field['setting']['option']['size']),
|
||||
'exts' => $field['setting']['option']['ext'],
|
||||
'attachment' => $field['setting']['option']['attachment'],
|
||||
'image_reduce' => $field['setting']['option']['image_reduce'],
|
||||
'count' => $count,
|
||||
], 'ENCODE');
|
||||
// 显示模板
|
||||
if (!$field['setting']['option']['grid']) {
|
||||
|
||||
$tpl = '<div class="grid-item files_row">';
|
||||
$tpl.= '<div class="files_row_preview preview">{preview}</div>';
|
||||
$tpl.= '<input type="hidden" class="files_row_id" name="data[' . $name . '][id][]" value="{id}">';
|
||||
$tpl.= '<input class="files_row_name" {disabled} type="hidden" name="data[' . $name . '][file][]" value="{filepath}">';
|
||||
|
||||
|
||||
$tpl.= '<div class="op-btn">';
|
||||
$tpl.= '<label><button onclick="dr_file_remove(this)" type="button" class="btn red file_delete btn-xs"><i class="fa fa-trash"></i></button></label>';
|
||||
|
||||
|
||||
$tpl.= $js_rm = '<label><button onclick="fileupload_file_edit(\''.$name.'\',this)" type="button" class="fileinput-button btn green file_edit btn-xs"><i class="fa fa-upload"></i>{upload}</button></label>';
|
||||
|
||||
$tpl.= '</div>';
|
||||
|
||||
if ($field['setting']['option']['name']) {
|
||||
$tpl.= '<div class="col-md-12 files_show_title_html">';
|
||||
$tpl .= '<input placeholder="'.dr_lang('名称').'" class="form-control files_row_title" type="text" name="data[' . $name . '][title][]" value="{title}">';
|
||||
$tpl.= '</div>';
|
||||
}
|
||||
|
||||
if ($field['setting']['option']['desc']) {
|
||||
$tpl.= '<div class="col-md-12 files_show_description_html">';
|
||||
$tpl.= '<textarea placeholder="'.dr_lang('描述').'" class="form-control files_row_description" name="data['.$name.'][description][]">{description}</textarea>';
|
||||
$tpl.= '</div>';
|
||||
}
|
||||
|
||||
$tpl.= '</div>';
|
||||
} else {
|
||||
// 普通table模式
|
||||
if ($field['setting']['option']['name'] or $field['setting']['option']['desc']) {
|
||||
// 有名字和描述
|
||||
$tpl = '<tr class="template-download files_row">';
|
||||
$tpl.= '<td style="text-align:center;width: 80px;">';
|
||||
$tpl.= '<div class="files_row_preview preview">{preview}</div>';
|
||||
$tpl.= '</td>';
|
||||
$tpl.= '<td class="files_show_info">';
|
||||
$tpl.= '<div class="row">';
|
||||
$tpl.= '<div class="col-md-12 files_show_title_html">';
|
||||
if ($field['setting']['option']['name']) {
|
||||
$tpl .= '<input placeholder="'.dr_lang('名称').'" class="form-control files_row_title" type="text" name="data[' . $name . '][title][]" value="{title}">';
|
||||
}
|
||||
$tpl.= '<input type="hidden" class="files_row_id" name="data[' . $name . '][id][]" value="{id}">';
|
||||
$tpl.= '<input class="files_row_name" {disabled} type="hidden" name="data[' . $name . '][file][]" value="{filepath}">';
|
||||
$tpl.= '</div>';
|
||||
if ($field['setting']['option']['desc']) {
|
||||
$tpl.= '<div class="col-md-12 files_show_description_html">';
|
||||
$tpl.= '<textarea placeholder="'.dr_lang('描述').'" class="form-control files_row_description" name="data['.$name.'][description][]">{description}</textarea>';
|
||||
$tpl.= '</div>';
|
||||
}
|
||||
$tpl.= '</div>';
|
||||
$tpl.= '</td>';
|
||||
|
||||
$tpl.= '<td style="text-align:center;width: 80px;">';
|
||||
$tpl.= '<label><button onclick="dr_file_remove(this)" type="button" class="btn red file_delete btn-sm"><i class="fa fa-trash"></i></button></label>';
|
||||
|
||||
$tpl.= $js_rm = '<label><button onclick="fileupload_file_edit(\''.$name.'\',this)" type="button" class="fileinput-button btn green file_edit btn-sm"><i class="fa fa-upload"></i>{upload}</button></label>';
|
||||
|
||||
$tpl.= '</td>';
|
||||
$tpl.= '</tr>';
|
||||
} else {
|
||||
// 没有描述和名字修改
|
||||
$tpl = '<div class="template-download files_row">';
|
||||
$tpl.= '<div class="files_row_preview preview">{preview}</div>';
|
||||
$tpl.= '<input type="hidden" class="files_row_id" name="data[' . $name . '][id][]" value="{id}">';
|
||||
$tpl.= '<input class="files_row_name" {disabled} type="hidden" name="data[' . $name . '][file][]" value="{filepath}">';
|
||||
|
||||
$tpl.= '<div class="op-btn">';
|
||||
$tpl.= '<label><button onclick="dr_file_remove(this)" type="button" class="btn red file_delete btn-xs"><i class="fa fa-trash"></i></button></label>';
|
||||
$tpl.= $js_rm = '<label><button onclick="fileupload_file_edit(\''.$name.'\',this)" type="button" class="fileinput-button btn green file_edit btn-xs"><i class="fa fa-edit"></i>{upload}</button></label>';
|
||||
|
||||
$tpl.= '</div>';
|
||||
$tpl.= '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// 已保存数据
|
||||
$val = '';
|
||||
$value = dr_get_files($value);
|
||||
if ($value) {
|
||||
foreach ($value as $i => $t) {
|
||||
$id = $t['id'] ? $t['id'] : $t['file'];
|
||||
$file = \Phpcmf\Service::C()->get_attachment($id, 1);
|
||||
$description = $t['description'] ? htmlspecialchars($t['description']) : '';
|
||||
if ($file) {
|
||||
$disabled = 'readonly';
|
||||
$preview = dr_file_preview_html($file['url'], $file['id']);
|
||||
$filepath = dr_strcut($file['attachment'], 30);
|
||||
$upload = '<input type="file" name="file_data">';
|
||||
} else {
|
||||
$disabled = '';
|
||||
$filepath = htmlspecialchars((string)$id);
|
||||
$preview = dr_file_preview_html($id);
|
||||
$upload = '';
|
||||
//$id = '';
|
||||
}
|
||||
$val.= str_replace(
|
||||
['{title}', '{description}', '{id}', '{file}', '{filepath}', '{disabled}', '{preview}', '{upload}'],
|
||||
[htmlspecialchars((string)$t['title']), $description, $id, $id, $filepath, $disabled, $preview, $upload],
|
||||
$tpl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$field['setting']['option']['grid']) {
|
||||
$val = '<div id="fileupload_'.$name.'_files" class="files-grid-list">'.$val.'</div>';
|
||||
} else {
|
||||
if ($field['setting']['option']['name'] or $field['setting']['option']['desc']) {
|
||||
$val = '<table role="presentation" class="table table-striped table-fc-upload clearfix">
|
||||
<tbody id="fileupload_'.$name.'_files" class="files scroller_body">'.$val.'</tbody>
|
||||
</table>';
|
||||
} else {
|
||||
$val = '<div id="fileupload_'.$name.'_files" class="files scroller_body files-image-list">'.$val.'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
$json = json_encode([
|
||||
'name' => $name,
|
||||
'ext' => !$field['setting']['option']['ext'] || $field['setting']['option']['ext'] == '*' ? 'null' : ' /(\.|\/)('.str_replace(',', '|', $field['setting']['option']['ext']).')$/i',
|
||||
'size' => floatval($field['setting']['option']['size']) * 1024 * 1024,
|
||||
'url' => dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&is_iframe=1&token='.dr_get_csrf_token()).'&siteid=' . SITE_ID . '&m=upload&p=' . $p . '&fid=' . $field['id'],
|
||||
'unused_url' => dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=input_file_list&is_iframe=1&token='.dr_get_csrf_token()).'&siteid='.SITE_ID.'&p=' . $p . '&fid=' . $field['id'],
|
||||
'input_url' => dr_web_prefix(''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=input_file_url&is_iframe=1&token='.dr_get_csrf_token()).'&siteid='.SITE_ID.'&p='.$p.'&fid='.$field['id'].'&one='.($field['setting']['option']['name']?0:1),
|
||||
'tpl' => str_replace($js_rm, '', $tpl),
|
||||
'area' => \Phpcmf\Service::IS_MOBILE_USER() ? ["95%", "90%"] : ["80%", "80%"],
|
||||
'url_area' => \Phpcmf\Service::IS_MOBILE_USER() ? ["95%", "90%"] : ["50%", "340px"],
|
||||
'count' => $count,
|
||||
'error' => dr_lang('上传文件不能超过%s个', $count).(CI_DEBUG ? '(可在自定义字段中设置本字段的个数值)' : ''),
|
||||
'chunk' => $field['setting']['option']['chunk'] ? 20 * 1024 * 1024 : 0,
|
||||
]);
|
||||
|
||||
$use = '';
|
||||
if (!$field['setting']['option']['unused'] && \Phpcmf\Service::C()->uid) {
|
||||
$use.= '<button type="button" class="btn red btn-sm fileinput-unused">
|
||||
<i class="fa fa-folder-open"></i>
|
||||
<span> '.dr_lang('浏览').' </span>
|
||||
</button>';
|
||||
}
|
||||
if ($field['setting']['option']['input']) {
|
||||
$use.= '<button style="margin-left: 5px;" type="button" class="btn green btn-sm fileinput-url">
|
||||
<i class="fa fa-edit"></i>
|
||||
<span> '.dr_lang('地址').' </span>
|
||||
</button>';
|
||||
}
|
||||
|
||||
// 表单输出
|
||||
$str = '
|
||||
<div class="row fileupload-buttonbar" id="fileupload_'.$name.'">
|
||||
<div class="col-lg-12">
|
||||
<button class="btn blue btn-sm fileinput-button">
|
||||
<i class="fa fa-plus"></i>
|
||||
<span> '.dr_lang('上传').' </span>
|
||||
<input type="file" name="file_data" multiple="">
|
||||
</button>
|
||||
|
||||
'.$use.'
|
||||
|
||||
<span class="fileupload-process"> </span>
|
||||
</div>
|
||||
<div class="col-lg-12 fileupload-progress fade" style="display:none">
|
||||
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
|
||||
<div class="progress-bar progress-bar-success" style="width:0%;"> </div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
if (!$field['setting']['option']['is_ext_tips']) {
|
||||
$str.= '<p class="finecms-file-ts">'.$ts.'</p>';
|
||||
}
|
||||
$str.= '
|
||||
<div class="scroller_'.$name.'_files">
|
||||
<div class="'.($field['setting']['option']['scroller'] ? 'scroller"' : '').'" data-inited="0" data-initialized="1" data-always-visible="1" data-rail-visible="1">
|
||||
'.$val.'
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
if (!$this->is_load_js('File')) {
|
||||
$str.= '
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/jquery-fileupload/css/jquery.fileupload.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/jquery-fileupload/js/jquery.fileupload.min.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
';
|
||||
$this->set_load_js('File', 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$str.= '<script type="text/javascript">
|
||||
var files_json_'.$name.' = '.$json.';
|
||||
$(function() {
|
||||
fileupload_files_init(files_json_'.$name.');
|
||||
'.($field['setting']['option']['scroller'] && dr_count($value)>10 ? '$(".scroller_'.$name.'_files .scroller").height("450");' : '').'
|
||||
});
|
||||
</script>
|
||||
|
||||
';
|
||||
|
||||
|
||||
// 输出最终表单显示
|
||||
return $this->input_format($name, $text, $str.$tips);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$html = '';
|
||||
$value = dr_get_files($value);
|
||||
if ($value) {
|
||||
|
||||
// 显示模板
|
||||
$tpl = '<tr class="template-download files_row">';
|
||||
$tpl.= '<td style="text-align:center;width:90px;border-top:0">';
|
||||
$tpl.= '<div class="files_row_preview preview">{preview}</div>';
|
||||
$tpl.= '</td>';
|
||||
$tpl.= '<td style="border-top:0">';
|
||||
$tpl.= '{title} {description}';
|
||||
$tpl.= '</td>';
|
||||
$tpl.= '</tr>';
|
||||
$html.= '<table role="presentation" class="table table-striped table-fc-upload clearfix">';
|
||||
$html.= '<tbody class="files">';
|
||||
foreach ($value as $i => $t) {
|
||||
$id = $t['id'] ? $t['id'] : $t['file'];
|
||||
$file = \Phpcmf\Service::C()->get_attachment($id, 1);
|
||||
$description = $t['description'] ? $t['description'] : '';
|
||||
if ($file) {
|
||||
$preview = dr_file_preview_html($file['url'], $file['id']);
|
||||
$filepath = $file['attachment'];
|
||||
$upload = '';
|
||||
} else {
|
||||
$filepath = $id;
|
||||
$preview = dr_file_preview_html($id);
|
||||
$upload = '';
|
||||
}
|
||||
$html.= str_replace(
|
||||
['{title}', '{description}', '{id}', '{filepath}', '{preview}', '{upload}'],
|
||||
[$t['title'], $description, $value, $filepath, $preview, $upload],
|
||||
$tpl
|
||||
);
|
||||
}
|
||||
$html.= '</tbody>';
|
||||
$html.= '</table>';
|
||||
}
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $html);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,614 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Ftable extends \Phpcmf\Library\A_Field {
|
||||
|
||||
protected $_load_date;
|
||||
protected $_load_datetime;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['TEXT' => ''];
|
||||
$this->defaulttype = 'TEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$html = '';
|
||||
$max = dr_count($option['field'])+5;
|
||||
for ($i = 1; $i <= $max; $i++) {
|
||||
$html.= '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('表格第%s列', $i).'</label>
|
||||
<div class="col-md-9">
|
||||
<label>'.$this->_field_type_select($i, $option['field'][$i]['type']).'</label>
|
||||
<label><input type="text" placeholder="'.dr_lang('列名称').'" class="form-control" size="20" value="'.$option['field'][$i]['name'].'" name="data[setting][option][field]['.$i.'][name]"></label>
|
||||
<label><input type="text" placeholder="'.dr_lang('列宽度').'" class="form-control" size="20" value="'.$option['field'][$i]['width'].'" name="data[setting][option][field]['.$i.'][width]"></label>
|
||||
<label id="dr_h_type_2"><input type="text" placeholder="'.dr_lang('选项配置').'" class="form-control input-xlarge" size="20" value="'.$option['field'][$i]['option'].'" name="data[setting][option][field]['.$i.'][option]">
|
||||
</label><label> <a href="javascript:dr_help(\'1234\');"><i class="fa fa-question-circle"></i></a>
|
||||
</label>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
$hang = '';
|
||||
$hs = (int)$option['count'];
|
||||
!$hs && $hs = 5;
|
||||
for ($i = 1; $i <= $hs; $i++) {
|
||||
$hang.= '<div class="form-group is_first_hang">
|
||||
<label class="col-md-2 control-label">'.dr_lang('表格第%s行', $i).'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" placeholder="'.dr_lang('行名称').'" class="form-control" size="20" value="'.$option['hang'][$i]['name'].'" name="data[setting][option][hang]['.$i.'][name]"></label>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
return [$this->_search_field().'
|
||||
<script>
|
||||
$(function() {
|
||||
dr_is_first_hang('.(int)$option['is_first_hang'].');
|
||||
dr_is_add_hang('.(int)$option['is_add'].');
|
||||
});
|
||||
function dr_is_first_hang(v) {
|
||||
if (v == 1) {
|
||||
$(".is_first_hang").show();
|
||||
} else {
|
||||
$(".is_first_hang").hide();
|
||||
}
|
||||
}
|
||||
function dr_is_add_hang(v) {
|
||||
if (v == 1) {
|
||||
$(".is_add_hang").hide();
|
||||
} else {
|
||||
$(".is_add_hang").show();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('无限添加行数').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" onclick="dr_is_add_hang(this.value)" name="data[setting][option][is_add]" value="1" '.($option['is_add'] ? 'checked' : '').'> '.dr_lang('开启').' <span></span></label>
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" onclick="dr_is_add_hang(this.value)" name="data[setting][option][is_add]" value="0" '.(!$option['is_add'] ? 'checked' : '').'> '.dr_lang('关闭').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('开启后可以在录入数据时自由添加行数,关闭时就只能是固定行数').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group is_add_hang">
|
||||
<label class="col-md-2 control-label">'.dr_lang('表格的首行').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" onclick="dr_is_first_hang(this.value)" name="data[setting][option][is_first_hang]" value="1" '.($option['is_first_hang'] ? 'checked' : '').'> '.dr_lang('显示').' <span></span></label>
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" onclick="dr_is_first_hang(this.value)" name="data[setting][option][is_first_hang]" value="0" '.(!$option['is_first_hang'] ? 'checked' : '').'> '.dr_lang('隐藏').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('首行表示每行的行名').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="is_add_hang">
|
||||
<div class="form-group ">
|
||||
<label class="col-md-2 control-label">'.dr_lang('表格行数').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][count]" value="'.$option['count'].'"></label>
|
||||
<span class="help-block">'.dr_lang('填写表格的行数,1表示只有一行表格,至少属于1行表格').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group is_first_hang">
|
||||
<label class="col-md-2 control-label">'.dr_lang('表格首行名').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][first_cname]" value="'.$option['first_cname'].'"></label>
|
||||
<span class="help-block">'.dr_lang('表格第一行的显示名称,不填写就不显示名称').'</span>
|
||||
</div>
|
||||
</div>'.$hang.'
|
||||
</div>'.$html.'
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label"></label>
|
||||
<div class="col-md-9">
|
||||
<p>'.dr_lang('列名称:是表格列的显示名称').'</p>
|
||||
<p>'.dr_lang('列宽度:是表格列的宽度,[整数]表示固定宽度;[整数%]表示百分比').'</p>
|
||||
<p>'.dr_lang('选择项:仅用于下拉选择框和复选框的选项,多个选项用半角,分开').'</p>
|
||||
<p>'.dr_lang('行名称:是表格每一行的显示名称,如果不填就按照默认行名称显示,如果默认行名称也没有填写就不显示行名').'</p>
|
||||
<span class="help-block"> <a href="javascript:dr_help(\'644\');"> '.dr_lang('了解此字段的使用方法').'</a> </span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
'.$this->attachment($option).'
|
||||
',
|
||||
'<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>'
|
||||
];
|
||||
}
|
||||
|
||||
// 属性类别
|
||||
protected function _field_type_select($id, $type) {
|
||||
|
||||
$arr = [
|
||||
0 => dr_lang('不使用'),
|
||||
1 => dr_lang('文本框'),
|
||||
2 => dr_lang('下拉框'),
|
||||
4 => dr_lang('复选框'),
|
||||
3 => dr_lang('文件'),
|
||||
5 => dr_lang('日期'),
|
||||
6 => dr_lang('日期时间'),
|
||||
7 => dr_lang('多行文本'),
|
||||
//8 => dr_lang('富文本框'), 实验失败
|
||||
];
|
||||
|
||||
$html = '<select class="form-control" name="data[setting][option][field]['.$id.'][type]">';
|
||||
foreach ($arr as $i => $name) {
|
||||
$html.= '<option '.($i == $type ? 'selected' : '').' value="'.$i.'">'.$name.'</option>';
|
||||
}
|
||||
$html.= '</select>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
// 对应的html
|
||||
protected function _field_type_html($config, $cname, $value, $hang, $lie, $field = []) {
|
||||
|
||||
$html = '';
|
||||
if ($config['type'] == 1) {
|
||||
$html.= '<input type="text" class="form-control" name="data['.$cname.']['.$hang.']['.$lie.']" value="'.htmlspecialchars((string)$value[$hang][$lie]).'">';
|
||||
} elseif ($config['type'] == 2) {
|
||||
$html = '<select class="form-control" name="data['.$cname.']['.$hang.']['.$lie.']">';
|
||||
$arr = explode(',', $config['option']);
|
||||
foreach ($arr as $name) {
|
||||
$html.= '<option '.($value[$hang][$lie] == $name ? 'selected' : '').' value="'.$name.'">'.$name.'</option>';
|
||||
}
|
||||
$html.= '</select>';
|
||||
} elseif ($config['type'] == 3) {
|
||||
// 文件
|
||||
$link = '';
|
||||
$preview = ROOT_THEME_PATH.'assets/images/ext/url.png';
|
||||
if ($value[$hang][$lie]) {
|
||||
$file = \Phpcmf\Service::C()->get_attachment((string)$value[$hang][$lie], 1);
|
||||
if ($file) {
|
||||
$link = $file['url'];
|
||||
if (dr_is_image($file['fileext'])) {
|
||||
$preview = $link;
|
||||
} elseif (is_file(ROOTPATH.'static/assets/images/ext/'.$file['fileext'].'.png')) {
|
||||
$preview = ROOT_THEME_PATH.'assets/images/ext/'.$file['fileext'].'.png';
|
||||
}
|
||||
} elseif (dr_is_image($value[$hang][$lie])) {
|
||||
$preview = $link = $value[$hang][$lie];
|
||||
}
|
||||
}
|
||||
if ($config['option'] && strpos((string)$config['option'], '-') !== false) {
|
||||
list($size, $exts) = explode('-', $config['option']);
|
||||
} else {
|
||||
$size = 10;
|
||||
$exts = $config['option'];
|
||||
}
|
||||
$url = '/'.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=input_file_list&token='.dr_get_csrf_token().'&siteid='.SITE_ID.'&p='.dr_authcode([
|
||||
'size' => $size ? $size : 10,
|
||||
'exts' => $exts ? $exts : 'jpg,gif,png,jpeg',
|
||||
'count' => 1,
|
||||
'attachment' => $field['setting']['option']['attachment'],
|
||||
'image_reduce' => $field['setting']['option']['image_reduce'],
|
||||
], 'ENCODE').'&ct=0&one=1';
|
||||
$html = '<label><input class="form-control2 form-control-file" type="hidden" name="data['.$cname.']['.$hang.']['.$lie.']" value="'.$value[$hang][$lie].'">';
|
||||
$html.= '<input class="form-control-link" type="hidden" value="'.$link.'">';
|
||||
$html.= '<input class="form-control-preview" type="hidden" value="'.$preview.'">';
|
||||
$html.= '<a href="javascript:;" onclick="dr_ftable_myfileinput(this, \''.$url.'\')" class="ftable-fileinput btn green btn-sm">'.dr_lang('上传').'</a>';
|
||||
$html.= '<a href="javascript:;" onclick="dr_ftable_myshow(this)" '.($value[$hang][$lie] ? '':'style="display:none"').' class="ftable-show btn blue btn-sm">'.dr_lang('预览').'</a>
|
||||
<a href="javascript:;" onclick="dr_ftable_mydelete(this)" '.($value[$hang][$lie] ? '':'style="display:none"').' class="ftable-delete btn red btn-sm">'.dr_lang('删除').'</a> ';
|
||||
$html.= '</label>';
|
||||
} elseif ($config['type'] == 5) {
|
||||
// 日期
|
||||
if ($config['option'] == 'SYS_TIME' && !$value[$hang][$lie]) {
|
||||
$value[$hang][$lie] = dr_date(SYS_TIME, 'Y-m-d');
|
||||
}
|
||||
$html.= '<div class="input-group date field_date_ftable_'.$cname.'">';
|
||||
$html.= '<input class="form-control" type="text" name="data['.$cname.']['.$hang.']['.$lie.']" value="'.$value[$hang][$lie].'">';
|
||||
$html.= '<span class="input-group-btn">
|
||||
<button class="btn date-set" type="button">
|
||||
<i class="fa fa-calendar"></i>
|
||||
</button>
|
||||
</span>';
|
||||
$html.= '</div>';
|
||||
$html.= '
|
||||
<script>
|
||||
$(function(){
|
||||
$(".field_date_ftable_'.$cname.'").datepicker({
|
||||
isRTL: false,
|
||||
format: "yyyy-mm-dd",
|
||||
showMeridian: true,
|
||||
autoclose: true,
|
||||
pickerPosition: "bottom-right",
|
||||
todayBtn: "linked"
|
||||
});
|
||||
});
|
||||
</script>
|
||||
';
|
||||
} elseif ($config['type'] == 6) {
|
||||
// 日期时间
|
||||
if ($config['option'] == 'SYS_TIME' && !$value[$hang][$lie]) {
|
||||
$value[$hang][$lie] = dr_date(SYS_TIME, 'Y-m-d H:i:s');
|
||||
}
|
||||
$html.= '<div class="input-group date field_datetime_ftable_'.$cname.'">';
|
||||
$html.= '<input class="form-control" type="text" name="data['.$cname.']['.$hang.']['.$lie.']" value="'.$value[$hang][$lie].'">';
|
||||
$html.= '<span class="input-group-btn">
|
||||
<button class="btn date-set" type="button">
|
||||
<i class="fa fa-calendar"></i>
|
||||
</button>
|
||||
</span>';
|
||||
$html.= '</div>';
|
||||
$html.= '
|
||||
<script>
|
||||
$(function(){
|
||||
$(".field_datetime_ftable_'.$cname.'").datetimepicker({
|
||||
isRTL: false,
|
||||
format: "yyyy-mm-dd hh:ii:ss",
|
||||
showMeridian: true,
|
||||
autoclose: true,
|
||||
pickerPosition: "bottom-right",
|
||||
todayBtn: "linked"
|
||||
});
|
||||
});
|
||||
</script>
|
||||
';
|
||||
} elseif ($config['type'] == 4) {
|
||||
$html = '<div class="table-scrollable" style="border: none; margin: 0!important"><div class="mt-checkbox-inline">';
|
||||
$arr = explode(',', $config['option']);
|
||||
foreach ($arr as $name) {
|
||||
$s = is_array($value[$hang][$lie]) && in_array($name, $value[$hang][$lie]) ? ' checked' : '';
|
||||
$kj = '<input type="checkbox" name="data['.$cname.']['.$hang.']['.$lie.'][]" value="'.$name.'" '.$s.' />';
|
||||
$html.= '<label class="mt-checkbox mt-checkbox-outline">'.$kj.' '.$name.' <span></span> </label>';
|
||||
}
|
||||
$html.= '</div></div>';
|
||||
} elseif ($config['type'] == 7) {
|
||||
$name = 'ftable_'.$cname.'_'.$hang.'_'.$lie;
|
||||
$html = '<textarea style="display:none" id="'.$name.'" name="data['.$cname.']['.$hang.']['.$lie.']">'.$value[$hang][$lie].'</textarea>';
|
||||
$html.= '<a href="javascript:;" onclick="dr_ftable_textareainput(\''.$name.'\')" class="ftable-fileinput btn green btn-sm">'.dr_lang('录入内容').'</a>';
|
||||
} elseif ($config['type'] == 8) {
|
||||
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字段显示
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_string2array($value);
|
||||
|
||||
$str = '<div class="table-scrollable">';
|
||||
$str.= dr_get_ftable($field['id'], $value);
|
||||
$str.= '</div>';
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return dr_string2array($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = dr_array2string(\Phpcmf\Service::L('Field')->post[$field['fieldname']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取附件id
|
||||
*/
|
||||
public function get_attach_id($value) {
|
||||
|
||||
if (!$this->field) {
|
||||
return NULL;
|
||||
} elseif (!isset($this->field['setting']['option']['field'])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$value = dr_string2array($value);
|
||||
|
||||
if ($value) {
|
||||
foreach ($value as $tt) {
|
||||
foreach ($this->field['setting']['option']['field'] as $lie => $t) {
|
||||
if ($t['type'] == 3 && isset($tt[$lie]) && $tt[$lie]) {
|
||||
$data[] = (int)$tt[$lie];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 附件处理
|
||||
*/
|
||||
public function attach($data, $_data) {
|
||||
|
||||
if (!$this->field) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$data = $this->get_attach_id($data);
|
||||
$_data = $this->get_attach_id($_data);
|
||||
|
||||
if (!isset($_data)) {
|
||||
$_data = [];
|
||||
}
|
||||
|
||||
if (!isset($data)) {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
// 新旧数据都无附件就跳出
|
||||
if (!$data && !$_data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 新旧数据都一样时表示没做改变就跳出
|
||||
if (dr_diff($data, $_data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 当无新数据且有旧数据表示删除旧附件
|
||||
if (!$data && $_data) {
|
||||
return [
|
||||
[],
|
||||
$_data
|
||||
];
|
||||
}
|
||||
|
||||
// 当无旧数据且有新数据表示增加新附件
|
||||
if ($data && !$_data) {
|
||||
return [
|
||||
$data,
|
||||
[]
|
||||
];
|
||||
}
|
||||
|
||||
// 剩下的情况就是删除旧文件增加新文件
|
||||
|
||||
// 新旧附件的交集,表示固定的
|
||||
$intersect = array_intersect($data, $_data);
|
||||
|
||||
return [
|
||||
array_diff($data, $intersect), // 固有的与新文件中的差集表示新增的附件
|
||||
array_diff($_data, $intersect), // 固有的与旧文件中的差集表示待删除的附件
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 表单宽度设置
|
||||
$width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'] : '100%');
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_string2array($value);
|
||||
|
||||
$this->_load_date = $this->_load_datetime = 0;
|
||||
|
||||
$str = '<div class="table-scrollable" style="width:'.$width.(is_numeric($width) ? 'px !important' : '').';">';
|
||||
$str.= '<table class="table fc-sku-table table-nomargin table-bordered table-striped table-bordered table-advance" >';
|
||||
$str.= ' <thead><tr>';
|
||||
if ($field['setting']['option']['is_first_hang'] && !$field['setting']['option']['is_add']) {
|
||||
$str.= ' <th> '.dr_lang($field['setting']['option']['first_cname']).' </th>';
|
||||
}
|
||||
if ($field['setting']['option']['field']) {
|
||||
foreach ($field['setting']['option']['field'] as $t) {
|
||||
if ($t['type']) {
|
||||
$style = $t['width'] ? 'style="width:'.$t['width'].(is_numeric($t['width']) ? 'px' : '').';"' : '';
|
||||
$str.= ' <th '.$style.'>'.dr_lang($t['name']).'</th>';
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($field['setting']['option']['is_add']) {
|
||||
$str.= ' <th width="70" style="text-align: center">';
|
||||
$str.= '<button type="button" class="btn blue btn-xs" onClick="dr_add_table_'.$name.'()"> <i class="fa fa-plus"></i> </button>';
|
||||
$str.'</th>';
|
||||
}
|
||||
$str.= ' </tr></thead>';
|
||||
$str.= ' <tbody id="dr_'.$name.'_body">';
|
||||
|
||||
if ($field['setting']['option']['is_add']) {
|
||||
// 支持添加列
|
||||
$tpl = ' <tr id="dr_ftable_'.$name.'_row_{hang}">';
|
||||
if ($field['setting']['option']['field']) {
|
||||
foreach ($field['setting']['option']['field'] as $n => $t) {
|
||||
if ($t['type']) {
|
||||
$tpl.= ' <td>'.$this->_field_type_html($t, $name, $value, '{hang}', $n, $field).'</td>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$tpl.= ' <td style="text-align: center"><button type="button" class="btn red btn-xs" onClick="dr_del_table_'.$name.'(this)"> <i class="fa fa-trash"></i> </button></td>';
|
||||
$tpl.= ' </tr>';
|
||||
$ksids = [];
|
||||
if ($value) {
|
||||
foreach ($value as $hang => $t) {
|
||||
$str.= ' <tr id="dr_ftable_'.$name.'_row_'.$hang.'">';
|
||||
if ($field['setting']['option']['field']) {
|
||||
foreach ($field['setting']['option']['field'] as $n => $t) {
|
||||
if ($t['type']) {
|
||||
$str.= ' <td>'.$this->_field_type_html($t, $name, $value, $hang, $n, $field).'</td>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$str.= ' <td style="text-align: center"><button type="button" class="btn red btn-xs" onClick="dr_del_table_'.$name.'(this)"> <i class="fa fa-trash"></i> </button></td>';
|
||||
$str.= ' </tr>';
|
||||
$ksids[] = $hang;
|
||||
}
|
||||
$ksid = is_array($ksids) && $ksids ? max($ksids) : 0; // 开始ID
|
||||
}
|
||||
} else {
|
||||
// 固定列
|
||||
for ($i = 1; $i <= (int)$field['setting']['option']['count']; $i++) {
|
||||
|
||||
$str.= ' <tr id="dr_ftable_'.$name.'_row_'.$i.'">';
|
||||
if ($field['setting']['option']['is_first_hang']) {
|
||||
$str.= ' <td> '.($field['setting']['option']['hang'][$i]['name'] ? $field['setting']['option']['hang'][$i]['name'] : '未命名').' </td>';
|
||||
}
|
||||
if ($field['setting']['option']['field']) {
|
||||
foreach ($field['setting']['option']['field'] as $n => $t) {
|
||||
if ($t['type']) {
|
||||
$str.= ' <td>'.$this->_field_type_html($t, $name, $value, $i, $n, $field).'</td>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$str.= ' </tr>';
|
||||
}
|
||||
}
|
||||
|
||||
$str.= ' </tbody>';
|
||||
$str.= '</table>';
|
||||
$str.= '</div>';
|
||||
|
||||
if (!$this->is_load_js('Date')) {
|
||||
$str.= '
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-daterangepicker/daterangepicker.min.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/moment.min.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.finecms.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.finecms.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
';
|
||||
$this->set_load_js('Date', 1);
|
||||
}
|
||||
if ($field['setting']['option']['is_add']) {
|
||||
$str.= '<script>
|
||||
var ks_'.$name.' = '.json_encode(['tpl' => $tpl, 'id' => $ksid]).';
|
||||
function dr_del_table_'.$name.'(e) {
|
||||
layer.confirm(\'确定删除本条数据吗?\', {
|
||||
shade: 0,
|
||||
title: \'提示\',
|
||||
}, function(index, layero){
|
||||
layer.close(index);
|
||||
$(e).parent().parent().remove();
|
||||
});
|
||||
}
|
||||
function dr_add_table_'.$name.'() {
|
||||
var tpl = ks_'.$name.'.tpl;
|
||||
ks_'.$name.'.id ++;
|
||||
tpl = tpl.replace(/\{hang\}/g, ks_'.$name.'.id);
|
||||
$(\'#dr_'.$name.'_body\').append(tpl);
|
||||
}
|
||||
</script>';
|
||||
}
|
||||
$str.= '<script> $("#dr_'.$name.'_body").sortable();';
|
||||
|
||||
|
||||
|
||||
$str.="
|
||||
$(\"#dr_".$name."_body\").sortable();
|
||||
</script>
|
||||
";
|
||||
|
||||
return $this->input_format($name, $text, $str.$tips);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示输出表格
|
||||
*/
|
||||
public function show_table($field, $value, $class = '') {
|
||||
|
||||
// class属性
|
||||
!$class && $class = 'table fc-sku-table table-nomargin table-bordered table-striped table-bordered table-advance';
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_string2array($value);
|
||||
// 表单宽度设置
|
||||
$width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'] : '100%');
|
||||
|
||||
$str = '<table id="dr_table_'.$field['fieldname'].'" class="'.$class.'" style="width:'.$width.(is_numeric($width) ? 'px' : '').';">';
|
||||
$str.= ' <thead><tr>';
|
||||
|
||||
if ($field['setting']['option']['is_first_hang'] && !$field['setting']['option']['is_add']) {
|
||||
$str .= ' <th> ' . dr_lang($field['setting']['option']['first_cname']) . ' </th>';
|
||||
}
|
||||
|
||||
if ($field['setting']['option']['field']) {
|
||||
foreach ($field['setting']['option']['field'] as $t) {
|
||||
if ($t['type']) {
|
||||
$style = $t['width'] ? 'style="width:'.$t['width'].(is_numeric($t['width']) ? 'px' : '').';"' : '';
|
||||
$str.= ' <th '.$style.'>'.dr_lang($t['name']).'</th>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$str.= ' </tr></thead>';
|
||||
$str.= ' <tbody>';
|
||||
|
||||
$i = 1;
|
||||
foreach ($value as $ii => $val) {
|
||||
|
||||
$str.= ' <tr>';
|
||||
if ($field['setting']['option']['is_first_hang'] && !$field['setting']['option']['is_add']) {
|
||||
$hname = $field['setting']['option']['hang'][$i]['name'] ? $field['setting']['option']['hang'][$i]['name'] : '未命名';
|
||||
$str .= ' <td> ' . $hname . ' </td>';
|
||||
}
|
||||
|
||||
if ($field['setting']['option']['field']) {
|
||||
foreach ($field['setting']['option']['field'] as $n => $t) {
|
||||
if ($t['type']) {
|
||||
$td = $val[$n];
|
||||
if ($td && $t['type'] == 3) {
|
||||
// 图片
|
||||
$td = '<img src="'.dr_get_file($td).'" class="ftable_img">';
|
||||
} elseif ($td && $t['type'] == 4) {
|
||||
// 复选
|
||||
$td = implode('、', $td);
|
||||
}
|
||||
$str.= ' <td>'.$td.'</td>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
$str.= ' </tr>';
|
||||
}
|
||||
|
||||
$str.= ' </tbody>';
|
||||
$str.= '</table>';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Group extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->close_xss = 1; // 关闭xss验证
|
||||
$this->is_validate = false; // 不允许字段验证
|
||||
$this->is_edit = false; // 不允许修改字段类别
|
||||
$this->fieldtype = ''; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... )
|
||||
$this->defaulttype = ''; // 当用户没有选择字段类型时的缺省值
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @param array $field 字段集合
|
||||
* @return string
|
||||
*/
|
||||
public function option($option, $field = NULL) {
|
||||
$group = [];
|
||||
$option['value'] = isset($option['value']) ? $option['value'] : '';
|
||||
if ($field) {
|
||||
foreach ($field as $t) {
|
||||
if ($t['fieldtype'] == 'Group') {
|
||||
$t['setting'] = dr_string2array($t['setting']);
|
||||
if (preg_match_all('/\{(.+)\}/U', $t['setting']['option']['value'], $value)) {
|
||||
foreach ($value[1] as $v) {
|
||||
$group[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$_field = [];
|
||||
$_field[] = '<option value=""> -- </option>';
|
||||
foreach ($field as $t) {
|
||||
$t['fieldtype'] != 'Group'
|
||||
&& !dr_in_array($t['fieldname'], $group)
|
||||
&& $_field[] = '<option value="'.$t['fieldname'].'">'.$t['name'].'</option>';
|
||||
}
|
||||
$_field = implode('', array_unique($_field));
|
||||
}
|
||||
|
||||
return [$this->_search_field().'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('可用字段').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><select class="form-control" name="xx" id="fxx">'.$_field.'</select></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('分组规则').'</label>
|
||||
<div class="col-md-9">
|
||||
<textarea name="data[setting][option][value]" id="fvalue" style="height:120px;" class="form-control">'.$option['value'].'</textarea>
|
||||
<span class="help-block">'.dr_lang('分组规则支持html标签,注意每个字段只能存在于一个分组中,否则会出错;此字段只能用于模块中').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$("#fxx").change(function(){
|
||||
var value = $(this).val();
|
||||
var fvalue = $("#fvalue").val();
|
||||
var text = $("#fxx").find("option:selected").text();
|
||||
$("#fxx option[value=\'"+value+"\']").remove();
|
||||
$("#fvalue").val(fvalue+" "+text+": {"+value+"}");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
'];
|
||||
}
|
||||
|
||||
/**
|
||||
* create_sql
|
||||
*/
|
||||
public function create_sql($name, $value, $cname = '') {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* alter_sql
|
||||
*/
|
||||
public function alter_sql($name, $value, $cname = '') {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* drop_sql
|
||||
*/
|
||||
public function drop_sql($name) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test
|
||||
*/
|
||||
public function test_sql($tables, $field) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 字段提示信息
|
||||
$tips = isset($field['setting']['validate']['tips']) && $field['setting']['validate']['tips'] ? '<div class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</div>' : '';
|
||||
|
||||
// 字段默认值
|
||||
$value = str_replace(['{', '}'], ['{|', '|}'], $field['setting']['option']['value']);
|
||||
|
||||
return $this->input_format($field['fieldname'], $text, $value.$tips);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,379 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Image extends \Phpcmf\Library\A_Field {
|
||||
|
||||
protected $img_ext;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->close_xss = 1; // 关闭xss验证
|
||||
$this->fieldtype = ['TEXT' => ''];
|
||||
$this->defaulttype = 'TEXT';
|
||||
$this->img_ext = 'jpg,gif,png,jpeg,svg,webp';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
|
||||
$mthumb = '';
|
||||
if (\Phpcmf\Service::M('field')->relatedname == 'module') {
|
||||
$mthumb = '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('首图作为缩略图').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][stslt]" '.($option['stslt'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('当缩略图字段为空时,用本字段的图片来填充(仅对模块字段有效)').'</span>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
return [$this->_search_field().$mthumb.'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('文件大小').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" value="'.$option['size'].'" name="data[setting][option][size]"></label>
|
||||
<span class="help-block">'.dr_lang('单位MB').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('上传数量').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" value="'.$option['count'].'" name="data[setting][option][count]"></label>
|
||||
<span class="help-block">'.dr_lang('每次最多上传的文件数量').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group hidden">
|
||||
<label class="col-md-2 control-label">'.dr_lang('扩展名').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="40" name="data[setting][option][ext]" value="'.$this->img_ext.'"></label>
|
||||
</div>
|
||||
</div>'.$this->attachment($option).'',
|
||||
|
||||
'<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div><div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('提示扩展名显示').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][option][is_ext_tips]" value="0" '.(!$option['is_ext_tips'] ? 'checked' : '').' /> '.dr_lang('已显示').' <span></span></label>
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][option][is_ext_tips]" value="1" '.($option['is_ext_tips'] ? 'checked' : '').' /> '.dr_lang('已关闭').' <span></span></label>
|
||||
</div><span class="help-block">'.dr_lang('提示字段上传的扩展名和大小限制的文本信息').'</span>
|
||||
</div>
|
||||
</div>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证字段属性
|
||||
*/
|
||||
public function edit_config($post) {
|
||||
|
||||
if (!isset($post['setting']['option']['size']) || !$post['setting']['option']['size']) {
|
||||
return dr_return_data(0, dr_lang('文件大小必须填写'));
|
||||
} elseif (!isset($post['setting']['option']['count']) || !$post['setting']['option']['count']) {
|
||||
return dr_return_data(0, dr_lang('上传数量必须填写'));
|
||||
}
|
||||
|
||||
return dr_return_data(1, 'ok');
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return dr_string2array($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取附件id
|
||||
*/
|
||||
public function get_attach_id($value) {
|
||||
return dr_string2array($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
$data = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
if ($data) {
|
||||
if ($field['setting']['option']['stslt']) {
|
||||
$_field = \Phpcmf\Service::L('form')->fields;
|
||||
if (isset($_field['thumb']) && $_field['thumb']['fieldtype'] == 'File' && !\Phpcmf\Service::L('Field')->data[$_field['thumb']['ismain']]['thumb']) {
|
||||
$one = array_key_first($data);
|
||||
if ($data[$one]) {
|
||||
\Phpcmf\Service::L('Field')->data[1]['thumb'] = $data[$one];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dr_count($data) > $field['setting']['option']['count']) {
|
||||
$data = array_slice($data, 0, $field['setting']['option']['count']-2);
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = dr_array2string($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 附件处理
|
||||
*/
|
||||
public function attach($data, $_data) {
|
||||
|
||||
$data = dr_string2array($data);
|
||||
$_data = dr_string2array($_data);
|
||||
|
||||
if (!isset($_data)) {
|
||||
$_data = [];
|
||||
}
|
||||
|
||||
if (!isset($data)) {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
// 新旧数据都无附件就跳出
|
||||
if (!$data && !$_data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 新旧数据都一样时表示没做改变就跳出
|
||||
if (dr_diff($data, $_data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 当无新数据且有旧数据表示删除旧附件
|
||||
if (!$data && $_data) {
|
||||
return [
|
||||
[],
|
||||
$_data
|
||||
];
|
||||
}
|
||||
|
||||
// 当无旧数据且有新数据表示增加新附件
|
||||
if ($data && !$_data) {
|
||||
return [
|
||||
$data,
|
||||
[]
|
||||
];
|
||||
}
|
||||
|
||||
// 剩下的情况就是删除旧文件增加新文件
|
||||
|
||||
// 新旧附件的交集,表示固定的
|
||||
$intersect = array_intersect($data, $_data);
|
||||
|
||||
return [
|
||||
array_diff($data, $intersect), // 固有的与新文件中的差集表示新增的附件
|
||||
array_diff($_data, $intersect), // 固有的与旧文件中的差集表示待删除的附件
|
||||
];
|
||||
}
|
||||
|
||||
protected function _format_file_size($fileSize, $round = 2) {
|
||||
|
||||
if (!$fileSize) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$inv = 1 / 1024;
|
||||
$unit = [' Bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB'];
|
||||
|
||||
while ($fileSize >= 1024 && $i < 8) {
|
||||
$fileSize *= $inv;
|
||||
++$i;
|
||||
}
|
||||
|
||||
$temp = sprintf("%.2f", $fileSize);
|
||||
$value = $temp - (int) $temp ? $temp : $fileSize;
|
||||
|
||||
return '<strong>'.round($value, $round).'</strong>' . $unit[$i];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '')
|
||||
{
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '') . dr_lang($field['name']);
|
||||
// 表单宽度设置
|
||||
$width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'] : '100%');
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_' . $field['fieldname'] . '_tips">' . $field['setting']['validate']['tips'] . '</span>' : '';
|
||||
|
||||
$size = ($field['setting']['option']['size']);
|
||||
!$size && $size = 0;
|
||||
$count = intval($field['setting']['option']['count']);
|
||||
|
||||
$p = dr_authcode([
|
||||
'size' => $size,
|
||||
'exts' => $this->img_ext,
|
||||
'attachment' => $field['setting']['option']['attachment'],
|
||||
'image_reduce' => $field['setting']['option']['image_reduce'],
|
||||
], 'ENCODE');
|
||||
$url = WEB_DIR.''.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&token='.dr_get_csrf_token().'&siteid=' . SITE_ID . '&m=upload&p=' . $p . '&fid=' . $field['id'];
|
||||
|
||||
// 显示模板
|
||||
$i = 0;
|
||||
$tpl = '';
|
||||
if ($value) {
|
||||
$value = dr_string2array($value);
|
||||
if ($value) {
|
||||
foreach ($value as $id) {
|
||||
$file = \Phpcmf\Service::C()->get_attachment($id, 1);
|
||||
if ($file) {
|
||||
$editname = '';
|
||||
if ($file['uid'] == \Phpcmf\Service::C()->uid || IS_ADMIN) {
|
||||
$editname = ' onclick="dr_iframe(\''.dr_lang('修改名称').'\', \''.dr_web_prefix((IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=name_edit&id='.$file['id']).'\', \'350px\', \'220px\');" title="'.dr_lang('修改名称').'"';
|
||||
}
|
||||
$tpl.= '<div id="image-'.$name.'-'.$id.'" class="dz-preview dz-processing dz-success dz-complete dz-image-preview">';
|
||||
$tpl.= '<div class="dz-image">';
|
||||
$tpl.= ' <img data-dz-thumbnail="" src="'.dr_get_file($id).'">';
|
||||
$tpl.= '</div>';
|
||||
|
||||
$tpl.= ' <div class="dz-details"><div class="dz-size" onclick="dr_preview_image(\''.$file['url'].'\');" title="'.dr_lang('放大图片').'"><span data-dz-size="">'.$this->_format_file_size($file['filesize']).'</span></div><div class="dz-filename" '.$editname.'><span data-dz-name="">'.$file['filename'].'</span></div></div>';
|
||||
|
||||
$tpl.= '<a class="dz-remove" href="javascript:dr_delete_image_'.$name.'('.$id.');" title="'.dr_lang('删除图片').'">';
|
||||
$tpl.= ' <i class="fa fa-times-circle"></i>';
|
||||
$tpl.= ' </a>';
|
||||
$tpl.= '<input class="dr_dropzone_'.$name.'" type="hidden" name="data['.$name.'][]" value="'.$id.'" />';
|
||||
$tpl.= '</div>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$tpl.= '<input class="dr_dropzone_'.$name.'_total" type="hidden" value="'.$i.'" />';
|
||||
$ts = dr_lang('每张图片最大%s,最多上传%s张图片', $size . 'MB', intval($field['setting']['option']['count']));
|
||||
|
||||
// 表单输出
|
||||
$str = '<div class="dropzone2 dropzone-file-area dropzone-images-area" id="my-dropzone-'.$name.'" style="width:'.$width.(is_numeric($width) ? 'px' : '').';">
|
||||
</div>
|
||||
';
|
||||
if (!$field['setting']['option']['is_ext_tips']) {
|
||||
$str.= '<div class="finecms-file-ts">'.$ts.'</div>';
|
||||
}
|
||||
|
||||
if (!$this->is_load_js($field['fieldtype'])) {
|
||||
$str.= '
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/dropzone/dropzone.min.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/dropzone/dropzone.min.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
';
|
||||
$this->set_load_js($field['fieldtype'], 1);
|
||||
}
|
||||
|
||||
$js = \Phpcmf\Service::L('js_packer');
|
||||
$str.= $js->pack('
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
$(function() {
|
||||
$("#my-dropzone-'.$name.'").sortable();
|
||||
Dropzone.autoDiscover = false;
|
||||
$("#my-dropzone-'.$name.'").dropzone({
|
||||
addRemoveLinks:true,
|
||||
maxFiles:99999,
|
||||
maxFilesize: '.$size.',
|
||||
acceptedFiles: "image/*",
|
||||
dictMaxFilesExceeded: "'.dr_lang("最多只能上传%s张图片", $count).(CI_DEBUG ? '(可在自定义字段中设置本字段的个数值)' : '').'",
|
||||
dictResponseError: \'文件上传失败\',
|
||||
dictInvalidFileType: "不能上传该类型文件",
|
||||
dictFallbackMessage:"浏览器不受支持",
|
||||
dictFileTooBig:"文件过大上传文件最大支持",
|
||||
url: "'.$url.'",
|
||||
init: function() {
|
||||
this.on("addedfile", function(file) {
|
||||
var activeFiles = this.getActiveFiles();
|
||||
var num = parseInt($(".dr_dropzone_'.$name.'_total").val());
|
||||
if (num+activeFiles.length+1 > '.$count.') {
|
||||
this.options.maxFiles = -1;
|
||||
}
|
||||
});
|
||||
this.on("success", function(file, res) {
|
||||
var rt = JSON.parse(res);
|
||||
if(rt.code){
|
||||
var num = parseInt($(".dr_dropzone_'.$name.'_total").val());
|
||||
$(".dr_dropzone_'.$name.'_total").val(num+1);
|
||||
var input = \'<input class="dr_dropzone_'.$name.'" type="hidden" name="data['.$name.'][]" value="\'+rt.id+\'" />\';
|
||||
$(file.previewElement).append(input);
|
||||
}else{
|
||||
dr_tips(0, rt.msg);
|
||||
file.previewElement.classList.remove("dz-success");
|
||||
file.previewElement.classList.add("dz-error");
|
||||
file.previewElement.classList.add("dz-error");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
$("#my-dropzone-'.$name.'").append("'.addslashes($tpl).'");
|
||||
});
|
||||
function dr_delete_image_'.$name.'(e) {
|
||||
var num = parseInt($(".dr_dropzone_'.$name.'_total").val());
|
||||
$(".dr_dropzone_'.$name.'_total").val(num-1);
|
||||
$("#image-'.$name.'-"+e).remove();
|
||||
}
|
||||
</script>
|
||||
|
||||
', 0);
|
||||
|
||||
// 输出最终表单显示
|
||||
return $this->input_format($name, $text, $str.$tips);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$html = '';
|
||||
$value = dr_string2array($value);
|
||||
if ($value) {
|
||||
$html.= '<div class="row">';
|
||||
foreach ($value as $id) {
|
||||
$html.= '<div class="col-sm-3 col-md-2">';
|
||||
$html.= '<a href="javascript:dr_preview_image(\''.dr_get_file($id).'\');" class="thumbnail">';
|
||||
$html.= '<img src="'.dr_get_file($id).'" style="width:100%">';
|
||||
$html.= '</a>';
|
||||
$html.= '</div>';
|
||||
}
|
||||
$html.= '</div>';
|
||||
}
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $html);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,366 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
class Join extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['TEXT' => '']; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... )
|
||||
$this->defaulttype = 'TEXT'; // 当用户没有选择字段类型时的缺省值
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
if ($option['field']) {
|
||||
foreach ($option['field'] as $k => $v) {
|
||||
if (!$v['field']) {
|
||||
unset($option['field'][$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$max = dr_count($option['field'])+2;
|
||||
for ($i = 1; $i <= $max; $i++) {
|
||||
$html.= '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('表格第%s列', $i).'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" placeholder="'.dr_lang('字段名').'" class="form-control" size="20" value="'.$option['field'][$i]['field'].'" name="data[setting][option][field]['.$i.'][field]"></label>
|
||||
<label><input type="text" placeholder="'.dr_lang('显示名').'" class="form-control" size="20" value="'.$option['field'][$i]['name'].'" name="data[setting][option][field]['.$i.'][name]"></label>
|
||||
<label><input type="text" placeholder="'.dr_lang('宽度').'" class="form-control" size="20" value="'.$option['field'][$i]['width'].'" name="data[setting][option][field]['.$i.'][width]"></label>
|
||||
</label>
|
||||
<label><input type="text" placeholder="'.dr_lang('回调函数').'" class="form-control" size="20" value="'.$option['field'][$i]['func'].'" name="data[setting][option][field]['.$i.'][func]"></label>
|
||||
</label>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
return [$this->_search_field().'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('关联表').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" name="data[setting][option][table]" value="'.$option['table'].'"></label>
|
||||
<span class="help-block">'.dr_lang('输入表名称,不带表前缀,如:article').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('最大选择数').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" name="data[setting][option][limit]" value="'.$option['limit'].'"></label>
|
||||
<span class="help-block">'.dr_lang('最大能选择的数量限制').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('每页显示条数').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" name="data[setting][option][pagesize]" value="'.$option['pagesize'].'"></label>
|
||||
<span class="help-block">'.dr_lang('选择列表分页条数,按多少条数据分页').'</span>
|
||||
</div>
|
||||
</div>'.$html.''];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
$data = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
$limit = intval($field['setting']['option']['limit']);
|
||||
if ($limit && $data && count($data) > $limit) {
|
||||
// 超限了
|
||||
$value = implode(',', dr_arraycut($data, $limit));
|
||||
} else {
|
||||
$value = !$data ? '' : implode(',', $data);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $cname 字段别名
|
||||
* @param string $name 字段名称
|
||||
* @param array $cfg 字段配置
|
||||
* @param string $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
|
||||
$is_show = 0;
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
// 字段提示信息
|
||||
$tips = isset($field['setting']['validate']['tips']) && $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$name.'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
// 区域大小
|
||||
$area = \Phpcmf\Service::IS_MOBILE_USER() ? '["95%", "90%"]' : '["50%", "65%"]';
|
||||
// 关联表名称
|
||||
$table = isset($field['setting']['option']['table']) ? $field['setting']['option']['table'] : '';
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
// 选择数量限制
|
||||
$limit = intval($field['setting']['option']['limit']);
|
||||
!$limit && $limit = 99999;
|
||||
|
||||
if (!$table) {
|
||||
if (CI_DEBUG) {
|
||||
return $this->input_format($name, $text, '<div class="form-control-static" style="color:red">关联字段没有设置关联表名称</div>');
|
||||
}
|
||||
return $this->input_format($name, $text, '');
|
||||
} elseif (!\Phpcmf\Service::M()->is_table_exists($table)) {
|
||||
if (CI_DEBUG) {
|
||||
return $this->input_format($name, $text, '<div class="form-control-static" style="color:red">关联字段设置的表【'.$table.'】不存在</div>');
|
||||
}
|
||||
return $this->input_format($name, $text, '');
|
||||
}
|
||||
|
||||
$value = $value ? trim($value, ',') : '';
|
||||
$mylist = [];
|
||||
if ($value && is_string($value)) {
|
||||
$arr = explode(',', $value);
|
||||
if ($arr) {
|
||||
$value = '';
|
||||
foreach ($arr as $a) {
|
||||
$a = intval($a);
|
||||
if ($a) {
|
||||
$value.= ','.$a;
|
||||
}
|
||||
}
|
||||
if ($value) {
|
||||
$value = trim($value, ',');
|
||||
$ids = array_values(array_filter(array_map('intval', explode(',', $value))));
|
||||
$mylist = [];
|
||||
if ($ids) {
|
||||
$rows = \Phpcmf\Service::M()->db->table($table)->whereIn('id', $ids)->get();
|
||||
$rows = $rows ? $rows->getResultArray() : [];
|
||||
$map = [];
|
||||
foreach ($rows as $r) {
|
||||
$map[(int) $r['id']] = $r;
|
||||
}
|
||||
foreach ($ids as $id) {
|
||||
if (isset($map[$id])) {
|
||||
$mylist[] = $map[$id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = is_file(MYPATH.'View/api_join_field_'.$field['fieldname'].'.html') ? MYPATH.'View/api_join_field_'.$field['fieldname'].'.html' : COREPATH.'View/api_join_field.html';
|
||||
if (!is_file($tpl)) {
|
||||
if (CI_DEBUG) {
|
||||
return $this->input_format($name, $text, '<div class="form-control-static" style="color:red">模板文件【'.$tpl.'】不存在</div>');
|
||||
}
|
||||
return $this->input_format($name, $text, '');
|
||||
}
|
||||
$code = file_get_contents($tpl);
|
||||
if (!$code) {
|
||||
if (CI_DEBUG) {
|
||||
return $this->input_format($name, $text, '<div class="form-control-static" style="color:red">模板文件【'.$tpl.'】内容为空</div>');
|
||||
}
|
||||
return $this->input_format($name, $text, '');
|
||||
}
|
||||
$file = \Phpcmf\Service::V()->code2php($code);
|
||||
ob_start();
|
||||
require $file;
|
||||
$str = ob_get_clean();
|
||||
|
||||
$str.= $tips;
|
||||
$js = \Phpcmf\Service::L('js_packer');
|
||||
$str.= $js->pack('
|
||||
<script type="text/javascript">
|
||||
var dr_join_'.$name.'_btn = null;
|
||||
function dr_join_body_'.$name.'(btn) {
|
||||
var $box = btn ? $(btn).closest(".scroller_'.$name.'_files") : $(".scroller_'.$name.'_files").first();
|
||||
return $box.find("tbody.scroller_body").first();
|
||||
}
|
||||
function dr_join_len_'.$name.'(btn) {
|
||||
var n = 0, seen = {}, $body = dr_join_body_'.$name.'(btn || dr_join_'.$name.'_btn);
|
||||
$body.children("tr").each(function(){
|
||||
var id = $(this).attr("id");
|
||||
if (id && id.indexOf("dr_items_'.$name.'_") === 0 && !seen[id]) {
|
||||
seen[id] = 1;
|
||||
n++;
|
||||
}
|
||||
});
|
||||
return n;
|
||||
}
|
||||
function dr_join_sortable_'.$name.'(btn) {
|
||||
var $body = dr_join_body_'.$name.'(btn);
|
||||
if ($body.data("ui-sortable")) {
|
||||
return;
|
||||
}
|
||||
$body.sortable({
|
||||
items: "> tr",
|
||||
axis: "y",
|
||||
containment: "parent",
|
||||
helper: function(e, tr) {
|
||||
var $originals = tr.children();
|
||||
var $helper = tr.clone();
|
||||
$helper.children().each(function(index) {
|
||||
$(this).width($originals.eq(index).width());
|
||||
});
|
||||
return $helper;
|
||||
}
|
||||
});
|
||||
}
|
||||
dr_slimScroll_init(".scroller_'.$name.'_files", 300);
|
||||
dr_join_sortable_'.$name.'($(".scroller_'.$name.'_files").first());
|
||||
function dr_add_join_'.$name.'(btn) {
|
||||
dr_join_'.$name.'_btn = btn;
|
||||
var len = dr_join_len_'.$name.'(btn);
|
||||
if (len >= '.$limit.') {
|
||||
dr_tips(0, "'.dr_lang('关联数量不得超过%s个', $limit).'");
|
||||
return;
|
||||
}
|
||||
var url = "'.dr_web_prefix('index.php?s=api&c=api&m=join&fid=').$field['id'].'&is_iframe=1";
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: \'<i class="fa fa-cog"></i> '.dr_lang($field['name']).'\',
|
||||
fix:true,
|
||||
shadeClose: true,
|
||||
shade: 0,
|
||||
area: '.$area.',
|
||||
btn: ["'.dr_lang('关联').'"],
|
||||
success: function (json) {
|
||||
if (json.code == 0) {
|
||||
layer.close();
|
||||
dr_tips(json.code, json.msg);
|
||||
}
|
||||
},
|
||||
yes: function(index, layero){
|
||||
var body = layer.getChildFrame(\'body\', index);
|
||||
var $joinBody = dr_join_body_'.$name.'(dr_join_'.$name.'_btn);
|
||||
// 延迟加载
|
||||
var loading = layer.load(2, {
|
||||
time: 10000
|
||||
});
|
||||
$.ajax({type: "POST",dataType:"json", url: url, data: $(body).find(\'#myform\').serialize(),
|
||||
success: function(json) {
|
||||
layer.close(loading);
|
||||
if (json.code == 1) {
|
||||
layer.close(index);
|
||||
var len = dr_join_len_'.$name.'(dr_join_'.$name.'_btn);
|
||||
if (len + json.data.ids.length > '.$limit.') {
|
||||
dr_tips(0, "'.dr_lang('关联数量超限').'");
|
||||
return;
|
||||
}
|
||||
for(var i in json.data.ids){
|
||||
var vid = json.data.ids[i];
|
||||
if (typeof vid != "undefined") {
|
||||
if($joinBody.find("#dr_items_'.$name.'_"+vid).length>0) {
|
||||
dr_tips(0, "'.dr_lang('已经存在').'");
|
||||
return;
|
||||
}
|
||||
if (dr_join_len_'.$name.'(dr_join_'.$name.'_btn) >= '.$limit.') {
|
||||
dr_tips(0, "'.dr_lang('关联数量超限').'");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$joinBody.append(json.data.html);
|
||||
dr_slimScroll_init(".scroller_'.$name.'_files", 300);
|
||||
dr_tips(1, json.msg);
|
||||
} else {
|
||||
dr_tips(0, json.msg);
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
content: url
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
</script>', 0);
|
||||
|
||||
return $this->input_format($name, $text, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$cname = ($field['setting']['option']['title'] ? $field['setting']['option']['title'] : dr_lang('主题'));
|
||||
$value = @trim($value, ',');
|
||||
$mylist = [];
|
||||
$is_show = 1;
|
||||
$table = isset($field['setting']['option']['table']) ? $field['setting']['option']['table'] : '';
|
||||
if ($value && is_string($value) && $table) {
|
||||
$arr = explode(',', $value);
|
||||
if ($arr) {
|
||||
$value = '';
|
||||
foreach ($arr as $a) {
|
||||
$a = intval($a);
|
||||
if ($a) {
|
||||
$value.= ','.$a;
|
||||
}
|
||||
}
|
||||
if ($value) {
|
||||
$value = trim($value, ',');
|
||||
$ids = array_values(array_filter(array_map('intval', explode(',', $value))));
|
||||
$mylist = [];
|
||||
if ($ids) {
|
||||
$rows = \Phpcmf\Service::M()->db->table($table)->whereIn('id', $ids)->get();
|
||||
$rows = $rows ? $rows->getResultArray() : [];
|
||||
$map = [];
|
||||
foreach ($rows as $r) {
|
||||
$map[(int) $r['id']] = $r;
|
||||
}
|
||||
foreach ($ids as $id) {
|
||||
if (isset($map[$id])) {
|
||||
$mylist[] = $map[$id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = $field['fieldname'];
|
||||
$file = \Phpcmf\Service::V()->code2php(
|
||||
file_get_contents(is_file(MYPATH.'View/api_join_field_'.$tpl.'.html') ? MYPATH.'View/api_join_field_'.$tpl.'.html' : COREPATH.'View/api_join_field.html')
|
||||
);
|
||||
ob_start();
|
||||
require $file;
|
||||
$str = ob_get_clean();
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Linkage extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['mediumint' => 8];
|
||||
$this->defaulttype = 'mediumint';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$str = '<select class="form-control" name="data[setting][option][linkage]">';
|
||||
$data = \Phpcmf\Service::M()->table('linkage')->getAll();
|
||||
if ($data) {
|
||||
$linkage = isset($option['linkage']) ? $option['linkage'] : '';
|
||||
foreach ($data as $t) {
|
||||
$str.= '<option value="'.$t['code'].'" '.($linkage == $t['code'] ? 'selected' : '').'> '.$t['name'].'('.$t['code'].') </option>';
|
||||
}
|
||||
}
|
||||
$str.= '</select>';
|
||||
|
||||
$str2 = '<select class="form-control" name="data[setting][option][file]"><option value=""> -- </option>';
|
||||
$files = dr_file_map(CONFIGPATH.'mylinkage/', 1);
|
||||
$files2 = dr_file_map(dr_get_app_dir($this->app).'Config/mylinkage/', 1);
|
||||
$files2 && $files = dr_array2array($files2, $files);
|
||||
if ($files) {
|
||||
foreach ($files as $t) {
|
||||
$t && strpos($t, '.php') !== 0 && $str2.= '<option value="'.$t.'" '.($option['file'] == $t ? 'selected' : '').'> '.$t.' </option>';
|
||||
}
|
||||
}
|
||||
$str2.= '</select>';
|
||||
|
||||
return ['<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('选择菜单').'</label>
|
||||
<div class="col-md-9"><label>'.$str.'</label></div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('强制选择最终项').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][ck_child]" '.($option['ck_child'] == 1 ? 'checked' : '').' > '.dr_lang('开启').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][ck_child]" '.($option['ck_child'] == 0 ? 'checked' : '').' > '.dr_lang('关闭').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('开启后会强制要求用户选择最终一个选项,需要启用必须验证才会生效').'</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('输入框显示方式').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][new]" '.($option['new'] == 1 ? 'checked' : '').' > '.dr_lang('折叠弹窗模式').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][new]" '.($option['new'] == 0 ? 'checked' : '').' > '.dr_lang('经典模式').' <span></span></label>
|
||||
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('针对输入框效果的显示方式').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认选择值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
', ''];
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建sql语句
|
||||
*/
|
||||
public function create_sql($name, $option, $cname = '') {
|
||||
// 联动菜单 ID:mediumint(8) UNSIGNED
|
||||
$type = 'mediumint(8)';
|
||||
$info = 'UNSIGNED NULL';
|
||||
$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 $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = (int)\Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证字段值
|
||||
*
|
||||
* @param string $field 字段类型
|
||||
* @param string $value 字段值
|
||||
* @return
|
||||
*/
|
||||
public function check_value($field, $value) {
|
||||
|
||||
$value = intval($value);
|
||||
if ($value) {
|
||||
$link = dr_linkage($field['setting']['option']['linkage'], $value);
|
||||
if (!$link) {
|
||||
return dr_lang('选项无效');
|
||||
} elseif ($field['setting']['option']['ck_child'] && $link['child']) {
|
||||
return dr_lang('需要选择下级选项');
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证必填字段值
|
||||
*
|
||||
* @param string $field 字段类型
|
||||
* @param string $value 字段值
|
||||
* @return
|
||||
*/
|
||||
public function check_required($field, $value) {
|
||||
|
||||
$value = intval($value);
|
||||
if (!$value) {
|
||||
// 验证值为空
|
||||
return dr_lang('%s不能为空', $field['name']);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 字段默认值
|
||||
$value = $value ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
|
||||
if ($field['setting']['option']['new']) {
|
||||
// 开始输出
|
||||
$str = '';
|
||||
if (!$this->is_load_js($field['fieldtype'])) {
|
||||
$str.= '
|
||||
<link rel="stylesheet" type="text/css" href="'.ROOT_THEME_PATH.'assets/layui/css/layui.css?v='.CMF_UPDATE_TIME.'"/>
|
||||
<link rel="stylesheet" type="text/css" href="'.ROOT_THEME_PATH.'assets/layui/cascader/cascader.css?v='.CMF_UPDATE_TIME.'"/>
|
||||
<script src="'.ROOT_THEME_PATH.'assets/layui/layui.js?v='.CMF_UPDATE_TIME.'"></script>
|
||||
<script src="'.ROOT_THEME_PATH.'assets/layui/cascader/cascader'.(IS_XRDEV ? '' : '.min').'.js?v='.CMF_UPDATE_TIME.'"></script>
|
||||
';
|
||||
$this->set_load_js($field['fieldtype'], 1);
|
||||
}
|
||||
|
||||
// 输出js支持
|
||||
$str.= '<input type="hidden" name="data['.$name.']" id="dr_'.$name.'" value="'.(int)$value.'" />
|
||||
<script src="'.WEB_DIR.'index.php?s=api&c=api&m=linkage&mid='.APP_DIR.'&file='.$field['setting']['option']['file'].'&code='.$field['setting']['option']['linkage'].'"></script>
|
||||
<script type="text/javascript">
|
||||
$(function (){
|
||||
layui.use(\'layCascader\', function () {
|
||||
var layCascader = layui.layCascader;
|
||||
layCascader({
|
||||
elem: \'#dr_'.$name.'\',
|
||||
value: \''.(int)$value.'\',
|
||||
clearable: true,
|
||||
filterable: true,
|
||||
options: linkage_'.$field['setting']['option']['linkage'].',
|
||||
props: {
|
||||
checkStrictly: '.($field['setting']['option']['ck_child'] ? 'false' : 'true').',
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
</script>'.$tips;
|
||||
} else {
|
||||
// 联动菜单缓存
|
||||
$linkage = dr_linkage_list($field['setting']['option']['linkage'], 0);
|
||||
if (!$linkage) {
|
||||
if (CI_DEBUG) {
|
||||
return $this->input_format($name, $text, '<div class="form-control-static" style="color:red">联动菜单【'.$field['setting']['option']['linkage'].'】没有数据</div>');
|
||||
}
|
||||
return $this->input_format($name, $text, '');
|
||||
}
|
||||
|
||||
// 最大几层
|
||||
$linklevel = dr_linkage_level($field['setting']['option']['linkage']) + 1;
|
||||
|
||||
// 开始输出
|
||||
$str = '<input type="hidden" name="data['.$name.']" id="dr_'.$name.'" value="'.(int)$value.'">';
|
||||
if (!$this->is_load_js($field['fieldtype'].'_LD')) {
|
||||
$str.= '<script type="text/javascript" src="'.ROOT_THEME_PATH.'assets/js/jquery.ld.js?v='.CMF_UPDATE_TIME.'"></script>';
|
||||
$this->set_load_js($field['fieldtype'].'_LD', 1);
|
||||
}
|
||||
$level = 1;
|
||||
$default = '';
|
||||
if ($value) {
|
||||
$link = dr_linkage($field['setting']['option']['linkage'], $value);
|
||||
if ($link) {
|
||||
$pids = substr($link['pids'], 2);
|
||||
$level = substr_count($pids, ',') + 1;
|
||||
$default = !$pids ? '["'.$value.'"]' : '["'.str_replace(',', '","', $pids).'","'.$value.'"]';
|
||||
}
|
||||
}
|
||||
// 输出默认菜单
|
||||
$str.= '<span id="dr_linkage_'.$name.'_select" style="'.($value ? 'display:none' : '').'">';
|
||||
for ($i = 1; $i <= $linklevel; $i++) {
|
||||
$style = $i > $level ? 'style="display:none"' : '';
|
||||
$str.= '<label style="padding-right:10px;"><select class="form-control finecms-select-'.$name.'" name="'.$name.'-'.$i.'" id="'.$name.'-'.$i.'" width="100" '.$style.'><option value=""> -- </option></select></label>';
|
||||
}
|
||||
$str.= '<label id="dr_linkage_'.$name.'_html"></label>';
|
||||
$str.= '</span>';
|
||||
// 重新选择
|
||||
if ($value) {
|
||||
$str.= '<div id="dr_linkage_'.$name.'_cxselect">';
|
||||
$edit_html = '<div class="form-control-static" >'.dr_linkagepos($field['setting']['option']['linkage'], $value, ' » ').' <a href="javascript:;" onclick="dr_linkage_select_'.$name.'()" style="color:blue">'.dr_lang('[重新选择]').'</a></div>';
|
||||
if ($field['setting']['option']['file']) {
|
||||
$data = dr_linkage($field['setting']['option']['linkage'], $value);
|
||||
$file = CONFIGPATH.'mylinkage/'.$field['setting']['option']['file'];
|
||||
$file2 = dr_get_app_dir(APP_DIR).'Config/mylinkage/'.$field['setting']['option']['file'];
|
||||
if (is_file($file)) {
|
||||
require $file;
|
||||
} elseif (is_file($file2)) {
|
||||
require $file2;
|
||||
} else {
|
||||
log_message('error', '联动菜单自定义程序文件【'.$field['setting']['option']['file'].'】不存在');
|
||||
if (CI_DEBUG) {
|
||||
$edit_html.= '联动菜单自定义程序文件【'.$field['setting']['option']['file'].'】不存在';
|
||||
}
|
||||
}
|
||||
}
|
||||
$str.= $edit_html;
|
||||
$str.= '</div>';
|
||||
}
|
||||
// 输出js支持
|
||||
$str.= '
|
||||
<script type="text/javascript">
|
||||
function dr_linkage_select_'.$name.'() {
|
||||
$("#dr_linkage_'.$name.'_select").show();
|
||||
$("#dr_linkage_'.$name.'_cxselect").hide();
|
||||
}
|
||||
$(function(){
|
||||
var $ld5 = $(".finecms-select-'.$name.'");
|
||||
$ld5.ld({ajaxOptions:{"url": "'.WEB_DIR.'index.php?s=api&c=api&m=linkage_ld&mid='.APP_DIR.'&file='.$field['setting']['option']['file'].'&code='.$field['setting']['option']['linkage'].'"},inputId:"dr_linkage_'.$name.'_html",defaultParentId:0});
|
||||
var ld5_api = $ld5.ld("api");
|
||||
ld5_api.selected('.$default.');
|
||||
$ld5.bind("change", function(e){
|
||||
var $target = $(e.target);
|
||||
var index = $ld5.index($target);
|
||||
//$("#'.$name.'-'.$i.'").remove();
|
||||
var vv = $ld5.eq(index).show().val();
|
||||
$("#dr_'.$name.'").val(vv);
|
||||
index ++;
|
||||
$ld5.eq(index).show();
|
||||
//console.log("value="+vv);
|
||||
});
|
||||
})
|
||||
</script>'.$tips;
|
||||
}
|
||||
|
||||
|
||||
return $this->input_format($name, $text, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], '<div class="form-control-static">'.dr_linkagepos($field['setting']['option']['linkage'], $value, ' - ').'</div>');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Linkages extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['TEXT' => ''];
|
||||
$this->defaulttype = 'TEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$str = '<select class="form-control" name="data[setting][option][linkage]">';
|
||||
$data = \Phpcmf\Service::M()->table('linkage')->getAll();
|
||||
if ($data) {
|
||||
$linkage = isset($option['linkage']) ? $option['linkage'] : '';
|
||||
foreach ($data as $t) {
|
||||
$str.= '<option value="'.$t['code'].'" '.($linkage == $t['code'] ? 'selected' : '').'> '.$t['name'].'('.$t['code'].') </option>';
|
||||
}
|
||||
}
|
||||
$str.= '</select>';
|
||||
|
||||
return [$this->_search_field().'<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('选择菜单').'</label>
|
||||
<div class="col-md-9"><label>'.$str.'</label></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('最大选择数').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][limit]" value="'.$option['limit'].'"></label>
|
||||
<span class="help-block">'.dr_lang('最大能选择的数量限制').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('强制选择最终项').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][ck_child]" '.($option['ck_child'] == 1 ? 'checked' : '').' > '.dr_lang('开启').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][ck_child]" '.($option['ck_child'] == 0 ? 'checked' : '').' > '.dr_lang('关闭').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('开启后会强制要求用户选择最终一个选项,需要启用必须验证才会生效').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('折叠显示到一行').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][collapse]" '.($option['collapse'] == 0 ? 'checked' : '').' > '.dr_lang('开启').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][collapse]" '.($option['collapse'] == 1 ? 'checked' : '').' > '.dr_lang('关闭').' <span></span></label>
|
||||
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('多选模式下是否折叠显示选择值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('输入框显示方式').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][new]" '.($option['new'] == 1 ? 'checked' : '').' > '.dr_lang('折叠弹窗模式').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][new]" '.($option['new'] == 0 ? 'checked' : '').' > '.dr_lang('经典模式').' <span></span></label>
|
||||
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('针对输入框效果的显示方式').'</span>
|
||||
</div>
|
||||
</div>
|
||||
', '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return dr_string2array($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
$save = [];
|
||||
$data = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
if ($data) {
|
||||
$data = dr_string2array($data);
|
||||
if ($data) {
|
||||
foreach ($data as $t) {
|
||||
if ($t) {
|
||||
$save[] = $t;
|
||||
}
|
||||
}
|
||||
$save = array_unique($save);
|
||||
}
|
||||
}
|
||||
// 判断超限
|
||||
if ($field['setting']['option']['limit'] && dr_count($save) > $field['setting']['option']['limit']) {
|
||||
$save = array_slice($save, 0, $field['setting']['option']['limit']);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = dr_array2string($save);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证字段值
|
||||
*
|
||||
* @param string $field 字段类型
|
||||
* @param string $value 字段值
|
||||
* @return
|
||||
*/
|
||||
public function check_value($field, $value) {
|
||||
|
||||
$values = dr_string2array($value);
|
||||
if ($values) {
|
||||
foreach ($values as $value) {
|
||||
$link = dr_linkage($field['setting']['option']['linkage'], $value);
|
||||
if (!$link) {
|
||||
return dr_lang('选项无效');
|
||||
} elseif ($field['setting']['option']['ck_child'] && $link['child']) {
|
||||
return dr_lang('需要选择下级选项');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证必填字段值
|
||||
*
|
||||
* @param string $field 字段类型
|
||||
* @param string $value 字段值
|
||||
* @return
|
||||
*/
|
||||
public function check_required($field, $values) {
|
||||
|
||||
if (!$values) {
|
||||
// 验证值为空
|
||||
return dr_lang('%s不能为空', $field['name']);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证加载变量设置
|
||||
*/
|
||||
public function set_load_js($name, $value) {
|
||||
\Phpcmf\Service::C()->loadjs['Linkage'] = \Phpcmf\Service::C()->loadjs[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
if ($field['setting']['option']['new']) {
|
||||
// 字段默认值
|
||||
$value = $value ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
$value = dr_string2array($value);
|
||||
if (is_array($value)) {
|
||||
$new = [];
|
||||
foreach ($value as $t) {
|
||||
$new[] = (string)$t;
|
||||
}
|
||||
$value = json_encode($new);
|
||||
} else {
|
||||
$value = '[]';
|
||||
}
|
||||
|
||||
// 开始输出
|
||||
$str = '';
|
||||
if (!$this->is_load_js('Linkage')) {
|
||||
$str.= '
|
||||
<link rel="stylesheet" type="text/css" href="'.ROOT_THEME_PATH.'assets/layui/css/layui.css?v='.CMF_UPDATE_TIME.'"/>
|
||||
<link rel="stylesheet" type="text/css" href="'.ROOT_THEME_PATH.'assets/layui/cascader/cascader.css?v='.CMF_UPDATE_TIME.'"/>
|
||||
<script src="'.ROOT_THEME_PATH.'assets/layui/layui.js?v='.CMF_UPDATE_TIME.'"></script>
|
||||
<script src="'.ROOT_THEME_PATH.'assets/layui/cascader/cascader.js?v='.CMF_UPDATE_TIME.'"></script>
|
||||
';
|
||||
$this->set_load_js('Linkage', 1);
|
||||
}
|
||||
|
||||
// 输出js支持
|
||||
$str.= '<input type="hidden" name="data['.$name.']" id="dr_'.$name.'" value="'.$value.'" />
|
||||
<script src="'.WEB_DIR.'index.php?s=api&c=api&m=linkage&mid='.APP_DIR.'&file='.$field['setting']['option']['file'].'&code='.$field['setting']['option']['linkage'].'"></script>
|
||||
<script type="text/javascript">
|
||||
$(function (){
|
||||
layui.use(\'layCascader\', function () {
|
||||
var layCascader = layui.layCascader;
|
||||
layCascader({
|
||||
elem: \'#dr_'.$name.'\',
|
||||
value: '.$value.',
|
||||
clearable: true,
|
||||
filterable: false,
|
||||
maxSize: '.intval($field['setting']['option']['limit']).',
|
||||
collapseTags: '.($field['setting']['option']['collapse'] ? 'false' : 'true').',
|
||||
minCollapseTagsNumber: 0,
|
||||
options: linkage_'.$field['setting']['option']['linkage'].',
|
||||
props: {
|
||||
multiple: true,
|
||||
checkStrictly: '.($field['setting']['option']['ck_child'] ? 'false' : 'true').',
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
</script>'.$tips;
|
||||
} else {
|
||||
// 经典模式
|
||||
// 联动菜单缓存
|
||||
$linkage = dr_linkage_list($field['setting']['option']['linkage'], 0);
|
||||
if (!$linkage) {
|
||||
if (CI_DEBUG) {
|
||||
return $this->input_format($name, $text, '<div class="form-control-static" style="color:red">联动菜单【'.$field['setting']['option']['linkage'].'】没有数据</div>');
|
||||
}
|
||||
return $this->input_format($name, $text, '');
|
||||
}
|
||||
|
||||
// 最大几层
|
||||
$linklevel = dr_linkage_level($field['setting']['option']['linkage']) + 1;
|
||||
// 开始输出
|
||||
$str = '';
|
||||
if (!$this->is_load_js($field['fieldtype'].'_LD')) {
|
||||
$str.= '<script type="text/javascript" src="'.ROOT_THEME_PATH.'assets/js/jquery.ld.js?v='.CMF_UPDATE_TIME.'"></script>';
|
||||
$this->set_load_js($field['fieldtype'].'_LD', 1);
|
||||
}
|
||||
|
||||
// 表单宽度设置
|
||||
$width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'] : '100%');
|
||||
$str.= '<div class="dropzone-file-area" style="text-align:left" id="linkages-'.$name.'-sort-items" style="width:'.$width.(is_numeric($width) ? 'px' : '').';">';
|
||||
$level = 1;
|
||||
|
||||
// 输出默认菜单
|
||||
$tpl = '<div class="linkages_'.$name.'_row" id="dr_linkages_'.$name.'_row_{id}">';
|
||||
$tpl.= '<label style="margin-right: 10px;"><a class="btn btn-sm " href="javascript:;" onclick="$(\'#dr_linkages_'.$name.'_row_{id}\').remove()"> <i class="fa fa-close"></i> </a></label>';
|
||||
$tpl.= '<input type="hidden" name="data['.$name.'][{id}]" id="dr_'.$name.'_{id}" value="{value}" />';
|
||||
$tpl.= '<input type="hidden" id="dr_'.$name.'_{id}_default" value="" />';
|
||||
$tpl.= '<span id="dr_linkages_'.$name.'_select_{id}" style="display:{display}">';
|
||||
for ($i = 1; $i <= $linklevel; $i++) {
|
||||
$style = $i > $level ? 'style="display:none"' : '';
|
||||
$tpl.= '<label style="padding-right:10px;"><select class="form-control finecms-selects-'.$name.'-{id}" name="'.$name.'-'.$i.'-{id}" id="'.$name.'-'.$i.'-{id}" width="100" '.$style.'><option value=""> -- </option></select></label>';
|
||||
}
|
||||
$tpl.= '</span>';
|
||||
$tpl.= '</div>';
|
||||
|
||||
// 字段默认值
|
||||
$values = dr_string2array($value);
|
||||
if ($values) {
|
||||
foreach ($values as $id => $value) {
|
||||
if ($value) {
|
||||
$link = dr_linkage($field['setting']['option']['linkage'], $value);
|
||||
if (!$link) {
|
||||
continue;
|
||||
}
|
||||
$pids = substr((string)$link['pids'], 2);
|
||||
$level = substr_count($pids, ',') + 1;
|
||||
$default = !$pids ? '["'.$value.'"]' : '["'.str_replace(',', '","', $pids).'","'.$value.'"]';
|
||||
$str.= '<div class="linkages_'.$name.'_row" id="dr_linkages_'.$name.'_row_'.$id.'">';
|
||||
$str.= '<label style="margin-right: 10px;"><a class="btn btn-sm " href="javascript:;" onclick="$(\'#dr_linkages_'.$name.'_row_'.$id.'\').remove()"> <i class="fa fa-close"></i> </a></label>';
|
||||
$str.= '<input type="hidden" name="data['.$name.']['.$id.']" id="dr_'.$name.'_'.$id.'" value="'.$value.'" />';
|
||||
$str.= '<input type="hidden" id="dr_'.$name.'_'.$id.'_default" value="'.addslashes($default).'" />';
|
||||
$str.= '<span id="dr_linkages_'.$name.'_select_'.$id.'" style="display:none">';
|
||||
for ($i = 1; $i <= $linklevel; $i++) {
|
||||
$style = $i > $level ? 'style="display:none"' : '';
|
||||
$str.= '<label style="padding-right:10px;"><select class="form-control finecms-selects-'.$name.'-'.$id.'" name="'.$name.'-'.$i.'-'.$id.'" id="'.$name.'-'.$i.'-'.$id.'" width="100" '.$style.'><option value=""> -- </option></select></label>';
|
||||
}
|
||||
$str.= '</span>';
|
||||
$str.= '<label class="form-control-static" id="dr_linkages_'.$name.'_cxselect_'.$id.'">'.dr_linkagepos($field['setting']['option']['linkage'], $value, ' » ').' <a href="javascript:;" onclick="dr_linkages_select_'.$name.'('.$id.')" style="color:blue">'.dr_lang('[重新选择]').'</a></label>';
|
||||
$str.= '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 整体
|
||||
$str.= '</div>';
|
||||
$str.= '<div class="margin-top-10"> <a href="javascript:;" class="btn blue btn-sm" onClick="dr_add_linkages_'.$name.'()"> <i class="fa fa-plus"></i> '.dr_lang('添加').' </a>';
|
||||
$str.= '</div>';
|
||||
$str.= '<script type="text/javascript">
|
||||
$("#linkages-'.$name.'-sort-items").sortable();
|
||||
function dr_add_linkages_'.$name.'() {
|
||||
var num = $("#linkages-'.$name.'-sort-items .linkages_'.$name.'_row").length;
|
||||
if ('.(int)$field['setting']['option']['limit'].' > 0 && num >= '.(int)$field['setting']['option']['limit'].') {
|
||||
dr_tips(0, "'.dr_lang('最多可以选择%s项', $field['setting']['option']['limit']).'");
|
||||
return;
|
||||
}
|
||||
var id=(num + 1) * 10;
|
||||
var html = "'.addslashes($tpl).'";
|
||||
html = html.replace(/\{id\}/g, id);
|
||||
html = html.replace(/\{display\}/g, "blank");
|
||||
html = html.replace(/\{value\}/g, "0");
|
||||
$("#linkages-'.$name.'-sort-items").append(html);
|
||||
dr_linkages_init_'.$name.'(id);
|
||||
}
|
||||
function dr_linkages_select_'.$name.'(id) {
|
||||
$("#dr_linkages_'.$name.'_select_"+id).show();
|
||||
$("#dr_linkages_'.$name.'_cxselect_"+id).hide();
|
||||
dr_linkages_init_'.$name.'(id);
|
||||
}
|
||||
function dr_linkages_init_'.$name.'(id) {
|
||||
var $ld5 = $(".finecms-selects-'.$name.'-"+id);
|
||||
$ld5.ld({ajaxOptions:{"url": "'.WEB_DIR.'index.php?s=api&c=api&m=linkage_ld&code='.$field['setting']['option']['linkage'].'"},defaultParentId:0})
|
||||
var ld5_api = $ld5.ld("api");
|
||||
ld5_api.selected($("#dr_'.$name.'_"+id+"_default").val());
|
||||
$ld5.bind("change", function(e){
|
||||
var $target = $(e.target);
|
||||
var index = $ld5.index($target);
|
||||
$("#dr_'.$name.'_"+id).val($ld5.eq(index).show().val());
|
||||
index ++;
|
||||
$ld5.eq(index).show();
|
||||
});
|
||||
|
||||
}
|
||||
</script><span class="help-block">'.$tips.'</span>';
|
||||
}
|
||||
|
||||
|
||||
return $this->input_format($name, $text, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$str = '';
|
||||
$values = dr_string2array($value);
|
||||
if ($values) {
|
||||
foreach ($values as $value) {
|
||||
$str.= '<div class="form-control-static">'.dr_linkagepos($field['setting']['option']['linkage'], $value, ' - ').'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $str);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Members extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['TEXT' => '']; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... )
|
||||
$this->defaulttype = 'TEXT'; // 当用户没有选择字段类型时的缺省值
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$group = '<div class="mt-checkbox-inline">';
|
||||
foreach (\Phpcmf\Service::C()->member_cache['group'] as $t) {
|
||||
$group.= '<label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" value="'.$t['id'].'" name="data[setting][option][group][]" '.(dr_in_array($t['id'], $option['group']) ? 'checked' : '').' /> '.dr_lang($t['name']).' <span></span></label>';
|
||||
}
|
||||
$group.= '</div>';
|
||||
|
||||
return [$this->_search_field().'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('最大选择数').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][limit]" value="'.$option['limit'].'"></label>
|
||||
<span class="help-block">'.dr_lang('最大能选择的数量限制').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('每页显示条数').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][pagesize]" value="'.$option['pagesize'].'"></label>
|
||||
<span class="help-block">'.dr_lang('选择列表分页条数,按多少条数据分页').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('指定用户组').'</label>
|
||||
<div class="col-md-9">
|
||||
'.$group.'
|
||||
<span class="help-block">'.dr_lang('列出指定用户组的用户列表,如果不选择时将显示全部用户').'</span>
|
||||
</div>
|
||||
</div>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
$data = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
$value = !$data ? '' : implode(',', $data);
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $cname 字段别名
|
||||
* @param string $name 字段名称
|
||||
* @param array $cfg 字段配置
|
||||
* @param string $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
$is_show = 0;
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
// 字段提示信息
|
||||
$tips = isset($field['setting']['validate']['tips']) && $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$name.'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 区域大小
|
||||
$area = \Phpcmf\Service::IS_MOBILE_USER() ? '["95%", "90%"]' : '["50%", "65%"]';
|
||||
|
||||
// 选择数量限制
|
||||
$limit = intval($field['setting']['option']['limit']);
|
||||
!$limit && $limit = 99999;
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
$value = $value ? trim($value, ',') : '';
|
||||
$mylist = [];
|
||||
if ($value && is_string($value)) {
|
||||
$arr = explode(',', $value);
|
||||
if ($arr) {
|
||||
$value = '';
|
||||
foreach ($arr as $a) {
|
||||
$a = intval($a);
|
||||
if ($a) {
|
||||
$value .= ',' . $a;
|
||||
}
|
||||
}
|
||||
if ($value) {
|
||||
$value = trim($value, ',');
|
||||
$db = \Phpcmf\Service::M()->db->query('select * from '.\Phpcmf\Service::M()->dbprefix('member').' where id IN ('.$value.') order by FIELD(id, '.$value.')');
|
||||
$mylist = $db ? $db->getResultArray() : [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$file = \Phpcmf\Service::V()->code2php(
|
||||
file_get_contents(is_file(MYPATH.'View/api_members_field_'.$field['fieldname'].'.html') ? MYPATH.'View/api_members_field_'.$field['fieldname'].'.html' : COREPATH.'View/api_members_field.html')
|
||||
);
|
||||
ob_start();
|
||||
require $file;
|
||||
$str = ob_get_clean();
|
||||
|
||||
$str.= $tips;
|
||||
$js = \Phpcmf\Service::L('js_packer');
|
||||
$str.= $js->pack('
|
||||
<script type="text/javascript">
|
||||
$("#rmember_'.$name.'-sort-items").sortable();
|
||||
dr_slimScroll_init(".scroller_'.$name.'_files", 300);
|
||||
function dr_add_rmember_'.$name.'() {
|
||||
var len = $(\'#rmember_'.$name.'-sort-items tr\').length;
|
||||
if (len >= '.$limit.') {
|
||||
dr_tips(0, "'.dr_lang('关联数量超限').'");
|
||||
return;
|
||||
}
|
||||
var url = "/index.php?&is_iframe=1&s=member&c=api&m=members&name='.$name.'&diy='.$field['fieldname'].'&pagesize='.intval($field['setting']['option']['pagesize']).'&group='.($field['setting']['option']['group'] ? implode(',', $field['setting']['option']['group']) : '').'";
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: \'<i class="fa fa-user"></i> '.dr_lang('关联用户').'\',
|
||||
fix:true,
|
||||
shadeClose: true,
|
||||
shade: 0,
|
||||
area: '.$area.',
|
||||
btn: ["'.dr_lang('关联').'"],
|
||||
success: function (json) {
|
||||
if (json.code == 0) {
|
||||
layer.close();
|
||||
dr_tips(json.code, json.msg);
|
||||
}
|
||||
},
|
||||
yes: function(index, layero){
|
||||
var body = layer.getChildFrame(\'body\', index);
|
||||
// 延迟加载
|
||||
var loading = layer.load(2, {
|
||||
time: 10000
|
||||
});
|
||||
$.ajax({type: "POST",dataType:"json", url: url, data: $(body).find(\'#myform\').serialize(),
|
||||
success: function(json) {
|
||||
layer.close(loading);
|
||||
if (json.code == 1) {
|
||||
layer.close(index);
|
||||
for(var i in json.data.ids){
|
||||
var vid = json.data.ids[i];
|
||||
if (typeof vid != "undefined") {
|
||||
if($("#dr_items_'.$name.'_"+vid).length>0) {
|
||||
dr_tips(0, "'.dr_lang('已经存在').'");
|
||||
return;
|
||||
}
|
||||
if ($(\'#rmember_'.$name.'-sort-items tr\').length >= '.$limit.') {
|
||||
dr_tips(0, "'.dr_lang('关联数量超限').'");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$(\'#rmember_'.$name.'-sort-items\').append(json.data.html);
|
||||
dr_slimScroll_init(".scroller_'.$name.'_files", 300);
|
||||
dr_tips(1, json.msg);
|
||||
} else {
|
||||
dr_tips(0, json.msg);
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
content: url
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
</script>', 0);
|
||||
|
||||
return $this->input_format($name, $text, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$value = @trim($value, ',');
|
||||
$mylist = [];
|
||||
$is_show = 1;
|
||||
if ($value && is_string($value)) {
|
||||
$arr = explode(',', $value);
|
||||
if ($arr) {
|
||||
$value = '';
|
||||
foreach ($arr as $a) {
|
||||
$a = intval($a);
|
||||
if ($a) {
|
||||
$value .= ',' . $a;
|
||||
}
|
||||
}
|
||||
if ($value) {
|
||||
$value = trim($value, ',');
|
||||
$db = \Phpcmf\Service::M()->db->query('select * from '.\Phpcmf\Service::M()->dbprefix('member').' where id IN ('.$value.') order by FIELD(id, '.$value.')');
|
||||
$mylist = $db ? $db->getResultArray() : [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$file = \Phpcmf\Service::V()->code2php(
|
||||
file_get_contents(is_file(MYPATH.'View/api_members_field_'.$field['fieldname'].'.html') ? MYPATH.'View/api_members_field_'.$field['fieldname'].'.html' : COREPATH.'View/api_members_field.html')
|
||||
);
|
||||
ob_start();
|
||||
require $file;
|
||||
$str = ob_get_clean();
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $str);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Merge extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->close_xss = 1; // 关闭xss验证
|
||||
$this->is_edit = false; // 不允许修改字段类别
|
||||
$this->fieldtype = ['TEXT'];
|
||||
$this->defaulttype = 'TEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @param array $field 字段集合
|
||||
* @return string
|
||||
*/
|
||||
public function option($option, $field = NULL) {
|
||||
$Merge = [];
|
||||
$option['value'] = isset($option['value']) ? $option['value'] : '';
|
||||
if ($field) {
|
||||
foreach ($field as $t) {
|
||||
if ($t['fieldtype'] == 'Merge') {
|
||||
$t['setting'] = dr_string2array($t['setting']);
|
||||
if (preg_match_all('/\{(.+)\}/U', $t['setting']['option']['value'], $value)) {
|
||||
foreach ($value[1] as $v) {
|
||||
$Merge[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$_field = [];
|
||||
$_field[] = '<option value=""> -- </option>';
|
||||
foreach ($field as $t) {
|
||||
$t['fieldtype'] != 'Merge' && !dr_in_array($t['fieldname'], $Merge) && $_field[] = '<option value="'.$t['fieldname'].'">'.$t['name'].'</option>';
|
||||
}
|
||||
$_field = implode('', array_unique($_field));
|
||||
}
|
||||
|
||||
return ['
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('可用字段').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><select class="form-control" name="xx" id="fxx">'.$_field.'</select></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('分组规则').'</label>
|
||||
<div class="col-md-9">
|
||||
<textarea name="data[setting][option][value]" id="fvalue" style="height:120px;" class="form-control">'.$option['value'].'</textarea>
|
||||
<span class="help-block">'.dr_lang('分组规则不支持html标签,注意每个字段只能存在于一个分组中,否则会出错;此字段只能用于模块中').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$("#fxx").change(function(){
|
||||
var value = $(this).val();
|
||||
var fvalue = $("#fvalue").val();
|
||||
var text = $("#fxx").find("option:selected").text();
|
||||
$("#fxx option[value=\'"+value+"\']").remove();
|
||||
$("#fvalue").val(fvalue+"\n{"+value+"}");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
'];
|
||||
}
|
||||
|
||||
/**
|
||||
* create_sql
|
||||
*/
|
||||
public function create_sql($name, $value, $cname = '') {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* alter_sql
|
||||
*/
|
||||
public function alter_sql($name, $value, $cname = '') {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* drop_sql
|
||||
*/
|
||||
public function drop_sql($name) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test
|
||||
*/
|
||||
public function test_sql($tables, $field) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $field['setting']['option']['value']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Pay extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['DECIMAL' => '10,2']; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... )
|
||||
$this->defaulttype = 'DECIMAL'; // 当用户没有选择字段类型时的缺省值
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
!$option['payfile'] && $option['payfile'] = 'buy.html';
|
||||
|
||||
$opt = '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('模板文件').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="20" name="data[setting][option][payfile]" value="'.$option['payfile'].'"></label>
|
||||
<span class="help-block">'.dr_lang('模板位于./config/pay/模板文件名').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('余额付款').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][is_finecms]" '.($option['is_finecms'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
$style = '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
return [$opt, $style];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = (float)\Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '', $html = []) {
|
||||
|
||||
if (!defined('FC_PAY') && (IS_MEMBER || IS_ADMIN)) {
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
// 表单宽度设置
|
||||
$width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ((int)$field['setting']['option']['width'] ? $field['setting']['option']['width'] : 250);
|
||||
|
||||
// 表单附加参数
|
||||
$attr = 'style="width:'.$width.(is_numeric($width) ? 'px' : '').';" '.$field['setting']['validate']['formattr'];
|
||||
// 字段提示信息
|
||||
$tips = $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
// 当字段必填时,加入html5验证标签
|
||||
$required = $field['setting']['validate']['required'] ? ' required="required"' : '';
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
$ipt = '<input class="form-control '.$field['setting']['option']['css'].'" type="text" name="data['.$field['fieldname'].']" id="dr_'.$field['fieldname'].'" value="'.$value.'" '.$required.' '.$attr.' />';
|
||||
|
||||
return $this->input_format($field['fieldname'], $text, $ipt.$tips);
|
||||
} else {
|
||||
|
||||
// 付款金额
|
||||
$html['pay_value'] = $value ? $value : 0;
|
||||
|
||||
if (!dr_is_app('pay')) {
|
||||
return '没有安装「支付系统」插件';
|
||||
}
|
||||
// 付款方式
|
||||
$html['pay_type'] = \Phpcmf\Service::M('pay', 'pay')->get_pay_type(\Phpcmf\Service::C()->member && $field['setting']['option']['is_finecms'] && is_file(ROOTPATH.'api/pay/finecms/config.php'));
|
||||
|
||||
// 取默认第一个
|
||||
if ($html['pay_type']) {
|
||||
reset($html['pay_type']);
|
||||
$html['pay_default'] = key($html['pay_type']);
|
||||
}
|
||||
|
||||
// 付款界面模板
|
||||
if (isset($html['tpl']) && $html['tpl'] && is_file($html['tpl'])) {
|
||||
$htmlfile = $html['tpl'];
|
||||
// 验证路径合法性
|
||||
if (!\Phpcmf\Service::V()->_safe_template_path($htmlfile)) {
|
||||
return '支付表单模板文件路径不合法:'.$htmlfile.'<br>'.(\Phpcmf\Service::V()->_safe_template_error);
|
||||
}
|
||||
} else {
|
||||
$htmlfile = CONFIGPATH.'pay/buy.html';
|
||||
if ($field['setting']['option']['payfile']) {
|
||||
if (is_file(WEBPATH.'config/pay/'.$field['setting']['option']['payfile'])) {
|
||||
$htmlfile = WEBPATH.'config/pay/'.$field['setting']['option']['payfile'];
|
||||
} elseif (is_file(CONFIGPATH.'pay/'.$field['setting']['option']['payfile'])) {
|
||||
$htmlfile = CONFIGPATH.'pay/'.$field['setting']['option']['payfile'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!is_file($htmlfile)) {
|
||||
return '支付表单模板文件不存在:'.$htmlfile;
|
||||
}
|
||||
|
||||
$member = \Phpcmf\Service::C()->member;
|
||||
$pay_url = \Phpcmf\Service::L('router')->member_url('pay/pay/index');
|
||||
|
||||
// 获取付款界面代码
|
||||
ob_start();
|
||||
$file = \Phpcmf\Service::V()->code2php(file_get_contents($htmlfile));
|
||||
require $file;
|
||||
$code = ob_get_clean();
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
return $this->input_format($field['fieldname'], $field['name'], '<div class="form-control-static">¥'.$value.'元</div>');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,857 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Pays extends \Phpcmf\Library\A_Field {
|
||||
|
||||
protected $showfield = [
|
||||
'image' => '图片',
|
||||
'price' => '价格',
|
||||
'quantity' => '数量',
|
||||
'sn' => '编码',
|
||||
];
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['DECIMAL' => '10,2']; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... )
|
||||
$this->defaulttype = 'DECIMAL'; // 当用户没有选择字段类型时的缺省值
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option, $field = null) {
|
||||
|
||||
$myfield = $this->showfield;
|
||||
!$option['field'] && $option['field'] = [];
|
||||
!$option['payfile'] && $option['payfile'] = 'buy.html';
|
||||
foreach ($field as $t) {
|
||||
$t['fieldtype'] == 'Paystext' && $myfield[$t['fieldname']] = $t['name'];
|
||||
}
|
||||
$param_html = '';
|
||||
foreach ($myfield as $id => $t) {
|
||||
$param_html.= '<p style="margin-bottom:10px">';
|
||||
$param_html.= '<input type="checkbox" name="data[setting][option][field][]" '.(dr_in_array($id, $option['field']) ? 'checked' : '').' value="'.$id.'" data-on-text="'.dr_lang('%s已显示', dr_lang($t)).'" data-off-text="'.dr_lang('%s已禁用', dr_lang($t)).'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
';
|
||||
$param_html.= '</p>';
|
||||
}
|
||||
|
||||
$tpl_group = $this->_get_tpl_group('data[setting][option][sku]');
|
||||
$tpl_value = $this->_get_tpl_value('data[setting][option][sku]');
|
||||
$value = $option;
|
||||
|
||||
// 显示字段
|
||||
|
||||
$result = '';
|
||||
if (isset($value['sku']['group']) && $value['sku']['group']) {
|
||||
foreach ($value['sku']['group'] as $id => $name) {
|
||||
$html = '';
|
||||
if (isset($value['sku']['name'][$id]) && $value['sku']['name'][$id]) {
|
||||
foreach ($value['sku']['name'][$id] as $iid => $vname) {
|
||||
$html.= str_replace(
|
||||
['{id}', '{name}', '{iid}'],
|
||||
[$id, $vname, $iid],
|
||||
$tpl_value
|
||||
);
|
||||
}
|
||||
}
|
||||
$result.= str_replace(
|
||||
['{id}', '{name}', '{value}'],
|
||||
[$id, $name, $html],
|
||||
$tpl_group
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$opt = '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('模板文件').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="20" name="data[setting][option][payfile]" value="'.$option['payfile'].'"></label>
|
||||
<span class="help-block">'.dr_lang('模板位于./config/pay/模板文件名').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('定价模式').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][close_one]" '.(!$option['close_one'] ? 'checked' : '').' > '.dr_lang('单一定价+组合定价').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][close_one]" '.($option['close_one'] ? 'checked' : '').' > '.dr_lang('组合定价').' <span></span></label>
|
||||
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('可以选择单一定价+组合定价模式、组合定价模式两种方式').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('固定组合规格').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input onclick="$(\'.gdggb\').show()" type="radio" value="1" name="data[setting][option][is_sku]" '.($option['is_sku'] ? 'checked' : '').' > '.dr_lang('开启').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input onclick="$(\'.gdggb\').hide()" type="radio" value="0" name="data[setting][option][is_sku]" '.(!$option['is_sku'] ? 'checked' : '').' > '.dr_lang('关闭').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('固定规格会调用指定的规格表,用户不能修改和添加属性').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group gdggb" style="display: '.($option['is_sku'] ? 'blank' : 'none').'" >
|
||||
<label class="col-md-2 control-label">'.dr_lang('指定规格表').'</label>
|
||||
<div class="col-md-9">
|
||||
<div id="dr_field_pays">
|
||||
<label><button type="button" class="btn blue btn-sm" onclick="dr_sku_add_group()"> <i class="fa fa-plus"></i> '.dr_lang('添加属性').'</button></label>
|
||||
<div class="portlet light bordered">
|
||||
<div id="dr_sku_result">
|
||||
'.$result.'
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var arrayValue = new Array();
|
||||
var tpl_group = "'.$this->_js_var($tpl_group).'";
|
||||
var tpl_value = "'.$this->_js_var($tpl_value).'";
|
||||
var field_name = "_sku";
|
||||
var sku_field_name = "";
|
||||
var sku_field_id = "";
|
||||
</script>
|
||||
<script type="text/javascript" src="'.ROOT_THEME_PATH.'assets/js/sku.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
dr_sku_init();
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('余额付款').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][is_finecms]" '.($option['is_finecms'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('显示参数').'</label>
|
||||
<div class="col-md-9">
|
||||
'.$param_html.'
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
$style = '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
return [$this->_search_field().$opt, $style];
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建sql语句
|
||||
*/
|
||||
public function create_sql($name, $value, $cname = '') {
|
||||
|
||||
$columns = [
|
||||
['name' => $name, 'type' => 'DECIMAL(9,2)', 'info' => 'NULL'],
|
||||
['name' => $name.'_sku', 'type' => 'TEXT', 'info' => 'NULL'],
|
||||
['name' => $name.'_quantity', 'type' => 'INT(10)', 'info' => 'UNSIGNED NULL'],
|
||||
['name' => $name.'_sn', 'type' => 'VARCHAR(10)', 'info' => 'NULL'],
|
||||
];
|
||||
$db = $this->_db_for_field_sql();
|
||||
if ($db && method_exists($db, 'sqlAddFields')) {
|
||||
return $db->sqlAddFields($columns);
|
||||
}
|
||||
|
||||
// 驱动未就绪时回退 MySQL 方言
|
||||
return 'ALTER TABLE `{tablename}` ADD `'.$name.'` DECIMAL(9,2) NULL, ADD `'.$name.'_sku` TEXT NULL, ADD `'.$name.'_quantity` INT(10) UNSIGNED NULL, ADD `'.$name.'_sn` VARCHAR(10) NULL';
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改sql语句
|
||||
*/
|
||||
public function alter_sql($name, $value, $cname = '') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除sql语句
|
||||
*/
|
||||
public function drop_sql($name) {
|
||||
|
||||
$names = [$name, $name.'_sku', $name.'_quantity', $name.'_sn'];
|
||||
$db = $this->_db_for_field_sql();
|
||||
if ($db && method_exists($db, 'sqlDropFields')) {
|
||||
return $db->sqlDropFields($names);
|
||||
}
|
||||
|
||||
return 'ALTER TABLE `{tablename}` DROP `'.$name.'`, DROP `'.$name.'_sku`, DROP `'.$name.'_quantity`, DROP `'.$name.'_sn`';
|
||||
}
|
||||
|
||||
// 测试字段是否被创建成功,默认成功为0,需要继承开发
|
||||
public function test_sql($tables, $field) {
|
||||
|
||||
if (!$tables) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($tables as $table) {
|
||||
if (!\Phpcmf\Service::M()->db->fieldExists($field.'_sku', $table)) {
|
||||
return '给表['.$table.']创建字段['.$field.'_sku'.']失败';
|
||||
}
|
||||
if (!\Phpcmf\Service::M()->db->fieldExists($field.'_quantity', $table)) {
|
||||
return '给表['.$table.']创建字段['.$field.'_quantity'.']失败';
|
||||
}
|
||||
if (!\Phpcmf\Service::M()->db->fieldExists($field.'_sn', $table)) {
|
||||
return '给表['.$table.']创建字段['.$field.'_sn'.']失败';
|
||||
}
|
||||
if (!\Phpcmf\Service::M()->db->fieldExists($field, $table)) {
|
||||
return '给表['.$table.']创建字段['.$field.']失败';
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 显示字段
|
||||
protected function _get_myfield($field) {
|
||||
|
||||
$my = [];
|
||||
$_field = \Phpcmf\Service::L('field')->fields;
|
||||
foreach ($field['setting']['option']['field'] as $ff) {
|
||||
if (isset($this->showfield[$ff])) {
|
||||
$my[$ff] = $this->showfield[$ff];
|
||||
} elseif (isset($_field[$ff])) {
|
||||
$my[$ff] = $_field[$ff]['name'];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $my;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
if (isset($field['setting']['option']['close_one']) && $field['setting']['option']['close_one']) {
|
||||
$is_field_pay = 1;
|
||||
} else {
|
||||
$is_field_pay = (int)$_POST['is_field_pay'];
|
||||
}
|
||||
|
||||
if ($is_field_pay) {
|
||||
// 组合
|
||||
$price = 0;
|
||||
$quantity = 0;
|
||||
if (isset($field['setting']['option']['is_sku']) && $field['setting']['option']['is_sku']) {
|
||||
$sku = $field['setting']['option']['sku'];
|
||||
$sku['value'] = $_POST['data'][$field['fieldname'].'_sku']['value'];
|
||||
} else {
|
||||
$sku = $_POST['data'][$field['fieldname'].'_sku'];
|
||||
}
|
||||
if ($sku['value']) {
|
||||
$price_array = [];
|
||||
foreach ($sku['value'] as $v) {
|
||||
$quantity+= intval($v['quantity']);
|
||||
$price_array[] = $v['price'];
|
||||
}
|
||||
$price = min($price_array);
|
||||
}
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = (float)$price;
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname'].'_sn'] = '';
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname'].'_sku'] = dr_array2string($sku);
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname'].'_quantity'] = abs((int)$quantity);
|
||||
} else {
|
||||
// 单一
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = (float)$_POST[$field['fieldname']]['price'];
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname'].'_sn'] = dr_safe_replace($_POST[$field['fieldname']]['sn']);
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname'].'_sku'] = '';
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname'].'_quantity'] = (int)$_POST[$field['fieldname']]['quantity'];
|
||||
$_field = \Phpcmf\Service::L('form')->fields;
|
||||
foreach ($field['setting']['option']['field'] as $ff) {
|
||||
if (isset($_field[$ff])) {
|
||||
\Phpcmf\Service::L('Field')->data[$_field[$ff]['ismain']][$ff] = (string)$_POST[$field['fieldname']][$ff];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取附件id
|
||||
*/
|
||||
public function get_attach_id($value) {
|
||||
|
||||
if (!$this->field) {
|
||||
return NULL;
|
||||
} elseif (!dr_in_array('image', $this->field['setting']['option']['field'])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$value = dr_string2array($value);
|
||||
|
||||
if ($value) {
|
||||
foreach ($value as $tt) {
|
||||
if (isset($tt['image']) && $tt['image']) {
|
||||
$data[] = intval($tt['image']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 附件处理
|
||||
*/
|
||||
public function attach($data, $_data) {
|
||||
|
||||
if (!$this->field) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$data = isset($_POST['data'][$this->field['fieldname'].'_sku']['value']) ? $_POST['data'][$this->field['fieldname'].'_sku']['value'] : [];
|
||||
if (isset(\Phpcmf\Service::L('Field')->old[$this->field['fieldname'].'_sku'])) {
|
||||
$old = dr_string2array(\Phpcmf\Service::L('Field')->old[$this->field['fieldname'].'_sku']);
|
||||
$_data = isset($old['value']) ? $old['value'] : [];
|
||||
}
|
||||
|
||||
$data = $this->get_attach_id($data);
|
||||
$_data = $this->get_attach_id($_data);
|
||||
|
||||
if (!isset($_data)) {
|
||||
$_data = [];
|
||||
}
|
||||
|
||||
if (!isset($data)) {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
// 新旧数据都无附件就跳出
|
||||
if (!$data && !$_data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 新旧数据都一样时表示没做改变就跳出
|
||||
if (dr_diff($data, $_data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 当无新数据且有旧数据表示删除旧附件
|
||||
if (!$data && $_data) {
|
||||
return [
|
||||
[],
|
||||
$_data
|
||||
];
|
||||
}
|
||||
|
||||
// 当无旧数据且有新数据表示增加新附件
|
||||
if ($data && !$_data) {
|
||||
return [
|
||||
$data,
|
||||
[]
|
||||
];
|
||||
}
|
||||
|
||||
// 剩下的情况就是删除旧文件增加新文件
|
||||
|
||||
// 新旧附件的交集,表示固定的
|
||||
$intersect = array_intersect($data, $_data);
|
||||
|
||||
return [
|
||||
array_diff($data, $intersect), // 固有的与新文件中的差集表示新增的附件
|
||||
array_diff($_data, $intersect), // 固有的与旧文件中的差集表示待删除的附件
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证必填字段值
|
||||
*
|
||||
* @param string $field 字段类型
|
||||
* @param string $value 字段值
|
||||
* @return
|
||||
*/
|
||||
public function check_required($field, $value) {
|
||||
|
||||
if (isset($field['setting']['option']['close_one']) && $field['setting']['option']['close_one']) {
|
||||
$is_field_pay = 1;
|
||||
} else {
|
||||
$is_field_pay = (int)$_POST['is_field_pay'];
|
||||
}
|
||||
|
||||
if ($is_field_pay) {
|
||||
if (isset($field['setting']['option']['is_sku']) && $field['setting']['option']['is_sku']) {
|
||||
$sku = $field['setting']['option']['sku'];
|
||||
$sku['value'] = $_POST['data'][$field['fieldname'].'_sku']['value'];
|
||||
} else {
|
||||
$sku = $_POST['data'][$field['fieldname'].'_sku'];
|
||||
}
|
||||
if ($sku['value']) {
|
||||
foreach ($sku['value'] as $v) {
|
||||
if (strlen($v['price']) == 0) {
|
||||
return dr_lang('%s不能为空', $field['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (strlen($_POST[$field['fieldname']]['price']) == 0) {
|
||||
return dr_lang('%s不能为空', $field['name']);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段值
|
||||
*/
|
||||
public function get_value($name, $data) {
|
||||
|
||||
$value = [
|
||||
'price' => $data[$name],
|
||||
'sku' => dr_string2array($data[$name.'_sku']),
|
||||
'sn' => $data[$name.'_sn'],
|
||||
'quantity' => $data[$name.'_quantity'],
|
||||
];
|
||||
|
||||
$field = \Phpcmf\Service::L('field')->fields;
|
||||
|
||||
foreach ($field[$name]['setting']['option']['field'] as $ff ) {
|
||||
if ($field[$ff]['fieldtype'] == 'Paystext') {
|
||||
$value[$ff] = (string)$data[$ff];
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付时获取商品属性
|
||||
*/
|
||||
public function get_pay_info($rt, $field, $sku) {
|
||||
|
||||
$rt[$field['fieldname'].'_sku'] = dr_string2array($rt[$field['fieldname'].'_sku']);
|
||||
if (!$sku && $rt[$field['fieldname'].'_sku']) {
|
||||
return dr_return_data(0, dr_lang('没有选择商品属性'));
|
||||
} elseif (!isset($rt[$field['fieldname'].'_sku']['value'][$sku]) || !$rt[$field['fieldname'].'_sku']['value'][$sku]) {
|
||||
return dr_return_data(0, dr_lang('商品(#'.$rt['id'].')属性(#'.$sku.')无效'));
|
||||
}
|
||||
|
||||
$sn = (string)$rt[$field['fieldname'].'_sku']['value'][$sku]['sn'];
|
||||
$quantity = (int)$rt[$field['fieldname'].'_sku']['value'][$sku]['quantity'];
|
||||
list($sku_name, $sku_string) = dr_sku_name($sku, $rt[$field['fieldname'].'_sku'], 1);
|
||||
|
||||
return dr_return_data(1, '', [$sn, $quantity, $sku_name, $sku_string]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function output($value) {
|
||||
return (float)$value;
|
||||
}
|
||||
|
||||
protected function _get_tpl_value($name) {
|
||||
return '
|
||||
<div class="fc-sku-group-value col-md-4" id="dr_sku_value_{id}_{iid}" did="{iid}">
|
||||
<div class="input-group input-group-sm">
|
||||
<input type="text" class="fc-sku-value-name-input form-control" onblur="dr_sku_init()" name="'.$name.'[name][{id}][{iid}]" fname="{id}_{iid}" value="{name}">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn red" onclick="javascript:dr_sku_del_value(\'{id}\', \'{iid}\');" type="button"><i class="fa fa-trash"></i></button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
protected function _get_tpl_group($name) {
|
||||
|
||||
return '
|
||||
<div class="portlet-body fc-sku-group" id="dr_sku_group_{id}" did="{id}">
|
||||
<input type="hidden" id="dr_sku_group_text_{id}" name="'.$name.'[group][{id}]" value="{name}">
|
||||
<div class="row fc-sku-group-name">
|
||||
<div class="col-md-6 fc-sku-group-name-input">{name}</div>
|
||||
<div class="text-right col-md-6">
|
||||
<button onclick="javascript:dr_sku_add_value(\'{id}\');" type="button" class="btn green btn-sm"> '.dr_lang('添加值').'</button>
|
||||
<button onclick="javascript:dr_sku_edit_group(\'{id}\');" type="button" class="edit btn blue btn-sm"> '.dr_lang('修改').'</button>
|
||||
<button onclick="javascript:dr_sku_save_group(\'{id}\');" type="button" class="save btn blue btn-sm" style="display:none"> '.dr_lang('保存').'</button>
|
||||
<button onclick="javascript:dr_sku_del_group(\'{id}\');" type="button" class="btn red btn-sm"> '.dr_lang('删除').'</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row fc-sku-group-body" id="dr_sku_value_{id}">
|
||||
{value}
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = [], $html = []) {
|
||||
|
||||
if (!defined('FC_PAY') && (IS_MEMBER || IS_ADMIN)) {
|
||||
|
||||
if (!$field['setting']['option']['field']) {
|
||||
return $this->input_format($field['fieldname'], $field['name'], '<div class="form-control-static">字段Pays没有设置显示参数</div>');
|
||||
}
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 字段提示信息
|
||||
$tips = $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
$tpl_group = $this->_get_tpl_group('data['.$field['fieldname'].'_sku]');
|
||||
|
||||
$tpl_value = $this->_get_tpl_value('data['.$field['fieldname'].'_sku]');
|
||||
|
||||
$image_url ='/'.(IS_ADMIN ? SELF.'?c=api' : 'index.php?s=api&c=file').'&m=input_file_list&token='.dr_get_csrf_token().'&siteid='.SITE_ID.'&p='.dr_authcode([
|
||||
'size' => 10,
|
||||
'count' => 1,
|
||||
'exts' => 'jpg,gif,png',
|
||||
'attachment' => 0,
|
||||
'image_reduce' => 0,
|
||||
], 'ENCODE').'&ct=0&one=1';
|
||||
// 显示字段
|
||||
$pay_html = ''; // 单一模式下的输出
|
||||
$myfield = $this->_get_myfield($field);
|
||||
$sku_field_name = '';
|
||||
$sku_field_id = [];
|
||||
foreach ($myfield as $ff => $name) {
|
||||
if ($ff == 'image') {
|
||||
|
||||
} else {
|
||||
$pay_html.= '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.$name.'</label>
|
||||
<div class="col-md-7">
|
||||
<input type="text" name="'.$field['fieldname'].'['.$ff.']" value="'.(isset($value[$ff]) ? $value[$ff] : '').'" class="form-control input-inline input-medium">
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
$sku_field_name.= '<th>'.$name.'</th>';
|
||||
$sku_field_id[] = $ff;
|
||||
}
|
||||
|
||||
|
||||
if (isset($field['setting']['option']['is_sku']) && $field['setting']['option']['is_sku']) {
|
||||
$value['sku']['name'] = $field['setting']['option']['sku']['name'];
|
||||
$value['sku']['group'] = $field['setting']['option']['sku']['group'];
|
||||
}
|
||||
|
||||
$result = '';
|
||||
if (isset($value['sku']['group']) && $value['sku']['group']) {
|
||||
foreach ($value['sku']['group'] as $id => $name) {
|
||||
$html = '';
|
||||
if (isset($value['sku']['name'][$id]) && $value['sku']['name'][$id]) {
|
||||
foreach ($value['sku']['name'][$id] as $iid => $vname) {
|
||||
$html.= str_replace(
|
||||
['{id}', '{name}', '{iid}'],
|
||||
[$id, $vname, $iid],
|
||||
$tpl_value
|
||||
);
|
||||
}
|
||||
}
|
||||
$result.= str_replace(
|
||||
['{id}', '{name}', '{value}'],
|
||||
[$id, $name, $html],
|
||||
$tpl_group
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$ovalue = [];
|
||||
if (isset($value['sku']['value']) && $value['sku']['value']) {
|
||||
foreach ($value['sku']['value'] as $ii => $t) {
|
||||
foreach ($sku_field_id as $if) {
|
||||
$ovalue[$ii.'_'.$if] = $t[$if];
|
||||
if ($if == 'image' && $t[$if]) {
|
||||
$ovalue[$ii.'_'.$if.'_url'] = dr_get_file($t[$if]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$str = '';
|
||||
|
||||
// 是否单一模式
|
||||
if (isset($field['setting']['option']['close_one']) && $field['setting']['option']['close_one']) {
|
||||
$is_field_pay = 1;
|
||||
$sku_html = '<p class="margin-bottom-20">
|
||||
<label><button type="button" class="btn blue btn-sm" onclick="dr_sku_add_group()"> <i class="fa fa-plus"></i> '.dr_lang('添加属性').'</button></label>
|
||||
<label><button type="button" class="btn green btn-sm" onclick="dr_sku_init()"> <i class="fa fa-refresh"></i> '.dr_lang('更新属性').'</button></label>
|
||||
</p>
|
||||
<div class="portlet light isbordered">
|
||||
<div id="dr_sku_result">
|
||||
'.$result.'
|
||||
</div>
|
||||
</div>';
|
||||
} else {
|
||||
$is_field_pay = $result && $ovalue ? 1 : 0;
|
||||
$str.= '<div class="mt-radio-inline">
|
||||
<label class="mt-radio">
|
||||
<input type="radio" onclick="$(\'#dr_field_pay\').show();$(\'#dr_field_pays\').hide();" name="is_field_pay" value="0" '.(!$is_field_pay ? 'checked' : '').'> '.dr_lang('单一价格').'
|
||||
<span></span>
|
||||
</label>
|
||||
<label class="mt-radio">
|
||||
<input type="radio" onclick="$(\'#dr_field_pays\').show();$(\'#dr_field_pay\').hide();" name="is_field_pay" value="1" '.($is_field_pay ? 'checked' : '').'> '.dr_lang('组合价格').'
|
||||
<span></span>
|
||||
</label>
|
||||
</div>';
|
||||
$sku_html = '<p class="margin-bottom-20">
|
||||
<label><button type="button" class="btn blue btn-sm" onclick="dr_sku_add_group()"> <i class="fa fa-plus"></i> '.dr_lang('添加属性').'</button></label>
|
||||
<label><button type="button" class="btn green btn-sm" onclick="dr_sku_init()"> <i class="fa fa-refresh"></i> '.dr_lang('更新属性').'</button></label>
|
||||
</p>
|
||||
<div class="portlet light isbordered">
|
||||
<div id="dr_sku_result">
|
||||
'.$result.'
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
|
||||
$str.= '
|
||||
|
||||
<div id="dr_field_pay" style="display:'.(!$is_field_pay ? 'block' : 'none').';">
|
||||
<div class="portlet light isbordered">
|
||||
<div class="form-body" style="padding:30px 0 10px 0">
|
||||
'.$pay_html.'
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="dr_field_pays" style="display:'.($is_field_pay ? 'block' : 'none').';">
|
||||
'.$sku_html.'
|
||||
<div id="dr_sku_table">
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var arrayValue = new Array();
|
||||
var tpl_group = "'.$this->_js_var($tpl_group).'";
|
||||
var tpl_value = "'.$this->_js_var($tpl_value).'";
|
||||
var field_name = "'.$field['fieldname'].'_sku";
|
||||
var sku_field_name = "'.$this->_js_var($sku_field_name).'";
|
||||
var sku_image_url = "'.$image_url.'";
|
||||
var sku_field_id = '.dr_array2string($sku_field_id).';
|
||||
arrayValue = '.($ovalue ? dr_array2string($ovalue) : 'new Array()').';
|
||||
</script>
|
||||
<script type="text/javascript" src="'.ROOT_THEME_PATH.'assets/js/sku.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
dr_sku_init();
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
';
|
||||
return $this->input_format($field['fieldname'], $text, $str.$tips);
|
||||
} else {
|
||||
|
||||
// 付款金额
|
||||
$html['pay_value'] = $value ? $value : 0;
|
||||
if (!dr_is_app('pay')) {
|
||||
return '没有安装「支付系统」插件';
|
||||
}
|
||||
// 付款方式
|
||||
$html['pay_type'] = \Phpcmf\Service::M('pay', 'pay')->get_pay_type(\Phpcmf\Service::C()->member && $field['setting']['option']['is_finecms'] && is_file(ROOTPATH.'api/pay/finecms/config.php'));
|
||||
|
||||
// 取默认第一个
|
||||
if ($html['pay_type']) {
|
||||
reset($html['pay_type']);
|
||||
$html['pay_default'] = key($html['pay_type']);
|
||||
}
|
||||
|
||||
|
||||
// 付款界面模板
|
||||
if (isset($html['tpl']) && $html['tpl'] && is_file($html['tpl'])) {
|
||||
$htmlfile = $html['tpl'];
|
||||
// 验证路径合法性
|
||||
if (!\Phpcmf\Service::V()->_safe_template_path($htmlfile)) {
|
||||
return '支付表单模板文件路径不合法:'.$htmlfile.'<br>'.(\Phpcmf\Service::V()->_safe_template_error);
|
||||
}
|
||||
} else {
|
||||
$htmlfile = CONFIGPATH.'pay/buy.html';
|
||||
if ($field['setting']['option']['payfile']) {
|
||||
if (is_file(WEBPATH.'config/pay/'.$field['setting']['option']['payfile'])) {
|
||||
$htmlfile = WEBPATH.'config/pay/'.$field['setting']['option']['payfile'];
|
||||
} elseif (is_file(CONFIGPATH.'pay/'.$field['setting']['option']['payfile'])) {
|
||||
$htmlfile = CONFIGPATH.'pay/'.$field['setting']['option']['payfile'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_file($htmlfile)) {
|
||||
return '支付表单模板文件不存在:'.$htmlfile;
|
||||
}
|
||||
|
||||
$member = \Phpcmf\Service::C()->member;
|
||||
$pay_url = \Phpcmf\Service::L('router')->member_url('pay/pay/index');
|
||||
|
||||
// 获取付款界面代码
|
||||
ob_start();
|
||||
$file = \Phpcmf\Service::V()->code2php(file_get_contents($htmlfile));
|
||||
require_once $file;
|
||||
$code = ob_get_clean();
|
||||
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').$field['name'];
|
||||
|
||||
$tpl_group = '
|
||||
<div class="portlet-body fc-sku-group" id="dr_sku_group_{id}" did="{id}">
|
||||
<input type="hidden" id="dr_sku_group_text_{id}" name="data['.$field['fieldname'].'_sku][group][{id}]" value="{name}">
|
||||
<div class="row fc-sku-group-name">
|
||||
<div class="col-md-6 fc-sku-group-name-input">{name}</div>
|
||||
</div>
|
||||
<div class="row fc-sku-group-body" id="dr_sku_value_{id}">
|
||||
{value}
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
$tpl_value = '
|
||||
<div class="fc-sku-group-value col-md-4" id="dr_sku_value_{id}_{iid}" did="{iid}">
|
||||
<div class="input-group input-group-sm">
|
||||
<input type="text" class="fc-sku-value-name-input form-control" onblur="dr_sku_init()" name="data['.$field['fieldname'].'_sku][name][{id}][{iid}]" fname="{id}_{iid}" value="{name}">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn red" onclick="javascript:dr_sku_del_value(\'{id}\', \'{iid}\');" type="button"><i class="fa fa-trash"></i></button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
// 显示字段
|
||||
$pay_html = '';
|
||||
$myfield = $this->_get_myfield($field);
|
||||
$sku_field_name = '';
|
||||
$sku_field_id = [];
|
||||
foreach ($myfield as $ff => $name) {
|
||||
$pay_html.= '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.$name.'</label>
|
||||
<div class="col-md-7">
|
||||
<div class="form-control-static">'.$value[$ff].'</div>
|
||||
</div>
|
||||
</div>';
|
||||
$sku_field_name.= '<th>'.$name.'</th>';
|
||||
$sku_field_id[] = $ff;
|
||||
}
|
||||
|
||||
$result = '';
|
||||
if (isset($value['sku']['group']) && $value['sku']['group']) {
|
||||
foreach ($value['sku']['group'] as $id => $name) {
|
||||
$html = '';
|
||||
if (isset($value['sku']['name'][$id]) && $value['sku']['name'][$id]) {
|
||||
foreach ($value['sku']['name'][$id] as $iid => $vname) {
|
||||
$html.= str_replace(
|
||||
['{id}', '{name}', '{iid}'],
|
||||
[$id, $vname, $iid],
|
||||
$tpl_value
|
||||
);
|
||||
}
|
||||
}
|
||||
$result.= str_replace(
|
||||
['{id}', '{name}', '{value}'],
|
||||
[$id, $name, $html],
|
||||
$tpl_group
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$ovalue = $oimg = [];
|
||||
if (isset($value['sku']['value']) && $value['sku']['value']) {
|
||||
foreach ($value['sku']['value'] as $ii => $t) {
|
||||
foreach ($sku_field_id as $if) {
|
||||
$ovalue[$ii.'_'.$if] = $t[$if];
|
||||
if ($if == 'image') {
|
||||
$ovalue[$ii.'_'.$if.'_url'] = dr_get_file($t[$if]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 是否单一模式
|
||||
$is_field_pay = $result && $ovalue ? 1 : 0;
|
||||
|
||||
$str = '
|
||||
|
||||
<div id="dr_field_pay" style="display:'.(!$is_field_pay ? 'block' : 'none').';">
|
||||
<div class="portlet light isbordered">
|
||||
|
||||
<div class="form-body" style="padding:30px 0 10px 0">
|
||||
|
||||
'.$pay_html.'
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="dr_field_pays" style="display:'.($is_field_pay ? 'block' : 'none').';">
|
||||
|
||||
<div class="hide">
|
||||
|
||||
<div id="dr_sku_result">
|
||||
'.$result.'
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="dr_sku_table">
|
||||
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var arrayValue = new Array();
|
||||
var tpl_group = "'.$this->_js_var($tpl_group).'";
|
||||
var tpl_value = "'.$this->_js_var($tpl_value).'";
|
||||
var field_name = "'.$field['fieldname'].'_sku";
|
||||
var sku_field_name = "'.$this->_js_var($sku_field_name).'";
|
||||
var sku_field_id = '.dr_array2string($sku_field_id).';
|
||||
arrayValue = '.dr_array2string($ovalue).';
|
||||
</script>
|
||||
<script type="text/javascript" src="'.ROOT_THEME_PATH.'assets/js/sku.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
dr_sku_init();
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
';
|
||||
return $this->input_format($field['fieldname'], $text, $str);
|
||||
}
|
||||
|
||||
// 格式化js变量
|
||||
protected function _js_var($html) {
|
||||
return str_replace([PHP_EOL, chr(13)], "", addslashes($html));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class PaysText extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = TRUE;
|
||||
$this->defaulttype = 'VARCHAR';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
return ['<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('字段作用').' </label>
|
||||
<div class="col-md-9"><label class="form-control-static" style="color: red">'.dr_lang('本类型字段需要在Pays类型的字段中启用后才能生效').'</label></div>
|
||||
</div>'.$this->field_type($option['fieldtype'], $option['fieldlength']).'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认填充值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>', '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Property extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->close_xss = 1; // 关闭xss验证
|
||||
$this->fieldtype = ['TEXT' => ''];
|
||||
$this->defaulttype = 'TEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
unset($option['width']);
|
||||
if (!isset($option['name_value']) || !$option['name_value']) {
|
||||
$option['name_value'] = dr_lang('名称');
|
||||
}
|
||||
if (!isset($option['value_value']) || !$option['value_value']) {
|
||||
$option['value_value'] = dr_lang('值');
|
||||
}
|
||||
$str = '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('选项名称').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="20" value="'.$option['name_value'].'" name="data[setting][option][name_value]"></label>
|
||||
<label><input type="text" class="form-control" size="20" value="'.$option['value_value'].'" name="data[setting][option][value_value]"></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group dr_option" id="dr_option_0">
|
||||
<label class="col-md-2 control-label">'.dr_lang('字段说明').'</label>
|
||||
<div class="col-md-9"><div class="form-control-static">'.dr_lang('选择框与复选框类型的选项值以,分隔').'</div><br>
|
||||
<a href="javascript:;" class="btn btn-sm red" onclick="dr_add_option()"><i class="fa fa-plus"></i> '.dr_lang('增加属性选项').'</a>
|
||||
</div>
|
||||
</div>';
|
||||
unset($option['name_value']);
|
||||
unset($option['value_value']);
|
||||
$i = 0;
|
||||
if ($option['default_value']) {
|
||||
foreach ($option['default_value'] as $i => $t) {
|
||||
$str.= '<div class="form-group dr_option" id="dr_option_'.$i.'" >';
|
||||
$str.= '<label class="col-md-2 control-label">'.dr_lang('属性名称').'</label>';
|
||||
$str.= '<div class="col-md-9"><label><input type="text" name="data[setting][option][default_value]['.$i.'][name]" value="'.$t['name'].'" class="form-control" /></label>';
|
||||
$str.= '<label> '.dr_lang('类型').':</label><label><select class="form-control" name="data[setting][option][default_value]['.$i.'][type]">';
|
||||
$str.= '<option value="1" '.($t['type'] == 1 ? "selected" : "").'> - '.dr_lang('文本框').' - </option>';
|
||||
$str.= '<option value="2" '.($t['type'] == 2 ? "selected" : "").'> - '.dr_lang('选择框').' - </option>';
|
||||
$str.= '<option value="3" '.($t['type'] == 3 ? "selected" : "").'> - '.dr_lang('复选框').' - </option>';
|
||||
$str.= '</select></label>';
|
||||
$str.= '<label> '.dr_lang('默认值/选项值').':</label><label><input type="text" name="data[setting][option][default_value]['.$i.'][value]" value="'.$t['value'].'" class="form-control input-xlarge"></label> <label><a onclick="$(\'#dr_option_'.$i.'\').remove()" href="javascript:;">'.dr_lang('删除').'</a></label>';
|
||||
$str.= '</div></div>';
|
||||
}
|
||||
}
|
||||
|
||||
$str.= '
|
||||
<script type="text/javascript">
|
||||
var id='.$i.';
|
||||
function dr_add_option() {
|
||||
id ++;
|
||||
if ($("#dr_option_"+id).length>0) {
|
||||
dr_tips(0, \''.dr_lang("序列生成重复,请重新添加").'\');
|
||||
return;
|
||||
}
|
||||
var html = "";
|
||||
html+= "<div class=\"form-group dr_option\" id=\"dr_option_"+id+"\" >";
|
||||
html+= "<label class=\"col-md-2 control-label\">'.dr_lang('属性名称').' "+id+"</label>";
|
||||
html+= "<div class=\"col-md-9\">";
|
||||
html+= "<label><input type=\"text\" name=\"data[setting][option][default_value]["+id+"][name]\" value=\"\" class=\"form-control\" /></label>";
|
||||
html+= "<label> '.dr_lang('类型').':</label><label><select class=\"form-control\" name=\"data[setting][option][default_value]["+id+"][type]\">";
|
||||
html+= "<option value=\"1\"> - '.dr_lang('文本框').' - </option>";
|
||||
html+= "<option value=\"2\"> - '.dr_lang('选择框').' - </option>";
|
||||
html+= "<option value=\"3\"> - '.dr_lang('复选框').' - </option>";
|
||||
html+= "</select></label>";
|
||||
html+= "<label> '.dr_lang('默认值/选项值').':</label><label><input type=\"text\" name=\"data[setting][option][default_value]["+id+"][value]\" class=\"form-control input-xlarge\"></label> <label><a onclick=\"$(\'#dr_option_"+id+"\').remove()\" href=\"javascript:;\">'.dr_lang('删除').'</a></label>";
|
||||
html+= "</div>";
|
||||
html+= "</div>";
|
||||
$("#dr_option_rows").append(html);
|
||||
}
|
||||
</script>
|
||||
<div id="dr_option_rows"></div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('行数模式').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][option][is_hang]" value="1" '.($option['is_hang'] ? 'checked' : '').'> '.dr_lang('固定').' <span></span></label>
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][option][is_hang]" value="0" '.(!$option['is_hang'] ? 'checked' : '').'> '.dr_lang('无限').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('无限行数可以在录入数据时自由添加行数,固定行数就只能是录入上述的固定属性行数').'</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
return ['
|
||||
'.$str];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return dr_string2array($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
$data = [];
|
||||
$value = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
if ($value) {
|
||||
$i = 1;
|
||||
foreach ($value as $t) {
|
||||
$data[$i] = $t;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = dr_array2string($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $cname 字段别名
|
||||
* @param string $name 字段名称
|
||||
* @param array $cfg 字段配置
|
||||
* @param string $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
// 字段默认值
|
||||
$value = $value ? dr_string2array($value) : array();
|
||||
$str = '';
|
||||
$str.= ' <div class="scroller_'.$name.'_files">
|
||||
<div class="scroller" data-inited="0" data-initialized="1" data-always-visible="1" data-rail-visible="1">
|
||||
|
||||
<table class="table fc-sku-table table-striped table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="200" style="border-left-width: 1px!important;">'.dr_lang($field['setting']['option']['name_value'] ? $field['setting']['option']['name_value'] : dr_lang('名称')).' </th>
|
||||
<th>'.dr_lang($field['setting']['option']['value_value'] ? $field['setting']['option']['value_value'] : dr_lang('值')).' </th>';
|
||||
if (!$field['setting']['option']['is_hang']) {
|
||||
$str.='
|
||||
<th width="70" style="text-align: center"> ';
|
||||
|
||||
$str.= ' <a href="javascript:;" class="btn blue btn-xs" onClick="dr_add_property_'.$name.'()"> <i class="fa fa-plus"></i></a>';
|
||||
$str.='</th>';
|
||||
}
|
||||
$str.= '
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="property_'.$name.'-sort-items" class="scroller_body">';
|
||||
$i = 0;
|
||||
|
||||
unset($field['setting']['width']);
|
||||
// 固定属性选项
|
||||
if (isset($field['setting']['option']['default_value']) && $field['setting']['option']['default_value']) {
|
||||
$i = 1;
|
||||
foreach ($field['setting']['option']['default_value'] as $t) {
|
||||
if (!isset($t['name']) && $t['name']) {
|
||||
continue;
|
||||
}
|
||||
$str.= '<tr id="dr_items_'.$name.'_'.$i.'" class="dr_items_readonly">';
|
||||
$str.= '<td class="highlight"><input type="text" readonly class="form-control input-sm" value="'.$t['name'].'" name="data['.$name.']['.$i.'][name]"></td>';
|
||||
$str.= '<td>';
|
||||
switch ($t['type']) {
|
||||
case 1:
|
||||
$v = $value[$i]['value'] ? $value[$i]['value'] : $t['value'];
|
||||
$str.= '<input type="text" class="form-control input-sm" value="'.htmlspecialchars((string)$v).'" name="data['.$name.']['.$i.'][value]" />';
|
||||
break;
|
||||
case 2:
|
||||
$v = explode(',', $t['value']);
|
||||
$str.= '<select class="form-control" name="data['.$name.']['.$i.'][value]">';
|
||||
$str.= '<option value=""> -- </option>';
|
||||
if ($v) {
|
||||
foreach ($v as $c) {
|
||||
$selected = isset($value[$i]['value']) && $value[$i]['value'] == $c ? 'selected' : '';
|
||||
$str.= '<option value="'.$c.'" '.$selected.'> '.$c.' </option>';
|
||||
}
|
||||
}
|
||||
$str.= '</select>';
|
||||
break;
|
||||
case 3:
|
||||
$v = explode(',', $t['value']);
|
||||
if ($v) {
|
||||
foreach ($v as $c) {
|
||||
$selected = isset($value[$i]['value']) && dr_in_array($c, $value[$i]['value']) ? 'checked' : '';
|
||||
$str.= '<input type="checkbox" name="data['.$name.']['.$i.'][value][]" value="'.$c.'" ' . $selected . ' />'.$c.'';
|
||||
}
|
||||
}
|
||||
}
|
||||
$str.= '</td>';
|
||||
if (!$field['setting']['option']['is_hang']) {
|
||||
$str.= '<td>';
|
||||
$str.= '</td>';
|
||||
}
|
||||
$str.= '</tr>';
|
||||
unset($value[$i]);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
// 剩下自定义属性
|
||||
if ($value && !$field['setting']['option']['is_hang']) {
|
||||
foreach ($value as $t) {
|
||||
$str.= '<tr id="dr_items_'.$name.'_'.$i.'" class="dr_items_sort">';
|
||||
$str.= '<td><input type="text" class="form-control input-sm" value="'.htmlspecialchars((string)$t['name']).'" name="data['.$name.']['.$i.'][name]"></td>';
|
||||
$str.= '<td>';
|
||||
$str.= '<input type="text" class="form-control input-sm" value="'.htmlspecialchars((string)$t['value']).'" name="data['.$name.']['.$i.'][value]" />';
|
||||
$str.= '</td>';
|
||||
$str.= '<td style="text-align: center"><a class="btn btn-xs red" href="javascript:;" onclick="$(\'#dr_items_'.$name.'_'.$i.'\').remove()"> <i class="fa fa-trash"></i> </a>';
|
||||
$str.= '</td>';
|
||||
$str.= '</tr>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$str.= '
|
||||
</tbody>
|
||||
</table></div></div>';
|
||||
if (!$field['setting']['option']['is_hang']) {
|
||||
$js = \Phpcmf\Service::L('js_packer');
|
||||
$str.= $js->pack('<script type="text/javascript">
|
||||
$("#property_'.$name.'-sort-items").sortable({
|
||||
items: ".dr_items_sort"
|
||||
});
|
||||
dr_slimScroll_init(".scroller_'.$name.'_files", 300);
|
||||
var id='.($i).';
|
||||
function dr_add_property_'.$name.'() {
|
||||
if ($("#dr_items_'.$name.'_"+id).length>0) {
|
||||
id++;
|
||||
dr_tips(0, \''.dr_lang("序列生成重复,请重新添加").'\');
|
||||
return;
|
||||
}
|
||||
var html = "<tr id=\"dr_items_'.$name.'_"+id+"\">";
|
||||
html+= "<td><input type=\"text\" class=\"form-control input-sm\" value=\"\" name=\"data['.$name.']["+id+"][name]\"></td>";
|
||||
html+= "<td><input type=\"text\" class=\"form-control input-sm\" value=\"\" name=\"data['.$name.']["+id+"][value]\"></td>";
|
||||
html+= "<td style=\"text-align: center\"><a class=\"btn btn-xs red\" href=\"javascript:;\" onclick=\"$(\'#dr_items_'.$name.'_"+id+"\').remove()\"> <i class=\"fa fa-trash\"></i> </a></td></tr>";
|
||||
$("#property_'.$name.'-sort-items").append(html);
|
||||
dr_slimScroll_init(".scroller_'.$name.'_files", 300);
|
||||
id++;
|
||||
}
|
||||
</script>', 0);
|
||||
}
|
||||
|
||||
$str.= '<span class="help-block">'.$field['setting']['validate']['tips'].'</span>';
|
||||
return $this->input_format($field['fieldname'], $text, $str);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$str = '
|
||||
<table class="table table-striped table-bordered table-advance ">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="200" style="border-left-width: 1px!important;">'.dr_lang($field['setting']['option']['name_value'] ? $field['setting']['option']['name_value'] : dr_lang('名称')).' </th>
|
||||
<th>'.dr_lang($field['setting']['option']['value_value'] ? $field['setting']['option']['value_value'] : dr_lang('值')).' </th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
$i = 0;
|
||||
|
||||
unset($field['setting']['width']);
|
||||
// 默认属性选项
|
||||
if ($value) {
|
||||
$value = dr_string2array($value);
|
||||
foreach ($value as $t) {
|
||||
|
||||
$str.= '<tr>';
|
||||
$str.= '<td class="highlight">'.$t['name'].'</td>';
|
||||
$str.= '<td>'.$t['value'].'</td>';
|
||||
$str.= '</tr>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$str.= '
|
||||
</tbody>
|
||||
</table>';
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $str);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Radio extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = TRUE; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... )
|
||||
$this->defaulttype = 'VARCHAR'; // 当用户没有选择字段类型时的缺省值
|
||||
}
|
||||
|
||||
// 调出字段遍历出来
|
||||
protected function _get_select_field($option, $field, $id, $at) {
|
||||
|
||||
$str = '<div class="mt-checkbox-list">';
|
||||
foreach ($field as $t) {
|
||||
if ($t['disabled']) {
|
||||
continue;
|
||||
} elseif ($t['fieldtype'] == 'Merge') {
|
||||
continue;
|
||||
} elseif ($t['fieldtype'] == 'Group') {
|
||||
continue;
|
||||
}
|
||||
$str.= '<label class="mt-checkbox mt-checkbox-outline">';
|
||||
$str.= '<input type="checkbox" '.(dr_in_array($t['fieldname'], $option['field_ld'][$id][$at]) ? 'checked' : '').' name="data[setting][option][field_ld]['.$id.']['.$at.'][]" value="'.$t['fieldname'].'"> '
|
||||
.($t['setting']['validate']['required'] ? '<b class="required" aria-required="true"> * </b>' : '').$t['name'].' ';
|
||||
$str.= '<span></span>';
|
||||
$str.= '</label>';
|
||||
}
|
||||
$str.= '</div>';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option, $field = NULL) {
|
||||
|
||||
$data = dr_format_option_array($option['options']);
|
||||
if (!$data) {
|
||||
$ld = dr_lang('需要保存字段配置后才能配置联动关系');
|
||||
} else {
|
||||
$ld = '<div class="table-scrollable">';
|
||||
$ld.= '<table class="table table-striped table-bordered table-advance ">';
|
||||
$ld.= '<thead>';
|
||||
$ld.= '<tr>';
|
||||
$ld.= '<th width="120">'.dr_lang('选项').'</th>';
|
||||
$ld.= '<th>'.dr_lang('隐藏字段').'</th>';
|
||||
$ld.= '</tr>';
|
||||
$ld.= '</thead>';
|
||||
$ld.= '<tbody>';
|
||||
$data['dr_null'] = dr_lang('未选择时');
|
||||
foreach ($data as $id => $name) {
|
||||
$ld.= '<tr>';
|
||||
$ld.= '<td>'.$name.'</td>';
|
||||
$ld.= '<td>'.$this->_get_select_field($option, $field, $id, 'hide').'</td>';
|
||||
$ld.= '</tr>';
|
||||
}
|
||||
$ld.= '</tbody>';
|
||||
$ld.= '</table>';
|
||||
$ld.= '</div>';
|
||||
}
|
||||
|
||||
$option['options'] = isset($option['options']) ? $option['options'] : 'name1|1'.PHP_EOL.'name2|2';
|
||||
|
||||
|
||||
|
||||
return [
|
||||
'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('选项列表').'</label>
|
||||
<div class="col-md-9">
|
||||
<textarea class="form-control" name="data[setting][option][options]" style="height:150px;width:400px;">'.$option['options'].'</textarea>
|
||||
<span class="help-block">'.dr_lang('格式:选项名称|选项值[回车换行]选项名称2|值2....').'</span>
|
||||
<span class="help-block">'.dr_lang('选项值建议使用从1开始的数字,不得带符号,也可以省略不写').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('多语言翻译').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][lang]" '.(!$option['lang'] ? 'checked' : '').' > '.dr_lang('开启').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][lang]" '.($option['lang'] ? 'checked' : '').' > '.dr_lang('关闭').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('开启后选项值被系统语言包翻译,否则就保持原样显示').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('条件联动关联').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][is_field_ld]" onclick="$(\'#ldtjxx\').hide()" value="0" '.(!$option['is_field_ld'] ? 'checked' : '').'> '.dr_lang('关闭').'
|
||||
<span></span>
|
||||
</label>
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][is_field_ld]" onclick="$(\'#ldtjxx\').show()" value="1" '.($option['is_field_ld'] ? 'checked' : '').'> '.dr_lang('启用').'
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" id="ldtjxx" style="'.(!$option['is_field_ld'] ? 'display: none' : '').'">
|
||||
<label class="col-md-2 control-label">'.dr_lang('设置条件').'</label>
|
||||
<div class="col-md-9">
|
||||
'.$ld.'
|
||||
<span class="help-block">'.dr_lang('当选择某一个选项时会联动显示或隐藏指定的字段').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认选中项').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>'.$this->field_type($option['fieldtype'], $option['fieldlength']).'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('显示格式').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][show_type]" value="0" '.(!$option['show_type'] ? 'checked' : '').'> '.dr_lang('横排显示').'
|
||||
<span></span>
|
||||
</label>
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][show_type]" value="1" '.($option['show_type'] ? 'checked' : '').'> '.dr_lang('竖排显示').'
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
$str = '';
|
||||
|
||||
// 显示方式
|
||||
$show_type = (int)$field['setting']['option']['show_type'];
|
||||
|
||||
if ($field['setting']['option']['is_field_ld'] && $field['setting']['option']['field_ld']) {
|
||||
$str.= '<script>function field_ld_'.$name.'(v) {';
|
||||
$show = [];
|
||||
foreach ($field['setting']['option']['field_ld'] as $ii => $t) {
|
||||
if ($t['hide']) {
|
||||
foreach ($t['hide'] as $f) {
|
||||
if (in_array($f, $show)) {
|
||||
continue;
|
||||
}
|
||||
$show[] = $f;
|
||||
$str.= PHP_EOL.'$("#dr_row_'.$f.'").show();';
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($field['setting']['option']['field_ld'] as $ii => $t) {
|
||||
$str.= PHP_EOL.'if (v == "'.($ii == 'dr_null' ? '' : $ii).'") {';
|
||||
/*
|
||||
if ($t['show']) {
|
||||
foreach ($t['show'] as $f) {
|
||||
$str.= PHP_EOL.'$("#dr_row_'.$f.'").show();';
|
||||
}
|
||||
}*/
|
||||
if ($t['hide']) {
|
||||
foreach ($t['hide'] as $f) {
|
||||
$str.= PHP_EOL.'$("#dr_row_'.$f.'").hide();';
|
||||
}
|
||||
}
|
||||
$str.= PHP_EOL.'}';
|
||||
}
|
||||
$str.= '}';
|
||||
$str.= '$(function(){
|
||||
field_ld_'.$name.'("'.$value.'");
|
||||
});';
|
||||
$str.= '</script>';
|
||||
$field['setting']['validate']['formattr'].= ' onclick="field_ld_'.$name.'(this.value)"';
|
||||
}
|
||||
|
||||
// 表单选项
|
||||
$options = dr_format_option_array($field['setting']['option']['options']);
|
||||
if ($options) {
|
||||
foreach ($options as $v => $n) {
|
||||
$s = $v == $value ? ' checked' : '';
|
||||
$kj = '<input type="radio" name="data['.$name.']" value="'.$v.'" '.$s.' '.$field['setting']['validate']['formattr'].' />';
|
||||
$str.= '<label class="mt-radio mt-radio-outline">'.$kj.' '.(isset($field['setting']['option']['lang']) && $field['setting']['option']['lang'] ? $n : dr_lang($n)).' <span></span> </label>';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->input_format($name, $text, '<div class="'.(!$show_type ? 'mt-radio-inline' : 'mt-radio-list').'">'.$str.'</div>'.$tips);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$options = dr_format_option_array($field['setting']['option']['options']);
|
||||
|
||||
$str = '<div class="form-control-static"> '.(isset($options[$value]) ? dr_lang($options[$value]) : dr_lang('未选择')).' </div>';
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本代码基于MIT开源协议,协议规定此处版权信息不可去除
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Redirect extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = TRUE;
|
||||
$this->defaulttype = 'TEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
$option['width'] = isset($option['width']) ? $option['width'] : 400;
|
||||
return ['<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('适应范围').'</label>
|
||||
<div class="col-md-9">
|
||||
<p class="form-control-static">'.dr_lang('此字段只能用于模块内容自定义字段').'</p>
|
||||
</div>
|
||||
</div>', '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
$value = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
if ($value && !dr_is_url($value)) {
|
||||
$value = dr_url_prefix($value);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').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'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = isset($field['setting']['validate']['tips']) && $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$name.'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 字段默认值
|
||||
$value = $value && strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
// 当字段必填时,加入html5验证标签
|
||||
isset($field['setting']['validate']['required']) && $field['setting']['validate']['required'] == 1 && $attr.= ' required="required"';
|
||||
|
||||
$str = '<input class="form-control" type="text" name="data['.$name.']" id="dr_'.$name.'" value="'.$value.'" '.$style.' '.$attr.' />'.$tips;
|
||||
return $this->input_format($name, $text, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], '<div class="form-control-static"><a href="'.$value.'" target="_blank">'.$value.'</a></div>');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本代码基于MIT开源协议,协议规定此处版权信息不可去除
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Related extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['TEXT' => '']; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... )
|
||||
$this->defaulttype = 'TEXT'; // 当用户没有选择字段类型时的缺省值
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$_option = '';
|
||||
$_module = \Phpcmf\Service::C()->get_cache('module-'.SITE_ID.'-content');
|
||||
if ($_module) {
|
||||
foreach ($_module as $dir => $t) {
|
||||
$_option.= '<option value="'.$dir.'" '.($dir == $option['module'] ? 'selected' : '').'>'.$t['name'].'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
return [$this->_search_field().'<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('内容模块').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><select class="form-control" name="data[setting][option][module]">
|
||||
'.$_option.'
|
||||
</select></label>
|
||||
<span class="help-block">'.dr_lang('必须选择一个模块作为关联数据源').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('显示归属内容').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][my]" '.($option['my'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('开启之后只显示当前登录的用户自己所发布的内容').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('主题显示名称').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][title]" value="'.($option['title'] ? $option['title'] : dr_lang('主题')).'"></label>
|
||||
<span class="help-block">'.dr_lang('用于显示管理的主题字段名称,默认是:主题').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('最大选择数').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][limit]" value="'.$option['limit'].'"></label>
|
||||
<span class="help-block">'.dr_lang('最大能选择的数量限制').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('每页显示条数').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][pagesize]" value="'.$option['pagesize'].'"></label>
|
||||
<span class="help-block">'.dr_lang('选择列表分页条数,按多少条数据分页').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('友情提示').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="form-control-static">'.dr_lang('此字段不能参与搜索条件筛选').'</div>
|
||||
</div>
|
||||
</div>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*/
|
||||
public function output($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
$data = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
$limit = intval($field['setting']['option']['limit']);
|
||||
if ($limit && $data && count($data) > $limit) {
|
||||
// 超限了
|
||||
$value = implode(',', dr_arraycut($data, $limit));
|
||||
} else {
|
||||
$value = !$data ? '' : implode(',', $data);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $cname 字段别名
|
||||
* @param string $name 字段名称
|
||||
* @param array $cfg 字段配置
|
||||
* @param string $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
if (!IS_USE_MODULE) {
|
||||
return '使用本字段类别需要安装【建站系统】插件';
|
||||
}
|
||||
|
||||
$is_show = 0;
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
// 字段提示信息
|
||||
$tips = isset($field['setting']['validate']['tips']) && $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$name.'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
// 区域大小
|
||||
$area = \Phpcmf\Service::IS_MOBILE_USER() ? '["95%", "90%"]' : '["50%", "65%"]';
|
||||
// 模块名称
|
||||
$module = $mid = isset($field['setting']['option']['module']) ? $field['setting']['option']['module'] : '';
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
// 选择数量限制
|
||||
$limit = intval($field['setting']['option']['limit']);
|
||||
!$limit && $limit = 99999;
|
||||
// 输出信息
|
||||
$cname = ($field['setting']['option']['title'] ? $field['setting']['option']['title'] : dr_lang('主题'));
|
||||
|
||||
if (!$module) {
|
||||
if (CI_DEBUG) {
|
||||
return $this->input_format($name, $text, '<div class="form-control-static" style="color:red">关联字段没有设置关联模块</div>');
|
||||
}
|
||||
return $this->input_format($name, $text, '');
|
||||
} elseif (!dr_is_module($module)) {
|
||||
if (CI_DEBUG) {
|
||||
return $this->input_format($name, $text, '<div class="form-control-static" style="color:red">关联字段设置的模块【'.$module.'】没有被安装</div>');
|
||||
}
|
||||
return $this->input_format($name, $text, '');
|
||||
}
|
||||
|
||||
$value = $value ? trim($value, ',') : '';
|
||||
$mylist = [];
|
||||
if ($value && is_string($value)) {
|
||||
$arr = explode(',', $value);
|
||||
if ($arr) {
|
||||
$value = '';
|
||||
foreach ($arr as $a) {
|
||||
$a = intval($a);
|
||||
if ($a) {
|
||||
$value.= ','.$a;
|
||||
}
|
||||
}
|
||||
if ($value) {
|
||||
$value = trim($value, ',');
|
||||
$db = \Phpcmf\Service::M()->db->query('select * from '.\Phpcmf\Service::M()->dbprefix(dr_module_table_prefix($module)).' where id IN ('.$value.') order by FIELD(id, '.$value.')');
|
||||
$mylist = $db ? $db->getResultArray() : [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$file = \Phpcmf\Service::V()->code2php(
|
||||
file_get_contents(is_file(MYPATH.'View/api_related_field_'.$field['fieldname'].'.html') ? MYPATH.'View/api_related_field_'.$field['fieldname'].'.html' : COREPATH.'View/api_related_field.html')
|
||||
);
|
||||
ob_start();
|
||||
require $file;
|
||||
$str = ob_get_clean();
|
||||
|
||||
$str.= $tips;
|
||||
$js = \Phpcmf\Service::L('js_packer');
|
||||
$str.= $js->pack('
|
||||
<script type="text/javascript">
|
||||
|
||||
dr_slimScroll_init(".scroller_'.$name.'_files", 300);
|
||||
$("#related_'.$name.'-sort-items").sortable();
|
||||
function dr_add_related_'.$name.'() {
|
||||
var len = $(\'#related_'.$name.'-sort-items tr\').length;
|
||||
if (len >= '.$limit.') {
|
||||
dr_tips(0, "'.dr_lang('关联数量超限').'");
|
||||
return;
|
||||
}
|
||||
var url = "'.dr_web_prefix('index.php?s=module&c=api&m=related&name=').$name.'&site='.SITE_ID.'&module='.$module.'&diy='.$field['fieldname'].'&my='.intval($field['setting']['option']['my']).'&pagesize='.intval($field['setting']['option']['pagesize']).'&is_iframe=1";
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: \'<i class="fa fa-cog"></i> '.dr_lang('关联内容').'\',
|
||||
fix:true,
|
||||
shadeClose: true,
|
||||
shade: 0,
|
||||
area: '.$area.',
|
||||
btn: ["'.dr_lang('关联').'"],
|
||||
success: function (json) {
|
||||
if (json.code == 0) {
|
||||
layer.close();
|
||||
dr_tips(json.code, json.msg);
|
||||
}
|
||||
},
|
||||
yes: function(index, layero){
|
||||
var body = layer.getChildFrame(\'body\', index);
|
||||
// 延迟加载
|
||||
var loading = layer.load(2, {
|
||||
time: 10000
|
||||
});
|
||||
$.ajax({type: "POST",dataType:"json", url: url, data: $(body).find(\'#myform\').serialize(),
|
||||
success: function(json) {
|
||||
layer.close(loading);
|
||||
if (json.code == 1) {
|
||||
layer.close(index);
|
||||
if (len + json.data.ids.length > '.$limit.') {
|
||||
dr_tips(0, "'.dr_lang('关联数量超限').'");
|
||||
return;
|
||||
}
|
||||
for(var i in json.data.ids){
|
||||
var vid = json.data.ids[i];
|
||||
if (typeof vid != "undefined") {
|
||||
if($("#dr_items_'.$name.'_"+vid).length>0) {
|
||||
dr_tips(0, "'.dr_lang('已经存在').'");
|
||||
return;
|
||||
}
|
||||
if ($(\'#related_'.$name.'-sort-items tr\').length >= '.$limit.') {
|
||||
dr_tips(0, "'.dr_lang('关联数量超限').'");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$(\'#related_'.$name.'-sort-items\').append(json.data.html);
|
||||
dr_slimScroll_init(".scroller_'.$name.'_files", 300);
|
||||
dr_tips(1, json.msg);
|
||||
} else {
|
||||
dr_tips(0, json.msg);
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
content: url
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
</script>', 0);
|
||||
|
||||
return $this->input_format($name, $text, $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
|
||||
$cname = ($field['setting']['option']['title'] ? $field['setting']['option']['title'] : dr_lang('主题'));
|
||||
$value = @trim($value, ',');
|
||||
$mylist = [];
|
||||
$is_show = 1;
|
||||
$module = $mid = isset($field['setting']['option']['module']) ? $field['setting']['option']['module'] : '';
|
||||
if ($value && is_string($value) && $module) {
|
||||
$arr = explode(',', $value);
|
||||
if ($arr) {
|
||||
$value = '';
|
||||
foreach ($arr as $a) {
|
||||
$a = intval($a);
|
||||
if ($a) {
|
||||
$value.= ','.$a;
|
||||
}
|
||||
}
|
||||
if ($value) {
|
||||
$value = trim($value, ',');
|
||||
$db = \Phpcmf\Service::M()->db->query('select * from '.\Phpcmf\Service::M()->dbprefix(dr_module_table_prefix($module)).' where id IN ('.$value.') order by FIELD(id, '.$value.')');
|
||||
$mylist = $db ? $db->getResultArray() : [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = $field['fieldname'];
|
||||
$file = \Phpcmf\Service::V()->code2php(
|
||||
file_get_contents(is_file(MYPATH.'View/api_'.$tpl.'_field.html') ? MYPATH.'View/api_'.$tpl.'_field.html' : COREPATH.'View/api_related_field.html')
|
||||
);
|
||||
ob_start();
|
||||
require $file;
|
||||
$str = ob_get_clean();
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Score extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*/
|
||||
public function option($option, $field = null) {
|
||||
return ['', '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('显示游客组').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][guest]" '.($option['guest'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
|
||||
<span class="help-block">'.dr_lang('把游客组作为一个用户组来显示').'</span>
|
||||
</div>
|
||||
</div>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建sql语句
|
||||
*/
|
||||
public function create_sql($name, $value, $cname = '') {
|
||||
$sql = 'ALTER TABLE `{tablename}` ADD `'.$name.'` varchar(255) NULL , ADD `'.$name.'_sku` TEXT NULL';
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改sql语句
|
||||
*/
|
||||
public function alter_sql($name, $value, $cname = '') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除sql语句
|
||||
*/
|
||||
public function drop_sql($name) {
|
||||
$sql = 'ALTER TABLE `{tablename}` DROP `'.$name.'`, DROP `'.$name.'_sku`';
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// 测试字段是否被创建成功,默认成功为0,需要继承开发
|
||||
public function test_sql($tables, $field) {
|
||||
|
||||
if (!$tables) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($tables as $table) {
|
||||
if (!\Phpcmf\Service::M()->db->fieldExists($field.'_sku', $table)) {
|
||||
return '给表['.$table.']创建字段['.$field.'_sku'.']失败';
|
||||
}
|
||||
if (!\Phpcmf\Service::M()->db->fieldExists($field.'', $table)) {
|
||||
return '给表['.$table.']创建字段['.$field.''.']失败';
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
if ((int)$_POST['is_field_'.$field['fieldname']]) {
|
||||
// 用户组
|
||||
$sku = $_POST['data'][$field['fieldname'].'_sku'];
|
||||
$price = min($sku);
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $price;
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname'].'_sku'] = dr_array2string($sku);
|
||||
} else {
|
||||
// 单一
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $_POST['data'][$field['fieldname']];
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname'].'_sku'] = '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段输出
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function output($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = []) {
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 字段提示信息
|
||||
$tips = $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 模式
|
||||
$sku = dr_string2array(\Phpcmf\Service::L('Field')->value[$field['fieldname'].'_sku']);
|
||||
$html = '';
|
||||
if ($field['setting']['option']['guest']) {
|
||||
$group = dr_array22array([
|
||||
0 => [
|
||||
'id' => 0,
|
||||
'name' => dr_lang('游客'),
|
||||
],
|
||||
], \Phpcmf\Service::C()->member_cache['group']);
|
||||
} else {
|
||||
$group = \Phpcmf\Service::C()->member_cache['group'];
|
||||
}
|
||||
foreach ($group as $g) {
|
||||
$html.= '<label><div class="input-group">
|
||||
<span class="input-group-addon">'.$g['name'].'</span>
|
||||
<input type="text" class="form-control" name="data['.$field['fieldname'].'_sku]['.$g['id'].']" value="'.(string)$sku[$g['id']].'" />
|
||||
</div></label>';
|
||||
}
|
||||
$is_field = $sku? 1 : 0;
|
||||
|
||||
$str = '
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio">
|
||||
<input type="radio" onclick="$(\'#dr_field_'.$field['fieldname'].'\').show();$(\'#dr_field_'.$field['fieldname'].'2\').hide();" name="is_field_'.$field['fieldname'].'" value="0" '.(!$is_field ? 'checked' : '').'> '.dr_lang('全局').'
|
||||
<span></span>
|
||||
</label>
|
||||
<label class="mt-radio">
|
||||
<input type="radio" onclick="$(\'#dr_field_'.$field['fieldname'].'2\').show();$(\'#dr_field_'.$field['fieldname'].'\').hide();" name="is_field_'.$field['fieldname'].'" value="1" '.($is_field ? 'checked' : '').'> '.dr_lang('用户组').'
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
<div id="dr_field_'.$field['fieldname'].'" style="display:'.(!$is_field ? 'block' : 'none').';">
|
||||
<label><input class="form-control " type="text" name="data['.$field['fieldname'].']" id="dr_'.$field['fieldname'].'" value="'.$value.'" /></label>
|
||||
</div>
|
||||
<div id="dr_field_'.$field['fieldname'].'2" style="display:'.($is_field ? 'block' : 'none').';">
|
||||
<div style="width: 50%">
|
||||
'.$html.'
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
return $this->input_format($field['fieldname'], $text, $str.$tips);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').$field['name'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 模式
|
||||
$sku = dr_string2array(\Phpcmf\Service::L('Field')->value['score_sku']);
|
||||
$html = '';
|
||||
if ($field['setting']['option']['guest']) {
|
||||
$group = dr_array22array([
|
||||
0 => [
|
||||
'id' => 0,
|
||||
'name' => dr_lang('游客'),
|
||||
],
|
||||
], \Phpcmf\Service::C()->member_cache['group']);
|
||||
} else {
|
||||
$group = \Phpcmf\Service::C()->member_cache['group'];
|
||||
}
|
||||
foreach ($group as $g) {
|
||||
$html.= '<label><div class="input-group">
|
||||
<span class="input-group-addon">'.$g['name'].'</span>
|
||||
<input type="text" class="form-control" readonly name="data['.$field['fieldname'].'_sku]['.$g['id'].']" value="'.(string)$sku[$g['id']].'" />
|
||||
</div></label>';
|
||||
}
|
||||
|
||||
$is_field = $sku? 1 : 0;
|
||||
|
||||
$str = '
|
||||
<div id="dr_field_'.$field['fieldname'].'" style="display:'.(!$is_field ? 'block' : 'none').';">
|
||||
<label><input class="form-control " readonly type="text" name="data['.$field['fieldname'].']" id="dr_'.$field['fieldname'].'" value="'.$value.'" /></label>
|
||||
</div>
|
||||
<div id="dr_field_'.$field['fieldname'].'2" style="display:'.($is_field ? 'block' : 'none').';">
|
||||
<div style="width: 50%">
|
||||
'.$html.'
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
return $this->input_format($field['fieldname'], $text, $str.$tips);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Select extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = TRUE;
|
||||
$this->defaulttype = 'VARCHAR';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$option['options'] = isset($option['options']) ? $option['options'] : 'name1|1'.PHP_EOL.'name2|2';
|
||||
|
||||
return [
|
||||
'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('选项列表').'</label>
|
||||
<div class="col-md-9">
|
||||
<textarea class="form-control" name="data[setting][option][options]" style="height:150px;width:400px;">'.$option['options'].'</textarea>
|
||||
<span class="help-block">'.dr_lang('格式:选项名称|选项值[回车换行]选项名称2|值2....').'</span>
|
||||
<span class="help-block">'.dr_lang('选项值建议使用从1开始的数字,不得带符号,也可以省略不写').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('多语言翻译').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][lang]" '.(!$option['lang'] ? 'checked' : '').' > '.dr_lang('开启').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][lang]" '.($option['lang'] ? 'checked' : '').' > '.dr_lang('关闭').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('开启后选项值被系统语言包翻译,否则就保持原样显示').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认选中项').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('启用选项搜索').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][is_search]" '.($option['is_search'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
|
||||
<span class="help-block">'.dr_lang('当选项值过多时,可以在选择框中搜索选项值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
'
|
||||
.
|
||||
$this->field_type($option['fieldtype'], $option['fieldlength'])
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 表单附加参数
|
||||
$attr = $field['setting']['validate']['formattr'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 是否必填
|
||||
$required = $field['setting']['validate']['required'] ? ' required="required"' : '';
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
$str = '<label><select '.$required.' class="'.(isset($field['setting']['option']['is_search']) && $field['setting']['option']['is_search'] ? 'bs-select' : '').' form-control '.$field['setting']['option']['css'].'" '.(isset($field['setting']['option']['is_search']) && $field['setting']['option']['is_search'] ? ' data-live-search="true" ' : '').' name="data['.$name.']" id="dr_'.$name.'" '.$attr.' >';
|
||||
|
||||
// 表单选项
|
||||
$options = dr_format_option_array($field['setting']['option']['options']);
|
||||
if ($options) {
|
||||
foreach ($options as $v => $n) {
|
||||
$str.= '<option value="'.$v.'" '.($v == $value ? ' selected' : '').'>'.
|
||||
(isset($field['setting']['option']['lang']) && $field['setting']['option']['lang'] ? $n : dr_lang($n)).'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
$str.= '</select></label>'.$tips;
|
||||
|
||||
if (isset($field['setting']['option']['is_search']) && $field['setting']['option']['is_search']) {
|
||||
// 防止重复加载JS
|
||||
if (!$this->is_load_js($field['fieldtype'])) {
|
||||
$str.= $this->get_select_search_code();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->input_format($name, $text, $str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$options = dr_format_option_array($field['setting']['option']['options']);
|
||||
|
||||
$str = '<div class="form-control-static"> '.(isset($options[$value]) ? dr_lang($options[$value]) : dr_lang('未选择')).' </div>';
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $str);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Selects extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = TRUE;
|
||||
$this->defaulttype = 'VARCHAR';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$option['options'] = isset($option['options']) ? $option['options'] : 'name1|1'.PHP_EOL.'name2|2';
|
||||
|
||||
return [
|
||||
$this->_search_field().'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('选项列表').'</label>
|
||||
<div class="col-md-9">
|
||||
<textarea class="form-control" name="data[setting][option][options]" style="height:150px;width:400px;">'.$option['options'].'</textarea>
|
||||
<span class="help-block">'.dr_lang('格式:选项名称|选项值[回车换行]选项名称2|值2....').'</span>
|
||||
<span class="help-block">'.dr_lang('选项值建议使用从1开始的数字,不得带符号,也可以省略不写').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('多语言翻译').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="0" name="data[setting][option][lang]" '.(!$option['lang'] ? 'checked' : '').' > '.dr_lang('开启').' <span></span></label>
|
||||
|
||||
<label class="mt-radio mt-radio-outline"><input type="radio" value="1" name="data[setting][option][lang]" '.($option['lang'] ? 'checked' : '').' > '.dr_lang('关闭').' <span></span></label>
|
||||
</div>
|
||||
<span class="help-block">'.dr_lang('开启后选项值被系统语言包翻译,否则就保持原样显示').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认选中项').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('启用选项搜索').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][is_search]" '.($option['is_search'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
|
||||
<span class="help-block">'.dr_lang('当选项值过多时,可以在选择框中搜索选项值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
'
|
||||
.
|
||||
$this->field_type($option['fieldtype'], $option['fieldlength'])
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = dr_array2string(\Phpcmf\Service::L('Field')->post[$field['fieldname']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*/
|
||||
public function output($value) {
|
||||
return dr_string2array($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 表单附加参数
|
||||
$attr = $field['setting']['validate']['formattr'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 是否必填
|
||||
$required = $field['setting']['validate']['required'] ? ' required="required"' : '';
|
||||
|
||||
// 字段默认值
|
||||
if ($value) {
|
||||
$value = dr_string2array($value);
|
||||
} elseif ($field['setting']['option']['value']) {
|
||||
$value = $this->get_default_value($field['setting']['option']['value']);
|
||||
$value = is_array($value) ? $value : explode('|', $value);
|
||||
} else {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
$str = '<label style="min-width: 200px"><select '.$required.' class="bs-select form-control '.$field['setting']['option']['css'].'" '.(isset($field['setting']['option']['is_search']) && $field['setting']['option']['is_search'] ? ' data-live-search="true" ' : '').' data-actions-box="true" multiple="multiple" name="data['.$name.'][]" id="dr_'.$name.'" '.$attr.' >';
|
||||
|
||||
// 表单选项
|
||||
$options = dr_format_option_array($field['setting']['option']['options']);
|
||||
if ($options) {
|
||||
foreach ($options as $v => $n) {
|
||||
$str.= '<option value="'.$v.'" '.(dr_in_array($v, $value) ? ' selected' : '').'>'.(isset($field['setting']['option']['lang']) && $field['setting']['option']['lang'] ? $n : dr_lang($n)).'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
$str.= '</select></label>'.$tips;
|
||||
|
||||
// 防止重复加载JS
|
||||
if (!$this->is_load_js('Select')) {
|
||||
$str.= $this->get_select_search_code();
|
||||
}
|
||||
|
||||
return $this->input_format($name, $text, $str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$str = '';
|
||||
$value = dr_string2array($value);
|
||||
$options = dr_format_option_array($field['setting']['option']['options']);
|
||||
if ($options && $value) {
|
||||
foreach ($options as $v => $n) {
|
||||
is_array($value) && in_array($v, $value) && $str.= '<label class="label label-default"> '.$n.' </label> ';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], '<div class="form-control-static">'.$str.'</div>');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Text extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = TRUE;
|
||||
$this->defaulttype = 'VARCHAR';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$mcf = '';
|
||||
if (\Phpcmf\Service::M('field')->relatedname == 'module') {
|
||||
$mcf = '<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('验证重复').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][unique]" '.($option['unique'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('已开启').'" data-off-text="'.dr_lang('已关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('开启将会判断此字段的唯一性(本字段只对内容模块主表有效)').'</span>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
$style = '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('密码框模式').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][ispwd]" '.($option['ispwd'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('开启').'" data-off-text="'.dr_lang('关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
|
||||
<span class="help-block">'.dr_lang('开启之后它将作为密码框来显示').'</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
'.$mcf;
|
||||
|
||||
$option = $this->field_type($option['fieldtype'], $option['fieldlength']).'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认填充值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
return [$option, $style];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
// 格式化入库值
|
||||
$value = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
if (in_array($field['setting']['option']['fieldtype'], array('INT', 'TINYINT', 'SMALLINT'))) {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value ? (int)$value : 0;
|
||||
} elseif (in_array($field['setting']['option']['fieldtype'], array('DECIMAL', 'FLOAT'))) {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value ? (float)$value : 0;
|
||||
} elseif ($field['setting']['option']['fieldtype'] == 'MEDIUMINT') {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value ? $value : 0;
|
||||
} elseif (dr_strlen($value) == 1 && $value == '0') {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = '0';
|
||||
} else {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = dr_htmlspecialchars($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').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'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 当字段必填时,加入html5验证标签
|
||||
$required = $field['setting']['validate']['required'] ? ' required="required"' : '';
|
||||
|
||||
// 是否密码框
|
||||
$type = $field['setting']['option']['ispwd'] ? 'password' : 'text';
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
$str = '<input class="form-control '.($field['setting']['validate']['required'] ? 'dr_required' : '').' '.$field['setting']['option']['css'].'" type="'.$type.'" name="data['.$field['fieldname'].']" id="dr_'.$field['fieldname'].'" value="'.$value.'" '.$style.' '.$required.' '.$attr.' />';
|
||||
|
||||
return $this->input_format($field['fieldname'], $text, $str.$tips);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Textarea extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = TRUE;
|
||||
$this->defaulttype = 'TEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
|
||||
return ['
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认存储值').'</label>
|
||||
<div class="col-md-9">
|
||||
<textarea id="field_default_value" style="width: 90%;height: 100px;" class="form-control" name="data[setting][option][value]">'.$option['value'].'</textarea>
|
||||
<p><label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span></p>
|
||||
</div>
|
||||
</div>
|
||||
'.$this->field_type($option['fieldtype'], $option['fieldlength']),
|
||||
'<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件高度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][height]" value="'.$option['height'].'"></label>
|
||||
<label>px</label>
|
||||
</div>
|
||||
</div>'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字段显示
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
$html = '
|
||||
<div class="portlet bordered light">
|
||||
<div class="portlet-body">
|
||||
<div class="scroller" style="width:'.(\Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? ($field['setting']['option']['width'].(is_numeric($field['setting']['option']['width']) ? 'px' : '')) : '400px')).';height:'.($field['setting']['option']['height'] ? $field['setting']['option']['height'] : '100').'px" data-always-visible="1" data-rail-visible="1">
|
||||
'.nl2br(htmlspecialchars_decode((string)$value)).'
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
return $this->input_format($field['fieldname'], $field['name'], $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*/
|
||||
public function input($field, $value = '') {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 表单宽度设置
|
||||
$width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'] : '100%');
|
||||
|
||||
// 表单附加参数
|
||||
$attr = $field['setting']['validate']['formattr'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 表单高度设置
|
||||
$height = $field['setting']['option']['height'] ? $field['setting']['option']['height'] : '100';
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
$str = '<textarea class="form-control" style="height:'.$height.'px; width:'.$width.(is_numeric($width) ? 'px' : '').';" name="data['.$name.']" id="dr_'.$name.'" '.$attr.'>'.$value.'</textarea>';
|
||||
|
||||
return $this->input_format($name, $text, $str.$tips);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Textbtn extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = TRUE;
|
||||
$this->defaulttype = 'VARCHAR';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
|
||||
$style = '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图标样式').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][icon]" value="'.$option['icon'].'"></label>
|
||||
<span class="help-block">'.dr_lang('例如: fa fa-user').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图标名称').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][name]" value="'.$option['name'].'"></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('按钮颜色').'</label>
|
||||
<div class="col-md-9">
|
||||
<label>'.$this->_color_select('color', $option['color']).'</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('点击JS函数').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="text" class="form-control Large" size="10" name="data[setting][option][func]" value="'.$option['func'].'">
|
||||
<span class="help-block">'.dr_lang('单击按钮时执行的js函数').'</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
|
||||
$option = $this->field_type($option['fieldtype'], $option['fieldlength']).'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认填充值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
return [$option, $style];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
// 格式化入库值
|
||||
$value = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
|
||||
if (isset($field['setting']['option']['diy_insert_value']) && $field['setting']['option']['diy_insert_value']) {
|
||||
// 扩展字段函数
|
||||
list($a, $method) = explode(':', $field['setting']['option']['diy_insert_value']);
|
||||
$obj = \Phpcmf\Service::M($a);
|
||||
if (method_exists($obj, $method)) {
|
||||
$value = call_user_func([$obj, $method], $value);
|
||||
} else {
|
||||
log_message('error', '扩展函数方法 '.$field['setting']['option']['diy_insert_value'].' 不存在!');
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
if (isset($field['setting']['option']['diy_show_value']) && $field['setting']['option']['diy_show_value']) {
|
||||
// 扩展字段函数
|
||||
list($a, $method) = explode(':', $field['setting']['option']['diy_show_value']);
|
||||
$obj = \Phpcmf\Service::M($a);
|
||||
if (method_exists($obj, $method)) {
|
||||
$value = call_user_func([$obj, $method], $value);
|
||||
} else {
|
||||
log_message('error', '扩展函数方法 '.$field['setting']['option']['diy_show_value'].' 不存在!');
|
||||
}
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').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'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 当字段必填时,加入html5验证标签
|
||||
$required = $field['setting']['validate']['required'] ? ' required="required"' : '';
|
||||
|
||||
// 按钮颜色
|
||||
$color = $field['setting']['option']['color'] ? $field['setting']['option']['color'] : 'default';
|
||||
|
||||
// 函数
|
||||
$func = $field['setting']['option']['func'] ? $field['setting']['option']['func'] : 'dr_diy_func';
|
||||
|
||||
$ipt = '<input class="form-control '.$field['setting']['option']['css'].'" type="text" name="data['.$field['fieldname'].']" id="dr_'.$field['fieldname'].'" value="'.$value.'" '.$required.' '.$attr.' />';
|
||||
$str = '
|
||||
<div class="input-group" '.$style.'>
|
||||
'.$ipt.'
|
||||
<span class="input-group-btn">
|
||||
<a class="btn btn-success " style="border-color:'.$color.';background-color:'.$color.'" href="javascript:'.$func.'(\''.$name.'\');" ><i class="'.dr_icon($field['setting']['option']['icon']).'" /></i> '.dr_lang($field['setting']['option']['name']).'</a>
|
||||
</span>
|
||||
</div>
|
||||
';
|
||||
|
||||
return $this->input_format($field['fieldname'], $text, $str.$tips);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
if (isset($field['setting']['option']['diy_show_value']) && $field['setting']['option']['diy_show_value']) {
|
||||
// 扩展字段函数
|
||||
list($a, $method) = explode(':', $field['setting']['option']['diy_show_value']);
|
||||
$obj = \Phpcmf\Service::M($a);
|
||||
if (method_exists($obj, $method)) {
|
||||
$value = call_user_func([$obj, $method], $value);
|
||||
} else {
|
||||
log_message('error', '扩展函数方法 '.$field['setting']['option']['diy_show_value'].' 不存在!');
|
||||
}
|
||||
}
|
||||
|
||||
$str = '<div class="form-control-static"> '.htmlspecialchars_decode((string)$value).' </div>';
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Textselect extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = TRUE;
|
||||
$this->defaulttype = 'TEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
$option['options'] = isset($option['options']) ? $option['options'] : '选项名称1'.PHP_EOL.'选项名称2';
|
||||
|
||||
|
||||
$style = '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('密码框模式').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][ispwd]" '.($option['ispwd'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('开启').'" data-off-text="'.dr_lang('关闭').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
|
||||
<span class="help-block">'.dr_lang('开启之后它将作为密码框来显示').'</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
';
|
||||
|
||||
$option = $this->field_type($option['fieldtype'], $option['fieldlength']).'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('选项列表').'</label>
|
||||
<div class="col-md-9">
|
||||
<textarea class="form-control" name="data[setting][option][options]" style="height:150px;width:400px;">'.$option['options'].'</textarea>
|
||||
<span class="help-block">'.dr_lang('格式:选项名称1[回车换行]选项名称2....').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认填充值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
return [$option, $style];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
// 格式化入库值
|
||||
$value = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
if (in_array($field['setting']['option']['fieldtype'], array('INT', 'TINYINT', 'SMALLINT'))) {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value ? (int)$value : 0;
|
||||
} elseif (in_array($field['setting']['option']['fieldtype'], array('DECIMAL', 'FLOAT'))) {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value ? (float)$value : 0;
|
||||
} elseif ($field['setting']['option']['fieldtype'] == 'MEDIUMINT') {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value ? $value : 0;
|
||||
} elseif (dr_strlen($value) == 1 && $value == '0') {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = '0';
|
||||
} else {
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = dr_htmlspecialchars($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').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'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 当字段必填时,加入html5验证标签
|
||||
$required = $field['setting']['validate']['required'] ? ' required="required"' : '';
|
||||
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
|
||||
$str = '';
|
||||
if (!$this->is_load_js($field['fieldtype'])) {
|
||||
$str.= '
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/jquery.editable-select/jquery.editable-select.min.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/jquery.editable-select/jquery.editable-select.min.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
';
|
||||
$this->set_load_js($field['fieldtype'], 1);
|
||||
}
|
||||
|
||||
//$str = '<input class="form-control '.($field['setting']['validate']['required'] ? 'dr_required' : '').' '.$field['setting']['option']['css'].'" type="'.$type.'" name="data['.$field['fieldname'].']" id="dr_'.$field['fieldname'].'" value="'.$value.'" '.$style.' '.$required.' '.$attr.' />';
|
||||
|
||||
$options = dr_format_option_array($field['setting']['option']['options']);
|
||||
$str.= '
|
||||
<select id="editable-select-'.$name.'" class="form-control es-input '.($field['setting']['validate']['required'] ? 'dr_required' : '').' '.$field['setting']['option']['css'].'" name="data['.$field['fieldname'].']" id="dr_'.$field['fieldname'].'" value="'.$value.'" '.$style.' '.$required.' '.$attr.'></select>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
var data = '.json_encode($options).';
|
||||
$.each(data, function (i, r) {
|
||||
$("#editable-select-'.$name.'").append(\'<option>\' + r + \'</option>\');
|
||||
});
|
||||
$(\'#editable-select-'.$name.'\').editableSelect({
|
||||
effects: \'slide\',//点击的时候,下拉框的过渡效果 有default,slide,fade三个值,默认是default
|
||||
filter: false,//选择option以后,是否过滤 默认 true
|
||||
duration: \'fast\',//下拉选项框展示的过度动画速度
|
||||
});
|
||||
});
|
||||
</script>
|
||||
';
|
||||
|
||||
return $this->input_format($field['fieldname'], $text, $str.$tips);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Time extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['VARCHAR' => 100];
|
||||
$this->defaulttype = 'VARCHAR';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
return ['
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('字段格式').'</label>
|
||||
<div class="col-md-9">
|
||||
<div class="mt-radio-inline">
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][format2]" value="0" '.(!$option['option']['format2'] ? 'checked' : '').'> '.dr_lang('时分格式').'
|
||||
<span></span>
|
||||
</label>
|
||||
<label class="mt-radio mt-radio-outline">
|
||||
<input type="radio" name="data[setting][option][format2]" value="1" '.($option['option']['format2'] ? 'checked' : '').'> '.dr_lang('时分秒格式').'
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认存储值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
'.$this->field_type($option['fieldtype'], $option['fieldlength'])
|
||||
|
||||
,
|
||||
|
||||
'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('按钮颜色').'</label>
|
||||
<div class="col-md-9">
|
||||
<label>'.$this->_color_select('color', $option['color']).'</label>
|
||||
</div>
|
||||
</div>
|
||||
'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建sql语句
|
||||
*/
|
||||
public function create_sql($name, $option, $cname = '') {
|
||||
// 时间字符串:VARCHAR(100)
|
||||
$type = 'VARCHAR(100)';
|
||||
$info = 'DEFAULT NULL';
|
||||
$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 $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @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'] ? '<span class="required" aria-required="true"> * </span>' : '').dr_lang($field['name']);
|
||||
|
||||
// 表单宽度设置
|
||||
$width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'] : 100);
|
||||
|
||||
// 风格
|
||||
$style = 'style="width:'.$width.(is_numeric($width) ? 'px' : '').';"';
|
||||
|
||||
// 表单附加参数
|
||||
$attr = $field['setting']['validate']['formattr'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 格式显示
|
||||
$format = (int)$field['setting']['option']['format2'] ? 'H:i:s' : 'H:i';
|
||||
// 按钮颜色
|
||||
$color = $field['setting']['option']['color'] ? $field['setting']['option']['color'] : 'default';
|
||||
|
||||
// 是否必填
|
||||
$required = $field['setting']['validate']['required'] ? ' required="required"' : '';
|
||||
|
||||
$str = '';
|
||||
if (!$this->is_load_js($field['fieldtype'])) {
|
||||
$str.= '
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-timepicker/css/bootstrap-timepicker.min.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-timepicker/js/bootstrap-timepicker.min.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
';
|
||||
$this->set_load_js($field['fieldtype'], 1);
|
||||
}
|
||||
|
||||
// 字段默认值
|
||||
!$value && $value = $this->get_default_value($field['setting']['option']['value']);
|
||||
if ($value == 'SYS_TIME') {
|
||||
$value = dr_date(SYS_TIME, $format);
|
||||
}
|
||||
|
||||
$str.= '<div class="input-group ">';
|
||||
$shuru = '<input name="data['.$name.']" type="text" '.$style.' value="'.$value.'" '.$required.' class="form-control timepicker field_time_'.$name.' '.$field['setting']['option']['css'].'">';
|
||||
$tubiao = '<span class="input-group-btn"><button class="btn '.$color.'" type="button">
|
||||
<i class="fa fa-clock-o"></i>
|
||||
</button>
|
||||
</span>';
|
||||
$str.= $field['setting']['option']['is_left'] ? $tubiao.$shuru : $shuru.$tubiao;
|
||||
|
||||
$str.= '</div>';
|
||||
$js = \Phpcmf\Service::L('js_packer');
|
||||
$str.= $js->pack('
|
||||
<script>
|
||||
$(function(){
|
||||
$(".field_time_'.$name.'").timepicker({
|
||||
autoclose: true,
|
||||
defaultTime:"'.($value ? $value : dr_date(SYS_TIME, $format)).'",
|
||||
minuteStep: 1,
|
||||
secondStep: 1,
|
||||
showSeconds: '.($format == 'H:i:s' ? 'true' : 'false').',
|
||||
showMeridian: false
|
||||
});
|
||||
$(".timepicker").parent(".input-group").on("click", ".input-group-btn", function(e){
|
||||
$(this).parent(".input-group").find(".timepicker").timepicker("showWidget");
|
||||
});
|
||||
$( document ).scroll(function(){
|
||||
$(".field_time_'.$name.'").timepicker("place");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
', 0);
|
||||
$str.= $tips;
|
||||
|
||||
return $this->input_format($name, $text, '<div class="form-date input-group">'.$str.'</div>');
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
$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'], '<div class="form-control-static"><span> '.$value.' </span></div>');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Touchspin extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['INT','TINYINT','SMALLINT','MEDIUMINT','DECIMAL','FLOAT'];
|
||||
$this->defaulttype = 'INT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
|
||||
$style = '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('显示模式').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="checkbox" name="data[setting][option][show]" '.($option['show'] ? 'checked' : '').' value="1" data-on-text="'.dr_lang('按钮').'" data-off-text="'.dr_lang('箭头').'" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
|
||||
<span class="help-block">'.dr_lang('按钮模式是左右两个加减按钮;箭头模式是左边上下箭头符号').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('加按钮class').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][up]" value="'.$option['up'].'"></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('减按钮class').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][down]" value="'.$option['down'].'"></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
';
|
||||
|
||||
|
||||
$option = '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('最大值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][max]" value="'.$option['max'].'"></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('最小值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][min]" value="'.$option['min'].'"></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('步长值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][step]" value="'.$option['step'].'"></label>
|
||||
</div>
|
||||
</div>
|
||||
'.$this->field_type($option['fieldtype'], $option['fieldlength']).'
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('默认填充值').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input id="field_default_value" type="text" class="form-control" size="20" value="'.$option['value'].'" name="data[setting][option][value]"></label>
|
||||
<label>'.$this->member_field_select().'</label>
|
||||
<span class="help-block">'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
return [$option, $style];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
// 格式化入库值
|
||||
$value = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
$value = in_array($field['setting']['option']['fieldtype'], ['DECIMAL', 'FLOAT']) ? ($value ? (float)$value : 0) : ($value ? (int)$value : 0);
|
||||
|
||||
// 最大值判断
|
||||
$field['setting']['option']['max'] && $value = min($field['setting']['option']['max'], $value);
|
||||
|
||||
// 最小值判断
|
||||
$field['setting']['option']['min'] && $value = max($field['setting']['option']['min'], $value);
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').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'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 当字段必填时,加入html5验证标签
|
||||
$required = $field['setting']['validate']['required'] ? ' required="required"' : '';
|
||||
|
||||
// 按钮颜色
|
||||
$up = $field['setting']['option']['up'] ? $field['setting']['option']['up'] : 'default';
|
||||
$down = $field['setting']['option']['down'] ? $field['setting']['option']['down'] : 'default';
|
||||
|
||||
// 字段默认值
|
||||
$value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']);
|
||||
|
||||
$str = '';
|
||||
|
||||
if (!$this->is_load_js($field['fieldtype'])) {
|
||||
$str.= '
|
||||
<link href="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-touchspin/bootstrap.touchspin.min.css?v='.CMF_UPDATE_TIME.'" rel="stylesheet" type="text/css" />
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/fuelux/js/spinner.min.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
<script src="'.ROOT_THEME_PATH.'assets/global/plugins/bootstrap-touchspin/bootstrap.touchspin.js?v='.CMF_UPDATE_TIME.'" type="text/javascript"></script>
|
||||
';
|
||||
$this->set_load_js($field['fieldtype'], 1);
|
||||
}
|
||||
|
||||
!$field['setting']['option']['max'] && $field['setting']['option']['max'] = 999999999999999;
|
||||
!$field['setting']['option']['min'] && $field['setting']['option']['min'] = 0;
|
||||
|
||||
$str.= '<div '.$style.'><input class="form-control '.$field['setting']['option']['css'].'" type="text" name="data['.$field['fieldname'].']" id="dr_'.$field['fieldname'].'" value="'.$value.'" '.$required.' '.$attr.' /></div>';
|
||||
$js = \Phpcmf\Service::L('js_packer');
|
||||
$xs = 0;
|
||||
if (strpos($field['setting']['option']['step'], '.')) {
|
||||
list($a, $b) = explode('.', $field['setting']['option']['step']);
|
||||
$xs = dr_strlen($b);
|
||||
}
|
||||
|
||||
$str.= $js->pack('<script type="text/javascript">
|
||||
$(function(){
|
||||
$("#dr_'.$field['fieldname'].'").TouchSpin({
|
||||
buttondown_class: "btn '.$down.'",
|
||||
buttonup_class: "btn '.$up.'",
|
||||
verticalbuttons: '.(!$field['setting']['option']['show'] ? 'true' : 'false').',
|
||||
decimals: '.$xs.',
|
||||
step: '.$field['setting']['option']['step'].',
|
||||
min: '.$field['setting']['option']['min'].',
|
||||
max: '.$field['setting']['option']['max'].'
|
||||
});
|
||||
});
|
||||
</script>', 0);
|
||||
|
||||
|
||||
return $this->input_format($field['fieldname'], $text, $str.$tips);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
<?php namespace Phpcmf\Field;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件,可以通过继承类方法来重写此文件
|
||||
**/
|
||||
|
||||
class Uid extends \Phpcmf\Library\A_Field {
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct(...$params) {
|
||||
parent::__construct(...$params);
|
||||
$this->fieldtype = ['INT' => 10];
|
||||
$this->defaulttype = 'INT';
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段相关属性参数
|
||||
*
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function option($option) {
|
||||
|
||||
|
||||
$style = '
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('控件宽度').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][width]" value="'.$option['width'].'"></label>
|
||||
<span class="help-block">'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图标样式').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][icon]" value="'.$option['icon'].'"></label>
|
||||
<span class="help-block">'.dr_lang('例如: fa fa-user').'</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('图标名称').'</label>
|
||||
<div class="col-md-9">
|
||||
<label><input type="text" class="form-control" size="10" name="data[setting][option][name]" value="'.$option['name'].'"></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('按钮颜色').'</label>
|
||||
<div class="col-md-9">
|
||||
<label>'.$this->_color_select('color', $option['color']).'</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">'.dr_lang('点击JS函数').'</label>
|
||||
<div class="col-md-9">
|
||||
<input type="text" class="form-control Large" size="10" name="data[setting][option][func]" value="'.$option['func'].'">
|
||||
<span class="help-block">'.dr_lang('单击按钮时执行的js函数').'</span>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
return ['', $style];
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段入库值
|
||||
*
|
||||
* @param array $field 字段信息
|
||||
* @return void
|
||||
*/
|
||||
public function insert_value($field) {
|
||||
|
||||
// 格式化入库值
|
||||
$value = \Phpcmf\Service::L('Field')->post[$field['fieldname']];
|
||||
if ($value) {
|
||||
$value = \Phpcmf\Service::M('member')->uid($value);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单输入
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function input($field, $value = null) {
|
||||
|
||||
// 字段禁止修改时就返回显示字符串
|
||||
if ($this->_not_edit($field, $value)) {
|
||||
return $this->show($field, $value);
|
||||
}
|
||||
|
||||
// 字段默认值
|
||||
if (dr_strlen($value)) {
|
||||
if (is_numeric($value)) {
|
||||
// 由uid获取用户名
|
||||
$user = \Phpcmf\Service::M('member')->username($value);
|
||||
if ($user) {
|
||||
$value = $user;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$value = \Phpcmf\Service::C()->member ? \Phpcmf\Service::C()->member['username'] : '';
|
||||
}
|
||||
|
||||
// 字段存储名称
|
||||
$name = $field['fieldname'];
|
||||
|
||||
// 字段显示名称
|
||||
$text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').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'];
|
||||
|
||||
// 字段提示信息
|
||||
$tips = $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';
|
||||
|
||||
// 当字段必填时,加入html5验证标签
|
||||
$required = $field['setting']['validate']['required'] ? ' required="required"' : '';
|
||||
|
||||
// 按钮颜色
|
||||
$color = $field['setting']['option']['color'] ? $field['setting']['option']['color'] : 'default';
|
||||
|
||||
$ipt = '<input class="form-control '.$field['setting']['option']['css'].'" type="text" name="data['.$field['fieldname'].']" id="dr_'.$field['fieldname'].'" value="'.$value.'" '.$required.' '.$attr.' />';
|
||||
if (IS_ADMIN) {
|
||||
$str = '
|
||||
<div class="input-group" '.$style.'>
|
||||
'.$ipt.'
|
||||
<span class="input-group-btn">
|
||||
<a class="btn btn-success " style="border-color:'.$color.';background-color:'.$color.'" href="javascript:dr_show_member(\''.$name.'\');" ><i class="fa fa-user" /></i> '.dr_lang('资料').'</a>
|
||||
</span>
|
||||
</div>
|
||||
';
|
||||
} else {
|
||||
$str = $ipt;
|
||||
}
|
||||
|
||||
return $this->input_format($field['fieldname'], $text, $str.$tips);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段表单显示
|
||||
*
|
||||
* @param string $field 字段数组
|
||||
* @param array $value 值
|
||||
* @return string
|
||||
*/
|
||||
public function show($field, $value = null) {
|
||||
|
||||
// 字段默认值
|
||||
if ($value) {
|
||||
$value = \Phpcmf\Service::M('member')->author($value);
|
||||
} else {
|
||||
$value = \Phpcmf\Service::C()->member ? \Phpcmf\Service::C()->member['username'] : '';
|
||||
}
|
||||
|
||||
$str = '<div class="form-control-static"> '.htmlspecialchars_decode((string)$value).' </div>';
|
||||
|
||||
return $this->input_format($field['fieldname'], $field['name'], $str);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user