|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\CommandContract; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Contracts\ControllerContract; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Contracts\PluginContract; |
|
8
|
|
|
use GeminiLabs\SiteReviews\HookProxy; |
|
9
|
|
|
|
|
10
|
|
|
abstract class AbstractController implements ControllerContract |
|
11
|
|
|
{ |
|
12
|
|
|
use HookProxy; |
|
13
|
|
|
|
|
14
|
|
|
public function app(): PluginContract |
|
15
|
|
|
{ |
|
16
|
|
|
return glsr(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function download(string $filename, string $content): void |
|
20
|
|
|
{ |
|
21
|
|
|
if (glsr()->can('edit_others_posts')) { |
|
22
|
|
|
nocache_headers(); |
|
23
|
|
|
header('Content-Type: text/plain'); |
|
24
|
|
|
header("Content-Disposition: attachment; filename=\"{$filename}\""); |
|
25
|
|
|
echo wp_specialchars_decode($content); |
|
26
|
|
|
exit; |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function execute(CommandContract $command): CommandContract |
|
31
|
|
|
{ |
|
32
|
|
|
$command->handle(); |
|
33
|
|
|
return $command; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function getPostId(): int |
|
37
|
|
|
{ |
|
38
|
|
|
return intval(filter_input(INPUT_GET, 'post')); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
protected function hasQueryPermission(\WP_Query $query, string $postType = ''): bool |
|
42
|
|
|
{ |
|
43
|
|
|
global $pagenow; |
|
44
|
|
|
return glsr()->isAdmin() |
|
45
|
|
|
&& $query->is_main_query() |
|
46
|
|
|
&& $query->get('post_type') === ($postType ?: glsr()->post_type) |
|
47
|
|
|
&& 'edit.php' === $pagenow; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
protected function isListTable(): bool |
|
51
|
|
|
{ |
|
52
|
|
|
$screen = glsr_current_screen(); |
|
53
|
|
|
return 'edit' === $screen->base && $this->isReviewAdminScreen(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
protected function isNoticeAdminScreen(): bool |
|
57
|
|
|
{ |
|
58
|
|
|
return 'dashboard' === glsr_current_screen()->id || $this->isReviewAdminScreen(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function isReviewAdminPage(): bool |
|
62
|
|
|
{ |
|
63
|
|
|
return glsr()->isAdmin() && in_array(glsr()->post_type, [ |
|
64
|
|
|
filter_input(INPUT_GET, 'post_type'), |
|
65
|
|
|
get_post_type(), |
|
66
|
|
|
]); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
protected function isReviewAdminScreen(): bool |
|
70
|
|
|
{ |
|
71
|
|
|
return str_starts_with(glsr_current_screen()->post_type, glsr()->post_type); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
protected function isReviewEditor(): bool |
|
75
|
|
|
{ |
|
76
|
|
|
$screen = glsr_current_screen(); |
|
77
|
|
|
return ('post' === $screen->base) |
|
78
|
|
|
&& glsr()->post_type === $screen->id |
|
79
|
|
|
&& glsr()->post_type === $screen->post_type; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
protected function isReviewListTable(): bool |
|
83
|
|
|
{ |
|
84
|
|
|
$screen = glsr_current_screen(); |
|
85
|
|
|
return 'edit' === $screen->base && glsr()->post_type === $screen->post_type; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|