字段表单输入

@param	string	$cname	字段别名
@param	string	$name	字段名称
@param	array	$cfg	字段配置
@param	string	$value	值
@return  string
182803
public function input($cname, $name, $cfg, $value = NULL, $id = 0) 
	{
		$areaid1 = isset($cfg['option']['areaid1']) ? $cfg['option']['areaid1'] : '';
		$areaid2 = isset($cfg['option']['areaid2']) ? $cfg['option']['areaid2'] : '';
		$areaid3 = isset($cfg['option']['areaid3']) ? $cfg['option']['areaid3'] : '';

		// 字段显示名称
		$text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font> ' : '').$cname.'';
		// 表单附加参数
		$attr = '';
		// 字段提示信息
		$tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? $cfg['validate']['tips'] : '';
		// 字段默认值
		$vInfo = [
			'joinids'=>[0,0,0]
		];
		if (!$value && $areaid3) {
			$vInfo = CommonAreaModel::getInfoByAreaid($areaid3, false);
		} else if (!$value && $areaid1 && $areaid2 && !$areaid3) {
			$vInfo = [
				'joinids'=>[$areaid1, $areaid2, 0]
			];
		} else if (!$value && $areaid1 && !$areaid2 && !$areaid3) {
			$vInfo = [
				'joinids'=>[$areaid1, 0, 0]
			];
		} else {
			if($value) {
				$vInfo = $value;
			}
		}
		$show =  '';
		$disabled = !$this->isadmin &&  $id && $value && isset($cfg['validate']['isedit']) && !$cfg['validate']['isedit'] ? ' disabled' : ' ';
		$required = isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? ' required="required"' : '';
		$str = '';
		$option1 = '';
		$areaList = CommonAreaModel::getSubByAreaid(0, false);
		foreach ($areaList as $key => $value) {
			$option1 .= '<option value="'.$value['areaid'].'" '.hst_isSelected($vInfo && $value['areaid'] == $vInfo['joinids'][0]).'>'.$value['name'].'</option>';
		}
		$str.= '<select '.$disabled.' name="'.$name.'1" class="hstui-input hstui-select J_areaAjax_'.$name.'" data-toid="hstcms_'.$name.'2" id="hstcms_'.$name.'1" data-area="1" data-tips="请选择省份">
					<option value="">请选择省份</option>
					'.$option1.'
	            </select>
	            <select '.$disabled.'  name="'.$name.'2" class="hstui-input hstui-select J_areaAjax_'.$name.'" data-toid="hstcms_'.$name.'3" id="hstcms_'.$name.'2" data-area="2" data-tips="请选择城市">
					<option value="">请选择城市</option>
	            </select>
	            <select '.$disabled.' name="'.$name.'3" class="hstui-input hstui-select" id="hstcms_'.$name.'3"  data-area="3" data-tips="请选择县(区)">
					<option value="">请选择县(区)</option>
	            </select>';
        $str .='
            <script>
            var '.$name.'1 = '.(int)$vInfo['joinids'][0].';
            var '.$name.'2 = '.(int)$vInfo['joinids'][1].';
            var '.$name.'3 = '.(int)$vInfo['joinids'][2].';
                Hstui.use(\'jquery\',function(){
                	function setArea_'.$name.'(areaid, toid, area, id) {
						var url = \''.route('publicAreaList').'\';
						var tips = $(\'#\'+toid).data(\'tips\')
						if(typeof(toid) !== \'undefined\') {
							var option = \'<option value="">\'+tips+\'</option>\';
							$.get(url + \'?areaid=\'+areaid,function(data, status){
							    if(data.length) {
							    	var selected = \'\';
							    	for (var i=0; i < data.length; i++) {
							    		selected = \'\';
							    		if(id == data[i].areaid) {
							    			selected = \'selected\';
							    		}
							    		option +=\'<option \'+selected+\' value="\'+data[i].areaid+\'">\'+data[i].name+\'</option>\';
							    	}
							    }
							    $(\'#\'+toid).html(option);
							}, \'json\');
						}
                	}
                	if('.$name.'1) {
                		setArea_'.$name.'('.$name.'1, \'hstcms_'.$name.'2\', 1, '.$name.'2);
                	}
                	if('.$name.'2) {
                		setArea_'.$name.'('.$name.'2, \'hstcms_'.$name.'3\', 2, '.$name.'3);
                	}
					$(".J_areaAjax_'.$name.'").on(\'change\',function(){
						var _this=$(this),val=_this.val(),toid=_this.data(\'toid\'),area=_this.data(\'area\');
						setArea_'.$name.'(val, toid, area);
						if(area == 1) {
                			setArea_'.$name.'(0, \'hstcms_'.$name.'3\');
						}
					});
                });
            </script>';
		return $this->input_format($name, $text, $str, $tips);
	}
861539
public function set($name, $value) {
        N('cache_write',1);
        $this->open();
        $value  =   serialize($value);
        $name   =   $this->options['prefix'].$name;        
        $s      =   'S' . pack('NN', strlen($name), strlen($value)) . $name . $value;

        fwrite($this->handler, $s);
        $ret = fgets($this->handler);
        $this->close();
        if($ret === "OK\n") {
            if($this->options['length']>0) {
                // 记录缓存队列
                $this->queue($name);
            }
            return true;
        }
        return false;
    }
57783
public function set($name, $value = '', $option = null) {
        // 参数设置(会覆盖黙认设置)
        if (!is_null($option)) {
            if (is_numeric($option)) {
                $option = ['expire' => $option];
            }
            elseif (is_string($option)) {
                parse_str($option, $option);
            }
            $config = array_merge($this->config, array_change_key_case($option));
        }
        else {
            $config = $this->config;
        }
        $name = $config['prefix'] . $name;
        // 设置cookie
        if (is_array($value)) {
            array_walk_recursive($value, 'self::jsonFormatProtect', 'encode');
            $value = 'nb:' . json_encode($value);
        }
        $expire = !empty($config['expire']) ? Request::ins()->requestTime + intval($config['expire']) : 0;
        $this->response->cookie($name, $value, $expire, $config['path'], $config['domain'], $config['secure'], $config['httponly']);
        $this->request->cookie[$name] = $value;
    }
504143
protected function getConfig($cfg, $name = null)
    {
        if (is_null($name)) {
            $name = $this->apiName;
        }

        $name = $name ? ".$name" : '';

        return config("api.$cfg{$name}");
    }
512128
public function getForeignKey(string $name = null)
    {
        // 构造 查询语句
        $sql = $this->db->getCreate($name ? $name : $this->tableName);
        $result = $this->query($sql);

        // 分析结果
        $statement = $result[0]['Create Table'];
        $matched = preg_match_all('/CONSTRAINT\s\S*\sFOREIGN\sKEY\s\(`([^`]*)`\) REFERENCES `([^`]*)` \(`([^`]*)`\)/i', $statement, $matches, PREG_SET_ORDER);
        if (!$matched) {
            return false;
        }

        // 如果有多个
        $fks = [];
        foreach ($matches as $m) {
            $fks[$m[1]] = [
                'table' => $m[2],
                'field' => $m[3]
            ];
        }
        return $fks;
    }
776050
public function config($name, $value = null)
    {
        if (func_num_args() === 1) {
            return $this["config"]->get($name);
        }

        return $this["config"]->set($name, $value);
    }
1048194
private function IsLegalValue($Name, $ClassName, $Value)
        {
            // 取得合法資料內容
            $ReflectionObject = new ReflectionClass($ClassName);
            $ContentList = $ReflectionObject->getConstants();
            unset($ReflectionObject);

            // 檢查是否為合法資料
            if (! in_array($Value, $ContentList)) {
                throw new Exception('Illegal '.$Name.'.');
            }
        }
186824
public static function patch( $name = '', $value = '' ) {

		if ( ! empty( $value ) ) {
			$GLOBALS['_PATCH'][ $name ] = $value;
		}

		if ( empty( $name ) ) {
			return ( isset( $GLOBALS['_PATCH'] ) ) ? $GLOBALS['_PATCH'] : NULL;
		} else {
			return ( isset( $GLOBALS['_PATCH'][ $name ] ) ) ? $GLOBALS['_PATCH'][ $name ] : NULL;
		}

	}
992619
protected function castConfigValue($name, $value)
	{
		foreach ($this->configTypes as list($nameRegexp, $valueRegexp, $methodName))
		{
			if (preg_match($nameRegexp, $name) && preg_match($valueRegexp, $value))
			{
				return $this->$methodName($value);
			}
		}

		return $value;
	}
761798
public function outputFormat($value, $name)
    {
        $strLen = mb_substr($value, 0, 64);
        $strValue = mb_substr($value, 64);
        $match = [];

        if (preg_match('/^[0]+([a-f0-9]+)$/', $strLen, $match) === 1) {
            $strLen = BigNumberFormatter::format('0x' . $match[1])->toString();
        }
        $strValue = mb_substr($strValue, 0, (int) $strLen * 2);

        return Utils::hexToBin($strValue);
    }
300267
static public function tuieditor($name, $value=null, $settings=array())
    {
        $form_id    = isset($settings['id']) ? static::formatId($settings['id']) : static::formatId($name);
        if (empty($value)) {
            $value = "### 编辑内容";
        }
        
        $defultSettings = array(
            'width'     => "100%",
            'height'    => "400",
        );
        $settings = array_merge($defultSettings, $settings);
        
        $str = "";
        
        $str .= <<<EOF
        <div id="tuieditor_box">

        </div>
EOF;
        // 此处动态加载有问题，不能直接运行脚本
        if (!isset(static::$isLoaded['tuieditor']) || !static::$isLoaded['tuieditor']) {
            $base_url = Config::getRootUrl() . '/static/tui-editor';
            $str .= <<<EOF
<link rel="stylesheet" type="text/css" href="${base_url}/dist/tui-editor.min.css" />
<link rel="stylesheet" type="text/css" href="${base_url}/dist/tui-editor-contents.min.css" />
<script type="text/javascript">
require(["tui-editor"], function () {
    var editor = new Editor({
        el: document.querySelector('#tuieditor_box'),
        initialEditType: 'markdown',
        previewStyle: 'vertical',
        height: '400px'
    });
});

/*
$(function () {
    var editor = new tui.Editor({
        el: document.querySelector('#tuieditor_box'),
        initialEditType: 'markdown',
        previewStyle:    'vertical',
        height:          '400px'
    });
});
*/
</script>
EOF;
            static::$isLoaded['tuieditor'] = true;
        }
        
        return $str;
    }
622027
protected function setAttrVal($name, $value)
    {
        // 数据保护，启用数据独立的模型，不允许重新加载数据
        if ($this->isInstanceApart && $this->isLoaded()) {
            $pk = $this->getPk();
            if((is_array($pk) && array_key_exists($name, $pk) && $this->getPkv()[$name] != $value)
                || (is_scalar($pk) && strtolower($name) == strtolower($pk) && $this->getPkv() != $value)) {
                $msg = "The primarykey '{$name}' is readonly, if you are going to change it in any case, "
                    . "you must new another instance of " . get_class($this) . " or set the 'isInstanceApart' property as false.";
                throw new Exception($msg);
            }
        }

        // 表字段有对应已定义模型类属性
        if($this->columnMap && array_key_exists($name, $this->columnMap)) {
            $attr = $this->columnMap[$name];
            $setter = 'set' . $attr;

            if(method_exists($this, $setter)) {
                $this->$setter($value);
            } else {
                $this->$attr = $value;
            }

            return $this;
        } else if (property_exists($this, $name)) {
            // 重载元素时存在同名已声明私有属性名无映射不允许重载赋值
            throw new \InvalidArgumentException('access non public property on __get():' . get_class($this) . '::' . $name);
        } else {
            $this->attrs[$name] = $value;
        }

        return $this;
    }
950406
public function get_namespace($name = null)
    {
        $ns = $this->namespace;

        if ($name) {
            // an alias for BC
            if ($name == 'prefix') {
                $name = 'prefix_in';
            }

            return isset($ns[$name]) ? $ns[$name] : null;
        }

        unset($ns['prefix_in'], $ns['prefix_out']);

        return $ns;
    }
1122802
public function set($name, $value = '', $option = null) {

        // 参数设置(会覆盖黙认设置)
        if (!is_null($option)) {
            if (is_numeric($option)) {
                $option = ['expire' => $option];
            }
            elseif (is_string($option)) {
                parse_str($option, $option);
            }
            $config = array_merge($this->config, array_change_key_case($option));
        }
        else {
            $config = $this->config;
        }
        $name = $config['prefix'] . $name;
        // 设置cookie
        if (is_array($value)) {
            array_walk_recursive($value, 'self::jsonFormatProtect', 'encode');
            $value = 'nb:' . json_encode($value);
        }
        $expire = !empty($config['expire']) ? $_SERVER['REQUEST_TIME'] + intval($config['expire']) : 0;
        if ($config['setcookie']) {
            setcookie($name, $value, $expire, $config['path'], $config['domain'], $config['secure'], $config['httponly']);
        }
        $_COOKIE[$name] = $value;
    }
511080
public static function set($name, $value = null)
	{
		$names = parseCfgName($name);
		if (isset($names[0]))
		{
			$first = array_shift($names);
			$obj = self::getInstance($first);
			if ($obj)
			{
				return $obj->setVal($names, $value);
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
788561
public function input($cname, $name, $cfg, $value = NULL, $id = 0) 
	{
		$cfg['validate']['tips'] = isset($cfg['validate']['tips']) ? $cfg['validate']['tips'] : "";
		$text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '<font color="red">*</font>' : '').$cname;
		// 表单附加参数
		$attr = isset($cfg['validate']['formattr']) && $cfg['validate']['formattr'] ? $cfg['validate']['formattr'] : '';
		// 表单宽度设置
		$width = isset($cfg['option']['width']) && $cfg['option']['width'] ? $cfg['option']['width'] : '200';
		$ispass = isset($cfg['option']['ispass']) && $cfg['option']['ispass'] ? $cfg['option']['ispass'] : 0;
		$width = 'style="width:'.$width.(is_numeric($width) ? 'px' : '').';"';
		// 字段提示信息
		$tips = ($name == 'title') || (isset($cfg['validate']['tips']) && $cfg['validate']['tips']) ? ''.$cfg['validate']['tips'].'' : '';
		// 字段默认值
		if(!$value) {
			$value = isset($cfg['option']['value']) && $cfg['option']['value'] ? htmlspecialchars_decode($cfg['option']['value']) : "";
		} else {
			$value = isset($value) && $value ? htmlspecialchars_decode($value) : "";
		}
		//修改
		$disabled = !$this->isadmin && $id && $value && isset($cfg['validate']['isedit']) && !$cfg['validate']['isedit'] ? ' disabled' : ' ';
		$_type = $ispass ? 'password' : 'text';
		// 当字段必填时，加入html5验证标签
		$required = isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? ' required="required"' : '';
		return $this->input_format($name, $text, '<input class="hstui-input" type="'.$_type.'" name="'.$name.'" id="hstcms_'.$name.'" value="'.$value.'" '.$width . $disabled . $required . $attr .' >', $tips);
	}
550548
public function getNameSpace(string $name) : string
    {
        $segs = [];
        $name = str_replace("/", "\\", $name);
        $namespace = explode("\\", $name);
        array_pop($namespace);

        array_walk($namespace, function (&$value) {
            $value = $this->removeNoneAlpherNumeric($value);
        });

        return implode("\\", $namespace);
    }