mapFile sources map ini if file_exists mapFile file_put_contents mapFi

 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
$mapFile = "sources/map.ini";
if(!file_exists($mapFile))
file_put_contents($mapFile, null);
function compile($path, $assoc_array) {
foreach($assoc_array as $key => $item) {
$content .= "[{$key}]\n";
foreach ($item as $key2 => $item2) {
if( $key2 != 'fn' ) {
if(is_numeric($item2) || is_bool($item2))
$content .= "{$key2} = {$item2}\n";
else
$content .= "{$key2} = \"{$item2}\"\n";
}
}
file_put_contents("sources/$key.txt", $item['fn'] );
}
if(!$handle = fopen($path, 'w'))
return false;
if(!fwrite($handle, $content))
return false;
fclose($handle);
return true;
}
$content = file('../source_code/konstruktor.js');
$arr = array();
$tmp = array();
$result = array();
$flag = false;
$count = 0;
foreach( $content as $str ){
if( preg_match("/\/\/>>>.*/", $str) )
$flag = true;
if( preg_match("/\/\/<<<.*/", $str) )
$flag = false;
if( $flag )
$tmp[] = $str;
if( !$flag ) {
$function = "\n\n" . implode('', $tmp) . "\n\n";
if( strlen( $function ) > 10 ) {
$conf = preg_replace('/[^\w\[\]\s,]/', '', trim($tmp[0]));
$conf = preg_replace('/ /', '_', $conf);
$conf = preg_replace('/,_/', ',', $conf);
$conf = preg_replace('/^_/', '', $conf);
$count++;
//$arr[$conf.'_n'.$count] = $function;
$data = array("num" => $count );
preg_match("/^([a-zA-Z]+)/", $conf, $tmp);
$section = $tmp[1];
$depend = preg_replace("/($section)|([\[\]_])|(depends)/","",$conf);
if( $depend )
$data['depends'] = $depend;
$data['fn'] = $function;
$arr[$section] = $data;
}
$tmp = array();
}
}
if(compile($mapFile, $arr))
echo "success";