From 99e243414a709ab9bd6e8574e8dabb7e5d252d93 Mon Sep 17 00:00:00 2001 From: ozh Date: Wed, 1 May 2013 00:17:54 +0200 Subject: [PATCH] Make yourls_is_shorturl() accept keyword and URLs. Fixes #1366. --- includes/functions.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 5550e10..ff1ae65 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -42,14 +42,22 @@ function yourls_make_regexp_pattern( $string ) { } /** - * Is a URL a short URL? + * Is a URL a short URL? Accept either 'http://sho.rt/abc' or 'abc' * */ function yourls_is_shorturl( $shorturl ) { // TODO: make sure this function evolves with the feature set. $is_short = false; - $keyword = yourls_get_relative_url( $shorturl ); // accept either 'http://ozh.in/abc' or 'abc' + + // Is $shorturl a URL (http://sho.rt/abc) or a keyword (abc) ? + if( yourls_get_protocol( $shorturl ) ) { + $keyword = yourls_get_relative_url( $shorturl ); + } else { + $keyword = $shorturl; + } + + // Check if it's a valid && used keyword if( $keyword && $keyword == yourls_sanitize_string( $keyword ) && yourls_keyword_is_taken( $keyword ) ) { $is_short = true; } @@ -1985,7 +1993,7 @@ function yourls_get_protocol( $url ) { */ function yourls_get_relative_url( $url, $strict = true ) { $url = yourls_sanitize_url( $url ); - + // Remove protocols to make it easier $noproto_url = str_replace( 'https:', 'http:', $url ); $noproto_site = str_replace( 'https:', 'http:', YOURLS_SITE ); -- 2.45.0