[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/ -> yourls-loader.php (source)

   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  
   9  // Handle inexistent root robots.txt requests and exit
  10  if ( '/robots.txt' == $_SERVER['REQUEST_URI'] ) {
  11      header( 'Content-Type: text/plain; charset=utf-8' );
  12      echo "User-agent: *\n";
  13      echo "Disallow:\n";
  14      exit;
  15  }
  16  
  17  // Load YOURLS
  18  require_once  __DIR__ . '/includes/load-yourls.php';
  19  
  20  // Get request in YOURLS base (eg in 'http://sho.rt/yourls/abcd' get 'abdc')
  21  // At this point, $request is NOT sanitized.
  22  $request = yourls_get_request();
  23  
  24  // Now load required template and exit
  25  yourls_do_action( 'pre_load_template', $request );
  26  
  27  // Let's look at the request : what we want to catch here is "anything", or "anything+" / "anything+all" (stat page)
  28  preg_match( "@^(.+?)(\+(all)?)?/?$@", $request, $matches );
  29  $keyword   = isset($matches[1]) ? $matches[1] : null; // 'anything' whatever the request is (keyword, bookmarklet URL...)
  30  $stats     = isset($matches[2]) ? $matches[2] : null; // null, or '+' if request is 'anything+', '+all' if request is 'anything+all'
  31  $stats_all = isset($matches[3]) ? $matches[3] : null; // null, or 'all' if request is 'anything+all'
  32  
  33  // if request has a scheme (eg scheme://uri) : "Prefix-n-Shorten" sends to bookmarklet (doesn't work on Windows)
  34  if ( yourls_get_protocol($keyword) ) {
  35      $url = yourls_sanitize_url_safe($keyword);
  36      $parse = yourls_get_protocol_slashes_and_rest( $url, [ 'up', 'us', 'ur' ] );
  37      yourls_do_action( 'load_template_redirect_admin', $url );
  38      yourls_do_action( 'pre_redirect_bookmarklet', $url );
  39  
  40      // Redirect to /admin/index.php?up=<url protocol>&us=<url slashes>&ur=<url rest>
  41      yourls_redirect( yourls_add_query_arg( $parse , yourls_admin_url( 'index.php' ) ), 302 );
  42      exit;
  43  }
  44  
  45  // if request is an existing short URL keyword ('abc') or stat page ('abc+') or an existing page :
  46  if ( yourls_keyword_is_taken($keyword) or yourls_is_page($keyword) ) {
  47  
  48      // we have a short URL or a page
  49      if( $keyword && !$stats ) {
  50          yourls_do_action( 'load_template_go', $keyword );
  51          require_once ( YOURLS_ABSPATH.'/yourls-go.php' );
  52          exit;
  53      }
  54  
  55      // we have a stat page
  56      if( $keyword && $stats ) {
  57          $aggregate = $stats_all && yourls_allow_duplicate_longurls();
  58          yourls_do_action( 'load_template_infos', $keyword );
  59          require_once ( YOURLS_ABSPATH.'/yourls-infos.php' );
  60          exit;
  61      }
  62  
  63  }
  64  
  65  // Past this point this is a request the loader could not understand : not a valid shorturl, not a bookmarklet
  66  yourls_do_action( 'redirect_keyword_not_found', $keyword );
  67  yourls_do_action( 'loader_failed', $request );
  68  yourls_redirect( YOURLS_SITE, 302 );
  69  exit;


Generated: Tue Dec 6 05:10:02 2022 Cross-referenced by PHPXref 0.7.1