]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - admin/admin-ajax.php
Translation readyness of admin/tools.php
[Github/YOURLS.git] / admin / admin-ajax.php
1 <?php\r
2 define( 'YOURLS_ADMIN', true );\r
3 define( 'YOURLS_AJAX', true );\r
4 require_once( dirname( dirname( __FILE__ ) ) .'/includes/load-yourls.php' );\r
5 yourls_maybe_require_auth();\r
6 \r
7 // This file will output a JSON string\r
8 header( 'Content-type: application/json' );\r
9 \r
10 if( !isset( $_REQUEST['action'] ) )\r
11         die();\r
12 \r
13 // Pick action\r
14 $action = $_REQUEST['action'];\r
15 switch( $action ) {\r
16 \r
17         case 'add':\r
18                 yourls_verify_nonce( 'add_url', $_REQUEST['nonce'], false, 'omg error' );\r
19                 $return = yourls_add_new_link( $_REQUEST['url'], $_REQUEST['keyword'] );\r
20                 echo json_encode($return);\r
21                 break;\r
22                 \r
23         case 'edit_display':\r
24                 yourls_verify_nonce( 'edit-link_'.$_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error' );\r
25                 $row = yourls_table_edit_row ( $_REQUEST['keyword'] );\r
26                 echo json_encode( array('html' => $row) );\r
27                 break;\r
28 \r
29         case 'edit_save':\r
30                 yourls_verify_nonce( 'edit-save_'.$_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error' );\r
31                 $return = yourls_edit_link( $_REQUEST['url'], $_REQUEST['keyword'], $_REQUEST['newkeyword'], $_REQUEST['title'] );\r
32                 echo json_encode($return);\r
33                 break;\r
34                 \r
35         case 'delete':\r
36                 yourls_verify_nonce( 'delete-link_'.$_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error' );\r
37                 $query = yourls_delete_link_by_keyword( $_REQUEST['keyword'] );\r
38                 echo json_encode(array('success'=>$query));\r
39                 break;\r
40                 \r
41         case 'logout':\r
42                 // unused for the moment\r
43                 yourls_logout();\r
44                 break;\r
45                 \r
46         default:\r
47                 yourls_do_action( 'yourls_ajax_'.$action );\r
48 \r
49 }\r
50 \r
51 die();\r