fetch-mf2 843 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env php
  2. <?php
  3. $files = array(
  4. __DIR__ . '/../vendor/autoload.php',
  5. __DIR__ . '/../../../autoload.php',
  6. __DIR__ . '/../Mf2/Parser.php'
  7. );
  8. foreach ($files as $file) {
  9. if (file_exists($file)) {
  10. require $file;
  11. define('COMPOSER_INSTALL_LOCATION', $file);
  12. break;
  13. }
  14. }
  15. if (!defined('COMPOSER_INSTALL_LOCATION')) {
  16. die('A composer /vendor/autoload.php file could not be found. You need to install composer: https://getcomposer.org/download');
  17. }
  18. $url = $argv[1];
  19. if (empty($url)) {
  20. die("Please provide a URL to fetch+parse, e.g. bin/fetch-mf2 waterpigs.co.uk/notes");
  21. }
  22. if (!file_exists($url)) {
  23. if (!preg_match('|https?://|', $url)) {
  24. $url = 'http://' . $url;
  25. }
  26. }
  27. $result = Mf2\fetch($url);
  28. if (defined('JSON_PRETTY_PRINT')) {
  29. echo json_encode($result, JSON_PRETTY_PRINT);
  30. } else {
  31. echo json_encode($result);
  32. }