forked from YOURLS/YOURLS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyourls-api.php
62 lines (48 loc) · 1.97 KB
/
yourls-api.php
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
define('YOURLS_API', true);
require_once( dirname(__FILE__).'/includes/load-yourls.php' );
yourls_maybe_require_auth();
$action = ( isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : null );
yourls_do_action( 'api', $action );
switch( $action ) {
// Shorten a URL
case 'shorturl':
$url = ( isset( $_REQUEST['url'] ) ? $_REQUEST['url'] : '' );
$keyword = ( isset( $_REQUEST['keyword'] ) ? $_REQUEST['keyword'] : '' );
$title = ( isset( $_REQUEST['title'] ) ? $_REQUEST['title'] : '' );
$return = yourls_add_new_link( $url, $keyword, $title );
$return['simple'] = ( isset( $return['shorturl'] ) ? $return['shorturl'] : '' ); // This one will be used in case output mode is 'simple'
unset( $return['html'] ); // in API mode, no need for our internal HTML output
break;
// Stats about links (XX top, bottom, last, rand)
case 'stats':
$filter = ( isset( $_REQUEST['filter'] ) ? $_REQUEST['filter'] : '' );
$limit = ( isset( $_REQUEST['limit'] ) ? $_REQUEST['limit'] : '' );
$start = ( isset( $_REQUEST['start'] ) ? $_REQUEST['start'] : '' );
$return = yourls_api_stats( $filter, $limit, $start );
break;
// Just the global counts of shorturls and clicks
case "db-stats":
$return = yourls_api_db_stats();
break;
// Stats for a shorturl
case 'url-stats':
$shorturl = ( isset( $_REQUEST['shorturl'] ) ? $_REQUEST['shorturl'] : '' );
$return = yourls_api_url_stats( $shorturl );
break;
// Expand a short link
case 'expand':
$shorturl = ( isset( $_REQUEST['shorturl'] ) ? $_REQUEST['shorturl'] : '' );
$return = yourls_api_expand( $shorturl );
break;
// Missing or incorrect action parameter
default:
$return = array(
'errorCode' => 400,
'message' => 'Unknown or missing "action" parameter',
'simple' => 'Unknown or missing "action" parameter',
);
}
$format = ( isset( $_REQUEST['format'] ) ? $_REQUEST['format'] : 'xml' );
yourls_api_output( $format, $return );
die();