Issues (2756)

admin/admin-ajax.php (9 issues)

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
yourls_no_cache_headers();
10
11
if( !isset( $_REQUEST['action'] ) )
12
	die();
13
14
// Pick action
15
$action = $_REQUEST['action'];
16
switch( $action ) {
17
18
	case 'add':
19
		yourls_verify_nonce( 'add_url', $_REQUEST['nonce'], false, 'omg error' );
20
		$return = yourls_add_new_link( $_REQUEST['url'], $_REQUEST['keyword'] );
21
		echo json_encode($return);
22
		break;
0 ignored issues
show
Case breaking statement indented incorrectly; expected 5 spaces, found 2
Loading history...
23
24
	case 'edit_display':
25
		yourls_verify_nonce( 'edit-link_'.$_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error' );
26
		$row = yourls_table_edit_row ( $_REQUEST['keyword'] );
27
		echo json_encode( array('html' => $row) );
28
		break;
0 ignored issues
show
Case breaking statement indented incorrectly; expected 5 spaces, found 2
Loading history...
29
30
	case 'edit_save':
31
		yourls_verify_nonce( 'edit-save_'.$_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error' );
32
		$return = yourls_edit_link( $_REQUEST['url'], $_REQUEST['keyword'], $_REQUEST['newkeyword'], $_REQUEST['title'] );
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 116 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
33
		echo json_encode($return);
34
		break;
0 ignored issues
show
Case breaking statement indented incorrectly; expected 5 spaces, found 2
Loading history...
35
36
	case 'delete':
37
		yourls_verify_nonce( 'delete-link_'.$_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error' );
38
		$query = yourls_delete_link_by_keyword( $_REQUEST['keyword'] );
39
		echo json_encode(array('success'=>$query));
0 ignored issues
show
Expected 1 space between "'success'" and double arrow; 0 found
Loading history...
Expected 1 space between double arrow and "$query"; 0 found
Loading history...
40
		break;
0 ignored issues
show
Case breaking statement indented incorrectly; expected 5 spaces, found 2
Loading history...
41
42
	case 'logout':
43
		// unused for the moment
44
		yourls_logout();
0 ignored issues
show
The function yourls_logout was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
		/** @scrutinizer ignore-call */ 
45
  yourls_logout();
Loading history...
45
		break;
0 ignored issues
show
Case breaking statement indented incorrectly; expected 5 spaces, found 2
Loading history...
46
47
	default:
48
		yourls_do_action( 'yourls_ajax_'.$action );
49
50
}
51
52
die();
53