- Eine PHP Klasse um mit der wCrypt.in API zu interagieren.
wCrypt.in
1 <?php
2
3 #######################################################
4 #
5 # wCrypt.class.php
6 #
7 # @project wCrypt.in API Wrapper
8 # @version 1.0
9 # @author EntenMann
10 # @copyright Copyright (c) 2010, EntenMann
11 #
12 # @lastmodified 08:12 Freitag, 28. August 2010
13 #
14 #######################################################
15
16 class wCrypt {
17 ##### Variablen
18 private static $strApi = 'http://data.wcrypt.in/api_';
19 private static $strKey = '';
20 private static $arrData = array();
21 #####
22
23 ##### API Key zuweisen
24 public static function set($strKey) {
25 if(strlen($strKey) == 32) {
26 if(preg_match('|[0-9a-fA-F]{32}|', $strKey, $arrFound)) {
27 self::$strKey = $arrFound[0];
28 } else {
29 die('API-Key ungültig!');
30 }
31 } else {
32 die('API-Key ungültig!');
33 }
34 }
35 #####
36
37 ##### Ordner erstellen
38 public static function insert($strName, $strLinks, $booWeb = 1, $booDlc = 0, $booCnl = 0, $booCcf = 0, $booRsdf = 0, $strPassword = '') {
39 self::$arrData = array('key' => self::$strKey,
40 'name' => $strName,
41 'links' => $strLinks,
42 'web' => $booWeb,
43 'dlc' => $booDlc,
44 'cnl' => $booCnl,
45 'ccf' => $booCcf,
46 'rsdf' => $booRsdf,
47 'container_password' => $strPassword);
48
49 switch(self::postRequest('insert')) {
50 case 1:
51 return 'Ordner erfolgreich bearbeitet';
52
53 case 2:
54 return 'Nicht alle Links gültig!';
55
56 case 3:
57 return 'API-Key ungültig!';
58
59 case 4:
60 return 'Nicht alle Daten angegeben!';
61
62 case 5:
63 return 'Ordner nicht gefunden!';
64
65 case 6:
66 return 'Keine Rechte!';
67
68 default:
69 return 'http://wcrypt.in/folder/' . self::postRequest('insert') . '/';
70 }
71
72 return false;
73 }
74 #####
75
76 ##### Ordner bearbeiten
77 public static function edit($strFolder, $strName, $strLinks = '', $booWeb = 1, $booDlc = 0, $booCnl = 0, $booCcf = 0, $booRsdf = 0, $strPassword = '') {
78 self::$arrData = array('folder' => self::getFolder($strFolder),
79 'key' => self::$strKey,
80 'name' => $strName,
81 'links' => $strLinks,
82 'web' => $booWeb,
83 'dlc' => $booDlc,
84 'cnl' => $booCnl,
85 'ccf' => $booCcf,
86 'rsdf' => $booRsdf,
87 'container_password' => $strPassword);
88
89 switch(self::postRequest('edit')) {
90 case 1:
91 return 'Ordner erfolgreich bearbeitet';
92
93 case 2:
94 return 'Nicht alle Links gültig!';
95
96 case 3:
97 return 'API-Key ungültig!';
98
99 case 4:
100 return 'Nicht alle Daten angegeben!';
101
102 case 5:
103 return 'Ordner nicht gefunden!';
104
105 case 6:
106 return 'Keine Rechte!';
107
108 default:
109 return self::postRequest('edit');
110 }
111
112 return false;
113 }
114 #####
115
116 ##### Ordner löschen
117 public static function delete($strFolder) {
118 self::$arrData = array('key' => self::$strKey,
119 'folder' => self::getFolder($strFolder));
120
121 switch(self::postRequest('delete')) {
122 case 1:
123 return 'Ordner wurde gelöscht';
124
125 case 2:
126 return 'Ordner nicht vorhanden!';
127
128 case 3:
129 return 'API-Key ungültig!';
130
131 case 4:
132 return 'Nicht alle Daten angegeben!';
133
134 default:
135 return self::postRequest('delete');
136 }
137
138 return false;
139 }
140 #####
141
142 ##### Status anzeigen
143 public static function status($strFolder) {
144 self::$arrData = array('folder' => self::getFolder($strFolder));
145
146 switch(self::postRequest('status')) {
147 case 1:
148 return 'Online';
149
150 case 2:
151 return 'Offline';
152
153 case 3:
154 return 'Unbestimmt';
155
156 case 4:
157 return 'Nicht geprüft';
158
159 case 5:
160 return 'Abused';
161
162 case 6:
163 return 'Ordner nicht vorhanden';
164
165 case 7:
166 return 'Nicht alle Daten angegeben';
167
168 default:
169 return self::postRequest('status');
170 }
171
172 return false;
173 }
174 #####
175
176 ##### Informationen anzeigen
177 public static function information($strFolder) {
178 self::$arrData = array('folder' => self::getFolder($strFolder));
179
180 switch(self::postRequest('information')) {
181 case 1:
182 return 'Ordner nicht gefunden';
183
184 case 2:
185 return 'Nicht alle Daten angegeben!';
186
187 default:
188 return self::postRequest('information');
189 }
190
191 return false;
192 }
193 #####
194
195 ##### Datei-Status auslesen
196 public static function fileStatus($strFile) {
197 self::$arrData = array('link' => $strFile);
198
199 switch(self::getRequest('file_status')) {
200 case 1:
201 return 'Online';
202
203 case 2:
204 return 'Offline';
205
206 case 3:
207 return 'Unbestimmt';
208
209 case 4:
210 return 'Nicht alle Daten angegeben';
211
212 default:
213 return self::getRequest('file_status');
214 }
215
216 return false;
217 }
218 #####
219
220 ##### Ordner-ID (32-stelliger Wert)
221 private static function getFolder($strFolder) {
222 return substr(str_replace('/', '', $strFolder), -32);
223 }
224 #####
225
226 ##### POST-Request mit cURL
227 private static function postRequest($strFunc) {
228 $arrDefaults = array(CURLOPT_POST => 1,
229 CURLOPT_HEADER => 0,
230 CURLOPT_URL => self::$strApi . $strFunc,
231 CURLOPT_RETURNTRANSFER => 1,
232 CURLOPT_POSTFIELDS => self::$arrData);
233
234 $objCurl = curl_init();
235
236 curl_setopt_array($objCurl, $arrDefaults);
237
238 if(!$strResult = curl_exec($objCurl)) {
239 trigger_error(curl_error($objCurl));
240 }
241
242 curl_close($objCurl);
243
244 return $strResult;
245 }
246 #####
247
248 ##### GET-Request mit cURL
249 public function getRequest($strFunc) {
250 $arrDefaults = array(CURLOPT_URL => self::$strApi . $strFunc . '?' . http_build_query(self::$arrData),
251 CURLOPT_HEADER => 0,
252 CURLOPT_RETURNTRANSFER => 1);
253
254 $objCurl = curl_init();
255
256 curl_setopt_array($objCurl, $arrDefaults);
257
258 if(!$strResult = curl_exec($objCurl)) {
259 trigger_error(curl_error($objCurl));
260 }
261
262 curl_close($objCurl);
263
264 return $strResult;
265 }
266 #####
267 }
268
269 ?>
Comments
Sign in to leave a comment.

