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 --- includes/functions-api.php | 232 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 includes/functions-api.php (limited to 'includes/functions-api.php') diff --git a/includes/functions-api.php b/includes/functions-api.php new file mode 100644 index 0000000..efb20de --- /dev/null +++ b/includes/functions-api.php @@ -0,0 +1,232 @@ + yourls_get_db_stats(), + 'statusCode' => 200, + 'simple' => 'Need either XML or JSON format for stats', + 'message' => 'success', + ); + + return yourls_apply_filter( 'api_db_stats', $return ); +} + +/** + * Return array for API stat requests + * + */ +function yourls_api_url_stats( $shorturl ) { + $keyword = str_replace( YOURLS_SITE . '/' , '', $shorturl ); // accept either 'http://ozh.in/abc' or 'abc' + $keyword = yourls_sanitize_string( $keyword ); + + $return = yourls_get_link_stats( $keyword ); + $return['simple'] = 'Need either XML or JSON format for stats'; + return yourls_apply_filter( 'api_url_stats', $return, $shorturl ); +} + +/** + * Expand short url to long url + * + */ +function yourls_api_expand( $shorturl ) { + $keyword = str_replace( YOURLS_SITE . '/' , '', $shorturl ); // accept either 'http://ozh.in/abc' or 'abc' + $keyword = yourls_sanitize_string( $keyword ); + + $longurl = yourls_get_keyword_longurl( $keyword ); + + if( $longurl ) { + $return = array( + 'keyword' => $keyword, + 'shorturl' => YOURLS_SITE . "/$keyword", + 'longurl' => $longurl, + 'title' => yourls_get_keyword_title( $keyword ), + 'simple' => $longurl, + 'message' => 'success', + 'statusCode' => 200, + ); + } else { + $return = array( + 'keyword' => $keyword, + 'simple' => 'not found', + 'message' => 'Error: short URL not found', + 'errorCode' => 404, + ); + } + + return yourls_apply_filter( 'api_expand', $return, $shorturl ); +} -- cgit v1.2.3