Addons.php
3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
namespace AC\Admin\Page;
use AC;
use AC\Admin;
use AC\Admin\RenderableHead;
use AC\Asset\Assets;
use AC\Asset\Enqueueables;
use AC\Asset\Location;
use AC\Asset\Style;
use AC\Integration\Filter;
use AC\IntegrationRepository;
use AC\Renderable;
class Addons implements Enqueueables, Renderable, RenderableHead {
const NAME = 'addons';
/**
* @var Location\Absolute
*/
protected $location;
/**
* @var IntegrationRepository
*/
protected $integrations;
/**
* @var Renderable
*/
protected $head;
public function __construct( Location\Absolute $location, IntegrationRepository $integrations, Renderable $head ) {
$this->location = $location;
$this->integrations = $integrations;
$this->head = $head;
}
public function render_head() {
return $this->head;
}
public function get_assets() {
return new Assets( [
new Style( 'ac-admin-page-addons', $this->location->with_suffix( 'assets/css/admin-page-addons.css' ) ),
new Admin\Asset\Addons( 'ac-admin-page-addons', $this->location->with_suffix( 'assets/js/admin-page-addons.js' ) ),
] );
}
public function render() {
ob_start();
echo '<h1 class="screen-reader-text">' . __( 'Add-ons', 'codepress-admin-columns' ) . '</h1>';
echo '<div class="ac-addons-groups">';
foreach ( $this->get_grouped_addons() as $group ) :
?>
<div class="ac-addons group-<?= esc_attr( $group['class'] ); ?>">
<h2 class="ac-lined-header"><?php echo $group['title']; ?></h2>
<ul>
<?php
foreach ( $group['integrations'] as $addon ) {
$actions = $this->render_actions( $addon );
/* @var AC\Integration $addon */
$view = new AC\View( [
'logo' => AC()->get_url() . $addon->get_logo(),
'title' => $addon->get_title(),
'slug' => $addon->get_slug(),
'description' => $addon->get_description(),
'link' => $addon->get_link(),
'actions' => $actions ? $actions->render() : null,
] );
echo $view->set_template( 'admin/edit-addon' );
}
?>
</ul>
</div>
<?php endforeach;
echo '</div>';
return ob_get_clean();
}
/**
* @param AC\Integration $addon
*
* @return Renderable
*/
protected function render_actions( AC\Integration $addon ): ?Renderable {
return new Admin\Section\AddonStatus( $addon );
}
/**
* @return array
*/
protected function get_grouped_addons() {
$recommended = $this->integrations->find_all( [
IntegrationRepository::ARG_FILTER => [
new Filter\IsPluginActive(),
],
] );
$available = $this->integrations->find_all( [
IntegrationRepository::ARG_FILTER => [
new Filter\IsPluginNotActive(),
],
] );
$groups = [];
if ( $recommended->exists() ) {
$groups[] = [
'title' => __( 'Recommended', 'codepress-admin-columns' ),
'class' => 'recommended',
'integrations' => $recommended,
];
}
if ( $available->exists() ) {
$groups[] = [
'title' => __( 'Available', 'codepress-admin-columns' ),
'class' => 'available',
'integrations' => $available,
];
}
return $groups;
}
}