| @@ -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; |
| @@ -165,8 +165,10 @@ | ||
| 165 | 165 | |
| 166 | 166 | $this->setCacheNames(); |
| 167 | 167 | $this->result = false; |
| 168 | 168 | |
| 169 | + | |
| 170 | + | |
| 169 | 171 | if ( $this->isCacheValid( $this->response_cache_file ) ) { |
| 170 | 172 | $this->response_type = 'cache'; |
| 171 | 173 | $this->why_no_cache = false; |
| 172 | 174 | $this->result = file_get_contents( $this->response_cache_file ); |
| @@ -277,8 +279,10 @@ | ||
| 277 | 279 | |
| 278 | 280 | } |
| 279 | 281 | $log_bits['response_length'] = strlen($this->result); |
| 280 | 282 | |
| 283 | + //plouf( $this ); die('erorkez'); | |
| 284 | + | |
| 281 | 285 | if ( $this->result ) { |
| 282 | 286 | $this->result = json_decode( $this->result ); |
| 283 | 287 | |
| 284 | 288 | $this->result = ( array ) $this->result; |
| @@ -311,9 +315,9 @@ | ||
| 311 | 315 | |
| 312 | 316 | public function getEndPointURL( $add_auth_key = false ) { |
| 313 | 317 | |
| 314 | 318 | |
| 315 | - $APIServer = DeeplConfiguration::getAPIServer(); | |
| 319 | + $APIServer = DeepLConfiguration::getAPIServer(); | |
| 316 | 320 | if ( !$this->endPointURL ) { |
| 317 | 321 | if ( $this->endPoint === '' ) { |
| 318 | 322 | $this->endPointURL = $APIServer; |
| 319 | 323 | } |
| @@ -347,9 +351,9 @@ | ||
| 347 | 351 | |
| 348 | 352 | $args['headers'] = $this->addHeaders( $args['headers'] ); |
| 349 | 353 | $args['body'] = $this->buildBody( 'POST', $this->endPoint ); |
| 350 | 354 | |
| 351 | - //plouf( $args ,__METHOD__ . "args"); | |
| 355 | + //wpdeepl_debug_display( $args ,__METHOD__ . "args"); | |
| 352 | 356 | |
| 353 | 357 | /* |
| 354 | 358 | $args['auth_key'] = $this->authKey; |
| 355 | 359 | |
| @@ -372,9 +376,9 @@ | ||
| 372 | 376 | |
| 373 | 377 | $bits = array_merge( array( $remoteURL, 'POST' ), $args ); |
| 374 | 378 | // unsafe |
| 375 | 379 | //wpdeepl_log( $bits, 'apiRequests'); |
| 376 | -// plouf( $args, "args" ); | |
| 380 | +// wpdeepl_debug_display( $args, "args" ); | |
| 377 | 381 | /* |
| 378 | 382 | $exec = "curl -X POST '$remoteURL' \\\n"; |
| 379 | 383 | foreach( $args['headers'] as $key => $value ) { |
| 380 | 384 | $exec .= "-H '$key: $value' \\\n"; |
| @@ -382,28 +386,28 @@ | ||
| 382 | 386 | foreach( $args['body'] as $key => $value ) { |
| 383 | 387 | $exec .= "-d '$value' \\\n"; |
| 384 | 388 | } |
| 385 | 389 | |
| 386 | - plouf( $exec ); | |
| 390 | + wpdeepl_debug_display( $exec ); | |
| 387 | 391 | $response = exec ( $exec ); |
| 388 | - plouf( $response ); | |
| 392 | + wpdeepl_debug_display( $response ); | |
| 389 | 393 | die('okaz4a6e4a68e4a86e'); |
| 390 | 394 | */ |
| 391 | 395 | |
| 392 | - //plouf( $args, $remoteURL ); die('68z4e6z48a68ee8aok'); | |
| 396 | + //wpdeepl_debug_display( $args, $remoteURL ); die('68z4e6z48a68ee8aok'); | |
| 393 | 397 | |
| 394 | 398 | //$args['body'] = str_replace('target_lang=NO', 'target_lang=NB', $args['body'] ); |
| 395 | 399 | $response = wp_remote_post( $remoteURL, $args ); |
| 396 | - //plouf( $args, $remoteURL, " post request"); plouf( $response ); die('okesoezporjkezor'); | |
| 400 | + //wpdeepl_debug_display( $args, $remoteURL, " post request"); wpdeepl_debug_display( $response ); die('okesoezporjkezor'); | |
| 397 | 401 | |
| 398 | -// plouf( $args, " args pour $remoteURL" ); plouf( $response, "zeirjzpeijrpizerjpirj" ); die('okaze6aze44e'); | |
| 399 | - //plouf( $args, "args"); | |
| 402 | +// wpdeepl_debug_display( $args, " args pour $remoteURL" ); wpdeepl_debug_display( $response, "zeirjzpeijrpizerjpirj" ); die('okaze6aze44e'); | |
| 403 | + //wpdeepl_debug_display( $args, "args"); | |
| 400 | 404 | |
| 401 | -// plouf( $args, "POST request to $remoteURL ");die('okaz5ea5zea4e'); | |
| 405 | +// wpdeepl_debug_display( $args, "POST request to $remoteURL ");die('okaz5ea5zea4e'); | |
| 402 | 406 | |
| 403 | 407 | if ( is_wp_error( $response ) ) { |
| 404 | 408 | $this->response = $response->get_error_message(); |
| 405 | - plouf( $args, $this->getEndPointURL() ); | |
| 409 | + wpdeepl_debug_display( $args, $this->getEndPointURL() ); | |
| 406 | 410 | die( __METHOD__ ); |
| 407 | 411 | } |
| 408 | 412 | else { |
| 409 | 413 | $this->response = $response; |
| @@ -443,12 +447,12 @@ | ||
| 443 | 447 | $bits = array_merge( array( $remoteURL, 'GET' ), $args ); |
| 444 | 448 | // unsafe |
| 445 | 449 | //wpdeepl_log( $bits, 'apiRequests'); |
| 446 | 450 | |
| 447 | -// plouf( $args, $remoteURL ); die('oazea4ze9684e84azek'); | |
| 451 | +// wpdeepl_debug_display( $args, $remoteURL ); die('oazea4ze9684e84azek'); | |
| 448 | 452 | |
| 449 | 453 | $response = wp_remote_get( $remoteURL, $args ); |
| 450 | - //plouf( $args, $remoteURL ); plouf( $response ); die('ok'); | |
| 454 | + //wpdeepl_debug_display( $args, $remoteURL ); wpdeepl_debug_display( $response ); die('ok'); | |
| 451 | 455 | if ( is_wp_error( $response ) ) { |
| 452 | 456 | $this->response = $response->get_error_message(); |
| 453 | 457 | } else { |
| 454 | 458 | $this->response = $response; |