]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - yourls-api.php
Smarter API (de/register methods) and a 'version' method. See Issue 1259.
[Github/YOURLS.git] / yourls-api.php
1 <?php\r
2 define( 'YOURLS_API', true );\r
3 require_once( dirname( __FILE__ ) . '/includes/load-yourls.php' );\r
4 yourls_maybe_require_auth();\r
5 \r
6 $action = ( isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : null );\r
7 \r
8 yourls_do_action( 'api', $action );\r
9 \r
10 // Define standard API actions\r
11 $api_actions = array(\r
12         'shorturl'  => 'yourls_api_action_shorturl',\r
13         'stats'     => 'yourls_api_action_stats',\r
14         'db-stats'  => 'yourls_api_action_db_stats',\r
15         'url-stats' => 'yourls_api_action_url_stats',\r
16         'expand'    => 'yourls_api_action_expand',\r
17         'version'   => 'yourls_api_action_version',\r
18 );\r
19 $api_actions = yourls_apply_filters( 'api_actions', $api_actions );\r
20 \r
21 // Register API actions\r
22 foreach( (array) $api_actions as $_action => $_callback ) {\r
23         yourls_add_filter( 'api_action_' . $_action, $_callback, 99 );          \r
24 }\r
25 \r
26 // Try requested API method. Properly registered actions should return an array.\r
27 $return = yourls_apply_filter( 'api_action_' . $action, false );\r
28 if ( false === $return ) {\r
29         $return = array(\r
30                 'errorCode' => 400,\r
31                 'message'   => 'Unknown or missing "action" parameter',\r
32                 'simple'    => 'Unknown or missing "action" parameter',\r
33         );\r
34 }\r
35 \r
36 if( isset( $_REQUEST['callback'] ) )\r
37         $return['callback'] = $_REQUEST['callback'];\r
38 \r
39 $format = ( isset( $_REQUEST['format'] ) ? $_REQUEST['format'] : 'xml' );\r
40 \r
41 yourls_api_output( $format, $return );\r
42 \r
43 die();