/
helper.overframe.php
executable file
·340 lines (286 loc) · 7.24 KB
/
helper.overframe.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<?php
use of\Ajax;
use of\Data;
use of\Database;
use of\Entity;
use of\Node;
use of\System;
$global_sys = null;
/**
* @note This method creates only one instance of System class.
* @return System
*/
function sys() {
global $global_sys ;
if ( $global_sys === null ) $global_sys = new System();
return $global_sys ;
}
/**
* @param null $name - table name of the entity
* @return Entity
*/
function entity($name=null) {
if ( $name ) {
$entity = new Entity();
$entity->setTableName($name);
return $entity;
}
else return new Entity();
}
function node($name) {
$node = new Node();
$node->setTableName($name);
return $node;
}
function meta($name) {
$meta = new \of\Meta();
$meta->setTableName($name);
return $meta;
}
/**
* @param int $id
* @return Data
*/
function data( $id = 0 ) {
if ( empty($id) ) return new Data();
else {
$data = new Data();
return $data->load($id);
}
}
function ajax() {
return new Ajax();
}
function database() {
return new Database();
}
$global_user = null;
/**
* @return of\User
*/
function user() {
global $global_user ;
if ( $global_user === null ) $global_user = new of\User();
return $global_user ;
}
if ( ! function_exists('di') ) {
function di($obj) {
if ( empty($obj) ) return;
echo "<pre>";
print_r($obj);
echo "</pre>";
}
}
$global_test_error = array();
function run_test() {
echo "<h2>Begin test</h2>";
echo "<hr>";
foreach ( sys()->getModelPaths() as $model ) {
$name = pathinfo($model, PATHINFO_BASENAME);
$files = glob( $model . '/*est.php' );
foreach( $files as $file ) {
$filename = pathinfo($file, PATHINFO_FILENAME);
$path = "of\\$name\\$filename";
$obj = new $path();
if ( method_exists( $obj, 'run') ) $obj->run();
}
}
show_test_result();
}
function test( $code, $good=null, $bad=null ) {
static $_count_test = 0;
global $global_test_error;
$_count_test ++;
$tree = get_backtrace();
if ( $code ) {
$path = path_run(2);
echo "<span style='font-size:100%;color:#7f7c85;' title='$good $path'>$_count_test</span> ";
}
else {
echo "<span style='font-size:160%;color:red;' title='$bad'>$_count_test</span> ";
$global_test_error[] = $bad . $tree;
}
}
function show_test_result() {
global $global_test_error;
echo "<hr>Test ended.";
foreach ( $global_test_error as $e ) {
echo '<hr>';
$e = nl2br($e);
echo $e;
}
}
function get_backtrace()
{
ob_start();
$arr = debug_print_backtrace();
$str = ob_get_clean();
return $str;
}
/**
* Returns page no.
* @note page no. begins with 1.
* if the input is not a number or less than 1, then it returns 1.
*
* @attention Since the return 'page no' is 1 on first page, you must do ('page_no' -1 ) for retrieving data form table.
* page_no 가 1 부터 시작하므로, 테이블에서 데이터를 처음 부터 추출하기 위해서는 offset 이 '0' 이어야 하므로 'page_no' - 1 을 해야 한다.
*
* @param $no
* @return int|string
*/
function page_no($no) {
if ( ! is_numeric($no) ) return 1;
else if ( $no < 1 ) return 1;
else return $no;
}
function path_run($n = 1) {
$d = debug_backtrace();
$func = $d[$n]['function'];
$cls = $d[$n]['class'];
$file = $d[$n]['file'];
$line = $d[$n]['line'];
return "$file at line $line - $cls::$func";
}
/**
* @short returns a UNIQUE ID
*
*/
function unique_id()
{
return md5(uniqid(rand(), true) . time());
}
$_http_input = array();
/**
* @param null $name
* @param null $default
* @return array
* @code
* $in = http_input();
* @endcode
*/
function http_input($name = null, $default = null) {
global $_http_input;
if ( empty($_http_input) )$_http_input = array_merge($_GET, $_POST);
if ( $name ) {
if ( isset( $_http_input[$name] ) ) return $_http_input[$name];
else return $default;
}
return $_http_input;
}
/**
* alias of http_input
* @param null $name
* @param null $default
* @return mixed
*/
function hi($name = null, $default = null) {
return http_input($name, $default);
}
function json_error($code, $message) {
$in = http_input();
$out = array('code'=>$code, 'message'=>$message, 'system'=>sys()->find() );
if ( isset( $in['do'] ) ) $out['do'] = $in['do'];
if ( isset( $in['model'] ) ) $out['model'] = $in['model'];
echo json_encode( $out );
exit;
}
function json_success($data) {
$in = http_input();
$out = array('code'=>0, 'system'=>sys()->find());
if ( isset($in['do']) ) $out['do'] = $in['do'];
else if ( isset($in['model'] ) ) $out['model'] = $in['model'];
$out['data'] = $data;
echo json_encode( $out );
exit;
}
function dir_overframe() {
return DIR_OVERFRAME;
}
function dir_overframe_data()
{
if ( sys()->isSapcms1() ) {
global $sys;
return $sys->config->dir_data . '/overframe';
}
else if ( sys()->isCodeIgniter3() ) {
return DIR_OVERFRAME . '/data';
}
else return null;
}
function url_overframe() {
if ( sys()->isSapcms1() ) {
$domain = etc::domain_name();
$url_overframe = "http://$domain/overframe";
}
else if ( sys()->isCodeIgniter3() ) {
$ci = & get_instance();
$ci->load->helper('url');
$url_overframe = base_url() . '/overframe';
}
else $url_overframe = null;
return $url_overframe;
}
function url_root() {
if ( sys()->isSapcms1() ) return '/';
else if ( sys()->isCodeIgniter3() ) {
$ci = & get_instance();
$ci->load->helper('url');
return base_url();
}
else return null;
}
/**
*
* Url for form submission and data retribution.
*/
function url_action() {
if ( sys()->isSapcms1() ) {
$domain = etc::domain_name();
return "http://$domain/?module=overframe&action=index";
}
if ( sys()->isCodeIgniter3() ) {
return url_root() . '?action=index';
}
else return null;
}
function url_overframe_data($filename=null) {
if ( sys()->isSapcms1() ) {
//$domain = etc::domain_name();
$domain = 'file.philgo.com';
return "http://$domain/data/overframe/$filename";
}
else if ( sys()->isCodeIgniter3() ) {
$ci = & get_instance();
$ci->load->helper('url');
return base_url('overframe/data') . '/' . $filename;
}
else return null;
}
function ajax_endpoint() {
if ( sys()->isSapcms1() ) {
$domain = etc::domain_name();
return "http://$domain/?module=overframe&action=index&mode=ajax&submit=1";
}
if ( sys()->isCodeIgniter3() ) {
return url_root() . '?action=ajax';
}
else return null;
}
function model_endpoint() {
if ( sys()->isSapcms1() ) {
$domain = etc::domain_name();
return "http://$domain/?module=overframe&action=index&model=";
}
if ( sys()->isCodeIgniter3() ) {
return url_root() . '?model=';
}
else return null;
}
function path_debug_log()
{
return dir_overframe_data() . '/overframe.debug.log';
}
function isLocalhost() {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') return true;
else return false;
}