|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Adapters: Batch Analysis Adapter. |
|
4
|
|
|
* |
|
5
|
|
|
* @since 3.14.2 |
|
6
|
|
|
* @package Wordlift |
|
7
|
|
|
* @subpackage Wordlift/includes |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Define the {@link Wordlift_Batch_Analysis_Adapter} class. |
|
12
|
|
|
* |
|
13
|
|
|
* @since 3.14.2 |
|
14
|
|
|
* @package Wordlift |
|
15
|
|
|
* @subpackage Wordlift/includes |
|
16
|
|
|
*/ |
|
17
|
|
|
class Wordlift_Batch_Analysis_Adapter { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var Wordlift_Batch_Analysis_Service |
|
21
|
|
|
*/ |
|
22
|
|
|
private $batch_analysis_service; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Wordlift_Batch_Analysis_Adapter constructor. |
|
27
|
|
|
* |
|
28
|
|
|
* @since 3.14.2 |
|
29
|
|
|
* |
|
30
|
|
|
* @param \Wordlift_Batch_Analysis_Service $batch_analysis_service |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( $batch_analysis_service ) { |
|
33
|
|
|
|
|
34
|
|
|
$this->batch_analysis_service = $batch_analysis_service; |
|
35
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
View Code Duplication |
public function submit_auto_selected_posts() { |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
if ( ! isset( $_REQUEST['link'] ) ) { |
|
41
|
|
|
wp_die( 'The `link` parameter is required.' ); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$count = $this->batch_analysis_service->submit_auto_selected_posts( $_REQUEST['link'] ); |
|
45
|
|
|
|
|
46
|
|
|
// Clear any buffer. |
|
47
|
|
|
ob_clean(); |
|
48
|
|
|
|
|
49
|
|
|
// Send the response. |
|
50
|
|
|
wp_send_json_success( array( 'count' => $count ) ); |
|
51
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function submit() { |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
if ( ! isset( $_REQUEST['link'] ) || ! isset( $_REQUEST['post'] ) ) { |
|
57
|
|
|
wp_die( 'The `link` and `post` parameters are required.' ); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$count = $this->batch_analysis_service->submit( (array) $_REQUEST['post'], $_REQUEST['link'] ); |
|
61
|
|
|
|
|
62
|
|
|
// Clear any buffer. |
|
63
|
|
|
ob_clean(); |
|
64
|
|
|
|
|
65
|
|
|
// Send the response. |
|
66
|
|
|
wp_send_json_success( array( 'count' => $count ) ); |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
View Code Duplication |
public function cancel() { |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
if ( ! isset( $_REQUEST['post'] ) ) { |
|
73
|
|
|
wp_die( 'The `post` parameter is required.' ); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$count = $this->batch_analysis_service->cancel( (array) $_REQUEST['post'] ); |
|
77
|
|
|
|
|
78
|
|
|
// Clear any buffer. |
|
79
|
|
|
ob_clean(); |
|
80
|
|
|
|
|
81
|
|
|
// Send the response. |
|
82
|
|
|
wp_send_json_success( array( 'count' => $count ) ); |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
View Code Duplication |
public function clear_warning() { |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
if ( ! isset( $_REQUEST['post'] ) ) { |
|
89
|
|
|
wp_die( 'The `post` parameter is required.' ); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$this->batch_analysis_service->clear_warning( (array) $_REQUEST['post'] ); |
|
93
|
|
|
|
|
94
|
|
|
// Clear any buffer. |
|
95
|
|
|
ob_clean(); |
|
96
|
|
|
|
|
97
|
|
|
// Send the response. |
|
98
|
|
|
wp_send_json_success(); |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
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.