forked from YOURLS/YOURLS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyourls-api.php
More file actions
58 lines (48 loc) · 1.7 KB
/
yourls-api.php
File metadata and controls
58 lines (48 loc) · 1.7 KB
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
<?php
/**
* YOURLS API
*
* This file is the entry point for the YOURLS API. It handles all API requests
* and returns the results in the requested format.
*
* @package YOURLS
* @since 1.0
*/
define( 'YOURLS_API', true );
require_once( dirname( __FILE__ ) . '/includes/load-yourls.php' );
yourls_maybe_require_auth();
$action = $_REQUEST['action'] ?? null;
yourls_do_action( 'api', $action );
// Define standard API actions
$api_actions = array(
'shorturl' => 'yourls_api_action_shorturl',
'stats' => 'yourls_api_action_stats',
'db-stats' => 'yourls_api_action_db_stats',
'url-stats' => 'yourls_api_action_url_stats',
'expand' => 'yourls_api_action_expand',
'version' => 'yourls_api_action_version',
'delete' => 'yourls_api_action_delete',
'edit' => 'yourls_api_action_edit',
'search' => 'yourls_api_action_search',
);
$api_actions = yourls_apply_filter( 'api_actions', $api_actions );
// Register API actions
foreach( (array) $api_actions as $_action => $_callback ) {
yourls_add_filter( 'api_action_' . $_action, $_callback, 99 );
}
// Try requested API method. Properly registered actions should return an array.
$return = yourls_apply_filter( 'api_action_' . $action, false );
if ( false === $return ) {
$return = array(
'errorCode' => '400',
'message' => 'Unknown or missing "action" parameter',
'simple' => 'Unknown or missing "action" parameter',
);
}
if( isset( $_REQUEST['callback'] ) )
$return['callback'] = $_REQUEST['callback'];
elseif ( isset( $_REQUEST['jsonp'] ) )
$return['callback'] = $_REQUEST['jsonp'];
$format = $_REQUEST['format'] ?? 'xml';
yourls_api_output( $format, $return );
die();