Mirror of the main YOURLS application https://yourls.org/
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.

yourls-loader.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // Handle inexistent root favicon requests and exit
  3. if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
  4. header( 'Content-Type: image/gif' );
  5. echo base64_decode( "R0lGODlhEAAQAJECAAAAzFZWzP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0PUQAgSGoNQFt0LWTVOE6GuX1H6onTVHaW2tEHnJ1YxPc+UwAAOw==" );
  6. exit;
  7. }
  8. // Handle inexistent root robots.txt requests and exit
  9. if ( '/robots.txt' == $_SERVER['REQUEST_URI'] ) {
  10. header( 'Content-Type: text/plain; charset=utf-8' );
  11. echo "User-agent: *\n";
  12. echo "Disallow:\n";
  13. exit;
  14. }
  15. // Load YOURLS
  16. require_once __DIR__ . '/includes/load-yourls.php';
  17. // Get request in YOURLS base (eg in 'http://sho.rt/yourls/abcd' get 'abdc')
  18. $request = yourls_get_request();
  19. // Make valid regexp pattern from authorized charset in keywords
  20. $pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() );
  21. // Now load required template and exit
  22. yourls_do_action( 'pre_load_template', $request );
  23. // At this point, $request is not sanitized. Sanitize in loaded template.
  24. // Redirection:
  25. if( preg_match( "@^([$pattern]+)/?$@", $request, $matches ) ) {
  26. $keyword = isset( $matches[1] ) ? $matches[1] : '';
  27. $keyword = yourls_sanitize_keyword( $keyword );
  28. yourls_do_action( 'load_template_go', $keyword );
  29. require_once( YOURLS_ABSPATH.'/yourls-go.php' );
  30. exit;
  31. }
  32. // Stats:
  33. if( preg_match( "@^([$pattern]+)\+(all)?/?$@", $request, $matches ) ) {
  34. $keyword = isset( $matches[1] ) ? $matches[1] : '';
  35. $keyword = yourls_sanitize_keyword( $keyword );
  36. $aggregate = isset( $matches[2] ) ? (bool)$matches[2] && yourls_allow_duplicate_longurls() : false;
  37. yourls_do_action( 'load_template_infos', $keyword );
  38. require_once( YOURLS_ABSPATH.'/yourls-infos.php' );
  39. exit;
  40. }
  41. // Prefix-n-Shorten sends to bookmarklet (doesn't work on Windows)
  42. if( preg_match( "@^[a-zA-Z]+://.+@", $request, $matches ) ) {
  43. $url = yourls_sanitize_url( $matches[0] );
  44. if( $parse = yourls_get_protocol_slashes_and_rest( $url, array( 'up', 'us', 'ur' ) ) ) {
  45. yourls_do_action( 'load_template_redirect_admin', $url );
  46. $parse = array_map( 'rawurlencode', $parse );
  47. // Redirect to /admin/index.php?up=<url protocol>&us=<url slashes>&ur=<url rest>
  48. yourls_redirect( yourls_add_query_arg( $parse , yourls_admin_url( 'index.php' ) ), 302 );
  49. exit;
  50. }
  51. }
  52. // Past this point this is a request the loader could not understand
  53. yourls_do_action( 'loader_failed', $request );
  54. yourls_redirect( YOURLS_SITE, 302 );
  55. exit;