186 lines
10 KiB
PHP
186 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* Admin Page for Maple Local Fonts.
|
|
*
|
|
* @package Maple_Local_Fonts
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Class MLF_Admin_Page
|
|
*
|
|
* Handles the admin settings page rendering.
|
|
*/
|
|
class MLF_Admin_Page {
|
|
|
|
/**
|
|
* Constructor.
|
|
*/
|
|
public function __construct() {
|
|
// Empty constructor - class is instantiated for rendering
|
|
}
|
|
|
|
/**
|
|
* Render the admin page.
|
|
*/
|
|
public function render() {
|
|
$capability = function_exists('mlf_get_capability') ? mlf_get_capability() : 'edit_theme_options';
|
|
if (!current_user_can($capability)) {
|
|
wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'maple-local-fonts'));
|
|
}
|
|
|
|
$registry = new MLF_Font_Registry();
|
|
$installed_fonts = $registry->get_imported_fonts();
|
|
?>
|
|
<div class="wrap mlf-wrap">
|
|
<h1><?php esc_html_e('Maple Fonts', 'maple-local-fonts'); ?></h1>
|
|
<p class="mlf-description"><?php esc_html_e('Import Google Fonts to your local server for privacy-friendly, GDPR-compliant typography.', 'maple-local-fonts'); ?></p>
|
|
|
|
<div class="mlf-container">
|
|
<!-- Import Section -->
|
|
<div class="mlf-section mlf-import-section">
|
|
<h2><?php esc_html_e('Import from Google Fonts', 'maple-local-fonts'); ?></h2>
|
|
|
|
<form id="mlf-import-form" class="mlf-form">
|
|
<!-- Search Input -->
|
|
<div class="mlf-form-row">
|
|
<label for="mlf-font-search"><?php esc_html_e('Search Fonts', 'maple-local-fonts'); ?></label>
|
|
<div class="mlf-search-wrapper">
|
|
<span class="dashicons dashicons-search mlf-search-icon"></span>
|
|
<input type="text"
|
|
id="mlf-font-search"
|
|
class="mlf-search-input"
|
|
placeholder="<?php esc_attr_e('Search Google Fonts...', 'maple-local-fonts'); ?>"
|
|
autocomplete="off" />
|
|
<span class="spinner mlf-search-spinner" id="mlf-search-spinner"></span>
|
|
</div>
|
|
<p class="description"><?php esc_html_e('Type at least 2 characters to search.', 'maple-local-fonts'); ?></p>
|
|
</div>
|
|
|
|
<!-- Search Results -->
|
|
<div class="mlf-search-results" id="mlf-search-results" style="display: none;">
|
|
<div class="mlf-results-list" id="mlf-results-list"></div>
|
|
</div>
|
|
|
|
<!-- Selected Font (hidden until a font is selected) -->
|
|
<div class="mlf-selected-font" id="mlf-selected-font" style="display: none;">
|
|
<div class="mlf-selected-font-header">
|
|
<span class="mlf-selected-label"><?php esc_html_e('Selected Font:', 'maple-local-fonts'); ?></span>
|
|
<span class="mlf-selected-name" id="mlf-selected-name"></span>
|
|
<button type="button" class="mlf-change-font" id="mlf-change-font">
|
|
<?php esc_html_e('Change', 'maple-local-fonts'); ?>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Hidden input for font name -->
|
|
<input type="hidden" id="mlf-font-name" name="font_name" value="" />
|
|
|
|
<div class="mlf-form-row mlf-italic-row">
|
|
<label class="mlf-checkbox-label mlf-italic-toggle">
|
|
<input type="checkbox" name="include_italic" id="mlf-include-italic" value="1" checked />
|
|
<span><?php esc_html_e('Include Italic styles', 'maple-local-fonts'); ?></span>
|
|
</label>
|
|
<p class="description"><?php esc_html_e('Italic styles are useful for emphasized text. Uncheck to reduce download size.', 'maple-local-fonts'); ?></p>
|
|
</div>
|
|
|
|
<div class="mlf-form-row mlf-form-row-submit">
|
|
<button type="submit" class="button button-primary" id="mlf-download-btn">
|
|
<?php esc_html_e('Download & Install', 'maple-local-fonts'); ?>
|
|
</button>
|
|
<span class="spinner" id="mlf-spinner"></span>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="mlf-message" class="mlf-message" style="display: none;"></div>
|
|
</form>
|
|
|
|
<div class="mlf-info-note">
|
|
<span class="dashicons dashicons-info-outline"></span>
|
|
<span><?php esc_html_e('All font weights (100-900) will be downloaded automatically. Variable fonts are used when available for better performance.', 'maple-local-fonts'); ?></span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Installed Fonts Section -->
|
|
<div class="mlf-section mlf-installed-section">
|
|
<h2><?php esc_html_e('Installed Fonts', 'maple-local-fonts'); ?></h2>
|
|
|
|
<?php if (empty($installed_fonts)) : ?>
|
|
<p class="mlf-no-fonts"><?php esc_html_e('No fonts installed yet. Search and select a font above to get started.', 'maple-local-fonts'); ?></p>
|
|
<?php else : ?>
|
|
<div id="mlf-font-list" class="mlf-font-list">
|
|
<?php foreach ($installed_fonts as $font) : ?>
|
|
<div class="mlf-font-item" data-font-id="<?php echo esc_attr($font['id']); ?>">
|
|
<div class="mlf-font-info">
|
|
<h3 class="mlf-font-name"><?php echo esc_html($font['name']); ?></h3>
|
|
<p class="mlf-font-variants">
|
|
<?php
|
|
$variant_strings = [];
|
|
foreach ($font['variants'] as $variant) {
|
|
$variant_strings[] = sprintf('%s %s', $variant['weight'], $variant['style']);
|
|
}
|
|
echo esc_html(implode(', ', $variant_strings));
|
|
?>
|
|
</p>
|
|
</div>
|
|
<div class="mlf-font-actions">
|
|
<button type="button" class="button mlf-delete-btn" data-font-id="<?php echo esc_attr($font['id']); ?>">
|
|
<?php esc_html_e('Delete', 'maple-local-fonts'); ?>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Info Section -->
|
|
<div class="mlf-section mlf-info-section">
|
|
<?php if (wp_is_block_theme()) : ?>
|
|
<div class="mlf-info-box">
|
|
<span class="dashicons dashicons-editor-textcolor"></span>
|
|
<div>
|
|
<p><strong><?php esc_html_e('How to use your fonts', 'maple-local-fonts'); ?></strong></p>
|
|
<p>
|
|
<?php
|
|
printf(
|
|
/* translators: %s: link to WordPress Editor */
|
|
esc_html__('Go to %s to apply fonts to your site.', 'maple-local-fonts'),
|
|
'<a href="' . esc_url(admin_url('site-editor.php?path=%2Fwp_global_styles')) . '">' . esc_html__('Appearance → Editor → Styles → Typography', 'maple-local-fonts') . '</a>'
|
|
);
|
|
?>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<?php else : ?>
|
|
<div class="mlf-info-box mlf-info-box-classic">
|
|
<span class="dashicons dashicons-editor-textcolor"></span>
|
|
<div class="mlf-classic-theme-info">
|
|
<p><strong><?php esc_html_e('Classic Theme Detected', 'maple-local-fonts'); ?></strong></p>
|
|
<p><?php esc_html_e('Your theme does not support the Full Site Editor. To use imported fonts, add custom CSS to your theme:', 'maple-local-fonts'); ?></p>
|
|
<pre class="mlf-code-example">body {
|
|
font-family: "Open Sans", sans-serif;
|
|
}
|
|
h1, h2, h3, h4, h5, h6 {
|
|
font-family: "Open Sans", sans-serif;
|
|
}</pre>
|
|
<p class="description">
|
|
<?php
|
|
printf(
|
|
/* translators: %s: link to Customizer */
|
|
esc_html__('Add this CSS in %s or your theme\'s style.css file.', 'maple-local-fonts'),
|
|
'<a href="' . esc_url(admin_url('customize.php')) . '">' . esc_html__('Appearance → Customize → Additional CSS', 'maple-local-fonts') . '</a>'
|
|
);
|
|
?>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|