Redux_P

The evolve Redux P class.

Defined (1)

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

/library/admin/redux-framework/inc/class.p.php  
  1. class Redux_P { 
  2.  
  3. public function __construct() { 
  4.  
  5. add_action( "wp_ajax_nopriv_redux_p", array( $this, 'proxy' ) ); 
  6. add_action( "wp_ajax_redux_p", array( $this, 'proxy' ) ); 
  7.  
  8. public function proxy() { 
  9.  
  10. if ( ! isset( $_GET['nonce'] ) || ( isset( $_GET['nonce'] ) && ! wp_verify_nonce( $_GET['nonce'], "redux-ads-nonce" ) ) ) { 
  11. die(); 
  12.  
  13. // Script: Simple PHP Proxy: Get external HTML, JSON and more! 
  14. // 
  15. // *Version: 1.6, Last updated: 1/24/2009* 
  16. // 
  17. // Project Home - http://benalman.com/projects/php-simple-proxy/ 
  18. // GitHub - http://github.com/cowboy/php-simple-proxy/ 
  19. // Source - http://github.com/cowboy/php-simple-proxy/raw/master/ba-simple-proxy.php 
  20. // 
  21. // About: License 
  22. // 
  23. // Copyright (c) 2010 "Cowboy" Ben Alman,  
  24. // Dual licensed under the MIT and GPL licenses. 
  25. // http://benalman.com/about/license/ 
  26. // 
  27. // About: Examples 
  28. // 
  29. // This working example, complete with fully commented code, illustrates one way 
  30. // in which this PHP script can be used. 
  31. // 
  32. // Simple - http://benalman.com/code/projects/php-simple-proxy/examples/simple/ 
  33. // 
  34. // About: Release History 
  35. // 
  36. // 1.6 - (1/24/2009) Now defaults to JSON mode, which can now be changed to 
  37. // native mode by specifying ?mode=native. Native and JSONP modes are 
  38. // disabled by default because of possible XSS vulnerability issues, but 
  39. // are configurable in the PHP script along with a url validation regex. 
  40. // 1.5 - (12/27/2009) Initial release 
  41. // 
  42. // Topic: GET Parameters 
  43. // 
  44. // Certain GET (query string) parameters may be passed into ba-simple-proxy.php 
  45. // to control its behavior, this is a list of these parameters. 
  46. // 
  47. // url - The remote URL resource to fetch. Any GET parameters to be passed 
  48. // through to the remote URL resource must be urlencoded in this parameter. 
  49. // mode - If mode=native, the response will be sent using the same content 
  50. // type and headers that the remote URL resource returned. If omitted, the 
  51. // response will be JSON (or JSONP). <Native requests> and <JSONP requests> 
  52. // are disabled by default, see <Configuration Options> for more information. 
  53. // callback - If specified, the response JSON will be wrapped in this named 
  54. // function call. This parameter and <JSONP requests> are disabled by 
  55. // default, see <Configuration Options> for more information. 
  56. // user_agent - This value will be sent to the remote URL request as the 
  57. // `User-Agent:` HTTP request header. If omitted, the browser user agent 
  58. // will be passed through. 
  59. // send_cookies - If send_cookies=1, all cookies will be forwarded through to 
  60. // the remote URL request. 
  61. // send_session - If send_session=1 and send_cookies=1, the SID cookie will be 
  62. // forwarded through to the remote URL request. 
  63. // full_headers - If a JSON request and full_headers=1, the JSON response will 
  64. // contain detailed header information. 
  65. // full_status - If a JSON request and full_status=1, the JSON response will 
  66. // contain detailed cURL status information, otherwise it will just contain 
  67. // the `http_code` property. 
  68. // 
  69. // Topic: POST Parameters 
  70. // 
  71. // All POST parameters are automatically passed through to the remote URL 
  72. // request. 
  73. // 
  74. // Topic: JSON requests 
  75. // 
  76. // This request will return the contents of the specified url in JSON format. 
  77. // 
  78. // Request: 
  79. // 
  80. // > ba-simple-proxy.php?url=http://example.com/ 
  81. // 
  82. // Response: 
  83. // 
  84. // > { "contents": "<html>...</html>", "headers": {...}, "status": {...} } 
  85. // 
  86. // JSON object properties: 
  87. // 
  88. // contents - (String) The contents of the remote URL resource. 
  89. // headers - (Object) A hash of HTTP headers returned by the remote URL 
  90. // resource. 
  91. // status - (Object) A hash of status codes returned by cURL. 
  92. // 
  93. // Topic: JSONP requests 
  94. // 
  95. // This request will return the contents of the specified url in JSONP format 
  96. // (but only if $enable_jsonp is enabled in the PHP script). 
  97. // 
  98. // Request: 
  99. // 
  100. // > ba-simple-proxy.php?url=http://example.com/&callback=foo 
  101. // 
  102. // Response: 
  103. // 
  104. // > foo({ "contents": "<html>...</html>", "headers": {...}, "status": {...} }) 
  105. // 
  106. // JSON object properties: 
  107. // 
  108. // contents - (String) The contents of the remote URL resource. 
  109. // headers - (Object) A hash of HTTP headers returned by the remote URL 
  110. // resource. 
  111. // status - (Object) A hash of status codes returned by cURL. 
  112. // 
  113. // Topic: Native requests 
  114. // 
  115. // This request will return the contents of the specified url in the format it 
  116. // was received in, including the same content-type and other headers (but only 
  117. // if $enable_native is enabled in the PHP script). 
  118. // 
  119. // Request: 
  120. // 
  121. // > ba-simple-proxy.php?url=http://example.com/&mode=native 
  122. // 
  123. // Response: 
  124. // 
  125. // > <html>...</html> 
  126. // 
  127. // Topic: Notes 
  128. // 
  129. // * Assumes magic_quotes_gpc = Off in php.ini 
  130. // 
  131. // Topic: Configuration Options 
  132. // 
  133. // These variables can be manually edited in the PHP file if necessary. 
  134. // 
  135. // $enable_jsonp - Only enable <JSONP requests> if you really need to. If you 
  136. // install this script on the same server as the page you're calling it 
  137. // from, plain JSON will work. Defaults to false. 
  138. // $enable_native - You can enable <Native requests>, but you should only do 
  139. // this if you also whitelist specific URLs using $valid_url_regex, to avoid 
  140. // possible XSS vulnerabilities. Defaults to false. 
  141. // $valid_url_regex - This regex is matched against the url parameter to 
  142. // ensure that it is valid. This setting only needs to be used if either 
  143. // $enable_jsonp or $enable_native are enabled. Defaults to '/.*/' which 
  144. // validates all URLs. 
  145. // 
  146. // ############################################################################ 
  147.  
  148.  
  149. $_GET['mode'] = "native"; 
  150. $_GET['full_headers'] = 1; 
  151. $_GET['full_status'] = 1; 
  152. $_GET['send_cookies'] = 1; 
  153.  
  154.  
  155. // Change these configuration options if needed, see above descriptions for info. 
  156. $enable_jsonp = false; 
  157. $enable_native = true; 
  158. $valid_url_regex = '/.*/'; 
  159.  
  160. // ############################################################################ 
  161. $url = $_GET['url']; 
  162.  
  163. if ( isset( $_GET['nonce'] ) ) { 
  164. $url = str_replace( 'nonce=' . $_GET['nonce'] . '&', '', $url ); 
  165.  
  166.  
  167. if ( ! $url ) { 
  168.  
  169. // Passed url not specified. 
  170. $contents = 'ERROR: url not specified'; 
  171. $status = array( 'http_code' => 'ERROR' ); 
  172.  
  173. } else if ( ! preg_match( $valid_url_regex, $url ) ) { 
  174.  
  175. // Passed url doesn't match $valid_url_regex. 
  176. $contents = 'ERROR: invalid url'; 
  177. $status = array( 'http_code' => 'ERROR' ); 
  178.  
  179. } else { 
  180. $url = urldecode( $url ); 
  181. if ( isset( $_GET['proxy'] ) ) { 
  182. $url .= '&proxy=' . $_GET['proxy']; 
  183.  
  184. // Ad URL rewrite 
  185. if ( strpos( $url, 'http' ) === false ) { 
  186. $url = 'http:' . $url; 
  187.  
  188. if ( isset( $_GET['callback'] ) ) { 
  189. foreach ( $_GET as $key => $value ) { 
  190. if ( in_array( $key, array( 'url', 'mode', 'full_headers', 'full_status', 'send_cookies' ) ) ) { 
  191. continue; 
  192. $url .= "&" . $key . '=' . $value; 
  193.  
  194.  
  195. $args = array( 
  196. 'user-agent' => isset( $_GET['user_agent'] ) ? $_GET['user_agent'] : $_SERVER['HTTP_USER_AGENT'],  
  197. 'method' => 'GET',  
  198. ); 
  199.  
  200. if ( isset( $_GET['send_cookies'] ) && $_GET['send_cookies'] ) { 
  201. $cookie = array(); 
  202. foreach ( $_COOKIE as $key => $value ) { 
  203. $cookie[] = $key . '=' . $value; 
  204. if ( isset( $_GET['send_session'] ) && $_GET['send_session'] ) { 
  205. $cookie[] = SID; 
  206. $args['cookies'] = $cookie; 
  207.  
  208. if ( strtolower( $_SERVER['REQUEST_METHOD'] ) == 'post' ) { 
  209. $args['body'] = $_POST; 
  210. $args['method'] = 'POST'; 
  211.  
  212.  
  213.  
  214. $response = wp_remote_request( 
  215. $url,  
  216. $args 
  217. ); 
  218.  
  219. if ( ! is_wp_error( $response ) ) { 
  220. $status = $response['response']['code']; 
  221. $contents = $response['body']; 
  222.  
  223.  
  224.  
  225. if ( isset( $_GET['mode'] ) && $_GET['mode'] == 'native' ) { 
  226. if ( ! $enable_native ) { 
  227. $contents = 'ERROR: invalid mode'; 
  228. $status = array( 'http_code' => 'ERROR' ); 
  229.  
  230. if ( ! is_wp_error( $response ) && isset( $response['headers']['content-type'] ) ) { 
  231. header( 'Content-Type: ' . $response['headers']['content-type'] ); 
  232. if ( ! is_wp_error( $response ) && isset( $response['headers']['content-language'] ) ) { 
  233. header( 'Content-Language: ' . $response['headers']['content-language'] ); 
  234. if ( ! is_wp_error( $response ) && isset( $response['headers']['set-cookie'] ) ) { 
  235. header( 'Set-Cookie: ' . $response['headers']['set-cookie'] ); 
  236.  
  237. if ( isset( $contents ) ) { 
  238. print str_replace( 'ads.reduxframework.com', 'look.reduxframework.com', $contents ); 
  239.  
  240. } else { 
  241.  
  242. // $data will be serialized into JSON data. 
  243. $data = array(); 
  244.  
  245. // Propagate all HTTP headers into the JSON data object. 
  246. if ( isset( $_GET['full_headers'] ) && $_GET['full_headers'] ) { 
  247. $data['headers'] = array(); 
  248.  
  249.  
  250. // Propagate all cURL request / response info to the JSON data object. 
  251. if ( isset( $_GET['full_status'] ) && $_GET['full_status'] ) { 
  252. $data['status'] = $status; 
  253. } else { 
  254. $data['status'] = array(); 
  255. $data['status']['http_code'] = $status['http_code']; 
  256.  
  257. // Set the JSON data object contents, decoding it from JSON if possible. 
  258. $decoded_json = json_decode( $contents ); 
  259. $data['contents'] = str_replace( 'e(window).width()', 'window.innerWidth||e(window).width()', $decoded_json ? $decoded_json : $contents ); 
  260.  
  261. // Generate appropriate content-type header. 
  262.  
  263. $is_xhr = isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) ? strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) : 'xmlhttprequest'; 
  264. header( 'Content-type: application/' . ( $is_xhr ? 'json' : 'x-javascript' ) ); 
  265.  
  266. // Get JSONP callback. 
  267. $jsonp_callback = $enable_jsonp && isset( $_GET['callback'] ) ? $_GET['callback'] : null; 
  268.  
  269. // Generate JSON/JSONP string 
  270. $json = json_encode( $data ); 
  271.  
  272. print $jsonp_callback ? "$jsonp_callback($json)" : $json; 
  273.  
  274.