5 * Note about translation : this file should NOT be translation ready
6 * API messages and returns are supposed to be programmatically tested, so default English is expected
10 define( 'YOURLS_API', true );
11 require_once( dirname( __FILE__ ) . '/includes/load-yourls.php' );
12 yourls_maybe_require_auth();
14 $action = ( isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : null );
16 yourls_do_action( 'api', $action );
18 // Define standard API actions
20 'shorturl' => 'yourls_api_action_shorturl',
21 'stats' => 'yourls_api_action_stats',
22 'db-stats' => 'yourls_api_action_db_stats',
23 'url-stats' => 'yourls_api_action_url_stats',
24 'expand' => 'yourls_api_action_expand',
25 'version' => 'yourls_api_action_version',
27 $api_actions = yourls_apply_filter( 'api_actions', $api_actions );
29 // Register API actions
30 foreach( (array) $api_actions as $_action => $_callback ) {
31 yourls_add_filter( 'api_action_' . $_action, $_callback, 99 );
34 // Try requested API method. Properly registered actions should return an array.
35 $return = yourls_apply_filter( 'api_action_' . $action, false );
36 if ( false === $return ) {
39 'message' => 'Unknown or missing "action" parameter',
40 'simple' => 'Unknown or missing "action" parameter',
44 if( isset( $_REQUEST['callback'] ) )
45 $return['callback'] = $_REQUEST['callback'];
47 $format = ( isset( $_REQUEST['format'] ) ? $_REQUEST['format'] : 'xml' );
49 yourls_api_output( $format, $return );