]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - yourls-api.php
Stricter coding syntax to avoid notices because of undefined indexes
[Github/YOURLS.git] / yourls-api.php
1 <?php\r
2 define('YOURLS_API', true);\r
3 require_once( dirname(__FILE__).'/includes/config.php' );\r
4 if ( defined('YOURLS_PRIVATE') && YOURLS_PRIVATE == true )\r
5         require_once( dirname(__FILE__).'/includes/auth.php' );\r
6 \r
7 if ( !isset($_REQUEST['action']) )\r
8         die( 'Missing parameter "action"' );\r
9 \r
10 $db = yourls_db_connect();\r
11 \r
12 $action = ( isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : null );\r
13         \r
14 switch( $action ) {\r
15 \r
16         case 'shorturl':\r
17                 $url = ( isset( $_REQUEST['url'] ) ? $_REQUEST['url'] : '' );\r
18                 $keyword = ( isset( $_REQUEST['keyword'] ) ? $_REQUEST['keyword'] : '' );\r
19                 $return = yourls_add_new_link( $url, $keyword, $db );\r
20                 unset($return['html']); // in API mode, no need for our internal HTML output\r
21                 break;\r
22         \r
23         case 'stats':\r
24                 $filter = ( isset( $_REQUEST['filter'] ) ? $_REQUEST['filter'] : '' );\r
25                 $limit = ( isset( $_REQUEST['limit'] ) ? $_REQUEST['limit'] : '' );\r
26                 $return = yourls_api_stats( $filter, $limit, $db );\r
27                 break;\r
28                 \r
29         default:\r
30                 die( 'Unknown "action" parameter' );\r
31 \r
32 }\r
33 \r
34 $format = ( isset( $_REQUEST['format'] ) ? $_REQUEST['format'] : 'xml' );\r
35 \r
36 yourls_api_output( $format, $return );\r
37 \r
38 die();