1 | <?php |
---|
2 | defined('PLA_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | /** |
---|
5 | * list files of a plugin |
---|
6 | */ |
---|
7 | function list_plugin_files($id, $path=null) |
---|
8 | { |
---|
9 | if (empty($path)) |
---|
10 | { |
---|
11 | $path = '/'; |
---|
12 | } |
---|
13 | |
---|
14 | if ($path == '/language/') |
---|
15 | { |
---|
16 | return array(); |
---|
17 | } |
---|
18 | |
---|
19 | if (strlen($path)-strrpos($path, '_data/') == 6) |
---|
20 | { |
---|
21 | return array(); |
---|
22 | } |
---|
23 | |
---|
24 | if (($handle = opendir(PHPWG_PLUGINS_PATH.$id.$path)) === false) |
---|
25 | { |
---|
26 | return array(); |
---|
27 | } |
---|
28 | |
---|
29 | $data = array(); |
---|
30 | |
---|
31 | while ($entry = readdir($handle)) |
---|
32 | { |
---|
33 | if ($entry=='.' || $entry=='..' || $entry=='.svn' || $entry=='index.php') continue; |
---|
34 | |
---|
35 | if (is_dir(PHPWG_PLUGINS_PATH.$id.$path.$entry)) |
---|
36 | { |
---|
37 | $data = array_merge($data, list_plugin_files($id, $path.$entry.'/')); |
---|
38 | } |
---|
39 | else |
---|
40 | { |
---|
41 | $ext = strtolower(get_extension($entry)); |
---|
42 | if (in_array($ext, array('php', 'tpl'))) |
---|
43 | { |
---|
44 | $data[] = $path.$entry; |
---|
45 | } |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | closedir($handle); |
---|
50 | |
---|
51 | return $data; |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * list translated strings of a file |
---|
56 | */ |
---|
57 | function analyze_file($path) |
---|
58 | { |
---|
59 | $lines = file(PHPWG_PLUGINS_PATH.$path, FILE_IGNORE_NEW_LINES); |
---|
60 | |
---|
61 | $strings = array(); |
---|
62 | |
---|
63 | foreach ($lines as $i => $line) |
---|
64 | { |
---|
65 | // l10n |
---|
66 | if (preg_match_all('#l10n\((?:[ ]*)(?:["\']{1})(.*?)(?:["\']{1})(?:[ ]*)\)#', $line, $matches)) |
---|
67 | { |
---|
68 | for ($j=0; $j<count($matches[1]); ++$j) |
---|
69 | { |
---|
70 | $strings[ stripslashes($matches[1][$j]) ][] = $i+1; |
---|
71 | } |
---|
72 | } |
---|
73 | // translate |
---|
74 | if (preg_match_all('#\{(?:["\']{1})(.*?)(?:["\']{1})\|\@translate#', $line, $matches)) |
---|
75 | { |
---|
76 | for ($j=0; $j<count($matches[1]); ++$j) |
---|
77 | { |
---|
78 | $strings[ stripslashes($matches[1][$j]) ][] = $i+1; |
---|
79 | } |
---|
80 | } |
---|
81 | // l10n_dec on one line |
---|
82 | if (preg_match_all('#l10n_dec\((?:[ ]*)(?:["\']{1})(.*?)(?:["\']{1})(?:[ ]*),(?:[ ]*)(?:["\']{1})(.*?)(?:["\']{1})#', $line, $matches)) |
---|
83 | { |
---|
84 | for ($j=0; $j<count($matches[1]); ++$j) |
---|
85 | { |
---|
86 | $strings[ stripslashes($matches[1][$j]) ][] = $i+1; |
---|
87 | $strings[ stripslashes($matches[2][$j]) ][] = $i+1; |
---|
88 | } |
---|
89 | } |
---|
90 | // l10n_dec on two or three lines |
---|
91 | else if (strpos($line, 'l10n_dec')!==false) |
---|
92 | { |
---|
93 | $three_lines = $lines[$i]; |
---|
94 | if (isset($lines[$i+1])) |
---|
95 | { |
---|
96 | $three_lines.= ' '.$lines[$i+1]; |
---|
97 | if (isset($lines[$i+2])) $three_lines.= ' '.$lines[$i+2]; |
---|
98 | } |
---|
99 | |
---|
100 | if (preg_match_all('#l10n_dec\((?:[ ]*)(?:["\']{1})(.*?)(?:["\']{1})(?:[ ]*),(?:[ ]*)(?:["\']{1})(.*?)(?:["\']{1})#', $three_lines, $matches)) |
---|
101 | { |
---|
102 | for ($j=0; $j<count($matches[1]); ++$j) |
---|
103 | { |
---|
104 | $strings[ stripslashes($matches[1][$j]) ][] = $i+1; |
---|
105 | $strings[ stripslashes($matches[2][$j]) ][] = $i+1; |
---|
106 | } |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | return $strings; |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | * load a language file |
---|
116 | */ |
---|
117 | function load_language_file($path) |
---|
118 | { |
---|
119 | @include($path); |
---|
120 | if (!isset($lang)) return array(); |
---|
121 | return $lang; |
---|
122 | } |
---|
123 | |
---|
124 | ?> |
---|