21
21
|* along with InMaFSS; if not, see http://www.gnu.org/licenses/. *|
22
22
\*================================================================================= */
23
23
24
- require_once (" global.php " );
24
+ require_once (dirname ( __FILE__ ). " / global.php " );
25
25
26
- new API ( );
26
+ require_once ( INC . " api.php " );
27
27
28
- class API {
29
-
30
- private $ data = Array ();
31
-
32
- public function __construct () {
33
- header ('content-type: application/json; charset=utf-8 ' );
34
-
35
- if (!isset ($ _GET ['key ' ]) || !$ this ->CheckAuth ($ _GET ['key ' ])) {
36
- $ this ->Error ("You have not been authenticated! " );
37
- }
38
-
39
- if (!isset ($ _GET ['action ' ])) {
40
- $ this ->Error ("No action specified " );
41
- }
42
-
43
- if (!$ this ->HasPerm ($ _GET ['action ' ])) {
44
- $ this ->Error ("This action does not exist or you don't have sufficient rights for this action " );
45
- }
46
-
47
- switch ($ _GET ['action ' ]) {
48
- case 'plan_update ' :
49
- if (!isset ($ _POST ['data ' ])) {
50
- $ this ->Error ("No file content found! " );
51
- }
52
-
53
- $ _POST ['data ' ] = urldecode ($ _POST ['data ' ]);
54
-
55
- $ files = explode (chr (1 ), $ _POST ['data ' ]);
56
- $ p = new parse ();
57
-
58
- foreach ($ files as $ file ) {
59
- # $file = stripslashes($file);
60
- $ file = utf8_decode ($ file );
61
- $ file = substr ($ file , strpos ($ file , "<html> " ));
62
- $ p ->parseHTML ($ file );
63
- }
64
-
65
- $ p ->UpdateDatabase ();
66
- $ this ->Output (Array ('STATUS ' => "OK " , 'message ' => 'Import completed ' ));
67
- break ;
68
-
69
- case 'replacements ' :
70
-
71
- if (!$ this ->HasPerm ('replacements_all ' ) && !isset ($ _GET ['g ' ])) {
72
- $ this ->Error ("You must provide a Grade! " );
73
- }
74
-
75
- $ view = $ this ->GetView ();
76
- $ view ->AddRepacements ();
77
-
78
- $ output = Array ();
79
-
80
- foreach ($ view ->replacements as $ page ) {
81
- foreach ($ page as $ grade => $ val ) {
82
- if (!isset ($ _GET ['g ' ]) || $ grade == $ _GET ['g ' ]) {
83
- foreach ($ val as $ k => $ v ) {
84
- $ val [$ k ]['comment ' ] = preg_replace ("/ / " , "" , htmlentities ($ v ['comment ' ]));
85
- $ val [$ k ]['replacement ' ] = preg_replace ("/ / " , "" , htmlentities ($ v ['replacement ' ]));
86
- }
87
- $ output [$ grade ] = $ val ;
88
- }
89
- }
90
- }
91
-
92
- $ this ->Output ($ output );
93
- break ;
94
-
95
- case 'other ' :
96
-
97
- if (!isset ($ _GET ['type ' ])) {
98
- $ this ->Error ("Specify a type " );
99
- }
100
-
101
- $ view = $ this ->GetView ();
102
- $ view ->type = 1 ;
103
- $ view ->AddRepacements ();
104
-
105
- $ output = Array ();
106
-
107
-
108
- foreach ($ view ->replacements [1 ] as $ k => $ val ) {
109
- if ($ k == $ _GET ['type ' ]) {
110
- $ output [$ k ] = $ val ;
111
- }
112
- }
113
-
114
-
115
- $ this ->Output ($ output );
116
-
117
- break ;
118
-
119
- case 'teacher_sub ' :
120
- $ view = $ this ->GetView ();
121
- $ view ->type = 1 ;
122
- $ view ->AddRepacements ();
123
-
124
- $ output = Array ();
125
-
126
- foreach ($ view ->replacements as $ page ) { // Can only be one page!
127
- foreach ($ page as $ k => $ val ) {
128
- switch ($ k ) {
129
- case 't ' :
130
- case 'n ' :
131
- case 'g ' :
132
- case 's ' :
133
- case 'a ' :
134
- case 'r ' :
135
- continue ;
136
- break ;
137
-
138
- default :
139
- if (!isset ($ _GET ['short ' ]) || $ k == $ _GET ['short ' ]) {
140
- foreach ($ val as $ i =>$ entry ) {
141
- foreach ($ entry as $ f =>$ x )
142
- $ val [$ i ][$ f ] = html_entity_decode ($ x , ENT_COMPAT , "UTF-8 " );
143
- }
144
-
145
- $ output [$ k ] = $ val ;
146
- }
147
- break ;
148
- }
149
- }
150
- }
151
-
152
- $ this ->Output ($ output );
153
- break ;
154
-
155
- case 'ticker ' :
156
- $ view = $ this ->GetView ();
157
- $ this ->Output ($ view ->GetTickers ());
158
-
159
- break ;
160
-
161
- default :
162
- $ this ->Error ("Unknown action! " );
163
- break ;
164
- }
165
- }
166
-
167
- function Error ($ msg ) {
168
- $ this ->Output (Array ('STATUS ' => "ERROR " , 'message ' => $ msg ));
169
- exit ;
170
- }
171
-
172
- function Output ($ output ) {
173
- $ output = getVar ('core ' )->FormatJson (json_encode ($ output ));
174
- echo $ output ;
175
- }
176
-
177
- function CheckAuth ($ api ) {
178
-
179
- if (isset ($ _GET ['licence ' ])) {
180
- if (strpos (file_get_contents ("http://licence.flx5.com/inmafss.php?ver= " . getVersion () . "&licence= " . $ _GET ['licence ' ]), "OK " ) !== false ) {
181
- $ this ->data = Array ("all " );
182
- }
183
- }
184
-
185
- $ api = filter ($ api );
186
- $ sql = dbquery ("SELECT permissions FROM api WHERE apikey = ' " . $ api . "' " );
187
-
188
- if (mysql_num_rows ($ sql ) != 1 ) {
189
- return false ;
190
- }
191
-
192
- $ data = mysql_result ($ sql , 0 );
193
- $ data = explode ("| " , $ data );
194
- $ this ->data = $ data ;
195
- return true ;
196
- }
197
-
198
- function HasPerm ($ perm ) {
199
- return true ; // todo!
200
- return in_array ($ perm , $ this ->data );
201
- }
202
-
203
- function GetView () {
204
- if (!isset ($ _GET ['day ' ]) || !is_numeric ($ _GET ['day ' ]) || strlen ($ _GET ['day ' ]) != 10 ) {
205
- $ this ->Error ("Day must be Unix Timestamp " );
206
- }
207
-
208
- require_once ("inc/view.php " );
209
-
210
- $ day = $ _GET ['day ' ];
211
-
212
- $ tfrom = gmmktime (0 , 0 , 0 , date ('m ' , $ day ), date ('d ' , $ day ), date ('Y ' , $ day ));
213
-
214
- $ view = new View (null , 99e99 );
215
- $ view ->tfrom = $ tfrom ;
216
- return $ view ;
217
- }
28
+ $ key = null ;
218
29
30
+ if (isset ($ _GET ['key ' ])) {
31
+ $ key = $ _GET ['key ' ];
219
32
}
220
33
34
+ $ api = new API ($ key );
35
+ $ api ->Exec ();
221
36
?>
0 commit comments