]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - yourls-loader.php
Change in logic: now all request are handled by PHP in yourls-loader.php instead...
[Github/YOURLS.git] / yourls-loader.php
1 <?php\r
2 // Handle inexistant root favicon requests and exit\r
3 if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {\r
4         header('Content-Type: image/gif');\r
5         echo base64_decode("R0lGODlhEAAQAJECAAAAzFZWzP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0PUQAgSGoNQFt0LWTVOE6GuX1H6onTVHaW2tEHnJ1YxPc+UwAAOw==");\r
6         exit;\r
7 }\r
8 \r
9 // Start YOURLS\r
10 require_once( dirname(__FILE__).'/includes/load-yourls.php' );\r
11 \r
12 // Get request in YOURLS base (eg in 'http://site.com/yourls/abcd' get 'abdc')\r
13 $scheme = ( isset($_SERVER["HTTPS"]) ? 'https' : 'http' );\r
14 $request = str_replace( YOURLS_SITE.'/', '', $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );\r
15 \r
16 // Make valid regexp pattern from authorized charset in keywords\r
17 $pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() );\r
18 \r
19 // Now load required template and exit\r
20 \r
21 yourls_do_action( 'pre_load_template', $request );\r
22 \r
23 // At this point, $request is not sanitized. Sanitize in loaded template.\r
24 \r
25 // Redirection:\r
26 if( preg_match( "/^([$pattern]+)\/?$/", $request, $matches ) ) {\r
27         $keyword   = isset( $matches[1] ) ? $matches[1] : '';\r
28         include( YOURLS_ABSPATH.'/yourls-go.php' );\r
29         exit;\r
30 }\r
31 \r
32 // Stats:\r
33 if( preg_match( "/^([$pattern]+)\+(all)?\/?$/", $request, $matches ) ) {\r
34         $keyword   = isset( $matches[1] ) ? $matches[1] : '';\r
35         $aggregate = isset( $matches[2] ) ? (bool)$matches[2] && yourls_allow_duplicate_longurls() : false;\r
36         include( YOURLS_ABSPATH.'/yourls-infos.php' );\r
37         exit;\r
38 }\r
39 \r
40 // Past this point this is a request the loader could not understand\r
41 yourls_do_action( 'loader_failed', $request );\r
42 yourls_redirect( YOURLS_SITE, 307 );\r
43 exit;