]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - yourls-api.php
Remove overzealous check
[Github/YOURLS.git] / yourls-api.php
1 <?php
2 /*
3  * YOURLS API
4  *
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
7  *
8  */
9
10 define( 'YOURLS_API', true );
11 require_once( dirname( __FILE__ ) . '/includes/load-yourls.php' );
12 yourls_maybe_require_auth();
13
14 $action = ( isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : null );
15
16 yourls_do_action( 'api', $action );
17
18 // Define standard API actions
19 $api_actions = array(
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',
26 );
27 $api_actions = yourls_apply_filter( 'api_actions', $api_actions );
28
29 // Register API actions
30 foreach( (array) $api_actions as $_action => $_callback ) {
31         yourls_add_filter( 'api_action_' . $_action, $_callback, 99 );          
32 }
33
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 ) {
37         $return = array(
38                 'errorCode' => 400,
39                 'message'   => 'Unknown or missing "action" parameter',
40                 'simple'    => 'Unknown or missing "action" parameter',
41         );
42 }
43
44 if( isset( $_REQUEST['callback'] ) )
45         $return['callback'] = $_REQUEST['callback'];
46
47 $format = ( isset( $_REQUEST['format'] ) ? $_REQUEST['format'] : 'xml' );
48
49 yourls_api_output( $format, $return );
50
51 die();