From 955022e7dc6bb8f581177ddbad84b4f59c349763 Mon Sep 17 00:00:00 2001 From: Keith Fernie Date: Thu, 9 Feb 2012 20:45:38 +0000 Subject: [PATCH 1/2] modified: library/slinky.php Added a custom YourLS shortener to the available shorteners --- library/slinky.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/library/slinky.php b/library/slinky.php index 51432c3f53..56734c9fb0 100755 --- a/library/slinky.php +++ b/library/slinky.php @@ -153,7 +153,7 @@ class Slinky { public function set_service_from_url( $url = false ) { if ( !$url ) $url = $this->url; - + $host = parse_url( $url, PHP_URL_HOST ); switch ( str_replace( 'www.', '', $host ) ) { case 'bit.ly': @@ -181,6 +181,11 @@ class Slinky { $this->service = new Slinky_Fongs(); break; } + case $this->get( 'yourls-url' ): + if ( class_exists( 'Slinky_YourLS' ) ) { + $this->service = new Slinky_YourLS(); + break; + } case 'micurl.com': if ( class_exists( 'Slinky_Micurl' ) ) { $this->service = new Slinky_Micurl(); @@ -574,6 +579,31 @@ class Slinky_Fongs extends Slinky_Service { } } +// yourls +class Slinky_YourLS extends Slinky_Service { + function url_is_short( $url ) { + return stristr( $url, 'shit.li/' ); + } + + function url_is_long( $url ) { + return !stristr( $url, 'shit.li/' ); + } + + function make_short( $url ) { + echo $this->get( 'username' ); + $use_ssl = $this->get( 'ssl' ); + if ( $use_ssl ) + $use_ssl = 's'; + else + $use_ssl = ''; + $result = $this->url_get( 'http'. $use_ssl . '://' . $this->get( 'yourls-url' ) . '/yourls-api.php?username=' . $this->get( 'username' ) . '&password=' . $this->get( 'password' ) . '&action=shorturl&format=simple&url=' . urlencode( $url ) ); + if ( 1 != $result && 2 != $result ) + return $result; + else + return $url; + } +} + // Micu.rl class Slinky_Micurl extends Slinky_Service { function url_is_short( $url ) { From 2c9cfb1fe9fe331cb386025643b2c23a32b25787 Mon Sep 17 00:00:00 2001 From: Keith Fernie Date: Thu, 9 Feb 2012 21:44:52 +0000 Subject: [PATCH 2/2] modified: library/slinky.php Set up tabs in code correctly. --- library/slinky.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/library/slinky.php b/library/slinky.php index 56734c9fb0..cae1f755ff 100755 --- a/library/slinky.php +++ b/library/slinky.php @@ -181,11 +181,11 @@ class Slinky { $this->service = new Slinky_Fongs(); break; } - case $this->get( 'yourls-url' ): - if ( class_exists( 'Slinky_YourLS' ) ) { - $this->service = new Slinky_YourLS(); - break; - } + case $this->get( 'yourls-url' ): + if ( class_exists( 'Slinky_YourLS' ) ) { + $this->service = new Slinky_YourLS(); + break; + } case 'micurl.com': if ( class_exists( 'Slinky_Micurl' ) ) { $this->service = new Slinky_Micurl(); @@ -581,27 +581,27 @@ class Slinky_Fongs extends Slinky_Service { // yourls class Slinky_YourLS extends Slinky_Service { - function url_is_short( $url ) { - return stristr( $url, 'shit.li/' ); + function url_is_short( $url ) { + return stristr( $url, 'shit.li/' ); } - function url_is_long( $url ) { - return !stristr( $url, 'shit.li/' ); + function url_is_long( $url ) { + return !stristr( $url, 'shit.li/' ); } - function make_short( $url ) { + function make_short( $url ) { echo $this->get( 'username' ); $use_ssl = $this->get( 'ssl' ); if ( $use_ssl ) $use_ssl = 's'; else $use_ssl = ''; - $result = $this->url_get( 'http'. $use_ssl . '://' . $this->get( 'yourls-url' ) . '/yourls-api.php?username=' . $this->get( 'username' ) . '&password=' . $this->get( 'password' ) . '&action=shorturl&format=simple&url=' . urlencode( $url ) ); - if ( 1 != $result && 2 != $result ) - return $result; - else - return $url; - } + $result = $this->url_get( 'http'. $use_ssl . '://' . $this->get( 'yourls-url' ) . '/yourls-api.php?username=' . $this->get( 'username' ) . '&password=' . $this->get( 'password' ) . '&action=shorturl&format=simple&url=' . urlencode( $url ) ); + if ( 1 != $result && 2 != $result ) + return $result; + else + return $url; + } } // Micu.rl