-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathonion.php
104 lines (104 loc) · 2.67 KB
/
onion.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
<?php
function html_string($pre){
$r = '';
$s = explode('-',$pre);
if(!empty($s)){
foreach($s as $t){
if(!empty($t)){
$r.= '[\''.$t.'\']';
}
}
}
if(!empty($r)){
$r = '$raw'.$r;
}
return $r;
}
function html_listing($str,$pre){
$r = $s = array();
$s = html_element($str,'tmp');
$r['html'] = '\'.html_'.md5($pre).'($raw,\''.$pre.'\')'.'.\'';
$r['func'] = 'function html_'.md5($pre).'($raw,$pre){
$r = \'\';
if(!empty($pre)){
foreach('.html_string($pre).' as $tmp){
$r.= \''.str_replace('$raw[\'tmp\']','$tmp',$s['html']).'\';
}
}
return $r;
}'.PHP_EOL;
return $r;
}
function html_element($str,$pre){
$r = array();
$r['html'] = $str;
$r['func'] = '';
if(preg_match('/'.preg_quote('<!--','/').'(unit|list|this)\.([a-z]+)'.preg_quote('-->','/').'/i',$str)){
preg_match_all('/'.preg_quote('<!--unit.','/').'([a-z]+)'.preg_quote('-->','/').'(.*?)'.preg_quote('<!--unit.','/').'\1'.preg_quote('-->','/').'/is',$r['html'],$tmp);
if(!empty($tmp[0])){
foreach(array_keys($tmp[0]) as $key){
$s = array();
$s = html_element($tmp[2][$key],$pre.'-'.$tmp[1][$key]);
$r['html'] = str_replace($tmp[0][$key],$s['html'],$r['html']);
$r['func'] = $r['func'].$s['func'];
}
}
preg_match_all('/'.preg_quote('<!--','/').'list\.([a-z]+)'.preg_quote('-->','/').'(.*?)'.preg_quote('<!--','/').'list\.\1'.preg_quote('-->','/').'/is',$r['html'],$tmp);
if(!empty($tmp[0])){
foreach(array_keys($tmp[0]) as $key){
$s = array();
$s = html_listing($tmp[2][$key],$pre.'-'.$tmp[1][$key]);
$r['html'] = str_replace($tmp[0][$key],$s['html'],$r['html']);
$r['func'] = $r['func'].$s['func'];
}
}
preg_match_all('/'.preg_quote('<!--','/').'this\.([a-z]+)'.preg_quote('-->','/').'/is',$r['html'],$tmp);
if(!empty($tmp[0])){
foreach(array_keys($tmp[0]) as $key){
$s = '';
$s = html_string($pre.'-'.$tmp[1][$key]);
$r['html'] = str_replace($tmp[0][$key],'\'.'.$s.'.\'',$r['html']);
}
}
}
return $r;
}
function html_build($raw){
$r = false;
$tpl = '';
if(is_file($raw['raw'])){
$tpl = file_get_contents($raw['raw']);
}
if(!empty($tpl)){
$out = array();
$out = html_element($tpl,'');
if(!empty($out['html'])){
$out['sync'] = '<?php
'.$out['func'].'
function html_handler($raw){
$r = \'\';
$r = \''.$out['html'].'\';
return $r;
}
?>'.PHP_EOL;
}
if(!empty($out['sync']) && file_put_contents($raw['out'],$out['sync'])){
$r = true;
}
}
return $r;
}
function html_render($str,$raw){
global $conf;
$r = '';
$tpl = array();
$tpl['raw'] = __DIR__.'/'.$str.'.html';
$tpl['out'] = __DIR__.'/tmp/'.md5($tpl['raw']);
if(!is_file($tpl['out'])){
html_build($tpl);
}
include($tpl['out']);
$r = html_handler($raw);
return $r;
}
?>