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.

38 lines
1.3 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 build_url($parsed_url) {
  16. $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
  17. $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
  18. $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
  19. $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
  20. $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
  21. $pass = ($user || $pass) ? "$pass@" : '';
  22. $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
  23. $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
  24. $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
  25. return "$scheme$user$pass$host$port$path$query$fragment";
  26. }
  27. function should_follow_redirects($url) {
  28. $host = parse_url($url, PHP_URL_HOST);
  29. if(preg_match('/brid\.gy|appspot\.com|blogspot\.com|youtube\.com/', $host)) {
  30. return false;
  31. } else {
  32. return true;
  33. }
  34. }