Skip to content

Commit

Permalink
Make yourls_is_shorturl() accept keyword and URLs. Fixes YOURLS#1366.
Browse files Browse the repository at this point in the history
  • Loading branch information
ozh committed Apr 30, 2013
1 parent 296da8b commit 99e2434
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 99e2434

Please sign in to comment.