From 25b7d2aab61ae6421398d3abae5da6ffe590333d Mon Sep 17 00:00:00 2001 From: s1n Date: Sat, 28 Mar 2020 10:36:41 -0700 Subject: 3/28/2020, 10:36 --- yourls-api.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 yourls-api.php (limited to 'yourls-api.php') diff --git a/yourls-api.php b/yourls-api.php new file mode 100644 index 0000000..413abad --- /dev/null +++ b/yourls-api.php @@ -0,0 +1,53 @@ + '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', +); +$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 = ( isset( $_REQUEST['format'] ) ? $_REQUEST['format'] : 'xml' ); + +yourls_api_output( $format, $return ); + +die(); \ No newline at end of file -- cgit v1.2.3