robotstxt-manager/admin/views/page-catalog.php
2026-08-12 13:18:40 +00:00

240 lines
9.7 KiB
PHP

<?php
/**
* Admin page view: ROBOTSTXT Plugins catalog.
*
* Available variables:
* $catalog list<array<string,mixed>> Catalog entries from Core.
* $local array<string, array{installed:bool, active:bool, version:string}>
* Local install state, keyed by slug.
*
* @package Robotstxt_Manager
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Variables provided by Robotstxt_Manager_Admin::render_page().
*
* @var list<array<string,mixed>> $catalog
* @var array<string, array{installed:bool, active:bool, version:string}> $local
*/
$client_configured = Robotstxt_Manager_Core_Client::from_options()->is_configured();
$refresh_url = add_query_arg(
array(
'action' => 'robotstxt_manager_refresh_catalog',
),
admin_url( 'admin-post.php' )
);
$refresh_url = wp_nonce_url( $refresh_url, 'robotstxt_manager_refresh_catalog' );
$refreshed = isset( $_GET['refreshed'] ) && '1' === $_GET['refreshed']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$local_wp_version = (string) get_bloginfo( 'version' );
$local_php_version = (string) PHP_VERSION;
$compat_warnings = 0;
?>
<div class="wrap">
<h1><?php esc_html_e( 'Manager (by ROBOTSTXT) — Plugins', 'robotstxt-manager' ); ?></h1>
<?php if ( $refreshed ) : ?>
<div class="notice notice-success is-dismissible"><p><?php esc_html_e( 'Catalog refreshed.', 'robotstxt-manager' ); ?></p></div>
<?php endif; ?>
<?php if ( ! $client_configured ) : ?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %s: settings URL. */
__( 'ROBOTSTXT Manager is not configured yet. <a href="%s">Set the Store URL and API key</a> to see your plugin catalog.', 'robotstxt-manager' ),
esc_url( admin_url( 'admin.php?page=' . Robotstxt_Manager_Settings::PAGE_SLUG ) )
)
);
?>
</p>
</div>
<?php elseif ( empty( $catalog ) ) : ?>
<div class="notice notice-warning">
<p>
<?php esc_html_e( 'No plugins were returned by the ROBOTSTXT store. Check the Store URL and API key on the Settings page, or click Refresh to try again.', 'robotstxt-manager' ); ?>
</p>
</div>
<p><a class="button" href="<?php echo esc_url( $refresh_url ); ?>"><?php esc_html_e( 'Refresh catalog', 'robotstxt-manager' ); ?></a></p>
<?php else : ?>
<p>
<a class="button" href="<?php echo esc_url( $refresh_url ); ?>"><?php esc_html_e( 'Refresh catalog', 'robotstxt-manager' ); ?></a>
</p>
<table class="wp-list-table widefat striped robotstxt-manager-catalog">
<thead>
<tr>
<th scope="col"><?php esc_html_e( 'Plugin', 'robotstxt-manager' ); ?></th>
<th scope="col"><?php esc_html_e( 'Type', 'robotstxt-manager' ); ?></th>
<th scope="col"><?php esc_html_e( 'Price', 'robotstxt-manager' ); ?></th>
<th scope="col"><?php esc_html_e( 'Requires WP', 'robotstxt-manager' ); ?></th>
<th scope="col"><?php esc_html_e( 'Requires PHP', 'robotstxt-manager' ); ?></th>
<th scope="col"><?php esc_html_e( 'Local state', 'robotstxt-manager' ); ?></th>
<th scope="col"><?php esc_html_e( 'Action', 'robotstxt-manager' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $catalog as $entry ) : ?>
<?php
$raw_slug = $entry['slug'] ?? '';
$raw_name = $entry['name'] ?? '';
$raw_kind = $entry['type'] ?? 'free';
$raw_cost = $entry['price_annual'] ?? 0;
$raw_ver = $entry['current_version'] ?? '';
$raw_url = $entry['page_url'] ?? '';
$raw_rwp = $entry['requires_wp'] ?? '';
$raw_rphp = $entry['requires_php'] ?? '';
$slug = is_string( $raw_slug ) ? $raw_slug : '';
$name = is_string( $raw_name ) ? $raw_name : $slug;
$kind = is_string( $raw_kind ) ? $raw_kind : 'free';
$cost = is_numeric( $raw_cost ) ? (float) ( $raw_cost + 0.0 ) : 0.0;
$remote_v = is_string( $raw_ver ) ? $raw_ver : '';
$page_url = is_string( $raw_url ) ? $raw_url : '';
$req_wp = is_string( $raw_rwp ) ? $raw_rwp : '';
$req_php = is_string( $raw_rphp ) ? $raw_rphp : '';
// Compatibility checks.
$wp_ok = '' === $req_wp || version_compare( $local_wp_version, $req_wp, '>=' );
$php_ok = '' === $req_php || version_compare( $local_php_version, $req_php, '>=' );
if ( ! $wp_ok || ! $php_ok ) {
++$compat_warnings;
}
$raw_state = $local[ $slug ] ?? array(
'installed' => false,
'active' => false,
'version' => '',
);
$l_installed = (bool) ( $raw_state['installed'] ?? false );
$l_active = (bool) ( $raw_state['active'] ?? false );
$raw_lv = $raw_state['version'] ?? '';
$l_version = is_string( $raw_lv ) ? $raw_lv : '';
$update_available = $l_installed && '' !== $remote_v && '' !== $l_version
&& version_compare( $l_version, $remote_v, '<' );
$row_class = ( ! $wp_ok || ! $php_ok ) ? ' robotstxt-manager-row--incompatible' : '';
?>
<tr class="<?php echo esc_attr( ltrim( $row_class ) ); ?>">
<td>
<strong><?php echo esc_html( $name ); ?></strong>
<?php if ( '' !== $remote_v ) : ?>
<br /><span class="description"><?php echo esc_html( sprintf( 'v%s', $remote_v ) ); ?></span>
<?php endif; ?>
</td>
<td><?php echo esc_html( 'premium' === $kind ? __( 'Premium', 'robotstxt-manager' ) : __( 'Free', 'robotstxt-manager' ) ); ?></td>
<td>
<?php
if ( $cost > 0.0 ) {
echo esc_html( sprintf( '€%s / year', number_format_i18n( $cost, 0 ) ) );
} else {
echo '&mdash;';
}
?>
</td>
<td>
<?php if ( '' !== $req_wp ) : ?>
<span class="<?php echo $wp_ok ? 'robotstxt-manager-compat--ok' : 'robotstxt-manager-compat--fail'; ?>">
<?php echo esc_html( $req_wp ); ?>
<?php if ( ! $wp_ok ) : ?>
<span class="robotstxt-manager-compat-warning" title="<?php esc_attr_e( 'Your site runs WordPress', 'robotstxt-manager' ); ?> <?php echo esc_attr( $local_wp_version ); ?>"> &#9888;</span>
<?php endif; ?>
</span>
<?php else : ?>
&mdash;
<?php endif; ?>
</td>
<td>
<?php if ( '' !== $req_php ) : ?>
<span class="<?php echo $php_ok ? 'robotstxt-manager-compat--ok' : 'robotstxt-manager-compat--fail'; ?>">
<?php echo esc_html( $req_php ); ?>
<?php if ( ! $php_ok ) : ?>
<span class="robotstxt-manager-compat-warning" title="<?php esc_attr_e( 'Your server runs PHP', 'robotstxt-manager' ); ?> <?php echo esc_attr( $local_php_version ); ?>"> &#9888;</span>
<?php endif; ?>
</span>
<?php else : ?>
&mdash;
<?php endif; ?>
</td>
<td>
<?php
if ( ! $l_installed ) {
echo '<span class="robotstxt-manager-state robotstxt-manager-state--not-installed">' . esc_html__( 'Not installed', 'robotstxt-manager' ) . '</span>';
} elseif ( ! $l_active ) {
echo '<span class="robotstxt-manager-state robotstxt-manager-state--inactive">' . esc_html__( 'Installed (inactive)', 'robotstxt-manager' ) . '</span>';
} elseif ( $update_available ) {
echo '<span class="robotstxt-manager-state robotstxt-manager-state--update">' . esc_html(
sprintf(
/* translators: 1: installed version, 2: available version. */
__( 'Update available (v%1$s → v%2$s)', 'robotstxt-manager' ),
$l_version,
$remote_v
)
) . '</span>';
} else {
echo '<span class="robotstxt-manager-state robotstxt-manager-state--ok">' . esc_html__( 'Up to date', 'robotstxt-manager' ) . '</span>';
}
?>
</td>
<td>
<?php if ( ! $l_installed ) : ?>
<?php if ( ! $wp_ok || ! $php_ok ) : ?>
<span class="description"><?php esc_html_e( 'Incompatible', 'robotstxt-manager' ); ?></span>
<?php elseif ( $cost > 0.0 && '' !== $page_url ) : ?>
<a class="button button-primary" href="<?php echo esc_url( $page_url ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Buy', 'robotstxt-manager' ); ?></a>
<?php elseif ( $cost <= 0.0 ) : ?>
<button type="button" class="button button-secondary robotstxt-manager-action-install" data-slug="<?php echo esc_attr( $slug ); ?>" disabled><?php esc_html_e( 'Install (soon)', 'robotstxt-manager' ); ?></button>
<?php endif; ?>
<?php elseif ( $update_available ) : ?>
<button type="button" class="button button-secondary robotstxt-manager-action-update" data-slug="<?php echo esc_attr( $slug ); ?>" disabled><?php esc_html_e( 'Update (soon)', 'robotstxt-manager' ); ?></button>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php if ( $compat_warnings > 0 ) : ?>
<div class="notice notice-warning inline" style="margin-top:1em">
<p>
<?php
echo esc_html(
sprintf(
/* translators: %d: number of incompatible plugins. */
_n( '%d plugin in the catalog is not compatible with this site\'s WordPress or PHP version.', '%d plugins in the catalog are not compatible with this site\'s WordPress or PHP version.', $compat_warnings, 'robotstxt-manager' ),
$compat_warnings
)
);
?>
<?php
echo esc_html(
sprintf(
/* translators: 1: local WP version, 2: local PHP version. */
__( 'This site runs WordPress %1$s on PHP %2$s.', 'robotstxt-manager' ),
$local_wp_version,
$local_php_version
)
);
?>
</p>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<style>
.robotstxt-manager-compat--ok { color: #00a32a; }
.robotstxt-manager-compat--fail { color: #d63638; font-weight: 600; }
.robotstxt-manager-compat-warning { cursor: help; }
.robotstxt-manager-row--incompatible { background-color: #fef7f0 !important; }
</style>