-
Notifications
You must be signed in to change notification settings - Fork 1
/
base.php
executable file
·119 lines (95 loc) · 1.96 KB
/
base.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace tp\widgets;
use tp\helpers\arr;
use tp\helpers\file;
use think\Request;
class base{
public $load;
public $ele;
public $par = [];
public $script;
public $scriptLink;
public $css;
public $cssLink;
static $exists;
public $option;
public $version = 1.0;
public $id;
protected $request;
function __construct(){
$this->request = Request::instance();
$this->init();
}
function init(){
$this->option = array_key_exists('option', $this->par)?$this->par['option']:[];
if($this->ele){
$this->id = substr($this->ele,1);
}elseif($this->id){
$this->ele = "#".$this->id;
}
}
function toJson($arr){
return json_encode($arr,JSON_PRETTY_PRINT);
}
function asssets($name){
$dir = 'assets/'.$name.'/';
$to = APP_PATH.'/../public/'.$dir;
if(!is_dir($to)){
@file::cpdir(__DIR__.'/'.$dir,$to);
}
return $this->request->root().'/'.$dir;
}
static function render($name,$par = []){
$over = "\widgets\\".$name;
$core = "\\tp\widgets\\".$name;
$e = "";
if(class_exists($over)){
$e = $over;
}elseif(class_exists($core)){
$e = $core;
}
$obj = self::$exists[$e];
if(!$obj && class_exists($e)){
$obj = new $e;
self::$exists[$e] = $obj;
}
if(is_object($obj) && $par){
foreach($par as $k=>$v){
$obj->$k = $v;
}
}
if($obj){
if(method_exists($obj,'load') && !$obj->load[$name]){
$obj->load();
$obj->load[$name] = true;
}
$obj->run();
}
self::$exists['_unique'][$name] = $obj;
return self::$exists['_unique'];
}
static function level($full){
$i = 1000000;
foreach($full as $k=>$v){
$j = $v->level;
if($j){
$out[$j][$k] = $v;
$out[$j]['level'] = $j;
}else{
$out[$i][$k] = $v;
$out[$i]['level'] = $j;
}
$i--;
}
$out = arr::order_by($out,'level',SORT_DESC);
foreach($out as $v){
foreach($v as $key=>$value){
if($key == 'level'){
continue;
}
$new[$key] = $value;
}
}
return $new;
}
}