Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. <?php
  2.  
  3. class ffHttp extends ffBasicObject {
  4. const ARG_TIMEOUT = 'timeout';
  5. const ARG_USER_AGENT = 'user-agent';
  6.  
  7. /**
  8. *
  9. * @var ffWPLayer
  10. */
  11. private $WPLayer = null;
  12.  
  13. public function __construct( ffWPLayer $WPLayer ) {
  14. $this->_setWPLayer($WPLayer);
  15. }
  16.  
  17.  
  18. /*$args = array(
  19. 'timeout' => 5,
  20. 'redirection' => 5,
  21. 'httpversion' => '1.0',
  22. 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ),
  23. 'blocking' => true,
  24. 'headers' => array(),
  25. 'cookies' => array(),
  26. 'body' => null,
  27. 'compress' => false,
  28. 'decompress' => true,
  29. 'sslverify' => true,
  30. 'stream' => false,
  31. 'filename' => null
  32. );*/
  33.  
  34. public function get( $url, $arguments = array() ) {
  35. if( !isset($arguments['user-agent']) ) {
  36. $arguments['user-agent'] = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; rv:11.0) like Gecko';
  37. }
  38.  
  39. return $this->_getWPLayer()->wp_remote_get( $url, $arguments );
  40. }
  41.  
  42. public function getOnlyContentOfUrl( $url ) {
  43. $result = $this->get( $url );
  44.  
  45. if( $result instanceof WP_Error ) {
  46. return null;
  47. }
  48.  
  49. if( isset( $result['response'] ) && isset( $result['response']['code'] ) && $result['response']['code'] == 200 ) {
  50. return $result['body'];
  51. } else {
  52. return null;
  53. }
  54. }
  55.  
  56. /*
  57. * $response = wp_remote_post( $url, array(
  58. 'method' => 'POST',
  59. 'timeout' => 45,
  60. 'redirection' => 5,
  61. 'httpversion' => '1.0',
  62. 'blocking' => true,
  63. 'headers' => array(),
  64. 'body' => array( 'username' => 'bob', 'password' => '1234xyz' ),
  65. 'cookies' => array()
  66. )
  67. );
  68. */
  69.  
  70. public function post( $url, $post, $arguments = array() ) {
  71. $arguments['body'] = $post;
  72. return wp_remote_post( $url, $arguments );
  73. }
  74.  
  75. /**
  76. *
  77. * @param unknown $url
  78. * @param number $timeout
  79. */
  80. public function download( $url, $timeout = 300 ) {
  81. return $this->_getWPLayer()->download_url( $url, $timeout );
  82. }
  83.  
  84. /**
  85. * @return ffWPLayer
  86. */
  87. protected function _getWPLayer() {
  88. return $this->_WPLayer;
  89. }
  90.  
  91. /**
  92. * @param ffWPLayer $WPLayer
  93. */
  94. protected function _setWPLayer($WPLayer) {
  95. $this->_WPLayer = $WPLayer;
  96. return $this;
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement