]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - yourls-api.php
Aaaaaaand more translation. Aaaaaaand I think that's it!
[Github/YOURLS.git] / yourls-api.php
1 <?php\r
2 /*\r
3  * YOURLS API\r
4  *\r
5  * Note about translation : this file should NOT be translation ready\r
6  * API messages and returns are supposed to be programmatically tested, so default English is expected\r
7  *\r
8  */\r
9 \r
10 define( 'YOURLS_API', true );\r
11 require_once( dirname( __FILE__ ) . '/includes/load-yourls.php' );\r
12 yourls_maybe_require_auth();\r
13 \r
14 $action = ( isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : null );\r
15 \r
16 yourls_do_action( 'api', $action );\r
17 \r
18 // Define standard API actions\r
19 $api_actions = array(\r
20         'shorturl'  => 'yourls_api_action_shorturl',\r
21         'stats'     => 'yourls_api_action_stats',\r
22         'db-stats'  => 'yourls_api_action_db_stats',\r
23         'url-stats' => 'yourls_api_action_url_stats',\r
24         'expand'    => 'yourls_api_action_expand',\r
25         'version'   => 'yourls_api_action_version',\r
26 );\r
27 $api_actions = yourls_apply_filters( 'api_actions', $api_actions );\r
28 \r
29 // Register API actions\r
30 foreach( (array) $api_actions as $_action => $_callback ) {\r
31         yourls_add_filter( 'api_action_' . $_action, $_callback, 99 );          \r
32 }\r
33 \r
34 // Try requested API method. Properly registered actions should return an array.\r
35 $return = yourls_apply_filter( 'api_action_' . $action, false );\r
36 if ( false === $return ) {\r
37         $return = array(\r
38                 'errorCode' => 400,\r
39                 'message'   => 'Unknown or missing "action" parameter',\r
40                 'simple'    => 'Unknown or missing "action" parameter',\r
41         );\r
42 }\r
43 \r
44 if( isset( $_REQUEST['callback'] ) )\r
45         $return['callback'] = $_REQUEST['callback'];\r
46 \r
47 $format = ( isset( $_REQUEST['format'] ) ? $_REQUEST['format'] : 'xml' );\r
48 \r
49 yourls_api_output( $format, $return );\r
50 \r
51 die();