*/
namespace RankMath\Search_Console;
use RankMath\Helper;
use MyThemeShop\Admin\List_Table;
defined( 'ABSPATH' ) || exit;
/**
* Sitemaps_List class.
*/
class Sitemaps_List extends List_Table {
/**
* The Constructor.
*/
public function __construct() {
parent::__construct(
[
'singular' => esc_html__( 'sitemap', 'rank-math' ),
'plural' => esc_html__( 'sitemaps', 'rank-math' ),
'no_items' => esc_html__( 'No sitemaps submitted.', 'rank-math' ),
]
);
}
/**
* Prepares the list of items for displaying.
*/
public function prepare_items() {
$this->set_column_headers();
$with_index = ! Helper::search_console()->sitemaps->selected_site_is_domain_property();
$this->items = Helper::search_console()->sitemaps->get_sitemaps( $with_index );
$this->set_pagination_args(
[
'total_items' => count( $this->items ),
'per_page' => 100,
]
);
}
/**
* Handle column path.
*
* @param object $item The current item.
*
* @return string
*/
protected function column_path( $item ) {
return ( empty( $item['isSitemapsIndex'] ) ? '' : '' ) . '' . $item['path'] . '';
}
/**
* Handle column lastDownloaded.
*
* @param object $item The current item.
*
* @return string
*/
protected function column_lastDownloaded( $item ) {
if ( ! empty( $item['lastDownloaded'] ) ) {
$date = date_parse( $item['lastDownloaded'] );
$date = date( 'Y-m-d H:i:s', mktime( $date['hour'], $date['minute'], $date['second'], $date['month'], $date['day'], $date['year'] ) );
return $date;
}
}
/**
* Handle column items.
*
* @param object $item The current item.
*
* @return string
*/
protected function column_items( $item ) {
if ( empty( $item['contents'] ) || ! is_array( $item['contents'] ) ) {
return;
}
$hash = [
'web' => [
'icon' => 'media-default',
'title' => esc_html__( 'Pages', 'rank-math' ),
],
'image' => [
'icon' => 'format-image',
'title' => esc_html__( 'Images', 'rank-math' ),
],
'news' => [
'icon' => 'media-document',
'title' => esc_html__( 'News', 'rank-math' ),
],
];
$items = '';
foreach ( $item['contents'] as $contents ) {
$items .= ! isset( $hash[ $contents['type'] ] ) ? '' :
sprintf(
' ',
$hash[ $contents['type'] ]['title'], $hash[ $contents['type'] ]['icon']
);
/* translators: content: submitted and indexed */
$items .= sprintf( wp_kses_post( __( '%1$d (%2$d indexed)
', 'rank-math' ) ), $contents['submitted'], $contents['indexed'] );
$items .= '';
}
return $items;
}
/**
* Handles the default column output.
*
* @param object $item The current item.
* @param string $column_name The current column name.
*
* @return string
*/
public function column_default( $item, $column_name ) {
if ( 'warnings' === $column_name ) {
return '' . $item['warnings'] . '';
}
if ( 'errors' === $column_name ) {
return '' . $item['errors'] . '';
}
return print_r( $item, true );
}
/**
* Get a list of columns.
*
* @return array
*/
public function get_columns() {
return [
'path' => esc_html__( 'Path', 'rank-math' ),
'lastDownloaded' => esc_html__( 'Last Downloaded', 'rank-math' ),
'items' => esc_html__( 'Items', 'rank-math' ),
'warnings' => esc_html__( 'Warnings', 'rank-math' ) . ' ',
'errors' => esc_html__( 'Errors', 'rank-math' ) . ' ',
];
}
/**
* Generates content for a single row of the table.
*
* @param object $item The current item.
*/
public function single_row( $item ) {
$classes = [];
$classes[] = ! empty( $item['isSitemapsIndex'] ) ? 'is-sitemap-index' : 'is-sitemap';
if ( ! empty( $item['isPending'] ) ) {
$classes[] = 'is-pending';
}
if ( ! empty( $item['errors'] ) ) {
$classes[] = 'has-errors';
}
if ( ! empty( $item['warnings'] ) ) {
$classes[] = 'has-warnings';
}
echo '';
$this->single_row_columns( $item );
echo '
';
}
/**
* Get refresh button
*/
public function get_refresh_button() {
$url = Helper::get_admin_url(
'search-console',
[
'view' => 'sitemaps',
'refresh_sitemaps' => '1',
'security' => wp_create_nonce( 'rank_math_refresh_sitemaps' ),
]
);
?>