]> git.mxchange.org Git - friendica.git/commitdiff
The function "short_url" is used in several addons, so it deserves a central place.
authorMichael Vogel <icarus@dabo.de>
Sat, 3 May 2014 10:07:34 +0000 (12:07 +0200)
committerMichael Vogel <icarus@dabo.de>
Sat, 3 May 2014 10:07:34 +0000 (12:07 +0200)
include/network.php

index b85775ba2b801489e61d494216c0d1ca9a207b1d..310b988cb3460fcee23b4af08be4e83ae6688d8c 100644 (file)
@@ -1173,3 +1173,27 @@ function original_url($url, $depth=1, $fetchbody = false) {
 
         return($url);
 }
+
+if (!function_exists('short_link')) {
+function short_link($url) {
+       require_once('library/slinky.php');
+       $slinky = new Slinky($url);
+       $yourls_url = get_config('yourls','url1');
+       if ($yourls_url) {
+               $yourls_username = get_config('yourls','username1');
+               $yourls_password = get_config('yourls', 'password1');
+               $yourls_ssl = get_config('yourls', 'ssl1');
+               $yourls = new Slinky_YourLS();
+               $yourls->set('username', $yourls_username);
+               $yourls->set('password', $yourls_password);
+               $yourls->set('ssl', $yourls_ssl);
+               $yourls->set('yourls-url', $yourls_url);
+               $slinky->set_cascade( array($yourls, new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL()));
+       } else {
+               // setup a cascade of shortening services
+               // try to get a short link from these services
+               // in the order ur1.ca, trim, id.gd, tinyurl
+               $slinky->set_cascade(array(new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL()));
+       }
+       return $slinky->short();
+}};