icon();
}
// 释放变量
public function __destruct()
{
unset($this->data);
unset($this->cache);
unset($this->ret);
unset($this->icon);
unset($this->result_array);
unset($this->nbsp_str);
unset($this->nbsp);
unset($this->result);
}
/**
* 设置html标签
*/
public function html_icon() {
$this->nbsp_str = '';
$this->icon = [
$this->nbsp_str,
'├ ',
'└ '
];
return $this;
}
/**
* 设置普通标签
*/
public function icon() {
$this->nbsp_str = ' ';
$this->icon = [
$this->nbsp_str,
'├ ',
'└ '
];
return $this;
}
/**
* 初始化类
*/
public function init($arr) {
$this->ret = '';
$this->data = $arr;
$this->result = [];
return $this;
}
// 创建数据
public function get($data) {
$this->data = $data;
$this->result = [];
$this->create(0);
return $this->result_array;
}
// 设置数据
protected function _data($data) {
$this->ret = '';
$this->data = $data;
$this->deep = 1;
return $this;
}
// 设置缓存
public function cache($is) {
$this->cache = $is;
return $this;
}
/**
* 得到子级数组
* @param int
* @return array
*/
protected function get_child($k_id) {
$arrays = [];
if ($this->mid) {
$child = \Phpcmf\Service::L('category', 'module')->get_child($this->mid, $k_id);
if ($child) {
foreach ($child as $id) {
$this->data[$id] && $arrays[$id] = $this->data[$id];
}
return $arrays;
}
}
if (is_array($this->data)) {
foreach($this->data as $id => $a) {
if ($a['pid'] == $k_id) {
$arrays[$id] = $a;
}
}
}
$this->deep++;
return $arrays;
}
/**
* 得到树型数组
*/
public function create($k_id = 0, $adds = '') {
if ($this->deep > 5000) {
return; // 防止死循环
}
$child = $this->get_child($k_id); // 获取子数据
$number = 1;
if (is_array($child)) {
$total = dr_count($child);
foreach($child as $id => $a) {
$k = $adds ? $this->nbsp : '';
$j = $number == $total ? $this->icon[2] : $this->icon[1];
$a['spacer'] = $this->_get_spacer($adds ? $adds.$j : '');
$this->result_array[] = $a;
$this->create($a['id'], $adds.$k.$this->nbsp);
$number++;
}
}
$this->deep = 1;
}
// 替换空格填充符号
protected function _get_spacer($str) {
$num = substr_count($str, $this->nbsp) * 2;
if ($num) {
$str = str_replace($this->nbsp, '', $str);
for ($i = 0; $i < $num; $i ++) {
$str = $this->nbsp_str.$str;
}
}
return $str;
}
// 替换逗号
protected function _have($list, $item){
return(strpos(',,'.$list.',', ','.$item.','));
}
public function ismain($v) {
$this->ismain = $v;
return $this;
}
public function mid($v) {
$this->mid = $v;
return $this;
}
/**
* 栏目选择
*
* @param array $data 栏目数据
* @param intval/array $id 被选中的ID
* @param string $str 属性
* @param string $default 默认选项
* @param intval $onlysub 只可选择子栏目
* @param intval $is_push 是否验证权限
* @param intval $is_first 是否返回第一个可用栏目id
* @return string
*/
public function select_category($data, $id = '', $str = '', $default = ' -- ', $onlysub = 0, $is_push = 0, $is_first = 0) {
if (dr_count($data) > 30) {
$string = '