PluginProbe
Translation with DeepL API / trunk
Translation with DeepL API vtrunk
trunk 0.1.20180323 1.0 1.2.5.1 1.5.2.5 1.7.5 2.4.3.12 2.4.3.9 2.4.5
← All changes | client/deeplapi.class.php +23 -14 2.4.3.12trunk View file →
@@ -1,6 +1,6 @@
1 1 <?php
2 -
2 +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 3 abstract class DeepLApi extends DeepLData {
4 4 protected $endPoint = '';
5 5 protected $http_mode = '';
6 6 private $endPointURL = false;
@@ -54,8 +54,12 @@
54 54
55 55 $this->cache_dir = $this->getCacheDirectory();
56 56 }
57 57
58 + public function allowCache( $allow_cache ) {
59 + $this->allow_cache = filter_var( $allow_cache, FILTER_VALIDATE_BOOLEAN );
60 + }
61 +
58 62 public function wasItCached() {
59 63 return $this->response_type === 'cache';
60 64 }
61 65
@@ -161,8 +165,10 @@
161 165
162 166 $this->setCacheNames();
163 167 $this->result = false;
164 168
169 +
170 +
165 171 if ( $this->isCacheValid( $this->response_cache_file ) ) {
166 172 $this->response_type = 'cache';
167 173 $this->why_no_cache = false;
168 174 $this->result = file_get_contents( $this->response_cache_file );
@@ -273,8 +279,10 @@
273 279
274 280 }
275 281 $log_bits['response_length'] = strlen($this->result);
276 282
283 + //plouf( $this ); die('erorkez');
284 +
277 285 if ( $this->result ) {
278 286 $this->result = json_decode( $this->result );
279 287
280 288 $this->result = ( array ) $this->result;
@@ -307,9 +315,9 @@
307 315
308 316 public function getEndPointURL( $add_auth_key = false ) {
309 317
310 318
311 - $APIServer = DeeplConfiguration::getAPIServer();
319 + $APIServer = DeepLConfiguration::getAPIServer();
312 320 if ( !$this->endPointURL ) {
313 321 if ( $this->endPoint === '' ) {
314 322 $this->endPointURL = $APIServer;
315 323 }
@@ -343,9 +351,9 @@
343 351
344 352 $args['headers'] = $this->addHeaders( $args['headers'] );
345 353 $args['body'] = $this->buildBody( 'POST', $this->endPoint );
346 354
347 - //plouf( $args ,__METHOD__ . "args");
355 + //wpdeepl_debug_display( $args ,__METHOD__ . "args");
348 356
349 357 /*
350 358 $args['auth_key'] = $this->authKey;
351 359
@@ -368,9 +376,9 @@
368 376
369 377 $bits = array_merge( array( $remoteURL, 'POST' ), $args );
370 378 // unsafe
371 379 //wpdeepl_log( $bits, 'apiRequests');
372 -// plouf( $args, "args" );
380 +// wpdeepl_debug_display( $args, "args" );
373 381 /*
374 382 $exec = "curl -X POST '$remoteURL' \\\n";
375 383 foreach( $args['headers'] as $key => $value ) {
376 384 $exec .= "-H '$key: $value' \\\n";
@@ -378,28 +386,28 @@
378 386 foreach( $args['body'] as $key => $value ) {
379 387 $exec .= "-d '$value' \\\n";
380 388 }
381 389
382 - plouf( $exec );
390 + wpdeepl_debug_display( $exec );
383 391 $response = exec ( $exec );
384 - plouf( $response );
392 + wpdeepl_debug_display( $response );
385 393 die('okaz4a6e4a68e4a86e');
386 394 */
387 395
388 - //plouf( $args, $remoteURL ); die('68z4e6z48a68ee8aok');
396 + //wpdeepl_debug_display( $args, $remoteURL ); die('68z4e6z48a68ee8aok');
389 397
390 398 //$args['body'] = str_replace('target_lang=NO', 'target_lang=NB', $args['body'] );
391 399 $response = wp_remote_post( $remoteURL, $args );
392 - //plouf( $args, $remoteURL, " post request"); plouf( $response ); die('okesoezporjkezor');
400 + //wpdeepl_debug_display( $args, $remoteURL, " post request"); wpdeepl_debug_display( $response ); die('okesoezporjkezor');
393 401
394 -// plouf( $args, " args pour $remoteURL" ); plouf( $response, "zeirjzpeijrpizerjpirj" ); die('okaze6aze44e');
395 - //plouf( $args, "args");
402 +// wpdeepl_debug_display( $args, " args pour $remoteURL" ); wpdeepl_debug_display( $response, "zeirjzpeijrpizerjpirj" ); die('okaze6aze44e');
403 + //wpdeepl_debug_display( $args, "args");
396 404
397 -// plouf( $args, "POST request to $remoteURL ");die('okaz5ea5zea4e');
405 +// wpdeepl_debug_display( $args, "POST request to $remoteURL ");die('okaz5ea5zea4e');
398 406
399 407 if ( is_wp_error( $response ) ) {
400 408 $this->response = $response->get_error_message();
401 - plouf( $args, $this->getEndPointURL() );
409 + wpdeepl_debug_display( $args, $this->getEndPointURL() );
402 410 die( __METHOD__ );
403 411 }
404 412 else {
405 413 $this->response = $response;
@@ -428,10 +436,10 @@
428 436 $args['headers'] = $this->addHeaders( $args['headers'] );
429 437
430 438 $remoteURL = $this->getEndPointURL();
431 439 //if( $args['query'] ) $remoteURL .= '?' . $args['query'];
432 - //plouf( $args, "REQUESTING URL = '$url'" ); die( '6ze846az6e646eok' );
433 440
441 +
434 442 $curl_string = 'curl -X ' . $args['method'] . " '$remoteURL'\n";
435 443 foreach( $args['headers'] as $key => $value ) {
436 444 $curl_string .= "$key: $value\n";
437 445 }
@@ -439,11 +447,12 @@
439 447 $bits = array_merge( array( $remoteURL, 'GET' ), $args );
440 448 // unsafe
441 449 //wpdeepl_log( $bits, 'apiRequests');
442 450
443 -// plouf( $args, $remoteURL ); die('oazea4ze9684e84azek');
451 +// wpdeepl_debug_display( $args, $remoteURL ); die('oazea4ze9684e84azek');
444 452
445 453 $response = wp_remote_get( $remoteURL, $args );
454 + //wpdeepl_debug_display( $args, $remoteURL ); wpdeepl_debug_display( $response ); die('ok');
446 455 if ( is_wp_error( $response ) ) {
447 456 $this->response = $response->get_error_message();
448 457 } else {
449 458 $this->response = $response;