From a45575f6ab86dba43d101c21c645d44a59280e5c Mon Sep 17 00:00:00 2001 From: ozhozh Date: Sat, 12 Jun 2010 17:01:04 +0000 Subject: [PATCH] Change in logic: now all request are handled by PHP in yourls-loader.php instead of relying on .htaccess. Fixes issue 358. git-svn-id: http://yourls.googlecode.com/svn/trunk@393 12232710-3e20-11de-b438-597f59cd7555 --- changelog.txt | 1 + includes/functions.php | 6 +++--- yourls-go.php | 8 ++++---- yourls-infos.php | 17 ++++++++++------- yourls-loader.php | 35 ++++++++++++++++++++++------------- 5 files changed, 40 insertions(+), 27 deletions(-) diff --git a/changelog.txt b/changelog.txt index 4306945..0378b1d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -57,4 +57,5 @@ list, simply refer to the commit messages: http://code.google.com/p/yourls/sourc - added directory /user, config.php can be moved there - added new instant bookmarklets - added 1 click copy to clipboard a la bitly +- change in logic: now all request are handled by PHP and don't rely on .htaccess - working on: maintenance mode \ No newline at end of file diff --git a/includes/functions.php b/includes/functions.php index 953baf4..e2220f8 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -11,15 +11,15 @@ function yourls_get_shorturl_charset() { return $charset; if( !defined('YOURLS_URL_CONVERT') ) { - $charset = '0123456789abcdefghijklmnopqrstuvwxyz'; + $charset = '0123456789abcdefghijklmnopqrstuvwxyz-'; } else { switch( YOURLS_URL_CONVERT ) { case 36: - $charset = '0123456789abcdefghijklmnopqrstuvwxyz'; + $charset = '0123456789abcdefghijklmnopqrstuvwxyz-'; break; case 62: case 64: // just because some people get this wrong in their config.php - $charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-'; break; } } diff --git a/yourls-go.php b/yourls-go.php index bf7756f..f8ccdbd 100644 --- a/yourls-go.php +++ b/yourls-go.php @@ -2,9 +2,10 @@ define('YOURLS_GO', true); require_once( dirname(__FILE__).'/includes/load-yourls.php' ); -// Variables -$id = ( isset( $_GET['id'] ) ? $_GET['id'] : '' ); -$keyword = yourls_sanitize_string( $id ); +// Variables should be defined in yourls-loader.php, if not try GET request (old behavior of yourls-go.php) +if( !isset( $keyword ) && isset( $_GET['id'] ) ) + $keyword = $_GET['id']; +$keyword = yourls_sanitize_string( $keyword ); // First possible exit: if ( !$keyword ) { @@ -42,4 +43,3 @@ } } exit(); -?> \ No newline at end of file diff --git a/yourls-infos.php b/yourls-infos.php index 6324679..6853fa8 100644 --- a/yourls-infos.php +++ b/yourls-infos.php @@ -1,20 +1,23 @@ "; - // Start YOURLS require_once( dirname(__FILE__).'/includes/load-yourls.php' ); -// Load required template - -// Get request in YOURLS base +// Get request in YOURLS base (eg in 'http://site.com/yourls/abcd' get 'abdc') $scheme = ( isset($_SERVER["HTTPS"]) ? 'https' : 'http' ); $request = str_replace( YOURLS_SITE.'/', '', $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); // Make valid regexp pattern from authorized charset in keywords $pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() ); -// Test server request and redirect accordingly +// Now load required template and exit + +yourls_do_action( 'pre_load_template', $request ); + +// At this point, $request is not sanitized. Sanitize in loaded template. + +// Redirection: if( preg_match( "/^([$pattern]+)\/?$/", $request, $matches ) ) { - // yourls-go.php?id=$1 + $keyword = isset( $matches[1] ) ? $matches[1] : ''; + include( YOURLS_ABSPATH.'/yourls-go.php' ); + exit; } -if( preg_match( "/^([$pattern]+)\+\/?$/", $request, $matches ) ) { - // yourls-infos.php?id=$1 +// Stats: +if( preg_match( "/^([$pattern]+)\+(all)?\/?$/", $request, $matches ) ) { + $keyword = isset( $matches[1] ) ? $matches[1] : ''; + $aggregate = isset( $matches[2] ) ? (bool)$matches[2] && yourls_allow_duplicate_longurls() : false; + include( YOURLS_ABSPATH.'/yourls-infos.php' ); + exit; } -if( preg_match( "/^([$pattern]+)\+all\/?$/", $request, $matches ) ) { - // yourls-infos.php?id=$1&all=1 -} +// Past this point this is a request the loader could not understand +yourls_do_action( 'loader_failed', $request ); +yourls_redirect( YOURLS_SITE, 307 ); +exit; \ No newline at end of file -- 2.45.0