/components/com_easyblog/classes/exceptional/remote.php

https://bitbucket.org/pastor399/newcastleunifc · PHP · 62 lines · 24 code · 4 blank · 34 comment · 3 complexity · 9626737b63c022c504b78c545452c905 MD5 · raw file

  1. <?php
  2. /**
  3. * @package EasyBlog
  4. * @copyright Copyright (C) 2010 Stack Ideas Private Limited. All rights reserved.
  5. * @license GNU/GPL, see LICENSE.php
  6. *
  7. * EasyBlog is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13. defined('_JEXEC') or die('Restricted access');
  14. class ExceptionalRemote {
  15. /*
  16. * Does the actual sending of an exception
  17. */
  18. static function send_exception($exception) {
  19. $uniqueness_hash = $exception->uniqueness_hash();
  20. $hash_param = ($uniqueness_hash) ? null : "&hash={$uniqueness_hash}";
  21. $url = "/api/errors?api_key=".Exceptional::$api_key."&protocol_version=".Exceptional::$protocol_version.$hash_param;
  22. $compressed = gzencode($exception->to_json(), 1);
  23. self::call_remote($url, $compressed);
  24. }
  25. /*
  26. * Sends a POST request
  27. */
  28. static function call_remote($url, $post_data) {
  29. if (Exceptional::$use_ssl === true) {
  30. $s = fsockopen("ssl://".Exceptional::$host, 443, $errno, $errstr, 4);
  31. }
  32. else {
  33. $s = fsockopen(Exceptional::$host, 80, $errno, $errstr, 2);
  34. }
  35. if (!$s) {
  36. echo "[Error $errno] $errstr\n";
  37. return false;
  38. }
  39. $request = "POST $url HTTP/1.1\r\n";
  40. $request .= "Host: ".Exceptional::$host."\r\n";
  41. $request .= "Accept: */*\r\n";
  42. $request .= "User-Agent: ".Exceptional::$client_name." ".Exceptional::$version."\r\n";
  43. $request .= "Content-Type: text/json\r\n";
  44. $request .= "Connection: close\r\n";
  45. $request .= "Content-Length: ".strlen($post_data)."\r\n\r\n";
  46. $request .= "$post_data\r\n";
  47. fwrite($s, $request);
  48. $response = "";
  49. while (!feof($s)) {
  50. $response .= fgets($s);
  51. }
  52. fclose($s);
  53. }
  54. }