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