-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUrlComponent.php
More file actions
27 lines (24 loc) · 795 Bytes
/
UrlComponent.php
File metadata and controls
27 lines (24 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
/**
* --- URL Component ---
* Github: https://github.com/steven/Cakephp-2.0.Component-URL
* For generating a short URL by using bitly.com
* You will need a free account from https://bitly.com/ to set up your API credentials
*
* @author Steven Thompson <steven@fantasmagorical.co.uk>
*/
class UrlComponent extends Component
{
var $login = 'LOGINUSERNAME';
var $apiKey = 'APIKEY';
// Returns the short URL from bit.ly
function shorten($url) {
$api_call = file_get_contents("http://api.bit.ly/shorten?version=2.0.1&longUrl=".$url."&login=".$bitly_login."&apiKey=".$bitly_apikey);
$bitlyinfo=json_decode(utf8_encode($api_call),true);
if ($bitlyinfo['errorCode']==0) {
return $bitlyinfo['results'][urldecode($url)]['shortUrl'];
} else {
return false;
}
}
} ?>