You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7 KiB

  1. <?php
  2. namespace p3k;
  3. class XRay {
  4. public $http;
  5. public function __construct() {
  6. $this->http = new HTTP();
  7. }
  8. public function rels($url, $opts=[]) {
  9. $rels = new XRay\Rels($this->http);
  10. return $rels->parse($url, $opts);
  11. }
  12. public function feeds($url, $opts=[]) {
  13. $feeds = new XRay\Feeds($this->http);
  14. return $feeds->find($url, $opts);
  15. }
  16. public function parse($url, $opts_or_body=false, $opts_for_body=[]) {
  17. if(!$opts_or_body || is_array($opts_or_body)) {
  18. $fetch = new XRay\Fetcher($this->http);
  19. $response = $fetch->fetch($url, $opts_or_body);
  20. if(!empty($response['error']))
  21. return $response;
  22. $body = $response['body'];
  23. $url = $response['url'];
  24. $code = $response['code'];
  25. $opts = is_array($opts_or_body) ? $opts_or_body : $opts_for_body;
  26. } else {
  27. $body = $opts_or_body;
  28. $opts = $opts_for_body;
  29. $code = null;
  30. }
  31. $parser = new XRay\Parser($this->http);
  32. $result = $parser->parse($body, $url, $opts);
  33. if(!isset($opts['include_original']) || !$opts['include_original'])
  34. unset($result['original']);
  35. $result['url'] = $url;
  36. $result['code'] = isset($result['code']) ? $result['code'] : $code;
  37. $result['source-format'] = isset($result['source-format']) ? $result['source-format'] : null;
  38. return $result;
  39. }
  40. public function process($url, $mf2json, $opts=[]) {
  41. $parser = new XRay\Parser($this->http);
  42. $result = $parser->parse($mf2json, $url, $opts);
  43. if(!isset($opts['include_original']) || !$opts['include_original'])
  44. unset($result['original']);
  45. $result['url'] = $url;
  46. $result['source-format'] = isset($result['source-format']) ? $result['source-format'] : null;
  47. return $result;
  48. }
  49. }