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.

59 lines
1.8 KiB

  1. <?php
  2. namespace p3k\XRay;
  3. function view($template, $data=[]) {
  4. global $templates;
  5. return $templates->render($template, $data);
  6. }
  7. // Adds slash if no path is in the URL, and convert hostname to lowercase
  8. function normalize_url($url) {
  9. $parts = parse_url($url);
  10. if(empty($parts['path']))
  11. $parts['path'] = '/';
  12. $parts['host'] = strtolower($parts['host']);
  13. return build_url($parts);
  14. }
  15. function normalize_urls($urls) {
  16. return array_map('\p3k\XRay\normalize_url', $urls);
  17. }
  18. function urls_are_equal($url1, $url2) {
  19. $url1 = normalize_url($url1);
  20. $url2 = normalize_url($url2);
  21. return $url1 == $url2;
  22. }
  23. function build_url($parsed_url) {
  24. $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
  25. $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
  26. $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
  27. $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
  28. $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
  29. $pass = ($user || $pass) ? "$pass@" : '';
  30. $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
  31. $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
  32. $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
  33. return "$scheme$user$pass$host$port$path$query$fragment";
  34. }
  35. function should_follow_redirects($url) {
  36. $host = parse_url($url, PHP_URL_HOST);
  37. if(preg_match('/brid\.gy|appspot\.com|blogspot\.com|youtube\.com/', $host)) {
  38. return false;
  39. } else {
  40. return true;
  41. }
  42. }
  43. function phpmf2_version() {
  44. $composer = json_decode(file_get_contents(dirname(__FILE__).'/../composer.lock'));
  45. $version = 'unknown';
  46. foreach($composer->packages as $pkg) {
  47. if($pkg->name == 'mf2/mf2') {
  48. $version = $pkg->version;
  49. }
  50. }
  51. return $version;
  52. }