forked from Automattic/aggregator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-aggregator-portals-list-table.php
executable file
·146 lines (111 loc) · 3.51 KB
/
class-aggregator-portals-list-table.php
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
138
139
140
141
142
143
144
145
146
<?php
/**
* Contains the Aggregator_Portals_List_Table for the network admin
*
* @package Aggregator
*/
if ( class_exists( 'WP_List_Table' ) ) {
/**
* List Table class fo rshowing Portals in network admin
*/
class Aggregator_Portals_List_Table extends WP_List_Table {
/**
* Constructor, we override the parent to pass our own arguments
*/
public function __construct() {
parent::__construct( array(
'singular' => 'wp_list_aggregator_site', // Singular label.
'plural' => 'wp_list_aggregator_sites', // plural label, also this well be one of the table css class.
'ajax' => false, // We won't support Ajax for this table.
) );
}
/**
* Define the columns that are going to be used in the table
*
* @return array $columns, the array of columns to use with the table
*/
public function get_columns() {
return array(
'col_site_domain' => __( 'Portals' ),
'col_sync_sites' => __( 'Sources' ),
);
}
/**
* Prepare our list items for display
*
* @todo pagination
*/
public function prepare_items() {
// Make sure we have an array for $this->items.
if ( ! is_array( $this->items ) ) {
$this->items = array();
}
// Get all the blogs.
$blogs = Aggregator::get_sites();
// Our array of portals.
$portals = array();
// Check if we have sync jobs for those sites.
foreach ( $blogs as $blog ) {
if ( $sync_blogs = get_site_option( "aggregator_{$blog->blog_id}_source_blogs" ) ) {
$portals[ $blog->blog_id ] = $sync_blogs;
}
unset( $sync_blogs );
}
if ( ! empty( $portals ) ) {
$this->items = $portals;
} else {
$this->items = array();
}
}
/**
* Display the table rows
*/
public function display_rows() {
// Get the sync sites to display.
$portals = $this->items;
if ( empty( $portals ) ) {
$this->no_items(); }
// Get the columns registered in the get_columns and get_sortable_columns methods.
list( $columns, $hidden ) = $this->get_column_info();
foreach ( $portals as $portal => $sync_blogs ) {
// Get the site info.
$portal = get_blog_details( $portal );
// Open the line.
echo '<tr id="record_' . esc_attr( $portal->blog_id ) . '">';
foreach ( $columns as $column_name => $column_display_name ) {
// Style attributes for each col.
$class = "class='$column_name column-$column_name'";
$style = ( in_array( $column_name, $hidden, true ) ) ? ' style="display:none;"' : '';
$attributes = $class . $style;
// Display the cell.
switch ( $column_name ) {
case 'col_site_domain':
// Define the action links order.
$actions = array(
'edit' => '',
);
// Create the links.
$actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'settings.php?page=aggregator&action=edit&id=' . $portal->blog_id ) ) . '">' . __( 'Edit' ) . '</a></span>';
echo "<td $attributes>" . esc_html( $portal->domain ) . $this->row_actions( $actions ) . '</td>'; // XSS ok.
break;
case 'col_sync_sites':
echo "<td $attributes>"; // XSS ok.
// Loop through each sync site getting relevant details for output.
foreach ( $sync_blogs as $sync_blog ) {
$sync_blog = get_blog_details( $sync_blog );
echo esc_html( $sync_blog->domain ) . '<br/>';
}
echo '</td>';
break;
}
}
}
}
/**
* Show a message when there are no rows
*/
function no_items() {
esc_html_e( 'No sync settings found.' );
}
}
}