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