Completed
Pull Request — master (#2345)
by ྅༻ Ǭɀħ
01:36
created

admin/admin-ajax.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 View Code Duplication
	case 'edit_display':
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
	case 'delete':
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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();
52