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.

36 lines
1.3 KiB

  1. <?php
  2. function view($template, $data=[]) {
  3. global $templates;
  4. return $templates->render($template, $data);
  5. }
  6. // Adds slash if no path is in the URL, and convert hostname to lowercase
  7. function normalize_url($url) {
  8. $parts = parse_url($url);
  9. if(empty($parts['path']))
  10. $parts['path'] = '/';
  11. $parts['host'] = strtolower($parts['host']);
  12. return build_url($parts);
  13. }
  14. function build_url($parsed_url) {
  15. $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
  16. $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
  17. $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
  18. $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
  19. $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
  20. $pass = ($user || $pass) ? "$pass@" : '';
  21. $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
  22. $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
  23. $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
  24. return "$scheme$user$pass$host$port$path$query$fragment";
  25. }
  26. function should_follow_redirects($url) {
  27. $host = parse_url($url, PHP_URL_HOST);
  28. if(preg_match('/brid\.gy|appspot\.com|blogspot\.com|youtube\.com/', $host)) {
  29. return false;
  30. } else {
  31. return true;
  32. }
  33. }