2 define( 'YOURLS_ADMIN', true );
3 define( 'YOURLS_AJAX', true );
4 require_once( dirname( dirname( __FILE__ ) ) .'/includes/load-yourls.php' );
5 yourls_maybe_require_auth();
7 // This file will output a JSON string
8 yourls_content_type_header( 'application/json' );
10 if( !isset( $_REQUEST['action'] ) )
14 $action = $_REQUEST['action'];
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);
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) );
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);
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));
42 // unused for the moment
47 yourls_do_action( 'yourls_ajax_'.$action );