Naguro_Image_Get_Request

The WooCommerce Naguro Connect Naguro Image Get Request class.

Defined (1)

The class is defined in the following location(s).

/includes/naguro/requests/class-image-get-request.php  
  1. class Naguro_Image_Get_Request extends Naguro_Request { 
  2. public function output() { 
  3. if ( isset( $this->params['image_id'] ) ) { 
  4. $id = absint( $this->params['image_id'] ); 
  5.  
  6. if ( get_post_meta( $id, '_naguro_image_session_id', true ) == $this->params['session'] ) { 
  7. $param_width = absint( $this->params['width'] ); 
  8. $image_src = wp_get_attachment_image_src( $id, 'full' ); 
  9.  
  10. $src = $image_src[0]; 
  11. $width = $image_src[1]; 
  12. $height = $image_src[2]; 
  13.  
  14. $this->params['src'] = $src; 
  15. $this->handler->handle_request('resize-image', $this->params, 'post' ); 
  16. $data = $this->handler->get_data(); 
  17. $body = json_decode( $data['body'] ); 
  18. $src = $body->filename; 
  19.  
  20. $tmp = download_url( $src ); 
  21. $file_array = array(); 
  22.  
  23. // If error storing temporarily, unlink 
  24. if ( is_wp_error( $tmp ) ) { 
  25. @unlink($file_array['tmp_name']); 
  26. $file_array['tmp_name'] = ''; 
  27.  
  28. // Set variables for storage 
  29. // fix file filename for query strings 
  30. preg_match('/[^\?]+\.(jpg|jpe|jpeg|gif|png)/i', $src, $matches); 
  31. $file_array['name'] = basename($matches[0]); 
  32. $file_array['tmp_name'] = $tmp; 
  33.  
  34. $new_id = media_handle_sideload( $file_array, 0 ); 
  35. update_post_meta( $new_id, '_naguro_image_session_id', $this->params['session']); 
  36. $image_src = wp_get_attachment_image_src( $new_id, 'full' ); 
  37. $src = $image_src[0]; 
  38.  
  39. echo json_encode( array( 
  40. 'id' => $id,  
  41. 'src' => $src,  
  42. 'width' => $width,  
  43. 'height' => $height,  
  44. ) ); 
  45. die();